@bendyline/gezel-service 1.0.7 → 1.1.0

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 (237) hide show
  1. package/dist/bin/gezeld.js +6253 -3616
  2. package/dist/handboek-content/whats-new/1.26224.md +1 -0
  3. package/dist/handboek-content/whats-new/1.26226.md +1 -0
  4. package/dist/handboek-content/whats-new/1.26231.md +1 -0
  5. package/dist/handboek-content/whats-new/1.26234.md +1 -0
  6. package/dist/handboek-content/whats-new/1.26237.md +1 -0
  7. package/dist/handboek-content/whats-new/1.26244.md +2 -1
  8. package/dist/handboek-content/whats-new/1.26247.md +88 -0
  9. package/dist/handboek-content/whats-new/whats-new-index.md +1 -0
  10. package/dist/index-store/static-index-worker.js +17 -1
  11. package/dist/index.d.ts +473 -209
  12. package/dist/index.js +6251 -3614
  13. package/dist/memory/embed-worker.js +58 -2
  14. package/dist/memory/image-embed-worker.js +8 -0
  15. package/dist/providers/llama-cpp/gguf-metadata-worker.js +2 -0
  16. package/dist/providers/mlx/python/gezel_mlx_server.py +18 -18
  17. package/dist/ui/assets/AmbientDashboardCard-Cf5fi_fY.js +1 -0
  18. package/dist/ui/assets/{AudioEngineSettings-BDrNIGGm.js → AudioEngineSettings-D3L7HOHe.js} +1 -1
  19. package/dist/ui/assets/{BenchmarksView-CHyujjs8.js → BenchmarksView-B68hrLCl.js} +1 -1
  20. package/dist/ui/assets/CatalogBrowser-DEM9t7Es.js +1 -0
  21. package/dist/ui/assets/{ChannelsSettings-Be_W1mr8.js → ChannelsSettings-DtK_k0Ul.js} +1 -1
  22. package/dist/ui/assets/ChatTimelineView-CQ4Sf4Ip.js +7 -0
  23. package/dist/ui/assets/ConfirmDialog-Dt1ed4Fh.js +1 -0
  24. package/dist/ui/assets/ConnectedAppsPanel-Cl8LEkrt.js +1 -0
  25. package/dist/ui/assets/CraftbookEditor-DEQRlQ2p.js +1 -0
  26. package/dist/ui/assets/{CraftbookScriptEditorView-DXIZYZT3.js → CraftbookScriptEditorView-DhXkkIdK.js} +1 -1
  27. package/dist/ui/assets/{CraftbookTabContent-Bm7t_b37.js → CraftbookTabContent-_oIdpQTG.js} +1 -1
  28. package/dist/ui/assets/{CraftbookToolsetSetup-DTEA-3K3.js → CraftbookToolsetSetup-BKg136L1.js} +1 -1
  29. package/dist/ui/assets/{CraftbooksView-C4X99TTe.js → CraftbooksView-Dm2zH-nW.js} +2 -2
  30. package/dist/ui/assets/{DiffpackReviewView-ClcNxtmF.js → DiffpackReviewView-EFLGJnwr.js} +1 -1
  31. package/dist/ui/assets/DocumentDetail-ClDRj2N-.js +1 -0
  32. package/dist/ui/assets/DocumentsView-ny9oieg2.js +1 -0
  33. package/dist/ui/assets/DropdownMenu-S4d9-3j3.js +1 -0
  34. package/dist/ui/assets/Ds4Settings-CeWlm5Vf.js +1 -0
  35. package/dist/ui/assets/EmbeddedChat-Hjrrgpao.js +1 -0
  36. package/dist/ui/assets/{FaceRecognitionCard-D3hdc7uU.js → FaceRecognitionCard-D7ufKqjI.js} +1 -1
  37. package/dist/ui/assets/FileMapView-DRjf59RH.js +1 -0
  38. package/dist/ui/assets/{FoldersSettings-BcNzl4vT.js → FoldersSettings-DDUhaFio.js} +1 -1
  39. package/dist/ui/assets/GezelDetail-Cph6pVGb.js +1 -0
  40. package/dist/ui/assets/{GezelJsonEditor-fOvYclu9.js → GezelJsonEditor-7vDGyBib.js} +1 -1
  41. package/dist/ui/assets/{GezellenView-BTzhHrxi.js → GezellenView-DQhcO1CP.js} +1 -1
  42. package/dist/ui/assets/{GildeUpdatesCard-Bq6XEpLP.js → GildeUpdatesCard-UKKNm_U8.js} +1 -1
  43. package/dist/ui/assets/{GithubSignInChip-CnlTCG8G.js → GithubSignInChip-DjM3qZsL.js} +1 -1
  44. package/dist/ui/assets/{HandboekMediaProvider-BfQW8_Nr.js → HandboekMediaProvider-DixaXTAH.js} +1 -1
  45. package/dist/ui/assets/HandboekView-BeNQqho9.js +1 -0
  46. package/dist/ui/assets/HistoryView-E2szGNGS.js +1 -0
  47. package/dist/ui/assets/{HomeView-CB_5TJIp.css → HomeView-CNeqCFPc.css} +1 -1
  48. package/dist/ui/assets/HomeView-CkiS3DXy.js +1 -0
  49. package/dist/ui/assets/{ImageEngineSettings-BpMfQy4f.js → ImageEngineSettings-BCKT7Gvi.js} +1 -1
  50. package/dist/ui/assets/{ImageRecognitionSettings-Ct-7-Oas.js → ImageRecognitionSettings-DD6syFez.js} +1 -1
  51. package/dist/ui/assets/IncompleteDownloads-BiPaaahS.js +1 -0
  52. package/dist/ui/assets/InstallProgressRow-DyKOI4MU.js +1 -0
  53. package/dist/ui/assets/KnowledgeCatalogsCard-B132vzRa.js +1 -0
  54. package/dist/ui/assets/KnowledgeView-CtPuIlN4.js +1 -0
  55. package/dist/ui/assets/LlamaCppSettings-D6zHcu4W.js +1 -0
  56. package/dist/ui/assets/{MarkdownField-D-0Zw7gM.js → MarkdownField-CK8K3fzj.js} +1 -1
  57. package/dist/ui/assets/MemoriesTree-DzjXzIrM.js +1 -0
  58. package/dist/ui/assets/{MicrophoneSettings-BIaFxyY_.js → MicrophoneSettings-1FH83SCq.js} +1 -1
  59. package/dist/ui/assets/MlxSettings-BYxUqFnJ.js +1 -0
  60. package/dist/ui/assets/ModelPicker-DoXPfQkQ.js +1 -0
  61. package/dist/ui/assets/{NewScriptDialog-D-gkY8TS.js → NewScriptDialog-C5X-7PMt.js} +1 -1
  62. package/dist/ui/assets/NewTaskDialog-Cyqtmigv.js +2 -0
  63. package/dist/ui/assets/{OllamaSettings-oIE2Mech.js → OllamaSettings-DkjmA-sB.js} +1 -1
  64. package/dist/ui/assets/ProjectChat-YEqUME6k.js +5 -0
  65. package/dist/ui/assets/{ProjectConnectionsTab-BZqp-oKI.js → ProjectConnectionsTab-dFCJpW93.js} +1 -1
  66. package/dist/ui/assets/ProjectGitStatusBar-CjZxG54t.js +1 -0
  67. package/dist/ui/assets/{ProjectGithubView-w8suLCsA.js → ProjectGithubView-CQ4-tmPx.js} +1 -1
  68. package/dist/ui/assets/{ProjectMailTab-DGo7eyB8.js → ProjectMailTab-NaScsZJf.js} +1 -1
  69. package/dist/ui/assets/ProjectOverviewView-ChjxbQas.js +1 -0
  70. package/dist/ui/assets/{ProjectTimeline-DRe3D9qY.js → ProjectTimeline-BZpdCisR.js} +1 -1
  71. package/dist/ui/assets/ProjectsView-J77ECk6V.js +7 -0
  72. package/dist/ui/assets/{RecommendedBadge-BKiDixnB.js → RecommendedBadge-D0m68PAu.js} +1 -1
  73. package/dist/ui/assets/{RemoteServersPanel-DGyl6-Rg.js → RemoteServersPanel-BdLOoORu.js} +1 -1
  74. package/dist/ui/assets/ScriptEditorTabs-BFvIiDFZ.js +2 -0
  75. package/dist/ui/assets/ScriptEditorView-B09rm1vz.js +5 -0
  76. package/dist/ui/assets/{ScriptsView-WQc28TmQ.js → ScriptsView-BvNAJXpo.js} +1 -1
  77. package/dist/ui/assets/{SecurityComplianceSettings-DsMEA4J3.js → SecurityComplianceSettings-DzGOnptO.js} +1 -1
  78. package/dist/ui/assets/SessionSwitcher-6okzcxT7.js +1 -0
  79. package/dist/ui/assets/SettingsView-Dur4dLhW.js +3 -0
  80. package/dist/ui/assets/SquisqIntegration-6v3yNOIP.js +2 -0
  81. package/dist/ui/assets/{StorageCleanupDialog-DHqwyMZZ.js → StorageCleanupDialog-OQlomMJD.js} +1 -1
  82. package/dist/ui/assets/{StorageUsageCard-CdT6SU51.js → StorageUsageCard-f6c6qTbM.js} +1 -1
  83. package/dist/ui/assets/Tabs-jE0Z5Tzd.js +1 -0
  84. package/dist/ui/assets/TaskTabContent-0w3kAUWR.js +1 -0
  85. package/dist/ui/assets/TasksView-BVMT4BAY.js +1 -0
  86. package/dist/ui/assets/{TerminalCodeEditor-77pBm6f3.js → TerminalCodeEditor-DO7zLKy-.js} +2 -2
  87. package/dist/ui/assets/ToolsetsEditor-Bb1wD5mV.js +8 -0
  88. package/dist/ui/assets/TransformToolbarButton-BWYkEB0d.js +5 -0
  89. package/dist/ui/assets/UnrecognizedModels-HtdMZUqK.js +1 -0
  90. package/dist/ui/assets/{VideoEngineSettings-DzMeINuv.js → VideoEngineSettings-Dq8Nw_tK.js} +1 -1
  91. package/dist/ui/assets/{WorkspaceIndexPane-DU4yd4Ai.js → WorkspaceIndexPane-fpDz4MwZ.js} +1 -1
  92. package/dist/ui/assets/{api-BX5xXiFs.js → api-BPraLwsh.js} +1 -1
  93. package/dist/ui/assets/chat-thread-memory-Be48zsyG.js +1 -0
  94. package/dist/ui/assets/chunk-6ECMNUIP-DDVjPyfK.js +15 -0
  95. package/dist/ui/assets/{chunk-6N2J7C2B-B5QIrD9m.js → chunk-6N2J7C2B-CsppiLVr.js} +1 -1
  96. package/dist/ui/assets/{chunk-A6N6IN3I-DXok09eC.js → chunk-A6N6IN3I-ofeM4l8g.js} +1 -1
  97. package/dist/ui/assets/chunk-B7GEAZBI-Divd2h1k.js +1 -0
  98. package/dist/ui/assets/chunk-DXYWKZ52-BXcAlClu.js +1 -0
  99. package/dist/ui/assets/chunk-FLR2ARKC-D7wrvQgT.js +2 -0
  100. package/dist/ui/assets/chunk-IIQYS2YH-DKZhWMpn.js +1 -0
  101. package/dist/ui/assets/{chunk-ILCJ3WFD-WRukZ7R1.js → chunk-ILCJ3WFD-CLZxw4Ge.js} +3 -3
  102. package/dist/ui/assets/chunk-OBADJV7C-CDVOcmYt.js +1 -0
  103. package/dist/ui/assets/chunk-Q77KNJIN-BIDRf0aP.js +6 -0
  104. package/dist/ui/assets/chunk-S5PCVMKU-Df5XzhSE.js +6 -0
  105. package/dist/ui/assets/chunk-UBFT2CDQ-FexGDigd.js +31 -0
  106. package/dist/ui/assets/{chunk-USU6HTKB-D5FmDzJU.js → chunk-USU6HTKB-B_p-YcDp.js} +1 -1
  107. package/dist/ui/assets/chunk-VKXOZTYP-BoVvWSBR.js +5 -0
  108. package/dist/ui/assets/{chunk-6RQOV3B3-CwvKotJw.js → chunk-VPWPEMZJ-DRKoa_j0.js} +1 -1
  109. package/dist/ui/assets/{chunk-WATAOG4Y-DXg2lov5.js → chunk-WATAOG4Y-C1EXVPmG.js} +1 -1
  110. package/dist/ui/assets/{container-B7jJtK5V.js → container-Ce94efbg.js} +1 -1
  111. package/dist/ui/assets/csv-62UGQMzZ.js +1 -0
  112. package/dist/ui/assets/data-B2kHjlc5.js +1 -0
  113. package/dist/ui/assets/dist-B9-VrAP8.js +2 -0
  114. package/dist/ui/assets/dist-BaHut5iX.js +2 -0
  115. package/dist/ui/assets/dist-BqGwkOe5.js +225 -0
  116. package/dist/ui/assets/dist-ZnIgkoEi.js +4 -0
  117. package/dist/ui/assets/{dist-BHl1ZAVG.js → dist-l6uUFZMV.js} +2 -2
  118. package/dist/ui/assets/dist-pLLFUPO-.js +1 -0
  119. package/dist/ui/assets/{doc-s6H7T0IO.js → doc-Dr5K49bx.js} +28 -28
  120. package/dist/ui/assets/document-companion-BQk2kS0F.js +1 -0
  121. package/dist/ui/assets/document-import-QoM9UxJr.js +1 -0
  122. package/dist/ui/assets/docx-sXa1Rf41.js +2 -0
  123. package/dist/ui/assets/{epub-B98SgHBz.js → epub-RopMP0ec.js} +4 -4
  124. package/dist/ui/assets/{export-options-Bu-tI6og.js → export-options-f7PKjEBb.js} +1 -1
  125. package/dist/ui/assets/extract-UTAOG7LV-4WDRw1o4.js +1 -0
  126. package/dist/ui/assets/file-browser-c2tf4MIb.js +5 -0
  127. package/dist/ui/assets/html-BGVOMhkv.js +253 -0
  128. package/dist/ui/assets/icons-DWaUNQbT.js +1 -0
  129. package/dist/ui/assets/images-JLBFCDD4-6JitW0hD.js +1 -0
  130. package/dist/ui/assets/index-B8NcxqcR.css +1 -0
  131. package/dist/ui/assets/index-C0DYtvfg.js +34 -0
  132. package/dist/ui/assets/index-J8TOMdvV.js +2 -0
  133. package/dist/ui/assets/{infer-kCLH1C8z.js → infer-LEGOsu64.js} +2 -2
  134. package/dist/ui/assets/ironcalc-BAi5gOlE.js +3 -0
  135. package/dist/ui/assets/layouts-2A7QNF6Y-CVwP7noP.js +1 -0
  136. package/dist/ui/assets/{mail-link-CI6YD6k2.js → mail-link-DXkmCd5b.js} +1 -1
  137. package/dist/ui/assets/markdown-baseline-9B52XlX2.js +1 -0
  138. package/dist/ui/assets/{markdown-Bi9b5f5Y.js → markdown-ryKA_OmY.js} +1 -1
  139. package/dist/ui/assets/materialize-A34OZGEU-xNNKzytx.js +1 -0
  140. package/dist/ui/assets/model-inventory-ykSm_IT5.js +1 -0
  141. package/dist/ui/assets/{model-quantization-BDzrELN_.js → model-quantization-CLO7XLoF.js} +1 -1
  142. package/dist/ui/assets/{monaco-base-BiVSa1J-.js → monaco-base-B1H1U1Sw.js} +1 -1
  143. package/dist/ui/assets/{monaco-setup-UeltVkg_.js → monaco-setup-DjhrGQui.js} +1 -1
  144. package/dist/ui/assets/{new-project-meta-0xhggGA_.js → new-project-meta-_f9sfcRX.js} +1 -1
  145. package/dist/ui/assets/outside-in-D73N1g_b.js +3 -0
  146. package/dist/ui/assets/{pdf-DgTjy3rN.js → pdf-BOjVDlCK.js} +3 -3
  147. package/dist/ui/assets/{pending-drafts-YVW6X55O.js → pending-drafts-B11MKQ9R.js} +1 -1
  148. package/dist/ui/assets/{poppetje-Ce-02Aqi.js → poppetje-DLB8uevw.js} +2 -2
  149. package/dist/ui/assets/pptx-BuxyNxQh.js +6 -0
  150. package/dist/ui/assets/primitives-CWrGZpPI.js +41 -0
  151. package/dist/ui/assets/run-export-ChaMXrKS.js +23 -0
  152. package/dist/ui/assets/squisq-formats-aAdypXoy.js +1 -0
  153. package/dist/ui/assets/standalone-source-q_Zzd1bd.js +11 -0
  154. package/dist/ui/assets/storage-D8pE2zg0.js +1 -0
  155. package/dist/ui/assets/styles-BhnF3s2q.css +1 -0
  156. package/dist/ui/assets/styles-CKVKwqoQ.js +550 -0
  157. package/dist/ui/assets/table-fcouR4db.js +1 -0
  158. package/dist/ui/assets/{terminal-monaco-setup-DNoK2tN4.js → terminal-monaco-setup-BAzrVzeR.js} +1 -1
  159. package/dist/ui/assets/{useCompactLayout-BarJPYcv.js → useCompactLayout-Dtolvzye.js} +0 -0
  160. package/dist/ui/assets/{useCopilotAvailability-BH1nLXQI.js → useCopilotAvailability-3xZvKgTF.js} +1 -1
  161. package/dist/ui/assets/{useDiffpacks-CK8W_OD_.js → useDiffpacks-Dsnr0wtX.js} +1 -1
  162. package/dist/ui/assets/{useGitSync-DWxX5-7K.js → useGitSync-BCTptQsp.js} +1 -1
  163. package/dist/ui/assets/{useShowWorkInProgressFeatures-DwwviLRO.js → useShowWorkInProgressFeatures-BhDNuQiU.js} +1 -1
  164. package/dist/ui/assets/{useTotalRamBytes-WoN_mi-V.js → useTotalRamBytes-DIx-_pf8.js} +1 -1
  165. package/dist/ui/assets/wasm-DdxEDD2H.js +1 -0
  166. package/dist/ui/assets/wasm_bg-DW9Xt_vt.wasm +0 -0
  167. package/dist/ui/assets/xlsx-DyBGuAO1.js +4 -0
  168. package/dist/ui/index.html +19 -18
  169. package/package.json +11 -11
  170. package/dist/ui/assets/AmbientDashboardCard-C1Ee-FKZ.js +0 -1
  171. package/dist/ui/assets/CatalogBrowser-Bz8ZtxPn.js +0 -1
  172. package/dist/ui/assets/ChatTimelineView-Do9EryEH.js +0 -7
  173. package/dist/ui/assets/ConfirmDialog-BHFs6vmJ.js +0 -1
  174. package/dist/ui/assets/ConnectedAppsPanel-BtMayq0R.js +0 -1
  175. package/dist/ui/assets/CraftbookEditor-D5jTzWwF.js +0 -1
  176. package/dist/ui/assets/DocumentDetail-CPU51d04.js +0 -1
  177. package/dist/ui/assets/DocumentsView-B6OyjvJ0.js +0 -1
  178. package/dist/ui/assets/DropdownMenu-D5fCzIrh.js +0 -1
  179. package/dist/ui/assets/Ds4Settings-CrUM_KGP.js +0 -1
  180. package/dist/ui/assets/EmbeddedChat-ue9ia-WY.js +0 -1
  181. package/dist/ui/assets/FileMapView-CxvfDLGA.js +0 -1
  182. package/dist/ui/assets/GezelDetail-DHuqBK55.js +0 -1
  183. package/dist/ui/assets/HandboekView-CPnnyj29.js +0 -1
  184. package/dist/ui/assets/HistoryView-B4VAfEMe.js +0 -1
  185. package/dist/ui/assets/HomeView-ccH60J6f.js +0 -1
  186. package/dist/ui/assets/KnowledgeCatalogsCard-Bi5Rx9Iz.js +0 -1
  187. package/dist/ui/assets/KnowledgeView-DAwjwLZo.js +0 -1
  188. package/dist/ui/assets/LlamaCppSettings-Ceyk9pDP.js +0 -1
  189. package/dist/ui/assets/MemoriesTree-BKZEPJpm.js +0 -1
  190. package/dist/ui/assets/MlxSettings-CG3wfuc3.js +0 -1
  191. package/dist/ui/assets/ModelPicker-CCBVjLMS.js +0 -1
  192. package/dist/ui/assets/NewPathDialog-D4jnNBfP.js +0 -1
  193. package/dist/ui/assets/NewTaskDialog-Ox9D612Z.js +0 -2
  194. package/dist/ui/assets/ProjectChat-DMwKnkW-.js +0 -5
  195. package/dist/ui/assets/ProjectGitStatusBar-C6bkCSby.js +0 -1
  196. package/dist/ui/assets/ProjectOverviewView-NNwXd_QQ.js +0 -1
  197. package/dist/ui/assets/ProjectsView-SBPgYOq8.js +0 -7
  198. package/dist/ui/assets/ScriptEditorTabs-paocQ6dj.js +0 -2
  199. package/dist/ui/assets/ScriptEditorView-N9zSLqqi.js +0 -5
  200. package/dist/ui/assets/SessionSwitcher-C8te7YSe.js +0 -1
  201. package/dist/ui/assets/SettingsView-Brl4JQkW.js +0 -3
  202. package/dist/ui/assets/Tabs-BAY1Q79B.js +0 -1
  203. package/dist/ui/assets/TaskTabContent-CNPJ4DQj.js +0 -1
  204. package/dist/ui/assets/TasksView-DuMjFS8S.js +0 -1
  205. package/dist/ui/assets/ToolsetsEditor-BdxHnIBj.js +0 -8
  206. package/dist/ui/assets/TransformToolbarButton-CVg5nz36.js +0 -5
  207. package/dist/ui/assets/UnrecognizedModels-Cw9Ku_bW.js +0 -1
  208. package/dist/ui/assets/chat-thread-memory-CZGcwgGo.js +0 -1
  209. package/dist/ui/assets/chunk-6ECMNUIP-C1kohb1U.js +0 -15
  210. package/dist/ui/assets/chunk-AONELFLA-Cv2nS9ga.js +0 -1
  211. package/dist/ui/assets/chunk-IIQYS2YH-Dxg6MAfT.js +0 -1
  212. package/dist/ui/assets/chunk-MIKKUKOD-XIkmalSN.js +0 -31
  213. package/dist/ui/assets/chunk-NNJLSQPW-DJA6camf.js +0 -5
  214. package/dist/ui/assets/chunk-S5PCVMKU-DbCZ5AUH.js +0 -6
  215. package/dist/ui/assets/csv-xmd1_Aqd.js +0 -4
  216. package/dist/ui/assets/dist-BPx-FyRH.js +0 -222
  217. package/dist/ui/assets/dist-Bvo52IGx.js +0 -1
  218. package/dist/ui/assets/dist-D5aoNQwk.js +0 -2
  219. package/dist/ui/assets/docx-Cj4A9MhC.js +0 -2
  220. package/dist/ui/assets/extract-UTAOG7LV-C4b7ycaL.js +0 -1
  221. package/dist/ui/assets/file-browser-80qWoVju.js +0 -5
  222. package/dist/ui/assets/html-C9TlzI57.js +0 -253
  223. package/dist/ui/assets/icons-C9dD-bDi.js +0 -1
  224. package/dist/ui/assets/images-ESPQKVTW-D7SgdVJ_.js +0 -1
  225. package/dist/ui/assets/index-D1m4Wx8V.css +0 -1
  226. package/dist/ui/assets/index-DXWR4qW1.js +0 -34
  227. package/dist/ui/assets/layouts-2A7QNF6Y-De2t-YXl.js +0 -1
  228. package/dist/ui/assets/markdown-baseline-HMqF2ChK.js +0 -1
  229. package/dist/ui/assets/outside-in-BFVUUcLa.js +0 -3
  230. package/dist/ui/assets/pptx-6ChgUEf4.js +0 -6
  231. package/dist/ui/assets/primitives-DEsn1shf.js +0 -41
  232. package/dist/ui/assets/run-export-BrYhHj1O.js +0 -23
  233. package/dist/ui/assets/standalone-source-D6mbpa3h.js +0 -11
  234. package/dist/ui/assets/storage-fn4FCEVK.js +0 -1
  235. package/dist/ui/assets/styles-C0EoNJbk.css +0 -1
  236. package/dist/ui/assets/styles-CKr_yrbn.js +0 -541
  237. package/dist/ui/assets/xlsx-DH7sTb3W.js +0 -4
