@aiworker/web 1.22.0 → 1.22.2

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 (354) hide show
  1. package/README.md +4 -4
  2. package/bin/cli.js +7 -4
  3. package/bin/cli.test.js +165 -73
  4. package/bin/lib/cli-api-target.js +2 -2
  5. package/bin/lib/cli-args.js +119 -119
  6. package/bin/lib/cli-lifecycle.js +9 -9
  7. package/bin/lib/cli-network.js +3 -3
  8. package/bin/lib/cli-paths.js +3 -3
  9. package/bin/lib/cli-ports.js +2 -2
  10. package/bin/lib/cli-process.js +4 -4
  11. package/bin/lib/cli-startup.js +64 -15
  12. package/bin/lib/cli-tunnel-profiles.js +1 -1
  13. package/bin/lib/cli-tunnel-utils.js +2 -2
  14. package/bin/lib/commands-connect-url.js +19 -19
  15. package/bin/lib/commands-lifecycle.js +27 -27
  16. package/bin/lib/commands-logs.js +5 -5
  17. package/bin/lib/commands-models.js +1 -1
  18. package/bin/lib/commands-projects.js +1 -1
  19. package/bin/lib/commands-schedule.js +1 -1
  20. package/bin/lib/commands-serve.js +29 -29
  21. package/bin/lib/commands-session.js +1 -1
  22. package/bin/lib/commands-startup.js +45 -10
  23. package/bin/lib/commands-status.js +1 -1
  24. package/bin/lib/commands-tunnel.js +40 -40
  25. package/bin/lib/commands-update.js +1 -1
  26. package/bin/lib/commands-update.test.js +6 -6
  27. package/dist/assets/{CodeMirrorCommentWidgets-B3u7UIcE.js → CodeMirrorCommentWidgets-CSICpWQD.js} +1 -1
  28. package/dist/assets/{DiffView-DluiRSla.js → DiffView-hDBKesA_.js} +3 -3
  29. package/dist/assets/DirtyBranchSwitchDialog-C22HdWj4.js +1 -0
  30. package/dist/assets/FilesView-CdWzeOp9.js +17 -0
  31. package/dist/assets/GitView-VQQkYuUw.js +6 -0
  32. package/dist/assets/{JsonTreeView-B0BdZEHG.js → JsonTreeView-6lrhwD3q.js} +1 -1
  33. package/dist/assets/LinearIssuesView-Ba6Q9569.js +1 -0
  34. package/dist/assets/{MarkdownImageGallery-ClOvuZxC.js → MarkdownImageGallery-Czv_mhvS.js} +1 -1
  35. package/dist/assets/MarkdownRendererImpl-BrMcswiy.js +12 -0
  36. package/dist/assets/{OnboardingScreen-D2DG7K6b.js → OnboardingScreen-ChxQoAkx.js} +1 -1
  37. package/dist/assets/{PatchDiff-DvfqDql7.js → PatchDiff-BzcZPlOq.js} +1 -1
  38. package/dist/assets/{PierreDiffViewer-B7m3f0d7.js → PierreDiffViewer-BchBtZlp.js} +2 -2
  39. package/dist/assets/PlanView-DyDt_nZ_.js +5 -0
  40. package/dist/assets/SettingsView-BKf5xBsP.js +28 -0
  41. package/dist/assets/{SettingsWindow-i45U1Cy1.js → SettingsWindow-DDQYaKWQ.js} +1 -1
  42. package/dist/assets/{ToolOutputDialog-BTwyh5OF.js → ToolOutputDialog-iYF8Y2bz.js} +6 -6
  43. package/dist/assets/ToolPartDiffPreview-CdjbOVMM.js +8 -0
  44. package/dist/assets/{VirtualizedFileDiff-DD8lDVej.js → VirtualizedFileDiff-fFFm2QgH.js} +1 -1
  45. package/dist/assets/{WalkthroughView-egQgxel3.js → WalkthroughView-DOeCsMju.js} +2 -2
  46. package/dist/assets/{computeVirtualFileMetrics-BMIRgMHv.js → computeVirtualFileMetrics-CzgLum_K.js} +2 -2
  47. package/dist/assets/{contextPanelEmbeddedChat-C3fjDbdg.js → contextPanelEmbeddedChat-C0ZLAepL.js} +1 -1
  48. package/dist/assets/{de-C1P6X5Rs.js → de-B5JaA3SA.js} +6 -5
  49. package/dist/assets/{es-CDgaF1_t.js → es-EPIH88ii.js} +6 -5
  50. package/dist/assets/{fr-Bgxqvvz_.js → fr-CAMfxUdZ.js} +6 -5
  51. package/dist/assets/{index-CODwDsU_.js → index-Bl3LSbjn.js} +1 -1
  52. package/dist/assets/index-DF5kMP-i.js +39 -0
  53. package/dist/assets/index-Dl3xbAB_.css +1 -0
  54. package/dist/assets/{isDiffPlainText-BqayB8d3.js → isDiffPlainText-Dx-dB_8l.js} +1 -1
  55. package/dist/assets/{isFilePlainText-QfoiKJNY.js → isFilePlainText-CWFPwmnU.js} +1 -1
  56. package/dist/assets/{ja-BDRrEcNP.js → ja-CifOE1VN.js} +7 -6
  57. package/dist/assets/{ko-Ba8sQV79.js → ko-BBDyAyYQ.js} +7 -6
  58. package/dist/assets/{main-C5DVOxc6.js → main-DnBAoktx.js} +2 -2
  59. package/dist/assets/main-MhSaOZoB.js +930 -0
  60. package/dist/assets/{markdownCore-CZwzz5gw.js → markdownCore-BrBwOOMn.js} +2 -2
  61. package/dist/assets/{miniChat-DUJ4irZc.js → miniChat-BKyvLseN.js} +2 -2
  62. package/dist/assets/{mobile-CcaxB0n4.js → mobile-DKjeFgMN.js} +2 -2
  63. package/dist/assets/{patchFileDiff-yNfWXN4E.js → patchFileDiff-o8ms1me8.js} +1 -1
  64. package/dist/assets/pl-DgEHYfFM.js +16 -0
  65. package/dist/assets/{pt-BR-DIs6ElwV.js → pt-BR-DuWHojUw.js} +6 -5
  66. package/dist/assets/{renderElectronMiniChatApp-BcKLHXKe.js → renderElectronMiniChatApp-CDgBwwCS.js} +2 -2
  67. package/dist/assets/renderMobileApp-DJIKIK1r.js +25 -0
  68. package/dist/assets/runtimeEndpointReset-CYJ9O_xX.js +17 -0
  69. package/dist/assets/{scheduledTasksApi-DLW0mkQK.js → scheduledTasksApi-D8yamh1b.js} +1 -1
  70. package/dist/assets/{shikiHighlight-DYOWuY65.js → shikiHighlight-TEQCmzW8.js} +1 -1
  71. package/dist/assets/tr-D5m2yIWL.js +7 -0
  72. package/dist/assets/{uk-ZrCNjM7Y.js → uk-D_q60oog.js} +6 -5
  73. package/dist/assets/{useAppFontEffects-CjrntdL0.js → useAppFontEffects-D7sNpuL2.js} +161 -190
  74. package/dist/assets/useInlineCommentController-Brz_cLcQ.js +2 -0
  75. package/dist/assets/{useRootScrollLock-BHYPkrLv.js → useRootScrollLock-lXEnWlaU.js} +1 -1
  76. package/dist/assets/{vendor-codemirror-language-data-DFZik9R2.js → vendor-codemirror-language-data-Dp3KMRQG.js} +2 -2
  77. package/dist/assets/vendor-zod-CK21ihK-.js +39 -0
  78. package/dist/assets/{web-components-Bhg83tjf.js → web-components-_mNEMjFY.js} +1 -1
  79. package/dist/assets/{zh-CN-iv_AV4EC.js → zh-CN-D8QvsVeg.js} +6 -5
  80. package/dist/assets/{zh-TW-CzEUk38j.js → zh-TW-B9t7rQQO.js} +6 -5
  81. package/dist/index.html +22 -22
  82. package/dist/mini-chat.html +7 -7
  83. package/dist/mobile.html +5 -5
  84. package/package.json +3 -3
  85. package/server/index.js +118 -85
  86. package/server/lib/agent-memory/actions.js +2 -2
  87. package/server/lib/agent-memory/feature-flag.js +1 -1
  88. package/server/lib/agent-memory/feature-flag.test.js +8 -8
  89. package/server/lib/agent-memory/routes.js +2 -2
  90. package/server/lib/agent-tool/runtime.js +37 -54
  91. package/server/lib/agent-tool/runtime.test.js +59 -59
  92. package/server/lib/browser-control/broker.js +3 -3
  93. package/server/lib/browser-control/broker.test.js +1 -1
  94. package/server/lib/changelog/update-notes.js +82 -0
  95. package/server/lib/changelog/update-notes.test.js +59 -0
  96. package/server/lib/client-auth/remote-clients.test.js +5 -5
  97. package/server/lib/context-obligatory/runtime.js +7 -7
  98. package/server/lib/context-obligatory/runtime.test.js +5 -5
  99. package/server/lib/dev-servers/parse.js +2 -2
  100. package/server/lib/dev-servers/parse.test.js +2 -2
  101. package/server/lib/dev-servers/routes.js +1 -1
  102. package/server/lib/dev-tunnel/DOCUMENTATION.md +13 -4
  103. package/server/lib/dev-tunnel/client.js +1 -1
  104. package/server/lib/dev-tunnel/runtime.js +5 -5
  105. package/server/lib/dev-tunnel/tunnel.test.js +21 -1
  106. package/server/lib/dictation/local/model-catalog.js +1 -1
  107. package/server/lib/dictation/local/worker-process.js +2 -2
  108. package/server/lib/event-stream/directory-ws-bridge.js +1 -1
  109. package/server/lib/event-stream/global-ws-bridge.js +1 -1
  110. package/server/lib/event-stream/protocol.test.js +4 -4
  111. package/server/lib/event-stream/runtime.test.js +6 -6
  112. package/server/lib/fs/DOCUMENTATION.md +2 -0
  113. package/server/lib/fs/routes.js +37 -26
  114. package/server/lib/fs/routes.test.js +98 -21
  115. package/server/lib/git/DOCUMENTATION.md +3 -1
  116. package/server/lib/git/identity-storage.js +1 -1
  117. package/server/lib/git/issue-2746-longpaths.test.js +4 -4
  118. package/server/lib/git/routes.js +17 -1
  119. package/server/lib/git/service.js +116 -26
  120. package/server/lib/git/service.test.js +174 -3
  121. package/server/lib/github/auth.js +8 -8
  122. package/server/lib/github/pr-status.js +1 -1
  123. package/server/lib/github/routes.js +2 -2
  124. package/server/lib/inherited-env.js +1 -1
  125. package/server/lib/inherited-env.test.js +2 -2
  126. package/server/lib/linear/auth.js +8 -8
  127. package/server/lib/linear/auth.test.js +24 -24
  128. package/server/lib/linear/issues.test.js +6 -6
  129. package/server/lib/linear/mapping.test.js +4 -4
  130. package/server/lib/linear/oauth.js +2 -2
  131. package/server/lib/linear/oauth.test.js +14 -14
  132. package/server/lib/linear/routes.js +5 -5
  133. package/server/lib/linear/routes.test.js +16 -16
  134. package/server/lib/linear/status-runtime.test.js +9 -9
  135. package/server/lib/linear/status.js +1 -1
  136. package/server/lib/linear/status.test.js +15 -15
  137. package/server/lib/linear/teams.test.js +4 -4
  138. package/server/lib/magic-prompts/routes.js +2 -2
  139. package/server/lib/mcp-reconnect/DOCUMENTATION.md +55 -0
  140. package/server/lib/mcp-reconnect/runtime.js +122 -0
  141. package/server/lib/mcp-reconnect/runtime.test.js +140 -0
  142. package/server/lib/message-queue/DOCUMENTATION.md +158 -0
  143. package/server/lib/message-queue/runtime.js +870 -0
  144. package/server/lib/message-queue/runtime.test.js +482 -0
  145. package/server/lib/notifications/apns-runtime.js +17 -17
  146. package/server/lib/notifications/apns-runtime.test.js +11 -11
  147. package/server/lib/notifications/emitter-runtime.js +1 -1
  148. package/server/lib/notifications/emitter-runtime.test.js +1 -1
  149. package/server/lib/notifications/push-runtime.js +7 -7
  150. package/server/lib/notifications/routes.js +1 -1
  151. package/server/lib/notifications/runtime.js +1 -1
  152. package/server/lib/openchamber-control/action-resolution.test.js +10 -10
  153. package/server/lib/openchamber-control/actions.js +24 -24
  154. package/server/lib/openchamber-control/error.js +4 -4
  155. package/server/lib/openchamber-control/routes.js +2 -2
  156. package/server/lib/openchamber-control/routes.test.js +5 -5
  157. package/server/lib/openchamber-control/screenshots.js +1 -1
  158. package/server/lib/openchamber-control/screenshots.test.js +1 -1
  159. package/server/lib/openchamber-control/service.js +50 -50
  160. package/server/lib/openchamber-control/service.test.js +5 -5
  161. package/server/lib/openchamber-sessions/routes.js +124 -22
  162. package/server/lib/openchamber-sessions/routes.test.js +99 -11
  163. package/server/lib/opencode/DOCUMENTATION.md +13 -5
  164. package/server/lib/opencode/auth.js +1 -1
  165. package/server/lib/opencode/bootstrap-runtime.js +6 -6
  166. package/server/lib/opencode/cli-options.js +8 -8
  167. package/server/lib/opencode/config-paths.test.js +116 -0
  168. package/server/lib/opencode/core-routes.js +8 -7
  169. package/server/lib/opencode/core-routes.test.js +11 -11
  170. package/server/lib/opencode/env-config.js +5 -5
  171. package/server/lib/opencode/env-config.test.js +7 -7
  172. package/server/lib/opencode/env-runtime.js +10 -10
  173. package/server/lib/opencode/env-runtime.test.js +18 -18
  174. package/server/lib/opencode/feature-routes-runtime.js +17 -12
  175. package/server/lib/opencode/hmr-state-runtime.js +2 -2
  176. package/server/lib/opencode/hmr-state-runtime.test.js +1 -1
  177. package/server/lib/opencode/input-history-scope.js +14 -0
  178. package/server/lib/opencode/lifecycle.js +8 -8
  179. package/server/lib/opencode/lifecycle.test.js +4 -4
  180. package/server/lib/opencode/managed-plugin-config.js +35 -0
  181. package/server/lib/opencode/managed-process-registry.js +3 -3
  182. package/server/lib/opencode/mcp-oauth-callback.test.js +2 -2
  183. package/server/lib/opencode/openchamber-routes.js +15 -15
  184. package/server/lib/opencode/openchamber-routes.test.js +11 -11
  185. package/server/lib/opencode/plugins.js +2 -2
  186. package/server/lib/opencode/plugins.test.js +1 -1
  187. package/server/lib/opencode/project-icon-routes.js +2 -2
  188. package/server/lib/opencode/project-icon-routes.test.js +1 -1
  189. package/server/lib/opencode/providers.js +44 -2
  190. package/server/lib/opencode/providers.test.js +131 -4
  191. package/server/lib/opencode/proxy.js +2 -2
  192. package/server/lib/opencode/pwa-manifest-routes.js +1 -1
  193. package/server/lib/opencode/restart-session-recovery.test.js +1 -1
  194. package/server/lib/opencode/routes-upgrade.test.js +4 -4
  195. package/server/lib/opencode/routes.js +14 -14
  196. package/server/lib/opencode/server-startup-runtime.js +6 -6
  197. package/server/lib/opencode/session-runtime.js +3 -3
  198. package/server/lib/opencode/session-runtime.test.js +6 -6
  199. package/server/lib/opencode/settings-helpers.js +31 -3
  200. package/server/lib/opencode/settings-helpers.test.js +189 -12
  201. package/server/lib/opencode/settings-runtime.js +2 -2
  202. package/server/lib/opencode/settings-runtime.test.js +29 -0
  203. package/server/lib/opencode/shared.js +5 -2
  204. package/server/lib/opencode/shared.test.js +7 -7
  205. package/server/lib/opencode/shutdown-runtime.js +2 -0
  206. package/server/lib/opencode/skill-routes.js +2 -1
  207. package/server/lib/opencode/snippets.js +1 -2
  208. package/server/lib/opencode/startup-performance.js +1 -1
  209. package/server/lib/opencode/startup-performance.test.js +6 -6
  210. package/server/lib/opencode/static-routes-runtime.js +8 -8
  211. package/server/lib/opencode/static-routes-runtime.test.js +7 -7
  212. package/server/lib/opencode/upgrade-capability.js +2 -2
  213. package/server/lib/opencode/upgrade-capability.test.js +3 -3
  214. package/server/lib/package-manager.js +17 -42
  215. package/server/lib/package-manager.test.js +19 -19
  216. package/server/lib/permission-auto-accept/runtime.js +1 -1
  217. package/server/lib/project-context/routes.js +1 -1
  218. package/server/lib/projects/project-config.js +2 -2
  219. package/server/lib/quota/DOCUMENTATION.md +9 -1
  220. package/server/lib/quota/credentials/providers.js +4 -0
  221. package/server/lib/quota/credentials/store.js +4 -4
  222. package/server/lib/quota/credentials/store.test.js +8 -8
  223. package/server/lib/quota/index.js +1 -0
  224. package/server/lib/quota/providers/exe-dev.js +75 -0
  225. package/server/lib/quota/providers/exe-dev.test.js +47 -0
  226. package/server/lib/quota/providers/hyper.js +118 -0
  227. package/server/lib/quota/providers/hyper.test.js +126 -0
  228. package/server/lib/quota/providers/index.js +15 -0
  229. package/server/lib/quota/providers/ollama-cloud.js +1 -1
  230. package/server/lib/quota/providers/opencode-go.js +2 -1
  231. package/server/lib/quota/providers/opencode-go.test.js +9 -5
  232. package/server/lib/quota/providers/xai.js +1 -1
  233. package/server/lib/quota/routes.js +2 -0
  234. package/server/lib/quota/utils/auth.js +1 -1
  235. package/server/lib/relay/DOCUMENTATION.md +1 -1
  236. package/server/lib/relay/host-client.js +1 -1
  237. package/server/lib/relay/host-client.test.js +9 -1
  238. package/server/lib/relay/host-lock.js +1 -1
  239. package/server/lib/relay/service.js +5 -5
  240. package/server/lib/relay/tunnel-host.js +3 -1
  241. package/server/lib/relay/tunnel-host.test.js +9 -1
  242. package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +2 -2
  243. package/server/lib/scheduled-tasks/routes.js +5 -5
  244. package/server/lib/scheduled-tasks/service.js +25 -25
  245. package/server/lib/scheduled-tasks/service.test.js +1 -1
  246. package/server/lib/security/bind-host.js +4 -4
  247. package/server/lib/security/bind-host.test.js +1 -1
  248. package/server/lib/security/request-security.js +11 -5
  249. package/server/lib/security/request-security.test.js +14 -14
  250. package/server/lib/session-assist/runtime.js +10 -9
  251. package/server/lib/session-folders/routes.js +2 -2
  252. package/server/lib/session-folders/routes.test.js +8 -8
  253. package/server/lib/session-goal/DOCUMENTATION.md +20 -7
  254. package/server/lib/session-goal/create.js +4 -2
  255. package/server/lib/session-goal/create.test.js +1 -1
  256. package/server/lib/session-goal/objectives.js +4 -4
  257. package/server/lib/session-goal/routes.js +1 -1
  258. package/server/lib/session-goal/runtime.js +88 -22
  259. package/server/lib/session-goal/runtime.test.js +428 -2
  260. package/server/lib/session-knowledge/runtime.js +11 -11
  261. package/server/lib/session-knowledge/runtime.test.js +5 -5
  262. package/server/lib/skills-catalog/DOCUMENTATION.md +1 -1
  263. package/server/lib/skills-catalog/cache.test.js +2 -2
  264. package/server/lib/skills-catalog/disk-cache.js +5 -5
  265. package/server/lib/skills-catalog/github-meta.test.js +2 -2
  266. package/server/lib/skills-catalog/install.js +3 -2
  267. package/server/lib/small-model/DOCUMENTATION.md +4 -0
  268. package/server/lib/small-model/call.js +9 -3
  269. package/server/lib/small-model/call.test.js +29 -6
  270. package/server/lib/small-model/index.js +8 -7
  271. package/server/lib/small-model/index.test.js +1 -1
  272. package/server/lib/small-model/resolve.js +1 -1
  273. package/server/lib/small-model/resolve.test.js +1 -1
  274. package/server/lib/small-model/routes.js +2 -1
  275. package/server/lib/system-prompt/runtime.js +3 -22
  276. package/server/lib/system-prompt/runtime.test.js +3 -3
  277. package/server/lib/terminal/DOCUMENTATION.md +11 -7
  278. package/server/lib/terminal/runtime.js +180 -26
  279. package/server/lib/terminal/runtime.test.js +554 -27
  280. package/server/lib/terminal/shells.js +20 -3
  281. package/server/lib/terminal/shells.test.js +33 -2
  282. package/server/lib/tts/base-url.js +3 -3
  283. package/server/lib/tts/routes.test.js +20 -20
  284. package/server/lib/ui-auth/ui-auth.js +12 -9
  285. package/server/lib/ui-auth/ui-auth.test.js +19 -3
  286. package/server/lib/ui-auth/ui-passkeys.js +7 -7
  287. package/server/lib/walkthrough/index.js +1 -0
  288. package/server/lib/walkthrough/jobs.test.js +1 -1
  289. package/server/lib/walkthrough/language.test.js +1 -1
  290. package/server/lib/walkthrough/model-settings.js +3 -3
  291. package/server/lib/walkthrough/model-settings.test.js +1 -1
  292. package/server/lib/walkthrough/pull-request.test.js +5 -5
  293. package/server/lib/walkthrough/reproduce-2607.test.js +2 -2
  294. package/server/lib/walkthrough/routes.test.js +26 -5
  295. package/server/lib/walkthrough/store.js +3 -3
  296. package/server/lib/walkthrough/store.test.js +1 -1
  297. package/server/opencode-proxy.test.js +2 -2
  298. package/server/proxy-headers.js +1 -1
  299. package/server/sse-routes.test.js +4 -4
  300. package/README.md.bak +0 -250
  301. package/bin/lib/DOCUMENTATION.md.bak +0 -163
  302. package/dist/assets/CommitSection-SGBCAW0w.js +0 -1
  303. package/dist/assets/FilesView-Bdq8ppva.js +0 -17
  304. package/dist/assets/GitView-Znn7VJcP.js +0 -6
  305. package/dist/assets/LinearIssuesView-jP-hXyac.js +0 -1
  306. package/dist/assets/MarkdownRendererImpl-Dt9mjTRN.js +0 -12
  307. package/dist/assets/PlanView-B0F3BtPZ.js +0 -5
  308. package/dist/assets/SettingsView-BBW-S-gh.js +0 -28
  309. package/dist/assets/ToolPartDiffPreview-CUNe28U1.js +0 -8
  310. package/dist/assets/index-C57jT0Sa.css +0 -1
  311. package/dist/assets/index-DW_E3rnL.js +0 -7
  312. package/dist/assets/main-Bv5Pkngh.js +0 -928
  313. package/dist/assets/pl-Dioz29BI.js +0 -15
  314. package/dist/assets/renderMobileApp-D9yQJy0L.js +0 -25
  315. package/dist/assets/runtimeEndpointReset-CjhvxLH0.js +0 -16
  316. package/dist/assets/tr-DFnMlPxY.js +0 -6
  317. package/dist/assets/useInlineCommentController-CDEuSlPH.js +0 -2
  318. package/dist/assets/vendor-zod-BLfBSgBh.js +0 -39
  319. package/server/index.d.ts.bak +0 -39
  320. package/server/lib/agent-tool/DOCUMENTATION.md.bak +0 -119
  321. package/server/lib/browser-control/DOCUMENTATION.md.bak +0 -50
  322. package/server/lib/context-obligatory/DOCUMENTATION.md.bak +0 -19
  323. package/server/lib/dev-tunnel/DOCUMENTATION.md.bak +0 -57
  324. package/server/lib/dictation/DOCUMENTATION.md.bak +0 -100
  325. package/server/lib/event-stream/DOCUMENTATION.md.bak +0 -62
  326. package/server/lib/fs/DOCUMENTATION.md.bak +0 -47
  327. package/server/lib/git/DOCUMENTATION.md.bak +0 -193
  328. package/server/lib/github/DOCUMENTATION.md.bak +0 -183
  329. package/server/lib/linear/DOCUMENTATION.md.bak +0 -97
  330. package/server/lib/linear/OAUTH-BROKER-HANDOFF.md.bak +0 -91
  331. package/server/lib/markdown-image-grants/DOCUMENTATION.md.bak +0 -40
  332. package/server/lib/notifications/APNS.md.bak +0 -135
  333. package/server/lib/notifications/DOCUMENTATION.md.bak +0 -138
  334. package/server/lib/openchamber-control/DOCUMENTATION.md.bak +0 -64
  335. package/server/lib/opencode/DOCUMENTATION.md.bak +0 -431
  336. package/server/lib/opencode/managed-process-registry.d.ts.bak +0 -13
  337. package/server/lib/opencode/provider-env-aliases.d.ts.bak +0 -3
  338. package/server/lib/permission-auto-accept/DOCUMENTATION.md.bak +0 -34
  339. package/server/lib/project-context/DOCUMENTATION.md.bak +0 -160
  340. package/server/lib/quota/DOCUMENTATION.md.bak +0 -123
  341. package/server/lib/relay/DOCUMENTATION.md.bak +0 -100
  342. package/server/lib/scheduled-tasks/DOCUMENTATION.md.bak +0 -182
  343. package/server/lib/session-assist/DOCUMENTATION.md.bak +0 -66
  344. package/server/lib/session-goal/DOCUMENTATION.md.bak +0 -213
  345. package/server/lib/session-knowledge/DOCUMENTATION.md.bak +0 -89
  346. package/server/lib/skills-catalog/DOCUMENTATION.md.bak +0 -151
  347. package/server/lib/small-model/DOCUMENTATION.md.bak +0 -212
  348. package/server/lib/system-prompt/DOCUMENTATION.md.bak +0 -36
  349. package/server/lib/terminal/DOCUMENTATION.md.bak +0 -50
  350. package/server/lib/text/DOCUMENTATION.md.bak +0 -35
  351. package/server/lib/tts/DOCUMENTATION.md.bak +0 -147
  352. package/server/lib/tunnels/DOCUMENTATION.md.bak +0 -21
  353. package/server/lib/ui-auth/DOCUMENTATION.md.bak +0 -44
  354. package/server/lib/walkthrough/DOCUMENTATION.md.bak +0 -411
