orc-ai 0.1.55 → 0.1.57
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/README.md +8 -0
- package/dist/index.js +1225 -613
- package/dist/skills/orc-platform/SKILL.md +1 -0
- package/dist/skills/orc-platform/references/chat-ui.md +99 -0
- package/dist/web/assets/{Agents-D70pZAkB.js → Agents-BqDgTY1y.js} +3 -3
- package/dist/web/assets/{Attention-DoTjQvwX.js → Attention-BhhQ7JI5.js} +2 -2
- package/dist/web/assets/{Audit-BilD5tHL.js → Audit-C9mm3LA5.js} +1 -1
- package/dist/web/assets/ChatUiRenderer-tVRUNwrT.js +4 -0
- package/dist/web/assets/{ConfirmDialog-Cyd60q9b.js → ConfirmDialog-tkekzo2g.js} +1 -1
- package/dist/web/assets/{Dashboard-BrpclE6i.js → Dashboard-Zt3HIH7H.js} +1 -1
- package/dist/web/assets/{DocumentWorkspace-BirLb0Py.js → DocumentWorkspace-k66oavWs.js} +1 -1
- package/dist/web/assets/{ErrorState-BrKz7Mii.js → ErrorState-DprXzfow.js} +1 -1
- package/dist/web/assets/{FileEditor-Cfl56W9G.js → FileEditor-DSpVqamv.js} +1 -1
- package/dist/web/assets/FormDialog-BY8LbFlB.js +1 -0
- package/dist/web/assets/IntegrationCallback-CyCrQmbt.js +1 -0
- package/dist/web/assets/{JobWebhooks-csgdKaIu.js → JobWebhooks-CPDNSZmh.js} +1 -1
- package/dist/web/assets/Jobs-XJjyV-d0.js +1 -0
- package/dist/web/assets/Knowledge-CexO9loe.js +1 -0
- package/dist/web/assets/Markdown-B0Ztqigq.js +2 -0
- package/dist/web/assets/MarkdownEditor-p8DBlDfc.js +2 -0
- package/dist/web/assets/{MarkdownRenderer-C4od8dIW.js → MarkdownRenderer-FKMLueR4.js} +7 -7
- package/dist/web/assets/{PackageCatalog-rIC8EqCV.js → PackageCatalog-DPkzNc8B.js} +2 -2
- package/dist/web/assets/PackageRunDialog-BWoyMyCc.js +105 -0
- package/dist/web/assets/{Pager-Bc666Oa5.js → Pager-CTRTlHtC.js} +1 -1
- package/dist/web/assets/{PriorityBadge-Ccw4iVk7.js → PriorityBadge-D263N3pH.js} +1 -1
- package/dist/web/assets/Projects-kevXjjnv.js +3 -0
- package/dist/web/assets/{ResponsiveFilters-DAeezpA-.js → ResponsiveFilters-DBO0_-qy.js} +1 -1
- package/dist/web/assets/ResumeActions-D6ZLCopA.js +1 -0
- package/dist/web/assets/{Rules-u4Yt3UWU.js → Rules-Ddgn5f0E.js} +4 -4
- package/dist/web/assets/ScratchpadDiagramEditor-BxrrJ0SE.js +1 -0
- package/dist/web/assets/ScratchpadDiagramPreview-C76RVMjL.js +1 -0
- package/dist/web/assets/Scratchpads-qbxW3MdR.js +10 -0
- package/dist/web/assets/Sessions-Cnz8Zmdd.js +3 -0
- package/dist/web/assets/Settings-BonKxwxT.js +10 -0
- package/dist/web/assets/Skills-CplC4QfG.js +8 -0
- package/dist/web/assets/{SourceEditor-BXHhVnEe.js → SourceEditor-78XFXmqS.js} +3 -3
- package/dist/web/assets/{StatusBadge-ia651_Df.js → StatusBadge-BUGpPpcH.js} +1 -1
- package/dist/web/assets/{TagInput-BCXK-1YG.js → TagInput-QRxyaeSJ.js} +1 -1
- package/dist/web/assets/TaskDetailSheet-BzxATS_B.js +1 -0
- package/dist/web/assets/{Tasks-CsBS5O9A.js → Tasks-ilYmRfqI.js} +7 -7
- package/dist/web/assets/Terminals-dKofw0PM.js +3 -0
- package/dist/web/assets/{ViewHeader-Ce5HQRJu.js → ViewHeader-C3jwAE4K.js} +1 -1
- package/dist/web/assets/{Webhooks-BCKPHvAT.js → Webhooks-C8LrcSUj.js} +1 -1
- package/dist/web/assets/{ar-SA-G6X2FPQ2-Dxcs6bnC.js → ar-SA-G6X2FPQ2-BHNmOPAa.js} +1 -1
- package/dist/web/assets/az-AZ-76LH7QW2-CYylNbd1.js +1 -0
- package/dist/web/assets/badge-4H7GKk39.js +1 -0
- package/dist/web/assets/{bg-BG-XCXSNQG7-GVnVbOJF.js → bg-BG-XCXSNQG7-VqpfCk7Q.js} +1 -1
- package/dist/web/assets/{bn-BD-2XOGV67Q-CBnLWZsm.js → bn-BD-2XOGV67Q-sq5066za.js} +1 -1
- package/dist/web/assets/bundle-mjs-CdK3cBzO.js +1 -0
- package/dist/web/assets/button-C91mbQEU.js +1 -0
- package/dist/web/assets/{ca-ES-6MX7JW3Y-nF87CFCd.js → ca-ES-6MX7JW3Y-C1-EfJt9.js} +1 -1
- package/dist/web/assets/chat-ui-BqBYGP0k.js +64 -0
- package/dist/web/assets/check-BN9WfUXs.js +1 -0
- package/dist/web/assets/chevron-down-DsKwSkKG.js +1 -0
- package/dist/web/assets/{chunk-EIO257PC-C5HXDKyY.js → chunk-EIO257PC-D5dZL9PV.js} +1 -1
- package/dist/web/assets/circle-check-BY2n9ZCv.js +1 -0
- package/dist/web/assets/client-BDeNEjHL.js +1 -0
- package/dist/web/assets/{cs-CZ-2BRQDIVT-Cz5r5OEj.js → cs-CZ-2BRQDIVT-57tJuhpe.js} +1 -1
- package/dist/web/assets/{da-DK-5WZEPLOC-B2TNmBRb.js → da-DK-5WZEPLOC-DM7XjaYi.js} +1 -1
- package/dist/web/assets/{de-DE-XR44H4JA-BNOqSnix.js → de-DE-XR44H4JA-CQpZC2C8.js} +1 -1
- package/dist/web/assets/{dialog-Juth7dP_.js → dialog-Dsdmr5mY.js} +1 -1
- package/dist/web/assets/{dist-DxwmSTqz.js → dist-BKxzy3T8.js} +1 -1
- package/dist/web/assets/{download-3BU1OMm1.js → download-DzO9zuw8.js} +1 -1
- package/dist/web/assets/{el-GR-BZB4AONW-BzwJhjCV.js → el-GR-BZB4AONW-BG0fwyry.js} +1 -1
- package/dist/web/assets/{en-B4ZKOASM-qumcDTz5.js → en-B4ZKOASM-CYtHfac-.js} +1 -1
- package/dist/web/assets/{es-ES-U4NZUMDT-CYNwXzvM.js → es-ES-U4NZUMDT-DeCoGq3I.js} +1 -1
- package/dist/web/assets/{eu-ES-A7QVB2H4-Bt_WsfwK.js → eu-ES-A7QVB2H4-BgrTM9Q_.js} +1 -1
- package/dist/web/assets/{fa-IR-HGAKTJCU-TG6ul0gf.js → fa-IR-HGAKTJCU-BMNXHhCI.js} +1 -1
- package/dist/web/assets/{fi-FI-Z5N7JZ37-BEmxMqCH.js → fi-FI-Z5N7JZ37-AvkTA6Bg.js} +1 -1
- package/dist/web/assets/floating-ui.react-dom-BDMgcqWu.js +1 -0
- package/dist/web/assets/{fr-FR-RHASNOE6-DVlOJmrm.js → fr-FR-RHASNOE6-DdOUGndN.js} +1 -1
- package/dist/web/assets/{gl-ES-HMX3MZ6V-C51CVUC3.js → gl-ES-HMX3MZ6V-BOcT9Eh2.js} +1 -1
- package/dist/web/assets/{he-IL-6SHJWFNN-BaHbjpvX.js → he-IL-6SHJWFNN-XKCHaRIK.js} +1 -1
- package/dist/web/assets/{hi-IN-IWLTKZ5I-BnsUhtYU.js → hi-IN-IWLTKZ5I-DIIO_PCe.js} +1 -1
- package/dist/web/assets/{highlighted-body-JLMTFACH-CCL_Oa2N.js → highlighted-body-JLMTFACH-CZFWIWYs.js} +1 -1
- package/dist/web/assets/{hu-HU-A5ZG7DT2-DJAd0DXQ.js → hu-HU-A5ZG7DT2-Dbjtq-D1.js} +1 -1
- package/dist/web/assets/{id-ID-SAP4L64H-D_Sp4hWt.js → id-ID-SAP4L64H-CDk9puhw.js} +1 -1
- package/dist/web/assets/image-GAAHSSAO-rkI8hLQy.js +1 -0
- package/dist/web/assets/index-B8T4bf2f.css +1 -0
- package/dist/web/assets/{index-C60WCVxH.js → index-D3mYpeGu.js} +19 -19
- package/dist/web/assets/{it-IT-JPQ66NNP-B2VOtgAl.js → it-IT-JPQ66NNP-YRZ57kPD.js} +1 -1
- package/dist/web/assets/{ja-JP-DBVTYXUO-D8n4LcP-.js → ja-JP-DBVTYXUO-DVMZSYKy.js} +1 -1
- package/dist/web/assets/kaa-6HZHGXH3-CptDAgKS.js +1 -0
- package/dist/web/assets/{kab-KAB-ZGHBKWFO-CBS-7rLX.js → kab-KAB-ZGHBKWFO-OATW2sAD.js} +1 -1
- package/dist/web/assets/kk-KZ-P5N5QNE5-B6R_70EG.js +1 -0
- package/dist/web/assets/{km-KH-HSX4SM5Z-DQKGOVey.js → km-KH-HSX4SM5Z-Cxdswtta.js} +1 -1
- package/dist/web/assets/{ko-KR-MTYHY66A-D-mh0Zog.js → ko-KR-MTYHY66A-C-K_IuWl.js} +1 -1
- package/dist/web/assets/{ku-TR-6OUDTVRD-02Q4uBGz.js → ku-TR-6OUDTVRD-zFXPVPDH.js} +1 -1
- package/dist/web/assets/{label-wk_QKooL.js → label-BdnRgBbz.js} +1 -1
- package/dist/web/assets/{link-2-Db-kEge7.js → link-2-Bp2r7lup.js} +1 -1
- package/dist/web/assets/{list-D_3Q3U-9.js → list-CtnWaAEh.js} +1 -1
- package/dist/web/assets/{lt-LT-XHIRWOB4-DLL22EcK.js → lt-LT-XHIRWOB4-DkOTIbBj.js} +1 -1
- package/dist/web/assets/{lv-LV-5QDEKY6T-D3GBaG3q.js → lv-LV-5QDEKY6T-DjJBaytN.js} +1 -1
- package/dist/web/assets/maximize-2-IKRw5Gjm.js +1 -0
- package/dist/web/assets/mermaid-WFAXDIZX-DGqlOTw7.js +1 -0
- package/dist/web/assets/{mr-IN-CRQNXWMA--HI3GWMp.js → mr-IN-CRQNXWMA-CpBrL5xP.js} +1 -1
- package/dist/web/assets/my-MM-5M5IBNSE-n3gOu566.js +1 -0
- package/dist/web/assets/{nb-NO-T6EIAALU-BpE3Sd7f.js → nb-NO-T6EIAALU-BotYv1MD.js} +1 -1
- package/dist/web/assets/{nl-NL-IS3SIHDZ-CVXeRx8i.js → nl-NL-IS3SIHDZ-DW0fsbWy.js} +1 -1
- package/dist/web/assets/{nn-NO-6E72VCQL-c6qBqD3x.js → nn-NO-6E72VCQL-Bb-fnU0x.js} +1 -1
- package/dist/web/assets/{oc-FR-POXYY2M6-Cau2e1RB.js → oc-FR-POXYY2M6-shEPc56q.js} +1 -1
- package/dist/web/assets/{pa-IN-N4M65BXN-BZBndxoR.js → pa-IN-N4M65BXN-DKavQSyF.js} +1 -1
- package/dist/web/assets/percentages-BXMCSKIN-G1-czdqc.js +1 -0
- package/dist/web/assets/{pl-PL-T2D74RX3-Z_GpAanN.js → pl-PL-T2D74RX3-BNiWQazy.js} +1 -1
- package/dist/web/assets/prod-BxHPuooG.js +159 -0
- package/dist/web/assets/{pt-BR-5N22H2LF-BlVpEHGK.js → pt-BR-5N22H2LF-BNrp0SJn.js} +1 -1
- package/dist/web/assets/{pt-PT-UZXXM6DQ-QuQH0hsZ.js → pt-PT-UZXXM6DQ-MqcjbYsn.js} +1 -1
- package/dist/web/assets/react-dom-DTbwZiiP.js +1 -0
- package/dist/web/assets/{ro-RO-JPDTUUEW-BGlQpI3X.js → ro-RO-JPDTUUEW-BaD_m5BY.js} +1 -1
- package/dist/web/assets/{ru-RU-B4JR7IUQ-CHU0e8TZ.js → ru-RU-B4JR7IUQ-BOeGQntq.js} +1 -1
- package/dist/web/assets/{save-CMSSgXiS.js → save-Bmsljxzd.js} +1 -1
- package/dist/web/assets/schemas-BQZhekae.js +55 -0
- package/dist/web/assets/scratchpad-kinds-DVmp6U2Q.js +1 -0
- package/dist/web/assets/scratchpad-routes-DyIIblLm.js +1 -0
- package/dist/web/assets/{scroll-area-D0FZFdju.js → scroll-area-Cmb_s_kX.js} +1 -1
- package/dist/web/assets/si-LK-N5RQ5JYF-CEpiTE5c.js +1 -0
- package/dist/web/assets/{sk-SK-C5VTKIMK-CuzZf_b9.js → sk-SK-C5VTKIMK-lXa56uQB.js} +1 -1
- package/dist/web/assets/{sl-SI-NN7IZMDC-DrOH-WzJ.js → sl-SI-NN7IZMDC-S7pYt-A8.js} +1 -1
- package/dist/web/assets/subset-shared.chunk-C-8kChur.js +1 -0
- package/dist/web/assets/subset-worker.chunk-DAdqTVJ_.js +1 -0
- package/dist/web/assets/{sv-SE-XGPEYMSR-BhIUxUn8.js → sv-SE-XGPEYMSR-BAmS64lt.js} +1 -1
- package/dist/web/assets/{ta-IN-2NMHFXQM-DxBax1RW.js → ta-IN-2NMHFXQM-B2aOysQ6.js} +1 -1
- package/dist/web/assets/{table-Cri9EUoE.js → table-Q26Vm3R3.js} +1 -1
- package/dist/web/assets/{tabs-Cv3KJIRq.js → tabs-DpKnjRll.js} +1 -1
- package/dist/web/assets/{textarea-Bt1FBmGL.js → textarea-BRdsUa6B.js} +1 -1
- package/dist/web/assets/th-TH-HPSO5L25-MKFJurV1.js +2 -0
- package/dist/web/assets/{tr-TR-DEFEU3FU-3u6WSMcx.js → tr-TR-DEFEU3FU-DKE7gZ4N.js} +1 -1
- package/dist/web/assets/{uk-UA-QMV73CPH-BbCm-sIk.js → uk-UA-QMV73CPH-DutAOQit.js} +1 -1
- package/dist/web/assets/{upload-BZ3CpmMe.js → upload-BS--UG8X.js} +1 -1
- package/dist/web/assets/useIntegrations-Dw2tGWu6.js +1 -0
- package/dist/web/assets/{useJobs-B2da-s4n.js → useJobs-Bt5IQ7lh.js} +1 -1
- package/dist/web/assets/{useListSelection-ZreW_5e4.js → useListSelection-DLQYrJX-.js} +1 -1
- package/dist/web/assets/{useMemories-UaTju2A_.js → useMemories-P5XFw8dY.js} +1 -1
- package/dist/web/assets/{useSessions-BNSlPToV.js → useSessions-cIszsUgG.js} +1 -1
- package/dist/web/assets/{vi-VN-M7AON7JQ-DgsVZ_V1.js → vi-VN-M7AON7JQ-BpbS22dK.js} +1 -1
- package/dist/web/assets/x-CzIc4TnV.js +1 -0
- package/dist/web/assets/{zh-CN-LNUGB5OW-DOVvsMem.js → zh-CN-LNUGB5OW-BWtL4V8y.js} +1 -1
- package/dist/web/assets/zh-HK-E62DVLB3-DrfXDi4l.js +1 -0
- package/dist/web/assets/{zh-TW-RAJ6MFWO-DieBH0AH.js → zh-TW-RAJ6MFWO-BVZGUfP5.js} +1 -1
- package/dist/web/index.html +21 -18
- package/package.json +1 -1
- package/dist/web/assets/Jobs-BeDH5Nqx.js +0 -1
- package/dist/web/assets/Knowledge-Bhe2osQ9.js +0 -1
- package/dist/web/assets/Markdown-cNY95m5f.js +0 -2
- package/dist/web/assets/MarkdownEditor-CPlYZ0ux.js +0 -2
- package/dist/web/assets/PackageRunDialog-BPLlcUBW.js +0 -105
- package/dist/web/assets/Projects-C5tjWMiN.js +0 -3
- package/dist/web/assets/ResumeActions-Xi3gsryf.js +0 -1
- package/dist/web/assets/ScratchpadDiagramEditor-CEZLGEOO.js +0 -159
- package/dist/web/assets/Scratchpads-BINR8pcN.js +0 -10
- package/dist/web/assets/Sessions-xflxxp3f.js +0 -3
- package/dist/web/assets/Settings-C5tS2MvS.js +0 -6
- package/dist/web/assets/Skills-QaW-IPD1.js +0 -8
- package/dist/web/assets/TaskDetailSheet-BIMcgJGc.js +0 -1
- package/dist/web/assets/Terminals-D3Yo-p_A.js +0 -3
- package/dist/web/assets/arrow-left-vCG_8rdy.js +0 -1
- package/dist/web/assets/az-AZ-76LH7QW2-DzTRmo_5.js +0 -1
- package/dist/web/assets/bundle-mjs-geeEdoSy.js +0 -1
- package/dist/web/assets/button-CXYVslgR.js +0 -1
- package/dist/web/assets/check-DOY0CJBh.js +0 -1
- package/dist/web/assets/chevron-down-hj6o3_QU.js +0 -1
- package/dist/web/assets/client-nzMXason.js +0 -1
- package/dist/web/assets/copy-DZWYRnrF.js +0 -1
- package/dist/web/assets/folder-open-BQI4k9Xd.js +0 -1
- package/dist/web/assets/image-GAAHSSAO-uTNUnk7Z.js +0 -1
- package/dist/web/assets/index-ghfkdpY-.css +0 -1
- package/dist/web/assets/kaa-6HZHGXH3-BvK7fQHB.js +0 -1
- package/dist/web/assets/kk-KZ-P5N5QNE5-D6rLwfEb.js +0 -1
- package/dist/web/assets/mermaid-WFAXDIZX-B8XO7yhf.js +0 -1
- package/dist/web/assets/my-MM-5M5IBNSE-BzpoSrEn.js +0 -1
- package/dist/web/assets/percentages-BXMCSKIN-D3Fw5F9S.js +0 -1
- package/dist/web/assets/schemas-CGoaq3B4.js +0 -55
- package/dist/web/assets/scratchpad-routes-Dbj7u895.js +0 -1
- package/dist/web/assets/select-Cj-m0J9A.js +0 -1
- package/dist/web/assets/si-LK-N5RQ5JYF-9PXfGp8N.js +0 -1
- package/dist/web/assets/subset-shared.chunk-CNd4ljrr.js +0 -1
- package/dist/web/assets/subset-worker.chunk-C1uKhPt9.js +0 -1
- package/dist/web/assets/th-TH-HPSO5L25-DA8qp-YV.js +0 -2
- package/dist/web/assets/useKnowledge-BGBP3GLW.js +0 -1
- package/dist/web/assets/x-CiIWeCBP.js +0 -1
- package/dist/web/assets/zh-HK-E62DVLB3-BuhcmxhT.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e}from"./rolldown-runtime-DSDNlrLa.js";import{n as t,t as n}from"./jsx-runtime-CVMpzJz9.js";import{t as r}from"./react-dom-DTbwZiiP.js";import{l as i}from"./chunk-OB3PAWPO-1IihCzFx.js";import{C as a,E as o,F as s,I as c,M as l,N as u,P as d,T as f,_ as p,f as m,g as h,h as g,j as _,k as v,l as y,m as b,p as x,t as S,v as C,y as w}from"./button-C91mbQEU.js";import{t as T}from"./dist-bytwC6rk.js";import{n as E,t as ee}from"./es2015-w69PgVrA.js";import{t as D}from"./dist-BKxzy3T8.js";import{t as te}from"./dist-Ct6061MC.js";import{t as O}from"./dist-D8Wfxh48.js";import{d as k}from"./client-BDeNEjHL.js";import{t as A}from"./check-BN9WfUXs.js";import{t as j}from"./chevron-down-DsKwSkKG.js";import{a as ne,i as M,n as N,o as re,r as P,t as F}from"./dialog-Dsdmr5mY.js";var I=e(t(),1),L=e(r(),1),R=n(),z=Object.defineProperty,B=(e,t)=>z(e,`name`,{value:t,configurable:!0}),ie={ItemAligned:`item-aligned`,Popper:`popper`},V={LTR:`ltr`,RTL:`rtl`},H=[` `,`Enter`,`ArrowUp`,`ArrowDown`],U=[` `,`Enter`],W=`Select`,[G,K,ae]=D(W),[q,oe]=d(W,[ae,h]),J=h(),[se,Y]=q(W),[ce,le]=q(W);function ue(e){let{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:a,value:o,defaultValue:s,onValueChange:c,dir:u,name:d,autoComplete:f,disabled:p,required:m,form:h,internal_do_not_use_render:g}=e,v=J(t),[y,b]=I.useState(null),[S,C]=I.useState(null),[w,T]=I.useState(!1),E=te(u),[ee,D]=_({prop:r,defaultProp:i??!1,onChange:a,caller:W}),[O,k]=_({prop:o,defaultProp:s,onChange:c,caller:W}),A=I.useRef(null),j=I.useRef(!1),[ne,M]=I.useState(null),N=B(e=>{M({value:e,hasConsumerStoppedPropagation:j.current}),k(e)},`handleUserSelect`),re=I.useRef(O);I.useEffect(()=>{let e=h?y?.ownerDocument.getElementById(h):y?.form;if(e instanceof HTMLFormElement){let t=B(()=>k(re.current),`reset`);return e.addEventListener(`reset`,t),()=>e.removeEventListener(`reset`,t)}},[h,y,k]);let P=!y||!!h||!!y.closest(`form`),[F,L]=I.useState(new Set),z=l(),ie=Array.from(F).map(e=>e.props.value).join(`;`),V=I.useCallback(e=>{L(t=>new Set(t).add(e))},[]),H=I.useCallback(e=>{L(t=>{let n=new Set(t);return n.delete(e),n})},[]),U={required:m,trigger:y,onTriggerChange:b,valueNode:S,onValueNodeChange:C,valueNodeHasChildren:w,onValueNodeHasChildrenChange:T,contentId:z,value:O,onValueChange:k,hasConsumerStoppedPropagationRef:j,userSelection:ne,onUserSelect:N,open:ee,onOpenChange:D,dir:E,triggerPointerDownPosRef:A,disabled:p,name:d,autoComplete:f,form:h,nativeOptions:F,nativeSelectKey:ie,isFormControl:P};return(0,R.jsx)(x,{...v,children:(0,R.jsx)(se,{scope:t,...U,children:(0,R.jsx)(G.Provider,{scope:t,children:(0,R.jsx)(ce,{scope:t,onNativeOptionAdd:V,onNativeOptionRemove:H,children:Ze(g)?g(U):n})})})})}B(ue,`SelectProvider`);var de=B(e=>{let{__scopeSelect:t,children:n,...r}=e;return(0,R.jsx)(ue,{__scopeSelect:t,...r,internal_do_not_use_render:({isFormControl:e})=>(0,R.jsxs)(R.Fragment,{children:[n,e?(0,R.jsx)(Xe,{__scopeSelect:t}):null]})})},`Select`),fe=`SelectTrigger`,pe=I.forwardRef(B(function(e,t){let{__scopeSelect:n,disabled:r=!1,...i}=e,a=J(n),l=Y(fe,n),u=l.disabled||r,d=s(t,l.onTriggerChange),f=K(n),p=I.useRef(`touch`),[m,h,g]=Qe(e=>{let t=f().filter(e=>!e.disabled),n=$e(t,e,t.find(e=>e.value===l.value));n!==void 0&&l.onUserSelect(n.value)}),_=B(e=>{u||(l.onOpenChange(!0),g()),e&&(l.triggerPointerDownPosRef.current={x:Math.round(e.pageX),y:Math.round(e.pageY)})},`handleOpen`);return(0,R.jsx)(b,{asChild:!0,...a,children:(0,R.jsx)(o.button,{type:`button`,role:`combobox`,"aria-controls":l.open?l.contentId:void 0,"aria-expanded":l.open,"aria-required":l.required,"aria-autocomplete":`none`,dir:l.dir,"data-state":l.open?`open`:`closed`,disabled:u,"data-disabled":u?``:void 0,"data-placeholder":$(l.value)?``:void 0,...i,ref:d,onClick:c(i.onClick,e=>{e.currentTarget.focus(),p.current!==`mouse`&&_(e)}),onPointerDown:c(i.onPointerDown,e=>{p.current=e.pointerType;let t=e.target;t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId),e.button===0&&e.ctrlKey===!1&&e.pointerType===`mouse`&&(_(e),e.preventDefault())}),onKeyDown:c(i.onKeyDown,e=>{let t=m.current!==``;!(e.ctrlKey||e.altKey||e.metaKey)&&e.key.length===1&&(l.hasConsumerStoppedPropagationRef.current=e.isPropagationStopped(),h(e.key)),!(t&&e.key===` `)&&H.includes(e.key)&&(_(),e.preventDefault())})})})},`SelectTrigger`)),me=`SelectValue`,he=I.forwardRef(B(function(e,t){let{__scopeSelect:n,className:r,style:i,children:a,placeholder:c=``,...l}=e,d=Y(me,n),{onValueNodeHasChildrenChange:f}=d,p=a!==void 0,m=s(t,d.onValueNodeChange);u(()=>{f(p)},[f,p]);let h=$(d.value);return(0,R.jsx)(o.span,{...l,asChild:!h&&l.asChild,ref:m,style:{pointerEvents:`none`},children:(0,R.jsx)(I.Fragment,{children:h?c:a},h?`placeholder`:`value`)})},`SelectValue`)),ge=I.forwardRef(B(function(e,t){let{__scopeSelect:n,children:r,...i}=e;return(0,R.jsx)(o.span,{"aria-hidden":!0,...i,ref:t,children:r||`▼`})},`SelectIcon`)),[_e,ve]=q(`SelectPortal`,{forceMount:void 0}),ye=B(e=>{let{__scopeSelect:t,forceMount:n,...r}=e;return(0,R.jsx)(_e,{scope:e.__scopeSelect,forceMount:n,children:(0,R.jsx)(C,{asChild:!0,...r})})},`SelectPortal`),X=`SelectContent`,be=I.forwardRef(B(function(e,t){let n=ve(X,e.__scopeSelect),{forceMount:r=n.forceMount,...i}=e,a=Y(X,e.__scopeSelect),[o,s]=I.useState();return u(()=>{s(new DocumentFragment)},[]),(0,R.jsx)(p,{present:r||a.open,children:({present:e})=>e?(0,R.jsx)(we,{...i,ref:t}):(0,R.jsx)(xe,{...i,fragment:o})})},`SelectContent`)),xe=I.forwardRef(B(function(e,t){let{__scopeSelect:n,children:r,fragment:i}=e;return i?L.createPortal((0,R.jsx)(Se,{scope:n,children:(0,R.jsx)(G.Slot,{scope:n,children:(0,R.jsx)(`div`,{ref:t,children:r})})}),i):null},`SelectContentFragment`)),Z=10,[Se,Q]=q(X),Ce=v(`SelectContent.RemoveScroll`),we=I.forwardRef(B(function(e,t){let{__scopeSelect:n}=e,{position:r=ie.ItemAligned,onCloseAutoFocus:i,onEscapeKeyDown:o,onPointerDownOutside:l,side:u,sideOffset:d,align:f,alignOffset:p,arrowPadding:m,collisionBoundary:h,collisionPadding:g,sticky:_,hideWhenDetached:v,avoidCollisions:y,...b}=e,x=Y(X,n),[S,C]=I.useState(null),[D,te]=I.useState(null),O=s(t,C),[k,A]=I.useState(null),[j,ne]=I.useState(null),M=K(n),[N,re]=I.useState(!1),P=I.useRef(!1),F=I.useRef(!1),L=I.useRef(!1);I.useEffect(()=>{if(S)return ee(S)},[S]),T();let z=I.useCallback(e=>{let[t,...n]=M().map(e=>e.ref.current),[r]=n.slice(-1),i=document.activeElement;for(let n of e)if(n===i||(n?.scrollIntoView({block:`nearest`}),n===t&&D&&(D.scrollTop=0),n===r&&D&&(D.scrollTop=D.scrollHeight),n?.focus(),document.activeElement!==i))return},[M,D]),V=I.useCallback(()=>z([k,S]),[z,k,S]);I.useEffect(()=>{N&&V()},[N,V]);let{onOpenChange:H,triggerPointerDownPosRef:U}=x;I.useEffect(()=>{if(S){let e={x:0,y:0},t=B(t=>{e={x:Math.abs(Math.round(t.pageX)-(U.current?.x??0)),y:Math.abs(Math.round(t.pageY)-(U.current?.y??0))}},`handlePointerMove`),n=B(n=>{e.x<=10&&e.y<=10?n.preventDefault():n.composedPath().includes(S)||H(!1),document.removeEventListener(`pointermove`,t),U.current=null},`handlePointerUp`);return U.current!==null&&(document.addEventListener(`pointermove`,t),document.addEventListener(`pointerup`,n,{capture:!0,once:!0})),()=>{document.removeEventListener(`pointermove`,t),document.removeEventListener(`pointerup`,n,{capture:!0})}}},[S,H,U]),I.useEffect(()=>{let e=B(()=>H(!1),`close`);return window.addEventListener(`blur`,e),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`blur`,e),window.removeEventListener(`resize`,e)}},[H]);let[W,G]=Qe(e=>{let t=M().filter(e=>!e.disabled),n=$e(t,e,t.find(e=>e.ref.current===document.activeElement));n&&setTimeout(()=>n.ref.current?.focus())}),ae=I.useCallback((e,t,n)=>{let r=!F.current;r&&(F.current=!0);let i=!P.current&&!n;x.value!==void 0&&x.value===t||i?(A(e),i&&(P.current=!0)):r&&A(e)},[x.value]),q=I.useCallback(()=>S?.focus(),[S]),oe=I.useCallback((e,t,n)=>{if(!e)return;let r=!L.current;r&&(L.current=!0);let i=!P.current&&!n;(x.value!==void 0&&x.value===t||i||r)&&ne(e)},[x.value]),J=r===ie.Popper?Ee:Te,se=J===Ee?{side:u,sideOffset:d,align:f,alignOffset:p,arrowPadding:m,collisionBoundary:h,collisionPadding:g,sticky:_,hideWhenDetached:v,avoidCollisions:y}:{};return(0,R.jsx)(Se,{scope:n,content:S,viewport:D,onViewportChange:te,itemRefCallback:ae,selectedItem:k,onItemLeave:q,itemTextRefCallback:oe,focusSelectedItem:V,selectedItemText:j,position:r,isPositioned:N,searchRef:W,children:(0,R.jsx)(E,{as:Ce,allowPinchZoom:!0,children:(0,R.jsx)(w,{asChild:!0,trapped:x.open,onMountAutoFocus:e=>{e.preventDefault()},onUnmountAutoFocus:c(i,e=>{x.trigger?.focus({preventScroll:!0}),e.preventDefault()}),children:(0,R.jsx)(a,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:o,onPointerDownOutside:l,onFocusOutside:e=>e.preventDefault(),onDismiss:()=>x.onOpenChange(!1),children:(0,R.jsx)(J,{role:`listbox`,id:x.contentId,"data-state":x.open?`open`:`closed`,dir:x.dir,onContextMenu:e=>e.preventDefault(),...b,...se,onPlaced:()=>re(!0),ref:O,style:{display:`flex`,flexDirection:`column`,outline:`none`,...b.style},onKeyDown:c(b.onKeyDown,e=>{let t=e.ctrlKey||e.altKey||e.metaKey;if(e.key===`Tab`&&e.preventDefault(),!t&&e.key.length===1&&G(e.key),[`ArrowUp`,`ArrowDown`,`Home`,`End`].includes(e.key)){let t=M().filter(e=>!e.disabled).map(e=>e.ref.current);if([`ArrowUp`,`End`].includes(e.key)&&(t=t.slice().reverse()),[`ArrowUp`,`ArrowDown`].includes(e.key)){let n=e.target,r=t.indexOf(n);t=t.slice(r+1)}setTimeout(()=>z(t)),e.preventDefault()}})})})})})})},`SelectContentImpl`)),Te=I.forwardRef(B(function(e,t){let{__scopeSelect:n,onPlaced:r,...i}=e,a=Y(X,n),c=Q(X,n),[l,d]=I.useState(null),[f,p]=I.useState(null),m=s(t,p),h=K(n),g=I.useRef(!1),_=I.useRef(!0),{viewport:v,selectedItem:y,selectedItemText:b,focusSelectedItem:x}=c,S=I.useCallback(()=>{if(a.trigger&&a.valueNode&&l&&f&&v&&y&&b){let e=a.trigger.getBoundingClientRect(),t=f.getBoundingClientRect(),n=a.valueNode.getBoundingClientRect(),i=b.getBoundingClientRect();if(a.dir!==V.RTL){let r=i.left-t.left,a=n.left-r,o=e.left-a,s=e.width+o,c=Math.max(s,t.width),u=window.innerWidth-Z,d=O(a,[Z,Math.max(Z,u-c)]);l.style.minWidth=s+`px`,l.style.left=d+`px`}else{let r=t.right-i.right,a=window.innerWidth-n.right-r,o=window.innerWidth-e.right-a,s=e.width+o,c=Math.max(s,t.width),u=window.innerWidth-Z,d=O(a,[Z,Math.max(Z,u-c)]);l.style.minWidth=s+`px`,l.style.right=d+`px`}let o=h(),s=window.innerHeight-Z*2,c=v.scrollHeight,u=window.getComputedStyle(f),d=parseInt(u.borderTopWidth,10),p=parseInt(u.paddingTop,10),m=parseInt(u.borderBottomWidth,10),_=parseInt(u.paddingBottom,10),x=d+p+c+_+m,S=Math.min(y.offsetHeight*5,x),C=window.getComputedStyle(v),w=parseInt(C.paddingTop,10),T=parseInt(C.paddingBottom,10),E=e.top+e.height/2-Z,ee=s-E,D=y.offsetHeight/2,te=y.offsetTop+D,k=d+p+te,A=x-k;if(k<=E){let e=o.length>0&&y===o[o.length-1].ref.current;l.style.bottom=`0px`;let t=f.clientHeight-v.offsetTop-v.offsetHeight,n=k+Math.max(ee,D+(e?T:0)+t+m);l.style.height=n+`px`}else{let e=o.length>0&&y===o[0].ref.current;l.style.top=`0px`;let t=Math.max(E,d+v.offsetTop+(e?w:0)+D)+A;l.style.height=t+`px`,v.scrollTop=k-E+v.offsetTop}l.style.margin=`${Z}px 0`,l.style.minHeight=S+`px`,l.style.maxHeight=s+`px`,r?.(),requestAnimationFrame(()=>g.current=!0)}},[h,a.trigger,a.valueNode,l,f,v,y,b,a.dir,r]);u(()=>S(),[S]);let[C,w]=I.useState();u(()=>{f&&w(window.getComputedStyle(f).zIndex)},[f]);let T=I.useCallback(e=>{e&&_.current===!0&&(S(),x?.(),_.current=!1)},[S,x]);return(0,R.jsx)(De,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:g,onScrollButtonChange:T,children:(0,R.jsx)(`div`,{ref:d,style:{display:`flex`,flexDirection:`column`,position:`fixed`,zIndex:C},children:(0,R.jsx)(o.div,{...i,ref:m,style:{boxSizing:`border-box`,maxHeight:`100%`,...i.style}})})})},`SelectItemAlignedPosition`)),Ee=I.forwardRef(B(function(e,t){let{__scopeSelect:n,align:r=`start`,collisionPadding:i=Z,...a}=e,o=J(n);return(0,R.jsx)(g,{...o,...a,ref:t,align:r,collisionPadding:i,style:{boxSizing:`border-box`,...a.style,"--radix-select-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-select-content-available-width":`var(--radix-popper-available-width)`,"--radix-select-content-available-height":`var(--radix-popper-available-height)`,"--radix-select-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-select-trigger-height":`var(--radix-popper-anchor-height)`}})},`SelectPopperPosition`)),[De,Oe]=q(X,{}),ke=`SelectViewport`,Ae=I.forwardRef(B(function(e,t){let{__scopeSelect:n,nonce:r,...i}=e,a=Q(ke,n),l=Oe(ke,n),u=s(t,a.onViewportChange),d=I.useRef(0);return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`style`,{dangerouslySetInnerHTML:{__html:`[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}`},nonce:r}),(0,R.jsx)(G.Slot,{scope:n,children:(0,R.jsx)(o.div,{"data-radix-select-viewport":``,role:`presentation`,...i,ref:u,style:{position:`relative`,flex:1,overflow:`hidden auto`,...i.style},onScroll:c(i.onScroll,e=>{let t=e.currentTarget,{contentWrapper:n,shouldExpandOnScrollRef:r}=l;if(r?.current&&n){let e=Math.abs(d.current-t.scrollTop);if(e>0){let r=window.innerHeight-Z*2,i=parseFloat(n.style.minHeight),a=parseFloat(n.style.height),o=Math.max(i,a);if(o<r){let i=o+e,a=Math.min(r,i),s=i-a;n.style.height=a+`px`,n.style.bottom===`0px`&&(t.scrollTop=s>0?s:0,n.style.justifyContent=`flex-end`)}}}d.current=t.scrollTop})})})]})},`SelectViewport`)),[je,Me]=q(`SelectGroup`),Ne=`SelectLabel`,Pe=I.forwardRef(B(function(e,t){let{__scopeSelect:n,...r}=e,i=Me(Ne,n);return(0,R.jsx)(o.div,{id:i.id,...r,ref:t})},`SelectLabel`)),Fe=`SelectItem`,[Ie,Le]=q(Fe),Re=I.forwardRef(B(function(e,t){let{__scopeSelect:n,value:r,disabled:i=!1,textValue:a,...u}=e,d=Y(Fe,n),p=Q(Fe,n),m=d.value===r,[h,g]=I.useState(a??``),[_,v]=I.useState(!1),y=f(e=>p.itemRefCallback?.(e,r,i)),b=s(t,y),x=l(),S=I.useRef(`touch`);function C(e){d.hasConsumerStoppedPropagationRef.current=e.isPropagationStopped(),d.onUserSelect(r),d.onOpenChange(!1)}return B(C,`handleSelect`),(0,R.jsx)(Ie,{scope:n,value:r,disabled:i,textId:x,isSelected:m,onItemTextChange:I.useCallback(e=>{g(t=>t||(e?.textContent??``).trim())},[]),children:(0,R.jsx)(G.ItemSlot,{scope:n,value:r,disabled:i,textValue:h,children:(0,R.jsx)(o.div,{role:`option`,"aria-labelledby":x,"data-highlighted":_?``:void 0,"aria-selected":m&&_,"data-state":m?`checked`:`unchecked`,"aria-disabled":i||void 0,"data-disabled":i?``:void 0,tabIndex:i?void 0:-1,...u,ref:b,onFocus:c(u.onFocus,()=>v(!0)),onBlur:c(u.onBlur,()=>v(!1)),onClick:c(u.onClick,e=>{i||S.current!==`mouse`&&C(e)}),onPointerUp:c(u.onPointerUp,e=>{i||S.current===`mouse`&&C(e)}),onPointerDown:c(u.onPointerDown,e=>{S.current=e.pointerType}),onPointerMove:c(u.onPointerMove,e=>{S.current=e.pointerType,i?p.onItemLeave?.():S.current===`mouse`&&e.currentTarget.focus({preventScroll:!0})}),onPointerLeave:c(u.onPointerLeave,e=>{e.currentTarget===document.activeElement&&p.onItemLeave?.()}),onKeyDown:c(u.onKeyDown,e=>{i||e.target!==e.currentTarget||(p.searchRef?.current===``||e.key!==` `)&&(U.includes(e.key)&&C(e),e.key===` `&&e.preventDefault())})})})})},`SelectItem`)),ze=`SelectItemText`,Be=I.forwardRef(B(function(e,t){let{__scopeSelect:n,className:r,style:i,...a}=e,c=Y(ze,n),l=Q(ze,n),d=Le(ze,n),p=le(ze,n),[m,h]=I.useState(null),g=f(e=>l.itemTextRefCallback?.(e,d.value,d.disabled)),_=s(t,h,d.onItemTextChange,g),v=m?.textContent,y=I.useMemo(()=>(0,R.jsx)(`option`,{value:d.value,disabled:d.disabled,children:v},d.value),[d.disabled,d.value,v]),{onNativeOptionAdd:b,onNativeOptionRemove:x}=p;return u(()=>(b(y),()=>x(y)),[b,x,y]),(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(o.span,{id:d.textId,...a,ref:_}),d.isSelected&&c.valueNode&&!c.valueNodeHasChildren&&!$(c.value)?L.createPortal(a.children,c.valueNode):null]})},`SelectItemText`)),Ve=`SelectItemIndicator`,He=I.forwardRef(B(function(e,t){let{__scopeSelect:n,...r}=e;return Le(Ve,n).isSelected?(0,R.jsx)(o.span,{"aria-hidden":!0,...r,ref:t}):null},`SelectItemIndicator`)),Ue=`SelectScrollUpButton`,We=I.forwardRef(B(function(e,t){let n=Q(Ue,e.__scopeSelect),r=Oe(Ue,e.__scopeSelect),[i,a]=I.useState(!1),o=s(t,r.onScrollButtonChange);return u(()=>{if(n.viewport&&n.isPositioned){let e=function(){let e=t.scrollTop>0;a(e)};B(e,`handleScroll`);let t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,R.jsx)(qe,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop-=t.offsetHeight)}}):null},`SelectScrollUpButton`)),Ge=`SelectScrollDownButton`,Ke=I.forwardRef(B(function(e,t){let n=Q(Ge,e.__scopeSelect),r=Oe(Ge,e.__scopeSelect),[i,a]=I.useState(!1),o=s(t,r.onScrollButtonChange);return u(()=>{if(n.viewport&&n.isPositioned){let e=function(){let e=t.scrollHeight-t.clientHeight,n=Math.ceil(t.scrollTop)<e;a(n)};B(e,`handleScroll`);let t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,R.jsx)(qe,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop+=t.offsetHeight)}}):null},`SelectScrollDownButton`)),qe=I.forwardRef(B(function(e,t){let{__scopeSelect:n,onAutoScroll:r,...i}=e,a=Q(`SelectScrollButton`,n),s=I.useRef(null),l=K(n),d=I.useCallback(()=>{s.current!==null&&(window.clearInterval(s.current),s.current=null)},[]);return I.useEffect(()=>()=>d(),[d]),u(()=>{l().find(e=>e.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:`nearest`})},[l]),(0,R.jsx)(o.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:c(i.onPointerDown,()=>{s.current===null&&(s.current=window.setInterval(r,50))}),onPointerMove:c(i.onPointerMove,()=>{a.onItemLeave?.(),s.current===null&&(s.current=window.setInterval(r,50))}),onPointerLeave:c(i.onPointerLeave,()=>{d()})})},`SelectScrollButtonImpl`)),Je=I.forwardRef(B(function(e,t){let{__scopeSelect:n,...r}=e;return(0,R.jsx)(o.div,{"aria-hidden":!0,...r,ref:t})},`SelectSeparator`)),Ye=`SelectBubbleInput`,Xe=I.forwardRef(B(function({__scopeSelect:e,...t},n){let r=Y(Ye,e),{value:i,onValueChange:a,required:c,disabled:l,name:u,autoComplete:d,form:f,userSelection:p}=r,{nativeOptions:h,nativeSelectKey:g}=r,_=I.useRef(null),v=s(n,_),y=i??``,b=I.useRef(y),x=I.useRef(p),S=I.useRef(!1),C=Array.from(h).some(e=>(e.props.value??``)===``);return I.useEffect(()=>{let e=_.current;if(!e)return;let t=window.HTMLSelectElement.prototype,n=Object.getOwnPropertyDescriptor(t,`value`).set,r=p!==null&&p!==x.current;x.current=p;let i=b.current!==y;b.current=y;let a=r&&i;if(r&&!i&&p.value!==y&&!p.hasConsumerStoppedPropagation&&n){S.current=!0;try{n.call(e,p.value),e.dispatchEvent(new Event(`change`,{bubbles:!0}))}finally{S.current=!1,n.call(e,y)}return}let o=a&&!p.hasConsumerStoppedPropagation;if(i&&n){let t=new Event(`change`,{bubbles:o});n.call(e,y),e.dispatchEvent(t)}},[y,p]),(0,R.jsxs)(o.select,{"aria-hidden":!0,required:c,tabIndex:-1,name:u,autoComplete:d,disabled:l,form:f,onChange:e=>{S.current||a(e.target.value)},...t,style:{...m,...t.style},ref:v,defaultValue:y,children:[$(i)&&!C?(0,R.jsx)(`option`,{value:``}):null,Array.from(h)]},g)},`SelectBubbleInput`));function Ze(e){return typeof e==`function`}B(Ze,`isFunction`);function $(e){return e===``||e===void 0}B($,`shouldShowPlaceholder`);function Qe(e){let t=f(e),n=I.useRef(``),r=I.useRef(0),i=I.useCallback(e=>{let i=n.current+e;t(i);function a(e){n.current=e,window.clearTimeout(r.current),e!==``&&(r.current=window.setTimeout(()=>a(``),1e3))}B(a,`updateSearch`),a(i)},[t]),a=I.useCallback(()=>{n.current=``,window.clearTimeout(r.current)},[]);return I.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,a]}B(Qe,`useTypeaheadSearch`);function $e(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,a=et(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.textValue.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}B($e,`findNextItem`);function et(e,t){return e.map((n,r)=>e[(t+r)%e.length])}B(et,`wrapArray`);var tt={name:`chevron-up`,size:24,node:[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]};tt.node;var nt=k(tt),rt=de,it=he,at=I.forwardRef(({className:e,children:t,...n},r)=>(0,R.jsxs)(pe,{ref:r,className:y(`form-control form-control-single select-trigger flex items-center justify-between gap-2 text-start data-placeholder:text-muted-foreground [&>span]:min-w-0 [&>span]:truncate`,e),...n,children:[t,(0,R.jsx)(ge,{asChild:!0,children:(0,R.jsx)(j,{className:`select-chevron shrink-0 text-muted-foreground`,strokeWidth:1.5,"aria-hidden":`true`})})]}));at.displayName=pe.displayName;var ot=I.forwardRef(({className:e,...t},n)=>(0,R.jsx)(We,{ref:n,className:y(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,R.jsx)(nt,{className:`h-4 w-4`})}));ot.displayName=We.displayName;var st=I.forwardRef(({className:e,...t},n)=>(0,R.jsx)(Ke,{ref:n,className:y(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,R.jsx)(j,{className:`h-4 w-4`})}));st.displayName=Ke.displayName;var ct=I.forwardRef(({className:e,children:t,position:n=`popper`,...r},i)=>(0,R.jsx)(ye,{children:(0,R.jsxs)(be,{ref:i,className:y(`relative z-50 max-h-(--radix-select-content-available-height) min-w-32 overflow-y-auto overflow-x-hidden rounded-md border border-control-border bg-surface-high text-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-(--radix-select-content-transform-origin) `,n===`popper`&&`data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1`,e),position:n,...r,children:[(0,R.jsx)(ot,{}),(0,R.jsx)(Ae,{className:y(`p-1`,n===`popper`&&`h-(--radix-select-trigger-height) w-full min-w-(--radix-select-trigger-width)`),children:t}),(0,R.jsx)(st,{})]})}));ct.displayName=be.displayName;var lt=I.forwardRef(({className:e,...t},n)=>(0,R.jsx)(Pe,{ref:n,className:y(`py-1.5 pl-8 pr-2 text-sm font-semibold`,e),...t}));lt.displayName=Pe.displayName;var ut=I.forwardRef(({className:e,children:t,...n},r)=>(0,R.jsxs)(Re,{ref:r,className:y(`relative flex min-h-8 w-full cursor-default select-none items-center rounded-xs py-1.5 pl-8 pr-2 text-sm outline-hidden focus:bg-muted focus:text-foreground data-disabled:pointer-events-none data-disabled:opacity-50 max-md:min-h-11 pointer-coarse:min-h-11`,e),...n,children:[(0,R.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,R.jsx)(He,{children:(0,R.jsx)(A,{className:`h-4 w-4`})})}),(0,R.jsx)(Be,{children:t})]}));ut.displayName=Re.displayName;var dt=I.forwardRef(({className:e,...t},n)=>(0,R.jsx)(Je,{ref:n,className:y(`-mx-1 my-1 h-px bg-muted `,e),...t}));dt.displayName=Je.displayName;function ft(e){return e.open?(0,R.jsx)(pt,{...e}):null}function pt({open:e,dirty:t,busy:n=!1,onClose:r,onDiscard:a,testId:o=`form-dialog`,className:s,children:c}){let[l,u]=(0,I.useState)(!1),d=(0,I.useId)(),f=(0,I.useRef)(null),p=(0,I.useRef)(!1),m=(0,I.useRef)(!1),h=(0,I.useRef)(null),g=(0,I.useRef)(null),_=(0,I.useRef)(!1),v=i(()=>e&&(t||n)&&!_.current);(0,I.useEffect)(()=>{if(n)return;let e=g.current?.querySelector(`[role="alert"]`);e instanceof HTMLElement&&e.scrollIntoView({block:`nearest`})},[n]),(0,I.useEffect)(()=>{v.state===`blocked`&&(p.current=!1,u(!0))},[v.state]),(0,I.useEffect)(()=>{if(!e||!t&&!n)return;let r=e=>{_.current||(e.preventDefault(),e.returnValue=``)};return window.addEventListener(`beforeunload`,r),()=>window.removeEventListener(`beforeunload`,r)},[e,t,n]);let b=()=>{v.state===`blocked`&&v.reset(),u(!1)},x=()=>{_.current=!0,v.state===`blocked`&&v.reset(),r()};e&&!m.current&&(h.current=document.activeElement instanceof HTMLElement?document.activeElement:null),m.current=e;let C=()=>{n||(t?(p.current=!1,u(!0)):r())};return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(F,{open:e,onOpenChange:e=>!e&&C(),children:(0,R.jsx)(N,{ref:g,"data-testid":o,closeDisabled:n,"aria-busy":n,className:y(`work-form-dialog flex w-[min(960px,calc(100vw-3rem))] max-w-none flex-col gap-0 overflow-hidden p-0 max-sm:h-[var(--app-height,100dvh)] max-sm:max-h-[var(--app-height,100dvh)] max-sm:w-full max-sm:rounded-none max-sm:border-0`,s),onCloseAutoFocus:e=>{h.current?.isConnected&&(e.preventDefault(),h.current.focus())},children:c(C,x)})}),(0,R.jsx)(F,{open:l,onOpenChange:e=>e?u(!0):b(),children:(0,R.jsxs)(N,{className:`max-w-sm`,"aria-describedby":d,onOpenAutoFocus:e=>{e.preventDefault(),f.current?.focus()},onCloseAutoFocus:e=>{p.current&&h.current?.isConnected&&(e.preventDefault(),h.current.focus())},children:[(0,R.jsxs)(ne,{children:[(0,R.jsx)(re,{children:`Discard changes?`}),(0,R.jsx)(P,{id:d,children:n?`Saving changes. Wait for this operation to finish.`:`Your form has unsaved changes.`})]}),(0,R.jsxs)(M,{children:[(0,R.jsx)(S,{variant:`ghost`,"data-testid":`discard-form-changes`,disabled:n,onClick:()=>{p.current=!0,_.current=!0,u(!1),a?.(),r(),v.state===`blocked`&&v.proceed()},children:`Discard changes`}),(0,R.jsx)(S,{ref:f,"data-testid":`keep-editing`,onClick:b,children:`Keep editing`})]})]})})]})}export{at as a,ut as i,rt as n,it as o,ct as r,ft as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e}from"./rolldown-runtime-DSDNlrLa.js";import{n as t,t as n}from"./jsx-runtime-CVMpzJz9.js";import{m as r,p as i,t as a}from"./chunk-OB3PAWPO-1IihCzFx.js";import{c as o,y as s}from"./useIntegrations-Dw2tGWu6.js";import{t as c}from"./circle-check-BY2n9ZCv.js";var l=e(t(),1),u=n(),d=`/settings?settingsSection=integrations&integrationsTab=connections`;function f(){let{name:e=``}=i(),[t]=r(),n=o(),f=t.get(`code`),p=t.get(`state`),m=t.get(`error_description`)??t.get(`error`),h=(0,l.useRef)(!1);(0,l.useEffect)(()=>{!h.current&&f&&p&&(h.current=!0,n.mutate({name:e,code:f,state:p}))},[n,e,f,p]);let g=m??(!f||!p?`The sign-in response is missing its code.`:n.error?.message);return(0,u.jsxs)(`main`,{className:`mx-auto max-w-md p-6`,"data-testid":`integration-callback`,children:[(0,u.jsxs)(`h1`,{className:`mb-3 font-headline text-base`,children:[`Sign in to `,e]}),g?(0,u.jsxs)(`p`,{role:`alert`,className:`flex gap-2 text-sm text-error`,children:[(0,u.jsx)(s,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,u.jsx)(`span`,{className:`min-w-0 wrap-break-word`,children:g})]}):n.isSuccess?(0,u.jsxs)(`p`,{role:`status`,className:`flex gap-2 text-sm`,children:[(0,u.jsx)(c,{className:`mt-0.5 size-4 shrink-0 text-success`,"aria-hidden":!0}),`Signed in. ORC and the `,(0,u.jsx)(`code`,{children:`spec`}),` CLI now use this connection's tokens.`]}):(0,u.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:`Finishing sign-in…`}),(0,u.jsx)(a,{to:d,className:`mt-4 inline-block text-sm text-primary underline`,children:`Back to connections`})]})}export{f as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./rolldown-runtime-DSDNlrLa.js";import{n as t,t as n}from"./jsx-runtime-CVMpzJz9.js";import{n as r}from"./QueryClientProvider-DlPztvhd.js";import{n as i,t as a}from"./useMutation-HX90wI4L.js";import{t as o}from"./chunk-OB3PAWPO-1IihCzFx.js";import{t as s}from"./button-CXYVslgR.js";import{t as c}from"./label-wk_QKooL.js";import{a as l,n as u}from"./client-nzMXason.js";import{It as d}from"./index-C60WCVxH.js";import{t as f}from"./ErrorState-BrKz7Mii.js";import{l as p}from"./useJobs-B2da-s4n.js";var m=e(t(),1);function h(e){return i({queryKey:[`webhooks`,e],queryFn:()=>u.webhooks.list(e),select:e=>e.webhooks})}function g(e){return i({queryKey:[`webhook-deliveries`,e],queryFn:()=>u.webhooks.deliveries(e),select:e=>e.deliveries,enabled:!!e,refetchInterval:3e3})}function _(){let e=r();return a({mutationFn:e=>u.webhooks.create(e),onSuccess:()=>e.invalidateQueries({queryKey:[`webhooks`]})})}function v(){let e=r();return a({mutationFn:({id:e,...t})=>u.webhooks.update(e,t),onSuccess:()=>e.invalidateQueries({queryKey:[`webhooks`]})})}function y(){let e=r();return a({mutationFn:e=>u.webhooks.delete(e),onSuccess:()=>e.invalidateQueries({queryKey:[`webhooks`]})})}function b(){return a({mutationFn:e=>u.webhooks.rotate(e)})}function x(e){return[...new Set(e.split(`,`).map(e=>e.trim()).filter(Boolean))]}function S(e,t,n){return new URL(`/webhooks/${encodeURIComponent(e)}`,new URL(t,n)).href}function C(e){return[`localhost`,`127.0.0.1`,`[::1]`].includes(new URL(e).hostname)}var w=n();function T({id:e,testId:t,value:n,onChange:r,placeholder:i}){let[a,o]=(0,m.useState)(n.join(`, `));return(0,w.jsx)(d,{id:e,"data-testid":t,value:a,placeholder:i,onChange:e=>{o(e.target.value),r(e.target.value)}})}function E({projectId:e,onCreated:t}){let n=_(),[r,i]=(0,m.useState)(``),[a,o]=(0,m.useState)(`github`),[l,u]=(0,m.useState)(null),f=(0,m.useId)();return l?(0,w.jsxs)(`div`,{"data-testid":`webhook-created`,className:`space-y-3`,children:[(0,w.jsx)(A,{hook:l,secret:l.secret}),(0,w.jsx)(s,{type:`button`,variant:`outline`,"data-testid":`webhook-setup-done`,onClick:()=>{t?.(l),u(null),i(``)},children:`I've copied the setup details`})]}):(0,w.jsxs)(`div`,{className:`space-y-3`,"data-testid":`webhook-create-form`,children:[(0,w.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,w.jsx)(c,{htmlFor:`${f}-name`,children:`Webhook name`}),(0,w.jsx)(d,{id:`${f}-name`,"data-testid":`webhook-name`,value:r,onChange:e=>i(e.target.value),maxLength:100,placeholder:`GitHub repository events`})]}),(0,w.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,w.jsx)(c,{htmlFor:`${f}-provider`,children:`Provider`}),(0,w.jsxs)(`select`,{id:`${f}-provider`,"data-testid":`webhook-provider`,className:`w-full min-h-8 rounded-md border border-control-border bg-background px-3 text-sm`,value:a,onChange:e=>o(e.target.value),children:[(0,w.jsx)(`option`,{value:`github`,children:`GitHub`}),(0,w.jsx)(`option`,{value:`generic`,children:`Other service (HMAC)`})]})]}),(0,w.jsx)(`p`,{className:`text-xs text-outline`,children:`Create the event source here. Connect jobs and choose their event filters in Jobs. No job is required to create a webhook.`}),n.error&&(0,w.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:n.error.message}),(0,w.jsx)(s,{type:`button`,"data-testid":`webhook-create`,disabled:!r.trim()||n.isPending,onClick:()=>n.mutate({name:r.trim(),provider:a,project_id:e??null},{onSuccess:u}),children:n.isPending?`Creating...`:`Create webhook`})]})}function D({value:e,onChange:t,projectId:n}){let{data:r,error:i,isLoading:a,refetch:o}=h(n),l=r?.filter(e=>e.project_id===null||e.project_id===n),[u,d]=(0,m.useState)(!1);function p(n){e.some(e=>e.webhook_id===n)||t([...e,{webhook_id:n,events:[],actions:[]}])}function g(n,r,i){t(e.map(e=>e.webhook_id===n?{...e,[r]:x(i)}:e))}return(0,w.jsxs)(`section`,{className:`space-y-3 border-y border-border py-4`,"data-testid":`job-webhook-picker`,children:[(0,w.jsx)(`h3`,{className:`text-sm font-medium`,children:`Which webhook should trigger this job?`}),i?(0,w.jsx)(f,{message:i.message,onRetry:()=>o()}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(c,{htmlFor:`job-webhook-source`,children:`Configured webhooks`}),(0,w.jsxs)(`select`,{id:`job-webhook-source`,"data-testid":`job-webhook-select`,className:`w-full min-h-8 rounded-md border border-control-border bg-background px-3 text-sm`,value:``,disabled:a,onChange:e=>{e.target.value&&p(e.target.value)},children:[(0,w.jsx)(`option`,{value:``,children:a?`Loading webhooks...`:`Select an existing webhook`}),(l??[]).filter(t=>!e.some(e=>e.webhook_id===t.id)).map(e=>(0,w.jsxs)(`option`,{value:e.id,children:[e.name,e.enabled?``:` (disabled)`]},e.id))]}),!a&&!l?.length&&(0,w.jsx)(`p`,{className:`text-xs text-outline`,children:`No webhooks configured for this project yet. Create one below or on the Webhooks page.`})]}),e.map(n=>(0,w.jsxs)(`div`,{className:`space-y-2 border-t border-border pt-3`,"data-testid":`job-webhook-binding`,"data-webhook-id":n.webhook_id,children:[(0,w.jsxs)(`div`,{className:`flex justify-between gap-2`,children:[(0,w.jsx)(`span`,{className:`text-sm font-medium`,children:l?.find(e=>e.id===n.webhook_id)?.name??n.webhook_id}),(0,w.jsx)(s,{type:`button`,variant:`ghost`,size:`sm`,"data-testid":`job-webhook-remove`,onClick:()=>t(e.filter(e=>e.webhook_id!==n.webhook_id)),children:`Disconnect`})]}),(0,w.jsx)(c,{htmlFor:`events-${n.webhook_id}`,children:`Events for this job`}),(0,w.jsx)(T,{id:`events-${n.webhook_id}`,testId:`webhook-events`,value:n.events,onChange:e=>g(n.webhook_id,`events`,e),placeholder:`pull_request, push (blank accepts all)`}),(0,w.jsx)(c,{htmlFor:`actions-${n.webhook_id}`,children:`Actions for this job (optional)`}),(0,w.jsx)(T,{id:`actions-${n.webhook_id}`,testId:`webhook-actions`,value:n.actions,onChange:e=>g(n.webhook_id,`actions`,e),placeholder:`opened, synchronize (blank accepts all)`})]},n.webhook_id)),(0,w.jsx)(s,{type:`button`,size:`sm`,variant:`outline`,"data-testid":`webhook-add`,onClick:()=>d(!u),children:u?`Close new webhook`:`Create a webhook`}),u&&(0,w.jsx)(E,{projectId:n,onCreated:e=>{p(e.id),d(!1)}})]})}function O({job:e}){let t=p(),[n,r]=(0,m.useState)(e.webhooks??[]);return(0,w.jsxs)(`section`,{className:`space-y-3`,"data-testid":`job-webhooks`,children:[!e.enabled&&(0,w.jsx)(`p`,{className:`text-sm text-outline`,children:`Job disabled. Configure connections now and enable it from Jobs when ready.`}),(0,w.jsx)(D,{value:n,onChange:r,projectId:e.project_id??void 0}),t.error&&(0,w.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:t.error.message}),(0,w.jsx)(s,{type:`button`,size:`sm`,"data-testid":`job-webhooks-save`,disabled:t.isPending,onClick:()=>t.mutate({id:e.id,webhooks:n,trigger_type:`webhook`}),children:`Save connections`}),t.isSuccess&&(0,w.jsx)(`p`,{role:`status`,className:`text-xs text-outline`,children:`Connections saved.`}),(0,w.jsx)(o,{className:`inline-block text-sm underline`,to:`/webhooks?project=${encodeURIComponent(e.project_id??`all`)}`,children:`Manage configured webhooks and deliveries`})]})}function k({label:e,value:t,secret:n=!1}){let[r,i]=(0,m.useState)(!1),[a,o]=(0,m.useState)(!1);return(0,w.jsxs)(`div`,{className:`space-y-1`,children:[(0,w.jsx)(`p`,{className:`text-xs text-outline`,children:e}),(0,w.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,w.jsx)(`code`,{className:`min-w-0 flex-1 break-all text-xs`,"data-testid":n?`webhook-secret`:`webhook-url`,children:t}),(0,w.jsx)(s,{type:`button`,size:`sm`,variant:`outline`,"aria-label":`Copy ${e}`,onClick:async()=>{try{await navigator.clipboard.writeText(t),i(!0),o(!1)}catch{o(!0)}},children:r?`Copied`:`Copy`})]}),a&&(0,w.jsx)(`p`,{role:`alert`,className:`text-xs text-error`,children:`Select and copy the value above; clipboard access is unavailable.`})]})}function A({hook:e,secret:t,showInstructions:n=!0,instructionsId:r}){let i=S(e.token,l(),window.location.origin);return(0,w.jsxs)(`div`,{className:`space-y-3`,"data-testid":`webhook-setup`,children:[(0,w.jsx)(k,{label:`Payload URL`,value:i}),C(i)&&(0,w.jsx)(`p`,{className:`text-sm text-warning`,children:`This address is local. For external providers, use your publicly reachable ORC address with the same /webhooks/ path.`}),n&&(0,w.jsxs)(`div`,{id:r,"data-testid":`webhook-setup-instructions`,className:`space-y-3`,children:[t?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(k,{label:`Signing secret`,value:t,secret:!0}),(0,w.jsx)(`p`,{className:`text-xs text-outline`,children:`Copy the signing secret before leaving. It is shown once.`})]}):(0,w.jsx)(`p`,{className:`text-xs text-outline`,children:`The signing secret is hidden. Generate a replacement only if you need to reconnect the sender.`}),e.provider===`github`?(0,w.jsxs)(`ol`,{className:`list-decimal space-y-1 pl-5 text-sm text-outline`,children:[(0,w.jsx)(`li`,{children:`In your repository, open GitHub Settings - Webhooks - Add webhook.`}),(0,w.jsx)(`li`,{children:`Paste the Payload URL, select application/json, and enter the signing secret.`}),(0,w.jsx)(`li`,{children:`Select the events needed by your connected jobs. Each job has its own filters.`}),(0,w.jsx)(`li`,{children:`Send a test event, then open Recent deliveries for this webhook.`})]}):(0,w.jsx)(`p`,{className:`text-sm text-outline`,children:`Send JSON, signed with HMAC-SHA256 of the raw body. Set X-Orc-Signature-256 to sha256=<hex signature>, X-Orc-Event to the event name and X-Orc-Delivery to a unique delivery ID.`})]})]})}function j({hook:e}){let t=v(),n=b(),[r,i]=(0,m.useState)(!1),[a,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(!1),[d,f]=(0,m.useState)(),p=(0,m.useId)();return(0,w.jsxs)(`article`,{className:`space-y-3 border-b border-border pb-5`,"data-testid":`webhook-endpoint`,"data-webhook-id":e.id,children:[(0,w.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,w.jsx)(`h3`,{className:`text-sm font-medium`,children:e.name}),(0,w.jsxs)(`span`,{className:`text-xs text-outline`,children:[e.provider,` - `,e.enabled?`Enabled`:`Disabled`]}),(0,w.jsx)(s,{type:`button`,variant:`outline`,size:`sm`,disabled:t.isPending,onClick:()=>t.mutate({id:e.id,enabled:!e.enabled}),children:e.enabled?`Disable`:`Enable`})]}),(0,w.jsxs)(`div`,{className:`space-y-1`,"data-testid":`webhook-connected-jobs`,children:[(0,w.jsxs)(`p`,{className:`text-xs text-outline`,children:[`Connected jobs (`,e.subscriptions.length,`)`]}),e.subscriptions.length?e.subscriptions.map(e=>(0,w.jsxs)(`div`,{className:`text-sm`,children:[(0,w.jsx)(o,{className:`underline`,"data-testid":`webhook-job-link`,to:`/jobs/${e.job_id}?project=all`,children:e.name}),(0,w.jsxs)(`span`,{className:`text-xs text-outline`,children:[` `,`- `,e.enabled?`Enabled`:`Disabled`,`; events:`,` `,e.events.join(`, `)||`all`,`; actions:`,` `,e.actions.join(`, `)||`all`]})]},e.job_id)):null]}),(0,w.jsx)(A,{hook:e,secret:d,showInstructions:a,instructionsId:p}),(0,w.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,w.jsx)(s,{type:`button`,variant:`outline`,size:`sm`,"data-testid":`webhook-deliveries-toggle`,onClick:()=>i(!r),children:r?`Hide deliveries`:`Recent deliveries`}),(0,w.jsx)(s,{type:`button`,variant:`ghost`,size:`sm`,"data-testid":`webhook-setup-toggle`,"aria-expanded":a,"aria-controls":a?p:void 0,disabled:n.isPending,onClick:()=>{a&&f(void 0),c(!a),u(!1)},children:a?d?`I've copied the setup details`:`Hide setup`:`Setup instructions`})]}),a&&(0,w.jsx)(s,{type:`button`,variant:`ghost`,size:`sm`,disabled:n.isPending,onClick:()=>u(!l),children:`New signing secret`}),a&&l&&(0,w.jsxs)(`div`,{className:`space-y-2 text-sm`,children:[(0,w.jsx)(`p`,{children:`The sender's existing secret will stop working. Update it after generating the replacement.`}),(0,w.jsx)(s,{type:`button`,variant:`outline`,size:`sm`,disabled:n.isPending,onClick:()=>n.mutate(e.id,{onSuccess:e=>{f(e.secret),c(!0),u(!1)}}),children:`Generate replacement secret`})]}),(t.error||n.error)&&(0,w.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:(t.error??n.error)?.message}),r&&(0,w.jsx)(M,{id:e.id})]})}function M({id:e}){let{data:t,isLoading:n,error:r,refetch:i}=g(e);return(0,w.jsxs)(`section`,{className:`space-y-2`,"data-testid":`webhook-deliveries`,children:[(0,w.jsx)(`h4`,{className:`text-sm font-medium`,children:`Recent deliveries`}),r?(0,w.jsx)(f,{message:r.message,onRetry:()=>i()}):n?(0,w.jsx)(`p`,{role:`status`,children:`Loading deliveries...`}):t?.length?t.map(e=>(0,w.jsxs)(`div`,{className:`space-y-1 border-t border-border py-2 text-xs`,"data-testid":`webhook-delivery`,children:[(0,w.jsxs)(`div`,{className:`flex flex-wrap justify-between gap-2`,children:[(0,w.jsxs)(`span`,{children:[e.event,e.action?` / ${e.action}`:``]}),(0,w.jsx)(`span`,{children:e.status})]}),(0,w.jsxs)(`p`,{className:`text-outline`,children:[e.repository,` `,new Date(e.created_at).toLocaleString()]}),e.status===`ignored`&&(0,w.jsx)(`p`,{className:`text-outline`,children:`No enabled connected job matched this event.`}),e.error&&(0,w.jsx)(`p`,{className:`text-error`,children:e.error}),e.runs.map(e=>(0,w.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,w.jsxs)(o,{className:`underline`,to:`/jobs/${e.job_id}?project=all`,children:[`Job run: `,e.status]}),e.task_id&&(0,w.jsx)(o,{className:`underline`,to:`/tasks/${e.task_id}?project=all`,children:`Created task`}),e.session_id&&(0,w.jsx)(o,{className:`underline`,to:`/audit/${e.session_id}?project=all`,children:`Agent session`})]},e.job_run_id))]},e.id)):(0,w.jsx)(`p`,{className:`text-sm text-outline`,children:`No events received yet. Register the endpoint with your provider, then send an event.`})]})}export{y as a,D as i,E as n,h as o,j as r,O as t};
|
|
1
|
+
import{a as e}from"./rolldown-runtime-DSDNlrLa.js";import{n as t,t as n}from"./jsx-runtime-CVMpzJz9.js";import{n as r}from"./QueryClientProvider-DlPztvhd.js";import{n as i,t as a}from"./useMutation-HX90wI4L.js";import{t as o}from"./chunk-OB3PAWPO-1IihCzFx.js";import{t as s}from"./button-C91mbQEU.js";import{t as c}from"./label-BdnRgBbz.js";import{a as l,n as u}from"./client-BDeNEjHL.js";import{Ft as d}from"./index-D3mYpeGu.js";import{l as f}from"./useJobs-Bt5IQ7lh.js";import{t as p}from"./ErrorState-DprXzfow.js";var m=e(t(),1);function h(e){return i({queryKey:[`webhooks`,e],queryFn:()=>u.webhooks.list(e),select:e=>e.webhooks})}function g(e){return i({queryKey:[`webhook-deliveries`,e],queryFn:()=>u.webhooks.deliveries(e),select:e=>e.deliveries,enabled:!!e,refetchInterval:3e3})}function _(){let e=r();return a({mutationFn:e=>u.webhooks.create(e),onSuccess:()=>e.invalidateQueries({queryKey:[`webhooks`]})})}function v(){let e=r();return a({mutationFn:({id:e,...t})=>u.webhooks.update(e,t),onSuccess:()=>e.invalidateQueries({queryKey:[`webhooks`]})})}function y(){let e=r();return a({mutationFn:e=>u.webhooks.delete(e),onSuccess:()=>e.invalidateQueries({queryKey:[`webhooks`]})})}function b(){return a({mutationFn:e=>u.webhooks.rotate(e)})}function x(e){return[...new Set(e.split(`,`).map(e=>e.trim()).filter(Boolean))]}function S(e,t,n){return new URL(`/webhooks/${encodeURIComponent(e)}`,new URL(t,n)).href}function C(e){return[`localhost`,`127.0.0.1`,`[::1]`].includes(new URL(e).hostname)}var w=n();function T({id:e,testId:t,value:n,onChange:r,placeholder:i}){let[a,o]=(0,m.useState)(n.join(`, `));return(0,w.jsx)(d,{id:e,"data-testid":t,value:a,placeholder:i,onChange:e=>{o(e.target.value),r(e.target.value)}})}function E({projectId:e,onCreated:t}){let n=_(),[r,i]=(0,m.useState)(``),[a,o]=(0,m.useState)(`github`),[l,u]=(0,m.useState)(null),f=(0,m.useId)();return l?(0,w.jsxs)(`div`,{"data-testid":`webhook-created`,className:`space-y-3`,children:[(0,w.jsx)(A,{hook:l,secret:l.secret}),(0,w.jsx)(s,{type:`button`,variant:`outline`,"data-testid":`webhook-setup-done`,onClick:()=>{t?.(l),u(null),i(``)},children:`I've copied the setup details`})]}):(0,w.jsxs)(`div`,{className:`space-y-3`,"data-testid":`webhook-create-form`,children:[(0,w.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,w.jsx)(c,{htmlFor:`${f}-name`,children:`Webhook name`}),(0,w.jsx)(d,{id:`${f}-name`,"data-testid":`webhook-name`,value:r,onChange:e=>i(e.target.value),maxLength:100,placeholder:`GitHub repository events`})]}),(0,w.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,w.jsx)(c,{htmlFor:`${f}-provider`,children:`Provider`}),(0,w.jsxs)(`select`,{id:`${f}-provider`,"data-testid":`webhook-provider`,className:`w-full min-h-8 rounded-md border border-control-border bg-background px-3 text-sm`,value:a,onChange:e=>o(e.target.value),children:[(0,w.jsx)(`option`,{value:`github`,children:`GitHub`}),(0,w.jsx)(`option`,{value:`generic`,children:`Other service (HMAC)`})]})]}),(0,w.jsx)(`p`,{className:`text-xs text-outline`,children:`Create the event source here. Connect jobs and choose their event filters in Jobs. No job is required to create a webhook.`}),n.error&&(0,w.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:n.error.message}),(0,w.jsx)(s,{type:`button`,"data-testid":`webhook-create`,disabled:!r.trim()||n.isPending,onClick:()=>n.mutate({name:r.trim(),provider:a,project_id:e??null},{onSuccess:u}),children:n.isPending?`Creating...`:`Create webhook`})]})}function D({value:e,onChange:t,projectId:n}){let{data:r,error:i,isLoading:a,refetch:o}=h(n),l=r?.filter(e=>e.project_id===null||e.project_id===n),[u,d]=(0,m.useState)(!1);function f(n){e.some(e=>e.webhook_id===n)||t([...e,{webhook_id:n,events:[],actions:[]}])}function g(n,r,i){t(e.map(e=>e.webhook_id===n?{...e,[r]:x(i)}:e))}return(0,w.jsxs)(`section`,{className:`space-y-3 border-y border-border py-4`,"data-testid":`job-webhook-picker`,children:[(0,w.jsx)(`h3`,{className:`text-sm font-medium`,children:`Which webhook should trigger this job?`}),i?(0,w.jsx)(p,{message:i.message,onRetry:()=>o()}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(c,{htmlFor:`job-webhook-source`,children:`Configured webhooks`}),(0,w.jsxs)(`select`,{id:`job-webhook-source`,"data-testid":`job-webhook-select`,className:`w-full min-h-8 rounded-md border border-control-border bg-background px-3 text-sm`,value:``,disabled:a,onChange:e=>{e.target.value&&f(e.target.value)},children:[(0,w.jsx)(`option`,{value:``,children:a?`Loading webhooks...`:`Select an existing webhook`}),(l??[]).filter(t=>!e.some(e=>e.webhook_id===t.id)).map(e=>(0,w.jsxs)(`option`,{value:e.id,children:[e.name,e.enabled?``:` (disabled)`]},e.id))]}),!a&&!l?.length&&(0,w.jsx)(`p`,{className:`text-xs text-outline`,children:`No webhooks configured for this project yet. Create one below or on the Webhooks page.`})]}),e.map(n=>(0,w.jsxs)(`div`,{className:`space-y-2 border-t border-border pt-3`,"data-testid":`job-webhook-binding`,"data-webhook-id":n.webhook_id,children:[(0,w.jsxs)(`div`,{className:`flex justify-between gap-2`,children:[(0,w.jsx)(`span`,{className:`text-sm font-medium`,children:l?.find(e=>e.id===n.webhook_id)?.name??n.webhook_id}),(0,w.jsx)(s,{type:`button`,variant:`ghost`,size:`sm`,"data-testid":`job-webhook-remove`,onClick:()=>t(e.filter(e=>e.webhook_id!==n.webhook_id)),children:`Disconnect`})]}),(0,w.jsx)(c,{htmlFor:`events-${n.webhook_id}`,children:`Events for this job`}),(0,w.jsx)(T,{id:`events-${n.webhook_id}`,testId:`webhook-events`,value:n.events,onChange:e=>g(n.webhook_id,`events`,e),placeholder:`pull_request, push (blank accepts all)`}),(0,w.jsx)(c,{htmlFor:`actions-${n.webhook_id}`,children:`Actions for this job (optional)`}),(0,w.jsx)(T,{id:`actions-${n.webhook_id}`,testId:`webhook-actions`,value:n.actions,onChange:e=>g(n.webhook_id,`actions`,e),placeholder:`opened, synchronize (blank accepts all)`})]},n.webhook_id)),(0,w.jsx)(s,{type:`button`,size:`sm`,variant:`outline`,"data-testid":`webhook-add`,onClick:()=>d(!u),children:u?`Close new webhook`:`Create a webhook`}),u&&(0,w.jsx)(E,{projectId:n,onCreated:e=>{f(e.id),d(!1)}})]})}function O({job:e}){let t=f(),[n,r]=(0,m.useState)(e.webhooks??[]);return(0,w.jsxs)(`section`,{className:`space-y-3`,"data-testid":`job-webhooks`,children:[!e.enabled&&(0,w.jsx)(`p`,{className:`text-sm text-outline`,children:`Job disabled. Configure connections now and enable it from Jobs when ready.`}),(0,w.jsx)(D,{value:n,onChange:r,projectId:e.project_id??void 0}),t.error&&(0,w.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:t.error.message}),(0,w.jsx)(s,{type:`button`,size:`sm`,"data-testid":`job-webhooks-save`,disabled:t.isPending,onClick:()=>t.mutate({id:e.id,webhooks:n,trigger_type:`webhook`}),children:`Save connections`}),t.isSuccess&&(0,w.jsx)(`p`,{role:`status`,className:`text-xs text-outline`,children:`Connections saved.`}),(0,w.jsx)(o,{className:`inline-block text-sm underline`,to:`/webhooks?project=${encodeURIComponent(e.project_id??`all`)}`,children:`Manage configured webhooks and deliveries`})]})}function k({label:e,value:t,secret:n=!1}){let[r,i]=(0,m.useState)(!1),[a,o]=(0,m.useState)(!1);return(0,w.jsxs)(`div`,{className:`space-y-1`,children:[(0,w.jsx)(`p`,{className:`text-xs text-outline`,children:e}),(0,w.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,w.jsx)(`code`,{className:`min-w-0 flex-1 break-all text-xs`,"data-testid":n?`webhook-secret`:`webhook-url`,children:t}),(0,w.jsx)(s,{type:`button`,size:`sm`,variant:`outline`,"aria-label":`Copy ${e}`,onClick:async()=>{try{await navigator.clipboard.writeText(t),i(!0),o(!1)}catch{o(!0)}},children:r?`Copied`:`Copy`})]}),a&&(0,w.jsx)(`p`,{role:`alert`,className:`text-xs text-error`,children:`Select and copy the value above; clipboard access is unavailable.`})]})}function A({hook:e,secret:t,showInstructions:n=!0,instructionsId:r}){let i=S(e.token,l(),window.location.origin);return(0,w.jsxs)(`div`,{className:`space-y-3`,"data-testid":`webhook-setup`,children:[(0,w.jsx)(k,{label:`Payload URL`,value:i}),C(i)&&(0,w.jsx)(`p`,{className:`text-sm text-warning`,children:`This address is local. For external providers, use your publicly reachable ORC address with the same /webhooks/ path.`}),n&&(0,w.jsxs)(`div`,{id:r,"data-testid":`webhook-setup-instructions`,className:`space-y-3`,children:[t?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(k,{label:`Signing secret`,value:t,secret:!0}),(0,w.jsx)(`p`,{className:`text-xs text-outline`,children:`Copy the signing secret before leaving. It is shown once.`})]}):(0,w.jsx)(`p`,{className:`text-xs text-outline`,children:`The signing secret is hidden. Generate a replacement only if you need to reconnect the sender.`}),e.provider===`github`?(0,w.jsxs)(`ol`,{className:`list-decimal space-y-1 pl-5 text-sm text-outline`,children:[(0,w.jsx)(`li`,{children:`In your repository, open GitHub Settings - Webhooks - Add webhook.`}),(0,w.jsx)(`li`,{children:`Paste the Payload URL, select application/json, and enter the signing secret.`}),(0,w.jsx)(`li`,{children:`Select the events needed by your connected jobs. Each job has its own filters.`}),(0,w.jsx)(`li`,{children:`Send a test event, then open Recent deliveries for this webhook.`})]}):(0,w.jsx)(`p`,{className:`text-sm text-outline`,children:`Send JSON, signed with HMAC-SHA256 of the raw body. Set X-Orc-Signature-256 to sha256=<hex signature>, X-Orc-Event to the event name and X-Orc-Delivery to a unique delivery ID.`})]})]})}function j({hook:e}){let t=v(),n=b(),[r,i]=(0,m.useState)(!1),[a,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(!1),[d,f]=(0,m.useState)(),p=(0,m.useId)();return(0,w.jsxs)(`article`,{className:`space-y-3 border-b border-border pb-5`,"data-testid":`webhook-endpoint`,"data-webhook-id":e.id,children:[(0,w.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,w.jsx)(`h3`,{className:`text-sm font-medium`,children:e.name}),(0,w.jsxs)(`span`,{className:`text-xs text-outline`,children:[e.provider,` - `,e.enabled?`Enabled`:`Disabled`]}),(0,w.jsx)(s,{type:`button`,variant:`outline`,size:`sm`,disabled:t.isPending,onClick:()=>t.mutate({id:e.id,enabled:!e.enabled}),children:e.enabled?`Disable`:`Enable`})]}),(0,w.jsxs)(`div`,{className:`space-y-1`,"data-testid":`webhook-connected-jobs`,children:[(0,w.jsxs)(`p`,{className:`text-xs text-outline`,children:[`Connected jobs (`,e.subscriptions.length,`)`]}),e.subscriptions.length?e.subscriptions.map(e=>(0,w.jsxs)(`div`,{className:`text-sm`,children:[(0,w.jsx)(o,{className:`underline`,"data-testid":`webhook-job-link`,to:`/jobs/${e.job_id}?project=all`,children:e.name}),(0,w.jsxs)(`span`,{className:`text-xs text-outline`,children:[` `,`- `,e.enabled?`Enabled`:`Disabled`,`; events:`,` `,e.events.join(`, `)||`all`,`; actions:`,` `,e.actions.join(`, `)||`all`]})]},e.job_id)):null]}),(0,w.jsx)(A,{hook:e,secret:d,showInstructions:a,instructionsId:p}),(0,w.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,w.jsx)(s,{type:`button`,variant:`outline`,size:`sm`,"data-testid":`webhook-deliveries-toggle`,onClick:()=>i(!r),children:r?`Hide deliveries`:`Recent deliveries`}),(0,w.jsx)(s,{type:`button`,variant:`ghost`,size:`sm`,"data-testid":`webhook-setup-toggle`,"aria-expanded":a,"aria-controls":a?p:void 0,disabled:n.isPending,onClick:()=>{a&&f(void 0),c(!a),u(!1)},children:a?d?`I've copied the setup details`:`Hide setup`:`Setup instructions`})]}),a&&(0,w.jsx)(s,{type:`button`,variant:`ghost`,size:`sm`,disabled:n.isPending,onClick:()=>u(!l),children:`New signing secret`}),a&&l&&(0,w.jsxs)(`div`,{className:`space-y-2 text-sm`,children:[(0,w.jsx)(`p`,{children:`The sender's existing secret will stop working. Update it after generating the replacement.`}),(0,w.jsx)(s,{type:`button`,variant:`outline`,size:`sm`,disabled:n.isPending,onClick:()=>n.mutate(e.id,{onSuccess:e=>{f(e.secret),c(!0),u(!1)}}),children:`Generate replacement secret`})]}),(t.error||n.error)&&(0,w.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:(t.error??n.error)?.message}),r&&(0,w.jsx)(M,{id:e.id})]})}function M({id:e}){let{data:t,isLoading:n,error:r,refetch:i}=g(e);return(0,w.jsxs)(`section`,{className:`space-y-2`,"data-testid":`webhook-deliveries`,children:[(0,w.jsx)(`h4`,{className:`text-sm font-medium`,children:`Recent deliveries`}),r?(0,w.jsx)(p,{message:r.message,onRetry:()=>i()}):n?(0,w.jsx)(`p`,{role:`status`,children:`Loading deliveries...`}):t?.length?t.map(e=>(0,w.jsxs)(`div`,{className:`space-y-1 border-t border-border py-2 text-xs`,"data-testid":`webhook-delivery`,children:[(0,w.jsxs)(`div`,{className:`flex flex-wrap justify-between gap-2`,children:[(0,w.jsxs)(`span`,{children:[e.event,e.action?` / ${e.action}`:``]}),(0,w.jsx)(`span`,{children:e.status})]}),(0,w.jsxs)(`p`,{className:`text-outline`,children:[e.repository,` `,new Date(e.created_at).toLocaleString()]}),e.status===`ignored`&&(0,w.jsx)(`p`,{className:`text-outline`,children:`No enabled connected job matched this event.`}),e.error&&(0,w.jsx)(`p`,{className:`text-error`,children:e.error}),e.runs.map(e=>(0,w.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,w.jsxs)(o,{className:`underline`,to:`/jobs/${e.job_id}?project=all`,children:[`Job run: `,e.status]}),e.task_id&&(0,w.jsx)(o,{className:`underline`,to:`/tasks/${e.task_id}?project=all`,children:`Created task`}),e.session_id&&(0,w.jsx)(o,{className:`underline`,to:`/audit/${e.session_id}?project=all`,children:`Agent session`})]},e.job_run_id))]},e.id)):(0,w.jsx)(`p`,{className:`text-sm text-outline`,children:`No events received yet. Register the endpoint with your provider, then send an event.`})]})}export{y as a,D as i,E as n,h as o,j as r,O as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e}from"./rolldown-runtime-DSDNlrLa.js";import{n as t,t as n}from"./jsx-runtime-CVMpzJz9.js";import{t as r}from"./chunk-OB3PAWPO-1IihCzFx.js";import{t as i}from"./button-C91mbQEU.js";import{t as a}from"./label-BdnRgBbz.js";import{t as o}from"./scroll-area-Cmb_s_kX.js";import{a as s,i as c,n as l,o as u,r as d,t as f}from"./FormDialog-BY8LbFlB.js";import{d as p}from"./client-BDeNEjHL.js";import{t as m}from"./chevron-down-DsKwSkKG.js";import{t as h}from"./ResponsiveFilters-DBO0_-qy.js";import{t as g}from"./textarea-BRdsUa6B.js";import{a as _,i as v,o as y}from"./dialog-Dsdmr5mY.js";import{Ct as b,Ft as x,G as S,J as C,K as w,P as T,Qt as E,St as D,Tt as O,U as k,W as A,X as j,Y as M,an as N,ft as P,nn as F,on as I,st as L,vn as R,vt as z,wt as B,xt as ee}from"./index-D3mYpeGu.js";import{t as V}from"./ConfirmDialog-tkekzo2g.js";import{a as H,c as U,i as te,l as W,n as G,o as ne,r as re,s as ie,t as ae}from"./useJobs-Bt5IQ7lh.js";import{t as oe}from"./StatusBadge-BUGpPpcH.js";import{t as K}from"./ErrorState-DprXzfow.js";import{t as se}from"./ViewHeader-C3jwAE4K.js";import{t as ce}from"./useDetailRoute-DOhAbdV7.js";import{t as q}from"./view-params-DD7i9s5g.js";import{t as le}from"./EmptyState-YM4VSLR9.js";import{a as ue,i as J,n as de,o as fe,r as Y,t as pe}from"./table-Q26Vm3R3.js";import{t as me}from"./useProjectScope-DtEj9j-P.js";import{n as he,t as ge}from"./useListSelection-DLQYrJX-.js";import{i as _e,t as ve}from"./JobWebhooks-CPDNSZmh.js";var ye={name:`play`,size:24,node:[[`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`}]]};ye.node;var X=p(ye),be={name:`power`,size:24,node:[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]};be.node;var xe=p(be),Z=e(t(),1),Q=n();function Se(e){return e.type===`command`?!!e.command.trim():e.type===`agent`?!!(e.prompt.trim()&&e.backend.trim()):!!e.title.trim()}function Ce({value:e,onChange:t}){let n=(0,Z.useId)(),{data:r}=P();return(0,Q.jsxs)(`section`,{className:`space-y-3 border-y border-border py-4`,"data-testid":`job-action-fields`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{htmlFor:`${n}-type`,children:`What should this job do?`}),(0,Q.jsxs)(`select`,{id:`${n}-type`,"data-testid":`job-action-type`,className:`w-full min-h-8 rounded-md border border-control-border bg-background px-3 text-sm`,value:e.type,onChange:e=>{e.target.value===`command`&&t({type:`command`,command:``}),e.target.value===`agent`&&t({type:`agent`,backend:`codex-cli`,prompt:``,auto_approve:!1}),e.target.value===`task`&&t({type:`task`,title:``,body:``,start_automatically:!1})},children:[(0,Q.jsx)(`option`,{value:`command`,children:`Run command`}),(0,Q.jsx)(`option`,{value:`agent`,children:`Run agent`}),(0,Q.jsx)(`option`,{value:`task`,children:`Create task`})]})]}),e.type===`command`&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{htmlFor:`${n}-command`,children:`Command`}),(0,Q.jsx)(g,{id:`${n}-command`,"aria-label":`Command`,"data-testid":`job-command-input`,value:e.command,onChange:n=>t({...e,command:n.target.value}),rows:3,placeholder:`bun run build`,required:!0})]}),e.type===`agent`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{htmlFor:`${n}-backend`,children:`Agent backend`}),(0,Q.jsx)(x,{id:`${n}-backend`,"data-testid":`job-agent-backend`,value:e.backend,list:`${n}-backends`,onChange:n=>t({...e,backend:n.target.value}),required:!0}),(0,Q.jsx)(`datalist`,{id:`${n}-backends`,children:r?.backends.map(e=>(0,Q.jsx)(`option`,{value:e.name,children:e.available?`Available`:`Unavailable`},e.name))})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{htmlFor:`${n}-model`,children:`Model (optional)`}),(0,Q.jsx)(x,{id:`${n}-model`,"data-testid":`job-agent-model`,value:e.model??``,onChange:n=>t({...e,model:n.target.value||void 0})})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{htmlFor:`${n}-prompt`,children:`Instructions`}),(0,Q.jsx)(g,{id:`${n}-prompt`,"data-testid":`job-agent-prompt`,value:e.prompt,onChange:n=>t({...e,prompt:n.target.value}),required:!0,rows:4})]}),(0,Q.jsxs)(`label`,{className:`flex min-h-11 items-center gap-2 text-sm`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:e.auto_approve,onChange:n=>t({...e,auto_approve:n.target.checked})}),`Allow agent tools automatically`]}),(0,Q.jsx)(`p`,{className:`text-xs text-outline`,children:`Starts a tracked agent session. When automatic tool approval is off, permission requests are denied.`})]}),e.type===`task`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{htmlFor:`${n}-title`,children:`Task title`}),(0,Q.jsx)(x,{id:`${n}-title`,"data-testid":`job-task-title`,value:e.title,onChange:n=>t({...e,title:n.target.value}),required:!0,maxLength:200})]}),(0,Q.jsx)(T,{label:`Task instructions`,id:`${n}-body`,"data-testid":`job-task-body`,value:e.body,onChange:n=>t({...e,body:n}),rows:4}),(0,Q.jsxs)(`label`,{className:`flex min-h-11 items-center gap-2 text-sm`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,"data-testid":`job-task-autostart`,checked:e.start_automatically,onChange:n=>t({...e,start_automatically:n.target.checked})}),`Start the task flow automatically`]}),e.start_automatically&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{htmlFor:`${n}-flow`,children:`Flow (blank uses the configured default)`}),(0,Q.jsx)(x,{id:`${n}-flow`,"data-testid":`job-task-flow`,value:e.flow_name??``,onChange:n=>t({...e,flow_name:n.target.value||void 0})})]}),(0,Q.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 we({jobId:e,open:t,onClose:n,onEdit:r,projectScope:a=`all`}){let{data:o,isLoading:s,error:c,refetch:l}=re(e),u=o&&(a===`all`||(a===`unassigned`?o.project_id===null:o.project_id===a)),d=u?o:void 0;(0,Z.useEffect)(()=>{t&&o&&!u&&n()},[t,o,u,n]);let{data:f,isLoading:p,error:m,refetch:h}=H(d?.id??null),g=U(),_=W(),[v,y]=(0,Z.useState)(null);return(0,Q.jsx)(A,{open:t,onOpenChange:e=>!e&&n(),children:(0,Q.jsxs)(w,{"data-testid":`job-detail-sheet`,children:[(0,Q.jsxs)(M,{children:[(0,Q.jsx)(j,{children:d?.name??`Job details`}),d?.description&&(0,Q.jsx)(`p`,{className:`font-body text-xs text-outline mt-1`,children:d.description})]}),(0,Q.jsx)(S,{children:c?(0,Q.jsx)(K,{message:c.message,onRetry:()=>l()}):s?(0,Q.jsx)(`div`,{className:`space-y-3`,children:[...[,,,,,,]].map((e,t)=>(0,Q.jsx)(k,{className:`h-8 w-full bg-surface-highest`},t))}):d?(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsx)(L,{label:`Action`,children:(0,Q.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.action?.type===`agent`?`Run agent (${d.action.backend}): ${d.action.prompt}`:d.action?.type===`task`?`Create task: ${d.action.title}`:d.command})}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-4`,children:[(0,Q.jsx)(L,{label:`Trigger Type`,children:(0,Q.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:d.trigger_type})}),(0,Q.jsx)(L,{label:`Enabled`,children:(0,Q.jsx)(`span`,{className:`font-label text-xs font-bold ${d.enabled?`text-secondary`:`text-outline`}`,children:d.enabled?`● ON`:`○ OFF`})})]}),d.cron_expr&&(0,Q.jsx)(L,{label:`Cron Expression`,children:(0,Q.jsx)(`code`,{className:`font-mono text-xs`,children:d.cron_expr})}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,Q.jsxs)(L,{label:`Timeout`,children:[d.timeout_secs,`s`]}),(0,Q.jsx)(L,{label:`Max Retries`,children:d.max_retries}),(0,Q.jsx)(L,{label:`Overlap`,children:d.overlap})]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-4`,children:[(0,Q.jsx)(L,{label:`Notify On`,children:d.notify_on}),(0,Q.jsx)(L,{label:`Run Count`,children:d.run_count})]}),d.next_run_at&&(0,Q.jsx)(L,{label:`Next Run`,children:new Date(d.next_run_at).toLocaleString()})]}),!d.command.startsWith(`__`)&&(0,Q.jsx)(ve,{job:d},d.id),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`font-label text-xs font-medium text-outline mb-3`,children:`Recent runs`}),m?(0,Q.jsx)(K,{message:m.message,onRetry:()=>h()}):p?(0,Q.jsx)(`div`,{className:`space-y-2`,children:[...[,,,]].map((e,t)=>(0,Q.jsx)(k,{className:`h-8 w-full bg-surface-highest`},t))}):f?.length?(0,Q.jsx)(`div`,{className:`space-y-1`,children:f.map(t=>(0,Q.jsx)(Te,{run:t,jobId:e,expanded:v===t.id,onToggle:()=>y(v===t.id?null:t.id)},t.id))}):(0,Q.jsx)(`div`,{className:`font-label text-xs text-outline py-4 text-center`,children:`No runs yet`})]})]}):(0,Q.jsx)(`p`,{className:`text-sm text-outline`,children:`Job not found`})}),(0,Q.jsxs)(C,{className:`flex-wrap`,children:[(_.error||g.error)&&(0,Q.jsx)(`p`,{role:`alert`,className:`w-full text-sm text-error`,children:(_.error??g.error)?.message}),d&&r&&(0,Q.jsxs)(i,{"data-testid":`job-detail-edit`,size:`sm`,variant:`outline`,onClick:()=>r(d),children:[(0,Q.jsx)(I,{size:16}),`Edit job`]}),d&&(0,Q.jsxs)(i,{size:`sm`,variant:`ghost`,disabled:_.isPending,onClick:()=>_.mutate({id:d.id,enabled:!d.enabled}),className:`font-label text-xs font-medium`,children:[(0,Q.jsx)(xe,{size:12,className:`mr-1.5`}),d.enabled?`Disable`:`Enable`]}),d&&(0,Q.jsxs)(i,{variant:`ghost`,size:`sm`,disabled:g.isPending,onClick:()=>g.mutate(d.id),className:`font-label text-xs font-medium bg-transparent text-on-surface border border-control-border hover:bg-surface`,children:[(0,Q.jsx)(X,{size:12,className:`mr-1.5`}),g.isPending?`Triggering...`:`Trigger run`]})]})]})})}function Te({run:e,jobId:t,expanded:n,onToggle:i}){return(0,Q.jsxs)(`div`,{className:`min-w-0 border-y border-border overflow-hidden bg-background`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:i,"aria-expanded":n,className:`w-full flex items-center gap-3 px-3 py-2 hover:bg-surface transition-colors text-left`,children:[n?(0,Q.jsx)(m,{size:12,className:`text-outline shrink-0`}):(0,Q.jsx)(R,{size:12,className:`text-outline shrink-0`}),(0,Q.jsx)(oe,{status:e.status,type:`job`}),(0,Q.jsxs)(`span`,{className:`font-label text-xs text-outline flex-1`,children:[e.started_at?new Date(e.started_at).toLocaleString():`—`,e.ended_at&&(0,Q.jsxs)(`span`,{className:`ml-2`,children:[`\\u2192 `,new Date(e.ended_at).toLocaleString()]})]}),e.exit_code!==null&&(0,Q.jsxs)(`span`,{className:`font-mono text-xs ${e.exit_code===0?`text-secondary`:`text-error`}`,children:[`exit `,e.exit_code]})]}),(e.task_id||e.session_id)&&(0,Q.jsxs)(`div`,{className:`flex gap-3 px-3 py-2 text-xs`,children:[e.task_id&&(0,Q.jsx)(r,{className:`underline`,"data-testid":`job-run-task-link`,to:`/tasks/${e.task_id}?project=all`,children:`Created task`}),e.session_id&&(0,Q.jsx)(r,{className:`underline`,"data-testid":`job-run-session-link`,to:`/audit/${e.session_id}?project=all`,children:`Agent session`})]}),e.error_msg&&(0,Q.jsx)(`div`,{className:`px-3 pb-2`,children:(0,Q.jsx)(`span`,{className:`font-body text-xs text-error`,children:e.error_msg})}),n&&(0,Q.jsx)(Ee,{jobId:t,runId:e.id})]})}function Ee({jobId:e,runId:t}){let{data:n,isLoading:r,error:i,refetch:a}=te(e,t);return i?(0,Q.jsx)(K,{message:i.message,onRetry:()=>a()}):r?(0,Q.jsx)(`div`,{className:`px-3 pb-3`,children:(0,Q.jsx)(k,{className:`h-24 w-full bg-surface-highest`})}):n?.length?(0,Q.jsx)(`div`,{className:`mx-3 mb-3 rounded-lg overflow-hidden border border-surface-highest`,children:(0,Q.jsx)(o,{className:`h-[240px]`,children:(0,Q.jsx)(`pre`,{className:`font-mono text-xs leading-relaxed bg-background p-3`,children:n.map(e=>(0,Q.jsx)(`div`,{className:e.stream===`stderr`?`text-error`:`text-on-surface`,children:e.line},e.id))})})}):(0,Q.jsx)(`div`,{className:`px-3 pb-3 font-label text-xs text-outline`,children:`No log output`})}var $=[`one-shot`,`cron`,`watch`,`webhook`,`manual`,`bridge-msg`],De=[`skip`,`queue`,`kill`],Oe=[`never`,`failure`,`always`];function ke({projectId:e}){let t=O(`xl`),[n,r]=q(`jobQuery`,``),[a,o]=q(`jobStatus`,`all`,[`all`,`enabled`,`disabled`]),[s,c]=q(`jobTrigger`,`all`,[`all`,...$]),l=me(e),u=l===`all`||l===`unassigned`?void 0:l,{data:d,isLoading:f,error:p,refetch:m}=ne({project_id:l===`all`?void 0:l,limit:100}),g=(l===`unassigned`?d?.filter(e=>e.project_id===null):d)?.filter(e=>(!n||`${e.name} ${e.description??``} ${e.command??``}`.toLowerCase().includes(n.toLowerCase()))&&(a===`all`||e.enabled===(a===`enabled`))&&(s===`all`||e.trigger_type===s)),_=JSON.stringify([l,n,a,s]),v=U(),y=G(),b=W(),S=ie(),C=S.data?.scope===_?S.data:void 0,w=ge((g??[]).map(e=>e.id),_);async function T(e){let t=await S.mutateAsync({ids:w.selectedIds,enabled:e,scope:_});w.select(t.failed.map(e=>e.id))}let{selectedId:D,openDetail:A,closeDetail:j}=ce(`/jobs`,`jobId`),[M,P]=(0,Z.useState)(!1),[L,R]=(0,Z.useState)(null),[z,B]=(0,Z.useState)(null);if(p)return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(se,{title:`Jobs`}),(0,Q.jsx)(K,{message:p.message,onRetry:()=>m()})]});let ee=(g??[]).filter(e=>e.enabled).length;return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(se,{title:`Jobs`,compact:!0,meta:`${ee}/${(g??[]).length} enabled`,action:(0,Q.jsxs)(i,{"data-testid":`new-job-button`,size:`sm`,onClick:()=>P(!0),className:`font-label text-xs font-medium bg-primary text-primary-foreground hover:bg-primary/90`,children:[(0,Q.jsx)(N,{size:12,className:`mr-1`}),` New job`]})}),(0,Q.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(`div`,{className:`relative min-w-0 flex-1 lg:max-w-md`,children:[(0,Q.jsx)(F,{size:14,className:`absolute left-3 top-1/2 -translate-y-1/2 text-outline`}),(0,Q.jsx)(x,{type:`search`,"aria-label":`Search jobs`,"data-testid":`job-search`,placeholder:`Search jobs…`,value:n,onChange:e=>r(e.target.value,{replace:!0}),className:`h-11 pl-9 text-base lg:h-9 lg:text-sm`})]}),(0,Q.jsxs)(h,{activeCount:Number(a!==`all`)+Number(s!==`all`),children:[(0,Q.jsxs)(`select`,{"aria-label":`Job status`,"data-testid":`job-status-filter`,value:a,onChange:e=>o(e.target.value),className:`form-control form-control-single max-w-full`,children:[(0,Q.jsx)(`option`,{value:`all`,children:`All statuses`}),(0,Q.jsx)(`option`,{value:`enabled`,children:`Enabled`}),(0,Q.jsx)(`option`,{value:`disabled`,children:`Disabled`})]}),(0,Q.jsxs)(`select`,{"aria-label":`Job trigger`,"data-testid":`job-trigger-filter`,value:s,onChange:e=>c(e.target.value),className:`form-control form-control-single max-w-full`,children:[(0,Q.jsx)(`option`,{value:`all`,children:`All triggers`}),$.map(e=>(0,Q.jsx)(`option`,{value:e,children:e},e))]})]})]}),(v.error||y.error||b.error)&&(0,Q.jsx)(`p`,{role:`alert`,className:`mb-4 text-sm text-error`,children:(v.error??y.error??b.error)?.message}),!!g?.length&&(0,Q.jsxs)(he,{resourceLabel:`jobs`,count:w.selectedIds.length,allSelected:w.allSelected,someSelected:w.someSelected,onSelectAll:w.selectAll,onClear:w.clear,disabled:S.isPending,children:[(0,Q.jsx)(i,{type:`button`,variant:`outline`,size:`sm`,"data-testid":`jobs-bulk-enable`,disabled:S.isPending||b.isPending,onClick:()=>void T(!0),children:`Enable selected`}),(0,Q.jsx)(i,{type:`button`,variant:`outline`,size:`sm`,"data-testid":`jobs-bulk-disable`,disabled:S.isPending||b.isPending,onClick:()=>void T(!1),children:`Disable selected`})]}),S.isPending&&(0,Q.jsx)(`p`,{role:`status`,className:`mb-3 text-sm text-outline`,children:`Updating selected jobs…`}),!S.isPending&&C&&(0,Q.jsxs)(`div`,{className:`mb-3 space-y-1 text-sm`,"data-testid":`jobs-bulk-result`,role:`status`,children:[(0,Q.jsxs)(`p`,{children:[C.succeeded.length,` jobs `,C.enabled?`enabled`:`disabled`,`.`]}),C.failed.map(e=>(0,Q.jsxs)(`p`,{className:`text-error`,children:[g?.find(t=>t.id===e.id)?.name??e.id,`: `,e.error,`. Still selected for retry.`]},e.id))]}),f?(0,Q.jsx)(`div`,{role:`status`,"aria-label":`Loading jobs`,className:`space-y-2`,children:[...[,,,]].map((e,t)=>(0,Q.jsx)(k,{className:`h-12 w-full bg-surface-highest`},t))}):(g??[]).length===0?(0,Q.jsx)(le,{message:n||a!==`all`||s!==`all`?`No jobs match`:`No jobs configured`}):t?(0,Q.jsx)(`div`,{className:`min-w-0 overflow-hidden`,children:(0,Q.jsxs)(pe,{children:[(0,Q.jsx)(ue,{children:(0,Q.jsxs)(fe,{className:`border-b border-border hover:bg-transparent`,children:[(0,Q.jsx)(J,{className:`w-11`,children:(0,Q.jsx)(`span`,{className:`sr-only`,children:`Select jobs`})}),(0,Q.jsx)(J,{className:`font-label text-xs font-medium text-outline`,children:`Name`}),(0,Q.jsx)(J,{className:`font-label text-xs font-medium text-outline w-24`,children:`Trigger`}),(0,Q.jsx)(J,{className:`font-label text-xs font-medium text-outline w-48`,children:`Action`}),(0,Q.jsx)(J,{className:`font-label text-xs font-medium text-outline w-16`,children:`Enabled`}),(0,Q.jsx)(J,{className:`font-label text-xs font-medium text-outline w-36`,children:`Last Run`}),(0,Q.jsx)(J,{className:`font-label text-xs font-medium text-outline w-16`,children:`Runs`}),(0,Q.jsx)(J,{className:`font-label text-xs font-medium text-outline w-36`,children:`Next Run`}),(0,Q.jsx)(J,{className:`w-28`})]})}),(0,Q.jsx)(de,{children:(g??[]).map(e=>(0,Q.jsxs)(fe,{"data-testid":`job-row`,"data-job-id":e.id,"data-job-name":e.name,className:`border-b border-border/65 hover:bg-surface-high cursor-pointer`,onClick:()=>A(e.id),children:[(0,Q.jsx)(Y,{children:(0,Q.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-primary`,"aria-label":`Select ${e.name}`,"data-testid":`job-select`,checked:w.selectedIds.includes(e.id),disabled:S.isPending,onClick:e=>e.stopPropagation(),onChange:()=>w.toggle(e.id)})}),(0,Q.jsxs)(Y,{children:[(0,Q.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:t=>{t.stopPropagation(),A(e.id)},children:e.name}),e.description&&(0,Q.jsx)(`div`,{className:`font-body text-sm text-outline mt-0.5 truncate max-w-[200px]`,children:e.description})]}),(0,Q.jsx)(Y,{children:(0,Q.jsx)(`span`,{className:`font-label text-xs text-on-surface-variant inline-flex`,children:e.trigger_type})}),(0,Q.jsx)(Y,{children:(0,Q.jsx)(`code`,{className:`font-mono text-xs text-outline truncate block max-w-[180px]`,children:e.action?.type===`agent`?`Agent: ${e.action.backend}`:e.action?.type===`task`?`Task: ${e.action.title}`:e.command})}),(0,Q.jsx)(Y,{children:(0,Q.jsx)(i,{type:`button`,"data-testid":`job-toggle-enabled`,variant:`outline`,size:`sm`,"aria-label":`${e.enabled?`Disable`:`Enable`} ${e.name}`,"aria-pressed":e.enabled,disabled:b.isPending||S.isPending,onClick:t=>{t.stopPropagation(),b.mutate({id:e.id,enabled:!e.enabled})},children:e.enabled?`Disable`:`Enable`})}),(0,Q.jsx)(Y,{className:`font-label text-xs text-outline`,children:e.last_run_at?new Date(e.last_run_at).toLocaleString():`—`}),(0,Q.jsx)(Y,{className:`font-label text-xs text-outline`,children:e.run_count}),(0,Q.jsx)(Y,{className:`font-label text-xs text-outline`,children:e.next_run_at?new Date(e.next_run_at).toLocaleString():`—`}),(0,Q.jsx)(Y,{children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,onClick:e=>e.stopPropagation(),children:[(0,Q.jsxs)(i,{variant:`ghost`,"data-testid":`job-trigger`,size:`sm`,disabled:v.isPending,onClick:()=>v.mutate(e.id),className:`font-label text-sm min-h-8 px-3 bg-transparent text-on-surface border border-border hover:bg-surface-high`,children:[(0,Q.jsx)(X,{size:10,className:`mr-1`}),` Run`]}),(0,Q.jsx)(i,{type:`button`,"data-testid":`job-edit`,variant:`ghost`,size:`icon`,"aria-label":`Edit ${e.name}`,onClick:()=>R(e),className:`inline-flex min-h-8 min-w-8 items-center justify-center rounded-md text-outline hover:text-primary hover:bg-surface-highest`,children:(0,Q.jsx)(I,{size:16})}),(0,Q.jsx)(i,{type:`button`,"data-testid":`job-delete`,variant:`ghost`,size:`icon`,"aria-label":`Delete ${e.name}`,onClick:()=>B(e),className:`inline-flex min-h-8 min-w-8 items-center justify-center rounded-md text-outline hover:text-error hover:bg-error/10`,children:(0,Q.jsx)(E,{size:12})})]})})]},e.id))})]})}):(0,Q.jsx)(`div`,{className:`divide-y divide-border`,children:(g??[]).map(e=>(0,Q.jsxs)(`article`,{"data-testid":`job-row`,"data-job-id":e.id,"data-job-name":e.name,className:`py-3 space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-primary shrink-0 mt-1`,"aria-label":`Select ${e.name}`,"data-testid":`job-select`,checked:w.selectedIds.includes(e.id),disabled:S.isPending,onChange:()=>w.toggle(e.id)}),(0,Q.jsx)(`button`,{type:`button`,className:`min-w-0 flex-1 text-left font-medium text-sm text-on-surface wrap-break-word hover:text-primary`,"data-testid":`job-open-detail`,onClick:()=>A(e.id),children:e.name}),(0,Q.jsx)(i,{type:`button`,"data-testid":`job-toggle-enabled`,variant:`outline`,size:`sm`,"aria-label":`${e.enabled?`Disable`:`Enable`} ${e.name}`,"aria-pressed":e.enabled,disabled:b.isPending||S.isPending,onClick:()=>b.mutate({id:e.id,enabled:!e.enabled}),children:e.enabled?`Disable`:`Enable`})]}),e.description&&(0,Q.jsx)(`p`,{className:`text-sm text-outline wrap-break-word`,children:e.description}),(0,Q.jsx)(`code`,{className:`block whitespace-pre-wrap break-all text-xs text-on-surface-variant`,children:e.action?.type===`agent`?`Agent: ${e.action.backend}`:e.action?.type===`task`?`Task: ${e.action.title}`:e.command}),(0,Q.jsxs)(`p`,{className:`text-xs text-outline`,children:[e.trigger_type,` · `,e.run_count,` runs`,e.next_run_at?` · Next: ${new Date(e.next_run_at).toLocaleString()}`:``]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsxs)(i,{"data-testid":`job-edit`,variant:`ghost`,size:`sm`,onClick:()=>R(e),children:[(0,Q.jsx)(I,{}),`Edit`]}),(0,Q.jsxs)(i,{"data-testid":`job-trigger`,variant:`ghost`,size:`sm`,disabled:v.isPending,onClick:()=>v.mutate(e.id),children:[(0,Q.jsx)(X,{}),`Run`]}),(0,Q.jsx)(i,{"data-testid":`job-delete`,"aria-label":`Delete ${e.name}`,variant:`ghost`,size:`icon`,onClick:()=>B(e),children:(0,Q.jsx)(E,{})})]})]},e.id))}),(0,Q.jsx)(we,{projectScope:l,jobId:D,open:!!D,onClose:j,onEdit:e=>{j(),R(e)}}),M&&(0,Q.jsx)(Ae,{defaultProjectId:u,open:M,onClose:()=>P(!1)}),L&&(0,Q.jsx)(je,{job:L,open:!!L,onClose:()=>R(null)}),z&&(0,Q.jsx)(V,{open:!!z,title:`Delete Job`,description:`Delete job "${z.name}"? This cannot be undone.`,confirmLabel:`Delete`,variant:`destructive`,isPending:y.isPending,onConfirm:()=>{y.mutate(z.id,{onSuccess:()=>B(null)})},onCancel:()=>B(null)})]})}function Ae({defaultProjectId:e,open:t,onClose:n}){let{data:r}=z(),o=B([{id:`details`,label:`Details`},{id:`execution`,label:`Execution`},{id:`automation`,label:`Automation`}],t),[p,m]=(0,Z.useState)(``),[h,g]=(0,Z.useState)(``),[S,C]=(0,Z.useState)({type:`command`,command:``}),[w,T]=(0,Z.useState)([]),[E,O]=(0,Z.useState)(`manual`),[k,A]=(0,Z.useState)(``),[j,M]=(0,Z.useState)(`300`),[N,P]=(0,Z.useState)(`0`),[F,I]=(0,Z.useState)(`skip`),[L,R]=(0,Z.useState)(`failure`),[V,H]=(0,Z.useState)(``),[U,te]=(0,Z.useState)(e??``),W=ae(),[G,ne]=(0,Z.useState)(!1),re=(e,t=n)=>{if(e.preventDefault(),E===`webhook`&&!w.length){o.invalid(`automation`,`Select at least one webhook for this trigger.`);return}if(!p.trim()||!Se(S))return;let r={name:p.trim(),description:h.trim(),action:S,webhooks:E===`webhook`?w:[],trigger_type:E,enabled:G,cron_expr:E===`cron`&&k.trim()||void 0,timeout_secs:Number.parseInt(j,10)||void 0,max_retries:Number.parseInt(N,10),overlap:F,notify_on:L,project_id:U||void 0,working_dir:V.trim()||void 0};W.mutate(r,{onSuccess:t})};return(0,Q.jsx)(f,{open:t,onClose:n,busy:W.isPending,dirty:JSON.stringify([p,h,S,w,E,k,j,N,F,L,V,U,G])!==JSON.stringify([``,``,{type:`command`,command:``},[],`manual`,``,`300`,`0`,`skip`,`failure`,``,e??``,!1]),children:(e,t)=>(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(_,{children:(0,Q.jsx)(y,{className:`font-headline text-sm font-medium text-on-surface`,children:`New job`})}),(0,Q.jsx)(`form`,{noValidate:!0,ref:o.form,onSubmit:e=>o.submit(e,()=>re(e,t)),className:`min-h-0`,children:(0,Q.jsxs)(b,{steps:o,children:[(0,Q.jsxs)(`div`,{className:`work-form-body space-y-4`,children:[(0,Q.jsxs)(D,{steps:o,id:`details`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Name *`}),(0,Q.jsx)(x,{required:!0,"aria-label":`Name`,"data-testid":`job-name-input`,value:p,onChange:e=>m(e.target.value),placeholder:`Job name...`,className:`bg-background border-control-border text-on-surface font-body text-sm`,autoFocus:!0})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Description`}),(0,Q.jsx)(x,{"aria-label":`Description`,value:h,onChange:e=>g(e.target.value),placeholder:`Optional description...`,className:`bg-background border-control-border text-on-surface font-body text-sm`})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Project`}),(0,Q.jsxs)(l,{value:U||`__none__`,onValueChange:e=>{te(e===`__none__`?``:e),T([])},children:[(0,Q.jsx)(s,{"aria-label":`Project`,"data-testid":`job-project-select`,className:`bg-background border-control-border text-on-surface font-body text-sm min-h-8`,children:(0,Q.jsx)(u,{})}),(0,Q.jsxs)(d,{className:`bg-surface border-border`,children:[(0,Q.jsx)(c,{value:`__none__`,className:`font-body text-sm`,children:`None`}),r?.map(e=>(0,Q.jsx)(c,{value:e.id,className:`font-body text-sm`,children:e.name},e.id))]})]})]})]}),(0,Q.jsxs)(D,{steps:o,id:`execution`,children:[(0,Q.jsx)(Ce,{value:S,onChange:C}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Working Dir`}),(0,Q.jsx)(x,{"aria-label":`Working directory`,value:V,onChange:e=>H(e.target.value),placeholder:`/path/to/dir`,className:`bg-background border-control-border text-on-surface font-body text-sm`})]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-3 md:col-span-2`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Timeout (s)`}),(0,Q.jsx)(x,{"aria-label":`Timeout in seconds`,type:`number`,min:1,required:!0,value:j,onChange:e=>M(e.target.value),className:`bg-background border-control-border text-on-surface font-body text-sm`})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Retries`}),(0,Q.jsx)(x,{"aria-label":`Maximum retries`,type:`number`,min:0,required:!0,value:N,onChange:e=>P(e.target.value),className:`bg-background border-control-border text-on-surface font-body text-sm`})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Overlap`}),(0,Q.jsxs)(l,{value:F,onValueChange:e=>I(e),children:[(0,Q.jsx)(s,{"aria-label":`Overlap`,className:`bg-background border-control-border text-on-surface font-body text-sm min-h-8`,children:(0,Q.jsx)(u,{})}),(0,Q.jsx)(d,{className:`bg-surface border-border`,children:De.map(e=>(0,Q.jsx)(c,{value:e,className:`font-body text-sm`,children:e},e))})]})]})]})]}),(0,Q.jsxs)(D,{steps:o,id:`automation`,children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2 md:col-span-2`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Trigger`}),(0,Q.jsxs)(l,{value:E,onValueChange:e=>O(e),children:[(0,Q.jsx)(s,{"aria-label":`Trigger type`,"data-testid":`job-trigger-type`,className:`bg-background border-control-border text-on-surface font-body text-sm min-h-8`,children:(0,Q.jsx)(u,{})}),(0,Q.jsx)(d,{className:`bg-surface border-border`,children:$.map(e=>(0,Q.jsx)(c,{value:e,"data-testid":`job-trigger-${e}`,className:`font-body text-sm`,children:e},e))})]})]}),E===`webhook`&&(0,Q.jsx)(`div`,{className:`sm:col-span-2`,children:(0,Q.jsx)(_e,{value:w,onChange:T,projectId:U||void 0})}),E===`cron`&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Cron expression`}),(0,Q.jsx)(x,{required:!0,"aria-label":`Cron expression`,value:k,onChange:e=>A(e.target.value),placeholder:`*/5 * * * *`,className:`bg-background border-control-border text-on-surface font-mono text-xs`})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Notify On`}),(0,Q.jsxs)(l,{value:L,onValueChange:e=>R(e),children:[(0,Q.jsx)(s,{"aria-label":`Notify on`,className:`bg-background border-control-border text-on-surface font-body text-sm min-h-8`,children:(0,Q.jsx)(u,{})}),(0,Q.jsx)(d,{className:`bg-surface border-border`,children:Oe.map(e=>(0,Q.jsx)(c,{value:e,className:`font-body text-sm`,children:e},e))})]})]}),(0,Q.jsxs)(`label`,{className:`flex min-h-11 items-center gap-3 text-sm md:col-span-2`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,"data-testid":`job-create-enabled`,checked:G,onChange:e=>ne(e.target.checked),className:`size-4 accent-primary`}),`Enable this job immediately`]}),(0,Q.jsx)(`p`,{className:`text-xs text-outline md:col-span-2`,children:`Created disabled unless you enable it above.`})]}),(0,Q.jsx)(`div`,{className:`md:col-span-2`,children:W.error&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:W.error.message})}),o.error&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:o.error})]}),(0,Q.jsxs)(v,{className:`work-form-footer`,children:[(0,Q.jsx)(i,{type:`button`,variant:`ghost`,size:`sm`,"data-testid":`form-cancel`,onClick:e,className:`font-label text-xs text-outline`,children:`Cancel`}),(0,Q.jsx)(ee,{steps:o,busy:W.isPending,children:(0,Q.jsx)(i,{"data-testid":`job-submit`,type:`submit`,size:`sm`,disabled:W.isPending,className:`font-label text-xs bg-primary text-primary-foreground hover:bg-primary/90`,children:W.isPending?`Creating...`:E===`webhook`?`Create job`:`Create`})})]})]})})]})})}function je({job:e,open:t,onClose:n}){let r=B([{id:`details`,label:`Details`},{id:`execution`,label:`Execution`},{id:`automation`,label:`Automation`}],t),[o,p]=(0,Z.useState)(e.name),[m,h]=(0,Z.useState)(e.description??``),[g,S]=(0,Z.useState)(e.action??{type:`command`,command:e.command}),[C,w]=(0,Z.useState)(e.webhooks??[]),[T,E]=(0,Z.useState)(e.trigger_type),[O,k]=(0,Z.useState)(e.cron_expr??``),[A,j]=(0,Z.useState)(String(e.timeout_secs)),[M,N]=(0,Z.useState)(String(e.max_retries)),[P,F]=(0,Z.useState)(e.overlap),[I,L]=(0,Z.useState)(e.notify_on),[R,z]=(0,Z.useState)(e.enabled),V=W(),H=(t,i=n)=>{if(t.preventDefault(),T===`webhook`&&!C.length){r.invalid(`automation`,`Select at least one webhook for this trigger.`);return}if(!o.trim()||!Se(g))return;let a={id:e.id,name:o.trim(),description:m.trim(),action:g,webhooks:T===`webhook`?C:[],trigger_type:T,cron_expr:T===`cron`&&O.trim()||void 0,timeout_secs:Number.parseInt(A,10)||void 0,max_retries:Number.parseInt(M,10),overlap:P,notify_on:I,enabled:R};V.mutate(a,{onSuccess:i})};return(0,Q.jsx)(f,{open:t,onClose:n,busy:V.isPending,dirty:JSON.stringify([o,m,g,C,T,O,A,M,P,I,R])!==JSON.stringify([e.name,e.description??``,e.action??{type:`command`,command:e.command},e.webhooks??[],e.trigger_type,e.cron_expr??``,String(e.timeout_secs),String(e.max_retries),e.overlap,e.notify_on,e.enabled]),children:(t,n)=>(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(_,{children:(0,Q.jsx)(y,{className:`font-headline text-sm font-medium text-on-surface`,children:`Edit job`})}),(0,Q.jsx)(`form`,{noValidate:!0,ref:r.form,id:`edit-job-form`,onSubmit:e=>r.submit(e,()=>H(e,n)),className:`min-h-0`,children:(0,Q.jsxs)(b,{steps:r,children:[(0,Q.jsxs)(`div`,{className:`work-form-body space-y-4`,children:[(0,Q.jsxs)(D,{steps:r,id:`details`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Name *`}),(0,Q.jsx)(x,{required:!0,"aria-label":`Name`,value:o,onChange:e=>p(e.target.value),className:`bg-background border-control-border text-on-surface font-body text-sm`})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Description`}),(0,Q.jsx)(x,{"aria-label":`Description`,value:m,onChange:e=>h(e.target.value),className:`bg-background border-control-border text-on-surface font-body text-sm`})]})]}),(0,Q.jsxs)(D,{steps:r,id:`execution`,children:[(0,Q.jsx)(Ce,{value:g,onChange:S}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-3 md:col-span-2`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Timeout (s)`}),(0,Q.jsx)(x,{"aria-label":`Timeout in seconds`,type:`number`,min:1,required:!0,value:A,onChange:e=>j(e.target.value),className:`bg-background border-control-border text-on-surface font-body text-sm`})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Retries`}),(0,Q.jsx)(x,{"aria-label":`Maximum retries`,type:`number`,min:0,required:!0,value:M,onChange:e=>N(e.target.value),className:`bg-background border-control-border text-on-surface font-body text-sm`})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Overlap`}),(0,Q.jsxs)(l,{value:P,onValueChange:e=>F(e),children:[(0,Q.jsx)(s,{"aria-label":`Overlap`,className:`bg-background border-control-border text-on-surface font-body text-sm min-h-8`,children:(0,Q.jsx)(u,{})}),(0,Q.jsx)(d,{className:`bg-surface border-border`,children:De.map(e=>(0,Q.jsx)(c,{value:e,className:`font-body text-sm`,children:e},e))})]})]})]})]}),(0,Q.jsxs)(D,{steps:r,id:`automation`,children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2 md:col-span-2`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Trigger`}),(0,Q.jsxs)(l,{value:T,onValueChange:e=>E(e),children:[(0,Q.jsx)(s,{"aria-label":`Trigger type`,"data-testid":`job-trigger-type`,className:`bg-background border-control-border text-on-surface font-body text-sm min-h-8`,children:(0,Q.jsx)(u,{})}),(0,Q.jsx)(d,{className:`bg-surface border-border`,children:$.map(e=>(0,Q.jsx)(c,{value:e,"data-testid":`job-trigger-${e}`,className:`font-body text-sm`,children:e},e))})]})]}),T===`webhook`&&(0,Q.jsx)(`div`,{className:`sm:col-span-2`,children:(0,Q.jsx)(_e,{value:C,onChange:w,projectId:e.project_id??void 0})}),T===`cron`&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Cron expression`}),(0,Q.jsx)(x,{required:!0,"aria-label":`Cron expression`,value:O,onChange:e=>k(e.target.value),placeholder:`*/5 * * * *`,className:`bg-background border-control-border text-on-surface font-mono text-xs`})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Notify On`}),(0,Q.jsxs)(l,{value:I,onValueChange:e=>L(e),children:[(0,Q.jsx)(s,{"aria-label":`Notify on`,className:`bg-background border-control-border text-on-surface font-body text-sm min-h-8`,children:(0,Q.jsx)(u,{})}),(0,Q.jsx)(d,{className:`bg-surface border-border`,children:Oe.map(e=>(0,Q.jsx)(c,{value:e,className:`font-body text-sm`,children:e},e))})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(a,{className:`font-label text-xs font-medium text-outline`,children:`Enabled`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>z(!R),className:`w-full min-h-11 rounded-md flex items-center justify-center border font-label text-xs font-medium transition-colors ${R?`bg-surface-highest text-on-surface border-border`:`bg-background text-outline border-border`}`,children:R?`● Enabled`:`○ Disabled`})]})]}),(0,Q.jsx)(`div`,{className:`md:col-span-2`,children:V.error&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:V.error.message})}),r.error&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:r.error})]}),(0,Q.jsxs)(v,{className:`work-form-footer`,children:[(0,Q.jsx)(i,{type:`button`,variant:`ghost`,size:`sm`,"data-testid":`form-cancel`,onClick:t,className:`font-label text-xs text-outline`,children:`Cancel`}),(0,Q.jsx)(ee,{steps:r,busy:V.isPending,children:(0,Q.jsx)(i,{"data-testid":`job-edit-submit`,form:`edit-job-form`,type:`submit`,size:`sm`,disabled:V.isPending,className:`font-label text-xs bg-primary text-primary-foreground hover:bg-primary/90`,children:V.isPending?`Saving...`:`Save`})})]})]})})]})})}export{ke as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e}from"./rolldown-runtime-DSDNlrLa.js";import{n as t,t as n}from"./jsx-runtime-CVMpzJz9.js";import{n as r}from"./QueryClientProvider-DlPztvhd.js";import{f as i,m as a,p as o,t as s,u as c}from"./chunk-OB3PAWPO-1IihCzFx.js";import{l,t as u,u as d}from"./button-C91mbQEU.js";import{a as f,c as p,i as m,l as h,n as g,o as _,s as v,t as y}from"./x-CzIc4TnV.js";import{t as b}from"./label-BdnRgBbz.js";import{a as x,i as S,n as C,o as w,r as T,t as E}from"./FormDialog-BY8LbFlB.js";import{d as D,n as O}from"./client-BDeNEjHL.js";import{t as k}from"./download-DzO9zuw8.js";import{t as A}from"./MarkdownEditor-p8DBlDfc.js";import{t as j}from"./ResponsiveFilters-DBO0_-qy.js";import{t as M}from"./upload-BS--UG8X.js";import{a as N,c as P,d as F,f as I,g as L,h as R,i as z,m as B,o as ee,t as V,u as H}from"./schemas-BQZhekae.js";import{t as U}from"./Markdown-B0Ztqigq.js";import{t as W}from"./textarea-BRdsUa6B.js";import{a as te,i as G,n as ne,o as re,t as ie}from"./dialog-Dsdmr5mY.js";import{An as ae,C as oe,Cn as se,Ct as ce,Dn as le,En as ue,F as de,Ft as K,G as fe,K as pe,On as me,P as he,Qt as ge,S as _e,St as ve,Tn as ye,Tt as be,U as xe,W as Se,X as Ce,Y as we,Zt as Te,an as Ee,en as De,ft as Oe,gn as ke,hn as Ae,in as je,kn as Me,ln as Ne,lt as Pe,mn as Fe,nn as Ie,on as Le,st as Re,vn as ze,vt as Be,wt as Ve,xn as He,xt as Ue}from"./index-D3mYpeGu.js";import{n as We}from"./wiki-links-A52THGx_.js";import{t as Ge}from"./ConfirmDialog-tkekzo2g.js";import{t as Ke}from"./save-file-3ZpJah8W.js";import{t as qe}from"./ErrorState-DprXzfow.js";import{t as Je}from"./ViewHeader-C3jwAE4K.js";import{t as Ye}from"./view-params-DD7i9s5g.js";import{t as Xe}from"./EmptyState-YM4VSLR9.js";import{a as Ze,i as Qe,n as $e,o as et,r as tt,t as nt}from"./table-Q26Vm3R3.js";import{t as rt}from"./useProjectScope-DtEj9j-P.js";import{a as it,c as at,i as ot,n as st,o as ct,r as lt,s as ut,t as dt}from"./useMemories-P5XFw8dY.js";import{n as ft,t as pt}from"./DocumentWorkspace-k66oavWs.js";import{_ as mt,a as ht,c as gt,d as _t,f as vt,g as yt,i as bt,l as xt,m as St,n as Ct,o as wt,p as Tt,r as q,s as Et,t as Dt,u as Ot,v as kt}from"./badge-4H7GKk39.js";import{t as At}from"./TagInput-QRxyaeSJ.js";var jt={name:`file-down`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 18v-6`,key:`17g6i2`}],[`path`,{d:`m9 15 3 3 3-3`,key:`1npd3o`}]]};jt.node;var Mt=D(jt),Nt={name:`file-plus`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M9 15h6`,key:`cctwl0`}],[`path`,{d:`M12 18v-6`,key:`17g6i2`}]]};Nt.node;var Pt=D(Nt),Ft={name:`file-up`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 12v6`,key:`3ahymv`}],[`path`,{d:`m15 15-3-3-3 3`,key:`15xj92`}]]};Ft.node;var It=D(Ft),Lt={name:`folder-sync`,size:24,node:[[`path`,{d:`M9 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v.5`,key:`1dkoa9`}],[`path`,{d:`M12 10v4h4`,key:`1czhmt`}],[`path`,{d:`m12 14 1.535-1.605a5 5 0 0 1 8 1.5`,key:`lvuxfi`}],[`path`,{d:`M22 22v-4h-4`,key:`1ewp4q`}],[`path`,{d:`m22 18-1.535 1.605a5 5 0 0 1-8-1.5`,key:`14ync0`}]]};Lt.node;var Rt=D(Lt),zt={name:`panel-right`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]};zt.node;var Bt=D(zt),J=e(t(),1),Y=[`mcp`,`api`,`cli`,`ui`],Vt=[`fetch`,`cited`,`search_hit`],Ht=B().trim().min(1).max(120),Ut=z(V(Y)).max(Y.length).transform(e=>Y.filter(t=>e.includes(t)));F({name:Ht,description:B().trim().max(2e3).default(``),project_id:B().min(1).nullable(),editable_by:Ut.default([...Y]),parser:B().min(1).max(40).nullable().default(null)}).strict(),F({name:Ht.optional(),description:B().trim().max(2e3).optional(),editable_by:Ut.optional(),parser:B().min(1).max(40).nullable().optional()}).strict();var Wt=[`default`,`project`,`global`,`all`],Gt=B().trim().min(1).max(500).refine(e=>!e.startsWith(`/`)&&!e.includes(`\\`)&&!e.includes(`:`)&&!e.includes(`\0`)&&e.split(`/`).every(e=>e&&e!==`.`&&e!==`..`),`Use a relative path with / separators and no . or .. segments`),Kt=z(B().trim().min(1).max(60)).max(30),qt=2097152;F({title:B().trim().min(1).max(300),path:Gt.optional(),description:B().trim().max(2e3).optional(),labels:Kt.default([]),content:B().max(qt),note:B().trim().max(1e3).optional(),derived_from:z(B().min(1)).max(50).default([])}).strict(),F({expected_revision:H().int().min(1),title:B().trim().min(1).max(300).optional(),path:Gt.optional(),description:B().trim().max(2e3).optional(),labels:Kt.optional(),content:B().max(qt).optional(),note:B().trim().max(1e3).optional(),derived_from:z(B().min(1)).max(50).optional()}).strict();var Jt=F({kind:V([`heading`,`paragraph`,`list_item`,`table`,`code`]),text:B(),level:H().int().min(1).max(6).optional(),rows:z(z(B())).optional(),heading_path:z(B()),locator:F({page:H().int().min(1).optional(),sheet:B().optional(),bbox:z(H()).length(4).optional()}).optional()});F({schema_version:P(1),parser:F({id:B(),version:B(),options:I(B(),L())}),source_sha256:B().regex(/^[0-9a-f]{64}$/),status:V([`ok`,`partial`,`failed`]),language:B().optional(),blocks:z(Jt),markdown:B(),warnings:z(B()),timings_ms:I(B(),H()).optional(),peak_rss_mb:H().optional()});var Yt=[`auto`,`lexical`,`semantic`,`hybrid`];F({query:B().trim().min(1).max(2e3),scope:V(Wt).default(`default`),kb_ids:z(B().min(1)).max(50).optional(),labels:z(B().min(1)).max(20).optional(),media_types:z(B().min(1)).max(20).optional(),mode:V(Yt).default(`auto`),limit:H().int().min(1).max(50).default(10)}).strict().omit({limit:!0,mode:!0}).extend({mode:V(Yt).default(`auto`),token_budget:H().int().min(500).max(32e3).default(6e3),max_per_document:H().int().min(1).max(10).default(3)}).strict();var Xt=F({old:B().min(1).max(qt),new:B().max(qt),replace_all:N().optional()}).strict(),Zt=F({start_line:H().int().min(1),end_line:H().int().min(0),new:B().max(qt)}).strict();F({expected_revision:H().int().min(1),edits:z(R([Xt,Zt])).min(1).max(50),note:B().trim().min(1).max(1e3)}).strict();var Qt=[`open`,`resolved`,`dismissed`];F({document_id:B().min(1).nullable().optional(),body:B().trim().min(1).max(1e4)}).strict(),F({status:V([`resolved`,`dismissed`]),reply:B().trim().min(1).max(4e3)}).strict();var $t=ee(`type`,[F({type:P(`cron`),cron:B().trim().min(1).max(120)}).strict(),F({type:P(`manual`)}).strict()]);F({instructions:B().trim().min(1).max(2e4).optional(),backend:B().min(1).max(64).regex(/^[a-z][a-z0-9_-]*$/).optional(),schedule:$t.optional(),enabled:N().optional(),timeout_secs:H().int().min(60).max(7200).optional()}).strict();var en=`0 3 * * *`,X=n();function tn({title:e,testId:t,toggleTestId:n,summary:r,actions:i,expanded:a=!1,onExpandedChange:o,heading:s=`h3`,compact:c=!1,children:u}){let d=(0,J.useId)(),f=u!==void 0&&o!==void 0;return(0,X.jsxs)(`section`,{"data-testid":t,"data-expanded":f?a:void 0,"aria-labelledby":`${d}-heading`,className:`min-w-0 text-sm`,children:[(0,X.jsxs)(`div`,{className:l(`grid min-h-12 min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-0.5 py-1.5`,!c&&`sm:grid-cols-[9rem_minmax(0,1fr)_auto]`),children:[(0,X.jsx)(s,{id:`${d}-heading`,className:`min-w-0 font-medium`,children:f?(0,X.jsxs)(`button`,{type:`button`,"data-testid":n,"aria-expanded":a,"aria-controls":d,className:`-ml-1 flex min-h-9 items-center gap-1.5 rounded px-1 text-left hover:bg-surface-high`,onClick:()=>o(!a),children:[(0,X.jsx)(ze,{size:14,"aria-hidden":!0,className:l(`shrink-0 text-outline transition-transform`,a&&`rotate-90`)}),e]}):(0,X.jsx)(`span`,{className:`flex min-h-9 items-center pl-5`,children:e})}),(0,X.jsx)(`div`,{className:l(`col-span-2 row-start-2 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 pl-5`,!c&&`sm:col-span-1 sm:col-start-2 sm:row-start-1 sm:pl-0`),children:r}),(0,X.jsx)(`div`,{className:l(`col-start-2 row-start-1 flex items-center justify-end gap-1`,!c&&`sm:col-start-3`),children:i})]}),f&&a&&(0,X.jsx)(`div`,{id:d,className:`min-w-0 pb-4 pl-5 pt-1`,children:u})]})}function Z({tone:e}){return(0,X.jsx)(`span`,{"aria-hidden":!0,className:l(`size-1.5 shrink-0 rounded-full`,e===`ok`&&`bg-secondary`,e===`warning`&&`bg-warning`,e===`error`&&`bg-error`,e===`off`&&`bg-muted-foreground`,e===`progress`&&`bg-progress`)})}var nn=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],rn=/^\d+$/,an=e=>e.padStart(2,`0`),on=e=>/^\*\/(\d+)$/.exec(e)?.[1],sn=(e,t)=>e===`1`?`Every ${t}`:`Every ${e} ${t}s`;function cn(e){let[t=``,n=``,r,i,a=``,...o]=e.trim().split(/\s+/);if(o.length||r!==`*`||i!==`*`)return e;if(n===`*`&&a===`*`){if(t===`*`)return`Every minute`;let n=on(t);return n?sn(n,`minute`):rn.test(t)?Number(t)?`Every hour at :${an(t)}`:`Every hour`:e}if(!rn.test(t))return e;let s=on(n);if(s&&a===`*`)return`${sn(s,`hour`)}${Number(t)?` at :${an(t)}`:``}`;if(!rn.test(n))return e;let c=`${an(n)}:${an(t)}`;return a===`*`?`Daily at ${c}`:a===`1-5`?`Weekdays at ${c}`:a===`0,6`||a===`6,0`?`Weekends at ${c}`:/^[0-7]$/.test(a)?`${nn[Number(a)%7]}s at ${c}`:e}var ln=[{name:`minute`,min:0,max:59,names:[]},{name:`hour`,min:0,max:23,names:[]},{name:`day of month`,min:1,max:31,names:[]},{name:`month`,min:1,max:12,names:[`JAN`,`FEB`,`MAR`,`APR`,`MAY`,`JUN`,`JUL`,`AUG`,`SEP`,`OCT`,`NOV`,`DEC`]},{name:`weekday`,min:0,max:7,names:[`SUN`,`MON`,`TUE`,`WED`,`THU`,`FRI`,`SAT`]}];function un(e,t){let n=e=>{let n=t.names.indexOf(e.toUpperCase()),r=n>=0?n+ +(t.min===1):rn.test(e)?Number(e):NaN;return r>=t.min&&r<=t.max?r:NaN};return e.split(`,`).every(e=>{let t=/^(\*|[a-z0-9]+(?:-[a-z0-9]+)?)(?:\/(\d+))?$/i.exec(e);if(!t?.[1]||t[2]!==void 0&&Number(t[2])<1)return!1;if(t[1]===`*`)return!0;let[r=``,i]=t[1].split(`-`);return i===void 0?!Number.isNaN(n(r)):n(r)<=n(i)})}function dn(e){let t=e.trim().split(/\s+/).filter(Boolean);if(!t.length)return`Enter a cron expression.`;if(t.length!==5)return`A cron expression has 5 fields (minute hour day month weekday); this one has ${t.length}.`;for(let[e,n]of ln.entries()){let r=t[e]??``;if(!un(r,n))return`The ${n.name} field "${r}" is not valid. Use a number from ${n.min} to ${n.max}, *, a range (1-5), a list (1,3) or a step (*/2).`}return null}function fn(e){let t=Math.max(0,Math.round((e-Date.now())/1e3));if(t<60)return`in under a minute`;if(t<3600)return`in ${Math.round(t/60)}m`;if(t<86400)return`in ${Math.round(t/3600)}h`;let n=new Date(e);return`${nn[n.getDay()]?.slice(0,3)} ${an(String(n.getHours()))}:${an(String(n.getMinutes()))}`}function pn(e){let t=Math.max(0,Math.round((Date.now()-e)/1e3));return t<60?`just now`:t<3600?`${Math.round(t/60)}m ago`:t<86400?`${Math.round(t/3600)}h ago`:`${Math.round(t/86400)}d ago`}function mn(e){let t=e.last_run?.status;return t===`running`?`progress`:e.schedule.type===`cron`&&!e.enabled?`off`:t===`failed`?`error`:t===`completed`?`ok`:`off`}function hn({kb:e}){let t=ht(e.id),[n,r]=(0,J.useState)(null),[i,a]=(0,J.useState)(!1),o=t.data;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(tn,{title:`Digest`,testId:`kb-digest`,toggleTestId:`kb-digest-expand`,expanded:i,onExpandedChange:a,summary:t.error?(0,X.jsx)(`span`,{role:`alert`,className:`text-error`,children:t.error.message}):t.isLoading?(0,X.jsx)(`span`,{className:`text-outline`,children:`Loading…`}):o?(0,X.jsx)(gn,{digest:o}):(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-outline`,"data-testid":`kb-digest-off`,children:[(0,X.jsx)(Z,{tone:`off`}),`Off, documents change only when someone edits them`]}),actions:o?(0,X.jsx)(_n,{kb:e,digest:o,onStarted:()=>a(!0)}):t.data===null?(0,X.jsx)(u,{size:`sm`,variant:`outline`,"data-testid":`kb-digest-add`,onClick:()=>r(`edit`),children:`Set up`}):null,children:o?(0,X.jsx)(vn,{kb:e,digest:o,onEdit:()=>r(`edit`)}):(0,X.jsx)(`p`,{className:`max-w-prose text-outline`,children:`A digest is an agent that reads new memories, sessions and open comments, then keeps the documents in this knowledge base current. It can run on a schedule or only when you start it.`})}),n===`edit`&&(0,X.jsx)(Hn,{kb:e,digest:o??null,onClose:()=>r(null),onRemove:()=>r(`remove`)}),n===`remove`&&(0,X.jsx)(Un,{kb:e,onClose:()=>r(null)})]})}function gn({digest:e}){let t=e.last_run,n=e.schedule.type===`manual`||e.enabled;return(0,X.jsxs)(`span`,{"data-testid":`kb-digest-summary`,className:`inline-flex min-w-0 flex-wrap items-center gap-x-1.5`,children:[(0,X.jsx)(Z,{tone:mn(e)}),(0,X.jsx)(`span`,{"data-testid":`kb-digest-enabled`,children:n?`On`:`Paused`}),(0,X.jsxs)(`span`,{children:[`·`,` `,e.schedule.type===`manual`?`runs when you start it`:(0,X.jsx)(`span`,{title:e.schedule.cron,children:cn(e.schedule.cron)})]}),e.next_run_at!==null&&(0,X.jsxs)(`span`,{className:`text-outline`,"data-testid":`kb-digest-next-run`,children:[`·`,` `,(0,X.jsxs)(`span`,{title:new Date(e.next_run_at).toLocaleString(),children:[`next run `,fn(e.next_run_at)]})]}),(0,X.jsxs)(`span`,{className:`text-outline`,"data-testid":`kb-digest-last-run`,"data-status":t?.status??`never`,children:[`·`,` `,t?t.status===`running`?`running now`:(0,X.jsxs)(`span`,{title:new Date(t.at).toLocaleString(),children:[`last run`,` `,(0,X.jsx)(`span`,{className:t.status===`failed`?`text-error`:void 0,children:t.status===`completed`?`succeeded`:t.status}),` `,pn(t.at)]}):`not run yet`]})]})}function _n({kb:e,digest:t,onStarted:n}){let r=q(),i=Q(),a=t.last_run?.status===`running`;async function o(){await i.run(()=>O.kb.runDigest(e.id))&&(n(),await r())}return(0,X.jsxs)(X.Fragment,{children:[i.error&&(0,X.jsx)(`span`,{role:`alert`,className:`text-error`,"data-testid":`kb-digest-error`,children:i.error}),(0,X.jsx)(u,{size:`sm`,variant:`outline`,"data-testid":`kb-digest-run`,onClick:o,disabled:i.pending||a,children:a?`Running…`:`Run now`})]})}function vn({kb:e,digest:t,onEdit:n}){let r=q(),i=Q(),a=wt(e.id,t);async function o(){await i.run(()=>O.kb.setDigest(e.id,{enabled:!t.enabled}))&&await r()}return(0,X.jsxs)(`div`,{className:`min-w-0 space-y-3`,children:[(0,X.jsxs)(`p`,{className:`max-w-prose text-outline`,children:[`The `,(0,X.jsx)(`span`,{className:`font-mono text-on-surface`,children:t.backend}),` agent reads new memories, sessions and open comments, then updates documents here.`,` `,(0,X.jsx)(`span`,{"data-testid":`kb-digest-open-comments`,children:t.open_comments}),` open`,` `,t.open_comments===1?`comment waits`:`comments wait`,` for the next run.`]}),(0,X.jsxs)(`div`,{className:`-ml-2 flex flex-wrap items-center gap-1`,children:[(0,X.jsx)(u,{size:`sm`,variant:`ghost`,"data-testid":`kb-digest-edit`,onClick:n,children:`Edit instructions and schedule`}),t.schedule.type===`cron`&&(0,X.jsx)(u,{size:`sm`,variant:`ghost`,"data-testid":`kb-digest-toggle`,onClick:o,disabled:i.pending,children:t.enabled?`Pause schedule`:`Resume schedule`}),(0,X.jsx)(u,{size:`sm`,variant:`ghost`,asChild:!0,children:(0,X.jsx)(s,{to:`/jobs/${encodeURIComponent(t.job_id)}`,"data-testid":`kb-digest-job`,children:`Job history`})})]}),i.error&&(0,X.jsx)(`p`,{role:`alert`,className:`text-error`,"data-testid":`kb-digest-error`,children:i.error}),(0,X.jsx)(bn,{runs:a.data??[]})]})}var yn={failed:`error`,success:`ok`,running:`progress`};function bn({runs:e}){return e.length?(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`h4`,{className:`text-xs font-medium text-outline`,children:`Recent runs`}),(0,X.jsx)(`ol`,{"data-testid":`kb-digest-runs`,className:`divide-y divide-outline-variant`,children:e.map(e=>(0,X.jsxs)(`li`,{"data-testid":`kb-digest-run-row`,"data-status":e.status,className:`min-w-0 wrap-break-word py-1.5`,children:[(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(Z,{tone:yn[e.status]??`off`}),e.status]}),(0,X.jsxs)(`span`,{className:`text-outline`,children:[` · `,e.started_at?(0,X.jsx)(`span`,{title:new Date(e.started_at).toLocaleString(),children:pn(e.started_at)}):`not started`,e.trigger_by?` · ${e.trigger_by}`:``]}),e.session_id&&(0,X.jsx)(s,{to:`/audit/${encodeURIComponent(e.session_id)}`,className:`ml-2 text-primary hover:underline`,children:`Session`}),(e.error||e.summary)&&(0,X.jsx)(`span`,{className:`block truncate text-xs text-outline`,title:e.error??e.summary??``,children:e.error??e.summary})]},e.run_id))})]}):(0,X.jsx)(`p`,{className:`text-outline`,children:`No runs yet.`})}var xn=`__global__`,Sn=`__auto__`;function Cn(e){return e instanceof Error?e.message:`Request failed`}function Q(){let[e,t]=(0,J.useState)(!1),[n,r]=(0,J.useState)(null);async function i(e){t(!0),r(null);try{return await e()}catch(e){r(Cn(e));return}finally{t(!1)}}return{pending:e,error:n,run:i,setError:r}}function $({label:e,children:t,hint:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(b,{className:`text-sm text-muted-foreground`,children:e}),t,n&&(0,X.jsx)(`p`,{className:`text-xs text-outline`,children:n})]})}function wn({error:e}){return e?(0,X.jsx)(`p`,{role:`alert`,"data-testid":`kb-dialog-error`,className:`text-sm text-error`,children:e}):null}function Tn({open:e,onClose:t,title:n,wide:r,size:i,children:a}){return(0,X.jsx)(ie,{open:e,onOpenChange:e=>!e&&t(),children:(0,X.jsxs)(ne,{className:`bg-surface border-outline-variant ${i===`xl`?`w-[calc(100%-1rem)] max-w-4xl`:r?`max-w-3xl`:`max-w-md`}`,children:[(0,X.jsx)(te,{children:(0,X.jsx)(re,{className:`text-base text-on-surface`,children:n})}),a]})})}function En({value:e,onChange:t}){let n=vt();return(0,X.jsxs)(C,{value:e??Sn,onValueChange:e=>t(e===Sn?null:e),children:[(0,X.jsx)(x,{"aria-label":`Parser`,"data-testid":`kb-parser-select`,children:(0,X.jsx)(w,{})}),(0,X.jsxs)(T,{children:[(0,X.jsx)(S,{value:Sn,children:`Workspace default`}),(n.data?.parsers??[]).map(e=>(0,X.jsxs)(S,{value:e.id,disabled:!e.installed,children:[e.label,e.installed?``:` (not installed)`]},e.id))]})]})}var Dn={ui:`Web UI`,cli:`CLI`,api:`REST API`,mcp:`Agents (MCP)`};function On({value:e,onChange:t}){return(0,X.jsxs)(`fieldset`,{className:`space-y-2 rounded-md border border-outline-variant p-3`,children:[(0,X.jsx)(`legend`,{className:`px-1 text-sm text-muted-foreground`,children:`Who can change documents`}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-2`,children:Y.map(n=>(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,X.jsx)(`input`,{type:`checkbox`,"data-testid":`kb-editable-${n}`,checked:e.includes(n),onChange:r=>t(Y.filter(t=>t===n?r.target.checked:e.includes(t)))}),Dn[n]]},n))}),(0,X.jsx)(`p`,{className:`text-xs text-outline`,children:`Every source can read and search. Knowledge base settings change only from the UI, CLI or API.`})]})}function kn({open:e,projectId:t,onClose:n,onCreated:r}){let i=Be(),a=q(),o=Q(),[s,c]=(0,J.useState)(``),[l,d]=(0,J.useState)(``),[f,p]=(0,J.useState)(t??xn),[m,h]=(0,J.useState)([...Y]),[g,_]=(0,J.useState)(null);async function v(e){e.preventDefault();let t=await o.run(()=>O.kb.create({name:s.trim(),description:l.trim(),project_id:f===xn?null:f,editable_by:m,parser:g}));t&&(await a(),r(t))}return(0,X.jsx)(Tn,{open:e,onClose:n,title:`New knowledge base`,children:(0,X.jsxs)(`form`,{onSubmit:v,className:`space-y-4`,children:[(0,X.jsx)($,{label:`Name`,children:(0,X.jsx)(K,{"aria-label":`Name`,"data-testid":`kb-name-input`,value:s,onChange:e=>c(e.target.value),placeholder:`e.g. Runbooks`,autoFocus:!0})}),(0,X.jsx)($,{label:`Description`,children:(0,X.jsx)(W,{"aria-label":`Description`,value:l,onChange:e=>d(e.target.value),rows:2})}),(0,X.jsx)($,{label:`Belongs to`,hint:`Project knowledge bases are visible in that project; global ones in every project.`,children:(0,X.jsxs)(C,{value:f,onValueChange:p,children:[(0,X.jsx)(x,{"aria-label":`Belongs to`,"data-testid":`kb-owner-select`,children:(0,X.jsx)(w,{})}),(0,X.jsxs)(T,{children:[(0,X.jsx)(S,{value:xn,children:`Global (all projects)`}),(i.data??[]).map(e=>(0,X.jsx)(S,{value:e.id,children:e.name},e.id))]})]})}),(0,X.jsx)(On,{value:m,onChange:h}),(0,X.jsx)($,{label:`Parser for uploads`,children:(0,X.jsx)(En,{value:g,onChange:_})}),(0,X.jsx)(wn,{error:o.error}),(0,X.jsxs)(G,{children:[(0,X.jsx)(u,{type:`button`,variant:`ghost`,onClick:n,children:`Cancel`}),(0,X.jsx)(u,{type:`submit`,"data-testid":`kb-create-submit`,disabled:!s.trim()||o.pending,children:o.pending?`Creating…`:`Create`})]})]})})}function An({kb:e,onClose:t,onDeleted:n}){let r=Be(),i=q(),a=Q(),[o,s]=(0,J.useState)(e.name),[c,l]=(0,J.useState)(e.description),[d,f]=(0,J.useState)(e.editable_by),[p,m]=(0,J.useState)(e.parser),[h,g]=(0,J.useState)(!1);async function _(n){n.preventDefault(),await a.run(()=>O.kb.update(e.id,{name:o.trim(),description:c.trim(),editable_by:d,parser:p}))&&(await i(),t())}return(0,X.jsxs)(Tn,{open:!0,onClose:t,title:`Knowledge base settings`,children:[(0,X.jsxs)(`form`,{onSubmit:_,className:`space-y-4`,children:[(0,X.jsx)($,{label:`Name`,children:(0,X.jsx)(K,{"aria-label":`Name`,"data-testid":`kb-name-input`,value:o,onChange:e=>s(e.target.value)})}),(0,X.jsx)($,{label:`Description`,children:(0,X.jsx)(W,{"aria-label":`Description`,value:c,onChange:e=>l(e.target.value),rows:2})}),(0,X.jsxs)(`div`,{className:`space-y-1 text-sm`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:`Belongs to`}),(0,X.jsxs)(`p`,{className:`text-outline`,"data-testid":`kb-settings-owner`,children:[e.project_id===null?`Global, visible in every project`:`${r.data?.find(t=>t.id===e.project_id)?.name??`A project`}, visible in that project`,`. Set when the knowledge base is created.`]})]}),(0,X.jsx)(On,{value:d,onChange:f}),(0,X.jsx)($,{label:`Parser for uploads`,hint:`Applies to new uploads and reparses.`,children:(0,X.jsx)(En,{value:p,onChange:m})}),(0,X.jsx)(wn,{error:a.error}),(0,X.jsxs)(G,{className:`gap-2 sm:justify-between`,children:[(0,X.jsxs)(u,{type:`button`,variant:`ghost`,className:`text-error`,"data-testid":`kb-delete`,onClick:()=>g(!0),children:[(0,X.jsx)(ge,{size:14}),`Delete`]}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(u,{type:`button`,variant:`ghost`,onClick:t,children:`Cancel`}),(0,X.jsx)(u,{type:`submit`,"data-testid":`kb-settings-save`,disabled:!o.trim()||a.pending,children:`Save`})]})]})]}),(0,X.jsx)(Ge,{open:h,title:`Delete knowledge base`,description:`Delete "${e.name}" with its ${e.document_count} documents, revisions and uploaded files? Registered folders on disk are not touched.`,isPending:a.pending,onCancel:()=>g(!1),onConfirm:async()=>{let t=await a.run(()=>O.kb.remove(e.id));g(!1),t!==void 0&&(await i(),n())}})]})}function jn(e){return`${e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`untitled`}.md`}function Mn(e){return e.match(/^#\s+(.+?)\s*#*\s*$/m)?.[1]?.trim()??``}var Nn=/\.(md|markdown|txt)$/i;function Pn({kb:e,initialFile:t,onClose:n,onCreated:r,onUploadMany:i}){let a=q(),o=Q(),s=Ot(e.id),[c,l]=(0,J.useState)(``),[f,p]=(0,J.useState)(``),[m,h]=(0,J.useState)(``),[g,_]=(0,J.useState)([]),[v,b]=(0,J.useState)(null),[x,S]=(0,J.useState)(!1),C=(0,J.useRef)(null),w=v?``:Mn(f),T=c.trim()||w,E=v?v.name:jn(T),D=v!==null||f.trim()!==``;async function k(e){let t=e.name.replace(/\.[^.]+$/,``);if(!Nn.test(e.name)){b(e),l(t),h(``);return}S(!0);let n=await o.run(()=>e.text());S(!1),n!==void 0&&(b(null),p(n),l(Mn(n)||t),h(/\.txt$/i.test(e.name)?jn(t):e.name))}function j(e){let t=[...e??[]];t.length>1?i(t):t[0]&&k(t[0])}(0,J.useEffect)(()=>{t&&k(t)},[]);async function N(t){t.preventDefault();let n=await o.run(()=>v?O.kb.upload(e.id,{file:v,title:T,path:m.trim()||void 0,labels:g}):O.kb.createDocument(e.id,{title:T,path:m.trim()||E,labels:g,content:D?f:`# ${T}\n\n`}));n&&(await a(),r(n,D))}return(0,X.jsx)(Tn,{open:!0,onClose:n,title:`New document in ${e.name}`,size:`xl`,children:(0,X.jsxs)(`form`,{onSubmit:N,className:`space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-sm text-outline`,children:[(0,X.jsx)(`span`,{children:`Write or paste below, or start from a file.`}),(0,X.jsxs)(u,{type:`button`,size:`sm`,variant:`outline`,"data-testid":`kb-doc-choose-file`,disabled:x||o.pending,onClick:()=>C.current?.click(),children:[(0,X.jsx)(M,{size:16}),x?`Reading…`:`Upload file`]}),(0,X.jsx)(`input`,{ref:C,type:`file`,multiple:!0,hidden:!0,"data-testid":`kb-doc-file-input`,onChange:e=>{j(e.target.files),e.target.value=``}})]}),(0,X.jsx)($,{label:`Title`,hint:w&&!c.trim()?`Taken from the first heading.`:void 0,children:(0,X.jsx)(K,{"aria-label":`Title`,"data-testid":`kb-doc-title-input`,value:c,onChange:e=>l(e.target.value),placeholder:w||`e.g. Deploy runbook`,autoFocus:!0})}),v?(0,X.jsx)($,{label:`File`,hint:`Converted to searchable text after it is added. The original file is kept.`,children:(0,X.jsxs)(`div`,{"data-testid":`kb-doc-file`,className:`flex items-center gap-3 rounded-md border border-surface-highest bg-surface p-3`,children:[(0,X.jsx)(Ae,{size:20,className:`shrink-0 text-outline`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm`,title:v.name,children:v.name}),(0,X.jsx)(`span`,{className:`shrink-0 text-xs text-outline`,children:d(v.size)}),(0,X.jsx)(u,{type:`button`,size:`icon`,variant:`ghost`,"aria-label":`Remove ${v.name}`,"data-testid":`kb-doc-file-remove`,onClick:()=>{b(null),l(``)},children:(0,X.jsx)(y,{size:16})})]})}):(0,X.jsx)($,{label:`Content`,hint:`Markdown. Leave empty to start writing in the editor.`,children:(0,X.jsx)(A,{path:m.trim()||E,value:f,onChange:p,testId:`kb-doc-content-input`,label:`Content`,placeholder:`Write or paste Markdown`,initialMode:`edit`,height:`45vh`})}),(0,X.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,X.jsx)($,{label:`Labels`,hint:`Enter, comma or space adds a label.`,children:(0,X.jsx)(At,{"aria-label":`Labels`,"data-testid":`kb-doc-labels-input`,value:g,onChange:_,suggestions:s.data?.labels.map(e=>e.label)})}),(0,X.jsx)($,{label:`Path`,hint:`Optional. Folders come from the path, e.g. guides/setup.md.`,children:(0,X.jsx)(K,{"aria-label":`Path`,"data-testid":`kb-doc-path-input`,value:m,onChange:e=>h(e.target.value),placeholder:E,className:`font-mono text-sm`})})]}),(0,X.jsx)(wn,{error:o.error}),(0,X.jsxs)(G,{children:[(0,X.jsx)(u,{type:`button`,variant:`ghost`,onClick:n,children:`Cancel`}),(0,X.jsx)(u,{type:`submit`,"data-testid":`kb-doc-create-submit`,disabled:!T||o.pending,children:`Create`})]})]})})}function Fn({doc:e,linkedFrom:t,onClose:n,onSaved:r}){let i=q(),a=Q(),[o,s]=(0,J.useState)(e.title),[c,l]=(0,J.useState)(e.path),d=Ot(e.kb_id),[f,p]=(0,J.useState)(e.labels),[m,h]=(0,J.useState)(e.description),g=o.trim()!==e.title||c.trim()!==e.path;async function _(t){t.preventDefault(),await a.run(()=>O.kb.updateDocument(e.id,{expected_revision:e.revision,title:o.trim(),path:c.trim(),labels:f,description:m.trim()}))&&(await i(),r())}return(0,X.jsx)(Tn,{open:!0,onClose:n,title:`Document properties`,children:(0,X.jsxs)(`form`,{onSubmit:_,className:`space-y-4`,children:[(0,X.jsx)($,{label:`Title`,children:(0,X.jsx)(K,{"aria-label":`Title`,"data-testid":`kb-doc-title-input`,value:o,onChange:e=>s(e.target.value)})}),(0,X.jsx)($,{label:`Path`,children:(0,X.jsx)(K,{"aria-label":`Path`,"data-testid":`kb-doc-path-input`,value:c,onChange:e=>l(e.target.value),className:`font-mono text-sm`})}),(0,X.jsx)($,{label:`Labels`,hint:`Enter, comma or space adds a label.`,children:(0,X.jsx)(At,{"aria-label":`Labels`,"data-testid":`kb-doc-labels-input`,value:f,onChange:p,suggestions:d.data?.labels.map(e=>e.label)})}),(0,X.jsx)($,{label:`Description`,children:(0,X.jsx)(W,{"aria-label":`Description`,value:m,onChange:e=>h(e.target.value),rows:2})}),g&&t>0&&(0,X.jsxs)(`p`,{role:`status`,className:`text-sm text-warning`,"data-testid":`kb-rename-warning`,children:[t===1?`1 document links`:`${t} documents link`,` to this document. Links that use the old title or path will show as missing.`]}),(0,X.jsx)(wn,{error:a.error}),(0,X.jsxs)(G,{children:[(0,X.jsx)(u,{type:`button`,variant:`ghost`,onClick:n,children:`Cancel`}),(0,X.jsx)(u,{type:`submit`,"data-testid":`kb-doc-properties-save`,disabled:!o.trim()||a.pending,children:`Save`})]})]})})}var In={daily:`Every day`,weekly:`Once a week`,custom:`Custom cron`,manual:`Manual only`};function Ln(e){let t=e.type===`cron`?e.cron:en,n={plan:`custom`,time:`03:00`,day:`1`,cron:t},r=/^(\d{1,2}) (\d{1,2}) \* \* (\*|[0-6])$/.exec(t.trim().split(/\s+/).join(` `)),[i,a]=[Number(r?.[1]),Number(r?.[2])],o=r&&i<=59&&a<=23?`${String(a).padStart(2,`0`)}:${String(i).padStart(2,`0`)}`:null;return e.type===`manual`?{...n,plan:`manual`,time:o??n.time}:!r?.[3]||!o?n:r[3]===`*`?{...n,plan:`daily`,time:o}:{...n,plan:`weekly`,time:o,day:r[3]}}function Rn({plan:e,time:t,day:n,cron:r}){if(e===`manual`)return null;if(e===`custom`)return r.trim();let[i,a]=t.split(`:`).map(Number);return`${a} ${i} * * ${e===`weekly`?n:`*`}`}function zn(e){return e.plan===`manual`?null:e.plan===`custom`?dn(e.cron):/^\d{2}:\d{2}$/.test(e.time)?null:`Pick a time.`}function Bn(e){let t=cn(e);return t===e?`Runs on this cron schedule`:nn.some(e=>t.startsWith(e))?`Runs ${t}`:`Runs ${t.charAt(0).toLowerCase()}${t.slice(1)}`}function Vn({value:e,onChange:t}){let n=Rn(e),r=zn(e),i=n=>t({...e,...n});return(0,X.jsxs)(`fieldset`,{className:`space-y-3 rounded-md border border-outline-variant p-3`,children:[(0,X.jsx)(`legend`,{className:`px-1 text-sm text-muted-foreground`,children:`When it runs`}),(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,X.jsx)($,{label:`Schedule`,children:(0,X.jsxs)(C,{value:e.plan,onValueChange:e=>i({plan:e,...e===`custom`&&n?{cron:n}:{}}),children:[(0,X.jsx)(x,{"aria-label":`Schedule`,"data-testid":`kb-digest-schedule`,children:(0,X.jsx)(w,{})}),(0,X.jsx)(T,{children:Object.keys(In).map(e=>(0,X.jsx)(S,{value:e,children:In[e]},e))})]})}),e.plan===`weekly`&&(0,X.jsx)($,{label:`Day`,children:(0,X.jsxs)(C,{value:e.day,onValueChange:e=>i({day:e}),children:[(0,X.jsx)(x,{"aria-label":`Day`,"data-testid":`kb-digest-day`,children:(0,X.jsx)(w,{})}),(0,X.jsx)(T,{children:nn.map((e,t)=>(0,X.jsx)(S,{value:String(t),children:e},e))})]})}),(e.plan===`daily`||e.plan===`weekly`)&&(0,X.jsx)($,{label:`Time`,children:(0,X.jsx)(K,{type:`time`,"aria-label":`Time`,"data-testid":`kb-digest-time`,value:e.time,onChange:e=>i({time:e.target.value})})}),e.plan===`custom`&&(0,X.jsx)(`div`,{className:`sm:col-span-2`,children:(0,X.jsx)($,{label:`Cron expression`,hint:`minute hour day month weekday, e.g. 0 */6 * * *`,children:(0,X.jsx)(K,{"aria-label":`Cron expression`,"aria-invalid":r!==null,"data-testid":`kb-digest-cron`,value:e.cron,onChange:e=>i({cron:e.target.value}),className:`font-mono`,autoComplete:`off`})})})]}),(0,X.jsx)(`p`,{"aria-live":`polite`,"data-testid":`kb-digest-schedule-preview`,"data-valid":r===null,className:`text-sm ${r?`text-error`:`text-outline`}`,children:r||(n?(0,X.jsxs)(X.Fragment,{children:[Bn(n),` `,(0,X.jsxs)(`span`,{className:`font-mono text-xs`,children:[`(`,n,`)`]}),`, in the ORC server's time zone.`]}):`Runs only when you start it.`)})]})}function Hn({kb:e,digest:t,onClose:n,onRemove:r}){let i=q(),a=Q(),o=Oe(),s=Et(!t),[c,l]=(0,J.useState)(t?.instructions??null),[d,f]=(0,J.useState)(t?.backend??`__default__`),[p,m]=(0,J.useState)(()=>Ln(t?.schedule??{type:`cron`,cron:`0 3 * * *`}));(0,J.useEffect)(()=>{c===null&&s.data&&l(s.data.instructions)},[c,s.data]);let h=zn(p);async function g(t){if(t.preventDefault(),h)return a.setError(h);let r=d===`__default__`?o.data?.default_backend:d,s=Rn(p);await a.run(()=>O.kb.setDigest(e.id,{instructions:c?.trim()??``,...r?{backend:r}:{},schedule:s?{type:`cron`,cron:s}:{type:`manual`}}))&&(await i(),n())}let _=c!==null;return(0,X.jsx)(Tn,{open:!0,onClose:n,title:t?`Digest settings`:`Set up a digest`,wide:!0,children:(0,X.jsxs)(`form`,{onSubmit:g,className:`min-w-0 space-y-4`,children:[!e.editable_by.includes(`mcp`)&&(0,X.jsx)(`p`,{className:`text-sm text-warning`,"data-testid":`kb-digest-mcp-hint`,children:`The digest writes through MCP. Allow Agents (MCP) in this knowledge base's settings first.`}),(0,X.jsx)(Vn,{value:p,onChange:m}),(0,X.jsx)(Pe,{value:d,onChange:f,testId:`kb-digest-backend`}),(0,X.jsx)($,{label:`Instructions`,children:_?(0,X.jsx)(A,{path:`digest.md`,value:c,onChange:l,testId:`kb-digest-instructions`,label:`Instructions`,initialMode:`edit`,height:320}):s.error?(0,X.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:Cn(s.error)}):(0,X.jsx)(`p`,{role:`status`,className:`text-sm text-outline`,children:`Loading template…`})}),(0,X.jsx)(wn,{error:a.error}),(0,X.jsxs)(G,{className:`gap-2 sm:justify-between`,children:[t&&r?(0,X.jsxs)(u,{type:`button`,variant:`ghost`,className:`text-error`,"data-testid":`kb-digest-remove`,onClick:r,children:[(0,X.jsx)(ge,{size:14}),`Remove digest`]}):(0,X.jsx)(`span`,{}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(u,{type:`button`,variant:`ghost`,onClick:n,children:`Cancel`}),(0,X.jsx)(u,{type:`submit`,"data-testid":`kb-digest-save`,disabled:!_||!c?.trim()||h!==null||a.pending,children:a.pending?`Saving…`:`Save`})]})]})]})})}function Un({kb:e,onClose:t}){let n=r(),i=Q();async function a(){await i.run(()=>O.kb.removeDigest(e.id,e.name))!==void 0&&(n.setQueryData([Ct,e.id],{digest:null}),await n.invalidateQueries({queryKey:[`kb`]}),t())}return(0,X.jsx)(Tn,{open:!0,onClose:t,title:`Remove digest?`,children:(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsx)(`p`,{className:`text-sm text-outline`,children:`Documents and comments stay. The digest's instructions, schedule, job and run history are removed.`}),(0,X.jsx)(wn,{error:i.error}),(0,X.jsxs)(G,{children:[(0,X.jsx)(u,{type:`button`,variant:`ghost`,onClick:t,children:`Cancel`}),(0,X.jsx)(u,{type:`button`,variant:`destructive`,"data-testid":`kb-digest-remove-confirm`,onClick:a,disabled:i.pending,autoFocus:!0,children:i.pending?`Removing…`:`Remove digest`})]})]})})}var Wn={open:`bg-warning`,resolved:`bg-secondary`,dismissed:`bg-muted-foreground`};function Gn({status:e}){return(0,X.jsx)(`span`,{"aria-hidden":!0,className:l(`size-1.5 shrink-0 rounded-full`,Wn[e])})}function Kn({kbId:e,documentId:t,onOpenDocument:n,heading:r=`h3`,compact:i=!1}){let[a,o]=(0,J.useState)(!1),[s,c]=(0,J.useState)(null),u=bt(e,{...t?{document_id:t}:{},...s?{status:s}:{}}),d=u.data?.counts,f=d?d.open+d.resolved+d.dismissed:0;function p(e){c(a&&s===e?null:e),o(!0)}return(0,X.jsx)(tn,{title:`Comments`,testId:`kb-comments`,toggleTestId:`kb-comments-toggle`,heading:r,compact:i,expanded:a,onExpandedChange:o,summary:(0,X.jsxs)(X.Fragment,{children:[d&&f===0&&(0,X.jsx)(`span`,{className:`text-outline`,"data-testid":`kb-comments-none`,children:`None yet`}),d&&Qt.filter(e=>d[e]>0).map(e=>(0,X.jsxs)(`button`,{type:`button`,"data-testid":`kb-comments-count-${e}`,"aria-pressed":a&&s===e,"aria-label":`${d[e]} ${e} ${d[e]===1?`comment`:`comments`}`,className:l(`inline-flex min-h-8 items-center gap-1.5 rounded px-1.5`,a&&s===e?`bg-surface-highest text-on-surface`:`text-outline hover:bg-surface-high`),onClick:()=>p(e),children:[(0,X.jsx)(Gn,{status:e}),(0,X.jsx)(`span`,{className:`tabular-nums text-on-surface`,children:d[e]}),e]},e)),u.error&&(0,X.jsx)(`span`,{role:`alert`,className:`text-error`,"data-testid":`kb-comments-error`,children:u.error.message})]}),children:(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsx)(qn,{kbId:e,documentId:t}),s&&u.data?.comments.length===0&&(0,X.jsxs)(`p`,{className:`text-outline`,"data-testid":`kb-comments-empty`,children:[`No `,s,` comments.`]}),(0,X.jsx)(`ul`,{className:`divide-y divide-outline-variant`,children:u.data?.comments.map(e=>(0,X.jsx)(Jn,{comment:e,showDocument:!t,onOpenDocument:n},e.id))})]})})}function qn({kbId:e,documentId:t}){let n=q(),r=Q(),[i,a]=(0,J.useState)(``);async function o(o){o.preventDefault(),await r.run(()=>O.kb.addComment(e,{body:i.trim(),...t?{document_id:t}:{}}))&&(a(``),await n())}return(0,X.jsxs)(`form`,{onSubmit:o,className:`space-y-2`,children:[(0,X.jsx)(W,{"aria-label":t?`Comment on this document`:`Comment on this knowledge base`,placeholder:t?`Ask for a change to this document`:`Ask for a change`,"data-testid":`kb-comment-input`,value:i,onChange:e=>a(e.target.value),rows:2,maxLength:1e4}),i.trim()&&(0,X.jsx)(u,{type:`submit`,size:`sm`,variant:`outline`,"data-testid":`kb-comment-add`,disabled:r.pending,children:`Add comment`}),r.error&&(0,X.jsx)(`p`,{role:`alert`,className:`text-error`,"data-testid":`kb-comment-add-error`,children:r.error})]})}function Jn({comment:e,showDocument:t,onOpenDocument:n}){let r=q(),i=Q(),[a,o]=(0,J.useState)(null),[s,c]=(0,J.useState)(``);async function l(t){if(t.preventDefault(),!a)return;let n=a;await i.run(()=>O.kb.closeComment(e.id,{status:n,reply:s.trim()}))&&(o(null),c(``),await r())}async function d(){await i.run(()=>O.kb.reopenComment(e.id))&&await r()}return(0,X.jsxs)(`li`,{"data-testid":`kb-comment`,"data-status":e.status,className:`min-w-0 space-y-1 py-2`,children:[(0,X.jsxs)(`p`,{className:`flex min-w-0 flex-wrap items-center gap-x-2 text-xs text-outline`,children:[(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-on-surface`,children:[(0,X.jsx)(Gn,{status:e.status}),(0,X.jsx)(`span`,{"data-testid":`kb-comment-status`,children:e.status})]}),(0,X.jsxs)(`span`,{className:`min-w-0 wrap-break-word`,children:[e.source===e.author?e.author:`${e.author} via ${e.source}`,` ·`,` `,new Date(e.created_at).toLocaleString(),t&&e.document_id&&(0,X.jsxs)(X.Fragment,{children:[` · on `,n?(0,X.jsx)(`button`,{type:`button`,className:`text-primary hover:underline`,onClick:()=>e.document_id&&n(e.document_id),children:e.document_title??`a deleted document`}):e.document_title??`a deleted document`]})]})]}),(0,X.jsx)(`p`,{className:`whitespace-pre-wrap wrap-break-word`,children:e.body}),e.reply&&(0,X.jsxs)(`p`,{className:`wrap-break-word text-xs`,"data-testid":`kb-comment-reply-text`,children:[(0,X.jsxs)(`span`,{className:`text-outline`,children:[e.status===`dismissed`?`Dismissed`:`Resolved`,e.resolved_by?` by ${e.resolved_by}`:``,`:`]}),` `,e.reply]}),a?(0,X.jsxs)(`form`,{onSubmit:l,className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(K,{"aria-label":a===`resolved`?`Resolution reply`:`Reason for dismissing`,placeholder:a===`resolved`?`What changed`:`Why not`,"data-testid":`kb-comment-reply`,value:s,onChange:e=>c(e.target.value),maxLength:4e3,autoFocus:!0,className:`min-w-0 flex-1 basis-48`}),(0,X.jsx)(u,{type:`submit`,size:`sm`,"data-testid":`kb-comment-close-submit`,disabled:!s.trim()||i.pending,children:a===`resolved`?`Resolve`:`Dismiss`}),(0,X.jsx)(u,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>{o(null),c(``),i.setError(null)},children:`Cancel`})]}):e.status===`open`?(0,X.jsxs)(`div`,{className:`-ml-2 flex flex-wrap`,children:[(0,X.jsx)(u,{size:`sm`,variant:`ghost`,"data-testid":`kb-comment-resolve`,onClick:()=>o(`resolved`),children:`Resolve`}),(0,X.jsx)(u,{size:`sm`,variant:`ghost`,"data-testid":`kb-comment-dismiss`,onClick:()=>o(`dismissed`),children:`Dismiss`})]}):(0,X.jsx)(u,{size:`sm`,variant:`ghost`,className:`-ml-2`,"data-testid":`kb-comment-reopen`,onClick:d,disabled:i.pending,children:`Reopen`}),i.error&&(0,X.jsx)(`p`,{role:`alert`,className:`text-xs text-error`,"data-testid":`kb-comment-error`,children:i.error})]})}var Yn=e=>`kb:${e}`,Xn={pending:`Processing`,partial:`Partially parsed`,failed:`Failed`,lexical_ready:`Keyword search ready`,semantic_pending:`Embedding`,semantic_ready:`Semantic search ready`};function Zn(e){let t=[...e.currentTarget.querySelectorAll(`[role="menuitem"]:not(:disabled)`)],n=t.indexOf(document.activeElement),r=e.key===`ArrowDown`?(n+1)%t.length:e.key===`ArrowUp`?(n-1+t.length)%t.length:e.key===`Home`?0:e.key===`End`?t.length-1:null;r!==null&&t.length&&(e.preventDefault(),t[r]?.focus())}function Qn({usage:e,testId:t}){return(0,X.jsxs)(`div`,{"data-testid":t,className:`space-y-2`,children:[(0,X.jsxs)(`div`,{className:`text-sm`,children:[(0,X.jsx)(`span`,{"data-testid":`${t}-reads`,className:`font-medium`,children:e.reads}),` `,`reads · `,e.exposures,` search appearances · `,e.distinct_sessions,` sessions`]}),(0,X.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{className:`text-outline`,children:[(0,X.jsx)(`th`,{className:`py-1 text-left font-normal`,children:`Source`}),Vt.map(e=>(0,X.jsx)(`th`,{className:`py-1 text-right font-normal`,children:e===`search_hit`?`listed`:e},e))]})}),(0,X.jsx)(`tbody`,{children:Y.map(n=>(0,X.jsxs)(`tr`,{"data-testid":`${t}-${n}`,className:`border-t border-outline-variant/50`,children:[(0,X.jsx)(`td`,{className:`py-1 uppercase`,children:n}),Vt.map(t=>(0,X.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:e.totals[n][t]},t))]},n))})]}),(0,X.jsxs)(`div`,{className:`text-xs text-outline`,children:[`Last 7 days `,e.window.days_7,` · last 30 days `,e.window.days_30]})]})}function $n({kb:e,doc:t,onHome:n,onOpen:r,onDeleted:i,onReplaceFile:o,detailsOpen:s,onDetailsOpenChange:c}){let f=q(),[p]=a(),m=p.get(`editorMode`),h=bt(t.kb_id,{document_id:t.id}).data?.counts.open??0,[g,_]=(0,J.useState)(!1),[v,y]=(0,J.useState)(!1),[b,x]=(0,J.useState)(!1),S=be(`lg`),[C,w]=(0,J.useState)(null),T=(0,J.useRef)(null),[E,D]=(0,J.useState)(null),[A,j]=(0,J.useState)(!1),M=(0,J.useRef)(null),N=(0,J.useRef)(t.revision),P=new Map(t.links.filter(e=>e.document_id).map(e=>[We(e.target),e.document_id])),F={slugs:[...P.keys()],select:e=>{let t=P.get(e);t&&r(t)}};async function I(e){j(!0),D(null);try{return await e(),await f(),!0}catch(e){return D(e instanceof Error?e.message:`Request failed`),!1}finally{j(!1)}}async function L(){await I(async()=>Ke(await O.kb.original(t.id),t.original_name??t.path.split(`/`).pop()??`document`))}function R(){let e=(t.path.split(`/`).pop()??`document`).replace(/\.(md|markdown)$/i,``);Ke(new Blob([t.content],{type:`text/markdown;charset=utf-8`}),`${e}.md`)}let z=t.origin===`upload`,B=z||t.origin===`external`&&!t.editable,ee=C?.backlinks.filter(e=>!t.backlinks.some(t=>t.document_id===e.document_id))??[],V=(e,t,n,r,i=!1)=>(0,X.jsxs)(`button`,{type:`button`,role:`menuitem`,"data-testid":e,disabled:A,className:l(`flex min-h-9 w-full items-center gap-2 rounded px-2 text-left text-sm outline-hidden hover:bg-surface-highest focus-visible:bg-surface-highest disabled:opacity-50`,i&&`text-error`),onClick:()=>{x(!1),r()},children:[t,n]});return(0,X.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-y-auto lg:flex-row lg:overflow-hidden`,children:[(0,X.jsx)(`article`,{"data-testid":`kb-document`,className:`min-w-0 lg:min-h-0 lg:flex-1 lg:overflow-y-auto`,children:(0,X.jsxs)(`div`,{className:`w-full min-w-0 px-4 pb-16 pt-4 sm:px-8 sm:pt-6`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,X.jsxs)(`nav`,{"aria-label":`Breadcrumb`,className:`flex min-w-0 flex-1 basis-48 items-center gap-1 text-sm text-outline`,children:[(0,X.jsx)(`button`,{type:`button`,"data-testid":`kb-breadcrumb-kb`,className:`min-w-0 max-w-[60%] truncate hover:text-on-surface hover:underline`,onClick:n,children:e.name}),(0,X.jsx)(ze,{size:14,className:`shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`min-w-0 truncate font-mono text-xs`,"data-testid":`kb-document-path`,title:t.path,children:t.path})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,X.jsxs)(u,{size:`sm`,variant:s?`secondary`:`ghost`,"aria-pressed":s,"data-testid":`kb-details-toggle`,onClick:()=>c(!s),children:[(0,X.jsx)(Bt,{size:14}),`Details`,h>0&&(0,X.jsxs)(`span`,{"data-testid":`kb-details-open-comments`,title:`${h} open ${h===1?`comment`:`comments`}`,className:`inline-flex items-center gap-1 text-xs tabular-nums text-outline`,children:[(0,X.jsx)(Z,{tone:`warning`}),h]})]}),(0,X.jsxs)(le,{open:b,onOpenChange:x,children:[(0,X.jsx)(ae,{asChild:!0,children:(0,X.jsx)(u,{size:`icon`,variant:`ghost`,"aria-label":`Document actions`,"aria-haspopup":`menu`,"data-testid":`kb-doc-menu`,children:(0,X.jsx)(ke,{size:16})})}),(0,X.jsx)(Me,{children:(0,X.jsxs)(me,{align:`end`,sideOffset:4,collisionPadding:8,role:`menu`,"aria-label":`Document actions`,className:`z-50 w-52 rounded-md border border-outline-variant bg-surface-high p-1 shadow-lg`,onOpenAutoFocus:e=>{e.preventDefault(),e.currentTarget.querySelector(`[role="menuitem"]:not(:disabled)`)?.focus()},onKeyDown:Zn,children:[V(`kb-doc-properties`,(0,X.jsx)(Le,{size:14}),`Title and labels`,()=>{T.current={title:t.title,backlinks:t.backlinks},_(!0)}),!B&&V(`kb-doc-download-markdown`,(0,X.jsx)(Mt,{size:14}),`Download Markdown`,R),B&&V(`kb-doc-download`,(0,X.jsx)(k,{size:14}),`Download original`,()=>void L()),z&&V(`kb-doc-reparse`,(0,X.jsx)(je,{size:14}),`Parse again`,()=>void I(()=>O.kb.reparse(t.id))),z&&V(`kb-doc-replace`,(0,X.jsx)(It,{size:14}),`Replace file`,()=>M.current?.click()),t.origin!==`external`&&V(`kb-doc-delete`,(0,X.jsx)(ge,{size:14}),`Delete document`,()=>y(!0),!0)]})})]})]})]}),(0,X.jsxs)(`header`,{className:`mb-2 mt-4 space-y-2`,children:[(0,X.jsx)(`h1`,{"data-testid":`kb-document-title`,className:`wrap-break-word text-3xl font-medium`,children:t.title}),t.description&&(0,X.jsx)(`p`,{className:`text-outline`,children:t.description}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1.5 text-xs text-outline`,children:[t.labels.length>0&&(0,X.jsx)(`span`,{className:`flex flex-wrap gap-1`,children:t.labels.map(e=>(0,X.jsx)(Dt,{variant:`secondary`,"data-testid":`kb-document-label`,children:e},e))}),t.parse_state!==`ok`&&(0,X.jsxs)(`span`,{className:l(`inline-flex items-center gap-1.5`,t.parse_state===`failed`&&`text-error`),children:[(0,X.jsx)(Z,{tone:t.parse_state===`failed`?`error`:t.parse_state===`partial`?`warning`:`progress`}),(0,X.jsx)(`span`,{"data-testid":`kb-parse-state`,children:Xn[t.parse_state]})]}),t.folder_sync&&(0,X.jsx)(`span`,{"data-testid":`kb-folder-sync`,title:t.folder_sync===`following`?`Copied from a synced folder; scans pick up changes to the file`:`Edited in ORC; scans no longer change this copy`,children:t.folder_sync===`following`?`Follows folder file`:`Edited, no longer synced`}),t.stale&&(0,X.jsx)(`span`,{className:`text-warning`,"data-testid":`kb-document-stale`,children:`Stale: a source changed`}),(0,X.jsxs)(`span`,{children:[`Updated `,new Date(t.updated_at).toLocaleDateString(),` by `,t.updated_by]})]})]}),t.warnings.length>0&&(0,X.jsx)(`ul`,{"data-testid":`kb-document-warnings`,className:`mb-2 space-y-1 text-sm text-warning`,children:t.warnings.map(e=>(0,X.jsxs)(`li`,{className:`flex gap-2`,children:[(0,X.jsx)(Te,{size:14,className:`mt-0.5 shrink-0`}),e]},e))}),z&&(0,X.jsxs)(`p`,{className:`mb-2 text-sm text-outline`,children:[`Text parsed from `,t.original_name??`the upload`,` (`,d(t.size_bytes),t.parser?`, ${t.parser.id} ${t.parser.version}`:``,`). Replace the file to change it.`]}),t.folder_sync===`following`&&(m===`edit`||m===`split`)&&(0,X.jsx)(`p`,{role:`status`,"data-testid":`kb-folder-sync-warning`,className:`mb-2 text-sm text-warning`,children:`This copy follows a file in a synced folder. Saving here stops it following that file; later changes to the file will not reach it.`}),E&&(0,X.jsx)(`p`,{role:`alert`,"data-testid":`kb-document-error`,className:`mb-2 text-sm text-error`,children:E}),C&&ee.length>0&&(0,X.jsxs)(`div`,{role:`status`,"data-testid":`kb-rename-broken-links`,className:`mb-2 flex flex-wrap items-center gap-x-2 text-sm text-warning`,children:[(0,X.jsx)(Te,{size:14,className:`shrink-0`,"aria-hidden":!0}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[ee.length===1?`1 document`:`${ee.length} documents`,` linked to “`,C.title,`” by its old title or path; those links now show as missing:`,` `,ee.map((e,t)=>(0,X.jsxs)(`span`,{children:[t>0&&`, `,(0,X.jsx)(`button`,{type:`button`,className:`underline underline-offset-2 hover:text-on-surface`,onClick:()=>r(e.document_id),children:e.title})]},e.document_id))]}),(0,X.jsx)(u,{size:`sm`,variant:`ghost`,onClick:()=>w(null),children:`Dismiss`})]}),(0,X.jsx)(pt,{documentId:Yn(t.id),path:t.editable?t.path:`${t.path}.md`,content:t.content,wikiLinks:F,testId:`kb-document-content`,layout:`page`,pageTitle:t.title,hideFrontmatter:!0,onSave:t.editable?async(e,n)=>{try{let r=await O.kb.updateDocument(t.id,{expected_revision:n===t.content?t.revision:N.current,content:e});return N.current=r.revision,e}finally{await f()}}:void 0},Yn(t.id))]})}),s&&S&&(0,X.jsx)(tr,{doc:t,onOpen:r}),!S&&(0,X.jsx)(Se,{open:s,onOpenChange:c,children:(0,X.jsxs)(pe,{defaultWidth:360,resizeKey:`kb-properties`,"aria-describedby":void 0,children:[(0,X.jsx)(we,{className:`py-3`,children:(0,X.jsx)(Ce,{children:`Details`})}),(0,X.jsx)(fe,{className:`p-0 sm:p-0`,children:(0,X.jsx)(tr,{doc:t,onOpen:(e,t)=>{c(!1),r(e,t)}})})]})}),(0,X.jsx)(`input`,{ref:M,type:`file`,hidden:!0,"data-testid":`kb-doc-replace-input`,onChange:e=>{let t=e.target.files?.[0];t&&o(t),e.target.value=``}}),g&&(0,X.jsx)(Fn,{doc:t,linkedFrom:t.backlinks.length,onClose:()=>_(!1),onSaved:()=>{_(!1),w(T.current)}}),(0,X.jsx)(Ge,{open:v,title:`Delete document`,description:`Delete "${t.title}" and its revision history${z?` and uploaded file`:``}?`,isPending:A,onCancel:()=>y(!1),onConfirm:async()=>{y(!1),await I(()=>O.kb.removeDocument(t.id))&&i()}})]})}function er({title:e,children:t}){return(0,X.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,X.jsx)(`h2`,{className:`text-sm font-medium text-outline`,children:e}),t]})}function tr({doc:e,onOpen:t}){let n=xt(e.id),r=Tt(e.id),i=`block min-h-8 w-full wrap-break-word text-left text-primary hover:underline`;return(0,X.jsxs)(`aside`,{"data-testid":`kb-document-details`,"aria-label":`Document details`,className:`w-full shrink-0 space-y-6 p-4 text-sm lg:min-h-0 lg:w-80 lg:overflow-y-auto lg:border-l lg:border-outline-variant`,children:[e.outline.length>0&&(0,X.jsx)(er,{title:`On this page`,children:(0,X.jsx)(`nav`,{"aria-label":`Outline`,className:`space-y-0.5`,children:e.outline.map(n=>(0,X.jsx)(`button`,{type:`button`,className:`block min-h-7 w-full truncate text-left text-outline hover:text-on-surface`,style:{paddingLeft:`${(n.level-1)*.75}rem`},onClick:()=>t(e.id,n.text),children:n.text},`${n.block}-${n.text}`))})}),e.links.length>0&&(0,X.jsx)(er,{title:`Links to (${e.links.length})`,children:e.links.map(e=>e.document_id?(0,X.jsx)(`button`,{type:`button`,"data-testid":`kb-outgoing-link`,className:i,onClick:()=>t(e.document_id),children:e.title??e.target},e.target):(0,X.jsxs)(`p`,{className:`py-1 text-outline`,"data-testid":`kb-unresolved-link`,children:[e.target,` `,(0,X.jsx)(`span`,{className:`text-xs`,children:`(no such document)`})]},e.target))}),e.backlinks.length>0&&(0,X.jsx)(er,{title:`Linked from (${e.backlinks.length})`,children:e.backlinks.map(e=>(0,X.jsx)(`button`,{type:`button`,"data-testid":`kb-backlink`,className:i,onClick:()=>t(e.document_id),children:e.title},e.document_id))}),(0,X.jsx)(`div`,{className:`border-y border-outline-variant`,children:(0,X.jsx)(Kn,{kbId:e.kb_id,documentId:e.id,heading:`h2`,compact:!0})}),(0,X.jsxs)(`details`,{"data-testid":`kb-doc-history`,className:`group`,children:[(0,X.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer list-none items-center gap-1.5 font-medium [&::-webkit-details-marker]:hidden`,children:[(0,X.jsx)(ze,{size:14,"aria-hidden":!0,className:`text-outline transition-transform group-open:rotate-90`}),`Usage and history`]}),(0,X.jsxs)(`div`,{className:`mt-3 space-y-5 pl-5`,children:[n.data?(0,X.jsx)(Qn,{usage:n.data,testId:`kb-doc-usage`}):(0,X.jsx)(`p`,{className:`text-outline`,children:n.error?`Usage unavailable`:`Loading…`}),(0,X.jsx)(`ol`,{className:`space-y-2`,"data-testid":`kb-revisions`,children:r.data?.map(e=>(0,X.jsxs)(`li`,{"data-testid":`kb-revision`,children:[(0,X.jsxs)(`div`,{children:[`Revision `,e.revision,` · `,e.actor,(0,X.jsxs)(`span`,{className:`text-outline`,children:[` via `,e.source]})]}),(0,X.jsxs)(`div`,{className:`text-xs text-outline`,children:[new Date(e.created_at).toLocaleString(),e.note?` · ${e.note}`:``]})]},e.revision))}),(0,X.jsxs)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 text-xs text-outline`,children:[(0,X.jsx)(`dt`,{children:`Search`}),(0,X.jsx)(`dd`,{"data-testid":`kb-index-state`,children:Xn[e.index_state]??e.index_state}),(0,X.jsx)(`dt`,{children:`Origin`}),(0,X.jsx)(`dd`,{children:e.origin}),(0,X.jsx)(`dt`,{children:`Type`}),(0,X.jsx)(`dd`,{children:e.media_type}),(0,X.jsx)(`dt`,{children:`Size`}),(0,X.jsx)(`dd`,{children:d(e.size_bytes)}),(0,X.jsx)(`dt`,{children:`Updated`}),(0,X.jsxs)(`dd`,{children:[new Date(e.updated_at).toLocaleString(),` by `,e.updated_by]}),(0,X.jsx)(`dt`,{children:`ID`}),(0,X.jsx)(`dd`,{className:`break-all font-mono`,children:e.id})]})]})]})]})}function nr(e){return`${e.added} added · ${e.updated} updated · ${e.missing} missing${e.errors.length?` · ${e.errors.length} errors: ${e.errors.slice(0,3).join(`; `)}`:``}`}var rr=(e,t,n)=>`${e} ${e===1?t:n}`;function ir(){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 ar(e){let t=e.document_count-e.edited_count,n=t?`${rr(t,`synced copy is`,`synced copies are`)} removed from this knowledge base`:`No synced copies are removed`,r=e.edited_count?`; ${rr(e.edited_count,`edited copy is`,`edited copies are`)} kept as documents`:``;return`Stop syncing ${e.root_path}? ${n}${r}. Files on disk are not touched.`}function or(e){return e.replace(/[\\/]+$/,``).split(/[\\/]/).pop()||e}function sr({kb:e}){let t=yt(e.id),n=q(),r=Q(),[i,a]=(0,J.useState)(!1),[o,s]=(0,J.useState)(``),[c,l]=(0,J.useState)(`**/*.md`),[d,f]=(0,J.useState)(null),[p,m]=(0,J.useState)(null),[h,g]=(0,J.useState)(!1),[_,v]=(0,J.useState)(!1),y=t.data??[],b=y.filter(e=>e.last_error).length,x=y.reduce((e,t)=>e+t.document_count,0);function S(){a(!0),g(!0)}function C(){g(!1),s(``),r.setError(null),y.length===0&&a(!1)}async function w(){v(!0),r.setError(null);try{let{path:e}=await O.terminals.pickFolder(o.trim()||void 0);e&&s(e)}catch(e){r.setError(e instanceof Error?e.message:String(e))}finally{v(!1)}}async function T(t){t.preventDefault();let i=await r.run(()=>O.kb.addSource(e.id,{root_path:o.trim(),pattern:c.trim()||`**/*.md`}));i&&(s(``),g(!1),f(nr(i.scan)),await n())}return(0,X.jsxs)(tn,{title:`Synced folders`,testId:`kb-folders`,toggleTestId:`kb-sources`,expanded:i,onExpandedChange:e=>{a(e),g(e&&y.length===0)},summary:t.isLoading?(0,X.jsx)(`span`,{className:`text-outline`,children:`Loading…`}):y.length===0?(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-outline`,"data-testid":`kb-folders-none`,children:[(0,X.jsx)(Z,{tone:`off`}),`None`]}):(0,X.jsxs)(`span`,{className:`inline-flex min-w-0 max-w-full items-center gap-1.5`,"data-testid":`kb-folders-summary`,children:[(0,X.jsx)(Z,{tone:b?`error`:`ok`}),y.length===1?(0,X.jsx)(`span`,{className:`min-w-0 truncate`,title:y[0]?.root_path,children:or(y[0]?.root_path??``)}):`${y.length} folders`,(0,X.jsxs)(`span`,{className:`shrink-0 text-outline`,children:[`· `,x,` `,x===1?`document`:`documents`,b?` · ${b} failing`:``]})]}),actions:y.length===0&&!i?(0,X.jsx)(u,{size:`sm`,variant:`outline`,"data-testid":`kb-folders-add`,onClick:S,children:`Add folder`}):null,children:[(0,X.jsxs)(`div`,{className:`min-w-0 space-y-3`,children:[(0,X.jsx)(`p`,{className:`max-w-prose text-outline`,children:`Matching files are copied in and kept in sync: ORC rescans every minute while the daemon runs, or when you choose Scan now. A copy you edit here stops following its file. ORC never writes to the folder.`}),y.length>0&&(0,X.jsx)(`ul`,{className:`divide-y divide-outline-variant`,"data-testid":`kb-sources-list`,children:y.map(e=>(0,X.jsxs)(`li`,{"data-testid":`kb-source-row`,className:`flex min-w-0 flex-wrap items-center gap-2 py-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1 basis-56`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:or(e.root_path)}),(0,X.jsx)(`div`,{className:`break-all font-mono text-xs text-outline`,children:e.root_path}),(0,X.jsxs)(`div`,{className:`text-xs text-outline`,children:[e.pattern,` · `,rr(e.document_count,`document`,`documents`),e.edited_count?` (${e.edited_count} edited)`:``,` ·`,` `,e.last_scan_at?(0,X.jsxs)(`span`,{title:new Date(e.last_scan_at).toLocaleString(),children:[`scanned `,pn(e.last_scan_at)]}):`not scanned yet`]}),e.last_error&&(0,X.jsx)(`div`,{className:`text-xs text-error`,children:e.last_error})]}),(0,X.jsxs)(u,{variant:`ghost`,size:`sm`,"data-testid":`kb-source-scan`,disabled:r.pending,onClick:async()=>{let t=await r.run(()=>O.kb.scanSource(e.id));t&&f(nr(t)),await n()},children:[(0,X.jsx)(Rt,{size:14}),`Scan now`]}),(0,X.jsx)(u,{variant:`ghost`,size:`sm`,title:`Stop syncing ${e.root_path}`,"data-testid":`kb-source-remove`,onClick:()=>m(e),children:`Stop syncing`})]},e.id))}),d&&(0,X.jsx)(`p`,{role:`status`,"data-testid":`kb-source-result`,className:`text-outline`,children:d}),h?(0,X.jsxs)(`form`,{onSubmit:T,className:`min-w-0 space-y-3`,"data-testid":`kb-source-form`,children:[(0,X.jsxs)(`div`,{className:`grid min-w-0 gap-3 sm:grid-cols-[minmax(0,1fr)_12rem]`,children:[(0,X.jsx)($,{label:`Folder path`,hint:ir(),children:(0,X.jsxs)(`div`,{className:`flex min-w-0 gap-2`,children:[(0,X.jsx)(K,{"aria-label":`Folder path`,"data-testid":`kb-source-path-input`,value:o,onChange:e=>s(e.target.value),className:`min-w-0 font-mono text-sm`,autoFocus:!0}),(0,X.jsxs)(u,{type:`button`,variant:`outline`,"data-testid":`kb-source-choose-folder`,onClick:w,disabled:_,className:`shrink-0`,children:[(0,X.jsx)(Fe,{size:14}),_?`Choosing…`:`Choose folder`]})]})}),(0,X.jsx)($,{label:`File pattern`,hint:`e.g. *.md, **/*.md`,children:(0,X.jsx)(K,{"aria-label":`File pattern`,"data-testid":`kb-source-pattern-input`,value:c,onChange:e=>l(e.target.value),className:`font-mono text-sm`})})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsx)(u,{type:`submit`,size:`sm`,variant:`outline`,"data-testid":`kb-source-add`,disabled:!o.trim()||r.pending,children:`Add folder`}),(0,X.jsx)(u,{type:`button`,size:`sm`,variant:`ghost`,"data-testid":`kb-source-cancel`,onClick:C,children:`Cancel`})]})]}):y.length>0&&(0,X.jsxs)(u,{size:`sm`,variant:`ghost`,className:`-ml-2`,"data-testid":`kb-folders-add-another`,onClick:()=>g(!0),children:[(0,X.jsx)(Ee,{size:14}),`Add another folder`]}),(0,X.jsx)(wn,{error:r.error})]}),(0,X.jsx)(Ge,{open:p!==null,title:`Stop syncing folder`,description:p?ar(p):``,confirmLabel:`Stop syncing`,variant:`warning`,isPending:r.pending,onCancel:()=>m(null),onConfirm:async()=>{let e=p;m(null),e&&await r.run(()=>O.kb.removeSource(e.id)),await n()}})]})}var cr=8;function lr(e,t,n){return n===`title`?e.title.localeCompare(t.title):n===`updated`?e.updated_at-t.updated_at:e.reads-t.reads}function ur(e,t){if(e.key===t)return e.desc?`descending`:`ascending`}function dr(e){let t=new Date(e);return t.toDateString()===new Date().toDateString()?t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):t.toLocaleDateString([],{month:`short`,day:`numeric`,year:`numeric`})}function fr({kb:e,owner:t,listing:n,label:r,onLabel:i,onOpen:a,onNewDocument:o,onSettings:s}){let c=e.editable_by.includes(`mcp`);return(0,X.jsxs)(`div`,{"data-testid":`kb-overview`,className:`w-full min-w-0 space-y-6 p-4 sm:p-6`,children:[(0,X.jsxs)(`header`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 space-y-1`,children:[(0,X.jsx)(`h2`,{className:`wrap-break-word text-base font-medium`,"data-testid":`kb-overview-name`,children:e.name}),e.description&&(0,X.jsx)(`p`,{className:`max-w-prose text-outline`,children:e.description}),(0,X.jsxs)(`p`,{className:`text-xs text-outline`,"data-testid":`kb-overview-meta`,children:[t,` · `,e.document_count,` `,e.document_count===1?`document`:`documents`,` ·`,` `,c?`agents can edit`:`agents read only`]})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsxs)(u,{size:`sm`,"data-testid":`kb-new-document`,onClick:o,children:[(0,X.jsx)(Pt,{size:16}),`New document`]}),(0,X.jsxs)(u,{size:`sm`,variant:`ghost`,"data-testid":`kb-settings`,onClick:s,children:[(0,X.jsx)(De,{size:16}),`Settings`]})]})]}),(0,X.jsx)(gr,{kbId:e.id,onOpen:a}),(0,X.jsx)(hr,{listing:n,total:e.document_count,label:r,onLabel:i,onOpen:a,onNewDocument:o}),(0,X.jsxs)(`section`,{"aria-labelledby":`kb-setup-heading`,className:`space-y-1`,children:[(0,X.jsx)(`h3`,{id:`kb-setup-heading`,className:`text-sm font-medium text-outline`,children:`Setup`}),(0,X.jsxs)(`div`,{className:`divide-y divide-outline-variant border-y border-outline-variant`,children:[(0,X.jsx)(hn,{kb:e}),(0,X.jsx)(sr,{kb:e}),(0,X.jsx)(pr,{kb:e,onSettings:s}),(0,X.jsx)(mr,{kb:e,onSettings:s}),(0,X.jsx)(Kn,{kbId:e.id,onOpenDocument:a})]})]})]})}function pr({kb:e,onSettings:t}){let n=e.editable_by.includes(`mcp`);return(0,X.jsx)(tn,{title:`Who can edit`,testId:`kb-access`,summary:(0,X.jsxs)(`span`,{className:`inline-flex min-w-0 flex-wrap items-center gap-x-1.5`,children:[(0,X.jsx)(Z,{tone:n?`ok`:`off`}),n?`Agents can edit`:`Agents read only`,(0,X.jsxs)(`span`,{className:`text-outline`,children:[`·`,` `,e.editable_by.length?e.editable_by.map(e=>Dn[e]).join(`, `):`nobody, read only everywhere`]})]}),actions:(0,X.jsx)(u,{size:`sm`,variant:`ghost`,"data-testid":`kb-access-change`,onClick:t,children:`Change`})})}function mr({kb:e,onSettings:t}){let n=vt(),r=e.parser?n.data?.parsers.find(t=>t.id===e.parser)?.label??e.parser:`Workspace default parser`;return(0,X.jsx)(tn,{title:`Uploads`,testId:`kb-uploads-setup`,summary:(0,X.jsxs)(`span`,{className:`text-outline`,"data-testid":`kb-uploads-parser`,children:[r,(0,X.jsx)(de,{label:`Document uploads`,children:`PDF, Word, PowerPoint, Excel, HTML, Markdown and text are converted to searchable Markdown by the selected parser.`})]}),actions:(0,X.jsx)(u,{size:`sm`,variant:`ghost`,"data-testid":`kb-parser-change`,onClick:t,children:`Change`})})}function hr({listing:e,total:t,label:n,onLabel:r,onOpen:i,onNewDocument:a}){let[o,s]=(0,J.useState)(``),[c,d]=(0,J.useState)(!1),[f,p]=(0,J.useState)({key:`updated`,desc:!0}),m=o.trim().toLowerCase(),h=(e?.documents??[]).filter(e=>(!n||e.labels.includes(n))&&(!m||e.title.toLowerCase().includes(m)||e.path.toLowerCase().includes(m)||e.labels.some(e=>e.toLowerCase().includes(m)))).sort((e,t)=>lr(e,t,f.key)*(f.desc?-1:1));function g(e){p(t=>t.key===e?{key:e,desc:!t.desc}:{key:e,desc:e!==`title`})}function _(e,t){let n=f.desc?ue:se;return(0,X.jsxs)(`button`,{type:`button`,"data-testid":`kb-sort-${e}`,className:`inline-flex min-h-8 items-center gap-1 hover:text-on-surface`,onClick:()=>g(e),children:[t,f.key===e&&(0,X.jsx)(n,{size:12,"aria-hidden":!0})]})}let v=[...e?.labels??[]].sort((e,t)=>t.count-e.count),y=c?v:v.filter((e,t)=>t<cr||e.label===n),b=v.length-y.length;return(0,X.jsxs)(`section`,{"aria-labelledby":`kb-documents-heading`,"data-testid":`kb-documents`,className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,X.jsxs)(`h3`,{id:`kb-documents-heading`,className:`mr-auto text-sm font-medium text-outline`,children:[`Documents`,n?` labelled ${n}`:``]}),t>0&&(0,X.jsx)(K,{"aria-label":`Filter documents`,"data-testid":`kb-documents-filter`,placeholder:`Filter by title, path or label`,value:o,onChange:e=>s(e.target.value),className:`h-9 w-full sm:w-64`})]}),y.length>0&&(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,"data-testid":`kb-labels`,children:[(0,X.jsx)(`span`,{className:`mr-1 text-xs text-outline`,children:`Label`}),y.map(e=>(0,X.jsxs)(`button`,{type:`button`,"data-testid":`kb-label-filter`,"aria-pressed":n===e.label,className:l(`min-h-8 rounded-full border px-2.5 text-xs`,n===e.label?`border-primary bg-primary/10 text-primary`:`border-outline-variant text-outline hover:text-on-surface`),onClick:()=>r(n===e.label?null:e.label),children:[e.label,` `,(0,X.jsx)(`span`,{className:`tabular-nums`,children:e.count})]},e.label)),(b>0||c)&&v.length>cr&&(0,X.jsx)(`button`,{type:`button`,"data-testid":`kb-labels-more`,className:`min-h-8 px-2 text-xs text-primary hover:underline`,onClick:()=>d(!c),children:c?`Fewer labels`:`${b} more`})]}),t===0?(0,X.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-2 rounded-md border border-dashed border-outline-variant px-6 py-10 text-center text-sm text-outline`,children:[(0,X.jsx)(M,{size:22,className:`text-primary`,"aria-hidden":!0}),(0,X.jsx)(`span`,{children:`This knowledge base is empty. Drop PDF, Word, PowerPoint, Excel, HTML, Markdown or text files here, or`}),(0,X.jsx)(u,{size:`sm`,variant:`outline`,onClick:a,"data-testid":`kb-overview-new-document`,children:`add a document`})]}):(0,X.jsxs)(X.Fragment,{children:[h.length===0&&e&&(0,X.jsxs)(`p`,{className:`py-4 text-sm text-outline`,"data-testid":`kb-documents-empty`,children:[`No documents match.`,` `,(0,X.jsx)(`button`,{type:`button`,"data-testid":`kb-documents-clear`,className:`text-primary hover:underline`,onClick:()=>{s(``),r(null)},children:`Clear filters`})]}),h.length>0&&(0,X.jsxs)(`table`,{className:`w-full table-fixed text-sm`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{className:`border-b border-outline-variant text-left text-xs text-outline`,children:[(0,X.jsx)(`th`,{className:`py-1 pr-3 font-normal`,"aria-sort":ur(f,`title`),children:_(`title`,`Title`)}),(0,X.jsx)(`th`,{className:`hidden w-[30%] py-2 pr-3 font-normal md:table-cell`,children:`Labels`}),(0,X.jsx)(`th`,{className:`w-24 py-1 pr-3 font-normal sm:w-28`,"aria-sort":ur(f,`updated`),children:_(`updated`,`Updated`)}),(0,X.jsx)(`th`,{className:`hidden w-16 py-1 text-right font-normal sm:table-cell`,"aria-sort":ur(f,`reads`),children:_(`reads`,`Reads`)})]})}),(0,X.jsx)(`tbody`,{children:h.map(e=>(0,X.jsxs)(`tr`,{className:`cursor-pointer border-b border-outline-variant/60 align-top hover:bg-surface-high`,onClick:()=>i(e.id),children:[(0,X.jsxs)(`td`,{className:`min-w-0 py-2 pr-3`,children:[(0,X.jsxs)(`button`,{type:`button`,"data-testid":`kb-document-row`,"data-document-title":e.title,className:`flex w-full min-w-0 items-center gap-1.5 text-left font-medium hover:text-primary`,onClick:t=>{t.stopPropagation(),i(e.id)},children:[(0,X.jsx)(`span`,{className:`min-w-0 truncate`,children:e.title}),e.origin===`external`&&(0,X.jsx)(Rt,{size:13,className:`shrink-0 text-outline`,"aria-label":`From a synced folder`})]}),(0,X.jsx)(`span`,{className:`block truncate font-mono text-xs text-outline`,children:e.path}),(e.parse_state===`pending`||e.parse_state===`failed`)&&(0,X.jsx)(`span`,{className:l(`text-xs`,e.parse_state===`failed`?`text-error`:`text-outline`),children:e.parse_state===`failed`?`Parsing failed`:`Parsing…`})]}),(0,X.jsx)(`td`,{className:`hidden py-2 pr-3 text-xs text-outline md:table-cell`,children:(0,X.jsx)(`span`,{className:`line-clamp-2`,children:e.labels.join(`, `)})}),(0,X.jsx)(`td`,{className:`py-2 pr-3 text-xs text-outline tabular-nums`,children:dr(e.updated_at)}),(0,X.jsx)(`td`,{className:`hidden py-2 text-right text-xs text-outline tabular-nums sm:table-cell`,children:e.reads||``})]},e.id))})]}),(0,X.jsx)(`p`,{className:`text-xs text-outline`,children:`Drop files anywhere on this page to upload.`})]})]})}function gr({kbId:e,onOpen:t}){let n=_t(e).data;return!n||!(n.stale.length||n.failed.length||n.unresolved_links.length)?null:(0,X.jsxs)(`section`,{"data-testid":`kb-maintenance`,className:`space-y-1 text-sm`,children:[(0,X.jsx)(`h3`,{className:`text-sm font-medium text-outline`,children:`Needs attention`}),(0,X.jsxs)(`ul`,{className:`space-y-1`,children:[n.failed.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,className:`text-left text-error hover:underline`,onClick:()=>t(e.id),children:[`Parsing failed: `,e.title]})},e.id)),n.stale.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,className:`text-left text-warning hover:underline`,onClick:()=>t(e.id),children:[`Stale summary: `,e.title]})},e.id)),n.unresolved_links.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,className:`text-left text-outline hover:underline`,onClick:()=>t(e.document_id),children:[`[[`,e.target,`]] in `,e.title,` has no target`]})},`${e.document_id}-${e.target}`))]})]})}function _r(){let e=q(),[t,n]=(0,J.useState)([]),r=(0,J.useRef)(1),i=(e,t)=>n(n=>n.map(n=>n.id===e?{...n,...t}:n));async function a(t){i(t.id,{status:`uploading`,progress:0,error:void 0});try{let n=await O.kb.upload(t.kbId,{file:t.file,...t.replace},e=>i(t.id,{progress:e}));i(t.id,{status:`done`,progress:1,document:n}),await e()}catch(e){i(t.id,{status:`failed`,error:e instanceof Error?e.message:`Upload failed`})}}function o(e,t,i={}){let o=t.map(t=>({id:r.current++,kbId:e,file:t,...i.replace?{replace:i.replace}:{},progress:0,status:`uploading`}));n(e=>[...e,...o]);for(let e of o)a(e)}return{uploads:t,add:o,retry:e=>{let n=t.find(t=>t.id===e);n&&a(n)},clearFinished:()=>n(e=>e.filter(e=>e.status===`uploading`))}}var vr=`all`,yr=200,br=[{value:`reads`,label:`Most read`},{value:`recent`,label:`Recent`},{value:`priority`,label:`Priority`}];function xr(e){return new Date(e*1e3).toLocaleString()}function Sr({projectId:e}){let t=i(),n=c(),{memoryProject:r,memoryName:a}=o(),[s,l]=Ye(`project`,e),[d,f]=Ye(`memoryQuery`,``),[p,m]=Ye(`memorySort`,`reads`,br.map(e=>e.value)),[h,g]=(0,J.useState)(d);(0,J.useEffect)(()=>g(d),[d]);let _=(0,J.useRef)(f);_.current=f,(0,J.useEffect)(()=>{if(h===d)return;let e=window.setTimeout(()=>_.current(h,{replace:!0}),250);return()=>window.clearTimeout(e)},[h,d]);let v=be(`lg`),[y,b]=(0,J.useState)(null),[E,D]=(0,J.useState)(null),{data:O}=Be({status:`active`}),k=st(),A=s===`unassigned`,M=s===vr,N=lt({project_id:M?void 0:s,q:d||void 0,sort:p,limit:yr},{enabled:!A}),P=N.data?.memories??[],F=e=>O?.find(t=>t.id===e)?.name??e,I=P.find(e=>e.project_id===r&&e.name===a),L=e=>t(`${oe(e.project_id,e.name)}${n.search}`),R=()=>t(`${_e}${n.search}`),z=M||!A&&r===s;return(0,J.useEffect)(()=>{r&&a&&!z&&t(`${_e}${n.search}`,{replace:!0})},[r,a,z,t,n.search]),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(Je,{title:`Memories`,help:`Short project facts such as ports, conventions and decisions that agents can read in later sessions. Longer procedures belong in a skill.`,meta:N.data?`${N.data.total} ${N.data.total===1?`memory`:`memories`}`:void 0,action:(0,X.jsxs)(u,{"data-testid":`new-memory-button`,size:`sm`,onClick:()=>b(`new`),className:`font-label text-sm`,children:[(0,X.jsx)(Ee,{size:12,className:`mr-1`}),` New memory`]})}),(0,X.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-2`,children:[(0,X.jsxs)(j,{activeCount:Number(p!==`reads`)+Number(s!==vr),children:[(0,X.jsxs)(C,{value:s,onValueChange:e=>l(e),children:[(0,X.jsx)(x,{"aria-label":`Project`,"data-testid":`memory-project-filter`,className:`h-9 w-48 bg-background text-on-surface font-body text-sm`,children:(0,X.jsx)(w,{})}),(0,X.jsxs)(T,{className:`bg-surface border-outline-variant`,children:[(0,X.jsx)(S,{value:vr,className:`font-body text-sm`,children:`All projects`}),A&&(0,X.jsx)(S,{value:`unassigned`,className:`font-body text-sm`,children:`Unassigned`}),O?.map(e=>(0,X.jsx)(S,{value:e.id,"data-testid":`memory-project-option-${e.id}`,className:`font-body text-sm`,children:e.name},e.id))]})]}),(0,X.jsx)(`div`,{className:`flex shrink-0 flex-wrap gap-1.5`,children:br.map(e=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>m(e.value),"data-testid":`memory-sort-${e.value}`,"aria-pressed":p===e.value,className:`font-label text-sm px-3 py-1.5 border transition-colors ${p===e.value?`bg-surface-highest text-on-surface border-transparent`:`bg-transparent border-transparent text-muted-foreground hover:bg-surface-low hover:text-on-surface`}`,children:e.label},e.value))})]}),(0,X.jsxs)(`div`,{className:`relative order-first min-w-0 flex-1 lg:max-w-md`,children:[(0,X.jsx)(Ie,{size:12,className:`absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground`}),(0,X.jsx)(K,{"aria-label":`Search memories`,"data-testid":`memory-search-input`,value:h,onChange:e=>g(e.target.value),onKeyDown:e=>e.key===`Enter`&&f(e.currentTarget.value),placeholder:`Search memories...`,className:`pl-8 bg-background text-on-surface font-body text-sm placeholder:text-muted-foreground`})]})]}),A?(0,X.jsx)(Xe,{message:`Memories belong to a project. Choose a project to see its memories.`}):N.error?(0,X.jsx)(qe,{message:N.error.message,onRetry:()=>void N.refetch()}):N.isLoading?(0,X.jsx)(`div`,{className:`space-y-2`,children:[...[,,,,,]].map((e,t)=>(0,X.jsx)(xe,{className:`h-10 w-full bg-surface-highest`},t))}):P.length===0?(0,X.jsx)(Xe,{message:d?`No memories match your search`:`No memories yet`}):v?(0,X.jsx)(`div`,{className:`overflow-hidden`,children:(0,X.jsxs)(nt,{children:[(0,X.jsx)(Ze,{children:(0,X.jsxs)(et,{className:`border-b border-outline-variant hover:bg-transparent`,children:[(0,X.jsx)(Qe,{className:`font-label text-sm text-muted-foreground`,children:`Name`}),(0,X.jsx)(Qe,{className:`font-label text-sm text-muted-foreground`,children:`Description`}),M&&(0,X.jsx)(Qe,{className:`font-label text-sm text-muted-foreground`,children:`Project`}),(0,X.jsx)(Qe,{className:`font-label text-sm text-muted-foreground w-20`,children:`Priority`}),(0,X.jsx)(Qe,{className:`font-label text-sm text-muted-foreground w-16`,children:`Reads`}),(0,X.jsx)(Qe,{className:`font-label text-sm text-muted-foreground w-44`,children:`Updated`})]})}),(0,X.jsx)($e,{children:P.map(e=>(0,X.jsxs)(et,{"data-testid":`memory-row`,"data-memory-name":e.name,"data-memory-project":e.project_id,className:`border-b border-outline-variant/50 hover:bg-surface-low cursor-pointer`,onClick:()=>L(e),children:[(0,X.jsx)(tt,{className:`font-body text-sm font-medium text-on-surface`,children:(0,X.jsx)(`button`,{type:`button`,className:`min-h-11 text-left hover:text-primary`,onClick:t=>{t.stopPropagation(),L(e)},children:e.name})}),(0,X.jsx)(tt,{className:`font-body text-sm text-muted-foreground max-w-md truncate`,children:e.description}),M&&(0,X.jsx)(tt,{className:`font-body text-sm text-muted-foreground`,children:F(e.project_id)}),(0,X.jsx)(tt,{children:(0,X.jsx)(wr,{priority:e.priority})}),(0,X.jsx)(tt,{"data-testid":`memory-read-count`,className:`font-label text-sm text-muted-foreground`,title:Cr(e),children:e.read_count}),(0,X.jsx)(tt,{className:`font-label text-sm text-muted-foreground`,children:xr(e.updated_at)})]},e.key))})]})}):(0,X.jsx)(`div`,{className:`divide-y divide-outline-variant`,children:P.map(e=>(0,X.jsxs)(`button`,{type:`button`,"data-testid":`memory-row`,"data-memory-name":e.name,"data-memory-project":e.project_id,onClick:()=>L(e),className:`flex w-full min-w-0 items-start justify-between gap-3 px-2 py-3 text-left hover:bg-surface`,children:[(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`span`,{className:`block wrap-break-word text-sm font-medium`,children:e.name}),(0,X.jsx)(`span`,{className:`mt-1 line-clamp-2 wrap-break-word text-sm text-muted-foreground`,children:e.description}),(0,X.jsxs)(`span`,{className:`mt-1 flex flex-wrap items-center gap-x-2 text-xs text-muted-foreground`,children:[M&&(0,X.jsx)(`span`,{children:F(e.project_id)}),(0,X.jsxs)(`span`,{"data-testid":`memory-read-count`,title:Cr(e),children:[e.read_count,` reads`]})]})]}),(0,X.jsx)(wr,{priority:e.priority})]},e.key))}),r&&a&&z&&(0,X.jsx)(Tr,{projectId:r,name:a,projectName:F(r),listItem:I,onClose:R,onEdit:b,onDelete:D},`${r}/${a}`),y&&(0,X.jsx)(Ar,{memory:y===`new`?null:y,defaultProjectId:M||A?``:s,onClose:()=>b(null),onCreated:e=>L(e)}),E&&(0,X.jsx)(Ge,{open:!0,title:`Delete memory`,description:`Delete "${E.name}"? It can be restored from its history.`,confirmLabel:`Delete`,variant:`destructive`,isPending:k.isPending,onConfirm:()=>k.mutate({projectId:E.project_id,name:E.name},{onSuccess:()=>{D(null),R()}}),onCancel:()=>D(null)}),k.error&&(0,X.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive mt-2`,children:k.error.message})]})}function Cr(e){let{mcp:t,cli:n,api:r,ui:i}=e.reads_by_source;return`mcp ${t} · cli ${n} · api ${r} · ui ${i}${e.last_read_at?` · last read ${xr(e.last_read_at)}`:``}`}function wr({priority:e}){return e===null?(0,X.jsx)(`span`,{"data-testid":`memory-priority`,className:`font-label text-xs text-outline`,children:`Unscored`}):(0,X.jsxs)(`span`,{"data-testid":`memory-priority`,className:`font-label text-xs text-primary`,children:[`P`,e]})}function Tr({projectId:e,name:t,projectName:n,listItem:r,onClose:i,onEdit:a,onDelete:o}){let{data:s,isLoading:c,error:l,refetch:d}=ot(e,t);return(0,X.jsx)(Se,{open:!0,onOpenChange:e=>!e&&i(),children:(0,X.jsxs)(pe,{"data-testid":`memory-detail`,defaultWidth:860,resizeKey:`memories`,children:[(0,X.jsxs)(we,{children:[(0,X.jsx)(Ce,{children:t}),s&&(0,X.jsx)(`p`,{"data-testid":`memory-detail-description`,className:`font-body text-sm text-muted-foreground mt-1`,children:s.description})]}),(0,X.jsx)(fe,{children:l?(0,X.jsx)(qe,{message:l.message,onRetry:()=>void d()}):c||!s?(0,X.jsx)(`div`,{className:`space-y-3`,children:[...[,,,,]].map((e,t)=>(0,X.jsx)(xe,{className:`h-8 w-full bg-surface-highest`},t))}):(0,X.jsxs)(`div`,{className:`space-y-6`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsxs)(u,{"data-testid":`memory-edit`,size:`sm`,variant:`outline`,onClick:()=>a(s),children:[(0,X.jsx)(Le,{size:12,className:`mr-1`}),` Edit`]}),(0,X.jsxs)(u,{"data-testid":`memory-delete`,size:`sm`,variant:`outline`,onClick:()=>o(s),children:[(0,X.jsx)(ge,{size:12,className:`mr-1`}),` Delete`]})]}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,X.jsx)(Re,{label:`Project`,children:n}),(0,X.jsx)(Re,{label:`Priority`,children:(0,X.jsx)(wr,{priority:s.priority})}),(0,X.jsx)(Re,{label:`Reads`,children:r?(0,X.jsx)(`span`,{title:Cr(r),children:r.read_count}):`—`}),(0,X.jsx)(Re,{label:`Author`,children:(0,X.jsx)(`span`,{"data-testid":`memory-detail-author`,children:s.author})}),(0,X.jsx)(Re,{label:`Session`,children:(0,X.jsx)(`code`,{className:`font-mono text-xs break-all`,children:s.session_id??`—`})}),(0,X.jsx)(Re,{label:`Updated`,children:xr(s.updated_at)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`font-label text-sm text-muted-foreground mb-2`,children:`Content`}),(0,X.jsx)(`div`,{"data-testid":`memory-detail-content`,className:`wrap-break-word font-body text-sm text-on-surface`,children:(0,X.jsx)(U,{readable:!0,children:s.content})})]}),(0,X.jsx)(Dr,{projectId:e,name:t,onDeleted:i})]})})]})})}function Er({label:e,snapshot:t}){return(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`text-xs text-outline mt-2`,children:e}),t?(0,X.jsxs)(`div`,{className:`text-xs space-y-1`,children:[(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`span`,{className:`text-outline`,children:`Priority:`}),` `,t.priority===null?`unscored`:t.priority]}),(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`span`,{className:`text-outline`,children:`Description:`}),` `,t.description]}),(0,X.jsx)(`pre`,{className:`whitespace-pre-wrap break-all`,children:t.content})]}):(0,X.jsx)(`p`,{className:`text-xs italic text-muted-foreground`,children:`(none)`})]})}function Dr({projectId:e,name:t,onDeleted:n}){let r=it(e,t),i=ut(),[a,o]=(0,J.useState)(``),s=r.data?.changes??[],c=s[0];return(0,X.jsxs)(`section`,{"data-testid":`memory-history-panel`,className:`space-y-3`,children:[(0,X.jsx)(`h3`,{className:`text-sm font-medium`,children:`History`}),r.error&&(0,X.jsx)(`p`,{role:`alert`,children:r.error.message}),i.error&&(0,X.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:i.error.message}),s.length>1&&(0,X.jsx)(K,{"data-testid":`memory-revert-reason`,"aria-label":`Reason for reverting`,value:a,onChange:e=>o(e.target.value),placeholder:`Reason for reverting...`}),s.map(r=>(0,X.jsxs)(`details`,{"data-testid":`memory-history-change`,className:`border-b border-outline-variant p-3`,children:[(0,X.jsxs)(`summary`,{className:`text-xs cursor-pointer`,children:[r.action.replace(`memory.`,``),` · `,xr(r.created_at),` ·`,` `,r.author,r.session_id?` · ${r.session_id}`:``,r.reason?` · ${r.reason}`:``]}),(0,X.jsx)(Er,{label:`Before`,snapshot:r.previous}),(0,X.jsx)(Er,{label:`After`,snapshot:r.current}),c&&r.previous&&(0,X.jsx)(u,{"data-testid":`memory-revert-change`,size:`sm`,variant:`outline`,className:`mt-2`,disabled:!a.trim()||i.isPending,onClick:()=>i.mutate({name:t,project_id:e,change_id:r.id,expected_change_id:c.id,reason:a.trim()},{onSuccess:({memory:e})=>{o(``),e||n()}}),children:`Restore state before this change`})]},r.id))]})}function Or(e){return[...e].length}function kr({value:e,max:t,testId:n}){let r=Or(e);return(0,X.jsx)(`span`,{"data-testid":n,className:`text-xs ${t!==void 0&&r>t?`text-destructive`:`text-muted-foreground`}`,children:t===void 0?r:`${r}/${t}`})}function Ar({memory:e,defaultProjectId:t,onClose:n,onCreated:r}){let{data:i}=Be({status:`active`}),[a,o]=(0,J.useState)(e?.project_id??t),[s,c]=(0,J.useState)(e?.name??``),[l,d]=(0,J.useState)(e?.description??``),[f,p]=(0,J.useState)(e?.content??``),[m,h]=(0,J.useState)(e?.priority===null||e?.priority===void 0?``:String(e.priority)),[g,_]=(0,J.useState)(``),v=dt(),y=at(),D=(0,J.useRef)(JSON.stringify([a,s,l,f,m,g])),O=ct().data?.content_max,k=e?y:v,A=Ve([{id:`details`,label:`Details`},{id:`content`,label:`Content`}]),j=m.trim()===``?null:Number(m),M=j===null||Number.isInteger(j)&&j>=0&&j<=100,N=!!a&&!!s.trim()&&!!l.trim()&&Or(l)<=300&&!!f.trim()&&(O===void 0||Or(f)<=O)&&M;function P(t){if(k.isPending)return;if(!N){!a||!s.trim()||!l.trim()||Or(l)>300||!M?A.invalid(`details`,a?M?`Enter a name and description within the displayed limits.`:`Priority must be a whole number from 0 to 100.`:`Choose a project.`):A.invalid(`content`,`Enter memory content within the displayed limit.`);return}if(!e){v.mutate({project_id:a,name:s.trim(),description:l.trim(),content:f.trim(),priority:j},{onSuccess:e=>{t(),r(e)}});return}let n={...l.trim()!==e.description&&{description:l.trim()},...f.trim()!==e.content&&{content:f.trim()},...j!==e.priority&&{priority:j}};Object.keys(n).length===0?t():y.mutate({name:e.name,project_id:e.project_id,...n,...g.trim()&&{reason:g.trim()}},{onSuccess:t})}return(0,X.jsx)(E,{open:!0,onClose:n,busy:k.isPending,dirty:JSON.stringify([a,s,l,f,m,g])!==D.current,testId:`memory-form-dialog`,className:A.step===`content`?`h-[min(85dvh,calc(var(--app-height,100dvh)-2rem))]`:void 0,children:(t,n)=>(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(te,{children:(0,X.jsx)(re,{className:`font-headline text-base text-on-surface`,children:e?`Edit ${e.name}`:`New memory`})}),(0,X.jsx)(`form`,{noValidate:!0,ref:A.form,onSubmit:e=>A.submit(e,()=>P(n)),className:A.step===`content`?`min-h-0 flex-1`:`min-h-0`,children:(0,X.jsxs)(ce,{steps:A,children:[(0,X.jsxs)(`div`,{className:A.step===`content`?`work-form-body flex min-h-0 flex-1 flex-col gap-4`:`work-form-body space-y-4`,children:[(0,X.jsxs)(ve,{steps:A,id:`details`,children:[!e&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(b,{className:`font-label text-sm text-muted-foreground`,children:`Project *`}),(0,X.jsxs)(C,{value:a,onValueChange:o,children:[(0,X.jsx)(x,{"aria-label":`Memory project`,"data-testid":`memory-project-select`,className:`bg-background text-on-surface font-body text-sm h-9`,children:(0,X.jsx)(w,{placeholder:`Choose a project`})}),(0,X.jsx)(T,{className:`bg-surface border-outline-variant`,children:i?.map(e=>(0,X.jsx)(S,{value:e.id,className:`font-body text-sm`,children:e.name},e.id))})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(b,{className:`font-label text-sm text-muted-foreground`,children:`Name *`}),(0,X.jsx)(K,{"aria-label":`Name`,"data-testid":`memory-name-input`,value:s,onChange:e=>c(e.target.value),placeholder:`api-port`,maxLength:64,required:!0,className:`bg-background text-on-surface font-body text-sm`,autoFocus:!0}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Lowercase words joined by hyphens, unique in the project.`})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(b,{className:`font-label text-sm text-muted-foreground`,children:`Description *`}),(0,X.jsx)(kr,{value:l,max:300,testId:`memory-description-count`})]}),(0,X.jsx)(W,{"aria-label":`Description`,"data-testid":`memory-description-input`,value:l,onChange:e=>d(e.target.value),placeholder:`One line agents see in lists and context`,className:`bg-background text-on-surface font-body text-sm resize-none`,rows:2,required:!0})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(b,{className:`font-label text-sm text-muted-foreground`,children:[`Priority (0-`,100,`, empty = unscored)`]}),(0,X.jsx)(K,{"aria-label":`Priority`,"data-testid":`memory-priority-input`,type:`number`,min:0,max:100,step:1,value:m,onChange:e=>h(e.target.value),className:`w-32 bg-background text-on-surface font-body text-sm`}),!M&&(0,X.jsxs)(`p`,{className:`text-xs text-destructive`,children:[`Priority must be a whole number from 0 to `,100,`.`]})]}),e&&(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(b,{className:`font-label text-sm text-muted-foreground`,children:`Reason`}),(0,X.jsx)(K,{"aria-label":`Reason`,"data-testid":`memory-reason-input`,value:g,onChange:e=>_(e.target.value),placeholder:`Why this changed (optional)`,className:`bg-background text-on-surface font-body text-sm`})]})]}),(0,X.jsx)(ve,{steps:A,id:`content`,className:`flex min-h-0 flex-1 flex-col`,children:(0,X.jsx)(he,{label:`Content`,"aria-label":`Content`,"data-testid":`memory-content-input`,value:f,onChange:p,placeholder:`The fact itself. Longer guidance belongs in a skill.`,accessory:(0,X.jsx)(kr,{value:f,max:O,testId:`memory-content-count`}),fill:!0,disabled:k.isPending,required:!0})}),A.error&&(0,X.jsx)(`p`,{role:`alert`,"data-testid":`memory-step-error`,className:`text-sm text-destructive`,children:A.error}),k.error&&(0,X.jsx)(`p`,{role:`alert`,"data-testid":`memory-form-error`,className:`text-sm text-destructive md:col-span-2`,children:k.error.message})]}),(0,X.jsxs)(G,{className:`work-form-footer`,children:[(0,X.jsx)(u,{type:`button`,variant:`ghost`,size:`sm`,onClick:t,disabled:k.isPending,className:`font-label text-sm text-muted-foreground`,children:`Cancel`}),(0,X.jsx)(Ue,{steps:A,busy:k.isPending,children:(0,X.jsx)(u,{"data-testid":`memory-submit`,type:`submit`,size:`sm`,disabled:k.isPending,className:`font-label text-sm`,children:k.isPending?`Saving...`:e?`Save`:`Create`})})]})]})})]})})}function jr({projectId:e}){let t=rt(e),{pathname:n}=c();return n.startsWith(`/knowledge/memories`)?(0,X.jsx)(`div`,{"data-testid":`knowledge-base-view`,children:(0,X.jsx)(Sr,{projectId:e,embedded:!0})}):(0,X.jsx)(`div`,{"data-testid":`knowledge-base-view`,className:`flex min-h-0 min-w-0 flex-1`,children:(0,X.jsx)(Pr,{projectId:t===`all`||t===`unassigned`?void 0:t,globalOnly:t===`unassigned`},t)})}function Mr(e){return e.replace(/```[\w-]*/g,` `).replace(/<\/?[a-z][^>]*>/gi,` `).replace(/!?\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/(^|\s)#{1,6}\s+/g,`$1`).replace(/(^|\n)\s*(?:>\s*)+/g,`$1`).replace(/(^|\n)\s*(?:[-*+]|\d+[.)])\s+/g,`$1`).replace(/\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?/g,` `).replace(/(^|\s)(?:\*{3,}|_{3,})(?=\s|$)/g,`$1`).replace(/`/g,``).replace(/(^|[\s(«])[*_~]+(?=\S)/g,`$1`).replace(/(\S)[*_~]+(?=$|[\s).,;:!?»])/g,`$1`).replace(/\s*\|[\s|]*/g,` · `).replace(/\s+/g,` `).replace(/^ · | · $/g,``).trim()}function Nr({text:e}){let t=Mr(e).split(/«([^»]*)»/g);return(0,X.jsx)(X.Fragment,{children:t.map((e,t)=>t%2?(0,X.jsx)(`mark`,{className:`rounded-xs bg-primary/20 px-0.5 text-on-surface`,children:e},t):(0,X.jsx)(J.Fragment,{children:e},t))})}function Pr({projectId:e,globalOnly:t=!1}){let[n,r]=a(),i=n.get(`kb`),o=n.get(`document`),s=n.get(`label`)??``,c=n.get(`q`)??``,d=n.get(`searchAll`)===`1`,[b,x]=(0,J.useState)(c);(0,J.useEffect)(()=>x(c),[c]);let[S,C]=(0,J.useState)(null),[w,T]=(0,J.useState)(!1),E=be(`lg`),[D,O]=(0,J.useState)(()=>typeof window<`u`&&window.innerWidth>=1600),[k,A]=(0,J.useState)(!1),[j,M]=(0,J.useState)(null),[N,P]=(0,J.useState)();function F(){C(null),P(void 0)}let I=Be(),L=kt(e,t),R=L.data?.find(e=>e.id===i)??null,z=Ot(R?.id??null),B=gt(L.data===void 0?null:o),ee=L.data!==void 0&&(R!==null||L.data.length===0),V=St(c&&ee?{query:c,...R&&!d?{kb_ids:[R.id]}:{},scope:e?`default`:t?`global`:`all`,limit:20}:null,e),H=_r();function U(e,t=!1){r(()=>{let t=new URLSearchParams(window.location.search);for(let[n,r]of Object.entries(e))r?t.set(n,r):t.delete(n);return t},{replace:t})}let W=()=>!o||ft(Yn(o));function te(e){T(!1),(e!==i||o||c)&&W()&&(e!==i&&H.clearFinished(),U({kb:e,document:null,label:null,q:null}))}function G(e,t){T(!1),(e===o||W())&&(U({document:e,q:null}),M(t??null))}function ne(e,t){U({document:e}),M(t??null)}function re(){T(!1);let e=b.trim();if(!e)return U({q:null});W()&&U({q:e,document:null})}(0,J.useEffect)(()=>{E&&T(!1)},[E]),(0,J.useEffect)(()=>{L.data&&(o&&B.data&&!L.data.some(e=>e.id===B.data.kb_id)?U({kb:L.data[0]?.id??null,document:null,label:null,q:null},!0):i&&!L.data.some(e=>e.id===i)&&(!o||B.error)?U({kb:null,document:null},!0):!i&&L.data[0]&&U({kb:L.data[0].id},!0))}),(0,J.useEffect)(()=>{B.data&&B.data.kb_id!==i&&L.data?.some(e=>e.id===B.data.kb_id)&&U({kb:B.data.kb_id,label:null},!0)}),(0,J.useEffect)(()=>{if(!j||!B.data)return;let e=[...document.querySelector(`[data-testid="kb-document"]`)?.querySelectorAll(`h1,h2,h3,h4,h5,h6`)??[]].find(e=>e.textContent?.trim()===j);e&&(e.scrollIntoView({block:`start`}),M(null))});function ie(e){e.preventDefault(),A(!1);let t=[...e.dataTransfer.files];R&&t.length!==0&&(t.length>1?H.add(R.id,t):(P(t[0]),C(`new-document`)))}let ae=e=>e===null?`Global`:I.data?.find(t=>t.id===e)?.name??`Project`;if(L.error)return(0,X.jsx)(qe,{message:L.error.message,onRetry:()=>L.refetch()});let oe=o?B.data&&R&&B.data.kb_id===R.id?(0,X.jsx)($n,{kb:R,doc:B.data,detailsOpen:D,onDetailsOpenChange:O,onHome:()=>te(R.id),onOpen:G,onDeleted:()=>U({document:null}),onReplaceFile:e=>B.data&&H.add(B.data.kb_id,[e],{replace:{document_id:B.data.id,expected_revision:B.data.revision}})},B.data.id):B.error?(0,X.jsxs)(Rr,{children:[(0,X.jsx)(`p`,{role:`alert`,"data-testid":`kb-document-error`,className:`text-sm text-error`,children:B.error.message}),(0,X.jsx)(u,{variant:`outline`,onClick:()=>U({document:null}),children:`Back`})]}):(0,X.jsx)(Rr,{children:(0,X.jsx)(`p`,{role:`status`,className:`text-sm text-outline`,children:`Loading document…`})}):c?(0,X.jsx)(Lr,{children:(0,X.jsx)(zr,{query:c,search:V,onOpen:ne,onClear:()=>U({q:null})})}):R?(0,X.jsx)(Lr,{children:(0,X.jsx)(fr,{kb:R,owner:ae(R.project_id),listing:z.data,label:s,onLabel:e=>U({label:e}),onOpen:G,onNewDocument:()=>C(`new-document`),onSettings:()=>C(`settings`)})}):L.data?.length===0?(0,X.jsxs)(Rr,{testId:`empty-state`,children:[(0,X.jsx)(`p`,{className:`text-sm text-outline`,children:`No knowledge bases configured`}),(0,X.jsxs)(u,{"data-testid":`kb-empty-create`,onClick:()=>C(`create`),children:[(0,X.jsx)(Ee,{size:16}),`New knowledge base`]})]}):null,se=(0,X.jsxs)(`nav`,{id:`kb-sidebar-panel`,"aria-label":`Knowledge bases`,"data-testid":`kb-sidebar`,className:`flex h-full min-h-0 flex-col border-outline-variant bg-background lg:w-72 lg:shrink-0 lg:border-r`,children:[(0,X.jsxs)(`form`,{className:`flex shrink-0 items-center gap-1.5 border-b border-outline-variant p-3`,onSubmit:e=>{e.preventDefault(),re()},children:[(0,X.jsx)(K,{"aria-label":`Search knowledge`,"data-testid":`kb-search-input`,value:b,onChange:e=>x(e.target.value),placeholder:R&&!d?`Search ${R.name}`:`Search everything`,className:`h-9 min-w-0 flex-1`}),(0,X.jsx)(u,{type:`submit`,size:`icon`,variant:`ghost`,"data-testid":`kb-search-submit`,"aria-label":`Search`,children:(0,X.jsx)(Ie,{size:16})}),w&&(0,X.jsx)(u,{type:`button`,size:`icon`,variant:`ghost`,"data-testid":`kb-browser-close`,"aria-label":`Close knowledge browser`,onClick:()=>T(!1),children:(0,X.jsx)(y,{size:16})})]}),R&&(0,X.jsxs)(`label`,{className:`flex shrink-0 items-center gap-2 border-b border-outline-variant px-3 py-2 text-xs text-outline`,children:[(0,X.jsx)(`input`,{type:`checkbox`,"data-testid":`kb-search-all`,checked:d,onChange:e=>U({searchAll:e.target.checked?`1`:null})}),`Search all knowledge bases`]}),(0,X.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-2 pb-1`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1`,children:[(0,X.jsx)(`h2`,{className:`text-sm font-medium text-outline`,children:`Knowledge bases`}),(0,X.jsx)(de,{label:`Knowledge bases`,children:`Upload documents, write Markdown or sync a folder. Agents search this knowledge with citations, and document details show what they read.`})]}),(0,X.jsx)(u,{size:`icon`,variant:`ghost`,"aria-label":`New knowledge base`,"data-testid":`kb-create`,onClick:()=>C(`create`),children:(0,X.jsx)(Ee,{size:16})})]}),L.isLoading&&(0,X.jsx)(xe,{className:`mx-2 h-9`}),(0,X.jsx)(Fr,{bases:L.data??[],projectName:ae,kbId:i,documentId:o,documents:z.data?.documents??[],onSelectKb:te,onOpenDocument:G})]}),(0,X.jsx)(Ir,{})]});return(0,X.jsx)(g,{open:w&&!E,onOpenChange:T,children:(0,X.jsxs)(`div`,{"data-testid":`knowledge-bases`,className:`relative flex min-h-0 min-w-0 flex-1`,children:[(0,X.jsx)(`h1`,{"data-testid":`view-title`,className:`sr-only`,children:`Knowledge bases`}),E&&se,!E&&(0,X.jsxs)(v,{children:[(0,X.jsx)(_,{className:`fixed inset-0 z-50 bg-black/70`}),(0,X.jsxs)(m,{"data-testid":`kb-mobile-browser`,className:`viewport-sheet fixed inset-x-0 z-50 bg-background`,children:[(0,X.jsx)(p,{className:`sr-only`,children:`Browse knowledge`}),(0,X.jsx)(f,{className:`sr-only`,children:`Search knowledge bases and choose a document`}),se]})]}),(0,X.jsxs)(`div`,{"data-testid":`kb-dropzone`,className:l(`relative flex min-h-0 min-w-0 flex-1 flex-col`,k&&`outline-2 -outline-offset-4 outline-dashed outline-primary`),onDragOver:e=>{R&&(e.preventDefault(),A(!0))},onDragLeave:()=>A(!1),onDrop:ie,children:[(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-outline-variant px-3 py-2 lg:hidden`,children:[(0,X.jsx)(h,{asChild:!0,children:(0,X.jsxs)(u,{"data-testid":`kb-browser-open`,variant:`ghost`,size:`sm`,"aria-expanded":w,"aria-controls":`kb-sidebar-panel`,onClick:()=>T(!0),children:[(0,X.jsx)(Ne,{size:16}),`Browse`]})}),R&&(0,X.jsx)(`span`,{className:`min-w-0 truncate text-sm text-outline`,children:R.name})]}),o&&c&&(0,X.jsx)(`div`,{className:`flex shrink-0 items-center border-b border-outline-variant px-3 py-1`,children:(0,X.jsxs)(u,{variant:`ghost`,size:`sm`,"data-testid":`kb-search-back`,className:`min-w-0`,onClick:()=>W()&&U({document:null}),children:[(0,X.jsx)(ye,{size:14}),(0,X.jsxs)(`span`,{className:`truncate`,children:[`Back to results for “`,c,`”`]})]})}),(0,X.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1`,children:oe}),(0,X.jsx)(Br,{uploads:H,onOpen:G})]}),S===`create`&&(0,X.jsx)(kn,{open:!0,projectId:e,onClose:()=>C(null),onCreated:e=>{C(null),T(!1),U({kb:e.id,document:null,label:null,q:null})}}),S===`settings`&&R&&(0,X.jsx)(An,{kb:R,onClose:()=>C(null),onDeleted:()=>{C(null),U({kb:null,document:null,label:null})}}),S===`new-document`&&R&&(0,X.jsx)(Pn,{kb:R,initialFile:N,onClose:F,onUploadMany:e=>{F(),H.add(R.id,e)},onCreated:(e,t)=>{F(),U({document:e.id,editorMode:t?null:`edit`})}})]})})}function Fr({bases:e,projectName:t,kbId:n,documentId:r,documents:i,onSelectKb:a,onOpenDocument:o}){let[s,c]=(0,J.useState)(null);(0,J.useEffect)(()=>{r&&c(null)},[r]);let u=new Map;for(let n of e){let e=t(n.project_id);u.set(e,[...u.get(e)??[],n])}let d=[...u.entries()].sort(([e],[t])=>e===`Global`?-1:t===`Global`?1:e.localeCompare(t));return(0,X.jsx)(`div`,{"data-testid":`kb-list`,className:`space-y-3`,children:d.map(([e,t])=>(0,X.jsxs)(`section`,{"aria-label":e,children:[d.length>1&&(0,X.jsx)(`h3`,{className:`truncate px-2 pb-0.5 pt-1 text-xs text-outline`,children:e}),(0,X.jsx)(`ul`,{className:`space-y-0.5`,children:t.map(e=>{let t=e.id===n,u=t&&s!==e.id&&i.length>0;return(0,X.jsxs)(`li`,{children:[(0,X.jsxs)(`button`,{type:`button`,"data-testid":`kb-row`,"data-kb-name":e.name,"aria-current":t&&!r?`page`:void 0,"aria-expanded":u,className:l(`flex min-h-9 w-full items-center gap-2 rounded-md px-2 text-left text-sm hover:bg-surface-high`,t&&`font-medium`,t&&!r&&`bg-surface-high`),onClick:()=>{t&&c(t=>t===e.id?null:e.id),a(e.id)},children:[(0,X.jsx)(ze,{size:14,"aria-hidden":!0,className:l(`-mr-1 shrink-0 text-outline transition-transform motion-reduce:transition-none`,u&&`rotate-90`,e.document_count===0&&`invisible`)}),(0,X.jsx)(He,{size:15,className:`shrink-0 text-outline`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),(0,X.jsx)(`span`,{className:`text-xs font-normal tabular-nums text-outline`,children:e.document_count})]}),u&&(0,X.jsx)(`ul`,{className:`ml-4 mt-0.5 space-y-0.5 border-l border-outline-variant pl-2`,children:i.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,"data-testid":`kb-nav-document`,"data-document-title":e.title,"aria-current":e.id===r?`page`:void 0,className:l(`flex min-h-8 w-full items-center gap-2 rounded-md px-2 text-left text-sm hover:bg-surface-high`,e.id===r?`bg-surface-high text-on-surface`:`text-outline`),onClick:()=>o(e.id),children:[(0,X.jsx)(Ae,{size:14,className:`shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.title})]})},e.id))})]},e.id)})})]},e))})}function Ir(){let e=mt(),t=e.data,n=t?t.embedding.provider===`none`?{text:`Keyword search only`,title:`Configure embeddings in Settings to also search by meaning`}:t.embedding.ready?{text:`Hybrid search`,title:t.embedding.model??void 0}:{text:`Embeddings not ready`,title:t.embedding.detail??``}:null,r=t?t.jobs.queued+t.jobs.running:0;return(0,X.jsx)(`p`,{role:`status`,"data-testid":`kb-status`,className:`shrink-0 border-t border-outline-variant px-4 py-2 text-xs text-outline`,children:t?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{title:n?.title,children:n?.text}),r?` · ${r} processing`:``]}):e.error?`Knowledge status unavailable`:`Loading…`})}function Lr({children:e}){return(0,X.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto`,children:e})}function Rr({children:e,testId:t}){return(0,X.jsx)(`div`,{"data-testid":t,className:`mx-auto flex max-w-lg flex-1 flex-col items-start justify-center gap-4 p-6`,children:e})}function zr({query:e,search:t,onOpen:n,onClear:r}){let i=t.data;return(0,X.jsxs)(`section`,{"data-testid":`kb-search-results`,"aria-label":`Search results`,className:`w-full min-w-0 space-y-4 p-4 sm:p-8`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsxs)(`h2`,{className:`mr-auto text-lg font-medium`,children:[`Results for “`,e,`”`]}),i&&i.hits.length>0&&(0,X.jsxs)(`span`,{className:`text-xs text-outline`,"data-testid":`kb-search-count`,children:[i.hits.length,` `,i.hits.length===1?`result`:`results`]}),(0,X.jsxs)(u,{variant:`ghost`,size:`sm`,onClick:r,"data-testid":`kb-search-clear`,children:[(0,X.jsx)(y,{size:14}),`Clear`]})]}),i?.degraded&&(0,X.jsx)(`p`,{role:`status`,className:`text-sm text-warning`,children:i.degraded}),t.isLoading&&(0,X.jsx)(`p`,{className:`text-sm text-outline`,children:`Searching…`}),t.error&&(0,X.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:t.error.message}),i?.hits.length===0&&(0,X.jsx)(`p`,{className:`text-sm text-outline`,"data-testid":`kb-search-empty`,children:`Nothing matched. Try other words or search all knowledge bases.`}),i?.hits.map(e=>(0,X.jsxs)(`article`,{"data-testid":`kb-search-result`,className:`space-y-2 border-b border-outline-variant pb-4`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`block text-left`,onClick:()=>n(e.document_id,Ur(e.passages[0]?.heading_path)),children:[(0,X.jsx)(`span`,{className:`block font-medium text-primary hover:underline`,children:e.title}),(0,X.jsxs)(`span`,{className:`block break-all text-xs text-outline`,children:[e.kb_name,` · `,e.path]})]}),e.labels.length>0&&(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.labels.map(e=>(0,X.jsx)(Dt,{variant:`secondary`,children:e},e))}),e.passages.map(t=>(0,X.jsxs)(`div`,{"data-testid":`kb-search-passage`,className:`cursor-pointer space-y-1 rounded-md p-2 hover:bg-surface-high`,onClick:()=>n(e.document_id,Ur(t.heading_path)),children:[(t.heading_path.length>0||t.locator?.page||t.locator?.sheet)&&(0,X.jsx)(`div`,{className:`text-xs text-outline`,children:[...t.heading_path.map(Mr),...t.locator?.page?[`page ${t.locator.page}`]:[],...t.locator?.sheet?[`sheet ${t.locator.sheet}`]:[]].join(` › `)}),(0,X.jsx)(`p`,{className:`text-sm leading-relaxed`,children:(0,X.jsx)(Nr,{text:t.snippet})})]},t.chunk_id))]},e.document_id))]})}function Br({uploads:e,onOpen:t}){if(!e.uploads.length)return null;let n=e.uploads.some(e=>e.status!==`uploading`);return(0,X.jsxs)(`section`,{"data-testid":`kb-upload-queue`,"aria-label":`Uploads`,className:`absolute bottom-4 right-4 z-10 flex max-h-72 w-80 max-w-[calc(100%-2rem)] flex-col rounded-lg border border-outline-variant bg-surface text-sm shadow-lg`,children:[(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between px-3 py-1.5`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:`Uploads`}),n&&(0,X.jsx)(u,{size:`sm`,variant:`ghost`,onClick:e.clearFinished,"data-testid":`kb-upload-clear`,children:`Dismiss`})]}),(0,X.jsx)(`div`,{className:`min-h-0 space-y-1 overflow-y-auto px-3 pb-2`,children:e.uploads.map(n=>(0,X.jsx)(Hr,{upload:n,onOpen:t,onRetry:()=>e.retry(n.id)},n.id))})]})}var Vr={pending:`Parsing…`,ok:`Open`,partial:`Open · partly parsed`,failed:`Parse failed`};function Hr({upload:e,onOpen:t,onRetry:n}){let r=Ot(e.status===`done`?e.kbId:null).data?.documents.find(t=>t.id===e.document?.id)??e.document;return(0,X.jsxs)(`div`,{"data-testid":`kb-upload-item`,"data-status":e.status,"data-parse-state":r?.parse_state,className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.file.name}),e.status===`uploading`&&(0,X.jsx)(`span`,{className:`h-1.5 w-24 overflow-hidden rounded-full bg-surface-high`,role:`progressbar`,"aria-label":`Upload progress`,"aria-valuenow":Math.round(e.progress*100),children:(0,X.jsx)(`span`,{className:`block h-full bg-primary`,style:{width:`${Math.round(e.progress*100)}%`}})}),e.status===`done`&&r&&(0,X.jsx)(`button`,{type:`button`,className:l(`hover:underline`,r.parse_state===`failed`?`text-error`:`text-primary`),onClick:()=>t(r.id),children:Vr[r.parse_state]}),e.status===`failed`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{role:`alert`,className:`text-error`,children:e.error}),(0,X.jsx)(u,{size:`sm`,variant:`ghost`,onClick:n,"data-testid":`kb-upload-retry`,children:`Retry`})]})]})}function Ur(e){return e?.[e.length-1]}export{jr as default};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MarkdownRenderer-FKMLueR4.js","assets/rolldown-runtime-DSDNlrLa.js","assets/jsx-runtime-CVMpzJz9.js","assets/react-dom-DTbwZiiP.js","assets/button-C91mbQEU.js","assets/floating-ui.react-dom-BDMgcqWu.js","assets/bundle-mjs-CdK3cBzO.js","assets/client-BDeNEjHL.js","assets/preload-helper-BLdHbfdN.js","assets/dialog-Dsdmr5mY.js","assets/x-CzIc4TnV.js","assets/dist-bytwC6rk.js","assets/es2015-w69PgVrA.js","assets/document-display-BQ5dM8QT.js","assets/index-D3mYpeGu.js","assets/QueryClientProvider-DlPztvhd.js","assets/useMutation-HX90wI4L.js","assets/chunk-OB3PAWPO-1IihCzFx.js","assets/tabs-DpKnjRll.js","assets/dist-BKxzy3T8.js","assets/dist-Ct6061MC.js","assets/label-BdnRgBbz.js","assets/FormDialog-BY8LbFlB.js","assets/dist-D8Wfxh48.js","assets/check-BN9WfUXs.js","assets/chevron-down-DsKwSkKG.js","assets/maximize-2-IKRw5Gjm.js","assets/MarkdownEditor-p8DBlDfc.js","assets/file-kind-BYU1kv95.js","assets/schemas-BQZhekae.js","assets/textarea-BRdsUa6B.js","assets/bulk-actions-C8S1Gt4W.js","assets/index-B8T4bf2f.css","assets/mermaid.core-CE0shN4j.js","assets/chunk-Y2CYZVJY-DsF7k-Jl.js","assets/src-DpAUOMD9.js","assets/chunk-DU6HZSFF-BaVVqpDB.js","assets/chunk-75Z2AOVW-DGmxZV98.js","assets/dist-BwUkq7ma.js","assets/chunk-P2QGCYS3-DpMkYw3X.js","assets/chunk-PWAF6VOD-CP1kSMru.js","assets/chunk-GMAD6QVW-D7d5cxQ3.js","assets/chunk-4HAMMTFA-DY6eE90t.js","assets/rough.esm-Dy-Kn_BL.js","assets/chunk-GVQU2GXP-GfOuiNH1.js","assets/chunk-L3NEJ4N5-BD8q2mez.js","assets/chunk-OSK3NFVY-DN8XtEwT.js","assets/line-BmNPsHiE.js","assets/path-fybaL0A-.js","assets/array-BifhSqXX.js","assets/graphlib-DS17s2tU.js","assets/wiki-links-A52THGx_.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{a as e}from"./rolldown-runtime-DSDNlrLa.js";import{n as t,t as n}from"./jsx-runtime-CVMpzJz9.js";import{t as r}from"./preload-helper-BLdHbfdN.js";var i=e(t(),1),a=n(),o=(0,i.lazy)(()=>r(()=>import(`./MarkdownRenderer-FKMLueR4.js`).then(e=>({default:e.MarkdownRenderer})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51]))),s=(0,i.memo)(function(e){let{fallback:t,...n}=e;return(0,a.jsx)(i.Suspense,{fallback:t??(0,a.jsx)(`div`,{role:`status`,className:`text-sm text-outline`,children:`Loading document…`}),children:(0,a.jsx)(o,{...n})})});export{s as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SourceEditor-78XFXmqS.js","assets/rolldown-runtime-DSDNlrLa.js","assets/jsx-runtime-CVMpzJz9.js","assets/client-BDeNEjHL.js","assets/Markdown-B0Ztqigq.js","assets/preload-helper-BLdHbfdN.js","assets/file-kind-BYU1kv95.js","assets/index-D3mYpeGu.js","assets/QueryClientProvider-DlPztvhd.js","assets/useMutation-HX90wI4L.js","assets/react-dom-DTbwZiiP.js","assets/chunk-OB3PAWPO-1IihCzFx.js","assets/button-C91mbQEU.js","assets/floating-ui.react-dom-BDMgcqWu.js","assets/bundle-mjs-CdK3cBzO.js","assets/dist-bytwC6rk.js","assets/es2015-w69PgVrA.js","assets/x-CzIc4TnV.js","assets/tabs-DpKnjRll.js","assets/dist-BKxzy3T8.js","assets/dist-Ct6061MC.js","assets/label-BdnRgBbz.js","assets/FormDialog-BY8LbFlB.js","assets/dist-D8Wfxh48.js","assets/check-BN9WfUXs.js","assets/chevron-down-DsKwSkKG.js","assets/dialog-Dsdmr5mY.js","assets/document-display-BQ5dM8QT.js","assets/maximize-2-IKRw5Gjm.js","assets/schemas-BQZhekae.js","assets/textarea-BRdsUa6B.js","assets/bulk-actions-C8S1Gt4W.js","assets/index-B8T4bf2f.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{a as e}from"./rolldown-runtime-DSDNlrLa.js";import{n as t,t as n}from"./jsx-runtime-CVMpzJz9.js";import{t as r}from"./button-C91mbQEU.js";import{d as i}from"./client-BDeNEjHL.js";import{t as a}from"./maximize-2-IKRw5Gjm.js";import{t as o}from"./preload-helper-BLdHbfdN.js";import{t as s}from"./Markdown-B0Ztqigq.js";import{r as c}from"./document-display-BQ5dM8QT.js";import{t as l}from"./file-kind-BYU1kv95.js";var u={name:`minimize-2`,size:24,node:[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]};u.node;var d=i(u),f=e(t(),1),p=n(),m=(0,f.lazy)(()=>o(()=>import(`./SourceEditor-78XFXmqS.js`).then(e=>({default:e.SourceEditor})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32])));function h(e){return(0,p.jsx)(f.Suspense,{fallback:(0,p.jsx)(`div`,{style:{height:e.height??320},className:`p-3 text-xs text-outline`,children:`Loading editor...`}),children:(0,p.jsx)(m,{...e})})}function g(e,t){if(!t)return e;let n=e.match(/^\s*#[ \t]+(.+?)[ \t#]*(?:\r?\n|$)/),r=e=>e.trim().replace(/\s+/g,` `).toLowerCase();return n?.[1]&&r(n[1])===r(t)?e.slice(n[0].length):e}function _({path:e,value:t,onChange:n,onSave:i,readOnly:o=!1,testId:u,wikiLinks:m,initialMode:_,mode:v,onModeChange:y,header:b,height:x,id:S,label:C,placeholder:w,expanded:T,onExpandedChange:E,layout:D=`frame`,actions:O,notice:k,pageTitle:A,hideFrontmatter:j=!1,compact:M=!1}){let N=l(e),[P,F]=(0,f.useState)(_??(o&&N?`read`:`edit`)),I=v??P;function L(e){F(e),y?.(e)}let[R,z]=(0,f.useState)(!1),B=T??R,V=(0,f.useRef)(null);(0,f.useEffect)(()=>{if(!B||!V.current)return;let e=[],t=V.current;for(;t.parentElement;){let n=t.parentElement;for(let r of Array.from(n.children))r!==t&&r instanceof HTMLElement&&(e.push({element:r,inert:r.inert}),r.inert=!0);if(n.hasAttribute(`data-document-container`)||n===document.body)break;t=n}return()=>{for(let t of e)t.element.inert=t.inert}},[B]);function H(e){z(e),E?.(e)}(0,f.useEffect)(()=>{if(!B)return;function e(e){if(e.key!==`Escape`||e.defaultPrevented)return;let t=document.querySelector(`[role="dialog"], [role="alertdialog"]`);(!t||V.current?.contains(t))&&(z(!1),E?.(!1))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[B,E]);let U=c(t),W=g(U.body,A),G=D===`page`&&N&&!B;return(0,p.jsxs)(`section`,{ref:V,"data-testid":`markdown-editor`,"data-expanded":B,"data-document-expanded":B,className:`flex min-w-0 flex-col ${G?``:`min-h-0 rounded-md border border-surface-highest bg-surface`} ${B?`fixed inset-2 z-60 sm:inset-6`:``}`,style:B||G?void 0:{height:x??`min(65dvh, 760px)`,minHeight:x?void 0:280},"aria-label":`Document ${e}`,onKeyDown:e=>{e.defaultPrevented||(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&(e.preventDefault(),i?.())},children:[b&&(0,p.jsx)(`div`,{className:`shrink-0 border-b border-surface-highest p-3`,children:b}),(0,p.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center ${M?`gap-1`:`gap-2`} border-b border-surface-highest ${G?`sticky top-0 z-10 bg-background py-2`:M?`px-2 py-1`:`p-2`}`,children:[N&&(0,p.jsx)(`fieldset`,{className:`flex gap-1`,"aria-label":`Document mode`,children:[`read`,`edit`,`split`].map(e=>(0,p.jsx)(r,{type:`button`,size:`sm`,variant:!M&&I===e?`default`:`ghost`,className:`${e===`split`&&D===`page`?`hidden md:inline-flex`:``} ${M&&I===e?`bg-surface-highest text-on-surface`:``}`,"data-testid":`markdown-mode-${e}`,"aria-pressed":I===e,onClick:()=>L(e),children:e===`read`?`Read`:e===`edit`?o?`Source`:`Edit`:`Split`},e))}),(0,p.jsx)(`span`,{className:`min-w-0 flex-1 truncate px-1 text-xs text-outline`,title:e,children:D===`page`||M?``:e}),O,B&&i&&!b&&!O&&(0,p.jsx)(r,{type:`button`,"data-testid":`markdown-save`,disabled:o,onClick:i,children:`Save`}),(0,p.jsx)(r,{type:`button`,size:`icon`,variant:`ghost`,"data-testid":`markdown-expand`,"aria-label":B?`Exit fullscreen`:`Expand editor`,"aria-pressed":B,onClick:()=>H(!B),children:B?(0,p.jsx)(d,{size:16}):(0,p.jsx)(a,{size:16})})]}),k&&(0,p.jsx)(`div`,{className:`shrink-0 space-y-1 border-b border-surface-highest ${G?`py-2`:`p-3`}`,children:k}),(0,p.jsxs)(`div`,{className:`grid min-h-0 min-w-0 flex-1 ${G?`items-start gap-6 pt-4`:`overflow-hidden`} ${I===`split`&&N?`grid-rows-2 md:grid-cols-2 md:grid-rows-1`:`grid-cols-1`}`,children:[(0,p.jsx)(`div`,{className:`min-h-0 min-w-0 ${G?`[&_.cm-editor]:min-h-[50dvh]`:`overflow-hidden`} ${I===`read`&&N?`hidden`:``}`,children:(0,p.jsx)(h,{path:e,value:t,onChange:n,onSave:i,readOnly:o,height:G?`auto`:`100%`,testId:u,hidePreview:!0,defaultWrap:!0,id:S,label:C,placeholder:w})}),N&&I!==`edit`&&(0,p.jsx)(`article`,{"data-testid":`markdown-preview`,"aria-label":`Rendered Markdown`,className:`min-h-0 min-w-0 ${G?`pb-6`:`overflow-auto p-4 sm:p-8`} ${I===`split`&&!G?`border-t border-surface-highest md:border-l md:border-t-0`:``}`,children:(0,p.jsxs)(`div`,{className:`wrap-break-word ${G?`[&_:is(p,ul,ol,blockquote,h1,h2,h3,h4,h5,h6)]:max-w-[72ch]`:`mx-auto max-w-[76ch]`}`,children:[U.metadata!==null&&!j&&(0,p.jsxs)(`details`,{className:`mb-5 rounded border border-surface-highest p-3 text-sm text-outline`,children:[(0,p.jsx)(`summary`,{className:`cursor-pointer`,children:`Document metadata`}),(0,p.jsx)(`pre`,{className:`mt-3 whitespace-pre-wrap wrap-break-word font-mono text-xs`,children:U.metadata})]}),t.trim()?(0,p.jsx)(s,{readable:!0,wikiLinks:m,children:W}):(0,p.jsx)(`p`,{className:`text-sm text-outline`,children:`This document is empty.`})]})})]})]})}export{h as n,d as r,_ as t};
|