orc-ai 0.1.49 → 0.1.50
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.
- package/dist/index.js +514 -485
- package/dist/skills/orc-platform/SKILL.md +2 -1
- package/dist/skills/orc-platform/references/scratchpads.md +140 -0
- package/dist/skills/orc-sdlc/references/planning.md +2 -0
- package/dist/web/assets/{Agents-C8dJX8px.js → Agents-DT7Kw4C9.js} +1 -1
- package/dist/web/assets/Assistant-Bold-gm-uSS1B.woff2 +0 -0
- package/dist/web/assets/Assistant-Medium-DrcxCXg3.woff2 +0 -0
- package/dist/web/assets/Assistant-Regular-DVxZuzxb.woff2 +0 -0
- package/dist/web/assets/Assistant-SemiBold-SCI4bEL9.woff2 +0 -0
- package/dist/web/assets/{Attention-BHYo8Lwr.js → Attention-Bibod5n4.js} +1 -1
- package/dist/web/assets/{Audit-CS_DZkbJ.js → Audit-DtPRrWXW.js} +1 -1
- package/dist/web/assets/{ConfirmDialog-CrSa87VF.js → ConfirmDialog-C_exU7Ga.js} +1 -1
- package/dist/web/assets/Dashboard-CUI_9Hz5.js +1 -0
- package/dist/web/assets/{DocumentWorkspace-CNyVQTjg.js → DocumentWorkspace-1MKzrR1V.js} +1 -1
- package/dist/web/assets/{EmptyState-Ctm7L70B.js → EmptyState-BVLws_BR.js} +1 -1
- package/dist/web/assets/{ErrorState-BPTepwiG.js → ErrorState-CwOWC9Qy.js} +1 -1
- package/dist/web/assets/{FileEditor-Dh29_xCL.js → FileEditor-Da165c-z.js} +1 -1
- package/dist/web/assets/{JobWebhooks-TvAY8p1V.js → JobWebhooks-hQGYLoqm.js} +1 -1
- package/dist/web/assets/{Jobs-C5ggSs2T.js → Jobs-8NrwRdn6.js} +3 -3
- package/dist/web/assets/Knowledge-HYfSkIC7.js +28 -0
- package/dist/web/assets/{PackageCatalog-B1U3vfhW.js → PackageCatalog-136z9RG3.js} +5 -5
- package/dist/web/assets/{Pager-ClYYU9et.js → Pager-BNTTeR5A.js} +1 -1
- package/dist/web/assets/{PriorityBadge-BW-A50LE.js → PriorityBadge-DHoaJR_M.js} +1 -1
- package/dist/web/assets/Projects-k8zYVv6p.js +3 -0
- package/dist/web/assets/ResumeActions-RtezaXDE.js +1 -0
- package/dist/web/assets/{Rules-DGKsAbTf.js → Rules-DhBnNVaL.js} +1 -1
- package/dist/web/assets/Scratchpads-ayvsVZxj.js +20 -0
- package/dist/web/assets/Sessions-69xt5f84.js +5 -0
- package/dist/web/assets/{Settings-yW1S2q4F.js → Settings-CQgEWLgI.js} +6 -6
- package/dist/web/assets/{Skills-BwdXE5nT.js → Skills-DBDN8e6r.js} +3 -3
- package/dist/web/assets/{SourceEditor-ft02z20v.js → SourceEditor-YTDMGFWW.js} +1 -1
- package/dist/web/assets/{StatusBadge-C5G1fdZh.js → StatusBadge-Cq2xO_SU.js} +1 -1
- package/dist/web/assets/TagInput-DDhc6WTI.js +1 -0
- package/dist/web/assets/{TaskDetailSheet-fUSHPFB-.js → TaskDetailSheet-BfRXcm8m.js} +2 -2
- package/dist/web/assets/{Tasks-uRqvmLz7.js → Tasks-DNk7-wgj.js} +5 -5
- package/dist/web/assets/{Terminals-W5nszLI1.js → Terminals-DjEvs39w.js} +7 -7
- package/dist/web/assets/{ViewHeader-DXR0ZaMO.js → ViewHeader-B9EgQxZk.js} +1 -1
- package/dist/web/assets/{Webhooks-lXLoKWdt.js → Webhooks-BvLKR0jj.js} +1 -1
- package/dist/web/assets/abnfDiagram-VCTEODGH-BuQM5S1v.js +1 -0
- package/dist/web/assets/ar-SA-G6X2FPQ2-BjnbTjeM.js +10 -0
- package/dist/web/assets/arc-DFP6bOTS.js +1 -0
- package/dist/web/assets/architectureDiagram-5GKGNRK7-BFJa9U2j.js +36 -0
- package/dist/web/assets/arrow-left-BTl_37z8.js +6 -0
- package/dist/web/assets/az-AZ-76LH7QW2-B8PZ0GKj.js +1 -0
- package/dist/web/assets/bg-BG-XCXSNQG7-DI7GiV-4.js +5 -0
- package/dist/web/assets/{blockDiagram-I7D4REHJ-DMrufypV.js → blockDiagram-I7D4REHJ-Cizo9Hl8.js} +3 -3
- package/dist/web/assets/bn-BD-2XOGV67Q-Dr7ktQFH.js +5 -0
- package/dist/web/assets/{c4Diagram-7LVT6UL2-BUUxjwvU.js → c4Diagram-7LVT6UL2-D8DiqXy4.js} +2 -2
- package/dist/web/assets/ca-ES-6MX7JW3Y-DqmXjVpI.js +8 -0
- package/dist/web/assets/channel-DbXZPmMe.js +1 -0
- package/dist/web/assets/chunk-2Q5K7J3B-JhTVpDn1.js +1 -0
- package/dist/web/assets/{chunk-5VM5RSS4-B6lAVcgQ.js → chunk-5VM5RSS4-BZ8K5AGw.js} +1 -1
- package/dist/web/assets/chunk-F27PBJKO-_mlKDDbq.js +1 -0
- package/dist/web/assets/{chunk-IMKFNOWR-CwyogA-y.js → chunk-IMKFNOWR-BnFGiWsy.js} +1 -1
- package/dist/web/assets/chunk-JWPE2WC7-bbN-huXf.js +1 -0
- package/dist/web/assets/chunk-POPQ4Y6H-wnVtHn_O.js +1 -0
- package/dist/web/assets/{chunk-SVP7TREG-CmiQdvOH.js → chunk-SVP7TREG-B1kaWVdh.js} +4 -4
- package/dist/web/assets/{chunk-TICWLB2K-CieIpfOy.js → chunk-TICWLB2K-BQ8K51Oc.js} +1 -1
- package/dist/web/assets/chunk-XXDRQBXY-CCJyOiYl.js +1 -0
- package/dist/web/assets/classDiagram-ZZMXUADV-BQ5ONiWc.js +1 -0
- package/dist/web/assets/classDiagram-v2-VYDZK3BY-BQ5ONiWc.js +1 -0
- package/dist/web/assets/copy-DsS5X55x.js +6 -0
- package/dist/web/assets/cose-bilkent-JH36ORCC-BKztu1Kn.js +1 -0
- package/dist/web/assets/cs-CZ-2BRQDIVT-qn9_RBqW.js +11 -0
- package/dist/web/assets/{cynefin-OW5HDTMX-vMXgcpgg.js → cynefin-OW5HDTMX-YAbh6GHR.js} +1 -1
- package/dist/web/assets/cynefinDiagram-5FMLGOSQ-CWidjPb8.js +62 -0
- package/dist/web/assets/da-DK-5WZEPLOC-DpER4jvL.js +5 -0
- package/dist/web/assets/{dagre-GXQ25YYZ-xmoviGlr.js → dagre-GXQ25YYZ-BuzvSdX0.js} +2 -2
- package/dist/web/assets/de-DE-XR44H4JA-CtleMrwo.js +8 -0
- package/dist/web/assets/{diagram-S7CK7UJ4-CguQzzXs.js → diagram-S7CK7UJ4-Ch-rAjmB.js} +5 -5
- package/dist/web/assets/diagram-UQ7AKVKN-DhixRZev.js +41 -0
- package/dist/web/assets/{diagram-VSXAHHWV-cuhv3Fvj.js → diagram-VSXAHHWV-4FwHTQjS.js} +3 -3
- package/dist/web/assets/diagram-VX7I27RA-BE_c4-lI.js +24 -0
- package/dist/web/assets/diagram-Z3DM3KII-j49FiH9W.js +24 -0
- package/dist/web/assets/directory-open-01563666-DWU9wJ6I.js +1 -0
- package/dist/web/assets/directory-open-4ed118d0-CunoC1EB.js +1 -0
- package/dist/web/assets/{download-UgMvjBjR.js → download-DCNlFjgq.js} +1 -1
- package/dist/web/assets/ebnfDiagram-PWID7BFC-DJd8fyb-.js +1 -0
- package/dist/web/assets/el-GR-BZB4AONW-DOGQ2uKF.js +10 -0
- package/dist/web/assets/erDiagram-RLTQ6QDP-CIzsltIW.js +99 -0
- package/dist/web/assets/es-ES-U4NZUMDT-BV7Xnx76.js +9 -0
- package/dist/web/assets/eu-ES-A7QVB2H4-Cy6tNdQP.js +11 -0
- package/dist/web/assets/excalidraw/fonts/Assistant/Assistant-Bold.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/Assistant/Assistant-Medium.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/Assistant/Assistant-Regular.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/Assistant/Assistant-SemiBold.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/Cascadia/CascadiaCode-Regular.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/ComicShanns/ComicShanns-Regular-279a7b317d12eb88de06167bd672b4b4.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/ComicShanns/ComicShanns-Regular-6e066e8de2ac57ea9283adb9c24d7f0c.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/ComicShanns/ComicShanns-Regular-dc6a8806fa96795d7b3be5026f989a17.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/ComicShanns/ComicShanns-Regular-fcb0fc02dcbee4c9846b3e2508668039.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/Excalifont/Excalifont-Regular-349fac6ca4700ffec595a7150a0d1e1d.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/Excalifont/Excalifont-Regular-3f2c5db56cc93c5a6873b1361d730c16.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/Excalifont/Excalifont-Regular-41b173a47b57366892116a575a43e2b6.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/Excalifont/Excalifont-Regular-623ccf21b21ef6b3a0d87738f77eb071.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/Excalifont/Excalifont-Regular-a88b72a24fb54c9f94e3b5fdaa7481c9.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/Excalifont/Excalifont-Regular-b9dcf9d2e50a1eaf42fc664b50a3fd0d.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/Excalifont/Excalifont-Regular-be310b9bcd4f1a43f571c46df7809174.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/Liberation/LiberationSans-Regular.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/Lilita/Lilita-Regular-i7dPIFZ9Zz-WBtRtedDbYE98RXi4EwSsbg.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/Lilita/Lilita-Regular-i7dPIFZ9Zz-WBtRtedDbYEF8RXi4EwQ.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/Nunito/Nunito-Regular-XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhdTA3j6zbXWjgevT5.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/Nunito/Nunito-Regular-XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhdTQ3j6zbXWjgeg.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/Nunito/Nunito-Regular-XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhdTk3j6zbXWjgevT5.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/Nunito/Nunito-Regular-XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhdTo3j6zbXWjgevT5.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/Nunito/Nunito-Regular-XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhdTs3j6zbXWjgevT5.woff2 +0 -0
- package/dist/web/assets/excalidraw/fonts/Virgil/Virgil-Regular.woff2 +0 -0
- package/dist/web/assets/fa-IR-HGAKTJCU-CbOnhX3T.js +8 -0
- package/dist/web/assets/fi-FI-Z5N7JZ37-qra5-Mob.js +6 -0
- package/dist/web/assets/file-open-002ab408-DIuFHtCF.js +1 -0
- package/dist/web/assets/file-open-7c801643-684qeFg4.js +1 -0
- package/dist/web/assets/file-save-3189631c-C1wFhQhH.js +1 -0
- package/dist/web/assets/file-save-745eba88-Bb9F9Kg7.js +1 -0
- package/dist/web/assets/{flowDiagram-HODETNUW-DueO0Ju6.js → flowDiagram-HODETNUW-AX8L-l_p.js} +5 -5
- package/dist/web/assets/folder-open-DAIhPqFI.js +11 -0
- package/dist/web/assets/fr-FR-RHASNOE6-DN9byp9Y.js +9 -0
- package/dist/web/assets/ganttDiagram-EL5Y4UJY-CETcz11y.js +292 -0
- package/dist/web/assets/gitGraphDiagram-WWUBYQGX-DrDRWd07.js +106 -0
- package/dist/web/assets/gl-ES-HMX3MZ6V-BylDWANB.js +10 -0
- package/dist/web/assets/he-IL-6SHJWFNN-BIl3mWuh.js +10 -0
- package/dist/web/assets/hi-IN-IWLTKZ5I-DeQ5X6EO.js +4 -0
- package/dist/web/assets/highlighted-body-KPVGNVTW-CKHMZ0iS.js +1 -0
- package/dist/web/assets/hu-HU-A5ZG7DT2-0hYCWJJc.js +7 -0
- package/dist/web/assets/id-ID-SAP4L64H-Dhbb7S2T.js +10 -0
- package/dist/web/assets/image-blob-reduce.esm-D6s-rqMO.js +7 -0
- package/dist/web/assets/index-3slyF2Z-.js +19 -0
- package/dist/web/assets/index-CY60J5zm.css +1 -0
- package/dist/web/assets/{index-C_jtMgr7.js → index-Ckq9CvHb.js} +89 -89
- package/dist/web/assets/infoDiagram-27XIBGKW-ST1zQCsj.js +2 -0
- package/dist/web/assets/{ishikawaDiagram-5VMMS53U-ccIPCUs4.js → ishikawaDiagram-5VMMS53U-B3SJTPoL.js} +5 -5
- package/dist/web/assets/it-IT-JPQ66NNP-BhOQg5cl.js +11 -0
- package/dist/web/assets/ja-JP-DBVTYXUO-BPw0tly-.js +8 -0
- package/dist/web/assets/{journeyDiagram-3NMN7TZE-rRe3uTLu.js → journeyDiagram-3NMN7TZE-B5lzDs3v.js} +2 -2
- package/dist/web/assets/kaa-6HZHGXH3-C5_ZIpfZ.js +1 -0
- package/dist/web/assets/kab-KAB-ZGHBKWFO-iqn4ZTub.js +8 -0
- package/dist/web/assets/{kanban-definition-UXKFOSKX-tAKCWntJ.js → kanban-definition-UXKFOSKX-BwPssY6F.js} +6 -6
- package/dist/web/assets/kk-KZ-P5N5QNE5-jAgtA3a3.js +1 -0
- package/dist/web/assets/km-KH-HSX4SM5Z-BE4HhYBv.js +11 -0
- package/dist/web/assets/ko-KR-MTYHY66A-BeajeVaX.js +9 -0
- package/dist/web/assets/ku-TR-6OUDTVRD-AogZs9l4.js +9 -0
- package/dist/web/assets/layout-CrpljNKI.js +1 -0
- package/dist/web/assets/linear-Bo2HXNnf.js +1 -0
- package/dist/web/assets/{list-BL4eRkIg.js → list-W5PAwY_1.js} +1 -1
- package/dist/web/assets/live-sessions-C4qBcPbR.js +6 -0
- package/dist/web/assets/lt-LT-XHIRWOB4-VJAq27RW.js +3 -0
- package/dist/web/assets/lv-LV-5QDEKY6T-DhV43c3O.js +7 -0
- package/dist/web/assets/mermaid-HWGCJPDP-CSzVGSXu.js +299 -0
- package/dist/web/assets/mermaid.core-BYL6TaO8.js +312 -0
- package/dist/web/assets/{mindmap-definition-YA3MSWOX-Cj5-j6a7.js → mindmap-definition-YA3MSWOX-EvJgLjwn.js} +4 -4
- package/dist/web/assets/mr-IN-CRQNXWMA-DSWzmLM0.js +13 -0
- package/dist/web/assets/my-MM-5M5IBNSE-gJ2ISU-G.js +1 -0
- package/dist/web/assets/nb-NO-T6EIAALU-DAwLq2T7.js +10 -0
- package/dist/web/assets/nl-NL-IS3SIHDZ-CjE7CpT4.js +8 -0
- package/dist/web/assets/nn-NO-6E72VCQL-CTVNnELU.js +8 -0
- package/dist/web/assets/oc-FR-POXYY2M6-vcMaQvFU.js +8 -0
- package/dist/web/assets/pa-IN-N4M65BXN-DJg1bUGg.js +4 -0
- package/dist/web/assets/pegDiagram-XKGWAZYB-TqqcNwRV.js +1 -0
- package/dist/web/assets/{pencil-gxvh59uO.js → pencil-CxDR8VFb.js} +1 -1
- package/dist/web/assets/percentages-BXMCSKIN-CnGxO6II.js +180 -0
- package/dist/web/assets/percentages-BXMCSKIN-DGBKIvAv.css +1 -0
- package/dist/web/assets/pica-DVsMi-pt.js +7 -0
- package/dist/web/assets/pieDiagram-E7YTZNPT-CjwbCJae.js +39 -0
- package/dist/web/assets/pl-PL-T2D74RX3-B499NViP.js +9 -0
- package/dist/web/assets/pt-BR-5N22H2LF-C99TatKy.js +9 -0
- package/dist/web/assets/pt-PT-UZXXM6DQ-DywHBJAr.js +9 -0
- package/dist/web/assets/{quadrantDiagram-AXDQQJYC-DKTP6jS5.js → quadrantDiagram-AXDQQJYC-C8k5-2L4.js} +1 -1
- package/dist/web/assets/railroadDiagram-O6MQD6OU-DN6DTUJL.js +1 -0
- package/dist/web/assets/{refresh-cw-BQRdbjy6.js → refresh-cw-C429XUIu.js} +1 -1
- package/dist/web/assets/{requirementDiagram-BXWQKSXE-B9hH69zu.js → requirementDiagram-BXWQKSXE-Yx4CbxBQ.js} +2 -2
- package/dist/web/assets/ro-RO-JPDTUUEW-BrIt0gdu.js +11 -0
- package/dist/web/assets/roundRect-0PYZxl1G.js +1 -0
- package/dist/web/assets/ru-RU-B4JR7IUQ-DikO_eDS.js +9 -0
- package/dist/web/assets/sankeyDiagram-P5KCCOFB-ChZBsAuF.js +40 -0
- package/dist/web/assets/{save-CYoz3QKB.js → save-Ca2pCtPv.js} +1 -1
- package/dist/web/assets/save-file-B_ZN6-id.js +1 -0
- package/dist/web/assets/scratchpad-routes-Cf4VNpSR.js +11 -0
- package/dist/web/assets/scroll-area-CUm8aggx.js +1 -0
- package/dist/web/assets/{sequenceDiagram-WJ2MYXX4-BF77J63J.js → sequenceDiagram-WJ2MYXX4-BJDwmaZp.js} +2 -2
- package/dist/web/assets/si-LK-N5RQ5JYF-BGOkewnb.js +1 -0
- package/dist/web/assets/sizeCapture-INFHLROL-DCT6mGJl.js +1 -0
- package/dist/web/assets/sk-SK-C5VTKIMK-Ci61SpsN.js +6 -0
- package/dist/web/assets/sl-SI-NN7IZMDC--KoF29T9.js +6 -0
- package/dist/web/assets/stateDiagram-D77RDMKH-DCAGD_ib.js +1 -0
- package/dist/web/assets/stateDiagram-v2-MP3YSRHH-BMQGBnFo.js +1 -0
- package/dist/web/assets/subset-shared.chunk-BwhnPDcu.js +84 -0
- package/dist/web/assets/subset-worker.chunk-Cnt_77Lu.js +1 -0
- package/dist/web/assets/sv-SE-XGPEYMSR-C0StL-sk.js +10 -0
- package/dist/web/assets/swimlanes-42K2YHIH-DPwHOZ8T.js +1 -0
- package/dist/web/assets/swimlanesDiagram-VR7AAH4N-DGqsbuuX.js +8 -0
- package/dist/web/assets/ta-IN-2NMHFXQM-D7MMI2_6.js +9 -0
- package/dist/web/assets/{table-D3N_5Wee.js → table-DTKUFFYV.js} +1 -1
- package/dist/web/assets/tabs-DcYod54F.js +1 -0
- package/dist/web/assets/th-TH-HPSO5L25-hlqKs6HJ.js +2 -0
- package/dist/web/assets/{timeline-definition-24CTP7MA-owGoHn8z.js → timeline-definition-24CTP7MA-7K6IPjAN.js} +8 -8
- package/dist/web/assets/tr-TR-DEFEU3FU-lJQToQnP.js +7 -0
- package/dist/web/assets/{trash-2-D3Ey4I09.js → trash-2-BOe9xa7a.js} +1 -1
- package/dist/web/assets/uk-UA-QMV73CPH-HdtjtiKv.js +6 -0
- package/dist/web/assets/{upload-DhVOCWST.js → upload-ZufDR-3q.js} +1 -1
- package/dist/web/assets/{useDetailRoute-j9nlwack.js → useDetailRoute-BvTqyOr1.js} +1 -1
- package/dist/web/assets/{useJobs-Dcl-Vim3.js → useJobs-rLcb_CgS.js} +1 -1
- package/dist/web/assets/{useKnowledge-gIjk0_I1.js → useKnowledge-DcZD9AcU.js} +1 -1
- package/dist/web/assets/{useListSelection-CSQd_Hmx.js → useListSelection-CyPVxpFj.js} +1 -1
- package/dist/web/assets/{useMemories-B8Zpz0Qz.js → useMemories-7v8TIl7-.js} +1 -1
- package/dist/web/assets/useProjectScope-C3iwCwG_.js +1 -0
- package/dist/web/assets/{useSessions-BrdK-12R.js → useSessions-BL5wWTxP.js} +1 -1
- package/dist/web/assets/vennDiagram-4TSXK5OY-Dfm3Tyo8.js +34 -0
- package/dist/web/assets/vi-VN-M7AON7JQ-Dj3F3Qzf.js +5 -0
- package/dist/web/assets/{view-params-Bm1Qf6KC.js → view-params-BeBdfQW5.js} +1 -1
- package/dist/web/assets/{wardleyDiagram-VM6X3IG4-D9GbTBKy.js → wardleyDiagram-VM6X3IG4-B6O-_Buj.js} +2 -2
- package/dist/web/assets/{xychartDiagram-S5SC5T6Z-BFqPF2Hl.js → xychartDiagram-S5SC5T6Z-BSRb_uOW.js} +4 -4
- package/dist/web/assets/zh-CN-LNUGB5OW-DAzBdZtp.js +10 -0
- package/dist/web/assets/zh-HK-E62DVLB3-C_VeJG0z.js +1 -0
- package/dist/web/assets/zh-TW-RAJ6MFWO-DRZgKpha.js +9 -0
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/web/assets/Dashboard-V813oIhq.js +0 -1
- package/dist/web/assets/Knowledge-BpiN3iVE.js +0 -28
- package/dist/web/assets/Projects-DRao5Qpk.js +0 -3
- package/dist/web/assets/ResumeActions-DHTOr6GQ.js +0 -11
- package/dist/web/assets/Sessions-CWHU6sYy.js +0 -5
- package/dist/web/assets/abnfDiagram-VCTEODGH-K8P_VxLi.js +0 -1
- package/dist/web/assets/arc-BOl9BKfD.js +0 -1
- package/dist/web/assets/architectureDiagram-5GKGNRK7-DIZ15fO5.js +0 -36
- package/dist/web/assets/channel-CQFNQIhG.js +0 -1
- package/dist/web/assets/chunk-2Q5K7J3B-wRIxA2_q.js +0 -1
- package/dist/web/assets/chunk-F27PBJKO-DVuei-Pl.js +0 -1
- package/dist/web/assets/chunk-JWPE2WC7-zdsOarNZ.js +0 -1
- package/dist/web/assets/chunk-POPQ4Y6H-D3ieeKih.js +0 -1
- package/dist/web/assets/chunk-XXDRQBXY-BoTHwisB.js +0 -1
- package/dist/web/assets/classDiagram-ZZMXUADV-B5yD90Df.js +0 -1
- package/dist/web/assets/classDiagram-v2-VYDZK3BY-B5yD90Df.js +0 -1
- package/dist/web/assets/cose-bilkent-JH36ORCC-CtGsuuTW.js +0 -1
- package/dist/web/assets/cynefinDiagram-5FMLGOSQ-kMbm5D7e.js +0 -62
- package/dist/web/assets/diagram-UQ7AKVKN-CMX0u7Gf.js +0 -41
- package/dist/web/assets/diagram-VX7I27RA-Bp_JbX0e.js +0 -24
- package/dist/web/assets/diagram-Z3DM3KII-oZ6jRSCd.js +0 -24
- package/dist/web/assets/ebnfDiagram-PWID7BFC-DbxnEjb0.js +0 -1
- package/dist/web/assets/erDiagram-RLTQ6QDP-Cl5kXPho.js +0 -99
- package/dist/web/assets/folder-open-DojCP5NP.js +0 -16
- package/dist/web/assets/ganttDiagram-EL5Y4UJY-DNjT4iVH.js +0 -292
- package/dist/web/assets/gitGraphDiagram-WWUBYQGX-B4aUQ9gY.js +0 -106
- package/dist/web/assets/highlighted-body-KPVGNVTW-gt1u8RcC.js +0 -1
- package/dist/web/assets/index-CyjfnRiI.css +0 -1
- package/dist/web/assets/infoDiagram-27XIBGKW-CWcOvNAB.js +0 -2
- package/dist/web/assets/layout-7xCiQ5Mn.js +0 -1
- package/dist/web/assets/linear-WCNhc07o.js +0 -1
- package/dist/web/assets/mermaid-HWGCJPDP-C8QwWdo5.js +0 -609
- package/dist/web/assets/pegDiagram-XKGWAZYB-BYB3oVZ_.js +0 -1
- package/dist/web/assets/pieDiagram-E7YTZNPT-CSbpzXas.js +0 -39
- package/dist/web/assets/railroadDiagram-O6MQD6OU-Ct8aPeLX.js +0 -1
- package/dist/web/assets/sankeyDiagram-P5KCCOFB-CDqNONxU.js +0 -40
- package/dist/web/assets/scroll-area-CU4DGUBA.js +0 -1
- package/dist/web/assets/sizeCapture-INFHLROL-Dpubco_U.js +0 -1
- package/dist/web/assets/stateDiagram-D77RDMKH-CzslKEYw.js +0 -1
- package/dist/web/assets/stateDiagram-v2-MP3YSRHH-DKbNjyV-.js +0 -1
- package/dist/web/assets/swimlanes-42K2YHIH-bD_tUjo6.js +0 -1
- package/dist/web/assets/swimlanesDiagram-VR7AAH4N-0wAluWQF.js +0 -8
- package/dist/web/assets/tabs-CSlEXoxD.js +0 -1
- package/dist/web/assets/useProjectScope-Dk0mjyHf.js +0 -1
- package/dist/web/assets/vennDiagram-4TSXK5OY-D0_6bldW.js +0 -34
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import{c as ae,r as o,
|
|
1
|
+
import{c as ae,r as o,av as ge,j as e,p as d,T as G,I as f,aj as pe,ak as je,al as fe,am as Ne,an as ye,S as H,y as P,aw as ve,B as g,ad as ke,F as _e,L as Z,Y as we,P as Se,e as Ce,D as ne,m as re,n as le,o as ie,q as V,s as q,t as M,v as W,w as B,x as oe}from"./index-Ckq9CvHb.js";import{u as Te,B as De}from"./useListSelection-CyPVxpFj.js";import{C as $e}from"./ConfirmDialog-C_exU7Ga.js";import{E as Pe}from"./EmptyState-BVLws_BR.js";import{E as U}from"./ErrorState-CwOWC9Qy.js";import{J as Ee,c as de}from"./JobWebhooks-hQGYLoqm.js";import{S as Re}from"./StatusBadge-Cq2xO_SU.js";import{S as Je}from"./scroll-area-CUm8aggx.js";import{b as ze,c as Ie,d as ce,a as X,e as Le,u as Oe,f as Ae,g as Fe,h as Be}from"./useJobs-rLcb_CgS.js";import{P as K}from"./pencil-CxDR8VFb.js";import{T as Ve,a as qe,b as ee,c as L,d as Me,e as O}from"./table-DTKUFFYV.js";import{V as te}from"./ViewHeader-B9EgQxZk.js";import{u as We}from"./useDetailRoute-BvTqyOr1.js";import{u as He}from"./useProjectScope-C3iwCwG_.js";import{T as se}from"./trash-2-BOe9xa7a.js";/**
|
|
2
2
|
* @license lucide-react v1.27.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
5
5
|
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const Ue=[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]],
|
|
6
|
+
*/const Ue=[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]],Q=ae("play",Ue);/**
|
|
7
7
|
* @license lucide-react v1.27.0 - ISC
|
|
8
8
|
*
|
|
9
9
|
* This source code is licensed under the ISC license.
|
|
10
10
|
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const Ye=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],Ge=ae("power",Ye);function Y(a){return a.type==="command"?!!a.command.trim():a.type==="agent"?!!(a.prompt.trim()&&a.backend.trim()):!!a.title.trim()}function me({value:a,onChange:c}){const n=o.useId(),{data:x}=ge();return e.jsxs("section",{className:"space-y-3 border-y border-border py-4","data-testid":"job-action-fields",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{htmlFor:`${n}-type`,children:"What should this job do?"}),e.jsxs("select",{id:`${n}-type`,"data-testid":"job-action-type",className:"w-full min-h-11 rounded-md border border-control-border bg-background px-3 text-sm",value:a.type,onChange:s=>{s.target.value==="command"&&c({type:"command",command:""}),s.target.value==="agent"&&c({type:"agent",backend:"codex-cli",prompt:"",auto_approve:!1}),s.target.value==="task"&&c({type:"task",title:"",body:"",start_automatically:!1})},children:[e.jsx("option",{value:"command",children:"Run command"}),e.jsx("option",{value:"agent",children:"Run agent"}),e.jsx("option",{value:"task",children:"Create task"})]})]}),a.type==="command"&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{htmlFor:`${n}-command`,children:"Command"}),e.jsx(G,{id:`${n}-command`,"aria-label":"Command","data-testid":"job-command-input",value:a.command,onChange:s=>c({...a,command:s.target.value}),rows:3,placeholder:"bun run build",required:!0})]}),a.type==="agent"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{htmlFor:`${n}-backend`,children:"Agent backend"}),e.jsx(j,{id:`${n}-backend`,"data-testid":"job-agent-backend",value:a.backend,list:`${n}-backends`,onChange:s=>c({...a,backend:s.target.value}),required:!0}),e.jsx("datalist",{id:`${n}-backends`,children:x==null?void 0:x.backends.map(s=>e.jsx("option",{value:s.name,children:s.available?"Available":"Unavailable"},s.name))})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{htmlFor:`${n}-model`,children:"Model (optional)"}),e.jsx(j,{id:`${n}-model`,"data-testid":"job-agent-model",value:a.model??"",onChange:s=>c({...a,model:s.target.value||void 0})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{htmlFor:`${n}-prompt`,children:"Instructions"}),e.jsx(G,{id:`${n}-prompt`,"data-testid":"job-agent-prompt",value:a.prompt,onChange:s=>c({...a,prompt:s.target.value}),required:!0,rows:4})]}),e.jsxs("label",{className:"flex min-h-11 items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:a.auto_approve,onChange:s=>c({...a,auto_approve:s.target.checked})}),"Allow agent tools automatically"]}),e.jsx("p",{className:"text-xs text-outline",children:"Starts a tracked agent session. When automatic tool approval is off, permission requests are denied."})]}),a.type==="task"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{htmlFor:`${n}-title`,children:"Task title"}),e.jsx(j,{id:`${n}-title`,"data-testid":"job-task-title",value:a.title,onChange:s=>c({...a,title:s.target.value}),required:!0,maxLength:200})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{htmlFor:`${n}-body`,children:"Task instructions"}),e.jsx(G,{id:`${n}-body`,"data-testid":"job-task-body",value:a.body,onChange:s=>c({...a,body:s.target.value}),rows:4})]}),e.jsxs("label",{className:"flex min-h-11 items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox","data-testid":"job-task-autostart",checked:a.start_automatically,onChange:s=>c({...a,start_automatically:s.target.checked})}),"Start the task flow automatically"]}),a.start_automatically&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{htmlFor:`${n}-flow`,children:"Flow (blank uses the configured default)"}),e.jsx(j,{id:`${n}-flow`,"data-testid":"job-task-flow",value:a.flow_name??"",onChange:s=>c({...a,flow_name:s.target.value||void 0})})]}),e.jsx("p",{className:"text-xs text-outline",children:"Creates a task in this job's project. Automatic start is off by default; the task waits for a manual flow start."})]})]})}function Xe({jobId:a,open:c,onClose:n,onEdit:x}){var D,k,$;const{data:s,isLoading:C,error:N,refetch:T}=ze(a),{data:m,isLoading:p,error:y,refetch:u}=Ie(a),i=ce(),v=Q(),[b,E]=o.useState(null);return e.jsx(pe,{open:c,onOpenChange:h=>!h&&n(),children:e.jsxs(fe,{"data-testid":"job-detail-sheet",children:[e.jsxs(je,{children:[e.jsx(Ne,{children:(s==null?void 0:s.name)??"Job details"}),(s==null?void 0:s.description)&&e.jsx("p",{className:"font-body text-xs text-outline mt-1",children:s.description})]}),e.jsx(ye,{children:N?e.jsx(U,{message:N.message,onRetry:()=>T()}):C?e.jsx("div",{className:"space-y-3",children:[...Array(6)].map((h,_)=>e.jsx(H,{className:"h-8 w-full bg-surface-highest"},_))}):s?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(P,{label:"Action",children:e.jsx("pre",{className:"font-mono text-xs bg-background p-2 rounded-lg border border-surface-highest overflow-x-auto whitespace-pre-wrap break-all",children:((D=s.action)==null?void 0:D.type)==="agent"?`Run agent (${s.action.backend}): ${s.action.prompt}`:((k=s.action)==null?void 0:k.type)==="task"?`Create task: ${s.action.title}`:s.command})}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsx(P,{label:"Trigger Type",children:e.jsx("span",{className:"font-label text-xs px-2 py-0.5 bg-surface-highest text-on-surface-variant border border-surface-highest/50 inline-flex",children:s.trigger_type})}),e.jsx(P,{label:"Enabled",children:e.jsx("span",{className:`font-label text-xs font-bold ${s.enabled?"text-secondary":"text-outline"}`,children:s.enabled?"● ON":"○ OFF"})})]}),s.cron_expr&&e.jsx(P,{label:"Cron Expression",children:e.jsx("code",{className:"font-mono text-xs",children:s.cron_expr})}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs(P,{label:"Timeout",children:[s.timeout_secs,"s"]}),e.jsx(P,{label:"Max Retries",children:s.max_retries}),e.jsx(P,{label:"Overlap",children:s.overlap})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsx(P,{label:"Notify On",children:s.notify_on}),e.jsx(P,{label:"Run Count",children:s.run_count})]}),s.next_run_at&&e.jsx(P,{label:"Next Run",children:new Date(s.next_run_at).toLocaleString()})]}),!s.command.startsWith("__")&&e.jsx(Ee,{job:s},s.id),e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-xs font-medium text-outline mb-3",children:"Recent runs"}),y?e.jsx(U,{message:y.message,onRetry:()=>u()}):p?e.jsx("div",{className:"space-y-2",children:[...Array(3)].map((h,_)=>e.jsx(H,{className:"h-8 w-full bg-surface-highest"},_))}):m!=null&&m.length?e.jsx("div",{className:"space-y-1",children:m.map(h=>e.jsx(Ke,{run:h,jobId:a,expanded:b===h.id,onToggle:()=>E(b===h.id?null:h.id)},h.id))}):e.jsx("div",{className:"font-label text-xs text-outline py-4 text-center",children:"No runs yet"})]})]}):e.jsx("p",{className:"text-sm text-outline",children:"Job not found"})}),e.jsxs(ve,{className:"flex-wrap",children:[(v.error||i.error)&&e.jsx("p",{role:"alert",className:"w-full text-sm text-error",children:($=v.error??i.error)==null?void 0:$.message}),s&&x&&e.jsxs(g,{"data-testid":"job-detail-edit",size:"sm",variant:"outline",onClick:()=>x(s),children:[e.jsx(X,{size:16}),"Edit job"]}),s&&e.jsxs(g,{size:"sm",variant:"ghost",disabled:v.isPending,onClick:()=>v.mutate({id:s.id,enabled:!s.enabled}),className:"font-label text-xs font-medium",children:[e.jsx(Ge,{size:12,className:"mr-1.5"}),s.enabled?"Disable":"Enable"]}),s&&e.jsxs(g,{size:"sm",disabled:i.isPending,onClick:()=>i.mutate(s.id),className:"font-label text-xs font-medium bg-transparent text-on-surface border border-control-border hover:bg-surface",children:[e.jsx(K,{size:12,className:"mr-1.5"}),i.isPending?"Triggering...":"Trigger run"]})]})]})})}function Ke({run:a,jobId:c,expanded:n,onToggle:x}){return e.jsxs("div",{className:"min-w-0 border-y border-border overflow-hidden bg-background",children:[e.jsxs("button",{type:"button",onClick:x,"aria-expanded":n,className:"w-full flex items-center gap-3 px-3 py-2 hover:bg-surface transition-colors text-left",children:[n?e.jsx(ke,{size:12,className:"text-outline shrink-0"}):e.jsx(_e,{size:12,className:"text-outline shrink-0"}),e.jsx(Re,{status:a.status,type:"job"}),e.jsxs("span",{className:"font-label text-xs text-outline flex-1",children:[a.started_at?new Date(a.started_at).toLocaleString():"—",a.ended_at&&e.jsxs("span",{className:"ml-2",children:["\\u2192 ",new Date(a.ended_at).toLocaleString()]})]}),a.exit_code!==null&&e.jsxs("span",{className:`font-mono text-xs ${a.exit_code===0?"text-secondary":"text-error"}`,children:["exit ",a.exit_code]})]}),(a.task_id||a.session_id)&&e.jsxs("div",{className:"flex gap-3 px-3 py-2 text-xs",children:[a.task_id&&e.jsx(Z,{className:"underline","data-testid":"job-run-task-link",to:`/tasks/${a.task_id}?project=all`,children:"Created task"}),a.session_id&&e.jsx(Z,{className:"underline","data-testid":"job-run-session-link",to:`/audit/${a.session_id}?project=all`,children:"Agent session"})]}),a.error_msg&&e.jsx("div",{className:"px-3 pb-2",children:e.jsx("span",{className:"font-body text-xs text-error",children:a.error_msg})}),n&&e.jsx(Qe,{jobId:c,runId:a.id})]})}function Qe({jobId:a,runId:c}){const{data:n,isLoading:x,error:s,refetch:C}=Le(a,c);return s?e.jsx(U,{message:s.message,onRetry:()=>C()}):x?e.jsx("div",{className:"px-3 pb-3",children:e.jsx(H,{className:"h-24 w-full bg-surface-highest"})}):n!=null&&n.length?e.jsx("div",{className:"mx-3 mb-3 rounded-lg overflow-hidden border border-surface-highest",children:e.jsx(Je,{className:"h-[240px]",children:e.jsx("pre",{className:"font-mono text-xs leading-relaxed bg-background p-3",children:n.map(N=>e.jsx("div",{className:N.stream==="stderr"?"text-error":"text-on-surface",children:N.line},N.id))})})}):e.jsx("div",{className:"px-3 pb-3 font-label text-xs text-outline",children:"No log output"})}const xe=["one-shot","cron","watch","webhook","manual","bridge-msg"],ue=["skip","queue","kill"],be=["never","failure","always"];function gt({projectId:a}){var F,l;const c=we("sm"),n=He(a),x=n==="all"||n==="unassigned"?void 0:n,{data:s,isLoading:C,error:N,refetch:T}=Oe({project_id:x,limit:100}),m=n==="unassigned"?s==null?void 0:s.filter(t=>t.project_id===null):s,p=ce(),y=Ae(),u=Q(),i=Fe(),v=((F=i.data)==null?void 0:F.scope)===n?i.data:void 0,b=Te((m??[]).map(t=>t.id),n);async function E(t){const f=await i.mutateAsync({ids:b.selectedIds,enabled:t,scope:n});b.select(f.failed.map(S=>S.id))}const{selectedId:D,openDetail:k,closeDetail:$}=We("/jobs","jobId"),[h,_]=o.useState(!1),[A,R]=o.useState(null),[w,J]=o.useState(null);if(N)return e.jsxs("div",{children:[e.jsx(te,{title:"Jobs"}),e.jsx(U,{message:N.message,onRetry:()=>T()})]});const z=(m??[]).filter(t=>t.enabled).length;return e.jsxs("div",{children:[e.jsx(te,{title:"Jobs",meta:`${z}/${(m??[]).length} enabled`,action:e.jsxs(g,{"data-testid":"new-job-button",size:"sm",onClick:()=>_(!0),className:"font-label text-xs font-medium bg-primary text-primary-foreground hover:bg-primary/90",children:[e.jsx(Se,{size:12,className:"mr-1"})," New job"]})}),(p.error||y.error||u.error)&&e.jsx("p",{role:"alert",className:"mb-4 text-sm text-error",children:(l=p.error??y.error??u.error)==null?void 0:l.message}),!!(m!=null&&m.length)&&e.jsxs(De,{resourceLabel:"jobs",count:b.selectedIds.length,allSelected:b.allSelected,someSelected:b.someSelected,onSelectAll:b.selectAll,onClear:b.clear,disabled:i.isPending,children:[e.jsx(g,{type:"button",variant:"outline",size:"sm","data-testid":"jobs-bulk-enable",disabled:i.isPending||u.isPending,onClick:()=>void E(!0),children:"Enable selected"}),e.jsx(g,{type:"button",variant:"outline",size:"sm","data-testid":"jobs-bulk-disable",disabled:i.isPending||u.isPending,onClick:()=>void E(!1),children:"Disable selected"})]}),i.isPending&&e.jsx("p",{role:"status",className:"mb-3 text-sm text-outline",children:"Updating selected jobs…"}),!i.isPending&&v&&e.jsxs("div",{className:"mb-3 space-y-1 text-sm","data-testid":"jobs-bulk-result",role:"status",children:[e.jsxs("p",{children:[v.succeeded.length," jobs ",v.enabled?"enabled":"disabled","."]}),v.failed.map(t=>{var f;return e.jsxs("p",{className:"text-error",children:[((f=m==null?void 0:m.find(S=>S.id===t.id))==null?void 0:f.name)??t.id,": ",t.error,". Still selected for retry."]},t.id)})]}),C?e.jsx("div",{role:"status","aria-label":"Loading jobs",className:"space-y-2",children:[...Array(3)].map((t,f)=>e.jsx(H,{className:"h-12 w-full bg-surface-highest"},f))}):(m??[]).length===0?e.jsx(Pe,{message:"No jobs configured"}):c?e.jsx("div",{className:"min-w-0 overflow-hidden",children:e.jsxs(Ve,{children:[e.jsx(qe,{children:e.jsxs(ee,{className:"border-b border-border hover:bg-transparent",children:[e.jsx(L,{className:"w-11",children:e.jsx("span",{className:"sr-only",children:"Select jobs"})}),e.jsx(L,{className:"font-label text-xs font-medium text-outline",children:"Name"}),e.jsx(L,{className:"font-label text-xs font-medium text-outline w-24",children:"Trigger"}),e.jsx(L,{className:"font-label text-xs font-medium text-outline w-48",children:"Action"}),e.jsx(L,{className:"font-label text-xs font-medium text-outline w-16",children:"Enabled"}),e.jsx(L,{className:"font-label text-xs font-medium text-outline w-36",children:"Last Run"}),e.jsx(L,{className:"font-label text-xs font-medium text-outline w-16",children:"Runs"}),e.jsx(L,{className:"font-label text-xs font-medium text-outline w-36",children:"Next Run"}),e.jsx(L,{className:"w-28"})]})}),e.jsx(Me,{children:(m??[]).map(t=>{var f,S;return e.jsxs(ee,{"data-testid":"job-row","data-job-id":t.id,"data-job-name":t.name,className:"border-b border-border/65 hover:bg-surface-high cursor-pointer",onClick:()=>k(t.id),children:[e.jsx(O,{children:e.jsx("input",{type:"checkbox",className:"size-4 accent-primary","aria-label":`Select ${t.name}`,"data-testid":"job-select",checked:b.selectedIds.includes(t.id),disabled:i.isPending,onClick:I=>I.stopPropagation(),onChange:()=>b.toggle(t.id)})}),e.jsxs(O,{children:[e.jsx("button",{type:"button",className:"font-body text-sm font-medium text-on-surface text-left hover:text-primary","data-testid":"job-open-detail",onClick:I=>{I.stopPropagation(),k(t.id)},children:t.name}),t.description&&e.jsx("div",{className:"font-body text-sm text-outline mt-0.5 truncate max-w-[200px]",children:t.description})]}),e.jsx(O,{children:e.jsx("span",{className:"font-label text-xs text-on-surface-variant inline-flex",children:t.trigger_type})}),e.jsx(O,{children:e.jsx("code",{className:"font-mono text-xs text-outline truncate block max-w-[180px]",children:((f=t.action)==null?void 0:f.type)==="agent"?`Agent: ${t.action.backend}`:((S=t.action)==null?void 0:S.type)==="task"?`Task: ${t.action.title}`:t.command})}),e.jsx(O,{children:e.jsx(g,{type:"button","data-testid":"job-toggle-enabled",variant:"outline",size:"sm","aria-label":`${t.enabled?"Disable":"Enable"} ${t.name}`,"aria-pressed":t.enabled,disabled:u.isPending||i.isPending,onClick:I=>{I.stopPropagation(),u.mutate({id:t.id,enabled:!t.enabled})},children:t.enabled?"Disable":"Enable"})}),e.jsx(O,{className:"font-label text-xs text-outline",children:t.last_run_at?new Date(t.last_run_at).toLocaleString():"—"}),e.jsx(O,{className:"font-label text-xs text-outline",children:t.run_count}),e.jsx(O,{className:"font-label text-xs text-outline",children:t.next_run_at?new Date(t.next_run_at).toLocaleString():"—"}),e.jsx(O,{children:e.jsxs("div",{className:"flex items-center gap-2",onClick:I=>I.stopPropagation(),children:[e.jsxs(g,{"data-testid":"job-trigger",size:"sm",disabled:p.isPending,onClick:()=>p.mutate(t.id),className:"font-label text-sm min-h-11 px-3 bg-transparent text-on-surface border border-border hover:bg-surface-high",children:[e.jsx(K,{size:10,className:"mr-1"})," Run"]}),e.jsx("button",{type:"button","data-testid":"job-edit","aria-label":`Edit ${t.name}`,onClick:()=>R(t),className:"inline-flex min-h-11 min-w-11 items-center justify-center rounded-md text-outline hover:text-primary hover:bg-surface-highest",children:e.jsx(X,{size:16})}),e.jsx("button",{type:"button","data-testid":"job-delete","aria-label":`Delete ${t.name}`,onClick:()=>J(t),className:"inline-flex min-h-11 min-w-11 items-center justify-center rounded-md text-outline hover:text-error hover:bg-error/10",children:e.jsx(se,{size:12})})]})})]},t.id)})})]})}):e.jsx("div",{className:"space-y-3",children:(m??[]).map(t=>{var f,S;return e.jsxs("article",{"data-testid":"job-row","data-job-id":t.id,"data-job-name":t.name,className:"border-b border-border/65 py-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("input",{type:"checkbox",className:"size-4 accent-primary shrink-0 mt-1","aria-label":`Select ${t.name}`,"data-testid":"job-select",checked:b.selectedIds.includes(t.id),disabled:i.isPending,onChange:()=>b.toggle(t.id)}),e.jsx("button",{type:"button",className:"min-w-0 text-left font-medium text-sm text-on-surface break-words hover:text-primary","data-testid":"job-open-detail",onClick:()=>k(t.id),children:t.name}),e.jsx(g,{type:"button","data-testid":"job-toggle-enabled",variant:"outline",size:"sm","aria-label":`${t.enabled?"Disable":"Enable"} ${t.name}`,"aria-pressed":t.enabled,disabled:u.isPending||i.isPending,onClick:()=>u.mutate({id:t.id,enabled:!t.enabled}),children:t.enabled?"Disable":"Enable"})]}),t.description&&e.jsx("p",{className:"text-sm text-outline break-words",children:t.description}),e.jsx("code",{className:"block whitespace-pre-wrap break-all text-xs text-on-surface-variant",children:((f=t.action)==null?void 0:f.type)==="agent"?`Agent: ${t.action.backend}`:((S=t.action)==null?void 0:S.type)==="task"?`Task: ${t.action.title}`:t.command}),e.jsxs("p",{className:"text-xs text-outline",children:[t.trigger_type," · ",t.run_count," runs",t.next_run_at?` · Next: ${new Date(t.next_run_at).toLocaleString()}`:""]}),e.jsxs("div",{className:"flex flex-wrap gap-2 border-t border-border pt-3",children:[e.jsxs(g,{"data-testid":"job-edit",variant:"outline",size:"sm",onClick:()=>R(t),children:[e.jsx(X,{}),"Edit"]}),e.jsxs(g,{"data-testid":"job-trigger",variant:"outline",size:"sm",disabled:p.isPending,onClick:()=>p.mutate(t.id),children:[e.jsx(K,{}),"Run"]}),e.jsx(g,{"data-testid":"job-delete","aria-label":`Delete ${t.name}`,variant:"ghost",size:"icon",onClick:()=>J(t),children:e.jsx(se,{})})]})]},t.id)})}),e.jsx(Xe,{jobId:D,open:!!D,onClose:$,onEdit:t=>{$(),R(t)}}),h&&e.jsx(Ze,{defaultProjectId:x,open:h,onClose:()=>_(!1)}),A&&e.jsx(et,{job:A,open:!!A,onClose:()=>R(null)}),w&&e.jsx($e,{open:!!w,title:"Delete Job",description:`Delete job "${w.name}"? This cannot be undone.`,confirmLabel:"Delete",variant:"destructive",isPending:y.isPending,onConfirm:()=>{y.mutate(w.id,{onSuccess:()=>J(null)})},onCancel:()=>J(null)})]})}function Ze({defaultProjectId:a,open:c,onClose:n}){const{data:x}=Ce(),[s,C]=o.useState(""),[N,T]=o.useState(""),[m,p]=o.useState({type:"command",command:""}),[y,u]=o.useState([]),[i,v]=o.useState("manual"),[b,E]=o.useState(""),[D,k]=o.useState("300"),[$,h]=o.useState("0"),[_,A]=o.useState("skip"),[R,w]=o.useState("failure"),[J,z]=o.useState(""),[F,l]=o.useState(a??""),t=Be(),[f,S]=o.useState(!1),I=r=>{if(r.preventDefault(),!s.trim()||!Y(m)||i==="webhook"&&!y.length)return;const he={name:s.trim(),description:N.trim(),action:m,webhooks:i==="webhook"?y:[],trigger_type:i,enabled:f,cron_expr:i==="cron"&&b.trim()||void 0,timeout_secs:Number.parseInt(D,10)||void 0,max_retries:Number.parseInt($,10),overlap:_,notify_on:R,project_id:F||void 0,working_dir:J.trim()||void 0};t.mutate(he,{onSuccess:n})};return e.jsx(ne,{open:c,onOpenChange:r=>!r&&n(),children:e.jsxs(re,{className:"bg-surface border-border max-w-lg max-h-[85dvh] overflow-y-auto",children:[e.jsx(le,{children:e.jsx(ie,{className:"font-headline text-sm font-medium text-on-surface",children:"New job"})}),e.jsxs("form",{onSubmit:I,className:"space-y-3 mt-2",children:[e.jsxs("label",{className:"flex min-h-11 items-center gap-3 text-sm",children:[e.jsx("input",{type:"checkbox","data-testid":"job-create-enabled",checked:f,onChange:r=>S(r.target.checked),className:"size-4 accent-primary"}),"Enable this job immediately"]}),e.jsx("p",{className:"text-xs text-outline",children:"New jobs stay disabled until you enable them. You can configure their webhook first."}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Name *"}),e.jsx(j,{"aria-label":"Name","data-testid":"job-name-input",value:s,onChange:r=>C(r.target.value),placeholder:"Job name...",className:"bg-background border-control-border text-on-surface font-body text-sm",autoFocus:!0})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Description"}),e.jsx(j,{"aria-label":"Description",value:N,onChange:r=>T(r.target.value),placeholder:"Optional description...",className:"bg-background border-control-border text-on-surface font-body text-sm"})]}),e.jsx(me,{value:m,onChange:p}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Trigger Type"}),e.jsxs(V,{value:i,onValueChange:r=>v(r),children:[e.jsx(q,{"aria-label":"Trigger type","data-testid":"job-trigger-type",className:"bg-background border-control-border text-on-surface font-body text-sm min-h-11",children:e.jsx(M,{})}),e.jsx(W,{className:"bg-surface border-border",children:xe.map(r=>e.jsx(B,{value:r,"data-testid":`job-trigger-${r}`,className:"font-body text-sm",children:r},r))})]})]}),i==="webhook"&&e.jsx("div",{className:"sm:col-span-2",children:e.jsx(de,{value:y,onChange:u,projectId:F||void 0})}),i==="cron"&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Cron Expression"}),e.jsx(j,{"aria-label":"Cron expression",value:b,onChange:r=>E(r.target.value),placeholder:"*/5 * * * *",className:"bg-background border-control-border text-on-surface font-mono text-xs"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Timeout (s)"}),e.jsx(j,{"aria-label":"Timeout in seconds",type:"number",min:1,required:!0,value:D,onChange:r=>k(r.target.value),className:"bg-background border-control-border text-on-surface font-body text-sm"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Max Retries"}),e.jsx(j,{"aria-label":"Maximum retries",type:"number",min:0,required:!0,value:$,onChange:r=>h(r.target.value),className:"bg-background border-control-border text-on-surface font-body text-sm"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Overlap"}),e.jsxs(V,{value:_,onValueChange:r=>A(r),children:[e.jsx(q,{"aria-label":"Overlap",className:"bg-background border-control-border text-on-surface font-body text-sm min-h-11",children:e.jsx(M,{})}),e.jsx(W,{className:"bg-surface border-border",children:ue.map(r=>e.jsx(B,{value:r,className:"font-body text-sm",children:r},r))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Notify On"}),e.jsxs(V,{value:R,onValueChange:r=>w(r),children:[e.jsx(q,{"aria-label":"Notify on",className:"bg-background border-control-border text-on-surface font-body text-sm min-h-11",children:e.jsx(M,{})}),e.jsx(W,{className:"bg-surface border-border",children:be.map(r=>e.jsx(B,{value:r,className:"font-body text-sm",children:r},r))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Working Dir"}),e.jsx(j,{"aria-label":"Working directory",value:J,onChange:r=>z(r.target.value),placeholder:"/path/to/dir",className:"bg-background border-control-border text-on-surface font-body text-sm"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Project"}),e.jsxs(V,{value:F||"__none__",onValueChange:r=>{l(r==="__none__"?"":r),u([])},children:[e.jsx(q,{"aria-label":"Project","data-testid":"job-project-select",className:"bg-background border-control-border text-on-surface font-body text-sm min-h-11",children:e.jsx(M,{})}),e.jsxs(W,{className:"bg-surface border-border",children:[e.jsx(B,{value:"__none__",className:"font-body text-sm",children:"None"}),x==null?void 0:x.map(r=>e.jsx(B,{value:r.id,className:"font-body text-sm",children:r.name},r.id))]})]})]}),e.jsxs(oe,{children:[e.jsx(g,{type:"button",variant:"ghost",size:"sm",onClick:n,className:"font-label text-xs text-outline",children:"Cancel"}),e.jsx(g,{"data-testid":"job-submit",type:"submit",size:"sm",disabled:t.isPending||!s.trim()||!Y(m)||i==="webhook"&&!y.length,className:"font-label text-xs bg-primary text-primary-foreground hover:bg-primary/90",children:t.isPending?"Creating...":i==="webhook"?"Create job":"Create"})]}),t.error&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:t.error.message})]})]})})}function et({job:a,open:c,onClose:n}){const[x,s]=o.useState(a.name),[C,N]=o.useState(a.description??""),[T,m]=o.useState(a.action??{type:"command",command:a.command}),[p,y]=o.useState(a.webhooks??[]),[u,i]=o.useState(a.trigger_type),[v,b]=o.useState(a.cron_expr??""),[E,D]=o.useState(String(a.timeout_secs)),[k,$]=o.useState(String(a.max_retries)),[h,_]=o.useState(a.overlap),[A,R]=o.useState(a.notify_on),[w,J]=o.useState(a.enabled),z=Q(),F=l=>{if(l.preventDefault(),!x.trim()||!Y(T)||u==="webhook"&&!p.length)return;const t={id:a.id,name:x.trim(),description:C.trim(),action:T,webhooks:u==="webhook"?p:[],trigger_type:u,cron_expr:u==="cron"&&v.trim()||void 0,timeout_secs:Number.parseInt(E,10)||void 0,max_retries:Number.parseInt(k,10),overlap:h,notify_on:A,enabled:w};z.mutate(t,{onSuccess:n})};return e.jsx(ne,{open:c,onOpenChange:l=>!l&&n(),children:e.jsxs(re,{className:"bg-surface border-border max-w-lg max-h-[85dvh] overflow-y-auto",children:[e.jsx(le,{children:e.jsx(ie,{className:"font-headline text-sm font-medium text-on-surface",children:"Edit job"})}),e.jsxs("form",{id:"edit-job-form",onSubmit:F,className:"space-y-3 mt-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Name *"}),e.jsx(j,{"aria-label":"Name",value:x,onChange:l=>s(l.target.value),className:"bg-background border-control-border text-on-surface font-body text-sm"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Description"}),e.jsx(j,{"aria-label":"Description",value:C,onChange:l=>N(l.target.value),className:"bg-background border-control-border text-on-surface font-body text-sm"})]}),e.jsx(me,{value:T,onChange:m}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Trigger Type"}),e.jsxs(V,{value:u,onValueChange:l=>i(l),children:[e.jsx(q,{"aria-label":"Trigger type","data-testid":"job-trigger-type",className:"bg-background border-control-border text-on-surface font-body text-sm min-h-11",children:e.jsx(M,{})}),e.jsx(W,{className:"bg-surface border-border",children:xe.map(l=>e.jsx(B,{value:l,"data-testid":`job-trigger-${l}`,className:"font-body text-sm",children:l},l))})]})]}),u==="webhook"&&e.jsx("div",{className:"sm:col-span-2",children:e.jsx(de,{value:p,onChange:y,projectId:a.project_id??void 0})}),u==="cron"&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Cron Expression"}),e.jsx(j,{"aria-label":"Cron expression",value:v,onChange:l=>b(l.target.value),placeholder:"*/5 * * * *",className:"bg-background border-control-border text-on-surface font-mono text-xs"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Timeout (s)"}),e.jsx(j,{"aria-label":"Timeout in seconds",type:"number",min:1,required:!0,value:E,onChange:l=>D(l.target.value),className:"bg-background border-control-border text-on-surface font-body text-sm"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Max Retries"}),e.jsx(j,{"aria-label":"Maximum retries",type:"number",min:0,required:!0,value:k,onChange:l=>$(l.target.value),className:"bg-background border-control-border text-on-surface font-body text-sm"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Overlap"}),e.jsxs(V,{value:h,onValueChange:l=>_(l),children:[e.jsx(q,{"aria-label":"Overlap",className:"bg-background border-control-border text-on-surface font-body text-sm min-h-11",children:e.jsx(M,{})}),e.jsx(W,{className:"bg-surface border-border",children:ue.map(l=>e.jsx(B,{value:l,className:"font-body text-sm",children:l},l))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Notify On"}),e.jsxs(V,{value:A,onValueChange:l=>R(l),children:[e.jsx(q,{"aria-label":"Notify on",className:"bg-background border-control-border text-on-surface font-body text-sm min-h-11",children:e.jsx(M,{})}),e.jsx(W,{className:"bg-surface border-border",children:be.map(l=>e.jsx(B,{value:l,className:"font-body text-sm",children:l},l))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Enabled"}),e.jsx("button",{type:"button",onClick:()=>J(!w),className:`w-full min-h-11 rounded-md flex items-center justify-center border font-label text-xs font-medium transition-colors ${w?"bg-surface-highest text-on-surface border-border":"bg-background text-outline border-border"}`,children:w?"● Enabled":"○ Disabled"})]})]})]}),e.jsxs(oe,{children:[e.jsx(g,{type:"button",variant:"ghost",size:"sm",onClick:n,className:"font-label text-xs text-outline",children:"Cancel"}),e.jsx(g,{"data-testid":"job-edit-submit",form:"edit-job-form",type:"submit",size:"sm",disabled:z.isPending||!x.trim()||!Y(T)||u==="webhook"&&!p.length,className:"font-label text-xs bg-primary text-primary-foreground hover:bg-primary/90",children:z.isPending?"Saving...":"Save"})]}),z.error&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:z.error.message})]})})}export{gt as default};
|
|
11
|
+
*/const Ye=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],Ge=ae("power",Ye);function Y(a){return a.type==="command"?!!a.command.trim():a.type==="agent"?!!(a.prompt.trim()&&a.backend.trim()):!!a.title.trim()}function me({value:a,onChange:c}){const n=o.useId(),{data:x}=ge();return e.jsxs("section",{className:"space-y-3 border-y border-border py-4","data-testid":"job-action-fields",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{htmlFor:`${n}-type`,children:"What should this job do?"}),e.jsxs("select",{id:`${n}-type`,"data-testid":"job-action-type",className:"w-full min-h-11 rounded-md border border-control-border bg-background px-3 text-sm",value:a.type,onChange:s=>{s.target.value==="command"&&c({type:"command",command:""}),s.target.value==="agent"&&c({type:"agent",backend:"codex-cli",prompt:"",auto_approve:!1}),s.target.value==="task"&&c({type:"task",title:"",body:"",start_automatically:!1})},children:[e.jsx("option",{value:"command",children:"Run command"}),e.jsx("option",{value:"agent",children:"Run agent"}),e.jsx("option",{value:"task",children:"Create task"})]})]}),a.type==="command"&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{htmlFor:`${n}-command`,children:"Command"}),e.jsx(G,{id:`${n}-command`,"aria-label":"Command","data-testid":"job-command-input",value:a.command,onChange:s=>c({...a,command:s.target.value}),rows:3,placeholder:"bun run build",required:!0})]}),a.type==="agent"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{htmlFor:`${n}-backend`,children:"Agent backend"}),e.jsx(f,{id:`${n}-backend`,"data-testid":"job-agent-backend",value:a.backend,list:`${n}-backends`,onChange:s=>c({...a,backend:s.target.value}),required:!0}),e.jsx("datalist",{id:`${n}-backends`,children:x==null?void 0:x.backends.map(s=>e.jsx("option",{value:s.name,children:s.available?"Available":"Unavailable"},s.name))})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{htmlFor:`${n}-model`,children:"Model (optional)"}),e.jsx(f,{id:`${n}-model`,"data-testid":"job-agent-model",value:a.model??"",onChange:s=>c({...a,model:s.target.value||void 0})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{htmlFor:`${n}-prompt`,children:"Instructions"}),e.jsx(G,{id:`${n}-prompt`,"data-testid":"job-agent-prompt",value:a.prompt,onChange:s=>c({...a,prompt:s.target.value}),required:!0,rows:4})]}),e.jsxs("label",{className:"flex min-h-11 items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:a.auto_approve,onChange:s=>c({...a,auto_approve:s.target.checked})}),"Allow agent tools automatically"]}),e.jsx("p",{className:"text-xs text-outline",children:"Starts a tracked agent session. When automatic tool approval is off, permission requests are denied."})]}),a.type==="task"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{htmlFor:`${n}-title`,children:"Task title"}),e.jsx(f,{id:`${n}-title`,"data-testid":"job-task-title",value:a.title,onChange:s=>c({...a,title:s.target.value}),required:!0,maxLength:200})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{htmlFor:`${n}-body`,children:"Task instructions"}),e.jsx(G,{id:`${n}-body`,"data-testid":"job-task-body",value:a.body,onChange:s=>c({...a,body:s.target.value}),rows:4})]}),e.jsxs("label",{className:"flex min-h-11 items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox","data-testid":"job-task-autostart",checked:a.start_automatically,onChange:s=>c({...a,start_automatically:s.target.checked})}),"Start the task flow automatically"]}),a.start_automatically&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{htmlFor:`${n}-flow`,children:"Flow (blank uses the configured default)"}),e.jsx(f,{id:`${n}-flow`,"data-testid":"job-task-flow",value:a.flow_name??"",onChange:s=>c({...a,flow_name:s.target.value||void 0})})]}),e.jsx("p",{className:"text-xs text-outline",children:"Creates a task in this job's project. Automatic start is off by default; the task waits for a manual flow start."})]})]})}function Ke({jobId:a,open:c,onClose:n,onEdit:x}){var D,k,$;const{data:s,isLoading:C,error:N,refetch:T}=ze(a),{data:m,isLoading:p,error:y,refetch:u}=Ie(a),i=ce(),v=X(),[b,E]=o.useState(null);return e.jsx(pe,{open:c,onOpenChange:h=>!h&&n(),children:e.jsxs(je,{"data-testid":"job-detail-sheet",children:[e.jsxs(fe,{children:[e.jsx(Ne,{children:(s==null?void 0:s.name)??"Job details"}),(s==null?void 0:s.description)&&e.jsx("p",{className:"font-body text-xs text-outline mt-1",children:s.description})]}),e.jsx(ye,{children:N?e.jsx(U,{message:N.message,onRetry:()=>T()}):C?e.jsx("div",{className:"space-y-3",children:[...Array(6)].map((h,_)=>e.jsx(H,{className:"h-8 w-full bg-surface-highest"},_))}):s?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(P,{label:"Action",children:e.jsx("pre",{className:"font-mono text-xs bg-background p-2 rounded-lg border border-surface-highest overflow-x-auto whitespace-pre-wrap break-all",children:((D=s.action)==null?void 0:D.type)==="agent"?`Run agent (${s.action.backend}): ${s.action.prompt}`:((k=s.action)==null?void 0:k.type)==="task"?`Create task: ${s.action.title}`:s.command})}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsx(P,{label:"Trigger Type",children:e.jsx("span",{className:"font-label text-xs px-2 py-0.5 bg-surface-highest text-on-surface-variant border border-surface-highest/50 inline-flex",children:s.trigger_type})}),e.jsx(P,{label:"Enabled",children:e.jsx("span",{className:`font-label text-xs font-bold ${s.enabled?"text-secondary":"text-outline"}`,children:s.enabled?"● ON":"○ OFF"})})]}),s.cron_expr&&e.jsx(P,{label:"Cron Expression",children:e.jsx("code",{className:"font-mono text-xs",children:s.cron_expr})}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs(P,{label:"Timeout",children:[s.timeout_secs,"s"]}),e.jsx(P,{label:"Max Retries",children:s.max_retries}),e.jsx(P,{label:"Overlap",children:s.overlap})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsx(P,{label:"Notify On",children:s.notify_on}),e.jsx(P,{label:"Run Count",children:s.run_count})]}),s.next_run_at&&e.jsx(P,{label:"Next Run",children:new Date(s.next_run_at).toLocaleString()})]}),!s.command.startsWith("__")&&e.jsx(Ee,{job:s},s.id),e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-xs font-medium text-outline mb-3",children:"Recent runs"}),y?e.jsx(U,{message:y.message,onRetry:()=>u()}):p?e.jsx("div",{className:"space-y-2",children:[...Array(3)].map((h,_)=>e.jsx(H,{className:"h-8 w-full bg-surface-highest"},_))}):m!=null&&m.length?e.jsx("div",{className:"space-y-1",children:m.map(h=>e.jsx(Qe,{run:h,jobId:a,expanded:b===h.id,onToggle:()=>E(b===h.id?null:h.id)},h.id))}):e.jsx("div",{className:"font-label text-xs text-outline py-4 text-center",children:"No runs yet"})]})]}):e.jsx("p",{className:"text-sm text-outline",children:"Job not found"})}),e.jsxs(ve,{className:"flex-wrap",children:[(v.error||i.error)&&e.jsx("p",{role:"alert",className:"w-full text-sm text-error",children:($=v.error??i.error)==null?void 0:$.message}),s&&x&&e.jsxs(g,{"data-testid":"job-detail-edit",size:"sm",variant:"outline",onClick:()=>x(s),children:[e.jsx(K,{size:16}),"Edit job"]}),s&&e.jsxs(g,{size:"sm",variant:"ghost",disabled:v.isPending,onClick:()=>v.mutate({id:s.id,enabled:!s.enabled}),className:"font-label text-xs font-medium",children:[e.jsx(Ge,{size:12,className:"mr-1.5"}),s.enabled?"Disable":"Enable"]}),s&&e.jsxs(g,{size:"sm",disabled:i.isPending,onClick:()=>i.mutate(s.id),className:"font-label text-xs font-medium bg-transparent text-on-surface border border-control-border hover:bg-surface",children:[e.jsx(Q,{size:12,className:"mr-1.5"}),i.isPending?"Triggering...":"Trigger run"]})]})]})})}function Qe({run:a,jobId:c,expanded:n,onToggle:x}){return e.jsxs("div",{className:"min-w-0 border-y border-border overflow-hidden bg-background",children:[e.jsxs("button",{type:"button",onClick:x,"aria-expanded":n,className:"w-full flex items-center gap-3 px-3 py-2 hover:bg-surface transition-colors text-left",children:[n?e.jsx(ke,{size:12,className:"text-outline shrink-0"}):e.jsx(_e,{size:12,className:"text-outline shrink-0"}),e.jsx(Re,{status:a.status,type:"job"}),e.jsxs("span",{className:"font-label text-xs text-outline flex-1",children:[a.started_at?new Date(a.started_at).toLocaleString():"—",a.ended_at&&e.jsxs("span",{className:"ml-2",children:["\\u2192 ",new Date(a.ended_at).toLocaleString()]})]}),a.exit_code!==null&&e.jsxs("span",{className:`font-mono text-xs ${a.exit_code===0?"text-secondary":"text-error"}`,children:["exit ",a.exit_code]})]}),(a.task_id||a.session_id)&&e.jsxs("div",{className:"flex gap-3 px-3 py-2 text-xs",children:[a.task_id&&e.jsx(Z,{className:"underline","data-testid":"job-run-task-link",to:`/tasks/${a.task_id}?project=all`,children:"Created task"}),a.session_id&&e.jsx(Z,{className:"underline","data-testid":"job-run-session-link",to:`/audit/${a.session_id}?project=all`,children:"Agent session"})]}),a.error_msg&&e.jsx("div",{className:"px-3 pb-2",children:e.jsx("span",{className:"font-body text-xs text-error",children:a.error_msg})}),n&&e.jsx(Xe,{jobId:c,runId:a.id})]})}function Xe({jobId:a,runId:c}){const{data:n,isLoading:x,error:s,refetch:C}=Le(a,c);return s?e.jsx(U,{message:s.message,onRetry:()=>C()}):x?e.jsx("div",{className:"px-3 pb-3",children:e.jsx(H,{className:"h-24 w-full bg-surface-highest"})}):n!=null&&n.length?e.jsx("div",{className:"mx-3 mb-3 rounded-lg overflow-hidden border border-surface-highest",children:e.jsx(Je,{className:"h-[240px]",children:e.jsx("pre",{className:"font-mono text-xs leading-relaxed bg-background p-3",children:n.map(N=>e.jsx("div",{className:N.stream==="stderr"?"text-error":"text-on-surface",children:N.line},N.id))})})}):e.jsx("div",{className:"px-3 pb-3 font-label text-xs text-outline",children:"No log output"})}const xe=["one-shot","cron","watch","webhook","manual","bridge-msg"],ue=["skip","queue","kill"],be=["never","failure","always"];function gt({projectId:a}){var F,l;const c=we("sm"),n=He(a),x=n==="all"||n==="unassigned"?void 0:n,{data:s,isLoading:C,error:N,refetch:T}=Oe({project_id:x,limit:100}),m=n==="unassigned"?s==null?void 0:s.filter(t=>t.project_id===null):s,p=ce(),y=Ae(),u=X(),i=Fe(),v=((F=i.data)==null?void 0:F.scope)===n?i.data:void 0,b=Te((m??[]).map(t=>t.id),n);async function E(t){const j=await i.mutateAsync({ids:b.selectedIds,enabled:t,scope:n});b.select(j.failed.map(S=>S.id))}const{selectedId:D,openDetail:k,closeDetail:$}=We("/jobs","jobId"),[h,_]=o.useState(!1),[A,R]=o.useState(null),[w,J]=o.useState(null);if(N)return e.jsxs("div",{children:[e.jsx(te,{title:"Jobs"}),e.jsx(U,{message:N.message,onRetry:()=>T()})]});const z=(m??[]).filter(t=>t.enabled).length;return e.jsxs("div",{children:[e.jsx(te,{title:"Jobs",meta:`${z}/${(m??[]).length} enabled`,action:e.jsxs(g,{"data-testid":"new-job-button",size:"sm",onClick:()=>_(!0),className:"font-label text-xs font-medium bg-primary text-primary-foreground hover:bg-primary/90",children:[e.jsx(Se,{size:12,className:"mr-1"})," New job"]})}),(p.error||y.error||u.error)&&e.jsx("p",{role:"alert",className:"mb-4 text-sm text-error",children:(l=p.error??y.error??u.error)==null?void 0:l.message}),!!(m!=null&&m.length)&&e.jsxs(De,{resourceLabel:"jobs",count:b.selectedIds.length,allSelected:b.allSelected,someSelected:b.someSelected,onSelectAll:b.selectAll,onClear:b.clear,disabled:i.isPending,children:[e.jsx(g,{type:"button",variant:"outline",size:"sm","data-testid":"jobs-bulk-enable",disabled:i.isPending||u.isPending,onClick:()=>void E(!0),children:"Enable selected"}),e.jsx(g,{type:"button",variant:"outline",size:"sm","data-testid":"jobs-bulk-disable",disabled:i.isPending||u.isPending,onClick:()=>void E(!1),children:"Disable selected"})]}),i.isPending&&e.jsx("p",{role:"status",className:"mb-3 text-sm text-outline",children:"Updating selected jobs…"}),!i.isPending&&v&&e.jsxs("div",{className:"mb-3 space-y-1 text-sm","data-testid":"jobs-bulk-result",role:"status",children:[e.jsxs("p",{children:[v.succeeded.length," jobs ",v.enabled?"enabled":"disabled","."]}),v.failed.map(t=>{var j;return e.jsxs("p",{className:"text-error",children:[((j=m==null?void 0:m.find(S=>S.id===t.id))==null?void 0:j.name)??t.id,": ",t.error,". Still selected for retry."]},t.id)})]}),C?e.jsx("div",{role:"status","aria-label":"Loading jobs",className:"space-y-2",children:[...Array(3)].map((t,j)=>e.jsx(H,{className:"h-12 w-full bg-surface-highest"},j))}):(m??[]).length===0?e.jsx(Pe,{message:"No jobs configured"}):c?e.jsx("div",{className:"min-w-0 overflow-hidden",children:e.jsxs(Ve,{children:[e.jsx(qe,{children:e.jsxs(ee,{className:"border-b border-border hover:bg-transparent",children:[e.jsx(L,{className:"w-11",children:e.jsx("span",{className:"sr-only",children:"Select jobs"})}),e.jsx(L,{className:"font-label text-xs font-medium text-outline",children:"Name"}),e.jsx(L,{className:"font-label text-xs font-medium text-outline w-24",children:"Trigger"}),e.jsx(L,{className:"font-label text-xs font-medium text-outline w-48",children:"Action"}),e.jsx(L,{className:"font-label text-xs font-medium text-outline w-16",children:"Enabled"}),e.jsx(L,{className:"font-label text-xs font-medium text-outline w-36",children:"Last Run"}),e.jsx(L,{className:"font-label text-xs font-medium text-outline w-16",children:"Runs"}),e.jsx(L,{className:"font-label text-xs font-medium text-outline w-36",children:"Next Run"}),e.jsx(L,{className:"w-28"})]})}),e.jsx(Me,{children:(m??[]).map(t=>{var j,S;return e.jsxs(ee,{"data-testid":"job-row","data-job-id":t.id,"data-job-name":t.name,className:"border-b border-border/65 hover:bg-surface-high cursor-pointer",onClick:()=>k(t.id),children:[e.jsx(O,{children:e.jsx("input",{type:"checkbox",className:"size-4 accent-primary","aria-label":`Select ${t.name}`,"data-testid":"job-select",checked:b.selectedIds.includes(t.id),disabled:i.isPending,onClick:I=>I.stopPropagation(),onChange:()=>b.toggle(t.id)})}),e.jsxs(O,{children:[e.jsx("button",{type:"button",className:"font-body text-sm font-medium text-on-surface text-left hover:text-primary","data-testid":"job-open-detail",onClick:I=>{I.stopPropagation(),k(t.id)},children:t.name}),t.description&&e.jsx("div",{className:"font-body text-sm text-outline mt-0.5 truncate max-w-[200px]",children:t.description})]}),e.jsx(O,{children:e.jsx("span",{className:"font-label text-xs text-on-surface-variant inline-flex",children:t.trigger_type})}),e.jsx(O,{children:e.jsx("code",{className:"font-mono text-xs text-outline truncate block max-w-[180px]",children:((j=t.action)==null?void 0:j.type)==="agent"?`Agent: ${t.action.backend}`:((S=t.action)==null?void 0:S.type)==="task"?`Task: ${t.action.title}`:t.command})}),e.jsx(O,{children:e.jsx(g,{type:"button","data-testid":"job-toggle-enabled",variant:"outline",size:"sm","aria-label":`${t.enabled?"Disable":"Enable"} ${t.name}`,"aria-pressed":t.enabled,disabled:u.isPending||i.isPending,onClick:I=>{I.stopPropagation(),u.mutate({id:t.id,enabled:!t.enabled})},children:t.enabled?"Disable":"Enable"})}),e.jsx(O,{className:"font-label text-xs text-outline",children:t.last_run_at?new Date(t.last_run_at).toLocaleString():"—"}),e.jsx(O,{className:"font-label text-xs text-outline",children:t.run_count}),e.jsx(O,{className:"font-label text-xs text-outline",children:t.next_run_at?new Date(t.next_run_at).toLocaleString():"—"}),e.jsx(O,{children:e.jsxs("div",{className:"flex items-center gap-2",onClick:I=>I.stopPropagation(),children:[e.jsxs(g,{"data-testid":"job-trigger",size:"sm",disabled:p.isPending,onClick:()=>p.mutate(t.id),className:"font-label text-sm min-h-11 px-3 bg-transparent text-on-surface border border-border hover:bg-surface-high",children:[e.jsx(Q,{size:10,className:"mr-1"})," Run"]}),e.jsx("button",{type:"button","data-testid":"job-edit","aria-label":`Edit ${t.name}`,onClick:()=>R(t),className:"inline-flex min-h-11 min-w-11 items-center justify-center rounded-md text-outline hover:text-primary hover:bg-surface-highest",children:e.jsx(K,{size:16})}),e.jsx("button",{type:"button","data-testid":"job-delete","aria-label":`Delete ${t.name}`,onClick:()=>J(t),className:"inline-flex min-h-11 min-w-11 items-center justify-center rounded-md text-outline hover:text-error hover:bg-error/10",children:e.jsx(se,{size:12})})]})})]},t.id)})})]})}):e.jsx("div",{className:"space-y-3",children:(m??[]).map(t=>{var j,S;return e.jsxs("article",{"data-testid":"job-row","data-job-id":t.id,"data-job-name":t.name,className:"border-b border-border/65 py-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("input",{type:"checkbox",className:"size-4 accent-primary shrink-0 mt-1","aria-label":`Select ${t.name}`,"data-testid":"job-select",checked:b.selectedIds.includes(t.id),disabled:i.isPending,onChange:()=>b.toggle(t.id)}),e.jsx("button",{type:"button",className:"min-w-0 text-left font-medium text-sm text-on-surface break-words hover:text-primary","data-testid":"job-open-detail",onClick:()=>k(t.id),children:t.name}),e.jsx(g,{type:"button","data-testid":"job-toggle-enabled",variant:"outline",size:"sm","aria-label":`${t.enabled?"Disable":"Enable"} ${t.name}`,"aria-pressed":t.enabled,disabled:u.isPending||i.isPending,onClick:()=>u.mutate({id:t.id,enabled:!t.enabled}),children:t.enabled?"Disable":"Enable"})]}),t.description&&e.jsx("p",{className:"text-sm text-outline break-words",children:t.description}),e.jsx("code",{className:"block whitespace-pre-wrap break-all text-xs text-on-surface-variant",children:((j=t.action)==null?void 0:j.type)==="agent"?`Agent: ${t.action.backend}`:((S=t.action)==null?void 0:S.type)==="task"?`Task: ${t.action.title}`:t.command}),e.jsxs("p",{className:"text-xs text-outline",children:[t.trigger_type," · ",t.run_count," runs",t.next_run_at?` · Next: ${new Date(t.next_run_at).toLocaleString()}`:""]}),e.jsxs("div",{className:"flex flex-wrap gap-2 border-t border-border pt-3",children:[e.jsxs(g,{"data-testid":"job-edit",variant:"outline",size:"sm",onClick:()=>R(t),children:[e.jsx(K,{}),"Edit"]}),e.jsxs(g,{"data-testid":"job-trigger",variant:"outline",size:"sm",disabled:p.isPending,onClick:()=>p.mutate(t.id),children:[e.jsx(Q,{}),"Run"]}),e.jsx(g,{"data-testid":"job-delete","aria-label":`Delete ${t.name}`,variant:"ghost",size:"icon",onClick:()=>J(t),children:e.jsx(se,{})})]})]},t.id)})}),e.jsx(Ke,{jobId:D,open:!!D,onClose:$,onEdit:t=>{$(),R(t)}}),h&&e.jsx(Ze,{defaultProjectId:x,open:h,onClose:()=>_(!1)}),A&&e.jsx(et,{job:A,open:!!A,onClose:()=>R(null)}),w&&e.jsx($e,{open:!!w,title:"Delete Job",description:`Delete job "${w.name}"? This cannot be undone.`,confirmLabel:"Delete",variant:"destructive",isPending:y.isPending,onConfirm:()=>{y.mutate(w.id,{onSuccess:()=>J(null)})},onCancel:()=>J(null)})]})}function Ze({defaultProjectId:a,open:c,onClose:n}){const{data:x}=Ce(),[s,C]=o.useState(""),[N,T]=o.useState(""),[m,p]=o.useState({type:"command",command:""}),[y,u]=o.useState([]),[i,v]=o.useState("manual"),[b,E]=o.useState(""),[D,k]=o.useState("300"),[$,h]=o.useState("0"),[_,A]=o.useState("skip"),[R,w]=o.useState("failure"),[J,z]=o.useState(""),[F,l]=o.useState(a??""),t=Be(),[j,S]=o.useState(!1),I=r=>{if(r.preventDefault(),!s.trim()||!Y(m)||i==="webhook"&&!y.length)return;const he={name:s.trim(),description:N.trim(),action:m,webhooks:i==="webhook"?y:[],trigger_type:i,enabled:j,cron_expr:i==="cron"&&b.trim()||void 0,timeout_secs:Number.parseInt(D,10)||void 0,max_retries:Number.parseInt($,10),overlap:_,notify_on:R,project_id:F||void 0,working_dir:J.trim()||void 0};t.mutate(he,{onSuccess:n})};return e.jsx(ne,{open:c,onOpenChange:r=>!r&&n(),children:e.jsxs(re,{className:"bg-surface border-border max-w-lg max-h-[85dvh] overflow-y-auto",children:[e.jsx(le,{children:e.jsx(ie,{className:"font-headline text-sm font-medium text-on-surface",children:"New job"})}),e.jsxs("form",{onSubmit:I,className:"space-y-3 mt-2",children:[e.jsxs("label",{className:"flex min-h-11 items-center gap-3 text-sm",children:[e.jsx("input",{type:"checkbox","data-testid":"job-create-enabled",checked:j,onChange:r=>S(r.target.checked),className:"size-4 accent-primary"}),"Enable this job immediately"]}),e.jsx("p",{className:"text-xs text-outline",children:"New jobs stay disabled until you enable them. You can configure their webhook first."}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Name *"}),e.jsx(f,{"aria-label":"Name","data-testid":"job-name-input",value:s,onChange:r=>C(r.target.value),placeholder:"Job name...",className:"bg-background border-control-border text-on-surface font-body text-sm",autoFocus:!0})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Description"}),e.jsx(f,{"aria-label":"Description",value:N,onChange:r=>T(r.target.value),placeholder:"Optional description...",className:"bg-background border-control-border text-on-surface font-body text-sm"})]}),e.jsx(me,{value:m,onChange:p}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Trigger Type"}),e.jsxs(V,{value:i,onValueChange:r=>v(r),children:[e.jsx(q,{"aria-label":"Trigger type","data-testid":"job-trigger-type",className:"bg-background border-control-border text-on-surface font-body text-sm min-h-11",children:e.jsx(M,{})}),e.jsx(W,{className:"bg-surface border-border",children:xe.map(r=>e.jsx(B,{value:r,"data-testid":`job-trigger-${r}`,className:"font-body text-sm",children:r},r))})]})]}),i==="webhook"&&e.jsx("div",{className:"sm:col-span-2",children:e.jsx(de,{value:y,onChange:u,projectId:F||void 0})}),i==="cron"&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Cron Expression"}),e.jsx(f,{"aria-label":"Cron expression",value:b,onChange:r=>E(r.target.value),placeholder:"*/5 * * * *",className:"bg-background border-control-border text-on-surface font-mono text-xs"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Timeout (s)"}),e.jsx(f,{"aria-label":"Timeout in seconds",type:"number",min:1,required:!0,value:D,onChange:r=>k(r.target.value),className:"bg-background border-control-border text-on-surface font-body text-sm"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Max Retries"}),e.jsx(f,{"aria-label":"Maximum retries",type:"number",min:0,required:!0,value:$,onChange:r=>h(r.target.value),className:"bg-background border-control-border text-on-surface font-body text-sm"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Overlap"}),e.jsxs(V,{value:_,onValueChange:r=>A(r),children:[e.jsx(q,{"aria-label":"Overlap",className:"bg-background border-control-border text-on-surface font-body text-sm min-h-11",children:e.jsx(M,{})}),e.jsx(W,{className:"bg-surface border-border",children:ue.map(r=>e.jsx(B,{value:r,className:"font-body text-sm",children:r},r))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Notify On"}),e.jsxs(V,{value:R,onValueChange:r=>w(r),children:[e.jsx(q,{"aria-label":"Notify on",className:"bg-background border-control-border text-on-surface font-body text-sm min-h-11",children:e.jsx(M,{})}),e.jsx(W,{className:"bg-surface border-border",children:be.map(r=>e.jsx(B,{value:r,className:"font-body text-sm",children:r},r))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Working Dir"}),e.jsx(f,{"aria-label":"Working directory",value:J,onChange:r=>z(r.target.value),placeholder:"/path/to/dir",className:"bg-background border-control-border text-on-surface font-body text-sm"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Project"}),e.jsxs(V,{value:F||"__none__",onValueChange:r=>{l(r==="__none__"?"":r),u([])},children:[e.jsx(q,{"aria-label":"Project","data-testid":"job-project-select",className:"bg-background border-control-border text-on-surface font-body text-sm min-h-11",children:e.jsx(M,{})}),e.jsxs(W,{className:"bg-surface border-border",children:[e.jsx(B,{value:"__none__",className:"font-body text-sm",children:"None"}),x==null?void 0:x.map(r=>e.jsx(B,{value:r.id,className:"font-body text-sm",children:r.name},r.id))]})]})]}),e.jsxs(oe,{children:[e.jsx(g,{type:"button",variant:"ghost",size:"sm",onClick:n,className:"font-label text-xs text-outline",children:"Cancel"}),e.jsx(g,{"data-testid":"job-submit",type:"submit",size:"sm",disabled:t.isPending||!s.trim()||!Y(m)||i==="webhook"&&!y.length,className:"font-label text-xs bg-primary text-primary-foreground hover:bg-primary/90",children:t.isPending?"Creating...":i==="webhook"?"Create job":"Create"})]}),t.error&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:t.error.message})]})]})})}function et({job:a,open:c,onClose:n}){const[x,s]=o.useState(a.name),[C,N]=o.useState(a.description??""),[T,m]=o.useState(a.action??{type:"command",command:a.command}),[p,y]=o.useState(a.webhooks??[]),[u,i]=o.useState(a.trigger_type),[v,b]=o.useState(a.cron_expr??""),[E,D]=o.useState(String(a.timeout_secs)),[k,$]=o.useState(String(a.max_retries)),[h,_]=o.useState(a.overlap),[A,R]=o.useState(a.notify_on),[w,J]=o.useState(a.enabled),z=X(),F=l=>{if(l.preventDefault(),!x.trim()||!Y(T)||u==="webhook"&&!p.length)return;const t={id:a.id,name:x.trim(),description:C.trim(),action:T,webhooks:u==="webhook"?p:[],trigger_type:u,cron_expr:u==="cron"&&v.trim()||void 0,timeout_secs:Number.parseInt(E,10)||void 0,max_retries:Number.parseInt(k,10),overlap:h,notify_on:A,enabled:w};z.mutate(t,{onSuccess:n})};return e.jsx(ne,{open:c,onOpenChange:l=>!l&&n(),children:e.jsxs(re,{className:"bg-surface border-border max-w-lg max-h-[85dvh] overflow-y-auto",children:[e.jsx(le,{children:e.jsx(ie,{className:"font-headline text-sm font-medium text-on-surface",children:"Edit job"})}),e.jsxs("form",{id:"edit-job-form",onSubmit:F,className:"space-y-3 mt-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Name *"}),e.jsx(f,{"aria-label":"Name",value:x,onChange:l=>s(l.target.value),className:"bg-background border-control-border text-on-surface font-body text-sm"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Description"}),e.jsx(f,{"aria-label":"Description",value:C,onChange:l=>N(l.target.value),className:"bg-background border-control-border text-on-surface font-body text-sm"})]}),e.jsx(me,{value:T,onChange:m}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Trigger Type"}),e.jsxs(V,{value:u,onValueChange:l=>i(l),children:[e.jsx(q,{"aria-label":"Trigger type","data-testid":"job-trigger-type",className:"bg-background border-control-border text-on-surface font-body text-sm min-h-11",children:e.jsx(M,{})}),e.jsx(W,{className:"bg-surface border-border",children:xe.map(l=>e.jsx(B,{value:l,"data-testid":`job-trigger-${l}`,className:"font-body text-sm",children:l},l))})]})]}),u==="webhook"&&e.jsx("div",{className:"sm:col-span-2",children:e.jsx(de,{value:p,onChange:y,projectId:a.project_id??void 0})}),u==="cron"&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Cron Expression"}),e.jsx(f,{"aria-label":"Cron expression",value:v,onChange:l=>b(l.target.value),placeholder:"*/5 * * * *",className:"bg-background border-control-border text-on-surface font-mono text-xs"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Timeout (s)"}),e.jsx(f,{"aria-label":"Timeout in seconds",type:"number",min:1,required:!0,value:E,onChange:l=>D(l.target.value),className:"bg-background border-control-border text-on-surface font-body text-sm"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Max Retries"}),e.jsx(f,{"aria-label":"Maximum retries",type:"number",min:0,required:!0,value:k,onChange:l=>$(l.target.value),className:"bg-background border-control-border text-on-surface font-body text-sm"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Overlap"}),e.jsxs(V,{value:h,onValueChange:l=>_(l),children:[e.jsx(q,{"aria-label":"Overlap",className:"bg-background border-control-border text-on-surface font-body text-sm min-h-11",children:e.jsx(M,{})}),e.jsx(W,{className:"bg-surface border-border",children:ue.map(l=>e.jsx(B,{value:l,className:"font-body text-sm",children:l},l))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Notify On"}),e.jsxs(V,{value:A,onValueChange:l=>R(l),children:[e.jsx(q,{"aria-label":"Notify on",className:"bg-background border-control-border text-on-surface font-body text-sm min-h-11",children:e.jsx(M,{})}),e.jsx(W,{className:"bg-surface border-border",children:be.map(l=>e.jsx(B,{value:l,className:"font-body text-sm",children:l},l))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(d,{className:"font-label text-xs font-medium text-outline",children:"Enabled"}),e.jsx("button",{type:"button",onClick:()=>J(!w),className:`w-full min-h-11 rounded-md flex items-center justify-center border font-label text-xs font-medium transition-colors ${w?"bg-surface-highest text-on-surface border-border":"bg-background text-outline border-border"}`,children:w?"● Enabled":"○ Disabled"})]})]})]}),e.jsxs(oe,{children:[e.jsx(g,{type:"button",variant:"ghost",size:"sm",onClick:n,className:"font-label text-xs text-outline",children:"Cancel"}),e.jsx(g,{"data-testid":"job-edit-submit",form:"edit-job-form",type:"submit",size:"sm",disabled:z.isPending||!x.trim()||!Y(T)||u==="webhook"&&!p.length,className:"font-label text-xs bg-primary text-primary-foreground hover:bg-primary/90",children:z.isPending?"Saving...":"Save"})]}),z.error&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:z.error.message})]})})}export{gt as default};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import{c as ve,b5 as _,b0 as H,b2 as re,a$ as O,b7 as W,b9 as et,ba as xs,b4 as Ue,b1 as Nt,b6 as hs,b3 as ps,j as e,A as U,r as u,F as Ee,B as g,L as wt,d as M,e as ke,I as B,T as xe,q as he,s as pe,t as fe,v as be,w as J,x as le,ax as _t,bn as We,X as Ve,K as St,D as Ct,m as Dt,n as $t,o as Et,p as ie,av as fs,aX as tt,aZ as bs,a as gs,b$ as js,H as Pt,Y as zt,ab as ys,ac as vs,ae as ks,af as Ns,c0 as st,aj as Rt,ak as Lt,al as Mt,am as Tt,an as At,P as $e,c1 as ws,bf as _s,bD as Ss,J as Cs,O as Ft,N as Ds,be as It,S as Ge,c2 as $s,M as Es,y as de,c3 as at,c4 as Ce,c5 as Kt,c6 as Ps,c7 as zs,c8 as Rs,c9 as Ls,ca as Ms,cb as Ts,cc as As,cd as Fs}from"./index-Ckq9CvHb.js";import{D as Is,c as Ks}from"./DocumentWorkspace-1MKzrR1V.js";import{E as Ye}from"./ErrorState-CwOWC9Qy.js";import{C as Pe}from"./ConfirmDialog-C_exU7Ga.js";import{d as Bs,c as V,e as Us,f as ze,a as Bt,g as Os,K as Hs,h as qs,i as Ut,j as Ws,k as Vs,l as Gs,m as Ys,n as Qs,o as Js,p as Xs,b as Zs}from"./useKnowledge-DcZD9AcU.js";import{T as Ot}from"./TagInput-DDhc6WTI.js";import{T as Re}from"./trash-2-BOe9xa7a.js";import{U as Ht}from"./upload-ZufDR-3q.js";import{s as nt}from"./save-file-B_ZN6-id.js";import{w as ea}from"./wiki-links-Y6CQL1QZ.js";import{E as ta,F as sa}from"./folder-open-DAIhPqFI.js";import{P as qt}from"./pencil-CxDR8VFb.js";import{D as aa}from"./download-DCNlFjgq.js";import{R as na}from"./refresh-cw-C429XUIu.js";import{u as ia}from"./useProjectScope-C3iwCwG_.js";import{E as it}from"./EmptyState-BVLws_BR.js";import{T as ra,a as la,b as rt,c as ce,d as oa,e as me}from"./table-DTKUFFYV.js";import{V as da}from"./ViewHeader-B9EgQxZk.js";import{a as ca,u as ma,b as ua,c as xa,d as ha,e as pa,f as fa,g as ba}from"./useMemories-7v8TIl7-.js";import{u as Te}from"./view-params-BeBdfQW5.js";import{A as ga}from"./arrow-left-BTl_37z8.js";/**
|
|
2
|
+
* @license lucide-react v1.27.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const ja=[["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"}]],ya=ve("file-down",ja);/**
|
|
7
|
+
* @license lucide-react v1.27.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const va=[["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"}]],ka=ve("file-plus",va);/**
|
|
12
|
+
* @license lucide-react v1.27.0 - ISC
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the ISC license.
|
|
15
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/const Na=[["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"}]],wa=ve("file-up",Na);/**
|
|
17
|
+
* @license lucide-react v1.27.0 - ISC
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the ISC license.
|
|
20
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
+
*/const _a=[["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"}]],Wt=ve("folder-sync",_a);/**
|
|
22
|
+
* @license lucide-react v1.27.0 - ISC
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the ISC license.
|
|
25
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/const Sa=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}]],Ca=ve("panel-right",Sa),se=["mcp","api","cli","ui"],lt=["fetch","cited","search_hit"],Vt=_().trim().min(1).max(120),Gt=H(re(se)).max(se.length).transform(t=>se.filter(s=>t.includes(s)));O({name:Vt,description:_().trim().max(2e3).default(""),project_id:_().min(1).nullable(),editable_by:Gt.default([...se]),parser:_().min(1).max(40).nullable().default(null)}).strict();O({name:Vt.optional(),description:_().trim().max(2e3).optional(),editable_by:Gt.optional(),parser:_().min(1).max(40).nullable().optional()}).strict();const Da=["default","project","global","all"],Yt=_().trim().min(1).max(500).refine(t=>!t.startsWith("/")&&!t.includes("\\")&&!t.includes(":")&&!t.includes("\0")&&t.split("/").every(s=>s&&s!=="."&&s!==".."),"Use a relative path with / separators and no . or .. segments"),Qt=H(_().trim().min(1).max(60)).max(30),ye=2*1024*1024;O({title:_().trim().min(1).max(300),path:Yt.optional(),description:_().trim().max(2e3).optional(),labels:Qt.default([]),content:_().max(ye),note:_().trim().max(1e3).optional(),derived_from:H(_().min(1)).max(50).default([])}).strict();O({expected_revision:W().int().min(1),title:_().trim().min(1).max(300).optional(),path:Yt.optional(),description:_().trim().max(2e3).optional(),labels:Qt.optional(),content:_().max(ye).optional(),note:_().trim().max(1e3).optional(),derived_from:H(_().min(1)).max(50).optional()}).strict();const $a=1,Ea=["heading","paragraph","list_item","table","code"],Pa=O({kind:re(Ea),text:_(),level:W().int().min(1).max(6).optional(),rows:H(H(_())).optional(),heading_path:H(_()),locator:O({page:W().int().min(1).optional(),sheet:_().optional(),bbox:H(W()).length(4).optional()}).optional()});O({schema_version:Ue($a),parser:O({id:_(),version:_(),options:et(_(),xs())}),source_sha256:_().regex(/^[0-9a-f]{64}$/),status:re(["ok","partial","failed"]),language:_().optional(),blocks:H(Pa),markdown:_(),warnings:H(_()),timings_ms:et(_(),W()).optional(),peak_rss_mb:W().optional()});const Jt=["auto","lexical","semantic","hybrid"],za=O({query:_().trim().min(1).max(2e3),scope:re(Da).default("default"),kb_ids:H(_().min(1)).max(50).optional(),labels:H(_().min(1)).max(20).optional(),media_types:H(_().min(1)).max(20).optional(),mode:re(Jt).default("auto"),limit:W().int().min(1).max(50).default(10)}).strict();za.omit({limit:!0,mode:!0}).extend({mode:re(Jt).default("auto"),token_budget:W().int().min(500).max(32e3).default(6e3),max_per_document:W().int().min(1).max(10).default(3)}).strict();const Ra=O({old:_().min(1).max(ye),new:_().max(ye),replace_all:Nt().optional()}).strict(),La=O({start_line:W().int().min(1),end_line:W().int().min(0),new:_().max(ye)}).strict();O({expected_revision:W().int().min(1),edits:H(hs([Ra,La])).min(1).max(50),note:_().trim().min(1).max(1e3)}).strict();const Ma=["open","resolved","dismissed"];O({document_id:_().min(1).nullable().optional(),body:_().trim().min(1).max(1e4)}).strict();O({status:re(["resolved","dismissed"]),reply:_().trim().min(1).max(4e3)}).strict();const Ta=ps("type",[O({type:Ue("cron"),cron:_().trim().min(1).max(120)}).strict(),O({type:Ue("manual")}).strict()]);O({instructions:_().trim().min(1).max(2e4).optional(),backend:_().min(1).max(64).regex(/^[a-z][a-z0-9_-]*$/).optional(),schedule:Ta.optional(),enabled:Nt().optional(),timeout_secs:W().int().min(60).max(7200).optional()}).strict();const Xt="0 3 * * *";function Ne({title:t,testId:s,toggleTestId:n,summary:a,actions:i,expanded:l=!1,onExpandedChange:r,heading:o="h3",compact:d=!1,children:p}){const m=u.useId(),x=p!==void 0&&r!==void 0;return e.jsxs("section",{"data-testid":s,"data-expanded":x?l:void 0,"aria-labelledby":`${m}-heading`,className:"min-w-0 text-sm",children:[e.jsxs("div",{className:U("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",!d&&"sm:grid-cols-[9rem_minmax(0,1fr)_auto]"),children:[e.jsx(o,{id:`${m}-heading`,className:"min-w-0 font-medium",children:x?e.jsxs("button",{type:"button","data-testid":n,"aria-expanded":l,"aria-controls":m,className:"-ml-1 flex min-h-9 items-center gap-1.5 rounded px-1 text-left hover:bg-surface-high",onClick:()=>r(!l),children:[e.jsx(Ee,{size:14,"aria-hidden":!0,className:U("shrink-0 text-outline transition-transform",l&&"rotate-90")}),t]}):e.jsx("span",{className:"flex min-h-9 items-center pl-5",children:t})}),e.jsx("div",{className:U("col-span-2 row-start-2 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 pl-5",!d&&"sm:col-span-1 sm:col-start-2 sm:row-start-1 sm:pl-0"),children:a}),e.jsx("div",{className:U("col-start-2 row-start-1 flex items-center justify-end gap-1",!d&&"sm:col-start-3"),children:i})]}),x&&l&&e.jsx("div",{id:m,className:"min-w-0 pb-4 pl-5 pt-1",children:p})]})}function ae({tone:t}){return e.jsx("span",{"aria-hidden":!0,className:U("size-1.5 shrink-0 rounded-full",t==="ok"&&"bg-secondary",t==="warning"&&"bg-warning",t==="error"&&"bg-error",t==="off"&&"bg-muted-foreground",t==="progress"&&"bg-progress")})}const Le=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],De=/^\d+$/,ue=t=>t.padStart(2,"0"),ot=t=>{var s;return(s=/^\*\/(\d+)$/.exec(t))==null?void 0:s[1]},dt=(t,s)=>t==="1"?`Every ${s}`:`Every ${t} ${s}s`;function Zt(t){const[s="",n="",a,i,l="",...r]=t.trim().split(/\s+/);if(r.length||a!=="*"||i!=="*")return t;if(n==="*"&&l==="*"){if(s==="*")return"Every minute";const p=ot(s);return p?dt(p,"minute"):De.test(s)?Number(s)?`Every hour at :${ue(s)}`:"Every hour":t}if(!De.test(s))return t;const o=ot(n);if(o&&l==="*")return`${dt(o,"hour")}${Number(s)?` at :${ue(s)}`:""}`;if(!De.test(n))return t;const d=`${ue(n)}:${ue(s)}`;return l==="*"?`Daily at ${d}`:l==="1-5"?`Weekdays at ${d}`:l==="0,6"||l==="6,0"?`Weekends at ${d}`:/^[0-7]$/.test(l)?`${Le[Number(l)%7]}s at ${d}`:t}const Aa=[{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 Fa(t,s){const n=a=>{const i=s.names.indexOf(a.toUpperCase()),l=i>=0?i+(s.min===1?1:0):De.test(a)?Number(a):Number.NaN;return l>=s.min&&l<=s.max?l:Number.NaN};return t.split(",").every(a=>{const i=/^(\*|[a-z0-9]+(?:-[a-z0-9]+)?)(?:\/(\d+))?$/i.exec(a);if(!(i!=null&&i[1])||i[2]!==void 0&&Number(i[2])<1)return!1;if(i[1]==="*")return!0;const[l="",r]=i[1].split("-");return r===void 0?!Number.isNaN(n(l)):n(l)<=n(r)})}function Ia(t){const s=t.trim().split(/\s+/).filter(Boolean);if(!s.length)return"Enter a cron expression.";if(s.length!==5)return`A cron expression has 5 fields (minute hour day month weekday); this one has ${s.length}.`;for(const[n,a]of Aa.entries()){const i=s[n]??"";if(!Fa(i,a))return`The ${a.name} field "${i}" is not valid. Use a number from ${a.min} to ${a.max}, *, a range (1-5), a list (1,3) or a step (*/2).`}return null}function Ka(t){var a;const s=Math.max(0,Math.round((t-Date.now())/1e3));if(s<60)return"in under a minute";if(s<3600)return`in ${Math.round(s/60)}m`;if(s<86400)return`in ${Math.round(s/3600)}h`;const n=new Date(t);return`${(a=Le[n.getDay()])==null?void 0:a.slice(0,3)} ${ue(String(n.getHours()))}:${ue(String(n.getMinutes()))}`}function Qe(t){const s=Math.max(0,Math.round((Date.now()-t)/1e3));return s<60?"just now":s<3600?`${Math.round(s/60)}m ago`:s<86400?`${Math.round(s/3600)}h ago`:`${Math.round(s/86400)}d ago`}function Ba(t){var n;const s=(n=t.last_run)==null?void 0:n.status;return s==="running"?"progress":t.schedule.type==="cron"&&!t.enabled?"off":s==="failed"?"error":s==="completed"?"ok":"off"}function Ua({kb:t}){const s=Bs(t.id),[n,a]=u.useState(null),[i,l]=u.useState(!1),r=s.data;return e.jsxs(e.Fragment,{children:[e.jsx(Ne,{title:"Digest",testId:"kb-digest",toggleTestId:"kb-digest-expand",expanded:i,onExpandedChange:l,summary:s.error?e.jsx("span",{role:"alert",className:"text-error",children:s.error.message}):s.isLoading?e.jsx("span",{className:"text-outline",children:"Loading…"}):r?e.jsx(Oa,{digest:r}):e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-outline","data-testid":"kb-digest-off",children:[e.jsx(ae,{tone:"off"}),"Off, documents change only when someone edits them"]}),actions:r?e.jsx(Ha,{kb:t,digest:r,onStarted:()=>l(!0)}):s.data===null?e.jsx(g,{size:"sm",variant:"outline","data-testid":"kb-digest-add",onClick:()=>a("edit"),children:"Set up"}):null,children:r?e.jsx(qa,{kb:t,digest:r,onEdit:()=>a("edit")}):e.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"&&e.jsx(sn,{kb:t,digest:r??null,onClose:()=>a(null),onRemove:()=>a("remove")}),n==="remove"&&e.jsx(an,{kb:t,onClose:()=>a(null)})]})}function Oa({digest:t}){const s=t.last_run,n=t.schedule.type==="manual"||t.enabled;return e.jsxs("span",{"data-testid":"kb-digest-summary",className:"inline-flex min-w-0 flex-wrap items-center gap-x-1.5",children:[e.jsx(ae,{tone:Ba(t)}),e.jsx("span",{"data-testid":"kb-digest-enabled",children:n?"On":"Paused"}),e.jsxs("span",{children:["·"," ",t.schedule.type==="manual"?"runs when you start it":e.jsx("span",{title:t.schedule.cron,children:Zt(t.schedule.cron)})]}),t.next_run_at!==null&&e.jsxs("span",{className:"text-outline","data-testid":"kb-digest-next-run",children:["·"," ",e.jsxs("span",{title:new Date(t.next_run_at).toLocaleString(),children:["next run ",Ka(t.next_run_at)]})]}),e.jsxs("span",{className:"text-outline","data-testid":"kb-digest-last-run","data-status":(s==null?void 0:s.status)??"never",children:["·"," ",s?s.status==="running"?"running now":e.jsxs("span",{title:new Date(s.at).toLocaleString(),children:["last run"," ",e.jsx("span",{className:s.status==="failed"?"text-error":void 0,children:s.status==="completed"?"succeeded":s.status})," ",Qe(s.at)]}):"not run yet"]})]})}function Ha({kb:t,digest:s,onStarted:n}){var o;const a=V(),i=Y(),l=((o=s.last_run)==null?void 0:o.status)==="running";async function r(){await i.run(()=>M.kb.runDigest(t.id))&&(n(),await a())}return e.jsxs(e.Fragment,{children:[i.error&&e.jsx("span",{role:"alert",className:"text-error","data-testid":"kb-digest-error",children:i.error}),e.jsx(g,{size:"sm",variant:"outline","data-testid":"kb-digest-run",onClick:r,disabled:i.pending||l,children:l?"Running…":"Run now"})]})}function qa({kb:t,digest:s,onEdit:n}){const a=V(),i=Y(),l=Us(t.id,s);async function r(){await i.run(()=>M.kb.setDigest(t.id,{enabled:!s.enabled}))&&await a()}return e.jsxs("div",{className:"min-w-0 space-y-3",children:[e.jsxs("p",{className:"max-w-prose text-outline",children:["The ",e.jsx("span",{className:"font-mono text-on-surface",children:s.backend})," agent reads new memories, sessions and open comments, then updates documents here."," ",e.jsx("span",{"data-testid":"kb-digest-open-comments",children:s.open_comments})," open"," ",s.open_comments===1?"comment waits":"comments wait"," for the next run."]}),e.jsxs("div",{className:"-ml-2 flex flex-wrap items-center gap-1",children:[e.jsx(g,{size:"sm",variant:"ghost","data-testid":"kb-digest-edit",onClick:n,children:"Edit instructions and schedule"}),s.schedule.type==="cron"&&e.jsx(g,{size:"sm",variant:"ghost","data-testid":"kb-digest-toggle",onClick:r,disabled:i.pending,children:s.enabled?"Pause schedule":"Resume schedule"}),e.jsx(g,{size:"sm",variant:"ghost",asChild:!0,children:e.jsx(wt,{to:`/jobs/${encodeURIComponent(s.job_id)}`,"data-testid":"kb-digest-job",children:"Job history"})})]}),i.error&&e.jsx("p",{role:"alert",className:"text-error","data-testid":"kb-digest-error",children:i.error}),e.jsx(Va,{runs:l.data??[]})]})}const Wa={failed:"error",success:"ok",running:"progress"};function Va({runs:t}){return t.length?e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-xs font-medium text-outline",children:"Recent runs"}),e.jsx("ol",{"data-testid":"kb-digest-runs",className:"divide-y divide-outline-variant",children:t.map(s=>e.jsxs("li",{"data-testid":"kb-digest-run-row","data-status":s.status,className:"min-w-0 break-words py-1.5",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ae,{tone:Wa[s.status]??"off"}),s.status]}),e.jsxs("span",{className:"text-outline",children:[" · ",s.started_at?e.jsx("span",{title:new Date(s.started_at).toLocaleString(),children:Qe(s.started_at)}):"not started",s.trigger_by?` · ${s.trigger_by}`:""]}),s.session_id&&e.jsx(wt,{to:`/audit/${encodeURIComponent(s.session_id)}`,className:"ml-2 text-primary hover:underline",children:"Session"}),(s.error||s.summary)&&e.jsx("span",{className:"block truncate text-xs text-outline",title:s.error??s.summary??"",children:s.error??s.summary})]},s.run_id))})]}):e.jsx("p",{className:"text-outline",children:"No runs yet."})}const Ae="__global__",Fe="__auto__";function es(t){return t instanceof Error?t.message:"Request failed"}function Y(){const[t,s]=u.useState(!1),[n,a]=u.useState(null);async function i(l){s(!0),a(null);try{return await l()}catch(r){a(es(r));return}finally{s(!1)}}return{pending:t,error:n,run:i,setError:a}}function L({label:t,children:s,hint:n}){return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(ie,{className:"text-sm text-muted-foreground",children:t}),s,n&&e.jsx("p",{className:"text-xs text-outline",children:n})]})}function oe({error:t}){return t?e.jsx("p",{role:"alert","data-testid":"kb-dialog-error",className:"text-sm text-error",children:t}):null}function ge({open:t,onClose:s,title:n,wide:a,size:i,children:l}){return e.jsx(Ct,{open:t,onOpenChange:r=>!r&&s(),children:e.jsxs(Dt,{className:`bg-surface border-outline-variant ${i==="xl"?"w-[calc(100%_-_1rem)] max-w-4xl":a?"max-w-3xl":"max-w-md"}`,children:[e.jsx($t,{children:e.jsx(Et,{className:"text-base text-on-surface",children:n})}),l]})})}function ts({value:t,onChange:s}){var a;const n=Bt();return e.jsxs(he,{value:t??Fe,onValueChange:i=>s(i===Fe?null:i),children:[e.jsx(pe,{"aria-label":"Parser","data-testid":"kb-parser-select",children:e.jsx(fe,{})}),e.jsxs(be,{children:[e.jsx(J,{value:Fe,children:"Workspace default"}),(((a=n.data)==null?void 0:a.parsers)??[]).map(i=>e.jsxs(J,{value:i.id,disabled:!i.installed,children:[i.label,i.installed?"":" (not installed)"]},i.id))]})]})}const ss={ui:"Web UI",cli:"CLI",api:"REST API",mcp:"Agents (MCP)"};function as({value:t,onChange:s}){return e.jsxs("fieldset",{className:"space-y-2 rounded-md border border-outline-variant p-3",children:[e.jsx("legend",{className:"px-1 text-sm text-muted-foreground",children:"Who can change documents"}),e.jsx("div",{className:"flex flex-wrap gap-x-4 gap-y-2",children:se.map(n=>e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox","data-testid":`kb-editable-${n}`,checked:t.includes(n),onChange:a=>s(se.filter(i=>i===n?a.target.checked:t.includes(i)))}),ss[n]]},n))}),e.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 Ga({open:t,projectId:s,onClose:n,onCreated:a}){const i=ke(),l=V(),r=Y(),[o,d]=u.useState(""),[p,m]=u.useState(""),[x,k]=u.useState(s??Ae),[j,C]=u.useState([...se]),[w,f]=u.useState(null);async function $(b){b.preventDefault();const c=await r.run(()=>M.kb.create({name:o.trim(),description:p.trim(),project_id:x===Ae?null:x,editable_by:j,parser:w}));c&&(await l(),a(c))}return e.jsx(ge,{open:t,onClose:n,title:"New knowledge base",children:e.jsxs("form",{onSubmit:$,className:"space-y-4",children:[e.jsx(L,{label:"Name",children:e.jsx(B,{"aria-label":"Name","data-testid":"kb-name-input",value:o,onChange:b=>d(b.target.value),placeholder:"e.g. Runbooks",autoFocus:!0})}),e.jsx(L,{label:"Description",children:e.jsx(xe,{"aria-label":"Description",value:p,onChange:b=>m(b.target.value),rows:2})}),e.jsx(L,{label:"Belongs to",hint:"Project knowledge bases are visible in that project; global ones in every project.",children:e.jsxs(he,{value:x,onValueChange:k,children:[e.jsx(pe,{"aria-label":"Belongs to","data-testid":"kb-owner-select",children:e.jsx(fe,{})}),e.jsxs(be,{children:[e.jsx(J,{value:Ae,children:"Global (all projects)"}),(i.data??[]).map(b=>e.jsx(J,{value:b.id,children:b.name},b.id))]})]})}),e.jsx(as,{value:j,onChange:C}),e.jsx(L,{label:"Parser for uploads",children:e.jsx(ts,{value:w,onChange:f})}),e.jsx(oe,{error:r.error}),e.jsxs(le,{children:[e.jsx(g,{type:"button",variant:"ghost",onClick:n,children:"Cancel"}),e.jsx(g,{type:"submit","data-testid":"kb-create-submit",disabled:!o.trim()||r.pending,children:r.pending?"Creating…":"Create"})]})]})})}function Ya({kb:t,onClose:s,onDeleted:n}){var $,b;const a=ke(),i=V(),l=Y(),[r,o]=u.useState(t.name),[d,p]=u.useState(t.description),[m,x]=u.useState(t.editable_by),[k,j]=u.useState(t.parser),[C,w]=u.useState(!1);async function f(c){c.preventDefault(),await l.run(()=>M.kb.update(t.id,{name:r.trim(),description:d.trim(),editable_by:m,parser:k}))&&(await i(),s())}return e.jsxs(ge,{open:!0,onClose:s,title:"Knowledge base settings",children:[e.jsxs("form",{onSubmit:f,className:"space-y-4",children:[e.jsx(L,{label:"Name",children:e.jsx(B,{"aria-label":"Name","data-testid":"kb-name-input",value:r,onChange:c=>o(c.target.value)})}),e.jsx(L,{label:"Description",children:e.jsx(xe,{"aria-label":"Description",value:d,onChange:c=>p(c.target.value),rows:2})}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsx("div",{className:"font-medium",children:"Belongs to"}),e.jsxs("p",{className:"text-outline","data-testid":"kb-settings-owner",children:[t.project_id===null?"Global, visible in every project":`${((b=($=a.data)==null?void 0:$.find(c=>c.id===t.project_id))==null?void 0:b.name)??"A project"}, visible in that project`,". Set when the knowledge base is created."]})]}),e.jsx(as,{value:m,onChange:x}),e.jsx(L,{label:"Parser for uploads",hint:"Applies to new uploads and reparses.",children:e.jsx(ts,{value:k,onChange:j})}),e.jsx(oe,{error:l.error}),e.jsxs(le,{className:"gap-2 sm:justify-between",children:[e.jsxs(g,{type:"button",variant:"ghost",className:"text-error","data-testid":"kb-delete",onClick:()=>w(!0),children:[e.jsx(Re,{size:14}),"Delete"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{type:"button",variant:"ghost",onClick:s,children:"Cancel"}),e.jsx(g,{type:"submit","data-testid":"kb-settings-save",disabled:!r.trim()||l.pending,children:"Save"})]})]})]}),e.jsx(Pe,{open:C,title:"Delete knowledge base",description:`Delete "${t.name}" with its ${t.document_count} documents, revisions and uploaded files? Registered folders on disk are not touched.`,isPending:l.pending,onCancel:()=>w(!1),onConfirm:async()=>{const c=await l.run(()=>M.kb.remove(t.id));w(!1),c!==void 0&&(await i(),n())}})]})}function ct(t){return`${t.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"untitled"}.md`}function mt(t){var s,n;return((n=(s=t.match(/^#\s+(.+?)\s*#*\s*$/m))==null?void 0:s[1])==null?void 0:n.trim())??""}const Qa=/\.(md|markdown|txt)$/i;function Ja({kb:t,initialFile:s,onClose:n,onCreated:a,onUploadMany:i}){var h;const l=V(),r=Y(),o=ze(t.id),[d,p]=u.useState(""),[m,x]=u.useState(""),[k,j]=u.useState(""),[C,w]=u.useState([]),[f,$]=u.useState(null),[b,c]=u.useState(!1),S=u.useRef(null),P=f?"":mt(m),T=d.trim()||P,K=f?f.name:ct(T),q=f!==null||m.trim()!=="";async function z(E){const F=E.name.replace(/\.[^.]+$/,"");if(!Qa.test(E.name)){$(E),p(F),j("");return}c(!0);const G=await r.run(()=>E.text());c(!1),G!==void 0&&($(null),x(G),p(mt(G)||F),j(/\.txt$/i.test(E.name)?ct(F):E.name))}function y(E){const F=[...E??[]];F.length>1?i(F):F[0]&&z(F[0])}u.useEffect(()=>{s&&z(s)},[]);async function v(E){E.preventDefault();const F=await r.run(()=>f?M.kb.upload(t.id,{file:f,title:T,path:k.trim()||void 0,labels:C}):M.kb.createDocument(t.id,{title:T,path:k.trim()||K,labels:C,content:q?m:`# ${T}
|
|
27
|
+
|
|
28
|
+
`}));F&&(await l(),a(F,q))}return e.jsx(ge,{open:!0,onClose:n,title:`New document in ${t.name}`,size:"xl",children:e.jsxs("form",{onSubmit:v,className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm text-outline",children:[e.jsx("span",{children:"Write or paste below, or start from a file."}),e.jsxs(g,{type:"button",size:"sm",variant:"outline","data-testid":"kb-doc-choose-file",disabled:b||r.pending,onClick:()=>{var E;return(E=S.current)==null?void 0:E.click()},children:[e.jsx(Ht,{size:16}),b?"Reading…":"Upload file"]}),e.jsx("input",{ref:S,type:"file",multiple:!0,hidden:!0,"data-testid":"kb-doc-file-input",onChange:E=>{y(E.target.files),E.target.value=""}})]}),e.jsx(L,{label:"Title",hint:P&&!d.trim()?"Taken from the first heading.":void 0,children:e.jsx(B,{"aria-label":"Title","data-testid":"kb-doc-title-input",value:d,onChange:E=>p(E.target.value),placeholder:P||"e.g. Deploy runbook",autoFocus:!0})}),f?e.jsx(L,{label:"File",hint:"Converted to searchable text after it is added. The original file is kept.",children:e.jsxs("div",{"data-testid":"kb-doc-file",className:"flex items-center gap-3 rounded-md border border-surface-highest bg-surface p-3",children:[e.jsx(_t,{size:20,className:"shrink-0 text-outline","aria-hidden":!0}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",title:f.name,children:f.name}),e.jsx("span",{className:"shrink-0 text-xs text-outline",children:We(f.size)}),e.jsx(g,{type:"button",size:"icon",variant:"ghost","aria-label":`Remove ${f.name}`,"data-testid":"kb-doc-file-remove",onClick:()=>{$(null),p("")},children:e.jsx(Ve,{size:16})})]})}):e.jsx(L,{label:"Content",hint:"Markdown. Leave empty to start writing in the editor.",children:e.jsx(St,{path:k.trim()||K,value:m,onChange:x,testId:"kb-doc-content-input",label:"Content",placeholder:"Write or paste Markdown",initialMode:"edit",height:"45vh"})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(L,{label:"Labels",hint:"Enter, comma or space adds a label.",children:e.jsx(Ot,{"aria-label":"Labels","data-testid":"kb-doc-labels-input",value:C,onChange:w,suggestions:(h=o.data)==null?void 0:h.labels.map(E=>E.label)})}),e.jsx(L,{label:"Path",hint:"Optional. Folders come from the path, e.g. guides/setup.md.",children:e.jsx(B,{"aria-label":"Path","data-testid":"kb-doc-path-input",value:k,onChange:E=>j(E.target.value),placeholder:K,className:"font-mono text-sm"})})]}),e.jsx(oe,{error:r.error}),e.jsxs(le,{children:[e.jsx(g,{type:"button",variant:"ghost",onClick:n,children:"Cancel"}),e.jsx(g,{type:"submit","data-testid":"kb-doc-create-submit",disabled:!T||r.pending,children:"Create"})]})]})})}function Xa({doc:t,linkedFrom:s,onClose:n,onSaved:a}){var $;const i=V(),l=Y(),[r,o]=u.useState(t.title),[d,p]=u.useState(t.path),m=ze(t.kb_id),[x,k]=u.useState(t.labels),[j,C]=u.useState(t.description),w=r.trim()!==t.title||d.trim()!==t.path;async function f(b){b.preventDefault(),await l.run(()=>M.kb.updateDocument(t.id,{expected_revision:t.revision,title:r.trim(),path:d.trim(),labels:x,description:j.trim()}))&&(await i(),a())}return e.jsx(ge,{open:!0,onClose:n,title:"Document properties",children:e.jsxs("form",{onSubmit:f,className:"space-y-4",children:[e.jsx(L,{label:"Title",children:e.jsx(B,{"aria-label":"Title","data-testid":"kb-doc-title-input",value:r,onChange:b=>o(b.target.value)})}),e.jsx(L,{label:"Path",children:e.jsx(B,{"aria-label":"Path","data-testid":"kb-doc-path-input",value:d,onChange:b=>p(b.target.value),className:"font-mono text-sm"})}),e.jsx(L,{label:"Labels",hint:"Enter, comma or space adds a label.",children:e.jsx(Ot,{"aria-label":"Labels","data-testid":"kb-doc-labels-input",value:x,onChange:k,suggestions:($=m.data)==null?void 0:$.labels.map(b=>b.label)})}),e.jsx(L,{label:"Description",children:e.jsx(xe,{"aria-label":"Description",value:j,onChange:b=>C(b.target.value),rows:2})}),w&&s>0&&e.jsxs("p",{role:"status",className:"text-sm text-warning","data-testid":"kb-rename-warning",children:[s===1?"1 document links":`${s} documents link`," to this document. Links that use the old title or path will show as missing."]}),e.jsx(oe,{error:l.error}),e.jsxs(le,{children:[e.jsx(g,{type:"button",variant:"ghost",onClick:n,children:"Cancel"}),e.jsx(g,{type:"submit","data-testid":"kb-doc-properties-save",disabled:!r.trim()||l.pending,children:"Save"})]})]})})}const ut={daily:"Every day",weekly:"Once a week",custom:"Custom cron",manual:"Manual only"};function Za(t){const s=t.type==="cron"?t.cron:Xt,n={plan:"custom",time:"03:00",day:"1",cron:s},a=/^(\d{1,2}) (\d{1,2}) \* \* (\*|[0-6])$/.exec(s.trim().split(/\s+/).join(" ")),[i,l]=[Number(a==null?void 0:a[1]),Number(a==null?void 0:a[2])],r=a&&i<=59&&l<=23?`${String(l).padStart(2,"0")}:${String(i).padStart(2,"0")}`:null;return t.type==="manual"?{...n,plan:"manual",time:r??n.time}:!(a!=null&&a[3])||!r?n:a[3]==="*"?{...n,plan:"daily",time:r}:{...n,plan:"weekly",time:r,day:a[3]}}function ns({plan:t,time:s,day:n,cron:a}){if(t==="manual")return null;if(t==="custom")return a.trim();const[i,l]=s.split(":").map(Number);return`${l} ${i} * * ${t==="weekly"?n:"*"}`}function is(t){return t.plan==="manual"?null:t.plan==="custom"?Ia(t.cron):/^\d{2}:\d{2}$/.test(t.time)?null:"Pick a time."}function en(t){const s=Zt(t);return s===t?"Runs on this cron schedule":Le.some(n=>s.startsWith(n))?`Runs ${s}`:`Runs ${s.charAt(0).toLowerCase()}${s.slice(1)}`}function tn({value:t,onChange:s}){const n=ns(t),a=is(t),i=l=>s({...t,...l});return e.jsxs("fieldset",{className:"space-y-3 rounded-md border border-outline-variant p-3",children:[e.jsx("legend",{className:"px-1 text-sm text-muted-foreground",children:"When it runs"}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsx(L,{label:"Schedule",children:e.jsxs(he,{value:t.plan,onValueChange:l=>i({plan:l,...l==="custom"&&n?{cron:n}:{}}),children:[e.jsx(pe,{"aria-label":"Schedule","data-testid":"kb-digest-schedule",children:e.jsx(fe,{})}),e.jsx(be,{children:Object.keys(ut).map(l=>e.jsx(J,{value:l,children:ut[l]},l))})]})}),t.plan==="weekly"&&e.jsx(L,{label:"Day",children:e.jsxs(he,{value:t.day,onValueChange:l=>i({day:l}),children:[e.jsx(pe,{"aria-label":"Day","data-testid":"kb-digest-day",children:e.jsx(fe,{})}),e.jsx(be,{children:Le.map((l,r)=>e.jsx(J,{value:String(r),children:l},l))})]})}),(t.plan==="daily"||t.plan==="weekly")&&e.jsx(L,{label:"Time",children:e.jsx(B,{type:"time","aria-label":"Time","data-testid":"kb-digest-time",value:t.time,onChange:l=>i({time:l.target.value})})}),t.plan==="custom"&&e.jsx("div",{className:"sm:col-span-2",children:e.jsx(L,{label:"Cron expression",hint:"minute hour day month weekday, e.g. 0 */6 * * *",children:e.jsx(B,{"aria-label":"Cron expression","aria-invalid":a!==null,"data-testid":"kb-digest-cron",value:t.cron,onChange:l=>i({cron:l.target.value}),className:"font-mono",autoComplete:"off"})})})]}),e.jsx("p",{"aria-live":"polite","data-testid":"kb-digest-schedule-preview","data-valid":a===null,className:`text-sm ${a?"text-error":"text-outline"}`,children:a||(n?e.jsxs(e.Fragment,{children:[en(n)," ",e.jsxs("span",{className:"font-mono text-xs",children:["(",n,")"]}),", in the ORC server's time zone."]}):"Runs only when you start it.")})]})}function sn({kb:t,digest:s,onClose:n,onRemove:a}){const i=V(),l=Y(),r=fs(),o=Os(!s),[d,p]=u.useState((s==null?void 0:s.instructions)??null),[m,x]=u.useState((s==null?void 0:s.backend)??tt),[k,j]=u.useState(()=>Za((s==null?void 0:s.schedule)??{type:"cron",cron:Xt}));u.useEffect(()=>{d===null&&o.data&&p(o.data.instructions)},[d,o.data]);const C=is(k);async function w($){var P;if($.preventDefault(),C)return l.setError(C);const b=m===tt?(P=r.data)==null?void 0:P.default_backend:m,c=ns(k);await l.run(()=>M.kb.setDigest(t.id,{instructions:(d==null?void 0:d.trim())??"",...b?{backend:b}:{},schedule:c?{type:"cron",cron:c}:{type:"manual"}}))&&(await i(),n())}const f=d!==null;return e.jsx(ge,{open:!0,onClose:n,title:s?"Digest settings":"Set up a digest",wide:!0,children:e.jsxs("form",{onSubmit:w,className:"min-w-0 space-y-4",children:[!t.editable_by.includes("mcp")&&e.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."}),e.jsx(tn,{value:k,onChange:j}),e.jsx(bs,{value:m,onChange:x,testId:"kb-digest-backend"}),e.jsx(L,{label:"Instructions",children:f?e.jsx(St,{path:"digest.md",value:d,onChange:p,testId:"kb-digest-instructions",label:"Instructions",initialMode:"edit",height:320}):o.error?e.jsx("p",{role:"alert",className:"text-sm text-error",children:es(o.error)}):e.jsx("p",{role:"status",className:"text-sm text-outline",children:"Loading template…"})}),e.jsx(oe,{error:l.error}),e.jsxs(le,{className:"gap-2 sm:justify-between",children:[s&&a?e.jsxs(g,{type:"button",variant:"ghost",className:"text-error","data-testid":"kb-digest-remove",onClick:a,children:[e.jsx(Re,{size:14}),"Remove digest"]}):e.jsx("span",{}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{type:"button",variant:"ghost",onClick:n,children:"Cancel"}),e.jsx(g,{type:"submit","data-testid":"kb-digest-save",disabled:!f||!(d!=null&&d.trim())||C!==null||l.pending,children:l.pending?"Saving…":"Save"})]})]})]})})}function an({kb:t,onClose:s}){const n=gs(),a=Y();async function i(){await a.run(()=>M.kb.removeDigest(t.id,t.name))!==void 0&&(n.setQueryData([Hs,t.id],{digest:null}),await n.invalidateQueries({queryKey:[qs]}),s())}return e.jsx(ge,{open:!0,onClose:s,title:"Remove digest?",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-outline",children:"Documents and comments stay. The digest's instructions, schedule, job and run history are removed."}),e.jsx(oe,{error:a.error}),e.jsxs(le,{children:[e.jsx(g,{type:"button",variant:"ghost",onClick:s,children:"Cancel"}),e.jsx(g,{type:"button",variant:"destructive","data-testid":"kb-digest-remove-confirm",onClick:i,disabled:a.pending,autoFocus:!0,children:a.pending?"Removing…":"Remove digest"})]})]})})}const nn=js("inline-flex items-center rounded-full border border-border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none 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 rs({className:t,variant:s,...n}){return e.jsx("div",{className:U(nn({variant:s}),t),...n})}const rn={open:"bg-warning",resolved:"bg-secondary",dismissed:"bg-muted-foreground"};function ls({status:t}){return e.jsx("span",{"aria-hidden":!0,className:U("size-1.5 shrink-0 rounded-full",rn[t])})}function os({kbId:t,documentId:s,onOpenDocument:n,heading:a="h3",compact:i=!1}){var j,C,w;const[l,r]=u.useState(!1),[o,d]=u.useState(null),p=Ut(t,{...s?{document_id:s}:{},...o?{status:o}:{}}),m=(j=p.data)==null?void 0:j.counts,x=m?m.open+m.resolved+m.dismissed:0;function k(f){d(l&&o===f?null:f),r(!0)}return e.jsx(Ne,{title:"Comments",testId:"kb-comments",toggleTestId:"kb-comments-toggle",heading:a,compact:i,expanded:l,onExpandedChange:r,summary:e.jsxs(e.Fragment,{children:[m&&x===0&&e.jsx("span",{className:"text-outline","data-testid":"kb-comments-none",children:"None yet"}),m&&Ma.filter(f=>m[f]>0).map(f=>e.jsxs("button",{type:"button","data-testid":`kb-comments-count-${f}`,"aria-pressed":l&&o===f,"aria-label":`${m[f]} ${f} ${m[f]===1?"comment":"comments"}`,className:U("inline-flex min-h-8 items-center gap-1.5 rounded px-1.5",l&&o===f?"bg-surface-highest text-on-surface":"text-outline hover:bg-surface-high"),onClick:()=>k(f),children:[e.jsx(ls,{status:f}),e.jsx("span",{className:"tabular-nums text-on-surface",children:m[f]}),f]},f)),p.error&&e.jsx("span",{role:"alert",className:"text-error","data-testid":"kb-comments-error",children:p.error.message})]}),children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(ln,{kbId:t,documentId:s}),o&&((C=p.data)==null?void 0:C.comments.length)===0&&e.jsxs("p",{className:"text-outline","data-testid":"kb-comments-empty",children:["No ",o," comments."]}),e.jsx("ul",{className:"divide-y divide-outline-variant",children:(w=p.data)==null?void 0:w.comments.map(f=>e.jsx(on,{comment:f,showDocument:!s,onOpenDocument:n},f.id))})]})})}function ln({kbId:t,documentId:s}){const n=V(),a=Y(),[i,l]=u.useState("");async function r(o){o.preventDefault(),await a.run(()=>M.kb.addComment(t,{body:i.trim(),...s?{document_id:s}:{}}))&&(l(""),await n())}return e.jsxs("form",{onSubmit:r,className:"space-y-2",children:[e.jsx(xe,{"aria-label":s?"Comment on this document":"Comment on this knowledge base",placeholder:s?"Ask for a change to this document":"Ask for a change","data-testid":"kb-comment-input",value:i,onChange:o=>l(o.target.value),rows:2,maxLength:1e4}),i.trim()&&e.jsx(g,{type:"submit",size:"sm",variant:"outline","data-testid":"kb-comment-add",disabled:a.pending,children:"Add comment"}),a.error&&e.jsx("p",{role:"alert",className:"text-error","data-testid":"kb-comment-add-error",children:a.error})]})}function on({comment:t,showDocument:s,onOpenDocument:n}){const a=V(),i=Y(),[l,r]=u.useState(null),[o,d]=u.useState("");async function p(x){if(x.preventDefault(),!l)return;const k=l;await i.run(()=>M.kb.closeComment(t.id,{status:k,reply:o.trim()}))&&(r(null),d(""),await a())}async function m(){await i.run(()=>M.kb.reopenComment(t.id))&&await a()}return e.jsxs("li",{"data-testid":"kb-comment","data-status":t.status,className:"min-w-0 space-y-1 py-2",children:[e.jsxs("p",{className:"flex min-w-0 flex-wrap items-center gap-x-2 text-xs text-outline",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-on-surface",children:[e.jsx(ls,{status:t.status}),e.jsx("span",{"data-testid":"kb-comment-status",children:t.status})]}),e.jsxs("span",{className:"min-w-0 break-words",children:[t.source===t.author?t.author:`${t.author} via ${t.source}`," ·"," ",new Date(t.created_at).toLocaleString(),s&&t.document_id&&e.jsxs(e.Fragment,{children:[" · on ",n?e.jsx("button",{type:"button",className:"text-primary hover:underline",onClick:()=>t.document_id&&n(t.document_id),children:t.document_title??"a deleted document"}):t.document_title??"a deleted document"]})]})]}),e.jsx("p",{className:"whitespace-pre-wrap break-words",children:t.body}),t.reply&&e.jsxs("p",{className:"break-words text-xs","data-testid":"kb-comment-reply-text",children:[e.jsxs("span",{className:"text-outline",children:[t.status==="dismissed"?"Dismissed":"Resolved",t.resolved_by?` by ${t.resolved_by}`:"",":"]})," ",t.reply]}),l?e.jsxs("form",{onSubmit:p,className:"flex flex-wrap items-center gap-2",children:[e.jsx(B,{"aria-label":l==="resolved"?"Resolution reply":"Reason for dismissing",placeholder:l==="resolved"?"What changed":"Why not","data-testid":"kb-comment-reply",value:o,onChange:x=>d(x.target.value),maxLength:4e3,autoFocus:!0,className:"min-w-0 flex-1 basis-48"}),e.jsx(g,{type:"submit",size:"sm","data-testid":"kb-comment-close-submit",disabled:!o.trim()||i.pending,children:l==="resolved"?"Resolve":"Dismiss"}),e.jsx(g,{type:"button",size:"sm",variant:"ghost",onClick:()=>{r(null),d(""),i.setError(null)},children:"Cancel"})]}):t.status==="open"?e.jsxs("div",{className:"-ml-2 flex flex-wrap",children:[e.jsx(g,{size:"sm",variant:"ghost","data-testid":"kb-comment-resolve",onClick:()=>r("resolved"),children:"Resolve"}),e.jsx(g,{size:"sm",variant:"ghost","data-testid":"kb-comment-dismiss",onClick:()=>r("dismissed"),children:"Dismiss"})]}):e.jsx(g,{size:"sm",variant:"ghost",className:"-ml-2","data-testid":"kb-comment-reopen",onClick:m,disabled:i.pending,children:"Reopen"}),i.error&&e.jsx("p",{role:"alert",className:"text-xs text-error","data-testid":"kb-comment-error",children:i.error})]})}const Oe=t=>`kb:${t}`,ds={pending:"Processing",partial:"Partially parsed",failed:"Failed",lexical_ready:"Keyword search ready",semantic_pending:"Embedding",semantic_ready:"Semantic search ready"};function dn(t){var i;const s=[...t.currentTarget.querySelectorAll('[role="menuitem"]:not(:disabled)')],n=s.indexOf(document.activeElement),a=t.key==="ArrowDown"?(n+1)%s.length:t.key==="ArrowUp"?(n-1+s.length)%s.length:t.key==="Home"?0:t.key==="End"?s.length-1:null;a===null||!s.length||(t.preventDefault(),(i=s[a])==null||i.focus())}function cn({usage:t,testId:s}){return e.jsxs("div",{"data-testid":s,className:"space-y-2",children:[e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{"data-testid":`${s}-reads`,className:"font-medium",children:t.reads})," ","reads · ",t.exposures," search appearances · ",t.distinct_sessions," sessions"]}),e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-outline",children:[e.jsx("th",{className:"py-1 text-left font-normal",children:"Source"}),lt.map(n=>e.jsx("th",{className:"py-1 text-right font-normal",children:n==="search_hit"?"listed":n},n))]})}),e.jsx("tbody",{children:se.map(n=>e.jsxs("tr",{"data-testid":`${s}-${n}`,className:"border-t border-outline-variant/50",children:[e.jsx("td",{className:"py-1 uppercase",children:n}),lt.map(a=>e.jsx("td",{className:"py-1 text-right tabular-nums",children:t.totals[n][a]},a))]},n))})]}),e.jsxs("div",{className:"text-xs text-outline",children:["Last 7 days ",t.window.days_7," · last 30 days ",t.window.days_30]})]})}function mn({kb:t,doc:s,onHome:n,onOpen:a,onDeleted:i,onReplaceFile:l,detailsOpen:r,onDetailsOpenChange:o}){var we;const d=V(),[p]=Pt(),m=p.get("editorMode"),x=((we=Ut(s.kb_id,{document_id:s.id}).data)==null?void 0:we.counts.open)??0,[k,j]=u.useState(!1),[C,w]=u.useState(!1),[f,$]=u.useState(!1),b=zt("lg"),[c,S]=u.useState(null),P=u.useRef(null),[T,K]=u.useState(null),[q,z]=u.useState(!1),y=u.useRef(null),v=u.useRef(s.revision),h=new Map(s.links.filter(D=>D.document_id).map(D=>[ea(D.target),D.document_id])),E={slugs:[...h.keys()],select:D=>{const R=h.get(D);R&&a(R)}};async function F(D){z(!0),K(null);try{return await D(),await d(),!0}catch(R){return K(R instanceof Error?R.message:"Request failed"),!1}finally{z(!1)}}async function G(){await F(async()=>nt(await M.kb.original(s.id),s.original_name??s.path.split("/").pop()??"document"))}function I(){const D=(s.path.split("/").pop()??"document").replace(/\.(md|markdown)$/i,"");nt(new Blob([s.content],{type:"text/markdown;charset=utf-8"}),`${D}.md`)}const Q=s.origin==="upload",je=Q||s.origin==="external"&&!s.editable,X=(c==null?void 0:c.backlinks.filter(D=>!s.backlinks.some(R=>R.document_id===D.document_id)))??[],Z=(D,R,ee,_e,Se=!1)=>e.jsxs("button",{type:"button",role:"menuitem","data-testid":D,disabled:q,className:U("flex min-h-9 w-full items-center gap-2 rounded px-2 text-left text-sm outline-none hover:bg-surface-highest focus-visible:bg-surface-highest disabled:opacity-50",Se&&"text-error"),onClick:()=>{$(!1),_e()},children:[R,ee]});return e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col overflow-y-auto lg:flex-row lg:overflow-hidden",children:[e.jsx("article",{"data-testid":"kb-document",className:"min-w-0 lg:min-h-0 lg:flex-1 lg:overflow-y-auto",children:e.jsxs("div",{className:"w-full min-w-0 px-4 pb-16 pt-4 sm:px-8 sm:pt-6",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsxs("nav",{"aria-label":"Breadcrumb",className:"flex min-w-0 flex-1 basis-48 items-center gap-1 text-sm text-outline",children:[e.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:t.name}),e.jsx(Ee,{size:14,className:"shrink-0","aria-hidden":!0}),e.jsx("span",{className:"min-w-0 truncate font-mono text-xs","data-testid":"kb-document-path",title:s.path,children:s.path})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsxs(g,{size:"sm",variant:r?"secondary":"ghost","aria-pressed":r,"data-testid":"kb-details-toggle",onClick:()=>o(!r),children:[e.jsx(Ca,{size:14}),"Details",x>0&&e.jsxs("span",{"data-testid":"kb-details-open-comments",title:`${x} open ${x===1?"comment":"comments"}`,className:"inline-flex items-center gap-1 text-xs tabular-nums text-outline",children:[e.jsx(ae,{tone:"warning"}),x]})]}),e.jsxs(ys,{open:f,onOpenChange:$,children:[e.jsx(vs,{asChild:!0,children:e.jsx(g,{size:"icon",variant:"ghost","aria-label":"Document actions","aria-haspopup":"menu","data-testid":"kb-doc-menu",children:e.jsx(ta,{size:16})})}),e.jsx(ks,{children:e.jsxs(Ns,{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:D=>{var R;D.preventDefault(),(R=D.currentTarget.querySelector('[role="menuitem"]:not(:disabled)'))==null||R.focus()},onKeyDown:dn,children:[Z("kb-doc-properties",e.jsx(qt,{size:14}),"Title and labels",()=>{P.current={title:s.title,backlinks:s.backlinks},j(!0)}),!je&&Z("kb-doc-download-markdown",e.jsx(ya,{size:14}),"Download Markdown",I),je&&Z("kb-doc-download",e.jsx(aa,{size:14}),"Download original",()=>void G()),Q&&Z("kb-doc-reparse",e.jsx(na,{size:14}),"Parse again",()=>void F(()=>M.kb.reparse(s.id))),Q&&Z("kb-doc-replace",e.jsx(wa,{size:14}),"Replace file",()=>{var D;return(D=y.current)==null?void 0:D.click()}),s.origin!=="external"&&Z("kb-doc-delete",e.jsx(Re,{size:14}),"Delete document",()=>w(!0),!0)]})})]})]})]}),e.jsxs("header",{className:"mb-2 mt-4 space-y-2",children:[e.jsx("h1",{"data-testid":"kb-document-title",className:"break-words text-3xl font-medium",children:s.title}),s.description&&e.jsx("p",{className:"text-outline",children:s.description}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5 text-xs text-outline",children:[s.labels.length>0&&e.jsx("span",{className:"flex flex-wrap gap-1",children:s.labels.map(D=>e.jsx(rs,{variant:"secondary","data-testid":"kb-document-label",children:D},D))}),s.parse_state!=="ok"&&e.jsxs("span",{className:U("inline-flex items-center gap-1.5",s.parse_state==="failed"&&"text-error"),children:[e.jsx(ae,{tone:s.parse_state==="failed"?"error":s.parse_state==="partial"?"warning":"progress"}),e.jsx("span",{"data-testid":"kb-parse-state",children:ds[s.parse_state]})]}),s.folder_sync&&e.jsx("span",{"data-testid":"kb-folder-sync",title:s.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:s.folder_sync==="following"?"Follows folder file":"Edited, no longer synced"}),s.stale&&e.jsx("span",{className:"text-warning","data-testid":"kb-document-stale",children:"Stale: a source changed"}),e.jsxs("span",{children:["Updated ",new Date(s.updated_at).toLocaleDateString()," by ",s.updated_by]})]})]}),s.warnings.length>0&&e.jsx("ul",{"data-testid":"kb-document-warnings",className:"mb-2 space-y-1 text-sm text-warning",children:s.warnings.map(D=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx(st,{size:14,className:"mt-0.5 shrink-0"}),D]},D))}),Q&&e.jsxs("p",{className:"mb-2 text-sm text-outline",children:["Text parsed from ",s.original_name??"the upload"," (",We(s.size_bytes),s.parser?`, ${s.parser.id} ${s.parser.version}`:"","). Replace the file to change it."]}),s.folder_sync==="following"&&(m==="edit"||m==="split")&&e.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."}),T&&e.jsx("p",{role:"alert","data-testid":"kb-document-error",className:"mb-2 text-sm text-error",children:T}),c&&X.length>0&&e.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:[e.jsx(st,{size:14,className:"shrink-0","aria-hidden":!0}),e.jsxs("span",{className:"min-w-0 flex-1",children:[X.length===1?"1 document":`${X.length} documents`," linked to “",c.title,"” by its old title or path; those links now show as missing:"," ",X.map((D,R)=>e.jsxs("span",{children:[R>0&&", ",e.jsx("button",{type:"button",className:"underline underline-offset-2 hover:text-on-surface",onClick:()=>a(D.document_id),children:D.title})]},D.document_id))]}),e.jsx(g,{size:"sm",variant:"ghost",onClick:()=>S(null),children:"Dismiss"})]}),e.jsx(Is,{documentId:Oe(s.id),path:s.editable?s.path:`${s.path}.md`,content:s.content,wikiLinks:E,testId:"kb-document-content",layout:"page",pageTitle:s.title,hideFrontmatter:!0,onSave:s.editable?async(D,R)=>{try{const ee=await M.kb.updateDocument(s.id,{expected_revision:R===s.content?s.revision:v.current,content:D});return v.current=ee.revision,D}finally{await d()}}:void 0},Oe(s.id))]})}),r&&b&&e.jsx(xt,{doc:s,onOpen:a}),!b&&e.jsx(Rt,{open:r,onOpenChange:o,children:e.jsxs(Lt,{className:"w-[360px]","aria-describedby":void 0,children:[e.jsx(Mt,{className:"py-3",children:e.jsx(Tt,{children:"Details"})}),e.jsx(At,{className:"p-0 sm:p-0",children:e.jsx(xt,{doc:s,onOpen:(D,R)=>{o(!1),a(D,R)}})})]})}),e.jsx("input",{ref:y,type:"file",hidden:!0,"data-testid":"kb-doc-replace-input",onChange:D=>{var ee;const R=(ee=D.target.files)==null?void 0:ee[0];R&&l(R),D.target.value=""}}),k&&e.jsx(Xa,{doc:s,linkedFrom:s.backlinks.length,onClose:()=>j(!1),onSaved:()=>{j(!1),S(P.current)}}),e.jsx(Pe,{open:C,title:"Delete document",description:`Delete "${s.title}" and its revision history${Q?" and uploaded file":""}?`,isPending:q,onCancel:()=>w(!1),onConfirm:async()=>{w(!1),await F(()=>M.kb.removeDocument(s.id))&&i()}})]})}function Ie({title:t,children:s}){return e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("h2",{className:"text-sm font-medium text-outline",children:t}),s]})}function xt({doc:t,onOpen:s}){var l;const n=Ws(t.id),a=Vs(t.id),i="block min-h-8 w-full break-words text-left text-primary hover:underline";return e.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:[t.outline.length>0&&e.jsx(Ie,{title:"On this page",children:e.jsx("nav",{"aria-label":"Outline",className:"space-y-0.5",children:t.outline.map(r=>e.jsx("button",{type:"button",className:"block min-h-7 w-full truncate text-left text-outline hover:text-on-surface",style:{paddingLeft:`${(r.level-1)*.75}rem`},onClick:()=>s(t.id,r.text),children:r.text},`${r.block}-${r.text}`))})}),t.links.length>0&&e.jsx(Ie,{title:`Links to (${t.links.length})`,children:t.links.map(r=>r.document_id?e.jsx("button",{type:"button","data-testid":"kb-outgoing-link",className:i,onClick:()=>s(r.document_id),children:r.title??r.target},r.target):e.jsxs("p",{className:"py-1 text-outline","data-testid":"kb-unresolved-link",children:[r.target," ",e.jsx("span",{className:"text-xs",children:"(no such document)"})]},r.target))}),t.backlinks.length>0&&e.jsx(Ie,{title:`Linked from (${t.backlinks.length})`,children:t.backlinks.map(r=>e.jsx("button",{type:"button","data-testid":"kb-backlink",className:i,onClick:()=>s(r.document_id),children:r.title},r.document_id))}),e.jsx("div",{className:"border-y border-outline-variant",children:e.jsx(os,{kbId:t.kb_id,documentId:t.id,heading:"h2",compact:!0})}),e.jsxs("details",{"data-testid":"kb-doc-history",className:"group",children:[e.jsxs("summary",{className:"flex min-h-9 cursor-pointer list-none items-center gap-1.5 font-medium [&::-webkit-details-marker]:hidden",children:[e.jsx(Ee,{size:14,"aria-hidden":!0,className:"text-outline transition-transform group-open:rotate-90"}),"Usage and history"]}),e.jsxs("div",{className:"mt-3 space-y-5 pl-5",children:[n.data?e.jsx(cn,{usage:n.data,testId:"kb-doc-usage"}):e.jsx("p",{className:"text-outline",children:n.error?"Usage unavailable":"Loading…"}),e.jsx("ol",{className:"space-y-2","data-testid":"kb-revisions",children:(l=a.data)==null?void 0:l.map(r=>e.jsxs("li",{"data-testid":"kb-revision",children:[e.jsxs("div",{children:["Revision ",r.revision," · ",r.actor,e.jsxs("span",{className:"text-outline",children:[" via ",r.source]})]}),e.jsxs("div",{className:"text-xs text-outline",children:[new Date(r.created_at).toLocaleString(),r.note?` · ${r.note}`:""]})]},r.revision))}),e.jsxs("dl",{className:"grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 text-xs text-outline",children:[e.jsx("dt",{children:"Search"}),e.jsx("dd",{"data-testid":"kb-index-state",children:ds[t.index_state]??t.index_state}),e.jsx("dt",{children:"Origin"}),e.jsx("dd",{children:t.origin}),e.jsx("dt",{children:"Type"}),e.jsx("dd",{children:t.media_type}),e.jsx("dt",{children:"Size"}),e.jsx("dd",{children:We(t.size_bytes)}),e.jsx("dt",{children:"Updated"}),e.jsxs("dd",{children:[new Date(t.updated_at).toLocaleString()," by ",t.updated_by]}),e.jsx("dt",{children:"ID"}),e.jsx("dd",{className:"break-all font-mono",children:t.id})]})]})]})]})}function ht(t){return`${t.added} added · ${t.updated} updated · ${t.missing} missing${t.errors.length?` · ${t.errors.length} errors: ${t.errors.slice(0,3).join("; ")}`:""}`}const He=(t,s,n)=>`${t} ${t===1?s:n}`;function un(){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 xn(t){const s=t.document_count-t.edited_count,n=s?`${He(s,"synced copy is","synced copies are")} removed from this knowledge base`:"No synced copies are removed",a=t.edited_count?`; ${He(t.edited_count,"edited copy is","edited copies are")} kept as documents`:"";return`Stop syncing ${t.root_path}? ${n}${a}. Files on disk are not touched.`}function pt(t){return t.replace(/[\\/]+$/,"").split(/[\\/]/).pop()||t}function hn({kb:t}){var z,y;const s=Gs(t.id),n=V(),a=Y(),[i,l]=u.useState(!1),[r,o]=u.useState(""),[d,p]=u.useState("**/*.md"),[m,x]=u.useState(null),[k,j]=u.useState(null),[C,w]=u.useState(!1),[f,$]=u.useState(!1),b=s.data??[],c=b.filter(v=>v.last_error).length,S=b.reduce((v,h)=>v+h.document_count,0);function P(){l(!0),w(!0)}function T(){w(!1),o(""),a.setError(null),b.length===0&&l(!1)}async function K(){$(!0),a.setError(null);try{const{path:v}=await M.terminals.pickFolder(r.trim()||void 0);v&&o(v)}catch(v){a.setError(v instanceof Error?v.message:String(v))}finally{$(!1)}}async function q(v){v.preventDefault();const h=await a.run(()=>M.kb.addSource(t.id,{root_path:r.trim(),pattern:d.trim()||"**/*.md"}));h&&(o(""),w(!1),x(ht(h.scan)),await n())}return e.jsxs(Ne,{title:"Synced folders",testId:"kb-folders",toggleTestId:"kb-sources",expanded:i,onExpandedChange:v=>{l(v),w(v&&b.length===0)},summary:s.isLoading?e.jsx("span",{className:"text-outline",children:"Loading…"}):b.length===0?e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-outline","data-testid":"kb-folders-none",children:[e.jsx(ae,{tone:"off"}),"None"]}):e.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1.5","data-testid":"kb-folders-summary",children:[e.jsx(ae,{tone:c?"error":"ok"}),b.length===1?e.jsx("span",{className:"min-w-0 truncate",title:(z=b[0])==null?void 0:z.root_path,children:pt(((y=b[0])==null?void 0:y.root_path)??"")}):`${b.length} folders`,e.jsxs("span",{className:"shrink-0 text-outline",children:["· ",S," ",S===1?"document":"documents",c?` · ${c} failing`:""]})]}),actions:b.length===0&&!i?e.jsx(g,{size:"sm",variant:"outline","data-testid":"kb-folders-add",onClick:P,children:"Add folder"}):null,children:[e.jsxs("div",{className:"min-w-0 space-y-3",children:[e.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."}),b.length>0&&e.jsx("ul",{className:"divide-y divide-outline-variant","data-testid":"kb-sources-list",children:b.map(v=>e.jsxs("li",{"data-testid":"kb-source-row",className:"flex min-w-0 flex-wrap items-center gap-2 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1 basis-56",children:[e.jsx("div",{className:"font-medium",children:pt(v.root_path)}),e.jsx("div",{className:"break-all font-mono text-xs text-outline",children:v.root_path}),e.jsxs("div",{className:"text-xs text-outline",children:[v.pattern," · ",He(v.document_count,"document","documents"),v.edited_count?` (${v.edited_count} edited)`:""," ·"," ",v.last_scan_at?e.jsxs("span",{title:new Date(v.last_scan_at).toLocaleString(),children:["scanned ",Qe(v.last_scan_at)]}):"not scanned yet"]}),v.last_error&&e.jsx("div",{className:"text-xs text-error",children:v.last_error})]}),e.jsxs(g,{variant:"ghost",size:"sm","data-testid":"kb-source-scan",disabled:a.pending,onClick:async()=>{const h=await a.run(()=>M.kb.scanSource(v.id));h&&x(ht(h)),await n()},children:[e.jsx(Wt,{size:14}),"Scan now"]}),e.jsx(g,{variant:"ghost",size:"sm",title:`Stop syncing ${v.root_path}`,"data-testid":"kb-source-remove",onClick:()=>j(v),children:"Stop syncing"})]},v.id))}),m&&e.jsx("p",{role:"status","data-testid":"kb-source-result",className:"text-outline",children:m}),C?e.jsxs("form",{onSubmit:q,className:"min-w-0 space-y-3","data-testid":"kb-source-form",children:[e.jsxs("div",{className:"grid min-w-0 gap-3 sm:grid-cols-[minmax(0,1fr)_12rem]",children:[e.jsx(L,{label:"Folder path",hint:un(),children:e.jsxs("div",{className:"flex min-w-0 gap-2",children:[e.jsx(B,{"aria-label":"Folder path","data-testid":"kb-source-path-input",value:r,onChange:v=>o(v.target.value),className:"min-w-0 font-mono text-sm",autoFocus:!0}),e.jsxs(g,{type:"button",variant:"outline","data-testid":"kb-source-choose-folder",onClick:K,disabled:f,className:"shrink-0",children:[e.jsx(sa,{size:14}),f?"Choosing…":"Choose folder"]})]})}),e.jsx(L,{label:"File pattern",hint:"e.g. *.md, **/*.md",children:e.jsx(B,{"aria-label":"File pattern","data-testid":"kb-source-pattern-input",value:d,onChange:v=>p(v.target.value),className:"font-mono text-sm"})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(g,{type:"submit",size:"sm",variant:"outline","data-testid":"kb-source-add",disabled:!r.trim()||a.pending,children:"Add folder"}),e.jsx(g,{type:"button",size:"sm",variant:"ghost","data-testid":"kb-source-cancel",onClick:T,children:"Cancel"})]})]}):b.length>0&&e.jsxs(g,{size:"sm",variant:"ghost",className:"-ml-2","data-testid":"kb-folders-add-another",onClick:()=>w(!0),children:[e.jsx($e,{size:14}),"Add another folder"]}),e.jsx(oe,{error:a.error})]}),e.jsx(Pe,{open:k!==null,title:"Stop syncing folder",description:k?xn(k):"",confirmLabel:"Stop syncing",variant:"warning",isPending:a.pending,onCancel:()=>j(null),onConfirm:async()=>{const v=k;j(null),v&&await a.run(()=>M.kb.removeSource(v.id)),await n()}})]})}const ft=8;function pn(t,s,n){return n==="title"?t.title.localeCompare(s.title):n==="updated"?t.updated_at-s.updated_at:t.reads-s.reads}function Ke(t,s){if(t.key===s)return t.desc?"descending":"ascending"}function fn(t){const s=new Date(t);return s.toDateString()===new Date().toDateString()?s.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):s.toLocaleDateString([],{month:"short",day:"numeric",year:"numeric"})}function bn({kb:t,owner:s,listing:n,label:a,onLabel:i,onOpen:l,onNewDocument:r,onSettings:o}){const d=t.editable_by.includes("mcp");return e.jsxs("div",{"data-testid":"kb-overview",className:"w-full min-w-0 space-y-8 p-4 sm:p-8",children:[e.jsxs("header",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"break-words text-2xl font-medium","data-testid":"kb-overview-name",children:t.name}),t.description&&e.jsx("p",{className:"max-w-prose text-outline",children:t.description}),e.jsxs("p",{className:"text-sm text-outline","data-testid":"kb-overview-meta",children:[s," · ",t.document_count," ",t.document_count===1?"document":"documents"," ·"," ",d?"agents can edit":"agents read only"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(g,{size:"sm","data-testid":"kb-new-document",onClick:r,children:[e.jsx(ka,{size:16}),"New document"]}),e.jsxs(g,{size:"sm",variant:"ghost","data-testid":"kb-settings",onClick:o,children:[e.jsx(ws,{size:16}),"Settings"]})]})]}),e.jsxs("section",{"aria-labelledby":"kb-setup-heading",className:"space-y-1",children:[e.jsx("h3",{id:"kb-setup-heading",className:"text-sm font-medium text-outline",children:"Setup"}),e.jsxs("div",{className:"divide-y divide-outline-variant border-y border-outline-variant",children:[e.jsx(Ua,{kb:t}),e.jsx(hn,{kb:t}),e.jsx(gn,{kb:t,onSettings:o}),e.jsx(jn,{kb:t,onSettings:o}),e.jsx(os,{kbId:t.id,onOpenDocument:l})]})]}),e.jsx(vn,{kbId:t.id,onOpen:l}),e.jsx(yn,{listing:n,total:t.document_count,label:a,onLabel:i,onOpen:l,onNewDocument:r})]})}function gn({kb:t,onSettings:s}){const n=t.editable_by.includes("mcp");return e.jsx(Ne,{title:"Who can edit",testId:"kb-access",summary:e.jsxs("span",{className:"inline-flex min-w-0 flex-wrap items-center gap-x-1.5",children:[e.jsx(ae,{tone:n?"ok":"off"}),n?"Agents can edit":"Agents read only",e.jsxs("span",{className:"text-outline",children:["·"," ",t.editable_by.length?t.editable_by.map(a=>ss[a]).join(", "):"nobody, read only everywhere"]})]}),actions:e.jsx(g,{size:"sm",variant:"ghost","data-testid":"kb-access-change",onClick:s,children:"Change"})})}function jn({kb:t,onSettings:s}){var i,l;const n=Bt(),a=t.parser?((l=(i=n.data)==null?void 0:i.parsers.find(r=>r.id===t.parser))==null?void 0:l.label)??t.parser:"Workspace default parser";return e.jsx(Ne,{title:"Uploads",testId:"kb-uploads-setup",summary:e.jsxs("span",{className:"text-outline","data-testid":"kb-uploads-parser",children:[a," · ","PDF, Word, PowerPoint, Excel, HTML, Markdown and text become Markdown"]}),actions:e.jsx(g,{size:"sm",variant:"ghost","data-testid":"kb-parser-change",onClick:s,children:"Change"})})}function yn({listing:t,total:s,label:n,onLabel:a,onOpen:i,onNewDocument:l}){const[r,o]=u.useState(""),[d,p]=u.useState(!1),[m,x]=u.useState({key:"updated",desc:!0}),k=r.trim().toLowerCase(),j=((t==null?void 0:t.documents)??[]).filter(c=>(!n||c.labels.includes(n))&&(!k||c.title.toLowerCase().includes(k)||c.path.toLowerCase().includes(k)||c.labels.some(S=>S.toLowerCase().includes(k)))).sort((c,S)=>pn(c,S,m.key)*(m.desc?-1:1));function C(c){x(S=>S.key===c?{key:c,desc:!S.desc}:{key:c,desc:c!=="title"})}function w(c,S){const P=m.desc?_s:Ss;return e.jsxs("button",{type:"button","data-testid":`kb-sort-${c}`,className:"inline-flex min-h-8 items-center gap-1 hover:text-on-surface",onClick:()=>C(c),children:[S,m.key===c&&e.jsx(P,{size:12,"aria-hidden":!0})]})}const f=[...(t==null?void 0:t.labels)??[]].sort((c,S)=>S.count-c.count),$=d?f:f.filter((c,S)=>S<ft||c.label===n),b=f.length-$.length;return e.jsxs("section",{"aria-labelledby":"kb-documents-heading","data-testid":"kb-documents",className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("h3",{id:"kb-documents-heading",className:"mr-auto text-sm font-medium text-outline",children:["Documents",n?` labelled ${n}`:""]}),s>0&&e.jsx(B,{"aria-label":"Filter documents","data-testid":"kb-documents-filter",placeholder:"Filter by title, path or label",value:r,onChange:c=>o(c.target.value),className:"h-9 w-full sm:w-64"})]}),$.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5","data-testid":"kb-labels",children:[e.jsx("span",{className:"mr-1 text-xs text-outline",children:"Label"}),$.map(c=>e.jsxs("button",{type:"button","data-testid":"kb-label-filter","aria-pressed":n===c.label,className:U("min-h-8 rounded-full border px-2.5 text-xs",n===c.label?"border-primary bg-primary/10 text-primary":"border-outline-variant text-outline hover:text-on-surface"),onClick:()=>a(n===c.label?null:c.label),children:[c.label," ",e.jsx("span",{className:"tabular-nums",children:c.count})]},c.label)),(b>0||d)&&f.length>ft&&e.jsx("button",{type:"button","data-testid":"kb-labels-more",className:"min-h-8 px-2 text-xs text-primary hover:underline",onClick:()=>p(!d),children:d?"Fewer labels":`${b} more`})]}),s===0?e.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:[e.jsx(Ht,{size:22,className:"text-primary","aria-hidden":!0}),e.jsx("span",{children:"This knowledge base is empty. Drop PDF, Word, PowerPoint, Excel, HTML, Markdown or text files here, or"}),e.jsx(g,{size:"sm",variant:"outline",onClick:l,"data-testid":"kb-overview-new-document",children:"add a document"})]}):e.jsxs(e.Fragment,{children:[j.length===0&&t&&e.jsxs("p",{className:"py-4 text-sm text-outline","data-testid":"kb-documents-empty",children:["No documents match."," ",e.jsx("button",{type:"button","data-testid":"kb-documents-clear",className:"text-primary hover:underline",onClick:()=>{o(""),a(null)},children:"Clear filters"})]}),j.length>0&&e.jsxs("table",{className:"w-full table-fixed text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-outline-variant text-left text-xs text-outline",children:[e.jsx("th",{className:"py-1 pr-3 font-normal","aria-sort":Ke(m,"title"),children:w("title","Title")}),e.jsx("th",{className:"hidden w-[30%] py-2 pr-3 font-normal md:table-cell",children:"Labels"}),e.jsx("th",{className:"w-24 py-1 pr-3 font-normal sm:w-28","aria-sort":Ke(m,"updated"),children:w("updated","Updated")}),e.jsx("th",{className:"hidden w-16 py-1 text-right font-normal sm:table-cell","aria-sort":Ke(m,"reads"),children:w("reads","Reads")})]})}),e.jsx("tbody",{children:j.map(c=>e.jsxs("tr",{className:"cursor-pointer border-b border-outline-variant/60 align-top hover:bg-surface-high",onClick:()=>i(c.id),children:[e.jsxs("td",{className:"min-w-0 py-2 pr-3",children:[e.jsxs("button",{type:"button","data-testid":"kb-document-row","data-document-title":c.title,className:"flex w-full min-w-0 items-center gap-1.5 text-left font-medium hover:text-primary",onClick:S=>{S.stopPropagation(),i(c.id)},children:[e.jsx("span",{className:"min-w-0 truncate",children:c.title}),c.origin==="external"&&e.jsx(Wt,{size:13,className:"shrink-0 text-outline","aria-label":"From a synced folder"})]}),e.jsx("span",{className:"block truncate font-mono text-xs text-outline",children:c.path}),(c.parse_state==="pending"||c.parse_state==="failed")&&e.jsx("span",{className:U("text-xs",c.parse_state==="failed"?"text-error":"text-outline"),children:c.parse_state==="failed"?"Parsing failed":"Parsing…"})]}),e.jsx("td",{className:"hidden py-2 pr-3 text-xs text-outline md:table-cell",children:e.jsx("span",{className:"line-clamp-2",children:c.labels.join(", ")})}),e.jsx("td",{className:"py-2 pr-3 text-xs text-outline tabular-nums",children:fn(c.updated_at)}),e.jsx("td",{className:"hidden py-2 text-right text-xs text-outline tabular-nums sm:table-cell",children:c.reads||""})]},c.id))})]}),e.jsx("p",{className:"text-xs text-outline",children:"Drop files anywhere on this page to upload."})]})]})}function vn({kbId:t,onOpen:s}){const n=Ys(t).data;return!n||!(n.stale.length||n.failed.length||n.unresolved_links.length)?null:e.jsxs("section",{"data-testid":"kb-maintenance",className:"space-y-1 text-sm",children:[e.jsx("h3",{className:"text-sm font-medium text-outline",children:"Needs attention"}),e.jsxs("ul",{className:"space-y-1",children:[n.failed.map(a=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"text-left text-error hover:underline",onClick:()=>s(a.id),children:["Parsing failed: ",a.title]})},a.id)),n.stale.map(a=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"text-left text-warning hover:underline",onClick:()=>s(a.id),children:["Stale summary: ",a.title]})},a.id)),n.unresolved_links.map(a=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"text-left text-outline hover:underline",onClick:()=>s(a.document_id),children:["[[",a.target,"]] in ",a.title," has no target"]})},`${a.document_id}-${a.target}`))]})]})}function kn(){const t=V(),[s,n]=u.useState([]),a=u.useRef(1),i=(o,d)=>n(p=>p.map(m=>m.id===o?{...m,...d}:m));async function l(o){i(o.id,{status:"uploading",progress:0,error:void 0});try{const d=await M.kb.upload(o.kbId,{file:o.file,...o.replace},p=>i(o.id,{progress:p}));i(o.id,{status:"done",progress:1,document:d}),await t()}catch(d){i(o.id,{status:"failed",error:d instanceof Error?d.message:"Upload failed"})}}function r(o,d,p={}){const m=d.map(x=>({id:a.current++,kbId:o,file:x,...p.replace?{replace:p.replace}:{},progress:0,status:"uploading"}));n(x=>[...x,...m]);for(const x of m)l(x)}return{uploads:s,add:r,retry:o=>{const d=s.find(p=>p.id===o);d&&l(d)},clearFinished:()=>n(o=>o.filter(d=>d.status==="uploading"))}}const bt="all",Nn=200,gt=[{value:"reads",label:"Most read"},{value:"recent",label:"Recent"},{value:"priority",label:"Priority"}];function Me(t){return new Date(t*1e3).toLocaleString()}function wn({projectId:t}){var v;const s=Cs(),n=Ft(),{memoryProject:a,memoryName:i}=Ds(),[l,r]=Te("project",t),[o,d]=Te("memoryQuery",""),[p,m]=Te("memorySort","reads",gt.map(h=>h.value)),[x,k]=u.useState(o);u.useEffect(()=>k(o),[o]);const[j,C]=u.useState(null),[w,f]=u.useState(null),{data:$}=ke({status:"active"}),b=ca(),c=l==="unassigned",S=l===bt,P=ma({project_id:S?void 0:l,q:o||void 0,sort:p,limit:Nn},{enabled:!c}),T=((v=P.data)==null?void 0:v.memories)??[],K=h=>{var E;return((E=$==null?void 0:$.find(F=>F.id===h))==null?void 0:E.name)??h},q=T.find(h=>h.project_id===a&&h.name===i),z=h=>s(`${$s(h.project_id,h.name)}${n.search}`),y=()=>s(`${Es}${n.search}`);return e.jsxs("div",{children:[e.jsx(da,{title:"Memories",meta:P.data?`${P.data.total} ${P.data.total===1?"memory":"memories"}`:void 0,action:e.jsxs(g,{"data-testid":"new-memory-button",size:"sm",onClick:()=>C("new"),className:"font-label text-sm",children:[e.jsx($e,{size:12,className:"mr-1"})," New memory"]})}),e.jsx("p",{className:"mb-4 text-sm leading-relaxed text-muted-foreground",children:"Short project facts agents load next session: ports, conventions, gotchas, decisions. Longer procedures belong in a skill."}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 mb-4",children:[e.jsxs(he,{value:l,onValueChange:h=>r(h),children:[e.jsx(pe,{"aria-label":"Project","data-testid":"memory-project-filter",className:"h-9 w-48 bg-background text-on-surface font-body text-sm",children:e.jsx(fe,{})}),e.jsxs(be,{className:"bg-surface border-outline-variant",children:[e.jsx(J,{value:bt,className:"font-body text-sm",children:"All projects"}),c&&e.jsx(J,{value:"unassigned",className:"font-body text-sm",children:"Unassigned"}),$==null?void 0:$.map(h=>e.jsx(J,{value:h.id,"data-testid":`memory-project-option-${h.id}`,className:"font-body text-sm",children:h.name},h.id))]})]}),e.jsx("div",{className:"flex shrink-0 flex-wrap gap-1.5",children:gt.map(h=>e.jsx("button",{type:"button",onClick:()=>m(h.value),"data-testid":`memory-sort-${h.value}`,"aria-pressed":p===h.value,className:`font-label text-sm px-3 py-1.5 border transition-colors ${p===h.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:h.label},h.value))}),e.jsxs("div",{className:"relative min-w-[160px] flex-1",children:[e.jsx(It,{size:12,className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground"}),e.jsx(B,{"aria-label":"Search memories","data-testid":"memory-search-input",value:x,onChange:h=>k(h.target.value),onKeyDown:h=>h.key==="Enter"&&d(h.currentTarget.value),placeholder:"Search memories...",className:"pl-8 bg-background text-on-surface font-body text-sm placeholder:text-muted-foreground"})]}),e.jsx(g,{variant:"outline",size:"sm",onClick:()=>d(x),className:"font-label text-sm",children:"Search"})]}),c?e.jsx(it,{message:"Memories belong to a project. Choose a project to see its memories."}):P.error?e.jsx(Ye,{message:P.error.message,onRetry:()=>void P.refetch()}):P.isLoading?e.jsx("div",{className:"space-y-2",children:[...Array(5)].map((h,E)=>e.jsx(Ge,{className:"h-10 w-full bg-surface-highest"},E))}):T.length===0?e.jsx(it,{message:o?"No memories match your search":"No memories yet"}):e.jsx("div",{className:"overflow-hidden",children:e.jsxs(ra,{children:[e.jsx(la,{children:e.jsxs(rt,{className:"border-b border-outline-variant hover:bg-transparent",children:[e.jsx(ce,{className:"font-label text-sm text-muted-foreground",children:"Name"}),e.jsx(ce,{className:"font-label text-sm text-muted-foreground",children:"Description"}),S&&e.jsx(ce,{className:"font-label text-sm text-muted-foreground",children:"Project"}),e.jsx(ce,{className:"font-label text-sm text-muted-foreground w-20",children:"Priority"}),e.jsx(ce,{className:"font-label text-sm text-muted-foreground w-16",children:"Reads"}),e.jsx(ce,{className:"font-label text-sm text-muted-foreground w-44",children:"Updated"})]})}),e.jsx(oa,{children:T.map(h=>e.jsxs(rt,{"data-testid":"memory-row","data-memory-name":h.name,"data-memory-project":h.project_id,className:"border-b border-outline-variant/50 hover:bg-surface-low cursor-pointer",onClick:()=>z(h),children:[e.jsx(me,{className:"font-body text-sm font-medium text-on-surface",children:e.jsx("button",{type:"button",className:"min-h-11 text-left hover:text-primary",onClick:E=>{E.stopPropagation(),z(h)},children:h.name})}),e.jsx(me,{className:"font-body text-sm text-muted-foreground max-w-md truncate",children:h.description}),S&&e.jsx(me,{className:"font-body text-sm text-muted-foreground",children:K(h.project_id)}),e.jsx(me,{children:e.jsx(ms,{priority:h.priority})}),e.jsx(me,{"data-testid":"memory-read-count",className:"font-label text-sm text-muted-foreground",title:cs(h),children:h.read_count}),e.jsx(me,{className:"font-label text-sm text-muted-foreground",children:Me(h.updated_at)})]},h.key))})]})}),a&&i&&e.jsx(_n,{projectId:a,name:i,projectName:K(a),listItem:q,onClose:y,onEdit:C,onDelete:f},`${a}/${i}`),j&&e.jsx(Cn,{memory:j==="new"?null:j,defaultProjectId:S||c?"":l,onClose:()=>C(null),onCreated:h=>z(h)}),w&&e.jsx(Pe,{open:!0,title:"Delete memory",description:`Delete "${w.name}"? It can be restored from its history.`,confirmLabel:"Delete",variant:"destructive",isPending:b.isPending,onConfirm:()=>b.mutate({projectId:w.project_id,name:w.name},{onSuccess:()=>{f(null),y()}}),onCancel:()=>f(null)}),b.error&&e.jsx("p",{role:"alert",className:"text-sm text-destructive mt-2",children:b.error.message})]})}function cs(t){const{mcp:s,cli:n,api:a,ui:i}=t.reads_by_source,l=t.last_read_at?` · last read ${Me(t.last_read_at)}`:"";return`mcp ${s} · cli ${n} · api ${a} · ui ${i}${l}`}function ms({priority:t}){return t===null?e.jsx("span",{"data-testid":"memory-priority",className:"font-label text-xs text-outline",children:"Unscored"}):e.jsxs("span",{"data-testid":"memory-priority",className:"font-label text-xs text-primary",children:["P",t]})}function _n({projectId:t,name:s,projectName:n,listItem:a,onClose:i,onEdit:l,onDelete:r}){const{data:o,isLoading:d,error:p,refetch:m}=ua(t,s);return e.jsx(Rt,{open:!0,onOpenChange:x=>!x&&i(),children:e.jsxs(Lt,{"data-testid":"memory-detail",className:"w-screen max-w-full sm:w-[860px] sm:max-w-[96vw]",children:[e.jsxs(Mt,{children:[e.jsx(Tt,{children:s}),o&&e.jsx("p",{"data-testid":"memory-detail-description",className:"font-body text-sm text-muted-foreground mt-1",children:o.description})]}),e.jsx(At,{children:p?e.jsx(Ye,{message:p.message,onRetry:()=>void m()}):d||!o?e.jsx("div",{className:"space-y-3",children:[...Array(4)].map((x,k)=>e.jsx(Ge,{className:"h-8 w-full bg-surface-highest"},k))}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(g,{"data-testid":"memory-edit",size:"sm",variant:"outline",onClick:()=>l(o),children:[e.jsx(qt,{size:12,className:"mr-1"})," Edit"]}),e.jsxs(g,{"data-testid":"memory-delete",size:"sm",variant:"outline",onClick:()=>r(o),children:[e.jsx(Re,{size:12,className:"mr-1"})," Delete"]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsx(de,{label:"Project",children:n}),e.jsx(de,{label:"Priority",children:e.jsx(ms,{priority:o.priority})}),e.jsx(de,{label:"Reads",children:a?e.jsx("span",{title:cs(a),children:a.read_count}):"—"}),e.jsx(de,{label:"Author",children:e.jsx("span",{"data-testid":"memory-detail-author",children:o.author})}),e.jsx(de,{label:"Session",children:e.jsx("code",{className:"font-mono text-xs break-all",children:o.session_id??"—"})}),e.jsx(de,{label:"Updated",children:Me(o.updated_at)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-sm text-muted-foreground mb-2",children:"Content"}),e.jsx("div",{"data-testid":"memory-detail-content",className:"whitespace-pre-wrap break-words font-body text-sm text-on-surface border border-outline-variant p-3",children:o.content})]}),e.jsx(Sn,{projectId:t,name:s,onDeleted:i})]})})]})})}function jt({label:t,snapshot:s}){return e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-outline mt-2",children:t}),s?e.jsxs("div",{className:"text-xs space-y-1",children:[e.jsxs("p",{children:[e.jsx("span",{className:"text-outline",children:"Priority:"})," ",s.priority===null?"unscored":s.priority]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-outline",children:"Description:"})," ",s.description]}),e.jsx("pre",{className:"whitespace-pre-wrap break-all",children:s.content})]}):e.jsx("p",{className:"text-xs italic text-muted-foreground",children:"(none)"})]})}function Sn({projectId:t,name:s,onDeleted:n}){var p;const a=fa(t,s),i=ba(),[l,r]=u.useState(""),o=((p=a.data)==null?void 0:p.changes)??[],d=o[0];return e.jsxs("section",{"data-testid":"memory-history-panel",className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:"History"}),a.error&&e.jsx("p",{role:"alert",children:a.error.message}),i.error&&e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:i.error.message}),o.length>1&&e.jsx(B,{"data-testid":"memory-revert-reason","aria-label":"Reason for reverting",value:l,onChange:m=>r(m.target.value),placeholder:"Reason for reverting..."}),o.map(m=>e.jsxs("details",{"data-testid":"memory-history-change",className:"border-b border-outline-variant p-3",children:[e.jsxs("summary",{className:"text-xs cursor-pointer",children:[m.action.replace("memory.","")," · ",Me(m.created_at)," ·"," ",m.author,m.session_id?` · ${m.session_id}`:"",m.reason?` · ${m.reason}`:""]}),e.jsx(jt,{label:"Before",snapshot:m.previous}),e.jsx(jt,{label:"After",snapshot:m.current}),d&&m.previous&&e.jsx(g,{"data-testid":"memory-revert-change",size:"sm",variant:"outline",className:"mt-2",disabled:!l.trim()||i.isPending,onClick:()=>i.mutate({name:s,project_id:t,change_id:m.id,expected_change_id:d.id,reason:l.trim()},{onSuccess:({memory:x})=>{r(""),x||n()}}),children:"Restore state before this change"})]},m.id))]})}function qe(t){return[...t].length}function yt({value:t,max:s,testId:n}){const a=qe(t);return e.jsx("span",{"data-testid":n,className:`text-xs ${s!==void 0&&a>s?"text-destructive":"text-muted-foreground"}`,children:s===void 0?a:`${a}/${s}`})}function Cn({memory:t,defaultProjectId:s,onClose:n,onCreated:a}){var z;const{data:i}=ke({status:"active"}),[l,r]=u.useState((t==null?void 0:t.project_id)??s),[o,d]=u.useState((t==null?void 0:t.name)??""),[p,m]=u.useState((t==null?void 0:t.description)??""),[x,k]=u.useState((t==null?void 0:t.content)??""),[j,C]=u.useState((t==null?void 0:t.priority)===null||(t==null?void 0:t.priority)===void 0?"":String(t.priority)),[w,f]=u.useState(""),$=xa(),b=ha(),c=(z=pa().data)==null?void 0:z.content_max,S=t?b:$,P=j.trim()===""?null:Number(j),T=P===null||Number.isInteger(P)&&P>=0&&P<=Ce,K=!!l&&!!o.trim()&&!!p.trim()&&qe(p)<=at&&!!x.trim()&&(c===void 0||qe(x)<=c)&&T;function q(){if(!K||S.isPending)return;if(!t){$.mutate({project_id:l,name:o.trim(),description:p.trim(),content:x.trim(),priority:P},{onSuccess:v=>{n(),a(v)}});return}const y={...p.trim()!==t.description&&{description:p.trim()},...x.trim()!==t.content&&{content:x.trim()},...P!==t.priority&&{priority:P}};if(Object.keys(y).length===0){n();return}b.mutate({name:t.name,project_id:t.project_id,...y,...w.trim()&&{reason:w.trim()}},{onSuccess:n})}return e.jsx(Ct,{open:!0,onOpenChange:y=>!y&&!S.isPending&&n(),children:e.jsxs(Dt,{"data-testid":"memory-form-dialog",className:"bg-surface border-outline-variant w-[calc(100%_-_1rem)] max-w-2xl max-h-[94dvh] overflow-y-auto",children:[e.jsx($t,{children:e.jsx(Et,{className:"font-headline text-base text-on-surface",children:t?`Edit ${t.name}`:"New memory"})}),e.jsxs("form",{onSubmit:y=>{y.preventDefault(),q()},className:"space-y-3 mt-2",children:[!t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(ie,{className:"font-label text-sm text-muted-foreground",children:"Project *"}),e.jsxs(he,{value:l,onValueChange:r,children:[e.jsx(pe,{"aria-label":"Memory project","data-testid":"memory-project-select",className:"bg-background text-on-surface font-body text-sm h-9",children:e.jsx(fe,{placeholder:"Choose a project"})}),e.jsx(be,{className:"bg-surface border-outline-variant",children:i==null?void 0:i.map(y=>e.jsx(J,{value:y.id,className:"font-body text-sm",children:y.name},y.id))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(ie,{className:"font-label text-sm text-muted-foreground",children:"Name *"}),e.jsx(B,{"aria-label":"Name","data-testid":"memory-name-input",value:o,onChange:y=>d(y.target.value),placeholder:"api-port",maxLength:64,className:"bg-background text-on-surface font-body text-sm",autoFocus:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Lowercase words joined by hyphens, unique in the project."})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ie,{className:"font-label text-sm text-muted-foreground",children:"Description *"}),e.jsx(yt,{value:p,max:at,testId:"memory-description-count"})]}),e.jsx(xe,{"aria-label":"Description","data-testid":"memory-description-input",value:p,onChange:y=>m(y.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})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ie,{className:"font-label text-sm text-muted-foreground",children:"Content *"}),e.jsx(yt,{value:x,max:c,testId:"memory-content-count"})]}),e.jsx(xe,{"aria-label":"Content","data-testid":"memory-content-input",value:x,onChange:y=>k(y.target.value),placeholder:"The fact itself. Longer guidance belongs in a skill.",className:"bg-background text-on-surface font-body text-sm",rows:6})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(ie,{className:"font-label text-sm text-muted-foreground",children:["Priority (0-",Ce,", empty = unscored)"]}),e.jsx(B,{"aria-label":"Priority","data-testid":"memory-priority-input",type:"number",min:0,max:Ce,step:1,value:j,onChange:y=>C(y.target.value),className:"w-32 bg-background text-on-surface font-body text-sm"}),!T&&e.jsxs("p",{className:"text-xs text-destructive",children:["Priority must be a whole number from 0 to ",Ce,"."]})]}),t&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(ie,{className:"font-label text-sm text-muted-foreground",children:"Reason"}),e.jsx(B,{"aria-label":"Reason","data-testid":"memory-reason-input",value:w,onChange:y=>f(y.target.value),placeholder:"Why this changed (optional)",className:"bg-background text-on-surface font-body text-sm"})]}),S.error&&e.jsx("p",{role:"alert","data-testid":"memory-form-error",className:"text-sm text-destructive",children:S.error.message}),e.jsxs(le,{children:[e.jsx(g,{type:"button",variant:"ghost",size:"sm",onClick:n,disabled:S.isPending,className:"font-label text-sm text-muted-foreground",children:"Cancel"}),e.jsx(g,{"data-testid":"memory-submit",type:"submit",size:"sm",disabled:!K||S.isPending,className:"font-label text-sm",children:S.isPending?"Saving...":t?"Save":"Create"})]})]})]})})}function ai({projectId:t}){const s=ia(t),{pathname:n}=Ft();return n.startsWith("/knowledge/memories")?e.jsx("div",{"data-testid":"knowledge-base-view",children:e.jsx(wn,{projectId:t,embedded:!0})}):e.jsx("div",{"data-testid":"knowledge-base-view",className:"flex min-h-0 min-w-0 flex-1",children:e.jsx($n,{projectId:s==="all"||s==="unassigned"?void 0:s},s)})}function us(t){return t.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 Dn({text:t}){const s=us(t).split(/«([^»]*)»/g);return e.jsx(e.Fragment,{children:s.map((n,a)=>a%2?e.jsx("mark",{className:"rounded-sm bg-primary/20 px-0.5 text-on-surface",children:n},a):e.jsx(u.Fragment,{children:n},a))})}function $n({projectId:t}){var Se,Je,Xe;const[s,n]=Pt(),a=s.get("kb"),i=s.get("document"),l=s.get("label")??"",r=s.get("q")??"",o=s.get("searchAll")==="1",[d,p]=u.useState(r);u.useEffect(()=>p(r),[r]);const[m,x]=u.useState(null),[k,j]=u.useState(!1),C=zt("lg"),[w,f]=u.useState(()=>typeof window<"u"&&window.innerWidth>=1600),[$,b]=u.useState(!1),[c,S]=u.useState(null),[P,T]=u.useState();function K(){x(null),T(void 0)}const q=ke(),z=Qs(t),y=((Se=z.data)==null?void 0:Se.find(N=>N.id===a))??null,v=ze((y==null?void 0:y.id)??null),h=Js(i),E=z.data!==void 0&&(y!==null||z.data.length===0),F=Xs(r&&E?{query:r,...y&&!o?{kb_ids:[y.id]}:{},scope:t?"default":"all",limit:20}:null,t),G=kn();function I(N,A=!1){n(()=>{const te=new URLSearchParams(window.location.search);for(const[ne,Ze]of Object.entries(N))Ze?te.set(ne,Ze):te.delete(ne);return te},{replace:A})}const Q=()=>!i||Ks(Oe(i));function je(N){j(!1),!(N===a&&!i&&!r||!Q())&&(N!==a&&G.clearFinished(),I({kb:N,document:null,label:null,q:null}))}function X(N,A){j(!1),!(N!==i&&!Q())&&(I({document:N,q:null}),S(A??null))}function Z(N,A){I({document:N}),S(A??null)}function we(){j(!1);const N=d.trim();if(!N)return I({q:null});Q()&&I({q:N,document:null})}u.useEffect(()=>{C&&j(!1)},[C]),u.useEffect(()=>{z.data&&(a&&!z.data.some(N=>N.id===a)&&!i?I({kb:null},!0):!a&&z.data[0]&&I({kb:z.data[0].id},!0))}),u.useEffect(()=>{var N;h.data&&h.data.kb_id!==a&&((N=z.data)!=null&&N.some(A=>A.id===h.data.kb_id))&&I({kb:h.data.kb_id,label:null},!0)}),u.useEffect(()=>{if(!c||!h.data)return;const N=document.querySelector('[data-testid="kb-document"]'),A=[...(N==null?void 0:N.querySelectorAll("h1,h2,h3,h4,h5,h6"))??[]].find(te=>{var ne;return((ne=te.textContent)==null?void 0:ne.trim())===c});A&&(A.scrollIntoView({block:"start"}),S(null))});function D(N){N.preventDefault(),b(!1);const A=[...N.dataTransfer.files];!y||A.length===0||(A.length>1?G.add(y.id,A):(T(A[0]),x("new-document")))}const R=N=>{var A,te;return N===null?"Global":((te=(A=q.data)==null?void 0:A.find(ne=>ne.id===N))==null?void 0:te.name)??"Project"};if(z.error)return e.jsx(Ye,{message:z.error.message,onRetry:()=>z.refetch()});const ee=i?h.data&&y?e.jsx(mn,{kb:y,doc:h.data,detailsOpen:w,onDetailsOpenChange:f,onHome:()=>je(y.id),onOpen:X,onDeleted:()=>I({document:null}),onReplaceFile:N=>h.data&&G.add(h.data.kb_id,[N],{replace:{document_id:h.data.id,expected_revision:h.data.revision}})},h.data.id):h.error?e.jsxs(Be,{children:[e.jsx("p",{role:"alert","data-testid":"kb-document-error",className:"text-sm text-error",children:h.error.message}),e.jsx(g,{variant:"outline",onClick:()=>I({document:null}),children:"Back"})]}):e.jsx(Be,{children:e.jsx("p",{role:"status",className:"text-sm text-outline",children:"Loading document…"})}):r?e.jsx(vt,{children:e.jsx(zn,{query:r,search:F,onOpen:Z,onClear:()=>I({q:null})})}):y?e.jsx(vt,{children:e.jsx(bn,{kb:y,owner:R(y.project_id),listing:v.data,label:l,onLabel:N=>I({label:N}),onOpen:X,onNewDocument:()=>x("new-document"),onSettings:()=>x("settings")})}):((Je=z.data)==null?void 0:Je.length)===0?e.jsxs(Be,{testId:"empty-state",children:[e.jsx(Kt,{size:28,className:"text-primary"}),e.jsx("h2",{className:"text-xl font-medium",children:"Build a knowledge base"}),e.jsx("p",{className:"max-w-md text-outline",children:"Upload documents, write Markdown or sync a folder. Agents search it with citations through MCP, the CLI and the API, and you can see what they read."}),e.jsxs(g,{"data-testid":"kb-empty-create",onClick:()=>x("create"),children:[e.jsx($e,{size:16}),"New knowledge base"]})]}):null,_e=e.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:[e.jsxs("form",{className:"flex shrink-0 items-center gap-1.5 border-b border-outline-variant p-3",onSubmit:N=>{N.preventDefault(),we()},children:[e.jsx(B,{"aria-label":"Search knowledge","data-testid":"kb-search-input",value:d,onChange:N=>p(N.target.value),placeholder:y&&!o?`Search ${y.name}`:"Search everything",className:"h-9 min-w-0 flex-1"}),e.jsx(g,{type:"submit",size:"icon",variant:"ghost","data-testid":"kb-search-submit","aria-label":"Search",children:e.jsx(It,{size:16})}),k&&e.jsx(g,{type:"button",size:"icon",variant:"ghost","data-testid":"kb-browser-close","aria-label":"Close knowledge browser",onClick:()=>j(!1),children:e.jsx(Ve,{size:16})})]}),y&&e.jsxs("label",{className:"flex shrink-0 items-center gap-2 border-b border-outline-variant px-3 py-2 text-xs text-outline",children:[e.jsx("input",{type:"checkbox","data-testid":"kb-search-all",checked:o,onChange:N=>I({searchAll:N.target.checked?"1":null})}),"Search all knowledge bases"]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:[e.jsxs("div",{className:"flex items-center justify-between px-2 pb-1",children:[e.jsx("h2",{className:"text-sm font-medium text-outline",children:"Knowledge bases"}),e.jsx(g,{size:"icon",variant:"ghost","aria-label":"New knowledge base","data-testid":"kb-create",onClick:()=>x("create"),children:e.jsx($e,{size:16})})]}),z.isLoading&&e.jsx(Ge,{className:"mx-2 h-9"}),e.jsx(En,{bases:z.data??[],projectName:R,kbId:a,documentId:i,documents:((Xe=v.data)==null?void 0:Xe.documents)??[],onSelectKb:je,onOpenDocument:X})]}),e.jsx(Pn,{})]});return e.jsx(Ps,{open:k&&!C,onOpenChange:j,children:e.jsxs("div",{"data-testid":"knowledge-bases",className:"relative flex min-h-0 min-w-0 flex-1",children:[e.jsx("h1",{"data-testid":"view-title",className:"sr-only",children:"Knowledge bases"}),C&&_e,!C&&e.jsxs(zs,{children:[e.jsx(Rs,{className:"fixed inset-0 z-50 bg-black/70"}),e.jsxs(Ls,{"data-testid":"kb-mobile-browser",className:"viewport-sheet fixed inset-x-0 z-50 bg-background",children:[e.jsx(Ms,{className:"sr-only",children:"Browse knowledge"}),e.jsx(Ts,{className:"sr-only",children:"Search knowledge bases and choose a document"}),_e]})]}),e.jsxs("div",{"data-testid":"kb-dropzone",className:U("relative flex min-h-0 min-w-0 flex-1 flex-col",$&&"outline-2 -outline-offset-4 outline-dashed outline-primary"),onDragOver:N=>{y&&(N.preventDefault(),b(!0))},onDragLeave:()=>b(!1),onDrop:D,children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-outline-variant px-3 py-2 lg:hidden",children:[e.jsx(As,{asChild:!0,children:e.jsxs(g,{"data-testid":"kb-browser-open",variant:"ghost",size:"sm","aria-expanded":k,"aria-controls":"kb-sidebar-panel",onClick:()=>j(!0),children:[e.jsx(Fs,{size:16}),"Browse"]})}),y&&e.jsx("span",{className:"min-w-0 truncate text-sm text-outline",children:y.name})]}),i&&r&&e.jsx("div",{className:"flex shrink-0 items-center border-b border-outline-variant px-3 py-1",children:e.jsxs(g,{variant:"ghost",size:"sm","data-testid":"kb-search-back",className:"min-w-0",onClick:()=>Q()&&I({document:null}),children:[e.jsx(ga,{size:14}),e.jsxs("span",{className:"truncate",children:["Back to results for “",r,"”"]})]})}),e.jsx("div",{className:"flex min-h-0 min-w-0 flex-1",children:ee}),e.jsx(Rn,{uploads:G,onOpen:X})]}),m==="create"&&e.jsx(Ga,{open:!0,projectId:t,onClose:()=>x(null),onCreated:N=>{x(null),j(!1),I({kb:N.id,document:null,label:null,q:null})}}),m==="settings"&&y&&e.jsx(Ya,{kb:y,onClose:()=>x(null),onDeleted:()=>{x(null),I({kb:null,document:null,label:null})}}),m==="new-document"&&y&&e.jsx(Ja,{kb:y,initialFile:P,onClose:K,onUploadMany:N=>{K(),G.add(y.id,N)},onCreated:(N,A)=>{K(),I({document:N.id,editorMode:A?null:"edit"})}})]})})}function En({bases:t,projectName:s,kbId:n,documentId:a,documents:i,onSelectKb:l,onOpenDocument:r}){const[o,d]=u.useState(null);u.useEffect(()=>{a&&d(null)},[a]);const p=new Map;for(const x of t){const k=s(x.project_id);p.set(k,[...p.get(k)??[],x])}const m=[...p.entries()].sort(([x],[k])=>x==="Global"?-1:k==="Global"?1:x.localeCompare(k));return e.jsx("div",{"data-testid":"kb-list",className:"space-y-3",children:m.map(([x,k])=>e.jsxs("section",{"aria-label":x,children:[m.length>1&&e.jsx("h3",{className:"truncate px-2 pb-0.5 pt-1 text-xs text-outline",children:x}),e.jsx("ul",{className:"space-y-0.5",children:k.map(j=>{const C=j.id===n,w=C&&o!==j.id&&i.length>0;return e.jsxs("li",{children:[e.jsxs("button",{type:"button","data-testid":"kb-row","data-kb-name":j.name,"aria-current":C&&!a?"page":void 0,"aria-expanded":w,className:U("flex min-h-9 w-full items-center gap-2 rounded-md px-2 text-left text-sm hover:bg-surface-high",C&&"font-medium",C&&!a&&"bg-surface-high"),onClick:()=>{C&&d(f=>f===j.id?null:j.id),l(j.id)},children:[e.jsx(Ee,{size:14,"aria-hidden":!0,className:U("-mr-1 shrink-0 text-outline transition-transform motion-reduce:transition-none",w&&"rotate-90",j.document_count===0&&"invisible")}),e.jsx(Kt,{size:15,className:"shrink-0 text-outline","aria-hidden":!0}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:j.name}),e.jsx("span",{className:"text-xs font-normal tabular-nums text-outline",children:j.document_count})]}),w&&e.jsx("ul",{className:"ml-4 mt-0.5 space-y-0.5 border-l border-outline-variant pl-2",children:i.map(f=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-testid":"kb-nav-document","data-document-title":f.title,"aria-current":f.id===a?"page":void 0,className:U("flex min-h-8 w-full items-center gap-2 rounded-md px-2 text-left text-sm hover:bg-surface-high",f.id===a?"bg-surface-high text-on-surface":"text-outline"),onClick:()=>r(f.id),children:[e.jsx(_t,{size:14,className:"shrink-0","aria-hidden":!0}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:f.title})]})},f.id))})]},j.id)})})]},x))})}function Pn(){const t=Zs(),s=t.data,n=s?s.embedding.provider==="none"?{text:"Keyword search only",title:"Configure embeddings in Settings to also search by meaning"}:s.embedding.ready?{text:"Hybrid search",title:s.embedding.model??void 0}:{text:"Embeddings not ready",title:s.embedding.detail??""}:null,a=s?s.jobs.queued+s.jobs.running:0;return e.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:s?e.jsxs(e.Fragment,{children:[e.jsx("span",{title:n==null?void 0:n.title,children:n==null?void 0:n.text}),a?` · ${a} processing`:""]}):t.error?"Knowledge status unavailable":"Loading…"})}function vt({children:t}){return e.jsx("div",{className:"min-h-0 min-w-0 flex-1 overflow-y-auto",children:t})}function Be({children:t,testId:s}){return e.jsx("div",{"data-testid":s,className:"mx-auto flex max-w-lg flex-1 flex-col items-start justify-center gap-4 p-6",children:t})}function zn({query:t,search:s,onOpen:n,onClear:a}){const i=s.data;return e.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:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("h2",{className:"mr-auto text-lg font-medium",children:["Results for “",t,"”"]}),i&&i.hits.length>0&&e.jsxs("span",{className:"text-xs text-outline","data-testid":"kb-search-count",children:[i.hits.length," ",i.hits.length===1?"result":"results"]}),e.jsxs(g,{variant:"ghost",size:"sm",onClick:a,"data-testid":"kb-search-clear",children:[e.jsx(Ve,{size:14}),"Clear"]})]}),(i==null?void 0:i.degraded)&&e.jsx("p",{role:"status",className:"text-sm text-warning",children:i.degraded}),s.isLoading&&e.jsx("p",{className:"text-sm text-outline",children:"Searching…"}),s.error&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:s.error.message}),(i==null?void 0:i.hits.length)===0&&e.jsx("p",{className:"text-sm text-outline","data-testid":"kb-search-empty",children:"Nothing matched. Try other words or search all knowledge bases."}),i==null?void 0:i.hits.map(l=>e.jsxs("article",{"data-testid":"kb-search-result",className:"space-y-2 border-b border-outline-variant pb-4",children:[e.jsxs("button",{type:"button",className:"block text-left",onClick:()=>{var r;return n(l.document_id,kt((r=l.passages[0])==null?void 0:r.heading_path))},children:[e.jsx("span",{className:"block font-medium text-primary hover:underline",children:l.title}),e.jsxs("span",{className:"block break-all text-xs text-outline",children:[l.kb_name," · ",l.path]})]}),l.labels.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1",children:l.labels.map(r=>e.jsx(rs,{variant:"secondary",children:r},r))}),l.passages.map(r=>{var o,d,p,m;return e.jsxs("div",{"data-testid":"kb-search-passage",className:"cursor-pointer space-y-1 rounded-md p-2 hover:bg-surface-high",onClick:()=>n(l.document_id,kt(r.heading_path)),children:[(r.heading_path.length>0||((o=r.locator)==null?void 0:o.page)||((d=r.locator)==null?void 0:d.sheet))&&e.jsx("div",{className:"text-xs text-outline",children:[...r.heading_path.map(us),...(p=r.locator)!=null&&p.page?[`page ${r.locator.page}`]:[],...(m=r.locator)!=null&&m.sheet?[`sheet ${r.locator.sheet}`]:[]].join(" › ")}),e.jsx("p",{className:"text-sm leading-relaxed",children:e.jsx(Dn,{text:r.snippet})})]},r.chunk_id)})]},l.document_id))]})}function Rn({uploads:t,onOpen:s}){if(!t.uploads.length)return null;const n=t.uploads.some(a=>a.status!=="uploading");return e.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:[e.jsxs("div",{className:"flex shrink-0 items-center justify-between px-3 py-1.5",children:[e.jsx("span",{className:"font-medium",children:"Uploads"}),n&&e.jsx(g,{size:"sm",variant:"ghost",onClick:t.clearFinished,"data-testid":"kb-upload-clear",children:"Dismiss"})]}),e.jsx("div",{className:"min-h-0 space-y-1 overflow-y-auto px-3 pb-2",children:t.uploads.map(a=>e.jsx(Mn,{upload:a,onOpen:s,onRetry:()=>t.retry(a.id)},a.id))})]})}const Ln={pending:"Parsing…",ok:"Open",partial:"Open · partly parsed",failed:"Parse failed"};function Mn({upload:t,onOpen:s,onRetry:n}){var l;const i=((l=ze(t.status==="done"?t.kbId:null).data)==null?void 0:l.documents.find(r=>{var o;return r.id===((o=t.document)==null?void 0:o.id)}))??t.document;return e.jsxs("div",{"data-testid":"kb-upload-item","data-status":t.status,"data-parse-state":i==null?void 0:i.parse_state,className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t.file.name}),t.status==="uploading"&&e.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(t.progress*100),children:e.jsx("span",{className:"block h-full bg-primary",style:{width:`${Math.round(t.progress*100)}%`}})}),t.status==="done"&&i&&e.jsx("button",{type:"button",className:U("hover:underline",i.parse_state==="failed"?"text-error":"text-primary"),onClick:()=>s(i.id),children:Ln[i.parse_state]}),t.status==="failed"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"alert",className:"text-error",children:t.error}),e.jsx(g,{size:"sm",variant:"ghost",onClick:n,"data-testid":"kb-upload-retry",children:"Retry"})]})]})}function kt(t){return t==null?void 0:t[t.length-1]}export{ai as default};
|