@@ -1,25 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesView-Bdq8ppva.js","assets/vendor-react-BUCujlKS.js","assets/vendor-scheduler-7OC5HNn7.js","assets/index-DW_E3rnL.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-zustand-BAGL70zf.js","assets/vendor-zod-BLfBSgBh.js","assets/vendor-opencode-sdk-BJ73u-bH.js","assets/index-C57jT0Sa.css","assets/useAppFontEffects-CjrntdL0.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-base-ui-BeMD8X_w.js","assets/vendor-floating-ui-utils-D6FqdtJt.js","assets/vendor-floating-ui-react-dom-DxYCWdHj.js","assets/vendor-floating-ui-dom-BTvzWks8.js","assets/vendor-floating-ui-core-PuGzNPnN.js","assets/vendor-use-sync-external-store-D6wYuSt-.js","assets/contextPanelEmbeddedChat-C3fjDbdg.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-dnd-kit-core-BZknOX2w.js","assets/vendor-dnd-kit-utilities-B_MdXhJC.js","assets/vendor-dnd-kit-accessibility-BHxJPORy.js","assets/vendor-dnd-kit-sortable-CsEagZ81.js","assets/vendor-framer-motion-livSKyyV.js","assets/vendor-motion-dom-D_o3BTI3.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-tanstack-react-virtual-g05Cx3z9.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-sonner-DFyL3AvE.js","assets/vendor-cmdk-DgLInKvT.js","assets/vendor-radix-ui-react-dialog-B94Bt2qq.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-DcAh5WdT.js","assets/vendor-radix-ui-react-context-Czxm7Z62.js","assets/vendor-radix-ui-react-id-f5BLKEVw.js","assets/vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js","assets/vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js","assets/vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js","assets/vendor-radix-ui-react-primitive-DhVoX9SD.js","assets/vendor-radix-ui-react-slot-BQgQOasS.js","assets/vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js","assets/vendor-radix-ui-react-use-escape-keydown-oph88g-F.js","assets/vendor-radix-ui-react-focus-scope-CiaxW4dD.js","assets/vendor-radix-ui-react-portal-BMJYHWck.js","assets/vendor-radix-ui-react-presence-CNxf-uq4.js","assets/vendor-radix-ui-react-focus-guards-B6qJXYua.js","assets/vendor-react-remove-scroll-DO7dCTnK.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-BcFYyj3E.js","assets/vendor-react-style-singleton-q6EMHnwf.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-zDC0RhA3.js","assets/vendor-use-callback-ref-D3RC8gqK.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-BgPj_McA.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-codemirror-state-C9awkmn-.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-codemirror-view-CiLROUVV.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-Cc2ZYbgX.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-DzPz9Wgq.js","assets/vendor-codemirror-lang-json-CMBS2tG9.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-O0cZX78y.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-CfgK872x.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-BPGOH9ye.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-DFZik9R2.js","assets/vendor-codemirror-lang-python-HahnQaAS.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-B7H_j0iU.js","assets/vendor-legendapp-list-gg7YLRW7.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/runtimeEndpointReset-CjhvxLH0.js","assets/shikiHighlight-DYOWuY65.js","assets/vendor-codemirror-search-BmS-GmcX.js","assets/vendor-replit-codemirror-vim-B2DJlAhT.js","assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js","assets/JsonTreeView-B0BdZEHG.js","assets/web-components-Bhg83tjf.js","assets/computeVirtualFileMetrics-BMIRgMHv.js","assets/vendor-shiki-Bbf2GEcE.js","assets/vendor-shikijs-core-CGM_jqPK.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-BgLrS_2D.js","assets/vendor-hast-util-to-html-BKBhbTDb.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-rJCbAzvX.js","assets/vendor-zwitch-C2o2j-tx.js","assets/vendor-stringify-entities-CsH1VEn9.js","assets/vendor-character-entities-legacy-BpoLgcEt.js","assets/vendor-character-entities-html4-D7taRCQ7.js","assets/vendor-ccount-c2V3InAJ.js","assets/vendor-comma-separated-tokens-D8TqSuIK.js","assets/vendor-space-separated-tokens-DD3iYX1K.js","assets/vendor-hast-util-whitespace-D4Wp6AEg.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/themeResolver-BmJyTmjJ.js","assets/vendor-pierre-theming-C6Z4M5_u.js","assets/vendor-shikijs-engine-javascript-Cme4830A.js","assets/vendor-oniguruma-to-es-DLBnFDCE.js","assets/vendor-oniguruma-parser-C0D4_9rT.js","assets/vendor-regex-BBWcyTkg.js","assets/vendor-regex-utilities-2BQyy0xI.js","assets/vendor-regex-recursion-JU4mF-dD.js","assets/vendor-shikijs-transformers-CZWsLLKm.js","assets/Virtualizer-CZlLSacm.js","assets/isFilePlainText-QfoiKJNY.js","assets/appThemeRegistry-BK0dHKa6.js","assets/registerCustomTheme-BBXUCRnG.js","assets/Virtualizer-D_a8gKmg.js","assets/scheduledTasksApi-DLW0mkQK.js","assets/vendor-react-drawio-Ct3Q0DsD.js","assets/useInlineCommentController-CDEuSlPH.js","assets/CodeMirrorCommentWidgets-B3u7UIcE.js","assets/vendor-capacitor-app-BrDJj9I_.js","assets/vendor-capacitor-core-B4EWRrHz.js","assets/vendor-capacitor-push-notifications-KNe1zSBF.js"])))=>i.map(i=>d[i]);
2
- import{f as ce,r as xs,j as t,R as l,c as bt,h as po}from"./vendor-react-BUCujlKS.js";import{u as He,a as kt,b as tr,d as pn,i as Pe,e as Ke,s as ft,f as $t,r as Cs,h as ho,j as sr,k as go,p as bo,l as xo,m as tt,n as yo,o as hn,q as gn,t as bn,v as vo,w as xn,M as Gt,x as wo,y as jo}from"./index-DW_E3rnL.js";import{u as Es,a as ko,b as Le,c as nr,d as rr,r as Rs,e as So,f as de,t as le,o as No,I as ee,B as ye,g as Co,O as Xe,h as J,P as Eo,i as Ro,j as Po,k as To,l as Oe,m as Ao,n as at,p as Io,q as yn,s as _o,v as Ps,w as Do,x as Mo,y as ke,z as zo,A as or,C as ir,D as ar,E as Oo,F as Ts,G as Lo,H as lr,J as Bo,K as $o,M as Fo,L as cr,N as ur,Q as dr,R as fr,S as As,T as Wo,U as Uo,V as Is,W as Vo,X as Go,Y as Pt,Z as us,_ as Ko,$ as mr,a0 as Ho,a1 as _s,a2 as pr,a3 as hr,a4 as It,a5 as ht,a6 as qo,a7 as Yo,a8 as Jo,a9 as Xo,aa as Qo,ab as Ds,ac as Zo,ad as ei,ae as ti,af as si,ag as We,ah as ni,ai as ri,aj as oi,ak as ii,al as ai,am as li,an as ci,ao as Be,ap as ui,aq as di,ar as fi,as as mi,at as pi,au as hi,av as gi,aw as gr,ax as bi,ay as xi,az as yi,aA as vi,aB as wi,aC as ji,aD as ki,aE as Si,aF as Ni,aG as Ci,aH as Ei,aI as Ri,aJ as Pi,aK as Ti,aL as Ai,aM as Ii,aN as _i,aO as Di,aP as Mi,aQ as zi,aR as Oi,aS as Li,aT as Bi,aU as $i,aV as Fi,aW as Wi,aX as Ui,aY as Vi,aZ as Gi,a_ as Ki,a$ as Hi}from"./useAppFontEffects-CjrntdL0.js";import{u as mt,S as br,p as qi,D as Yi,N as Ji,a as Xi,b as Qi,c as Zi,d as ea,T as ta,P as sa,r as na,e as ra,f as oa,g as ia,O as aa,C as la,h as ca,i as ua}from"./runtimeEndpointReset-CjhvxLH0.js";import{_ as xt}from"./vendor-vite-runtime-DD1OZmLC.js";import{S as da,A as fa}from"./SettingsView-BBW-S-gh.js";import{PlanView as ma}from"./PlanView-B0F3BtPZ.js";import{p as pa}from"./vendor-aparajita-capacitor-secure-storage-5IShChL0.js";import{Capacitor as ha}from"./vendor-capacitor-core-B4EWRrHz.js";import{k as ys,s as xr,M as Ms,a as Qt,J as vs,p as ga,_ as vn,b as yr,P as vr,d as ba,f as zs,V as xa,K as wn,c as ya,Q as va,r as wa,U as ja,Z as ka}from"./vendor-remixicon-react-Dil0zKKT.js";import{f as Os,h as yt,i as Ls,P as Bs,D as $s,j as Fs}from"./vendor-dnd-kit-core-BZknOX2w.js";import{s as Ws,S as Us,v as Vs,u as Gs}from"./vendor-dnd-kit-sortable-CsEagZ81.js";import{C as Ks}from"./vendor-dnd-kit-utilities-B_MdXhJC.js";import{c as Hs,p as wr}from"./vendor-zustand-BAGL70zf.js";import{toast as jn}from"./vendor-sonner-DFyL3AvE.js";import{C as Sa,a as Na}from"./CommitSection-SGBCAW0w.js";import{P as Ca}from"./PierreDiffViewer-B7m3f0d7.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zod-BLfBSgBh.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-BeMD8X_w.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-C3fjDbdg.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-DFZik9R2.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-yaml-3778uTud.js";import"./shikiHighlight-DYOWuY65.js";import"./vendor-codemirror-search-BmS-GmcX.js";import"./vendor-replit-codemirror-vim-B2DJlAhT.js";import"./vendor-replit-codemirror-vim-core-FHzKdNUS.js";import"./appThemeRegistry-BK0dHKa6.js";import"./registerCustomTheme-BBXUCRnG.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-qrcode-DTJ12-WC.js";import"./vendor-dijkstrajs-COg3n3zL.js";import"./useInlineCommentController-CDEuSlPH.js";import"./CodeMirrorCommentWidgets-B3u7UIcE.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./web-components-Bhg83tjf.js";import"./computeVirtualFileMetrics-BMIRgMHv.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./VirtualizedFileDiff-DD8lDVej.js";import"./isDiffPlainText-BqayB8d3.js";import"./vendor-diff-C3JhlQdm.js";import"./Virtualizer-D_a8gKmg.js";let jr=null,kn=!1;const Ea=new Promise(n=>{jr=n});function Ra(){kn||(kn=!0,jr?.())}const Pa=6,Ta=n=>n.parentID??null,Sn=n=>{const e=n.replace(/\/+$/,"");return e.slice(e.lastIndexOf("/")+1)||e},Aa=n=>n.replace(/\\/g,"/").replace(/\/+$/,""),Ia=(n,e)=>{if(!n)return"";let s=null,o=-1;for(const r of e){const i=Aa(r.path);(n===i||n.startsWith(`${i}/`))&&i.length>o&&(s=r,o=i.length)}return s?s.label?.trim()||Sn(s.path):Sn(n)},_a=()=>{const n=Es.getState().activeSessions,e=ko.getState().index.session.unseenCount,s=He.getState().notifyOnSubtasks,o=Le.getState().projects,r=nr.getState().ids,i=rr.getState().rankById;let c=0;const u=[];for(const a of n){const d=Ta(a)!==null,g=(e[a.id]??0)>0&&(!d||s);g&&(c+=1),d||u.push({session:a,unread:g,project:Ia(Rs(a),o)})}u.sort((a,d)=>So(a.session,d.session,r,i));const f=u.slice(0,Pa).map(({session:a,unread:d,project:p})=>({id:a.id,title:a.title??"",unread:d,project:p}));return{runtimeKey:kt(),attentionCount:c,recentSessions:f}},Da="__AIWORKER_WIDGET_SNAPSHOT__",Ma=()=>{typeof window>"u"||(window[Da]=()=>{try{return JSON.stringify(_a())}catch{return null}})},ds="mobile-app-update-available",Nn="mobile-app-update-toast-dismissed-version",za=()=>{const n=ce.c(8),{t:e}=de(),s=mt(Oa),o=mt(La),r=mt(Ba),i=mt($a);let c;n[0]===Symbol.for("react.memo_cache_sentinel")?(c=new Set,n[0]=c):c=n[0];const u=xs.useRef(c);let f,a;return n[1]!==s||n[2]!==i||n[3]!==o||n[4]!==e||n[5]!==r?(f=()=>{if(tr()!=="android"||o!=="mobile"||!s||!r||!i){le.dismiss(ds);return}pn().getItem(Nn)!==r&&(u.current.has(r)||(u.current.add(r),le.info(e("mobileUpdate.toast.available.title"),{id:ds,description:e("mobileUpdate.toast.available.description",{version:r}),duration:1/0,icon:t.jsx(ee,{name:"download",className:"h-4 w-4 text-muted-foreground"}),action:{label:e("mobileUpdate.toast.actions.download"),onClick:()=>{No(i)}},cancel:{label:e("mobileUpdate.toast.actions.dismiss"),onClick:()=>{pn().setItem(Nn,r),le.dismiss(ds)}}})))},a=[s,i,o,e,r],n[1]=s,n[2]=i,n[3]=o,n[4]=e,n[5]=r,n[6]=f,n[7]=a):(f=n[6],a=n[7]),xs.useEffect(f,a),null};function Oa(n){return n.available}function La(n){return n.runtimeType}function Ba(n){return n.info?.version}function $a(n){return n.info?.downloadUrl}const Cn=300,Fa="aiworker.mobile.connectLog.v1",pt=[];if(typeof window<"u")try{window.localStorage.removeItem(Fa)}catch{}const qs=(n,e)=>{pt.push({at:Date.now(),step:n,detail:e}),pt.length>Cn&&pt.splice(0,pt.length-Cn)};typeof window<"u"&&qs("app:launch","{}");const Wa=()=>[...pt],Ua=n=>{const e=new Date(n),s=(o,r=2)=>String(o).padStart(r,"0");return`${s(e.getHours())}:${s(e.getMinutes())}:${s(e.getSeconds())}.${s(e.getMilliseconds(),3)}`},kr=n=>`${Ua(n.at)} ${n.step}${n.detail&&n.detail!=="{}"?` ${n.detail}`:""}`,Va=()=>pt.map(kr).join(`
3
- `),Sr=(n,e)=>{const s=ce.c(10),o=700,r=l.useRef(null),i=l.useRef(null),c=l.useRef(!1);let u;s[0]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{r.current!==null&&window.clearTimeout(r.current),r.current=null,i.current=null},s[0]=u):u=s[0];const f=u;let a,d;s[1]===Symbol.for("react.memo_cache_sentinel")?(a=()=>f,d=[f],s[1]=a,s[2]=d):(a=s[1],d=s[2]),l.useEffect(a,d);let p;s[3]!==o||s[4]!==n?(p=S=>{c.current=!1,i.current={x:S.clientX,y:S.clientY},r.current!==null&&window.clearTimeout(r.current),r.current=window.setTimeout(()=>{r.current=null,c.current=!0,n()},o)},s[3]=o,s[4]=n,s[5]=p):p=s[5];const g=p;let h;s[6]===Symbol.for("react.memo_cache_sentinel")?(h=S=>{const E=i.current;E&&(Math.abs(S.clientX-E.x)>10||Math.abs(S.clientY-E.y)>10)&&f()},s[6]=h):h=s[6];const b=h;let j;s[7]===Symbol.for("react.memo_cache_sentinel")?(j=S=>{c.current&&(c.current=!1,S.preventDefault(),S.stopPropagation())},s[7]=j):j=s[7];const y=j;let A;return s[8]!==g?(A={onPointerDown:g,onPointerMove:b,onPointerUp:f,onPointerCancel:f,onClickCapture:y},s[8]=g,s[9]=A):A=s[9],A},Zt="aiworker.mobile.connections.v1",Ga="aiworker.mobile.",En="aiworker.mobile.deviceId",Ka=()=>{try{const n=window.localStorage.getItem(En);if(n&&n.trim())return n.trim();const e=crypto.randomUUID();return window.localStorage.setItem(En,e),e}catch{return crypto.randomUUID()}},Rn=()=>`mobile:${Ka()}`,Pn=()=>{try{const n=ha.getPlatform();return n==="ios"||n==="android"?n:void 0}catch{return}},Nr=12,Cr=8e3,Ha=2500,qa=3e3,es=2500,Ya=()=>{let n=0;return{begin:()=>(n+=1,n),cancel:()=>{n+=1},isCurrent:e=>e===n}},St=n=>{const e=n.trim();if(!e)return"";const s=/^https?:\/\//i.test(e)?e:`http://${e}`,o=new URL(s);return o.hash="",o.search="",o.pathname=o.pathname.replace(/\/+$/,""),o.toString().replace(/\/+$/,"")},Yt=n=>{try{return new URL(n).host}catch{return n}},vt=n=>{try{return St(n)}catch{return n.trim().replace(/\/+$/g,"")}},Er=(n,e)=>vt(n)===vt(e),Rr=n=>`relay:${n.serverId}@${n.relayUrl.trim()}`,Ja=n=>`relay://${n.serverId}`,rs=n=>n.candidates.filter(e=>e.kind==="direct"),st=n=>{const e=n.candidates.find(s=>s.kind==="relay");return e&&e.kind==="relay"?e.relay:null},qe=n=>{const e=rs(n)[0];if(e)return e.url;const s=st(n);return s?Ja(s):""},Re=n=>{const e=st(n);if(e)return Rr(e);const s=rs(n)[0];return s?vt(s.url):""},ts=(n,e)=>{const s=n.find(i=>i.kind==="relay"),o=s&&s.kind==="relay"?s.relay.serverId:null,r=new Set(n.filter(i=>i.kind==="direct").map(i=>vt(i.url)));return e.some(i=>i.kind==="relay"?o!==null&&i.relay.serverId===o:r.has(vt(i.url)))},Ys=n=>{const e=(()=>{try{return St(n)}catch{return""}})();return e?[{kind:"direct",url:e}]:[]},Tn=n=>{if(n.candidates&&n.candidates.length>0)return n.candidates;const e=[];return typeof n.url=="string"&&n.url.trim()&&!/^relay:\/\//i.test(n.url.trim())&&e.push(...Ys(n.url)),n.relay&&e.push({kind:"relay",relay:n.relay}),e},Js=n=>{if(!n||typeof n!="object"||Array.isArray(n))return null;const e=n;if(typeof e.relayUrl!="string"||!e.relayUrl.trim()||typeof e.serverId!="string"||!e.serverId.trim())return null;const s=e.hostEncPubJwk;if(!s||typeof s!="object"||Array.isArray(s))return null;const o=s;return o.kty!=="EC"||o.crv!=="P-256"||typeof o.x!="string"||!o.x||typeof o.y!="string"||!o.y?null:{relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:{kty:"EC",crv:"P-256",x:o.x,y:o.y}}},Pr=n=>{try{return JSON.stringify(n)}catch{return String(n)}},ge=(n,e={})=>{const s=Pr(e);console.info("[mobile-connect]",n,s),qs(n,s)},Tt=(n,e={})=>{ge(n,e)},wt=(n,e={})=>{const s=Pr(e);console.info("[mobile-storage]",n,s),qs(n,s)},Xa=n=>{if(typeof n!="string")return n;try{return JSON.parse(n)}catch{return n}},Qa=n=>{if(typeof n!="string")return n??void 0;try{return JSON.parse(n)}catch{return n}},Za=async(n,e)=>{if(!Pe())return null;try{const{CapacitorHttp:s}=await xt(async()=>{const{CapacitorHttp:i}=await import("./vendor-capacitor-core-B4EWRrHz.js");return{CapacitorHttp:i}},[]),o=go(n,new Headers(e?.headers)),r=await s.request({url:n,method:e?.method||"GET",headers:Object.fromEntries(o.entries()),data:Qa(e?.body)});return{ok:r.status>=200&&r.status<300,status:r.status,source:"native-http",json:async()=>Xa(r.data)}}catch(s){return ge("native-http:failed",{url:n,error:s instanceof Error?s.message:String(s)}),null}},el=async(n,e)=>{const s=await fetch(n,e).catch(o=>(ge("browser-fetch:failed",{url:n,error:o instanceof Error?o.message:String(o)}),null));return s?{ok:s.ok,status:s.status,source:"browser-fetch",json:()=>s.json()}:null},Je=async(n,e,s)=>{let o;const r=new Promise(i=>{o=window.setTimeout(()=>{s?.(),i(null)},n)});try{return await Promise.race([e,r])}catch{return null}finally{o!==void 0&&window.clearTimeout(o)}},nt=async(n,e,s)=>{const o=s?.totalTimeoutMs??Cr,r=Date.now(),i=await Je(Math.min(Ha,o),Za(n,e));if(i)return i;const c=new AbortController,u=Math.max(500,o-(Date.now()-r));return Je(u,el(n,{...e,signal:c.signal}),()=>c.abort())},os=async n=>{if(!n)return null;const e=await n.json().catch(()=>null);if(!e||typeof e!="object")return null;const s=e;return{authenticated:typeof s.authenticated=="boolean"?s.authenticated:void 0,disabled:typeof s.disabled=="boolean"?s.disabled:void 0,scope:typeof s.scope=="string"?s.scope:void 0}},jt=15e3,tl=async(n,e,s,o=jt,r)=>{const i=sr({relayUrl:n.relayUrl,serverId:n.serverId,hostEncPubJwk:n.hostEncPubJwk}),c=u=>u==="ok"&&r?.keepTunnel?{outcome:u,tunnel:i}:(i.close(),{outcome:u});try{const u=e?{Authorization:`Bearer ${e}`}:void 0,f=await Je(o,i.fetch("/auth/session",{headers:u}).catch(()=>null));if(ge("relay:session",{ok:f?.ok===!0,status:f?.status??null,hasToken:!!e}),!f)return c("unreachable");if(f.status===401)return c(e?"auth-failed":"needs-login");if(!f.ok&&f.status!==404)return c("auth-failed");const a=await os(f);return a&&a.disabled!==!0&&a.authenticated===!1?c(e?"auth-failed":"needs-login"):c("ok")}catch(u){throw i.close(),u}},sl=(n,e,s,o,r)=>{const i=typeof window<"u"?window.location.origin:"",c={relayUrl:n.relayUrl,serverId:n.serverId,hostEncPubJwk:n.hostEncPubJwk,...s?{grant:s}:{}};r&&ho(c,r),ft({apiBaseUrl:i,clientToken:e,runtimeKey:o??Rr(n),relay:c})},nl=n=>{if(!n||typeof n!="object")return null;const e=n;if(e.kind==="direct")return typeof e.url=="string"&&e.url.trim()?{kind:"direct",url:e.url}:null;if(e.kind==="relay"){const s=Js(e.relay);return s?{kind:"relay",relay:s}:null}return null},rl=n=>{if(n.mode==="relay"){const e=Js(n.relay);return e?[{kind:"relay",relay:e}]:[]}return typeof n.url=="string"?Ys(n.url):[]},ot=()=>{if(typeof window>"u")return[];let n;try{n=JSON.parse(window.localStorage.getItem(Zt)||"[]")}catch{return[]}if(!Array.isArray(n))return[];const e=Pe();return n.flatMap(s=>{if(!s||typeof s!="object")return[];const o=s;if(typeof o.id!="string")return[];const r=Array.isArray(o.candidates)?o.candidates.map(nl).filter(f=>!!f):rl(o);if(r.length===0)return[];const i=typeof o.clientToken=="string"&&o.clientToken.trim()?o.clientToken:void 0,c=typeof o.label=="string"&&o.label.trim()?o.label:Yt(qe({candidates:r})),u={id:o.id,label:c,candidates:r,lastUsedAt:typeof o.lastUsedAt=="number"?o.lastUsedAt:0};return e?[{...u,hasToken:!!o.hasToken||!!i}]:[{...u,clientToken:i,hasToken:!!i}]}).sort((s,o)=>o.lastUsedAt-s.lastUsedAt)},ws=n=>n.kind==="relay"?{kind:"relay",relay:{relayUrl:n.relay.relayUrl,serverId:n.relay.serverId,hostEncPubJwk:n.relay.hostEncPubJwk}}:{kind:"direct",url:n.url},Xs=n=>{if(typeof window>"u")return;const e=Pe(),s=n.slice(0,Nr).map(o=>{const r={id:o.id,label:o.label,candidates:o.candidates.map(ws),lastUsedAt:o.lastUsedAt};return e?{...r,hasToken:!!(o.hasToken||o.clientToken)}:{...r,clientToken:o.clientToken}});try{window.localStorage.setItem(Zt,JSON.stringify(s))}catch(o){console.warn("[mobile-storage] failed to persist connection metadata",o)}},Tr=(n,e)=>{const s=n.find(i=>e.id&&i.id===e.id||ts(i.candidates,e.candidates)),o=Pe(),r={id:e.id||s?.id||crypto.randomUUID(),label:e.label,candidates:e.candidates,lastUsedAt:Date.now(),...o?{hasToken:e.hasToken??(!!e.clientToken||s?.hasToken||!1)}:{clientToken:e.clientToken??s?.clientToken,hasToken:!!(e.clientToken??s?.clientToken)}};return[r,...n.filter(i=>i.id!==r.id&&!ts(i.candidates,e.candidates))].slice(0,Nr)},Qs=pa,ol=0,Zs=n=>`${Ga}token.${encodeURIComponent(n)}`,il=async(n,e)=>{let s;const o=new Promise(r=>{s=window.setTimeout(()=>r(e),qa)});try{return await Promise.race([n.catch(()=>e),o])}finally{s!==void 0&&window.clearTimeout(s)}},en=async(n,e,s)=>Pe()?il(e().catch(o=>(console.warn(`[mobile-storage] ${n} failed`,o),s)),s):s,Ft=async n=>{wt("secure:read-start",{key:n});const e=await en("secure:read",async()=>(await Qs.internalGetItem({prefixedKey:Zs(n),sync:!1})).data,null),s=typeof e=="string"&&e.trim()?e:void 0;return wt("secure:read",{key:n,hasToken:!!s}),s},Qe=async(n,e)=>{wt("secure:write-start",{key:n});const s=await en("secure:write",async()=>(await Qs.internalSetItem({prefixedKey:Zs(n),data:e,sync:!1,access:ol}),!0),!1);return wt("secure:write",{key:n,ok:s}),s},al=async n=>{await en("secure:delete",async()=>(await Qs.internalRemoveItem({prefixedKey:Zs(n),sync:!1}),!0),!1)},ll=async(n,e)=>{let s=0,o=0;return{records:await Promise.all(n.map(async i=>{if(!i||typeof i!="object")return i;const c=i,u=typeof c.url=="string"?c.url:null,f=typeof c.clientToken=="string"?c.clientToken.trim():"";if(!u||!f)return i;if(!await e(u,f))return o+=1,i;s+=1;const{clientToken:a,...d}=c;return{...d,hasToken:!0}})),migrated:s,failed:o}},Ar=async()=>{if(typeof window>"u"||!Pe())return;let n;try{n=JSON.parse(window.localStorage.getItem(Zt)||"[]")}catch{return}if(!Array.isArray(n))return;const e=n.filter(o=>!!o&&typeof o=="object"&&typeof o.url=="string"&&typeof o.clientToken=="string"&&!!o.clientToken.trim());if(e.length===0)return;wt("secure:migrate-start",{count:e.length});const s=await ll(n,async(o,r)=>{const i=vt(o);return await Qe(i,r)?await Ft(i)===r:!1});if(s.migrated>0)try{window.localStorage.setItem(Zt,JSON.stringify(s.records))}catch(o){console.warn("[mobile-storage] failed to finalize secure token migration",o);return}wt("secure:migrate-done",{migrated:s.migrated,failed:s.failed})},cl=async()=>(await Ar(),ot()),ss=async n=>{const e=Tr(ot(),n);return Xs(e),Pe()&&n.clientToken&&await Qe(Re({candidates:n.candidates}),n.clientToken),e},ul=async n=>{const e=ot(),s=e.find(r=>r.id===n)??null,o=e.filter(r=>r.id!==n);return Xs(o),s&&Pe()&&await al(Re(s)),o},dl=1500,ns=async(n,e,s)=>{const o=s?.fast?{totalTimeoutMs:es}:void 0,r=st({candidates:n})?.serverId??null,i=n.find(a=>a.kind==="relay")??null,c=n.filter(a=>a.kind==="direct"),u=async()=>{for(const a of c){const d=St(a.url)||a.url,p=e?{Authorization:`Bearer ${e}`}:void 0,g=await nt(`${d}/health`,{method:"GET"},o);if(ge("probe:direct:health",{url:d,ok:g?.ok===!0,status:g?.status??null,source:g?.source??null}),!g?.ok)continue;if(r){const y=await g.json().catch(()=>null),A=y&&typeof y=="object"?y.serverId:null;if(typeof A=="string"&&A&&A!==r){ge("probe:server-id-mismatch",{url:d});continue}}const h=await nt(`${d}/auth/session`,{method:"GET",credentials:e?"omit":"include",headers:p},o);if(ge("probe:direct:session",{url:d,ok:h?.ok===!0,status:h?.status??null,source:h?.source??null,hasToken:!!e}),h?.status===401)return{status:"needs-login"};if(!h||!h.ok&&h.status!==404)continue;const b=await os(h);if(b&&b.disabled!==!0&&b.authenticated===!1)return{status:"needs-login"};const j=b?.disabled===!0;return!e&&Pe()&&!j&&b?.scope!=="client"?{status:"needs-login"}:{status:"ok",transport:{kind:"direct",url:d}}}return{status:"unreachable"}},f=async()=>{if(!i)return{status:"unreachable"};const{outcome:a,tunnel:d}=await tl(i.relay,e,void 0,s?.fast?es:Cr,{keepTunnel:!0});return a==="ok"?{status:"ok",transport:{kind:"relay",relay:i.relay,tunnel:d}}:a==="needs-login"||a==="auth-failed"?{status:"needs-login"}:{status:"unreachable"}};return i?c.length===0?f():new Promise(a=>{let d=!1,p=!1,g,h=null,b=null;const j=S=>{S?.status==="ok"&&S.transport.kind==="relay"&&S.transport.tunnel?.close()},y=S=>{d||(d=!0,a(S))},A=()=>{p||d||(g!==void 0&&(window.clearTimeout(g),g=void 0),f().then(S=>{if(b=S,d||p){j(S);return}if(S.status==="ok"||S.status==="needs-login"){y(S);return}h&&y(h)}))};u().then(S=>{if(h=S,!d){if(S.status==="ok"||S.status==="needs-login"){p=!0,g!==void 0&&window.clearTimeout(g),j(b),y(S);return}if(b){y(b);return}A()}}),g=window.setTimeout(A,dl)}):u()},Ze=(n,e,s)=>{n.kind==="relay"?sl(n.relay,e,s?.grant,s?.runtimeKey,n.tunnel):ft({apiBaseUrl:n.url,clientToken:e,runtimeKey:s?.runtimeKey}),_r()},_t=()=>{const n=ot()[0];return n?.label?.trim()?n.label:null},At=async n=>{const e=n?.fast!==!1;await Ar();const s=ot()[0];if(ge("auto-connect:start",{hasCandidate:!!s,fast:e}),!s)return{status:"no-candidate"};let o;if(Pe()){if(s.hasToken&&(o=await Ft(Re(s)),!o))return{status:"no-candidate"}}else if(o=s.clientToken,!o&&s.hasToken)return{status:"no-candidate"};const r=await ns(s.candidates,o,{fast:e});return ge("auto-connect:probe",{status:r.status,candidates:s.candidates.map(i=>i.kind)}),r.status==="needs-login"?{status:"needs-login",label:s.label}:r.status!=="ok"?{status:"unreachable",label:s.label}:n?.skipIfConnected&&Ke()?(r.transport.kind==="relay"&&r.transport.tunnel?.close(),ge("auto-connect:superseded",{}),{status:"no-candidate"}):(await ss({id:s.id,label:s.label,candidates:s.candidates}),Ze(r.transport,o??null,{runtimeKey:Re(s)}),{status:"connected"})},fl=async(n,e)=>{let s="";try{s=St(n.url)}catch{return!1}if(!s)return!1;const o=n.clientToken?.trim()||void 0,r=o?{Authorization:`Bearer ${o}`}:void 0,i=e?.fast?{totalTimeoutMs:es}:void 0;if(!(await nt(`${s}/health`,{method:"GET",headers:r},i))?.ok)return!1;const u=await nt(`${s}/auth/session`,{method:"GET",credentials:o?"omit":"include",headers:r},i);if(!u||!u.ok&&u.status!==404)return!1;const f=await os(u);return!(f&&f.disabled!==!0&&f.authenticated===!1)},ml=n=>[...n].sort((e,s)=>{const o=(e.priority??100)-(s.priority??100);if(o!==0)return o;const r=i=>i.type==="relay"?2:i.url.startsWith("https://")?0:1;return r(e)-r(s)}).flatMap(e=>{if(e.type==="relay"){const s=Js({relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:e.hostEncPubJwk});return s?[{kind:"relay",relay:s}]:[]}return Ys(e.url)}),An=async n=>{const e=st({candidates:n})?.serverId??null;for(const s of n){if(s.kind==="relay"){const i=sr(s.relay),c=await Je(jt,i.fetch("/health").catch(()=>null));if(ge("establish:relay:health",{ok:c?.ok===!0,status:c?.status??null}),c?.ok)return{kind:"relay",relay:s.relay,tunnel:i};i.close();continue}const o=St(s.url)||s.url,r=await nt(`${o}/health`,{method:"GET"});if(ge("establish:direct:health",{ok:r?.ok===!0,status:r?.status??null}),!!r?.ok){if(e){const i=await r.json().catch(()=>null),c=i&&typeof i=="object"?i.serverId:null;if(typeof c=="string"&&c&&c!==e){ge("establish:server-id-mismatch",{url:o});continue}}return{kind:"direct",url:o}}}return null},pl=async(n,e)=>{if(!$t())return fl(n,e);const s=await Je(e?.fast?es:jt,Cs("/auth/session").then(r=>r).catch(()=>null));if(!s)return!0;if(s.status===401)return!1;if(!s.ok&&s.status!==404)return!0;const o=await os(s);return!(o&&o.disabled!==!0&&o.authenticated===!1)},hl=n=>n.kind==="relay"?$t():!$t()&&Er(n.url,Ke()),Ir=()=>{const n=kt();return n?ot().find(e=>Re(e)===n)??null:null},In=n=>{const e=kt();return!!e&&Re(n)===e},Jt=async n=>{const e=n?.fast!==!1,s=Ir();if(!s)return ge("reprobe:no-connection",{runtimeKey:!!kt()}),"no-connection";let o;if(Pe()?o=s.hasToken?await Ft(Re(s)):void 0:o=s.clientToken,!o&&s.hasToken)return ge("reprobe:no-token",{hasToken:!0}),"unreachable";ge("reprobe:start",{candidates:s.candidates.map(a=>a.kind),fast:e,hasToken:!!o});const r=s.candidates.findIndex(a=>hl(a.kind==="relay"?{kind:"relay",relay:a.relay}:{kind:"direct",url:a.url})),i=r>=0?s.candidates.slice(0,r):s.candidates,c=await ns(i,o,{fast:e});if(ge("reprobe:better",{status:c.status,probed:i.length}),c.status==="ok")return await ss({id:s.id,label:s.label,candidates:s.candidates}),Ze(c.transport,o??null,{runtimeKey:Re(s)}),"switched";if(c.status==="needs-login")return"needs-login";if(r>=0){const a=await pl({url:Ke(),clientToken:o},{fast:e});if(ge("reprobe:current",{stillValid:a}),a)return _r(),"unchanged"}const u=r>=0?s.candidates.slice(r+1):[],f=await ns(u,o,{fast:e});return ge("reprobe:fallback",{status:f.status,probed:u.length}),f.status==="ok"?(await ss({id:s.id,label:s.label,candidates:s.candidates}),Ze(f.transport,o??null,{runtimeKey:Re(s)}),"switched"):f.status==="needs-login"?"needs-login":"unreachable"},gl=5e3;let fs=!1;const bl=async()=>{if(fs)return"skipped";const n=Ir();if(!n)return ge("candidates:refresh-skip",{reason:"no-active-connection"}),"skipped";const e=st(n);if(!e)return ge("candidates:refresh-skip",{reason:"no-relay-candidate"}),"skipped";fs=!0;try{const s=await Je(jt,Cs("/api/client-auth/connection/candidates").then(a=>a).catch(()=>null));if(!s?.ok)return ge("candidates:refresh-skip",{reason:"fetch-failed",status:s?.status??null}),"skipped";const o=await s.json().catch(()=>null);if(!o||o.serverId!==e.serverId)return ge("candidates:refresh-skip",{reason:"server-id-mismatch"}),"skipped";const r=Array.isArray(o.candidates)?o.candidates:[],i=[];for(const a of r){if(!a||typeof a!="object")continue;const d=a;if(!(d.type!=="lan"||typeof d.url!="string"))try{const p=St(d.url);p&&!i.includes(p)&&i.push(p)}catch{}}if(i.length===0)return ge("candidates:refresh-skip",{reason:"no-lan-reported"}),"skipped";const c=rs(n).filter(a=>a.url.startsWith("https://")),u=[...i.map(a=>({kind:"direct",url:a})),...c,{kind:"relay",relay:e}];return JSON.stringify(n.candidates.map(ws))===JSON.stringify(u.map(ws))?"unchanged":(ge("candidates:refreshed",{lanCount:i.length}),await ss({id:n.id,label:n.label,candidates:u}),"updated")}finally{fs=!1}},_r=()=>{typeof window>"u"||window.setTimeout(()=>{(async()=>{const n=await bl().catch(()=>"skipped");ge("candidates:refresh-result",{result:n}),n==="updated"&&$t()&&await Jt().catch(()=>null)})()},gl)},Dr=n=>{const{t:e}=de(),[s,o]=l.useState(()=>ot()),[r,i]=l.useState(null),[c,u]=l.useState(null),[f,a]=l.useState(null),d=l.useRef(s),p=l.useRef(null),g=l.useRef(Ya()),h=l.useCallback(w=>{d.current=w,o(w)},[]),b=l.useCallback(w=>{p.current=w,i(w)},[]),j=l.useCallback(w=>{p.current===w&&(p.current=null,i(null))},[]);l.useEffect(()=>{let w=!1;return cl().then(P=>{w||h(P)}),()=>{w=!0}},[h]);const y=l.useCallback(w=>{const P=Tr(d.current,w);return h(P),Xs(P),P},[h]),A=l.useCallback(async w=>{u(null),b("connect");try{const P=Tn(w);if(P.length===0){u(e("mobile.connect.error.urlRequired"));return}const x=w.id?d.current.find(F=>F.id===w.id):d.current.find(F=>ts(F.candidates,P)),_=w.label?.trim()||x?.label||Yt(qe({candidates:P})),D=w.relayGrant;let C=w.clientToken?.trim()||void 0;const R=!!C;C||(Pe()?x?.hasToken&&(C=await Ft(Re({candidates:P}))):C=x?.clientToken),ge("connect:start",{candidates:P.map(F=>F.kind),hasToken:!!C});const B=await ns(P,C);if(ge("connect:probe",{status:B.status}),B.status==="unreachable"){u(e("mobile.connect.error.unreachable"));return}if(B.status==="needs-login"){y({id:x?.id,label:_,candidates:P}),a({id:x?.id??crypto.randomUUID(),label:_,candidates:P,relay:st({candidates:P})??void 0,relayGrant:D});return}C&&R&&Pe()&&await Qe(Re({candidates:P}),C),y({id:x?.id,label:_,candidates:P,clientToken:C}),Ze(B.transport,C??null,{runtimeKey:Re({candidates:P}),grant:D}),n()}catch(P){console.warn("[mobile-connect] connect threw",P),u(e("mobile.connect.error.invalidUrl"))}finally{j("connect")}},[b,j,n,y,e]),S=l.useCallback(async w=>{if(p.current==="pairing")return;u(null),b("pairing");const P=ml(w.candidates);let x=null,_=!1;try{if(x=await An(P),!x){u(e("mobile.connect.error.unreachable"));return}const D=JSON.stringify({pairingId:w.pairingId,secret:w.secret,clientLabel:"AiWorker Mobile",clientKind:"mobile",deviceName:"AiWorker Mobile",devicePlatform:Pn(),dedupeKey:Rn()}),C={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:D},R=x.kind==="relay"?await Je(jt,x.tunnel.fetch("/api/client-auth/pairing/redeem",C).catch(()=>null)):await nt(`${x.url}/api/client-auth/pairing/redeem`,C);if(!R?.ok){u(e("mobile.connect.error.authRequired"));return}const B=await R.json().catch(()=>null),F=typeof B?.clientToken=="string"?B.clientToken.trim():"";if(!F){u(e("mobile.connect.error.authRequired"));return}const v=typeof B?.server?.label=="string"?B.server.label:"",I=w.label||v||Yt(qe({candidates:P}));if(Pe()&&!await Qe(Re({candidates:P}),F)){u(e("mobile.connect.error.authRequired"));return}y({label:I,candidates:P,clientToken:F}),Ze(x.kind==="relay"?{kind:"relay",relay:x.relay,tunnel:x.tunnel}:{kind:"direct",url:x.url},F,{runtimeKey:Re({candidates:P})}),_=x.kind==="relay",n()}catch(D){console.warn("[mobile-connect] pairing threw",D),u(e("mobile.connect.error.authRequired"))}finally{!_&&x?.kind==="relay"&&x.tunnel.close(),j("pairing")}},[b,j,n,y,e]),E=l.useCallback(async w=>{if(!f||!w.trim()||p.current==="password")return;u(null),b("password");const P=g.current.begin(),x=()=>g.current.isCurrent(P),{id:_,label:D,candidates:C}=f;let R=null,B=!1;try{if(R=await An(C),!x())return;if(!R){u(e("mobile.connect.error.unreachable"));return}const F={method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({password:w,trustDevice:!0,issueClientToken:!0,clientLabel:"AiWorker Mobile",clientKind:"mobile",devicePlatform:Pn(),dedupeKey:Rn()})};ge("password:start",{transport:R.kind});const v=R.kind==="relay"?await Je(jt,R.tunnel.fetch("/auth/session",F).catch(()=>null)):await nt(`${R.url}/auth/session`,F);if(!x())return;if(ge("password:done",{ok:v?.ok===!0,status:v?.status??null}),!v?.ok){u(e("mobile.connect.error.passwordFailed"));return}const I=await v.json().catch(()=>null);if(!x())return;const $=typeof I?.clientToken=="string"?I.clientToken.trim():"";if(ge("password:token",{issued:!!$}),!$){if(R.kind==="direct"&&!Pe()){y({id:_,label:D,candidates:C}),a(null),Ze({kind:"direct",url:R.url},null,{runtimeKey:Re({candidates:C})}),n();return}u(e("mobile.connect.error.authRequired"));return}if(Pe()&&(!x()||(await Qe(Re({candidates:C}),$),!x()))||!x()||(y({id:_,label:D,candidates:C,clientToken:$}),a(null),Ze(R.kind==="relay"?{kind:"relay",relay:R.relay,tunnel:R.tunnel}:{kind:"direct",url:R.url},$,{runtimeKey:Re({candidates:C})}),B=R.kind==="relay",!x()))return;n()}catch(F){if(!x())return;console.warn("[mobile-connect] password threw",F),u(e("mobile.connect.error.passwordFailed"))}finally{!B&&R?.kind==="relay"&&R.tunnel.close(),x()&&j("password")}},[b,j,n,f,y,e]),T=l.useCallback(()=>{g.current.cancel(),j("password"),a(null),u(null)},[j]),k=l.useCallback(async w=>{u(null);let P=Tn(w);const x=w.id?d.current.find(R=>R.id===w.id)??null:null;if(x){const R=P.filter(v=>v.kind==="direct"),B=rs(x).filter(v=>v.url.startsWith("https://")&&!R.some(I=>Er(I.url,v.url))),F=st(x);P=[...R,...B,...F?[{kind:"relay",relay:F}]:[]]}if(P.length===0)return u(e("mobile.connect.error.urlRequired")),null;const _=w.clientToken?.trim()||void 0,D=w.label?.trim()||Yt(qe({candidates:P}));if(Pe()){const R=Re({candidates:P});if(_)await Qe(R,_);else if(x?.hasToken){const B=Re(x);if(B&&R&&B!==R){const F=await Ft(B);F&&await Qe(R,F)}}}return y({id:w.id,label:D,candidates:P,clientToken:_}).find(R=>ts(R.candidates,P))??null},[y,e]),N=l.useCallback(async w=>{const P=d.current.find(_=>_.id===w)??null,x=await ul(w);return h(x),P},[h]);return{connections:s,isBusy:r!==null,isPasswordBusy:r==="password",error:c,pendingConnection:f,connect:A,redeemPairingConnection:S,submitPassword:E,cancelPassword:T,saveConnection:k,removeConnection:N,setError:u}},Mr=n=>{const e=ce.c(31),{onClose:s}=n,{t:o}=de(),[r,i]=l.useState(!1);let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=Wa(),e[0]=c):c=e[0];const u=c;let f;e[1]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{Co(Va()).then(w=>{w.ok&&(i(!0),window.setTimeout(()=>i(!1),2e3))})},e[1]=f):f=e[1];const a=f;let d;e[2]!==o?(d=o("mobile.connectionDebug.title"),e[2]=o,e[3]=d):d=e[3];let p;e[4]!==d?(p=t.jsx("h2",{className:"min-w-0 truncate typography-ui-label text-foreground",children:d}),e[4]=d,e[5]=p):p=e[5];const g=r?"check":"file-copy";let h;e[6]!==g?(h=t.jsx(ee,{name:g,className:"size-4"}),e[6]=g,e[7]=h):h=e[7];let b;e[8]!==r||e[9]!==o?(b=o(r?"mobile.connectionDebug.copied":"mobile.connectionDebug.copy"),e[8]=r,e[9]=o,e[10]=b):b=e[10];let j;e[11]!==h||e[12]!==b?(j=t.jsxs(ye,{type:"button",variant:"outline",size:"sm",onClick:a,disabled:u.length===0,children:[h,b]}),e[11]=h,e[12]=b,e[13]=j):j=e[13];let y;e[14]!==o?(y=o("mobile.connectionDebug.close"),e[14]=o,e[15]=y):y=e[15];let A;e[16]===Symbol.for("react.memo_cache_sentinel")?(A=t.jsx(ee,{name:"close",className:"size-[18px]"}),e[16]=A):A=e[16];let S;e[17]!==s||e[18]!==y?(S=t.jsx(ye,{type:"button",variant:"ghost",size:"icon","aria-label":y,onClick:s,children:A}),e[17]=s,e[18]=y,e[19]=S):S=e[19];let E;e[20]!==S||e[21]!==j?(E=t.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[j,S]}),e[20]=S,e[21]=j,e[22]=E):E=e[22];let T;e[23]!==E||e[24]!==p?(T=t.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-border/70 px-4 py-2.5",children:[p,E]}),e[23]=E,e[24]=p,e[25]=T):T=e[25];let k;e[26]!==o?(k=t.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-4 py-3",children:u.length===0?t.jsx("p",{className:"typography-small text-muted-foreground",children:o("mobile.connectionDebug.empty")}):t.jsx("pre",{className:"whitespace-pre-wrap break-words typography-code text-muted-foreground",children:u.map(kr).join(`
4
- `)})}),e[26]=o,e[27]=k):k=e[27];let N;return e[28]!==T||e[29]!==k?(N=t.jsxs("div",{className:"fixed inset-0 z-[70] flex flex-col bg-background pb-[var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))] pt-[var(--safe-area-inset-top,env(safe-area-inset-top,0px))] text-foreground",children:[T,k]}),e[28]=T,e[29]=k,e[30]=N):N=e[30],N},zr=()=>{if(typeof window>"u")return null;const e=window.Capacitor?.Plugins?.BarcodeScanner;return e&&(typeof e.scan=="function"||typeof e.startScan=="function")?e:null},xl=()=>window.Capacitor?.getPlatform?.()==="android",Or=n=>{const e=n.trim();if(!e)return null;if(/^aiworker:\/\//i.test(e)){const s=bo(e);return s?{pairing:s}:null}return/^https?:\/\//i.test(e)?{url:e}:null},Lr=(n,e)=>{const s=Or(n);if(!s&&e?.pairingStringFallback){const o=xo(n);if(o)return{status:"pairing",pairing:o}}return s?"pairing"in s?{status:"pairing",...s}:{status:"ok",...s}:{status:"invalid"}},yl=async(n,e)=>{if(!n.startScan||!n.stopScan||!n.addListener)return{status:"unsupported"};if(e?.aborted)return{status:"cancelled"};let s,o,r=!1,i=()=>{};const c=new Promise(a=>{i=a}),u=a=>{r||(r=!0,i(a))},f=()=>u({status:"cancelled"});e?.addEventListener("abort",f,{once:!0});try{return(await Promise.allSettled([Promise.resolve(n.addListener("barcodesScanned",({barcodes:d})=>{const p=d?.[0],g=(p?.rawValue??p?.displayValue??"").trim();g&&u(Lr(g,{pairingStringFallback:!0}))})).then(d=>{s=d}),Promise.resolve(n.addListener("scanError",()=>u({status:"failed"}))).then(d=>{o=d})])).some(({status:d})=>d==="rejected")?u({status:"failed"}):r||n.startScan({formats:["QR_CODE"]}).catch(()=>u({status:"failed"})),await c}finally{e?.removeEventListener("abort",f),await Promise.allSettled([Promise.resolve(s?.remove()),Promise.resolve(o?.remove()),n.stopScan()])}},js=()=>zr()!==null,Br=async n=>{const e=zr();if(!e)return{status:"unsupported"};try{if(e.requestPermissions){const c=(await e.requestPermissions())?.camera;if(c&&c!=="granted"&&c!=="limited")return{status:"permission-denied"}}if(n?.signal?.aborted)return{status:"cancelled"};if(xl())return yl(e,n?.signal);if(!e.scan)return{status:"unsupported"};const o=(await e.scan({formats:["QR_CODE"]}))?.barcodes?.[0],r=(o?.rawValue??o?.displayValue??"").trim();return r?Lr(r):{status:"cancelled"}}catch{return{status:"failed"}}},gt={autoComplete:"off",autoCorrect:"off",spellCheck:!1},Dt="h-12 w-full rounded-[16px] border border-border/70 bg-surface-elevated px-4 text-[16px] text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-primary focus:ring-2 focus:ring-primary/20",$r=n=>{const e=ce.c(22),{onCancel:s}=n,{t:o}=de(),r=l.useRef(null);let i,c;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=()=>{const A={value:document.documentElement.style.getPropertyValue("background-color"),priority:document.documentElement.style.getPropertyPriority("background-color")},S={value:document.body.style.getPropertyValue("background-color"),priority:document.body.style.getPropertyPriority("background-color")};document.documentElement.style.setProperty("background-color","rgba(0, 0, 0, 0)","important"),document.body.style.setProperty("background-color","rgba(0, 0, 0, 0)","important");const E=new Map,T=N=>{!(N instanceof HTMLElement)||N===r.current||E.has(N)||(E.set(N,{opacity:N.style.opacity,pointerEvents:N.style.pointerEvents}),N.style.setProperty("opacity","0"),N.style.setProperty("pointer-events","none"))};Array.from(document.body.children).forEach(T);const k=new MutationObserver(N=>{N.forEach(w=>w.addedNodes.forEach(T))});return k.observe(document.body,{childList:!0}),()=>{k.disconnect(),E.forEach(vl),A.value?document.documentElement.style.setProperty("background-color",A.value,A.priority):document.documentElement.style.removeProperty("background-color"),S.value?document.body.style.setProperty("background-color",S.value,S.priority):document.body.style.removeProperty("background-color")}},c=[],e[0]=i,e[1]=c):(i=e[0],c=e[1]),l.useLayoutEffect(i,c);let u,f;e[2]!==s?(u=()=>{const A=()=>{document.visibilityState==="hidden"&&s()};return document.addEventListener("visibilitychange",A),()=>document.removeEventListener("visibilitychange",A)},f=[s],e[2]=s,e[3]=u,e[4]=f):(u=e[3],f=e[4]),l.useEffect(u,f);let a;e[5]!==o?(a=o("mobile.connect.scanQr"),e[5]=o,e[6]=a):a=e[6];let d;e[7]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx("div",{className:"aspect-square w-full max-w-72 rounded-[28px] border-2 border-foreground/90 shadow-[0_0_0_9999px_color-mix(in_srgb,var(--surface-background)_18%,transparent)]","aria-hidden":!0}),e[7]=d):d=e[7];let p;e[8]!==o?(p=o("mobile.connect.welcome.scanHint"),e[8]=o,e[9]=p):p=e[9];let g;e[10]!==p?(g=t.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-6",children:[d,t.jsx("p",{className:"max-w-sm rounded-[16px] border border-border/60 bg-background px-4 py-3 text-center typography-body text-foreground shadow-sm",children:p})]}),e[10]=p,e[11]=g):g=e[11];let h;e[12]===Symbol.for("react.memo_cache_sentinel")?(h=t.jsx(ee,{name:"close",className:"size-[18px]"}),e[12]=h):h=e[12];let b;e[13]!==o?(b=o("mobile.instances.cancelEdit"),e[13]=o,e[14]=b):b=e[14];let j;e[15]!==s||e[16]!==b?(j=t.jsxs(ye,{type:"button",variant:"outline",size:"lg",className:"mx-auto min-h-12 w-full max-w-sm bg-background",onClick:s,children:[h,b]}),e[15]=s,e[16]=b,e[17]=j):j=e[17];let y;return e[18]!==j||e[19]!==a||e[20]!==g?(y=bt.createPortal(t.jsxs("div",{ref:r,role:"dialog","aria-modal":"true","aria-label":a,className:"fixed inset-0 z-[1000] flex flex-col bg-transparent px-6 pb-[calc(var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))+24px)] pt-[calc(var(--safe-area-inset-top,env(safe-area-inset-top,0px))+24px)] text-foreground",children:[g,j]}),document.body),e[18]=j,e[19]=a,e[20]=g,e[21]=y):y=e[21],y},Fr=()=>{const n=ce.c(6),{t:e}=de();let s;n[0]===Symbol.for("react.memo_cache_sentinel")?(s=t.jsx(Xe,{width:96,height:96,isAnimated:!0}),n[0]=s):s=n[0];let o;n[1]===Symbol.for("react.memo_cache_sentinel")?(o=t.jsx(ee,{name:"loader-4",className:"size-[18px] animate-spin"}),n[1]=o):o=n[1];let r;n[2]!==e?(r=e("mobile.connect.connecting"),n[2]=e,n[3]=r):r=n[3];let i;return n[4]!==r?(i=bt.createPortal(t.jsxs("div",{role:"status",className:"fixed inset-0 z-[1000] flex flex-col items-center justify-center gap-5 bg-background px-6 text-foreground",children:[s,t.jsxs("div",{className:"flex items-center gap-2 typography-ui-label text-muted-foreground",children:[o,t.jsx("span",{children:r})]})]}),document.body),n[4]=r,n[5]=i):i=n[5],i};function vl(n,e){e.style.opacity=n.opacity,e.style.pointerEvents=n.pointerEvents}const wl=({onConnected:n,notice:e=null})=>{const{t:s}=de(),o=Dr(n),{connections:r,isBusy:i,isPasswordBusy:c,error:u,pendingConnection:f}=o,[a,d]=l.useState(""),[p,g]=l.useState(""),[h,b]=l.useState(""),[j,y]=l.useState(!1),[A,S]=l.useState(!1),E=l.useRef(null),T=l.useMemo(()=>js(),[]),[k,N]=l.useState(()=>!js()),[w,P]=l.useState(null),[x,_]=l.useState(""),[D,C]=l.useState(!1),R=Sr(l.useCallback(()=>C(!0),[])),B=l.useCallback(z=>{z.preventDefault(),o.connect({url:a,clientToken:h,label:p})},[h,o,p,a]),F=l.useCallback(z=>{if(/^aiworker:\/\//i.test(z.trim())){const O=Or(z);if(O){if("pairing"in O){o.redeemPairingConnection(O.pairing);return}d(O.url),O.label&&g(O.label),O.clientToken&&b(O.clientToken);return}}d(z)},[o]),v=l.useCallback(async()=>{if(E.current||i)return;o.setError(null),y(!0);const z=new AbortController;E.current=z;try{const O=await Br({signal:z.signal});switch(E.current===z&&(E.current=null,y(!1)),O.status){case"ok":S(!0),d(O.url),O.label&&g(O.label),O.clientToken&&b(O.clientToken),await o.connect({url:O.url,clientToken:O.clientToken,label:O.label});break;case"pairing":S(!0),await o.redeemPairingConnection(O.pairing);break;case"permission-denied":o.setError(s("mobile.connect.scan.permissionDenied"));break;case"invalid":o.setError(s("mobile.connect.scan.invalid"));break;case"unsupported":o.setError(s("mobile.connect.scan.unsupported"));break;case"failed":o.setError(s("mobile.connect.scan.failed"));break;default:break}}finally{S(!1),E.current===z&&(E.current=null,y(!1))}},[o,i,s]);l.useEffect(()=>()=>E.current?.abort(),[]);const I=l.useCallback(z=>{z.preventDefault(),o.submitPassword(x)},[o,x]),$=l.useCallback(()=>{_(""),o.cancelPassword()},[o]);return t.jsxs(t.Fragment,{children:[j?t.jsx($r,{onCancel:()=>E.current?.abort()}):null,A?t.jsx(Fr,{}):null,D?t.jsx(Mr,{onClose:()=>C(!1)}):null,t.jsx("main",{className:"oc-keyboard-fill-screen flex min-h-dvh flex-col overflow-y-auto bg-background px-6 pb-[calc(var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))+28px)] pt-[calc(var(--safe-area-inset-top,env(safe-area-inset-top,0px))+28px)] text-foreground",children:t.jsxs("div",{className:"m-auto flex w-full max-w-[360px] shrink-0 flex-col items-center gap-9 py-8",children:[t.jsxs("div",{className:"flex flex-col items-center gap-5 text-center",children:[t.jsx("span",{...R,className:"select-none",style:{touchAction:"manipulation"},children:t.jsx(Xe,{width:72,height:72,className:"size-[72px]"})}),t.jsx("h1",{className:"typography-h2 text-foreground",children:s("mobile.connect.welcome.title")})]}),e?t.jsxs("div",{role:"status",className:"flex w-full items-center gap-3 rounded-[18px] border border-[color-mix(in_srgb,var(--status-warning)_35%,transparent)] bg-[color-mix(in_srgb,var(--status-warning)_10%,transparent)] px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-[color-mix(in_srgb,var(--status-warning)_16%,transparent)] text-[var(--status-warning)]",children:t.jsx(ee,{name:e.kind==="auth-expired"?"lock":"cloud-off",className:"size-[18px]"})}),t.jsx("p",{className:"min-w-0 flex-1 typography-small text-foreground",children:e.kind==="auth-expired"?s("mobile.connect.notice.authExpired",{label:e.label}):s("mobile.connect.notice.unreachable",{label:e.label})})]}):null,f?t.jsxs("form",{className:"flex w-full flex-col gap-3",onSubmit:I,children:[t.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(ee,{name:"lock",className:"size-[18px]"})}),t.jsxs("div",{className:"min-w-0 text-left",children:[t.jsx("p",{className:"truncate typography-ui-label text-foreground",children:f.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:f.candidates.some(z=>z.kind==="direct")?qe(f):s("mobile.connect.relay.badge")})]})]}),t.jsx("input",{...gt,value:x,onChange:z=>_(z.target.value),placeholder:s("mobile.connect.password.placeholder"),"aria-label":s("mobile.connect.password.label"),type:"password",autoFocus:!0,className:Dt}),u?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:u}):null,t.jsx(ye,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:c||!x.trim(),children:s(c?"mobile.connect.connecting":"mobile.connect.unlockButton")}),t.jsx(ye,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:$,children:s("mobile.connect.cancelPassword")})]}):t.jsxs("div",{className:"flex w-full flex-col gap-6",children:[T?t.jsxs("div",{className:"flex w-full flex-col gap-2",children:[t.jsxs(ye,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{v()},disabled:j||i,children:[t.jsx(ee,{name:"scan-2",className:J("size-[18px]",j&&"animate-pulse")}),s(i?"mobile.connect.connecting":"mobile.connect.scanQr")]}),t.jsx("p",{className:"px-2 text-center typography-small text-muted-foreground",children:s("mobile.connect.welcome.scanHint")})]}):null,u&&!k?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:u}):null,r.length>0?t.jsxs("section",{className:"flex w-full flex-col gap-2.5",children:[t.jsx("h2",{className:"text-center typography-micro uppercase tracking-[0.14em] text-muted-foreground",children:s("mobile.connect.saved.title")}),t.jsx("div",{className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map(z=>{const O=w===z.id;return t.jsxs("button",{type:"button",disabled:i,className:"flex min-h-14 w-full items-center gap-3 border-b border-border/70 px-3.5 py-2.5 text-left last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary disabled:opacity-70",onClick:()=>{P(z.id),o.connect({id:z.id,candidates:z.candidates,clientToken:z.clientToken,label:z.label}).finally(()=>P(null))},children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(ee,{name:"server",className:"size-[18px]"})}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:z.label}),t.jsx("span",{className:J("block truncate typography-small",O?"text-foreground":"text-muted-foreground"),children:O?s("mobile.connect.connecting"):z.candidates.some(te=>te.kind==="direct")?qe(z):s("mobile.connect.relay.badge")})]}),O?t.jsx(ee,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):t.jsx(ee,{name:"arrow-right-s",className:"size-5 text-muted-foreground"})]},z.id)})})]}):null,t.jsxs("div",{className:"flex w-full flex-col",children:[T?t.jsxs("button",{type:"button",onClick:()=>N(z=>!z),"aria-expanded":k,className:"mx-auto flex items-center gap-1 rounded-full px-2 py-1 typography-small text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:[t.jsx("span",{children:s("mobile.connect.manual.toggle")}),t.jsx(ee,{name:"arrow-down-s",className:J("size-4 transition-transform duration-200",k&&"rotate-180")})]}):null,t.jsx("div",{className:"grid transition-[grid-template-rows] duration-200 ease-out",style:{gridTemplateRows:k?"1fr":"0fr"},children:t.jsx("div",{className:"min-h-0 overflow-hidden",children:t.jsxs("form",{className:"flex w-full flex-col gap-3 pt-3",onSubmit:B,children:[t.jsx("input",{...gt,value:a,onChange:z=>F(z.target.value),placeholder:s("mobile.connect.url.placeholder"),"aria-label":s("mobile.connect.url.label"),type:"url",inputMode:"url",autoCapitalize:"none",tabIndex:k?void 0:-1,className:J(Dt,"text-center")}),t.jsx("input",{value:p,onChange:z=>g(z.target.value),placeholder:s("mobile.instances.label.placeholder"),"aria-label":s("mobile.instances.label.label"),autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,tabIndex:k?void 0:-1,className:J(Dt,"text-center")}),t.jsx("input",{...gt,value:h,onChange:z=>b(z.target.value),placeholder:s("mobile.connect.token.placeholder"),"aria-label":s("mobile.connect.token.label"),tabIndex:k?void 0:-1,autoCapitalize:"none",className:J(Dt,"text-center")}),t.jsx("p",{className:"px-1 text-center typography-micro text-muted-foreground",children:s("mobile.connect.token.hint")}),u?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:u}):null,t.jsx(ye,{type:"submit",variant:T?"outline":"default",size:"lg",className:"h-12 w-full",disabled:i||j||!a.trim(),children:s(i?"mobile.connect.connecting":"mobile.connect.connectButton")})]})})})]})]})]})})]})},jl=n=>{const e=n.usedPercent;return typeof e!="number"||!Number.isFinite(e)?"text-foreground":e>=80?"text-[var(--status-error)]":e>=50?"text-[var(--status-warning)]":"text-foreground"},kl=n=>{const e=ce.c(12),{groups:s,displayMode:o,timeFormatPreference:r,className:i}=n;let c;e[0]!==i?(c=J("space-y-1.5",i),e[0]=i,e[1]=c):c=e[1];let u;if(e[2]!==o||e[3]!==s||e[4]!==r){let a;e[6]!==o||e[7]!==r?(a=d=>t.jsxs("div",{className:"min-w-0 rounded-xl bg-[var(--surface-muted)] p-2.5",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx(Eo,{providerId:d.providerId,className:"size-4 shrink-0"}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium text-foreground",children:d.providerName}),d.planLabel?t.jsx("span",{className:"shrink-0 typography-micro capitalize text-muted-foreground",children:d.planLabel}):null,d.status&&d.rows.length===0?t.jsx("span",{className:"shrink-0 truncate typography-micro text-muted-foreground",children:d.status}):null]}),d.rows.length>0?t.jsx("div",{className:"mt-1.5 space-y-1",children:d.rows.map(p=>{const g=o==="remaining"?p.window.remainingPercent:p.window.usedPercent,h=Ro(p.window.valueLabel,g),b=Po(p.window.resetAt,p.window.resetAfterFormatted??p.window.resetAtFormatted,r);return t.jsxs("div",{className:"flex min-w-0 items-baseline justify-between gap-3",children:[t.jsxs("span",{className:"flex min-w-0 flex-1 items-baseline gap-1.5",children:[t.jsx("span",{className:"shrink-0 truncate typography-ui-label text-muted-foreground",children:p.subtitle?`${p.subtitle} · ${p.label}`:p.label}),b?t.jsx("span",{className:"min-w-0 truncate typography-micro text-muted-foreground/70",children:b}):null]}),t.jsx("span",{className:J("shrink-0 typography-ui-label font-semibold tabular-nums",jl(p.window)),children:h==="-"?"":h})]},p.key)})}):null,d.status&&d.rows.length>0?t.jsx("div",{className:"mt-1.5 typography-micro text-muted-foreground",children:d.status}):null]},d.providerId),e[6]=o,e[7]=r,e[8]=a):a=e[8],u=s.map(a),e[2]=o,e[3]=s,e[4]=r,e[5]=u}else u=e[5];let f;return e[9]!==c||e[10]!==u?(f=t.jsx("div",{className:c,children:u}),e[9]=c,e[10]=u,e[11]=f):f=e[11],f},_n=380,Sl=(n,e)=>{if(!n||typeof n!="object")return;const s=n[e];return typeof s=="number"&&Number.isFinite(s)?s:void 0},lt=n=>typeof n=="number"&&Number.isFinite(n)?n:0,Dn=n=>n>=1e6?`${(n/1e6).toFixed(1)}M`:n>=1e3?`${(n/1e3).toFixed(1)}K`:String(n),Wr=n=>{const e=ce.c(19),{percentage:s}=n;let o,r,i,c,u,f,a;if(e[0]!==s){i=Do(s)??0;const b=Mo(s);r=b==="critical"?"var(--status-error)":b==="warn"?"var(--status-warning)":"var(--status-success)",o=2*Math.PI*7.5,c="0 0 18 18",u="size-[18px] -rotate-90",f="progressbar",a=Math.round(i),e[0]=s,e[1]=o,e[2]=r,e[3]=i,e[4]=c,e[5]=u,e[6]=f,e[7]=a}else o=e[1],r=e[2],i=e[3],c=e[4],u=e[5],f=e[6],a=e[7];let d;e[8]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx("circle",{cx:9,cy:9,r:7.5,fill:"none",stroke:"var(--interactive-border)",strokeWidth:3}),e[8]=d):d=e[8];const p=o*(1-i/100);let g;e[9]!==o||e[10]!==r||e[11]!==p?(g=t.jsx("circle",{cx:9,cy:9,r:7.5,fill:"none",stroke:r,strokeWidth:3,strokeLinecap:"round",strokeDasharray:o,strokeDashoffset:p,className:"transition-[stroke-dashoffset,stroke] duration-300"}),e[9]=o,e[10]=r,e[11]=p,e[12]=g):g=e[12];let h;return e[13]!==c||e[14]!==u||e[15]!==f||e[16]!==a||e[17]!==g?(h=t.jsxs("svg",{viewBox:c,className:u,role:f,"aria-valuenow":a,"aria-valuemin":0,"aria-valuemax":100,children:[d,g]}),e[13]=c,e[14]=u,e[15]=f,e[16]=a,e[17]=g,e[18]=h):h=e[18],h},Nl=n=>{const e=ce.c(13),{icon:s,iconNode:o,label:r,children:i}=n;let c;e[0]!==s||e[1]!==o?(c=o??(s?t.jsx(ee,{name:s,className:"size-[18px]"}):null),e[0]=s,e[1]=o,e[2]=c):c=e[2];let u;e[3]!==c?(u=t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:c}),e[3]=c,e[4]=u):u=e[4];let f;e[5]!==r?(f=t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:r}),e[5]=r,e[6]=f):f=e[6];let a;e[7]!==i?(a=t.jsx("span",{className:"min-w-0 flex-1 truncate text-right typography-ui-label font-medium text-foreground",children:i}),e[7]=i,e[8]=a):a=e[8];let d;return e[9]!==u||e[10]!==f||e[11]!==a?(d=t.jsxs("div",{className:"flex min-w-0 items-center gap-3 rounded-xl px-2.5 py-2.5",children:[u,f,a]}),e[9]=u,e[10]=f,e[11]=a,e[12]=d):d=e[12],d},Cl=n=>{const e=ce.c(49),{open:s,onClose:o,anchorRef:r,contextDisplay:i,usageGroups:c,usageDisplayMode:u,isUsageLoading:f,timeFormatPreference:a}=n,{t:d}=de(),p=l.useRef(null),[g,h]=l.useState(s),[b,j]=l.useState(!1),{enabled:y}=Ps(),A=l.useRef(null),[S,E]=l.useState(null);let T,k;e[0]!==r||e[1]!==y||e[2]!==s||e[3]!==g?(T=()=>{if(!s||!y||!g)return;const G=()=>{const Z=r.current?.getBoundingClientRect(),ie=A.current?.getBoundingClientRect();if(!Z||!ie){E(null);return}const fe=Z.left-ie.left,ae=Math.min(Math.max(fe,8),Math.max(8,ie.width-_n-8));E(ae)};G();const q=A.current;if(typeof ResizeObserver>"u"||!q)return;const X=new ResizeObserver(G);return X.observe(q),()=>X.disconnect()},k=[r,y,s,g],e[0]=r,e[1]=y,e[2]=s,e[3]=g,e[4]=T,e[5]=k):(T=e[4],k=e[5]),l.useLayoutEffect(T,k);const N=y&&S!==null;let w,P;e[6]!==s||e[7]!==g?(w=()=>{if(s){h(!0),j(!1);return}if(!g)return;j(!0);const G=window.setTimeout(()=>{h(!1),j(!1)},140);return()=>window.clearTimeout(G)},P=[s,g],e[6]=s,e[7]=g,e[8]=w,e[9]=P):(w=e[8],P=e[9]),l.useEffect(w,P);let x,_;e[10]!==o||e[11]!==s?(x=()=>{if(!s)return;const G=q=>{q.key==="Escape"&&o()};return document.addEventListener("keydown",G),()=>document.removeEventListener("keydown",G)},_=[o,s],e[10]=o,e[11]=s,e[12]=x,e[13]=_):(x=e[12],_=e[13]),l.useEffect(x,_);let D,C;if(e[14]!==r||e[15]!==o||e[16]!==s?(D=()=>{if(!s)return;const G=q=>{const X=q.target;if(!(X instanceof Node)){o();return}p.current?.contains(X)||r.current?.contains(X)||o()};return document.addEventListener("pointerdown",G,!0),document.addEventListener("wheel",G,!0),()=>{document.removeEventListener("pointerdown",G,!0),document.removeEventListener("wheel",G,!0)}},C=[r,o,s],e[14]=r,e[15]=o,e[16]=s,e[17]=D,e[18]=C):(D=e[17],C=e[18]),l.useEffect(D,C),!g)return null;let R;e[19]!==d?(R=d("mobile.header.openMetadataAria"),e[19]=d,e[20]=R):R=e[20];const B=N?"absolute origin-top-left":"mx-3 mt-2",F=b?"pointer-events-none":"pointer-events-auto";let v;e[21]!==B||e[22]!==F?(v=J("overflow-y-auto overscroll-contain rounded-[20px] border border-border/70 bg-[var(--surface-elevated)] p-2 shadow-[0_12px_32px_rgb(0_0_0_/_0.2)] will-change-transform",B,F),e[21]=B,e[22]=F,e[23]=v):v=e[23];const I=`${b?"session-metadata-out":"session-metadata-in"} ${b?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`;let $;e[24]!==S||e[25]!==N?($=N?{top:8,left:S??8,width:`min(${_n}px, calc(100% - 16px))`}:null,e[24]=S,e[25]=N,e[26]=$):$=e[26];let z;e[27]!==I||e[28]!==$?(z={animation:I,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...$},e[27]=I,e[28]=$,e[29]=z):z=e[29];let O;e[30]!==i||e[31]!==d?(O=i?t.jsx(Nl,{iconNode:t.jsx(Wr,{percentage:i.percentage}),label:d("mobile.header.metadata.context"),children:t.jsxs("span",{className:"inline-flex items-baseline gap-1.5 tabular-nums",children:[t.jsxs("span",{className:J("font-semibold",i.colorClass),children:[i.percentage.toFixed(1),"%"]}),t.jsx("span",{className:"text-muted-foreground",children:i.tokens})]})}):null,e[30]=i,e[31]=d,e[32]=O):O=e[32];let te;e[33]!==f||e[34]!==a||e[35]!==u||e[36]!==c?(te=t.jsx(El,{groups:c,displayMode:u,isLoading:f,timeFormatPreference:a}),e[33]=f,e[34]=a,e[35]=u,e[36]=c,e[37]=te):te=e[37];let Q;e[38]!==O||e[39]!==te?(Q=t.jsxs("div",{className:"space-y-1",children:[O,te]}),e[38]=O,e[39]=te,e[40]=Q):Q=e[40];let se;e[41]!==v||e[42]!==z||e[43]!==Q||e[44]!==R?(se=t.jsx("div",{ref:p,role:"dialog","aria-label":R,className:v,style:z,children:Q}),e[41]=v,e[42]=z,e[43]=Q,e[44]=R,e[45]=se):se=e[45];let M;e[46]===Symbol.for("react.memo_cache_sentinel")?(M=t.jsx("style",{children:`
5
- @keyframes session-metadata-in {
6
- from { opacity: 0; transform: translateY(-8px) scale(0.985); }
7
- to { opacity: 1; transform: translateY(0) scale(1); }
8
- }
9
- @keyframes session-metadata-out {
10
- from { opacity: 1; transform: translateY(0) scale(1); }
11
- to { opacity: 0; transform: translateY(-6px) scale(0.985); }
12
- }
13
- `}),e[46]=M):M=e[46];let W;return e[47]!==se?(W=t.jsxs("div",{ref:A,className:"fixed inset-x-0 bottom-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px))] z-20 pointer-events-none",children:[se,M]}),e[47]=se,e[48]=W):W=e[48],W},El=n=>{const e=ce.c(30),{groups:s,displayMode:o,isLoading:r,timeFormatPreference:i}=n,{t:c}=de();let u;e[0]!==o||e[1]!==c?(u=c(o==="remaining"?"header.services.remaining":"header.services.used"),e[0]=o,e[1]=c,e[2]=u):u=e[2];const f=u;if(s.length===0){if(!r)return null;let S;e[3]===Symbol.for("react.memo_cache_sentinel")?(S=t.jsx(ee,{name:"loader-4",className:"size-4 animate-spin","aria-hidden":!0}),e[3]=S):S=e[3];let E;e[4]!==c?(E=c("common.loading"),e[4]=c,e[5]=E):E=e[5];let T;return e[6]!==E?(T=t.jsxs("div",{className:"flex items-center justify-center gap-2 px-2.5 py-6 text-muted-foreground",children:[S,t.jsx("span",{className:"typography-ui-label",children:E})]}),e[6]=E,e[7]=T):T=e[7],T}let a;e[8]===Symbol.for("react.memo_cache_sentinel")?(a=t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:t.jsx(ee,{name:"timer",className:"size-[18px]"})}),e[8]=a):a=e[8];let d;e[9]!==c?(d=c("mobile.header.metadata.usage"),e[9]=c,e[10]=d):d=e[10];let p;e[11]!==d?(p=t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:d}),e[11]=d,e[12]=p):p=e[12];let g;e[13]!==r?(g=r?t.jsx(ee,{name:"refresh",className:"size-3.5 animate-spin"}):null,e[13]=r,e[14]=g):g=e[14];let h;e[15]!==f?(h=t.jsx("span",{className:"truncate",children:f}),e[15]=f,e[16]=h):h=e[16];let b;e[17]!==g||e[18]!==h?(b=t.jsxs("span",{className:"inline-flex min-w-0 flex-1 items-center justify-end gap-1.5 typography-ui-label text-muted-foreground",children:[g,h]}),e[17]=g,e[18]=h,e[19]=b):b=e[19];let j;e[20]!==p||e[21]!==b?(j=t.jsxs("div",{className:"flex min-w-0 items-center gap-3 px-2.5 pb-1.5",children:[a,p,b]}),e[20]=p,e[21]=b,e[22]=j):j=e[22];let y;e[23]!==o||e[24]!==s||e[25]!==i?(y=t.jsx(kl,{groups:s,displayMode:o,timeFormatPreference:i}),e[23]=o,e[24]=s,e[25]=i,e[26]=y):y=e[26];let A;return e[27]!==j||e[28]!==y?(A=t.jsxs("div",{className:"pt-2.5",children:[j,y]}),e[27]=j,e[28]=y,e[29]=A):A=e[29],A},Rl=l.memo(function({open:e,onOpenChange:s,currentSessionId:o,effectiveDirectory:r,isNewSessionDraftOpen:i}){const{t:c}=de(),u=l.useRef(null),f=To(o??"",r||void 0),a=Oe(I=>I.providers),d=Oe(I=>I.currentProviderId),p=Oe(I=>I.currentModelId),g=Oe(I=>I.getModelMetadata);Oe(I=>I.modelsMetadata.size);const h=Ao(l.useCallback(I=>o?I.sessionModelSelections.get(o)??null:null,[o])),b=at(I=>I.results),j=at(I=>I.loadSettings),y=at(I=>I.fetchAllQuotas),A=at(I=>I.isLoading),S=at(I=>I.displayMode),E=at(I=>I.dropdownProviderIds),T=He(I=>I.timeFormatPreference);Io(),l.useEffect(()=>{j()},[j]),l.useEffect(()=>{yn(E)},[E]),l.useEffect(()=>{!e||A||!E.some($=>!b.some(z=>z.providerId===$))||y()},[E,y,A,e,b]);const N=l.useMemo(()=>{for(let I=f.length-1;I>=0;I-=1){const $=f[I];if($.role!=="user")continue;const z=typeof $.model?.providerID=="string"&&$.model.providerID.trim().length>0?$.model.providerID:void 0,O=typeof $.model?.modelID=="string"&&$.model.modelID.trim().length>0?$.model.modelID:void 0;if(z&&O)return{providerID:z,modelID:O}}return null},[f])??(h?{providerID:h.providerId,modelID:h.modelId}:null)??(d&&p?{providerID:d,modelID:p}:null),P=(N?a.find(I=>I.id===N.providerID):void 0)?.models.find(I=>I.id===N?.modelID),x=N?g(N.providerID,N.modelID):void 0,_=Sl(P?.limit,"context")??x?.limit?.context??0,D=l.useMemo(()=>{for(let I=f.length-1;I>=0;I-=1){const $=f[I];if($.role!=="assistant"||!$.tokens)continue;const z=lt($.tokens.total);if(z>0)return z;const O=lt($.tokens.input)+lt($.tokens.output)+lt($.tokens.reasoning)+lt($.tokens.cache?.read)+lt($.tokens.cache?.write);if(O>0)return O}return 0},[f]),C=!i&&D>0&&_>0?Math.min(D/_*100,999):null,R=C!==null?`${Dn(D)}/${Dn(_)}`:null,B=C===null?"":C>=90?"text-[var(--status-error)]":C>=75?"text-[var(--status-warning)]":"text-[var(--status-success)]",F=C!==null&&R?{percentage:C,tokens:R,colorClass:B}:null,v=_o();return l.useEffect(()=>{!e||v.length===0||yn(v.map(I=>I.providerId))},[e,v]),t.jsxs(t.Fragment,{children:[t.jsx("button",{ref:u,type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":c("mobile.header.openMetadataAria"),"aria-expanded":e,onClick:()=>s(I=>!I),style:{touchAction:"manipulation"},children:t.jsx(Wr,{percentage:F?.percentage??0})}),t.jsx(Cl,{open:e,onClose:()=>s(!1),anchorRef:u,contextDisplay:F,usageGroups:v,usageDisplayMode:S,isUsageLoading:A,timeFormatPreference:T})]})}),Pl=10,Mn=380,Tl=(n,e)=>n.title?.trim()||e,Al=n=>{const e=ce.c(32),{session:s,meta:o,active:r,onSelect:i}=n,{t:c}=de(),u=or(s.id),f=ir(s.id),a=u?.type??"idle",d=a==="busy"||a==="retry",p=!d&&f>0&&!r,g=ar(s.id,d),h=(d||p)&&g,b=s.time?.updated??s.time?.created??0;let j;e[0]!==b?(j=Oo(b),e[0]=b,e[1]=j):j=e[1];const y=j,A=r&&"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]";let S;e[2]!==A?(S=J("flex w-full items-center gap-3 rounded-xl px-2.5 py-2 text-left transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary",A),e[2]=A,e[3]=S):S=e[3];let E;e[4]===Symbol.for("react.memo_cache_sentinel")?(E={touchAction:"manipulation"},e[4]=E):E=e[4];const T=r?"text-primary":"text-foreground";let k;e[5]!==T?(k=J("block truncate typography-ui-label",T),e[5]=T,e[6]=k):k=e[6];let N;e[7]!==s||e[8]!==c?(N=Tl(s,c("sessions.sidebar.session.untitled")),e[7]=s,e[8]=c,e[9]=N):N=e[9];let w;e[10]!==k||e[11]!==N?(w=t.jsx("span",{className:k,children:N}),e[10]=k,e[11]=N,e[12]=w):w=e[12];let P;e[13]!==o?(P=o?t.jsx("span",{className:"block truncate typography-micro text-muted-foreground",children:o}):null,e[13]=o,e[14]=P):P=e[14];let x;e[15]!==P||e[16]!==w?(x=t.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[w,P]}),e[15]=P,e[16]=w,e[17]=x):x=e[17];let _;e[18]!==d||e[19]!==p?(_=d||p?t.jsx("span",{className:J("size-1.5 shrink-0 rounded-full",d?"bg-primary":"bg-[var(--status-info)]"),"aria-hidden":!0}):null,e[18]=d,e[19]=p,e[20]=_):_=e[20];let D;e[21]!==d||e[22]!==s.id||e[23]!==h||e[24]!==y?(D=h?t.jsx(br,{sessionId:s.id,running:d,className:"typography-micro"}):y?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:y}):null,e[21]=d,e[22]=s.id,e[23]=h,e[24]=y,e[25]=D):D=e[25];let C;return e[26]!==i||e[27]!==x||e[28]!==_||e[29]!==D||e[30]!==S?(C=t.jsxs("button",{type:"button",className:S,onClick:i,style:E,children:[x,_,D]}),e[26]=i,e[27]=x,e[28]=_,e[29]=D,e[30]=S,e[31]=C):C=e[31],C},Il=n=>{const e=ce.c(50),{open:s,onClose:o,anchorRef:r}=n,{t:i}=de(),c=l.useRef(null),[u,f]=l.useState(s),[a,d]=l.useState(!1),{enabled:p}=Ps(),g=l.useRef(null),[h,b]=l.useState(null);let j,y;e[0]!==r||e[1]!==p||e[2]!==s||e[3]!==u?(j=()=>{if(!s||!p||!u)return;const q=()=>{const ie=r.current?.getBoundingClientRect(),fe=g.current?.getBoundingClientRect();if(!ie||!fe){b(null);return}const ae=ie.left-fe.left;b(Math.min(Math.max(ae,8),Math.max(8,fe.width-Mn-8)))};q();const X=g.current;if(typeof ResizeObserver>"u"||!X)return;const Z=new ResizeObserver(q);return Z.observe(X),()=>Z.disconnect()},y=[r,p,s,u],e[0]=r,e[1]=p,e[2]=s,e[3]=u,e[4]=j,e[5]=y):(j=e[4],y=e[5]),l.useLayoutEffect(j,y);const A=p&&h!==null,S=ke(_l),E=ke(Dl),T=Le(Ml);let k;e[6]===Symbol.for("react.memo_cache_sentinel")?(k={maxParents:Pl},e[6]=k):k=e[6];const N=zo(s||u,k);let w,P;e[7]!==s||e[8]!==u?(w=()=>{if(s){Ts(),f(!0),d(!1);return}if(!u)return;d(!0);const q=window.setTimeout(()=>{f(!1),d(!1)},140);return()=>window.clearTimeout(q)},P=[s,u],e[7]=s,e[8]=u,e[9]=w,e[10]=P):(w=e[9],P=e[10]),l.useEffect(w,P);let x,_;e[11]!==o||e[12]!==s?(x=()=>{if(!s)return;const q=X=>{X.key==="Escape"&&o()};return document.addEventListener("keydown",q),()=>document.removeEventListener("keydown",q)},_=[o,s],e[11]=o,e[12]=s,e[13]=x,e[14]=_):(x=e[13],_=e[14]),l.useEffect(x,_);let D,C;e[15]!==r||e[16]!==o||e[17]!==s?(D=()=>{if(!s)return;const q=X=>{const Z=X.target;if(!(Z instanceof Node)){o();return}c.current?.contains(Z)||r.current?.contains(Z)||o()};return document.addEventListener("pointerdown",q,!0),()=>document.removeEventListener("pointerdown",q,!0)},C=[r,o,s],e[15]=r,e[16]=o,e[17]=s,e[18]=D,e[19]=C):(D=e[18],C=e[19]),l.useEffect(D,C);let R;e[20]!==o||e[21]!==E?(R=q=>{E(q.id,Rs(q)),o()},e[20]=o,e[21]=E,e[22]=R):R=e[22];const B=R;if(!u)return null;let F;e[23]!==i?(F=i("sessions.switcher.openAria"),e[23]=i,e[24]=F):F=e[24];const v=A?"absolute origin-top-left":"mx-3 mt-2",I=a?"pointer-events-none":"pointer-events-auto";let $;e[25]!==v||e[26]!==I?($=J("flex flex-col overflow-hidden rounded-[20px] border border-border/70 bg-[var(--surface-elevated)] p-2 shadow-[0_12px_32px_rgb(0_0_0_/_0.2)] will-change-transform",v,I),e[25]=v,e[26]=I,e[27]=$):$=e[27];const z=`${a?"session-switcher-out":"session-switcher-in"} ${a?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`;let O;e[28]!==h||e[29]!==A?(O=A?{top:8,left:h??8,width:`min(${Mn}px, calc(100% - 16px))`}:null,e[28]=h,e[29]=A,e[30]=O):O=e[30];let te;e[31]!==z||e[32]!==O?(te={animation:z,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...O},e[31]=z,e[32]=O,e[33]=te):te=e[33];let Q;e[34]!==S||e[35]!==B||e[36]!==N||e[37]!==T||e[38]!==i?(Q=N.length===0?t.jsx("p",{className:"px-3 py-6 text-center typography-small text-muted-foreground",children:i("sessions.switcher.empty")}):N.map(q=>{const X=q.node.session,Z=[q.secondaryMeta?.projectLabel,q.secondaryMeta?.branchLabel].filter(Boolean).join(" · ");return t.jsx(Al,{session:X,meta:Z,active:X.id===S,onSelect:()=>{q.projectId&&T(q.projectId),B(X)}},X.id)}),e[34]=S,e[35]=B,e[36]=N,e[37]=T,e[38]=i,e[39]=Q):Q=e[39];let se;e[40]!==Q?(se=t.jsx("div",{className:"oc-hide-scrollbar min-h-0 flex-1 space-y-0.5 overflow-y-auto overscroll-contain",children:Q}),e[40]=Q,e[41]=se):se=e[41];let M;e[42]!==F||e[43]!==$||e[44]!==te||e[45]!==se?(M=t.jsx("div",{ref:c,role:"dialog","aria-label":F,className:$,style:te,children:se}),e[42]=F,e[43]=$,e[44]=te,e[45]=se,e[46]=M):M=e[46];let W;e[47]===Symbol.for("react.memo_cache_sentinel")?(W=t.jsx("style",{children:`
14
- @keyframes session-switcher-in {
15
- from { opacity: 0; transform: translateY(-8px) scale(0.985); }
16
- to { opacity: 1; transform: translateY(0) scale(1); }
17
- }
18
- @keyframes session-switcher-out {
19
- from { opacity: 1; transform: translateY(0) scale(1); }
20
- to { opacity: 0; transform: translateY(-6px) scale(0.985); }
21
- }
22
- `}),e[47]=W):W=e[47];let G;return e[48]!==M?(G=t.jsxs("div",{ref:g,className:"fixed inset-x-0 bottom-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px))] z-20 pointer-events-none",children:[M,W]}),e[48]=M,e[49]=G):G=e[49],G};function _l(n){return n.currentSessionId}function Dl(n){return n.setCurrentSession}function Ml(n){return n.setActiveProjectIdOnly}const zl=n=>{const e=ce.c(71),{onOpenSessions:s,onOpenWorkspace:o,compactTitle:r}=n,i=r===void 0?!1:r,{t:c}=de(),[u,f]=l.useState(!1),[a,d]=l.useState(!1),p=l.useRef(null),g=tt(Ol),h=ke(Ll);let b;e[0]!==h?(b=Ce=>h?Ce.getDirectoryForSession(h):null,e[0]=h,e[1]=b):b=e[1];const y=ke(b)||g,A=Lo(h,y||void 0),S=ke(Bl);let E;e[2]!==A?.title?(E=A?.title?.trim(),e[2]=A?.title,e[3]=E):E=e[3];const T=E;let k;e[4]!==h||e[5]!==T||e[6]!==c?(k=T||c(h?"mobile.sessions.untitled":"sessions.switcher.draftTitle"),e[4]=h,e[5]=T,e[6]=c,e[7]=k):k=e[7];const N=k;let w;e[8]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{f(!1),d(!1)},e[8]=w):w=e[8];let P;e[9]!==h||e[10]!==y?(P=[h,y],e[9]=h,e[10]=y,e[11]=P):P=e[11],l.useEffect(w,P);let x;e[12]!==s?(x=()=>{f(!1),d(!1),s()},e[12]=s,e[13]=x):x=e[13];const _=x;let D;e[14]===Symbol.for("react.memo_cache_sentinel")?(D=Ce=>{f(Ae=>{const we=typeof Ce=="function"?Ce(Ae):Ce;return we&&d(!1),we})},e[14]=D):D=e[14];const C=D;let R;e[15]===Symbol.for("react.memo_cache_sentinel")?(R=()=>{d(Ce=>{const Ae=!Ce;return Ae&&f(!1),Ae})},e[15]=R):R=e[15];const B=R;let F;e[16]===Symbol.for("react.memo_cache_sentinel")?(F={paddingTop:"var(--oc-safe-area-top, 0px)"},e[16]=F):F=e[16];let v;e[17]!==c?(v=c("mobile.sessions.openSheetAria"),e[17]=c,e[18]=v):v=e[18];let I,$;e[19]===Symbol.for("react.memo_cache_sentinel")?(I={touchAction:"manipulation"},$=t.jsx(ee,{name:"list-unordered",className:"size-5"}),e[19]=I,e[20]=$):(I=e[19],$=e[20]);let z;e[21]!==_||e[22]!==v?(z=t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":v,onClick:_,style:I,children:$}),e[21]=_,e[22]=v,e[23]=z):z=e[23];const O=i?"shrink":"flex-1";let te;e[24]!==O?(te=J("flex min-w-0 items-center rounded-lg px-2 py-1.5 text-left transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",O),e[24]=O,e[25]=te):te=e[25];let Q;e[26]!==c?(Q=c("sessions.switcher.openAria"),e[26]=c,e[27]=Q):Q=e[27];let se;e[28]===Symbol.for("react.memo_cache_sentinel")?(se={touchAction:"manipulation"},e[28]=se):se=e[28];let M;e[29]!==N?(M=t.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",children:N}),e[29]=N,e[30]=M):M=e[30];const W=a&&"rotate-180";let G;e[31]!==W?(G=J("size-4 shrink-0 text-muted-foreground transition-transform duration-150",W),e[31]=W,e[32]=G):G=e[32];let q;e[33]!==G?(q=t.jsx(ee,{name:"arrow-down-s",className:G}),e[33]=G,e[34]=q):q=e[34];let X;e[35]!==M||e[36]!==q?(X=t.jsxs("span",{className:"flex min-w-0 items-center gap-1",children:[M,q]}),e[35]=M,e[36]=q,e[37]=X):X=e[37];let Z;e[38]!==a||e[39]!==te||e[40]!==Q||e[41]!==X?(Z=t.jsx("button",{ref:p,type:"button",className:te,"aria-label":Q,"aria-haspopup":"dialog","aria-expanded":a,onClick:B,style:se,children:X}),e[38]=a,e[39]=te,e[40]=Q,e[41]=X,e[42]=Z):Z=e[42];let ie;e[43]!==i?(ie=i?t.jsx("div",{className:"min-w-0 flex-1"}):null,e[43]=i,e[44]=ie):ie=e[44];let fe;e[45]!==h||e[46]!==y||e[47]!==S||e[48]!==u?(fe=t.jsx(Rl,{open:u,onOpenChange:C,currentSessionId:h,effectiveDirectory:y,isNewSessionDraftOpen:S}),e[45]=h,e[46]=y,e[47]=S,e[48]=u,e[49]=fe):fe=e[49];let ae;e[50]!==c?(ae=c("mobile.header.openWorkspaceAria"),e[50]=c,e[51]=ae):ae=e[51];let V;e[52]!==o?(V=()=>{f(!1),d(!1),o()},e[52]=o,e[53]=V):V=e[53];let ne,K;e[54]===Symbol.for("react.memo_cache_sentinel")?(ne={touchAction:"manipulation"},K=t.jsx(ee,{name:"pencil-ruler-2",className:"size-5"}),e[54]=ne,e[55]=K):(ne=e[54],K=e[55]);let pe;e[56]!==ae||e[57]!==V?(pe=t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":ae,onClick:V,style:ne,children:K}),e[56]=ae,e[57]=V,e[58]=pe):pe=e[58];let Te;e[59]!==z||e[60]!==Z||e[61]!==ie||e[62]!==fe||e[63]!==pe?(Te=t.jsx("header",{className:"oc-mobile-header relative z-30 flex shrink-0 items-center gap-1 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80",style:F,children:t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] w-full items-center gap-1 px-2",children:[z,Z,ie,fe,pe]})}),e[59]=z,e[60]=Z,e[61]=ie,e[62]=fe,e[63]=pe,e[64]=Te):Te=e[64];let be;e[65]===Symbol.for("react.memo_cache_sentinel")?(be=()=>d(!1),e[65]=be):be=e[65];let Ne;e[66]!==a?(Ne=t.jsx(Il,{open:a,onClose:be,anchorRef:p}),e[66]=a,e[67]=Ne):Ne=e[67];let Me;return e[68]!==Te||e[69]!==Ne?(Me=t.jsxs(t.Fragment,{children:[Te,Ne]}),e[68]=Te,e[69]=Ne,e[70]=Me):Me=e[70],Me};function Ol(n){return n.currentDirectory}function Ll(n){return n.currentSessionId}function Bl(n){return!!n.newSessionDraft?.open}const $l=({onActiveConnectionDeleted:n,onConnect:e})=>{const{t:s}=de(),o=Dr(e),{connections:r,isBusy:i,isPasswordBusy:c,error:u,pendingConnection:f,connect:a,submitPassword:d,cancelPassword:p,saveConnection:g,removeConnection:h,setError:b}=o,[j,y]=l.useState(null),A=j?r.find(V=>V.id===j)??null:null,[S,E]=l.useState(null),[T,k]=l.useState(""),[N,w]=l.useState(""),[P,x]=l.useState(""),[_,D]=l.useState(""),[C,R]=l.useState(!1),[B,F]=l.useState(!1),v=l.useRef(null),I=l.useMemo(()=>js(),[]),[$,z]=l.useState(!1),[O,te]=l.useState(null),[Q,se]=l.useState(!1),M=Sr(l.useCallback(()=>se(!0),[])),W=l.useCallback(()=>{y(null),k(""),w(""),x(""),b(null),z(!1)},[b]),G=l.useCallback(V=>{V.preventDefault(),g({id:j??void 0,url:T,label:N,clientToken:P}).then(ne=>{ne&&W()})},[P,j,N,W,g,T]),q=l.useCallback(async()=>{if(v.current)return;b(null),R(!0);const V=new AbortController;v.current=V;try{const ne=await Br({signal:V.signal});switch(v.current===V&&(v.current=null,R(!1)),ne.status){case"ok":k(ne.url),ne.label&&w(ne.label),ne.clientToken&&x(ne.clientToken),z(!0);break;case"pairing":F(!0),await o.redeemPairingConnection(ne.pairing);break;case"permission-denied":b(s("mobile.connect.scan.permissionDenied"));break;case"invalid":b(s("mobile.connect.scan.invalid"));break;case"unsupported":b(s("mobile.connect.scan.unsupported"));break;case"failed":b(s("mobile.connect.scan.failed"));break;default:break}}finally{F(!1),v.current===V&&(v.current=null,R(!1))}},[o,b,s]);l.useEffect(()=>()=>v.current?.abort(),[]);const X=l.useCallback(V=>{V.preventDefault(),d(_)},[_,d]),Z=l.useCallback(()=>{D(""),p()},[p]),ie=l.useCallback(V=>{E(ne=>ne===V?null:V)},[]),fe=l.useCallback(V=>{E(null),j===V&&W();const ne=r.length===1;h(V).then(K=>{K&&(ne||In(K))&&n()})},[r.length,j,n,h,W]),ae=Dt;return f?t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx("form",{className:"flex-1 overflow-y-auto px-5 py-4",onSubmit:X,children:t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(ee,{name:"lock",className:"size-[18px]"})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"truncate typography-ui-label text-foreground",children:f.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:f.candidates.some(V=>V.kind==="direct")?qe(f):s("mobile.connect.relay.badge")})]})]}),t.jsx("input",{...gt,value:_,onChange:V=>D(V.target.value),placeholder:s("mobile.connect.password.placeholder"),"aria-label":s("mobile.connect.password.label"),type:"password",autoFocus:!0,className:ae}),u?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:u}):null,t.jsx(ye,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:c||!_.trim(),children:s(c?"mobile.connect.connecting":"mobile.connect.unlockButton")}),t.jsx(ye,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:Z,children:s("mobile.connect.cancelPassword")})]})})}):t.jsxs(t.Fragment,{children:[C?t.jsx($r,{onCancel:()=>v.current?.abort()}):null,B?t.jsx(Fr,{}):null,Q?t.jsx(Mr,{onClose:()=>se(!1)}):null,t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:t.jsxs("div",{className:"space-y-6",children:[r.length>0?t.jsx("div",{...M,className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map(V=>{const ne=S===V.id,K=In(V),pe=O===V.id,Te=pe?s("mobile.connect.connecting"):K?$t()?s("mobile.instances.status.connectedRelay"):s("mobile.instances.status.connectedDirect"):V.candidates.some(be=>be.kind==="direct")?qe(V):s("mobile.connect.relay.badge");return t.jsxs("div",{className:J("flex items-center border-b border-border/70 transition-colors last:border-b-0",ne&&"bg-[color-mix(in_srgb,var(--destructive)_8%,transparent)]"),children:[t.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-3 px-3.5 py-3 text-left transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary disabled:opacity-60",onClick:()=>{K||(te(V.id),a({id:V.id,candidates:V.candidates,clientToken:V.clientToken,label:V.label}).finally(()=>te(null)))},disabled:i&&!pe||ne,children:[t.jsxs("span",{className:"relative flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:[t.jsx(ee,{name:"server",className:"size-[18px]"}),K?t.jsx("span",{className:"absolute -right-0.5 -top-0.5 size-2.5 rounded-full border-2 border-[var(--surface-elevated)] bg-[var(--status-success)]","aria-hidden":!0}):null]}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:V.label}),t.jsx("span",{className:J("block truncate typography-small",K&&!pe?"text-[var(--status-success)]":"text-muted-foreground"),children:Te})]}),pe?t.jsx(ee,{name:"loader-4",className:"size-5 shrink-0 animate-spin text-muted-foreground"}):null]}),t.jsxs("div",{className:"flex items-center gap-0.5 pr-2",children:[ne?t.jsxs("button",{type:"button","aria-label":s("mobile.instances.confirmDeleteAria",{label:V.label}),className:"flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-destructive px-3 text-destructive-foreground transition-opacity active:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive",onClick:()=>fe(V.id),style:{touchAction:"manipulation"},children:[t.jsx(ee,{name:"delete-bin",className:"size-[18px]"}),t.jsx("span",{className:"typography-ui-label",children:s("mobile.instances.delete")})]}):V.candidates.some(be=>be.kind==="direct")?t.jsx("button",{type:"button","aria-label":s("mobile.instances.edit"),className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:()=>{y(V.id),k(qe(V)),w(V.label),x(V.clientToken||""),b(null)},style:{touchAction:"manipulation"},children:t.jsx(ee,{name:"edit",className:"size-[18px]"})}):null,t.jsx("button",{type:"button","aria-label":ne?s("mobile.instances.cancelDeleteAria",{label:V.label}):s("mobile.instances.deleteAria",{label:V.label}),className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:()=>ie(V.id),style:{touchAction:"manipulation"},children:t.jsx(ee,{name:ne?"close":"delete-bin",className:"size-[18px]"})})]})]},V.id)})}):t.jsx("p",{...M,className:"rounded-[18px] border border-dashed border-border/70 px-4 py-6 text-center typography-small text-muted-foreground",children:s("mobile.connect.saved.empty")}),!$&&!A?t.jsxs("div",{className:"space-y-2",children:[I?t.jsxs(ye,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{q()},disabled:C,children:[t.jsx(ee,{name:"scan-2",className:J("size-[18px]",C&&"animate-pulse")}),s("mobile.connect.scanQr")]}):null,t.jsxs(ye,{type:"button",variant:I?"ghost":"outline",size:"lg",className:"h-12 w-full",onClick:()=>{b(null),z(!0)},children:[t.jsx(ee,{name:"add",className:"size-[18px]"}),s("mobile.instances.addManual")]}),u?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:u}):null]}):t.jsxs("form",{className:"space-y-3",onSubmit:G,children:[t.jsxs("div",{className:"flex h-8 items-center justify-between gap-3 px-1",children:[t.jsx("h3",{className:"typography-ui-label text-foreground",children:s(A?"mobile.instances.editTitle":"mobile.instances.addTitle")}),t.jsx(ye,{type:"button",variant:"ghost",size:"xs",onClick:W,children:s("mobile.instances.cancelEdit")})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:s("mobile.connect.url.label")}),t.jsx("input",{...gt,value:T,onChange:V=>k(V.target.value),placeholder:s("mobile.connect.url.placeholder"),type:"url",inputMode:"url",autoCapitalize:"none",className:ae})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:s("mobile.instances.label.label")}),t.jsx("input",{value:N,onChange:V=>w(V.target.value),placeholder:s("mobile.instances.label.placeholder"),autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,className:ae})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:s("mobile.connect.token.label")}),t.jsx("input",{...gt,value:P,onChange:V=>x(V.target.value),placeholder:s("mobile.connect.token.placeholder"),autoCapitalize:"none",className:ae}),t.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:s("mobile.connect.token.hint")})]}),u?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:u}):null,t.jsx(ye,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",children:s(A?"mobile.instances.saveEdit":"mobile.instances.saveNew")})]})]})})})]})},Se=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/g,""),ms=n=>{const e=Se(n);if(!e)return"";const s=e.split("/").filter(Boolean);return s[s.length-1]?.replace(/[-_]/g," ")||e},zn=Hs(n=>({expandedParents:{},toggleParent:e=>n(s=>{const o={...s.expandedParents};return o[e]?delete o[e]:o[e]=!0,{expandedParents:o}})})),Kt=Hs()(wr(n=>({projectExpanded:{},worktreeExpanded:{},setProjectExpanded:(e,s)=>n(o=>({projectExpanded:{...o.projectExpanded,[e]:s}})),setWorktreeExpanded:(e,s)=>n(o=>({worktreeExpanded:{...o.worktreeExpanded,[e]:s}}))}),{name:"mobile-session-tree"})),ks=Hs()(wr(n=>({orderByProject:{},setWorktreeOrder:(e,s)=>n(o=>({orderByProject:{...o.orderByProject,[e]:s}}))}),{name:"mobile-worktree-order"})),On=n=>n.replace(/\\/g,"/").replace(/\/+$/,""),Fl=(n,e)=>{if(!n||n.length===0)return e;const s=new Map(n.map((r,i)=>[On(r),i])),o=r=>s.get(On(r.path))??Number.MAX_SAFE_INTEGER;return e.map((r,i)=>({worktree:r,index:i})).sort((r,i)=>{const c=o(r.worktree)-o(i.worktree);return c!==0?c:r.index-i.index}).map(r=>r.worktree)},Mt=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/,""),Wl=n=>{const e=n;return Mt(e.directory??e.project?.worktree??null)},Ur=({open:n,project:e,worktree:s,onClose:o,onDeleted:r})=>{const{t:i}=de(),c=lr(),u=Es(x=>x.activeSessions),f=ke(x=>x.archiveSessions),a=tt(x=>x.currentDirectory),[d,p]=l.useState(!1),[g,h]=l.useState(!1),[b,j]=l.useState(!1),[y,A]=l.useState(!1),S=Mt(s?.path),E=typeof s?.branch=="string"&&s.branch.trim().length>0,T=l.useMemo(()=>{if(!S)return[];const x=new Map;for(const _ of[...u,...c])Wl(_)===S&&x.set(_.id,_);return Array.from(x.values())},[u,c,S]);l.useEffect(()=>{if(!n){p(!1),h(!1),j(!1),A(!1);return}if(!s?.path)return;let x=!1;return Bo(s.path).then(_=>{x||j(!!_?.isDirty)}).catch(()=>{x||j(!!s.status?.isDirty)}),()=>{x=!0}},[n,s?.path,s?.status?.isDirty]);const k=l.useCallback(x=>{(async()=>{try{await $o(e,x,{deleteRemoteBranch:E&&g,deleteLocalBranch:E&&d}),Mt(a)===S&&Mt(e.path)&&tt.getState().setDirectory(Mt(e.path),{showOverlay:!1}),le.success(i("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:i(E&&g?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed")}),r?.()}catch(_){le.error(i("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:_ instanceof Error?_.message:i("sessions.sidebar.dialogs.deleteResult.tryAgain")})}})()},[a,d,g,E,r,e,i,S]),N=async()=>{if(!(!s||y)){A(!0);try{if(T.length>0){const{archivedIds:x,failedIds:_}=await f(T.map(D=>D.id));if(_.length>0){x.length>0&&le.success(x.length===1?i("sessions.sidebar.bulkActions.archivedSingle",{count:x.length}):i("sessions.sidebar.bulkActions.archivedPlural",{count:x.length})),le.error(_.length===1?i("sessions.sidebar.bulkActions.failedArchiveSingle",{count:_.length}):i("sessions.sidebar.bulkActions.failedArchivePlural",{count:_.length}),{description:i("sessions.sidebar.dialogs.deleteResult.tryAgain")}),A(!1);return}}k(s),o()}catch(x){le.error(i("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:x instanceof Error?x.message:i("sessions.sidebar.dialogs.deleteResult.tryAgain")}),A(!1)}finally{n||A(!1)}}};if(!s)return null;const w=s.branch||s.label||s.path,P=(x,_,D,C)=>t.jsxs("button",{type:"button",role:"switch","aria-checked":x,disabled:C,onClick:()=>_(!x),className:J("flex w-full items-center justify-between gap-3 rounded-xl border border-border/70 px-3.5 py-3 text-left transition-colors","hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",C&&"pointer-events-none opacity-40"),style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:D}),t.jsx("span",{className:J("relative h-6 w-10 shrink-0 rounded-full transition-colors",x?"bg-primary":"bg-muted-foreground/30"),children:t.jsx("span",{className:J("absolute top-0.5 size-5 rounded-full bg-white transition-transform",x?"translate-x-[1.125rem]":"translate-x-0.5")})})]});return t.jsx(Fo,{open:n,onClose:o,title:i("mobile.projectEdit.deleteWorktreeTitle"),footer:t.jsxs("div",{className:"flex gap-2",children:[t.jsx(ye,{variant:"ghost",className:"flex-1",onClick:o,disabled:y,children:i("projectEditDialog.actions.cancel")}),t.jsx(ye,{variant:"destructive",className:"flex-1",onClick:()=>{N()},disabled:y,children:i("mobile.projectEdit.deleteWorktreeConfirmButton")})]}),children:t.jsxs("div",{className:"flex flex-col gap-4 px-1 py-1",children:[t.jsx("p",{className:"typography-ui-body text-foreground",children:i("mobile.projectEdit.deleteWorktreeConfirm",{name:w})}),b?t.jsx("p",{className:"rounded-xl border border-[var(--warning)]/40 bg-[color-mix(in_srgb,var(--warning)_10%,transparent)] px-3.5 py-3 typography-meta text-foreground",children:i("mobile.projectEdit.deleteWorktreeDirty")}):null,T.length>0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:i("mobile.projectEdit.deleteWorktreeArchiveNote",{count:T.length})}):null,E?t.jsxs("div",{className:"flex flex-col gap-2",children:[P(d,p,i("mobile.projectEdit.deleteLocalBranch"),y),P(g,h,i("mobile.projectEdit.deleteRemoteBranch"),y)]}):null]})})},Ln="mobile-surface-root",ps=16,Ht=200,Ul=()=>{if(typeof document>"u")return null;let n=document.getElementById(Ln);return n||(n=document.createElement("div"),n.id=Ln,document.body.appendChild(n)),n},zt=({open:n,onClose:e,title:s,subtitle:o,trailing:r,disableEscapeDismiss:i=!1,headerless:c=!1,noHeaderBorder:u=!1,ariaLabel:f,variant:a="fullscreen",dialogAlign:d="chat",children:p})=>{const{t:g}=de(),h=l.useRef(null),[b,j]=l.useState(!1),[y,A]=l.useState(!1),S=l.useRef(null),E=l.useRef(null),T=l.useRef(e);if(l.useEffect(()=>{T.current=e},[e]),typeof document<"u"&&!h.current&&(h.current=Ul()),l.useEffect(()=>{if(!n){j(!1);return}const w=window.setTimeout(()=>j(!0),ps);return()=>window.clearTimeout(w)},[n]),l.useEffect(()=>{if(!n){A(!1);return}const w=window.setTimeout(()=>A(!0),ps+Ht+80);return()=>window.clearTimeout(w)},[n]),l.useEffect(()=>{if(!n)return;const w=document.body.style.overflow;E.current=document.activeElement instanceof HTMLElement?document.activeElement:null,document.body.style.overflow="hidden";const P=()=>{const D=S.current;if(!D)return;(D.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')??D).focus({preventScroll:!0})},x=window.setTimeout(P,ps),_=D=>{if(D.key==="Escape"&&!i){T.current();return}if(D.key!=="Tab")return;const C=S.current;if(!C)return;const R=Array.from(C.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(I=>!I.hasAttribute("disabled")&&I.getAttribute("aria-hidden")!=="true");if(R.length===0){D.preventDefault(),C.focus({preventScroll:!0});return}const B=R[0],F=R[R.length-1],v=document.activeElement;D.shiftKey&&v===B?(D.preventDefault(),F.focus({preventScroll:!0})):!D.shiftKey&&v===F&&(D.preventDefault(),B.focus({preventScroll:!0}))};return document.addEventListener("keydown",_),()=>{window.clearTimeout(x),document.body.style.overflow=w,document.removeEventListener("keydown",_),E.current?.focus?.({preventScroll:!0}),E.current=null}},[i,n]),!n||!h.current)return null;const k=a==="dialog",N=t.jsxs("section",{ref:S,role:"dialog","aria-modal":"true","aria-label":f,tabIndex:-1,className:J("flex flex-col bg-background text-foreground",k?"h-[min(88dvh,860px)] w-full max-w-[720px] overflow-hidden rounded-2xl border border-border/70 shadow-[0_24px_64px_rgb(0_0_0_/_0.32)]":"oc-keyboard-inset-surface fixed inset-0 z-50"),style:k?{opacity:b?1:0,transform:b?"none":"scale(0.97)",transition:`opacity ${Ht}ms ease-out, transform ${Ht}ms cubic-bezier(0.32, 0.72, 0, 1)`}:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:b?"none":"translateX(100%)",transition:`transform ${Ht}ms cubic-bezier(0.32, 0.72, 0, 1)`},onTransitionEnd:w=>{b&&w.target===w.currentTarget&&w.propertyName==="transform"&&A(!0)},children:[c?null:t.jsxs("header",{className:J("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",!u&&"border-b border-border/70"),children:[t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":g("mobile.surface.closeAria"),onClick:e,style:{touchAction:"manipulation"},children:t.jsx(ee,{name:"close",className:"size-5"})}),t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[s?typeof s=="string"?t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:s}):s:null,o?typeof o=="string"?t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:o}):o:null]}),r?t.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:r}):null]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:y?t.jsx("div",{className:"h-full",style:{animation:"oc-surface-content-in 200ms ease-out"},children:p}):null}),t.jsx("style",{children:"@keyframes oc-surface-content-in { from { opacity: 0 } to { opacity: 1 } }"})]});return k?bt.createPortal(t.jsx("div",{className:"oc-keyboard-inset-surface fixed inset-0 z-50 flex items-center justify-center p-4 transition-opacity duration-200 ease-out",style:{background:"rgb(0 0 0 / 0.45)",opacity:b?1:0,paddingLeft:d==="chat"?"max(1rem, var(--oc-chat-inset-left, 0px))":"1rem",paddingRight:d==="chat"?"max(1rem, var(--oc-chat-inset-right, 0px))":"1rem",paddingTop:"max(1rem, var(--oc-safe-area-top, 0px))"},onClick:e,children:t.jsx("div",{className:"flex w-full max-w-[720px] justify-center",onClick:w=>w.stopPropagation(),children:N})}),h.current):bt.createPortal(N,h.current)},Vl=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/,""),Gl=n=>{const e=ce.c(36),{worktree:s,onDelete:o}=n,{t:r}=de();let i;e[0]!==s.path?(i={id:s.path},e[0]=s.path,e[1]=i):i=e[1];const{attributes:c,listeners:u,setNodeRef:f,transform:a,transition:d,isDragging:p}=Gs(i);let g;e[2]!==a?(g=Ks.Transform.toString(a),e[2]=a,e[3]=g):g=e[3];const h=p?10:1;let b;e[4]!==g||e[5]!==h||e[6]!==d?(b={transform:g,transition:d,zIndex:h},e[4]=g,e[5]=h,e[6]=d,e[7]=b):b=e[7];const j=b,y=s.branch||s.label||s.path,A=p&&"shadow-lg shadow-black/20";let S;e[8]!==A?(S=J("flex items-center gap-1 rounded-2xl border border-border/70 bg-[var(--surface-elevated)] px-1.5 py-1.5 transition-colors",A),e[8]=A,e[9]=S):S=e[9];let E;e[10]!==y||e[11]!==r?(E=r("mobile.projectEdit.dragWorktreeAria",{label:y}),e[10]=y,e[11]=r,e[12]=E):E=e[12];let T;e[13]===Symbol.for("react.memo_cache_sentinel")?(T=t.jsx(Ms,{className:"size-4"}),e[13]=T):T=e[13];let k;e[14]!==c||e[15]!==u||e[16]!==E?(k=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 cursor-grab touch-none items-center justify-center rounded-xl text-muted-foreground/70 transition-colors hover:text-foreground active:cursor-grabbing","aria-label":E,...c,...u,children:T}),e[14]=c,e[15]=u,e[16]=E,e[17]=k):k=e[17];let N;e[18]===Symbol.for("react.memo_cache_sentinel")?(N=t.jsx(ee,{name:"node-tree",className:"size-4 shrink-0 text-muted-foreground"}),e[18]=N):N=e[18];let w;e[19]!==y?(w=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:y}),e[19]=y,e[20]=w):w=e[20];let P;e[21]!==y||e[22]!==r?(P=r("mobile.projectEdit.deleteWorktreeAria",{label:y}),e[21]=y,e[22]=r,e[23]=P):P=e[23];let x,_;e[24]===Symbol.for("react.memo_cache_sentinel")?(x={touchAction:"manipulation"},_=t.jsx(Qt,{className:"size-4"}),e[24]=x,e[25]=_):(x=e[24],_=e[25]);let D;e[26]!==o||e[27]!==P?(D=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-xl text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive","aria-label":P,onClick:o,style:x,children:_}),e[26]=o,e[27]=P,e[28]=D):D=e[28];let C;return e[29]!==f||e[30]!==j||e[31]!==w||e[32]!==D||e[33]!==S||e[34]!==k?(C=t.jsxs("div",{ref:f,style:j,className:S,children:[k,N,w,D]}),e[29]=f,e[30]=j,e[31]=w,e[32]=D,e[33]=S,e[34]=k,e[35]=C):C=e[35],C},Kl=({open:n,project:e,onClose:s,onWorktreesChanged:o})=>{const{t:r}=de(),{currentTheme:i}=cr(),c=Le(v=>v.updateProjectMeta),u=Le(v=>v.discoverProjectIcon),f=Le(v=>v.removeProjectIcon),a=ks(v=>v.setWorktreeOrder),d=Le(v=>e?v.projects.find(I=>I.id===e.id)?.iconImage??null:null),[p,g]=l.useState(""),[h,b]=l.useState(null),[j,y]=l.useState(null),[A,S]=l.useState(!1),[E,T]=l.useState([]),[k,N]=l.useState(null),w=e?.id??null;l.useEffect(()=>{!n||!e||(g(e.label),b(e.icon??null),y(e.color??null),T(e.worktrees))},[n,w]),l.useEffect(()=>{!n||!e||T(v=>{const I=e.worktrees.map(O=>O.path),$=v.map(O=>O.path);return I.length===$.length&&I.every(O=>$.includes(O))?v:e.worktrees})},[e?.worktrees]);const P=Os(yt(Bs,{activationConstraint:{distance:8}}),yt(Ls,{coordinateGetter:Ws})),x=()=>{if(!e)return;const v=p.trim();c(e.id,{label:v||e.label,icon:h,color:j}),s()},_=()=>{!e||A||(S(!0),u(e.id).then(v=>{if(!v.ok){le.error(v.error||r("projectEditDialog.toast.failedToDiscoverIcon"));return}if(v.skipped){le.success(r("projectEditDialog.toast.customIconAlreadySet"));return}le.success(r("projectEditDialog.toast.iconDiscovered"))}).finally(()=>S(!1)))},D=()=>{e&&f(e.id).then(v=>{if(!v.ok){le.error(v.error||r("projectEditDialog.toast.failedToRemoveIcon"));return}le.success(r("projectEditDialog.toast.iconRemoved"))})},C=v=>{const{active:I,over:$}=v;if(!$||I.id===$.id||!e)return;const z=E.findIndex(se=>se.path===I.id),O=E.findIndex(se=>se.path===$.id);if(z<0||O<0)return;const te=[...E],[Q]=te.splice(z,1);te.splice(O,0,Q),T(te),a(e.id,te.map(se=>Vl(se.path)))},R=j?ur[j]??null:null,B=h?dr[h]:null,F=!!d;return t.jsxs(t.Fragment,{children:[t.jsx(zt,{open:n,onClose:s,title:r("projectEditDialog.title"),ariaLabel:r("projectEditDialog.title"),noHeaderBorder:!0,trailing:t.jsxs(ye,{type:"button",variant:"default",size:"sm","aria-label":r("projectEditDialog.actions.save"),onClick:x,disabled:!p.trim(),style:{touchAction:"manipulation"},children:[t.jsx(xr,{className:"size-4"}),r("projectEditDialog.actions.save")]}),children:e?t.jsxs("div",{className:"h-full space-y-6 overflow-y-auto px-4 pb-8 pt-2",children:[t.jsx("div",{className:"flex justify-center pt-2",children:t.jsx("span",{className:"flex size-16 items-center justify-center overflow-hidden rounded-2xl bg-[var(--surface-muted)] text-muted-foreground",style:e.iconBackground?{backgroundColor:e.iconBackground}:void 0,children:F?t.jsx(fr,{project:{id:e.id,iconImage:d},options:{themeVariant:i.metadata.variant,iconColor:i.colors.surface.foreground},className:"size-full object-contain",fallback:t.jsx(ys,{className:"size-7"})}):B?t.jsx(ee,{name:B,className:"size-7",style:R?{color:R}:void 0}):t.jsx(ys,{className:"size-7",style:R?{color:R}:void 0})})}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:r("projectEditDialog.field.name")}),t.jsx(As,{value:p,onChange:v=>g(v.target.value),placeholder:r("projectEditDialog.field.namePlaceholder"),className:"h-11"}),t.jsx("p",{className:"truncate typography-meta text-muted-foreground",title:e.path,children:e.path})]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:r("projectEditDialog.field.color")}),t.jsxs("div",{className:"flex flex-wrap gap-2.5",children:[t.jsx("button",{type:"button",onClick:()=>y(null),"aria-label":r("projectEditDialog.option.none"),className:J("flex size-9 items-center justify-center rounded-xl border-2 transition-all",j===null?"border-foreground":"border-border/70 hover:border-border/70"),style:{touchAction:"manipulation"},children:t.jsx("span",{className:"h-0.5 w-4 rotate-45 rounded-full bg-muted-foreground/40"})}),Wo.map(v=>t.jsx("button",{type:"button",onClick:()=>y(v.key),"aria-label":v.label,title:v.label,className:J("size-9 rounded-xl border-2 transition-all",j===v.key?"border-foreground":"border-transparent hover:border-border/70"),style:{backgroundColor:v.cssVar,touchAction:"manipulation"}},v.key))]})]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:r("projectEditDialog.field.icon")}),t.jsxs("div",{className:"flex flex-wrap gap-2.5",children:[t.jsx("button",{type:"button",onClick:()=>b(null),"aria-label":r("projectEditDialog.option.none"),className:J("flex size-9 items-center justify-center rounded-xl border-2 transition-all",h===null?"border-foreground bg-[var(--surface-elevated)]":"border-border/70 hover:border-border/70"),style:{touchAction:"manipulation"},children:t.jsx("span",{className:"h-0.5 w-4 rotate-45 rounded-full bg-muted-foreground/40"})}),Uo.map(v=>t.jsx("button",{type:"button",onClick:()=>b(v.key),"aria-label":v.label,title:v.label,className:J("flex size-9 items-center justify-center rounded-xl border-2 transition-all",h===v.key?"border-foreground bg-[var(--surface-elevated)]":"border-border/70 hover:border-border/70"),style:{touchAction:"manipulation"},children:t.jsx(ee,{name:v.Icon,className:"size-4",style:R?{color:R}:void 0})},v.key))]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:[t.jsx(ye,{size:"sm",variant:"outline",onClick:_,disabled:A,children:r(A?"projectEditDialog.actions.discovering":"projectEditDialog.actions.discoverFavicon")}),F?t.jsx(ye,{size:"sm",variant:"outline",onClick:D,children:r("projectEditDialog.actions.removeProjectIcon")}):null]})]}),e.isGitRepo?t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:r("mobile.projectEdit.worktreesTitle")}),E.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:r("mobile.projectEdit.worktreesEmpty")}):t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:r("mobile.projectEdit.reorderHint")}),t.jsx($s,{sensors:P,collisionDetection:Fs,onDragEnd:C,children:t.jsx(Us,{items:E.map(v=>v.path),strategy:Vs,children:t.jsx("div",{className:"flex flex-col gap-1.5",children:E.map(v=>t.jsx(Gl,{worktree:v,onDelete:()=>N(v)},v.path))})})})]})]}):null]}):null}),e?t.jsx(Ur,{open:!!k,project:{id:e.id,path:e.path},worktree:k,onClose:()=>N(null),onDeleted:()=>{T(v=>v.filter(I=>I.path!==k?.path)),o?.()}}):null]})},Hl=new Set,hs=7,qt=40,ql=16,ct=n=>n.parentID??null,dt=n=>{const e=n;return Se(e.directory??e.project?.worktree??null)},Yl=n=>{const e=n.time?.updated??n.time?.created,s=typeof e=="number"?e:Number(e);return Number.isFinite(s)&&s>0?s:0},Jl=n=>{if(n<=0)return"";const e=Date.now()-n;if(e<6e4)return"now";const s=Math.floor(e/6e4);if(s<60)return`${s}m`;const o=Math.floor(s/60);if(o<24)return`${o}h`;const r=Math.floor(o/24);return r<7?`${r}d`:new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric"}).format(new Date(n))},Xl=(n,e)=>{const s=Se(n),o=Se(e);return!!(s&&o&&(s===o||s.startsWith(`${o}/`)))},Xt=(n,e)=>n.worktrees.find(s=>Se(s.path)===e)??null,Ss=(n,e)=>e===n.path||!!Xt(n,e),gs=(n,e)=>{const s=Se(e);return s?n.find(o=>Ss(o,s))??null:null},bs=(n,e,s)=>mr([n.title,n.id,dt(n),e],s),Ns=n=>{const e=ce.c(17),{project:s,size:o}=n,r=o===void 0?"md":o,{currentTheme:i}=cr(),c=s.icon?dr[s.icon]:null,u=s.color?ur[s.color]??null:null,f=r==="sm"?"size-6 rounded-md":"size-8 rounded-lg",a=r==="sm"?"size-3.5":"size-4";let d;e[0]!==c||e[1]!==u||e[2]!==a?(d=c?t.jsx(ee,{name:c,className:a,style:u?{color:u}:void 0}):t.jsx(ys,{className:a,style:u?{color:u}:void 0}),e[0]=c,e[1]=u,e[2]=a,e[3]=d):d=e[3];const p=d;let g;e[4]!==f?(g=J("flex shrink-0 items-center justify-center overflow-hidden bg-[var(--surface-muted)] text-muted-foreground",f),e[4]=f,e[5]=g):g=e[5];let h;e[6]!==s.iconBackground?(h=s.iconBackground?{backgroundColor:s.iconBackground}:void 0,e[6]=s.iconBackground,e[7]=h):h=e[7];let b;e[8]!==i||e[9]!==p||e[10]!==s.iconImage||e[11]!==s.id?(b=s.iconImage?t.jsx(fr,{project:{id:s.id,iconImage:s.iconImage??null},options:{themeVariant:i.metadata.variant,iconColor:i.colors.surface.foreground},className:"size-full object-contain",fallback:p}):p,e[8]=i,e[9]=p,e[10]=s.iconImage,e[11]=s.id,e[12]=b):b=e[12];let j;return e[13]!==g||e[14]!==h||e[15]!==b?(j=t.jsx("span",{className:g,style:h,children:b}),e[13]=g,e[14]=h,e[15]=b,e[16]=j):j=e[16],j},Bn=n=>{const e=ce.c(2),{ariaLabel:s}=n;let o;return e[0]!==s?(o=t.jsx("span",{className:"inline-block size-1.5 shrink-0 rounded-full bg-primary","aria-label":s}),e[0]=s,e[1]=o):o=e[1],o},$n=n=>{const e=ce.c(12),{onClick:s,className:o}=n,{t:r}=de();let i;e[0]!==r?(i=r("sessions.sidebar.project.actions.newWorktree"),e[0]=r,e[1]=i):i=e[1];const c=i;let u;e[2]!==o?(u=J("flex size-9 shrink-0 items-center justify-center rounded-full text-[var(--surface-mutedForeground)] transition-colors hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",o),e[2]=o,e[3]=u):u=e[3];let f;e[4]!==s?(f=g=>{g.stopPropagation(),s()},e[4]=s,e[5]=f):f=e[5];let a,d;e[6]===Symbol.for("react.memo_cache_sentinel")?(a={touchAction:"manipulation"},d=t.jsx(ee,{name:"node-tree",className:"size-4"}),e[6]=a,e[7]=d):(a=e[6],d=e[7]);let p;return e[8]!==c||e[9]!==u||e[10]!==f?(p=t.jsx("button",{type:"button",className:u,"aria-label":c,title:c,onClick:f,style:a,children:d}),e[8]=c,e[9]=u,e[10]=f,e[11]=p):p=e[11],p},ut=144,Vr=180,Fn=n=>{const e=ce.c(25),{actionsWidth:s,actions:o,revealed:r,onRevealedChange:i,children:c}=n,u=l.useRef(null),f=l.useRef(null),a=l.useRef(!1),d=l.useRef(0),p=l.useRef(r);let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=(C,R)=>{const B=u.current;B&&(B.style.transition=R?`transform ${Vr}ms ease-out`:"none",B.style.transform=C===0?"none":`translateX(${C}px)`,d.current=C)},e[0]=g):g=e[0];const h=g;let b,j;e[1]!==s||e[2]!==r?(b=()=>{p.current=r,h(r?-s:0,!0)},j=[s,h,r],e[1]=s,e[2]=r,e[3]=b,e[4]=j):(b=e[3],j=e[4]),l.useEffect(b,j);let y;e[5]===Symbol.for("react.memo_cache_sentinel")?(y=C=>{if(C.touches.length!==1)return;const R=C.touches[0];f.current={x:R.clientX,y:R.clientY},a.current=!1},e[5]=y):y=e[5];const A=y;let S;e[6]!==s?(S=C=>{if(!f.current)return;const R=C.touches[0],B=R.clientX-f.current.x,F=R.clientY-f.current.y;if(!a.current){if(Math.abs(B)<8||Math.abs(B)<=Math.abs(F))return;a.current=!0}const v=p.current?-s:0;h(Math.min(0,Math.max(-s,v+B)),!1)},e[6]=s,e[7]=S):S=e[7];const E=S;let T;e[8]!==s||e[9]!==i?(T=()=>{if(f.current=null,!a.current)return;a.current=!1;const C=d.current<-s/2;h(C?-s:0,!0),C!==p.current&&i(C)},e[8]=s,e[9]=i,e[10]=T):T=e[10];const k=T;let N;e[11]===Symbol.for("react.memo_cache_sentinel")?(N={touchAction:"pan-y"},e[11]=N):N=e[11];let w;e[12]!==s?(w={width:s},e[12]=s,e[13]=w):w=e[13];const P=!r;let x;e[14]!==o||e[15]!==w||e[16]!==P?(x=t.jsx("div",{className:"absolute inset-y-0 right-0 flex items-stretch",style:w,"aria-hidden":P,children:o}),e[14]=o,e[15]=w,e[16]=P,e[17]=x):x=e[17];let _;e[18]!==c?(_=t.jsx("div",{ref:u,className:"relative flex w-full items-center bg-background",children:c}),e[18]=c,e[19]=_):_=e[19];let D;return e[20]!==k||e[21]!==E||e[22]!==x||e[23]!==_?(D=t.jsxs("div",{className:"relative overflow-hidden",onTouchStart:A,onTouchMove:E,onTouchEnd:k,onTouchCancel:k,style:N,children:[x,_]}),e[20]=k,e[21]=E,e[22]=x,e[23]=_,e[24]=D):D=e[24],D},Ql=n=>{const e=ce.c(41),{initialTitle:s,indent:o,onSubmit:r,onCancel:i}=n,{t:c}=de(),[u,f]=l.useState(s);let a;e[0]!==s||e[1]!==i||e[2]!==r||e[3]!==u?(a=()=>{const C=u.trim();if(!C||C===s.trim()){i();return}r(C)},e[0]=s,e[1]=i,e[2]=r,e[3]=u,e[4]=a):a=e[4];const d=a;let p;e[5]!==o?(p={paddingLeft:o},e[5]=o,e[6]=p):p=e[6];let g;e[7]!==d?(g=C=>{C.preventDefault(),d()},e[7]=d,e[8]=g):g=e[8];let h;e[9]===Symbol.for("react.memo_cache_sentinel")?(h=C=>f(C.target.value),e[9]=h):h=e[9];let b;e[10]!==i?(b=C=>{C.stopPropagation(),C.key==="Escape"&&i()},e[10]=i,e[11]=b):b=e[11];let j;e[12]!==c?(j=c("sessions.sidebar.session.rename.save"),e[12]=c,e[13]=j):j=e[13];let y;e[14]!==c?(y=c("sessions.sidebar.session.menu.rename"),e[14]=c,e[15]=y):y=e[15];let A;e[16]===Symbol.for("react.memo_cache_sentinel")?(A={minHeight:0},e[16]=A):A=e[16];let S;e[17]!==b||e[18]!==j||e[19]!==y||e[20]!==u?(S=t.jsx("input",{autoFocus:!0,value:u,onChange:h,onKeyDown:b,"aria-label":j,placeholder:y,className:"min-w-0 flex-1 bg-transparent text-[16px] typography-ui-label text-foreground outline-none placeholder:text-muted-foreground",style:A,enterKeyHint:"done"}),e[17]=b,e[18]=j,e[19]=y,e[20]=u,e[21]=S):S=e[21];let E;e[22]!==c?(E=c("sessions.sidebar.session.rename.save"),e[22]=c,e[23]=E):E=e[23];let T,k;e[24]===Symbol.for("react.memo_cache_sentinel")?(T={touchAction:"manipulation",minHeight:0,minWidth:0},k=t.jsx(ee,{name:"check",className:"size-4"}),e[24]=T,e[25]=k):(T=e[24],k=e[25]);let N;e[26]!==E?(N=t.jsx("button",{type:"submit","aria-label":E,className:"flex size-8 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",style:T,children:k}),e[26]=E,e[27]=N):N=e[27];let w;e[28]!==c?(w=c("sessions.sidebar.session.rename.cancel"),e[28]=c,e[29]=w):w=e[29];let P,x;e[30]===Symbol.for("react.memo_cache_sentinel")?(P={touchAction:"manipulation",minHeight:0,minWidth:0},x=t.jsx(ee,{name:"close",className:"size-4"}),e[30]=P,e[31]=x):(P=e[30],x=e[31]);let _;e[32]!==i||e[33]!==w?(_=t.jsx("button",{type:"button",onClick:i,"aria-label":w,className:"flex size-8 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",style:P,children:x}),e[32]=i,e[33]=w,e[34]=_):_=e[34];let D;return e[35]!==N||e[36]!==_||e[37]!==p||e[38]!==g||e[39]!==S?(D=t.jsxs("form",{className:"flex h-9 min-w-0 flex-1 items-center gap-2 pr-2",style:p,onSubmit:g,children:[S,N,_]}),e[35]=N,e[36]=_,e[37]=p,e[38]=g,e[39]=S,e[40]=D):D=e[40],D},Wn=n=>{const e=ce.c(51),{session:s,active:o,indent:r,contextLabel:i,hasChildren:c,expanded:u,onToggleChildren:f,onSelect:a,revealed:d,onRevealedChange:p,confirmingDelete:g,onArchive:h,onRequestDelete:b,onConfirmDelete:j,renaming:y,onRequestRename:A,onSubmitRename:S,onCancelRename:E}=n,T=c===void 0?!1:c,k=u===void 0?!1:u,N=d===void 0?!1:d,w=g===void 0?!1:g,P=y===void 0?!1:y,{t:x}=de();let _;e[0]!==s?(_=Jl(Yl(s)),e[0]=s,e[1]=_):_=e[1];const D=_,C=s.title?.trim()||x("mobile.sessions.untitled"),R=!!(p&&h),B=or(s.id),F=ir(s.id),v=B?.type??"idle",I=v==="busy"||v==="retry",$=!I&&F>0&&!o,z=ar(s.id,I),O=(I||$)&&z,te=l.useRef(null),Q=l.useRef(null),se=l.useRef(!1),M=l.useRef(0),W=l.useRef(N);let G;e[2]===Symbol.for("react.memo_cache_sentinel")?(G=(Ee,De)=>{const xe=te.current;xe&&(xe.style.transition=De?`transform ${Vr}ms ease-out`:"none",xe.style.transform=Ee===0?"none":`translateX(${Ee}px)`,M.current=Ee)},e[2]=G):G=e[2];const q=G;let X,Z;e[3]!==N?(X=()=>{W.current=N,q(N?-ut:0,!0)},Z=[q,N],e[3]=N,e[4]=X,e[5]=Z):(X=e[4],Z=e[5]),l.useEffect(X,Z);let ie;e[6]!==R?(ie=Ee=>{if(!R||Ee.touches.length!==1)return;const De=Ee.touches[0];Q.current={x:De.clientX,y:De.clientY},se.current=!1},e[6]=R,e[7]=ie):ie=e[7];const fe=ie;let ae;e[8]!==R?(ae=Ee=>{if(!R||!Q.current)return;const De=Ee.touches[0],xe=De.clientX-Q.current.x,L=De.clientY-Q.current.y;if(!se.current){if(Math.abs(xe)<8||Math.abs(xe)<=Math.abs(L))return;se.current=!0}const H=W.current?-ut:0,oe=Math.min(0,Math.max(-ut,H+xe));q(oe,!1)},e[8]=R,e[9]=ae):ae=e[9];const V=ae;let ne;e[10]!==p?(ne=()=>{if(Q.current=null,!se.current)return;se.current=!1;const Ee=M.current<-ut/2;q(Ee?-ut:0,!0),Ee!==W.current&&p?.(Ee)},e[10]=p,e[11]=ne):ne=e[11];const K=ne,pe=o||void 0,Te="relative overflow-hidden";let be;e[12]!==R?(be=R?{touchAction:"pan-y"}:void 0,e[12]=R,e[13]=be):be=e[13];const Ne=R?t.jsxs("div",{className:"absolute inset-y-0 right-0 flex items-stretch",style:{width:ut},"aria-hidden":!N,children:[t.jsx("button",{type:"button",tabIndex:N?0:-1,className:"flex flex-1 items-center justify-center text-muted-foreground transition-colors active:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary","aria-label":x("mobile.sessions.renameSessionAria",{title:C}),onClick:A,style:{touchAction:"manipulation"},children:t.jsx(vs,{className:"size-[18px]"})}),t.jsx("button",{type:"button",tabIndex:N?0:-1,className:"flex flex-1 items-center justify-center text-muted-foreground transition-colors active:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary","aria-label":x("mobile.sessions.archiveSessionAria",{title:C}),onClick:h,style:{touchAction:"manipulation"},children:t.jsx(ba,{className:"size-[18px]"})}),t.jsx("button",{type:"button",tabIndex:N?0:-1,className:J("flex flex-1 items-center justify-center transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-destructive",w?"rounded-lg bg-destructive text-destructive-foreground":"text-[var(--status-error)] active:opacity-80"),"aria-label":w?x("mobile.sessions.confirmDeleteSessionAria",{title:C}):x("mobile.sessions.deleteSessionAria",{title:C}),onClick:w?j:b,style:{touchAction:"manipulation"},children:t.jsx(Qt,{className:"size-[18px]"})})]}):null,Me=R&&"bg-background",Ce=o&&(R?"bg-[color-mix(in_srgb,var(--primary)_10%,var(--background))]":"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]");let Ae;e[14]!==Me||e[15]!==Ce?(Ae=J("relative flex items-center gap-1 transition-colors",Me,Ce),e[14]=Me,e[15]=Ce,e[16]=Ae):Ae=e[16];let we;e[17]!==k||e[18]!==T||e[19]!==r||e[20]!==I||e[21]!==f||e[22]!==$||e[23]!==x?(we=I||$||T&&f?t.jsx("button",{type:"button",className:"absolute z-10 flex w-6 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",style:{left:Math.max(r-32,2),top:0,bottom:0,touchAction:"manipulation"},"aria-label":x(k?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),disabled:!T||!f,onClick:Ee=>{Ee.stopPropagation(),f?.()},children:I||$?t.jsx("span",{className:J("size-1.5 rounded-full",I?"bg-primary":"bg-[var(--status-info)]"),"aria-hidden":!0}):t.jsx(zs,{className:J("size-[18px] transition-transform duration-150",k?"rotate-0":"-rotate-90")})}):null,e[17]=k,e[18]=T,e[19]=r,e[20]=I,e[21]=f,e[22]=$,e[23]=x,e[24]=we):we=e[24];let Fe;e[25]!==o||e[26]!==i||e[27]!==r||e[28]!==I||e[29]!==E||e[30]!==p||e[31]!==a||e[32]!==S||e[33]!==P||e[34]!==s.id||e[35]!==O||e[36]!==D||e[37]!==C?(Fe=P&&S&&E?t.jsx(Ql,{initialTitle:C,indent:r,onSubmit:S,onCancel:E}):t.jsx("button",{type:"button",className:J("flex min-w-0 flex-1 items-center gap-2.5 pr-3.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",i?"min-h-10 py-1":"h-9"),style:{paddingLeft:r,touchAction:"manipulation"},onClick:()=>{if(W.current){p?.(!1);return}a()},children:t.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[t.jsxs("span",{className:"flex items-center gap-2.5",children:[t.jsx("span",{className:J("block min-w-0 flex-1 truncate typography-ui-label",o?"text-primary":"text-foreground"),children:C}),O?t.jsx(br,{sessionId:s.id,running:I,className:"typography-micro"}):D?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:D}):null]}),i?t.jsx("span",{className:"block truncate typography-micro text-muted-foreground",children:i}):null]})}),e[25]=o,e[26]=i,e[27]=r,e[28]=I,e[29]=E,e[30]=p,e[31]=a,e[32]=S,e[33]=P,e[34]=s.id,e[35]=O,e[36]=D,e[37]=C,e[38]=Fe):Fe=e[38];let Ue;e[39]!==Ae||e[40]!==we||e[41]!==Fe?(Ue=t.jsxs("div",{ref:te,className:Ae,children:[we,Fe]}),e[39]=Ae,e[40]=we,e[41]=Fe,e[42]=Ue):Ue=e[42];let Ve;return e[43]!==K||e[44]!==V||e[45]!==fe||e[46]!==pe||e[47]!==be||e[48]!==Ne||e[49]!==Ue?(Ve=t.jsxs("div",{"data-active-session":pe,className:Te,onTouchStart:fe,onTouchMove:V,onTouchEnd:K,onTouchCancel:K,style:be,children:[Ne,Ue]}),e[43]=K,e[44]=V,e[45]=fe,e[46]=pe,e[47]=be,e[48]=Ne,e[49]=Ue,e[50]=Ve):Ve=e[50],Ve},Zl=n=>{const e=ce.c(11),{indent:s,onClick:o}=n,{t:r}=de();let i;e[0]!==s?(i={paddingLeft:s,touchAction:"manipulation"},e[0]=s,e[1]=i):i=e[1];let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=t.jsx(zs,{className:"size-4"}),e[2]=c):c=e[2];let u;e[3]!==r?(u=r("sessions.sidebar.group.showMore"),e[3]=r,e[4]=u):u=e[4];let f;e[5]!==u?(f=t.jsx("span",{className:"typography-micro",children:u}),e[5]=u,e[6]=f):f=e[6];let a;return e[7]!==o||e[8]!==i||e[9]!==f?(a=t.jsxs("button",{type:"button",className:"flex min-h-9 w-full items-center gap-2 py-1 pr-3 text-left text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",style:i,onClick:o,children:[c,f]}),e[7]=o,e[8]=i,e[9]=f,e[10]=a):a=e[10],a},ec=n=>{const e=ce.c(11),{indent:s,onClick:o}=n,{t:r}=de();let i;e[0]!==s?(i={paddingLeft:s,touchAction:"manipulation"},e[0]=s,e[1]=i):i=e[1];let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=t.jsx(xa,{className:"size-4"}),e[2]=c):c=e[2];let u;e[3]!==r?(u=r("sessions.sidebar.group.showFewer"),e[3]=r,e[4]=u):u=e[4];let f;e[5]!==u?(f=t.jsx("span",{className:"typography-micro",children:u}),e[5]=u,e[6]=f):f=e[6];let a;return e[7]!==o||e[8]!==i||e[9]!==f?(a=t.jsxs("button",{type:"button",className:"flex min-h-9 w-full items-center gap-2 py-1 pr-3 text-left text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",style:i,onClick:o,children:[c,f]}),e[7]=o,e[8]=i,e[9]=f,e[10]=a):a=e[10],a},tc=n=>{const e=ce.c(29),{worktree:s}=n,{t:o}=de();let r;e[0]!==s.path?(r=Se(s.path),e[0]=s.path,e[1]=r):r=e[1];const i=r;let c;e[2]!==i?(c={id:i},e[2]=i,e[3]=c):c=e[3];const{attributes:u,listeners:f,setNodeRef:a,transform:d,transition:p,isDragging:g}=Gs(c),h=s.branch||s.label||s.path;let b;e[4]!==d?(b=Ks.Transform.toString(d),e[4]=d,e[5]=b):b=e[5];const j=g?10:1;let y;e[6]!==b||e[7]!==j||e[8]!==p?(y={transform:b,transition:p,zIndex:j},e[6]=b,e[7]=j,e[8]=p,e[9]=y):y=e[9];const A=g&&"shadow-lg shadow-black/20";let S;e[10]!==A?(S=J("flex items-center gap-1 rounded-xl bg-background px-1 py-1",A),e[10]=A,e[11]=S):S=e[11];let E;e[12]!==h||e[13]!==o?(E=o("mobile.sessions.dragHandleAria",{label:h}),e[12]=h,e[13]=o,e[14]=E):E=e[14];let T;e[15]===Symbol.for("react.memo_cache_sentinel")?(T=t.jsx(Ms,{className:"size-4"}),e[15]=T):T=e[15];let k;e[16]!==u||e[17]!==f||e[18]!==E?(k=t.jsx("button",{type:"button",className:"flex size-8 shrink-0 cursor-grab touch-none items-center justify-center rounded-lg text-muted-foreground/70 transition-colors hover:text-foreground active:cursor-grabbing","aria-label":E,...u,...f,children:T}),e[16]=u,e[17]=f,e[18]=E,e[19]=k):k=e[19];let N;e[20]===Symbol.for("react.memo_cache_sentinel")?(N=t.jsx(ee,{name:"git-branch",className:"size-4 shrink-0 text-muted-foreground"}),e[20]=N):N=e[20];let w;e[21]!==h?(w=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label font-bold text-muted-foreground",children:h}),e[21]=h,e[22]=w):w=e[22];let P;return e[23]!==a||e[24]!==k||e[25]!==w||e[26]!==y||e[27]!==S?(P=t.jsxs("div",{ref:a,style:y,className:S,children:[k,N,w]}),e[23]=a,e[24]=k,e[25]=w,e[26]=y,e[27]=S,e[28]=P):P=e[28],P},sc=n=>{const e=ce.c(61),{project:s,totalSessions:o,expanded:r,onToggleExpanded:i,onReorderWorktrees:c}=n,{t:u}=de();let f;e[0]!==s.id?(f={id:s.id},e[0]=s.id,e[1]=f):f=e[1];const{attributes:a,listeners:d,setNodeRef:p,transform:g,transition:h,isDragging:b}=Gs(f);let j;e[2]===Symbol.for("react.memo_cache_sentinel")?(j={activationConstraint:{distance:8}},e[2]=j):j=e[2];let y;e[3]===Symbol.for("react.memo_cache_sentinel")?(y={coordinateGetter:Ws},e[3]=y):y=e[3];const A=Os(yt(Bs,j),yt(Ls,y)),S=s.worktrees.length>0;let E;e[4]!==c||e[5]!==s.worktrees?(E=M=>{const{active:W,over:G}=M;if(!G||W.id===G.id)return;const q=s.worktrees.map(ic),X=q.indexOf(String(W.id)),Z=q.indexOf(String(G.id));if(X<0||Z<0)return;const ie=[...q],[fe]=ie.splice(X,1);ie.splice(Z,0,fe),c(ie)},e[4]=c,e[5]=s.worktrees,e[6]=E):E=e[6];const T=E;let k;e[7]!==g?(k=Ks.Transform.toString(g),e[7]=g,e[8]=k):k=e[8];const N=b?10:1;let w;e[9]!==k||e[10]!==N||e[11]!==h?(w={transform:k,transition:h,zIndex:N},e[9]=k,e[10]=N,e[11]=h,e[12]=w):w=e[12];const P=b&&"shadow-lg shadow-black/20";let x;e[13]!==P?(x=J("rounded-2xl border border-border/70 bg-[var(--surface-elevated)] px-1.5 py-1.5 transition-colors",P),e[13]=P,e[14]=x):x=e[14];let _;e[15]!==s.label||e[16]!==u?(_=u("mobile.sessions.dragHandleAria",{label:s.label}),e[15]=s.label,e[16]=u,e[17]=_):_=e[17];let D;e[18]===Symbol.for("react.memo_cache_sentinel")?(D=t.jsx(Ms,{className:"size-4"}),e[18]=D):D=e[18];let C;e[19]!==a||e[20]!==d||e[21]!==_?(C=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 cursor-grab touch-none items-center justify-center rounded-xl text-muted-foreground/70 transition-colors hover:text-foreground active:cursor-grabbing","aria-label":_,...a,...d,children:D}),e[19]=a,e[20]=d,e[21]=_,e[22]=C):C=e[22];let R;e[23]!==r||e[24]!==s.label||e[25]!==u?(R=r?u("sessions.sidebar.group.collapseAria",{label:s.label}):u("sessions.sidebar.group.expandAria",{label:s.label}),e[23]=r,e[24]=s.label,e[25]=u,e[26]=R):R=e[26];const B=!S;let F;e[27]===Symbol.for("react.memo_cache_sentinel")?(F={touchAction:"manipulation"},e[27]=F):F=e[27];let v;e[28]!==s?(v=t.jsx(Ns,{project:s}),e[28]=s,e[29]=v):v=e[29];let I;e[30]!==s.label?(I=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:s.label}),e[30]=s.label,e[31]=I):I=e[31];let $;e[32]!==o?($=t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:o}),e[32]=o,e[33]=$):$=e[33];let z;e[34]!==r||e[35]!==S?(z=S?t.jsx(zs,{className:J("size-4 shrink-0 text-muted-foreground transition-transform",r&&"rotate-180")}):null,e[34]=r,e[35]=S,e[36]=z):z=e[36];let O;e[37]!==r||e[38]!==i||e[39]!==R||e[40]!==B||e[41]!==v||e[42]!==I||e[43]!==$||e[44]!==z?(O=t.jsxs("button",{type:"button",className:"flex min-h-9 min-w-0 flex-1 items-center gap-2 rounded-xl px-1 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary",onClick:i,"aria-expanded":r,"aria-label":R,disabled:B,style:F,children:[v,I,$,z]}),e[37]=r,e[38]=i,e[39]=R,e[40]=B,e[41]=v,e[42]=I,e[43]=$,e[44]=z,e[45]=O):O=e[45];let te;e[46]!==C||e[47]!==O?(te=t.jsxs("div",{className:"flex items-center gap-1",children:[C,O]}),e[46]=C,e[47]=O,e[48]=te):te=e[48];let Q;e[49]!==r||e[50]!==T||e[51]!==S||e[52]!==s.worktrees||e[53]!==A?(Q=r&&S?t.jsx($s,{sensors:A,collisionDetection:Fs,onDragEnd:T,children:t.jsx(Us,{items:s.worktrees.map(ac),strategy:Vs,children:t.jsx("div",{className:"mt-1 flex flex-col gap-0.5 pl-3",children:s.worktrees.map(lc)})})}):null,e[49]=r,e[50]=T,e[51]=S,e[52]=s.worktrees,e[53]=A,e[54]=Q):Q=e[54];let se;return e[55]!==p||e[56]!==te||e[57]!==Q||e[58]!==w||e[59]!==x?(se=t.jsxs("div",{ref:p,style:w,className:x,children:[te,Q]}),e[55]=p,e[56]=te,e[57]=Q,e[58]=w,e[59]=x,e[60]=se):se=e[60],se},Un=({open:n,onOpenChange:e,variant:s="drawer",footer:o})=>{const{t:r}=de(),{git:i}=Is(),c=lr(),u=Es(m=>m.activeSessions),f=nr(l.useCallback(m=>n||s==="sidebar"?m.ids:Hl,[n,s])),a=rr(l.useCallback(m=>n||s==="sidebar"?m.rankById:Vo,[n,s])),d=Le(m=>m.projects),p=Le(m=>m.activeProjectId),g=tt(m=>m.currentDirectory),h=ke(m=>m.currentSessionId),b=ke(m=>m.setCurrentSession),j=ke(m=>m.archiveSession),y=ke(m=>m.deleteSession),A=ke(m=>m.updateSessionTitle),S=ke(m=>m.openNewSessionDraft),E=Le(m=>m.setActiveProject),T=Le(m=>m.setActiveProjectIdOnly),k=Le(m=>m.reorderProjects),N=Le(m=>m.removeProject),w=Kt(m=>m.projectExpanded),P=Kt(m=>m.worktreeExpanded),x=Kt(m=>m.setProjectExpanded),_=Kt(m=>m.setWorktreeExpanded),D=ks(m=>m.orderByProject),C=ks(m=>m.setWorktreeOrder),R=zn(m=>m.expandedParents),B=zn(m=>m.toggleParent),[F,v]=l.useState(""),[I,$]=l.useState(null),[z,O]=l.useState(null),[te,Q]=l.useState(null),[se,M]=l.useState(null),[W,G]=l.useState(null),[q,X]=l.useState(null),[Z,ie]=l.useState(null),[fe,ae]=l.useState(0),[V,ne]=l.useState(!1),[K,pe]=l.useState(!1),[Te,be]=l.useState(null),[Ne,Me]=l.useState(()=>new Map(ke.getState().availableWorktreesByProject)),[Ce,Ae]=l.useState(()=>{const m=new Set;for(const[U,Y]of ke.getState().availableWorktreesByProject)Y.length>0&&m.add(U);return m}),[we,Fe]=l.useState(!1),[Ue,Ve]=l.useState(new Set),[Ee,De]=l.useState(new Map);l.useEffect(()=>{if(!n){v(""),Fe(!1),Ve(new Set),De(new Map),$(null),O(null),Q(null),M(null),G(null),X(null);return}Ts(c)},[n]),l.useEffect(()=>{we||Ve(new Set)},[we]),l.useEffect(()=>{if(!n||d.length===0)return;let m=!1;return(async()=>{const Y=await Promise.all(d.map(async me=>{const ue=Se(me.path);if(!ue)return null;const Ie=await i.checkIsGitRepository(ue).catch(()=>!1),$e=Ie?await pr({id:me.id,path:ue}).catch(()=>[]):[];return[ue,$e,Ie]}));if(m)return;const re=new Map,he=new Set;for(const me of Y)me&&(re.set(me[0],me[1]),me[2]&&he.add(me[0]));Me(hr(d,re)),Ae(he)})(),()=>{m=!0}},[i,n,d,fe]);const xe=l.useMemo(()=>d.map(m=>({id:m.id,label:m.label?.trim()||ms(m.path),path:Se(m.path),icon:m.icon,color:m.color,iconImage:m.iconImage,iconBackground:m.iconBackground,isGitRepo:Ce.has(Se(m.path)),worktrees:Fl(D[m.id],Ne.get(Se(m.path))??[])})),[Ce,d,D,Ne]),L=l.useMemo(()=>{const m=new Map(c.map(re=>[re.id,re])),U=u.map(re=>{const he=m.get(re.id);return he?Go(he,re):re}),Y=new Set(U.map(re=>re.id));for(const re of c)Y.has(re.id)||U.push(re);return U.filter(re=>!re.time?.archived)},[u,c]),{projectSessions:H,chatSessions:oe}=l.useMemo(()=>qi(L,!1),[L]),je=l.useMemo(()=>({key:Pt,label:"",path:"",worktree:null,sessions:us(oe,f,a)}),[oe,f,a]),Ye=`${Pt}::${Pt}`,Nt=l.useMemo(()=>oe.filter(m=>!ct(m)).length,[oe]),_e=F.trim().toLowerCase(),is=l.useRef(null);l.useEffect(()=>{if(!n)return;const m=window.requestAnimationFrame(()=>{const U=is.current;if(!U)return;(U.querySelector('[data-active-session="true"]')??U.querySelector('[data-active-project="true"]'))?.scrollIntoView({block:"center"})});return()=>window.cancelAnimationFrame(m)},[n]);const it=l.useMemo(()=>{const m=xe.map(Y=>({project:Y,buckets:[],totalSessions:0,isActive:Y.id===p})),U=(Y,re,he)=>{const me=Se(re)||Y.project.path,ue=me||"__root__";let Ie=Y.buckets.find($e=>$e.key===ue);return Ie||(Ie={key:ue,label:he?.branch||ms(me),path:me,worktree:he,sessions:[]},Y.buckets.push(Ie)),Ie};for(const Y of m){U(Y,Y.project.path,null);for(const re of Y.project.worktrees)U(Y,re.path,re)}for(const Y of H){const re=dt(Y);if(!re)continue;const he=Se(re),me=m.find($e=>Ss($e.project,he));if(!me)continue;const ue=Xt(me.project,he);(ue?U(me,ue.path,ue):U(me,me.project.path,null)).sessions.push(Y)}for(const Y of m)for(const re of Y.buckets){re.sessions=us(re.sessions,f,a);for(const he of re.sessions)ct(he)||(Y.totalSessions+=1)}return m},[p,f,H,xe,a]),sn=Se(g),qr=m=>m.isActive?sn===m.project.path?m.project.path:m.project.worktrees.find(Y=>Xl(sn,Y.path))?.path??m.project.path:null,Yr=m=>w[m.project.id]??!0,Jr=(m,U)=>P[`${m.project.id}::${U.key}`]??!0,nn=m=>{De(U=>{if(!U.has(m))return U;const Y=new Map(U);return Y.delete(m),Y})},Xr=m=>{De(U=>{let Y=!1;const re=new Map(U),he=`${m}::`;for(const me of re.keys())me.startsWith(he)&&(re.delete(me),Y=!0);return Y?re:U})},Qr=(m,U)=>{De(Y=>{const re=new Map(Y);return re.set(m,U+hs),re})},as=(m,U,Y)=>{const re=new Set(U.sessions.map(ve=>ve.id)),he=new Map;for(const ve of U.sessions){const Ge=ct(ve);if(Ge&&re.has(Ge)){const Et=he.get(Ge)??[];Et.push(ve),he.set(Ge,Et)}}const me=U.sessions.filter(ve=>{const Ge=ct(ve);return!Ge||!re.has(Ge)}),ue=Ee.get(m)??hs,Ie=me.slice(0,ue),$e=me.length-Ie.length,ls=me.length>hs&&$e===0,fn=(ve,Ge)=>{const Et=he.get(ve.id)??[],cs=Et.length>0,mn=!!R[ve.id];return t.jsxs(l.Fragment,{children:[t.jsx(Wn,{session:ve,active:h===ve.id,indent:Ge,hasChildren:cs,expanded:mn,onToggleChildren:cs?()=>B(ve.id):void 0,onSelect:()=>on(ve),revealed:z===ve.id,onRevealedChange:Rt=>eo(ve.id,Rt),confirmingDelete:te===ve.id,onArchive:()=>{to(ve)},onRequestDelete:()=>Q(ve.id),onConfirmDelete:()=>{so(ve)},renaming:se===ve.id,onRequestRename:()=>no(ve.id),onSubmitRename:Rt=>{ro(ve.id,Rt)},onCancelRename:()=>M(null)}),cs&&mn?Et.map(Rt=>fn(Rt,Ge+ql)):null]},ve.id)};return t.jsxs("div",{children:[Ie.map(ve=>fn(ve,Y)),$e>0?t.jsx(Zl,{indent:Y,onClick:()=>Qr(m,Ie.length)}):null,ls?t.jsx(ec,{indent:Y,onClick:()=>nn(m)}):null]})},rn=(m,U)=>{x(m,!U),Xr(m)},Zr=(m,U,Y)=>{_(`${m}::${U}`,!Y),nn(`${m}::${U}`)},on=m=>{const U=dt(m)||null,Y=gs(xe,U??"");if(Y){T(Y.id),x(Y.id,!0);const re=Xt(Y,Se(U??""));re&&_(`${Y.id}::${Se(re.path)}`,!0)}b(m.id,U),e(!1)},eo=(m,U)=>{O(U?m:null),Q(null),G(null),X(null)},Ct=(m,U)=>{G(U?m:null),X(null),O(null),Q(null)},to=async m=>{O(null),Q(null),await j(m.id)?le.success(r("sessions.sidebar.session.archive.success")):le.error(r("sessions.sidebar.session.archive.error"))},so=async m=>{O(null),Q(null),await y(m.id)?le.success(r("sessions.sidebar.session.delete.success")):le.error(r("sessions.sidebar.session.delete.error"))},no=m=>{O(null),Q(null),M(m)},ro=async(m,U)=>{M(null);try{await A(m,U)}catch{le.error(r("mobile.sessions.renameError"))}},oo=()=>{S(),e(!1)},an=m=>{be(m),T(m),pe(!0)},io=Os(yt(Bs,{activationConstraint:{distance:8}}),yt(Ls,{coordinateGetter:Ws})),ao=m=>{const{active:U,over:Y}=m;if(!Y||U.id===Y.id)return;const re=xe.findIndex(me=>me.id===U.id),he=xe.findIndex(me=>me.id===Y.id);re<0||he<0||k(re,he)},lo=m=>{Ve(U=>{const Y=new Set(U);return Y.has(m)?Y.delete(m):Y.add(m),Y})},co=l.useCallback(m=>{const U=dt(m);if(Ko(U))return r("mobile.sessions.section.chats");const Y=gs(xe,U);if(!Y)return ms(U)||U;const re=Xt(Y,Se(U));return re?.branch?`${Y.label} · ${re.branch}`:Y.label},[xe,r]),uo=m=>{E(m.id),e(!1)},fo=l.useMemo(()=>_e?it.filter(m=>mr([m.project.label,m.project.path],_e)?!0:m.buckets.some(U=>U.sessions.some(Y=>bs(Y,m.project.label,_e)))):it,[_e,it]),Wt=l.useMemo(()=>_e?us(L.filter(m=>{if(ct(m))return!1;const U=dt(m),Y=gs(xe,U);return bs(m,Y?.label??"",_e)}),f,a):[],[_e,f,xe,a,L]),Ut=l.useMemo(()=>_e?Ho(xe,_e,m=>[m.label,m.path]).map(m=>({...m,sessionCount:L.filter(U=>{if(ct(U))return!1;const Y=Se(dt(U));return Ss(m,Y)}).length})):[],[_e,xe,L]),mo=_e&&Wt.length===0&&Ut.length===0,ln=!_e&&xe.length>1?t.jsx(ye,{type:"button",variant:"chip",size:"sm","aria-label":r(we?"mobile.sessions.doneEditing":"mobile.sessions.editOrder"),"aria-pressed":we,onClick:()=>Fe(m=>!m),style:{touchAction:"manipulation"},children:we?t.jsx(xr,{className:"size-4"}):t.jsx(vs,{className:"size-4"})}):null,cn=!we&&xe.length>0?t.jsxs(ye,{type:"button",variant:"default",size:"sm","aria-label":r("mobile.sessions.newChat"),onClick:oo,style:{touchAction:"manipulation"},children:[t.jsx(ga,{className:"size-4"}),r("mobile.sessions.newChat")]}):null,un=we?null:t.jsx(ye,{type:"button",variant:"chip",size:"sm","aria-label":r("sessions.sidebar.header.actions.addProject"),title:r("sessions.sidebar.header.actions.addProject"),onClick:()=>ne(!0),style:{touchAction:"manipulation"},children:t.jsx(vn,{className:"size-4"})}),Vt=cn||un||ln?t.jsxs(t.Fragment,{children:[cn,un,ln]}):null,dn=t.jsxs("div",{ref:is,className:"flex min-h-0 flex-1 flex-col",children:[t.jsxs(_s,{className:"min-h-0 flex-1 overflow-y-auto pb-4",children:[t.jsx("div",{className:J("px-4 pb-2 pt-1",we&&"hidden"),children:t.jsxs("div",{className:"relative",children:[t.jsx(yr,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(As,{value:F,onChange:m=>v(m.target.value),placeholder:r("mobile.sessions.search.placeholder"),className:J("h-11 pl-9",F&&"pr-10")}),F?t.jsx("button",{type:"button",className:"absolute right-1.5 top-1/2 flex size-8 -translate-y-1/2 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":r("mobile.sessions.clearSearchAria"),onClick:()=>v(""),style:{touchAction:"manipulation"},children:t.jsx(vr,{className:"size-4"})}):null]})}),xe.length===0&&oe.length===0?t.jsx(Kn,{title:r("mobile.sessions.empty.noProjectsTitle"),description:r("mobile.sessions.empty.noProjectsDescription"),action:t.jsxs("button",{type:"button",className:"flex items-center justify-center gap-2 rounded-2xl bg-primary px-5 py-3 typography-ui-label text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:()=>ne(!0),children:[t.jsx(vn,{className:"size-4"}),r("sessions.sidebar.header.actions.addProject")]})}):mo?t.jsx(Kn,{title:r("mobile.sessions.empty.searchTitle"),description:r("mobile.sessions.empty.searchDescription")}):_e&&!we?t.jsxs("div",{className:"flex flex-col gap-3 px-3 pt-2",children:[Wt.length>0?t.jsxs("section",{children:[t.jsxs("div",{className:"flex items-center justify-between px-1 pb-1.5",children:[t.jsx("span",{className:"typography-micro font-semibold uppercase tracking-wider text-muted-foreground",children:r("mobile.sessions.search.section.sessions")}),t.jsx("span",{className:"typography-micro text-muted-foreground tabular-nums",children:Wt.length})]}),t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:Wt.map((m,U)=>t.jsx("div",{className:J(U>0&&"border-t border-border/70"),children:t.jsx(Wn,{session:m,active:h===m.id,indent:12,contextLabel:co(m),onSelect:()=>on(m)})},m.id))})]}):null,Ut.length>0?t.jsxs("section",{children:[t.jsxs("div",{className:"flex items-center justify-between px-1 pb-1.5",children:[t.jsx("span",{className:"typography-micro font-semibold uppercase tracking-wider text-muted-foreground",children:r("mobile.sessions.search.section.projects")}),t.jsx("span",{className:"typography-micro text-muted-foreground tabular-nums",children:Ut.length})]}),t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:Ut.map((m,U)=>t.jsxs("div",{className:J("flex items-center",U>0&&"border-t border-border/70"),children:[t.jsxs("button",{type:"button",className:"flex min-h-12 min-w-0 flex-1 items-center gap-3 px-3 py-1.5 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",onClick:()=>uo(m),style:{touchAction:"manipulation"},children:[t.jsx(Ns,{project:m}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:m.label}),t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:m.sessionCount})]}),m.isGitRepo?t.jsx($n,{className:"mr-2",onClick:()=>an(m.id)}):null]},m.id))})]}):null]}):we?t.jsxs("div",{className:"flex flex-col gap-2 px-3 py-2",children:[t.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:r("mobile.sessions.editOrderHint")}),t.jsx($s,{sensors:io,collisionDetection:Fs,onDragEnd:ao,children:t.jsx(Us,{items:xe.map(m=>m.id),strategy:Vs,children:t.jsx("div",{className:"flex flex-col gap-1.5",children:xe.map(m=>{const U=it.find(Y=>Y.project.id===m.id);return t.jsx(sc,{project:m,totalSessions:U?.totalSessions??0,expanded:Ue.has(m.id),onToggleExpanded:()=>lo(m.id),onReorderWorktrees:Y=>C(m.id,Y)},m.id)})})})})]}):t.jsxs("div",{className:"flex flex-col",children:[(()=>{const m=w[Pt]??!0,U=r("mobile.sessions.section.chats");return t.jsxs("section",{children:[t.jsx("div",{className:"flex min-h-12 w-full items-center",children:t.jsxs("button",{type:"button",className:"flex min-h-12 min-w-0 flex-1 items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",onClick:()=>{if(W){Ct(W,!1);return}rn(Pt,m)},"aria-expanded":m,"aria-label":m?r("sessions.sidebar.group.collapseAria",{label:U}):r("sessions.sidebar.group.expandAria",{label:U}),style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center overflow-hidden rounded-lg bg-[var(--surface-muted)] text-muted-foreground",children:t.jsx(ee,{name:"chat-4",className:"size-4"})}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground",children:U}),t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:Nt})]})}),m?t.jsx("div",{className:"pb-2",children:je.sessions.length>0?as(Ye,je,qt):t.jsx("p",{className:"px-3 pb-1 typography-micro text-muted-foreground",style:{paddingLeft:qt},children:r("sessions.sidebar.activity.chatsEmpty")})}):null]})})(),fo.map(m=>{const U=Yr(m),Y=_e?m.buckets.filter(he=>he.sessions.some(me=>bs(me,m.project.label,_e))):m.buckets,re=qr(m);return t.jsxs("section",{className:"border-t border-border/70",children:[t.jsx(Fn,{actionsWidth:96,revealed:W===`project:${m.project.id}`,onRevealedChange:he=>Ct(`project:${m.project.id}`,he),actions:t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",tabIndex:W===`project:${m.project.id}`?0:-1,className:"flex flex-1 items-center justify-center text-muted-foreground transition-colors active:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary","aria-label":r("mobile.sessions.editProjectAria",{label:m.project.label}),onClick:()=>{G(null),$(m.project.id)},style:{touchAction:"manipulation"},children:t.jsx(vs,{className:"size-[18px]"})}),t.jsx("button",{type:"button",tabIndex:W===`project:${m.project.id}`?0:-1,className:J("flex flex-1 items-center justify-center transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-destructive",q===m.project.id?"rounded-lg bg-destructive text-destructive-foreground":"text-[var(--status-error)] active:opacity-80"),"aria-label":q===m.project.id?r("mobile.sessions.confirmRemoveProjectAria",{label:m.project.label}):r("mobile.sessions.removeProjectAria",{label:m.project.label}),onClick:()=>{if(q===m.project.id){G(null),X(null),N(m.project.id),le.success(r("mobile.sessions.toast.projectRemoved",{label:m.project.label}));return}X(m.project.id)},style:{touchAction:"manipulation"},children:t.jsx(Qt,{className:"size-[18px]"})})]}),children:t.jsxs("div",{"data-active-project":m.isActive||void 0,className:"flex min-h-12 w-full items-center",children:[t.jsxs("button",{type:"button",className:"flex min-h-12 min-w-0 flex-1 items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",onClick:()=>{if(W){Ct(W,!1);return}rn(m.project.id,U)},"aria-expanded":U,"aria-label":U?r("sessions.sidebar.group.collapseAria",{label:m.project.label}):r("sessions.sidebar.group.expandAria",{label:m.project.label}),style:{touchAction:"manipulation"},children:[t.jsx(Ns,{project:m.project}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground",children:m.project.label}),m.isActive?t.jsx(Bn,{ariaLabel:r("mobile.sessions.activeProjectAria")}):null,t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:m.totalSessions})]}),m.project.isGitRepo?t.jsx($n,{className:"mr-2",onClick:()=>an(m.project.id)}):null]})}),U?t.jsx("div",{className:"pb-2",children:(()=>{const he=Y.find(ue=>ue.worktree===null),me=Y.filter(ue=>ue.worktree!==null);return t.jsxs(t.Fragment,{children:[he&&he.sessions.length>0?as(`${m.project.id}::${he.key}`,he,qt):null,me.map(ue=>{const Ie=Jr(m,ue),$e=re===ue.path;return t.jsxs("div",{children:[t.jsx(Fn,{actionsWidth:48,revealed:W===`wt:${ue.key}`,onRevealedChange:ls=>Ct(`wt:${ue.key}`,ls),actions:t.jsx("button",{type:"button",tabIndex:W===`wt:${ue.key}`?0:-1,className:"flex flex-1 items-center justify-center text-[var(--status-error)] transition-colors active:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-destructive","aria-label":r("mobile.projectEdit.deleteWorktreeAria",{label:ue.label}),onClick:()=>{G(null),ue.worktree&&ie({project:m.project,worktree:ue.worktree})},style:{touchAction:"manipulation"},children:t.jsx(Qt,{className:"size-[18px]"})}),children:t.jsxs("button",{type:"button",className:"flex min-h-10 w-full items-center gap-2 px-3 py-1 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",onClick:()=>{if(W){Ct(W,!1);return}Zr(m.project.id,ue.key,Ie)},"aria-expanded":Ie,"aria-label":Ie?r("sessions.sidebar.group.collapseAria",{label:ue.label}):r("sessions.sidebar.group.expandAria",{label:ue.label}),style:{touchAction:"manipulation"},children:[t.jsx(ee,{name:"git-branch",className:J("size-4 shrink-0",$e?"text-primary":"text-muted-foreground")}),t.jsx("span",{className:J("block min-w-0 flex-1 truncate typography-ui-label font-bold",$e?"text-foreground":"text-muted-foreground"),children:ue.label}),$e?t.jsx(Bn,{ariaLabel:r("mobile.sessions.activeWorktreeAria")}):null,t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:ue.sessions.length})]})}),Ie?as(`${m.project.id}::${ue.key}`,ue,qt):null]},ue.key)})]})})()}):null]},m.project.id)})]})]}),o?t.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-t border-border/70 px-2 pt-1.5",style:{paddingBottom:"calc(0.375rem + var(--oc-safe-area-bottom, 0px))"},children:[o.instanceLabel&&o.onOpenInstances?t.jsxs(ye,{type:"button",variant:"info",size:"lg",className:"min-w-0 shrink justify-start",onClick:o.onOpenInstances,"aria-label":r("mobile.menu.instances"),style:{touchAction:"manipulation"},children:[t.jsx(ee,{name:"server",className:"size-[18px]"}),t.jsx("span",{className:"block min-w-0 truncate",children:o.instanceLabel})]}):t.jsx("div",{className:"min-w-0 flex-1"}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[o.onOpenUpdate?t.jsxs(ye,{type:"button",variant:"default",size:"lg",className:"w-10 px-0",onClick:o.onOpenUpdate,"aria-label":r("mobile.menu.update"),title:r("mobile.menu.update"),style:{touchAction:"manipulation"},children:[t.jsx(ee,{name:"download",className:"size-5"}),t.jsx("span",{className:"absolute right-2 top-2 inline-flex size-2 rounded-full bg-primary","aria-hidden":!0})]}):null,t.jsx(ye,{type:"button",variant:"default",size:"lg",className:"w-10 px-0",onClick:o.onOpenSettings,"aria-label":r("mobile.menu.settings"),title:r("mobile.menu.settings"),style:{touchAction:"manipulation"},children:t.jsx(ee,{name:"settings-3",className:"size-5"})})]})]}):null,t.jsx(Yi,{open:V,onOpenChange:ne}),t.jsx(Ji,{open:K,onOpenChange:m=>{pe(m),m||be(null)},onWorktreeCreated:(m,U)=>{U?.sessionId?b(U.sessionId,m):S({selectedProjectId:Te,directoryOverride:m,preserveDirectoryOverride:!0}),e(!1)}}),t.jsx(Kl,{open:I!==null,project:xe.find(m=>m.id===I)??null,onClose:()=>$(null),onWorktreesChanged:()=>ae(m=>m+1)}),Z?t.jsx(Ur,{open:!0,project:{id:Z.project.id,path:Z.project.path},worktree:Z.worktree,onClose:()=>ie(null),onDeleted:()=>ae(m=>m+1)}):null]});return s==="sidebar"?n?t.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center justify-between gap-2 border-b border-border/70 px-4",children:[t.jsx("h2",{className:"truncate typography-ui-label font-semibold text-foreground",children:r("mobile.sessions.sheet.title")}),Vt?t.jsx("div",{className:"flex shrink-0 items-center gap-2",children:Vt}):null]}),dn]}):null:t.jsxs(oc,{open:n,onClose:()=>e(!1),ariaLabel:r("mobile.sessions.sheet.title"),children:[t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",children:[t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":r("mobile.surface.closeAria"),onClick:()=>e(!1),style:{touchAction:"manipulation"},children:t.jsx(ee,{name:"close",className:"size-5"})}),t.jsx("h2",{className:"min-w-0 flex-1 truncate px-1 typography-ui-label font-semibold text-foreground",children:r("mobile.sessions.sheet.title")}),Vt?t.jsx("div",{className:"flex shrink-0 items-center gap-2",children:Vt}):null]}),dn]})},Vn="mobile-surface-root",nc=16,Gn=320,rc="cubic-bezier(0.22, 1, 0.36, 1)",oc=({open:n,onClose:e,ariaLabel:s,children:o})=>{const r=l.useRef(null),[i,c]=l.useState(!1),[u,f]=l.useState(n),a=l.useRef(e);if(l.useEffect(()=>{a.current=e},[e]),typeof document<"u"&&!r.current){let d=document.getElementById(Vn);d||(d=document.createElement("div"),d.id=Vn,document.body.appendChild(d)),r.current=d}return l.useEffect(()=>{if(n){f(!0);const p=window.setTimeout(()=>c(!0),nc);return()=>window.clearTimeout(p)}c(!1);const d=window.setTimeout(()=>f(!1),Gn+40);return()=>window.clearTimeout(d)},[n]),l.useEffect(()=>{if(!n)return;const d=document.body.style.overflow;document.body.style.overflow="hidden";const p=g=>{g.key==="Escape"&&a.current()};return document.addEventListener("keydown",p),()=>{document.body.style.overflow=d,document.removeEventListener("keydown",p)}},[n]),r.current?bt.createPortal(t.jsx("section",{role:"dialog","aria-modal":"true","aria-label":s,"aria-hidden":!n,className:"oc-keyboard-inset-surface fixed inset-0 z-50 flex flex-col bg-background text-foreground",style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:i?"none":"translateX(-100%)",transition:`transform ${Gn}ms ${rc}`,visibility:u?"visible":"hidden",pointerEvents:n?"auto":"none"},children:t.jsx("div",{className:"flex h-full min-h-0 flex-col",children:o})}),r.current):null},Kn=n=>{const e=ce.c(10),{title:s,description:o,action:r}=n;let i;e[0]!==s?(i=t.jsx("p",{className:"typography-ui-label text-foreground",children:s}),e[0]=s,e[1]=i):i=e[1];let c;e[2]!==o?(c=o?t.jsx("p",{className:"typography-meta text-muted-foreground",children:o}):null,e[2]=o,e[3]=c):c=e[3];let u;e[4]!==r?(u=r?t.jsx("div",{className:"pt-2",children:r}):null,e[4]=r,e[5]=u):u=e[5];let f;return e[6]!==i||e[7]!==c||e[8]!==u?(f=t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[i,c,u]}),e[6]=i,e[7]=c,e[8]=u,e[9]=f):f=e[9],f};function ic(n){return Se(n.path)}function ac(n){return Se(n.path)}function lc(n){return t.jsx(tc,{worktree:n},Se(n.path))}const cc=(n,e)=>{if(!n)return e("mcpDropdown.status.unknown");switch(n.status){case"connected":return e("mcpDropdown.status.connected");case"failed":return e("mcpDropdown.status.failed",{error:n.error||e("mcpDropdown.status.unknownError")});case"needs_auth":return e("mcpDropdown.status.needsAuth");case"needs_client_registration":return e("mcpDropdown.status.needsRegistration",{error:n.error||""});default:return n.status}},uc=n=>{switch(n?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},dc=({active:n,className:e,headerAction:s,listClassName:o,hideHeader:r=!1,mobileListDensity:i=!1})=>{const{t:c}=de(),f=tt(k=>k.currentDirectory)??null,a=It(k=>k.getStatusForDirectory(f)),d=It(k=>k.refresh),p=It(k=>k.connect),g=It(k=>k.disconnect),h=ht(k=>k.mcpServers),b=ht(k=>k.loadMcpConfigs),[j,y]=l.useState(!1),[A,S]=l.useState(null);l.useEffect(()=>{d({directory:f,silent:!0})},[d,f]),l.useEffect(()=>{b({force:!0})},[b]),l.useEffect(()=>{n&&Promise.all([d({directory:f,silent:!0}),b({force:!0})])},[n,d,f,b]);const E=l.useMemo(()=>{const k=new Set(Object.keys(a));for(const N of h)N?.name&&k.add(N.name);return Array.from(k).sort((N,w)=>N.localeCompare(w))},[h,a]),T=l.useCallback(k=>{if(k?.preventDefault(),j)return;y(!0);const N=new Promise(w=>setTimeout(w,500));Promise.all([d({directory:f}),N]).finally(()=>{y(!1)})},[j,d,f]);return t.jsxs("div",{className:J("w-full",e),children:[r?null:t.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:t.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5",children:[t.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[t.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:c("mcpDropdown.title")}),f&&t.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:f.split("/").pop()||f})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s,t.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:j,onClick:T,"aria-label":c("mcpDropdown.actions.refreshAria"),children:t.jsx(ee,{name:"refresh",className:J("h-4 w-4",j&&"animate-spin")})})]})]})}),t.jsx("div",{className:J("max-h-64 overflow-y-auto",i?"space-y-1 py-3":"px-3 py-2.5",o),children:t.jsxs("div",{className:J(!i&&E.length>0&&"rounded-xl bg-[var(--surface-muted)] p-1.5"),children:[E.map(k=>{const N=a[k],w=uc(N),P=N?.status==="connected",x=A===k,_=cc(N,c);return t.jsxs("div",{className:J("flex items-center justify-between rounded-lg hover:bg-interactive-hover/50",i?"gap-3 px-4 py-3":"gap-2 px-2.5 py-2"),children:[t.jsx("div",{className:"min-w-0 flex-1",children:t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsxs(qo,{children:[t.jsx(Yo,{asChild:!0,children:t.jsx("span",{className:J("rounded-full flex-shrink-0",i?"h-2.5 w-2.5":"h-2 w-2",w==="success"&&"bg-status-success",w==="error"&&"bg-status-error",w==="warning"&&"bg-status-warning",w==="default"&&"bg-muted-foreground/40"),"aria-label":_})}),t.jsx(Jo,{side:"left",children:t.jsx("p",{children:_})})]}),t.jsx("span",{className:J("truncate",i?"text-[17px] leading-6 font-medium":"typography-ui-label"),children:k})]})}),t.jsx(Xo,{checked:P,disabled:x,className:"data-[checked]:bg-status-info",onCheckedChange:async D=>{S(k);try{if(!D){await g(k,f);return}const C=a?.[k]?.status;if(C==="needs_auth"||C==="needs_client_registration"){const{opened:R}=await Qo({name:k,directory:f});R||jn.error(c("mcpDropdown.toast.authorizeOpenFailed"));return}await p(k,f)}catch(C){jn.error(C instanceof Error?C.message:c("mcpDropdown.toast.authorizeFailed"))}finally{S(null)}}})]},k)}),E.length===0&&t.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:c("mcpDropdown.empty.configureInConfig")})]})})]})},fc=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/g,""),mc=n=>{const e=n.index?.trim();return!!(e&&e!=="?")},pc=n=>{const e=n.working_dir?.trim(),s=n.index?.trim();return!!(e||s==="?")},Hn=(n,e)=>e?`${n}\0staged`:n,hc=({onClose:n,initialDiffPath:e,initialDiffStaged:s=!1})=>{const{t:o}=de(),{git:r}=Is(),i=fc(Ds()??null),{rootIsGitRepo:c,gitDirectory:u,nestedRepos:f}=Zo(i||null),a=u??i,d=ei(a||null),p=ti(a||null),g=si(a||null),h=We(L=>L.setActiveDirectory),b=We(L=>L.ensureAll),j=We(L=>L.ensureNestedRepos),y=We(L=>L.selectNestedRepo),A=We(L=>L.fetchStatus),S=We(L=>L.fetchBranches),E=We(L=>L.prefetchDiffs),T=We(L=>L.getDiff),k=We(L=>L.setDiff),[N,w]=l.useState(()=>e?{type:"diff",path:e,staged:s}:{type:"list"});l.useEffect(()=>{e&&w(L=>L.type==="diff"&&L.path===e&&L.staged===s?L:{type:"diff",path:e,staged:s})},[e,s]);const[P,x]=l.useState(null),[_,D]=l.useState(null),[C,R]=l.useState(""),[B,F]=l.useState(new Set),[v,I]=l.useState(!1),[$,z]=l.useState(!1),[O,te]=l.useState([]),[Q,se]=l.useState([]),[M,W]=l.useState([]),[G,q]=l.useState(null),[X,Z]=l.useState(null),[ie,fe]=l.useState(0),ae=l.useMemo(()=>{const L=d?.files??[],H=new Map;for(const oe of L)H.set(oe.path,oe);return Array.from(H.values()).sort((oe,je)=>oe.path.localeCompare(je.path))},[d?.files]),V=l.useMemo(()=>ae.filter(mc),[ae]),ne=l.useMemo(()=>ae.filter(pc),[ae]),K=l.useMemo(()=>{if(M.length>0)return M;const L=d?.tracking?.includes("/")?d.tracking.split("/")[0]:null;return L||G?[{name:L||"origin",fetchUrl:G??"",pushUrl:G??""}]:[]},[G,M,d?.tracking]),pe=We(l.useCallback(L=>!a||N.type!=="diff"?null:L.directories.get(a)?.diffCache.get(Hn(N.path,N.staged))??null,[a,N])),Te=l.useMemo(()=>N.type!=="diff"?null:ae.find(L=>L.path===N.path)??null,[ae,N]),be=l.useCallback(async(L=!0)=>{if(a)try{await Promise.all([A(a,r),S(a,r)])}catch(H){L&&le.error(H instanceof Error?H.message:o("gitView.toast.refreshRepositoryFailed"))}},[a,S,A,r,o]),Ne=l.useCallback(async()=>{if(!a){W([]),q(null);return}try{const[L,H]=await Promise.all([r.getRemotes(a).catch(()=>[]),r.getRemoteUrl?r.getRemoteUrl(a).catch(()=>null):Promise.resolve(null)]);W(L),q(H)}catch{W([]),q(null)}},[a,r]);l.useEffect(()=>{a&&(h(a),b(a,r))},[a,b,r,h]),l.useEffect(()=>{Ne()},[Ne]),l.useEffect(()=>{if(!a||ae.length===0)return;const L=Array.from(new Set([...V.map(oe=>oe.path),...Q,...ae.slice(0,20).map(oe=>oe.path)])).filter(Boolean);if(L.length===0)return;const H=window.setTimeout(()=>{E(a,r,L,{maxFiles:40})},120);return()=>window.clearTimeout(H)},[ae,a,r,E,V,Q]),l.useEffect(()=>{if(N.type!=="diff"){Z(null);return}const L=Hn(N.path,N.staged);if(!a||T(a,L)){Z(null);return}let H=!1;const oe=kt();return Z(null),r.getGitFileDiff(a,{path:N.path,staged:N.staged||void 0}).then(je=>{H||k(a,L,{original:je.original??"",modified:je.modified??"",isBinary:je.isBinary},oe)}).catch(je=>{H||Z(je instanceof Error?je.message:String(je))}),()=>{H=!0}},[a,ie,T,r,N,k]);const Me=async(L,H)=>{if(a){x(L);try{const oe=je=>{const Ye=`${je.name}/`,Nt=d?.tracking?.startsWith(Ye)?d.tracking.slice(Ye.length):void 0;return{remote:je.name,branch:Nt,rebase:!0}};if(L==="fetch"){if(!H)throw new Error(o("mobile.changes.noRemote"));await r.gitFetch(a,{remote:H.name}),le.success(o("gitView.toast.fetchedFromRemote",{name:H.name}))}else if(L==="sync"){if(!H)throw new Error(o("mobile.changes.noRemote"));await r.gitFetch(a,{remote:H.name});const je=await r.getGitStatus(a);if((je.behind??0)>0){if((je.files?.length??0)>0){le.error(o("gitView.toast.commitOrStashBeforeSync"));return}await r.gitPull(a,oe(H))}((await r.getGitStatus(a)).ahead??0)>0&&await r.gitPush(a),le.success(o("gitView.toast.alreadyUpToDate"))}await be(!1),await Ne()}catch(oe){le.error(oe instanceof Error?oe.message:o("gitView.toast.syncActionFailed",{action:o("gitView.sync.syncChanges")}))}finally{x(null)}}},Ce=l.useCallback(async(L,H)=>{if(!(!a||L.length===0))try{H==="stage"?L.length>1?await ni(a,L):await ri(a,L[0]):L.length>1?await oi(a,L):await ii(a,L[0]),await be(!1)}catch(oe){le.error(oe instanceof Error?oe.message:o(H==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed"))}},[a,be,o]),Ae=l.useCallback((L,H=!1)=>{w({type:"diff",path:L,staged:H})},[]),we=l.useCallback(async L=>{if(a){F(H=>new Set(H).add(L));try{await r.revertGitFile(a,L),le.success(o("gitView.toast.revertedFile",{path:L})),await be(!1)}catch(H){le.error(H instanceof Error?H.message:o("gitView.toast.revertFailed"))}finally{F(H=>{const oe=new Set(H);return oe.delete(L),oe})}}},[a,r,be,o]),Fe=l.useCallback(async L=>{if(!a||L.length===0||v)return;const H=Array.from(new Set(L));I(!0),F(new Set(H));try{await Promise.all(H.map(oe=>r.revertGitFile(a,oe))),await be(!1),le.success(H.length===1?o("gitView.toast.revertedFilesSingle",{count:H.length}):o("gitView.toast.revertedFilesPlural",{count:H.length}))}catch(oe){le.error(oe instanceof Error?oe.message:o("gitView.toast.revertFailed"))}finally{F(new Set),I(!1)}},[a,r,v,be,o]),Ue=l.useCallback(L=>{const H=L.map(oe=>oe.trim()).filter(Boolean);if(H.length===0){te([]);return}R(oe=>`${oe.trim()}${oe.trim()?`
23
-
24
- `:""}${H.join(`
25
- `)}`.trim()),te([])},[]),Ve=l.useCallback(async()=>{if(!a)return;const L=V.map(H=>H.path).sort();if(L.length===0){le.error(o("gitView.toast.selectFileToDescribe"));return}z(!0);try{const{message:H}=await ai(a,L);R(H.subject?.trim()??""),te(Array.isArray(H.highlights)?H.highlights:[])}catch(H){le.error(H instanceof Error?H.message:o("gitView.toast.generateCommitMessageFailed"))}finally{z(!1)}},[a,V,o]),Ee=async(L={})=>{if(!a)return;if(!C.trim()){le.error(o("gitView.toast.enterCommitMessage"));return}const H=V.map(oe=>oe.path).sort();if(H.length===0){le.error(o("gitView.toast.selectFileToCommit"));return}D(L.pushAfter?"commitAndPush":"commit");try{if(await r.createGitCommit(a,C.trim(),{files:H}),le.success(o("gitView.toast.commitCreated")),R(""),te([]),L.pushAfter){const oe=d?.tracking?.split("/")[0],je=K.find(it=>it.name===oe)??K[0];if(!je)throw new Error(o("mobile.changes.noRemote"));x("sync");const Ye=`${je.name}/`,Nt=d?.tracking?.startsWith(Ye)?d.tracking.slice(Ye.length):void 0;await r.gitFetch(a,{remote:je.name}),((await r.getGitStatus(a)).behind??0)>0&&await r.gitPull(a,{remote:je.name,branch:Nt,rebase:!0}),((await r.getGitStatus(a)).ahead??0)>0&&await r.gitPush(a),await be(!1),await Ne()}else await be(!1)}catch(oe){le.error(oe instanceof Error?oe.message:o("gitView.toast.createCommitFailed"))}finally{D(null),L.pushAfter&&x(null)}},De=l.useMemo(()=>{const L=[];return V.length>0&&L.push({id:"staged",title:o("gitView.changes.stagedTitle"),entries:V,actionSymbol:"-",actionAllLabel:o("gitView.changes.unstageAllAria"),getActionLabel:H=>o("gitView.changes.unstageFileAria",{path:H}),onActionFile:H=>{Ce([H],"unstage")},onActionAll:H=>{Ce(H,"unstage")},onViewDiff:H=>Ae(H,!0),onRevertFile:we,showRevertActions:!1,accent:!0}),ne.length>0&&L.push({id:"unstaged",title:o("gitView.changes.title"),entries:ne,actionSymbol:"+",actionAllLabel:o("gitView.changes.stageAllAria"),getActionLabel:H=>o("gitView.changes.stageFileAria",{path:H}),onActionFile:H=>{Ce([H],"stage")},onActionAll:H=>{Ce(H,"stage")},onViewDiff:H=>Ae(H,!1),onRevertFile:we}),L},[we,Ae,Ce,V,o,ne]),xe=L=>t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3 text-foreground",children:[n?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":o("mobile.surface.closeAria"),onClick:n,style:{touchAction:"manipulation"},children:t.jsx(ee,{name:"close",className:"size-5"})}):null,t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[t.jsx("h2",{className:"typography-ui-label text-foreground",children:o("mobile.nav.changes")}),t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:d?.current||a||""})]}),c===!1&&Array.isArray(f)&&f.length>0?t.jsx(Qi,{repositories:f,selectedRepository:u??null,onSelectRepository:H=>{i&&y(i,H)},repositoryRoot:i??void 0}):null]}),t.jsx("div",{className:"min-h-0 flex-1",children:L})]});return a?c===!1&&p!==!0?xe(t.jsx(Zi,{rootIsGitRepo:c,resolvedIsGitRepo:p,nestedRepos:f,onRetryDiscovery:()=>{i&&j(i,{force:!0})}})):g&&p===null?xe(t.jsx(et,{loading:!0,message:o("gitView.loading.checkingRepository")})):N.type==="diff"?t.jsx(gc,{path:N.path,diff:pe,fileExists:!!Te,error:X,onBack:()=>w({type:"list"}),onRetry:()=>fe(L=>L+1)}):t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3 text-foreground",children:[n?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":o("mobile.surface.closeAria"),onClick:n,style:{touchAction:"manipulation"},children:t.jsx(ee,{name:"close",className:"size-5"})}):null,t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[t.jsx("h2",{className:"typography-ui-label text-foreground",children:o("mobile.nav.changes")}),t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:d?.current||a})]}),t.jsx(Xi,{syncAction:P,remotes:K,onFetch:L=>{Me("fetch",L)},onSync:L=>{Me("sync",L)},disabled:_!==null||g,aheadCount:d?.ahead??0,behindCount:d?.behind??0,trackingRemoteName:d?.tracking?.split("/")[0],hasUncommittedChanges:ae.length>0})]}),ae.length>0?t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden px-4 pt-4",children:t.jsx(Sa,{groups:De,diffStats:d?.diffStats,revertingPaths:B,onRevertAll:Fe,isRevertingAll:v,headerBackgroundClassName:"bg-transparent",onVisiblePathsChange:se})}),t.jsx("div",{className:"shrink-0 border-t border-border/70 px-4 pb-4 pt-3",children:t.jsx(Na,{stagedCount:V.length,commitMessage:C,onCommitMessageChange:R,generatedHighlights:O,onInsertHighlights:Ue,onGenerateMessage:Ve,isGeneratingMessage:$,onCommit:()=>{Ee({pushAfter:!1})},onCommitAndPush:()=>{Ee({pushAfter:!0})},commitAction:_,gitmojiEnabled:!1,onOpenGitmojiPicker:()=>{}})})]}):t.jsx("div",{className:"min-h-0 flex-1",children:t.jsx(et,{icon:!0,message:o("gitView.empty.cleanTitle"),description:o("mobile.changes.cleanDescription")})})]}):xe(t.jsx(et,{message:o("gitView.empty.selectSessionOrDirectory")}))},et=n=>{const e=ce.c(13),{message:s,description:o,loading:r,icon:i}=n,c=r===void 0?!1:r,u=i===void 0?!1:i;let f;e[0]!==c?(f=c?t.jsx(ee,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):null,e[0]=c,e[1]=f):f=e[1];let a;e[2]!==u?(a=u?t.jsx(ee,{name:"git-branch",className:"size-6 text-muted-foreground"}):null,e[2]=u,e[3]=a):a=e[3];let d;e[4]!==s?(d=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:s}),e[4]=s,e[5]=d):d=e[5];let p;e[6]!==o?(p=o?t.jsx("p",{className:"typography-meta text-muted-foreground",children:o}):null,e[6]=o,e[7]=p):p=e[7];let g;return e[8]!==f||e[9]!==a||e[10]!==d||e[11]!==p?(g=t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[f,a,d,p]})}),e[8]=f,e[9]=a,e[10]=d,e[11]=p,e[12]=g):g=e[12],g},gc=n=>{const e=ce.c(24),{path:s,diff:o,fileExists:r,error:i,onBack:c,onRetry:u}=n,{t:f}=de();let a;e[0]!==s?(a=li(s)||"text",e[0]=s,e[1]=a):a=e[1];const d=a;let p;e[2]!==f?(p=f("header.actions.backAria"),e[2]=f,e[3]=p):p=e[3];let g;e[4]===Symbol.for("react.memo_cache_sentinel")?(g=t.jsx(ee,{name:"arrow-left",className:"size-5"}),e[4]=g):g=e[4];let h;e[5]!==c||e[6]!==p?(h=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":p,onClick:c,children:g}),e[5]=c,e[6]=p,e[7]=h):h=e[7];let b;e[8]!==s?(b=t.jsx("div",{className:"min-w-0 flex-1 px-2",children:t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:s})}),e[8]=s,e[9]=b):b=e[9];let j;e[10]!==h||e[11]!==b?(j=t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-3 border-b border-border/70 px-3 text-foreground",children:[h,b]}),e[10]=h,e[11]=b,e[12]=j):j=e[12];let y;e[13]!==o||e[14]!==i||e[15]!==r||e[16]!==d||e[17]!==u||e[18]!==s||e[19]!==f?(y=t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:r?i?t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-3",children:[t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:f("mobile.changes.diffDetail.loadFailed")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:i}),t.jsx(ye,{type:"button",size:"sm",variant:"outline",onClick:u,children:f("diffView.actions.retry")})]})}):o?o.isBinary?t.jsx(et,{icon:!0,message:f("diffView.binary.unavailable")}):ci(s)?t.jsx(et,{icon:!0,message:f("mobile.changes.diffDetail.imageUnavailable")}):t.jsx(_s,{className:"h-full overflow-y-auto overflow-x-hidden p-3","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:t.jsx(Ca,{original:o.original,modified:o.modified,language:d,fileName:s,renderSideBySide:!1,wrapLines:!0,layout:"inline"})}):t.jsx(et,{loading:!0,message:f("diffView.state.loadingDiff")}):t.jsx(et,{icon:!0,message:f("mobile.changes.diffDetail.missingTitle"),description:f("mobile.changes.diffDetail.missingDescription")})}),e[13]=o,e[14]=i,e[15]=r,e[16]=d,e[17]=u,e[18]=s,e[19]=f,e[20]=y):y=e[20];let A;return e[21]!==j||e[22]!==y?(A=t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[j,y]}),e[21]=j,e[22]=y,e[23]=A):A=e[23],A},bc=l.lazy(()=>xt(()=>import("./FilesView-Bdq8ppva.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124])).then(n=>({default:n.FilesView}))),rt=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/g,""),Lt=n=>{const e=rt(n);return!e||e==="/"?e||"/":e.split("/").filter(Boolean).at(-1)??e},xc=n=>{const e=rt(n);if(!e||e==="/")return null;const s=e.lastIndexOf("/");return s<=0?e.startsWith("/")?"/":null:e.slice(0,s)},yc=(n,e)=>{const s=rt(n),o=rt(e);return!o||s===o?Lt(s):s.startsWith(`${o}/`)?s.slice(o.length+1):s},vc=n=>{if(typeof n!="number"||!Number.isFinite(n)||n<0)return"";if(n<1024)return`${n} B`;const e=["KB","MB","GB"];let s=n/1024;for(const o of e){if(s<1024||o===e[e.length-1])return`${s.toFixed(s>=10?0:1)} ${o}`;s/=1024}return""},wc=({onClose:n})=>{const{t:e}=de(),{files:s}=Is(),o=yo(v=>v.setSelectedPath),r=rt(Ds()??null),[i,c]=l.useState(()=>({type:"browser",directory:r})),[u,f]=l.useState([]),[a,d]=l.useState(!1),[p,g]=l.useState(null),[h,b]=l.useState(""),[j,y]=l.useState([]),[A,S]=l.useState(!1),E=l.useRef(0);l.useEffect(()=>{r&&c(v=>v.type==="browser"&&v.directory?v:{type:"browser",directory:r})},[r]);const T=i.type==="browser"?i.directory:i.returnDirectory,k=l.useCallback(async v=>{if(!v)return;const I=E.current+1;E.current=I,d(!0),g(null);try{const $=await s.listDirectory(v);if(E.current!==I)return;f($.entries.slice().sort((z,O)=>z.isDirectory!==O.isDirectory?z.isDirectory?-1:1:z.name.localeCompare(O.name)))}catch($){if(E.current!==I)return;f([]),g($ instanceof Error?$.message:e("mobile.files.error.listFailed"))}finally{E.current===I&&d(!1)}},[s,e]);l.useEffect(()=>{i.type==="browser"&&k(i.directory)},[k,i]),l.useEffect(()=>{if(i.type!=="browser")return;const v=h.trim();if(!v){y([]),S(!1);return}let I=!1;const $=window.setTimeout(()=>{S(!0),s.search({directory:i.directory,query:v,maxResults:40}).then(z=>{I||y(z)}).catch(()=>{I||y([])}).finally(()=>{I||S(!1)})},250);return()=>{I=!0,window.clearTimeout($)}},[s,h,i]);const N=v=>{b(""),c({type:"browser",directory:v})},w=v=>{o(r,v),c({type:"file",path:v,returnDirectory:T||r})},P=He(v=>v.pendingFileFocusPath),x=He(v=>v.pendingFileNavigation);if(l.useEffect(()=>{const v=rt(x?.path??P??"");!v||!r||v!==r&&!v.startsWith(`${r}/`)||(o(r,v),c({type:"file",path:v,returnDirectory:r}),P&&He.getState().setPendingFileFocusPath(null))},[P,x,r,o]),!r)return t.jsx(Bt,{message:e("mobile.files.empty.noDirectory")});if(i.type==="file")return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 border-b border-border/70 px-3 text-foreground",children:[t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-lg text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":e("header.actions.backAria"),onClick:()=>c({type:"browser",directory:i.returnDirectory}),style:{touchAction:"manipulation"},children:t.jsx(wn,{className:"size-5"})}),t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:Lt(i.path)})})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:t.jsx(Be,{children:t.jsx(l.Suspense,{fallback:t.jsx(Bt,{loading:!0,message:e("filesView.state.loading")}),children:t.jsx(bc,{mode:"editor-only"})})})})]});const _=i.directory===r?e("mobile.files.rootDirectory"):Lt(i.directory),D=h.trim()?j:[],C=xc(i.directory),R=i.directory!==r&&C!==null&&(C===r||C.startsWith(`${r}/`)),B=R&&!h.trim(),F=R?C:null;return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3 text-foreground",children:[n?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":e("mobile.surface.closeAria"),onClick:n,style:{touchAction:"manipulation"},children:t.jsx(vr,{className:"size-5"})}):null,B&&F?t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":e("mobile.files.backToParentAria",{name:Lt(F)}),onClick:()=>N(F),style:{touchAction:"manipulation"},children:t.jsx(wn,{className:"size-5"})}):null,t.jsx("div",{className:"min-w-0 flex-1 px-1",children:t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:_})}),t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":e("mobile.files.refreshAria"),onClick:()=>{k(i.directory)},style:{touchAction:"manipulation"},children:t.jsx(ya,{className:J("size-5",a&&"animate-spin")})})]}),t.jsx("div",{className:"shrink-0 px-4 pb-2 pt-1",children:t.jsxs("div",{className:"relative",children:[t.jsx(yr,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(As,{value:h,onChange:v=>b(v.target.value),placeholder:e("mobile.files.search.placeholder"),className:"h-11 pl-9"})]})}),t.jsx(_s,{className:"min-h-0 flex-1 overflow-y-auto px-4 pb-3",children:p?t.jsx(Bt,{message:p}):h.trim()?t.jsx(jc,{results:D,isSearching:A,onOpenFile:w}):t.jsxs("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:[u.length===0&&!a?t.jsx("div",{className:"px-4 py-8 text-center typography-body text-muted-foreground",children:e("mobile.files.empty.directory")}):null,u.map(v=>t.jsx(Gr,{name:v.name,path:v.path,directory:v.isDirectory,meta:v.isDirectory?void 0:vc(v.size),onClick:()=>v.isDirectory?N(v.path):w(v.path)},v.path))]})})]})},Gr=n=>{const e=ce.c(16),{name:s,path:o,directory:r,meta:i,onClick:c}=n;let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u={touchAction:"manipulation"},e[0]=u):u=e[0];let f;e[1]!==r||e[2]!==o?(f=r?t.jsx(va,{className:"size-5 shrink-0 text-primary/80"}):t.jsx(ui,{filePath:o,className:"size-5 shrink-0"}),e[1]=r,e[2]=o,e[3]=f):f=e[3];let a;e[4]!==s?(a=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:s}),e[4]=s,e[5]=a):a=e[5];let d;e[6]!==i?(d=i?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground",children:i}):null,e[6]=i,e[7]=d):d=e[7];let p;e[8]!==r?(p=r?t.jsx(wa,{className:"size-4 shrink-0 text-muted-foreground/60"}):null,e[8]=r,e[9]=p):p=e[9];let g;return e[10]!==c||e[11]!==f||e[12]!==a||e[13]!==d||e[14]!==p?(g=t.jsxs("button",{type:"button",className:"flex min-h-14 w-full items-center gap-3 border-b border-border/70 px-3 py-2.5 text-left transition-colors last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",onClick:c,style:u,children:[f,a,d,p]}),e[10]=c,e[11]=f,e[12]=a,e[13]=d,e[14]=p,e[15]=g):g=e[15],g},jc=n=>{const e=ce.c(10),{results:s,isSearching:o,onOpenFile:r}=n,{t:i}=de(),c=rt(Ds()??null);if(o){let d;e[0]!==i?(d=i("common.loading"),e[0]=i,e[1]=d):d=e[1];let p;return e[2]!==d?(p=t.jsx(Bt,{loading:!0,message:d}),e[2]=d,e[3]=p):p=e[3],p}if(s.length===0){let d;e[4]!==i?(d=i("mobile.files.search.empty"),e[4]=i,e[5]=d):d=e[5];let p;return e[6]!==d?(p=t.jsx(Bt,{message:d}),e[6]=d,e[7]=p):p=e[7],p}const u="overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",f=s.map(d=>t.jsx(Gr,{name:Lt(d.path),path:d.path,directory:!1,meta:yc(d.path,c),onClick:()=>r(d.path)},d.path));let a;return e[8]!==f?(a=t.jsx("div",{className:u,children:f}),e[8]=f,e[9]=a):a=e[9],a},Bt=n=>{const e=ce.c(7),{message:s,loading:o}=n,r=o===void 0?!1:o;let i;e[0]!==r?(i=r?t.jsx(ja,{className:"size-5 animate-spin text-muted-foreground"}):t.jsx(ka,{className:"size-6 text-muted-foreground"}),e[0]=r,e[1]=i):i=e[1];let c;e[2]!==s?(c=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:s}),e[2]=s,e[3]=c):c=e[3];let u;return e[4]!==i||e[5]!==c?(u=t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[i,c]})}),e[4]=i,e[5]=c,e[6]=u):u=e[6],u},qn="mobile-surface-root",kc=16,Yn=320,Sc="cubic-bezier(0.22, 1, 0.36, 1)",Nc=n=>{const e=ce.c(36),{onOpenMcpSettings:s}=n,{t:o}=de(),[r,i]=l.useState(!1),c=tt(Cc),u=It(Ec),f=ht(Rc);let a;e[0]!==c||e[1]!==r||e[2]!==f||e[3]!==u?(a=()=>{if(r)return;i(!0);const _=new Promise(Pc);Promise.all([u({directory:c||null,silent:!0}),f({force:!0}),_]).finally(()=>i(!1))},e[0]=c,e[1]=r,e[2]=f,e[3]=u,e[4]=a):a=e[4];const d=a;let p;e[5]!==o?(p=o("settings.mcp.sidebar.actions.addServerTitle"),e[5]=o,e[6]=p):p=e[6];let g;e[7]!==o?(g=o("settings.mcp.sidebar.actions.addServerTitle"),e[7]=o,e[8]=g):g=e[8];let h,b;e[9]===Symbol.for("react.memo_cache_sentinel")?(h={touchAction:"manipulation"},b=t.jsx(ee,{name:"add",className:"size-5"}),e[9]=h,e[10]=b):(h=e[9],b=e[10]);let j;e[11]!==s||e[12]!==p||e[13]!==g?(j=t.jsx("button",{type:"button",className:"flex size-10 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:s,"aria-label":p,title:g,style:h,children:b}),e[11]=s,e[12]=p,e[13]=g,e[14]=j):j=e[14];let y;e[15]!==o?(y=o("mcpDropdown.actions.refreshAria"),e[15]=o,e[16]=y):y=e[16];let A;e[17]!==o?(A=o("mcpDropdown.actions.refreshAria"),e[17]=o,e[18]=A):A=e[18];let S;e[19]===Symbol.for("react.memo_cache_sentinel")?(S={touchAction:"manipulation"},e[19]=S):S=e[19];const E=r&&"animate-spin";let T;e[20]!==E?(T=J("size-5",E),e[20]=E,e[21]=T):T=e[21];let k;e[22]!==T?(k=t.jsx(ee,{name:"refresh",className:T}),e[22]=T,e[23]=k):k=e[23];let N;e[24]!==r||e[25]!==d||e[26]!==k||e[27]!==y||e[28]!==A?(N=t.jsx("button",{type:"button",className:"flex size-10 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground disabled:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:d,disabled:r,"aria-label":y,title:A,style:S,children:k}),e[24]=r,e[25]=d,e[26]=k,e[27]=y,e[28]=A,e[29]=N):N=e[29];let w;e[30]!==N||e[31]!==j?(w=t.jsxs("div",{className:"flex shrink-0 items-center justify-end gap-1 px-2 pt-1",children:[j,N]}),e[30]=N,e[31]=j,e[32]=w):w=e[32];let P;e[33]===Symbol.for("react.memo_cache_sentinel")?(P=t.jsx("div",{className:"min-h-0 flex-1",children:t.jsx(dc,{active:!0,className:"h-full",listClassName:"max-h-none",hideHeader:!0,mobileListDensity:!0})}),e[33]=P):P=e[33];let x;return e[34]!==w?(x=t.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[w,P]}),e[34]=w,e[35]=x):x=e[35],x},Jn=({open:n,onClose:e,tab:s,onTabChange:o,pendingChangesDiff:r,onOpenPlan:i,onOpenMcpSettings:c,variant:u="drawer"})=>{const{t:f}=de(),a=l.useRef(null),[d,p]=l.useState(!1),[g,h]=l.useState(n),b=l.useRef(e);l.useEffect(()=>{b.current=e},[e]);const j=l.useRef(s);l.useEffect(()=>{j.current=s},[s]);const[y,A]=l.useState(()=>new Set);if(l.useEffect(()=>{n&&A(T=>{if(T.has(s))return T;const k=new Set(T);return k.add(s),k})},[n,s]),typeof document<"u"&&!a.current){let T=document.getElementById(qn);T||(T=document.createElement("div"),T.id=qn,document.body.appendChild(T)),a.current=T}if(l.useEffect(()=>{if(n){h(!0);const k=window.setTimeout(()=>p(!0),kc);return()=>window.clearTimeout(k)}p(!1);const T=window.setTimeout(()=>h(!1),Yn+40);return()=>window.clearTimeout(T)},[n]),l.useEffect(()=>{if(!n)return;const T=document.body.style.overflow;u==="drawer"&&(document.body.style.overflow="hidden");const k=N=>{N.key==="Escape"&&j.current!=="terminal"&&b.current()};return document.addEventListener("keydown",k),()=>{u==="drawer"&&(document.body.style.overflow=T),document.removeEventListener("keydown",k)}},[n,u]),u==="drawer"&&!a.current)return null;const S=[{id:"changes",label:f("mobile.menu.changes"),icon:t.jsx(ee,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"files",label:f("mobile.menu.files"),icon:t.jsx(ee,{name:"file-text",className:"h-3.5 w-3.5"})},{id:"terminal",label:f("mobile.menu.terminal"),icon:t.jsx(ee,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"notes",label:f("contextRail.surface.notes"),icon:t.jsx(ee,{name:"sticky-note",className:"h-3.5 w-3.5"})},{id:"mcp",label:f("mobile.menu.mcp"),icon:t.jsx(di,{className:"h-3.5 w-3.5"})}],E=t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",children:[t.jsx("div",{className:"flex h-9 min-w-0 flex-1 items-center",children:g?t.jsx(ea,{items:S,activeId:s,onSelect:T=>o(T),layoutMode:"fit",variant:"active-pill",nonCompositedIndicator:!0,inactiveTabsIconOnly:!0,className:"h-full"}):null}),t.jsx("button",{type:"button",className:"-mr-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":f("mobile.surface.closeAria"),onClick:e,style:{touchAction:"manipulation"},children:t.jsx(ee,{name:"close",className:"size-5"})})]}),t.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[y.has("changes")?t.jsx("div",{className:J("h-full",s!=="changes"&&"hidden"),children:t.jsx(Be,{children:t.jsx(hc,{initialDiffPath:r?.path??null,initialDiffStaged:r?.staged===!0})})},r?`changes:${r.path}:${r.staged}`:"changes"):null,y.has("files")?t.jsx("div",{className:J("h-full",s!=="files"&&"hidden"),children:t.jsx(Be,{children:t.jsx(wc,{})})}):null,y.has("terminal")?t.jsx("div",{className:J("h-full",s!=="terminal"&&"hidden"),children:t.jsx(Be,{children:t.jsx(ta,{visible:n&&s==="terminal"})})}):null,y.has("notes")?t.jsx("div",{className:J("h-full",s!=="notes"&&"hidden"),children:t.jsx(Be,{children:t.jsx(sa,{onActionComplete:e,onOpenPlan:i})})}):null,y.has("mcp")?t.jsx("div",{className:J("h-full",s!=="mcp"&&"hidden"),children:t.jsx(Be,{children:t.jsx(Nc,{onOpenMcpSettings:c})})}):null]})]});return u==="panel"?t.jsx("div",{className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:E}):bt.createPortal(t.jsx("section",{role:"dialog","aria-modal":"true","aria-label":f("mobile.header.openWorkspaceAria"),"aria-hidden":!n,className:"oc-keyboard-inset-surface fixed inset-0 z-50 flex flex-col bg-background text-foreground",style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:d?"none":"translateX(100%)",transition:`transform ${Yn}ms ${Sc}`,visibility:g?"visible":"hidden",pointerEvents:n?"auto":"none"},children:E}),a.current)};function Cc(n){return n.currentDirectory}function Ec(n){return n.refresh}function Rc(n){return n.loadMcpConfigs}function Pc(n){return window.setTimeout(n,500)}function Tc(n){const e=ce.c(4),s=2500,{uiFont:o}=fi(),[r,i]=l.useState(!1);let c,u;return e[0]!==s||e[1]!==o?(c=()=>{let f=!1;const a=()=>{f||i(!0)},d=()=>{requestAnimationFrame(()=>requestAnimationFrame(a))},p=Promise.all([mi(o).catch(Mc),document.fonts?.ready?.then(Dc).catch(_c)??Promise.resolve(),Ea.catch(Ic)]).then(Ac),g=new Promise(h=>{window.setTimeout(h,s)});return Promise.race([p,g]).then(d),()=>{f=!0}},u=[o,s],e[0]=s,e[1]=o,e[2]=c,e[3]=u):(c=e[2],u=e[3]),l.useEffect(c,u),r}function Ac(){}function Ic(){}function _c(){}function Dc(){}function Mc(){}const zc="aiworker",Oc=n=>n.replace(/^\/+|\/+$/g,""),Lc=n=>{const e=Oc(n.pathname).split("/").filter(Boolean);return n.host?[n.host,...e]:e};function Bc(n){if(typeof n!="string"||n.length===0)return null;let e;try{e=new URL(n)}catch{return null}if(e.protocol!==`${zc}:`)return null;const s=Lc(e),o=(s[0]??"").toLowerCase(),r=s.slice(1),i=e.searchParams;switch(o){case"session":{const c=r[0]||i.get("id")||"";return c?{type:"session",sessionId:c,directory:i.get("dir")??void 0}:null}case"new":case"new-session":return{type:"new-session",directory:i.get("dir")??void 0,projectId:i.get("project")??void 0,agent:i.get("agent")??void 0,model:i.get("model")??void 0};case"sessions":{const c=i.get("filter");return{type:"sessions",filter:c==="attention"||c==="recent"||c==="all"?c:void 0}}case"status":return{type:"status"};case"settings":return{type:"settings",section:r[0]||i.get("section")||void 0};case"changes":return{type:"changes",path:r.join("/")||i.get("path")||void 0,staged:i.get("staged")==="true"};case"view":{const c=(r[0]||"").toLowerCase();return c==="changes"?{type:"changes"}:c==="files"||c==="mcp"||c==="instances"||c==="update"?{type:"view",target:c}:null}default:return null}}let ze={},Kr=!1,Ot=null;const $c=n=>{switch(n.type){case"session":return ke.getState().setCurrentSession(n.sessionId,n.directory??null),!0;case"new-session":{const e=ke.getState();return e.openNewSessionDraft(),(n.directory||n.projectId)&&e.setNewSessionDraftTarget({directoryOverride:n.directory??null,projectId:n.projectId??null,selectedProjectId:n.projectId??null}),!0}case"sessions":return ze.openSessions?(ze.openSessions(n.filter),!0):!1;case"status":return ze.openSessions?(ze.openSessions(),!0):!1;case"view":return ze.openView?(ze.openView(n.target),!0):!1;case"changes":return ze.openChanges?(ze.openChanges({path:n.path,staged:n.staged}),!0):!1;case"settings":return ze.openSettings?(ze.openSettings(n.section),!0):!1}},tn=()=>{if(!Kr||!Ot)return;const n=Ot;Ot=null,$c(n)||(Ot=n)},Hr=n=>{Ot=n,tn()},Xn=n=>{const e=Bc(n);e&&Hr(e)},Fc=n=>{Kr=n,tn()},Wc=n=>{const e=ce.c(3);let s,o;e[0]!==n?(s=()=>(ze=n,tn(),()=>{ze===n&&(ze={})}),o=[n],e[0]=n,e[1]=s,e[2]=o):(s=e[1],o=e[2]),l.useEffect(s,o)},Uc=n=>{const{ready:e}=n;l.useEffect(()=>{Fc(e)},[e]),l.useEffect(()=>{if(!Pe())return;let s=!1;const o=[];return xt(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([125,4,126])).then(async({App:r})=>{if(s)return;const i=await r.addListener("appUrlOpen",c=>{Xn(c?.url)});if(s){i.remove();return}o.push(()=>{i.remove()})}).catch(()=>{}),xt(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([127,126])).then(async({PushNotifications:r})=>{if(s)return;const i=await r.addListener("pushNotificationActionPerformed",c=>{const u=c?.notification?.data,f=typeof u?.url=="string"?u.url:typeof u?.deeplink=="string"?u.deeplink:void 0;if(f){Xn(f);return}const a=typeof u?.sessionId=="string"?u.sessionId:void 0;a&&Hr({type:"session",sessionId:a})});if(s){i.remove();return}o.push(()=>{i.remove()})}).catch(()=>{}),()=>{s=!0,o.forEach(r=>r())}},[])},Vc=32,Gc=80,Kc=64,Hc=.7,qc=(n,e)=>{const s=l.useRef(e);s.current=e,l.useEffect(()=>{const o=n.current;if(!o)return;const i=window.Capacitor?.getPlatform?.()==="android"?Gc:Vc;let c=!1,u=!1,f=0,a=0;const d=g=>{if(g.touches.length!==1){c=!1;return}const h=g.touches[0],b=o.clientWidth,j=h.clientX<=i,y=h.clientX>=b-i;c=j||y,u=j,f=h.clientX,a=h.clientY},p=g=>{if(!c)return;c=!1;const h=g.changedTouches[0];if(!h)return;const b=h.clientX-f,j=h.clientY-a;Math.abs(b)<Kc||Math.abs(j)>Math.abs(b)*Hc||u&&b<=0||!u&&b>=0||(u?s.current.onLeftEdgeSwipe?.():s.current.onRightEdgeSwipe?.())};return o.addEventListener("touchstart",d,{passive:!0}),o.addEventListener("touchend",p,{passive:!0}),()=>{o.removeEventListener("touchstart",d),o.removeEventListener("touchend",p)}},[n])},Yc=()=>{if(typeof window>"u")return;const n=window.__AIWORKER_APNS_ENV__;if(n==="development")return"sandbox";if(n==="production")return"production"},Jc=()=>{if(typeof window>"u")return!1;const e=window.Capacitor?.getPlatform?.();return e==="ios"||e==="android"},Xc=n=>{const{enabled:e}=n,s=He(r=>r.nativeNotificationsEnabled),o=l.useRef(null);l.useEffect(()=>{if(!e||!s||!Jc())return;let r=!1;const i=[];return xt(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([127,126])).then(async({PushNotifications:c})=>{if(r)return;let u=await c.checkPermissions().catch(()=>null);if(u?.receive!=="granted"&&(u=await c.requestPermissions().catch(()=>null)),u?.receive!=="granted")return;const f=await c.addListener("registration",d=>{o.current=d.value,hn()?.push?.registerApnsToken?.({token:d.value,platform:tr(),environment:Yc()})}),a=await c.addListener("registrationError",d=>{console.warn("[Push] APNs registration error:",d)});if(await c.register().catch(()=>{}),r){f.remove(),a.remove();return}i.push(()=>{f.remove()},()=>{a.remove()})}).catch(()=>{}),()=>{r=!0,i.forEach(c=>c())}},[e,s]),l.useEffect(()=>{if(s)return;const r=o.current;if(!r)return;o.current=null,hn()?.push?.unregisterApnsToken?.({token:r})},[s])},Qn=n=>{const e=ce.c(12),{side:s,isResizing:o,ariaLabel:r,handleProps:i}=n,c=s==="left"?"right-0":"left-0";let u;e[0]!==c?(u=J("absolute inset-y-0 z-50 w-6 cursor-col-resize touch-none",c),e[0]=c,e[1]=u):u=e[1];const f=s==="left"?"right-0":"left-0",a=o&&"bg-[var(--interactive-border)]";let d;e[2]!==f||e[3]!==a?(d=J("absolute inset-y-0 w-[3px] transition-colors",f,a),e[2]=f,e[3]=a,e[4]=d):d=e[4];let p;e[5]!==d?(p=t.jsx("div",{className:d}),e[5]=d,e[6]=p):p=e[6];let g;return e[7]!==r||e[8]!==i||e[9]!==u||e[10]!==p?(g=t.jsx("div",{className:u,role:"separator","aria-orientation":"vertical","aria-label":r,...i,children:p}),e[7]=r,e[8]=i,e[9]=u,e[10]=p,e[11]=g):g=e[11],g},Qc=320,Zc=380,Zn=280,eu=560,tu=900;function er(n,e,s,o){const r=ce.c(23),i=o===void 0?eu:o,c=l.useRef(null);let u;r[0]!==s||r[1]!==i||r[2]!==e?(u=()=>{if(typeof window>"u")return s;const R=Number.parseInt(window.localStorage.getItem(e)??"",10);return Number.isFinite(R)?Math.min(i,Math.max(Zn,R)):s},r[0]=s,r[1]=i,r[2]=e,r[3]=u):u=r[3];const[f,a]=l.useState(u),[d,p]=l.useState(!1),g=l.useRef(0),h=l.useRef(f),b=l.useRef(null),j=l.useRef(null);let y;r[4]!==i?(y=R=>Math.min(i,Math.max(Zn,Math.round(R))),r[4]=i,r[5]=y):y=r[5];const A=y;let S;r[6]===Symbol.for("react.memo_cache_sentinel")?(S=R=>{const B=c.current;B&&(B.style.width=`${R}px`,B.style.minWidth=`${R}px`,B.style.maxWidth=`${R}px`,B.style.setProperty("--oc-ipad-sidebar-width",`${R}px`))},r[6]=S):S=r[6];const E=S;let T;r[7]!==f?(T=R=>{try{R.currentTarget.setPointerCapture(R.pointerId)}catch{}j.current=R.pointerId,g.current=R.clientX,h.current=f,b.current=f,p(!0),R.preventDefault()},r[7]=f,r[8]=T):T=r[8];const k=T;let N;r[9]!==A||r[10]!==n?(N=R=>{if(j.current!==R.pointerId)return;const B=R.clientX-g.current,F=A(h.current+(n==="left"?B:-B));b.current!==F&&(b.current=F,E(F))},r[9]=A,r[10]=n,r[11]=N):N=r[11];const w=N;let P;r[12]!==A||r[13]!==e?(P=R=>{if(j.current!==R.pointerId)return;try{R.currentTarget.releasePointerCapture(R.pointerId)}catch{}const B=A(b.current??h.current);j.current=null,b.current=null,p(!1),a(B);try{window.localStorage.setItem(e,String(B))}catch{}},r[12]=A,r[13]=e,r[14]=P):P=r[14];const x=P;let _;r[15]!==k||r[16]!==x||r[17]!==w?(_={onPointerDown:k,onPointerMove:w,onPointerUp:x,onPointerCancel:x},r[15]=k,r[16]=x,r[17]=w,r[18]=_):_=r[18];const D=_;let C;return r[19]!==D||r[20]!==d||r[21]!==f?(C={asideRef:c,width:f,isResizing:d,handleProps:D},r[19]=D,r[20]=d,r[21]=f,r[22]=C):C=r[22],C}const su=["general","appearance","chat","notifications","sessions","git","magic-prompts","behavior","mcp","providers","usage","voice","integrations","about"],nu=1e3,ru=({onActiveConnectionDeleted:n})=>{const{t:e}=de(),[s,o]=l.useState(!1),[r,i]=l.useState(null),[c,u]=l.useState(!1),[f,a]=l.useState("changes"),[d,p]=l.useState(null),[g,h]=l.useState("nav"),[b,j]=l.useState(null),y=He(K=>K.setSettingsPage),A=He(K=>K.wideChatLayoutEnabled),S=mt(K=>K.available),E=mt(K=>K.runtimeType),T=l.useMemo(()=>gr(),[]),k=ht(K=>K.mcpServers),N=ht(K=>K.setMcpDraft),w=ht(K=>K.setSelectedMcp),P=l.useCallback(()=>{i(null),p(null)},[]),x=l.useCallback(K=>{i(K)},[]),_=l.useCallback(()=>{u(!1)},[]),D=l.useCallback(K=>{h(K),x("settings")},[x]),{enabled:C,roomyForPanels:R}=Ps(),F=Ii()==="portrait",v=_i(),[I,$]=l.useState(()=>Di().roomyForPanels),z=l.useCallback(()=>{$(K=>!K)},[]);l.useEffect(()=>{C||$(!1)},[C]);const O=l.useCallback(()=>{j(null),a("files"),u(!0)},[]),te=l.useCallback((K=null)=>{j(K),a("changes"),u(!0)},[]),Q=er("left","aiworker.ipad.leftSidebarWidth",Qc),se=er("right","aiworker.ipad.rightSidebarWidth",Zc,tu),M=R,W=M&&c?se.width:0,G=C&&I?Q.width:0;l.useEffect(()=>{if(typeof document>"u")return;const K=document.documentElement;return K.style.setProperty("--oc-chat-inset-left",`${G}px`),K.style.setProperty("--oc-chat-inset-right",`${W}px`),()=>{K.style.removeProperty("--oc-chat-inset-left"),K.style.removeProperty("--oc-chat-inset-right")}},[G,W]),l.useEffect(()=>{if(typeof document>"u")return;const K=document.documentElement;return K.classList.toggle("wide-chat-layout",A),()=>K.classList.remove("wide-chat-layout")},[A]),l.useEffect(()=>{if(typeof document>"u")return;const K=C&&(F||v),pe=document.documentElement;return pe.classList.toggle("oc-keep-draft-starters",K),()=>pe.classList.remove("oc-keep-draft-starters")},[v,C,F]);const q=l.useMemo(()=>({openChanges:({diffPath:K,staged:pe}={})=>{te(K?{path:K,staged:pe===!0}:null)},openFiles:()=>O(),openSettings:()=>D("nav")}),[te,O,D]),X=l.useMemo(()=>({openSessions:()=>{C?$(!0):o(!0)},openView:K=>{if(K==="files"){O();return}if(K==="mcp"){a("mcp"),u(!0);return}x(K)},openChanges:({path:K,staged:pe}={})=>{te(K?{path:K,staged:pe===!0}:null)},openSettings:K=>{K&&y(K),D(K?"page-content":"nav")}}),[C,te,O,D,x,y]);Wc(X);const Z=l.useRef(null);qc(Z,{onLeftEdgeSwipe:()=>{C?$(!0):o(!0)},onRightEdgeSwipe:()=>u(!0)});const ie=l.useCallback(()=>d?(p(null),!0):r?(P(),!0):c?(_(),!0):s?(o(!1),!0):!1,[r,P,_,d,s,c]);Mi(ie);const fe=!T&&S&&(E==="desktop"||E==="web"),ae=C?"dialog":"fullscreen",V=l.useMemo(()=>({instanceLabel:T?_t():null,onOpenInstances:T?()=>x("instances"):void 0,onOpenSettings:()=>D("nav"),onOpenUpdate:fe?()=>x("update"):void 0}),[D,x,T,fe]),ne=l.useCallback(()=>{const K="new-mcp-server";let pe=K,Te=1;for(;k.some(Ne=>Ne.name===pe);)pe=`${K}-${Te}`,Te+=1;N({name:pe,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),w(pe),y("mcp"),D("page-content")},[k,D,N,w,y]);return t.jsx(zi,{actions:q,children:t.jsxs("div",{className:"oc-mobile-app-shell main-content-safe-area flex h-[100dvh] flex-row bg-background text-foreground","data-page-scroll-lock":"true",children:[C?t.jsxs("aside",{ref:Q.asideRef,className:J("relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border/70 bg-background will-change-[width] motion-reduce:transition-none",!I&&"border-r-0"),style:{width:I?Q.width:0,minWidth:I?Q.width:0,maxWidth:I?Q.width:0,"--oc-ipad-sidebar-width":`${Q.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:Q.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!I,"data-page-scroll-lock":"true",children:[t.jsx("div",{className:J("flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",Q.isResizing&&"pointer-events-none",!I&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(Be,{children:t.jsx(Un,{open:!0,variant:"sidebar",onOpenChange:K=>{!K&&!R&&$(!1)},footer:V})})}),I?t.jsx(Qn,{side:"left",isResizing:Q.isResizing,ariaLabel:e("sidebar.resize.leftPanelAria"),handleProps:Q.handleProps}):null]}):null,t.jsxs("div",{className:"flex h-full min-w-0 flex-1 flex-col","data-page-scroll-lock":"true",children:[t.jsx(zl,{onOpenSessions:()=>C?z():o(!0),onOpenWorkspace:()=>u(!0),compactTitle:C}),t.jsx("main",{ref:Z,className:"relative min-h-0 flex-1 overflow-hidden","data-page-scroll-lock":"true",children:t.jsx("div",{className:"h-full w-full",children:t.jsx(Be,{children:t.jsx(ca,{})})})})]}),C?null:t.jsx(Un,{open:s,onOpenChange:o,footer:V}),C?t.jsxs("aside",{ref:se.asideRef,className:J("relative flex h-full shrink-0 flex-col overflow-hidden border-l border-border/70 bg-background will-change-[width] motion-reduce:transition-none",!W&&"border-l-0"),style:{width:W,minWidth:W,maxWidth:W,"--oc-ipad-sidebar-width":`${se.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:se.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!W,"data-page-scroll-lock":"true",children:[t.jsx("div",{className:J("flex h-full min-h-0 shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",se.isResizing&&"pointer-events-none",!W&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(Be,{children:t.jsx(Jn,{open:c,onClose:_,tab:f,onTabChange:a,pendingChangesDiff:b,onOpenPlan:p,onOpenMcpSettings:ne,variant:M?"panel":"drawer"})})}),W?t.jsx(Qn,{side:"right",isResizing:se.isResizing,ariaLabel:e("sidebar.resize.rightPanelAria"),handleProps:se.handleProps}):null]}):t.jsx(Jn,{open:c,onClose:_,tab:f,onTabChange:a,pendingChangesDiff:b,onOpenPlan:p,onOpenMcpSettings:ne}),d?t.jsx(zt,{open:!0,variant:ae,onClose:()=>p(null),ariaLabel:d.title,title:d.title,children:t.jsx(Be,{children:t.jsx(ma,{savedProjectPlan:{projectRef:d.projectRef,planId:d.id},onNavigatedToChat:()=>{P(),_()}})})}):null,r==="instances"&&T?t.jsx(zt,{open:!0,variant:ae,dialogAlign:"app",onClose:P,ariaLabel:e("mobile.menu.instances"),title:e("mobile.menu.instances"),children:t.jsx($l,{onConnect:P,onActiveConnectionDeleted:n})}):null,r==="settings"?t.jsx(zt,{open:!0,variant:ae,dialogAlign:"app",onClose:P,ariaLabel:e("mobile.menu.settings"),headerless:!0,children:t.jsx(Be,{children:t.jsx(da,{forceMobile:!0,isWindowed:!0,initialMobileStage:g,visiblePageSlugs:su.filter(K=>!(T&&K==="about")),onClose:P})})}):null,r==="update"?t.jsx(zt,{open:!0,variant:ae,dialogAlign:"app",onClose:P,ariaLabel:e("mobile.menu.update"),title:e("mobile.menu.update"),children:t.jsx(Be,{children:t.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:t.jsx(fa,{initialUpdateDialogOpen:!0})})})}):null]})})};function ou({apis:n}){const{t:e}=de(),s=Oe(M=>M.initializeApp),o=Oe(M=>M.isInitialized),r=Oe(M=>M.isConnected),i=Oe(M=>M.connectionPhase),c=Oe(M=>M.providers.length),u=Oe(M=>M.agents.length),f=Oe(M=>M.loadProviders),a=Oe(M=>M.loadAgents),d=tt(M=>M.currentDirectory),p=ke(M=>M.error),g=ke(M=>M.clearError),h=He(M=>M.setIsMobile),b=pi(M=>M.refreshStatus),j=hi(M=>M.refreshStatus),y=gi(M=>M.setPlanModeEnabled),A=Le(M=>M.projects),[S,E]=l.useState(0),[T,k]=l.useState(0),[N,w]=l.useState(!1),[P,x]=l.useState("pending"),[_,D]=l.useState(null),C=l.useMemo(()=>_t(),[]),[,R]=l.useReducer(M=>M+1,0),B=l.useMemo(()=>gr(),[]),F=l.useRef(0),v=l.useRef(0),I=l.useCallback(()=>{const M=Ke(),W=v.current+1;if(v.current=W,!M){Tt("resume:auto-connect",{}),At();return}Tt("resume:reprobe",{});const G=()=>{s(),b(n.github,{force:!0}),j(n.linear,{force:!0}),c===0&&f({source:"mobileApp:nativeResume"}),u===0&&a({source:"mobileApp:nativeResume"})},q=Z=>{Tt("resume:disconnect",{reason:Z}),ft({apiBaseUrl:"",clientToken:null,runtimeKey:Gt}),E(ie=>ie+1)};Jt().then(Z=>{if(v.current===W){if(Z==="no-connection"){q("no-connection");return}if(Z==="needs-login"){D({kind:"auth-expired",label:_t()??""}),q("needs-login");return}if(Z==="unreachable"){const ie=[4e3,1e4],fe=ae=>{window.setTimeout(()=>{if(v.current!==W)return;const V=ae===ie.length-1;Jt({fast:!V}).then(ne=>{if(v.current===W&&ne!=="switched"){if(ne==="unchanged"){G();return}if(ne==="needs-login"){D({kind:"auth-expired",label:_t()??""}),q("retry-needs-login");return}if(!V){fe(ae+1);return}q(`retry-${ne}`)}})},ie[ae])};fe(0);return}Z!=="switched"&&G()}});const X=Date.now();X-F.current>=nu&&(F.current=X,window.dispatchEvent(new Event("aiworker:system-resume")))},[u,n.github,n.linear,s,a,f,c,b,j]);bi(),xi(I),l.useEffect(()=>{if(!B)return;let M;const W=()=>{window.clearTimeout(M),M=window.setTimeout(()=>I(),1500)};return window.addEventListener("online",W),()=>{window.removeEventListener("online",W),window.clearTimeout(M)}},[B,I]),l.useEffect(()=>{if(B)return gn.subscribe((M,W)=>{M.state==="expired"&&W.state!=="expired"&&(I(),gn.getState().markAuthenticated())})},[B,I]),l.useEffect(()=>(bn(n),()=>bn(null)),[n]),l.useEffect(()=>vo(M=>{if(Tt("endpoint:changed",{runtimeKey:M.runtimeKey||"none",previousRuntimeKey:M.previousRuntimeKey||"none",connected:!!M.apiBaseUrl}),!!M.runtimeKey&&M.runtimeKey===M.previousRuntimeKey){na(),R();return}ra(M),k(G=>G+1),E(G=>G+1)}),[]),l.useEffect(()=>{if(!B||r||Ke()){x("done");return}let M=!1;return x("attempting"),(async()=>{const W=await At().catch(()=>({status:"no-candidate"}));M||(W.status==="unreachable"?D({kind:"unreachable",label:W.label}):W.status==="needs-login"&&D({kind:"auth-expired",label:W.label}),x("done"),W.status==="unreachable"&&At({fast:!1,skipIfConnected:!0}).catch(()=>null))})(),()=>{M=!0}},[]),l.useEffect(()=>{if(!B||!Ke())return;let M=!1;const W=G=>{Tt("cold-launch:drop",{kind:G?.kind??"unknown"}),G&&D(G),ft({apiBaseUrl:"",clientToken:null,runtimeKey:Gt}),E(q=>q+1)};return Jt().then(async G=>{if(M||G==="switched"||G==="unchanged")return;const q=_t();if(G==="needs-login"){W({kind:"auth-expired",label:q??""});return}if(G==="unreachable"){W(q?{kind:"unreachable",label:q}:null),At({fast:!1,skipIfConnected:!0}).catch(()=>null);return}const X=await At().catch(()=>({status:"no-candidate"}));M||X.status==="connected"||(X.status==="needs-login"?W({kind:"auth-expired",label:X.label}):X.status==="unreachable"?W({kind:"unreachable",label:X.label}):W(null))}),()=>{M=!0}},[]),l.useEffect(()=>{h(!0)},[h]),l.useEffect(()=>{B&&!Ke()||s()},[S,s,B]),l.useEffect(()=>{r&&(c===0&&f({source:"mobileApp:recovery"}),u===0&&a({source:"mobileApp:recovery"}))},[u,r,a,f,c]);const $=l.useRef(!1),[z,O]=l.useState(B);l.useEffect(()=>{if(!B||!r||$.current)return;if(ke.getState().currentSessionId){$.current=!0,O(!1);return}const M=kt(),W=yi(M);if(!W){$.current=!0,O(!1);return}let G=!1;const q=window.setTimeout(()=>O(!1),6e3);return(async()=>{const X=await Ts().catch(()=>null);if(G)return;if(!X){O(!1);return}$.current=!0;const Z=X.activeSessions.find(fe=>fe.id===W.sessionId);if(!Z){vi(M),O(!1);return}const ie=ke.getState();ie.currentSessionId||ie.setCurrentSession(Z.id,Rs(Z)??W.directory??void 0),O(!1)})(),()=>{G=!0,window.clearTimeout(q)}},[S,r,B]),l.useEffect(()=>{r&&xn.setDirectory(d)},[d,r]),l.useEffect(()=>{r&&(b(n.github,{force:!0}),j(n.linear,{force:!0}))},[n.github,n.linear,r,b,j]),l.useEffect(()=>{if(!r||A.length===0)return;let M=!1;return(async()=>{const G=new Map(ke.getState().availableWorktreesByProject);if(await Promise.all(A.map(async Z=>{const ie=Z.path.replace(/\\/g,"/").replace(/\/+$/,"");if(ie)try{if(!(We.getState().directories.get(ie)?.isGitRepo??await xt(()=>import("./useAppFontEffects-CjrntdL0.js").then(ne=>ne.ih),__vite__mapDeps([9,1,2,3,4,5,6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82])).then(ne=>ne.checkIsGitRepository(ie))))return;const V=await pr({id:Z.id,path:ie});if(M)return;G.set(ie,V)}catch{}})),M)return;const q=hr(A,G),X=ke.getState().availableWorktreesByProject;Ai(q,X)||ke.setState({availableWorktrees:[...q.values()].flat(),availableWorktreesByProject:q})})(),()=>{M=!0}},[r,A]),l.useEffect(()=>{let M=!1;return(async()=>{const G=await Cs("/health",{method:"GET"}).catch(()=>null);if(!G||!G.ok||M)return;const q=await G.json().catch(()=>null);if(!q||M)return;const X=q.planModeExperimentalEnabled;y(X===!0||X===1||X==="1"||X==="true")})(),()=>{M=!0}},[y]),l.useEffect(()=>{if(!p)return;const M=window.setTimeout(()=>g(),5e3);return()=>window.clearTimeout(M)},[g,p]),l.useEffect(()=>{if(!(!r&&(B?!!Ke():!0))){w(!1);return}const W=window.setTimeout(()=>{w(!0)},B?4e3:8e3);return()=>window.clearTimeout(W)},[r,B,S,T]),wi(),ji({enabled:!0}),oa(),ki(),ia(),Xc({enabled:B&&r}),Uc({ready:B&&r&&o});const te=Tc(),Q=!r&&i==="reconnecting";if(!te)return t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:t.jsx(Xe,{width:120,height:120,isAnimated:!0})});const se=!!Ke();return B&&(!se||!r&&!Q)?se?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-4",children:[t.jsx(Xe,{width:120,height:120,isAnimated:!N}),N?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:e("sessionAuth.error.networkTitle")}),t.jsx("p",{className:"typography-body text-muted-foreground",children:e("mobile.connect.recovery.description")})]}),t.jsx(ye,{type:"button",variant:"outline",onClick:()=>{ft({apiBaseUrl:"",clientToken:null,runtimeKey:Gt}),E(M=>M+1)},children:e("mobile.connect.cancelPassword")})]}):null]})}):P!=="done"?t.jsxs("main",{className:"relative flex min-h-dvh items-center justify-center bg-background text-foreground",children:[t.jsx(Xe,{width:120,height:120,isAnimated:!0}),C?t.jsxs("div",{className:"absolute inset-x-0 top-[calc(50%+84px)] flex flex-col items-center gap-0.5 px-6 text-center",children:[t.jsx("p",{className:"typography-small text-muted-foreground",children:e("mobile.connect.splash.connectingTo")}),t.jsxs("p",{className:"typography-small text-foreground",children:[C,t.jsx(Si,{})]})]}):null]}):t.jsx(t.Fragment,{children:t.jsx(wl,{onConnected:()=>E(M=>M+1),notice:_})}):!r&&!Q?N?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:t.jsxs("div",{className:"max-w-sm space-y-3",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:e("sessionAuth.error.networkTitle")}),t.jsx("p",{className:"typography-body text-muted-foreground",children:e("sessionAuth.error.networkDescription")})]})}):t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:t.jsx(Xe,{width:120,height:120,isAnimated:!0})}):t.jsx(Be,{children:t.jsx(Ni,{sdk:xn.getSdkClient(),directory:d||"",children:t.jsx(Ci,{apis:n,children:t.jsx(Ei,{delayDuration:300,skipDelayDuration:150,children:t.jsxs("div",{className:"h-full bg-background text-foreground",children:[B&&z?t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background",children:t.jsx(Xe,{width:120,height:120,isAnimated:!0})}):null,t.jsx(Ri,{embeddedBackgroundWorkEnabled:o}),t.jsx(aa,{}),t.jsx(za,{}),t.jsx(ru,{onActiveConnectionDeleted:()=>{ft({apiBaseUrl:"",clientToken:null,runtimeKey:Gt}),E(M=>M+1)}}),t.jsx(Pi,{}),t.jsx(Ti,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),o?t.jsx(la,{}):null]})})})},T)})}const iu=()=>{Ui(),wo().then(()=>{Promise.all([jo(),Vi()]).catch(n=>{console.error("[mobile-main] settings init failed:",n)}),Gi(),Ki(),Hi()}).catch(n=>{console.error("[mobile-main] appearance init failed:",n)}).finally(()=>{Ra()})};function _f(n){window.__AIWORKER_SURFACE__="mobile",Oi(),iu(),Ma(),Li();const e=document.getElementById("root");if(!e)throw new Error("Root element not found");const o=window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",r=o?{...n,notifications:{notifyAgentCompletion:async()=>!1,canNotify:()=>!1}}:n,i=t.jsx(ou,{apis:r});po.createRoot(e).render(t.jsx(xs.StrictMode,{children:t.jsx(Bi,{children:t.jsx($i,{children:t.jsx(Fi,{children:t.jsx(ua,{children:o?i:t.jsx(Wi,{children:i})})})})})}))}export{_f as renderMobileApp};