@@ -0,0 +1,7 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-BaHut5iX.js","assets/rolldown-runtime-aKtaBQYM.js","assets/dist-BqGwkOe5.js"])))=>i.map(i=>d[i]);
2
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{B as r,Ft as i,G as a,Pt as o,V as s,W as c,cn as l,hn as u,it as d,nn as f,rt as p,tn as m,yt as h}from"./dist-BqGwkOe5.js";import{a as g}from"./dist-BaHut5iX.js";import{t as _}from"./api-BPraLwsh.js";import{_ as v,g as y,o as ee,v as b}from"./primitives-CWrGZpPI.js";import{n as x,t as S}from"./relative-time-B2kBaekd.js";import{t as C}from"./preload-helper-Czpn1I53.js";import{c as w,i as T,l as E,n as te,o as D,s as ne}from"./styles-CKVKwqoQ.js";import{C as O,Ct as re,D as k,E as A,It as j,O as ie,St as M,T as ae,bt as oe,ft as se,ht as ce,i as le,k as ue,p as de,vt as fe,w as pe,xt as me,y as N,yt as he,zt as ge}from"./index-C0DYtvfg.js";import{c as P,o as F,r as _e}from"./SquisqIntegration-6v3yNOIP.js";import{n as I,t as ve}from"./microphone-input-5gqW_NKf.js";import{r as ye,t as be}from"./composer-prefill-CbG_i1Rx.js";var L=e(t(),1),R=n();function z(e){return e.replace(/\.[^.]+$/,``).replace(/[-_]/g,` `)}function xe(e){return e.replace(/([\\\[\]])/g,`\\$1`)}function Se(){return(0,R.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,children:[(0,R.jsx)(`rect`,{x:`2`,y:`2.5`,width:`12`,height:`11`,rx:`1.5`,stroke:`currentColor`,strokeWidth:`1.35`}),(0,R.jsx)(`circle`,{cx:`5.25`,cy:`5.75`,r:`1.1`,stroke:`currentColor`,strokeWidth:`1.2`}),(0,R.jsx)(`path`,{d:`m3.5 12 3.1-3.25 2.05 1.9 1.55-1.55 2.3 2.9`,stroke:`currentColor`,strokeWidth:`1.35`,strokeLinecap:`round`,strokeLinejoin:`round`})]})}function Ce(){return(0,R.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,children:(0,R.jsx)(`path`,{d:`m5.25 8.7 4.2-4.2a2.1 2.1 0 0 1 2.97 2.97l-5.1 5.1a3.2 3.2 0 0 1-4.53-4.52l5-5`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinecap:`round`,strokeLinejoin:`round`})})}function we({mediaProvider:e,onError:t}){let{bumpMediaRevision:n,insertAtCursor:r}=T(),i=(0,L.useRef)(null),a=(0,L.useRef)(null),[o,s]=(0,L.useState)(null),c=(0,L.useCallback)(async(i,a)=>{s(a),t(null);try{let t=i.type||`application/octet-stream`,o=await e.addMedia(i.name,await i.arrayBuffer(),t);n();let s=xe(z(i.name));r(a===`image`?`![${s}](${o})`:`[${s}](${o})`)}catch(e){t(e instanceof Error?e.message:`Could not attach that file.`)}finally{s(null)}},[n,r,e,t]),l=(0,L.useCallback)((e,t)=>{let n=e.target.files?.[0];e.target.value=``,n&&c(n,t)},[c]);return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`chat-composer-attachment-actions`,children:[(0,R.jsx)(`input`,{ref:i,type:`file`,accept:`image/*`,hidden:!0,onChange:e=>l(e,`image`)}),(0,R.jsx)(`input`,{ref:a,type:`file`,hidden:!0,onChange:e=>l(e,`file`)}),(0,R.jsx)(`button`,{type:`button`,className:`squisq-toolbar-button`,onClick:()=>i.current?.click(),disabled:o!==null,"aria-label":o===`image`?`Inserting image…`:`Insert image`,"aria-busy":o===`image`,title:`Insert image`,"data-tooltip":`Insert image`,children:(0,R.jsx)(Se,{})}),(0,R.jsx)(`button`,{type:`button`,className:`squisq-toolbar-button`,onClick:()=>a.current?.click(),disabled:o!==null,"aria-label":o===`file`?`Attaching file…`:`Attach file`,"aria-busy":o===`file`,title:`Attach file`,"data-tooltip":`Attach file`,children:(0,R.jsx)(Ce,{})})]}),(0,R.jsx)(`span`,{className:`chat-composer-toolbar-spacer`,"aria-hidden":`true`})]})}var B=50;function Te(e){return typeof AudioContext>`u`?null:new Ee(e)}var Ee=class{stream;context=null;source=null;analyser=null;timer=null;samples=null;noiseFloor=.004;speaking=!1;constructor(e){this.stream=e}start(e){if(this.timer!==null)return;let t=new AudioContext;this.context=t;try{let e=t.createMediaStreamSource(this.stream),n=t.createAnalyser();n.fftSize=1024,n.smoothingTimeConstant=.15,e.connect(n),this.source=e,this.analyser=n,this.samples=new Float32Array(n.fftSize),t.resume().catch(()=>void 0)}catch(e){throw this.stop(),e}this.timer=setInterval(()=>{if(!this.analyser||!this.samples)return;this.analyser.getFloatTimeDomainData(this.samples);let t=V(this.samples),n=Math.max(.012,this.noiseFloor*2.8),r=Math.max(.008,this.noiseFloor*1.8);this.speaking=t>=(this.speaking?r:n),this.speaking||(this.noiseFloor=Math.min(.03,this.noiseFloor*.95+t*.05)),e(this.speaking,t)},B)}stop(){this.timer!==null&&(clearInterval(this.timer),this.timer=null),this.source?.disconnect(),this.analyser?.disconnect(),this.source=null,this.analyser=null,this.samples=null;let e=this.context;this.context=null,e&&e.close().catch(()=>void 0)}};function V(e){if(e.length===0)return 0;let t=0;for(let n of e)t+=n*n;return Math.sqrt(t/e.length)}var De=2500,Oe=350,ke=650,Ae=1e4,je=1e3,Me=class{stream;mimeType;segmentMs;speechPauseMs;minSegmentMs;longPauseMs;transcribe;onTranscript;onError;onLongPause;onAudioLevel;abortController=new AbortController;activityMonitor;activityMonitorStarted=!1;recorder=null;chunks=[];segmentTimer=null;transcriptionQueue=Promise.resolve();stopPromise=null;resolveStop=null;finalSegmentRequested=!1;segmentStartedAt=0;segmentHasSpeech=!1;currentlySpeaking=!1;lastSpeechAt=null;confirmedSilenceMs=0;recognitionPrompt=``;hasTranscript=!1;longPauseNotified=!1;disposed=!1;constructor(e){this.stream=e.stream,this.mimeType=e.mimeType??``,this.segmentMs=e.segmentMs??De,this.speechPauseMs=e.speechPauseMs??Oe,this.minSegmentMs=e.minSegmentMs??ke,this.longPauseMs=e.longPauseMs??Ae,this.activityMonitor=e.activityMonitor===void 0?Te(e.stream):e.activityMonitor,this.transcribe=e.transcribe,this.onTranscript=e.onTranscript,this.onError=e.onError,this.onLongPause=e.onLongPause,this.onAudioLevel=e.onAudioLevel}start(){this.disposed||this.recorder||(this.startSegment(),this.startActivityMonitor())}stop(){if(this.stopPromise)return this.stopPromise;this.finalSegmentRequested=!0,this.stopActivityMonitor(),this.clearSegmentTimer(),this.stopPromise=new Promise(e=>{this.resolveStop=e});let e=this.recorder;return e?.state===`recording`?e.stop():e||this.finish(),this.stopPromise}cancel(){if(this.disposed)return;this.disposed=!0,this.abortController.abort(),this.stopActivityMonitor(),this.clearSegmentTimer();let e=this.recorder;if(this.recorder=null,e&&(e.ondataavailable=null,e.onstop=null,e.onerror=null,e.state!==`inactive`))try{e.stop()}catch{}this.releaseStream(),this.resolveStop?.(),this.resolveStop=null}startSegment(){if(this.disposed||this.finalSegmentRequested)return;let e=this.mimeType?{mimeType:this.mimeType}:void 0,t=new MediaRecorder(this.stream,e);this.recorder=t,this.chunks=[],this.segmentStartedAt=Date.now(),this.segmentHasSpeech=this.currentlySpeaking,t.ondataavailable=e=>{!this.disposed&&e.data.size>0&&this.chunks.push(e.data)},t.onerror=e=>{let t=e.error;this.onError(t??Error(`Microphone recording failed.`)),this.finalSegmentRequested=!0,this.clearSegmentTimer()},t.onstop=()=>{if(this.disposed||this.recorder!==t)return;this.recorder=null;let e=t.mimeType||this.mimeType||`audio/webm`,n=new Blob(this.chunks,{type:e}),r=Math.max(0,Date.now()-this.segmentStartedAt);this.chunks=[],this.finalSegmentRequested||this.startSegment(),n.size>0&&this.enqueueTranscription(n,e,r),this.finalSegmentRequested&&this.finish()},t.start(),this.segmentTimer=setTimeout(()=>{this.segmentTimer=null,!this.disposed&&!this.finalSegmentRequested&&t.state===`recording`&&t.stop()},this.segmentMs)}startActivityMonitor(){if(!(!this.activityMonitor||this.activityMonitorStarted))try{this.activityMonitor.start((e,t)=>{this.onAudioLevel?.(t),this.onSpeechActivity(e)}),this.activityMonitorStarted=!0}catch{this.activityMonitor.stop(),this.activityMonitor=null}}stopActivityMonitor(){this.activityMonitor?.stop()}onSpeechActivity(e){if(this.disposed||this.finalSegmentRequested)return;let t=Date.now();if(this.currentlySpeaking=e,e){this.segmentHasSpeech=!0,this.lastSpeechAt=t,this.longPauseNotified=!1;return}if(this.lastSpeechAt===null)return;let n=t-this.lastSpeechAt;this.segmentHasSpeech&&t-this.segmentStartedAt>=this.minSegmentMs&&n>=this.speechPauseMs&&this.flushCurrentSegment()}flushCurrentSegment(){let e=this.recorder;!e||e.state!==`recording`||(this.clearSegmentTimer(),e.stop())}enqueueTranscription(e,t,n){this.transcriptionQueue=this.transcriptionQueue.then(async()=>{if(!this.disposed)try{let r=H(await this.transcribe(e,t,this.abortController.signal,this.recognitionPrompt));if(this.disposed)return;if(r){this.confirmedSilenceMs=0,this.hasTranscript=!0,this.longPauseNotified=!1,this.recognitionPrompt=Ne(this.recognitionPrompt,r),this.onTranscript(r);return}this.confirmedSilenceMs+=n,!this.longPauseNotified&&this.onLongPause&&this.confirmedSilenceMs>=this.longPauseMs&&(this.longPauseNotified=!0,this.onLongPause(this.hasTranscript))}catch(e){if(this.disposed||this.abortController.signal.aborted)return;this.onError(e instanceof Error?e:Error(String(e)))}})}async finish(){this.clearSegmentTimer(),this.stopActivityMonitor(),this.releaseStream(),await this.transcriptionQueue,!this.disposed&&(this.disposed=!0,this.resolveStop?.(),this.resolveStop=null)}clearSegmentTimer(){this.segmentTimer!==null&&(clearTimeout(this.segmentTimer),this.segmentTimer=null)}releaseStream(){for(let e of this.stream.getTracks())e.stop()}};function H(e){let t=e.trim();return/^\[\s*BLANK_AUDIO\s*\]$/i.test(t)?``:t}function Ne(e,t){let n=`${e.trim()} ${t.trim()}`.trim();if(n.length<=je)return n;let r=n.slice(-1e3),i=r.search(/\s/);return(i>=0?r.slice(i+1):r).trim()}async function Pe(e){if(/^audio\/(?:wav|wave|x-wav)(?:;|$)/i.test(e.type))return e;if(typeof AudioContext>`u`)throw Error(`This recording could not be prepared for speech-to-text.`);let t=new AudioContext;try{let n=await t.decodeAudioData(await e.arrayBuffer()),r=Fe(Array.from({length:n.numberOfChannels},(e,t)=>n.getChannelData(t)),n.sampleRate);return new Blob([r.buffer],{type:`audio/wav`})}catch(e){let t=e instanceof Error&&e.message?` (${e.message})`:``;throw Error(`This recording could not be prepared for speech-to-text${t}`)}finally{await t.close().catch(()=>void 0)}}function Fe(e,t){let n=e[0]?.length??0;if(e.length===0||n===0)throw Error(`The microphone recording was empty.`);if(!Number.isFinite(t)||t<=0)throw Error(`The microphone recording has an invalid sample rate.`);if(e.some(e=>e.length!==n))throw Error(`The microphone recording channels have different lengths.`);let r=n*2,i=new ArrayBuffer(44+r),a=new DataView(i);Ie(a,0,`RIFF`),a.setUint32(4,36+r,!0),Ie(a,8,`WAVE`),Ie(a,12,`fmt `),a.setUint32(16,16,!0),a.setUint16(20,1,!0),a.setUint16(22,1,!0),a.setUint32(24,Math.round(t),!0),a.setUint32(28,Math.round(t)*2,!0),a.setUint16(32,2,!0),a.setUint16(34,16,!0),Ie(a,36,`data`),a.setUint32(40,r,!0);for(let t=0;t<n;t+=1){let n=0;for(let r of e)n+=r[t]??0;n=Math.max(-1,Math.min(1,n/e.length));let r=Math.round(n<0?n*32768:n*32767);a.setInt16(44+t*2,r,!0)}return new Uint8Array(i)}function Ie(e,t,n){for(let r=0;r<n.length;r+=1)e.setUint8(t+r,n.charCodeAt(r))}var Le=12;function Re({projectId:e,disabled:t=!1,onTranscript:n,onError:r}){let[i,a]=(0,L.useState)(`idle`),[o,s]=(0,L.useState)(()=>ze()),c=(0,L.useRef)(null),l=(0,L.useRef)(!0),u=(0,L.useRef)(!1),d=(0,L.useRef)(0),f=(0,L.useRef)(e),p=E()&&w();(0,L.useEffect)(()=>(l.current=!0,()=>{l.current=!1,d.current+=1,c.current?.cancel(),c.current=null}),[]),(0,L.useEffect)(()=>{f.current!==e&&(f.current=e,d.current+=1,c.current?.cancel(),c.current=null,u.current=!1,a(`idle`),s(ze()))},[e]);let m=(0,L.useCallback)(async()=>{let e=c.current;if(e){a(`transcribing`);try{await e.stop()}finally{c.current===e&&(c.current=null),l.current&&a(`idle`)}}},[]),h=(0,L.useCallback)(async()=>{if(!p||t||u.current||c.current)return;u.current=!0;let i=d.current;a(`requesting`),s(ze()),r(null);let o=null;try{let t=await _.getConfig().catch(()=>void 0),u={...t?.microphoneDeviceId?{deviceId:t.microphoneDeviceId}:{},...t?.microphoneDeviceLabel?{label:t.microphoneDeviceLabel}:{}},f=I(u.deviceId||u.label?await ve().catch(()=>[]):[],u),p=f?.deviceId??u.deviceId;if(o=await D({echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0,...p?{deviceId:{exact:p}}:{}}),!l.current||i!==d.current){for(let e of o.getTracks())e.stop();return}let h=o.getAudioTracks?.()[0]?.label?.trim()||f?.label||u.label,g=ne(`audio`),v=new Me({stream:o,...g.mimeType?{mimeType:g.mimeType}:{},transcribe:async(t,n,i,a)=>{let o=await Pe(t),s=H((await _.transcribeAudio({audio:{data:await U(o),mimeType:o.type||n},projectId:e,signal:i,...a?{prompt:a}:{}})).text);return s?(r(null),s):``},onTranscript:n,onAudioLevel:e=>{if(!l.current||i!==d.current)return;let t=Be(e);s(e=>[...e.slice(1),t])},onLongPause:e=>{e||r(`No speech detected${h?` from ${h}`:``}. Choose the microphone in Settings → Device Integration if this isn't the expected input.`),m()},onError:e=>{v.cancel(),c.current===v&&(c.current=null,l.current&&i===d.current&&(a(`idle`),r(W(e))))}});c.current=v,v.start(),o=null,a(`recording`)}catch(e){if(o)for(let e of o.getTracks())e.stop();l.current&&i===d.current&&(a(`idle`),r(W(e)))}finally{i===d.current&&(u.current=!1)}},[t,r,n,e,m,p]),g=i===`recording`,v=!p;return(0,R.jsxs)(`button`,{type:`button`,className:`chat-narrate-btn${g?` chat-narrate-btn-recording`:``}`,"data-testid":`chat-narrate`,onClick:g?()=>void m():()=>void h(),disabled:i===`requesting`||i===`transcribing`||i===`idle`&&(t||v),"aria-label":i===`requesting`?`Starting microphone…`:g?`Stop narrating`:i===`transcribing`?`Finishing transcription…`:`Narrate prompt`,"aria-pressed":g,"aria-busy":i===`requesting`||i===`transcribing`,title:v?`Voice input is unavailable in this browser`:g?`Listening — short pauses add speech; click to finish now`:i===`transcribing`?`Adding the remaining speech to this prompt`:`Narrate this prompt with your microphone`,children:[(0,R.jsx)(Ue,{}),g&&(0,R.jsx)(Ve,{levels:o}),g&&(0,R.jsx)(`span`,{className:`chat-narrate-live-dot`,"aria-hidden":`true`})]})}function ze(){return Array.from({length:Le},()=>0)}function Be(e){return Math.min(1,Math.max(0,e*14))}function Ve({levels:e}){return(0,R.jsx)(`span`,{className:`chat-narrate-waveform`,"data-testid":`microphone-waveform`,"aria-hidden":`true`,children:e.map((e,t)=>(0,R.jsx)(`span`,{className:`chat-narrate-waveform-bar`,style:{height:`${2+e*14}px`}},t))})}async function U(e){let t=new Uint8Array(await e.arrayBuffer()),n=``,r=32768;for(let e=0;e<t.length;e+=r)n+=String.fromCharCode(...t.subarray(e,e+r));return btoa(n)}function W(e){let t=e instanceof Error?e:Error(String(e)),n=He(t)??t.message;return t.name===`NotAllowedError`||/permission|not allowed|denied/i.test(n)?`Microphone access was not granted. Allow it in your system settings, then try again.`:t.name===`OverconstrainedError`||/constraint|selected microphone/i.test(n)?`The selected microphone is unavailable. Choose another in Settings → Device Integration.`:t.name===`NotFoundError`||/requested device not found|no microphone/i.test(n)?`No microphone is available.`:/speech_to_text_not_ready|no stt model|download one from settings|speech-to-text model/i.test(n)?`Speech-to-text is not ready. Download a model in Settings → Audio, then try again.`:/speech_to_text_failed/i.test(n)?`Speech-to-text could not transcribe this recording. Check Settings → Audio, then try again.`:`Could not narrate this prompt: ${n}`}function He(e){let t=e.details;if(t&&typeof t==`object`&&`error`in t){let e=t.error;if(typeof e==`string`&&e.trim())return e.trim()}return typeof t==`string`&&t.trim()?t.trim():null}function Ue(){return(0,R.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,focusable:`false`,children:[(0,R.jsx)(`rect`,{x:`5.25`,y:`1.5`,width:`5.5`,height:`8`,rx:`2.75`,stroke:`currentColor`}),(0,R.jsx)(`path`,{d:`M3.5 7.5a4.5 4.5 0 0 0 9 0M8 12v2.5M5.75 14.5h4.5`,stroke:`currentColor`})]})}function We({gezels:e,primaryGezelId:t,additionalRecipientIds:n,roleBasedNameOnlyMode:r,onSelectPrimary:i,onAddRecipient:a}){let[o,c]=(0,L.useState)(!1),[l,u]=(0,L.useState)(``),d=(0,L.useMemo)(()=>{let t=new Set;return e.filter(e=>t.has(e.id)?!1:(t.add(e.id),!0)).map(e=>({gezel:e,rendered:s({name:e.name,roleBasedName:e.roleBasedName},r)}))},[e,r]),f=d.length>8,p=l.trim().toLowerCase(),m=f&&p?d.filter(({gezel:e,rendered:t})=>t.toLowerCase().includes(p)||(e.role??``).toLowerCase().includes(p)):d,h=new Set(n);return(0,R.jsxs)(v,{open:o,onOpenChange:e=>{c(e),e||u(``)},children:[(0,R.jsx)(b,{asChild:!0,children:(0,R.jsx)(`button`,{type:`button`,className:`chat-composer-recipient-trigger`,"aria-label":`Choose recipients`,title:`Add or change recipients`,children:(0,R.jsx)(`span`,{className:`chat-recipient-plus-glyph`,"aria-hidden":`true`,children:`+`})})}),(0,R.jsxs)(y,{className:`chat-recipient-popover`,align:`end`,side:`top`,"aria-label":`Choose a gezel`,children:[(0,R.jsx)(`span`,{className:`chat-recipient-popover-label`,children:`Choose a gezel`}),f&&(0,R.jsx)(`input`,{className:`chat-recipient-search`,type:`search`,value:l,placeholder:`Search by name or role`,"aria-label":`Search gezels`,onChange:e=>u(e.target.value)}),(0,R.jsxs)(`div`,{className:`chat-recipient-list`,children:[m.map(({gezel:e,rendered:n})=>{let r=e.id===t,o=h.has(e.id);return(0,R.jsxs)(`div`,{className:`chat-recipient-option${r?` chat-recipient-option-primary`:``}`,children:[(0,R.jsxs)(`button`,{type:`button`,className:`chat-recipient-select`,"aria-current":r?`true`:void 0,"aria-label":`Talk to ${n}`,onClick:()=>{i(e.id),c(!1)},children:[(0,R.jsx)(j,{svg:e.icon??null,poppetje:e.poppetje,iconOverride:e.iconOverride,name:n,size:26}),(0,R.jsxs)(`span`,{className:`chat-recipient-option-text`,children:[(0,R.jsx)(`span`,{className:`chat-recipient-option-name`,children:n}),e.role&&(0,R.jsx)(`span`,{className:`chat-recipient-option-role`,children:e.role})]})]}),r||o?(0,R.jsx)(`span`,{className:`chat-recipient-option-state`,children:r?`To`:`Added`}):(0,R.jsx)(`button`,{type:`button`,className:`chat-recipient-add`,"aria-label":`Add ${n} to recipients`,title:`Add ${n}`,onClick:()=>a(e.id),children:(0,R.jsx)(`span`,{className:`chat-recipient-plus-glyph`,"aria-hidden":`true`,children:`+`})})]},e.id)}),m.length===0&&(0,R.jsx)(`p`,{className:`muted small chat-recipient-empty`,children:`No matches.`})]})]})]})}var Ge=new Map,Ke=`data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=`;function qe(e){let t=e.trim();return/^(?:data|blob):/i.test(t)?!1:t.startsWith(`//`)||/^[a-z][a-z0-9+.-]*:/i.test(t)}function Je(e,t){let n=`${e}:${t}`,r=Ge.get(n);return r||(r=G({projectId:e,legacySessionId:t}),Ge.set(n,r)),r}function G(e){let t=new Map,n=new Map,r=async(e,t)=>{if(e instanceof Blob)return e;let n=e instanceof Uint8Array?e:new Uint8Array(e),r=new Uint8Array(n.byteLength);return r.set(n),new Blob([r.buffer],{type:t})},i=e=>{let t=/^attachments\/([^/]+)$/.exec(e);if(t)return{scope:`attachments`,filename:t[1]};let n=/^images\/([^/]+)$/.exec(e);if(n)return{scope:`images`,filename:n[1]};let r=/^artifacts\/(.+)$/.exec(e);return r?{scope:`artifact`,path:r[1]}:/^generated\/[^/].*\.(png|jpe?g|gif|webp|svg)$/i.test(e)?{scope:`artifact`,path:e}:null};return{async addMedia(n,i,a){let o=await r(i,a),s=await _.uploadProjectAttachment(e.projectId,o,a,n);return t.set(s.relativePath,URL.createObjectURL(o)),s.relativePath},async resolveUrl(r){if(qe(r))return Ke;if(/^(?:data|blob):/i.test(r.trim()))return r;let a=t.get(r);if(a)return a;let o=n.get(r);if(o)return o;let s=i(r);if(!s)return r;let c=(async()=>{try{let n;if(s.scope===`attachments`)n=await _.fetchProjectAttachment(e.projectId,s.filename);else if(s.scope===`artifact`)n=await _.fetchProjectArtifactBlob(e.projectId,s.path);else{if(!e.legacySessionId)return r;n=await _.fetchSessionImage(e.projectId,e.legacySessionId,s.filename)}let i=URL.createObjectURL(n);return t.set(r,i),i}finally{n.delete(r)}})();return n.set(r,c),c},async listMedia(){return(await _.listProjectAttachments(e.projectId)).attachments.map(e=>({name:`attachments/${e.filename}`,mimeType:e.mimeType,size:e.size}))},async removeMedia(n){let r=i(n);if(!r)return;r.scope===`attachments`?await _.deleteProjectAttachment(e.projectId,r.filename):r.scope===`images`&&e.legacySessionId&&await _.deleteSessionImage(e.projectId,e.legacySessionId,r.filename);let a=t.get(n);a&&(URL.revokeObjectURL(a),t.delete(n))},dispose(){for(let e of t.values())URL.revokeObjectURL(e);t.clear(),n.clear()}}}function Ye(e){let t=e.trim();return/^(?:data|blob):/i.test(t)?!1:t.startsWith(`//`)||/^[a-z][a-z0-9+.-]*:/i.test(t)}function Xe(e){let t=new Map,n=null,r=n=>{let r=t.get(n);return r||(r=F(_e({projectId:e.projectId,root:`prompts/${n}/message_files`,client:_,referencePrefix:`message_files`}),`message_files`),t.set(n,r)),r},i=()=>(n??=G({projectId:e.projectId}),n);return{async addMedia(t,n,i){let a=await e.ensureDraftId();return r(a).addMedia(t,n,i)},async resolveUrl(t){if(Ye(t))return Ke;if(/^(?:data|blob):/i.test(t.trim()))return t;let n=e.getDraftId(),a=t.replace(/^\.\//,``).replace(/^\/+/,``);return n&&a.startsWith(`message_files/`)?r(n).resolveUrl(t):i().resolveUrl(t)},async listMedia(){let t=e.getDraftId();return t?r(t).listMedia():[]},async removeMedia(t){let n=e.getDraftId(),a=t.replace(/^\.\//,``).replace(/^\/+/,``);if(n&&a.startsWith(`message_files/`)){await r(n).removeMedia(t);return}await i().removeMedia(t)},dispose(){for(let e of t.values())e.dispose();t.clear(),n?.dispose(),n=null}}}function Ze(e){if(e.includes(`
3
+ `)||e.includes(`\r`))return null;let t=e.trim().match(/^\/open(?:[ \t]+(.*))?$/i);return t?(t[1]??``).trim():null}function Qe(e,t,n=8){let r=K(e),i=[`workspace`,`artifacts`].map(e=>({key:`folder:${e}`,label:e,description:`Open the project ${e} folder`,target:{type:`folder`,folder:e}})).filter(e=>et(r,e.label)),a=new Set,o=[];for(let e of t){let t=`${e.projectId??``}:${e.kind}:${K(e.path)}`;if(!a.has(t)&&(a.add(t),!(!et(r,e.path)&&!et(r,tt(e.path)))&&(o.push({key:`reference:${e.key}`,label:e.path,description:`Open recent ${e.kind}`,target:{type:`reference`,reference:e}}),o.length>=n)))break}return[...i,...o]}function $e(e,t){let n=K(e);if(n===`workspace`||n===`artifacts`)return{type:`folder`,folder:n};if(!n)return null;let r=t.find(e=>K(e.path)===n);if(r)return{type:`reference`,reference:r};let i=t.filter(e=>K(tt(e.path))===n);return i.length===1?{type:`reference`,reference:i[0]}:null}function K(e){return e.trim().replaceAll(`\\`,`/`).toLowerCase()}function et(e,t){return!e||K(t).includes(e)}function tt(e){let t=e.replaceAll(`\\`,`/`);return t.slice(t.lastIndexOf(`/`)+1)}var nt=new Set;function rt(e){for(let t of nt)t(e)}function it(e){return nt.add(e),()=>{nt.delete(e)}}var at=64,q=new Map,J=new Map;function ot(e){return[e.scope??`chat`,e.projectId,e.gezelId,e.taskRef??``,e.craftbookRef??``].join(`|`)}function st(e){return`${ot(e)}|${e.sessionId??`new`}`}function ct(e){return q.get(e)}function Y(e,t){if(!t){q.delete(e);return}for(q.delete(e),q.set(e,t);q.size>at;){let e=q.keys().next();if(e.done)break;q.delete(e.value)}}var lt=new Set;function ut(e){return lt.add(e),()=>{lt.delete(e)}}function X(){for(let e of lt)e()}function Z(e){return J.get(e)}function Q(e,t){for(J.delete(e),J.set(e,t);J.size>at;){let e=J.keys().next();if(e.done)break;J.delete(e.value)}X()}function $(e){J.delete(e);for(let[t,n]of q)n===e&&q.delete(t);X()}var dt=1e3;function ft(e){let{address:t,sessionId:n,draftId:r,onDraftIdChange:i,getText:a,onLoaded:o}=e,{scope:s,projectId:c,gezelId:l,taskRef:u,craftbookRef:d}=t,f=(0,L.useMemo)(()=>st({...s?{scope:s}:{},projectId:c,gezelId:l,...u?{taskRef:u}:{},...d?{craftbookRef:d}:{},sessionId:n??null}),[s,c,l,u,d,n]),[p,m]=(0,L.useState)(()=>r??ct(f)??null),[h,g]=(0,L.useState)(null),[v,y]=(0,L.useState)({phase:`idle`,dirty:!1,error:null}),ee=(0,L.useRef)(p),b=(0,L.useRef)(f),x=(0,L.useRef)(!1),S=(0,L.useRef)(n===void 0),C=(0,L.useRef)(!1),w=(0,L.useRef)(null),T=(0,L.useRef)(!1),E=(0,L.useRef)(0),te=(0,L.useRef)(a);te.current=a;let D=(0,L.useRef)(o);D.current=o;let ne=(0,L.useRef)(i);ne.current=i;let O=(0,L.useRef)(t);O.current=t;let re=(0,L.useRef)(n);re.current=n;let k=(0,L.useCallback)(e=>{ee.current=e,m(e)},[]),A=(0,L.useRef)(null),j=(0,L.useRef)(null),ie=(0,L.useCallback)(async e=>{let t=ee.current;if(!t)return;let n=O.current.projectId;if(!e.trim()&&!x.current){await _.deletePromptDraft(n,t).catch(()=>{}),$(t),Y(b.current,void 0),A.current=null,j.current=null,k(null),g(null),ne.current?.(void 0);return}try{let r=await _.writePromptDraftContent(n,t,e);if(r.deleted){$(t),Y(b.current,void 0),k(null),g(null),ne.current?.(void 0);return}r.draft&&(g(r.draft),x.current=r.draft.hasFiles),Q(t,e)}catch(e){if(pt(e)){$(t),Y(b.current,void 0),k(null),g(null),ne.current?.(void 0);return}throw e}},[k]),M=(0,L.useCallback)(e=>{if(A.current&&j.current===e)return A.current.configure(ie),A.current;let t=new N({resourceKey:`prompt-draft:${O.current.projectId}:${e}`,initialValue:Z(e)??``,save:ie,debounceMs:dt});return t.subscribe(e=>y(e)),A.current=t,j.current=e,t},[ie]),ae=(0,L.useCallback)(async()=>{let e=ee.current;if(e)return e;if(w.current)return w.current;let t=O.current.projectId,n=(async()=>{let e=await _.createPromptDraft(t,{gezelId:O.current.gezelId,sessionId:re.current??null,content:te.current(),...O.current.taskRef?{taskRef:O.current.taskRef}:{},...O.current.craftbookRef?{craftbookRef:O.current.craftbookRef}:{},...O.current.scope?{scope:O.current.scope}:{}});if(T.current)throw await _.deletePromptDraft(t,e.id).catch(()=>{}),Error(`draft discarded while it was being created`);S.current=re.current===void 0,x.current=e.hasFiles,Y(b.current,e.id),k(e.id),g(e),ne.current?.(e.id),Q(e.id,e.content);let n=M(e.id),r=te.current();return r!==e.content&&(Q(e.id,r),n.update(r)),e.id})();w.current=n;try{return await n}finally{w.current===n&&(w.current=null)}},[M,k]),oe=(0,L.useCallback)(e=>{let t=ee.current;if(t){let n=M(t);Q(t,e),n.update(e);return}e.trim()&&(T.current=!1,ae().catch(()=>{}))},[ae,M]),se=(0,L.useCallback)(async()=>{w.current&&await w.current.catch(()=>{});let e=ee.current;!e||j.current!==e||await A.current?.flush().catch(()=>{})},[]),ce=(0,L.useCallback)(()=>{let e=ee.current;e&&(A.current=null,j.current=null,$(e),Y(b.current,void 0),x.current=!1,C.current=!1,k(null),g(null),y({phase:`idle`,dirty:!1,error:null}),ne.current?.(void 0))},[k]),le=(0,L.useCallback)(async()=>{T.current=!0,w.current&&await w.current.catch(()=>{});let e=ee.current;A.current=null,j.current=null,x.current=!1,C.current=!1,k(null),g(null),y({phase:`idle`,dirty:!1,error:null}),ne.current?.(void 0),e&&($(e),Y(b.current,void 0),await _.deletePromptDraft(O.current.projectId,e).catch(()=>{}))},[k]),ue=(0,L.useCallback)(()=>{x.current=!0},[]),de=(0,L.useCallback)(async()=>{await A.current?.retry().catch(()=>{})},[]),fe=(0,L.useCallback)(async(e,t)=>{let n=Z(e);n!==void 0&&!te.current().trim()&&n!==te.current()&&D.current(n,{id:e});try{let n=await _.getPromptDraft(O.current.projectId,e);if(E.current!==t)return;x.current=n.hasFiles,C.current=n.sessionId===null,Q(e,n.content),g(n);let r=M(e);if(r.getSnapshot().dirty)return;let i=r.hydrate(n.content);i!==te.current()&&D.current(i,n)}catch(n){if(E.current!==t)return;pt(n)&&($(e),Y(b.current,void 0),k(null),g(null),ne.current?.(void 0))}},[M,k]),pe=(0,L.useRef)(f),me=(0,L.useRef)(t.gezelId),he=(0,L.useRef)(t.projectId),ge=(0,L.useRef)(n),P=(0,L.useRef)(r),F=(0,L.useRef)(!1);(0,L.useEffect)(()=>{let e=pe.current,i=me.current!==t.gezelId,a=he.current!==t.projectId,o=ge.current===void 0&&n!==void 0,s=P.current!==r,c=!F.current,l=!c&&P.current!==void 0&&r===void 0;b.current=f,pe.current=f,me.current=t.gezelId,he.current=t.projectId,ge.current=n,P.current=r,F.current=!0;let u=ee.current;if(!c&&u&&i&&!a&&!s){Y(e,void 0),Y(f,u),_.patchPromptDraft(t.projectId,u,{gezelId:t.gezelId,sessionId:n??null}).then(e=>g(e)).catch(()=>{});return}if(!c&&u&&o&&S.current&&!C.current&&!s){S.current=!1,Y(e,void 0),Y(f,u),_.patchPromptDraft(t.projectId,u,{sessionId:n??null}).then(e=>g(e)).catch(()=>{});return}if(!c&&!s&&e===f)return;l&&Y(f,void 0);let d=r??ct(f);if(d&&d===u){Y(f,d);return}let p=++E.current;if(A.current=null,j.current=null,T.current=!1,S.current=n===void 0,y({phase:`idle`,dirty:!1,error:null}),d){Y(f,d),k(d),fe(d,p);return}let m=u?``:te.current();k(null),g(null),x.current=!1,C.current=!1,!c&&!m.trim()&&D.current(``,{id:``}),n!==void 0&&(async()=>{try{let{drafts:e}=await _.listPromptDrafts(t.projectId,{gezelId:t.gezelId,sessionId:n,status:`draft`});if(E.current!==p)return;let r=e[0];if(!r)return;Y(f,r.id),k(r.id),await fe(r.id,p)}catch{}})()},[f,r]),(0,L.useEffect)(()=>{let e=()=>{A.current?.flush().catch(()=>{})},t=()=>{document.visibilityState===`hidden`&&e()};return window.addEventListener(`pagehide`,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`pagehide`,e),document.removeEventListener(`visibilitychange`,t),e()}},[]);let _e=(0,L.useMemo)(()=>({...v,retry:de}),[v,de]);return{draftId:p,meta:h,isFreshThread:C.current||h?.sessionId===null&&n===void 0,autosave:_e,update:oe,ensureDraft:ae,flush:se,markSent:ce,discard:le,noteFileAdded:ue}}function pt(e){let t=e instanceof Error?e.message:String(e);return/\b404\b/.test(t)||/not found/i.test(t)}function mt(){return(0,R.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,children:(0,R.jsx)(`path`,{d:`M5 6.4 8 3.4l3 3M11 9.6l-3 3-3-3`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinecap:`round`,strokeLinejoin:`round`})})}function ht(){return(0,R.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,children:(0,R.jsx)(`path`,{d:`M5 3.4l3 3 3-3M11 12.6l-3-3-3 3`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinecap:`round`,strokeLinejoin:`round`})})}var gt={showFilesWhenNotEmpty:!0};function _t({projectId:e,disabled:t,onAppendTranscript:n,onError:r}){let{replaceAll:i}=T();return(0,R.jsx)(Re,{projectId:e,disabled:t,onTranscript:(0,L.useCallback)(e=>{let t=n(e);t!==null&&i(t)},[n,i]),onError:r})}function vt({gezelId:e,gezelName:t,gezelRoleBasedName:n,gezelRole:r,gezelIcon:o,gezelPoppetje:u,gezelIconOverride:d,focusRequestKey:f,recipientGezels:p,onPrimaryRecipientChange:m,projectId:h,sessionId:v,onSessionCreated:y,onToolActivity:b,recentReferences:x=[],onOpenReference:S,craftbookRef:C,onTurnStateChange:w,placeholder:T,taskRef:E,stepId:D,belowAddressLine:ne,addressLineTrailing:re,onPivotToMention:k,passiveCcGezelIds:A,onPassiveCcConsumed:ie,onTerminalEscape:M,draftScope:ae,draftId:oe,onDraftIdChange:se}){let le=(0,L.useRef)(null);(0,L.useEffect)(()=>{if(!f)return;let e=window.requestAnimationFrame(()=>{le.current?.querySelector(`.squisq-wysiwyg-editor`)?.focus({preventScroll:!0})});return()=>window.cancelAnimationFrame(e)},[f]);let ue=ce(),de=O(),fe=s({name:t,roleBasedName:n},de),[pe,me]=(0,L.useState)(!1),[N,he]=(0,L.useState)(!1),[ge,F]=(0,L.useState)(!1),[_e,I]=(0,L.useState)(null),ve=(0,L.useRef)(!1),[z,xe]=(0,L.useState)(!1),[Se,Ce]=(0,L.useState)(null),[B,Te]=(0,L.useState)(null),Ee=(0,L.useMemo)(()=>({...ae?{scope:ae}:{},projectId:h,gezelId:e,...E?{taskRef:E}:{},...C?{craftbookRef:C}:{}}),[C,ae,e,h,E]),V=(0,L.useRef)((()=>{let e=st({...Ee,sessionId:v??null}),t=oe??ct(e);return(t?Z(t):void 0)??``})()),De=(0,L.useRef)(0),Oe=(0,L.useRef)(()=>{}),ke=(0,L.useRef)(async()=>{}),Ae=(0,L.useRef)(async()=>``),je=(0,L.useRef)(()=>{}),Me=(0,L.useRef)(!1),H=(0,L.useRef)(V.current.length),[Ne,Pe]=(0,L.useState)(()=>V.current.trim().length>0),[Fe,Ie]=(0,L.useState)(()=>Ze(V.current)),[Le,Re]=(0,L.useState)(0),ze=(0,L.useCallback)(()=>{let e=ye(h);if(!e)return;let t=V.current.trim(),n=t?`${t}\n\n${e}`:e;V.current=n,Oe.current(n),De.current+=1,H.current=n.length,Pe(n.trim().length>0),Ie(Ze(n)),Re(e=>e+1)},[h]);(0,L.useEffect)(()=>{ze();let e=e=>{e.detail?.projectId===h&&ze()};return window.addEventListener(be,e),()=>window.removeEventListener(be,e)},[ze,h]);let[Be,Ve]=(0,L.useState)(()=>c(V.current)),U=ft({address:Ee,sessionId:v,draftId:oe,onDraftIdChange:se,getText:()=>V.current,onLoaded:e=>{V.current=e,H.current=e.length,De.current+=1,Pe(e.trim().length>0),Ie(Ze(e)),Ve(c(e)),Re(e=>e+1)}}),W=(0,L.useRef)(U.draftId);W.current=U.draftId,Oe.current=U.update,ke.current=U.discard,Ae.current=U.ensureDraft,je.current=U.noteFileAdded,Me.current=U.isFreshThread;let[He,Ue]=(0,L.useState)([]);(0,L.useEffect)(()=>{Ue([])},[e,h]);let Ge=(0,L.useMemo)(()=>{let e=new Map((p??[]).map(e=>[e.id,e]));return He.flatMap(t=>{let n=e.get(t);return n?[n]:[]})},[He,p]),[Ke,qe]=(0,L.useState)(`proactive`);(0,L.useEffect)(()=>{_.getConfig().then(e=>qe(e.aiEngagementMode??`proactive`)).catch(()=>{});let e=e=>{let t=e.detail;t?.aiEngagementMode&&qe(t.aiEngagementMode)};return window.addEventListener(`gezel:config-updated`,e),()=>window.removeEventListener(`gezel:config-updated`,e)},[]);let Je=Ke===`off`,G=(0,L.useRef)(null),Ye=(0,L.useRef)(0),K=(0,L.useRef)(v??null),[et,tt]=(0,L.useState)(v??null);(0,L.useEffect)(()=>{K.current=v??null,tt(v??null)},[v]);let nt=(0,L.useCallback)(async()=>{let t=await _.createChatSession({gezelId:e,projectId:h,...E?{taskRef:E}:{},...D?{stepId:D}:{},...C?{craftbookRef:C}:{}});return K.current=t.id,tt(t.id),y?.(t.id),t.id},[e,h,E,D,C,y]),it=(0,L.useCallback)(async()=>{if(K.current)return K.current;if(Me.current)return nt();try{if(E){let t=i(E);if(t){let n=(await _.listTaskSessions(t.projectId,t.num)).sessions.find(t=>!t.archived&&t.gezelId===e);if(n)return K.current=n.id,tt(n.id),y?.(n.id),n.id}}else{let t=(await _.listChatSessions({gezelId:e,projectId:h})).sessions.find(e=>!e.archived&&!e.taskRef);if(t)return K.current=t.id,tt(t.id),y?.(t.id),t.id}}catch{}return nt()},[e,h,E,nt,y]),at=(0,L.useMemo)(()=>Xe({projectId:h,getDraftId:()=>W.current,ensureDraftId:async()=>{let e=await Ae.current();return je.current(),e}}),[h]);(0,L.useEffect)(()=>()=>{G.current?.controller.abort(),G.current=null,at.dispose()},[at]);let q=(0,L.useCallback)((e,t={})=>{let n=G.current;!n||n.id!==e||(G.current=null,t.abort&&n.controller.abort(),me(!1),Ce(null),t.serverIdle&&F(!1))},[]),J=(0,L.useCallback)(async(e,t)=>{let n=G.current,r=n?.sessionId===e&&n.accepted?n.id:null,i=await _.getChatSessionInflight(e);if(t&&!t()||K.current!==e||r!==null&&G.current?.id!==r)return;let a=i.inflight!==null;F(a),!a&&r!==null&&q(r,{abort:!0,serverIdle:!0})},[q]);(0,L.useEffect)(()=>{if(!et){F(!1);return}let e=!1,t=async()=>{try{e||await J(et,()=>!e)}catch{}};t();let n=window.setInterval(()=>void t(),2e3);return()=>{e=!0,window.clearInterval(n)}},[et,J]);let ot=pe||ge,Y=(0,L.useRef)(ot);Y.current=ot;let lt=(0,L.useCallback)(async e=>{try{return(await _.listMentionCandidates({projectId:h,query:e})).candidates.map(e=>({id:e.id,label:de&&e.roleBasedName?e.roleBasedName:e.label,scheme:`gezel`,...e.description?{description:e.description}:{},...e.group?{group:e.group}:{}}))}catch{return[]}},[h,de]);(0,L.useEffect)(()=>{w?.(_e?`error`:Se===null?ot?`streaming`:`idle`:`queued`,_e??void 0)},[ot,Se,_e,w]);let ut=(0,L.useCallback)(e=>{let t=H.current;H.current=e.length;let n=V.current!==e;if(V.current=e,Oe.current(e),n&&(De.current+=1),Pe(e.trim().length>0),Ie(Ze(e)),M&&t<=2){let t=e.trimStart().match(/^>\s+([^\n]*)/);if(t){ke.current(),M((t[1]??``).trim());return}}let r=c(e);Ve(e=>yt(e,r)?e:r)},[M]),X=(0,L.useCallback)(e=>{let t=e.trim();if(!t)return null;let n=V.current,r=`${n}${n&&!/\s$/.test(n)?` `:``}${t}`;V.current=r,Oe.current(r),De.current+=1,H.current=r.length,Pe(!0),Ie(Ze(r));let i=c(r);return Ve(e=>yt(e,i)?e:i),r},[]),Q=(0,L.useCallback)(()=>{if(ve.current)return null;let e=V.current;return e.trim()?(ve.current=!0,xe(!0),{source:e,editVersion:De.current}):null},[]),$=(0,L.useCallback)(()=>{ve.current=!1,xe(!1)},[]),dt=(0,L.useCallback)(e=>{De.current!==e.editVersion||V.current!==e.source||(V.current=``,H.current=0,Pe(!1),Ie(null),Re(e=>e+1),Ve([]))},[]),pt=(0,L.useMemo)(()=>Fe===null?[]:Qe(Fe,x),[Fe,x]),vt=(0,L.useCallback)(async e=>{let t=Q();if(!t)return;let n=Ze(t.source),r=e??(n===null?null:$e(n,x));if(!r){I(n?`No recent file matches “${n}”. Choose a suggestion or use workspace or artifacts.`:`Choose workspace, artifacts, or a recent file.`),$();return}I(null);try{if(r.type===`folder`)await _.revealProject(h,r.folder);else if(S)S(r.reference);else throw Error(`Recent file opening is unavailable in this chat.`);ke.current(),dt(t)}catch(e){I(`Open failed: ${e instanceof Error?e.message:String(e)}`)}finally{$()}},[Q,dt,$,S,h,x]),xt=(0,L.useRef)(null);(0,L.useEffect)(()=>{if(!k){xt.current=null;return}let t=Be.find(t=>t.id!==e&&(!t.projectId||t.projectId===h));if(!t){xt.current=null;return}xt.current!==t.id&&(xt.current=t.id,k(t.id))},[Be,e,h,k]);let wt=(0,L.useCallback)(async()=>{if(Ze(V.current)!==null){await vt();return}if(!e||ot||Je)return;let t=Q();if(!t)return;let n=t.source.trim();I(null),Ce(null);let r;try{await U.flush(),r=await U.ensureDraft()??void 0}catch{r=void 0}let i;try{i=await it()}catch(e){I(Ct(e.message)),$();return}let o=++Ye.current,s=new AbortController;G.current={id:o,sessionId:i,controller:s,accepted:!1};let c=(async()=>{let e=0,t=0;for(;;){let n=0;try{for await(let e of g({url:_.sessionEventsUrl(i),headers:_.authHeader(),signal:s.signal,fetch:_.getFetch(),keepaliveTimeoutMs:1e4})){if(G.current?.id!==o)return;if(e.type===`tool`){if(n+=1,n<=t)continue;t=n;let r={name:e.name,durationMs:e.durationMs,success:e.success,...e.errorMessage?{errorMessage:e.errorMessage}:{},...e.path?{path:e.path}:{},...e.paths&&e.paths.length>0?{paths:e.paths}:{},...e.argsSummary?{argsSummary:e.argsSummary}:{},...e.argsFull?{argsFull:e.argsFull}:{},...e.resultText?{resultText:e.resultText}:{},...e.resultTruncated?{resultTruncated:!0}:{},...e.diff===void 0?{}:{diff:e.diff},...e.addedLines===void 0?{}:{addedLines:e.addedLines},...e.removedLines===void 0?{}:{removedLines:e.removedLines},...e.card?{card:e.card}:{},projectId:h};b?.(r)}else if(e.type===`error`)I(St(e.error)),Ce(null);else if(e.type===`done`){q(o,{serverIdle:!0});return}else e.type===`queued`?Ce(e.aheadOf):e.type===`delta`&&Ce(null)}return}catch(t){if(t.name===`AbortError`){q(o);return}if(G.current?.id!==o)return;if(e+=1,e>5){console.warn(`[ChatComposer] chat event stream lost, giving up:`,t),I(Ct(t.message)),q(o);return}let n=Math.min(500*2**(e-1),5e3);if(console.warn(`[ChatComposer] chat event stream lost (reconnect ${e}/5 in ${n}ms):`,t),await new Promise(e=>setTimeout(e,n)),s.signal.aborted||G.current?.id!==o)return}}})();try{let s=[...new Set([...a(n),...He])].filter(t=>t!==e),c=(A??[]).filter(t=>t&&t!==e),u={message:n};s.length>0&&(u.mentions=s),c.length>0&&(u.passiveCcGezelIds=c),r&&(u.draftId=r),await _.sendToChatSession(i,u);let d=G.current;d?.id===o&&(d.accepted=!0,me(!0),J(i).catch(()=>{})),r&&U.markSent(),dt(t),rt({sessionId:i,gezelId:e,projectId:h,content:r?l(n,r):n,at:new Date().toISOString()}),c.length>0&&ie?.()}catch(e){s.abort(),q(o);let t=e.message??String(e);if(/already in flight/i.test(t))try{let{inflight:e}=await _.getChatSessionInflight(i);e?(Te({userText:e.userText,elapsedMs:e.elapsedMs,sessionId:i}),I(null)):I(St(t))}catch{I(St(t))}else I(Ct(t))}finally{$()}await c},[e,h,ot,Je,Q,dt,it,$,q,J,b,He,A,ie,vt,U]),Tt=(0,L.useCallback)(async()=>{if(B){try{await _.cancelChatSessionTurn(B.sessionId)}catch(e){I(`Cancel failed: ${e.message}`);return}Te(null),I(null)}},[B]),Et=(0,L.useCallback)(async()=>{let e=K.current,t=G.current;if(t?(t.controller.abort(),q(t.id)):(me(!1),Ce(null)),!e){F(!1);return}try{await _.cancelChatSessionTurn(e),F(!1),I(null)}catch(e){I(`Cancel failed: ${e.message}`)}},[q]);(0,L.useEffect)(()=>{let e=e=>{!Y.current||ve.current||e.key!==`Escape`||e.defaultPrevented||(e.preventDefault(),Et())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Et]);let Dt=(0,L.useCallback)(async()=>{let t=K.current;if(!e||!t||Je)return;let n=Q();if(!n)return;let r=n.source.trim();I(null);let i;try{await U.flush(),i=await U.ensureDraft()??void 0}catch{i=void 0}try{await _.sendToChatSession(t,{message:r,nudge:!0,...i?{draftId:i}:{}}),i&&U.markSent(),dt(n)}catch(e){I(St(e.message??String(e)))}finally{$()}},[e,Je,Q,dt,$,U]),Ot=(0,L.useCallback)(async()=>{let t=K.current;if(!e||!t||Je)return;let n=Q();if(!n)return;let r=n.source.trim();I(null),F(!0);let i;try{await U.flush(),i=await U.ensureDraft()??void 0}catch{i=void 0}try{await _.interruptChatSession(t,{message:r,...i?{draftId:i}:{}}),i&&U.markSent(),dt(n),J(t).catch(()=>{})}catch(e){I(St(e.message??String(e)))}finally{$()}},[e,Je,Q,dt,$,J,U]),kt=(0,L.useRef)(()=>{});kt.current=z?()=>{}:Fe===null?ot?()=>void Dt():()=>void wt():()=>void vt();let At=(0,L.useCallback)(e=>{if(e.key!==`Enter`||!e.shiftKey||e.metaKey||e.ctrlKey||e.altKey||!(e.target instanceof HTMLElement?e.target:null)?.closest(`.squisq-wysiwyg-editor, .squisq-raw-editor-container`))return;let t=e.currentTarget.querySelector(`.squisq-mention-popover`);t&&t.style.display!==`none`||(e.preventDefault(),e.stopPropagation(),kt.current())},[]);return(0,R.jsxs)(`div`,{ref:le,className:`chat-composer`,"data-testid":`chat-composer`,"data-composer-expanded":N?`true`:void 0,onKeyDownCapture:At,children:[Je&&(0,R.jsxs)(`div`,{className:`chat-composer-disabled-banner`,role:`alert`,children:[(0,R.jsx)(`span`,{children:`AI disabled in Settings → General. Chat is paused.`}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>window.dispatchEvent(new CustomEvent(`gezel:navigate`,{detail:{view:`settings`}})),children:`Open Settings`})]}),B&&(0,R.jsxs)(`div`,{className:`chat-composer-wedged`,children:[(0,R.jsxs)(`div`,{className:`chat-composer-wedged-head`,children:[(0,R.jsx)(`strong`,{children:`Previous turn still running`}),(0,R.jsxs)(`span`,{className:`muted`,children:[` · `,bt(B.elapsedMs)]})]}),(0,R.jsx)(`div`,{className:`chat-composer-wedged-preview`,children:B.userText.length>180?`${B.userText.slice(0,177)}…`:B.userText}),(0,R.jsxs)(`div`,{className:`chat-composer-wedged-actions`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:()=>void Tt(),children:`Cancel stuck turn`}),(0,R.jsx)(`button`,{type:`button`,className:`subtle`,onClick:()=>Te(null),children:`Dismiss`})]})]}),_e&&(0,R.jsxs)(`div`,{className:`chat-composer-error`,role:`alert`,children:[(0,R.jsx)(`span`,{className:`chat-composer-error-mark`,"aria-hidden":`true`,children:`✗`}),(0,R.jsx)(`span`,{className:`chat-composer-error-text`,children:_e})]}),(0,R.jsxs)(`div`,{className:`chat-composer-to`,children:[(0,R.jsx)(`span`,{className:`chat-composer-to-label muted`,children:`To:`}),(0,R.jsx)(j,{svg:o??null,poppetje:u,iconOverride:d,name:fe,size:18}),(0,R.jsxs)(`span`,{className:`chat-composer-to-text`,children:[(0,R.jsx)(`span`,{className:`chat-composer-to-name`,children:fe}),!de&&r&&(0,R.jsx)(`span`,{className:`chat-composer-to-role`,children:r})]}),Ge.map(e=>{let t=s({name:e.name,roleBasedName:e.roleBasedName},de);return(0,R.jsxs)(`span`,{className:`chat-composer-to-recipient`,children:[(0,R.jsx)(j,{svg:e.icon??null,poppetje:e.poppetje,iconOverride:e.iconOverride,name:t,size:18}),(0,R.jsxs)(`span`,{className:`chat-composer-to-text`,children:[(0,R.jsx)(`span`,{className:`chat-composer-to-name`,children:t}),!de&&e.role&&(0,R.jsx)(`span`,{className:`chat-composer-to-role`,children:e.role})]}),(0,R.jsx)(`button`,{type:`button`,className:`chat-composer-recipient-remove`,"aria-label":`Remove ${t} from recipients`,title:`Remove ${t}`,onClick:()=>Ue(t=>t.filter(t=>t!==e.id)),children:`×`})]},e.id)}),Be.filter(t=>(t.id!==e||t.projectId!==void 0)&&!He.includes(t.id)).map(e=>(0,R.jsxs)(`span`,{className:`chat-composer-to-mention`,title:e.projectId?`@${e.label} re: ${e.projectId}`:`@${e.label}`,children:[`@`,e.label]},e.rawId)),p&&m&&p.length>0&&(0,R.jsx)(We,{gezels:p,primaryGezelId:e,additionalRecipientIds:He,roleBasedNameOnlyMode:de,onSelectPrimary:e=>{Ue([]),m(e)},onAddRecipient:t=>Ue(n=>t===e||n.includes(t)?n:[...n,t])}),re]}),ne,(0,R.jsxs)(`div`,{className:`chat-editor-wrap`,children:[Fe!==null&&(0,R.jsxs)(`div`,{className:`chat-open-command-menu`,role:`menu`,"aria-label":`Open targets`,children:[(0,R.jsxs)(`div`,{className:`chat-open-command-heading`,children:[(0,R.jsx)(`code`,{children:`/open`}),(0,R.jsx)(`span`,{children:`Project folders and recent chat files`})]}),pt.length>0?(0,R.jsx)(`div`,{className:`chat-open-command-items`,children:pt.map(e=>(0,R.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`chat-open-command-item`,"aria-label":e.target.type===`folder`?`Open ${e.target.folder} folder`:`Open ${e.label}`,onMouseDown:e=>e.preventDefault(),onClick:()=>void vt(e.target),children:[(0,R.jsx)(`code`,{children:e.label}),(0,R.jsx)(`span`,{children:e.description})]},e.key))}):(0,R.jsx)(`p`,{className:`chat-open-command-empty`,children:`No matching recent files.`})]}),(0,R.jsx)(te,{initialMarkdown:V.current,hostMode:`chat`,mediaProvider:at,mentionProvider:lt,...T?{placeholder:T}:{},imageDisplayMode:`thumbnail`,onChange:ut,minHeight:N?`100%`:`120px`,maxHeight:N?`100%`:`50vh`,colorScheme:ue,uxFont:`var(--font-ui)`,showPlayTab:!1,showStatusBar:!1,showFilesToggle:!0,...gt,fullWidth:!0,thinMargins:!0,toolbarSlotAfterActions:(0,R.jsx)(we,{mediaProvider:at,onError:I}),toolbarSlotRight:(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(P,{autosave:U.autosave,failuresOnly:!0}),(0,R.jsx)(_t,{projectId:h,disabled:!e||Je||z,onAppendTranscript:X,onError:I}),(0,R.jsx)(`button`,{type:`button`,className:`squisq-toolbar-button chat-composer-expand-btn`,"data-testid":`chat-composer-expand`,onClick:()=>he(e=>!e),"aria-pressed":N,"aria-label":N?`Collapse the draft`:`Expand the draft`,title:N?`Collapse the draft back to a few lines`:`Expand the draft to fill the chat window`,"data-tooltip":N?`Collapse the draft`:`Expand the draft`,children:N?(0,R.jsx)(ht,{}):(0,R.jsx)(mt,{})}),Fe===null?ot?(0,R.jsxs)(R.Fragment,{children:[Ne&&!Je&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`button`,{type:`button`,className:`chat-send-btn chat-nudge-btn`,"data-testid":`chat-nudge`,onClick:()=>void Dt(),disabled:z,title:`Queue for after this turn (Shift+Enter)`,children:`Nudge`}),(0,R.jsx)(`button`,{type:`button`,className:`chat-interrupt-btn`,"data-testid":`chat-interrupt`,onClick:()=>void Ot(),disabled:z,title:`Stop this turn and send now`,children:`Interrupt`})]}),(0,R.jsx)(`button`,{type:`button`,className:`chat-stop-btn`,onClick:()=>void Et(),disabled:z,title:`Stop generating (Escape)`,children:`■ Stop`})]}):(0,R.jsx)(`button`,{type:`button`,className:`chat-send-btn chat-send-btn-icon`,"data-testid":`chat-send`,onClick:wt,disabled:!e||Je||z,"aria-label":z?`Sending…`:`Send`,"aria-busy":z,title:Je?`AI is disabled in Settings → General`:`Shift+Enter to send, Enter for newline`,children:(0,R.jsx)(ee,{})}):(0,R.jsx)(`button`,{type:`button`,className:`chat-send-btn`,"data-testid":`chat-open`,onClick:()=>void vt(),disabled:z,title:`Open this folder or recent file (Shift+Enter)`,children:z?`Opening…`:`Open`})]})},`${Le}:${e}:${T??``}`)]})]})}function yt(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],i=t[n];if(!r||!i||r.rawId!==i.rawId||r.label!==i.label)return!1}return!0}function bt(e){let t=Math.floor(e/1e3);return t<60?`${t}s elapsed`:`${Math.floor(t/60)}m ${t%60}s elapsed`}function xt(e){let t=/"error"\s*:\s*"model_not_loaded"/.test(e)||/model_not_loaded/.test(e),n=/is not available locally for provider/i.test(e),r=/"error"\s*:\s*"model_not_found"/.test(e);if(!t&&!n&&!r)return;let i=/"model"\s*:\s*"([^"]+)"/.exec(e)?.[1],a=/Model\s+"([^"]+)"/i.exec(e)?.[1],o=i??a??``,s=o.indexOf(`:`);return s===-1?o:o.slice(s+1)}function St(e){if(!e)return e;let t=xt(e);return t===void 0?/Timeout\s+after\s+\d+ms\s+waiting\s+for\s+session\.idle/i.test(e)?`Copilot stalled without streaming a reply — this usually means the SDK lost its connection. Your message is saved; try Send again, or pick a different model in Settings → Defaults.`:/timed out after \d+s/i.test(e)?`The model didn't respond in time. Your message is saved — try Send again.`:e:`The model ${t?`"${t}" `:``}isn't available on this device — it may never have finished downloading. Pick a model that is installed, or download this one, in Settings → Artificial Intelligence.`}function Ct(e){return/network\s?error/i.test(e)||/failed to fetch/i.test(e)||/load failed/i.test(e)||/transport unavailable/i.test(e)||/SSE stream (stale|failed)/i.test(e)||/ended before a terminal event/i.test(e)?`Lost the connection to the gezel service and could not reconnect. Your message is saved — if no reply appears, check that the service is running and try Send again.`:St(e)}function wt(e){let t=Et(e);return t===``?`/`:t.startsWith(`/`)||/^[A-Za-z]:[\\/]/.test(t)?t:`/${t}`}var Tt=/\x1b\[[0-9;?]*[ -/]*[@-~]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\x1b[@-_]|\uFFFD\[[0-9;?]*[ -/]*[@-~]/g;function Et(e){let t=``;for(let n of e.replace(Tt,``)){let e=n.charCodeAt(0);e>=32&&e!==127&&(t+=n)}return t.trim()}function Dt(e){return e.replace(/!\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/@\[([^\]]+)\]\([^)]+\)/g,`@$1`).replace(/\[([^\]]+)\]\([^)]+\)/g,`$1`).replace(/\*\*([^*]+)\*\*/g,`$1`).replace(/__([^_]+)__/g,`$1`).replace(/(?<!\*)\*([^*]+)\*(?!\*)/g,`$1`).replace(/(?<!_)_([^_]+)_(?!_)/g,`$1`).replace(/~~([^~]+)~~/g,`$1`).replace(/`+([^`]+)`+/g,`$1`).replace(/^\s*#+\s+/gm,``).replace(/^\s*>\s+/gm,``).replace(/^\s*[-*+]\s+/gm,``).replace(/^\s*\d+\.\s+/gm,``).replace(/\s+/g,` `).trim()}function Ot({payload:e,gezels:t}){let{userMsg:n,assistantInfo:r}=e,i=r.kind===`live`,a=i?r.slot:null,c=ue(i?a?.startedAt??null:null),l=i?r.sessionId:r.msg.gezelId,u=t.get(i?a?.gezelId??``:r.msg.gezelId),f=O(),m=u?s({name:u.name,roleBasedName:u.roleBasedName},f):`Gezel`,h=n.origin===`system`?o(n.content):null,g=h?p(h,m):Dt(n.content);return(0,R.jsxs)(`div`,{className:`chat-sticky-header`,"aria-live":`polite`,children:[(0,R.jsxs)(`div`,{className:`chat-sticky-header-user`,title:n.content,children:[(0,R.jsx)(`span`,{className:`chat-sticky-header-author`,children:h?d(h).toUpperCase():n.origin===`system`?`SYSTEM`:`YOU`}),(0,R.jsx)(`span`,{className:`chat-sticky-header-preview`,children:g})]}),(0,R.jsxs)(`div`,{className:`chat-sticky-header-assistant`,children:[(0,R.jsx)(j,{svg:u?.icon??null,poppetje:u?.poppetje,iconOverride:u?.iconOverride,name:m,size:18}),(0,R.jsx)(`span`,{className:`chat-sticky-header-author`,children:m}),!f&&u?.role&&(0,R.jsx)(A,{role:u.role}),i&&a&&(0,R.jsx)(ie,{failed:!!a.error,queued:a.queueAhead!==void 0&&me(a.queuedAt,Date.now())&&!M(a.segments),queueAhead:a.queueAhead,elapsedSeconds:c,toolCount:fe(a.segments),wirePulseCount:a.wirePulseCount,...oe(a)?{thinkingLabel:oe(a)}:{},...a.thinkingProgress===void 0?{}:{thinkingProgress:a.thinkingProgress},...a.thinkingDetail?{thinkingDetail:a.thinkingDetail}:{},...a.awaitingGezelName?{awaitingGezelName:a.awaitingGezelName}:{}})]},l)]})}var kt=`gezel:timeline:indexing-receipts:v1:`;function At(e){return`${kt}${e}`}function jt(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.id==`string`&&typeof t.gezelId==`string`&&typeof t.projectId==`string`&&typeof t.startedAt==`string`&&typeof t.completedAt==`string`&&Array.isArray(t.files)&&t.files.every(e=>typeof e==`string`&&e.length>0)}function Mt(e){if(typeof window>`u`)return[];try{let t=JSON.parse(window.localStorage.getItem(At(e))??`[]`);return Array.isArray(t)?t.filter(jt).slice(-20):[]}catch{return[]}}function Nt(e,t){if(!(typeof window>`u`))try{window.localStorage.setItem(At(e),JSON.stringify(t.slice(-20)))}catch{}}function Pt(e){return/^Indexing\s+(.+)$/i.exec(e?.trim()??``)?.[1]?.trim()||null}function Ft(e,t){let n=Date.parse(t.completedAt),r=-1;for(let i=e.length-1;i>=0;i--){let a=e[i];if(a.gezelId!==t.gezelId||a.projectId!==t.projectId)continue;let o=Date.parse(a.completedAt);Number.isFinite(n)&&Number.isFinite(o)&&n-o<=3e5&&(r=i);break}if(r<0)return[...e,{id:`indexing:${t.sessionId}`,gezelId:t.gezelId,projectId:t.projectId,startedAt:t.startedAt,completedAt:t.completedAt,files:[t.path]}].slice(-20);let i=[...e],a=i[r];return a.files.includes(t.path)?e:(i[r]={...a,completedAt:t.completedAt,files:[...a.files,t.path]},i)}function It({receipt:e,gezels:t,projects:n,showProjectName:r,roleBasedNameOnlyMode:i,onOpenWorkspaceFile:a}){let[o,c]=(0,L.useState)(!1),l=t.get(e.gezelId),u=l?s({name:l.name,roleBasedName:l.roleBasedName},i):`Boekwachter`,d=r&&e.projectId!=="default"?n.get(e.projectId):void 0,f=e.files.length;return(0,R.jsxs)(`details`,{className:`timeline-indexing-receipt`,onToggle:e=>c(e.currentTarget.open),children:[(0,R.jsxs)(`summary`,{title:S(e.completedAt),children:[(0,R.jsx)(j,{svg:l?.icon??null,poppetje:l?.poppetje,iconOverride:l?.iconOverride,name:u,size:16}),(0,R.jsxs)(`span`,{className:`timeline-indexing-receipt-label`,children:[(0,R.jsx)(`strong`,{children:u}),` has indexed `,(0,R.jsx)(`strong`,{children:f}),` `,f===1?`file`:`files`,d&&(0,R.jsxs)(R.Fragment,{children:[` in `,d.name]}),` · `,x(e.completedAt)]})]}),o&&(0,R.jsx)(`ul`,{className:`timeline-indexing-file-list`,children:e.files.map(t=>(0,R.jsx)(`li`,{children:a?(0,R.jsx)(`button`,{type:`button`,className:`timeline-indexing-file-link`,title:`Open ${t}`,"aria-label":`Open ${t}`,onClick:()=>a(t,e.projectId),children:t}):(0,R.jsx)(`span`,{className:`timeline-indexing-file-path`,children:t})},t))})]})}function Lt(e){return e===`dispatching`?`Starting`:e===`night-shift`||e===`night-quota`?`Scheduled`:e===`engagement-off`||e===`engagement-paused`?`On hold`:`In the queue`}function Rt(e,t){switch(e){case`dispatching`:return`${t} is picking it up now.`;case`provider-busy`:return`Waiting for a free slot — other work is using the model right now.`;case`night-shift`:return`Parked for Night Shift — it starts when tonight's window opens.`;case`night-quota`:return`Held back by the cloud quota reserve — it starts once the quota frees up.`;case`engagement-off`:return`Held because AI engagement is off. Turn it back on in Settings to let it start.`;case`engagement-paused`:return`Held because AI work is paused. Resume to let it start.`;default:return`Waiting its turn — it starts as soon as ${t} is free.`}}function zt({task:e,wait:t,gezel:n,onTaskReference:r}){let i=O(),a=n?s({name:n.name,roleBasedName:n.roleBasedName},i):`the assigned gezel`,o=x(t.since,{style:`long`,fallback:t.since});return(0,R.jsx)(`div`,{className:`msg msg-user msg-system msg-queued-task`,"data-task-ref":e.ref,children:(0,R.jsxs)(`div`,{className:`msg-queued-task-card`,children:[(0,R.jsxs)(`div`,{className:`msg-queued-task-head`,children:[(0,R.jsx)(de,{area:`tasks`,size:12,className:`msg-queued-task-icon`}),(0,R.jsx)(`span`,{className:`msg-queued-task-kind`,children:Lt(t.reason)}),(0,R.jsxs)(`span`,{className:`msg-role-time`,title:S(t.since),children:[`· `,o]})]}),(0,R.jsxs)(`p`,{className:`msg-queued-task-headline`,children:[(0,R.jsxs)(`span`,{className:`msg-queued-task-number`,children:[`#`,e.num]}),` `,e.title]}),(0,R.jsxs)(`p`,{className:`msg-queued-task-context`,children:[n&&(0,R.jsx)(j,{svg:n.icon??null,poppetje:n.poppetje,iconOverride:n.iconOverride,name:a,size:14}),Rt(t.reason,a)]}),(0,R.jsx)(`div`,{className:`msg-queued-task-actions`,children:r?(0,R.jsxs)(`button`,{type:`button`,className:`msg-ref-chip`,onClick:()=>r(e.ref),title:`Open this task`,children:[`Task `,e.ref]}):(0,R.jsxs)(`span`,{className:`msg-queued-task-ref`,children:[`Task `,e.ref]})})]})})}var Bt=[`black`,`red`,`green`,`yellow`,`blue`,`magenta`,`cyan`,`white`,`bright-black`,`bright-red`,`bright-green`,`bright-yellow`,`bright-blue`,`bright-magenta`,`bright-cyan`,`bright-white`];function Vt(){return{fg:null,bg:null,bold:!1,dim:!1,italic:!1,underline:!1,reverse:!1,hidden:!1}}function Ht(e){let t=[],n=e.reverse?e.bg:e.fg,r=e.reverse?e.fg:e.bg;return n!==null&&t.push(`ansi-fg-${Bt[n]}`),r!==null&&t.push(`ansi-bg-${Bt[r]}`),e.bold&&t.push(`ansi-bold`),e.dim&&t.push(`ansi-dim`),e.italic&&t.push(`ansi-italic`),e.underline&&t.push(`ansi-underline`),e.reverse&&t.push(`ansi-reverse`),e.hidden&&t.push(`ansi-hidden`),t.join(` `)}function Ut(e,t){if(t+1>=e.length)return null;let n=e[t+1];if(n===`[`){let n=t+2;for(;n<e.length;){let t=e.charCodeAt(n);if(t>=48&&t<=63)n++;else break}for(;n<e.length;){let t=e.charCodeAt(n);if(t>=32&&t<=47)n++;else break}if(n>=e.length)return null;let r=e.charCodeAt(n);if(r<64||r>126)return{end:t+1};if(e[n]===`m`){let r=e.slice(t+2,n),i=r===``?[0]:r.split(`;`).map(e=>{let t=Number.parseInt(e,10);return Number.isFinite(t)?t:0});return{end:n+1,sgrParams:i}}if(e[n]===`H`||e[n]===`f`){let r=e.slice(t+2,n).split(`;`).map(e=>Number.parseInt(e,10)),i=Number.isFinite(r[0])&&r[0]>0?r[0]:1,a=Number.isFinite(r[1])&&r[1]>0?r[1]:1;return{end:n+1,transcriptLineBreak:i>1&&a===1}}return{end:n+1}}if(n===`]`){let n=t+2;for(;n<e.length;){let t=e[n];if(t===`\x07`)return{end:n+1};if(t===`\x1B`&&n+1<e.length&&e[n+1]===`\\`)return{end:n+2};n++}return null}return{end:t+2}}function Wt(e,t){let n={...e},r=0;for(;r<t.length;){let e=t[r];e===0?(n.fg=null,n.bg=null,n.bold=!1,n.dim=!1,n.italic=!1,n.underline=!1,n.reverse=!1,n.hidden=!1):e===1?n.bold=!0:e===2?n.dim=!0:e===3?n.italic=!0:e===4?n.underline=!0:e===7?n.reverse=!0:e===8?n.hidden=!0:e===22?(n.bold=!1,n.dim=!1):e===23?n.italic=!1:e===24?n.underline=!1:e===27?n.reverse=!1:e===28?n.hidden=!1:e>=30&&e<=37?n.fg=e-30:e===38?t[r+1]===5?r+=2:t[r+1]===2&&(r+=4):e===39?n.fg=null:e>=40&&e<=47?n.bg=e-40:e===48?t[r+1]===5?r+=2:t[r+1]===2&&(r+=4):e===49?n.bg=null:e>=90&&e<=97?n.fg=e-90+8:e>=100&&e<=107&&(n.bg=e-100+8),r++}return n}function Gt(e){let t=Vt(),n=``,r=!1,i=0;return{feed(a){let o=n+a;n=``;let s=[],c=0,l=0,u=n=>{if(n<=l)return;let a=o.slice(l,n);if(a===``)return;r&&/\S/.test(a)&&(s.push(`
4
+
5
+ `),r=!1);let c=e?e(a):a,u=Ht(t);u===``?s.push(c):s.push((0,R.jsx)(`span`,{className:u,children:c},i++))};for(;c<o.length;){if(o.charCodeAt(c)!==27){c++;continue}let e=Ut(o,c);if(e===null)return u(c),n=o.slice(c),s;u(c),e.sgrParams&&(t=Wt(t,e.sgrParams)),e.transcriptLineBreak&&Kt(o,e.end)?(s.push(`
6
+
7
+ `),r=!1):e.transcriptLineBreak&&(r=!0),c=e.end,l=c}return u(o.length),s}}}function Kt(e,t){let n=t;for(;n<e.length;){if(e.charCodeAt(n)===27){let t=Ut(e,n);if(t===null)return!1;n=t.end;continue}if(!/\s/.test(e[n]))return!0;n++}return!1}function qt({text:e,renderText:t}){return(0,R.jsx)(R.Fragment,{children:(0,L.useMemo)(()=>Gt(t).feed(e),[e,t])})}var Jt={tabIndex:0};function Yt({entry:e,onOpenWorkspaceFile:t}){let n=wt(e.cwd===void 0?e.workingDir:e.cwd);if(e.msgKind===`command`)return(0,R.jsxs)(`div`,{className:`msg msg-user terminal-group terminal-group-command`,"data-terminal-message-id":e.messageId,"data-terminal-thread-id":e.threadId,children:[(0,R.jsxs)(`div`,{className:`msg-header terminal-group-header`,children:[(0,R.jsx)(`span`,{className:`terminal-folder-pill`,title:`Working folder`,children:n}),(0,R.jsx)(`span`,{className:`msg-author`,children:`You · terminal`})]}),(0,R.jsxs)(`div`,{className:`msg-body terminal-cmd-body`,children:[(0,R.jsx)(`span`,{className:`terminal-prompt-sigil`,children:`>`}),` `,(0,R.jsx)(`code`,{className:`terminal-cmd-code`,children:e.content})]}),e.resolvedFrom&&e.resolvedFrom!==e.content&&(0,R.jsxs)(`div`,{className:`terminal-resolved-hint`,children:[`from: `,e.resolvedFrom]})]});let r=e.exitCode!==void 0&&e.exitCode!==0,i=e.exitCode===void 0?null:e.exitCode===0?`exit 0`:`exit ${e.exitCode}`,a=n=>Xt(n,e.fileReferences??[],t);return(0,R.jsxs)(`div`,{className:`msg msg-assistant terminal-group terminal-group-output`,"data-terminal-message-id":e.messageId,"data-terminal-thread-id":e.threadId,children:[(0,R.jsxs)(`div`,{className:`msg-header terminal-group-header`,children:[(0,R.jsx)(`span`,{className:`terminal-folder-pill`,title:`Working folder`,children:n}),(0,R.jsx)(`span`,{className:`msg-author`,children:`Terminal output`}),i&&(0,R.jsx)(`span`,{className:`terminal-exit-pill ${r?`terminal-exit-fail`:`terminal-exit-ok`}`,children:i}),typeof e.durationMs==`number`&&(0,R.jsx)(`span`,{className:`terminal-duration`,children:Qt(e.durationMs)}),e.truncated&&(0,R.jsx)(`span`,{className:`terminal-truncated-pill`,title:`200KB output cap reached`,children:`truncated`})]}),e.errorMessage&&e.exitCode===-1&&(0,R.jsx)(`div`,{className:`terminal-error-banner`,children:e.errorMessage}),(0,R.jsx)(`section`,{className:`terminal-output-viewport`,"aria-label":`Terminal output`,...Jt,children:(0,R.jsx)(`pre`,{className:`terminal-output-body`,children:e.content?(0,R.jsx)(qt,{text:e.content,renderText:a}):r?`(no output)`:``})})]})}function Xt(e,t,n){if(!n||t.length===0||!e)return e;let r=[...t].sort((e,t)=>t.label.length-e.label.length),i=e.toLowerCase(),a=[],o=0,s=0;for(;o<e.length;){let t=null;for(let n of r){let r=n.label.toLowerCase(),a=i.indexOf(r,o);for(;a>=0&&!Zt(e,a,n.label.length);)a=i.indexOf(r,a+Math.max(1,r.length));a>=0&&(!t||a<t.at)&&(t={at:a,reference:n})}if(!t)break;t.at>o&&a.push(e.slice(o,t.at));let c=e.slice(t.at,t.at+t.reference.label.length);a.push((0,R.jsx)(`button`,{type:`button`,className:`terminal-file-link`,title:`Preview ${t.reference.path}`,onClick:()=>n(t.reference.path),children:c},`${t.reference.path}:${s++}`)),o=t.at+t.reference.label.length}return o===0?e:(o<e.length&&a.push(e.slice(o)),a)}function Zt(e,t,n){let r=t===0?``:e[t-1],i=t+n,a=i>=e.length?``:e[i];return(r===``||/[\s"'([{<]/.test(r))&&(a===``||/[\s"')\]}>:,;]/.test(a))}function Qt(e){if(e<1e3)return`${e}ms`;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60);return`${n}m${Math.round(t-n*60).toString().padStart(2,`0`)}s`}var $t=24,en={tabIndex:0};function tn({content:e,cwd:t,startedAt:n,onCancel:r,awaitingInput:i,onSendInput:a}){let o=wt(t),s=(0,L.useRef)(null),c=(0,L.useRef)(!0);(0,L.useLayoutEffect)(()=>{let e=s.current;!e||!c.current||(e.scrollTop=e.scrollHeight)},[e]);let l=()=>{let e=s.current;if(!e)return;let t=e.scrollHeight-e.clientHeight-e.scrollTop;c.current=t<=$t};return(0,R.jsxs)(`div`,{className:`msg msg-assistant terminal-group terminal-group-output terminal-group-streaming`,children:[(0,R.jsxs)(`div`,{className:`msg-header terminal-group-header`,children:[(0,R.jsx)(`span`,{className:`terminal-folder-pill`,title:`Working folder`,children:o}),(0,R.jsx)(`span`,{className:`msg-author`,children:`Terminal output`}),(0,R.jsx)(rn,{startedAt:n}),r&&(0,R.jsx)(`button`,{type:`button`,className:`terminal-cancel-btn`,onClick:r,title:`Stop the running command (Ctrl+C)`,children:`■ Stop`})]}),(0,R.jsx)(`section`,{ref:s,className:`terminal-output-viewport`,"aria-label":`Live terminal output`,"aria-busy":`true`,...en,onScroll:l,children:(0,R.jsx)(`pre`,{className:`terminal-output-body`,children:(0,R.jsx)(qt,{text:e})})}),i&&a&&(0,R.jsx)(nn,{awaitingInput:i,onSubmit:a})]})}function nn({awaitingInput:e,onSubmit:t}){let[n,r]=(0,L.useState)(``),i=e=>{t(e),r(``)},a=e=>{e.key===`Enter`&&(e.preventDefault(),i(n))};if(e.mode===`yes-no`)return(0,R.jsxs)(`div`,{className:`terminal-input-prompt`,children:[(0,R.jsx)(`div`,{className:`terminal-input-prompt-line`,children:e.promptLine}),(0,R.jsxs)(`div`,{className:`terminal-input-prompt-row`,children:[(0,R.jsx)(`button`,{type:`button`,className:`terminal-input-yesno-btn`,onClick:()=>i(`y`),children:`Yes`}),(0,R.jsx)(`button`,{type:`button`,className:`terminal-input-yesno-btn`,onClick:()=>i(`n`),children:`No`}),(0,R.jsx)(`input`,{type:`text`,className:`terminal-input-reply`,value:n,onChange:e=>r(e.target.value),onKeyDown:a,placeholder:`or type a custom reply`,autoCapitalize:`off`,autoComplete:`off`,autoCorrect:`off`,spellCheck:!1})]})]});let o=e.mode===`password`;return(0,R.jsxs)(`div`,{className:`terminal-input-prompt`,children:[(0,R.jsx)(`div`,{className:`terminal-input-prompt-line`,children:e.promptLine}),(0,R.jsxs)(`div`,{className:`terminal-input-prompt-row`,children:[(0,R.jsx)(`input`,{type:o?`password`:`text`,className:`terminal-input-reply`,value:n,onChange:e=>r(e.target.value),onKeyDown:a,placeholder:o?`password (not echoed or saved)`:`reply…`,autoFocus:!0,autoCapitalize:`off`,autoComplete:`off`,autoCorrect:`off`,spellCheck:!1}),(0,R.jsx)(`button`,{type:`button`,className:`terminal-input-send-btn`,onClick:()=>i(n),children:`Send`})]}),o&&(0,R.jsx)(`div`,{className:`terminal-input-hint`,children:`Your input is hidden and isn't kept in the timeline.`})]})}function rn({startedAt:e}){let[,t]=(0,L.useState)(0);(0,L.useEffect)(()=>{let e=setInterval(()=>t(e=>e+1),1e3);return()=>clearInterval(e)},[]);let n=(0,L.useMemo)(()=>new Date(e).getTime(),[e]);return(0,R.jsxs)(`span`,{className:`terminal-running-pill`,title:`Running…`,children:[`running `,an(Math.max(0,Date.now()-n))]})}function an(e){if(e<1e3)return`${e}ms`;let t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m${(t%60).toString().padStart(2,`0`)}s`}var on=1440*60*1e3;function sn(e,t){if(!e)return!1;let n=Date.parse(e);return Number.isFinite(n)&&t-n<=864e5}var cn=300*1e3;function ln(e){let t=Date.parse(e);return Number.isFinite(t)?t+cn:void 0}function un(e,t){let n;for(let r of e){let e=ln(r.at);e===void 0||e<t||(n===void 0||e<n)&&(n=e)}return n}function dn(e,t){if(e.kind===`terminal-streaming`)return!0;if(e.kind!==`terminal`)return!1;let n=ln(e.at);return n!==void 0&&t<=n}function fn(e,t){return dn(e,t)?2:+(e.kind===`streaming`)}function pn(e,t,n){let r=fn(e,n)-fn(t,n);return r===0?e.at<t.at?-1:+(e.at>t.at):r}function mn(e){let t=-1/0,n=e.root?[e.root,...e.replies]:e.replies;for(let e of n){let n=Date.parse(e.at);Number.isFinite(n)&&n>t&&(t=n)}return t}function hn(e,t,n){if(!t)return e;let r=-1;for(let n=e.length-1;n>=0;n--){let i=e[n];if(i?.kind===`thread`&&i.sessionId===t){r=n;break}}if(r===-1)return e;let i=e[r],a=mn(i);if(!Number.isFinite(a)||n-a>864e5)return e;let o=e.length;for(;o>0;){let t=e[o-1];if(!t||!dn(t,n))break;o--}let s=o-1;if(s<=r)return e;let c=[...e];return c.splice(r,1),c.splice(s,0,i),c}var gn=280;function _n(e,t){t?.current&&(t.current.abort(),t.current=null);let n=e.current;if(n){try{n.pause(),n.removeAttribute(`src`),n.load()}catch{}e.current=null}}function vn(e){let t=e.trim();if(t.length<=gn)return t;let n=t.slice(0,gn),r=Math.max(n.lastIndexOf(`. `),n.lastIndexOf(`! `),n.lastIndexOf(`? `));return r>=gn/2?n.slice(0,r+1).trim():`${n.trim()}…`}async function yn(e,t,n,r,i){_n(r,i);let a=new AbortController;i.current=a;let o=vn(e);console.debug(`[narrate] synth start chars=${o.length} (of ${e.length}) gezelId=${t}`);let s;try{s=await _.synthesizeSpeech({text:o,gezelId:t,projectId:n,inline:!0,signal:a.signal})}catch(e){if(a.signal.aborted){console.debug(`[narrate] synth aborted (superseded by newer turn)`);return}console.warn(`[narrate] synth failed:`,e);return}if(a.signal.aborted){console.debug(`[narrate] synth resolved but aborted — dropping`);return}if(console.debug(`[narrate] synth ok b64Len=${s.b64Wav?.length??0} meta=`,s.meta),!s.b64Wav){console.warn(`[narrate] synth returned no b64Wav — narration skipped`);return}let c=new Audio(`data:audio/wav;base64,${s.b64Wav}`);r.current=c,c.addEventListener(`ended`,()=>{console.debug(`[narrate] playback ended`),r.current===c&&(r.current=null),i.current===a&&(i.current=null)});try{await c.play(),console.debug(`[narrate] playback started`)}catch(e){console.warn(`[narrate] playback rejected:`,e),r.current===c&&(r.current=null),i.current===a&&(i.current=null)}}function bn(e){let{branch:t,phase:n}=e,r=t.ancestorContinuationLevels.filter(e=>e>=2&&e<=4);return(0,R.jsxs)(R.Fragment,{children:[(n===`thread`&&t.hasFollowingSibling?[1,...r]:r).map(e=>(0,R.jsx)(`span`,{className:`timeline-tree-guide timeline-tree-guide-${n} timeline-tree-guide-up-${e}`,"aria-hidden":`true`},`${n}:${e}`)),n===`divider`&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`timeline-tree-parent-line timeline-tree-guide-up-1${t.hasFollowingSibling?` timeline-tree-parent-line-continues`:``}`,"aria-hidden":`true`}),(0,R.jsx)(`span`,{className:`timeline-tree-elbow timeline-tree-guide-up-1`,"aria-hidden":`true`})]})]})}function xn(e){let{row:t,gezels:n,projects:r,showProjectName:i,activeSessionId:a,onFocusSession:o,continuing:c,depth:l=0,treeBranch:u,key:d,roleBasedNameOnlyMode:f}=e,p=t.kind===`streaming`?t.sessionId:t.msg.sessionId,m=t.kind===`streaming`?t.slot.gezelId:t.msg.gezelId,h=t.kind===`streaming`?t.slot.projectId:t.msg.projectId,g=n.get(m),_=i&&h!=="default"?r.get(h):void 0,v=p===a,y=t.kind===`message`?t.msg.sessionCreatedAt:t.slot.sessionCreatedAt??new Date(t.slot.startedAt).toISOString(),ee=t.kind===`message`?t.msg.taskRef:t.slot.taskRef,b=t.kind===`message`?t.msg.sessionSource:t.slot.sessionSource,C=t.kind===`message`?t.msg.parentSession:t.slot.parentSession,w=t.kind===`message`?t.msg.handoffFrom:t.slot.handoffFrom,T=C??(w?{...w,kind:`task-handoff`}:void 0),E=T?(()=>{let e=n.get(T.gezelId);return e?s({name:e.name,roleBasedName:e.roleBasedName},f):void 0})():void 0,te=w?(()=>{let e=n.get(w.gezelId);return e?s({name:e.name,roleBasedName:e.roleBasedName},f):void 0})():void 0,D=g?s({name:g.name,roleBasedName:g.roleBasedName},f):`Gezel`;if(t.kind===`streaming`&&p.startsWith(`one-shot:`)){let e=t.slot.activity?.trim()||`Background work`;return(0,R.jsxs)(`output`,{className:`timeline-session-divider timeline-session-divider-activity`,children:[(0,R.jsx)(j,{svg:g?.icon??null,poppetje:g?.poppetje,iconOverride:g?.iconOverride,name:D,size:16}),(0,R.jsxs)(`span`,{className:`timeline-divider-meta`,title:S(y),children:[D,` · `,e,_&&(0,R.jsxs)(R.Fragment,{children:[` · in `,_.name]}),` · `,`started `,x(y)]})]},d)}return(0,R.jsxs)(`button`,{type:`button`,className:`timeline-session-divider${v?` timeline-session-divider-active`:``}${c?` timeline-session-divider-continuing`:``}${l>0?` timeline-session-divider-child timeline-session-depth-${Math.min(l,4)}`:``}`,onClick:()=>o?.(p,m,h),title:b?`View this read-only thread from ${b.appName}`:`Focus this thread — composer will post here`,children:[l>0&&u&&(0,R.jsx)(bn,{branch:u,phase:`divider`}),(0,R.jsx)(j,{svg:g?.icon??null,poppetje:g?.poppetje,iconOverride:g?.iconOverride,name:D,size:16}),(0,R.jsxs)(`span`,{className:`timeline-divider-meta`,title:S(y),children:[c?(0,R.jsxs)(R.Fragment,{children:[`↩ continuing with `,D,_&&(0,R.jsxs)(R.Fragment,{children:[` · in `,_.name]}),b&&(0,R.jsxs)(R.Fragment,{children:[` · from `,b.appName,` · read-only`]})]}):b?(0,R.jsxs)(R.Fragment,{children:[`external thread with `,D,` · from `,b.appName,` · read-only`,_&&(0,R.jsxs)(R.Fragment,{children:[` · in `,_.name]}),` · `,`started `,x(y)]}):T?(0,R.jsxs)(R.Fragment,{children:[T.kind===`consultation`?`consultation with ${D}`:T.kind===`task-handoff`?`task hand-off to ${D}`:`delegated to ${D}`,_&&(0,R.jsxs)(R.Fragment,{children:[` · in `,_.name]}),` · `,`started `,x(y)]}):(0,R.jsxs)(R.Fragment,{children:[`new thread with `,D,_&&(0,R.jsxs)(R.Fragment,{children:[` · in `,_.name]}),` · `,`started `,x(y)]}),ee&&(0,R.jsxs)(R.Fragment,{children:[` · task `,ee]})]}),T&&(T.kind===`task-handoff`?te??E:E)&&(0,R.jsxs)(`span`,{className:`timeline-divider-handoff`,children:[(0,R.jsxs)(`svg`,{className:`timeline-divider-handoff-icon`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,focusable:`false`,children:[(0,R.jsx)(`path`,{d:`M2.5 4.25v2.1a4.4 4.4 0 0 0 4.4 4.4H13`}),(0,R.jsx)(`path`,{d:`m10.5 8.25 2.75 2.5-2.75 2.5`})]}),T.kind===`task-handoff`?`from`:`by`,` `,T.kind===`task-handoff`?te??E:E]})]},d)}function Sn(e){let{entry:t,key:n}=e;return(0,R.jsxs)(`div`,{className:`timeline-session-divider timeline-terminal-session-divider`,children:[(0,R.jsx)(`span`,{className:`terminal-folder-pill`,title:`Working folder`,children:t.workingDir===``?`/`:t.workingDir}),(0,R.jsxs)(`span`,{className:`timeline-divider-meta`,title:S(t.at),children:[`terminal session · started `,x(t.at)]})]},n)}function Cn(e){return e.replace(/["\\]/g,`\\$&`)}function wn(e,t){let n=new Map((e??[]).map(e=>[e.messageId,e]));for(let e of t)n.set(e.messageId,e);return[...n.values()].sort((e,t)=>e.at<t.at?-1:+(e.at>t.at))}function Tn(e,t){let n=t.filter(e=>e.role===`user`),r=e.filter(e=>{if(!e.optimistic)return!0;let t=Date.parse(e.at);return!n.some(n=>{if(n.sessionId!==e.sessionId||n.content!==e.content)return!1;let r=Date.parse(n.at);return Number.isFinite(t)&&Number.isFinite(r)?Math.abs(r-t)<2*6e4:!0})}),i=new Set,a=[];for(let e of[...t,...r]){let t=`${e.sessionId}:${e.at}:${e.role}`;i.has(t)||(i.add(t),a.push(e))}return a.sort((e,t)=>e.at<t.at?-1:+(e.at>t.at)),a}function En(e,t){for(let n=e.length-1;n>=0;n--)if(e[n].sessionId===t)return e[n];return null}function Dn(e){return/model\s+.*\bnot available\b/i.test(e)||/\bunknown model\b/i.test(e)}function On(e){return e?.code===`capacity-denied`||e?.code===`engine-busy`}function kn(e,t){return h(e)||Dn(e)||/\bdo not retry\b|\bcannot run on this machine\b/i.test(e)?!1:t?.code===`engine-busy`||t?.code===`capacity-denied`||t?.code===`native-engine-crash`||/\bretry the turn\b|\bsend (?:the )?message again\b|\bretry \(the cache is warm now\)|\btry a shorter prompt, retry\b/i.test(e)}var An=[];function jn(e){return e.referencedFiles?.length?e.referencedFiles:e.referencedArtifacts?.length?e.referencedArtifacts.map(e=>({kind:`artifact`,path:e})):An}function Mn(e,t){if(!e)return!1;try{let n=new Date(e).getTime();return Date.now()-n<=t}catch{return!1}}function Nn(e){switch(e){case`copilot`:return`Copilot`;case`openai`:return`OpenAI`;case`anthropic`:return`Claude`;case`anthropic-cli`:return`Claude CLI`;case`codex-cli`:return`Codex CLI`;case`ollama`:return`Ollama`;case`llama-cpp`:return`On-device`;case`mlx`:return`MLX`;case`ds4`:return`DwarfStar`;case`remote`:return`Remote`}}function Pn({store:e,itemKey:t,render:n,onRendered:r}){let i=(0,L.useCallback)(n=>e.subscribeItem(t,n),[e,t]),a=(0,L.useCallback)(()=>e.getItemSnapshot(t),[e,t]),o=(0,L.useSyncExternalStore)(i,a,a),s=e.items.get(t);return(0,L.useLayoutEffect)(()=>{s&&r?.()},[s,r,o]),s?(0,R.jsx)(R.Fragment,{children:n(s)}):null}function Fn({store:e,sessionId:t,userMsg:n,gezels:r}){return(0,R.jsx)(Pn,{store:e,itemKey:t,render:e=>(0,R.jsx)(Ot,{payload:{userMsg:n,assistantInfo:{kind:`live`,sessionId:t,slot:e}},gezels:r})})}var In={request(e){return typeof requestAnimationFrame==`function`?requestAnimationFrame(e):window.setTimeout(()=>e(performance.now()),16)},cancel(e){typeof cancelAnimationFrame==`function`?cancelAnimationFrame(e):window.clearTimeout(e)}},Ln=class{scheduler;items=new Map;structureVersion=0;itemVersions=new Map;structureListeners=new Set;itemListeners=new Map;pendingItems=new Set;pendingStructure=!1;frameHandle=null;constructor(e=In){this.scheduler=e}getStructureSnapshot=()=>this.structureVersion;subscribeStructure=e=>(this.structureListeners.add(e),()=>this.structureListeners.delete(e));getItemSnapshot(e){return this.itemVersions.get(e)??0}subscribeItem(e,t){let n=this.itemListeners.get(e);return n||(n=new Set,this.itemListeners.set(e,n)),n.add(t),()=>{n?.delete(t),n?.size===0&&this.itemListeners.delete(e)}}markItemChanged(e){this.pendingItems.add(e),this.scheduleFlush()}markStructureChanged(){this.pendingStructure=!0,this.scheduleFlush()}scheduleFlush(){this.frameHandle===null&&(this.frameHandle=this.scheduler.request(()=>this.flush()))}flush(){this.frameHandle=null;let e=this.pendingStructure,t=[...this.pendingItems];if(this.pendingStructure=!1,this.pendingItems.clear(),e){this.structureVersion+=1;for(let e of this.structureListeners)e()}for(let e of t){this.itemVersions.set(e,(this.itemVersions.get(e)??0)+1);for(let t of this.itemListeners.get(e)??[])t()}}dispose(){this.frameHandle!==null&&this.scheduler.cancel(this.frameHandle),this.frameHandle=null,this.pendingStructure=!1,this.pendingItems.clear(),this.structureListeners.clear(),this.itemListeners.clear()}};function Rn(e){let t=e.root?[e.root,...e.replies]:e.replies;for(let e of t)if(e.kind===`message`&&e.msg.parentSession?.sessionId)return e.msg.parentSession.sessionId}function zn(e){let t=new Map,n=new Map,r=new Map;for(let i=0;i<e.length;i++){let a=e[i];if(!a||a.kind!==`thread`)continue;let o=t.get(a.sessionId)??[];o.push(a),t.set(a.sessionId,o),n.has(a.sessionId)||n.set(a.sessionId,i);let s=Rn(a);s&&s!==a.sessionId&&r.set(a.sessionId,s)}let i=new Set(t.keys()),a=new Map;for(let[e,t]of r){if(!i.has(t))continue;let n=a.get(t)??[];n.push(e),a.set(t,n)}for(let e of a.values())e.sort((e,t)=>(n.get(e)??0)-(n.get(t)??0));let o=new Map;for(let e of a.values())for(let t=0;t<e.length;t++){let n=e[t];n&&o.set(n,t<e.length-1)}let s=new Map,c=(e,t=new Set)=>{let n=s.get(e);if(n!==void 0)return n;if(t.has(e))return 0;let a=r.get(e);if(!a||!i.has(a))return s.set(e,0),0;let o=new Set(t);o.add(e);let l=Math.min(4,c(a,o)+1);return s.set(e,l),l};for(let e of i)c(e);let l=new Map;for(let e of i){let t=[];if((s.get(e)??0)>0){let n=r.get(e),i=2;for(;n&&r.has(n);)o.get(n)===!0&&t.push(i),n=r.get(n),i+=1}l.set(e,{hasChildren:(a.get(e)?.length??0)>0,hasFollowingSibling:o.get(e)===!0,ancestorContinuationLevels:t})}let u=new Set;for(let[e,t]of r)i.has(t)&&(s.get(e)??0)>0&&u.add(e);let d=[],f=new Set,p=(e,n=new Set)=>{if(f.has(e)||n.has(e))return;f.add(e);for(let n of t.get(e)??[])d.push(n);let r=new Set(n);r.add(e);for(let t of a.get(e)??[])p(t,r)},m=new Map;for(let t=0;t<e.length;t++){let n=e[t];n?.kind===`thread`&&!u.has(n.sessionId)&&m.set(n.sessionId,t)}for(let t=0;t<e.length;t++){let n=e[t];if(n){if(n.kind!==`thread`){d.push(n);continue}if(!u.has(n.sessionId)&&(d.push(n),m.get(n.sessionId)===t)){f.add(n.sessionId);for(let e of a.get(n.sessionId)??[])p(e)}}}for(let e of i)f.has(e)||p(e);return{items:d,depthBySession:s,branchBySession:l}}function Bn(e){let t=new Map,n=new Map;for(let r of e){if(r.role!==`user`)continue;let e=r.content.trim(),i=Date.parse(r.at),a=t.get(e);if(a&&a.sessionId!==r.sessionId&&i-a.atMs<=5e3){n.set(r,a.row);continue}t.set(e,{atMs:i,sessionId:r.sessionId,row:r})}return n}function Vn(e){let t=Bn(e.flatMap(e=>e.kind===`message`&&e.msg.role===`user`?[{at:e.msg.at,role:e.msg.role,content:e.msg.content,sessionId:e.msg.sessionId,ref:e}]:[])),n=new Map;for(let[e,r]of t)n.set(e.ref,r.ref);let r=[],i=new Map,a=new Map;for(let t of e){if(t.kind===`indexing`||t.kind===`terminal`||t.kind===`terminal-streaming`){r.push(t);continue}if(t.kind===`message`&&t.msg.role===`user`){let e=n.get(t);if(e){let n=a.get(e);if(n){i.set(t.msg.sessionId,n);continue}}let o={kind:`thread`,sessionId:t.msg.sessionId,at:t.at,root:t,replies:[]};r.push(o),i.set(t.msg.sessionId,o),a.set(t,o);continue}let e=t.kind===`message`?t.msg.sessionId:t.sessionId,o=i.get(e);o||(o={kind:`thread`,sessionId:e,at:t.kind===`streaming`?t.threadAt??t.at:t.at,replies:[]},r.push(o),i.set(e,o)),o.replies.push(t);let s=r.indexOf(o);s>=0&&s!==r.length-1&&(r.splice(s,1),r.push(o))}return r}function Hn(){let[e,t]=(0,L.useState)(!1);return(0,L.useEffect)(()=>{let e=!1;_.getConfig().then(n=>{e||t(n.narrateAssistantReplies??!1)}).catch(()=>{});let n=e=>{let n=e.detail;n&&typeof n.narrateAssistantReplies==`boolean`&&t(n.narrateAssistantReplies)};return window.addEventListener(`gezel:config-updated`,n),()=>{e=!0,window.removeEventListener(`gezel:config-updated`,n)}},[]),e}var Un=100,Wn=new Set([`ollama`,`llama-cpp`,`mlx`,`ds4`]),Gn=180*1e3,Kn=80,qn=80,Jn=700,Yn=300,Xn=2e3,Zn=7200*1e3,Qn=4,$n=1e4;function er(e){return e.role===`assistant`&&e.toolCalls?.some(e=>e.success&&u(e.name).replace(/^gezel-/,``)===`ask_user_question`)===!0}var tr={starting:`Starting engine`,loading_model:`Loading model`,prefill:`Thinking it through`,generating:`Generating`,ready:`Ready`};function nr({scopeKey:e,activeSessionId:t,onFocusSession:n,onToolActivity:i,onArtifactReference:a,onArtifactSeen:o,onWorkspaceReference:c,onWorkspaceSeen:l,onOpenReference:u,onTaskReference:d,queuedTasks:p,emptyPlaceholder:g,emptyContent:v,loadTimeline:y,streamUrl:ee,terminalStreamUrl:b,terminalRefreshKey:S,terminalSubmission:w,terminalFocusRequest:T,sessionFocusRequest:E,onTerminalWorkingDirChanged:te,showProjectName:D,inflightScope:ne,scopedSessionIds:A,onUnknownSession:j}){let ie=O(),M=(0,L.useRef)(A);M.current=A;let ce=(0,L.useRef)(j);ce.current=j;let ue=Hn(),de=(0,L.useRef)(ue);de.current=ue;let fe=(0,L.useRef)(null),me=(0,L.useRef)(null),N=(0,L.useRef)(new Map);(0,L.useEffect)(()=>()=>{_n(fe,me)},[]);let[P,F]=(0,L.useState)([]),_e=(0,L.useRef)([]),I=(0,L.useRef)(new Set);(0,L.useEffect)(()=>{_e.current=P},[P]),(0,L.useEffect)(()=>{if(d)for(let e of P){if(e.taskRef){let n=!!t&&e.sessionId===t;d(e.taskRef,{scoped:n})}if(e.referencedTasks)for(let t of e.referencedTasks)d(t)}},[P,t,d]),(0,L.useEffect)(()=>{if(!(!o&&!l))for(let e of P){let t=`${e.sessionId}\u0000${e.at}\u0000${e.role}`,n=(n,r)=>{let i=n===`workspace`?l:o;if(!i)return;let a=`${t}\u0000${n}\u0000${r}`;I.current.has(a)||(I.current.add(a),i(r,e.projectId))};for(let t of jn(e))n(t.kind,t.path);for(let t of e.toolCalls??[]){if(!t.success)continue;for(let e of[...t.images??[],...t.audios??[],...t.videos??[]])n(`artifact`,e.path);let e=t.paths?.length?t.paths:t.path?[t.path]:[];for(let r of e)t.name===`read_artifact`||t.name===`write_artifact`?n(`artifact`,r):(t.name===`read_file`||t.name===`read_files`||t.name===`write_file`)&&n(`workspace`,r)}}},[P,o,l]);let[ve,ye]=(0,L.useState)([]),[be,z]=(0,L.useState)([]),[xe,Se]=(0,L.useState)(0),[Ce,we]=(0,L.useState)(!1),[B,Te]=(0,L.useState)();(0,L.useEffect)(()=>{let e=un(ve,Date.now());if(e===void 0)return;let t=window.setTimeout(()=>Se(e=>e+1),Math.max(0,e-Date.now()+1));return()=>window.clearTimeout(t)},[ve,xe]),(0,L.useEffect)(()=>{t&&_.warmSessionCache(t).catch(()=>{})},[t]);let[Ee,V]=(0,L.useState)(!0),[De,Oe]=(0,L.useState)(null),[ke,Ae]=(0,L.useState)(new Map),[je,Me]=(0,L.useState)(new Set),[H,Ne]=(0,L.useState)(new Map),Pe=(0,L.useRef)(H);Pe.current=H;let[Fe,Ie]=(0,L.useState)(new Map),[Le,Re]=(0,L.useState)(new Map),ze=(0,L.useRef)(new Set),Be=(0,L.useRef)(e);Be.current=e;let Ve=(0,L.useRef)(null);Ve.current||=new Ln;let U=Ve.current,W=(0,L.useRef)(U.items),He=(0,L.useSyncExternalStore)(U.subscribeStructure,U.getStructureSnapshot,U.getStructureSnapshot),Ue=(0,L.useRef)(null);Ue.current||=new Ln;let We=Ue.current;(0,L.useEffect)(()=>{let e=e=>{let t=e.detail?.projectId;if(typeof t!=`string`||t.length===0)return;Me(e=>{let n=new Set(e);return n.add(t),n}),F(e=>e.map(e=>e.projectId===t?{...e,sessionLastTurnError:void 0,sessionLastTurnErrorDetail:void 0}:e));let n=!1;for(let[e,r]of W.current)r.projectId!==t||!r.error||(W.current.delete(e),n=!0);n&&U.markStructureChanged(),Ae(e=>{let n=new Map(e);for(let e of _e.current)e.projectId===t&&n.delete(e.sessionId);return n})};return window.addEventListener(`gezel:session-error-cleared`,e),()=>window.removeEventListener(`gezel:session-error-cleared`,e)},[U]);let Ge=(0,L.useRef)(We.items),Ke=(0,L.useSyncExternalStore)(We.subscribeStructure,We.getStructureSnapshot,We.getStructureSnapshot),qe=(0,L.useRef)(new Map),G=(0,L.useRef)(null),Ye=(0,L.useRef)(null),Xe=(0,L.useRef)(null),[Ze,Qe]=(0,L.useState)(!0),$e=(0,L.useRef)(!0);$e.current=Ze;let[K,et]=(0,L.useState)(null),[tt,nt]=(0,L.useState)(null),rt=(0,L.useRef)(null),at=(0,L.useRef)(null),q=(0,L.useRef)(!1),[J,ot]=(0,L.useState)(null),st=(0,L.useRef)(null),ct=(0,L.useRef)(60),Y=(0,L.useRef)(0),lt=(0,L.useRef)(0),ut=(0,L.useRef)(null),X=ne?.projectId,Z=ne?.gezelId;(0,L.useEffect)(()=>{let t=!1;return V(!0),Oe(null),Ae(new Map),F([]),ye([]),z(Mt(e)),we(!1),Te(void 0),Me(new Set),I.current.clear(),ze.current.clear(),W.current.clear(),U.markStructureChanged(),Ge.current.clear(),We.markStructureChanged(),qe.current.clear(),$e.current=!0,Qe(!0),et(null),nt(null),Y.current=0,lt.current=0,(async()=>{try{let e=await y({limit:Un});if(t)return;F(e.messages),we(e.hasMore),Te(e.nextCursor),ye(t=>wn(e.terminalEntries,t));try{let n=await _.listInflightTurns({...X===void 0?{}:{projectId:X},...Z===void 0?{}:{gezelId:Z}});if(t)return;for(let t of n.inflight){if(W.current.has(t.sessionId)||M.current&&!M.current.has(t.sessionId))continue;let n=En(e.messages,t.sessionId);W.current.set(t.sessionId,{gezelId:t.gezelId,projectId:t.projectId,segments:[],startedAt:t.startedAt,lastActivityAt:t.lastProgressAgoMs==null?t.startedAt:Date.now()-t.lastProgressAgoMs,hasProgress:t.lastProgressAgoMs!=null,...n?{sessionTitle:n.sessionTitle,sessionCreatedAt:n.sessionCreatedAt,sessionProviderName:n.sessionProviderName,...n.sessionModel?{sessionModel:n.sessionModel}:{},...n.taskRef?{taskRef:n.taskRef}:{}}:{}})}n.inflight.length>0&&U.markStructureChanged()}catch{}try{let e=await _.getQueueStatus();if(t)return;for(let t of e.sessions)M.current&&!M.current.has(t.sessionId)||qe.current.set(t.sessionId,t.entries.map(e=>({id:e.queueId,preview:e.preview,enqueuedAt:e.enqueuedAt,...e.nudge?{nudge:!0}:{}})));e.sessions.length>0&&U.markStructureChanged()}catch{}try{let e=await y({limit:Un});if(t)return;F(t=>Tn(t,e.messages)),ye(t=>wn(e.terminalEntries,t))}catch{}}catch(e){t||Oe(e.message)}finally{t||V(!1)}})(),()=>{t=!0}},[e,y,X,Z]);let[Q,$]=(0,L.useState)(`copilot`),[dt,ft]=(0,L.useState)({}),[pt,mt]=(0,L.useState)(!1);(0,L.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await _.getConfig();if(e)return;$(t.provider),ft(t.defaultModel??{}),mt(t.debugMode===!0)}catch{}})(),()=>{e=!0}},[]);let ht=(0,L.useCallback)((e,t,n=!1)=>{let i=En(e,t.sessionId);return{sessionId:t.sessionId,gezelId:t.gezelId,projectId:t.projectId,sessionTitle:i?.sessionTitle??r(t.content),sessionCreatedAt:i?.sessionCreatedAt??t.at,sessionLastActivityAt:t.at,sessionProviderName:i?.sessionProviderName??Q,...i?.sessionModel?{sessionModel:i.sessionModel}:{},...i?.taskRef?{taskRef:i.taskRef}:{},...i?.stepId?{stepId:i.stepId}:{},role:`user`,content:t.content,at:t.at,...t.from?{from:t.from}:{},...n?{optimistic:!0}:{}}},[Q]),gt=(0,L.useCallback)(e=>H.get(e)?.provider??Q,[H,Q]),_t=(0,L.useCallback)(e=>{let t=H.get(e),n=gt(e),r=t?.model;return r?`Provider: ${Nn(n)} (${r})`:`Provider: ${Nn(n)}`},[H,gt]),vt=(0,L.useCallback)((e,t)=>{let n=dt[Q],r=Wn.has(e);if(e!==Q)return t&&!r?`${Nn(e)} · ${t}`:Nn(e);if(!r&&t&&n&&t!==n)return t},[Q,dt]),yt=(0,L.useRef)(null),bt=(0,L.useCallback)(()=>{if(yt.current)return yt.current;let e=(async()=>{try{let e=await _.listGezels(),t=new Map;for(let n of e.gezels)t.set(n.id,n);Ne(t)}catch{}finally{yt.current=null}})();return yt.current=e,e},[]);(0,L.useEffect)(()=>{bt()},[bt]),(0,L.useEffect)(()=>{let e=e=>{let t=e.detail;t?.id&&Ne(e=>{let n=new Map(e);return n.set(t.id,{...n.get(t.id),...t}),n})};return window.addEventListener(`gezel:gezel-updated`,e),()=>window.removeEventListener(`gezel:gezel-updated`,e)},[]),(0,L.useEffect)(()=>{if(!D)return;let e=!1;return(async()=>{try{let t=await _.listProjects();if(e)return;let n=new Map;for(let e of t.projects)n.set(e.id,e);Ie(n)}catch{}})(),()=>{e=!0}},[D]);let xt=(0,L.useCallback)(async()=>{try{let e=await _.listQuestions({pending:!0});Re(t=>{let n=new Map(t);for(let[e,t]of n)t.answer||n.delete(e);for(let t of e.questions)n.set(t.id,t);return n})}catch{}},[]);(0,L.useEffect)(()=>{xt()},[e,xt]),(0,L.useEffect)(()=>{let t=new Set;for(let e of P)!e.pendingQuestionId&&!er(e)||ze.current.has(e.projectId)||t.add(e.projectId);if(t.size===0)return;let n=[...t],r=e;for(let e of n)ze.current.add(e);Promise.allSettled(n.map(e=>_.listQuestions({projectId:e}))).then(e=>{if(Be.current!==r)return;let t=[];e.forEach((e,r)=>{e.status===`fulfilled`?t.push(...e.value.questions):ze.current.delete(n[r])}),t.length!==0&&Re(e=>{let n=new Map(e);for(let e of t)n.set(e.id,e);return n})})},[P,e]),(0,L.useEffect)(()=>{let e=new AbortController,t=!1,n=250;return(async()=>{for(;!t;){try{let r={url:ee(),headers:_.authHeader(),signal:e.signal,fetch:_.getFetch()};for await(let e of ge(r)){if(t)return;Ct(e),n=250}}catch(e){if(t||e.name===`AbortError`)return;console.warn(`[ChatTimelineView] envelope stream error (reconnecting in ${n}ms):`,e)}if(t)return;await new Promise(e=>setTimeout(e,n)),n=Math.min(n*2,5e3)}})(),()=>{t=!0,e.abort()}},[e,ee]),(0,L.useEffect)(()=>{if(!b)return;let e=new AbortController,t=!1,n=250;return(async()=>{let{streamTerminalEvents:r}=await C(async()=>{let{streamTerminalEvents:e}=await import(`./dist-BaHut5iX.js`).then(e=>e.r);return{streamTerminalEvents:e}},__vite__mapDeps([0,1,2]));for(;!t;){try{for await(let i of r({url:b(),headers:_.authHeader(),signal:e.signal,fetch:_.getFetch()})){if(t)return;if(i.kind===`workingDirChanged`){te?.(i.threadId,i.newWorkingDir),n=250;continue}if(i.kind===`openFile`){c?.(i.path,i.projectId),n=250;continue}if(i.kind===`runStarted`){Ge.current.set(i.runId,{projectId:i.projectId,threadId:i.threadId,commandMessageId:i.commandMessageId,startedAt:i.at,cwd:i.cwd,content:``}),We.markStructureChanged(),n=250;continue}if(i.kind===`outputChunk`){let e=Ge.current.get(i.runId);e&&(e.content+=i.chunk,e.awaitingInput&&delete e.awaitingInput,We.markItemChanged(i.runId)),n=250;continue}if(i.kind===`inputRequested`){let e=Ge.current.get(i.runId);e&&(e.awaitingInput={promptLine:i.promptLine,mode:i.mode},We.markItemChanged(i.runId)),n=250;continue}i.runId&&(Ge.current.delete(i.runId),We.markStructureChanged()),ye(e=>{if(e.some(e=>e.messageId===i.message.id))return e;let t={threadId:i.threadId,projectId:i.projectId,workingDir:i.workingDir,threadCreatedAt:i.message.at,threadLastActivityAt:i.message.at,messageId:i.message.id,msgKind:i.message.kind,content:i.message.content,at:i.message.at,...i.message.resolvedFrom?{resolvedFrom:i.message.resolvedFrom}:{},...i.message.stdout===void 0?{}:{stdout:i.message.stdout},...i.message.stderr===void 0?{}:{stderr:i.message.stderr},...i.message.exitCode===void 0?{}:{exitCode:i.message.exitCode},...i.message.durationMs===void 0?{}:{durationMs:i.message.durationMs},...i.message.truncated?{truncated:!0}:{},...i.message.errorMessage?{errorMessage:i.message.errorMessage}:{},...i.message.fileReferences?{fileReferences:i.message.fileReferences}:{},...i.message.cwd===void 0?{}:{cwd:i.message.cwd}},n=[...e,t];return n.sort((e,t)=>e.at<t.at?-1:+(e.at>t.at)),n}),n=250}}catch(e){if(t||e.name===`AbortError`)return;console.warn(`[ChatTimelineView] terminal stream error (reconnecting in ${n}ms):`,e)}if(t)return;await new Promise(e=>setTimeout(e,n)),n=Math.min(n*2,5e3)}})(),()=>{t=!0,e.abort()}},[e,b,c]),(0,L.useEffect)(()=>{if(!S)return;let e=!1;return y({limit:Un}).then(t=>{e||ye(e=>wn(t.terminalEntries,e))}).catch(()=>{}),()=>{e=!0}},[S,y]),(0,L.useEffect)(()=>{w&&(et({kind:`terminal`,key:`terminal:${w.runId}`,runId:w.runId,threadId:w.threadId,input:w.input}),nt(null))},[w]);let St=(0,L.useCallback)(async()=>{try{let e=await y({limit:Un});F(t=>Tn(t,e.messages));let t=he(W.current,e.messages);for(let e of t)W.current.delete(e);t.length>0&&U.markStructureChanged()}catch{}},[y,U.markStructureChanged]);(0,L.useEffect)(()=>{let e=!1,t=!1,n=async()=>{if(t||W.current.size===0)return;t=!0;let n=new Map(W.current);try{let t=await _.listInflightTurns({...X===void 0?{}:{projectId:X},...Z===void 0?{}:{gezelId:Z}});if(e)return;let r=new Set(t.inflight.map(e=>e.sessionId)),i=re(W.current,n,r);if(i.length===0)return;for(let e of i)W.current.delete(e),N.current.delete(e);U.markStructureChanged(),St()}catch{}finally{t=!1}},r=window.setInterval(()=>{n()},5e3);return()=>{e=!0,window.clearInterval(r)}},[X,Z,St,U.markStructureChanged]),(0,L.useEffect)(()=>it(e=>{if(X!==void 0&&e.projectId!==X||Z!==void 0&&e.gezelId!==Z||M.current&&!M.current.has(e.sessionId))return;let t=Date.parse(e.at);if(F(n=>{if(n.some(n=>{if(n.sessionId!==e.sessionId||n.role!==`user`||n.content!==e.content)return!1;let r=Date.parse(n.at);return Number.isFinite(t)&&Number.isFinite(r)?Math.abs(r-t)<2*6e4:!0}))return n;let r=[...n,ht(n,e,!0)];return r.sort((e,t)=>e.at<t.at?-1:+(e.at>t.at)),r}),!W.current.has(e.sessionId)){let n=En(_e.current,e.sessionId),i=Number.isFinite(t)?t:Date.now();W.current.set(e.sessionId,{gezelId:e.gezelId,projectId:e.projectId,segments:[],startedAt:i,lastActivityAt:i,hasProgress:!1,...n?{sessionTitle:n.sessionTitle}:{sessionTitle:r(e.content)},...n?{sessionCreatedAt:n.sessionCreatedAt}:{sessionCreatedAt:e.at},...n?{sessionProviderName:n.sessionProviderName,...n.sessionModel?{sessionModel:n.sessionModel}:{}}:{},...n?.taskRef?{taskRef:n.taskRef}:{},...n?.stepId?{stepId:n.stepId}:{}}),U.markStructureChanged()}et({kind:`chat`,key:`chat:${e.sessionId}:${e.at}`,sessionId:e.sessionId,content:e.content,at:e.at}),nt(null)}),[X,Z,ht,U.markStructureChanged]);let Ct=(0,L.useCallback)(t=>{let{sessionId:n,gezelId:a,projectId:o,event:s}=t;if(X!==void 0&&o!==X||Z!==void 0&&a!==Z)return;let c=M.current;if(c&&!c.has(n)){ce.current?.(n);return}if(Pe.current.has(a)||bt(),s.type===`user_message`){!s.message.hidden&&!s.message.from&&(_n(fe,me),N.current.delete(n));let e=En(P,n),i={sessionId:n,gezelId:a,projectId:o,sessionTitle:e?.sessionTitle??r(s.message.content),sessionCreatedAt:e?.sessionCreatedAt??s.message.at,sessionLastActivityAt:s.message.at,sessionProviderName:e?.sessionProviderName??Q,...e?.sessionSource?{sessionSource:e.sessionSource}:t.sessionSource?{sessionSource:t.sessionSource}:{},...e?.sessionModel?{sessionModel:e.sessionModel}:{},...e?.taskRef?{taskRef:e.taskRef}:{},...e?.stepId?{stepId:e.stepId}:{},...e?.parentSession?{parentSession:e.parentSession}:t.parentSession?{parentSession:t.parentSession}:{},...e?.handoffFrom?{handoffFrom:e.handoffFrom}:t.handoffFrom?{handoffFrom:t.handoffFrom}:{},role:s.message.role,content:s.message.content,at:s.message.at,...s.message.from?{from:s.message.from}:{},...s.message.nudge?{nudge:!0}:{},...s.message.origin===`system`?{origin:`system`}:{}},c=`${n}:${s.message.at}:${s.message.role}`;if(F(e=>{if(s.message.hidden)return e;let t=e.filter(e=>!e.optimistic||!(e.sessionId===n&&e.role===s.message.role&&e.content===s.message.content));if(t.some(e=>`${e.sessionId}:${e.at}:${e.role}`===c))return t;let r=[...t,i];return r.sort((e,t)=>e.at<t.at?-1:+(e.at>t.at)),r}),s.message.role===`user`&&W.current.get(n)?.error&&W.current.delete(n),s.message.role===`user`&&!W.current.has(n)){let r=Date.parse(s.message.at),c=Number.isFinite(r)?r:Date.now();W.current.set(n,{gezelId:a,projectId:o,segments:[],startedAt:c,lastActivityAt:c,hasProgress:!1,...e?{sessionTitle:e.sessionTitle}:{sessionTitle:i.sessionTitle},...e?{sessionCreatedAt:e.sessionCreatedAt}:{sessionCreatedAt:i.sessionCreatedAt},...e?{sessionProviderName:e.sessionProviderName,...e.sessionModel?{sessionModel:e.sessionModel}:{}}:{},...e?.sessionSource?{sessionSource:e.sessionSource}:t.sessionSource?{sessionSource:t.sessionSource}:{},...e?.taskRef?{taskRef:e.taskRef}:{},...e?.parentSession?{parentSession:e.parentSession}:t.parentSession?{parentSession:t.parentSession}:{},...e?.handoffFrom?{handoffFrom:e.handoffFrom}:t.handoffFrom?{handoffFrom:t.handoffFrom}:{}}),U.markStructureChanged()}}else if(s.type===`delta`){let e=W.current.get(n)??l(a,o,n),t=e.segments[e.segments.length-1],r=Date.now(),i=r-e.lastActivityAt<5e3;t?.kind===`text`&&i?t.content+=s.content:e.segments.push({kind:`text`,content:s.content}),e.lastActivityAt=r,e.hasProgress=!0,delete e.queueAhead,delete e.queuedAt,e.wirePulseCount=0,e.thinkingLabel=void 0,delete e.thinkingProgress,delete e.thinkingDetail,delete e.liveToolArgs,W.current.set(n,e),U.markItemChanged(n)}else if(s.type===`reasoning_delta`){let e=W.current.get(n)??l(a,o,n),t=e.segments[e.segments.length-1];t?.kind===`reasoning`?t.content+=s.content:e.segments.push({kind:`reasoning`,content:s.content}),e.lastActivityAt=Date.now(),e.hasProgress=!0,delete e.queueAhead,delete e.queuedAt,e.wirePulseCount=0,delete e.thinkingProgress,delete e.thinkingDetail,W.current.set(n,e),U.markItemChanged(n)}else if(s.type===`tool_args_delta`){let e=W.current.get(n)??l(a,o,n),t=e.liveToolArgs,r=s.name.length>0?s.name:t?.name??``,i=((t?.head??``)+s.content).slice(0,400),c=((t?.tail??``)+s.content).slice(-2e3);e.liveToolArgs={name:r,chars:(t?.chars??0)+s.content.length,head:i,tail:c},e.lastActivityAt=Date.now(),e.hasProgress=!0,delete e.queueAhead,delete e.queuedAt,W.current.set(n,e),U.markItemChanged(n)}else if(s.type===`wire_pulse`){let e=W.current.get(n)??l(a,o,n);e.wirePulseCount=(e.wirePulseCount??0)+1,e.lastActivityAt=Date.now(),e.hasProgress=!0,W.current.set(n,e),U.markItemChanged(n)}else if(s.type===`intent`){let e=W.current.get(n)??l(a,o,n);e.segments.push({kind:`intent`,label:s.label}),e.lastActivityAt=Date.now(),e.hasProgress=!0,e.wirePulseCount=0,delete e.queueAhead,delete e.queuedAt,W.current.set(n,e),U.markItemChanged(n)}else if(s.type===`heartbeat`){let e=W.current.get(n)??l(a,o,n);e.lastActivityAt=Date.now(),e.hasProgress=!0,e.wirePulseCount=0,e.thinkingLabel=s.label,W.current.set(n,e),U.markItemChanged(n)}else if(s.type===`warning`){let e=W.current.get(n)??l(a,o,n);e.warnings=[...e.warnings??[],s],W.current.set(n,e),U.markItemChanged(n)}else if(s.type===`queued`){let e=W.current.get(n)??l(a,o,n);e.queueAhead=s.aheadOf,e.queuedAt=Date.now(),W.current.set(n,e),U.markItemChanged(n)}else if(s.type===`queue_enqueued`){let e=qe.current.get(n)??[],t={id:s.queueId,preview:s.preview,enqueuedAt:s.enqueuedAt,...s.nudge?{nudge:!0}:{}},r=e.findIndex(e=>e.id===s.queueId);r>=0?e[r]=t:e.push(t),qe.current.set(n,e),U.markStructureChanged()}else if(s.type===`queue_removed`){let e=qe.current.get(n);if(e){let t=e.filter(e=>e.id!==s.queueId);t.length===0?qe.current.delete(n):qe.current.set(n,t),U.markStructureChanged()}}else if(s.type===`tool`){let e=W.current.get(n)??l(a,o,n),t={name:s.name,durationMs:s.durationMs,success:s.success,...s.errorMessage?{errorMessage:s.errorMessage}:{},...s.path?{path:s.path}:{},...s.paths&&s.paths.length>0?{paths:s.paths}:{},...s.argsSummary?{argsSummary:s.argsSummary}:{},...s.argsFull?{argsFull:s.argsFull}:{},...s.resultText?{resultText:s.resultText}:{},...s.resultTruncated?{resultTruncated:!0}:{},...s.images&&s.images.length>0?{images:s.images}:{},...s.diff===void 0?{}:{diff:s.diff},...s.addedLines===void 0?{}:{addedLines:s.addedLines},...s.removedLines===void 0?{}:{removedLines:s.removedLines},...s.card?{card:s.card}:{},projectId:o};e.segments.push({kind:`tool`,tool:t}),e.lastActivityAt=Date.now(),e.hasProgress=!0,e.wirePulseCount=0,delete e.liveToolArgs,delete e.queueAhead,delete e.queuedAt,W.current.set(n,e),U.markItemChanged(n),i?.(t)}else if(s.type===`complete`){F(e=>e.map(e=>e.sessionId===n?{...e,sessionLastTurnError:void 0,sessionLastTurnErrorDetail:void 0}:e)),Ae(e=>{if(!e.has(n))return e;let t=new Map(e);return t.delete(n),t});let e=W.current.get(n);e&&(e.segments=[],e.lastActivityAt=Date.now(),e.hasProgress=!0,e.wirePulseCount=0,delete e.liveToolArgs,delete e.queueAhead,delete e.error,W.current.set(n,e)),U.markItemChanged(n),St();let t=s.message.content.trim().length;console.debug(`[narrate] complete event — contentLen=${t} gezelId=${a} projectId=${o} sessionId=${n} (buffering for done)`),t>0&&N.current.set(n,{content:s.message.content,gezelId:a,projectId:o})}else if(s.type===`error`){Me(e=>{if(!e.has(o))return e;let t=new Set(e);return t.delete(o),t}),F(e=>e.map(e=>e.sessionId===n?{...e,sessionLastTurnError:s.error,sessionLastTurnErrorDetail:s.errorDetail}:e)),Ae(e=>{if(!e.has(n))return e;let t=new Map(e);return t.delete(n),t});let e=W.current.get(n);e&&(e.error=s.error,e.errorDetail=s.errorDetail,W.current.set(n,e),U.markItemChanged(n))}else if(s.type===`cancelled`)W.current.delete(n)&&U.markStructureChanged(),St();else if(s.type===`done`){let t=W.current.get(n),r=Pt(t?.activity);if(t&&!t.error&&r){let i=new Date().toISOString();z(a=>{let o=Ft(a,{sessionId:n,gezelId:t.gezelId,projectId:t.projectId,path:r,startedAt:new Date(t.startedAt).toISOString(),completedAt:i});return o===a?a:(Nt(e,o),o)})}t&&!t.error&&(W.current.delete(n),U.markStructureChanged());let i=N.current.get(n);i&&(N.current.delete(n),de.current&&(console.debug(`[narrate] done event — playing buffered narration chars=${i.content.length} sessionId=${n}`),yn(i.content,i.gezelId,i.projectId,fe,me))),St()}else if(s.type===`engine_phase`){let t=W.current.get(n)??l(a,o,n);if(t.lastActivityAt=Date.now(),t.hasProgress=!0,s.activity?.trim()&&(t.activity=s.activity.trim()),s.phase===`ready`)delete t.thinkingLabel,delete t.thinkingProgress,delete t.thinkingDetail,delete t.thinkingPhase;else{let e=tr[s.phase];s.progress===void 0?(t.thinkingLabel=s.detail??e,t.thinkingPhase!==s.phase&&(delete t.thinkingProgress,delete t.thinkingDetail)):(t.thinkingLabel=e,t.thinkingProgress=s.progress,s.detail?t.thinkingDetail=s.detail:delete t.thinkingDetail),t.thinkingPhase=s.phase}W.current.set(n,t),U.markItemChanged(n);let r=Pt(s.activity);if(r){let i=new Date().toISOString();z(a=>{let o=Ft(a,{sessionId:n,gezelId:t.gezelId,projectId:t.projectId,path:r,startedAt:new Date(t.startedAt).toISOString(),completedAt:i});return o===a?a:(Nt(e,o),o)})}}else if(s.type===`gpu_swap`){let e=W.current.get(n)??l(a,o,n);e.lastActivityAt=Date.now(),s.state===`ended`?(delete e.gpuSwapTask,delete e.gpuSwapDetail,delete e.gpuSwapPrompt,delete e.gpuSwapProgress,delete e.gpuSwapStep,delete e.gpuSwapTotalSteps,delete e.gpuSwapSecondsPerStep):(e.gpuSwapTask=s.task,s.detail?e.gpuSwapDetail=s.detail:s.state===`started`&&delete e.gpuSwapDetail,s.prompt&&(e.gpuSwapPrompt=s.prompt),typeof s.progress==`number`&&(e.gpuSwapProgress=s.progress),typeof s.step==`number`&&(e.gpuSwapStep=s.step),typeof s.totalSteps==`number`&&(e.gpuSwapTotalSteps=s.totalSteps),typeof s.secondsPerStep==`number`&&(e.gpuSwapSecondsPerStep=s.secondsPerStep)),W.current.set(n,e),U.markItemChanged(n)}else if(s.type===`awaiting_gezel`){let e=W.current.get(n)??l(a,o,n);e.lastActivityAt=Date.now(),s.state===`ended`?delete e.awaitingGezelName:e.awaitingGezelName=s.targetGezelName,W.current.set(n,e),U.markItemChanged(n)}else s.type===`context_compacted`?(s.mode!==`mid-turn`&&St(),U.markStructureChanged()):(s.type===`question_asked`||s.type===`question_answered`)&&(Re(e=>{let t=new Map(e);return s.type===`question_answered`&&!s.question.answer?t.delete(s.question.id):t.set(s.question.id,s.question),t}),s.type===`question_asked`&&St());function l(e,n,r){let i=En(P,r);U.markStructureChanged();let a=Date.now();return{gezelId:e,projectId:n,segments:[],startedAt:a,lastActivityAt:a,hasProgress:!1,...i?{sessionTitle:i.sessionTitle}:{},...i?{sessionCreatedAt:i.sessionCreatedAt}:{},...i?.taskRef?{taskRef:i.taskRef}:{},...i?.parentSession?{parentSession:i.parentSession}:t.parentSession?{parentSession:t.parentSession}:{},...i?.handoffFrom?{handoffFrom:i.handoffFrom}:t.handoffFrom?{handoffFrom:t.handoffFrom}:{},...i?.sessionSource?{sessionSource:i.sessionSource}:t.sessionSource?{sessionSource:t.sessionSource}:{}}}},[P,i,St,bt,Q,X,Z,e,U.markItemChanged,U.markStructureChanged]),wt=(0,L.useMemo)(()=>{let e=[];for(let[t,n]of W.current.entries())e.push({kind:`streaming`,sessionId:t,slot:n});let t=P.map(e=>({kind:`message`,msg:e,at:e.at})),n=e.map(e=>({kind:`streaming`,sessionId:e.sessionId,slot:e.slot,at:new Date(e.slot.lastActivityAt).toISOString(),threadAt:new Date(e.slot.startedAt).toISOString()})),r=ve.map(e=>({kind:`terminal`,entry:e,at:e.at})),i=[];for(let[e,t]of Ge.current.entries())i.push({kind:`terminal-streaming`,runId:e,slot:t,at:t.startedAt});let a=be.map(e=>({kind:`indexing`,entry:e,at:e.completedAt})),o=[...t,...n,...a,...r,...i],s=Date.now();return o.sort((e,t)=>pn(e,t,s)),o},[P,be,ve,He,Ke,xe]),Tt=(0,L.useMemo)(()=>zn(hn(Vn(wt),t,Date.now())),[wt,t,xe]),Et=Tt.items,Dt=Tt.depthBySession,kt=Tt.branchBySession,At=(0,L.useMemo)(()=>{if(!p?.length)return[];let e=new Set;for(let[t,n]of W.current.entries()){let r=n.taskRef??En(P,t)?.taskRef;r&&e.add(r)}return p.filter(t=>{if(e.has(t.task.ref))return!1;let n=t.wait.sessionId;return!n||!W.current.has(n)&&!P.some(e=>e.sessionId===n)})},[p,P,He]);(0,L.useEffect)(()=>{let e=G.current;if(!e)return;let t=wt.length>Y.current,n=e.scrollHeight>lt.current;Y.current=wt.length,lt.current=e.scrollHeight,!(!t&&!n)&&Ze&&e.scrollTo({top:e.scrollHeight,behavior:`instant`})},[wt,Ze]);let jt=(0,L.useCallback)(()=>{ut.current===null&&(ut.current=requestAnimationFrame(()=>{ut.current=null;let e=G.current;if(!e)return;let t=e.scrollHeight,n=t>lt.current;lt.current=t,!(!n||!$e.current)&&e.scrollTo({top:t,behavior:`instant`})}))},[]);(0,L.useLayoutEffect)(()=>{let e=G.current,t=Ye.current;if(!e||!t)return;let n=()=>{let n=Number.parseFloat(getComputedStyle(e).rowGap)||0,r=0,i=new Set,a=e.querySelectorAll(`[data-msg-id^="live:"], .terminal-group-streaming`);for(let e of a){if(i.has(e))continue;i.add(e),r+=e.getBoundingClientRect().height;let t=e.closest(`.timeline-thread-rootless`)?.previousElementSibling;t?.classList.contains(`timeline-session-divider-activity`)&&(r+=t.getBoundingClientRect().height+n);let a=e.closest(`.timeline-thread-replies`),o=a&&Number.parseFloat(getComputedStyle(a).rowGap)||n;r+=o}t.style.blockSize=`${Math.max(0,Yn-r)}px`};if(n(),typeof ResizeObserver>`u`)return;let r=new ResizeObserver(n);for(let t of e.querySelectorAll(`[data-msg-id^="live:"], .terminal-group-streaming`))r.observe(t);return()=>r.disconnect()},[He,Ke]),(0,L.useEffect)(()=>{let e=G.current;if(!e||!K||tt===K.key)return;let t=null;if(K.kind===`chat`){let n=Date.parse(K.at),r=P.filter(e=>e.sessionId===K.sessionId&&e.role===`user`&&e.content===K.content).sort((e,t)=>Math.abs(Date.parse(e.at)-n)-Math.abs(Date.parse(t.at)-n))[0];if(r){let n=Cn(`msg:${r.sessionId}:${r.at}:${r.role}`);t=e.querySelector(`[data-msg-id="${n}"]`)}}else{let n=[...ve].reverse().find(e=>e.threadId===K.threadId&&e.msgKind===`command`&&(e.content===K.input||e.resolvedFrom===K.input));if(n){let r=Cn(n.messageId);t=e.querySelector(`[data-terminal-message-id="${r}"]`)}}if(!t)return;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=Math.max(0,e.scrollTop+r.top-n.top-12);$e.current=!0,Qe(!0),e.scrollTo({top:i}),nt(K.key)},[P,ve,K,tt]),(0,L.useEffect)(()=>{if(!T||rt.current===T.requestKey)return;let e=G.current;if(!e)return;let t=Cn(T.threadId),n=e.querySelectorAll(`[data-terminal-thread-id="${t}"]`),r=n[n.length-1];r&&(rt.current=T.requestKey,$e.current=!1,Qe(!1),typeof r.scrollIntoView==`function`&&r.scrollIntoView({block:`center`}),r.classList.add(`timeline-focus-flash`),window.setTimeout(()=>r.classList.remove(`timeline-focus-flash`),Xn))},[T,ve]);let Lt=(0,L.useCallback)((e,t)=>{let r=G.current;if(!r)return!1;let i=Cn(e),a=r.querySelector(`[data-session-error="${i}"]`),o=r.querySelectorAll(`[data-session-id="${i}"]`),s=null;if(t?.messageIndex!==void 0){let n=_e.current.filter(t=>t.sessionId===e),i=n[Math.max(0,Math.min(t.messageIndex-1,n.length-1))];i&&(s=r.querySelector(`[data-msg-id="${Cn(`msg:${i.sessionId}:${i.at}:${i.role}`)}"]`))}let c=s??a??o[o.length-1]??null;if(!c)return!1;if($e.current=!1,Qe(!1),typeof c.scrollIntoView==`function`&&c.scrollIntoView({block:`center`}),c.classList.add(`timeline-focus-flash`),window.setTimeout(()=>c.classList.remove(`timeline-focus-flash`),Xn),t?.notifyParent!==!1){let t=_e.current.find(t=>t.sessionId===e);t&&n?.(e,t.gezelId,t.projectId)}return!0},[n]),Rt=(0,L.useRef)(null),[Bt,Vt]=(0,L.useState)(0),Ht=(0,L.useCallback)((e,t)=>{Rt.current={sessionId:e,notifyParent:t?.notifyParent!==!1,...t?.messageIndex===void 0?{}:{messageIndex:t.messageIndex}},Vt(e=>e+1)},[]);(0,L.useEffect)(()=>{let e=Rt.current;if(e){if(Lt(e.sessionId,{notifyParent:e.notifyParent,...e.messageIndex===void 0?{}:{messageIndex:e.messageIndex}})){Rt.current=null;return}if(!(Ee||q.current)){if(!Ce||!B){Rt.current=null;return}q.current=!0,(async()=>{try{let t=await y({limit:Un,before:B});if(Rt.current!==e)return;F(e=>[...t.messages,...e]),we(t.hasMore),Te(t.nextCursor)}catch{Rt.current===e&&(Rt.current=null)}finally{q.current=!1,Vt(e=>e+1)}})()}}},[wt,Bt,Lt,Ee,Ce,B,y]),(0,L.useEffect)(()=>{let e=e=>{let t=e.detail;t?.sessionId&&t.projectId===X&&(X&&le(X),Ht(t.sessionId))};return window.addEventListener(`gezel:focus-session-error`,e),()=>window.removeEventListener(`gezel:focus-session-error`,e)},[X,Ht]);let Ut=(0,L.useRef)(void 0);(0,L.useEffect)(()=>{if(Ut.current!==X&&(Ut.current=X,Rt.current=null),!X)return;let e=le(X);e&&Ht(e.sessionId)},[X,Ht]),(0,L.useEffect)(()=>{E&&at.current!==E.requestKey&&(at.current=E.requestKey,Ht(E.sessionId,{notifyParent:!1,...E.messageIndex===void 0?{}:{messageIndex:E.messageIndex}}))},[E,Ht]);let Wt=(0,L.useCallback)(()=>{let e=G.current;if(!e){ot(e=>e===null?e:null);return}let t=e.getBoundingClientRect(),n=e.parentElement;if(n){let t=e.offsetWidth-e.clientWidth;n.style.setProperty(`--chat-timeline-sb-width`,`${t}px`)}let r=e.parentElement?.querySelector(`.chat-sticky-header`);if(r){let e=r.getBoundingClientRect().height;e>0&&(ct.current=e)}let i=ct.current,a=t.top,o=t.top+i,s=null,c=0,l=null,u=null,d=null,f=e.querySelectorAll(`[data-msg-id]`);for(let e of f){let t=e.dataset.msgId,n=e.dataset.sessionId;if(!t)continue;let r=e.getBoundingClientRect(),i=r.top<a&&r.bottom>o,d=e.classList.contains(`msg-assistant`)||e.classList.contains(`msg-from-gezel`);i&&d&&(s=t,c=r.top,l=n??null,u=r)}if(n&&u){let e=n.getBoundingClientRect(),t=u.left-e.left;n.style.setProperty(`--chat-sticky-left`,`${t}px`),n.style.setProperty(`--chat-sticky-width`,`${u.width}px`)}if(s&&l)for(let e of f){let t=e.dataset.msgId,n=e.dataset.sessionId;!t||n!==l||e.classList.contains(`msg-user`)&&e.getBoundingClientRect().bottom<=c&&(d=t)}let p=s&&d?{userMessageId:d,assistantMessageId:s}:null;ot(e=>e===p||e&&p&&e.userMessageId===p.userMessageId&&e.assistantMessageId===p.assistantMessageId?e:p)},[]),Gt=(0,L.useCallback)(()=>{st.current===null&&(st.current=requestAnimationFrame(()=>{st.current=null,Wt()}))},[Wt]);(0,L.useEffect)(()=>{Gt()},[wt,Gt]),(0,L.useEffect)(()=>{let e=G.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(Gt);return t.observe(e),()=>t.disconnect()},[Gt]),(0,L.useEffect)(()=>()=>{st.current!==null&&(cancelAnimationFrame(st.current),st.current=null),ut.current!==null&&(cancelAnimationFrame(ut.current),ut.current=null),Xe.current!==null&&(window.clearTimeout(Xe.current),Xe.current=null)},[]);let Kt=(0,L.useCallback)(()=>{Gt();let e=G.current;if(!e)return;e.classList.add(`chat-timeline-scrolling`),Xe.current!==null&&window.clearTimeout(Xe.current),Xe.current=window.setTimeout(()=>{G.current?.classList.remove(`chat-timeline-scrolling`),Xe.current=null},Jn);let t=e.scrollHeight-(e.scrollTop+e.clientHeight)<=Kn;if($e.current=t,Qe(e=>e===t?e:t),e.scrollTop<=qn&&Ce&&!Ee&&!q.current&&B){q.current=!0;let t=e.scrollHeight,n=e.scrollTop;(async()=>{try{let e=await y({limit:Un,before:B});F(t=>[...e.messages,...t]),we(e.hasMore),Te(e.nextCursor),requestAnimationFrame(()=>{let e=G.current;e&&e.scrollTo({top:e.scrollHeight-t+n,behavior:`instant`}),q.current=!1,Rt.current&&Vt(e=>e+1)})}catch{q.current=!1,Rt.current&&Vt(e=>e+1)}})()}},[Ce,Ee,B,y,Gt]),qt=(0,L.useCallback)(()=>{Qe(e=>{let t=!e;if($e.current=t,t){let e=G.current;e&&e.scrollTo({top:e.scrollHeight,behavior:`instant`})}return t})},[]),Jt=(0,L.useMemo)(()=>{if(!J)return null;let e=P.find(e=>`msg:${e.sessionId}:${e.at}:${e.role}`===J.userMessageId);if(!e)return null;let t=null;if(J.assistantMessageId.startsWith(`live:`)){let e=J.assistantMessageId.slice(5);W.current.has(e)&&(t={kind:`live`,sessionId:e})}else{let e=P.find(e=>`msg:${e.sessionId}:${e.at}:${e.role}`===J.assistantMessageId);e&&(t={kind:`message`,msg:e})}return t?{userMsg:e,assistantInfo:t}:null},[J,P,He]),Xt=At.slice(0,Qn),Zt=At.length-Xt.length,Qt=(0,R.jsxs)(R.Fragment,{children:[Xt.map(e=>(0,R.jsx)(zt,{task:e.task,wait:e.wait,gezel:H.get(e.wait.gezelId),onTaskReference:e=>window.dispatchEvent(new CustomEvent(`gezel:open-tab`,{detail:{kind:`task`,ref:e}}))},`queued-task:${e.task.ref}`)),Zt>0&&(0,R.jsxs)(`p`,{className:`msg-queued-task-overflow muted small`,children:[`+ `,Zt,` more task`,Zt===1?``:`s`,` waiting in the queue.`]})]}),$t=(e,t)=>{Ae(n=>{let r=new Map(n);return t?r.set(e,t):r.delete(e),r})},en=async(e,t)=>{$t(e,{busy:`acknowledge`});let n=new AbortController,r=window.setTimeout(()=>n.abort(),$n);try{await _.clearProjectErrors(t,n.signal),window.dispatchEvent(new CustomEvent(`gezel:session-error-cleared`,{detail:{projectId:t}}))}catch{$t(e,{error:n.signal.aborted?`Clearing the alert took too long. Check the connection and try again.`:`Could not clear the alert. Check the connection and try again.`})}finally{window.clearTimeout(r)}},nn=async e=>{$t(e,{busy:`retry`});try{await _.retryChatSessionTurn(e)}catch{$t(e,{error:`Retry could not start. Check the connection or settings, then try again.`})}},rn=(e,t,n,r,i)=>{let a=ke.get(e),o=a?.busy;return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`timeline-session-error-actions`,"aria-label":`Failed turn actions`,children:[kn(t,n)&&(0,R.jsx)(`button`,{type:`button`,className:`timeline-session-error-action timeline-session-error-action-primary`,disabled:o!==void 0,onClick:()=>void nn(e),children:o===`retry`?`Retrying…`:`Retry`}),Dn(t)&&(0,R.jsx)(`button`,{type:`button`,className:`timeline-session-error-action secondary`,disabled:o!==void 0,onClick:()=>window.dispatchEvent(new CustomEvent(`gezel:navigate`,{detail:{view:`settings`,section:`defaults`}})),children:`Open Settings`}),r&&(0,R.jsx)(`button`,{type:`button`,className:`timeline-session-error-action secondary`,title:`Clear this project's failed-turn alerts without rerunning the work`,disabled:o!==void 0,onClick:()=>void en(e,r),children:o===`acknowledge`?`Acknowledging…`:`Acknowledge`}),!h(t)&&!On(n)&&(0,R.jsx)(se,{className:`timeline-session-error-link`,report:{surface:i,message:t,detail:n}})]}),a?.error&&(0,R.jsx)(`p`,{className:`timeline-session-error-action-error`,role:`alert`,children:a.error})]})};if(Ee&&P.length===0)return(0,R.jsx)(`div`,{className:`chat-timeline chat-timeline-loading`,children:(0,R.jsx)(`p`,{className:`muted small`,children:`Loading…`})});if(De)return(0,R.jsx)(`div`,{className:`chat-timeline chat-timeline-error`,children:(0,R.jsx)(`p`,{className:`error`,children:De})});if(wt.length===0)return(0,R.jsxs)(`div`,{className:`chat-timeline`,ref:G,"data-testid":`chat-timeline`,children:[v??(g?(0,R.jsx)(`p`,{className:`placeholder`,children:g}):null),Qt]});let an=null,sn=null,cn,ln=null,dn=new Set,fn=new Map,mn=new Set;for(let e of P)e.pendingQuestionId&&mn.add(e.pendingQuestionId);let gn=new Map;for(let e of Le.values()){if(mn.has(e.id))continue;let t=gn.get(e.sessionId);(!t||e.createdAt>t.createdAt)&&gn.set(e.sessionId,e)}let vn=new Map;for(let e of P){if(e.role!==`assistant`||e.pendingQuestionId||!er(e))continue;let t=`${e.sessionId}\u0000${e.at}\u0000${e.role}`,n=vn.get(e.sessionId);(!n||e.at>n.at)&&vn.set(e.sessionId,{key:t,at:e.at})}let An=new Map,In=new Map;for(let[e,t]of gn){let n=vn.get(e);n?An.set(n.key,t):t.answer||In.set(e,t)}let Rn=[],Bn=(e,t,n,r)=>{Rn.push((0,R.jsxs)(`div`,{className:`timeline-session-error-banner`,"data-session-error":e,role:`alert`,children:[(0,R.jsxs)(`div`,{className:`timeline-session-error-body`,children:[(0,R.jsx)(`span`,{"aria-hidden":`true`,children:`✗`}),(0,R.jsxs)(`span`,{children:[(0,R.jsx)(`strong`,{children:`Last turn failed.`}),` `,t]})]}),rn(e,t,n,r,`session-error`)]},`session-error:${e}`))},nr=e=>{d?d(e,{focus:!0}):window.dispatchEvent(new CustomEvent(`gezel:open-tab`,{detail:{kind:`task`,ref:e}}))},rr=(e,n)=>{let r=H.get(e.gezelId),i=e.sessionId===t,o=Mn(e.sessionLastActivityAt,on),l=!i&&!o,d=D&&e.projectId!=="default"?Fe.get(e.projectId):void 0,p=e.from?e.from.gezelId:e.gezelId,h=H.get(p)?.font,g=m(h),_=f(h),v=jn(e),y=(e.pendingQuestionId?Le.get(e.pendingQuestionId):void 0)??An.get(`${e.sessionId}\u0000${e.at}\u0000${e.role}`);return(0,R.jsx)(ae,{dataMsgId:`msg:${e.sessionId}:${e.at}:${e.role}`,dataSessionId:e.sessionId,debugMode:pt,sessionId:e.sessionId,messageAt:e.at,role:e.role,content:e.content,authorLabel:r?s({name:r.name,roleBasedName:r.roleBasedName},ie):`Gezel`,authorIcon:r?.icon??null,...r?.poppetje?{authorPoppetje:r.poppetje}:{},...r?.iconOverride?{authorIconOverride:!0}:{},authorTooltip:_t(e.gezelId),...(()=>{let t=vt(e.sessionProviderName,e.sessionModel);return t?{driftLabel:t}:{}})(),...!ie&&r?.role?{authorRole:r.role}:{},...e.from?{from:e.from}:{},...e.nudge?{nudge:!0}:{},...e.origin===`system`?{origin:`system`}:{},receiverLabel:r?s({name:r.name,roleBasedName:r.roleBasedName},ie):`Gezel`,...g?{fontFamily:g}:{},..._===1?{}:{fontScale:_},...d?{projectLabel:d.name}:{},extraClass:l?`timeline-msg-faded`:void 0,mediaProvider:Je(e.projectId,e.sessionId),...v.length>0?{referencedFiles:v}:{},...e.retrieval&&e.retrieval.hits.length>0?{retrieval:e.retrieval}:{},...e.referencedTasks?{referencedTasks:e.referencedTasks}:{},...e.toolCalls&&e.toolCalls.length>0?{toolCalls:e.toolCalls,projectId:e.projectId}:{},...u?{onOpenReference:u}:{},...e.reasoning?{reasoning:e.reasoning}:{},...e.reasoningDurationMs===void 0?{}:{reasoningDurationMs:e.reasoningDurationMs},...e.attemptedToolCalls&&e.attemptedToolCalls.length>0?{attemptedToolCalls:e.attemptedToolCalls}:{},...n?.recoveredInNextTurn?{recoveredInNextTurn:!0}:{},...n?.suppressHeader?{suppressHeader:!0}:{},...n?.timestampLabel?{timestampLabel:n.timestampLabel}:{},...e.intents&&e.intents.length>0?{intents:e.intents}:{},...e.warnings&&e.warnings.length>0?{warnings:e.warnings}:{},...e.synthetic?{synthetic:e.synthetic}:{},...e.contextCompaction?{contextCompaction:e.contextCompaction}:{},...y?{question:y,onQuestionAnswered:e=>Re(t=>{let n=new Map(t);return n.set(e.id,e),n})}:{},...a||c?{onFileReference:t=>{t.kind===`workspace`?c?.(t.path,e.projectId):a?.(t.path,e.projectId)}}:{},onTaskReference:e=>window.dispatchEvent(new CustomEvent(`gezel:open-tab`,{detail:{kind:`task`,ref:e}})),onFocusTask:nr},`msg:${e.sessionId}:${e.at}:${e.role}`)},ir=(e,t)=>{let n=[],r=H.get(t.gezelId),i=m(r?.font),a=f(r?.font);n.push((0,R.jsx)(k,{dataMsgId:`live:${e}`,dataSessionId:e,authorLabel:r?s({name:r.name,roleBasedName:r.roleBasedName},ie):`Gezel`,authorIcon:r?.icon??null,...r?.poppetje?{authorPoppetje:r.poppetje}:{},...r?.iconOverride?{authorIconOverride:!0}:{},authorTooltip:_t(t.gezelId),...(()=>{if(!t.sessionProviderName)return{};let e=vt(t.sessionProviderName,t.sessionModel);return e?{driftLabel:e}:{}})(),...!ie&&r?.role?{authorRole:r.role}:{},segments:t.segments,...u?{onOpenReference:u}:{},onFocusTask:nr,startedAt:t.startedAt,lastActivityAt:t.lastActivityAt,hasProgress:t.hasProgress,...gt(t.gezelId)===`ollama`?{onProbeOllama:()=>_.ollamaProbe()}:{},...gt(t.gezelId)===`ollama`?{localEngine:`ollama`}:gt(t.gezelId)===`llama-cpp`?{localEngine:`llama-cpp`}:gt(t.gezelId)===`ds4`?{localEngine:`ds4`}:{},...t.sessionSource||e.startsWith(`one-shot:`)?{}:{onCancel:async()=>{try{await _.cancelChatSessionTurn(e)}catch(e){console.warn(`[timeline] failed to cancel turn:`,e)}},onReEngage:async()=>{try{await _.cancelChatSessionTurn(e)}catch(e){console.warn(`[timeline] re-engage: cancel failed:`,e)}try{await _.sendToChatSession(e,{message:`Please continue where you left off and finish the work you started.`})}catch(e){console.warn(`[timeline] re-engage: send failed:`,e)}}},...i?{fontFamily:i}:{},...a===1?{}:{fontScale:a},...t.error?{error:t.error}:{},...t.errorDetail?{errorDetail:t.errorDetail}:{},...t.error?{errorActions:rn(e,t.error,t.errorDetail,t.projectId,`chat-turn`)}:{},...t.queueAhead===void 0?{}:{queueAhead:t.queueAhead},...t.queuedAt===void 0?{}:{queuedAt:t.queuedAt},...t.wirePulseCount&&t.wirePulseCount>0?{wirePulseCount:t.wirePulseCount}:{},...oe(t)?{thinkingLabel:oe(t)}:{},...t.thinkingProgress===void 0?{}:{thinkingProgress:t.thinkingProgress},...t.thinkingDetail?{thinkingDetail:t.thinkingDetail}:{},...t.liveToolArgs?{liveToolArgs:t.liveToolArgs}:{},...t.gpuSwapTask?{gpuSwapTask:t.gpuSwapTask}:{},...t.gpuSwapDetail?{gpuSwapDetail:t.gpuSwapDetail}:{},...t.gpuSwapPrompt?{gpuSwapPrompt:t.gpuSwapPrompt}:{},...t.gpuSwapProgress===void 0?{}:{gpuSwapProgress:t.gpuSwapProgress},...t.gpuSwapStep===void 0?{}:{gpuSwapStep:t.gpuSwapStep},...t.gpuSwapTotalSteps===void 0?{}:{gpuSwapTotalSteps:t.gpuSwapTotalSteps},...t.gpuSwapSecondsPerStep===void 0?{}:{gpuSwapSecondsPerStep:t.gpuSwapSecondsPerStep},...t.awaitingGezelName?{awaitingGezelName:t.awaitingGezelName}:{},...t.warnings&&t.warnings.length>0?{warnings:t.warnings}:{},...In.get(e)?{question:In.get(e),onQuestionAnswered:e=>Re(t=>{let n=new Map(t);return n.set(e.id,e),n})}:{},debugMode:pt,sessionId:e},`live:${e}`));let o=qe.current.get(e);if(o&&o.length>0)for(let r of o)n.push((0,R.jsx)(pe,{sessionId:e,queueId:r.id,preview:r.preview,enqueuedAt:r.enqueuedAt,mediaProvider:Je(t.projectId,e),...r.nudge?{nudge:!0}:{},onDiscard:async()=>{try{await _.cancelQueuedMessage(e,r.id)}catch(e){console.warn(`[timeline] failed to discard queued message:`,e)}},onCancelCurrent:async()=>{try{await _.cancelChatSessionTurn(e)}catch(e){console.warn(`[timeline] failed to cancel current turn:`,e)}},onLoadText:async()=>{try{return(await _.listSessionQueue(e)).entries.find(e=>e.queueId===r.id)?.text??null}catch{return null}},onSaveEdit:async t=>{try{return await _.updateQueuedMessage(e,r.id,{message:t}),!0}catch(e){if(/not found/i.test(e.message??``))return!1;throw e}}},`ghost:${r.id}`));return n};for(let e of Et){if(e.kind===`indexing`){Rn.push((0,R.jsx)(It,{receipt:e.entry,gezels:H,projects:Fe,showProjectName:D,roleBasedNameOnlyMode:ie,...c?{onOpenWorkspaceFile:c}:{}},e.entry.id));continue}if(e.kind===`terminal`){let t=e.entry,n=fn.get(t.threadId),r=!n,i=n?Math.max(0,new Date(t.at).getTime()-new Date(n.at).getTime()):0;(r||i>Zn)&&Rn.push(Sn({entry:t,key:`terminal-divider:${t.threadId}:${t.messageId}`})),Rn.push((0,R.jsx)(Yt,{entry:t,...c?{onOpenWorkspaceFile:e=>c(e,t.projectId)}:{}},`terminal:${t.threadId}:${t.messageId}`)),fn.set(t.threadId,t);continue}if(e.kind===`terminal-streaming`){let t=e.slot.projectId,n=e.runId;Rn.push((0,R.jsx)(Pn,{store:We,itemKey:n,onRendered:jt,render:e=>(0,R.jsx)(tn,{content:e.content,cwd:e.cwd,startedAt:e.startedAt,...e.awaitingInput?{awaitingInput:e.awaitingInput}:{},onCancel:()=>{_.cancelTerminalRun(t,n).catch(()=>{})},onSendInput:e=>{let r=Ge.current.get(n);r&&(delete r.awaitingInput,We.markItemChanged(n)),_.sendTerminalInput(t,n,e).catch(e=>{console.warn(`[ChatTimelineView] sendTerminalInput failed`,e)})}})},`terminal-streaming:${n}`));continue}let r=e.sessionId,i=Dt.get(r)??0,a=kt.get(r),o=e.root??e.replies[0];if(!o)continue;if(r!==an){an&&sn&&!W.current.has(an)&&Bn(an,sn,cn,ln);let s=dn.has(r);Rn.push(xn({row:o,gezels:H,projects:Fe,showProjectName:D,activeSessionId:t,onFocusSession:n,continuing:s,depth:i,...a?{treeBranch:a}:{},key:`divider:${r}:${e.at}`,roleBasedNameOnlyMode:ie})),dn.add(r),an=r,sn=null,cn=void 0,ln=null}let s=e.root??e.replies.find(e=>e.kind===`message`);s&&s.kind===`message`&&s.msg.sessionLastTurnError&&!je.has(s.msg.projectId)&&(sn=s.msg.sessionLastTurnError,cn=s.msg.sessionLastTurnErrorDetail,ln=s.msg.projectId);let l=[];if(e.root&&l.push(rr(e.root.msg,{timestampLabel:x(e.root.at)})),e.replies.length>0){let t=[];for(let n=0;n<e.replies.length;n++){let r=e.replies[n];if(r.kind===`streaming`){t.push((0,R.jsx)(Pn,{store:U,itemKey:r.sessionId,onRendered:jt,render:e=>ir(r.sessionId,e)},`live-slot:${r.sessionId}`));continue}let i=r.msg,a=n>0?e.replies[n-1]:void 0,o=a?a.at:e.root?.at,s=(o?Math.max(0,Date.parse(i.at)-Date.parse(o)):0)>Gn,c=a?.kind===`message`&&a.msg.gezelId===i.gezelId,l=e.replies[n+1],u=i.role===`assistant`&&i.content.trim().length===0&&!!i.toolCalls&&i.toolCalls.length>0&&l!==void 0&&l.kind===`message`&&l.msg.sessionId===i.sessionId&&l.msg.role===`assistant`&&l.msg.content.trim().length>0;t.push(rr(i,{...c&&!s?{suppressHeader:!0}:{},...s?{timestampLabel:x(i.at)}:{},...u?{recoveredInNextTurn:!0}:{}}))}l.push((0,R.jsx)(`div`,{className:`timeline-thread-replies`,children:t},`replies`))}let u=a?.hasChildren===!0||i===0&&e.replies.length>0&&(!e.root||!e.root.msg.from);Rn.push((0,R.jsxs)(`div`,{className:`timeline-thread${i>0?` timeline-session-subthread timeline-session-depth-${Math.min(i,4)}`:``}${a?.hasChildren?` timeline-session-parent`:``}${e.root?``:` timeline-thread-rootless`}${u?` timeline-thread-railed`:``}`,children:[i>0&&a&&(0,R.jsx)(bn,{branch:a,phase:`thread`}),l]},`thread:${r}:${e.at}`))}return an&&sn&&!W.current.has(an)&&Bn(an,sn,cn,ln),(0,R.jsxs)(`div`,{className:`chat-timeline-viewport`,children:[Jt&&(Jt.assistantInfo.kind===`live`?(0,R.jsx)(Fn,{store:U,sessionId:Jt.assistantInfo.sessionId,userMsg:Jt.userMsg,gezels:H}):(0,R.jsx)(Ot,{payload:{userMsg:Jt.userMsg,assistantInfo:{kind:`message`,msg:Jt.assistantInfo.msg}},gezels:H})),(0,R.jsxs)(`div`,{className:`chat-timeline`,ref:G,onScroll:Kt,"data-testid":`chat-timeline`,children:[Ce&&(0,R.jsx)(`div`,{className:`timeline-loading-pill muted small`,children:q.current?`Loading older messages…`:`Scroll up for older messages`}),Rn.length===0?v??(g?(0,R.jsx)(`p`,{className:`placeholder`,children:g}):null):Rn,Qt,(0,R.jsx)(`div`,{ref:Ye,className:`timeline-response-runway`,"aria-hidden":`true`})]}),!Ze&&(0,R.jsx)(`button`,{type:`button`,className:`chat-timeline-pin-toggle`,onClick:qt,title:`Jump to newest and follow`,"aria-label":`Jump to newest and follow`,children:(0,R.jsxs)(`svg`,{className:`chat-timeline-pin-glyph`,width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,role:`img`,"aria-hidden":!0,children:[(0,R.jsx)(`title`,{children:`Jump to newest`}),(0,R.jsx)(`line`,{x1:`12`,y1:`4`,x2:`12`,y2:`15`}),(0,R.jsx)(`polyline`,{points:`6 10 12 16 18 10`}),(0,R.jsx)(`line`,{x1:`5`,y1:`20`,x2:`19`,y2:`20`})]})})]})}export{Z as a,vt as i,sn as n,ut as o,wt as r,nr as t};
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{B as r,F as i,I as a,L as o,N as s,P as c,R as l,V as u,z as d}from"./primitives-CWrGZpPI.js";var f=e(t(),1),p=n();function m({open:e,title:t,message:n,confirmLabel:m=`Confirm`,cancelLabel:h=`Cancel`,danger:g=!1,onConfirm:_,onCancel:v}){let[y,b]=(0,f.useState)(!1),x=async()=>{if(!y){b(!0);try{await _()}finally{b(!1)}}};return(0,p.jsx)(r,{open:e,onOpenChange:e=>{!e&&!y&&v()},children:(0,p.jsxs)(d,{children:[(0,p.jsx)(l,{}),(0,p.jsxs)(a,{children:[(0,p.jsx)(u,{asChild:!0,children:(0,p.jsx)(`h3`,{children:t})}),n&&(0,p.jsx)(o,{className:`muted small`,children:n}),(0,p.jsxs)(c,{children:[(0,p.jsx)(i,{asChild:!0,children:(0,p.jsx)(`button`,{type:`button`,disabled:y,children:h})}),(0,p.jsx)(s,{asChild:!0,children:(0,p.jsx)(`button`,{type:`button`,className:g?`danger`:`primary`,onClick:e=>{e.preventDefault(),x()},disabled:y,children:y?`Working…`:m})})]})]})]})})}export{m as t};
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{t as r}from"./api-BPraLwsh.js";import{c as i,d as a,f as o,l as s,m as c,p as l,s as u,u as d}from"./primitives-CWrGZpPI.js";import{n as f,t as p}from"./relative-time-B2kBaekd.js";import{t as m}from"./ConfirmDialog-Dt1ed4Fh.js";import{At as h,Ot as g,kt as _}from"./index-C0DYtvfg.js";import"./provider-default-BLsHrgzI.js";var v=e(t(),1);function y(e){let t=(0,v.useRef)(null),[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(null),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(!1),g=(0,v.useRef)(e);g.current=e;let _=(0,v.useCallback)(e=>{r(e);let t=g.current.backupNotice?.(e);t&&l(t),a(t=>{let n=new Set(e.models.map(e=>e.id));return t&&n.has(t)?t:e.configuredModel&&n.has(e.configuredModel)?e.configuredModel:e.recommendedModel&&n.has(e.recommendedModel)?e.recommendedModel:e.models[0]?.id??``})},[]),y=(0,v.useCallback)(async()=>{s(null);try{_(await g.current.fetchStatus())}catch(e){s(`Could not check the ${g.current.label} setup — ${S(e)}`)}},[_]);(0,v.useEffect)(()=>(y(),()=>{t.current!==null&&window.clearTimeout(t.current)}),[y]);let b=window.__GEZEL__?.mode,x=b===`local-adopt`||b===`local-spawn-packaged`||b===`local-spawn-dev`||b===`embedded`,C=b===`remote`,w=n?.state===`configured`||n?.state===`update-needed`,T=n?.state===`configured`&&n.bridge.listening&&e.endpointsEnabled&&x,E=e.modelSelection!==!1,D=E&&w&&i!==n?.configuredModel,O=n?.state===`conflict`&&n.canRepair,k=n?.state===`not-configured`||n?.state===`update-needed`||D||O,A=n?.state===`conflict`?n.canRepair:n?.canConfigure??!1,j=f||!x||!e.endpointsEnabled||!A||E&&!i,M=f||!x||!e.endpointsEnabled||!A;return{status:n,model:i,setModel:a,error:o,setError:s,notice:c,confirmation:u,setConfirmation:d,busy:f,copied:m,refresh:y,runConfirmedAction:(0,v.useCallback)(async()=>{if(!(!u||f)){p(!0),s(null),l(null);try{_(await g.current.runAction(u,i)),d(null),Promise.resolve(g.current.onChanged?.()).catch(()=>{})}catch(e){d(null),s(`${g.current.errorPrefix(u,n?.state)} — ${S(e)}`)}finally{p(!1)}}},[_,f,u,i,n?.state]),copyLaunchCommand:(0,v.useCallback)(async()=>{if(n?.launchCommand){s(null);try{if(!navigator.clipboard?.writeText)throw Error(`clipboard access is unavailable`);await navigator.clipboard.writeText(n.launchCommand),h(!0),t.current!==null&&window.clearTimeout(t.current),t.current=window.setTimeout(()=>{t.current=null,h(!1)},2e3)}catch(e){s(`Could not copy the ${g.current.label} command — ${S(e)}`)}}},[n?.launchCommand]),localDesktopMode:x,remoteMode:C,configured:w,canLaunch:T,modelChanged:D,repairable:O,needsConfigure:k,configureDisabled:j,selectionDisabled:M}}function b(e){switch(e){case`not-configured`:return`Not configured`;case`configured`:return`Configured`;case`update-needed`:return`Update needed`;case`conflict`:return`Needs attention`;case`unavailable`:return`Unavailable`}}function x(e){return e.kind===`gezel`||e.id.startsWith(`gezel:`)}function S(e){if(e&&typeof e==`object`&&`details`in e){let t=e.details;if(typeof t==`string`&&t)return t;if(t&&typeof t==`object`){let e=t;if(typeof e.message==`string`&&e.message)return e.message;if(typeof e.error==`string`&&e.error)return e.error}}return e instanceof Error?e.message:String(e)}var C=n();function w({headingId:e,title:t,status:n,intro:r,notInstalledNote:f,repairExplainer:p,notice:m,reasonsIntro:h,configuredNote:g,commandRow:_,modelRow:y,extraRows:S,actions:w,error:E,emptyModelsNote:D,remoteMode:O,localDesktopMode:k,endpointsEnabled:A,repairable:j,children:M}){let N=(0,v.useId)(),P=n?b(n.state):`Checking…`,F=n?.models.filter(x)??[],I=n?.models.filter(e=>!x(e))??[];return(0,C.jsxs)(`section`,{className:`settings-subsection provider-card harness-setup-card`,"aria-labelledby":e,children:[(0,C.jsxs)(`div`,{className:`settings-card-header`,children:[(0,C.jsx)(`h3`,{id:e,children:t}),(0,C.jsx)(`span`,{className:`harness-setup-state harness-setup-state--${n?.state??`checking`}`,"aria-live":`polite`,children:P})]}),(0,C.jsx)(`p`,{className:`muted small harness-setup-intro`,children:r}),!n&&!E&&(0,C.jsx)(`p`,{className:`muted small`,children:`Checking the setup…`}),n&&(0,C.jsxs)(C.Fragment,{children:[n.message&&(0,C.jsx)(`p`,{className:n.state===`conflict`||n.state===`unavailable`?`harness-setup-caution small`:`muted small`,children:n.message}),j&&p&&(0,C.jsx)(`p`,{className:`muted small`,children:p}),m&&(0,C.jsx)(`p`,{className:`muted small`,children:m}),f&&n.state!==`unavailable`&&(0,C.jsx)(`p`,{className:`muted small`,children:f}),O&&(0,C.jsx)(`p`,{className:`harness-setup-caution small`,children:`One-click setup is unavailable while this app is connected to a remote Gezel service. Set it up on the computer where you plan to run it.`}),!O&&!k&&(0,C.jsx)(`p`,{className:`harness-setup-caution small`,children:`One-click setup is available in the Gezel desktop app when it is connected to your user service on this computer.`}),!A&&(0,C.jsxs)(`p`,{className:`harness-setup-caution small`,children:[`Turn on `,(0,C.jsx)(`strong`,{children:`Allow apps to connect`}),` above before setting up or updating this.`]}),n.state===`update-needed`&&n.reasons.length>0&&(0,C.jsxs)(`div`,{className:`harness-setup-reasons`,children:[(0,C.jsx)(`span`,{className:`small`,children:h}),(0,C.jsx)(`ul`,{className:`muted small`,children:n.reasons.map(e=>(0,C.jsx)(`li`,{children:e},e))})]}),g&&(0,C.jsx)(`p`,{className:`muted small`,children:g}),_,y&&n.models.length>0&&(n.state!==`conflict`||j)&&(0,C.jsxs)(`div`,{className:`harness-setup-model-row`,children:[(0,C.jsx)(`span`,{id:N,children:y.label}),(0,C.jsxs)(a,{value:y.value,onValueChange:y.onChange,disabled:y.disabled,children:[(0,C.jsx)(l,{"aria-labelledby":N,children:(0,C.jsx)(c,{})}),(0,C.jsxs)(u,{children:[F.length>0&&(0,C.jsxs)(i,{children:[(0,C.jsx)(d,{children:`Gezels`}),F.map(e=>(0,C.jsx)(s,{value:e.id,children:T(e)},e.id))]}),F.length>0&&I.length>0&&(0,C.jsx)(o,{}),I.length>0&&(0,C.jsxs)(i,{children:[(0,C.jsx)(d,{children:`Raw models`}),I.map(e=>(0,C.jsx)(s,{value:e.id,children:T(e)},e.id))]})]})]})]}),n.models.length===0&&n.state!==`conflict`&&(0,C.jsx)(`p`,{className:`harness-setup-caution small`,children:D}),S,(0,C.jsx)(`div`,{className:`harness-setup-actions`,children:w})]}),E&&(0,C.jsx)(`p`,{className:`error small harness-setup-error`,role:`alert`,children:E}),M]})}function T(e){return e.description?`${e.label} — ${e.description}`:e.label}function E({endpointsEnabled:e,onChanged:t}){let n=y({label:`Codex`,endpointsEnabled:e,fetchStatus:()=>r.getCodexSetupStatus(),runAction:(0,v.useCallback)((e,t)=>e===`remove`?r.removeCodexSetup():r.configureCodex({model:t,...e===`repair`?{backupConflictingProfile:!0}:{}}),[]),errorPrefix:D,backupNotice:e=>e.profileBackupPath?`The previous file was saved as ${e.profileBackupPath}.`:null,...t?{onChanged:t}:{}}),{status:i,confirmation:a,setConfirmation:o,setError:s,busy:c,copied:l}=n,u=i?.models.find(e=>e.id===n.model),d=i?.models.find(e=>e.id===i.configuredModel),f=n.repairable?`Repair Codex setup…`:i?.state===`not-configured`?`Set up Codex…`:`Update Codex…`;return(0,C.jsxs)(w,{headingId:`codex-setup-heading`,title:`Use Gezel in Codex`,status:i,remoteMode:n.remoteMode,localDesktopMode:n.localDesktopMode,endpointsEnabled:e,repairable:!!n.repairable,notice:n.notice,error:n.error,reasonsIntro:`The managed setup needs an update:`,emptyModelsNote:`No gezels or inference models compatible with the Codex tool loop are available yet.`,intro:(0,C.jsx)(C.Fragment,{children:`Codex keeps its coding tools, sandbox, approvals, and conversation loop while a gezel supplies the character, model, and tuning. Your whole eligible crew is offered to Codex — the gezel you pick here is the one it starts with, and you can switch to any other from Codex's own model picker. Raw local models remain available when you want inference without a gezel persona.`}),...i?{repairExplainer:(0,C.jsxs)(C.Fragment,{children:[`Repair writes a fresh `,(0,C.jsx)(`code`,{children:i.profileName}),` profile for this Gezel and keeps a copy of the existing file next to it.`]})}:{},...i&&!i.codexInstalled?{notInstalledNote:`Codex was not found on this computer. You can prepare the setup now and use it after installing Codex.`}:{},...n.configured&&d&&!n.modelChanged?{configuredNote:(0,C.jsxs)(C.Fragment,{children:[`Codex starts with `,(0,C.jsx)(`strong`,{children:d.label}),`.`,i?.codexVersion?` Codex ${i.codexVersion} was found.`:``]})}:{},...n.canLaunch&&i?{commandRow:(0,C.jsxs)(`div`,{className:`harness-setup-command-row`,children:[(0,C.jsx)(`span`,{className:`muted small`,children:`Start it with`}),(0,C.jsx)(`code`,{children:i.launchCommand}),(0,C.jsx)(`button`,{type:`button`,onClick:()=>void n.copyLaunchCommand(),children:l?`Copied`:`Copy command`}),(0,C.jsx)(`output`,{className:`sr-only`,"aria-live":`polite`,children:l?`Codex launch command copied.`:``}),(0,C.jsx)(`span`,{className:`muted small`,children:`Keep Gezel running while you use Codex.`})]})}:{},modelRow:{label:`Default gezel`,value:n.model,onChange:n.setModel,disabled:n.selectionDisabled},actions:(0,C.jsxs)(C.Fragment,{children:[n.needsConfigure&&(0,C.jsx)(`button`,{type:`button`,className:`primary`,disabled:n.configureDisabled,onClick:()=>{s(null),o(n.repairable?`repair`:`configure`)},children:f}),i?.canRemove&&(0,C.jsx)(`button`,{type:`button`,disabled:c||!n.localDesktopMode,onClick:()=>{s(null),o(`remove`)},children:i.state===`conflict`?`Clear Gezel setup…`:`Remove setup…`}),n.error&&(0,C.jsx)(`button`,{type:`button`,onClick:()=>void n.refresh(),disabled:c,children:`Try again`})]}),children:[(0,C.jsx)(m,{open:a===`configure`,title:i?.state===`not-configured`?`Set up Codex with Gezel?`:`Update Codex setup?`,message:(0,C.jsxs)(C.Fragment,{children:[`Gezel will `,i?.state===`not-configured`?`create`:`update`,` its managed Codex profile for `,(0,C.jsx)(`strong`,{children:u?.label??n.model}),`.`,` `,u&&x(u)?(0,C.jsxs)(C.Fragment,{children:[`This gezel's character, `,u.modelLabel??`model`,`, and tuning will guide Codex.`,` `]}):(0,C.jsx)(C.Fragment,{children:`Codex will use it as a raw inference model without a gezel persona. `}),`The profile includes the local connection and app-scoped credential`,i?.profilePath?(0,C.jsxs)(C.Fragment,{children:[` `,`at `,(0,C.jsx)(`code`,{children:i.profilePath})]}):null,`. Your other Codex settings and conversations stay untouched.`]}),confirmLabel:i?.state===`not-configured`?`Set up Codex`:`Update Codex`,onConfirm:n.runConfirmedAction,onCancel:()=>o(null)}),(0,C.jsx)(m,{open:a===`repair`,title:`Repair the Codex setup?`,message:(0,C.jsxs)(C.Fragment,{children:[`Gezel will write a working `,(0,C.jsx)(`code`,{children:i?.profileName}),` profile for`,` `,(0,C.jsx)(`strong`,{children:u?.label??n.model}),`, connected to this copy of Gezel.`,i?.profilePath?(0,C.jsxs)(C.Fragment,{children:[` `,`The file now at `,(0,C.jsx)(`code`,{children:i.profilePath}),` is kept as a `,(0,C.jsx)(`code`,{children:`.backup`}),` `,`copy beside it, so nothing is lost.`]}):(0,C.jsx)(C.Fragment,{children:` The file it replaces is kept as a .backup copy beside it, so nothing is lost.`}),` `,`Your other Codex settings and conversations stay untouched.`]}),confirmLabel:`Repair setup`,onConfirm:n.runConfirmedAction,onCancel:()=>o(null)}),(0,C.jsx)(m,{open:a===`remove`,title:i?.state===`conflict`?`Clear Gezel setup for Codex?`:`Remove Gezel setup from Codex?`,message:(0,C.jsxs)(C.Fragment,{children:[`This removes only Gezel's managed Codex profile, catalog, state, and credential. It does not uninstall Codex or delete your other settings and conversations.`,i?.state===`conflict`?` Any Codex profile not managed by Gezel will be preserved.`:``]}),confirmLabel:i?.state===`conflict`?`Clear Gezel setup`:`Remove setup`,danger:!0,onConfirm:n.runConfirmedAction,onCancel:()=>o(null)})]})}function D(e,t){switch(e){case`remove`:return`Could not remove the Codex setup`;case`repair`:return`Could not repair the Codex setup`;default:return t===`not-configured`?`Could not set up the Codex setup`:`Could not update the Codex setup`}}function O({endpointsEnabled:e,onChanged:t}){let n=y({label:`OpenCode`,endpointsEnabled:e,fetchStatus:()=>r.getOpenCodeSetupStatus(),runAction:(0,v.useCallback)((e,t)=>{switch(e){case`remove`:return r.removeOpenCodeSetup();case`install-plugin`:return r.installOpenCodePlugin();case`replace-plugin`:return r.installOpenCodePlugin({backupConflictingPlugin:!0});case`remove-plugin`:return r.removeOpenCodePlugin();default:return r.configureOpenCode({model:t,...e===`repair`?{backupConflictingConfig:!0}:{}})}},[]),errorPrefix:k,backupNotice:e=>e.pluginBackupPath?`The previous plugin file was saved as ${e.pluginBackupPath}.`:e.configBackupPath?`The previous file was saved as ${e.configBackupPath}.`:null,...t?{onChanged:t}:{}}),{status:i,confirmation:a,setConfirmation:o,setError:s,busy:c,copied:l}=n,u=i?.models.find(e=>e.id===n.model),d=i?.models.find(e=>e.id===i.configuredModel),f=n.configured&&n.localDesktopMode&&i?.state!==`conflict`&&i?.plugin.state!==`unsupported`,p=n.repairable?`Repair OpenCode setup…`:i?.state===`not-configured`?`Set up OpenCode…`:`Update OpenCode…`;return(0,C.jsxs)(w,{headingId:`opencode-setup-heading`,title:`Use Gezel in OpenCode`,status:i,remoteMode:n.remoteMode,localDesktopMode:n.localDesktopMode,endpointsEnabled:e,repairable:!!n.repairable,notice:n.notice,error:n.error,reasonsIntro:`The managed setup needs an update:`,emptyModelsNote:`No gezels or inference models compatible with the OpenCode tool loop are available yet.`,intro:(0,C.jsx)(C.Fragment,{children:`OpenCode keeps its own tools, permissions, and conversation loop while a gezel supplies the character, model, and tuning. Gezel writes its own settings file and points OpenCode at it with one command. You can also let Gezel add a small plugin of its own to OpenCode, so the gezel provider is simply there in every session. Either way, your own OpenCode settings, conversations, and permissions are never edited. Your whole eligible crew is offered, so you can switch between them from OpenCode's model picker.`}),repairExplainer:`Repair writes a fresh settings file for this Gezel and keeps a copy of the existing one next to it.`,...i&&!i.opencodeInstalled?{notInstalledNote:`OpenCode was not found on this computer. You can prepare the setup now and use it after installing OpenCode.`}:{},...n.configured&&d&&!n.modelChanged?{configuredNote:(0,C.jsxs)(C.Fragment,{children:[`OpenCode starts with `,(0,C.jsx)(`strong`,{children:d.label}),`.`,i?.opencodeVersion?` OpenCode ${i.opencodeVersion} was found.`:``]})}:{},...n.canLaunch&&i?{commandRow:(0,C.jsxs)(`div`,{className:`harness-setup-command-row`,children:[(0,C.jsx)(`span`,{className:`muted small`,children:`Start it with`}),(0,C.jsx)(`code`,{children:i.launchCommand}),(0,C.jsx)(`button`,{type:`button`,onClick:()=>void n.copyLaunchCommand(),children:l?`Copied`:`Copy command`}),(0,C.jsx)(`output`,{className:`sr-only`,"aria-live":`polite`,children:l?`OpenCode launch command copied.`:``}),(0,C.jsx)(`span`,{className:`muted small`,children:`Keep Gezel running while you use OpenCode.`})]})}:{},modelRow:{label:`Default gezel`,value:n.model,onChange:n.setModel,disabled:n.selectionDisabled},...f&&i?{extraRows:(0,C.jsx)(`p`,{className:`muted small`,children:i.plugin.state===`installed`||i.plugin.state===`stale`?(0,C.jsxs)(C.Fragment,{children:[`Gezel is in OpenCode's provider list without the command, through`,` `,(0,C.jsx)(`code`,{children:i.plugin.path}),`.`]}):i.plugin.state===`conflict`?i.plugin.message:(0,C.jsx)(C.Fragment,{children:`Rather not use the command every time? Gezel can add its own plugin file to OpenCode so the crew shows up in every session.`})})}:{},actions:(0,C.jsxs)(C.Fragment,{children:[n.needsConfigure&&(0,C.jsx)(`button`,{type:`button`,className:`primary`,disabled:n.configureDisabled,onClick:()=>{s(null),o(n.repairable?`repair`:`configure`)},children:p}),f&&i&&(i.plugin.canInstall||i.plugin.canReplace)&&(0,C.jsx)(`button`,{type:`button`,disabled:c||!n.localDesktopMode,onClick:()=>{s(null),o(i.plugin.canReplace?`replace-plugin`:`install-plugin`)},children:i.plugin.canReplace?`Replace OpenCode plugin…`:`Add to OpenCode…`}),f&&i?.plugin.canRemove&&(0,C.jsx)(`button`,{type:`button`,disabled:c||!n.localDesktopMode,onClick:()=>{s(null),o(`remove-plugin`)},children:`Remove from OpenCode…`}),i?.canRemove&&(0,C.jsx)(`button`,{type:`button`,disabled:c||!n.localDesktopMode,onClick:()=>{s(null),o(`remove`)},children:i.state===`conflict`?`Clear Gezel setup…`:`Remove setup…`}),n.error&&(0,C.jsx)(`button`,{type:`button`,onClick:()=>void n.refresh(),disabled:c,children:`Try again`})]}),children:[(0,C.jsx)(m,{open:a===`configure`,title:i?.state===`not-configured`?`Set up OpenCode with Gezel?`:`Update OpenCode setup?`,message:(0,C.jsxs)(C.Fragment,{children:[`Gezel will `,i?.state===`not-configured`?`create`:`update`,` its own OpenCode settings file for `,(0,C.jsx)(`strong`,{children:u?.label??n.model}),`.`,` `,u&&x(u)?(0,C.jsxs)(C.Fragment,{children:[`This gezel's character, `,u.modelLabel??`model`,`, and tuning will guide OpenCode.`,` `]}):(0,C.jsx)(C.Fragment,{children:`OpenCode will use it as a raw inference model without a gezel persona. `}),`The file holds the local connection and app-scoped credential`,i?.configPath?(0,C.jsxs)(C.Fragment,{children:[` `,`at `,(0,C.jsx)(`code`,{children:i.configPath})]}):null,`. Your own OpenCode configuration, sessions, and permissions stay untouched.`]}),confirmLabel:i?.state===`not-configured`?`Set up OpenCode`:`Update OpenCode`,onConfirm:n.runConfirmedAction,onCancel:()=>o(null)}),(0,C.jsx)(m,{open:a===`repair`,title:`Repair the OpenCode setup?`,message:(0,C.jsxs)(C.Fragment,{children:[`Gezel will write a working settings file for`,` `,(0,C.jsx)(`strong`,{children:u?.label??n.model}),`, connected to this copy of Gezel.`,i?.configPath?(0,C.jsxs)(C.Fragment,{children:[` `,`The file now at `,(0,C.jsx)(`code`,{children:i.configPath}),` is kept as a `,(0,C.jsx)(`code`,{children:`.backup`}),` `,`copy beside it, so nothing is lost.`]}):(0,C.jsx)(C.Fragment,{children:` The file it replaces is kept as a .backup copy beside it, so nothing is lost.`}),` `,`Your own OpenCode configuration stays untouched.`]}),confirmLabel:`Repair setup`,onConfirm:n.runConfirmedAction,onCancel:()=>o(null)}),(0,C.jsx)(m,{open:a===`remove`,title:i?.state===`conflict`?`Clear Gezel setup for OpenCode?`:`Remove Gezel setup from OpenCode?`,message:(0,C.jsxs)(C.Fragment,{children:[`This removes only Gezel's own OpenCode settings file, state, and credential`,i?.plugin.canRemove?(0,C.jsxs)(C.Fragment,{children:[`, along with the plugin file Gezel added at `,(0,C.jsx)(`code`,{children:i.plugin.path})]}):null,`. It does not uninstall OpenCode or touch your own configuration and sessions.`]}),confirmLabel:i?.state===`conflict`?`Clear Gezel setup`:`Remove setup`,danger:!0,onConfirm:n.runConfirmedAction,onCancel:()=>o(null)}),(0,C.jsx)(m,{open:a===`install-plugin`||a===`replace-plugin`,title:a===`replace-plugin`?`Replace the plugin file in OpenCode?`:`Add Gezel to OpenCode?`,message:(0,C.jsxs)(C.Fragment,{children:[`Gezel will add one file of its own`,i?.plugin.path?(0,C.jsxs)(C.Fragment,{children:[` `,`at `,(0,C.jsx)(`code`,{children:i.plugin.path})]}):null,`, so every OpenCode session on this computer offers the `,(0,C.jsx)(`strong`,{children:`gezel`}),` provider without the command above. It holds no password — it reads Gezel's own settings when OpenCode starts, and does nothing at all when Gezel is not running. It does not change which model OpenCode starts with; pick a gezel from OpenCode's own model picker. Your own OpenCode configuration, sessions, and permissions stay untouched, and`,` `,(0,C.jsx)(`code`,{children:`opencode --pure`}),` always starts without it.`,a===`replace-plugin`?(0,C.jsx)(C.Fragment,{children:` The file it replaces is kept as a .backup copy beside it, so nothing is lost.`}):null]}),confirmLabel:a===`replace-plugin`?`Replace plugin`:`Add to OpenCode`,onConfirm:n.runConfirmedAction,onCancel:()=>o(null)}),(0,C.jsx)(m,{open:a===`remove-plugin`,title:`Remove Gezel from OpenCode?`,message:(0,C.jsxs)(C.Fragment,{children:[`This deletes the plugin file Gezel added`,i?.plugin.path?(0,C.jsxs)(C.Fragment,{children:[` `,`at `,(0,C.jsx)(`code`,{children:i.plugin.path})]}):null,`. OpenCode stops offering the gezel provider unless you start it with the command on this card. The rest of the setup, and everything of your own, stays as it is.`]}),confirmLabel:`Remove from OpenCode`,onConfirm:n.runConfirmedAction,onCancel:()=>o(null)})]})}function k(e,t){switch(e){case`remove`:return`Could not remove the OpenCode setup`;case`repair`:return`Could not repair the OpenCode setup`;case`install-plugin`:case`replace-plugin`:return`Could not add Gezel to OpenCode`;case`remove-plugin`:return`Could not remove Gezel from OpenCode`;default:return t===`not-configured`?`Could not set up the OpenCode setup`:`Could not update the OpenCode setup`}}function A({endpointsEnabled:e,onChanged:t}){let n=y({label:`pi`,endpointsEnabled:e,fetchStatus:()=>r.getPiSetupStatus(),runAction:(0,v.useCallback)((e,t)=>{switch(e){case`remove`:return r.removePiSetup();case`install-extension`:return r.installPiExtension();case`replace-extension`:return r.installPiExtension({backupConflictingExtension:!0});case`remove-extension`:return r.removePiExtension();default:return r.configurePi({model:t,...e===`repair`?{backupConflictingConfig:!0}:{}})}},[]),errorPrefix:j,backupNotice:e=>e.extensionBackupPath?`The previous extension file was saved as ${e.extensionBackupPath}.`:e.configBackupPath?`The previous file was saved as ${e.configBackupPath}.`:null,...t?{onChanged:t}:{}}),{status:i,confirmation:a,setConfirmation:o,setError:s,busy:c,copied:l}=n,u=i?.models.find(e=>e.id===n.model),d=i?.models.find(e=>e.id===i.configuredModel),f=n.configured&&n.localDesktopMode&&i?.state!==`conflict`&&i?.extension.state!==`unsupported`,p=n.repairable?`Repair pi setup…`:i?.state===`not-configured`?`Set up pi…`:`Update pi…`;return(0,C.jsxs)(w,{headingId:`pi-setup-heading`,title:`Use Gezel in pi`,status:i,remoteMode:n.remoteMode,localDesktopMode:n.localDesktopMode,endpointsEnabled:e,repairable:!!n.repairable,notice:n.notice,error:n.error,reasonsIntro:`The managed setup needs an update:`,emptyModelsNote:`No gezels or inference models compatible with the pi tool loop are available yet.`,intro:(0,C.jsx)(C.Fragment,{children:`pi keeps its own tools, permissions, and conversation loop while a gezel supplies the character, model, and tuning. Gezel writes an extension of its own and hands you a command that loads it for that run. You can also let Gezel add that same file to pi, so the gezel provider is simply there in every session. Either way, your own pi settings, sessions, and models are never edited.`}),repairExplainer:`Repair writes a fresh model list for this Gezel and keeps a copy of the existing one next to it.`,...i&&!i.piInstalled?{notInstalledNote:`pi was not found on this computer. You can prepare the setup now and use it after installing pi.`}:{},...n.configured&&d&&!n.modelChanged?{configuredNote:(0,C.jsxs)(C.Fragment,{children:[`pi starts with `,(0,C.jsx)(`strong`,{children:d.label}),`, and offers the whole crew in its own model picker.`,i?.piVersion?` pi ${i.piVersion} was found.`:``]})}:{},...n.canLaunch&&i?{commandRow:(0,C.jsxs)(`div`,{className:`harness-setup-command-row`,children:[(0,C.jsx)(`span`,{className:`muted small`,children:`Start it with`}),(0,C.jsx)(`code`,{children:i.launchCommand}),(0,C.jsx)(`button`,{type:`button`,onClick:()=>void n.copyLaunchCommand(),children:l?`Copied`:`Copy command`}),(0,C.jsx)(`output`,{className:`sr-only`,"aria-live":`polite`,children:l?`pi launch command copied.`:``}),(0,C.jsx)(`span`,{className:`muted small`,children:`Keep Gezel running while you use pi.`})]})}:{},modelRow:{label:`Default gezel`,value:n.model,onChange:n.setModel,disabled:n.selectionDisabled},...f&&i?{extraRows:(0,C.jsx)(`p`,{className:`muted small`,children:i.extension.state===`installed`||i.extension.state===`stale`?(0,C.jsxs)(C.Fragment,{children:[`Gezel is in pi's provider list without the command, through`,` `,(0,C.jsx)(`code`,{children:i.extension.path}),`.`]}):i.extension.state===`conflict`?i.extension.message:(0,C.jsx)(C.Fragment,{children:`Rather not use the command every time? Gezel can add the same extension to pi so the crew shows up in every session.`})})}:{},actions:(0,C.jsxs)(C.Fragment,{children:[n.needsConfigure&&(0,C.jsx)(`button`,{type:`button`,className:`primary`,disabled:n.configureDisabled,onClick:()=>{s(null),o(n.repairable?`repair`:`configure`)},children:p}),f&&i&&(i.extension.canInstall||i.extension.canReplace)&&(0,C.jsx)(`button`,{type:`button`,disabled:c||!n.localDesktopMode,onClick:()=>{s(null),o(i.extension.canReplace?`replace-extension`:`install-extension`)},children:i.extension.canReplace?`Replace pi extension…`:`Add to pi…`}),f&&i?.extension.canRemove&&(0,C.jsx)(`button`,{type:`button`,disabled:c||!n.localDesktopMode,onClick:()=>{s(null),o(`remove-extension`)},children:`Remove from pi…`}),i?.canRemove&&(0,C.jsx)(`button`,{type:`button`,disabled:c||!n.localDesktopMode,onClick:()=>{s(null),o(`remove`)},children:i.state===`conflict`?`Clear Gezel setup…`:`Remove setup…`}),n.error&&(0,C.jsx)(`button`,{type:`button`,onClick:()=>void n.refresh(),disabled:c,children:`Try again`})]}),children:[(0,C.jsx)(m,{open:a===`configure`,title:i?.state===`not-configured`?`Set up pi with Gezel?`:`Update pi setup?`,message:(0,C.jsxs)(C.Fragment,{children:[`Gezel will `,i?.state===`not-configured`?`create`:`update`,` its own pi extension and model list for `,(0,C.jsx)(`strong`,{children:u?.label??n.model}),`.`,` `,u&&x(u)?(0,C.jsxs)(C.Fragment,{children:[`This gezel's character, `,u.modelLabel??`model`,`, and tuning will guide pi.`,` `]}):(0,C.jsx)(C.Fragment,{children:`pi will use it as a raw inference model without a gezel persona. `}),`Both files live in Gezel's own folder`,i?.extensionPath?(0,C.jsxs)(C.Fragment,{children:[`, at `,(0,C.jsx)(`code`,{children:i.extensionPath})]}):null,`, and the command above points pi at them for that run. Your own pi settings, sessions, and models stay untouched.`]}),confirmLabel:i?.state===`not-configured`?`Set up pi`:`Update pi`,onConfirm:n.runConfirmedAction,onCancel:()=>o(null)}),(0,C.jsx)(m,{open:a===`repair`,title:`Repair the pi setup?`,message:(0,C.jsxs)(C.Fragment,{children:[`Gezel will write a working model list for`,` `,(0,C.jsx)(`strong`,{children:u?.label??n.model}),`, connected to this copy of Gezel.`,i?.configPath?(0,C.jsxs)(C.Fragment,{children:[` `,`The file now at `,(0,C.jsx)(`code`,{children:i.configPath}),` is kept as a `,(0,C.jsx)(`code`,{children:`.backup`}),` `,`copy beside it, so nothing is lost.`]}):(0,C.jsx)(C.Fragment,{children:` The file it replaces is kept as a .backup copy beside it, so nothing is lost.`}),` `,`Your own pi configuration stays untouched.`]}),confirmLabel:`Repair setup`,onConfirm:n.runConfirmedAction,onCancel:()=>o(null)}),(0,C.jsx)(m,{open:a===`remove`,title:i?.state===`conflict`?`Clear Gezel setup for pi?`:`Remove Gezel setup from pi?`,message:(0,C.jsxs)(C.Fragment,{children:[`This removes only Gezel's own pi extension, model list, state, and credential`,i?.extension.canRemove?(0,C.jsxs)(C.Fragment,{children:[`, along with the copy Gezel added at `,(0,C.jsx)(`code`,{children:i.extension.path})]}):null,`. It does not uninstall pi or touch your own settings and sessions.`]}),confirmLabel:i?.state===`conflict`?`Clear Gezel setup`:`Remove setup`,danger:!0,onConfirm:n.runConfirmedAction,onCancel:()=>o(null)}),(0,C.jsx)(m,{open:a===`install-extension`||a===`replace-extension`,title:a===`replace-extension`?`Replace the extension file in pi?`:`Add Gezel to pi?`,message:(0,C.jsxs)(C.Fragment,{children:[`Gezel will add its extension`,i?.extension.path?(0,C.jsxs)(C.Fragment,{children:[` `,`at `,(0,C.jsx)(`code`,{children:i.extension.path})]}):null,`, so every pi session on this computer offers the `,(0,C.jsx)(`strong`,{children:`gezel`}),` provider without the command above. It holds no password — it reads Gezel's own model list when pi starts, and does nothing at all when Gezel is not running. It does not change which model pi starts with; pick a gezel from pi's own model picker. Your own pi settings, sessions, and models stay untouched, and `,(0,C.jsx)(`code`,{children:`pi -ne`}),` always starts without it.`,i?.extension.agentDirSource==="default"?(0,C.jsxs)(C.Fragment,{children:[` `,`Gezel found pi's folder in its usual place. If you point pi elsewhere with`,` `,(0,C.jsx)(`code`,{children:`PI_CODING_AGENT_DIR`}),` in your shell, it will not be picked up.`]}):null,a===`replace-extension`?(0,C.jsx)(C.Fragment,{children:` The file it replaces is kept as a .backup copy beside it, so nothing is lost.`}):null]}),confirmLabel:a===`replace-extension`?`Replace extension`:`Add to pi`,onConfirm:n.runConfirmedAction,onCancel:()=>o(null)}),(0,C.jsx)(m,{open:a===`remove-extension`,title:`Remove Gezel from pi?`,message:(0,C.jsxs)(C.Fragment,{children:[`This deletes the extension Gezel added`,i?.extension.path?(0,C.jsxs)(C.Fragment,{children:[` `,`at `,(0,C.jsx)(`code`,{children:i.extension.path})]}):null,`. pi stops offering the gezel provider unless you start it with the command on this card. The rest of the setup, and everything of your own, stays as it is.`]}),confirmLabel:`Remove from pi`,onConfirm:n.runConfirmedAction,onCancel:()=>o(null)})]})}function j(e,t){switch(e){case`remove`:return`Could not remove the pi setup`;case`repair`:return`Could not repair the pi setup`;case`install-extension`:case`replace-extension`:return`Could not add Gezel to pi`;case`remove-extension`:return`Could not remove Gezel from pi`;default:return t===`not-configured`?`Could not set up pi`:`Could not update the pi setup`}}function M({endpointsEnabled:e,onChanged:t}){let[n,i]=(0,v.useState)(``),o=(0,v.useId)(),d=y({label:`VS Code`,endpointsEnabled:e,fetchStatus:()=>r.getVSCodeSetupStatus(),runAction:(0,v.useCallback)(e=>e===`remove`?r.removeVSCodeSetup():r.configureVSCode({profileId:n,...e===`repair`?{backupConflictingConfig:!0}:{}}),[n]),modelSelection:!1,errorPrefix:N,backupNotice:e=>e.configBackupPath?`The previous file was saved as ${e.configBackupPath}.`:null,...t?{onChanged:t}:{}}),{status:f,confirmation:p,setConfirmation:h,setError:g,busy:_}=d;(0,v.useEffect)(()=>{f&&i(e=>f.profiles.some(t=>t.id===e)?e:f.configuredProfileId??f.profiles[0]?.id??``)},[f]);let b=f?.profiles.find(e=>e.id===n),x=P(f?.vscodeVersion),S=!!f?.configuredProfileId,T=d.repairable?`Repair VS Code setup…`:f?.state===`not-configured`?`Set up VS Code…`:`Update VS Code…`;return(0,C.jsxs)(w,{headingId:`vscode-setup-heading`,title:`Use Gezel in VS Code`,status:f,remoteMode:d.remoteMode,localDesktopMode:d.localDesktopMode,endpointsEnabled:e,repairable:!!d.repairable,notice:d.notice,error:d.error,reasonsIntro:`The managed setup needs an update:`,emptyModelsNote:`No gezels or inference models compatible with VS Code's agent tool loop are available yet.`,intro:(0,C.jsx)(C.Fragment,{children:`VS Code keeps its native agent tools, permissions, and conversation loop. Gezel adds your eligible crew and raw local models through VS Code's built-in custom endpoint — no extension is installed. Setup edits only the Gezel provider in the selected profile.`}),repairExplainer:(0,C.jsxs)(C.Fragment,{children:[`Repair keeps a copy of `,(0,C.jsx)(`code`,{children:f?.configPath}),`, then replaces only the conflicting Gezel provider entry. Other providers stay in place.`]}),...f&&!f.vscodeInstalled?{notInstalledNote:`VS Code was not found on PATH. You can prepare its conventional profile now and use it after installing VS Code.`}:{},...d.configured&&b?{configuredNote:(0,C.jsxs)(C.Fragment,{children:[`Gezel is available in `,(0,C.jsx)(`strong`,{children:b.label}),`.`,x?` VS Code ${x} was found.`:``,` Keep Gezel running while you use the models.`]})}:{},extraRows:f&&(f.state!==`conflict`||d.repairable)?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`div`,{className:`harness-setup-model-row`,children:[(0,C.jsx)(`span`,{id:o,children:`VS Code profile`}),(0,C.jsxs)(a,{value:n,onValueChange:i,disabled:_||!d.localDesktopMode||!e||S,children:[(0,C.jsx)(l,{"aria-labelledby":o,children:(0,C.jsx)(c,{})}),(0,C.jsx)(u,{children:f.profiles.map(e=>(0,C.jsx)(s,{value:e.id,children:e.label},e.id))})]})]}),S&&(0,C.jsx)(`p`,{className:`muted small`,children:`Clear this setup before choosing a different profile.`}),(0,C.jsxs)(`p`,{className:`muted small`,children:[`If VS Code is already open, you may need to run`,` `,(0,C.jsx)(`strong`,{children:`Developer: Reload Window`}),` or restart VS Code after setup before the models work.`]})]}):null,actions:(0,C.jsxs)(C.Fragment,{children:[d.needsConfigure&&(0,C.jsx)(`button`,{type:`button`,className:`primary`,disabled:d.configureDisabled||!n,onClick:()=>{g(null),h(d.repairable?`repair`:`configure`)},children:T}),f?.canRemove&&(0,C.jsx)(`button`,{type:`button`,disabled:_||!d.localDesktopMode,onClick:()=>{g(null),h(`remove`)},children:f.state===`conflict`?`Clear Gezel setup…`:`Remove setup…`}),d.error&&(0,C.jsx)(`button`,{type:`button`,onClick:()=>void d.refresh(),disabled:_,children:`Try again`})]}),children:[(0,C.jsx)(m,{open:p===`configure`,title:f?.state===`not-configured`?`Set up VS Code with Gezel?`:`Update VS Code setup?`,message:(0,C.jsxs)(C.Fragment,{children:[`Gezel will add or update one provider in `,(0,C.jsx)(`code`,{children:b?.configPath}),`. VS Code will show every eligible gezel and raw local model in its native model picker and keep control of agent tools and permissions. Other custom endpoint providers are preserved.`,(0,C.jsx)(`br`,{}),(0,C.jsx)(`br`,{}),`Because no extension is involved, the dedicated inference-only credential is stored as plain text in this profile file. It works only through Gezel's loopback inference bridge and can be revoked by clearing this setup. If VS Code is already open, reload its window or restart it after setup so it picks up the new credential.`]}),confirmLabel:f?.state===`not-configured`?`Set up VS Code`:`Update VS Code`,onConfirm:d.runConfirmedAction,onCancel:()=>h(null)}),(0,C.jsx)(m,{open:p===`repair`,title:`Repair the VS Code setup?`,message:(0,C.jsxs)(C.Fragment,{children:[`Gezel will save the current `,(0,C.jsx)(`code`,{children:f?.configPath}),` beside it as a backup, then publish a working Gezel provider for this installation. Providers that are not named Gezel remain untouched. The replacement contains a new plain-text, inference-only loopback credential.`]}),confirmLabel:`Repair setup`,onConfirm:d.runConfirmedAction,onCancel:()=>h(null)}),(0,C.jsx)(m,{open:p===`remove`,title:`Remove Gezel setup from VS Code?`,message:(0,C.jsx)(C.Fragment,{children:`This removes only the Gezel provider entry, setup state, and dedicated credential. It does not uninstall VS Code, touch other endpoint providers, or delete conversations. A Gezel entry changed outside this setup is preserved, but its credential is revoked.`}),confirmLabel:`Remove setup`,danger:!0,onConfirm:d.runConfirmedAction,onCancel:()=>h(null)})]})}function N(e,t){return e===`remove`?`Could not remove the VS Code setup`:e===`repair`?`Could not repair the VS Code setup`:t===`not-configured`?`Could not set up the VS Code setup`:`Could not update the VS Code setup`}function P(e){if(!e)return;let t=e.split(/\s+/).filter(e=>e&&!/^[a-f\d]{40}$/i.test(e));return t.length>0?t.join(` `):void 0}function F(e){return e?f(e):`never`}var I=`__AUTOMATIC__`,L=new Set([`copilot`,`anthropic-cli`,`codex-cli`]);function R(){let[e,t]=(0,v.useState)(null),[n,i]=(0,v.useState)(null),[o,d]=(0,v.useState)(null),[f,y]=(0,v.useState)(null),[b,x]=(0,v.useState)({}),[S,w]=(0,v.useState)({}),[T,D]=(0,v.useState)([]),[k,j]=(0,v.useState)(null),[N,P]=(0,v.useState)(0),[R,z]=(0,v.useState)(`copilot`),[B,V]=(0,v.useState)(),H=(0,v.useCallback)(async()=>{try{let e=await fetch(`${r.getBaseUrl()}/v1/apps`,{headers:r.authHeader()});if(!e.ok){i(`Failed to load apps: HTTP ${e.status}`);return}i(null),t(await e.json())}catch(e){i(e instanceof Error?e.message:String(e))}},[]);(0,v.useEffect)(()=>{H();let e=window.setInterval(()=>void H(),4e3);return()=>window.clearInterval(e)},[H]),(0,v.useEffect)(()=>{r.getConfig().then(e=>{w(e.openaiEndpoints??{}),z(e.provider??`llama-cpp`),V(e.meesterGezelId)}).catch(()=>{}),r.listGezels().then(e=>D(e.gezels.map(({id:e,name:t,role:n,provider:r})=>({id:e,name:t,role:n,provider:r})))).catch(()=>{})},[]);let U=(0,v.useCallback)(async e=>{let t=S,n=e.emulateOllama===t.emulateOllama?`endpoints`:`ollama`;w(e),j({scope:n,text:`saving…`});try{let t=await r.updateConfig({openaiEndpoints:e});w(t.openaiEndpoints??{}),P(e=>e+1),j(null)}catch(e){w(t);let r=e&&typeof e==`object`&&`details`in e?e.details?.message:void 0;j({scope:n,text:`save failed: ${r??(e instanceof Error?e.message:String(e))}`})}},[S]),W=S.enabled!==!1,G=T.find(e=>e.id===S.servingGezelId),K=T.find(e=>e.id===B)??T[0],q=G??K,J=e=>e.provider??R,Y=q!==void 0&&L.has(J(q)),X=(0,v.useCallback)(async(t,n)=>{if(o)return;let a=e?.grants.find(e=>e.id===t),s=b[t]??``;d(`${n}:${t}`);try{let e=await fetch(`${r.getBaseUrl()}/v1/apps/grant/${encodeURIComponent(t)}/${n}`,{method:`POST`,headers:{...r.authHeader(),...n===`approve`&&a?.verificationRequired?{"Content-Type":`application/json`}:{}},...n===`approve`&&a?.verificationRequired?{body:JSON.stringify({verificationCode:s})}:{}});if(!e.ok){i(await g(e,`Failed to ${n} grant`));return}x(e=>{let n={...e};return delete n[t],n}),await H()}catch(e){i(e instanceof Error?e.message:String(e))}finally{d(null)}},[o,H,e?.grants,b]),Z=(0,v.useCallback)(async()=>{if(f){d(`revoke:${f.appId}`);try{let e=await fetch(`${r.getBaseUrl()}/v1/apps/${encodeURIComponent(f.appId)}/token`,{method:`DELETE`,headers:r.authHeader()});if(!e.ok){i(`Failed to revoke ${f.appId}: HTTP ${e.status}`);return}y(null),await H(),P(e=>e+1)}finally{d(null)}}},[f,H]),Q=(e?.grants??[]).filter(e=>e.status===`pending`),$=e?.apps??[];return(0,C.jsxs)(`section`,{className:`settings-section`,children:[(0,C.jsx)(`h2`,{children:`Connected Apps`}),(0,C.jsx)(`p`,{className:`muted small`,children:`Apps and command-line clients that have asked for access to your Gezel service. Each client is granted only the scopes it requested. Revoke any time.`}),n&&(0,C.jsx)(`p`,{className:`settings-error`,role:`alert`,children:n}),(0,C.jsxs)(`div`,{className:`settings-subsection`,children:[(0,C.jsx)(`h3`,{children:`OpenAI-compatible endpoints`}),(0,C.jsx)(`p`,{className:`muted small`,children:`Other apps (editors, browser tools) can use your gezellen and models through standard OpenAI-style endpoints. Each app still needs your approval below before it gets access.`}),(0,C.jsxs)(`label`,{className:`debug-toggle`,children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:W,onChange:e=>void U({...S,enabled:e.target.checked?void 0:!1})}),(0,C.jsx)(`span`,{children:`Allow apps to connect`})]}),W?(0,C.jsxs)(`p`,{className:`muted small`,children:[`Point apps at `,(0,C.jsxs)(`code`,{children:[r.getBaseUrl(),`/v1`]})]}):(0,C.jsx)(`p`,{className:`muted small`,children:`Turned off — connected apps are refused and new apps cannot ask for access until this is back on.`}),(0,C.jsxs)(`div`,{className:`connected-apps-serving`,children:[(0,C.jsx)(`span`,{id:`serving-gezel-label`,children:`Fallback gezel`}),(0,C.jsxs)(a,{value:G?G.id:I,onValueChange:e=>void U({...S,servingGezelId:e===I?void 0:e}),disabled:!W,children:[(0,C.jsx)(l,{"aria-labelledby":`serving-gezel-label`,children:(0,C.jsx)(c,{})}),(0,C.jsxs)(u,{children:[(0,C.jsxs)(s,{value:I,children:[`Automatic`,K?` — ${K.name}`:``]}),T.map(e=>(0,C.jsxs)(s,{value:e.id,children:[e.name,e.role?` — ${e.role}`:``,` (${J(e)})`]},e.id))]})]})]}),(0,C.jsxs)(`p`,{className:`muted small`,children:[`Apps receive your gezellen as model choices, including their names and roles. If an app asks for something else, `,q?.name??`your default gezel`,` answers with their character and model settings.`]}),q&&Y&&(0,C.jsxs)(`p`,{className:`small connected-apps-caution`,children:[q.name,` runs on `,J(q),`, which can't accept tools sent by apps — editors that use tools will get an error. For full compatibility, pick a gezel on a local model or a direct API provider.`]}),(0,C.jsxs)(`label`,{className:`debug-toggle`,children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:S.supportingBehaviors!==!1,onChange:e=>void U({...S,supportingBehaviors:e.target.checked?void 0:!1}),disabled:!W}),(0,C.jsx)(`span`,{children:`Supporting behaviors`})]}),(0,C.jsx)(`p`,{className:`muted small`,children:`Gezel knows how to get the best out of each model — catching runaway rambling, folding leaked reasoning, and applying model-specific fixes. Turn this off for plain serving: apps still get the gezel's character and each model's tuned settings (sampling, thinking mode), but no runtime interventions.`}),k?.scope===`endpoints`&&(0,C.jsx)(`output`,{className:`muted small`,children:k.text})]}),(0,C.jsx)(E,{endpointsEnabled:W,onChanged:H},`codex-${N}`),(0,C.jsx)(M,{endpointsEnabled:W,onChanged:H},`vscode-${N}`),(0,C.jsx)(O,{endpointsEnabled:W,onChanged:H},`opencode-${N}`),(0,C.jsx)(A,{endpointsEnabled:W,onChanged:H},`pi-${N}`),(0,C.jsxs)(`div`,{className:`settings-subsection`,children:[(0,C.jsx)(`h3`,{children:`Ollama emulation`}),(0,C.jsxs)(`label`,{className:`debug-toggle`,children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:S.emulateOllama===!0,onChange:e=>void U({...S,emulateOllama:e.target.checked?!0:void 0}),disabled:!W}),(0,C.jsx)(`span`,{children:`Emulate Ollama (port 11434)`})]}),(0,C.jsx)(`p`,{className:`muted small`,children:`Apps that auto-discover Ollama will find gezel instead — no setup needed in each app. Security note: Ollama's convention is no password, so while this is on, any program on this computer can use your models without asking first. Gezel refuses to take the port if Ollama itself is already running.`}),k?.scope===`ollama`&&(0,C.jsx)(`output`,{className:`muted small`,children:k.text})]}),Q.length>0&&(0,C.jsxs)(`div`,{className:`settings-subsection`,children:[(0,C.jsx)(`h3`,{children:`Pending requests`}),(0,C.jsx)(`ul`,{className:`settings-list`,children:Q.map(e=>(0,C.jsxs)(`li`,{className:`connected-app-row connected-app-row--pending`,children:[(0,C.jsxs)(`div`,{className:`connected-app-meta`,children:[(0,C.jsxs)(`div`,{className:`connected-app-name`,children:[e.appName,e.kind===`device`&&(0,C.jsx)(`span`,{className:`badge`,children:` device`})]}),(0,C.jsx)(`div`,{className:`muted small`,children:e.kind===`device`?`wants to run models on this device`:e.scopes.includes(`cli`)?`${e.appId} — wants command-line control of this Gezel service`:e.scopes.includes(`product`)?`${e.appId} — wants access to Gezel features and data`:`${e.appId} — wants: ${e.scopes.join(`, `)}`})]}),(0,C.jsxs)(`div`,{className:`connected-app-actions`,children:[e.verificationRequired&&(0,C.jsxs)(`label`,{className:`connected-app-code`,children:[(0,C.jsx)(`span`,{children:`Connection code`}),(0,C.jsx)(`input`,{value:b[e.id]??``,onChange:t=>{let n=_(t.currentTarget.value);x(t=>({...t,[e.id]:n}))},placeholder:`___-___`,maxLength:7,autoComplete:`off`,autoCapitalize:`characters`,spellCheck:!1,"aria-label":`Connection code for ${e.appName}`})]}),(0,C.jsx)(`button`,{type:`button`,onClick:()=>void X(e.id,`deny`),disabled:o!==null,children:`Deny`}),(0,C.jsx)(`button`,{type:`button`,className:`primary`,onClick:()=>void X(e.id,`approve`),disabled:o!==null||e.verificationRequired&&!h(b[e.id]??``),children:o===`approve:${e.id}`?`Approving…`:`Approve`})]})]},e.id))})]}),(0,C.jsxs)(`div`,{className:`settings-subsection`,children:[(0,C.jsx)(`h3`,{children:`Connected`}),$.length===0?(0,C.jsx)(`p`,{className:`muted small`,children:`No apps connected. Apps that use the gezel SDK appear here after you approve them.`}):(0,C.jsx)(`div`,{className:`connected-apps-table-wrap`,children:(0,C.jsxs)(`table`,{className:`connected-apps-table`,"aria-label":`Connected apps`,children:[(0,C.jsx)(`thead`,{children:(0,C.jsxs)(`tr`,{children:[(0,C.jsx)(`th`,{scope:`col`,children:`App`}),(0,C.jsx)(`th`,{scope:`col`,children:`Scopes`}),(0,C.jsx)(`th`,{scope:`col`,children:`Last used`}),(0,C.jsx)(`th`,{scope:`col`,children:(0,C.jsx)(`span`,{className:`sr-only`,children:`Actions`})})]})}),(0,C.jsx)(`tbody`,{children:$.map(e=>(0,C.jsxs)(`tr`,{children:[(0,C.jsxs)(`td`,{"data-label":`App`,children:[(0,C.jsxs)(`div`,{className:`connected-apps-identity`,children:[(0,C.jsx)(`span`,{className:`connected-apps-name`,children:e.appName}),e.kind===`device`&&(0,C.jsx)(`span`,{className:`connected-apps-kind`,children:`Device`})]}),(0,C.jsx)(`span`,{className:`connected-apps-id`,children:e.appId})]}),(0,C.jsx)(`td`,{"data-label":`Scopes`,children:e.scopes.length>0?(0,C.jsx)(`ul`,{className:`connected-apps-scopes`,children:e.scopes.map(e=>(0,C.jsx)(`li`,{children:e},e))}):(0,C.jsx)(`span`,{className:`connected-apps-empty`,children:`None`})}),(0,C.jsx)(`td`,{"data-label":`Last used`,children:(0,C.jsx)(`span`,{className:`connected-apps-last-used`,title:e.lastUsedAt?p(e.lastUsedAt):void 0,children:F(e.lastUsedAt)})}),(0,C.jsx)(`td`,{className:`connected-apps-action`,children:(0,C.jsx)(`button`,{type:`button`,className:`connected-apps-revoke`,"aria-label":`Revoke ${e.appName}`,onClick:()=>y(e),disabled:o!==null,children:`Revoke`})})]},e.appId))})]})})]}),(0,C.jsx)(m,{open:f!==null,title:f?`Revoke ${f.appName}?`:`Revoke app`,message:f?(0,C.jsxs)(C.Fragment,{children:[`The next time `,(0,C.jsx)(`strong`,{children:f.appName}),` tries to use gezel it will be denied. The app can reconnect later by going through the consent flow again.`]}):null,confirmLabel:`Revoke`,danger:!0,onConfirm:Z,onCancel:()=>y(null)})]})}export{R as ConnectedAppsPanel};
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{Ot as r,Qt as i,V as a,Xt as o,_n as s,k as c,kt as l}from"./dist-BqGwkOe5.js";import{t as u}from"./api-BPraLwsh.js";import{i as d,n as f,r as p}from"./Tabs-jE0Z5Tzd.js";import{d as m,l as h,m as g,p as _,s as v}from"./primitives-CWrGZpPI.js";import{C as y,X as b}from"./index-C0DYtvfg.js";import{i as x}from"./ChatTimelineView-CQ4Sf4Ip.js";import{t as S}from"./ProjectTimeline-BZpdCisR.js";import{t as C}from"./MarkdownField-CK8K3fzj.js";var w=e(t(),1),T=n(),E=`default`;function D({craftbookId:e,craftbookName:t,readOnly:n}){let r=y(),[i,o]=(0,w.useState)([]),[s,c]=(0,w.useState)(``);(0,w.useEffect)(()=>{u.listGezels().then(e=>o(e.gezels)).catch(()=>{})},[]),(0,w.useEffect)(()=>{c(``)},[e]);let l=(0,w.useMemo)(()=>i.find(e=>e.role===`voorman`)??i.find(e=>e.role===`meester`)??i[0],[i]),d=t=>{t?.startsWith(`craftbook_`)&&window.dispatchEvent(new CustomEvent(`gezel:craftbook-edited`,{detail:{id:e}}))};if(n)return(0,T.jsx)(`div`,{className:`craftbook-chat-pane muted small`,children:`This craftbook is read-only — fork it to a local copy to edit it with AI.`});if(!l)return(0,T.jsx)(`div`,{className:`craftbook-chat-pane muted small`,children:`No gezel available yet. Create a voorman or the Meester first, then come back.`});let f=a(l,r);return(0,T.jsxs)(`div`,{className:`craftbook-chat-pane task-detail-chat`,children:[(0,T.jsx)(S,{projectId:E,activeSessionId:s||void 0,onFocusSession:(e,t)=>{t===l.id&&c(e)},onToolActivity:e=>d(e.name)}),(0,T.jsx)(x,{gezelId:l.id,gezelName:l.name,gezelRoleBasedName:l.roleBasedName,gezelRole:l.role,gezelIcon:l.icon??null,...l.poppetje?{gezelPoppetje:l.poppetje}:{},...l.iconOverride?{gezelIconOverride:l.iconOverride}:{},projectId:E,sessionId:s||void 0,onSessionCreated:e=>c(e),onToolActivity:e=>d(e.name),craftbookRef:e,placeholder:`Ask ${f} to shape “${t}” — add steps, set roles, wire gates…`})]})}function O(e){window.dispatchEvent(new CustomEvent(`gezel:open-tab`,{detail:e}))}function k({craftbookId:e,steps:t,stepId:n,entryStepId:i,gezels:a,readOnly:o,busy:s,onPatch:c,onRemove:u,onSetEntry:d}){let f=n?t.find(e=>e.id===n)??null:null,[p,y]=(0,w.useState)(n),b=(0,w.useRef)(f?.name??``),x=(0,w.useRef)(f?.description??``),S=(0,w.useRef)(f?.prompt??``),E=(0,w.useRef)(f?.suggestedRole??``);if((0,w.useEffect)(()=>{b.current=f?.name??``,x.current=f?.description??``,S.current=f?.prompt??``,E.current=f?.suggestedRole??``,y(f?.id??null)},[f?.id,f?.name,f?.description,f?.prompt,f?.suggestedRole]),!f)return(0,T.jsx)(`section`,{className:`task-step-panel empty`,children:(0,T.jsx)(`p`,{className:`muted small`,children:t.length===0?`No steps yet — add one with the + button to begin.`:`Select a step above to view and edit it.`})});let D=f.id===i,k=e=>{o||c(f.id,e)},A=()=>{let e=b.current.trim();!e||e===f.name||k({name:e})},j=()=>{x.current!==(f.description??``)&&k({description:x.current})},M=()=>{S.current!==(f.prompt??``)&&k({prompt:S.current})},N=()=>{let e=E.current.trim();e!==(f.suggestedRole??``)&&k({suggestedRole:e||null})},P=f.assignee?f.assignee.kind===`user`?`__user`:f.assignee.gezelId:f.suggestedGezelId?f.suggestedGezelId:`__none`,F=e=>{k(e===`__user`?{assignee:{kind:`user`},suggestedGezelId:null}:e===`__none`?{assignee:null,suggestedGezelId:null}:{assignee:null,suggestedGezelId:e})},I=f.terminal?`__terminal`:f.next??`__linear`,L=e=>{k(e===`__terminal`?{terminal:!0,next:null}:e===`__linear`?{terminal:!1,next:null}:{terminal:!1,next:e})},R=t=>{let n=r(t===`enter`?f.onEnter:f.onExit),i=t===`enter`?`onEnter`:`onExit`,a=e=>k({[i]:e.length>0?e:null});return(0,T.jsxs)(`div`,{className:`step-script-row`,children:[(0,T.jsx)(`span`,{className:`step-script-moment muted small`,children:t===`enter`?`when it starts`:`when it finishes`}),n.length===0&&o&&(0,T.jsx)(`span`,{className:`muted small`,children:`—`}),n.map((t,r)=>(0,T.jsxs)(`span`,{className:`step-script-chip`,children:[(0,T.jsxs)(`button`,{type:`button`,className:`link-button`,onClick:()=>{(t.scope===void 0||t.scope===`craftbook`)&&O({kind:`craftbook-script`,craftbookId:e,name:t.name})},title:t.scope?`${t.scope} script`:`Open this script in the editor`,children:[`⚙ `,t.name,t.scope&&t.scope!==`craftbook`?` (${t.scope})`:``]}),!o&&(0,T.jsx)(`button`,{type:`button`,className:`link-button muted`,onClick:()=>a(n.filter((e,t)=>t!==r)),children:`detach`})]},`${t.scope??`craftbook`}:${t.name}:${r}`)),!o&&(0,T.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>{let r=`${f.id}-${t}${n.length>0?`-${n.length+1}`:``}`;a([...n,{name:r}]),O({kind:`craftbook-script`,craftbookId:e,name:r})},children:`+ attach script`})]})},z=[];if(f.gate){let e=l(f.gate),t=[...e.checks.length>0?[`${e.checks.length} check(s)`]:[],...e.scripts.length>0?[`${e.scripts.length} script(s)`]:[]];z.push(`gate at ${e.at}: ${t.join(` + `)||`empty`}`)}return f.advanceWhen&&z.push(`auto-advance on ${f.advanceWhen.file}`),f.branches&&f.branches.length>0&&z.push(`${f.branches.length} branch(es)`),(0,T.jsxs)(`section`,{className:`task-step-panel`,children:[(0,T.jsxs)(`header`,{className:`task-step-panel-header`,children:[(0,T.jsxs)(`div`,{className:`task-step-panel-title`,children:[(0,T.jsx)(`h4`,{children:f.name}),D&&(0,T.jsx)(`span`,{className:`step-status-pill status-active`,children:`Entry`})]}),!o&&(0,T.jsxs)(`div`,{className:`task-step-panel-actions`,children:[(0,T.jsx)(`button`,{type:`button`,className:`secondary`,onClick:()=>void d(f.id),disabled:s||D,title:`Make this the craftbook's entry step`,children:`Set as entry`}),(0,T.jsx)(`button`,{type:`button`,className:`danger`,onClick:()=>void u(f.id),disabled:s||t.length<=1,title:t.length<=1?`A craftbook needs at least one step`:`Delete this step`,children:`Delete`})]})]}),(0,T.jsxs)(`div`,{className:`task-step-panel-grid`,children:[(0,T.jsxs)(`label`,{className:`task-step-field`,children:[(0,T.jsx)(`span`,{className:`task-step-field-label`,children:`Name`}),(0,T.jsx)(`input`,{defaultValue:f.name,disabled:o,onChange:e=>{b.current=e.target.value},onBlur:A},`name-${p}`)]}),(0,T.jsxs)(`label`,{className:`task-step-field`,children:[(0,T.jsx)(`span`,{className:`task-step-field-label`,children:`Indexed context`}),(0,T.jsxs)(m,{value:f.retrieval?.mode??`__inherit`,disabled:o||s,onValueChange:e=>k(e===`__inherit`?{retrieval:null}:{retrieval:{mode:e,...f.retrieval?.maxTokens?{maxTokens:f.retrieval.maxTokens}:{},...f.retrieval?.sources?{sources:f.retrieval.sources}:{}}}),children:[(0,T.jsx)(_,{children:(0,T.jsx)(g,{})}),(0,T.jsxs)(v,{children:[(0,T.jsx)(h,{value:`__inherit`,children:`Inherit from gezel`}),(0,T.jsx)(h,{value:`off`,children:`Off — tools only`}),(0,T.jsx)(h,{value:`lean`,children:`Lean — paths and hints`}),(0,T.jsx)(h,{value:`balanced`,children:`Balanced — a few excerpts`}),(0,T.jsx)(h,{value:`deep`,children:`Deep — broad evidence`})]})]})]}),(0,T.jsxs)(`label`,{className:`task-step-field`,children:[(0,T.jsx)(`span`,{className:`task-step-field-label`,children:`Context token cap`}),(0,T.jsx)(`input`,{type:`number`,min:0,max:16e3,defaultValue:f.retrieval?.maxTokens??``,disabled:o||s||!f.retrieval||f.retrieval.mode===`off`,placeholder:`Mode default`,onBlur:e=>{if(!f.retrieval)return;let t=e.currentTarget.value.trim(),n=t?Number.parseInt(t,10):void 0;if(n!==void 0&&!Number.isFinite(n)||n===f.retrieval.maxTokens)return;let{maxTokens:r,...i}=f.retrieval;k({retrieval:n===void 0?i:{...i,maxTokens:n}})}},`retrieval-budget-${p}`)]}),(0,T.jsxs)(`label`,{className:`task-step-field`,children:[(0,T.jsx)(`span`,{className:`task-step-field-label`,children:`Suggested role`}),(0,T.jsx)(`input`,{defaultValue:f.suggestedRole??``,disabled:o,placeholder:`developer, reviewer, designer…`,onChange:e=>{E.current=e.target.value},onBlur:N},`role-${p}`)]}),(0,T.jsxs)(`label`,{className:`task-step-field`,children:[(0,T.jsx)(`span`,{className:`task-step-field-label`,children:`Assignee (override)`}),(0,T.jsxs)(m,{value:P,disabled:o||s,onValueChange:F,children:[(0,T.jsx)(_,{children:(0,T.jsx)(g,{})}),(0,T.jsxs)(v,{children:[(0,T.jsx)(h,{value:`__none`,children:`— by role —`}),(0,T.jsx)(h,{value:`__user`,children:`→ You`}),a.map(e=>(0,T.jsxs)(h,{value:e.id,children:[`→ `,e.name]},e.id))]})]})]}),(0,T.jsxs)(`label`,{className:`task-step-field`,children:[(0,T.jsx)(`span`,{className:`task-step-field-label`,children:`Next step`}),(0,T.jsxs)(m,{value:I,disabled:o||s,onValueChange:L,children:[(0,T.jsx)(_,{children:(0,T.jsx)(g,{})}),(0,T.jsxs)(v,{children:[(0,T.jsx)(h,{value:`__linear`,children:`→ next in order`}),(0,T.jsx)(h,{value:`__terminal`,children:`■ terminal (ends here)`}),t.filter(e=>e.id!==f.id).map(e=>(0,T.jsxs)(h,{value:e.id,children:[`→ `,e.name]},e.id))]})]})]}),(0,T.jsxs)(`div`,{className:`task-step-field full-width`,children:[(0,T.jsx)(`span`,{className:`task-step-field-label`,children:`Description`}),(0,T.jsx)(C,{value:f.description??``,readOnly:o,placeholder:`What this step produces, who it's for, what 'done' looks like.`,onCommit:e=>{x.current=e,j()}},`desc-${p}`)]}),(0,T.jsxs)(`div`,{className:`task-step-field full-width`,children:[(0,T.jsxs)(`span`,{className:`task-step-field-label`,children:[`Prompt `,(0,T.jsx)(`span`,{className:`muted small`,children:`— step-specific guidance for the assignee`})]}),(0,T.jsx)(C,{value:f.prompt??``,readOnly:o,placeholder:`Instructions the assignee can lean on for this step.`,onCommit:e=>{S.current=e,M()}},`prompt-${p}`)]}),(0,T.jsxs)(`div`,{className:`task-step-field full-width`,children:[(0,T.jsx)(`span`,{className:`task-step-field-label`,children:`Scripts`}),(0,T.jsxs)(`div`,{className:`step-scripts`,children:[R(`enter`),R(`exit`)]})]}),z.length>0&&(0,T.jsxs)(`div`,{className:`task-step-field full-width`,children:[(0,T.jsx)(`span`,{className:`task-step-field-label`,children:`Routing`}),(0,T.jsxs)(`p`,{className:`muted small`,children:[z.join(` · `),` — edit gates/branches/auto-advance via the AI assist.`]})]})]})]})}function A(e){window.dispatchEvent(new CustomEvent(`gezel:open-tab`,{detail:e}))}function j(e){return{name:e.name,description:e.description??null,plan:e.plan??null,defaultAssignee:e.defaultAssignee??null,steps:e.steps,entryStepId:e.entryStepId}}function M({craftbookId:e,source:t,onChanged:n}){let[r,a]=(0,w.useState)(null),[l,m]=(0,w.useState)(t??`local`),[h,g]=(0,w.useState)([]),[_,v]=(0,w.useState)(null),[y,x]=(0,w.useState)(`editor`),[S,E]=(0,w.useState)(!1),[O,M]=(0,w.useState)(null),N=(0,w.useRef)(``),P=(0,w.useRef)(``),F=l!==`local`,I=(0,w.useCallback)(async()=>{try{let n=await u.getCraftbook(e,t?{source:t}:{});a(n.craftbook),N.current=n.craftbook.name,P.current=n.craftbook.description??``,v(e=>e&&n.craftbook.steps.some(t=>t.id===e)?e:n.craftbook.entryStepId??n.craftbook.steps[0]?.id??null)}catch(e){M(e.message)}},[e,t]);(0,w.useEffect)(()=>{I()},[I]),(0,w.useEffect)(()=>{u.listGezels().then(e=>g(e.gezels)).catch(()=>{})},[]),(0,w.useEffect)(()=>{if(t){m(t);return}u.listCraftbooks({source:`all`}).then(t=>{let n=t.craftbooks.find(t=>t.id===e);n&&m(n.source)}).catch(()=>{})},[e,t]),(0,w.useEffect)(()=>{let t=t=>{let n=t.detail;(!n?.id||n.id===e)&&I()};return window.addEventListener(`gezel:craftbook-edited`,t),()=>window.removeEventListener(`gezel:craftbook-edited`,t)},[e,I]);let L=(0,w.useCallback)(async e=>{if(a(e),!F){E(!0),M(null);try{let t=await u.updateCraftbook(e.id,j(e));a(t.craftbook),n?.()}catch(e){M(e.message),await I()}finally{E(!1)}}},[F,n,I]);if(O&&!r)return(0,T.jsx)(`p`,{className:`error`,children:O});if(!r)return(0,T.jsx)(`p`,{className:`placeholder`,children:`Loading…`});let R=(e,t)=>{L({...r,steps:r.steps.map(n=>n.id===e?c(n,t):n)})},z=e=>{L({...r,steps:i(r.steps,e)})},B=e=>{try{let t=o(r.steps,e),n=r.entryStepId===e?t[0].id:r.entryStepId;_===e&&v(n),L({...r,steps:t,entryStepId:n})}catch(e){M(e.message)}},V=e=>{L({...r,entryStepId:e})},H=()=>{let e=s(r.steps,`New step`),t={id:e,name:`New step`};v(e),L({...r,steps:[...r.steps,t]})},U=()=>{let e=N.current.trim();!e||e===r.name||L({...r,name:e})},W=()=>{P.current!==(r.description??``)&&L({...r,description:P.current||void 0})},G=async()=>{E(!0),M(null);try{A({kind:`craftbook`,id:(await u.createCraftbook({name:`${r.name} (copy)`,...r.description?{description:r.description}:{},...r.plan?{plan:r.plan}:{},steps:r.steps,entryStepId:r.entryStepId})).craftbook.id,source:`local`})}catch(e){M(e.message)}finally{E(!1)}};return(0,T.jsxs)(`div`,{className:`craftbook-editor`,"data-testid":`craftbook-editor`,children:[(0,T.jsxs)(`header`,{className:`craftbook-editor-header`,children:[(0,T.jsxs)(`div`,{className:`craftbook-editor-title`,children:[F?(0,T.jsx)(`h3`,{children:r.name}):(0,T.jsx)(`input`,{className:`craftbook-name-input`,defaultValue:r.name,onChange:e=>{N.current=e.target.value},onBlur:U,"aria-label":`Craftbook name`}),(0,T.jsx)(`span`,{className:`task-ref`,children:r.id}),(0,T.jsx)(`span`,{className:`task-badge task-badge-${l}`,children:l}),F&&(0,T.jsx)(`button`,{type:`button`,className:`primary`,onClick:()=>void G(),disabled:S,children:`Copy to edit`})]}),O&&(0,T.jsx)(`p`,{className:`error small`,children:O})]}),(0,T.jsx)(`div`,{className:`task-bench-row craftbook-bench-row${_===null?``:` has-docked-panel has-selected-step`}`,children:(0,T.jsx)(b,{steps:r.steps,selectedStepId:_,onSelect:v,entryStepId:r.entryStepId,busy:S,ariaLabel:`Craftbook steps`,addLabel:`Add step`,variant:`bench`,...F?{}:{onAddStep:H,onReorder:z}})}),(0,T.jsx)(k,{craftbookId:r.id,steps:r.steps,stepId:_,entryStepId:r.entryStepId,gezels:h,readOnly:F,busy:S,onPatch:R,onRemove:B,onSetEntry:V}),(0,T.jsx)(`div`,{className:`craftbook-editor-tabs`,children:(0,T.jsx)(p,{value:y,onValueChange:e=>x(e),children:(0,T.jsxs)(f,{children:[(0,T.jsx)(d,{value:`editor`,children:`Overview`}),(0,T.jsx)(d,{value:`chat`,children:`AI assist`})]})})}),y===`editor`&&(0,T.jsxs)(`div`,{className:`craftbook-overview`,children:[(0,T.jsxs)(`div`,{className:`task-step-field full-width`,children:[(0,T.jsx)(`span`,{className:`task-step-field-label`,children:`Description`}),(0,T.jsx)(C,{value:r.description??``,readOnly:F,placeholder:`What this craftbook is for and when to reach for it.`,onCommit:e=>{P.current=e,W()}},`cbdesc-${r.id}`)]}),r.plan&&(0,T.jsxs)(`div`,{className:`task-step-field full-width`,children:[(0,T.jsx)(`span`,{className:`task-step-field-label`,children:`Plan`}),(0,T.jsx)(`p`,{className:`muted small`,children:r.plan})]})]}),y===`chat`&&(0,T.jsx)(D,{craftbookId:r.id,craftbookName:r.name,readOnly:F})]})}export{M as t};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{t as r}from"./api-BX5xXiFs.js";import{t as i}from"./ScriptEditorTabs-paocQ6dj.js";var a=e(t(),1),o=n();function s({craftbookId:e,scriptName:t}){let n=(0,a.useRef)(null),[s,c]=(0,a.useState)(null),[l,u]=(0,a.useState)([]),[d,f]=(0,a.useState)(!1),[p,m]=(0,a.useState)(!1),[h,g]=(0,a.useState)(null);(0,a.useEffect)(()=>{let n=!1;return(async()=>{try{let i=await r.getCraftbookScriptSource(e,t).catch(()=>null);i||=(await r.createCraftbookScript(e,{name:t}),await r.getCraftbookScriptSource(e,t)),n||c(i)}catch(e){n||g(e.message)}})(),()=>{n=!0}},[e,t]);let _=(0,a.useCallback)(async()=>{let i=n.current?.getValue();if(!(i==null||!s)){m(!0),g(null);try{let a=await r.saveCraftbookScriptSource(e,{name:t,source:i,baseHash:s.hash});if(a.status===`conflict`){g(`The script changed on disk — reopen the tab to get the latest.`);return}c({...s,source:i,hash:a.hash}),f(!1),n.current?.setServerDiagnostics(a.diagnostics)}catch(e){g(e.message)}finally{m(!1)}}},[e,t,s]);if(h&&!s)return(0,o.jsx)(`p`,{className:`error`,children:h});if(!s)return(0,o.jsx)(`p`,{className:`placeholder`,children:`Loading…`});let v=l.filter(e=>e.severity===`error`).length;return(0,o.jsxs)(`div`,{className:`script-editor-view`,children:[(0,o.jsxs)(`header`,{className:`script-editor-header`,children:[(0,o.jsxs)(`div`,{className:`script-editor-title`,children:[(0,o.jsx)(`span`,{className:`task-ref`,children:e}),(0,o.jsx)(`h3`,{children:t}),d&&(0,o.jsx)(`span`,{className:`muted small`,children:`• unsaved`})]}),(0,o.jsx)(`div`,{className:`script-editor-actions`,children:(0,o.jsx)(`button`,{type:`button`,className:`primary`,onClick:()=>void _(),disabled:p||!d,children:p?`Saving…`:`Save`})})]}),h&&(0,o.jsx)(`p`,{className:`error small`,children:h}),(0,o.jsx)(`div`,{className:`script-editor-body`,children:(0,o.jsx)(i,{ref:n,projectId:`craftbook:${e}`,scriptName:t,initialSource:s.source,initialMeta:s.meta,onChangeContent:()=>f(!0),onSave:()=>void _(),onProblems:u})}),v>0&&(0,o.jsxs)(`div`,{className:`script-editor-problems small`,children:[v,` problem`,v===1?``:`s`,` — hover the red marks in the editor.`]})]})}export{s as CraftbookScriptEditorView};
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{t as r}from"./api-BPraLwsh.js";import{t as i}from"./ScriptEditorTabs-BFvIiDFZ.js";var a=e(t(),1),o=n();function s({craftbookId:e,scriptName:t}){let n=(0,a.useRef)(null),[s,c]=(0,a.useState)(null),[l,u]=(0,a.useState)([]),[d,f]=(0,a.useState)(!1),[p,m]=(0,a.useState)(!1),[h,g]=(0,a.useState)(null);(0,a.useEffect)(()=>{let n=!1;return(async()=>{try{let i=await r.getCraftbookScriptSource(e,t).catch(()=>null);i||=(await r.createCraftbookScript(e,{name:t}),await r.getCraftbookScriptSource(e,t)),n||c(i)}catch(e){n||g(e.message)}})(),()=>{n=!0}},[e,t]);let _=(0,a.useCallback)(async()=>{let i=n.current?.getValue();if(!(i==null||!s)){m(!0),g(null);try{let a=await r.saveCraftbookScriptSource(e,{name:t,source:i,baseHash:s.hash});if(a.status===`conflict`){g(`The script changed on disk — reopen the tab to get the latest.`);return}c({...s,source:i,hash:a.hash}),f(!1),n.current?.setServerDiagnostics(a.diagnostics)}catch(e){g(e.message)}finally{m(!1)}}},[e,t,s]);if(h&&!s)return(0,o.jsx)(`p`,{className:`error`,children:h});if(!s)return(0,o.jsx)(`p`,{className:`placeholder`,children:`Loading…`});let v=l.filter(e=>e.severity===`error`).length;return(0,o.jsxs)(`div`,{className:`script-editor-view`,children:[(0,o.jsxs)(`header`,{className:`script-editor-header`,children:[(0,o.jsxs)(`div`,{className:`script-editor-title`,children:[(0,o.jsx)(`span`,{className:`task-ref`,children:e}),(0,o.jsx)(`h3`,{children:t}),d&&(0,o.jsx)(`span`,{className:`muted small`,children:`• unsaved`})]}),(0,o.jsx)(`div`,{className:`script-editor-actions`,children:(0,o.jsx)(`button`,{type:`button`,className:`primary`,onClick:()=>void _(),disabled:p||!d,children:p?`Saving…`:`Save`})})]}),h&&(0,o.jsx)(`p`,{className:`error small`,children:h}),(0,o.jsx)(`div`,{className:`script-editor-body`,children:(0,o.jsx)(i,{ref:n,projectId:`craftbook:${e}`,scriptName:t,initialSource:s.source,initialMeta:s.meta,onChangeContent:()=>f(!0),onSave:()=>void _(),onProblems:u})}),v>0&&(0,o.jsxs)(`div`,{className:`script-editor-problems small`,children:[v,` problem`,v===1?``:`s`,` — hover the red marks in the editor.`]})]})}export{s as CraftbookScriptEditorView};
@@ -1 +1 @@
1
- import{t as e}from"./jsx-runtime-CEpd2cAX.js";import{t}from"./CraftbookEditor-D5jTzWwF.js";var n=e();function r({craftbookId:e,source:r,onChanged:i}){return(0,n.jsx)(`div`,{className:`craftbook-tab`,children:(0,n.jsx)(t,{craftbookId:e,...r?{source:r}:{},...i?{onChanged:i}:{}},e)})}export{r as CraftbookTabContent};
1
+ import{t as e}from"./jsx-runtime-CEpd2cAX.js";import{t}from"./CraftbookEditor-DEQRlQ2p.js";var n=e();function r({craftbookId:e,source:r,onChanged:i}){return(0,n.jsx)(`div`,{className:`craftbook-tab`,children:(0,n.jsx)(t,{craftbookId:e,...r?{source:r}:{},...i?{onChanged:i}:{}},e)})}export{r as CraftbookTabContent};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{t as r}from"./api-BX5xXiFs.js";import{t as i}from"./ToolsetConfigForm-gUVMTPR_.js";var a=e(t(),1),o=n();function s({missing:e,onAllInstalled:t,onCancel:n}){let[s,c]=(0,a.useState)(new Set),[l,u]=(0,a.useState)(null),[d,f]=(0,a.useState)(null),[p,m]=(0,a.useState)(null),h=n=>{let r=new Set(s);r.add(n),c(r),e.every(e=>r.has(e.toolsetId))&&t()},g=async(e,t,n)=>{u(e),f(null);try{let i=await r.getCatalogItem(`toolset`,e,{...t?{source:t}:{},...n?{version:n}:{}});if(i.manifest.kind!==`toolset`)throw Error(`catalog item is not a toolset`);let a=i.manifest;(a.config??[]).length===0?(await r.installToolset(e,{scope:{kind:`shared`},...n?{version:n}:{}}),h(e)):m(a)}catch(e){f(e instanceof Error?e.message:String(e))}finally{u(null)}};return p?(0,o.jsxs)(`div`,{className:`craftbook-toolset-setup`,children:[(0,o.jsxs)(`h4`,{className:`small`,children:[`Configure `,p.name]}),(0,o.jsx)(i,{fields:p.config??[],submitLabel:`Install`,busy:l===p.id,onSubmit:async e=>{if(!p)return;let t=p.id;u(t),f(null);try{let n={};for(let[t,r]of Object.entries(e.secrets))typeof r==`string`&&(n[t]=r);await r.installToolset(t,{scope:{kind:`shared`},values:e.values,secrets:n}),m(null),h(t)}catch(e){f(e instanceof Error?e.message:String(e))}finally{u(null)}},onCancel:()=>m(null)}),d&&(0,o.jsx)(`p`,{className:`error small`,children:d})]}):(0,o.jsxs)(`div`,{className:`craftbook-toolset-setup`,children:[(0,o.jsx)(`h4`,{className:`small`,children:`This craftbook needs:`}),(0,o.jsx)(`ul`,{className:`commands-panel-list`,children:e.map(e=>{let t=s.has(e.toolsetId);return(0,o.jsx)(`li`,{children:(0,o.jsxs)(`div`,{className:`commands-panel-item`,title:e.reason??e.toolsetId,children:[(0,o.jsx)(`span`,{className:`commands-panel-item-name`,children:e.toolsetId}),e.reason&&(0,o.jsx)(`span`,{className:`commands-panel-item-desc muted small`,children:e.reason}),(0,o.jsx)(`span`,{className:`commands-panel-item-actions`,children:t?(0,o.jsx)(`span`,{className:`muted small`,children:`installed ✓`}):(0,o.jsx)(`button`,{type:`button`,className:`commands-panel-mini`,disabled:l===e.toolsetId,onClick:()=>void g(e.toolsetId,e.sourceId,e.minVersion),children:l===e.toolsetId?`…`:`Install`})})]})},`need:${e.toolsetId}`)})}),d&&(0,o.jsx)(`p`,{className:`error small`,children:d}),(0,o.jsx)(`div`,{className:`toolset-config-actions`,children:(0,o.jsx)(`button`,{type:`button`,className:`gz-link-button`,onClick:n,children:`Cancel`})})]})}export{s as t};
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{t as r}from"./api-BPraLwsh.js";import{t as i}from"./ToolsetConfigForm-gUVMTPR_.js";var a=e(t(),1),o=n();function s({missing:e,onAllInstalled:t,onCancel:n}){let[s,c]=(0,a.useState)(new Set),[l,u]=(0,a.useState)(null),[d,f]=(0,a.useState)(null),[p,m]=(0,a.useState)(null),h=n=>{let r=new Set(s);r.add(n),c(r),e.every(e=>r.has(e.toolsetId))&&t()},g=async(e,t,n)=>{u(e),f(null);try{let i=await r.getCatalogItem(`toolset`,e,{...t?{source:t}:{},...n?{version:n}:{}});if(i.manifest.kind!==`toolset`)throw Error(`catalog item is not a toolset`);let a=i.manifest;(a.config??[]).length===0?(await r.installToolset(e,{scope:{kind:`shared`},...n?{version:n}:{}}),h(e)):m(a)}catch(e){f(e instanceof Error?e.message:String(e))}finally{u(null)}};return p?(0,o.jsxs)(`div`,{className:`craftbook-toolset-setup`,children:[(0,o.jsxs)(`h4`,{className:`small`,children:[`Configure `,p.name]}),(0,o.jsx)(i,{fields:p.config??[],submitLabel:`Install`,busy:l===p.id,onSubmit:async e=>{if(!p)return;let t=p.id;u(t),f(null);try{let n={};for(let[t,r]of Object.entries(e.secrets))typeof r==`string`&&(n[t]=r);await r.installToolset(t,{scope:{kind:`shared`},values:e.values,secrets:n}),m(null),h(t)}catch(e){f(e instanceof Error?e.message:String(e))}finally{u(null)}},onCancel:()=>m(null)}),d&&(0,o.jsx)(`p`,{className:`error small`,children:d})]}):(0,o.jsxs)(`div`,{className:`craftbook-toolset-setup`,children:[(0,o.jsx)(`h4`,{className:`small`,children:`This craftbook needs:`}),(0,o.jsx)(`ul`,{className:`commands-panel-list`,children:e.map(e=>{let t=s.has(e.toolsetId);return(0,o.jsx)(`li`,{children:(0,o.jsxs)(`div`,{className:`commands-panel-item`,title:e.reason??e.toolsetId,children:[(0,o.jsx)(`span`,{className:`commands-panel-item-name`,children:e.toolsetId}),e.reason&&(0,o.jsx)(`span`,{className:`commands-panel-item-desc muted small`,children:e.reason}),(0,o.jsx)(`span`,{className:`commands-panel-item-actions`,children:t?(0,o.jsx)(`span`,{className:`muted small`,children:`installed ✓`}):(0,o.jsx)(`button`,{type:`button`,className:`commands-panel-mini`,disabled:l===e.toolsetId,onClick:()=>void g(e.toolsetId,e.sourceId,e.minVersion),children:l===e.toolsetId?`…`:`Install`})})]})},`need:${e.toolsetId}`)})}),d&&(0,o.jsx)(`p`,{className:`error small`,children:d}),(0,o.jsx)(`div`,{className:`toolset-config-actions`,children:(0,o.jsx)(`button`,{type:`button`,className:`gz-link-button`,onClick:n,children:`Cancel`})})]})}export{s as t};
@@ -1,3 +1,3 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{F as r,I as i,N as a,P as o,j as s,k as c}from"./primitives-DEsn1shf.js";import{t as l}from"./api-BX5xXiFs.js";import{t as u}from"./CraftbookEditor-D5jTzWwF.js";var d=e(t(),1),f=n(),p=[{source:`local`,label:`My craftbooks`,hint:`editable`},{source:`project`,label:`Project`,hint:`read-only`},{source:`bundled`,label:`Gilde catalog`,hint:`read-only — copy to edit`}];function m(){let[e,t]=(0,d.useState)([]),[n,r]=(0,d.useState)(``),[i,a]=(0,d.useState)(null),[o,s]=(0,d.useState)(!1),[c,m]=(0,d.useState)(null),g=(0,d.useCallback)(async()=>{try{let e=await l.listCraftbooks({source:`all`});t(e.craftbooks)}catch(e){m(e.message)}},[]);(0,d.useEffect)(()=>{g()},[g]);let _=(0,d.useMemo)(()=>{let t=n.trim().toLowerCase();return t?e.filter(e=>e.name.toLowerCase().includes(t)||e.id.toLowerCase().includes(t)||(e.description??``).toLowerCase().includes(t)):e},[e,n]),v=(0,d.useCallback)((e,t)=>{s(!1),a({id:e,source:t})},[]);(0,d.useEffect)(()=>{if(i||e.length===0)return;let t=p.map(t=>e.find(e=>e.source===t.source)).find(Boolean)??e[0];t&&a({id:t.id,source:t.source})},[i,e]);let y=(0,d.useCallback)(async e=>{s(!1),await g(),v(e,`local`)},[g,v]),b=(0,d.useMemo)(()=>[...e].sort((e,t)=>e.name.localeCompare(t.name)),[e]);return(0,f.jsxs)(`div`,{className:`tasks-view craftbooks-view`,"data-testid":`craftbooks-view`,children:[(0,f.jsxs)(`div`,{className:`tasks-layout craftbooks-layout`,children:[(0,f.jsxs)(`aside`,{className:`craftbooks-sidebar`,"aria-label":`Craftbook library`,children:[(0,f.jsxs)(`div`,{className:`craftbooks-toolbar`,children:[(0,f.jsxs)(`label`,{className:`craftbooks-search-field`,children:[(0,f.jsx)(`span`,{className:`sr-only`,children:`Search craftbooks`}),(0,f.jsx)(`input`,{type:`search`,className:`craftbook-search`,placeholder:`Search craftbooks…`,value:n,onChange:e=>r(e.target.value)})]}),(0,f.jsx)(`button`,{type:`button`,className:`primary`,onClick:()=>s(!0),children:`+ New craftbook`})]}),c&&(0,f.jsx)(`p`,{className:`error craftbooks-list-error`,children:c}),(0,f.jsxs)(`div`,{className:`tasks-list craftbooks-list`,children:[p.map(e=>{let t=_.filter(t=>t.source===e.source);return t.length===0?null:(0,f.jsxs)(`div`,{className:`craftbook-group`,children:[(0,f.jsxs)(`div`,{className:`craftbook-group-header small muted`,children:[e.label,` `,(0,f.jsxs)(`span`,{className:`craftbook-group-hint`,children:[`· `,e.hint]})]}),(0,f.jsx)(`ul`,{children:t.map(e=>(0,f.jsx)(`li`,{children:(0,f.jsx)(`button`,{type:`button`,className:`task-row${i?.id===e.id&&i?.source===e.source?` task-row-selected`:``}`,onClick:()=>v(e.id,e.source),children:(0,f.jsxs)(`span`,{className:`task-row-body`,children:[(0,f.jsx)(`span`,{className:`task-title`,children:e.name}),(0,f.jsxs)(`span`,{className:`task-row-meta`,children:[(0,f.jsx)(`span`,{className:`task-ref`,children:e.id}),(0,f.jsxs)(`span`,{className:`task-assignee`,children:[e.stepCount,` step`,e.stepCount===1?``:`s`]})]})]})})},`${e.source}:${e.id}`))})]},e.source)}),_.length===0&&(0,f.jsxs)(`p`,{className:`muted craftbooks-empty`,children:[`No craftbooks`,n?` match your search`:` yet`,`.`]})]})]}),(0,f.jsx)(`section`,{className:`task-detail-panel craftbooks-detail`,"aria-label":`Craftbook editor`,children:i?(0,f.jsx)(u,{craftbookId:i.id,source:i.source,onChanged:()=>void g()},`${i.source}:${i.id}`):(0,f.jsx)(`p`,{className:`placeholder`,children:`Select a craftbook to edit it, or start a new one. Gilde books open read-only — make a copy to edit them.`})})]}),(0,f.jsx)(h,{open:o,cloneSources:b,onClose:()=>s(!1),onCreated:y})]})}function h({open:e,cloneSources:t,onClose:n,onCreated:u}){let[p,m]=(0,d.useState)(`blank`),[h,g]=(0,d.useState)(``),[_,v]=(0,d.useState)(!1),[y,b]=(0,d.useState)(``),[x,S]=(0,d.useState)(`Build
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{t as r}from"./api-BPraLwsh.js";import{H as i,J as a,K as o,W as s,Y as c,q as l}from"./primitives-CWrGZpPI.js";import{t as u}from"./CraftbookEditor-DEQRlQ2p.js";var d=e(t(),1),f=n(),p=[{source:`local`,label:`My craftbooks`,hint:`editable`},{source:`project`,label:`Project`,hint:`read-only`},{source:`bundled`,label:`Gilde catalog`,hint:`read-only — copy to edit`}];function m(){let[e,t]=(0,d.useState)([]),[n,i]=(0,d.useState)(``),[a,o]=(0,d.useState)(null),[s,c]=(0,d.useState)(!1),[l,m]=(0,d.useState)(null),g=(0,d.useCallback)(async()=>{try{let e=await r.listCraftbooks({source:`all`});t(e.craftbooks)}catch(e){m(e.message)}},[]);(0,d.useEffect)(()=>{g()},[g]);let _=(0,d.useMemo)(()=>{let t=n.trim().toLowerCase();return t?e.filter(e=>e.name.toLowerCase().includes(t)||e.id.toLowerCase().includes(t)||(e.description??``).toLowerCase().includes(t)):e},[e,n]),v=(0,d.useCallback)((e,t)=>{c(!1),o({id:e,source:t})},[]);(0,d.useEffect)(()=>{if(a||e.length===0)return;let t=p.map(t=>e.find(e=>e.source===t.source)).find(Boolean)??e[0];t&&o({id:t.id,source:t.source})},[a,e]);let y=(0,d.useCallback)(async e=>{c(!1),await g(),v(e,`local`)},[g,v]),b=(0,d.useMemo)(()=>[...e].sort((e,t)=>e.name.localeCompare(t.name)),[e]);return(0,f.jsxs)(`div`,{className:`tasks-view craftbooks-view`,"data-testid":`craftbooks-view`,children:[(0,f.jsxs)(`div`,{className:`tasks-layout craftbooks-layout`,children:[(0,f.jsxs)(`aside`,{className:`craftbooks-sidebar`,"aria-label":`Craftbook library`,children:[(0,f.jsxs)(`div`,{className:`craftbooks-toolbar`,children:[(0,f.jsxs)(`label`,{className:`craftbooks-search-field`,children:[(0,f.jsx)(`span`,{className:`sr-only`,children:`Search craftbooks`}),(0,f.jsx)(`input`,{type:`search`,className:`craftbook-search`,placeholder:`Search craftbooks…`,value:n,onChange:e=>i(e.target.value)})]}),(0,f.jsx)(`button`,{type:`button`,className:`primary`,onClick:()=>c(!0),children:`+ New craftbook`})]}),l&&(0,f.jsx)(`p`,{className:`error craftbooks-list-error`,children:l}),(0,f.jsxs)(`div`,{className:`tasks-list craftbooks-list`,children:[p.map(e=>{let t=_.filter(t=>t.source===e.source);return t.length===0?null:(0,f.jsxs)(`div`,{className:`craftbook-group`,children:[(0,f.jsxs)(`div`,{className:`craftbook-group-header small muted`,children:[e.label,` `,(0,f.jsxs)(`span`,{className:`craftbook-group-hint`,children:[`· `,e.hint]})]}),(0,f.jsx)(`ul`,{children:t.map(e=>(0,f.jsx)(`li`,{children:(0,f.jsx)(`button`,{type:`button`,className:`task-row${a?.id===e.id&&a?.source===e.source?` task-row-selected`:``}`,onClick:()=>v(e.id,e.source),children:(0,f.jsxs)(`span`,{className:`task-row-body`,children:[(0,f.jsx)(`span`,{className:`task-title`,children:e.name}),(0,f.jsxs)(`span`,{className:`task-row-meta`,children:[(0,f.jsx)(`span`,{className:`task-ref`,children:e.id}),(0,f.jsxs)(`span`,{className:`task-assignee`,children:[e.stepCount,` step`,e.stepCount===1?``:`s`]})]})]})})},`${e.source}:${e.id}`))})]},e.source)}),_.length===0&&(0,f.jsxs)(`p`,{className:`muted craftbooks-empty`,children:[`No craftbooks`,n?` match your search`:` yet`,`.`]})]})]}),(0,f.jsx)(`section`,{className:`task-detail-panel craftbooks-detail`,"aria-label":`Craftbook editor`,children:a?(0,f.jsx)(u,{craftbookId:a.id,source:a.source,onChanged:()=>void g()},`${a.source}:${a.id}`):(0,f.jsx)(`p`,{className:`placeholder`,children:`Select a craftbook to edit it, or start a new one. Gilde books open read-only — make a copy to edit them.`})})]}),(0,f.jsx)(h,{open:s,cloneSources:b,onClose:()=>c(!1),onCreated:y})]})}function h({open:e,cloneSources:t,onClose:n,onCreated:u}){let[p,m]=(0,d.useState)(`blank`),[h,g]=(0,d.useState)(``),[_,v]=(0,d.useState)(!1),[y,b]=(0,d.useState)(``),[x,S]=(0,d.useState)(`Build
2
2
  Review`),[C,w]=(0,d.useState)(``),[T,E]=(0,d.useState)(null),[D,O]=(0,d.useState)(!1),[k,A]=(0,d.useState)(null);(0,d.useEffect)(()=>{e&&(m(`blank`),g(``),v(!1),b(``),S(`Build
3
- Review`),w(``),E(null),O(!1),A(null))},[e]);let j=(0,d.useMemo)(()=>{let e=C.trim().toLowerCase();return e?t.filter(t=>t.name.toLowerCase().includes(e)||t.id.toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e)):t},[t,C]),M=e=>{E(e),_||g(`${e.name} copy`)},N=!D&&h.trim().length>0&&(p===`blank`||T!==null),P=async()=>{if(h.trim()){O(!0),A(null);try{let e;if(p===`existing`){if(!T){A(`Pick a craftbook to base this on.`),O(!1);return}let{craftbook:t}=await l.getCraftbook(T.id,{source:T.source}),n=t.steps.map(e=>({...e}));e={name:h.trim(),...y.trim()?{description:y.trim()}:t.description?{description:t.description}:{},steps:n,entryStepId:t.entryStepId,...t.plan?{plan:t.plan}:{},...t.defaultAssignee?{defaultAssignee:t.defaultAssignee}:{},...t.paramSchema?{paramSchema:t.paramSchema}:{},...t.requirements?{requirements:t.requirements}:{},...t.recommends?{recommends:t.recommends}:{},...t.toolsets?{toolsets:t.toolsets}:{}}}else{let t=x.split(/\n|,/).map(e=>e.trim()).filter(Boolean).map(e=>({name:e}));if(t.length===0){A(`A craftbook needs at least one step.`),O(!1);return}e={name:h.trim(),...y.trim()?{description:y.trim()}:{},steps:t}}u((await l.createCraftbook(e)).craftbook.id)}catch(e){A(e.message)}finally{O(!1)}}};return(0,f.jsx)(r,{open:e,onOpenChange:e=>{!e&&!D&&n()},children:(0,f.jsxs)(o,{children:[(0,f.jsx)(a,{}),(0,f.jsxs)(s,{className:`new-craftbook-dialog`,children:[(0,f.jsx)(i,{asChild:!0,children:(0,f.jsx)(`h3`,{children:`New craftbook`})}),(0,f.jsxs)(`div`,{className:`new-craftbook-modes`,role:`radiogroup`,"aria-label":`How to start the craftbook`,children:[(0,f.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":p===`blank`,className:`new-craftbook-mode${p===`blank`?` active`:``}`,onClick:()=>m(`blank`),disabled:D,children:[(0,f.jsx)(`strong`,{children:`Blank`}),(0,f.jsx)(`span`,{className:`muted small`,children:`Start from a fresh list of steps.`})]}),(0,f.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":p===`existing`,className:`new-craftbook-mode${p===`existing`?` active`:``}`,onClick:()=>m(`existing`),disabled:D,children:[(0,f.jsx)(`strong`,{children:`Based on existing`}),(0,f.jsx)(`span`,{className:`muted small`,children:`Copy another craftbook's steps, then edit.`})]})]}),p===`existing`&&(0,f.jsxs)(`div`,{className:`new-craftbook-picker`,children:[(0,f.jsx)(`span`,{className:`new-craftbook-field-label`,children:`Base craftbook`}),(0,f.jsx)(`input`,{type:`text`,className:`craftbook-search`,placeholder:`Search craftbooks…`,value:C,onChange:e=>w(e.target.value),disabled:D}),(0,f.jsxs)(`ul`,{className:`new-craftbook-picker-list`,"aria-label":`Pick a craftbook to copy`,children:[j.map(e=>(0,f.jsx)(`li`,{children:(0,f.jsxs)(`button`,{type:`button`,"aria-pressed":T?.id===e.id&&T?.source===e.source,className:`new-craftbook-picker-row${T?.id===e.id&&T?.source===e.source?` active`:``}`,onClick:()=>M(e),disabled:D,children:[(0,f.jsx)(`span`,{className:`new-craftbook-picker-name`,children:e.name}),(0,f.jsxs)(`span`,{className:`muted small`,children:[e.source,` · `,e.stepCount,` step`,e.stepCount===1?``:`s`]})]})},`${e.source}:${e.id}`)),j.length===0&&(0,f.jsx)(`li`,{className:`muted small new-craftbook-picker-empty`,children:`No craftbooks match.`})]})]}),(0,f.jsxs)(`label`,{children:[`Name`,(0,f.jsx)(`input`,{type:`text`,value:h,onChange:e=>{g(e.target.value),v(!0)},disabled:D})]}),(0,f.jsxs)(`label`,{children:[`Description`,(0,f.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),rows:2,placeholder:p===`existing`?`Leave blank to keep the original's description.`:`What this craftbook is for.`,disabled:D})]}),p===`blank`&&(0,f.jsxs)(`label`,{children:[`Steps (one per line)`,(0,f.jsx)(`textarea`,{value:x,onChange:e=>S(e.target.value),rows:4,disabled:D})]}),k&&(0,f.jsx)(`p`,{className:`gz-dialog-error`,children:k}),(0,f.jsxs)(c,{children:[(0,f.jsx)(`button`,{type:`button`,onClick:n,disabled:D,children:`Cancel`}),(0,f.jsx)(`button`,{type:`button`,className:`primary`,disabled:!N,onClick:()=>void P(),children:D?`Creating…`:`Create`})]})]})]})})}export{m as CraftbooksView};
3
+ Review`),w(``),E(null),O(!1),A(null))},[e]);let j=(0,d.useMemo)(()=>{let e=C.trim().toLowerCase();return e?t.filter(t=>t.name.toLowerCase().includes(e)||t.id.toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e)):t},[t,C]),M=e=>{E(e),_||g(`${e.name} copy`)},N=!D&&h.trim().length>0&&(p===`blank`||T!==null),P=async()=>{if(h.trim()){O(!0),A(null);try{let e;if(p===`existing`){if(!T){A(`Pick a craftbook to base this on.`),O(!1);return}let{craftbook:t}=await r.getCraftbook(T.id,{source:T.source}),n=t.steps.map(e=>({...e}));e={name:h.trim(),...y.trim()?{description:y.trim()}:t.description?{description:t.description}:{},steps:n,entryStepId:t.entryStepId,...t.plan?{plan:t.plan}:{},...t.defaultAssignee?{defaultAssignee:t.defaultAssignee}:{},...t.paramSchema?{paramSchema:t.paramSchema}:{},...t.requirements?{requirements:t.requirements}:{},...t.recommends?{recommends:t.recommends}:{},...t.toolsets?{toolsets:t.toolsets}:{}}}else{let t=x.split(/\n|,/).map(e=>e.trim()).filter(Boolean).map(e=>({name:e}));if(t.length===0){A(`A craftbook needs at least one step.`),O(!1);return}e={name:h.trim(),...y.trim()?{description:y.trim()}:{},steps:t}}u((await r.createCraftbook(e)).craftbook.id)}catch(e){A(e.message)}finally{O(!1)}}};return(0,f.jsx)(a,{open:e,onOpenChange:e=>{!e&&!D&&n()},children:(0,f.jsxs)(l,{children:[(0,f.jsx)(o,{}),(0,f.jsxs)(s,{className:`new-craftbook-dialog`,children:[(0,f.jsx)(c,{asChild:!0,children:(0,f.jsx)(`h3`,{children:`New craftbook`})}),(0,f.jsxs)(`div`,{className:`new-craftbook-modes`,role:`radiogroup`,"aria-label":`How to start the craftbook`,children:[(0,f.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":p===`blank`,className:`new-craftbook-mode${p===`blank`?` active`:``}`,onClick:()=>m(`blank`),disabled:D,children:[(0,f.jsx)(`strong`,{children:`Blank`}),(0,f.jsx)(`span`,{className:`muted small`,children:`Start from a fresh list of steps.`})]}),(0,f.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":p===`existing`,className:`new-craftbook-mode${p===`existing`?` active`:``}`,onClick:()=>m(`existing`),disabled:D,children:[(0,f.jsx)(`strong`,{children:`Based on existing`}),(0,f.jsx)(`span`,{className:`muted small`,children:`Copy another craftbook's steps, then edit.`})]})]}),p===`existing`&&(0,f.jsxs)(`div`,{className:`new-craftbook-picker`,children:[(0,f.jsx)(`span`,{className:`new-craftbook-field-label`,children:`Base craftbook`}),(0,f.jsx)(`input`,{type:`text`,className:`craftbook-search`,placeholder:`Search craftbooks…`,value:C,onChange:e=>w(e.target.value),disabled:D}),(0,f.jsxs)(`ul`,{className:`new-craftbook-picker-list`,"aria-label":`Pick a craftbook to copy`,children:[j.map(e=>(0,f.jsx)(`li`,{children:(0,f.jsxs)(`button`,{type:`button`,"aria-pressed":T?.id===e.id&&T?.source===e.source,className:`new-craftbook-picker-row${T?.id===e.id&&T?.source===e.source?` active`:``}`,onClick:()=>M(e),disabled:D,children:[(0,f.jsx)(`span`,{className:`new-craftbook-picker-name`,children:e.name}),(0,f.jsxs)(`span`,{className:`muted small`,children:[e.source,` · `,e.stepCount,` step`,e.stepCount===1?``:`s`]})]})},`${e.source}:${e.id}`)),j.length===0&&(0,f.jsx)(`li`,{className:`muted small new-craftbook-picker-empty`,children:`No craftbooks match.`})]})]}),(0,f.jsxs)(`label`,{children:[`Name`,(0,f.jsx)(`input`,{type:`text`,value:h,onChange:e=>{g(e.target.value),v(!0)},disabled:D})]}),(0,f.jsxs)(`label`,{children:[`Description`,(0,f.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),rows:2,placeholder:p===`existing`?`Leave blank to keep the original's description.`:`What this craftbook is for.`,disabled:D})]}),p===`blank`&&(0,f.jsxs)(`label`,{children:[`Steps (one per line)`,(0,f.jsx)(`textarea`,{value:x,onChange:e=>S(e.target.value),rows:4,disabled:D})]}),k&&(0,f.jsx)(`p`,{className:`gz-dialog-error`,children:k}),(0,f.jsxs)(i,{children:[(0,f.jsx)(`button`,{type:`button`,onClick:n,disabled:D,children:`Cancel`}),(0,f.jsx)(`button`,{type:`button`,className:`primary`,disabled:!N,onClick:()=>void P(),children:D?`Creating…`:`Create`})]})]})]})})}export{m as CraftbooksView};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{K as r}from"./dist-BPx-FyRH.js";import{t as i}from"./api-BX5xXiFs.js";import{t as a}from"./relative-time-B2kBaekd.js";import{t as o}from"./ConfirmDialog-BHFs6vmJ.js";import{t as s}from"./GitDiffView-DrDrSeBb.js";import{a as c}from"./gitCopy-Dcjz17cJ.js";import{t as l}from"./MarkdownField-D-0Zw7gM.js";import{n as u}from"./useDiffpacks-CK8W_OD_.js";var d=e(t(),1),f=n();function p({paths:e,onConfirm:t,onCancel:n}){return(0,f.jsx)(o,{open:!0,danger:!0,title:`These files changed since the proposal was written`,confirmLabel:`Apply anyway`,message:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`p`,{children:e.length===1?`This file has been edited since the gezel drafted its change:`:`These files have been edited since the gezel drafted its change:`}),(0,f.jsx)(`ul`,{children:e.map(e=>(0,f.jsx)(`li`,{children:(0,f.jsx)(`code`,{children:e})},e))}),(0,f.jsx)(`p`,{children:`The change may no longer do what was intended. Anything that plainly doesn’t fit will still be refused.`})]}),onConfirm:t,onCancel:n})}var m=()=>{};function h(e){switch(e.status){case`drafting`:return`Being written`;case`ready`:return`Ready to review`;case`applied`:return`Applied`;case`partially-applied`:return`Partly applied`;case`dismissed`:return`Dismissed`;case`failed`:return`Didn’t work out`}}function g(e){return e.change===`add`?`New file`:e.change===`delete`?`Delete`:`Edit`}function _({projectId:e}){let{diffpacks:t,loaded:n,busy:o,apply:_,dismiss:v}=u(e),[y,b]=(0,d.useState)(null),[x,S]=(0,d.useState)(null),[C,w]=(0,d.useState)({}),[T,E]=(0,d.useState)(null),[D,O]=(0,d.useState)(null),k=(0,d.useMemo)(()=>t.find(e=>e.packId===y)??t[0]??null,[t,y]);(0,d.useEffect)(()=>{if(!k)return;let t=!1;S(null),w({}),i.getDiffpack(e,k.packId).then(e=>{t||S({packId:k.packId,text:e.notes})}).catch(()=>{t||S({packId:k.packId,text:``})});for(let n of k.files)n.diffArtifact&&i.readProjectArtifact(e,n.diffArtifact).then(e=>{t||w(t=>({...t,[n.path]:e.content}))}).catch(()=>{});return()=>{t=!0}},[e,k]);let A=async(e={})=>{if(!k)return;let t=await _(k.packId,e);if(!t.ok&&t.drifted.length>0&&!e.allowDrifted){O({paths:t.drifted,...e.paths?{subset:e.paths}:{}});return}E(t.message)},j=async()=>{if(k)try{let t=await i.exportDiffpack(e,k.packId),n=URL.createObjectURL(t),a=document.createElement(`a`);a.href=n,a.download=`${r(k.packId)}.zip`,a.click(),URL.revokeObjectURL(n)}catch(e){E(e instanceof Error?e.message:String(e))}};return n&&t.length===0?(0,f.jsx)(`div`,{className:`dp-empty`,children:(0,f.jsx)(`p`,{className:`placeholder`,children:`No change proposals yet. When a gezel fixes something here, the change lands as a proposal you read and apply — your files aren’t touched until you say so.`})}):(0,f.jsxs)(`div`,{className:`dp-layout`,children:[(0,f.jsx)(`div`,{className:`dp-list`,children:t.map(e=>(0,f.jsxs)(`button`,{type:`button`,className:`dp-list-item${e.packId===k?.packId?` dp-list-item-active`:``}`,onClick:()=>b(e.packId),children:[(0,f.jsxs)(`span`,{className:`dp-list-head`,children:[(0,f.jsx)(`code`,{className:`dp-ref`,children:r(e.packId)}),(0,f.jsx)(`span`,{className:`dp-status dp-status-${e.status}`,children:h(e)})]}),(0,f.jsx)(`span`,{className:`dp-list-title`,children:e.title}),(0,f.jsxs)(`span`,{className:`muted small`,children:[c(e.files.length,`file`),` · +`,e.additions,` −`,e.deletions,e.origin.kind===`boekwachter-issue`?` · ${e.origin.issueRefs.join(`, `)}`:``]}),(e.drifted.length>0||e.overlaps.length>0)&&(0,f.jsxs)(`span`,{className:`dp-list-flags`,children:[e.drifted.length>0&&(0,f.jsx)(`span`,{className:`dp-flag dp-flag-drift`,children:`Out of date`}),e.overlaps.length>0&&(0,f.jsxs)(`span`,{className:`dp-flag`,children:[`Overlaps`,` `,[...new Set(e.overlaps.flatMap(e=>e.packIds))].map(r).join(`, `)]})]})]},e.packId))}),(0,f.jsx)(`div`,{className:`dp-detail`,children:k?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(`div`,{className:`dp-detail-head`,children:[(0,f.jsx)(`h3`,{children:k.title}),(0,f.jsxs)(`p`,{className:`muted small`,children:[k.gezelName?`Drafted by ${k.gezelName}`:`Drafted`,k.sealedAt?` · ${a(k.sealedAt)}`:``]})]}),k.drifted.length>0&&(0,f.jsxs)(`output`,{className:`dp-notice`,children:[k.drifted.join(`, `),` changed since this was written, so the proposal may no longer fit. Read the diff before applying.`]}),k.overlaps.length>0&&(0,f.jsxs)(`output`,{className:`dp-notice`,children:[`Another proposal touches`,` `,[...new Set(k.overlaps.map(e=>e.path))].join(`, `),`. Applying one will put the other out of date.`]}),x?.packId===k.packId&&x.text?(0,f.jsx)(l,{value:x.text,readOnly:!0,onCommit:m},k.packId):k.status===`drafting`?(0,f.jsx)(`p`,{className:`muted`,children:`Still being written…`}):null,(0,f.jsx)(`div`,{className:`dp-files`,children:k.files.map(e=>(0,f.jsxs)(`section`,{className:`dp-file`,children:[(0,f.jsxs)(`header`,{className:`dp-file-head`,children:[(0,f.jsx)(`code`,{className:`dp-file-path`,title:e.path,children:e.path}),(0,f.jsxs)(`span`,{className:`muted small`,children:[g(e),` · +`,e.additions,` −`,e.deletions]}),k.status===`ready`&&e.change!==`delete`&&(0,f.jsx)(`button`,{type:`button`,className:`small`,disabled:o===k.packId,onClick:()=>void A({paths:[e.path]}),children:`Apply this file`})]}),e.change===`delete`?(0,f.jsx)(`p`,{className:`git-diff-placeholder muted`,children:`This proposal suggests deleting the file.`}):(0,f.jsx)(s,{diff:C[e.path]})]},e.path))}),T&&(0,f.jsx)(`output`,{className:`dp-toast`,children:T}),(0,f.jsxs)(`div`,{className:`gz-tray dp-actions`,role:`toolbar`,"aria-label":`Actions for ${r(k.packId)}`,children:[(0,f.jsx)(`button`,{type:`button`,className:`gz-key dp-key-apply`,disabled:k.status!==`ready`||o===k.packId,onClick:()=>void A(),children:o===k.packId?`Applying…`:`Apply all`}),(0,f.jsx)(`button`,{type:`button`,className:`gz-key`,onClick:()=>void j(),children:`Export`}),(0,f.jsx)(`button`,{type:`button`,className:`gz-key`,disabled:o===k.packId,onClick:()=>{v(k.packId).then(e=>e&&E(e))},children:`Dismiss`})]})]}):(0,f.jsx)(`p`,{className:`placeholder`,children:`Pick a proposal to read it.`})}),D&&k&&(0,f.jsx)(p,{paths:D.paths,onCancel:()=>O(null),onConfirm:()=>{let e=D.subset;O(null),A({allowDrifted:!0,...e?{paths:e}:{}})}})]})}export{_ as DiffpackReviewView};
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-CEpd2cAX.js";import{X as r}from"./dist-BqGwkOe5.js";import{t as i}from"./api-BPraLwsh.js";import{t as a}from"./relative-time-B2kBaekd.js";import{t as o}from"./ConfirmDialog-Dt1ed4Fh.js";import{t as s}from"./GitDiffView-DrDrSeBb.js";import{a as c}from"./gitCopy-Dcjz17cJ.js";import{t as l}from"./MarkdownField-CK8K3fzj.js";import{n as u}from"./useDiffpacks-Dsnr0wtX.js";var d=e(t(),1),f=n();function p({paths:e,onConfirm:t,onCancel:n}){return(0,f.jsx)(o,{open:!0,danger:!0,title:`These files changed since the proposal was written`,confirmLabel:`Apply anyway`,message:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`p`,{children:e.length===1?`This file has been edited since the gezel drafted its change:`:`These files have been edited since the gezel drafted its change:`}),(0,f.jsx)(`ul`,{children:e.map(e=>(0,f.jsx)(`li`,{children:(0,f.jsx)(`code`,{children:e})},e))}),(0,f.jsx)(`p`,{children:`The change may no longer do what was intended. Anything that plainly doesn’t fit will still be refused.`})]}),onConfirm:t,onCancel:n})}var m=()=>{};function h(e){switch(e.status){case`drafting`:return`Being written`;case`ready`:return`Ready to review`;case`applied`:return`Applied`;case`partially-applied`:return`Partly applied`;case`dismissed`:return`Dismissed`;case`failed`:return`Didn’t work out`}}function g(e){return e.change===`add`?`New file`:e.change===`delete`?`Delete`:`Edit`}function _({projectId:e}){let{diffpacks:t,loaded:n,busy:o,apply:_,dismiss:v}=u(e),[y,b]=(0,d.useState)(null),[x,S]=(0,d.useState)(null),[C,w]=(0,d.useState)({}),[T,E]=(0,d.useState)(null),[D,O]=(0,d.useState)(null),k=(0,d.useMemo)(()=>t.find(e=>e.packId===y)??t[0]??null,[t,y]);(0,d.useEffect)(()=>{if(!k)return;let t=!1;S(null),w({}),i.getDiffpack(e,k.packId).then(e=>{t||S({packId:k.packId,text:e.notes})}).catch(()=>{t||S({packId:k.packId,text:``})});for(let n of k.files)n.diffArtifact&&i.readProjectArtifact(e,n.diffArtifact).then(e=>{t||w(t=>({...t,[n.path]:e.content}))}).catch(()=>{});return()=>{t=!0}},[e,k]);let A=async(e={})=>{if(!k)return;let t=await _(k.packId,e);if(!t.ok&&t.drifted.length>0&&!e.allowDrifted){O({paths:t.drifted,...e.paths?{subset:e.paths}:{}});return}E(t.message)},j=async()=>{if(k)try{let t=await i.exportDiffpack(e,k.packId),n=URL.createObjectURL(t),a=document.createElement(`a`);a.href=n,a.download=`${r(k.packId)}.zip`,a.click(),URL.revokeObjectURL(n)}catch(e){E(e instanceof Error?e.message:String(e))}};return n&&t.length===0?(0,f.jsx)(`div`,{className:`dp-empty`,children:(0,f.jsx)(`p`,{className:`placeholder`,children:`No change proposals yet. When a gezel fixes something here, the change lands as a proposal you read and apply — your files aren’t touched until you say so.`})}):(0,f.jsxs)(`div`,{className:`dp-layout`,children:[(0,f.jsx)(`div`,{className:`dp-list`,children:t.map(e=>(0,f.jsxs)(`button`,{type:`button`,className:`dp-list-item${e.packId===k?.packId?` dp-list-item-active`:``}`,onClick:()=>b(e.packId),children:[(0,f.jsxs)(`span`,{className:`dp-list-head`,children:[(0,f.jsx)(`code`,{className:`dp-ref`,children:r(e.packId)}),(0,f.jsx)(`span`,{className:`dp-status dp-status-${e.status}`,children:h(e)})]}),(0,f.jsx)(`span`,{className:`dp-list-title`,children:e.title}),(0,f.jsxs)(`span`,{className:`muted small`,children:[c(e.files.length,`file`),` · +`,e.additions,` −`,e.deletions,e.origin.kind===`boekwachter-issue`?` · ${e.origin.issueRefs.join(`, `)}`:``]}),(e.drifted.length>0||e.overlaps.length>0)&&(0,f.jsxs)(`span`,{className:`dp-list-flags`,children:[e.drifted.length>0&&(0,f.jsx)(`span`,{className:`dp-flag dp-flag-drift`,children:`Out of date`}),e.overlaps.length>0&&(0,f.jsxs)(`span`,{className:`dp-flag`,children:[`Overlaps`,` `,[...new Set(e.overlaps.flatMap(e=>e.packIds))].map(r).join(`, `)]})]})]},e.packId))}),(0,f.jsx)(`div`,{className:`dp-detail`,children:k?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(`div`,{className:`dp-detail-head`,children:[(0,f.jsx)(`h3`,{children:k.title}),(0,f.jsxs)(`p`,{className:`muted small`,children:[k.gezelName?`Drafted by ${k.gezelName}`:`Drafted`,k.sealedAt?` · ${a(k.sealedAt)}`:``]})]}),k.drifted.length>0&&(0,f.jsxs)(`output`,{className:`dp-notice`,children:[k.drifted.join(`, `),` changed since this was written, so the proposal may no longer fit. Read the diff before applying.`]}),k.overlaps.length>0&&(0,f.jsxs)(`output`,{className:`dp-notice`,children:[`Another proposal touches`,` `,[...new Set(k.overlaps.map(e=>e.path))].join(`, `),`. Applying one will put the other out of date.`]}),x?.packId===k.packId&&x.text?(0,f.jsx)(l,{value:x.text,readOnly:!0,onCommit:m},k.packId):k.status===`drafting`?(0,f.jsx)(`p`,{className:`muted`,children:`Still being written…`}):null,(0,f.jsx)(`div`,{className:`dp-files`,children:k.files.map(e=>(0,f.jsxs)(`section`,{className:`dp-file`,children:[(0,f.jsxs)(`header`,{className:`dp-file-head`,children:[(0,f.jsx)(`code`,{className:`dp-file-path`,title:e.path,children:e.path}),(0,f.jsxs)(`span`,{className:`muted small`,children:[g(e),` · +`,e.additions,` −`,e.deletions]}),k.status===`ready`&&e.change!==`delete`&&(0,f.jsx)(`button`,{type:`button`,className:`small`,disabled:o===k.packId,onClick:()=>void A({paths:[e.path]}),children:`Apply this file`})]}),e.change===`delete`?(0,f.jsx)(`p`,{className:`git-diff-placeholder muted`,children:`This proposal suggests deleting the file.`}):(0,f.jsx)(s,{diff:C[e.path]})]},e.path))}),T&&(0,f.jsx)(`output`,{className:`dp-toast`,children:T}),(0,f.jsxs)(`div`,{className:`gz-tray dp-actions`,role:`toolbar`,"aria-label":`Actions for ${r(k.packId)}`,children:[(0,f.jsx)(`button`,{type:`button`,className:`gz-key dp-key-apply`,disabled:k.status!==`ready`||o===k.packId,onClick:()=>void A(),children:o===k.packId?`Applying…`:`Apply all`}),(0,f.jsx)(`button`,{type:`button`,className:`gz-key`,onClick:()=>void j(),children:`Export`}),(0,f.jsx)(`button`,{type:`button`,className:`gz-key`,disabled:o===k.packId,onClick:()=>{v(k.packId).then(e=>e&&E(e))},children:`Dismiss`})]})]}):(0,f.jsx)(`p`,{className:`placeholder`,children:`Pick a proposal to read it.`})}),D&&k&&(0,f.jsx)(p,{paths:D.paths,onCancel:()=>O(null),onConfirm:()=>{let e=D.subset;O(null),A({allowDrifted:!0,...e?{paths:e}:{}})}})]})}export{_ as DiffpackReviewView};