orc-ai 0.1.53 → 0.1.55

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 (208) hide show
  1. package/README.md +26 -2
  2. package/dist/index.js +769 -591
  3. package/dist/skills/orc-platform/SKILL.md +2 -1
  4. package/dist/skills/orc-platform/references/channels.md +169 -0
  5. package/dist/skills/orc-platform/references/setup.md +3 -3
  6. package/dist/web/assets/Agents-D70pZAkB.js +34 -0
  7. package/dist/web/assets/Attention-DoTjQvwX.js +2 -0
  8. package/dist/web/assets/Audit-BilD5tHL.js +1 -0
  9. package/dist/web/assets/ConfirmDialog-Cyd60q9b.js +1 -0
  10. package/dist/web/assets/Dashboard-BrpclE6i.js +1 -0
  11. package/dist/web/assets/DocumentWorkspace-BirLb0Py.js +1 -0
  12. package/dist/web/assets/{ErrorState-BoQqdsym.js → ErrorState-BrKz7Mii.js} +1 -1
  13. package/dist/web/assets/FileEditor-Cfl56W9G.js +1 -0
  14. package/dist/web/assets/JobWebhooks-csgdKaIu.js +1 -0
  15. package/dist/web/assets/Jobs-BeDH5Nqx.js +1 -0
  16. package/dist/web/assets/Knowledge-Bhe2osQ9.js +1 -0
  17. package/dist/web/assets/Markdown-cNY95m5f.js +2 -0
  18. package/dist/web/assets/MarkdownEditor-CPlYZ0ux.js +2 -0
  19. package/dist/web/assets/{MarkdownRenderer-B5esWp7J.js → MarkdownRenderer-C4od8dIW.js} +9 -9
  20. package/dist/web/assets/PackageCatalog-rIC8EqCV.js +8 -0
  21. package/dist/web/assets/{PackageRunDialog-DxUs3Qnc.js → PackageRunDialog-BPLlcUBW.js} +46 -46
  22. package/dist/web/assets/{Pager-DQCWHQWA.js → Pager-Bc666Oa5.js} +1 -1
  23. package/dist/web/assets/{PriorityBadge-ADp-pD5B.js → PriorityBadge-Ccw4iVk7.js} +1 -1
  24. package/dist/web/assets/Projects-C5tjWMiN.js +3 -0
  25. package/dist/web/assets/ResponsiveFilters-DAeezpA-.js +1 -0
  26. package/dist/web/assets/ResumeActions-Xi3gsryf.js +1 -0
  27. package/dist/web/assets/Rules-u4Yt3UWU.js +18 -0
  28. package/dist/web/assets/{ScratchpadDiagramEditor-D44NiVP_.js → ScratchpadDiagramEditor-CEZLGEOO.js} +7 -7
  29. package/dist/web/assets/Scratchpads-BINR8pcN.js +10 -0
  30. package/dist/web/assets/Sessions-xflxxp3f.js +3 -0
  31. package/dist/web/assets/Settings-C5tS2MvS.js +6 -0
  32. package/dist/web/assets/Skills-QaW-IPD1.js +8 -0
  33. package/dist/web/assets/{SourceEditor-B5CtJBt0.js → SourceEditor-BXHhVnEe.js} +1 -1
  34. package/dist/web/assets/{StatusBadge-CTFDUHuw.js → StatusBadge-ia651_Df.js} +1 -1
  35. package/dist/web/assets/TagInput-BCXK-1YG.js +1 -0
  36. package/dist/web/assets/TaskDetailSheet-BIMcgJGc.js +1 -0
  37. package/dist/web/assets/Tasks-CsBS5O9A.js +22 -0
  38. package/dist/web/assets/Terminals-C0aoP7ar.css +1 -0
  39. package/dist/web/assets/Terminals-D3Yo-p_A.js +3 -0
  40. package/dist/web/assets/ViewHeader-Ce5HQRJu.js +1 -0
  41. package/dist/web/assets/Webhooks-BCKPHvAT.js +1 -0
  42. package/dist/web/assets/{ar-SA-G6X2FPQ2-9uLW-Aib.js → ar-SA-G6X2FPQ2-Dxcs6bnC.js} +1 -1
  43. package/dist/web/assets/arrow-left-vCG_8rdy.js +1 -0
  44. package/dist/web/assets/{az-AZ-76LH7QW2-DOqqo97y.js → az-AZ-76LH7QW2-DzTRmo_5.js} +1 -1
  45. package/dist/web/assets/{bg-BG-XCXSNQG7-BHUaosi9.js → bg-BG-XCXSNQG7-GVnVbOJF.js} +1 -1
  46. package/dist/web/assets/{bn-BD-2XOGV67Q-_-LDSkWx.js → bn-BD-2XOGV67Q-CBnLWZsm.js} +1 -1
  47. package/dist/web/assets/bundle-mjs-geeEdoSy.js +1 -0
  48. package/dist/web/assets/button-CXYVslgR.js +1 -0
  49. package/dist/web/assets/{ca-ES-6MX7JW3Y-D00wQc68.js → ca-ES-6MX7JW3Y-nF87CFCd.js} +1 -1
  50. package/dist/web/assets/check-DOY0CJBh.js +1 -0
  51. package/dist/web/assets/chevron-down-hj6o3_QU.js +1 -0
  52. package/dist/web/assets/{chunk-EIO257PC-BfeJ3EDs.js → chunk-EIO257PC-C5HXDKyY.js} +1 -1
  53. package/dist/web/assets/chunk-OB3PAWPO-1IihCzFx.js +4 -0
  54. package/dist/web/assets/claude-DyzolaFc.svg +3 -0
  55. package/dist/web/assets/client-nzMXason.js +1 -0
  56. package/dist/web/assets/codex-BNO0LSlX.svg +1 -0
  57. package/dist/web/assets/copilot-BALWjOlU.svg +1 -0
  58. package/dist/web/assets/copy-DZWYRnrF.js +1 -0
  59. package/dist/web/assets/{cs-CZ-2BRQDIVT-EB-m3ztC.js → cs-CZ-2BRQDIVT-Cz5r5OEj.js} +1 -1
  60. package/dist/web/assets/cursor-DdfUZ9gB.svg +12 -0
  61. package/dist/web/assets/{da-DK-5WZEPLOC-DWYR6cGM.js → da-DK-5WZEPLOC-B2TNmBRb.js} +1 -1
  62. package/dist/web/assets/{de-DE-XR44H4JA-Ck6sMUnJ.js → de-DE-XR44H4JA-BNOqSnix.js} +1 -1
  63. package/dist/web/assets/dialog-Juth7dP_.js +1 -0
  64. package/dist/web/assets/dist-DxwmSTqz.js +1 -0
  65. package/dist/web/assets/dist-bytwC6rk.js +1 -0
  66. package/dist/web/assets/download-3BU1OMm1.js +1 -0
  67. package/dist/web/assets/{el-GR-BZB4AONW-DTkIqoGp.js → el-GR-BZB4AONW-BzwJhjCV.js} +1 -1
  68. package/dist/web/assets/{en-B4ZKOASM-Boq12EIA.js → en-B4ZKOASM-qumcDTz5.js} +1 -1
  69. package/dist/web/assets/{es-ES-U4NZUMDT-DY7ipP7c.js → es-ES-U4NZUMDT-CYNwXzvM.js} +1 -1
  70. package/dist/web/assets/{eu-ES-A7QVB2H4-D4Y6LEUc.js → eu-ES-A7QVB2H4-Bt_WsfwK.js} +1 -1
  71. package/dist/web/assets/{fa-IR-HGAKTJCU-BlO1bnpc.js → fa-IR-HGAKTJCU-TG6ul0gf.js} +1 -1
  72. package/dist/web/assets/{fi-FI-Z5N7JZ37-CQlPsyFJ.js → fi-FI-Z5N7JZ37-BEmxMqCH.js} +1 -1
  73. package/dist/web/assets/folder-open-BQI4k9Xd.js +1 -0
  74. package/dist/web/assets/{fr-FR-RHASNOE6-DsyF_chP.js → fr-FR-RHASNOE6-DVlOJmrm.js} +1 -1
  75. package/dist/web/assets/{gl-ES-HMX3MZ6V-BGAJPW2y.js → gl-ES-HMX3MZ6V-C51CVUC3.js} +1 -1
  76. package/dist/web/assets/{he-IL-6SHJWFNN-BCFUF5Bi.js → he-IL-6SHJWFNN-BaHbjpvX.js} +1 -1
  77. package/dist/web/assets/{hi-IN-IWLTKZ5I-CWKeCfbn.js → hi-IN-IWLTKZ5I-BnsUhtYU.js} +1 -1
  78. package/dist/web/assets/{highlighted-body-JLMTFACH-CYOy6uZ1.js → highlighted-body-JLMTFACH-CCL_Oa2N.js} +1 -1
  79. package/dist/web/assets/{hu-HU-A5ZG7DT2-fqogn_m9.js → hu-HU-A5ZG7DT2-DJAd0DXQ.js} +1 -1
  80. package/dist/web/assets/{id-ID-SAP4L64H-XFT4nLO5.js → id-ID-SAP4L64H-D_Sp4hWt.js} +1 -1
  81. package/dist/web/assets/{image-GAAHSSAO-CtqEtsMw.js → image-GAAHSSAO-uTNUnk7Z.js} +1 -1
  82. package/dist/web/assets/{index-CMRGRbC9.js → index-C60WCVxH.js} +23 -79
  83. package/dist/web/assets/index-ghfkdpY-.css +1 -0
  84. package/dist/web/assets/{it-IT-JPQ66NNP-CjvUp5j1.js → it-IT-JPQ66NNP-B2VOtgAl.js} +1 -1
  85. package/dist/web/assets/{ja-JP-DBVTYXUO-WaxwOOp1.js → ja-JP-DBVTYXUO-D8n4LcP-.js} +1 -1
  86. package/dist/web/assets/{kaa-6HZHGXH3-BABl6rMV.js → kaa-6HZHGXH3-BvK7fQHB.js} +1 -1
  87. package/dist/web/assets/{kab-KAB-ZGHBKWFO-vrrKDhKa.js → kab-KAB-ZGHBKWFO-CBS-7rLX.js} +1 -1
  88. package/dist/web/assets/{kk-KZ-P5N5QNE5-DV0HT-Fa.js → kk-KZ-P5N5QNE5-D6rLwfEb.js} +1 -1
  89. package/dist/web/assets/{km-KH-HSX4SM5Z-CMzRvYB5.js → km-KH-HSX4SM5Z-DQKGOVey.js} +1 -1
  90. package/dist/web/assets/{ko-KR-MTYHY66A-7XqecPXy.js → ko-KR-MTYHY66A-D-mh0Zog.js} +1 -1
  91. package/dist/web/assets/{ku-TR-6OUDTVRD-D8O0bwyA.js → ku-TR-6OUDTVRD-02Q4uBGz.js} +1 -1
  92. package/dist/web/assets/label-wk_QKooL.js +1 -0
  93. package/dist/web/assets/link-2-Db-kEge7.js +1 -0
  94. package/dist/web/assets/list-D_3Q3U-9.js +1 -0
  95. package/dist/web/assets/{lt-LT-XHIRWOB4-DrK90jMT.js → lt-LT-XHIRWOB4-DLL22EcK.js} +1 -1
  96. package/dist/web/assets/{lv-LV-5QDEKY6T-D7Xl2RRC.js → lv-LV-5QDEKY6T-D3GBaG3q.js} +1 -1
  97. package/dist/web/assets/mermaid-WFAXDIZX-B8XO7yhf.js +1 -0
  98. package/dist/web/assets/{mr-IN-CRQNXWMA-CjH1Q3x7.js → mr-IN-CRQNXWMA--HI3GWMp.js} +1 -1
  99. package/dist/web/assets/{my-MM-5M5IBNSE-CvdwmXcF.js → my-MM-5M5IBNSE-BzpoSrEn.js} +1 -1
  100. package/dist/web/assets/{nb-NO-T6EIAALU-BWMKi1Br.js → nb-NO-T6EIAALU-BpE3Sd7f.js} +1 -1
  101. package/dist/web/assets/{nl-NL-IS3SIHDZ-D5A6sC_f.js → nl-NL-IS3SIHDZ-CVXeRx8i.js} +1 -1
  102. package/dist/web/assets/{nn-NO-6E72VCQL-D-p6QrsB.js → nn-NO-6E72VCQL-c6qBqD3x.js} +1 -1
  103. package/dist/web/assets/{oc-FR-POXYY2M6-6fyqLMv5.js → oc-FR-POXYY2M6-Cau2e1RB.js} +1 -1
  104. package/dist/web/assets/{pa-IN-N4M65BXN-D99Vs_Tb.js → pa-IN-N4M65BXN-BZBndxoR.js} +1 -1
  105. package/dist/web/assets/{percentages-BXMCSKIN-B0BZzQvB.js → percentages-BXMCSKIN-D3Fw5F9S.js} +1 -1
  106. package/dist/web/assets/{pl-PL-T2D74RX3-cl5WZaGT.js → pl-PL-T2D74RX3-Z_GpAanN.js} +1 -1
  107. package/dist/web/assets/{pt-BR-5N22H2LF-T6l12jm6.js → pt-BR-5N22H2LF-BlVpEHGK.js} +1 -1
  108. package/dist/web/assets/{pt-PT-UZXXM6DQ-DnxUMvhO.js → pt-PT-UZXXM6DQ-QuQH0hsZ.js} +1 -1
  109. package/dist/web/assets/{ro-RO-JPDTUUEW-w6wCZHtR.js → ro-RO-JPDTUUEW-BGlQpI3X.js} +1 -1
  110. package/dist/web/assets/{ru-RU-B4JR7IUQ-DMaA4CQ-.js → ru-RU-B4JR7IUQ-CHU0e8TZ.js} +1 -1
  111. package/dist/web/assets/save-CMSSgXiS.js +1 -0
  112. package/dist/web/assets/schemas-CGoaq3B4.js +55 -0
  113. package/dist/web/assets/scratchpad-routes-Dbj7u895.js +1 -0
  114. package/dist/web/assets/scroll-area-D0FZFdju.js +1 -0
  115. package/dist/web/assets/select-Cj-m0J9A.js +1 -0
  116. package/dist/web/assets/{si-LK-N5RQ5JYF-Coe9-5Yb.js → si-LK-N5RQ5JYF-9PXfGp8N.js} +1 -1
  117. package/dist/web/assets/{sk-SK-C5VTKIMK-Bq23BXvP.js → sk-SK-C5VTKIMK-CuzZf_b9.js} +1 -1
  118. package/dist/web/assets/{sl-SI-NN7IZMDC-WZEKy1qu.js → sl-SI-NN7IZMDC-DrOH-WzJ.js} +1 -1
  119. package/dist/web/assets/subset-shared.chunk-CNd4ljrr.js +1 -0
  120. package/dist/web/assets/{subset-worker.chunk-CAbfOFrS.js → subset-worker.chunk-C1uKhPt9.js} +1 -1
  121. package/dist/web/assets/{sv-SE-XGPEYMSR-p1gc_GrE.js → sv-SE-XGPEYMSR-BhIUxUn8.js} +1 -1
  122. package/dist/web/assets/{ta-IN-2NMHFXQM-o8J0vNj1.js → ta-IN-2NMHFXQM-DxBax1RW.js} +1 -1
  123. package/dist/web/assets/table-Cri9EUoE.js +1 -0
  124. package/dist/web/assets/{tabs-DltQVo38.js → tabs-Cv3KJIRq.js} +1 -1
  125. package/dist/web/assets/textarea-Bt1FBmGL.js +1 -0
  126. package/dist/web/assets/{th-TH-HPSO5L25-pt7Zt9xm.js → th-TH-HPSO5L25-DA8qp-YV.js} +1 -1
  127. package/dist/web/assets/{tr-TR-DEFEU3FU-BENdvVvp.js → tr-TR-DEFEU3FU-3u6WSMcx.js} +1 -1
  128. package/dist/web/assets/{uk-UA-QMV73CPH-CenI2hX1.js → uk-UA-QMV73CPH-BbCm-sIk.js} +1 -1
  129. package/dist/web/assets/upload-BZ3CpmMe.js +1 -0
  130. package/dist/web/assets/useDetailRoute-DOhAbdV7.js +1 -0
  131. package/dist/web/assets/useJobs-B2da-s4n.js +1 -0
  132. package/dist/web/assets/useKnowledge-BGBP3GLW.js +1 -0
  133. package/dist/web/assets/useListSelection-ZreW_5e4.js +1 -0
  134. package/dist/web/assets/{useMemories-D0tEN20z.js → useMemories-UaTju2A_.js} +1 -1
  135. package/dist/web/assets/useProjectScope-DtEj9j-P.js +1 -0
  136. package/dist/web/assets/useSessions-BNSlPToV.js +1 -0
  137. package/dist/web/assets/{vi-VN-M7AON7JQ-REgvRLzg.js → vi-VN-M7AON7JQ-DgsVZ_V1.js} +1 -1
  138. package/dist/web/assets/view-params-DD7i9s5g.js +1 -0
  139. package/dist/web/assets/x-CiIWeCBP.js +1 -0
  140. package/dist/web/assets/{zh-CN-LNUGB5OW-Ceo4z5r5.js → zh-CN-LNUGB5OW-DOVvsMem.js} +1 -1
  141. package/dist/web/assets/{zh-HK-E62DVLB3-CFQOn9E1.js → zh-HK-E62DVLB3-BuhcmxhT.js} +1 -1
  142. package/dist/web/assets/{zh-TW-RAJ6MFWO-GpxYPogk.js → zh-TW-RAJ6MFWO-DieBH0AH.js} +1 -1
  143. package/dist/web/index.html +19 -18
  144. package/dist/web/provider-notices.txt +58 -0
  145. package/package.json +1 -1
  146. package/dist/web/assets/Agents-D71JHI2H.js +0 -34
  147. package/dist/web/assets/Attention-C_LKxdwf.js +0 -2
  148. package/dist/web/assets/Audit-BWh52YwS.js +0 -1
  149. package/dist/web/assets/ConfirmDialog-D25Wf6Nc.js +0 -1
  150. package/dist/web/assets/Dashboard-DmYJjKna.js +0 -1
  151. package/dist/web/assets/DocumentWorkspace-CW6S2i4-.js +0 -1
  152. package/dist/web/assets/FileEditor-_z3t0Dbd.js +0 -1
  153. package/dist/web/assets/JobWebhooks-Z4MXZNvH.js +0 -1
  154. package/dist/web/assets/Jobs-B-7i16mV.js +0 -1
  155. package/dist/web/assets/Knowledge-DX3nwzng.js +0 -1
  156. package/dist/web/assets/Markdown-BYChkZ3Z.js +0 -2
  157. package/dist/web/assets/MarkdownEditor-BMQq1cAY.js +0 -2
  158. package/dist/web/assets/PackageCatalog-CYF3tX8J.js +0 -8
  159. package/dist/web/assets/Projects-C2Ei5Q8Q.js +0 -3
  160. package/dist/web/assets/RemoteFolderBrowser-Btryj6gG.js +0 -1
  161. package/dist/web/assets/ResumeActions-1gJa3nsX.js +0 -1
  162. package/dist/web/assets/Rules-CZvA-Eis.js +0 -18
  163. package/dist/web/assets/Scratchpads-DP_v2hc8.js +0 -10
  164. package/dist/web/assets/Sessions-Ctd49sC9.js +0 -3
  165. package/dist/web/assets/Settings-BmbdT6Mp.js +0 -5
  166. package/dist/web/assets/Skills-C_bBvy92.js +0 -8
  167. package/dist/web/assets/TagInput-T6rDuQ7O.js +0 -1
  168. package/dist/web/assets/TaskDetailSheet-BiIQ82AG.js +0 -1
  169. package/dist/web/assets/Tasks-OQmOaNqh.js +0 -24
  170. package/dist/web/assets/Terminals-DISwtHL-.css +0 -1
  171. package/dist/web/assets/Terminals-DVu5OtGU.js +0 -3
  172. package/dist/web/assets/ViewHeader-DHM9SSkD.js +0 -1
  173. package/dist/web/assets/Webhooks-CDNv5fUD.js +0 -1
  174. package/dist/web/assets/arrow-left-Czr-LF4l.js +0 -1
  175. package/dist/web/assets/bundle-mjs-CdK3cBzO.js +0 -1
  176. package/dist/web/assets/button-BHKbOsmj.js +0 -1
  177. package/dist/web/assets/check-hFtKhUSV.js +0 -1
  178. package/dist/web/assets/chevron-down-D2sszSv3.js +0 -1
  179. package/dist/web/assets/client-BwhkVepQ.js +0 -1
  180. package/dist/web/assets/copy-d40YbOUX.js +0 -1
  181. package/dist/web/assets/createLucideIcon-jLuHkL03.js +0 -1
  182. package/dist/web/assets/dist-B9K53eWS.js +0 -1
  183. package/dist/web/assets/dist-ClOxCp9t.js +0 -1
  184. package/dist/web/assets/dist-D3PXSw6Q.js +0 -1
  185. package/dist/web/assets/dist-HH469UWY.js +0 -1
  186. package/dist/web/assets/download-WG9NKrMe.js +0 -1
  187. package/dist/web/assets/folder-open-D5XA0mXE.js +0 -1
  188. package/dist/web/assets/index-BCGI8JzG.css +0 -1
  189. package/dist/web/assets/label-BQ1Lr4sA.js +0 -1
  190. package/dist/web/assets/link-2-DSYfKX_9.js +0 -1
  191. package/dist/web/assets/list-DhKHpsuX.js +0 -1
  192. package/dist/web/assets/mermaid-WFAXDIZX-CiFtUZlz.js +0 -1
  193. package/dist/web/assets/react-dom-DTbwZiiP.js +0 -1
  194. package/dist/web/assets/save-3DxWVsBU.js +0 -1
  195. package/dist/web/assets/scratchpad-routes-B75DnNPp.js +0 -1
  196. package/dist/web/assets/scroll-area-DMjOmHf5.js +0 -1
  197. package/dist/web/assets/select-CBHDS40x.js +0 -1
  198. package/dist/web/assets/subset-shared.chunk-CAD0Eg6H.js +0 -1
  199. package/dist/web/assets/table-ByS-sgsb.js +0 -1
  200. package/dist/web/assets/upload-Djrxq3zy.js +0 -1
  201. package/dist/web/assets/useDetailRoute-C8xQeILG.js +0 -1
  202. package/dist/web/assets/useJobs-CCQUWZt3.js +0 -1
  203. package/dist/web/assets/useKnowledge-DbjT1a0E.js +0 -1
  204. package/dist/web/assets/useListSelection-CgpNqqAb.js +0 -1
  205. package/dist/web/assets/useProjectScope-CZEfU9mq.js +0 -1
  206. package/dist/web/assets/useSessions-C2GU4FkG.js +0 -1
  207. package/dist/web/assets/view-params-BqRwdnv0.js +0 -1
  208. package/dist/web/assets/x-BKorzD7S.js +0 -1
@@ -0,0 +1 @@
1
+ import{a as e}from"./rolldown-runtime-DSDNlrLa.js";import{n as t,t as n}from"./jsx-runtime-CVMpzJz9.js";import{n as r}from"./QueryClientProvider-DlPztvhd.js";import{f as i,m as a,p as o,t as s,u as c}from"./chunk-OB3PAWPO-1IihCzFx.js";import{l,r as u,t as d,u as f}from"./button-CXYVslgR.js";import{a as p,c as m,i as h,l as g,n as _,o as v,s as y,t as b}from"./x-CiIWeCBP.js";import{t as x}from"./label-wk_QKooL.js";import{a as S,i as C,n as w,r as T,t as E}from"./select-Cj-m0J9A.js";import{d as D,n as O}from"./client-nzMXason.js";import{t as k}from"./arrow-left-vCG_8rdy.js";import{t as A}from"./download-3BU1OMm1.js";import{t as j}from"./folder-open-BQI4k9Xd.js";import{t as M}from"./MarkdownEditor-CPlYZ0ux.js";import{t as N}from"./ResponsiveFilters-DAeezpA-.js";import{t as P}from"./upload-BZ3CpmMe.js";import{t as F}from"./Markdown-cNY95m5f.js";import{a as I,c as L,d as R,f as z,i as ee,l as B,o as V,p as te,r as H,t as U,u as ne}from"./schemas-CGoaq3B4.js";import{t as W}from"./textarea-Bt1FBmGL.js";import{a as re,i as G,n as ie,o as ae,t as oe}from"./dialog-Juth7dP_.js";import{$t as se,C as ce,Ct as le,Et as ue,F as de,G as fe,It as K,K as pe,Kt as me,P as he,Qt as ge,S as _e,St as ve,U as ye,W as be,X as xe,Y as Se,Yt as Ce,Zt as we,_n as Te,_t as Ee,bn as De,bt as Oe,cn as ke,en as Ae,ft as je,gn as Me,hn as Ne,ln as Pe,lt as Fe,pn as Ie,qt as Le,rn as Re,st as ze,un as Be,vn as Ve,wt as He,xt as Ue,yn as We}from"./index-C60WCVxH.js";import{n as Ge}from"./wiki-links-A52THGx_.js";import{t as Ke}from"./save-file-3ZpJah8W.js";import{t as qe}from"./ConfirmDialog-Cyd60q9b.js";import{t as Je}from"./ErrorState-BrKz7Mii.js";import{t as Ye}from"./ViewHeader-Ce5HQRJu.js";import{t as Xe}from"./view-params-DD7i9s5g.js";import{t as Ze}from"./EmptyState-YM4VSLR9.js";import{a as Qe,i as $e,n as et,o as tt,r as nt,t as rt}from"./table-Cri9EUoE.js";import{t as it}from"./useProjectScope-DtEj9j-P.js";import{a as at,c as ot,i as st,n as ct,o as lt,r as ut,s as dt,t as ft}from"./useMemories-UaTju2A_.js";import{n as pt,t as mt}from"./DocumentWorkspace-BirLb0Py.js";import{_ as ht,a as gt,c as _t,d as vt,f as yt,g as bt,h as xt,i as St,l as Ct,n as q,o as wt,p as Tt,r as Et,s as Dt,t as Ot,u as kt}from"./useKnowledge-BGBP3GLW.js";import{t as At}from"./TagInput-BCXK-1YG.js";var jt={name:`file-down`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 18v-6`,key:`17g6i2`}],[`path`,{d:`m9 15 3 3 3-3`,key:`1npd3o`}]]};jt.node;var Mt=D(jt),Nt={name:`file-plus`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M9 15h6`,key:`cctwl0`}],[`path`,{d:`M12 18v-6`,key:`17g6i2`}]]};Nt.node;var Pt=D(Nt),Ft={name:`file-up`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 12v6`,key:`3ahymv`}],[`path`,{d:`m15 15-3-3-3 3`,key:`15xj92`}]]};Ft.node;var It=D(Ft),Lt={name:`folder-sync`,size:24,node:[[`path`,{d:`M9 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v.5`,key:`1dkoa9`}],[`path`,{d:`M12 10v4h4`,key:`1czhmt`}],[`path`,{d:`m12 14 1.535-1.605a5 5 0 0 1 8 1.5`,key:`lvuxfi`}],[`path`,{d:`M22 22v-4h-4`,key:`1ewp4q`}],[`path`,{d:`m22 18-1.535 1.605a5 5 0 0 1-8-1.5`,key:`14ync0`}]]};Lt.node;var Rt=D(Lt),zt={name:`panel-right`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]};zt.node;var Bt=D(zt),J=e(t(),1),Y=[`mcp`,`api`,`cli`,`ui`],Vt=[`fetch`,`cited`,`search_hit`],Ht=R().trim().min(1).max(120),Ut=H(U(Y)).max(Y.length).transform(e=>Y.filter(t=>e.includes(t)));B({name:Ht,description:R().trim().max(2e3).default(``),project_id:R().min(1).nullable(),editable_by:Ut.default([...Y]),parser:R().min(1).max(40).nullable().default(null)}).strict(),B({name:Ht.optional(),description:R().trim().max(2e3).optional(),editable_by:Ut.optional(),parser:R().min(1).max(40).nullable().optional()}).strict();var Wt=[`default`,`project`,`global`,`all`],Gt=R().trim().min(1).max(500).refine(e=>!e.startsWith(`/`)&&!e.includes(`\\`)&&!e.includes(`:`)&&!e.includes(`\0`)&&e.split(`/`).every(e=>e&&e!==`.`&&e!==`..`),`Use a relative path with / separators and no . or .. segments`),Kt=H(R().trim().min(1).max(60)).max(30),qt=2097152;B({title:R().trim().min(1).max(300),path:Gt.optional(),description:R().trim().max(2e3).optional(),labels:Kt.default([]),content:R().max(qt),note:R().trim().max(1e3).optional(),derived_from:H(R().min(1)).max(50).default([])}).strict(),B({expected_revision:L().int().min(1),title:R().trim().min(1).max(300).optional(),path:Gt.optional(),description:R().trim().max(2e3).optional(),labels:Kt.optional(),content:R().max(qt).optional(),note:R().trim().max(1e3).optional(),derived_from:H(R().min(1)).max(50).optional()}).strict();var Jt=B({kind:U([`heading`,`paragraph`,`list_item`,`table`,`code`]),text:R(),level:L().int().min(1).max(6).optional(),rows:H(H(R())).optional(),heading_path:H(R()),locator:B({page:L().int().min(1).optional(),sheet:R().optional(),bbox:H(L()).length(4).optional()}).optional()});B({schema_version:V(1),parser:B({id:R(),version:R(),options:ne(R(),te())}),source_sha256:R().regex(/^[0-9a-f]{64}$/),status:U([`ok`,`partial`,`failed`]),language:R().optional(),blocks:H(Jt),markdown:R(),warnings:H(R()),timings_ms:ne(R(),L()).optional(),peak_rss_mb:L().optional()});var Yt=[`auto`,`lexical`,`semantic`,`hybrid`];B({query:R().trim().min(1).max(2e3),scope:U(Wt).default(`default`),kb_ids:H(R().min(1)).max(50).optional(),labels:H(R().min(1)).max(20).optional(),media_types:H(R().min(1)).max(20).optional(),mode:U(Yt).default(`auto`),limit:L().int().min(1).max(50).default(10)}).strict().omit({limit:!0,mode:!0}).extend({mode:U(Yt).default(`auto`),token_budget:L().int().min(500).max(32e3).default(6e3),max_per_document:L().int().min(1).max(10).default(3)}).strict();var Xt=B({old:R().min(1).max(qt),new:R().max(qt),replace_all:ee().optional()}).strict(),Zt=B({start_line:L().int().min(1),end_line:L().int().min(0),new:R().max(qt)}).strict();B({expected_revision:L().int().min(1),edits:H(z([Xt,Zt])).min(1).max(50),note:R().trim().min(1).max(1e3)}).strict();var Qt=[`open`,`resolved`,`dismissed`];B({document_id:R().min(1).nullable().optional(),body:R().trim().min(1).max(1e4)}).strict(),B({status:U([`resolved`,`dismissed`]),reply:R().trim().min(1).max(4e3)}).strict();var $t=I(`type`,[B({type:V(`cron`),cron:R().trim().min(1).max(120)}).strict(),B({type:V(`manual`)}).strict()]);B({instructions:R().trim().min(1).max(2e4).optional(),backend:R().min(1).max(64).regex(/^[a-z][a-z0-9_-]*$/).optional(),schedule:$t.optional(),enabled:ee().optional(),timeout_secs:L().int().min(60).max(7200).optional()}).strict();var en=`0 3 * * *`,X=n();function tn({title:e,testId:t,toggleTestId:n,summary:r,actions:i,expanded:a=!1,onExpandedChange:o,heading:s=`h3`,compact:c=!1,children:u}){let d=(0,J.useId)(),f=u!==void 0&&o!==void 0;return(0,X.jsxs)(`section`,{"data-testid":t,"data-expanded":f?a:void 0,"aria-labelledby":`${d}-heading`,className:`min-w-0 text-sm`,children:[(0,X.jsxs)(`div`,{className:l(`grid min-h-12 min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-0.5 py-1.5`,!c&&`sm:grid-cols-[9rem_minmax(0,1fr)_auto]`),children:[(0,X.jsx)(s,{id:`${d}-heading`,className:`min-w-0 font-medium`,children:f?(0,X.jsxs)(`button`,{type:`button`,"data-testid":n,"aria-expanded":a,"aria-controls":d,className:`-ml-1 flex min-h-9 items-center gap-1.5 rounded px-1 text-left hover:bg-surface-high`,onClick:()=>o(!a),children:[(0,X.jsx)(Be,{size:14,"aria-hidden":!0,className:l(`shrink-0 text-outline transition-transform`,a&&`rotate-90`)}),e]}):(0,X.jsx)(`span`,{className:`flex min-h-9 items-center pl-5`,children:e})}),(0,X.jsx)(`div`,{className:l(`col-span-2 row-start-2 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 pl-5`,!c&&`sm:col-span-1 sm:col-start-2 sm:row-start-1 sm:pl-0`),children:r}),(0,X.jsx)(`div`,{className:l(`col-start-2 row-start-1 flex items-center justify-end gap-1`,!c&&`sm:col-start-3`),children:i})]}),f&&a&&(0,X.jsx)(`div`,{id:d,className:`min-w-0 pb-4 pl-5 pt-1`,children:u})]})}function Z({tone:e}){return(0,X.jsx)(`span`,{"aria-hidden":!0,className:l(`size-1.5 shrink-0 rounded-full`,e===`ok`&&`bg-secondary`,e===`warning`&&`bg-warning`,e===`error`&&`bg-error`,e===`off`&&`bg-muted-foreground`,e===`progress`&&`bg-progress`)})}var nn=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],rn=/^\d+$/,an=e=>e.padStart(2,`0`),on=e=>/^\*\/(\d+)$/.exec(e)?.[1],sn=(e,t)=>e===`1`?`Every ${t}`:`Every ${e} ${t}s`;function cn(e){let[t=``,n=``,r,i,a=``,...o]=e.trim().split(/\s+/);if(o.length||r!==`*`||i!==`*`)return e;if(n===`*`&&a===`*`){if(t===`*`)return`Every minute`;let n=on(t);return n?sn(n,`minute`):rn.test(t)?Number(t)?`Every hour at :${an(t)}`:`Every hour`:e}if(!rn.test(t))return e;let s=on(n);if(s&&a===`*`)return`${sn(s,`hour`)}${Number(t)?` at :${an(t)}`:``}`;if(!rn.test(n))return e;let c=`${an(n)}:${an(t)}`;return a===`*`?`Daily at ${c}`:a===`1-5`?`Weekdays at ${c}`:a===`0,6`||a===`6,0`?`Weekends at ${c}`:/^[0-7]$/.test(a)?`${nn[Number(a)%7]}s at ${c}`:e}var ln=[{name:`minute`,min:0,max:59,names:[]},{name:`hour`,min:0,max:23,names:[]},{name:`day of month`,min:1,max:31,names:[]},{name:`month`,min:1,max:12,names:[`JAN`,`FEB`,`MAR`,`APR`,`MAY`,`JUN`,`JUL`,`AUG`,`SEP`,`OCT`,`NOV`,`DEC`]},{name:`weekday`,min:0,max:7,names:[`SUN`,`MON`,`TUE`,`WED`,`THU`,`FRI`,`SAT`]}];function un(e,t){let n=e=>{let n=t.names.indexOf(e.toUpperCase()),r=n>=0?n+ +(t.min===1):rn.test(e)?Number(e):NaN;return r>=t.min&&r<=t.max?r:NaN};return e.split(`,`).every(e=>{let t=/^(\*|[a-z0-9]+(?:-[a-z0-9]+)?)(?:\/(\d+))?$/i.exec(e);if(!t?.[1]||t[2]!==void 0&&Number(t[2])<1)return!1;if(t[1]===`*`)return!0;let[r=``,i]=t[1].split(`-`);return i===void 0?!Number.isNaN(n(r)):n(r)<=n(i)})}function dn(e){let t=e.trim().split(/\s+/).filter(Boolean);if(!t.length)return`Enter a cron expression.`;if(t.length!==5)return`A cron expression has 5 fields (minute hour day month weekday); this one has ${t.length}.`;for(let[e,n]of ln.entries()){let r=t[e]??``;if(!un(r,n))return`The ${n.name} field "${r}" is not valid. Use a number from ${n.min} to ${n.max}, *, a range (1-5), a list (1,3) or a step (*/2).`}return null}function fn(e){let t=Math.max(0,Math.round((e-Date.now())/1e3));if(t<60)return`in under a minute`;if(t<3600)return`in ${Math.round(t/60)}m`;if(t<86400)return`in ${Math.round(t/3600)}h`;let n=new Date(e);return`${nn[n.getDay()]?.slice(0,3)} ${an(String(n.getHours()))}:${an(String(n.getMinutes()))}`}function pn(e){let t=Math.max(0,Math.round((Date.now()-e)/1e3));return t<60?`just now`:t<3600?`${Math.round(t/60)}m ago`:t<86400?`${Math.round(t/3600)}h ago`:`${Math.round(t/86400)}d ago`}function mn(e){let t=e.last_run?.status;return t===`running`?`progress`:e.schedule.type===`cron`&&!e.enabled?`off`:t===`failed`?`error`:t===`completed`?`ok`:`off`}function hn({kb:e}){let t=St(e.id),[n,r]=(0,J.useState)(null),[i,a]=(0,J.useState)(!1),o=t.data;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(tn,{title:`Digest`,testId:`kb-digest`,toggleTestId:`kb-digest-expand`,expanded:i,onExpandedChange:a,summary:t.error?(0,X.jsx)(`span`,{role:`alert`,className:`text-error`,children:t.error.message}):t.isLoading?(0,X.jsx)(`span`,{className:`text-outline`,children:`Loading…`}):o?(0,X.jsx)(gn,{digest:o}):(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-outline`,"data-testid":`kb-digest-off`,children:[(0,X.jsx)(Z,{tone:`off`}),`Off, documents change only when someone edits them`]}),actions:o?(0,X.jsx)(_n,{kb:e,digest:o,onStarted:()=>a(!0)}):t.data===null?(0,X.jsx)(d,{size:`sm`,variant:`outline`,"data-testid":`kb-digest-add`,onClick:()=>r(`edit`),children:`Set up`}):null,children:o?(0,X.jsx)(vn,{kb:e,digest:o,onEdit:()=>r(`edit`)}):(0,X.jsx)(`p`,{className:`max-w-prose text-outline`,children:`A digest is an agent that reads new memories, sessions and open comments, then keeps the documents in this knowledge base current. It can run on a schedule or only when you start it.`})}),n===`edit`&&(0,X.jsx)(Hn,{kb:e,digest:o??null,onClose:()=>r(null),onRemove:()=>r(`remove`)}),n===`remove`&&(0,X.jsx)(Un,{kb:e,onClose:()=>r(null)})]})}function gn({digest:e}){let t=e.last_run,n=e.schedule.type===`manual`||e.enabled;return(0,X.jsxs)(`span`,{"data-testid":`kb-digest-summary`,className:`inline-flex min-w-0 flex-wrap items-center gap-x-1.5`,children:[(0,X.jsx)(Z,{tone:mn(e)}),(0,X.jsx)(`span`,{"data-testid":`kb-digest-enabled`,children:n?`On`:`Paused`}),(0,X.jsxs)(`span`,{children:[`·`,` `,e.schedule.type===`manual`?`runs when you start it`:(0,X.jsx)(`span`,{title:e.schedule.cron,children:cn(e.schedule.cron)})]}),e.next_run_at!==null&&(0,X.jsxs)(`span`,{className:`text-outline`,"data-testid":`kb-digest-next-run`,children:[`·`,` `,(0,X.jsxs)(`span`,{title:new Date(e.next_run_at).toLocaleString(),children:[`next run `,fn(e.next_run_at)]})]}),(0,X.jsxs)(`span`,{className:`text-outline`,"data-testid":`kb-digest-last-run`,"data-status":t?.status??`never`,children:[`·`,` `,t?t.status===`running`?`running now`:(0,X.jsxs)(`span`,{title:new Date(t.at).toLocaleString(),children:[`last run`,` `,(0,X.jsx)(`span`,{className:t.status===`failed`?`text-error`:void 0,children:t.status===`completed`?`succeeded`:t.status}),` `,pn(t.at)]}):`not run yet`]})]})}function _n({kb:e,digest:t,onStarted:n}){let r=q(),i=Q(),a=t.last_run?.status===`running`;async function o(){await i.run(()=>O.kb.runDigest(e.id))&&(n(),await r())}return(0,X.jsxs)(X.Fragment,{children:[i.error&&(0,X.jsx)(`span`,{role:`alert`,className:`text-error`,"data-testid":`kb-digest-error`,children:i.error}),(0,X.jsx)(d,{size:`sm`,variant:`outline`,"data-testid":`kb-digest-run`,onClick:o,disabled:i.pending||a,children:a?`Running…`:`Run now`})]})}function vn({kb:e,digest:t,onEdit:n}){let r=q(),i=Q(),a=gt(e.id,t);async function o(){await i.run(()=>O.kb.setDigest(e.id,{enabled:!t.enabled}))&&await r()}return(0,X.jsxs)(`div`,{className:`min-w-0 space-y-3`,children:[(0,X.jsxs)(`p`,{className:`max-w-prose text-outline`,children:[`The `,(0,X.jsx)(`span`,{className:`font-mono text-on-surface`,children:t.backend}),` agent reads new memories, sessions and open comments, then updates documents here.`,` `,(0,X.jsx)(`span`,{"data-testid":`kb-digest-open-comments`,children:t.open_comments}),` open`,` `,t.open_comments===1?`comment waits`:`comments wait`,` for the next run.`]}),(0,X.jsxs)(`div`,{className:`-ml-2 flex flex-wrap items-center gap-1`,children:[(0,X.jsx)(d,{size:`sm`,variant:`ghost`,"data-testid":`kb-digest-edit`,onClick:n,children:`Edit instructions and schedule`}),t.schedule.type===`cron`&&(0,X.jsx)(d,{size:`sm`,variant:`ghost`,"data-testid":`kb-digest-toggle`,onClick:o,disabled:i.pending,children:t.enabled?`Pause schedule`:`Resume schedule`}),(0,X.jsx)(d,{size:`sm`,variant:`ghost`,asChild:!0,children:(0,X.jsx)(s,{to:`/jobs/${encodeURIComponent(t.job_id)}`,"data-testid":`kb-digest-job`,children:`Job history`})})]}),i.error&&(0,X.jsx)(`p`,{role:`alert`,className:`text-error`,"data-testid":`kb-digest-error`,children:i.error}),(0,X.jsx)(bn,{runs:a.data??[]})]})}var yn={failed:`error`,success:`ok`,running:`progress`};function bn({runs:e}){return e.length?(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`h4`,{className:`text-xs font-medium text-outline`,children:`Recent runs`}),(0,X.jsx)(`ol`,{"data-testid":`kb-digest-runs`,className:`divide-y divide-outline-variant`,children:e.map(e=>(0,X.jsxs)(`li`,{"data-testid":`kb-digest-run-row`,"data-status":e.status,className:`min-w-0 wrap-break-word py-1.5`,children:[(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(Z,{tone:yn[e.status]??`off`}),e.status]}),(0,X.jsxs)(`span`,{className:`text-outline`,children:[` · `,e.started_at?(0,X.jsx)(`span`,{title:new Date(e.started_at).toLocaleString(),children:pn(e.started_at)}):`not started`,e.trigger_by?` · ${e.trigger_by}`:``]}),e.session_id&&(0,X.jsx)(s,{to:`/audit/${encodeURIComponent(e.session_id)}`,className:`ml-2 text-primary hover:underline`,children:`Session`}),(e.error||e.summary)&&(0,X.jsx)(`span`,{className:`block truncate text-xs text-outline`,title:e.error??e.summary??``,children:e.error??e.summary})]},e.run_id))})]}):(0,X.jsx)(`p`,{className:`text-outline`,children:`No runs yet.`})}var xn=`__global__`,Sn=`__auto__`;function Cn(e){return e instanceof Error?e.message:`Request failed`}function Q(){let[e,t]=(0,J.useState)(!1),[n,r]=(0,J.useState)(null);async function i(e){t(!0),r(null);try{return await e()}catch(e){r(Cn(e));return}finally{t(!1)}}return{pending:e,error:n,run:i,setError:r}}function $({label:e,children:t,hint:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(x,{className:`text-sm text-muted-foreground`,children:e}),t,n&&(0,X.jsx)(`p`,{className:`text-xs text-outline`,children:n})]})}function wn({error:e}){return e?(0,X.jsx)(`p`,{role:`alert`,"data-testid":`kb-dialog-error`,className:`text-sm text-error`,children:e}):null}function Tn({open:e,onClose:t,title:n,wide:r,size:i,children:a}){return(0,X.jsx)(oe,{open:e,onOpenChange:e=>!e&&t(),children:(0,X.jsxs)(ie,{className:`bg-surface border-outline-variant ${i===`xl`?`w-[calc(100%-1rem)] max-w-4xl`:r?`max-w-3xl`:`max-w-md`}`,children:[(0,X.jsx)(re,{children:(0,X.jsx)(ae,{className:`text-base text-on-surface`,children:n})}),a]})})}function En({value:e,onChange:t}){let n=vt();return(0,X.jsxs)(E,{value:e??Sn,onValueChange:e=>t(e===Sn?null:e),children:[(0,X.jsx)(C,{"aria-label":`Parser`,"data-testid":`kb-parser-select`,children:(0,X.jsx)(S,{})}),(0,X.jsxs)(w,{children:[(0,X.jsx)(T,{value:Sn,children:`Workspace default`}),(n.data?.parsers??[]).map(e=>(0,X.jsxs)(T,{value:e.id,disabled:!e.installed,children:[e.label,e.installed?``:` (not installed)`]},e.id))]})]})}var Dn={ui:`Web UI`,cli:`CLI`,api:`REST API`,mcp:`Agents (MCP)`};function On({value:e,onChange:t}){return(0,X.jsxs)(`fieldset`,{className:`space-y-2 rounded-md border border-outline-variant p-3`,children:[(0,X.jsx)(`legend`,{className:`px-1 text-sm text-muted-foreground`,children:`Who can change documents`}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-2`,children:Y.map(n=>(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,X.jsx)(`input`,{type:`checkbox`,"data-testid":`kb-editable-${n}`,checked:e.includes(n),onChange:r=>t(Y.filter(t=>t===n?r.target.checked:e.includes(t)))}),Dn[n]]},n))}),(0,X.jsx)(`p`,{className:`text-xs text-outline`,children:`Every source can read and search. Knowledge base settings change only from the UI, CLI or API.`})]})}function kn({open:e,projectId:t,onClose:n,onCreated:r}){let i=Ee(),a=q(),o=Q(),[s,c]=(0,J.useState)(``),[l,u]=(0,J.useState)(``),[f,p]=(0,J.useState)(t??xn),[m,h]=(0,J.useState)([...Y]),[g,_]=(0,J.useState)(null);async function v(e){e.preventDefault();let t=await o.run(()=>O.kb.create({name:s.trim(),description:l.trim(),project_id:f===xn?null:f,editable_by:m,parser:g}));t&&(await a(),r(t))}return(0,X.jsx)(Tn,{open:e,onClose:n,title:`New knowledge base`,children:(0,X.jsxs)(`form`,{onSubmit:v,className:`space-y-4`,children:[(0,X.jsx)($,{label:`Name`,children:(0,X.jsx)(K,{"aria-label":`Name`,"data-testid":`kb-name-input`,value:s,onChange:e=>c(e.target.value),placeholder:`e.g. Runbooks`,autoFocus:!0})}),(0,X.jsx)($,{label:`Description`,children:(0,X.jsx)(W,{"aria-label":`Description`,value:l,onChange:e=>u(e.target.value),rows:2})}),(0,X.jsx)($,{label:`Belongs to`,hint:`Project knowledge bases are visible in that project; global ones in every project.`,children:(0,X.jsxs)(E,{value:f,onValueChange:p,children:[(0,X.jsx)(C,{"aria-label":`Belongs to`,"data-testid":`kb-owner-select`,children:(0,X.jsx)(S,{})}),(0,X.jsxs)(w,{children:[(0,X.jsx)(T,{value:xn,children:`Global (all projects)`}),(i.data??[]).map(e=>(0,X.jsx)(T,{value:e.id,children:e.name},e.id))]})]})}),(0,X.jsx)(On,{value:m,onChange:h}),(0,X.jsx)($,{label:`Parser for uploads`,children:(0,X.jsx)(En,{value:g,onChange:_})}),(0,X.jsx)(wn,{error:o.error}),(0,X.jsxs)(G,{children:[(0,X.jsx)(d,{type:`button`,variant:`ghost`,onClick:n,children:`Cancel`}),(0,X.jsx)(d,{type:`submit`,"data-testid":`kb-create-submit`,disabled:!s.trim()||o.pending,children:o.pending?`Creating…`:`Create`})]})]})})}function An({kb:e,onClose:t,onDeleted:n}){let r=Ee(),i=q(),a=Q(),[o,s]=(0,J.useState)(e.name),[c,l]=(0,J.useState)(e.description),[u,f]=(0,J.useState)(e.editable_by),[p,m]=(0,J.useState)(e.parser),[h,g]=(0,J.useState)(!1);async function _(n){n.preventDefault(),await a.run(()=>O.kb.update(e.id,{name:o.trim(),description:c.trim(),editable_by:u,parser:p}))&&(await i(),t())}return(0,X.jsxs)(Tn,{open:!0,onClose:t,title:`Knowledge base settings`,children:[(0,X.jsxs)(`form`,{onSubmit:_,className:`space-y-4`,children:[(0,X.jsx)($,{label:`Name`,children:(0,X.jsx)(K,{"aria-label":`Name`,"data-testid":`kb-name-input`,value:o,onChange:e=>s(e.target.value)})}),(0,X.jsx)($,{label:`Description`,children:(0,X.jsx)(W,{"aria-label":`Description`,value:c,onChange:e=>l(e.target.value),rows:2})}),(0,X.jsxs)(`div`,{className:`space-y-1 text-sm`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:`Belongs to`}),(0,X.jsxs)(`p`,{className:`text-outline`,"data-testid":`kb-settings-owner`,children:[e.project_id===null?`Global, visible in every project`:`${r.data?.find(t=>t.id===e.project_id)?.name??`A project`}, visible in that project`,`. Set when the knowledge base is created.`]})]}),(0,X.jsx)(On,{value:u,onChange:f}),(0,X.jsx)($,{label:`Parser for uploads`,hint:`Applies to new uploads and reparses.`,children:(0,X.jsx)(En,{value:p,onChange:m})}),(0,X.jsx)(wn,{error:a.error}),(0,X.jsxs)(G,{className:`gap-2 sm:justify-between`,children:[(0,X.jsxs)(d,{type:`button`,variant:`ghost`,className:`text-error`,"data-testid":`kb-delete`,onClick:()=>g(!0),children:[(0,X.jsx)(Le,{size:14}),`Delete`]}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(d,{type:`button`,variant:`ghost`,onClick:t,children:`Cancel`}),(0,X.jsx)(d,{type:`submit`,"data-testid":`kb-settings-save`,disabled:!o.trim()||a.pending,children:`Save`})]})]})]}),(0,X.jsx)(qe,{open:h,title:`Delete knowledge base`,description:`Delete "${e.name}" with its ${e.document_count} documents, revisions and uploaded files? Registered folders on disk are not touched.`,isPending:a.pending,onCancel:()=>g(!1),onConfirm:async()=>{let t=await a.run(()=>O.kb.remove(e.id));g(!1),t!==void 0&&(await i(),n())}})]})}function jn(e){return`${e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`untitled`}.md`}function Mn(e){return e.match(/^#\s+(.+?)\s*#*\s*$/m)?.[1]?.trim()??``}var Nn=/\.(md|markdown|txt)$/i;function Pn({kb:e,initialFile:t,onClose:n,onCreated:r,onUploadMany:i}){let a=q(),o=Q(),s=Ct(e.id),[c,l]=(0,J.useState)(``),[u,p]=(0,J.useState)(``),[m,h]=(0,J.useState)(``),[g,_]=(0,J.useState)([]),[v,y]=(0,J.useState)(null),[x,S]=(0,J.useState)(!1),C=(0,J.useRef)(null),w=v?``:Mn(u),T=c.trim()||w,E=v?v.name:jn(T),D=v!==null||u.trim()!==``;async function k(e){let t=e.name.replace(/\.[^.]+$/,``);if(!Nn.test(e.name)){y(e),l(t),h(``);return}S(!0);let n=await o.run(()=>e.text());S(!1),n!==void 0&&(y(null),p(n),l(Mn(n)||t),h(/\.txt$/i.test(e.name)?jn(t):e.name))}function A(e){let t=[...e??[]];t.length>1?i(t):t[0]&&k(t[0])}(0,J.useEffect)(()=>{t&&k(t)},[]);async function j(t){t.preventDefault();let n=await o.run(()=>v?O.kb.upload(e.id,{file:v,title:T,path:m.trim()||void 0,labels:g}):O.kb.createDocument(e.id,{title:T,path:m.trim()||E,labels:g,content:D?u:`# ${T}\n\n`}));n&&(await a(),r(n,D))}return(0,X.jsx)(Tn,{open:!0,onClose:n,title:`New document in ${e.name}`,size:`xl`,children:(0,X.jsxs)(`form`,{onSubmit:j,className:`space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-sm text-outline`,children:[(0,X.jsx)(`span`,{children:`Write or paste below, or start from a file.`}),(0,X.jsxs)(d,{type:`button`,size:`sm`,variant:`outline`,"data-testid":`kb-doc-choose-file`,disabled:x||o.pending,onClick:()=>C.current?.click(),children:[(0,X.jsx)(P,{size:16}),x?`Reading…`:`Upload file`]}),(0,X.jsx)(`input`,{ref:C,type:`file`,multiple:!0,hidden:!0,"data-testid":`kb-doc-file-input`,onChange:e=>{A(e.target.files),e.target.value=``}})]}),(0,X.jsx)($,{label:`Title`,hint:w&&!c.trim()?`Taken from the first heading.`:void 0,children:(0,X.jsx)(K,{"aria-label":`Title`,"data-testid":`kb-doc-title-input`,value:c,onChange:e=>l(e.target.value),placeholder:w||`e.g. Deploy runbook`,autoFocus:!0})}),v?(0,X.jsx)($,{label:`File`,hint:`Converted to searchable text after it is added. The original file is kept.`,children:(0,X.jsxs)(`div`,{"data-testid":`kb-doc-file`,className:`flex items-center gap-3 rounded-md border border-surface-highest bg-surface p-3`,children:[(0,X.jsx)(ke,{size:20,className:`shrink-0 text-outline`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm`,title:v.name,children:v.name}),(0,X.jsx)(`span`,{className:`shrink-0 text-xs text-outline`,children:f(v.size)}),(0,X.jsx)(d,{type:`button`,size:`icon`,variant:`ghost`,"aria-label":`Remove ${v.name}`,"data-testid":`kb-doc-file-remove`,onClick:()=>{y(null),l(``)},children:(0,X.jsx)(b,{size:16})})]})}):(0,X.jsx)($,{label:`Content`,hint:`Markdown. Leave empty to start writing in the editor.`,children:(0,X.jsx)(M,{path:m.trim()||E,value:u,onChange:p,testId:`kb-doc-content-input`,label:`Content`,placeholder:`Write or paste Markdown`,initialMode:`edit`,height:`45vh`})}),(0,X.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,X.jsx)($,{label:`Labels`,hint:`Enter, comma or space adds a label.`,children:(0,X.jsx)(At,{"aria-label":`Labels`,"data-testid":`kb-doc-labels-input`,value:g,onChange:_,suggestions:s.data?.labels.map(e=>e.label)})}),(0,X.jsx)($,{label:`Path`,hint:`Optional. Folders come from the path, e.g. guides/setup.md.`,children:(0,X.jsx)(K,{"aria-label":`Path`,"data-testid":`kb-doc-path-input`,value:m,onChange:e=>h(e.target.value),placeholder:E,className:`font-mono text-sm`})})]}),(0,X.jsx)(wn,{error:o.error}),(0,X.jsxs)(G,{children:[(0,X.jsx)(d,{type:`button`,variant:`ghost`,onClick:n,children:`Cancel`}),(0,X.jsx)(d,{type:`submit`,"data-testid":`kb-doc-create-submit`,disabled:!T||o.pending,children:`Create`})]})]})})}function Fn({doc:e,linkedFrom:t,onClose:n,onSaved:r}){let i=q(),a=Q(),[o,s]=(0,J.useState)(e.title),[c,l]=(0,J.useState)(e.path),u=Ct(e.kb_id),[f,p]=(0,J.useState)(e.labels),[m,h]=(0,J.useState)(e.description),g=o.trim()!==e.title||c.trim()!==e.path;async function _(t){t.preventDefault(),await a.run(()=>O.kb.updateDocument(e.id,{expected_revision:e.revision,title:o.trim(),path:c.trim(),labels:f,description:m.trim()}))&&(await i(),r())}return(0,X.jsx)(Tn,{open:!0,onClose:n,title:`Document properties`,children:(0,X.jsxs)(`form`,{onSubmit:_,className:`space-y-4`,children:[(0,X.jsx)($,{label:`Title`,children:(0,X.jsx)(K,{"aria-label":`Title`,"data-testid":`kb-doc-title-input`,value:o,onChange:e=>s(e.target.value)})}),(0,X.jsx)($,{label:`Path`,children:(0,X.jsx)(K,{"aria-label":`Path`,"data-testid":`kb-doc-path-input`,value:c,onChange:e=>l(e.target.value),className:`font-mono text-sm`})}),(0,X.jsx)($,{label:`Labels`,hint:`Enter, comma or space adds a label.`,children:(0,X.jsx)(At,{"aria-label":`Labels`,"data-testid":`kb-doc-labels-input`,value:f,onChange:p,suggestions:u.data?.labels.map(e=>e.label)})}),(0,X.jsx)($,{label:`Description`,children:(0,X.jsx)(W,{"aria-label":`Description`,value:m,onChange:e=>h(e.target.value),rows:2})}),g&&t>0&&(0,X.jsxs)(`p`,{role:`status`,className:`text-sm text-warning`,"data-testid":`kb-rename-warning`,children:[t===1?`1 document links`:`${t} documents link`,` to this document. Links that use the old title or path will show as missing.`]}),(0,X.jsx)(wn,{error:a.error}),(0,X.jsxs)(G,{children:[(0,X.jsx)(d,{type:`button`,variant:`ghost`,onClick:n,children:`Cancel`}),(0,X.jsx)(d,{type:`submit`,"data-testid":`kb-doc-properties-save`,disabled:!o.trim()||a.pending,children:`Save`})]})]})})}var In={daily:`Every day`,weekly:`Once a week`,custom:`Custom cron`,manual:`Manual only`};function Ln(e){let t=e.type===`cron`?e.cron:en,n={plan:`custom`,time:`03:00`,day:`1`,cron:t},r=/^(\d{1,2}) (\d{1,2}) \* \* (\*|[0-6])$/.exec(t.trim().split(/\s+/).join(` `)),[i,a]=[Number(r?.[1]),Number(r?.[2])],o=r&&i<=59&&a<=23?`${String(a).padStart(2,`0`)}:${String(i).padStart(2,`0`)}`:null;return e.type===`manual`?{...n,plan:`manual`,time:o??n.time}:!r?.[3]||!o?n:r[3]===`*`?{...n,plan:`daily`,time:o}:{...n,plan:`weekly`,time:o,day:r[3]}}function Rn({plan:e,time:t,day:n,cron:r}){if(e===`manual`)return null;if(e===`custom`)return r.trim();let[i,a]=t.split(`:`).map(Number);return`${a} ${i} * * ${e===`weekly`?n:`*`}`}function zn(e){return e.plan===`manual`?null:e.plan===`custom`?dn(e.cron):/^\d{2}:\d{2}$/.test(e.time)?null:`Pick a time.`}function Bn(e){let t=cn(e);return t===e?`Runs on this cron schedule`:nn.some(e=>t.startsWith(e))?`Runs ${t}`:`Runs ${t.charAt(0).toLowerCase()}${t.slice(1)}`}function Vn({value:e,onChange:t}){let n=Rn(e),r=zn(e),i=n=>t({...e,...n});return(0,X.jsxs)(`fieldset`,{className:`space-y-3 rounded-md border border-outline-variant p-3`,children:[(0,X.jsx)(`legend`,{className:`px-1 text-sm text-muted-foreground`,children:`When it runs`}),(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,X.jsx)($,{label:`Schedule`,children:(0,X.jsxs)(E,{value:e.plan,onValueChange:e=>i({plan:e,...e===`custom`&&n?{cron:n}:{}}),children:[(0,X.jsx)(C,{"aria-label":`Schedule`,"data-testid":`kb-digest-schedule`,children:(0,X.jsx)(S,{})}),(0,X.jsx)(w,{children:Object.keys(In).map(e=>(0,X.jsx)(T,{value:e,children:In[e]},e))})]})}),e.plan===`weekly`&&(0,X.jsx)($,{label:`Day`,children:(0,X.jsxs)(E,{value:e.day,onValueChange:e=>i({day:e}),children:[(0,X.jsx)(C,{"aria-label":`Day`,"data-testid":`kb-digest-day`,children:(0,X.jsx)(S,{})}),(0,X.jsx)(w,{children:nn.map((e,t)=>(0,X.jsx)(T,{value:String(t),children:e},e))})]})}),(e.plan===`daily`||e.plan===`weekly`)&&(0,X.jsx)($,{label:`Time`,children:(0,X.jsx)(K,{type:`time`,"aria-label":`Time`,"data-testid":`kb-digest-time`,value:e.time,onChange:e=>i({time:e.target.value})})}),e.plan===`custom`&&(0,X.jsx)(`div`,{className:`sm:col-span-2`,children:(0,X.jsx)($,{label:`Cron expression`,hint:`minute hour day month weekday, e.g. 0 */6 * * *`,children:(0,X.jsx)(K,{"aria-label":`Cron expression`,"aria-invalid":r!==null,"data-testid":`kb-digest-cron`,value:e.cron,onChange:e=>i({cron:e.target.value}),className:`font-mono`,autoComplete:`off`})})})]}),(0,X.jsx)(`p`,{"aria-live":`polite`,"data-testid":`kb-digest-schedule-preview`,"data-valid":r===null,className:`text-sm ${r?`text-error`:`text-outline`}`,children:r||(n?(0,X.jsxs)(X.Fragment,{children:[Bn(n),` `,(0,X.jsxs)(`span`,{className:`font-mono text-xs`,children:[`(`,n,`)`]}),`, in the ORC server's time zone.`]}):`Runs only when you start it.`)})]})}function Hn({kb:e,digest:t,onClose:n,onRemove:r}){let i=q(),a=Q(),o=je(),s=wt(!t),[c,l]=(0,J.useState)(t?.instructions??null),[u,f]=(0,J.useState)(t?.backend??`__default__`),[p,m]=(0,J.useState)(()=>Ln(t?.schedule??{type:`cron`,cron:`0 3 * * *`}));(0,J.useEffect)(()=>{c===null&&s.data&&l(s.data.instructions)},[c,s.data]);let h=zn(p);async function g(t){if(t.preventDefault(),h)return a.setError(h);let r=u===`__default__`?o.data?.default_backend:u,s=Rn(p);await a.run(()=>O.kb.setDigest(e.id,{instructions:c?.trim()??``,...r?{backend:r}:{},schedule:s?{type:`cron`,cron:s}:{type:`manual`}}))&&(await i(),n())}let _=c!==null;return(0,X.jsx)(Tn,{open:!0,onClose:n,title:t?`Digest settings`:`Set up a digest`,wide:!0,children:(0,X.jsxs)(`form`,{onSubmit:g,className:`min-w-0 space-y-4`,children:[!e.editable_by.includes(`mcp`)&&(0,X.jsx)(`p`,{className:`text-sm text-warning`,"data-testid":`kb-digest-mcp-hint`,children:`The digest writes through MCP. Allow Agents (MCP) in this knowledge base's settings first.`}),(0,X.jsx)(Vn,{value:p,onChange:m}),(0,X.jsx)(Fe,{value:u,onChange:f,testId:`kb-digest-backend`}),(0,X.jsx)($,{label:`Instructions`,children:_?(0,X.jsx)(M,{path:`digest.md`,value:c,onChange:l,testId:`kb-digest-instructions`,label:`Instructions`,initialMode:`edit`,height:320}):s.error?(0,X.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:Cn(s.error)}):(0,X.jsx)(`p`,{role:`status`,className:`text-sm text-outline`,children:`Loading template…`})}),(0,X.jsx)(wn,{error:a.error}),(0,X.jsxs)(G,{className:`gap-2 sm:justify-between`,children:[t&&r?(0,X.jsxs)(d,{type:`button`,variant:`ghost`,className:`text-error`,"data-testid":`kb-digest-remove`,onClick:r,children:[(0,X.jsx)(Le,{size:14}),`Remove digest`]}):(0,X.jsx)(`span`,{}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(d,{type:`button`,variant:`ghost`,onClick:n,children:`Cancel`}),(0,X.jsx)(d,{type:`submit`,"data-testid":`kb-digest-save`,disabled:!_||!c?.trim()||h!==null||a.pending,children:a.pending?`Saving…`:`Save`})]})]})]})})}function Un({kb:e,onClose:t}){let n=r(),i=Q();async function a(){await i.run(()=>O.kb.removeDigest(e.id,e.name))!==void 0&&(n.setQueryData([Ot,e.id],{digest:null}),await n.invalidateQueries({queryKey:[`kb`]}),t())}return(0,X.jsx)(Tn,{open:!0,onClose:t,title:`Remove digest?`,children:(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsx)(`p`,{className:`text-sm text-outline`,children:`Documents and comments stay. The digest's instructions, schedule, job and run history are removed.`}),(0,X.jsx)(wn,{error:i.error}),(0,X.jsxs)(G,{children:[(0,X.jsx)(d,{type:`button`,variant:`ghost`,onClick:t,children:`Cancel`}),(0,X.jsx)(d,{type:`button`,variant:`destructive`,"data-testid":`kb-digest-remove-confirm`,onClick:a,disabled:i.pending,autoFocus:!0,children:i.pending?`Removing…`:`Remove digest`})]})]})})}var Wn=u(`inline-flex items-center rounded-full border border-border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-hidden focus:ring-2 focus:ring-primary focus:ring-offset-2 `,{variants:{variant:{default:`border-transparent bg-primary text-primary-foreground hover:bg-primary/80 `,secondary:`border-transparent bg-muted text-foreground hover:bg-muted/80 `,destructive:`border-transparent bg-error text-primary-foreground hover:bg-error/80 `,outline:`text-foreground `}},defaultVariants:{variant:`default`}});function Gn({className:e,variant:t,...n}){return(0,X.jsx)(`div`,{className:l(Wn({variant:t}),e),...n})}var Kn={open:`bg-warning`,resolved:`bg-secondary`,dismissed:`bg-muted-foreground`};function qn({status:e}){return(0,X.jsx)(`span`,{"aria-hidden":!0,className:l(`size-1.5 shrink-0 rounded-full`,Kn[e])})}function Jn({kbId:e,documentId:t,onOpenDocument:n,heading:r=`h3`,compact:i=!1}){let[a,o]=(0,J.useState)(!1),[s,c]=(0,J.useState)(null),u=Et(e,{...t?{document_id:t}:{},...s?{status:s}:{}}),d=u.data?.counts,f=d?d.open+d.resolved+d.dismissed:0;function p(e){c(a&&s===e?null:e),o(!0)}return(0,X.jsx)(tn,{title:`Comments`,testId:`kb-comments`,toggleTestId:`kb-comments-toggle`,heading:r,compact:i,expanded:a,onExpandedChange:o,summary:(0,X.jsxs)(X.Fragment,{children:[d&&f===0&&(0,X.jsx)(`span`,{className:`text-outline`,"data-testid":`kb-comments-none`,children:`None yet`}),d&&Qt.filter(e=>d[e]>0).map(e=>(0,X.jsxs)(`button`,{type:`button`,"data-testid":`kb-comments-count-${e}`,"aria-pressed":a&&s===e,"aria-label":`${d[e]} ${e} ${d[e]===1?`comment`:`comments`}`,className:l(`inline-flex min-h-8 items-center gap-1.5 rounded px-1.5`,a&&s===e?`bg-surface-highest text-on-surface`:`text-outline hover:bg-surface-high`),onClick:()=>p(e),children:[(0,X.jsx)(qn,{status:e}),(0,X.jsx)(`span`,{className:`tabular-nums text-on-surface`,children:d[e]}),e]},e)),u.error&&(0,X.jsx)(`span`,{role:`alert`,className:`text-error`,"data-testid":`kb-comments-error`,children:u.error.message})]}),children:(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsx)(Yn,{kbId:e,documentId:t}),s&&u.data?.comments.length===0&&(0,X.jsxs)(`p`,{className:`text-outline`,"data-testid":`kb-comments-empty`,children:[`No `,s,` comments.`]}),(0,X.jsx)(`ul`,{className:`divide-y divide-outline-variant`,children:u.data?.comments.map(e=>(0,X.jsx)(Xn,{comment:e,showDocument:!t,onOpenDocument:n},e.id))})]})})}function Yn({kbId:e,documentId:t}){let n=q(),r=Q(),[i,a]=(0,J.useState)(``);async function o(o){o.preventDefault(),await r.run(()=>O.kb.addComment(e,{body:i.trim(),...t?{document_id:t}:{}}))&&(a(``),await n())}return(0,X.jsxs)(`form`,{onSubmit:o,className:`space-y-2`,children:[(0,X.jsx)(W,{"aria-label":t?`Comment on this document`:`Comment on this knowledge base`,placeholder:t?`Ask for a change to this document`:`Ask for a change`,"data-testid":`kb-comment-input`,value:i,onChange:e=>a(e.target.value),rows:2,maxLength:1e4}),i.trim()&&(0,X.jsx)(d,{type:`submit`,size:`sm`,variant:`outline`,"data-testid":`kb-comment-add`,disabled:r.pending,children:`Add comment`}),r.error&&(0,X.jsx)(`p`,{role:`alert`,className:`text-error`,"data-testid":`kb-comment-add-error`,children:r.error})]})}function Xn({comment:e,showDocument:t,onOpenDocument:n}){let r=q(),i=Q(),[a,o]=(0,J.useState)(null),[s,c]=(0,J.useState)(``);async function l(t){if(t.preventDefault(),!a)return;let n=a;await i.run(()=>O.kb.closeComment(e.id,{status:n,reply:s.trim()}))&&(o(null),c(``),await r())}async function u(){await i.run(()=>O.kb.reopenComment(e.id))&&await r()}return(0,X.jsxs)(`li`,{"data-testid":`kb-comment`,"data-status":e.status,className:`min-w-0 space-y-1 py-2`,children:[(0,X.jsxs)(`p`,{className:`flex min-w-0 flex-wrap items-center gap-x-2 text-xs text-outline`,children:[(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-on-surface`,children:[(0,X.jsx)(qn,{status:e.status}),(0,X.jsx)(`span`,{"data-testid":`kb-comment-status`,children:e.status})]}),(0,X.jsxs)(`span`,{className:`min-w-0 wrap-break-word`,children:[e.source===e.author?e.author:`${e.author} via ${e.source}`,` ·`,` `,new Date(e.created_at).toLocaleString(),t&&e.document_id&&(0,X.jsxs)(X.Fragment,{children:[` · on `,n?(0,X.jsx)(`button`,{type:`button`,className:`text-primary hover:underline`,onClick:()=>e.document_id&&n(e.document_id),children:e.document_title??`a deleted document`}):e.document_title??`a deleted document`]})]})]}),(0,X.jsx)(`p`,{className:`whitespace-pre-wrap wrap-break-word`,children:e.body}),e.reply&&(0,X.jsxs)(`p`,{className:`wrap-break-word text-xs`,"data-testid":`kb-comment-reply-text`,children:[(0,X.jsxs)(`span`,{className:`text-outline`,children:[e.status===`dismissed`?`Dismissed`:`Resolved`,e.resolved_by?` by ${e.resolved_by}`:``,`:`]}),` `,e.reply]}),a?(0,X.jsxs)(`form`,{onSubmit:l,className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(K,{"aria-label":a===`resolved`?`Resolution reply`:`Reason for dismissing`,placeholder:a===`resolved`?`What changed`:`Why not`,"data-testid":`kb-comment-reply`,value:s,onChange:e=>c(e.target.value),maxLength:4e3,autoFocus:!0,className:`min-w-0 flex-1 basis-48`}),(0,X.jsx)(d,{type:`submit`,size:`sm`,"data-testid":`kb-comment-close-submit`,disabled:!s.trim()||i.pending,children:a===`resolved`?`Resolve`:`Dismiss`}),(0,X.jsx)(d,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>{o(null),c(``),i.setError(null)},children:`Cancel`})]}):e.status===`open`?(0,X.jsxs)(`div`,{className:`-ml-2 flex flex-wrap`,children:[(0,X.jsx)(d,{size:`sm`,variant:`ghost`,"data-testid":`kb-comment-resolve`,onClick:()=>o(`resolved`),children:`Resolve`}),(0,X.jsx)(d,{size:`sm`,variant:`ghost`,"data-testid":`kb-comment-dismiss`,onClick:()=>o(`dismissed`),children:`Dismiss`})]}):(0,X.jsx)(d,{size:`sm`,variant:`ghost`,className:`-ml-2`,"data-testid":`kb-comment-reopen`,onClick:u,disabled:i.pending,children:`Reopen`}),i.error&&(0,X.jsx)(`p`,{role:`alert`,className:`text-xs text-error`,"data-testid":`kb-comment-error`,children:i.error})]})}var Zn=e=>`kb:${e}`,Qn={pending:`Processing`,partial:`Partially parsed`,failed:`Failed`,lexical_ready:`Keyword search ready`,semantic_pending:`Embedding`,semantic_ready:`Semantic search ready`};function $n(e){let t=[...e.currentTarget.querySelectorAll(`[role="menuitem"]:not(:disabled)`)],n=t.indexOf(document.activeElement),r=e.key===`ArrowDown`?(n+1)%t.length:e.key===`ArrowUp`?(n-1+t.length)%t.length:e.key===`Home`?0:e.key===`End`?t.length-1:null;r!==null&&t.length&&(e.preventDefault(),t[r]?.focus())}function er({usage:e,testId:t}){return(0,X.jsxs)(`div`,{"data-testid":t,className:`space-y-2`,children:[(0,X.jsxs)(`div`,{className:`text-sm`,children:[(0,X.jsx)(`span`,{"data-testid":`${t}-reads`,className:`font-medium`,children:e.reads}),` `,`reads · `,e.exposures,` search appearances · `,e.distinct_sessions,` sessions`]}),(0,X.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{className:`text-outline`,children:[(0,X.jsx)(`th`,{className:`py-1 text-left font-normal`,children:`Source`}),Vt.map(e=>(0,X.jsx)(`th`,{className:`py-1 text-right font-normal`,children:e===`search_hit`?`listed`:e},e))]})}),(0,X.jsx)(`tbody`,{children:Y.map(n=>(0,X.jsxs)(`tr`,{"data-testid":`${t}-${n}`,className:`border-t border-outline-variant/50`,children:[(0,X.jsx)(`td`,{className:`py-1 uppercase`,children:n}),Vt.map(t=>(0,X.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:e.totals[n][t]},t))]},n))})]}),(0,X.jsxs)(`div`,{className:`text-xs text-outline`,children:[`Last 7 days `,e.window.days_7,` · last 30 days `,e.window.days_30]})]})}function tr({kb:e,doc:t,onHome:n,onOpen:r,onDeleted:i,onReplaceFile:o,detailsOpen:s,onDetailsOpenChange:c}){let u=q(),[p]=a(),m=p.get(`editorMode`),h=Et(t.kb_id,{document_id:t.id}).data?.counts.open??0,[g,_]=(0,J.useState)(!1),[v,y]=(0,J.useState)(!1),[b,x]=(0,J.useState)(!1),S=ue(`lg`),[C,w]=(0,J.useState)(null),T=(0,J.useRef)(null),[E,D]=(0,J.useState)(null),[k,j]=(0,J.useState)(!1),M=(0,J.useRef)(null),N=(0,J.useRef)(t.revision),P=new Map(t.links.filter(e=>e.document_id).map(e=>[Ge(e.target),e.document_id])),F={slugs:[...P.keys()],select:e=>{let t=P.get(e);t&&r(t)}};async function I(e){j(!0),D(null);try{return await e(),await u(),!0}catch(e){return D(e instanceof Error?e.message:`Request failed`),!1}finally{j(!1)}}async function L(){await I(async()=>Ke(await O.kb.original(t.id),t.original_name??t.path.split(`/`).pop()??`document`))}function R(){let e=(t.path.split(`/`).pop()??`document`).replace(/\.(md|markdown)$/i,``);Ke(new Blob([t.content],{type:`text/markdown;charset=utf-8`}),`${e}.md`)}let z=t.origin===`upload`,ee=z||t.origin===`external`&&!t.editable,B=C?.backlinks.filter(e=>!t.backlinks.some(t=>t.document_id===e.document_id))??[],V=(e,t,n,r,i=!1)=>(0,X.jsxs)(`button`,{type:`button`,role:`menuitem`,"data-testid":e,disabled:k,className:l(`flex min-h-9 w-full items-center gap-2 rounded px-2 text-left text-sm outline-hidden hover:bg-surface-highest focus-visible:bg-surface-highest disabled:opacity-50`,i&&`text-error`),onClick:()=>{x(!1),r()},children:[t,n]});return(0,X.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-y-auto lg:flex-row lg:overflow-hidden`,children:[(0,X.jsx)(`article`,{"data-testid":`kb-document`,className:`min-w-0 lg:min-h-0 lg:flex-1 lg:overflow-y-auto`,children:(0,X.jsxs)(`div`,{className:`w-full min-w-0 px-4 pb-16 pt-4 sm:px-8 sm:pt-6`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,X.jsxs)(`nav`,{"aria-label":`Breadcrumb`,className:`flex min-w-0 flex-1 basis-48 items-center gap-1 text-sm text-outline`,children:[(0,X.jsx)(`button`,{type:`button`,"data-testid":`kb-breadcrumb-kb`,className:`min-w-0 max-w-[60%] truncate hover:text-on-surface hover:underline`,onClick:n,children:e.name}),(0,X.jsx)(Be,{size:14,className:`shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`min-w-0 truncate font-mono text-xs`,"data-testid":`kb-document-path`,title:t.path,children:t.path})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,X.jsxs)(d,{size:`sm`,variant:s?`secondary`:`ghost`,"aria-pressed":s,"data-testid":`kb-details-toggle`,onClick:()=>c(!s),children:[(0,X.jsx)(Bt,{size:14}),`Details`,h>0&&(0,X.jsxs)(`span`,{"data-testid":`kb-details-open-comments`,title:`${h} open ${h===1?`comment`:`comments`}`,className:`inline-flex items-center gap-1 text-xs tabular-nums text-outline`,children:[(0,X.jsx)(Z,{tone:`warning`}),h]})]}),(0,X.jsxs)(Te,{open:b,onOpenChange:x,children:[(0,X.jsx)(De,{asChild:!0,children:(0,X.jsx)(d,{size:`icon`,variant:`ghost`,"aria-label":`Document actions`,"aria-haspopup":`menu`,"data-testid":`kb-doc-menu`,children:(0,X.jsx)(Pe,{size:16})})}),(0,X.jsx)(We,{children:(0,X.jsxs)(Ve,{align:`end`,sideOffset:4,collisionPadding:8,role:`menu`,"aria-label":`Document actions`,className:`z-50 w-52 rounded-md border border-outline-variant bg-surface-high p-1 shadow-lg`,onOpenAutoFocus:e=>{e.preventDefault(),e.currentTarget.querySelector(`[role="menuitem"]:not(:disabled)`)?.focus()},onKeyDown:$n,children:[V(`kb-doc-properties`,(0,X.jsx)(Ae,{size:14}),`Title and labels`,()=>{T.current={title:t.title,backlinks:t.backlinks},_(!0)}),!ee&&V(`kb-doc-download-markdown`,(0,X.jsx)(Mt,{size:14}),`Download Markdown`,R),ee&&V(`kb-doc-download`,(0,X.jsx)(A,{size:14}),`Download original`,()=>void L()),z&&V(`kb-doc-reparse`,(0,X.jsx)(ge,{size:14}),`Parse again`,()=>void I(()=>O.kb.reparse(t.id))),z&&V(`kb-doc-replace`,(0,X.jsx)(It,{size:14}),`Replace file`,()=>M.current?.click()),t.origin!==`external`&&V(`kb-doc-delete`,(0,X.jsx)(Le,{size:14}),`Delete document`,()=>y(!0),!0)]})})]})]})]}),(0,X.jsxs)(`header`,{className:`mb-2 mt-4 space-y-2`,children:[(0,X.jsx)(`h1`,{"data-testid":`kb-document-title`,className:`wrap-break-word text-3xl font-medium`,children:t.title}),t.description&&(0,X.jsx)(`p`,{className:`text-outline`,children:t.description}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1.5 text-xs text-outline`,children:[t.labels.length>0&&(0,X.jsx)(`span`,{className:`flex flex-wrap gap-1`,children:t.labels.map(e=>(0,X.jsx)(Gn,{variant:`secondary`,"data-testid":`kb-document-label`,children:e},e))}),t.parse_state!==`ok`&&(0,X.jsxs)(`span`,{className:l(`inline-flex items-center gap-1.5`,t.parse_state===`failed`&&`text-error`),children:[(0,X.jsx)(Z,{tone:t.parse_state===`failed`?`error`:t.parse_state===`partial`?`warning`:`progress`}),(0,X.jsx)(`span`,{"data-testid":`kb-parse-state`,children:Qn[t.parse_state]})]}),t.folder_sync&&(0,X.jsx)(`span`,{"data-testid":`kb-folder-sync`,title:t.folder_sync===`following`?`Copied from a synced folder; scans pick up changes to the file`:`Edited in ORC; scans no longer change this copy`,children:t.folder_sync===`following`?`Follows folder file`:`Edited, no longer synced`}),t.stale&&(0,X.jsx)(`span`,{className:`text-warning`,"data-testid":`kb-document-stale`,children:`Stale: a source changed`}),(0,X.jsxs)(`span`,{children:[`Updated `,new Date(t.updated_at).toLocaleDateString(),` by `,t.updated_by]})]})]}),t.warnings.length>0&&(0,X.jsx)(`ul`,{"data-testid":`kb-document-warnings`,className:`mb-2 space-y-1 text-sm text-warning`,children:t.warnings.map(e=>(0,X.jsxs)(`li`,{className:`flex gap-2`,children:[(0,X.jsx)(me,{size:14,className:`mt-0.5 shrink-0`}),e]},e))}),z&&(0,X.jsxs)(`p`,{className:`mb-2 text-sm text-outline`,children:[`Text parsed from `,t.original_name??`the upload`,` (`,f(t.size_bytes),t.parser?`, ${t.parser.id} ${t.parser.version}`:``,`). Replace the file to change it.`]}),t.folder_sync===`following`&&(m===`edit`||m===`split`)&&(0,X.jsx)(`p`,{role:`status`,"data-testid":`kb-folder-sync-warning`,className:`mb-2 text-sm text-warning`,children:`This copy follows a file in a synced folder. Saving here stops it following that file; later changes to the file will not reach it.`}),E&&(0,X.jsx)(`p`,{role:`alert`,"data-testid":`kb-document-error`,className:`mb-2 text-sm text-error`,children:E}),C&&B.length>0&&(0,X.jsxs)(`div`,{role:`status`,"data-testid":`kb-rename-broken-links`,className:`mb-2 flex flex-wrap items-center gap-x-2 text-sm text-warning`,children:[(0,X.jsx)(me,{size:14,className:`shrink-0`,"aria-hidden":!0}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[B.length===1?`1 document`:`${B.length} documents`,` linked to “`,C.title,`” by its old title or path; those links now show as missing:`,` `,B.map((e,t)=>(0,X.jsxs)(`span`,{children:[t>0&&`, `,(0,X.jsx)(`button`,{type:`button`,className:`underline underline-offset-2 hover:text-on-surface`,onClick:()=>r(e.document_id),children:e.title})]},e.document_id))]}),(0,X.jsx)(d,{size:`sm`,variant:`ghost`,onClick:()=>w(null),children:`Dismiss`})]}),(0,X.jsx)(mt,{documentId:Zn(t.id),path:t.editable?t.path:`${t.path}.md`,content:t.content,wikiLinks:F,testId:`kb-document-content`,layout:`page`,pageTitle:t.title,hideFrontmatter:!0,onSave:t.editable?async(e,n)=>{try{let r=await O.kb.updateDocument(t.id,{expected_revision:n===t.content?t.revision:N.current,content:e});return N.current=r.revision,e}finally{await u()}}:void 0},Zn(t.id))]})}),s&&S&&(0,X.jsx)(rr,{doc:t,onOpen:r}),!S&&(0,X.jsx)(be,{open:s,onOpenChange:c,children:(0,X.jsxs)(pe,{defaultWidth:360,resizeKey:`kb-properties`,"aria-describedby":void 0,children:[(0,X.jsx)(Se,{className:`py-3`,children:(0,X.jsx)(xe,{children:`Details`})}),(0,X.jsx)(fe,{className:`p-0 sm:p-0`,children:(0,X.jsx)(rr,{doc:t,onOpen:(e,t)=>{c(!1),r(e,t)}})})]})}),(0,X.jsx)(`input`,{ref:M,type:`file`,hidden:!0,"data-testid":`kb-doc-replace-input`,onChange:e=>{let t=e.target.files?.[0];t&&o(t),e.target.value=``}}),g&&(0,X.jsx)(Fn,{doc:t,linkedFrom:t.backlinks.length,onClose:()=>_(!1),onSaved:()=>{_(!1),w(T.current)}}),(0,X.jsx)(qe,{open:v,title:`Delete document`,description:`Delete "${t.title}" and its revision history${z?` and uploaded file`:``}?`,isPending:k,onCancel:()=>y(!1),onConfirm:async()=>{y(!1),await I(()=>O.kb.removeDocument(t.id))&&i()}})]})}function nr({title:e,children:t}){return(0,X.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,X.jsx)(`h2`,{className:`text-sm font-medium text-outline`,children:e}),t]})}function rr({doc:e,onOpen:t}){let n=_t(e.id),r=yt(e.id),i=`block min-h-8 w-full wrap-break-word text-left text-primary hover:underline`;return(0,X.jsxs)(`aside`,{"data-testid":`kb-document-details`,"aria-label":`Document details`,className:`w-full shrink-0 space-y-6 p-4 text-sm lg:min-h-0 lg:w-80 lg:overflow-y-auto lg:border-l lg:border-outline-variant`,children:[e.outline.length>0&&(0,X.jsx)(nr,{title:`On this page`,children:(0,X.jsx)(`nav`,{"aria-label":`Outline`,className:`space-y-0.5`,children:e.outline.map(n=>(0,X.jsx)(`button`,{type:`button`,className:`block min-h-7 w-full truncate text-left text-outline hover:text-on-surface`,style:{paddingLeft:`${(n.level-1)*.75}rem`},onClick:()=>t(e.id,n.text),children:n.text},`${n.block}-${n.text}`))})}),e.links.length>0&&(0,X.jsx)(nr,{title:`Links to (${e.links.length})`,children:e.links.map(e=>e.document_id?(0,X.jsx)(`button`,{type:`button`,"data-testid":`kb-outgoing-link`,className:i,onClick:()=>t(e.document_id),children:e.title??e.target},e.target):(0,X.jsxs)(`p`,{className:`py-1 text-outline`,"data-testid":`kb-unresolved-link`,children:[e.target,` `,(0,X.jsx)(`span`,{className:`text-xs`,children:`(no such document)`})]},e.target))}),e.backlinks.length>0&&(0,X.jsx)(nr,{title:`Linked from (${e.backlinks.length})`,children:e.backlinks.map(e=>(0,X.jsx)(`button`,{type:`button`,"data-testid":`kb-backlink`,className:i,onClick:()=>t(e.document_id),children:e.title},e.document_id))}),(0,X.jsx)(`div`,{className:`border-y border-outline-variant`,children:(0,X.jsx)(Jn,{kbId:e.kb_id,documentId:e.id,heading:`h2`,compact:!0})}),(0,X.jsxs)(`details`,{"data-testid":`kb-doc-history`,className:`group`,children:[(0,X.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer list-none items-center gap-1.5 font-medium [&::-webkit-details-marker]:hidden`,children:[(0,X.jsx)(Be,{size:14,"aria-hidden":!0,className:`text-outline transition-transform group-open:rotate-90`}),`Usage and history`]}),(0,X.jsxs)(`div`,{className:`mt-3 space-y-5 pl-5`,children:[n.data?(0,X.jsx)(er,{usage:n.data,testId:`kb-doc-usage`}):(0,X.jsx)(`p`,{className:`text-outline`,children:n.error?`Usage unavailable`:`Loading…`}),(0,X.jsx)(`ol`,{className:`space-y-2`,"data-testid":`kb-revisions`,children:r.data?.map(e=>(0,X.jsxs)(`li`,{"data-testid":`kb-revision`,children:[(0,X.jsxs)(`div`,{children:[`Revision `,e.revision,` · `,e.actor,(0,X.jsxs)(`span`,{className:`text-outline`,children:[` via `,e.source]})]}),(0,X.jsxs)(`div`,{className:`text-xs text-outline`,children:[new Date(e.created_at).toLocaleString(),e.note?` · ${e.note}`:``]})]},e.revision))}),(0,X.jsxs)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 text-xs text-outline`,children:[(0,X.jsx)(`dt`,{children:`Search`}),(0,X.jsx)(`dd`,{"data-testid":`kb-index-state`,children:Qn[e.index_state]??e.index_state}),(0,X.jsx)(`dt`,{children:`Origin`}),(0,X.jsx)(`dd`,{children:e.origin}),(0,X.jsx)(`dt`,{children:`Type`}),(0,X.jsx)(`dd`,{children:e.media_type}),(0,X.jsx)(`dt`,{children:`Size`}),(0,X.jsx)(`dd`,{children:f(e.size_bytes)}),(0,X.jsx)(`dt`,{children:`Updated`}),(0,X.jsxs)(`dd`,{children:[new Date(e.updated_at).toLocaleString(),` by `,e.updated_by]}),(0,X.jsx)(`dt`,{children:`ID`}),(0,X.jsx)(`dd`,{className:`break-all font-mono`,children:e.id})]})]})]})]})}function ir(e){return`${e.added} added · ${e.updated} updated · ${e.missing} missing${e.errors.length?` · ${e.errors.length} errors: ${e.errors.slice(0,3).join(`; `)}`:``}`}var ar=(e,t,n)=>`${e} ${e===1?t:n}`;function or(){return/win/i.test(navigator.platform)?`Choose a folder or type its full path, e.g. C:\\notes`:/mac/i.test(navigator.platform)?`Choose a folder or type its full path, e.g. /Users/you/notes`:`Choose a folder or type its full path, e.g. /home/you/notes`}function sr(e){let t=e.document_count-e.edited_count,n=t?`${ar(t,`synced copy is`,`synced copies are`)} removed from this knowledge base`:`No synced copies are removed`,r=e.edited_count?`; ${ar(e.edited_count,`edited copy is`,`edited copies are`)} kept as documents`:``;return`Stop syncing ${e.root_path}? ${n}${r}. Files on disk are not touched.`}function cr(e){return e.replace(/[\\/]+$/,``).split(/[\\/]/).pop()||e}function lr({kb:e}){let t=xt(e.id),n=q(),r=Q(),[i,a]=(0,J.useState)(!1),[o,s]=(0,J.useState)(``),[c,l]=(0,J.useState)(`**/*.md`),[u,f]=(0,J.useState)(null),[p,m]=(0,J.useState)(null),[h,g]=(0,J.useState)(!1),[_,v]=(0,J.useState)(!1),y=t.data??[],b=y.filter(e=>e.last_error).length,x=y.reduce((e,t)=>e+t.document_count,0);function S(){a(!0),g(!0)}function C(){g(!1),s(``),r.setError(null),y.length===0&&a(!1)}async function w(){v(!0),r.setError(null);try{let{path:e}=await O.terminals.pickFolder(o.trim()||void 0);e&&s(e)}catch(e){r.setError(e instanceof Error?e.message:String(e))}finally{v(!1)}}async function T(t){t.preventDefault();let i=await r.run(()=>O.kb.addSource(e.id,{root_path:o.trim(),pattern:c.trim()||`**/*.md`}));i&&(s(``),g(!1),f(ir(i.scan)),await n())}return(0,X.jsxs)(tn,{title:`Synced folders`,testId:`kb-folders`,toggleTestId:`kb-sources`,expanded:i,onExpandedChange:e=>{a(e),g(e&&y.length===0)},summary:t.isLoading?(0,X.jsx)(`span`,{className:`text-outline`,children:`Loading…`}):y.length===0?(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-outline`,"data-testid":`kb-folders-none`,children:[(0,X.jsx)(Z,{tone:`off`}),`None`]}):(0,X.jsxs)(`span`,{className:`inline-flex min-w-0 max-w-full items-center gap-1.5`,"data-testid":`kb-folders-summary`,children:[(0,X.jsx)(Z,{tone:b?`error`:`ok`}),y.length===1?(0,X.jsx)(`span`,{className:`min-w-0 truncate`,title:y[0]?.root_path,children:cr(y[0]?.root_path??``)}):`${y.length} folders`,(0,X.jsxs)(`span`,{className:`shrink-0 text-outline`,children:[`· `,x,` `,x===1?`document`:`documents`,b?` · ${b} failing`:``]})]}),actions:y.length===0&&!i?(0,X.jsx)(d,{size:`sm`,variant:`outline`,"data-testid":`kb-folders-add`,onClick:S,children:`Add folder`}):null,children:[(0,X.jsxs)(`div`,{className:`min-w-0 space-y-3`,children:[(0,X.jsx)(`p`,{className:`max-w-prose text-outline`,children:`Matching files are copied in and kept in sync: ORC rescans every minute while the daemon runs, or when you choose Scan now. A copy you edit here stops following its file. ORC never writes to the folder.`}),y.length>0&&(0,X.jsx)(`ul`,{className:`divide-y divide-outline-variant`,"data-testid":`kb-sources-list`,children:y.map(e=>(0,X.jsxs)(`li`,{"data-testid":`kb-source-row`,className:`flex min-w-0 flex-wrap items-center gap-2 py-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1 basis-56`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:cr(e.root_path)}),(0,X.jsx)(`div`,{className:`break-all font-mono text-xs text-outline`,children:e.root_path}),(0,X.jsxs)(`div`,{className:`text-xs text-outline`,children:[e.pattern,` · `,ar(e.document_count,`document`,`documents`),e.edited_count?` (${e.edited_count} edited)`:``,` ·`,` `,e.last_scan_at?(0,X.jsxs)(`span`,{title:new Date(e.last_scan_at).toLocaleString(),children:[`scanned `,pn(e.last_scan_at)]}):`not scanned yet`]}),e.last_error&&(0,X.jsx)(`div`,{className:`text-xs text-error`,children:e.last_error})]}),(0,X.jsxs)(d,{variant:`ghost`,size:`sm`,"data-testid":`kb-source-scan`,disabled:r.pending,onClick:async()=>{let t=await r.run(()=>O.kb.scanSource(e.id));t&&f(ir(t)),await n()},children:[(0,X.jsx)(Rt,{size:14}),`Scan now`]}),(0,X.jsx)(d,{variant:`ghost`,size:`sm`,title:`Stop syncing ${e.root_path}`,"data-testid":`kb-source-remove`,onClick:()=>m(e),children:`Stop syncing`})]},e.id))}),u&&(0,X.jsx)(`p`,{role:`status`,"data-testid":`kb-source-result`,className:`text-outline`,children:u}),h?(0,X.jsxs)(`form`,{onSubmit:T,className:`min-w-0 space-y-3`,"data-testid":`kb-source-form`,children:[(0,X.jsxs)(`div`,{className:`grid min-w-0 gap-3 sm:grid-cols-[minmax(0,1fr)_12rem]`,children:[(0,X.jsx)($,{label:`Folder path`,hint:or(),children:(0,X.jsxs)(`div`,{className:`flex min-w-0 gap-2`,children:[(0,X.jsx)(K,{"aria-label":`Folder path`,"data-testid":`kb-source-path-input`,value:o,onChange:e=>s(e.target.value),className:`min-w-0 font-mono text-sm`,autoFocus:!0}),(0,X.jsxs)(d,{type:`button`,variant:`outline`,"data-testid":`kb-source-choose-folder`,onClick:w,disabled:_,className:`shrink-0`,children:[(0,X.jsx)(j,{size:14}),_?`Choosing…`:`Choose folder`]})]})}),(0,X.jsx)($,{label:`File pattern`,hint:`e.g. *.md, **/*.md`,children:(0,X.jsx)(K,{"aria-label":`File pattern`,"data-testid":`kb-source-pattern-input`,value:c,onChange:e=>l(e.target.value),className:`font-mono text-sm`})})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsx)(d,{type:`submit`,size:`sm`,variant:`outline`,"data-testid":`kb-source-add`,disabled:!o.trim()||r.pending,children:`Add folder`}),(0,X.jsx)(d,{type:`button`,size:`sm`,variant:`ghost`,"data-testid":`kb-source-cancel`,onClick:C,children:`Cancel`})]})]}):y.length>0&&(0,X.jsxs)(d,{size:`sm`,variant:`ghost`,className:`-ml-2`,"data-testid":`kb-folders-add-another`,onClick:()=>g(!0),children:[(0,X.jsx)(se,{size:14}),`Add another folder`]}),(0,X.jsx)(wn,{error:r.error})]}),(0,X.jsx)(qe,{open:p!==null,title:`Stop syncing folder`,description:p?sr(p):``,confirmLabel:`Stop syncing`,variant:`warning`,isPending:r.pending,onCancel:()=>m(null),onConfirm:async()=>{let e=p;m(null),e&&await r.run(()=>O.kb.removeSource(e.id)),await n()}})]})}var ur=8;function dr(e,t,n){return n===`title`?e.title.localeCompare(t.title):n===`updated`?e.updated_at-t.updated_at:e.reads-t.reads}function fr(e,t){if(e.key===t)return e.desc?`descending`:`ascending`}function pr(e){let t=new Date(e);return t.toDateString()===new Date().toDateString()?t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):t.toLocaleDateString([],{month:`short`,day:`numeric`,year:`numeric`})}function mr({kb:e,owner:t,listing:n,label:r,onLabel:i,onOpen:a,onNewDocument:o,onSettings:s}){let c=e.editable_by.includes(`mcp`);return(0,X.jsxs)(`div`,{"data-testid":`kb-overview`,className:`w-full min-w-0 space-y-6 p-4 sm:p-6`,children:[(0,X.jsxs)(`header`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 space-y-1`,children:[(0,X.jsx)(`h2`,{className:`wrap-break-word text-base font-medium`,"data-testid":`kb-overview-name`,children:e.name}),e.description&&(0,X.jsx)(`p`,{className:`max-w-prose text-outline`,children:e.description}),(0,X.jsxs)(`p`,{className:`text-xs text-outline`,"data-testid":`kb-overview-meta`,children:[t,` · `,e.document_count,` `,e.document_count===1?`document`:`documents`,` ·`,` `,c?`agents can edit`:`agents read only`]})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsxs)(d,{size:`sm`,"data-testid":`kb-new-document`,onClick:o,children:[(0,X.jsx)(Pt,{size:16}),`New document`]}),(0,X.jsxs)(d,{size:`sm`,variant:`ghost`,"data-testid":`kb-settings`,onClick:s,children:[(0,X.jsx)(Ce,{size:16}),`Settings`]})]})]}),(0,X.jsx)(vr,{kbId:e.id,onOpen:a}),(0,X.jsx)(_r,{listing:n,total:e.document_count,label:r,onLabel:i,onOpen:a,onNewDocument:o}),(0,X.jsxs)(`section`,{"aria-labelledby":`kb-setup-heading`,className:`space-y-1`,children:[(0,X.jsx)(`h3`,{id:`kb-setup-heading`,className:`text-sm font-medium text-outline`,children:`Setup`}),(0,X.jsxs)(`div`,{className:`divide-y divide-outline-variant border-y border-outline-variant`,children:[(0,X.jsx)(hn,{kb:e}),(0,X.jsx)(lr,{kb:e}),(0,X.jsx)(hr,{kb:e,onSettings:s}),(0,X.jsx)(gr,{kb:e,onSettings:s}),(0,X.jsx)(Jn,{kbId:e.id,onOpenDocument:a})]})]})]})}function hr({kb:e,onSettings:t}){let n=e.editable_by.includes(`mcp`);return(0,X.jsx)(tn,{title:`Who can edit`,testId:`kb-access`,summary:(0,X.jsxs)(`span`,{className:`inline-flex min-w-0 flex-wrap items-center gap-x-1.5`,children:[(0,X.jsx)(Z,{tone:n?`ok`:`off`}),n?`Agents can edit`:`Agents read only`,(0,X.jsxs)(`span`,{className:`text-outline`,children:[`·`,` `,e.editable_by.length?e.editable_by.map(e=>Dn[e]).join(`, `):`nobody, read only everywhere`]})]}),actions:(0,X.jsx)(d,{size:`sm`,variant:`ghost`,"data-testid":`kb-access-change`,onClick:t,children:`Change`})})}function gr({kb:e,onSettings:t}){let n=vt(),r=e.parser?n.data?.parsers.find(t=>t.id===e.parser)?.label??e.parser:`Workspace default parser`;return(0,X.jsx)(tn,{title:`Uploads`,testId:`kb-uploads-setup`,summary:(0,X.jsxs)(`span`,{className:`text-outline`,"data-testid":`kb-uploads-parser`,children:[r,(0,X.jsx)(de,{label:`Document uploads`,children:`PDF, Word, PowerPoint, Excel, HTML, Markdown and text are converted to searchable Markdown by the selected parser.`})]}),actions:(0,X.jsx)(d,{size:`sm`,variant:`ghost`,"data-testid":`kb-parser-change`,onClick:t,children:`Change`})})}function _r({listing:e,total:t,label:n,onLabel:r,onOpen:i,onNewDocument:a}){let[o,s]=(0,J.useState)(``),[c,u]=(0,J.useState)(!1),[f,p]=(0,J.useState)({key:`updated`,desc:!0}),m=o.trim().toLowerCase(),h=(e?.documents??[]).filter(e=>(!n||e.labels.includes(n))&&(!m||e.title.toLowerCase().includes(m)||e.path.toLowerCase().includes(m)||e.labels.some(e=>e.toLowerCase().includes(m)))).sort((e,t)=>dr(e,t,f.key)*(f.desc?-1:1));function g(e){p(t=>t.key===e?{key:e,desc:!t.desc}:{key:e,desc:e!==`title`})}function _(e,t){let n=f.desc?Me:Ne;return(0,X.jsxs)(`button`,{type:`button`,"data-testid":`kb-sort-${e}`,className:`inline-flex min-h-8 items-center gap-1 hover:text-on-surface`,onClick:()=>g(e),children:[t,f.key===e&&(0,X.jsx)(n,{size:12,"aria-hidden":!0})]})}let v=[...e?.labels??[]].sort((e,t)=>t.count-e.count),y=c?v:v.filter((e,t)=>t<ur||e.label===n),b=v.length-y.length;return(0,X.jsxs)(`section`,{"aria-labelledby":`kb-documents-heading`,"data-testid":`kb-documents`,className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,X.jsxs)(`h3`,{id:`kb-documents-heading`,className:`mr-auto text-sm font-medium text-outline`,children:[`Documents`,n?` labelled ${n}`:``]}),t>0&&(0,X.jsx)(K,{"aria-label":`Filter documents`,"data-testid":`kb-documents-filter`,placeholder:`Filter by title, path or label`,value:o,onChange:e=>s(e.target.value),className:`h-9 w-full sm:w-64`})]}),y.length>0&&(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,"data-testid":`kb-labels`,children:[(0,X.jsx)(`span`,{className:`mr-1 text-xs text-outline`,children:`Label`}),y.map(e=>(0,X.jsxs)(`button`,{type:`button`,"data-testid":`kb-label-filter`,"aria-pressed":n===e.label,className:l(`min-h-8 rounded-full border px-2.5 text-xs`,n===e.label?`border-primary bg-primary/10 text-primary`:`border-outline-variant text-outline hover:text-on-surface`),onClick:()=>r(n===e.label?null:e.label),children:[e.label,` `,(0,X.jsx)(`span`,{className:`tabular-nums`,children:e.count})]},e.label)),(b>0||c)&&v.length>ur&&(0,X.jsx)(`button`,{type:`button`,"data-testid":`kb-labels-more`,className:`min-h-8 px-2 text-xs text-primary hover:underline`,onClick:()=>u(!c),children:c?`Fewer labels`:`${b} more`})]}),t===0?(0,X.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-2 rounded-md border border-dashed border-outline-variant px-6 py-10 text-center text-sm text-outline`,children:[(0,X.jsx)(P,{size:22,className:`text-primary`,"aria-hidden":!0}),(0,X.jsx)(`span`,{children:`This knowledge base is empty. Drop PDF, Word, PowerPoint, Excel, HTML, Markdown or text files here, or`}),(0,X.jsx)(d,{size:`sm`,variant:`outline`,onClick:a,"data-testid":`kb-overview-new-document`,children:`add a document`})]}):(0,X.jsxs)(X.Fragment,{children:[h.length===0&&e&&(0,X.jsxs)(`p`,{className:`py-4 text-sm text-outline`,"data-testid":`kb-documents-empty`,children:[`No documents match.`,` `,(0,X.jsx)(`button`,{type:`button`,"data-testid":`kb-documents-clear`,className:`text-primary hover:underline`,onClick:()=>{s(``),r(null)},children:`Clear filters`})]}),h.length>0&&(0,X.jsxs)(`table`,{className:`w-full table-fixed text-sm`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{className:`border-b border-outline-variant text-left text-xs text-outline`,children:[(0,X.jsx)(`th`,{className:`py-1 pr-3 font-normal`,"aria-sort":fr(f,`title`),children:_(`title`,`Title`)}),(0,X.jsx)(`th`,{className:`hidden w-[30%] py-2 pr-3 font-normal md:table-cell`,children:`Labels`}),(0,X.jsx)(`th`,{className:`w-24 py-1 pr-3 font-normal sm:w-28`,"aria-sort":fr(f,`updated`),children:_(`updated`,`Updated`)}),(0,X.jsx)(`th`,{className:`hidden w-16 py-1 text-right font-normal sm:table-cell`,"aria-sort":fr(f,`reads`),children:_(`reads`,`Reads`)})]})}),(0,X.jsx)(`tbody`,{children:h.map(e=>(0,X.jsxs)(`tr`,{className:`cursor-pointer border-b border-outline-variant/60 align-top hover:bg-surface-high`,onClick:()=>i(e.id),children:[(0,X.jsxs)(`td`,{className:`min-w-0 py-2 pr-3`,children:[(0,X.jsxs)(`button`,{type:`button`,"data-testid":`kb-document-row`,"data-document-title":e.title,className:`flex w-full min-w-0 items-center gap-1.5 text-left font-medium hover:text-primary`,onClick:t=>{t.stopPropagation(),i(e.id)},children:[(0,X.jsx)(`span`,{className:`min-w-0 truncate`,children:e.title}),e.origin===`external`&&(0,X.jsx)(Rt,{size:13,className:`shrink-0 text-outline`,"aria-label":`From a synced folder`})]}),(0,X.jsx)(`span`,{className:`block truncate font-mono text-xs text-outline`,children:e.path}),(e.parse_state===`pending`||e.parse_state===`failed`)&&(0,X.jsx)(`span`,{className:l(`text-xs`,e.parse_state===`failed`?`text-error`:`text-outline`),children:e.parse_state===`failed`?`Parsing failed`:`Parsing…`})]}),(0,X.jsx)(`td`,{className:`hidden py-2 pr-3 text-xs text-outline md:table-cell`,children:(0,X.jsx)(`span`,{className:`line-clamp-2`,children:e.labels.join(`, `)})}),(0,X.jsx)(`td`,{className:`py-2 pr-3 text-xs text-outline tabular-nums`,children:pr(e.updated_at)}),(0,X.jsx)(`td`,{className:`hidden py-2 text-right text-xs text-outline tabular-nums sm:table-cell`,children:e.reads||``})]},e.id))})]}),(0,X.jsx)(`p`,{className:`text-xs text-outline`,children:`Drop files anywhere on this page to upload.`})]})]})}function vr({kbId:e,onOpen:t}){let n=kt(e).data;return!n||!(n.stale.length||n.failed.length||n.unresolved_links.length)?null:(0,X.jsxs)(`section`,{"data-testid":`kb-maintenance`,className:`space-y-1 text-sm`,children:[(0,X.jsx)(`h3`,{className:`text-sm font-medium text-outline`,children:`Needs attention`}),(0,X.jsxs)(`ul`,{className:`space-y-1`,children:[n.failed.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,className:`text-left text-error hover:underline`,onClick:()=>t(e.id),children:[`Parsing failed: `,e.title]})},e.id)),n.stale.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,className:`text-left text-warning hover:underline`,onClick:()=>t(e.id),children:[`Stale summary: `,e.title]})},e.id)),n.unresolved_links.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,className:`text-left text-outline hover:underline`,onClick:()=>t(e.document_id),children:[`[[`,e.target,`]] in `,e.title,` has no target`]})},`${e.document_id}-${e.target}`))]})]})}function yr(){let e=q(),[t,n]=(0,J.useState)([]),r=(0,J.useRef)(1),i=(e,t)=>n(n=>n.map(n=>n.id===e?{...n,...t}:n));async function a(t){i(t.id,{status:`uploading`,progress:0,error:void 0});try{let n=await O.kb.upload(t.kbId,{file:t.file,...t.replace},e=>i(t.id,{progress:e}));i(t.id,{status:`done`,progress:1,document:n}),await e()}catch(e){i(t.id,{status:`failed`,error:e instanceof Error?e.message:`Upload failed`})}}function o(e,t,i={}){let o=t.map(t=>({id:r.current++,kbId:e,file:t,...i.replace?{replace:i.replace}:{},progress:0,status:`uploading`}));n(e=>[...e,...o]);for(let e of o)a(e)}return{uploads:t,add:o,retry:e=>{let n=t.find(t=>t.id===e);n&&a(n)},clearFinished:()=>n(e=>e.filter(e=>e.status===`uploading`))}}var br=`all`,xr=200,Sr=[{value:`reads`,label:`Most read`},{value:`recent`,label:`Recent`},{value:`priority`,label:`Priority`}];function Cr(e){return new Date(e*1e3).toLocaleString()}function wr({projectId:e}){let t=i(),n=c(),{memoryProject:r,memoryName:a}=o(),[s,l]=Xe(`project`,e),[u,f]=Xe(`memoryQuery`,``),[p,m]=Xe(`memorySort`,`reads`,Sr.map(e=>e.value)),[h,g]=(0,J.useState)(u);(0,J.useEffect)(()=>g(u),[u]);let _=(0,J.useRef)(f);_.current=f,(0,J.useEffect)(()=>{if(h===u)return;let e=window.setTimeout(()=>_.current(h,{replace:!0}),250);return()=>window.clearTimeout(e)},[h,u]);let v=ue(`lg`),[y,b]=(0,J.useState)(null),[x,D]=(0,J.useState)(null),{data:O}=Ee({status:`active`}),k=ct(),A=s===`unassigned`,j=s===br,M=ut({project_id:j?void 0:s,q:u||void 0,sort:p,limit:xr},{enabled:!A}),P=M.data?.memories??[],F=e=>O?.find(t=>t.id===e)?.name??e,I=P.find(e=>e.project_id===r&&e.name===a),L=e=>t(`${ce(e.project_id,e.name)}${n.search}`),R=()=>t(`${_e}${n.search}`),z=j||!A&&r===s;return(0,J.useEffect)(()=>{r&&a&&!z&&t(`${_e}${n.search}`,{replace:!0})},[r,a,z,t,n.search]),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(Ye,{title:`Memories`,help:`Short project facts such as ports, conventions and decisions that agents can read in later sessions. Longer procedures belong in a skill.`,meta:M.data?`${M.data.total} ${M.data.total===1?`memory`:`memories`}`:void 0,action:(0,X.jsxs)(d,{"data-testid":`new-memory-button`,size:`sm`,onClick:()=>b(`new`),className:`font-label text-sm`,children:[(0,X.jsx)(se,{size:12,className:`mr-1`}),` New memory`]})}),(0,X.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-2`,children:[(0,X.jsxs)(N,{activeCount:Number(p!==`reads`)+Number(s!==br),children:[(0,X.jsxs)(E,{value:s,onValueChange:e=>l(e),children:[(0,X.jsx)(C,{"aria-label":`Project`,"data-testid":`memory-project-filter`,className:`h-9 w-48 bg-background text-on-surface font-body text-sm`,children:(0,X.jsx)(S,{})}),(0,X.jsxs)(w,{className:`bg-surface border-outline-variant`,children:[(0,X.jsx)(T,{value:br,className:`font-body text-sm`,children:`All projects`}),A&&(0,X.jsx)(T,{value:`unassigned`,className:`font-body text-sm`,children:`Unassigned`}),O?.map(e=>(0,X.jsx)(T,{value:e.id,"data-testid":`memory-project-option-${e.id}`,className:`font-body text-sm`,children:e.name},e.id))]})]}),(0,X.jsx)(`div`,{className:`flex shrink-0 flex-wrap gap-1.5`,children:Sr.map(e=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>m(e.value),"data-testid":`memory-sort-${e.value}`,"aria-pressed":p===e.value,className:`font-label text-sm px-3 py-1.5 border transition-colors ${p===e.value?`bg-surface-highest text-on-surface border-transparent`:`bg-transparent border-transparent text-muted-foreground hover:bg-surface-low hover:text-on-surface`}`,children:e.label},e.value))})]}),(0,X.jsxs)(`div`,{className:`relative order-first min-w-0 flex-1 lg:max-w-md`,children:[(0,X.jsx)(we,{size:12,className:`absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground`}),(0,X.jsx)(K,{"aria-label":`Search memories`,"data-testid":`memory-search-input`,value:h,onChange:e=>g(e.target.value),onKeyDown:e=>e.key===`Enter`&&f(e.currentTarget.value),placeholder:`Search memories...`,className:`pl-8 bg-background text-on-surface font-body text-sm placeholder:text-muted-foreground`})]})]}),A?(0,X.jsx)(Ze,{message:`Memories belong to a project. Choose a project to see its memories.`}):M.error?(0,X.jsx)(Je,{message:M.error.message,onRetry:()=>void M.refetch()}):M.isLoading?(0,X.jsx)(`div`,{className:`space-y-2`,children:[...[,,,,,]].map((e,t)=>(0,X.jsx)(ye,{className:`h-10 w-full bg-surface-highest`},t))}):P.length===0?(0,X.jsx)(Ze,{message:u?`No memories match your search`:`No memories yet`}):v?(0,X.jsx)(`div`,{className:`overflow-hidden`,children:(0,X.jsxs)(rt,{children:[(0,X.jsx)(Qe,{children:(0,X.jsxs)(tt,{className:`border-b border-outline-variant hover:bg-transparent`,children:[(0,X.jsx)($e,{className:`font-label text-sm text-muted-foreground`,children:`Name`}),(0,X.jsx)($e,{className:`font-label text-sm text-muted-foreground`,children:`Description`}),j&&(0,X.jsx)($e,{className:`font-label text-sm text-muted-foreground`,children:`Project`}),(0,X.jsx)($e,{className:`font-label text-sm text-muted-foreground w-20`,children:`Priority`}),(0,X.jsx)($e,{className:`font-label text-sm text-muted-foreground w-16`,children:`Reads`}),(0,X.jsx)($e,{className:`font-label text-sm text-muted-foreground w-44`,children:`Updated`})]})}),(0,X.jsx)(et,{children:P.map(e=>(0,X.jsxs)(tt,{"data-testid":`memory-row`,"data-memory-name":e.name,"data-memory-project":e.project_id,className:`border-b border-outline-variant/50 hover:bg-surface-low cursor-pointer`,onClick:()=>L(e),children:[(0,X.jsx)(nt,{className:`font-body text-sm font-medium text-on-surface`,children:(0,X.jsx)(`button`,{type:`button`,className:`min-h-11 text-left hover:text-primary`,onClick:t=>{t.stopPropagation(),L(e)},children:e.name})}),(0,X.jsx)(nt,{className:`font-body text-sm text-muted-foreground max-w-md truncate`,children:e.description}),j&&(0,X.jsx)(nt,{className:`font-body text-sm text-muted-foreground`,children:F(e.project_id)}),(0,X.jsx)(nt,{children:(0,X.jsx)(Er,{priority:e.priority})}),(0,X.jsx)(nt,{"data-testid":`memory-read-count`,className:`font-label text-sm text-muted-foreground`,title:Tr(e),children:e.read_count}),(0,X.jsx)(nt,{className:`font-label text-sm text-muted-foreground`,children:Cr(e.updated_at)})]},e.key))})]})}):(0,X.jsx)(`div`,{className:`divide-y divide-outline-variant`,children:P.map(e=>(0,X.jsxs)(`button`,{type:`button`,"data-testid":`memory-row`,"data-memory-name":e.name,"data-memory-project":e.project_id,onClick:()=>L(e),className:`flex w-full min-w-0 items-start justify-between gap-3 px-2 py-3 text-left hover:bg-surface`,children:[(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`span`,{className:`block wrap-break-word text-sm font-medium`,children:e.name}),(0,X.jsx)(`span`,{className:`mt-1 line-clamp-2 wrap-break-word text-sm text-muted-foreground`,children:e.description}),(0,X.jsxs)(`span`,{className:`mt-1 flex flex-wrap items-center gap-x-2 text-xs text-muted-foreground`,children:[j&&(0,X.jsx)(`span`,{children:F(e.project_id)}),(0,X.jsxs)(`span`,{"data-testid":`memory-read-count`,title:Tr(e),children:[e.read_count,` reads`]})]})]}),(0,X.jsx)(Er,{priority:e.priority})]},e.key))}),r&&a&&z&&(0,X.jsx)(Dr,{projectId:r,name:a,projectName:F(r),listItem:I,onClose:R,onEdit:b,onDelete:D},`${r}/${a}`),y&&(0,X.jsx)(Mr,{memory:y===`new`?null:y,defaultProjectId:j||A?``:s,onClose:()=>b(null),onCreated:e=>L(e)}),x&&(0,X.jsx)(qe,{open:!0,title:`Delete memory`,description:`Delete "${x.name}"? It can be restored from its history.`,confirmLabel:`Delete`,variant:`destructive`,isPending:k.isPending,onConfirm:()=>k.mutate({projectId:x.project_id,name:x.name},{onSuccess:()=>{D(null),R()}}),onCancel:()=>D(null)}),k.error&&(0,X.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive mt-2`,children:k.error.message})]})}function Tr(e){let{mcp:t,cli:n,api:r,ui:i}=e.reads_by_source;return`mcp ${t} · cli ${n} · api ${r} · ui ${i}${e.last_read_at?` · last read ${Cr(e.last_read_at)}`:``}`}function Er({priority:e}){return e===null?(0,X.jsx)(`span`,{"data-testid":`memory-priority`,className:`font-label text-xs text-outline`,children:`Unscored`}):(0,X.jsxs)(`span`,{"data-testid":`memory-priority`,className:`font-label text-xs text-primary`,children:[`P`,e]})}function Dr({projectId:e,name:t,projectName:n,listItem:r,onClose:i,onEdit:a,onDelete:o}){let{data:s,isLoading:c,error:l,refetch:u}=st(e,t);return(0,X.jsx)(be,{open:!0,onOpenChange:e=>!e&&i(),children:(0,X.jsxs)(pe,{"data-testid":`memory-detail`,defaultWidth:860,resizeKey:`memories`,children:[(0,X.jsxs)(Se,{children:[(0,X.jsx)(xe,{children:t}),s&&(0,X.jsx)(`p`,{"data-testid":`memory-detail-description`,className:`font-body text-sm text-muted-foreground mt-1`,children:s.description})]}),(0,X.jsx)(fe,{children:l?(0,X.jsx)(Je,{message:l.message,onRetry:()=>void u()}):c||!s?(0,X.jsx)(`div`,{className:`space-y-3`,children:[...[,,,,]].map((e,t)=>(0,X.jsx)(ye,{className:`h-8 w-full bg-surface-highest`},t))}):(0,X.jsxs)(`div`,{className:`space-y-6`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsxs)(d,{"data-testid":`memory-edit`,size:`sm`,variant:`outline`,onClick:()=>a(s),children:[(0,X.jsx)(Ae,{size:12,className:`mr-1`}),` Edit`]}),(0,X.jsxs)(d,{"data-testid":`memory-delete`,size:`sm`,variant:`outline`,onClick:()=>o(s),children:[(0,X.jsx)(Le,{size:12,className:`mr-1`}),` Delete`]})]}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,X.jsx)(ze,{label:`Project`,children:n}),(0,X.jsx)(ze,{label:`Priority`,children:(0,X.jsx)(Er,{priority:s.priority})}),(0,X.jsx)(ze,{label:`Reads`,children:r?(0,X.jsx)(`span`,{title:Tr(r),children:r.read_count}):`—`}),(0,X.jsx)(ze,{label:`Author`,children:(0,X.jsx)(`span`,{"data-testid":`memory-detail-author`,children:s.author})}),(0,X.jsx)(ze,{label:`Session`,children:(0,X.jsx)(`code`,{className:`font-mono text-xs break-all`,children:s.session_id??`—`})}),(0,X.jsx)(ze,{label:`Updated`,children:Cr(s.updated_at)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`font-label text-sm text-muted-foreground mb-2`,children:`Content`}),(0,X.jsx)(`div`,{"data-testid":`memory-detail-content`,className:`wrap-break-word font-body text-sm text-on-surface`,children:(0,X.jsx)(F,{readable:!0,children:s.content})})]}),(0,X.jsx)(kr,{projectId:e,name:t,onDeleted:i})]})})]})})}function Or({label:e,snapshot:t}){return(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-xs text-outline mt-2`,children:e}),t?(0,X.jsxs)(`div`,{className:`text-xs space-y-1`,children:[(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`span`,{className:`text-outline`,children:`Priority:`}),` `,t.priority===null?`unscored`:t.priority]}),(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`span`,{className:`text-outline`,children:`Description:`}),` `,t.description]}),(0,X.jsx)(`pre`,{className:`whitespace-pre-wrap break-all`,children:t.content})]}):(0,X.jsx)(`p`,{className:`text-xs italic text-muted-foreground`,children:`(none)`})]})}function kr({projectId:e,name:t,onDeleted:n}){let r=at(e,t),i=dt(),[a,o]=(0,J.useState)(``),s=r.data?.changes??[],c=s[0];return(0,X.jsxs)(`section`,{"data-testid":`memory-history-panel`,className:`space-y-3`,children:[(0,X.jsx)(`h3`,{className:`text-sm font-medium`,children:`History`}),r.error&&(0,X.jsx)(`p`,{role:`alert`,children:r.error.message}),i.error&&(0,X.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:i.error.message}),s.length>1&&(0,X.jsx)(K,{"data-testid":`memory-revert-reason`,"aria-label":`Reason for reverting`,value:a,onChange:e=>o(e.target.value),placeholder:`Reason for reverting...`}),s.map(r=>(0,X.jsxs)(`details`,{"data-testid":`memory-history-change`,className:`border-b border-outline-variant p-3`,children:[(0,X.jsxs)(`summary`,{className:`text-xs cursor-pointer`,children:[r.action.replace(`memory.`,``),` · `,Cr(r.created_at),` ·`,` `,r.author,r.session_id?` · ${r.session_id}`:``,r.reason?` · ${r.reason}`:``]}),(0,X.jsx)(Or,{label:`Before`,snapshot:r.previous}),(0,X.jsx)(Or,{label:`After`,snapshot:r.current}),c&&r.previous&&(0,X.jsx)(d,{"data-testid":`memory-revert-change`,size:`sm`,variant:`outline`,className:`mt-2`,disabled:!a.trim()||i.isPending,onClick:()=>i.mutate({name:t,project_id:e,change_id:r.id,expected_change_id:c.id,reason:a.trim()},{onSuccess:({memory:e})=>{o(``),e||n()}}),children:`Restore state before this change`})]},r.id))]})}function Ar(e){return[...e].length}function jr({value:e,max:t,testId:n}){let r=Ar(e);return(0,X.jsx)(`span`,{"data-testid":n,className:`text-xs ${t!==void 0&&r>t?`text-destructive`:`text-muted-foreground`}`,children:t===void 0?r:`${r}/${t}`})}function Mr({memory:e,defaultProjectId:t,onClose:n,onCreated:r}){let{data:i}=Ee({status:`active`}),[a,o]=(0,J.useState)(e?.project_id??t),[s,c]=(0,J.useState)(e?.name??``),[l,u]=(0,J.useState)(e?.description??``),[f,p]=(0,J.useState)(e?.content??``),[m,h]=(0,J.useState)(e?.priority===null||e?.priority===void 0?``:String(e.priority)),[g,_]=(0,J.useState)(``),v=ft(),y=ot(),b=(0,J.useRef)(JSON.stringify([a,s,l,f,m,g])),D=lt().data?.content_max,O=e?y:v,k=le([{id:`details`,label:`Details`},{id:`content`,label:`Content`}]),A=m.trim()===``?null:Number(m),j=A===null||Number.isInteger(A)&&A>=0&&A<=100,M=!!a&&!!s.trim()&&!!l.trim()&&Ar(l)<=300&&!!f.trim()&&(D===void 0||Ar(f)<=D)&&j;function N(t){if(O.isPending)return;if(!M){!a||!s.trim()||!l.trim()||Ar(l)>300||!j?k.invalid(`details`,a?j?`Enter a name and description within the displayed limits.`:`Priority must be a whole number from 0 to 100.`:`Choose a project.`):k.invalid(`content`,`Enter memory content within the displayed limit.`);return}if(!e){v.mutate({project_id:a,name:s.trim(),description:l.trim(),content:f.trim(),priority:A},{onSuccess:e=>{t(),r(e)}});return}let n={...l.trim()!==e.description&&{description:l.trim()},...f.trim()!==e.content&&{content:f.trim()},...A!==e.priority&&{priority:A}};Object.keys(n).length===0?t():y.mutate({name:e.name,project_id:e.project_id,...n,...g.trim()&&{reason:g.trim()}},{onSuccess:t})}return(0,X.jsx)(He,{open:!0,onClose:n,busy:O.isPending,dirty:JSON.stringify([a,s,l,f,m,g])!==b.current,testId:`memory-form-dialog`,className:k.step===`content`?`h-[min(85dvh,calc(var(--app-height,100dvh)-2rem))]`:void 0,children:(t,n)=>(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(re,{children:(0,X.jsx)(ae,{className:`font-headline text-base text-on-surface`,children:e?`Edit ${e.name}`:`New memory`})}),(0,X.jsx)(`form`,{noValidate:!0,ref:k.form,onSubmit:e=>k.submit(e,()=>N(n)),className:k.step===`content`?`min-h-0 flex-1`:`min-h-0`,children:(0,X.jsxs)(ve,{steps:k,children:[(0,X.jsxs)(`div`,{className:k.step===`content`?`work-form-body flex min-h-0 flex-1 flex-col gap-4`:`work-form-body space-y-4`,children:[(0,X.jsxs)(Ue,{steps:k,id:`details`,children:[!e&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(x,{className:`font-label text-sm text-muted-foreground`,children:`Project *`}),(0,X.jsxs)(E,{value:a,onValueChange:o,children:[(0,X.jsx)(C,{"aria-label":`Memory project`,"data-testid":`memory-project-select`,className:`bg-background text-on-surface font-body text-sm h-9`,children:(0,X.jsx)(S,{placeholder:`Choose a project`})}),(0,X.jsx)(w,{className:`bg-surface border-outline-variant`,children:i?.map(e=>(0,X.jsx)(T,{value:e.id,className:`font-body text-sm`,children:e.name},e.id))})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(x,{className:`font-label text-sm text-muted-foreground`,children:`Name *`}),(0,X.jsx)(K,{"aria-label":`Name`,"data-testid":`memory-name-input`,value:s,onChange:e=>c(e.target.value),placeholder:`api-port`,maxLength:64,required:!0,className:`bg-background text-on-surface font-body text-sm`,autoFocus:!0}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Lowercase words joined by hyphens, unique in the project.`})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(x,{className:`font-label text-sm text-muted-foreground`,children:`Description *`}),(0,X.jsx)(jr,{value:l,max:300,testId:`memory-description-count`})]}),(0,X.jsx)(W,{"aria-label":`Description`,"data-testid":`memory-description-input`,value:l,onChange:e=>u(e.target.value),placeholder:`One line agents see in lists and context`,className:`bg-background text-on-surface font-body text-sm resize-none`,rows:2,required:!0})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(x,{className:`font-label text-sm text-muted-foreground`,children:[`Priority (0-`,100,`, empty = unscored)`]}),(0,X.jsx)(K,{"aria-label":`Priority`,"data-testid":`memory-priority-input`,type:`number`,min:0,max:100,step:1,value:m,onChange:e=>h(e.target.value),className:`w-32 bg-background text-on-surface font-body text-sm`}),!j&&(0,X.jsxs)(`p`,{className:`text-xs text-destructive`,children:[`Priority must be a whole number from 0 to `,100,`.`]})]}),e&&(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(x,{className:`font-label text-sm text-muted-foreground`,children:`Reason`}),(0,X.jsx)(K,{"aria-label":`Reason`,"data-testid":`memory-reason-input`,value:g,onChange:e=>_(e.target.value),placeholder:`Why this changed (optional)`,className:`bg-background text-on-surface font-body text-sm`})]})]}),(0,X.jsx)(Ue,{steps:k,id:`content`,className:`flex min-h-0 flex-1 flex-col`,children:(0,X.jsx)(he,{label:`Content`,"aria-label":`Content`,"data-testid":`memory-content-input`,value:f,onChange:p,placeholder:`The fact itself. Longer guidance belongs in a skill.`,accessory:(0,X.jsx)(jr,{value:f,max:D,testId:`memory-content-count`}),fill:!0,disabled:O.isPending,required:!0})}),k.error&&(0,X.jsx)(`p`,{role:`alert`,"data-testid":`memory-step-error`,className:`text-sm text-destructive`,children:k.error}),O.error&&(0,X.jsx)(`p`,{role:`alert`,"data-testid":`memory-form-error`,className:`text-sm text-destructive md:col-span-2`,children:O.error.message})]}),(0,X.jsxs)(G,{className:`work-form-footer`,children:[(0,X.jsx)(d,{type:`button`,variant:`ghost`,size:`sm`,onClick:t,disabled:O.isPending,className:`font-label text-sm text-muted-foreground`,children:`Cancel`}),(0,X.jsx)(Oe,{steps:k,busy:O.isPending,children:(0,X.jsx)(d,{"data-testid":`memory-submit`,type:`submit`,size:`sm`,disabled:O.isPending,className:`font-label text-sm`,children:O.isPending?`Saving...`:e?`Save`:`Create`})})]})]})})]})})}function Nr({projectId:e}){let t=it(e),{pathname:n}=c();return n.startsWith(`/knowledge/memories`)?(0,X.jsx)(`div`,{"data-testid":`knowledge-base-view`,children:(0,X.jsx)(wr,{projectId:e,embedded:!0})}):(0,X.jsx)(`div`,{"data-testid":`knowledge-base-view`,className:`flex min-h-0 min-w-0 flex-1`,children:(0,X.jsx)(Ir,{projectId:t===`all`||t===`unassigned`?void 0:t,globalOnly:t===`unassigned`},t)})}function Pr(e){return e.replace(/```[\w-]*/g,` `).replace(/<\/?[a-z][^>]*>/gi,` `).replace(/!?\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/(^|\s)#{1,6}\s+/g,`$1`).replace(/(^|\n)\s*(?:>\s*)+/g,`$1`).replace(/(^|\n)\s*(?:[-*+]|\d+[.)])\s+/g,`$1`).replace(/\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?/g,` `).replace(/(^|\s)(?:\*{3,}|_{3,})(?=\s|$)/g,`$1`).replace(/`/g,``).replace(/(^|[\s(«])[*_~]+(?=\S)/g,`$1`).replace(/(\S)[*_~]+(?=$|[\s).,;:!?»])/g,`$1`).replace(/\s*\|[\s|]*/g,` · `).replace(/\s+/g,` `).replace(/^ · | · $/g,``).trim()}function Fr({text:e}){let t=Pr(e).split(/«([^»]*)»/g);return(0,X.jsx)(X.Fragment,{children:t.map((e,t)=>t%2?(0,X.jsx)(`mark`,{className:`rounded-xs bg-primary/20 px-0.5 text-on-surface`,children:e},t):(0,X.jsx)(J.Fragment,{children:e},t))})}function Ir({projectId:e,globalOnly:t=!1}){let[n,r]=a(),i=n.get(`kb`),o=n.get(`document`),s=n.get(`label`)??``,c=n.get(`q`)??``,u=n.get(`searchAll`)===`1`,[f,x]=(0,J.useState)(c);(0,J.useEffect)(()=>x(c),[c]);let[S,C]=(0,J.useState)(null),[w,T]=(0,J.useState)(!1),E=ue(`lg`),[D,O]=(0,J.useState)(()=>typeof window<`u`&&window.innerWidth>=1600),[A,j]=(0,J.useState)(!1),[M,N]=(0,J.useState)(null),[P,F]=(0,J.useState)();function I(){C(null),F(void 0)}let L=Ee(),R=ht(e,t),z=R.data?.find(e=>e.id===i)??null,ee=Ct(z?.id??null),B=Dt(R.data===void 0?null:o),V=R.data!==void 0&&(z!==null||R.data.length===0),te=Tt(c&&V?{query:c,...z&&!u?{kb_ids:[z.id]}:{},scope:e?`default`:t?`global`:`all`,limit:20}:null,e),H=yr();function U(e,t=!1){r(()=>{let t=new URLSearchParams(window.location.search);for(let[n,r]of Object.entries(e))r?t.set(n,r):t.delete(n);return t},{replace:t})}let ne=()=>!o||pt(Zn(o));function W(e){T(!1),(e!==i||o||c)&&ne()&&(e!==i&&H.clearFinished(),U({kb:e,document:null,label:null,q:null}))}function re(e,t){T(!1),(e===o||ne())&&(U({document:e,q:null}),N(t??null))}function G(e,t){U({document:e}),N(t??null)}function ie(){T(!1);let e=f.trim();if(!e)return U({q:null});ne()&&U({q:e,document:null})}(0,J.useEffect)(()=>{E&&T(!1)},[E]),(0,J.useEffect)(()=>{R.data&&(o&&B.data&&!R.data.some(e=>e.id===B.data.kb_id)?U({kb:R.data[0]?.id??null,document:null,label:null,q:null},!0):i&&!R.data.some(e=>e.id===i)&&(!o||B.error)?U({kb:null,document:null},!0):!i&&R.data[0]&&U({kb:R.data[0].id},!0))}),(0,J.useEffect)(()=>{B.data&&B.data.kb_id!==i&&R.data?.some(e=>e.id===B.data.kb_id)&&U({kb:B.data.kb_id,label:null},!0)}),(0,J.useEffect)(()=>{if(!M||!B.data)return;let e=[...document.querySelector(`[data-testid="kb-document"]`)?.querySelectorAll(`h1,h2,h3,h4,h5,h6`)??[]].find(e=>e.textContent?.trim()===M);e&&(e.scrollIntoView({block:`start`}),N(null))});function ae(e){e.preventDefault(),j(!1);let t=[...e.dataTransfer.files];z&&t.length!==0&&(t.length>1?H.add(z.id,t):(F(t[0]),C(`new-document`)))}let oe=e=>e===null?`Global`:L.data?.find(t=>t.id===e)?.name??`Project`;if(R.error)return(0,X.jsx)(Je,{message:R.error.message,onRetry:()=>R.refetch()});let ce=o?B.data&&z&&B.data.kb_id===z.id?(0,X.jsx)(tr,{kb:z,doc:B.data,detailsOpen:D,onDetailsOpenChange:O,onHome:()=>W(z.id),onOpen:re,onDeleted:()=>U({document:null}),onReplaceFile:e=>B.data&&H.add(B.data.kb_id,[e],{replace:{document_id:B.data.id,expected_revision:B.data.revision}})},B.data.id):B.error?(0,X.jsxs)(Br,{children:[(0,X.jsx)(`p`,{role:`alert`,"data-testid":`kb-document-error`,className:`text-sm text-error`,children:B.error.message}),(0,X.jsx)(d,{variant:`outline`,onClick:()=>U({document:null}),children:`Back`})]}):(0,X.jsx)(Br,{children:(0,X.jsx)(`p`,{role:`status`,className:`text-sm text-outline`,children:`Loading document…`})}):c?(0,X.jsx)(zr,{children:(0,X.jsx)(Vr,{query:c,search:te,onOpen:G,onClear:()=>U({q:null})})}):z?(0,X.jsx)(zr,{children:(0,X.jsx)(mr,{kb:z,owner:oe(z.project_id),listing:ee.data,label:s,onLabel:e=>U({label:e}),onOpen:re,onNewDocument:()=>C(`new-document`),onSettings:()=>C(`settings`)})}):R.data?.length===0?(0,X.jsxs)(Br,{testId:`empty-state`,children:[(0,X.jsx)(`p`,{className:`text-sm text-outline`,children:`No knowledge bases configured`}),(0,X.jsxs)(d,{"data-testid":`kb-empty-create`,onClick:()=>C(`create`),children:[(0,X.jsx)(se,{size:16}),`New knowledge base`]})]}):null,le=(0,X.jsxs)(`nav`,{id:`kb-sidebar-panel`,"aria-label":`Knowledge bases`,"data-testid":`kb-sidebar`,className:`flex h-full min-h-0 flex-col border-outline-variant bg-background lg:w-72 lg:shrink-0 lg:border-r`,children:[(0,X.jsxs)(`form`,{className:`flex shrink-0 items-center gap-1.5 border-b border-outline-variant p-3`,onSubmit:e=>{e.preventDefault(),ie()},children:[(0,X.jsx)(K,{"aria-label":`Search knowledge`,"data-testid":`kb-search-input`,value:f,onChange:e=>x(e.target.value),placeholder:z&&!u?`Search ${z.name}`:`Search everything`,className:`h-9 min-w-0 flex-1`}),(0,X.jsx)(d,{type:`submit`,size:`icon`,variant:`ghost`,"data-testid":`kb-search-submit`,"aria-label":`Search`,children:(0,X.jsx)(we,{size:16})}),w&&(0,X.jsx)(d,{type:`button`,size:`icon`,variant:`ghost`,"data-testid":`kb-browser-close`,"aria-label":`Close knowledge browser`,onClick:()=>T(!1),children:(0,X.jsx)(b,{size:16})})]}),z&&(0,X.jsxs)(`label`,{className:`flex shrink-0 items-center gap-2 border-b border-outline-variant px-3 py-2 text-xs text-outline`,children:[(0,X.jsx)(`input`,{type:`checkbox`,"data-testid":`kb-search-all`,checked:u,onChange:e=>U({searchAll:e.target.checked?`1`:null})}),`Search all knowledge bases`]}),(0,X.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-2 pb-1`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1`,children:[(0,X.jsx)(`h2`,{className:`text-sm font-medium text-outline`,children:`Knowledge bases`}),(0,X.jsx)(de,{label:`Knowledge bases`,children:`Upload documents, write Markdown or sync a folder. Agents search this knowledge with citations, and document details show what they read.`})]}),(0,X.jsx)(d,{size:`icon`,variant:`ghost`,"aria-label":`New knowledge base`,"data-testid":`kb-create`,onClick:()=>C(`create`),children:(0,X.jsx)(se,{size:16})})]}),R.isLoading&&(0,X.jsx)(ye,{className:`mx-2 h-9`}),(0,X.jsx)(Lr,{bases:R.data??[],projectName:oe,kbId:i,documentId:o,documents:ee.data?.documents??[],onSelectKb:W,onOpenDocument:re})]}),(0,X.jsx)(Rr,{})]});return(0,X.jsx)(_,{open:w&&!E,onOpenChange:T,children:(0,X.jsxs)(`div`,{"data-testid":`knowledge-bases`,className:`relative flex min-h-0 min-w-0 flex-1`,children:[(0,X.jsx)(`h1`,{"data-testid":`view-title`,className:`sr-only`,children:`Knowledge bases`}),E&&le,!E&&(0,X.jsxs)(y,{children:[(0,X.jsx)(v,{className:`fixed inset-0 z-50 bg-black/70`}),(0,X.jsxs)(h,{"data-testid":`kb-mobile-browser`,className:`viewport-sheet fixed inset-x-0 z-50 bg-background`,children:[(0,X.jsx)(m,{className:`sr-only`,children:`Browse knowledge`}),(0,X.jsx)(p,{className:`sr-only`,children:`Search knowledge bases and choose a document`}),le]})]}),(0,X.jsxs)(`div`,{"data-testid":`kb-dropzone`,className:l(`relative flex min-h-0 min-w-0 flex-1 flex-col`,A&&`outline-2 -outline-offset-4 outline-dashed outline-primary`),onDragOver:e=>{z&&(e.preventDefault(),j(!0))},onDragLeave:()=>j(!1),onDrop:ae,children:[(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-outline-variant px-3 py-2 lg:hidden`,children:[(0,X.jsx)(g,{asChild:!0,children:(0,X.jsxs)(d,{"data-testid":`kb-browser-open`,variant:`ghost`,size:`sm`,"aria-expanded":w,"aria-controls":`kb-sidebar-panel`,onClick:()=>T(!0),children:[(0,X.jsx)(Re,{size:16}),`Browse`]})}),z&&(0,X.jsx)(`span`,{className:`min-w-0 truncate text-sm text-outline`,children:z.name})]}),o&&c&&(0,X.jsx)(`div`,{className:`flex shrink-0 items-center border-b border-outline-variant px-3 py-1`,children:(0,X.jsxs)(d,{variant:`ghost`,size:`sm`,"data-testid":`kb-search-back`,className:`min-w-0`,onClick:()=>ne()&&U({document:null}),children:[(0,X.jsx)(k,{size:14}),(0,X.jsxs)(`span`,{className:`truncate`,children:[`Back to results for “`,c,`”`]})]})}),(0,X.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1`,children:ce}),(0,X.jsx)(Hr,{uploads:H,onOpen:re})]}),S===`create`&&(0,X.jsx)(kn,{open:!0,projectId:e,onClose:()=>C(null),onCreated:e=>{C(null),T(!1),U({kb:e.id,document:null,label:null,q:null})}}),S===`settings`&&z&&(0,X.jsx)(An,{kb:z,onClose:()=>C(null),onDeleted:()=>{C(null),U({kb:null,document:null,label:null})}}),S===`new-document`&&z&&(0,X.jsx)(Pn,{kb:z,initialFile:P,onClose:I,onUploadMany:e=>{I(),H.add(z.id,e)},onCreated:(e,t)=>{I(),U({document:e.id,editorMode:t?null:`edit`})}})]})})}function Lr({bases:e,projectName:t,kbId:n,documentId:r,documents:i,onSelectKb:a,onOpenDocument:o}){let[s,c]=(0,J.useState)(null);(0,J.useEffect)(()=>{r&&c(null)},[r]);let u=new Map;for(let n of e){let e=t(n.project_id);u.set(e,[...u.get(e)??[],n])}let d=[...u.entries()].sort(([e],[t])=>e===`Global`?-1:t===`Global`?1:e.localeCompare(t));return(0,X.jsx)(`div`,{"data-testid":`kb-list`,className:`space-y-3`,children:d.map(([e,t])=>(0,X.jsxs)(`section`,{"aria-label":e,children:[d.length>1&&(0,X.jsx)(`h3`,{className:`truncate px-2 pb-0.5 pt-1 text-xs text-outline`,children:e}),(0,X.jsx)(`ul`,{className:`space-y-0.5`,children:t.map(e=>{let t=e.id===n,u=t&&s!==e.id&&i.length>0;return(0,X.jsxs)(`li`,{children:[(0,X.jsxs)(`button`,{type:`button`,"data-testid":`kb-row`,"data-kb-name":e.name,"aria-current":t&&!r?`page`:void 0,"aria-expanded":u,className:l(`flex min-h-9 w-full items-center gap-2 rounded-md px-2 text-left text-sm hover:bg-surface-high`,t&&`font-medium`,t&&!r&&`bg-surface-high`),onClick:()=>{t&&c(t=>t===e.id?null:e.id),a(e.id)},children:[(0,X.jsx)(Be,{size:14,"aria-hidden":!0,className:l(`-mr-1 shrink-0 text-outline transition-transform motion-reduce:transition-none`,u&&`rotate-90`,e.document_count===0&&`invisible`)}),(0,X.jsx)(Ie,{size:15,className:`shrink-0 text-outline`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),(0,X.jsx)(`span`,{className:`text-xs font-normal tabular-nums text-outline`,children:e.document_count})]}),u&&(0,X.jsx)(`ul`,{className:`ml-4 mt-0.5 space-y-0.5 border-l border-outline-variant pl-2`,children:i.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,"data-testid":`kb-nav-document`,"data-document-title":e.title,"aria-current":e.id===r?`page`:void 0,className:l(`flex min-h-8 w-full items-center gap-2 rounded-md px-2 text-left text-sm hover:bg-surface-high`,e.id===r?`bg-surface-high text-on-surface`:`text-outline`),onClick:()=>o(e.id),children:[(0,X.jsx)(ke,{size:14,className:`shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.title})]})},e.id))})]},e.id)})})]},e))})}function Rr(){let e=bt(),t=e.data,n=t?t.embedding.provider===`none`?{text:`Keyword search only`,title:`Configure embeddings in Settings to also search by meaning`}:t.embedding.ready?{text:`Hybrid search`,title:t.embedding.model??void 0}:{text:`Embeddings not ready`,title:t.embedding.detail??``}:null,r=t?t.jobs.queued+t.jobs.running:0;return(0,X.jsx)(`p`,{role:`status`,"data-testid":`kb-status`,className:`shrink-0 border-t border-outline-variant px-4 py-2 text-xs text-outline`,children:t?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{title:n?.title,children:n?.text}),r?` · ${r} processing`:``]}):e.error?`Knowledge status unavailable`:`Loading…`})}function zr({children:e}){return(0,X.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto`,children:e})}function Br({children:e,testId:t}){return(0,X.jsx)(`div`,{"data-testid":t,className:`mx-auto flex max-w-lg flex-1 flex-col items-start justify-center gap-4 p-6`,children:e})}function Vr({query:e,search:t,onOpen:n,onClear:r}){let i=t.data;return(0,X.jsxs)(`section`,{"data-testid":`kb-search-results`,"aria-label":`Search results`,className:`w-full min-w-0 space-y-4 p-4 sm:p-8`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsxs)(`h2`,{className:`mr-auto text-lg font-medium`,children:[`Results for “`,e,`”`]}),i&&i.hits.length>0&&(0,X.jsxs)(`span`,{className:`text-xs text-outline`,"data-testid":`kb-search-count`,children:[i.hits.length,` `,i.hits.length===1?`result`:`results`]}),(0,X.jsxs)(d,{variant:`ghost`,size:`sm`,onClick:r,"data-testid":`kb-search-clear`,children:[(0,X.jsx)(b,{size:14}),`Clear`]})]}),i?.degraded&&(0,X.jsx)(`p`,{role:`status`,className:`text-sm text-warning`,children:i.degraded}),t.isLoading&&(0,X.jsx)(`p`,{className:`text-sm text-outline`,children:`Searching…`}),t.error&&(0,X.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:t.error.message}),i?.hits.length===0&&(0,X.jsx)(`p`,{className:`text-sm text-outline`,"data-testid":`kb-search-empty`,children:`Nothing matched. Try other words or search all knowledge bases.`}),i?.hits.map(e=>(0,X.jsxs)(`article`,{"data-testid":`kb-search-result`,className:`space-y-2 border-b border-outline-variant pb-4`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`block text-left`,onClick:()=>n(e.document_id,Gr(e.passages[0]?.heading_path)),children:[(0,X.jsx)(`span`,{className:`block font-medium text-primary hover:underline`,children:e.title}),(0,X.jsxs)(`span`,{className:`block break-all text-xs text-outline`,children:[e.kb_name,` · `,e.path]})]}),e.labels.length>0&&(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.labels.map(e=>(0,X.jsx)(Gn,{variant:`secondary`,children:e},e))}),e.passages.map(t=>(0,X.jsxs)(`div`,{"data-testid":`kb-search-passage`,className:`cursor-pointer space-y-1 rounded-md p-2 hover:bg-surface-high`,onClick:()=>n(e.document_id,Gr(t.heading_path)),children:[(t.heading_path.length>0||t.locator?.page||t.locator?.sheet)&&(0,X.jsx)(`div`,{className:`text-xs text-outline`,children:[...t.heading_path.map(Pr),...t.locator?.page?[`page ${t.locator.page}`]:[],...t.locator?.sheet?[`sheet ${t.locator.sheet}`]:[]].join(` › `)}),(0,X.jsx)(`p`,{className:`text-sm leading-relaxed`,children:(0,X.jsx)(Fr,{text:t.snippet})})]},t.chunk_id))]},e.document_id))]})}function Hr({uploads:e,onOpen:t}){if(!e.uploads.length)return null;let n=e.uploads.some(e=>e.status!==`uploading`);return(0,X.jsxs)(`section`,{"data-testid":`kb-upload-queue`,"aria-label":`Uploads`,className:`absolute bottom-4 right-4 z-10 flex max-h-72 w-80 max-w-[calc(100%-2rem)] flex-col rounded-lg border border-outline-variant bg-surface text-sm shadow-lg`,children:[(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between px-3 py-1.5`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:`Uploads`}),n&&(0,X.jsx)(d,{size:`sm`,variant:`ghost`,onClick:e.clearFinished,"data-testid":`kb-upload-clear`,children:`Dismiss`})]}),(0,X.jsx)(`div`,{className:`min-h-0 space-y-1 overflow-y-auto px-3 pb-2`,children:e.uploads.map(n=>(0,X.jsx)(Wr,{upload:n,onOpen:t,onRetry:()=>e.retry(n.id)},n.id))})]})}var Ur={pending:`Parsing…`,ok:`Open`,partial:`Open · partly parsed`,failed:`Parse failed`};function Wr({upload:e,onOpen:t,onRetry:n}){let r=Ct(e.status===`done`?e.kbId:null).data?.documents.find(t=>t.id===e.document?.id)??e.document;return(0,X.jsxs)(`div`,{"data-testid":`kb-upload-item`,"data-status":e.status,"data-parse-state":r?.parse_state,className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.file.name}),e.status===`uploading`&&(0,X.jsx)(`span`,{className:`h-1.5 w-24 overflow-hidden rounded-full bg-surface-high`,role:`progressbar`,"aria-label":`Upload progress`,"aria-valuenow":Math.round(e.progress*100),children:(0,X.jsx)(`span`,{className:`block h-full bg-primary`,style:{width:`${Math.round(e.progress*100)}%`}})}),e.status===`done`&&r&&(0,X.jsx)(`button`,{type:`button`,className:l(`hover:underline`,r.parse_state===`failed`?`text-error`:`text-primary`),onClick:()=>t(r.id),children:Ur[r.parse_state]}),e.status===`failed`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{role:`alert`,className:`text-error`,children:e.error}),(0,X.jsx)(d,{size:`sm`,variant:`ghost`,onClick:n,"data-testid":`kb-upload-retry`,children:`Retry`})]})]})}function Gr(e){return e?.[e.length-1]}export{Nr as default};
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MarkdownRenderer-C4od8dIW.js","assets/rolldown-runtime-DSDNlrLa.js","assets/jsx-runtime-CVMpzJz9.js","assets/bundle-mjs-geeEdoSy.js","assets/button-CXYVslgR.js","assets/client-nzMXason.js","assets/preload-helper-BLdHbfdN.js","assets/dialog-Juth7dP_.js","assets/x-CiIWeCBP.js","assets/dist-bytwC6rk.js","assets/es2015-w69PgVrA.js","assets/document-display-BQ5dM8QT.js","assets/index-C60WCVxH.js","assets/QueryClientProvider-DlPztvhd.js","assets/useMutation-HX90wI4L.js","assets/chunk-OB3PAWPO-1IihCzFx.js","assets/tabs-Cv3KJIRq.js","assets/dist-DxwmSTqz.js","assets/dist-Ct6061MC.js","assets/label-wk_QKooL.js","assets/select-Cj-m0J9A.js","assets/dist-D8Wfxh48.js","assets/check-DOY0CJBh.js","assets/chevron-down-hj6o3_QU.js","assets/MarkdownEditor-CPlYZ0ux.js","assets/file-kind-BYU1kv95.js","assets/schemas-CGoaq3B4.js","assets/textarea-Bt1FBmGL.js","assets/bulk-actions-C8S1Gt4W.js","assets/index-ghfkdpY-.css","assets/mermaid.core-CE0shN4j.js","assets/chunk-Y2CYZVJY-DsF7k-Jl.js","assets/src-DpAUOMD9.js","assets/chunk-DU6HZSFF-BaVVqpDB.js","assets/chunk-75Z2AOVW-DGmxZV98.js","assets/dist-BwUkq7ma.js","assets/chunk-P2QGCYS3-DpMkYw3X.js","assets/chunk-PWAF6VOD-CP1kSMru.js","assets/chunk-GMAD6QVW-D7d5cxQ3.js","assets/chunk-4HAMMTFA-DY6eE90t.js","assets/rough.esm-Dy-Kn_BL.js","assets/chunk-GVQU2GXP-GfOuiNH1.js","assets/chunk-L3NEJ4N5-BD8q2mez.js","assets/chunk-OSK3NFVY-DN8XtEwT.js","assets/line-BmNPsHiE.js","assets/path-fybaL0A-.js","assets/array-BifhSqXX.js","assets/graphlib-DS17s2tU.js","assets/wiki-links-A52THGx_.js"])))=>i.map(i=>d[i]);
2
+ import{a as e}from"./rolldown-runtime-DSDNlrLa.js";import{n as t,t as n}from"./jsx-runtime-CVMpzJz9.js";import{t as r}from"./preload-helper-BLdHbfdN.js";var i=e(t(),1),a=n(),o=(0,i.lazy)(()=>r(()=>import(`./MarkdownRenderer-C4od8dIW.js`).then(e=>({default:e.MarkdownRenderer})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48]))),s=(0,i.memo)(function(e){let{fallback:t,...n}=e;return(0,a.jsx)(i.Suspense,{fallback:t??(0,a.jsx)(`div`,{role:`status`,className:`text-sm text-outline`,children:`Loading document…`}),children:(0,a.jsx)(o,{...n})})});export{s as t};
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SourceEditor-BXHhVnEe.js","assets/rolldown-runtime-DSDNlrLa.js","assets/jsx-runtime-CVMpzJz9.js","assets/client-nzMXason.js","assets/Markdown-cNY95m5f.js","assets/preload-helper-BLdHbfdN.js","assets/file-kind-BYU1kv95.js","assets/index-C60WCVxH.js","assets/QueryClientProvider-DlPztvhd.js","assets/useMutation-HX90wI4L.js","assets/bundle-mjs-geeEdoSy.js","assets/chunk-OB3PAWPO-1IihCzFx.js","assets/button-CXYVslgR.js","assets/dist-bytwC6rk.js","assets/es2015-w69PgVrA.js","assets/x-CiIWeCBP.js","assets/tabs-Cv3KJIRq.js","assets/dist-DxwmSTqz.js","assets/dist-Ct6061MC.js","assets/label-wk_QKooL.js","assets/select-Cj-m0J9A.js","assets/dist-D8Wfxh48.js","assets/check-DOY0CJBh.js","assets/chevron-down-hj6o3_QU.js","assets/schemas-CGoaq3B4.js","assets/textarea-Bt1FBmGL.js","assets/document-display-BQ5dM8QT.js","assets/dialog-Juth7dP_.js","assets/bulk-actions-C8S1Gt4W.js","assets/index-ghfkdpY-.css"])))=>i.map(i=>d[i]);
2
+ import{a as e}from"./rolldown-runtime-DSDNlrLa.js";import{n as t,t as n}from"./jsx-runtime-CVMpzJz9.js";import{t as r}from"./button-CXYVslgR.js";import{d as i}from"./client-nzMXason.js";import{t as a}from"./preload-helper-BLdHbfdN.js";import{t as o}from"./Markdown-cNY95m5f.js";import{r as s}from"./document-display-BQ5dM8QT.js";import{t as c}from"./file-kind-BYU1kv95.js";var l={name:`maximize-2`,size:24,node:[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`m21 3-7 7`,key:`1l2asr`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M9 21H3v-6`,key:`wtvkvv`}]]};l.node;var u=i(l),d={name:`minimize-2`,size:24,node:[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]};d.node;var f=i(d),p=e(t(),1),m=n(),h=(0,p.lazy)(()=>a(()=>import(`./SourceEditor-BXHhVnEe.js`).then(e=>({default:e.SourceEditor})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29])));function g(e){return(0,m.jsx)(p.Suspense,{fallback:(0,m.jsx)(`div`,{style:{height:e.height??320},className:`p-3 text-xs text-outline`,children:`Loading editor...`}),children:(0,m.jsx)(h,{...e})})}function _(e,t){if(!t)return e;let n=e.match(/^\s*#[ \t]+(.+?)[ \t#]*(?:\r?\n|$)/),r=e=>e.trim().replace(/\s+/g,` `).toLowerCase();return n?.[1]&&r(n[1])===r(t)?e.slice(n[0].length):e}function v({path:e,value:t,onChange:n,onSave:i,readOnly:a=!1,testId:l,wikiLinks:d,initialMode:h,mode:v,onModeChange:y,header:b,height:x,id:S,label:C,placeholder:w,expanded:T,onExpandedChange:E,layout:D=`frame`,actions:O,notice:k,pageTitle:A,hideFrontmatter:j=!1,compact:M=!1}){let N=c(e),[P,F]=(0,p.useState)(h??(a&&N?`read`:`edit`)),I=v??P;function L(e){F(e),y?.(e)}let[R,z]=(0,p.useState)(!1),B=T??R,V=(0,p.useRef)(null);(0,p.useEffect)(()=>{if(!B||!V.current)return;let e=[],t=V.current;for(;t.parentElement;){let n=t.parentElement;for(let r of Array.from(n.children))r!==t&&r instanceof HTMLElement&&(e.push({element:r,inert:r.inert}),r.inert=!0);if(n.hasAttribute(`data-document-container`)||n===document.body)break;t=n}return()=>{for(let t of e)t.element.inert=t.inert}},[B]);function H(e){z(e),E?.(e)}(0,p.useEffect)(()=>{if(!B)return;function e(e){if(e.key!==`Escape`||e.defaultPrevented)return;let t=document.querySelector(`[role="dialog"], [role="alertdialog"]`);(!t||V.current?.contains(t))&&(z(!1),E?.(!1))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[B,E]);let U=s(t),W=_(U.body,A),G=D===`page`&&N&&!B;return(0,m.jsxs)(`section`,{ref:V,"data-testid":`markdown-editor`,"data-expanded":B,"data-document-expanded":B,className:`flex min-w-0 flex-col ${G?``:`min-h-0 rounded-md border border-surface-highest bg-surface`} ${B?`fixed inset-2 z-60 sm:inset-6`:``}`,style:B||G?void 0:{height:x??`min(65dvh, 760px)`,minHeight:x?void 0:280},"aria-label":`Document ${e}`,onKeyDown:e=>{e.defaultPrevented||(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&(e.preventDefault(),i?.())},children:[b&&(0,m.jsx)(`div`,{className:`shrink-0 border-b border-surface-highest p-3`,children:b}),(0,m.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center ${M?`gap-1`:`gap-2`} border-b border-surface-highest ${G?`sticky top-0 z-10 bg-background py-2`:M?`px-2 py-1`:`p-2`}`,children:[N&&(0,m.jsx)(`fieldset`,{className:`flex gap-1`,"aria-label":`Document mode`,children:[`read`,`edit`,`split`].map(e=>(0,m.jsx)(r,{type:`button`,size:`sm`,variant:!M&&I===e?`default`:`ghost`,className:`${e===`split`&&D===`page`?`hidden md:inline-flex`:``} ${M&&I===e?`bg-surface-highest text-on-surface`:``}`,"data-testid":`markdown-mode-${e}`,"aria-pressed":I===e,onClick:()=>L(e),children:e===`read`?`Read`:e===`edit`?a?`Source`:`Edit`:`Split`},e))}),(0,m.jsx)(`span`,{className:`min-w-0 flex-1 truncate px-1 text-xs text-outline`,title:e,children:D===`page`||M?``:e}),O,B&&i&&!b&&!O&&(0,m.jsx)(r,{type:`button`,"data-testid":`markdown-save`,disabled:a,onClick:i,children:`Save`}),(0,m.jsx)(r,{type:`button`,size:`icon`,variant:`ghost`,"data-testid":`markdown-expand`,"aria-label":B?`Exit fullscreen`:`Expand editor`,"aria-pressed":B,onClick:()=>H(!B),children:B?(0,m.jsx)(f,{size:16}):(0,m.jsx)(u,{size:16})})]}),k&&(0,m.jsx)(`div`,{className:`shrink-0 space-y-1 border-b border-surface-highest ${G?`py-2`:`p-3`}`,children:k}),(0,m.jsxs)(`div`,{className:`grid min-h-0 min-w-0 flex-1 ${G?`items-start gap-6 pt-4`:`overflow-hidden`} ${I===`split`&&N?`grid-rows-2 md:grid-cols-2 md:grid-rows-1`:`grid-cols-1`}`,children:[(0,m.jsx)(`div`,{className:`min-h-0 min-w-0 ${G?`[&_.cm-editor]:min-h-[50dvh]`:`overflow-hidden`} ${I===`read`&&N?`hidden`:``}`,children:(0,m.jsx)(g,{path:e,value:t,onChange:n,onSave:i,readOnly:a,height:G?`auto`:`100%`,testId:l,hidePreview:!0,defaultWrap:!0,id:S,label:C,placeholder:w})}),N&&I!==`edit`&&(0,m.jsx)(`article`,{"data-testid":`markdown-preview`,"aria-label":`Rendered Markdown`,className:`min-h-0 min-w-0 ${G?`pb-6`:`overflow-auto p-4 sm:p-8`} ${I===`split`&&!G?`border-t border-surface-highest md:border-l md:border-t-0`:``}`,children:(0,m.jsxs)(`div`,{className:`wrap-break-word ${G?`[&_:is(p,ul,ol,blockquote,h1,h2,h3,h4,h5,h6)]:max-w-[72ch]`:`mx-auto max-w-[76ch]`}`,children:[U.metadata!==null&&!j&&(0,m.jsxs)(`details`,{className:`mb-5 rounded border border-surface-highest p-3 text-sm text-outline`,children:[(0,m.jsx)(`summary`,{className:`cursor-pointer`,children:`Document metadata`}),(0,m.jsx)(`pre`,{className:`mt-3 whitespace-pre-wrap wrap-break-word font-mono text-xs`,children:U.metadata})]}),t.trim()?(0,m.jsx)(o,{readable:!0,wikiLinks:d,children:W}):(0,m.jsx)(`p`,{className:`text-sm text-outline`,children:`This document is empty.`})]})})]})]})}export{u as i,g as n,f as r,v as t};