orc-ai 0.1.37 → 0.1.41
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 +37 -1
- package/dist/index.js +641 -584
- package/dist/skills/orc-platform/SKILL.md +7 -0
- package/dist/skills/orc-platform/references/execution.md +7 -1
- package/dist/skills/orc-platform/references/session-archive.md +199 -0
- package/dist/skills/orc-platform/scripts/sync-sessions.py +297 -0
- package/dist/web/assets/{Agents-BbR4Bppp.js → Agents-1lX_DRrR.js} +1 -1
- package/dist/web/assets/{Audit-BFK82hee.js → Audit-DnRP9Ivm.js} +1 -1
- package/dist/web/assets/{Dashboard-DJufUiXp.js → Dashboard-bT5SABu_.js} +1 -1
- package/dist/web/assets/{DocumentWorkspace-C6iWm8RY.js → DocumentWorkspace-BI4JWVsO.js} +1 -1
- package/dist/web/assets/{FileEditor-C5d4xs5E.js → FileEditor-Cb8uXr6e.js} +1 -1
- package/dist/web/assets/{JobWebhooks-DGM7EHVj.js → JobWebhooks-CYE2UA0V.js} +1 -1
- package/dist/web/assets/{Jobs-Cwhf6HrZ.js → Jobs-Fyd46CkI.js} +1 -1
- package/dist/web/assets/Knowledge-prZWODFP.js +28 -0
- package/dist/web/assets/{PackageCatalog-rlnJnlaQ.js → PackageCatalog-R8kcGP28.js} +4 -4
- package/dist/web/assets/{Pager-B53jtBdE.js → Pager-urh4-P2a.js} +1 -1
- package/dist/web/assets/{Rules-C5l03Rhx.js → Rules-if9ZzABl.js} +2 -2
- package/dist/web/assets/Sessions-AfC-wZoj.js +5 -0
- package/dist/web/assets/Settings-CNPE54fO.js +20 -0
- package/dist/web/assets/Skills-BJcE6uiQ.js +1 -0
- package/dist/web/assets/{SourceEditor-DW0vd3ce.js → SourceEditor-a2_IdCoT.js} +3 -3
- package/dist/web/assets/{Tasks-DEDs5HYJ.js → Tasks-COQCj4HF.js} +8 -13
- package/dist/web/assets/Terminals-D4K_u_ch.js +115 -0
- package/dist/web/assets/Terminals-DODPh4gr.css +1 -0
- package/dist/web/assets/{Webhooks-BopgoCAt.js → Webhooks-DvsCfbZY.js} +1 -1
- package/dist/web/assets/{abnfDiagram-VCTEODGH-99oetRq5.js → abnfDiagram-VCTEODGH-C1g9AmGT.js} +1 -1
- package/dist/web/assets/{arc-jz6C0oUp.js → arc-BX1-afFK.js} +1 -1
- package/dist/web/assets/{architectureDiagram-5GKGNRK7-CDnf-tTr.js → architectureDiagram-5GKGNRK7-DTDe767x.js} +3 -3
- package/dist/web/assets/{blockDiagram-I7D4REHJ-wUZULRmh.js → blockDiagram-I7D4REHJ-DJnvrUZM.js} +1 -1
- package/dist/web/assets/{c4Diagram-7LVT6UL2-BbTCN0gc.js → c4Diagram-7LVT6UL2-rpXv4dc9.js} +1 -1
- package/dist/web/assets/channel-DsRXlXQz.js +1 -0
- package/dist/web/assets/{chunk-2Q5K7J3B-DXQa_KS-.js → chunk-2Q5K7J3B-BEq6zYAO.js} +1 -1
- package/dist/web/assets/{chunk-5VM5RSS4-DKex8fM9.js → chunk-5VM5RSS4-kAS1IBM0.js} +1 -1
- package/dist/web/assets/{chunk-F27PBJKO-CV24Bpwp.js → chunk-F27PBJKO-BtG5IndH.js} +1 -1
- package/dist/web/assets/{chunk-IMKFNOWR-dgfQu6Cr.js → chunk-IMKFNOWR-C-NO8OSz.js} +1 -1
- package/dist/web/assets/{chunk-JWPE2WC7-rU75UmMf.js → chunk-JWPE2WC7-2IhqyMft.js} +1 -1
- package/dist/web/assets/{chunk-POPQ4Y6H-D05TMjhY.js → chunk-POPQ4Y6H-DmxK4niw.js} +1 -1
- package/dist/web/assets/{chunk-SVP7TREG-DCPR8a_3.js → chunk-SVP7TREG-BkVeMS09.js} +1 -1
- package/dist/web/assets/{chunk-TICWLB2K-14JxXrzn.js → chunk-TICWLB2K-DzlMwg1V.js} +1 -1
- package/dist/web/assets/{chunk-XXDRQBXY-CU-iUgTI.js → chunk-XXDRQBXY-ttUQmtBw.js} +1 -1
- package/dist/web/assets/classDiagram-ZZMXUADV-CZXMGXM8.js +1 -0
- package/dist/web/assets/classDiagram-v2-VYDZK3BY-CZXMGXM8.js +1 -0
- package/dist/web/assets/{cose-bilkent-JH36ORCC-DsK-Wgux.js → cose-bilkent-JH36ORCC-yhoqj6vM.js} +1 -1
- package/dist/web/assets/{cynefin-OW5HDTMX-CIbMF4yA.js → cynefin-OW5HDTMX-CQZuSJ5b.js} +1 -1
- package/dist/web/assets/{cynefinDiagram-5FMLGOSQ-Dfa-crHB.js → cynefinDiagram-5FMLGOSQ-Dz-2nuEW.js} +1 -1
- package/dist/web/assets/{dagre-GXQ25YYZ-B4F2yY9x.js → dagre-GXQ25YYZ-DZJid-R_.js} +1 -1
- package/dist/web/assets/{diagram-S7CK7UJ4-f6czEOz8.js → diagram-S7CK7UJ4-DB-Uzpn6.js} +1 -1
- package/dist/web/assets/{diagram-UQ7AKVKN-Bzc5H6mj.js → diagram-UQ7AKVKN-BjIgjC39.js} +1 -1
- package/dist/web/assets/{diagram-VSXAHHWV-nchG2_is.js → diagram-VSXAHHWV-CjFlgbiX.js} +1 -1
- package/dist/web/assets/{diagram-VX7I27RA-DtoGnSm-.js → diagram-VX7I27RA-BlfR5PYu.js} +1 -1
- package/dist/web/assets/{diagram-Z3DM3KII-B5RB4-4l.js → diagram-Z3DM3KII-DL6_QJQh.js} +1 -1
- package/dist/web/assets/{download-CUHnwD4I.js → download-CK_EusLu.js} +1 -1
- package/dist/web/assets/{ebnfDiagram-PWID7BFC-474F-fnY.js → ebnfDiagram-PWID7BFC-BjdizMG0.js} +1 -1
- package/dist/web/assets/{erDiagram-RLTQ6QDP-DjcLWB7r.js → erDiagram-RLTQ6QDP-BxMzPgpM.js} +1 -1
- package/dist/web/assets/{flowDiagram-HODETNUW-ClrSnJZC.js → flowDiagram-HODETNUW-C-HgPS9G.js} +1 -1
- package/dist/web/assets/folder-open-Bcqha5Pu.js +16 -0
- package/dist/web/assets/{ganttDiagram-EL5Y4UJY-DvUWwHi6.js → ganttDiagram-EL5Y4UJY-BEx6HKx_.js} +4 -4
- package/dist/web/assets/{gitGraphDiagram-WWUBYQGX-DzQUHPow.js → gitGraphDiagram-WWUBYQGX-D9yMgjsA.js} +1 -1
- package/dist/web/assets/{highlighted-body-KPVGNVTW-BwSphjF-.js → highlighted-body-KPVGNVTW-Cdq0W8LG.js} +1 -1
- package/dist/web/assets/index-BqQDBYwx.js +461 -0
- package/dist/web/assets/index-D1sNa9P-.css +1 -0
- package/dist/web/assets/{infoDiagram-27XIBGKW-BXiAYW5v.js → infoDiagram-27XIBGKW-e_LgGqFP.js} +1 -1
- package/dist/web/assets/{ishikawaDiagram-5VMMS53U-DtkPoBMd.js → ishikawaDiagram-5VMMS53U-jOCokdCr.js} +1 -1
- package/dist/web/assets/{journeyDiagram-3NMN7TZE-De55MHfN.js → journeyDiagram-3NMN7TZE-DfyXRW30.js} +1 -1
- package/dist/web/assets/{kanban-definition-UXKFOSKX-CMbmC8bh.js → kanban-definition-UXKFOSKX-D6Mgx6_N.js} +1 -1
- package/dist/web/assets/{layout-CMoc3Ymp.js → layout-BFQQ8SSL.js} +1 -1
- package/dist/web/assets/{linear-ByaFbiCi.js → linear-C251cMFR.js} +1 -1
- package/dist/web/assets/list-BnZDr6iH.js +6 -0
- package/dist/web/assets/mermaid-HWGCJPDP-DE8bnMel.js +609 -0
- package/dist/web/assets/{mindmap-definition-YA3MSWOX-DHpoB_3Z.js → mindmap-definition-YA3MSWOX-hX6YQE6d.js} +1 -1
- package/dist/web/assets/{pegDiagram-XKGWAZYB-DlUFQicu.js → pegDiagram-XKGWAZYB-DRRv8KEz.js} +1 -1
- package/dist/web/assets/{pencil-C7MeJi2-.js → pencil-ClEwbF1x.js} +1 -1
- package/dist/web/assets/{pieDiagram-E7YTZNPT-BTxNRrLy.js → pieDiagram-E7YTZNPT-DwRQy5kr.js} +1 -1
- package/dist/web/assets/{quadrantDiagram-AXDQQJYC-BXisK15b.js → quadrantDiagram-AXDQQJYC-u-NZRX9E.js} +1 -1
- package/dist/web/assets/{railroadDiagram-O6MQD6OU-Dep-5EOi.js → railroadDiagram-O6MQD6OU-DsGn0lJc.js} +1 -1
- package/dist/web/assets/{refresh-cw-Bwp-x39v.js → refresh-cw-BGtNOi70.js} +1 -1
- package/dist/web/assets/{requirementDiagram-BXWQKSXE-Dts4RxIL.js → requirementDiagram-BXWQKSXE-Bak7hmyH.js} +1 -1
- package/dist/web/assets/{sankeyDiagram-P5KCCOFB-B55oiprJ.js → sankeyDiagram-P5KCCOFB-Bx5Wxkio.js} +1 -1
- package/dist/web/assets/{save-F382q8r7.js → save-ChNqW56W.js} +1 -1
- package/dist/web/assets/{scroll-area-B2WVTNHY.js → scroll-area-YSA2ORI8.js} +1 -1
- package/dist/web/assets/{sequenceDiagram-WJ2MYXX4-Dm8OZOYP.js → sequenceDiagram-WJ2MYXX4-CyWelz_H.js} +1 -1
- package/dist/web/assets/{sizeCapture-INFHLROL-CdGYDQGd.js → sizeCapture-INFHLROL-BCzEf-8B.js} +1 -1
- package/dist/web/assets/{stateDiagram-D77RDMKH-DzLl6piI.js → stateDiagram-D77RDMKH-BkqZfGYQ.js} +1 -1
- package/dist/web/assets/stateDiagram-v2-MP3YSRHH-PLwI4Xlh.js +1 -0
- package/dist/web/assets/{swimlanes-42K2YHIH-C0y9oB16.js → swimlanes-42K2YHIH-BMYDAy8X.js} +1 -1
- package/dist/web/assets/swimlanesDiagram-VR7AAH4N-BEGqjIIe.js +8 -0
- package/dist/web/assets/{timeline-definition-24CTP7MA-BcFnACv9.js → timeline-definition-24CTP7MA-BrGykZXB.js} +1 -1
- package/dist/web/assets/{upload-De21en-z.js → upload-waJ36Q68.js} +1 -1
- package/dist/web/assets/{useJobs-C4BQQWOR.js → useJobs-By4K4BjX.js} +1 -1
- package/dist/web/assets/{useKnowledge-Dlk6zbmi.js → useKnowledge-DMSoPz-b.js} +1 -1
- package/dist/web/assets/{useMemories-B0YNmRrw.js → useMemories-bv4XvbzQ.js} +1 -1
- package/dist/web/assets/useProjectScope-BvcpSOql.js +1 -0
- package/dist/web/assets/{vennDiagram-4TSXK5OY-Bn7Y7h5d.js → vennDiagram-4TSXK5OY-CkLSasvk.js} +1 -1
- package/dist/web/assets/{wardleyDiagram-VM6X3IG4-Bd7zbrPy.js → wardleyDiagram-VM6X3IG4-DfPte2eh.js} +1 -1
- package/dist/web/assets/{xychartDiagram-S5SC5T6Z-CyDYeK9G.js → xychartDiagram-S5SC5T6Z-ClFkeona.js} +1 -1
- package/dist/web/index.html +3 -3
- package/package.json +1 -1
- package/dist/web/assets/Knowledge-D5JF_DmG.js +0 -38
- package/dist/web/assets/Sessions-B1ES2jjN.js +0 -1
- package/dist/web/assets/Settings-DZTNnZp2.js +0 -12
- package/dist/web/assets/Skills-zUJSqzxy.js +0 -1
- package/dist/web/assets/Terminals-BbWYyHA3.css +0 -1
- package/dist/web/assets/Terminals-jLXfmfnA.js +0 -43
- package/dist/web/assets/channel-BMK2j5Xo.js +0 -1
- package/dist/web/assets/classDiagram-ZZMXUADV-C3CpsbeZ.js +0 -1
- package/dist/web/assets/classDiagram-v2-VYDZK3BY-C3CpsbeZ.js +0 -1
- package/dist/web/assets/folder-open-DqVAWgc5.js +0 -6
- package/dist/web/assets/index-2ojlkIJg.css +0 -1
- package/dist/web/assets/index-CRsafixF.js +0 -379
- package/dist/web/assets/mermaid-HWGCJPDP-BANMxb7n.js +0 -609
- package/dist/web/assets/schemas-Cwl03S4d.js +0 -57
- package/dist/web/assets/stateDiagram-v2-MP3YSRHH-Bd9-xfy5.js +0 -1
- package/dist/web/assets/swimlanesDiagram-VR7AAH4N-CY_HM0pG.js +0 -8
- package/dist/web/assets/useProjectScope-NKMBMTCk.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{h as E,l as U,m as V,n as q,o as I,p as J,j as t,E as Q,S as H,q as T,P as S,T as z,s as W,t as L,v as m,w as O,x as v,y as F,z as $,R as G}from"./index-
|
|
1
|
+
import{h as E,l as U,m as V,n as q,o as I,p as J,j as t,E as Q,S as H,q as T,P as S,T as z,s as W,t as L,v as m,w as O,x as v,y as F,z as $,R as G}from"./index-BqQDBYwx.js";import{u as K}from"./useJobs-By4K4BjX.js";import{u as X}from"./useMemories-bv4XvbzQ.js";import{u as Y}from"./useProjectScope-BvcpSOql.js";function l(o,p){return o.isLoading?"…":o.error?"—":p}function es({projectId:o}){var f,_;const p=E(),a=Y(o),D=U("sm"),i=s=>{const e=new URL(s,window.location.origin);e.searchParams.set("project",a),p({pathname:e.pathname,search:e.search,hash:e.hash})},d=a==="all"||a==="unassigned"?void 0:{project_id:a},c=V(d),{data:b,isLoading:P}=c,u=K(d),{data:N}=u,h=X({project_id:d==null?void 0:d.project_id,limit:1},{enabled:a!=="unassigned"}),R=a==="unassigned"?0:((f=h.data)==null?void 0:f.total)??0,{data:n}=q(),j=I(!0),g=(j.data??[]).filter(s=>a==="all"||(a==="unassigned"?s.project_id===null:s.project_id===a)),w=a==="unassigned"?(N??[]).filter(s=>s.project_id===null):N??[],k=a==="unassigned"?(b??[]).filter(s=>s.project_id===null):b??[],r=k.reduce((s,e)=>(s[e.status]=(s[e.status]??0)+1,s),{}),y=[...k].sort((s,e)=>new Date(e.updated_at).getTime()-new Date(s.updated_at).getTime()).slice(0,8),x=w.filter(s=>s.enabled),A=a==="all"?"All Projects":a==="unassigned"?"Unassigned":((_=n==null?void 0:n.find(s=>s.id===a))==null?void 0:_.name)??"",M=[{label:"Doing",value:l(c,r.doing??0),sub:"in progress",path:"/tasks?view=table&status=doing"},{label:"Review",value:l(c,r.review??0),sub:"awaiting review",path:"/tasks?view=table&status=review"},{label:"Blocked",value:l(c,r.blocked??0),sub:"needs attention",path:"/tasks?view=table&status=blocked"},{label:"Todo",value:l(c,(r.todo??0)+(r.queued??0)),sub:"pending",path:"/tasks?view=board"},{label:"Done",value:l(c,r.done??0),sub:"completed",path:"/tasks?view=table&status=done"}],B=[{label:"Active jobs",value:l(u,x.length),sub:`of ${w.length} total`,path:"/jobs"},{label:"Memories",value:l(h,R),sub:"in this scope",path:J},{label:"Projects",value:(n??[]).filter(s=>s.status==="active").length,sub:"active across workspace",path:"/projects"}];return t.jsxs("div",{"data-activity-preview":!0,"data-testid":"activity-preview",className:"activity-preview",children:[t.jsxs("div",{className:"activity-heading",children:[t.jsxs("div",{children:[t.jsx("h1",{"data-testid":"view-title",children:"Activity"}),t.jsx("p",{"data-testid":"view-meta",children:A||"All projects"})]}),t.jsx("button",{type:"button",className:"activity-primary",onClick:()=>i("/tasks"),children:"View tasks"})]}),[c,u,h,j].some(s=>s.isLoading)&&t.jsx("p",{role:"status",className:"activity-muted mb-4",children:"Loading activity…"}),[{name:"Tasks",query:c},{name:"Jobs",query:u},{name:"Memories",query:h},{name:"Sessions",query:j}].filter(({query:s})=>s.error).map(({name:s,query:e})=>{var C;return t.jsx(Q,{message:`${s}: ${((C=e.error)==null?void 0:C.message)??"Could not load activity"}`,onRetry:()=>e.refetch()},s)}),t.jsx("section",{className:"activity-metrics","aria-label":"Task summary",children:M.map(s=>t.jsxs("button",{type:"button","data-testid":"stat-card","data-stat-label":s.label,className:"activity-metric",onClick:()=>i(s.path),children:[t.jsx("span",{className:"activity-metric-label",children:s.label}),t.jsx("span",{"data-testid":"stat-card-value",className:"activity-metric-value",children:s.value}),t.jsx("span",{className:"activity-metric-sub",children:s.sub})]},s.label))}),t.jsx("section",{className:"activity-resources","aria-label":"Workspace summary",children:B.map(s=>t.jsxs("button",{type:"button","data-testid":"stat-card","data-stat-label":s.label,onClick:()=>i(s.path),children:[t.jsx("span",{children:s.label}),t.jsx("span",{"data-testid":"stat-card-value",className:"activity-resource-value",children:s.value}),t.jsx("span",{className:"activity-resource-sub",children:s.sub})]},s.label))}),t.jsxs("section",{className:"activity-section",children:[t.jsxs("div",{className:"activity-section-heading",children:[t.jsx("h2",{children:"Recent tasks"}),t.jsx("button",{type:"button",className:"activity-text-action",onClick:()=>i("/tasks"),children:"View all"})]}),P?t.jsx("div",{className:"space-y-2",children:[0,1,2,3].map(s=>t.jsx(H,{className:"h-10 w-full"},s))}):y.length===0?t.jsx("p",{className:"activity-empty",children:"No tasks"}):D?t.jsxs(z,{className:"activity-task-table",children:[t.jsx(W,{children:t.jsxs(L,{children:[t.jsx(m,{children:"Task"}),t.jsx(m,{className:"w-36",children:"Status"}),t.jsx(m,{className:"w-28",children:"Priority"}),t.jsx(m,{className:"w-28",children:"Updated"})]})}),t.jsx(O,{children:y.map(s=>t.jsxs(L,{onClick:()=>i(`/tasks/${s.id}`),children:[t.jsx(v,{children:t.jsx("button",{type:"button",className:"activity-task-title",onClick:e=>{e.stopPropagation(),i(`/tasks/${s.id}`)},children:s.title})}),t.jsx(v,{children:t.jsx("span",{className:"activity-status","data-status":s.status,children:t.jsx(T,{status:s.status})})}),t.jsx(v,{children:t.jsx("span",{className:"activity-priority",children:t.jsx(S,{priority:s.priority})})}),t.jsx(v,{className:"activity-muted",children:new Date(s.updated_at).toLocaleDateString()})]},s.id))})]}):t.jsx("div",{className:"activity-task-list",children:y.map(s=>t.jsxs("article",{className:"activity-task-mobile",children:[t.jsx("button",{type:"button",className:"activity-task-title",onClick:()=>i(`/tasks/${s.id}`),children:s.title}),t.jsxs("div",{className:"activity-task-meta",children:[t.jsx("span",{className:"activity-status","data-status":s.status,children:t.jsx(T,{status:s.status})}),t.jsx("span",{className:"activity-priority",children:t.jsx(S,{priority:s.priority})}),t.jsx("span",{children:new Date(s.updated_at).toLocaleDateString()})]})]},s.id))})]}),t.jsxs("div",{className:"activity-secondary",children:[x.length>0&&t.jsxs("section",{className:"activity-section",children:[t.jsxs("div",{className:"activity-section-heading",children:[t.jsx("h2",{children:"Active jobs"}),t.jsx("button",{type:"button",className:"activity-text-action",onClick:()=>i("/jobs"),children:"View all"})]}),t.jsx("div",{className:"activity-row-list",children:x.slice(0,5).map(s=>t.jsxs("button",{type:"button",className:"activity-row",onClick:()=>i(`/jobs/${s.id}`),children:[t.jsxs("span",{className:"activity-row-heading",children:[t.jsx("span",{children:s.name}),t.jsx("span",{className:"activity-muted",children:s.trigger_type})]}),s.last_run_at&&t.jsxs("span",{className:"activity-row-description",children:["Last run ",new Date(s.last_run_at).toLocaleString()]})]},s.id))})]}),g.length>0&&t.jsxs("section",{className:"activity-section",children:[t.jsxs("div",{className:"activity-section-heading",children:[t.jsx("h2",{children:"Agent sessions"}),t.jsx("button",{type:"button",className:"activity-text-action",onClick:()=>i("/sessions"),children:"View all"})]}),t.jsx("div",{className:"activity-row-list",children:g.slice(0,5).map(s=>t.jsxs("div",{className:"activity-row",children:[t.jsxs("button",{type:"button",className:"w-full text-left","data-testid":"activity-session-link","data-session-id":s.id,onClick:()=>i(`/sessions?session=${encodeURIComponent(s.id)}`),children:[t.jsxs("span",{className:"activity-row-heading",children:[t.jsx("span",{children:s.name??s.agent}),t.jsx("span",{className:"activity-muted",children:F(s.last_activity_at)})]}),t.jsxs("span",{className:"activity-row-description inline-flex items-center gap-2",children:[t.jsx("span",{className:`size-1.5 rounded-full ${$[s.status].dot}`}),s.agent," · ",$[s.status].label,s.task?` · ${s.task.title}`:""]})]}),t.jsx(G,{session:s})]},s.id))})]})]}),a==="all"&&(n??[]).length>0&&t.jsxs("section",{className:"activity-section",children:[t.jsxs("div",{className:"activity-section-heading",children:[t.jsx("h2",{children:"Projects"}),t.jsx("button",{type:"button",className:"activity-text-action",onClick:()=>i("/projects"),children:"View all"})]}),t.jsx("div",{className:"activity-projects",children:(n??[]).filter(s=>s.status==="active").slice(0,6).map(s=>t.jsxs("button",{type:"button",className:"activity-row",onClick:()=>i(`/projects/${s.id}`),children:[t.jsx("span",{className:"activity-row-heading",children:s.name}),s.description&&t.jsx("span",{className:"activity-row-description",children:s.description})]},s.id))})]})]})}export{es as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as A,h as G,r as o,j as e,M as Y,B as m}from"./index-
|
|
1
|
+
import{g as A,h as G,r as o,j as e,M as Y,B as m}from"./index-BqQDBYwx.js";const i=new Map,M=new Set;typeof window<"u"&&window.addEventListener("beforeunload",t=>{i.size&&(t.preventDefault(),t.returnValue="")});function H(t){return M.has(t)?!1:i.has(t)?window.confirm("Discard unsaved changes to this document?")?(i.delete(t),!0):!1:!0}function K({documentId:t,content:s,path:D,onSave:d,testId:N,wikiLinks:C,navigation:k,expanded:R,onExpandedChange:E,layout:F,pageTitle:q,hideFrontmatter:T}){const[V]=A(),W=G(),v=V.get("editorMode"),x=v==="edit"||v==="split"?v:"read",p=o.useRef(i.get(t)??{original:s,content:s}),[w,f]=o.useState(p.current.content),[u,j]=o.useState(p.current.original),[r,z]=o.useState(!1),[y,b]=o.useState(null),S=o.useRef(!1),l=o.useRef(p.current.content),c=w!==u;o.useEffect(()=>{i.has(t)||(f(s),l.current=s,j(s))},[s,t]);function O(a){l.current=a,f(a),a===u?i.delete(t):i.set(t,{original:u,content:a})}async function h(){if(!d||!c||S.current)return;S.current=!0,M.add(t),z(!0),b(null);const a=l.current;try{const n=await d(a,u),g=typeof n=="string"?n:a;j(g),l.current===a?(i.delete(t),l.current=g,f(g)):i.set(t,{original:g,content:l.current})}catch(n){b(n instanceof Error?n.message:"Could not save document")}finally{S.current=!1,M.delete(t),z(!1)}}function P(a){const n=new URLSearchParams(window.location.search);n.set("editorMode",a),n.toString()!==new URLSearchParams(window.location.search).toString()&&W({search:n.toString(),hash:window.location.hash})}function U(){H(t)&&(f(s),j(s),l.current=s,b(null))}const B=d?r?"Saving…":c?"Unsaved changes":"Saved":"Read-only",L=e.jsxs(e.Fragment,{children:[y&&e.jsxs("p",{role:"alert",className:"text-sm text-destructive",children:[y," Your draft has been kept."]}),c&&s!==u&&e.jsx("p",{role:"status",className:"text-sm text-outline",children:"The document changed elsewhere. Your draft is preserved; saving will check for conflicts."})]});return F==="page"?e.jsx("div",{className:"min-w-0","data-testid":"document-workspace",children:e.jsx(Y,{path:D,value:w,onChange:O,onSave:()=>void h(),readOnly:!d||r,testId:N,wikiLinks:C,initialMode:"read",mode:x,onModeChange:P,expanded:R,onExpandedChange:E,layout:"page",pageTitle:q,hideFrontmatter:T,notice:y||c&&s!==u?L:void 0,actions:(x!=="read"||c||r)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{"data-testid":"document-save-status",role:"status",className:"text-xs text-outline",children:B}),d&&(c||r)&&e.jsxs(e.Fragment,{children:[e.jsx(m,{type:"button",size:"sm",variant:"ghost","data-testid":"document-discard",disabled:r,onClick:U,children:"Discard"}),e.jsx(m,{type:"button",size:"sm","data-testid":"document-save",disabled:r,onClick:()=>void h(),children:"Save"})]})]})})}):e.jsx("div",{className:"min-w-0 space-y-3","data-testid":"document-workspace",children:e.jsx(Y,{path:D,value:w,onChange:O,onSave:()=>void h(),readOnly:!d||r,testId:N,wikiLinks:C,initialMode:"read",mode:x,onModeChange:P,expanded:R,onExpandedChange:E,layout:F,header:e.jsxs("div",{className:"space-y-2",children:[k&&e.jsx("div",{className:"mb-3 min-w-0",children:k}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{"data-testid":"document-save-status",role:"status",className:"min-w-0 flex-1 text-sm text-outline",children:B}),d&&e.jsxs(e.Fragment,{children:[e.jsx(m,{type:"button",variant:"ghost","data-testid":"document-discard",disabled:!c||r,onClick:U,children:"Discard changes"}),e.jsx(m,{type:"button","data-testid":"document-save",disabled:!c||r,onClick:()=>void h(),children:"Save changes"})]})]}),L]})})})}export{K as D,H as c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as U,r as t,a as $,j as n,i as K,M as A,k as T,d as P}from"./index-
|
|
1
|
+
import{g as U,r as t,a as $,j as n,i as K,M as A,k as T,d as P}from"./index-BqQDBYwx.js";import{S as V}from"./save-ChNqW56W.js";const c=new Map;typeof window<"u"&&window.addEventListener("beforeunload",s=>{c.size!==0&&(s.preventDefault(),s.returnValue="")});function H({terminalId:s,path:i,content:u,readOnly:v,onDirty:w}){const[Q,z]=U(),p=Q.get("editorMode"),D=p==="read"||p==="split"?p:"edit",a=`${s}:${i}`,d=t.useRef(c.get(a)??{original:u,content:u}),o=t.useRef(d.current.original),l=t.useRef(d.current.content),[S,g]=t.useState(d.current.content!==d.current.original),[C,j]=t.useState(!1),[E,x]=t.useState(null),[k,b]=t.useState(d.current.content),R=$(),y=t.useRef(()=>{}),h=t.useRef(!1),m=t.useRef(!1),f=t.useRef(w);f.current=w;async function M(){if(h.current||v||l.current===o.current)return;h.current=!0,j(!0),x(null);const e=l.current;try{await P.git.saveFile(s,i,e,o.current),o.current=e;const r=l.current!==e;g(r),m.current&&f.current(r),r?c.set(a,{original:e,content:l.current}):c.delete(a),R.invalidateQueries({queryKey:["checkout-files",s,i]}),R.invalidateQueries({queryKey:["git",s]})}catch(r){x(r instanceof Error?r.message:"Could not save file")}finally{h.current=!1,j(!1)}}y.current=()=>void M(),t.useEffect(()=>(m.current=!0,f.current(d.current.content!==d.current.original),()=>{m.current=!1}),[]),t.useEffect(()=>{h.current||c.has(a)||u===o.current||(o.current=u,l.current=u,b(u),g(!1),m.current&&f.current(!1))},[u,a]);function N(e){l.current=e,b(e);const r=e!==o.current;g(r),f.current(r),r?c.set(a,{original:o.current,content:e}):c.delete(a)}function L(){window.confirm("Discard your edits and reload the file from disk?")&&P.git.files(s,i).then(e=>{if(e.content===null||e.binary||e.truncated)throw new Error("File is no longer editable");o.current=e.content,l.current=e.content,c.delete(a),b(e.content),g(!1),f.current(!1),x(null)}).catch(e=>x(e instanceof Error?e.message:"Could not reload file"))}const F=n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-surface-highest px-2 py-1",children:[n.jsxs("button",{type:"button","data-testid":"file-save",disabled:!S||C||v,onClick:()=>void M(),className:"flex min-h-11 items-center gap-1 rounded px-2 py-1 text-sm text-primary hover:bg-surface-highest disabled:opacity-40",title:"Save (Ctrl/Cmd+S)",children:[n.jsx(V,{size:14}),C?"Saving…":"Save"]}),n.jsx("span",{"data-testid":"file-save-status",className:"min-w-0 flex-1 truncate text-sm text-on-surface-variant",children:v?"Read-only preview":S?"Unsaved changes":"Saved"})]}),E&&n.jsxs("div",{role:"alert",className:"shrink-0 border-b border-error/30 p-2 text-xs text-error",children:[E,n.jsx("button",{type:"button","data-testid":"file-reload",onClick:L,className:"ml-2 underline",children:"Reload from disk"})]})]});return n.jsxs("div",{className:"flex min-h-0 flex-1 flex-col","data-testid":"file-editor",children:[!K(i)&&F,n.jsx("div",{"data-testid":"file-preview",className:"min-h-0 flex-1 overflow-hidden",children:K(i)?n.jsx(A,{path:i,value:k,onChange:N,onSave:()=>y.current(),readOnly:v,height:"100%",testId:"file-editor-input",header:F,mode:D,onModeChange:e=>z(r=>{const q=new URLSearchParams(r);return q.set("editorMode",e),q})}):n.jsx(T,{path:i,value:k,onChange:N,onSave:()=>y.current(),readOnly:v,height:"100%",testId:"file-editor-input"})})]})}export{H as FileEditor};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as S,a as f,b as v,d as j,r as h,j as e,B as b,Y as w,Z as _,L as k,E as R,a9 as F}from"./index-CRsafixF.js";import{a as $}from"./useJobs-C4BQQWOR.js";function L(t){return S({queryKey:["webhooks",t],queryFn:()=>j.webhooks.list(t),select:s=>s.webhooks})}function D(t){return S({queryKey:["webhook-deliveries",t],queryFn:()=>j.webhooks.deliveries(t),select:s=>s.deliveries,enabled:!!t,refetchInterval:3e3})}function U(){const t=f();return v({mutationFn:s=>j.webhooks.create(s),onSuccess:()=>t.invalidateQueries({queryKey:["webhooks"]})})}function E(){const t=f();return v({mutationFn:({id:s,...a})=>j.webhooks.update(s,a),onSuccess:()=>t.invalidateQueries({queryKey:["webhooks"]})})}function G(){const t=f();return v({mutationFn:s=>j.webhooks.delete(s),onSuccess:()=>t.invalidateQueries({queryKey:["webhooks"]})})}function P(){return v({mutationFn:t=>j.webhooks.rotate(t)})}function q(t){return[...new Set(t.split(",").map(s=>s.trim()).filter(Boolean))]}function I(t,s,a){return new URL(`/webhooks/${encodeURIComponent(t)}`,new URL(s,a)).href}function z(t){return["localhost","127.0.0.1","[::1]"].includes(new URL(t).hostname)}function N({id:t,testId:s,value:a,onChange:i,placeholder:d}){const[n,r]=h.useState(a.join(", "));return e.jsx(_,{id:t,"data-testid":s,value:n,placeholder:d,onChange:l=>{r(l.target.value),i(l.target.value)}})}function J({projectId:t,onCreated:s}){const a=U(),[i,d]=h.useState(""),[n,r]=h.useState("github"),[l,m]=h.useState(null),u=h.useId();return l?e.jsxs("div",{"data-testid":"webhook-created",className:"space-y-3",children:[e.jsx(W,{hook:l,secret:l.secret}),e.jsx(b,{type:"button",variant:"outline","data-testid":"webhook-setup-done",onClick:()=>{s==null||s(l),m(null),d("")},children:"I've copied the setup details"})]}):e.jsxs("div",{className:"space-y-3","data-testid":"webhook-create-form",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(w,{htmlFor:`${u}-name`,children:"Webhook name"}),e.jsx(_,{id:`${u}-name`,"data-testid":"webhook-name",value:i,onChange:c=>d(c.target.value),maxLength:100,placeholder:"GitHub repository events"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(w,{htmlFor:`${u}-provider`,children:"Provider"}),e.jsxs("select",{id:`${u}-provider`,"data-testid":"webhook-provider",className:"w-full min-h-11 rounded-md border border-control-border bg-background px-3 text-sm",value:n,onChange:c=>r(c.target.value),children:[e.jsx("option",{value:"github",children:"GitHub"}),e.jsx("option",{value:"generic",children:"Other service (HMAC)"})]})]}),e.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."}),a.error&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:a.error.message}),e.jsx(b,{type:"button","data-testid":"webhook-create",disabled:!i.trim()||a.isPending,onClick:()=>a.mutate({name:i.trim(),provider:n,project_id:t??null},{onSuccess:m}),children:a.isPending?"Creating...":"Create webhook"})]})}function A({value:t,onChange:s,projectId:a}){const{data:i,error:d,isLoading:n,refetch:r}=L(a),l=i==null?void 0:i.filter(o=>o.project_id===null||o.project_id===a),[m,u]=h.useState(!1);function c(o){t.some(p=>p.webhook_id===o)||s([...t,{webhook_id:o,events:[],actions:[]}])}function y(o,p,x){s(t.map(g=>g.webhook_id===o?{...g,[p]:q(x)}:g))}return e.jsxs("section",{className:"space-y-3 border-y border-border py-4","data-testid":"job-webhook-picker",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Which webhook should trigger this job?"}),d?e.jsx(R,{message:d.message,onRetry:()=>r()}):e.jsxs(e.Fragment,{children:[e.jsx(w,{htmlFor:"job-webhook-source",children:"Configured webhooks"}),e.jsxs("select",{id:"job-webhook-source","data-testid":"job-webhook-select",className:"w-full min-h-11 rounded-md border border-control-border bg-background px-3 text-sm",value:"",disabled:n,onChange:o=>{o.target.value&&c(o.target.value)},children:[e.jsx("option",{value:"",children:n?"Loading webhooks...":"Select an existing webhook"}),(l??[]).filter(o=>!t.some(p=>p.webhook_id===o.id)).map(o=>e.jsxs("option",{value:o.id,children:[o.name,o.enabled?"":" (disabled)"]},o.id))]}),!n&&!(l!=null&&l.length)&&e.jsx("p",{className:"text-xs text-outline",children:"No webhooks configured for this project yet. Create one below or on the Webhooks page."})]}),t.map(o=>{var p;return e.jsxs("div",{className:"space-y-2 border-t border-border pt-3","data-testid":"job-webhook-binding","data-webhook-id":o.webhook_id,children:[e.jsxs("div",{className:"flex justify-between gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:((p=l==null?void 0:l.find(x=>x.id===o.webhook_id))==null?void 0:p.name)??o.webhook_id}),e.jsx(b,{type:"button",variant:"ghost",size:"sm","data-testid":"job-webhook-remove",onClick:()=>s(t.filter(x=>x.webhook_id!==o.webhook_id)),children:"Disconnect"})]}),e.jsx(w,{htmlFor:`events-${o.webhook_id}`,children:"Events for this job"}),e.jsx(N,{id:`events-${o.webhook_id}`,testId:"webhook-events",value:o.events,onChange:x=>y(o.webhook_id,"events",x),placeholder:"pull_request, push (blank accepts all)"}),e.jsx(w,{htmlFor:`actions-${o.webhook_id}`,children:"Actions for this job (optional)"}),e.jsx(N,{id:`actions-${o.webhook_id}`,testId:"webhook-actions",value:o.actions,onChange:x=>y(o.webhook_id,"actions",x),placeholder:"opened, synchronize (blank accepts all)"})]},o.webhook_id)}),e.jsx(b,{type:"button",size:"sm",variant:"outline","data-testid":"webhook-add",onClick:()=>u(!m),children:m?"Close new webhook":"Create a webhook"}),m&&e.jsx(J,{projectId:a,onCreated:o=>{c(o.id),u(!1)}})]})}function K({job:t}){const s=$(),[a,i]=h.useState(t.webhooks??[]);return e.jsxs("section",{className:"space-y-3","data-testid":"job-webhooks",children:[!t.enabled&&e.jsx("p",{className:"text-sm text-outline",children:"Job disabled. Configure connections now and enable it from Jobs when ready."}),e.jsx(A,{value:a,onChange:i,projectId:t.project_id??void 0}),s.error&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:s.error.message}),e.jsx(b,{type:"button",size:"sm","data-testid":"job-webhooks-save",disabled:s.isPending,onClick:()=>s.mutate({id:t.id,webhooks:a,trigger_type:"webhook"}),children:"Save connections"}),s.isSuccess&&e.jsx("p",{role:"status",className:"text-xs text-outline",children:"Connections saved."}),e.jsx(k,{className:"inline-block text-sm underline",to:`/webhooks?project=${encodeURIComponent(t.project_id??"all")}`,children:"Manage configured webhooks and deliveries"})]})}function C({label:t,value:s,secret:a=!1}){const[i,d]=h.useState(!1),[n,r]=h.useState(!1);return e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-outline",children:t}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("code",{className:"min-w-0 flex-1 break-all text-xs","data-testid":a?"webhook-secret":"webhook-url",children:s}),e.jsx(b,{type:"button",size:"sm",variant:"outline","aria-label":`Copy ${t}`,onClick:async()=>{try{await navigator.clipboard.writeText(s),d(!0),r(!1)}catch{r(!0)}},children:i?"Copied":"Copy"})]}),n&&e.jsx("p",{role:"alert",className:"text-xs text-error",children:"Select and copy the value above; clipboard access is unavailable."})]})}function W({hook:t,secret:s}){const a=I(t.token,F(),window.location.origin);return e.jsxs("div",{className:"space-y-3","data-testid":"webhook-setup",children:[e.jsx(C,{label:"Payload URL",value:a}),z(a)&&e.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."}),s?e.jsxs(e.Fragment,{children:[e.jsx(C,{label:"Signing secret",value:s,secret:!0}),e.jsx("p",{className:"text-xs text-outline",children:"Copy the signing secret before leaving. It is shown once."})]}):e.jsx("p",{className:"text-xs text-outline",children:"The signing secret is hidden. Generate a replacement only if you need to reconnect the sender."}),t.provider==="github"?e.jsxs("ol",{className:"list-decimal space-y-1 pl-5 text-sm text-outline",children:[e.jsx("li",{children:"In your repository, open GitHub Settings - Webhooks - Add webhook."}),e.jsx("li",{children:"Paste the Payload URL, select application/json, and enter the signing secret."}),e.jsx("li",{children:"Select the events needed by your connected jobs. Each job has its own filters."}),e.jsx("li",{children:"Send an event and inspect Recent deliveries below."})]}):e.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 Q({hook:t}){var u;const s=E(),a=P(),[i,d]=h.useState(!1),[n,r]=h.useState(!1),[l,m]=h.useState();return e.jsxs("article",{className:"space-y-3 border-b border-border pb-5","data-testid":"webhook-endpoint","data-webhook-id":t.id,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:t.name}),e.jsxs("span",{className:"text-xs text-outline",children:[t.provider," - ",t.enabled?"Enabled":"Disabled"]}),e.jsx(b,{type:"button",variant:"outline",size:"sm",disabled:s.isPending,onClick:()=>s.mutate({id:t.id,enabled:!t.enabled}),children:t.enabled?"Disable":"Enable"})]}),e.jsxs("div",{className:"space-y-1","data-testid":"webhook-connected-jobs",children:[e.jsxs("p",{className:"text-xs text-outline",children:["Connected jobs (",t.subscriptions.length,")"]}),t.subscriptions.length?t.subscriptions.map(c=>e.jsxs("div",{className:"text-sm",children:[e.jsx(k,{className:"underline","data-testid":"webhook-job-link",to:`/jobs/${c.job_id}?project=all`,children:c.name}),e.jsxs("span",{className:"text-xs text-outline",children:[" ","- ",c.enabled?"Enabled":"Disabled","; events:"," ",c.events.join(", ")||"all","; actions: ",c.actions.join(", ")||"all"]})]},c.job_id)):e.jsx("p",{className:"text-sm text-outline",children:"No connected jobs. Select this webhook when creating or editing a job."})]}),e.jsx(W,{hook:t,secret:l}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(b,{type:"button",variant:"outline",size:"sm","data-testid":"webhook-deliveries-toggle",onClick:()=>d(!i),children:i?"Hide deliveries":"Recent deliveries"}),e.jsx(b,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!n),children:"New signing secret"})]}),n&&e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsx("p",{children:"The sender's existing secret will stop working. Update it after generating the replacement."}),e.jsx(b,{type:"button",variant:"outline",size:"sm",disabled:a.isPending,onClick:()=>a.mutate(t.id,{onSuccess:c=>{m(c.secret),r(!1)}}),children:"Generate replacement secret"})]}),(s.error||a.error)&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:(u=s.error??a.error)==null?void 0:u.message}),i&&e.jsx(H,{id:t.id})]})}function H({id:t}){const{data:s,isLoading:a,error:i,refetch:d}=D(t);return e.jsxs("section",{className:"space-y-2","data-testid":"webhook-deliveries",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Recent deliveries"}),i?e.jsx(R,{message:i.message,onRetry:()=>d()}):a?e.jsx("p",{role:"status",children:"Loading deliveries..."}):s!=null&&s.length?s.map(n=>e.jsxs("div",{className:"space-y-1 border-t border-border py-2 text-xs","data-testid":"webhook-delivery",children:[e.jsxs("div",{className:"flex flex-wrap justify-between gap-2",children:[e.jsxs("span",{children:[n.event,n.action?` / ${n.action}`:""]}),e.jsx("span",{children:n.status})]}),e.jsxs("p",{className:"text-outline",children:[n.repository," ",new Date(n.created_at).toLocaleString()]}),n.status==="ignored"&&e.jsx("p",{className:"text-outline",children:"No enabled connected job matched this event."}),n.error&&e.jsx("p",{className:"text-error",children:n.error}),n.runs.map(r=>e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsxs(k,{className:"underline",to:`/jobs/${r.job_id}?project=all`,children:["Job run: ",r.status]}),r.task_id&&e.jsx(k,{className:"underline",to:`/tasks/${r.task_id}?project=all`,children:"Created task"}),r.session_id&&e.jsx(k,{className:"underline",to:`/audit/${r.session_id}?project=all`,children:"Agent session"})]},r.job_run_id))]},n.id)):e.jsx("p",{className:"text-sm text-outline",children:"No events received yet. Register the endpoint with your provider, then send an event."})]})}export{K as J,J as W,G as a,Q as b,A as c,L as u};
|
|
1
|
+
import{u as S,a as f,b as v,d as j,r as h,j as e,B as b,Y as w,Z as _,L as k,E as R,a9 as F}from"./index-BqQDBYwx.js";import{a as $}from"./useJobs-By4K4BjX.js";function L(t){return S({queryKey:["webhooks",t],queryFn:()=>j.webhooks.list(t),select:s=>s.webhooks})}function D(t){return S({queryKey:["webhook-deliveries",t],queryFn:()=>j.webhooks.deliveries(t),select:s=>s.deliveries,enabled:!!t,refetchInterval:3e3})}function U(){const t=f();return v({mutationFn:s=>j.webhooks.create(s),onSuccess:()=>t.invalidateQueries({queryKey:["webhooks"]})})}function E(){const t=f();return v({mutationFn:({id:s,...a})=>j.webhooks.update(s,a),onSuccess:()=>t.invalidateQueries({queryKey:["webhooks"]})})}function G(){const t=f();return v({mutationFn:s=>j.webhooks.delete(s),onSuccess:()=>t.invalidateQueries({queryKey:["webhooks"]})})}function P(){return v({mutationFn:t=>j.webhooks.rotate(t)})}function q(t){return[...new Set(t.split(",").map(s=>s.trim()).filter(Boolean))]}function I(t,s,a){return new URL(`/webhooks/${encodeURIComponent(t)}`,new URL(s,a)).href}function z(t){return["localhost","127.0.0.1","[::1]"].includes(new URL(t).hostname)}function N({id:t,testId:s,value:a,onChange:i,placeholder:d}){const[n,r]=h.useState(a.join(", "));return e.jsx(_,{id:t,"data-testid":s,value:n,placeholder:d,onChange:l=>{r(l.target.value),i(l.target.value)}})}function J({projectId:t,onCreated:s}){const a=U(),[i,d]=h.useState(""),[n,r]=h.useState("github"),[l,m]=h.useState(null),u=h.useId();return l?e.jsxs("div",{"data-testid":"webhook-created",className:"space-y-3",children:[e.jsx(W,{hook:l,secret:l.secret}),e.jsx(b,{type:"button",variant:"outline","data-testid":"webhook-setup-done",onClick:()=>{s==null||s(l),m(null),d("")},children:"I've copied the setup details"})]}):e.jsxs("div",{className:"space-y-3","data-testid":"webhook-create-form",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(w,{htmlFor:`${u}-name`,children:"Webhook name"}),e.jsx(_,{id:`${u}-name`,"data-testid":"webhook-name",value:i,onChange:c=>d(c.target.value),maxLength:100,placeholder:"GitHub repository events"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(w,{htmlFor:`${u}-provider`,children:"Provider"}),e.jsxs("select",{id:`${u}-provider`,"data-testid":"webhook-provider",className:"w-full min-h-11 rounded-md border border-control-border bg-background px-3 text-sm",value:n,onChange:c=>r(c.target.value),children:[e.jsx("option",{value:"github",children:"GitHub"}),e.jsx("option",{value:"generic",children:"Other service (HMAC)"})]})]}),e.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."}),a.error&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:a.error.message}),e.jsx(b,{type:"button","data-testid":"webhook-create",disabled:!i.trim()||a.isPending,onClick:()=>a.mutate({name:i.trim(),provider:n,project_id:t??null},{onSuccess:m}),children:a.isPending?"Creating...":"Create webhook"})]})}function A({value:t,onChange:s,projectId:a}){const{data:i,error:d,isLoading:n,refetch:r}=L(a),l=i==null?void 0:i.filter(o=>o.project_id===null||o.project_id===a),[m,u]=h.useState(!1);function c(o){t.some(p=>p.webhook_id===o)||s([...t,{webhook_id:o,events:[],actions:[]}])}function y(o,p,x){s(t.map(g=>g.webhook_id===o?{...g,[p]:q(x)}:g))}return e.jsxs("section",{className:"space-y-3 border-y border-border py-4","data-testid":"job-webhook-picker",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Which webhook should trigger this job?"}),d?e.jsx(R,{message:d.message,onRetry:()=>r()}):e.jsxs(e.Fragment,{children:[e.jsx(w,{htmlFor:"job-webhook-source",children:"Configured webhooks"}),e.jsxs("select",{id:"job-webhook-source","data-testid":"job-webhook-select",className:"w-full min-h-11 rounded-md border border-control-border bg-background px-3 text-sm",value:"",disabled:n,onChange:o=>{o.target.value&&c(o.target.value)},children:[e.jsx("option",{value:"",children:n?"Loading webhooks...":"Select an existing webhook"}),(l??[]).filter(o=>!t.some(p=>p.webhook_id===o.id)).map(o=>e.jsxs("option",{value:o.id,children:[o.name,o.enabled?"":" (disabled)"]},o.id))]}),!n&&!(l!=null&&l.length)&&e.jsx("p",{className:"text-xs text-outline",children:"No webhooks configured for this project yet. Create one below or on the Webhooks page."})]}),t.map(o=>{var p;return e.jsxs("div",{className:"space-y-2 border-t border-border pt-3","data-testid":"job-webhook-binding","data-webhook-id":o.webhook_id,children:[e.jsxs("div",{className:"flex justify-between gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:((p=l==null?void 0:l.find(x=>x.id===o.webhook_id))==null?void 0:p.name)??o.webhook_id}),e.jsx(b,{type:"button",variant:"ghost",size:"sm","data-testid":"job-webhook-remove",onClick:()=>s(t.filter(x=>x.webhook_id!==o.webhook_id)),children:"Disconnect"})]}),e.jsx(w,{htmlFor:`events-${o.webhook_id}`,children:"Events for this job"}),e.jsx(N,{id:`events-${o.webhook_id}`,testId:"webhook-events",value:o.events,onChange:x=>y(o.webhook_id,"events",x),placeholder:"pull_request, push (blank accepts all)"}),e.jsx(w,{htmlFor:`actions-${o.webhook_id}`,children:"Actions for this job (optional)"}),e.jsx(N,{id:`actions-${o.webhook_id}`,testId:"webhook-actions",value:o.actions,onChange:x=>y(o.webhook_id,"actions",x),placeholder:"opened, synchronize (blank accepts all)"})]},o.webhook_id)}),e.jsx(b,{type:"button",size:"sm",variant:"outline","data-testid":"webhook-add",onClick:()=>u(!m),children:m?"Close new webhook":"Create a webhook"}),m&&e.jsx(J,{projectId:a,onCreated:o=>{c(o.id),u(!1)}})]})}function K({job:t}){const s=$(),[a,i]=h.useState(t.webhooks??[]);return e.jsxs("section",{className:"space-y-3","data-testid":"job-webhooks",children:[!t.enabled&&e.jsx("p",{className:"text-sm text-outline",children:"Job disabled. Configure connections now and enable it from Jobs when ready."}),e.jsx(A,{value:a,onChange:i,projectId:t.project_id??void 0}),s.error&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:s.error.message}),e.jsx(b,{type:"button",size:"sm","data-testid":"job-webhooks-save",disabled:s.isPending,onClick:()=>s.mutate({id:t.id,webhooks:a,trigger_type:"webhook"}),children:"Save connections"}),s.isSuccess&&e.jsx("p",{role:"status",className:"text-xs text-outline",children:"Connections saved."}),e.jsx(k,{className:"inline-block text-sm underline",to:`/webhooks?project=${encodeURIComponent(t.project_id??"all")}`,children:"Manage configured webhooks and deliveries"})]})}function C({label:t,value:s,secret:a=!1}){const[i,d]=h.useState(!1),[n,r]=h.useState(!1);return e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-outline",children:t}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("code",{className:"min-w-0 flex-1 break-all text-xs","data-testid":a?"webhook-secret":"webhook-url",children:s}),e.jsx(b,{type:"button",size:"sm",variant:"outline","aria-label":`Copy ${t}`,onClick:async()=>{try{await navigator.clipboard.writeText(s),d(!0),r(!1)}catch{r(!0)}},children:i?"Copied":"Copy"})]}),n&&e.jsx("p",{role:"alert",className:"text-xs text-error",children:"Select and copy the value above; clipboard access is unavailable."})]})}function W({hook:t,secret:s}){const a=I(t.token,F(),window.location.origin);return e.jsxs("div",{className:"space-y-3","data-testid":"webhook-setup",children:[e.jsx(C,{label:"Payload URL",value:a}),z(a)&&e.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."}),s?e.jsxs(e.Fragment,{children:[e.jsx(C,{label:"Signing secret",value:s,secret:!0}),e.jsx("p",{className:"text-xs text-outline",children:"Copy the signing secret before leaving. It is shown once."})]}):e.jsx("p",{className:"text-xs text-outline",children:"The signing secret is hidden. Generate a replacement only if you need to reconnect the sender."}),t.provider==="github"?e.jsxs("ol",{className:"list-decimal space-y-1 pl-5 text-sm text-outline",children:[e.jsx("li",{children:"In your repository, open GitHub Settings - Webhooks - Add webhook."}),e.jsx("li",{children:"Paste the Payload URL, select application/json, and enter the signing secret."}),e.jsx("li",{children:"Select the events needed by your connected jobs. Each job has its own filters."}),e.jsx("li",{children:"Send an event and inspect Recent deliveries below."})]}):e.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 Q({hook:t}){var u;const s=E(),a=P(),[i,d]=h.useState(!1),[n,r]=h.useState(!1),[l,m]=h.useState();return e.jsxs("article",{className:"space-y-3 border-b border-border pb-5","data-testid":"webhook-endpoint","data-webhook-id":t.id,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:t.name}),e.jsxs("span",{className:"text-xs text-outline",children:[t.provider," - ",t.enabled?"Enabled":"Disabled"]}),e.jsx(b,{type:"button",variant:"outline",size:"sm",disabled:s.isPending,onClick:()=>s.mutate({id:t.id,enabled:!t.enabled}),children:t.enabled?"Disable":"Enable"})]}),e.jsxs("div",{className:"space-y-1","data-testid":"webhook-connected-jobs",children:[e.jsxs("p",{className:"text-xs text-outline",children:["Connected jobs (",t.subscriptions.length,")"]}),t.subscriptions.length?t.subscriptions.map(c=>e.jsxs("div",{className:"text-sm",children:[e.jsx(k,{className:"underline","data-testid":"webhook-job-link",to:`/jobs/${c.job_id}?project=all`,children:c.name}),e.jsxs("span",{className:"text-xs text-outline",children:[" ","- ",c.enabled?"Enabled":"Disabled","; events:"," ",c.events.join(", ")||"all","; actions: ",c.actions.join(", ")||"all"]})]},c.job_id)):e.jsx("p",{className:"text-sm text-outline",children:"No connected jobs. Select this webhook when creating or editing a job."})]}),e.jsx(W,{hook:t,secret:l}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(b,{type:"button",variant:"outline",size:"sm","data-testid":"webhook-deliveries-toggle",onClick:()=>d(!i),children:i?"Hide deliveries":"Recent deliveries"}),e.jsx(b,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!n),children:"New signing secret"})]}),n&&e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsx("p",{children:"The sender's existing secret will stop working. Update it after generating the replacement."}),e.jsx(b,{type:"button",variant:"outline",size:"sm",disabled:a.isPending,onClick:()=>a.mutate(t.id,{onSuccess:c=>{m(c.secret),r(!1)}}),children:"Generate replacement secret"})]}),(s.error||a.error)&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:(u=s.error??a.error)==null?void 0:u.message}),i&&e.jsx(H,{id:t.id})]})}function H({id:t}){const{data:s,isLoading:a,error:i,refetch:d}=D(t);return e.jsxs("section",{className:"space-y-2","data-testid":"webhook-deliveries",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Recent deliveries"}),i?e.jsx(R,{message:i.message,onRetry:()=>d()}):a?e.jsx("p",{role:"status",children:"Loading deliveries..."}):s!=null&&s.length?s.map(n=>e.jsxs("div",{className:"space-y-1 border-t border-border py-2 text-xs","data-testid":"webhook-delivery",children:[e.jsxs("div",{className:"flex flex-wrap justify-between gap-2",children:[e.jsxs("span",{children:[n.event,n.action?` / ${n.action}`:""]}),e.jsx("span",{children:n.status})]}),e.jsxs("p",{className:"text-outline",children:[n.repository," ",new Date(n.created_at).toLocaleString()]}),n.status==="ignored"&&e.jsx("p",{className:"text-outline",children:"No enabled connected job matched this event."}),n.error&&e.jsx("p",{className:"text-error",children:n.error}),n.runs.map(r=>e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsxs(k,{className:"underline",to:`/jobs/${r.job_id}?project=all`,children:["Job run: ",r.status]}),r.task_id&&e.jsx(k,{className:"underline",to:`/tasks/${r.task_id}?project=all`,children:"Created task"}),r.session_id&&e.jsx(k,{className:"underline",to:`/audit/${r.session_id}?project=all`,children:"Agent session"})]},r.job_run_id))]},n.id)):e.jsx("p",{className:"text-sm text-outline",children:"No events received yet. Register the endpoint with your provider, then send an event."})]})}export{K as J,J as W,G as a,Q as b,A as c,L as u};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as ae,r as o,ag as ge,j as e,Y as d,ah as G,Z as f,a2 as pe,a3 as je,a4 as fe,a5 as Ne,a6 as ye,E as H,S as U,ac as P,ai as ve,B as g,ad as ke,f as _e,q as we,L as Q,l as Se,aj as Ce,a0 as De,V as ee,ak as Te,al as $e,af as Pe,am as te,T as Ee,s as Re,t as se,v as L,w as Je,x as O,a7 as ze,n as Ie,a8 as ne,U as re,W as le,X as ie,an as V,ao as q,ap as M,aq as W,ar as B,as as oe}from"./index-
|
|
1
|
+
import{c as ae,r as o,ag as ge,j as e,Y as d,ah as G,Z as f,a2 as pe,a3 as je,a4 as fe,a5 as Ne,a6 as ye,E as H,S as U,ac as P,ai as ve,B as g,ad as ke,f as _e,q as we,L as Q,l as Se,aj as Ce,a0 as De,V as ee,ak as Te,al as $e,af as Pe,am as te,T as Ee,s as Re,t as se,v as L,w as Je,x as O,a7 as ze,n as Ie,a8 as ne,U as re,W as le,X as ie,an as V,ao as q,ap as M,aq as W,ar as B,as as oe}from"./index-BqQDBYwx.js";import{J as Le,c as de}from"./JobWebhooks-CYE2UA0V.js";import{S as Oe}from"./scroll-area-YSA2ORI8.js";import{b as Ae,c as Fe,d as ce,a as K,e as Be,u as Ve,f as qe,g as Me,h as We}from"./useJobs-By4K4BjX.js";import{P as X}from"./pencil-ClEwbF1x.js";import{u as He}from"./useProjectScope-BvcpSOql.js";/**
|
|
2
2
|
* @license lucide-react v1.27.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import{c as ve,bO as _,bJ as q,bL as re,bI as O,bQ as W,bS as tt,bN as Oe,bK as _t,bP as ps,bM as fs,bT as gs,j as e,Q as B,r as m,f as Ee,B as y,L as St,d as M,ch as Pe,n as ke,Z as U,ah as xe,an as he,ao as pe,ap as fe,aq as ge,ar as J,as as le,am as Re,a7 as ze,aG as Ct,ci as Ge,M as Dt,a8 as $t,U as Et,W as Pt,X as Rt,Y as ie,ag as bs,cj as st,ck as js,a as ys,cl as vs,g as zt,l as Lt,cm as ks,cn as Ns,co as ws,cp as _s,cq as at,a2 as Mt,a3 as Tt,a4 as At,a5 as Ft,a6 as It,ak as $e,cr as Ss,aD as Cs,cs as Ds,h as $s,_ as Kt,b$ as Es,$ as Ae,V as Ps,aC as Bt,af as nt,E as Qe,S as Ye,T as Rs,s as zs,t as it,v as de,w as Ls,x as ce,ct as Ms,p as Ts,ac as ue,cu as rt,cv as Ce,cw as Ut,cx as As,cy as Fs,cz as Is,cA as Ks,cB as Bs,cC as Us,cD as Os,cE as qs}from"./index-BqQDBYwx.js";import{D as Hs,c as Ws}from"./DocumentWorkspace-BI4JWVsO.js";import{d as Vs,c as V,e as Gs,f as Le,a as Ot,g as Qs,K as Ys,h as Js,i as qt,j as Xs,k as Zs,l as ea,m as ta,n as sa,o as aa,p as na,b as ia}from"./useKnowledge-DMSoPz-b.js";import{U as Ht}from"./upload-waJ36Q68.js";import{w as ra}from"./wiki-links-Y6CQL1QZ.js";import{E as la,F as oa,A as da}from"./folder-open-Bcqha5Pu.js";import{P as Wt}from"./pencil-ClEwbF1x.js";import{D as ca}from"./download-CK_EusLu.js";import{R as ua}from"./refresh-cw-BGtNOi70.js";import{u as ma}from"./useProjectScope-BvcpSOql.js";import{a as xa,u as ha,b as pa,c as fa,d as ga,e as ba,f as ja,g as ya}from"./useMemories-bv4XvbzQ.js";/**
|
|
2
|
+
* @license lucide-react v1.27.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const va=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M12 18v-6",key:"17g6i2"}],["path",{d:"m9 15 3 3 3-3",key:"1npd3o"}]],ka=ve("file-down",va);/**
|
|
7
|
+
* @license lucide-react v1.27.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const Na=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M9 15h6",key:"cctwl0"}],["path",{d:"M12 18v-6",key:"17g6i2"}]],wa=ve("file-plus",Na);/**
|
|
12
|
+
* @license lucide-react v1.27.0 - ISC
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the ISC license.
|
|
15
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/const _a=[["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"}]],Sa=ve("file-up",_a);/**
|
|
17
|
+
* @license lucide-react v1.27.0 - ISC
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the ISC license.
|
|
20
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
+
*/const Ca=[["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"}]],Vt=ve("folder-sync",Ca);/**
|
|
22
|
+
* @license lucide-react v1.27.0 - ISC
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the ISC license.
|
|
25
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/const Da=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}]],$a=ve("panel-right",Da),se=["mcp","api","cli","ui"],lt=["fetch","cited","search_hit"],Gt=_().trim().min(1).max(120),Qt=q(re(se)).max(se.length).transform(t=>se.filter(s=>t.includes(s)));O({name:Gt,description:_().trim().max(2e3).default(""),project_id:_().min(1).nullable(),editable_by:Qt.default([...se]),parser:_().min(1).max(40).nullable().default(null)}).strict();O({name:Gt.optional(),description:_().trim().max(2e3).optional(),editable_by:Qt.optional(),parser:_().min(1).max(40).nullable().optional()}).strict();const Ea=["default","project","global","all"],Yt=_().trim().min(1).max(500).refine(t=>!t.startsWith("/")&&!t.includes("\\")&&!t.includes(":")&&!t.includes("\0")&&t.split("/").every(s=>s&&s!=="."&&s!==".."),"Use a relative path with / separators and no . or .. segments"),Jt=q(_().trim().min(1).max(60)).max(30),ye=2*1024*1024;O({title:_().trim().min(1).max(300),path:Yt.optional(),description:_().trim().max(2e3).optional(),labels:Jt.default([]),content:_().max(ye),note:_().trim().max(1e3).optional(),derived_from:q(_().min(1)).max(50).default([])}).strict();O({expected_revision:W().int().min(1),title:_().trim().min(1).max(300).optional(),path:Yt.optional(),description:_().trim().max(2e3).optional(),labels:Jt.optional(),content:_().max(ye).optional(),note:_().trim().max(1e3).optional(),derived_from:q(_().min(1)).max(50).optional()}).strict();const Pa=1,Ra=["heading","paragraph","list_item","table","code"],za=O({kind:re(Ra),text:_(),level:W().int().min(1).max(6).optional(),rows:q(q(_())).optional(),heading_path:q(_()),locator:O({page:W().int().min(1).optional(),sheet:_().optional(),bbox:q(W()).length(4).optional()}).optional()});O({schema_version:Oe(Pa),parser:O({id:_(),version:_(),options:tt(_(),gs())}),source_sha256:_().regex(/^[0-9a-f]{64}$/),status:re(["ok","partial","failed"]),language:_().optional(),blocks:q(za),markdown:_(),warnings:q(_()),timings_ms:tt(_(),W()).optional(),peak_rss_mb:W().optional()});const Xt=["auto","lexical","semantic","hybrid"],La=O({query:_().trim().min(1).max(2e3),scope:re(Ea).default("default"),kb_ids:q(_().min(1)).max(50).optional(),labels:q(_().min(1)).max(20).optional(),media_types:q(_().min(1)).max(20).optional(),mode:re(Xt).default("auto"),limit:W().int().min(1).max(50).default(10)}).strict();La.omit({limit:!0,mode:!0}).extend({mode:re(Xt).default("auto"),token_budget:W().int().min(500).max(32e3).default(6e3),max_per_document:W().int().min(1).max(10).default(3)}).strict();const Ma=O({old:_().min(1).max(ye),new:_().max(ye),replace_all:_t().optional()}).strict(),Ta=O({start_line:W().int().min(1),end_line:W().int().min(0),new:_().max(ye)}).strict();O({expected_revision:W().int().min(1),edits:q(ps([Ma,Ta])).min(1).max(50),note:_().trim().min(1).max(1e3)}).strict();const Aa=["open","resolved","dismissed"];O({document_id:_().min(1).nullable().optional(),body:_().trim().min(1).max(1e4)}).strict();O({status:re(["resolved","dismissed"]),reply:_().trim().min(1).max(4e3)}).strict();const Fa=fs("type",[O({type:Oe("cron"),cron:_().trim().min(1).max(120)}).strict(),O({type:Oe("manual")}).strict()]);O({instructions:_().trim().min(1).max(2e4).optional(),backend:_().min(1).max(64).regex(/^[a-z][a-z0-9_-]*$/).optional(),schedule:Fa.optional(),enabled:_t().optional(),timeout_secs:W().int().min(60).max(7200).optional()}).strict();const Zt="0 3 * * *";function Ne({title:t,testId:s,toggleTestId:n,summary:a,actions:i,expanded:l=!1,onExpandedChange:r,heading:o="h3",compact:d=!1,children:p}){const c=m.useId(),x=p!==void 0&&r!==void 0;return e.jsxs("section",{"data-testid":s,"data-expanded":x?l:void 0,"aria-labelledby":`${c}-heading`,className:"min-w-0 text-sm",children:[e.jsxs("div",{className:B("grid min-h-12 min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-0.5 py-1.5",!d&&"sm:grid-cols-[9rem_minmax(0,1fr)_auto]"),children:[e.jsx(o,{id:`${c}-heading`,className:"min-w-0 font-medium",children:x?e.jsxs("button",{type:"button","data-testid":n,"aria-expanded":l,"aria-controls":c,className:"-ml-1 flex min-h-9 items-center gap-1.5 rounded px-1 text-left hover:bg-surface-high",onClick:()=>r(!l),children:[e.jsx(Ee,{size:14,"aria-hidden":!0,className:B("shrink-0 text-outline transition-transform",l&&"rotate-90")}),t]}):e.jsx("span",{className:"flex min-h-9 items-center pl-5",children:t})}),e.jsx("div",{className:B("col-span-2 row-start-2 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 pl-5",!d&&"sm:col-span-1 sm:col-start-2 sm:row-start-1 sm:pl-0"),children:a}),e.jsx("div",{className:B("col-start-2 row-start-1 flex items-center justify-end gap-1",!d&&"sm:col-start-3"),children:i})]}),x&&l&&e.jsx("div",{id:c,className:"min-w-0 pb-4 pl-5 pt-1",children:p})]})}function ae({tone:t}){return e.jsx("span",{"aria-hidden":!0,className:B("size-1.5 shrink-0 rounded-full",t==="ok"&&"bg-secondary",t==="warning"&&"bg-warning",t==="error"&&"bg-error",t==="off"&&"bg-muted-foreground",t==="progress"&&"bg-progress")})}const Me=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],De=/^\d+$/,me=t=>t.padStart(2,"0"),ot=t=>{var s;return(s=/^\*\/(\d+)$/.exec(t))==null?void 0:s[1]},dt=(t,s)=>t==="1"?`Every ${s}`:`Every ${t} ${s}s`;function es(t){const[s="",n="",a,i,l="",...r]=t.trim().split(/\s+/);if(r.length||a!=="*"||i!=="*")return t;if(n==="*"&&l==="*"){if(s==="*")return"Every minute";const p=ot(s);return p?dt(p,"minute"):De.test(s)?Number(s)?`Every hour at :${me(s)}`:"Every hour":t}if(!De.test(s))return t;const o=ot(n);if(o&&l==="*")return`${dt(o,"hour")}${Number(s)?` at :${me(s)}`:""}`;if(!De.test(n))return t;const d=`${me(n)}:${me(s)}`;return l==="*"?`Daily at ${d}`:l==="1-5"?`Weekdays at ${d}`:l==="0,6"||l==="6,0"?`Weekends at ${d}`:/^[0-7]$/.test(l)?`${Me[Number(l)%7]}s at ${d}`:t}const Ia=[{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 Ka(t,s){const n=a=>{const i=s.names.indexOf(a.toUpperCase()),l=i>=0?i+(s.min===1?1:0):De.test(a)?Number(a):Number.NaN;return l>=s.min&&l<=s.max?l:Number.NaN};return t.split(",").every(a=>{const i=/^(\*|[a-z0-9]+(?:-[a-z0-9]+)?)(?:\/(\d+))?$/i.exec(a);if(!(i!=null&&i[1])||i[2]!==void 0&&Number(i[2])<1)return!1;if(i[1]==="*")return!0;const[l="",r]=i[1].split("-");return r===void 0?!Number.isNaN(n(l)):n(l)<=n(r)})}function Ba(t){const s=t.trim().split(/\s+/).filter(Boolean);if(!s.length)return"Enter a cron expression.";if(s.length!==5)return`A cron expression has 5 fields (minute hour day month weekday); this one has ${s.length}.`;for(const[n,a]of Ia.entries()){const i=s[n]??"";if(!Ka(i,a))return`The ${a.name} field "${i}" is not valid. Use a number from ${a.min} to ${a.max}, *, a range (1-5), a list (1,3) or a step (*/2).`}return null}function Ua(t){var a;const s=Math.max(0,Math.round((t-Date.now())/1e3));if(s<60)return"in under a minute";if(s<3600)return`in ${Math.round(s/60)}m`;if(s<86400)return`in ${Math.round(s/3600)}h`;const n=new Date(t);return`${(a=Me[n.getDay()])==null?void 0:a.slice(0,3)} ${me(String(n.getHours()))}:${me(String(n.getMinutes()))}`}function Je(t){const s=Math.max(0,Math.round((Date.now()-t)/1e3));return s<60?"just now":s<3600?`${Math.round(s/60)}m ago`:s<86400?`${Math.round(s/3600)}h ago`:`${Math.round(s/86400)}d ago`}function Oa(t){var n;const s=(n=t.last_run)==null?void 0:n.status;return s==="running"?"progress":t.schedule.type==="cron"&&!t.enabled?"off":s==="failed"?"error":s==="completed"?"ok":"off"}function qa({kb:t}){const s=Vs(t.id),[n,a]=m.useState(null),[i,l]=m.useState(!1),r=s.data;return e.jsxs(e.Fragment,{children:[e.jsx(Ne,{title:"Digest",testId:"kb-digest",toggleTestId:"kb-digest-expand",expanded:i,onExpandedChange:l,summary:s.error?e.jsx("span",{role:"alert",className:"text-error",children:s.error.message}):s.isLoading?e.jsx("span",{className:"text-outline",children:"Loading…"}):r?e.jsx(Ha,{digest:r}):e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-outline","data-testid":"kb-digest-off",children:[e.jsx(ae,{tone:"off"}),"Off, documents change only when someone edits them"]}),actions:r?e.jsx(Wa,{kb:t,digest:r,onStarted:()=>l(!0)}):s.data===null?e.jsx(y,{size:"sm",variant:"outline","data-testid":"kb-digest-add",onClick:()=>a("edit"),children:"Set up"}):null,children:r?e.jsx(Va,{kb:t,digest:r,onEdit:()=>a("edit")}):e.jsx("p",{className:"max-w-prose text-outline",children:"A digest is an agent that reads new memories, sessions and open comments, then keeps the documents in this knowledge base current. It can run on a schedule or only when you start it."})}),n==="edit"&&e.jsx(nn,{kb:t,digest:r??null,onClose:()=>a(null),onRemove:()=>a("remove")}),n==="remove"&&e.jsx(rn,{kb:t,onClose:()=>a(null)})]})}function Ha({digest:t}){const s=t.last_run,n=t.schedule.type==="manual"||t.enabled;return e.jsxs("span",{"data-testid":"kb-digest-summary",className:"inline-flex min-w-0 flex-wrap items-center gap-x-1.5",children:[e.jsx(ae,{tone:Oa(t)}),e.jsx("span",{"data-testid":"kb-digest-enabled",children:n?"On":"Paused"}),e.jsxs("span",{children:["·"," ",t.schedule.type==="manual"?"runs when you start it":e.jsx("span",{title:t.schedule.cron,children:es(t.schedule.cron)})]}),t.next_run_at!==null&&e.jsxs("span",{className:"text-outline","data-testid":"kb-digest-next-run",children:["·"," ",e.jsxs("span",{title:new Date(t.next_run_at).toLocaleString(),children:["next run ",Ua(t.next_run_at)]})]}),e.jsxs("span",{className:"text-outline","data-testid":"kb-digest-last-run","data-status":(s==null?void 0:s.status)??"never",children:["·"," ",s?s.status==="running"?"running now":e.jsxs("span",{title:new Date(s.at).toLocaleString(),children:["last run"," ",e.jsx("span",{className:s.status==="failed"?"text-error":void 0,children:s.status==="completed"?"succeeded":s.status})," ",Je(s.at)]}):"not run yet"]})]})}function Wa({kb:t,digest:s,onStarted:n}){var o;const a=V(),i=Q(),l=((o=s.last_run)==null?void 0:o.status)==="running";async function r(){await i.run(()=>M.kb.runDigest(t.id))&&(n(),await a())}return e.jsxs(e.Fragment,{children:[i.error&&e.jsx("span",{role:"alert",className:"text-error","data-testid":"kb-digest-error",children:i.error}),e.jsx(y,{size:"sm",variant:"outline","data-testid":"kb-digest-run",onClick:r,disabled:i.pending||l,children:l?"Running…":"Run now"})]})}function Va({kb:t,digest:s,onEdit:n}){const a=V(),i=Q(),l=Gs(t.id,s);async function r(){await i.run(()=>M.kb.setDigest(t.id,{enabled:!s.enabled}))&&await a()}return e.jsxs("div",{className:"min-w-0 space-y-3",children:[e.jsxs("p",{className:"max-w-prose text-outline",children:["The ",e.jsx("span",{className:"font-mono text-on-surface",children:s.backend})," agent reads new memories, sessions and open comments, then updates documents here."," ",e.jsx("span",{"data-testid":"kb-digest-open-comments",children:s.open_comments})," open"," ",s.open_comments===1?"comment waits":"comments wait"," for the next run."]}),e.jsxs("div",{className:"-ml-2 flex flex-wrap items-center gap-1",children:[e.jsx(y,{size:"sm",variant:"ghost","data-testid":"kb-digest-edit",onClick:n,children:"Edit instructions and schedule"}),s.schedule.type==="cron"&&e.jsx(y,{size:"sm",variant:"ghost","data-testid":"kb-digest-toggle",onClick:r,disabled:i.pending,children:s.enabled?"Pause schedule":"Resume schedule"}),e.jsx(y,{size:"sm",variant:"ghost",asChild:!0,children:e.jsx(St,{to:`/jobs/${encodeURIComponent(s.job_id)}`,"data-testid":"kb-digest-job",children:"Job history"})})]}),i.error&&e.jsx("p",{role:"alert",className:"text-error","data-testid":"kb-digest-error",children:i.error}),e.jsx(Qa,{runs:l.data??[]})]})}const Ga={failed:"error",success:"ok",running:"progress"};function Qa({runs:t}){return t.length?e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-xs font-medium text-outline",children:"Recent runs"}),e.jsx("ol",{"data-testid":"kb-digest-runs",className:"divide-y divide-outline-variant",children:t.map(s=>e.jsxs("li",{"data-testid":"kb-digest-run-row","data-status":s.status,className:"min-w-0 break-words py-1.5",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ae,{tone:Ga[s.status]??"off"}),s.status]}),e.jsxs("span",{className:"text-outline",children:[" · ",s.started_at?e.jsx("span",{title:new Date(s.started_at).toLocaleString(),children:Je(s.started_at)}):"not started",s.trigger_by?` · ${s.trigger_by}`:""]}),s.session_id&&e.jsx(St,{to:`/audit/${encodeURIComponent(s.session_id)}`,className:"ml-2 text-primary hover:underline",children:"Session"}),(s.error||s.summary)&&e.jsx("span",{className:"block truncate text-xs text-outline",title:s.error??s.summary??"",children:s.error??s.summary})]},s.run_id))})]}):e.jsx("p",{className:"text-outline",children:"No runs yet."})}const qe=/[,\s]+/;function ct(t,s){const n=s.split(qe).map(a=>a.trim()).filter(Boolean);return[...new Set([...t,...n])]}function ts({value:t,onChange:s,suggestions:n=[],placeholder:a="Add a label","aria-label":i,"data-testid":l}){const[r,o]=m.useState(""),d=m.useRef(null),p=m.useId(),c=n.filter(g=>!t.includes(g));function x(g){const h=ct(t,g);h.length!==t.length&&s(h),o("")}function k(g){const h=g.split(qe);if(h.length>1){const D=h.pop()??"";s(ct(t,h.join(","))),o(D)}else o(g)}function j(g){(g.key==="Enter"||g.key==="Tab")&&r.trim()?(g.preventDefault(),x(r)):g.key==="Backspace"&&!r&&t.length>0&&(g.preventDefault(),s(t.slice(0,-1)))}function S(g){const h=g.clipboardData.getData("text");qe.test(h)&&(g.preventDefault(),x(`${r},${h}`))}return e.jsxs("div",{className:B("flex min-h-10 w-full cursor-text flex-wrap items-center gap-1.5 rounded-md border border-control-border bg-surface px-2 py-1.5 text-sm","focus-within:ring-2 focus-within:ring-focus focus-within:ring-offset-2 ring-offset-background"),onClick:()=>{var g;return(g=d.current)==null?void 0:g.focus()},children:[t.map(g=>e.jsxs("span",{"data-testid":"tag-input-tag",className:"inline-flex max-w-full items-center gap-1 rounded-full border border-outline-variant bg-surface-high py-0.5 pl-2.5 pr-1 text-xs text-on-surface",children:[e.jsx("span",{className:"truncate",children:g}),e.jsx("button",{type:"button","aria-label":`Remove ${g}`,className:"rounded-full p-0.5 text-outline hover:bg-surface-highest hover:text-on-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus",onClick:h=>{var D;h.stopPropagation(),s(t.filter(b=>b!==g)),(D=d.current)==null||D.focus()},children:e.jsx(Pe,{size:12,"aria-hidden":!0})})]},g)),e.jsx("input",{ref:d,"aria-label":i,"data-testid":l,list:c.length>0?p:void 0,value:r,onChange:g=>k(g.target.value),onKeyDown:j,onPaste:S,onBlur:()=>r.trim()&&x(r),placeholder:t.length===0?a:"",className:"h-7 min-w-[8rem] flex-1 bg-transparent px-1 outline-none placeholder:text-muted-foreground"}),c.length>0&&e.jsx("datalist",{id:p,children:c.map(g=>e.jsx("option",{value:g},g))})]})}const Fe="__global__",Ie="__auto__";function ss(t){return t instanceof Error?t.message:"Request failed"}function Q(){const[t,s]=m.useState(!1),[n,a]=m.useState(null);async function i(l){s(!0),a(null);try{return await l()}catch(r){a(ss(r));return}finally{s(!1)}}return{pending:t,error:n,run:i,setError:a}}function L({label:t,children:s,hint:n}){return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(ie,{className:"text-sm text-muted-foreground",children:t}),s,n&&e.jsx("p",{className:"text-xs text-outline",children:n})]})}function oe({error:t}){return t?e.jsx("p",{role:"alert","data-testid":"kb-dialog-error",className:"text-sm text-error",children:t}):null}function be({open:t,onClose:s,title:n,wide:a,size:i,children:l}){return e.jsx($t,{open:t,onOpenChange:r=>!r&&s(),children:e.jsxs(Et,{className:`bg-surface border-outline-variant ${i==="xl"?"w-[calc(100%_-_1rem)] max-w-4xl":a?"max-w-3xl":"max-w-md"}`,children:[e.jsx(Pt,{children:e.jsx(Rt,{className:"text-base text-on-surface",children:n})}),l]})})}function as({value:t,onChange:s}){var a;const n=Ot();return e.jsxs(he,{value:t??Ie,onValueChange:i=>s(i===Ie?null:i),children:[e.jsx(pe,{"aria-label":"Parser","data-testid":"kb-parser-select",children:e.jsx(fe,{})}),e.jsxs(ge,{children:[e.jsx(J,{value:Ie,children:"Workspace default"}),(((a=n.data)==null?void 0:a.parsers)??[]).map(i=>e.jsxs(J,{value:i.id,disabled:!i.installed,children:[i.label,i.installed?"":" (not installed)"]},i.id))]})]})}const ns={ui:"Web UI",cli:"CLI",api:"REST API",mcp:"Agents (MCP)"};function is({value:t,onChange:s}){return e.jsxs("fieldset",{className:"space-y-2 rounded-md border border-outline-variant p-3",children:[e.jsx("legend",{className:"px-1 text-sm text-muted-foreground",children:"Who can change documents"}),e.jsx("div",{className:"flex flex-wrap gap-x-4 gap-y-2",children:se.map(n=>e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox","data-testid":`kb-editable-${n}`,checked:t.includes(n),onChange:a=>s(se.filter(i=>i===n?a.target.checked:t.includes(i)))}),ns[n]]},n))}),e.jsx("p",{className:"text-xs text-outline",children:"Every source can read and search. Knowledge base settings change only from the UI, CLI or API."})]})}function Ya({open:t,projectId:s,onClose:n,onCreated:a}){const i=ke(),l=V(),r=Q(),[o,d]=m.useState(""),[p,c]=m.useState(""),[x,k]=m.useState(s??Fe),[j,S]=m.useState([...se]),[g,h]=m.useState(null);async function D(b){b.preventDefault();const u=await r.run(()=>M.kb.create({name:o.trim(),description:p.trim(),project_id:x===Fe?null:x,editable_by:j,parser:g}));u&&(await l(),a(u))}return e.jsx(be,{open:t,onClose:n,title:"New knowledge base",children:e.jsxs("form",{onSubmit:D,className:"space-y-4",children:[e.jsx(L,{label:"Name",children:e.jsx(U,{"aria-label":"Name","data-testid":"kb-name-input",value:o,onChange:b=>d(b.target.value),placeholder:"e.g. Runbooks",autoFocus:!0})}),e.jsx(L,{label:"Description",children:e.jsx(xe,{"aria-label":"Description",value:p,onChange:b=>c(b.target.value),rows:2})}),e.jsx(L,{label:"Belongs to",hint:"Project knowledge bases are visible in that project; global ones in every project.",children:e.jsxs(he,{value:x,onValueChange:k,children:[e.jsx(pe,{"aria-label":"Belongs to","data-testid":"kb-owner-select",children:e.jsx(fe,{})}),e.jsxs(ge,{children:[e.jsx(J,{value:Fe,children:"Global (all projects)"}),(i.data??[]).map(b=>e.jsx(J,{value:b.id,children:b.name},b.id))]})]})}),e.jsx(is,{value:j,onChange:S}),e.jsx(L,{label:"Parser for uploads",children:e.jsx(as,{value:g,onChange:h})}),e.jsx(oe,{error:r.error}),e.jsxs(le,{children:[e.jsx(y,{type:"button",variant:"ghost",onClick:n,children:"Cancel"}),e.jsx(y,{type:"submit","data-testid":"kb-create-submit",disabled:!o.trim()||r.pending,children:r.pending?"Creating…":"Create"})]})]})})}function Ja({kb:t,onClose:s,onDeleted:n}){var D,b;const a=ke(),i=V(),l=Q(),[r,o]=m.useState(t.name),[d,p]=m.useState(t.description),[c,x]=m.useState(t.editable_by),[k,j]=m.useState(t.parser),[S,g]=m.useState(!1);async function h(u){u.preventDefault(),await l.run(()=>M.kb.update(t.id,{name:r.trim(),description:d.trim(),editable_by:c,parser:k}))&&(await i(),s())}return e.jsxs(be,{open:!0,onClose:s,title:"Knowledge base settings",children:[e.jsxs("form",{onSubmit:h,className:"space-y-4",children:[e.jsx(L,{label:"Name",children:e.jsx(U,{"aria-label":"Name","data-testid":"kb-name-input",value:r,onChange:u=>o(u.target.value)})}),e.jsx(L,{label:"Description",children:e.jsx(xe,{"aria-label":"Description",value:d,onChange:u=>p(u.target.value),rows:2})}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsx("div",{className:"font-medium",children:"Belongs to"}),e.jsxs("p",{className:"text-outline","data-testid":"kb-settings-owner",children:[t.project_id===null?"Global, visible in every project":`${((b=(D=a.data)==null?void 0:D.find(u=>u.id===t.project_id))==null?void 0:b.name)??"A project"}, visible in that project`,". Set when the knowledge base is created."]})]}),e.jsx(is,{value:c,onChange:x}),e.jsx(L,{label:"Parser for uploads",hint:"Applies to new uploads and reparses.",children:e.jsx(as,{value:k,onChange:j})}),e.jsx(oe,{error:l.error}),e.jsxs(le,{className:"gap-2 sm:justify-between",children:[e.jsxs(y,{type:"button",variant:"ghost",className:"text-error","data-testid":"kb-delete",onClick:()=>g(!0),children:[e.jsx(Re,{size:14}),"Delete"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{type:"button",variant:"ghost",onClick:s,children:"Cancel"}),e.jsx(y,{type:"submit","data-testid":"kb-settings-save",disabled:!r.trim()||l.pending,children:"Save"})]})]})]}),e.jsx(ze,{open:S,title:"Delete knowledge base",description:`Delete "${t.name}" with its ${t.document_count} documents, revisions and uploaded files? Registered folders on disk are not touched.`,isPending:l.pending,onCancel:()=>g(!1),onConfirm:async()=>{const u=await l.run(()=>M.kb.remove(t.id));g(!1),u!==void 0&&(await i(),n())}})]})}function ut(t){return`${t.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"untitled"}.md`}function mt(t){var s,n;return((n=(s=t.match(/^#\s+(.+?)\s*#*\s*$/m))==null?void 0:s[1])==null?void 0:n.trim())??""}const Xa=/\.(md|markdown|txt)$/i;function Za({kb:t,initialFile:s,onClose:n,onCreated:a,onUploadMany:i}){var f;const l=V(),r=Q(),o=Le(t.id),[d,p]=m.useState(""),[c,x]=m.useState(""),[k,j]=m.useState(""),[S,g]=m.useState([]),[h,D]=m.useState(null),[b,u]=m.useState(!1),C=m.useRef(null),P=h?"":mt(c),T=d.trim()||P,K=h?h.name:ut(T),H=h!==null||c.trim()!=="";async function R(E){const F=E.name.replace(/\.[^.]+$/,"");if(!Xa.test(E.name)){D(E),p(F),j("");return}u(!0);const G=await r.run(()=>E.text());u(!1),G!==void 0&&(D(null),x(G),p(mt(G)||F),j(/\.txt$/i.test(E.name)?ut(F):E.name))}function v(E){const F=[...E??[]];F.length>1?i(F):F[0]&&R(F[0])}m.useEffect(()=>{s&&R(s)},[]);async function N(E){E.preventDefault();const F=await r.run(()=>h?M.kb.upload(t.id,{file:h,title:T,path:k.trim()||void 0,labels:S}):M.kb.createDocument(t.id,{title:T,path:k.trim()||K,labels:S,content:H?c:`# ${T}
|
|
27
|
+
|
|
28
|
+
`}));F&&(await l(),a(F,H))}return e.jsx(be,{open:!0,onClose:n,title:`New document in ${t.name}`,size:"xl",children:e.jsxs("form",{onSubmit:N,className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm text-outline",children:[e.jsx("span",{children:"Write or paste below, or start from a file."}),e.jsxs(y,{type:"button",size:"sm",variant:"outline","data-testid":"kb-doc-choose-file",disabled:b||r.pending,onClick:()=>{var E;return(E=C.current)==null?void 0:E.click()},children:[e.jsx(Ht,{size:16}),b?"Reading…":"Upload file"]}),e.jsx("input",{ref:C,type:"file",multiple:!0,hidden:!0,"data-testid":"kb-doc-file-input",onChange:E=>{v(E.target.files),E.target.value=""}})]}),e.jsx(L,{label:"Title",hint:P&&!d.trim()?"Taken from the first heading.":void 0,children:e.jsx(U,{"aria-label":"Title","data-testid":"kb-doc-title-input",value:d,onChange:E=>p(E.target.value),placeholder:P||"e.g. Deploy runbook",autoFocus:!0})}),h?e.jsx(L,{label:"File",hint:"Converted to searchable text after it is added. The original file is kept.",children:e.jsxs("div",{"data-testid":"kb-doc-file",className:"flex items-center gap-3 rounded-md border border-surface-highest bg-surface p-3",children:[e.jsx(Ct,{size:20,className:"shrink-0 text-outline","aria-hidden":!0}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",title:h.name,children:h.name}),e.jsx("span",{className:"shrink-0 text-xs text-outline",children:Ge(h.size)}),e.jsx(y,{type:"button",size:"icon",variant:"ghost","aria-label":`Remove ${h.name}`,"data-testid":"kb-doc-file-remove",onClick:()=>{D(null),p("")},children:e.jsx(Pe,{size:16})})]})}):e.jsx(L,{label:"Content",hint:"Markdown. Leave empty to start writing in the editor.",children:e.jsx(Dt,{path:k.trim()||K,value:c,onChange:x,testId:"kb-doc-content-input",label:"Content",placeholder:"Write or paste Markdown",initialMode:"edit",height:"45vh"})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(L,{label:"Labels",hint:"Enter, comma or space adds a label.",children:e.jsx(ts,{"aria-label":"Labels","data-testid":"kb-doc-labels-input",value:S,onChange:g,suggestions:(f=o.data)==null?void 0:f.labels.map(E=>E.label)})}),e.jsx(L,{label:"Path",hint:"Optional. Folders come from the path, e.g. guides/setup.md.",children:e.jsx(U,{"aria-label":"Path","data-testid":"kb-doc-path-input",value:k,onChange:E=>j(E.target.value),placeholder:K,className:"font-mono text-sm"})})]}),e.jsx(oe,{error:r.error}),e.jsxs(le,{children:[e.jsx(y,{type:"button",variant:"ghost",onClick:n,children:"Cancel"}),e.jsx(y,{type:"submit","data-testid":"kb-doc-create-submit",disabled:!T||r.pending,children:"Create"})]})]})})}function en({doc:t,linkedFrom:s,onClose:n,onSaved:a}){var D;const i=V(),l=Q(),[r,o]=m.useState(t.title),[d,p]=m.useState(t.path),c=Le(t.kb_id),[x,k]=m.useState(t.labels),[j,S]=m.useState(t.description),g=r.trim()!==t.title||d.trim()!==t.path;async function h(b){b.preventDefault(),await l.run(()=>M.kb.updateDocument(t.id,{expected_revision:t.revision,title:r.trim(),path:d.trim(),labels:x,description:j.trim()}))&&(await i(),a())}return e.jsx(be,{open:!0,onClose:n,title:"Document properties",children:e.jsxs("form",{onSubmit:h,className:"space-y-4",children:[e.jsx(L,{label:"Title",children:e.jsx(U,{"aria-label":"Title","data-testid":"kb-doc-title-input",value:r,onChange:b=>o(b.target.value)})}),e.jsx(L,{label:"Path",children:e.jsx(U,{"aria-label":"Path","data-testid":"kb-doc-path-input",value:d,onChange:b=>p(b.target.value),className:"font-mono text-sm"})}),e.jsx(L,{label:"Labels",hint:"Enter, comma or space adds a label.",children:e.jsx(ts,{"aria-label":"Labels","data-testid":"kb-doc-labels-input",value:x,onChange:k,suggestions:(D=c.data)==null?void 0:D.labels.map(b=>b.label)})}),e.jsx(L,{label:"Description",children:e.jsx(xe,{"aria-label":"Description",value:j,onChange:b=>S(b.target.value),rows:2})}),g&&s>0&&e.jsxs("p",{role:"status",className:"text-sm text-warning","data-testid":"kb-rename-warning",children:[s===1?"1 document links":`${s} documents link`," to this document. Links that use the old title or path will show as missing."]}),e.jsx(oe,{error:l.error}),e.jsxs(le,{children:[e.jsx(y,{type:"button",variant:"ghost",onClick:n,children:"Cancel"}),e.jsx(y,{type:"submit","data-testid":"kb-doc-properties-save",disabled:!r.trim()||l.pending,children:"Save"})]})]})})}const xt={daily:"Every day",weekly:"Once a week",custom:"Custom cron",manual:"Manual only"};function tn(t){const s=t.type==="cron"?t.cron:Zt,n={plan:"custom",time:"03:00",day:"1",cron:s},a=/^(\d{1,2}) (\d{1,2}) \* \* (\*|[0-6])$/.exec(s.trim().split(/\s+/).join(" ")),[i,l]=[Number(a==null?void 0:a[1]),Number(a==null?void 0:a[2])],r=a&&i<=59&&l<=23?`${String(l).padStart(2,"0")}:${String(i).padStart(2,"0")}`:null;return t.type==="manual"?{...n,plan:"manual",time:r??n.time}:!(a!=null&&a[3])||!r?n:a[3]==="*"?{...n,plan:"daily",time:r}:{...n,plan:"weekly",time:r,day:a[3]}}function rs({plan:t,time:s,day:n,cron:a}){if(t==="manual")return null;if(t==="custom")return a.trim();const[i,l]=s.split(":").map(Number);return`${l} ${i} * * ${t==="weekly"?n:"*"}`}function ls(t){return t.plan==="manual"?null:t.plan==="custom"?Ba(t.cron):/^\d{2}:\d{2}$/.test(t.time)?null:"Pick a time."}function sn(t){const s=es(t);return s===t?"Runs on this cron schedule":Me.some(n=>s.startsWith(n))?`Runs ${s}`:`Runs ${s.charAt(0).toLowerCase()}${s.slice(1)}`}function an({value:t,onChange:s}){const n=rs(t),a=ls(t),i=l=>s({...t,...l});return e.jsxs("fieldset",{className:"space-y-3 rounded-md border border-outline-variant p-3",children:[e.jsx("legend",{className:"px-1 text-sm text-muted-foreground",children:"When it runs"}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsx(L,{label:"Schedule",children:e.jsxs(he,{value:t.plan,onValueChange:l=>i({plan:l,...l==="custom"&&n?{cron:n}:{}}),children:[e.jsx(pe,{"aria-label":"Schedule","data-testid":"kb-digest-schedule",children:e.jsx(fe,{})}),e.jsx(ge,{children:Object.keys(xt).map(l=>e.jsx(J,{value:l,children:xt[l]},l))})]})}),t.plan==="weekly"&&e.jsx(L,{label:"Day",children:e.jsxs(he,{value:t.day,onValueChange:l=>i({day:l}),children:[e.jsx(pe,{"aria-label":"Day","data-testid":"kb-digest-day",children:e.jsx(fe,{})}),e.jsx(ge,{children:Me.map((l,r)=>e.jsx(J,{value:String(r),children:l},l))})]})}),(t.plan==="daily"||t.plan==="weekly")&&e.jsx(L,{label:"Time",children:e.jsx(U,{type:"time","aria-label":"Time","data-testid":"kb-digest-time",value:t.time,onChange:l=>i({time:l.target.value})})}),t.plan==="custom"&&e.jsx("div",{className:"sm:col-span-2",children:e.jsx(L,{label:"Cron expression",hint:"minute hour day month weekday, e.g. 0 */6 * * *",children:e.jsx(U,{"aria-label":"Cron expression","aria-invalid":a!==null,"data-testid":"kb-digest-cron",value:t.cron,onChange:l=>i({cron:l.target.value}),className:"font-mono",autoComplete:"off"})})})]}),e.jsx("p",{"aria-live":"polite","data-testid":"kb-digest-schedule-preview","data-valid":a===null,className:`text-sm ${a?"text-error":"text-outline"}`,children:a||(n?e.jsxs(e.Fragment,{children:[sn(n)," ",e.jsxs("span",{className:"font-mono text-xs",children:["(",n,")"]}),", in the ORC server's time zone."]}):"Runs only when you start it.")})]})}function nn({kb:t,digest:s,onClose:n,onRemove:a}){const i=V(),l=Q(),r=bs(),o=Qs(!s),[d,p]=m.useState((s==null?void 0:s.instructions)??null),[c,x]=m.useState((s==null?void 0:s.backend)??st),[k,j]=m.useState(()=>tn((s==null?void 0:s.schedule)??{type:"cron",cron:Zt}));m.useEffect(()=>{d===null&&o.data&&p(o.data.instructions)},[d,o.data]);const S=ls(k);async function g(D){var P;if(D.preventDefault(),S)return l.setError(S);const b=c===st?(P=r.data)==null?void 0:P.default_backend:c,u=rs(k);await l.run(()=>M.kb.setDigest(t.id,{instructions:(d==null?void 0:d.trim())??"",...b?{backend:b}:{},schedule:u?{type:"cron",cron:u}:{type:"manual"}}))&&(await i(),n())}const h=d!==null;return e.jsx(be,{open:!0,onClose:n,title:s?"Digest settings":"Set up a digest",wide:!0,children:e.jsxs("form",{onSubmit:g,className:"min-w-0 space-y-4",children:[!t.editable_by.includes("mcp")&&e.jsx("p",{className:"text-sm text-warning","data-testid":"kb-digest-mcp-hint",children:"The digest writes through MCP. Allow Agents (MCP) in this knowledge base's settings first."}),e.jsx(an,{value:k,onChange:j}),e.jsx(js,{value:c,onChange:x,testId:"kb-digest-backend"}),e.jsx(L,{label:"Instructions",children:h?e.jsx(Dt,{path:"digest.md",value:d,onChange:p,testId:"kb-digest-instructions",label:"Instructions",initialMode:"edit",height:320}):o.error?e.jsx("p",{role:"alert",className:"text-sm text-error",children:ss(o.error)}):e.jsx("p",{role:"status",className:"text-sm text-outline",children:"Loading template…"})}),e.jsx(oe,{error:l.error}),e.jsxs(le,{className:"gap-2 sm:justify-between",children:[s&&a?e.jsxs(y,{type:"button",variant:"ghost",className:"text-error","data-testid":"kb-digest-remove",onClick:a,children:[e.jsx(Re,{size:14}),"Remove digest"]}):e.jsx("span",{}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{type:"button",variant:"ghost",onClick:n,children:"Cancel"}),e.jsx(y,{type:"submit","data-testid":"kb-digest-save",disabled:!h||!(d!=null&&d.trim())||S!==null||l.pending,children:l.pending?"Saving…":"Save"})]})]})]})})}function rn({kb:t,onClose:s}){const n=ys(),a=Q();async function i(){await a.run(()=>M.kb.removeDigest(t.id,t.name))!==void 0&&(n.setQueryData([Ys,t.id],{digest:null}),await n.invalidateQueries({queryKey:[Js]}),s())}return e.jsx(be,{open:!0,onClose:s,title:"Remove digest?",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-outline",children:"Documents and comments stay. The digest's instructions, schedule, job and run history are removed."}),e.jsx(oe,{error:a.error}),e.jsxs(le,{children:[e.jsx(y,{type:"button",variant:"ghost",onClick:s,children:"Cancel"}),e.jsx(y,{type:"button",variant:"destructive","data-testid":"kb-digest-remove-confirm",onClick:i,disabled:a.pending,autoFocus:!0,children:a.pending?"Removing…":"Remove digest"})]})]})})}const ln=vs("inline-flex items-center rounded-full border border-border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 ",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80 ",secondary:"border-transparent bg-muted text-foreground hover:bg-muted/80 ",destructive:"border-transparent bg-error text-primary-foreground hover:bg-error/80 ",outline:"text-foreground "}},defaultVariants:{variant:"default"}});function os({className:t,variant:s,...n}){return e.jsx("div",{className:B(ln({variant:s}),t),...n})}const on={open:"bg-warning",resolved:"bg-secondary",dismissed:"bg-muted-foreground"};function ds({status:t}){return e.jsx("span",{"aria-hidden":!0,className:B("size-1.5 shrink-0 rounded-full",on[t])})}function cs({kbId:t,documentId:s,onOpenDocument:n,heading:a="h3",compact:i=!1}){var j,S,g;const[l,r]=m.useState(!1),[o,d]=m.useState(null),p=qt(t,{...s?{document_id:s}:{},...o?{status:o}:{}}),c=(j=p.data)==null?void 0:j.counts,x=c?c.open+c.resolved+c.dismissed:0;function k(h){d(l&&o===h?null:h),r(!0)}return e.jsx(Ne,{title:"Comments",testId:"kb-comments",toggleTestId:"kb-comments-toggle",heading:a,compact:i,expanded:l,onExpandedChange:r,summary:e.jsxs(e.Fragment,{children:[c&&x===0&&e.jsx("span",{className:"text-outline","data-testid":"kb-comments-none",children:"None yet"}),c&&Aa.filter(h=>c[h]>0).map(h=>e.jsxs("button",{type:"button","data-testid":`kb-comments-count-${h}`,"aria-pressed":l&&o===h,"aria-label":`${c[h]} ${h} ${c[h]===1?"comment":"comments"}`,className:B("inline-flex min-h-8 items-center gap-1.5 rounded px-1.5",l&&o===h?"bg-surface-highest text-on-surface":"text-outline hover:bg-surface-high"),onClick:()=>k(h),children:[e.jsx(ds,{status:h}),e.jsx("span",{className:"tabular-nums text-on-surface",children:c[h]}),h]},h)),p.error&&e.jsx("span",{role:"alert",className:"text-error","data-testid":"kb-comments-error",children:p.error.message})]}),children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(dn,{kbId:t,documentId:s}),o&&((S=p.data)==null?void 0:S.comments.length)===0&&e.jsxs("p",{className:"text-outline","data-testid":"kb-comments-empty",children:["No ",o," comments."]}),e.jsx("ul",{className:"divide-y divide-outline-variant",children:(g=p.data)==null?void 0:g.comments.map(h=>e.jsx(cn,{comment:h,showDocument:!s,onOpenDocument:n},h.id))})]})})}function dn({kbId:t,documentId:s}){const n=V(),a=Q(),[i,l]=m.useState("");async function r(o){o.preventDefault(),await a.run(()=>M.kb.addComment(t,{body:i.trim(),...s?{document_id:s}:{}}))&&(l(""),await n())}return e.jsxs("form",{onSubmit:r,className:"space-y-2",children:[e.jsx(xe,{"aria-label":s?"Comment on this document":"Comment on this knowledge base",placeholder:s?"Ask for a change to this document":"Ask for a change","data-testid":"kb-comment-input",value:i,onChange:o=>l(o.target.value),rows:2,maxLength:1e4}),i.trim()&&e.jsx(y,{type:"submit",size:"sm",variant:"outline","data-testid":"kb-comment-add",disabled:a.pending,children:"Add comment"}),a.error&&e.jsx("p",{role:"alert",className:"text-error","data-testid":"kb-comment-add-error",children:a.error})]})}function cn({comment:t,showDocument:s,onOpenDocument:n}){const a=V(),i=Q(),[l,r]=m.useState(null),[o,d]=m.useState("");async function p(x){if(x.preventDefault(),!l)return;const k=l;await i.run(()=>M.kb.closeComment(t.id,{status:k,reply:o.trim()}))&&(r(null),d(""),await a())}async function c(){await i.run(()=>M.kb.reopenComment(t.id))&&await a()}return e.jsxs("li",{"data-testid":"kb-comment","data-status":t.status,className:"min-w-0 space-y-1 py-2",children:[e.jsxs("p",{className:"flex min-w-0 flex-wrap items-center gap-x-2 text-xs text-outline",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-on-surface",children:[e.jsx(ds,{status:t.status}),e.jsx("span",{"data-testid":"kb-comment-status",children:t.status})]}),e.jsxs("span",{className:"min-w-0 break-words",children:[t.source===t.author?t.author:`${t.author} via ${t.source}`," ·"," ",new Date(t.created_at).toLocaleString(),s&&t.document_id&&e.jsxs(e.Fragment,{children:[" · on ",n?e.jsx("button",{type:"button",className:"text-primary hover:underline",onClick:()=>t.document_id&&n(t.document_id),children:t.document_title??"a deleted document"}):t.document_title??"a deleted document"]})]})]}),e.jsx("p",{className:"whitespace-pre-wrap break-words",children:t.body}),t.reply&&e.jsxs("p",{className:"break-words text-xs","data-testid":"kb-comment-reply-text",children:[e.jsxs("span",{className:"text-outline",children:[t.status==="dismissed"?"Dismissed":"Resolved",t.resolved_by?` by ${t.resolved_by}`:"",":"]})," ",t.reply]}),l?e.jsxs("form",{onSubmit:p,className:"flex flex-wrap items-center gap-2",children:[e.jsx(U,{"aria-label":l==="resolved"?"Resolution reply":"Reason for dismissing",placeholder:l==="resolved"?"What changed":"Why not","data-testid":"kb-comment-reply",value:o,onChange:x=>d(x.target.value),maxLength:4e3,autoFocus:!0,className:"min-w-0 flex-1 basis-48"}),e.jsx(y,{type:"submit",size:"sm","data-testid":"kb-comment-close-submit",disabled:!o.trim()||i.pending,children:l==="resolved"?"Resolve":"Dismiss"}),e.jsx(y,{type:"button",size:"sm",variant:"ghost",onClick:()=>{r(null),d(""),i.setError(null)},children:"Cancel"})]}):t.status==="open"?e.jsxs("div",{className:"-ml-2 flex flex-wrap",children:[e.jsx(y,{size:"sm",variant:"ghost","data-testid":"kb-comment-resolve",onClick:()=>r("resolved"),children:"Resolve"}),e.jsx(y,{size:"sm",variant:"ghost","data-testid":"kb-comment-dismiss",onClick:()=>r("dismissed"),children:"Dismiss"})]}):e.jsx(y,{size:"sm",variant:"ghost",className:"-ml-2","data-testid":"kb-comment-reopen",onClick:c,disabled:i.pending,children:"Reopen"}),i.error&&e.jsx("p",{role:"alert",className:"text-xs text-error","data-testid":"kb-comment-error",children:i.error})]})}const He=t=>`kb:${t}`,us={pending:"Processing",partial:"Partially parsed",failed:"Failed",lexical_ready:"Keyword search ready",semantic_pending:"Embedding",semantic_ready:"Semantic search ready"};function ht(t,s){const n=URL.createObjectURL(t),a=document.createElement("a");a.href=n,a.download=s,a.click(),setTimeout(()=>URL.revokeObjectURL(n),1e3)}function un(t){var i;const s=[...t.currentTarget.querySelectorAll('[role="menuitem"]:not(:disabled)')],n=s.indexOf(document.activeElement),a=t.key==="ArrowDown"?(n+1)%s.length:t.key==="ArrowUp"?(n-1+s.length)%s.length:t.key==="Home"?0:t.key==="End"?s.length-1:null;a===null||!s.length||(t.preventDefault(),(i=s[a])==null||i.focus())}function mn({usage:t,testId:s}){return e.jsxs("div",{"data-testid":s,className:"space-y-2",children:[e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{"data-testid":`${s}-reads`,className:"font-medium",children:t.reads})," ","reads · ",t.exposures," search appearances · ",t.distinct_sessions," sessions"]}),e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-outline",children:[e.jsx("th",{className:"py-1 text-left font-normal",children:"Source"}),lt.map(n=>e.jsx("th",{className:"py-1 text-right font-normal",children:n==="search_hit"?"listed":n},n))]})}),e.jsx("tbody",{children:se.map(n=>e.jsxs("tr",{"data-testid":`${s}-${n}`,className:"border-t border-outline-variant/50",children:[e.jsx("td",{className:"py-1 uppercase",children:n}),lt.map(a=>e.jsx("td",{className:"py-1 text-right tabular-nums",children:t.totals[n][a]},a))]},n))})]}),e.jsxs("div",{className:"text-xs text-outline",children:["Last 7 days ",t.window.days_7," · last 30 days ",t.window.days_30]})]})}function xn({kb:t,doc:s,onHome:n,onOpen:a,onDeleted:i,onReplaceFile:l,detailsOpen:r,onDetailsOpenChange:o}){var we;const d=V(),[p]=zt(),c=p.get("editorMode"),x=((we=qt(s.kb_id,{document_id:s.id}).data)==null?void 0:we.counts.open)??0,[k,j]=m.useState(!1),[S,g]=m.useState(!1),[h,D]=m.useState(!1),b=Lt("lg"),[u,C]=m.useState(null),P=m.useRef(null),[T,K]=m.useState(null),[H,R]=m.useState(!1),v=m.useRef(null),N=m.useRef(s.revision),f=new Map(s.links.filter($=>$.document_id).map($=>[ra($.target),$.document_id])),E={slugs:[...f.keys()],select:$=>{const z=f.get($);z&&a(z)}};async function F($){R(!0),K(null);try{return await $(),await d(),!0}catch(z){return K(z instanceof Error?z.message:"Request failed"),!1}finally{R(!1)}}async function G(){await F(async()=>ht(await M.kb.original(s.id),s.original_name??s.path.split("/").pop()??"document"))}function I(){const $=(s.path.split("/").pop()??"document").replace(/\.(md|markdown)$/i,"");ht(new Blob([s.content],{type:"text/markdown;charset=utf-8"}),`${$}.md`)}const Y=s.origin==="upload",je=Y||s.origin==="external"&&!s.editable,X=(u==null?void 0:u.backlinks.filter($=>!s.backlinks.some(z=>z.document_id===$.document_id)))??[],Z=($,z,ee,_e,Se=!1)=>e.jsxs("button",{type:"button",role:"menuitem","data-testid":$,disabled:H,className:B("flex min-h-9 w-full items-center gap-2 rounded px-2 text-left text-sm outline-none hover:bg-surface-highest focus-visible:bg-surface-highest disabled:opacity-50",Se&&"text-error"),onClick:()=>{D(!1),_e()},children:[z,ee]});return e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col overflow-y-auto lg:flex-row lg:overflow-hidden",children:[e.jsx("article",{"data-testid":"kb-document",className:"min-w-0 lg:min-h-0 lg:flex-1 lg:overflow-y-auto",children:e.jsxs("div",{className:"w-full min-w-0 px-4 pb-16 pt-4 sm:px-8 sm:pt-6",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsxs("nav",{"aria-label":"Breadcrumb",className:"flex min-w-0 flex-1 basis-48 items-center gap-1 text-sm text-outline",children:[e.jsx("button",{type:"button","data-testid":"kb-breadcrumb-kb",className:"min-w-0 max-w-[60%] truncate hover:text-on-surface hover:underline",onClick:n,children:t.name}),e.jsx(Ee,{size:14,className:"shrink-0","aria-hidden":!0}),e.jsx("span",{className:"min-w-0 truncate font-mono text-xs","data-testid":"kb-document-path",title:s.path,children:s.path})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsxs(y,{size:"sm",variant:r?"secondary":"ghost","aria-pressed":r,"data-testid":"kb-details-toggle",onClick:()=>o(!r),children:[e.jsx($a,{size:14}),"Details",x>0&&e.jsxs("span",{"data-testid":"kb-details-open-comments",title:`${x} open ${x===1?"comment":"comments"}`,className:"inline-flex items-center gap-1 text-xs tabular-nums text-outline",children:[e.jsx(ae,{tone:"warning"}),x]})]}),e.jsxs(ks,{open:h,onOpenChange:D,children:[e.jsx(Ns,{asChild:!0,children:e.jsx(y,{size:"icon",variant:"ghost","aria-label":"Document actions","aria-haspopup":"menu","data-testid":"kb-doc-menu",children:e.jsx(la,{size:16})})}),e.jsx(ws,{children:e.jsxs(_s,{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:$=>{var z;$.preventDefault(),(z=$.currentTarget.querySelector('[role="menuitem"]:not(:disabled)'))==null||z.focus()},onKeyDown:un,children:[Z("kb-doc-properties",e.jsx(Wt,{size:14}),"Title and labels",()=>{P.current={title:s.title,backlinks:s.backlinks},j(!0)}),!je&&Z("kb-doc-download-markdown",e.jsx(ka,{size:14}),"Download Markdown",I),je&&Z("kb-doc-download",e.jsx(ca,{size:14}),"Download original",()=>void G()),Y&&Z("kb-doc-reparse",e.jsx(ua,{size:14}),"Parse again",()=>void F(()=>M.kb.reparse(s.id))),Y&&Z("kb-doc-replace",e.jsx(Sa,{size:14}),"Replace file",()=>{var $;return($=v.current)==null?void 0:$.click()}),s.origin!=="external"&&Z("kb-doc-delete",e.jsx(Re,{size:14}),"Delete document",()=>g(!0),!0)]})})]})]})]}),e.jsxs("header",{className:"mb-2 mt-4 space-y-2",children:[e.jsx("h1",{"data-testid":"kb-document-title",className:"break-words text-3xl font-medium",children:s.title}),s.description&&e.jsx("p",{className:"text-outline",children:s.description}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5 text-xs text-outline",children:[s.labels.length>0&&e.jsx("span",{className:"flex flex-wrap gap-1",children:s.labels.map($=>e.jsx(os,{variant:"secondary","data-testid":"kb-document-label",children:$},$))}),s.parse_state!=="ok"&&e.jsxs("span",{className:B("inline-flex items-center gap-1.5",s.parse_state==="failed"&&"text-error"),children:[e.jsx(ae,{tone:s.parse_state==="failed"?"error":s.parse_state==="partial"?"warning":"progress"}),e.jsx("span",{"data-testid":"kb-parse-state",children:us[s.parse_state]})]}),s.folder_sync&&e.jsx("span",{"data-testid":"kb-folder-sync",title:s.folder_sync==="following"?"Copied from a synced folder; scans pick up changes to the file":"Edited in ORC; scans no longer change this copy",children:s.folder_sync==="following"?"Follows folder file":"Edited, no longer synced"}),s.stale&&e.jsx("span",{className:"text-warning","data-testid":"kb-document-stale",children:"Stale: a source changed"}),e.jsxs("span",{children:["Updated ",new Date(s.updated_at).toLocaleDateString()," by ",s.updated_by]})]})]}),s.warnings.length>0&&e.jsx("ul",{"data-testid":"kb-document-warnings",className:"mb-2 space-y-1 text-sm text-warning",children:s.warnings.map($=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx(at,{size:14,className:"mt-0.5 shrink-0"}),$]},$))}),Y&&e.jsxs("p",{className:"mb-2 text-sm text-outline",children:["Text parsed from ",s.original_name??"the upload"," (",Ge(s.size_bytes),s.parser?`, ${s.parser.id} ${s.parser.version}`:"","). Replace the file to change it."]}),s.folder_sync==="following"&&(c==="edit"||c==="split")&&e.jsx("p",{role:"status","data-testid":"kb-folder-sync-warning",className:"mb-2 text-sm text-warning",children:"This copy follows a file in a synced folder. Saving here stops it following that file; later changes to the file will not reach it."}),T&&e.jsx("p",{role:"alert","data-testid":"kb-document-error",className:"mb-2 text-sm text-error",children:T}),u&&X.length>0&&e.jsxs("div",{role:"status","data-testid":"kb-rename-broken-links",className:"mb-2 flex flex-wrap items-center gap-x-2 text-sm text-warning",children:[e.jsx(at,{size:14,className:"shrink-0","aria-hidden":!0}),e.jsxs("span",{className:"min-w-0 flex-1",children:[X.length===1?"1 document":`${X.length} documents`," linked to “",u.title,"” by its old title or path; those links now show as missing:"," ",X.map(($,z)=>e.jsxs("span",{children:[z>0&&", ",e.jsx("button",{type:"button",className:"underline underline-offset-2 hover:text-on-surface",onClick:()=>a($.document_id),children:$.title})]},$.document_id))]}),e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>C(null),children:"Dismiss"})]}),e.jsx(Hs,{documentId:He(s.id),path:s.editable?s.path:`${s.path}.md`,content:s.content,wikiLinks:E,testId:"kb-document-content",layout:"page",pageTitle:s.title,hideFrontmatter:!0,onSave:s.editable?async($,z)=>{try{const ee=await M.kb.updateDocument(s.id,{expected_revision:z===s.content?s.revision:N.current,content:$});return N.current=ee.revision,$}finally{await d()}}:void 0},He(s.id))]})}),r&&b&&e.jsx(pt,{doc:s,onOpen:a}),!b&&e.jsx(Mt,{open:r,onOpenChange:o,children:e.jsxs(Tt,{className:"w-[360px]","aria-describedby":void 0,children:[e.jsx(At,{className:"py-3",children:e.jsx(Ft,{children:"Details"})}),e.jsx(It,{className:"p-0 sm:p-0",children:e.jsx(pt,{doc:s,onOpen:($,z)=>{o(!1),a($,z)}})})]})}),e.jsx("input",{ref:v,type:"file",hidden:!0,"data-testid":"kb-doc-replace-input",onChange:$=>{var ee;const z=(ee=$.target.files)==null?void 0:ee[0];z&&l(z),$.target.value=""}}),k&&e.jsx(en,{doc:s,linkedFrom:s.backlinks.length,onClose:()=>j(!1),onSaved:()=>{j(!1),C(P.current)}}),e.jsx(ze,{open:S,title:"Delete document",description:`Delete "${s.title}" and its revision history${Y?" and uploaded file":""}?`,isPending:H,onCancel:()=>g(!1),onConfirm:async()=>{g(!1),await F(()=>M.kb.removeDocument(s.id))&&i()}})]})}function Ke({title:t,children:s}){return e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("h2",{className:"text-sm font-medium text-outline",children:t}),s]})}function pt({doc:t,onOpen:s}){var l;const n=Xs(t.id),a=Zs(t.id),i="block min-h-8 w-full break-words text-left text-primary hover:underline";return e.jsxs("aside",{"data-testid":"kb-document-details","aria-label":"Document details",className:"w-full shrink-0 space-y-6 p-4 text-sm lg:min-h-0 lg:w-80 lg:overflow-y-auto lg:border-l lg:border-outline-variant",children:[t.outline.length>0&&e.jsx(Ke,{title:"On this page",children:e.jsx("nav",{"aria-label":"Outline",className:"space-y-0.5",children:t.outline.map(r=>e.jsx("button",{type:"button",className:"block min-h-7 w-full truncate text-left text-outline hover:text-on-surface",style:{paddingLeft:`${(r.level-1)*.75}rem`},onClick:()=>s(t.id,r.text),children:r.text},`${r.block}-${r.text}`))})}),t.links.length>0&&e.jsx(Ke,{title:`Links to (${t.links.length})`,children:t.links.map(r=>r.document_id?e.jsx("button",{type:"button","data-testid":"kb-outgoing-link",className:i,onClick:()=>s(r.document_id),children:r.title??r.target},r.target):e.jsxs("p",{className:"py-1 text-outline","data-testid":"kb-unresolved-link",children:[r.target," ",e.jsx("span",{className:"text-xs",children:"(no such document)"})]},r.target))}),t.backlinks.length>0&&e.jsx(Ke,{title:`Linked from (${t.backlinks.length})`,children:t.backlinks.map(r=>e.jsx("button",{type:"button","data-testid":"kb-backlink",className:i,onClick:()=>s(r.document_id),children:r.title},r.document_id))}),e.jsx("div",{className:"border-y border-outline-variant",children:e.jsx(cs,{kbId:t.kb_id,documentId:t.id,heading:"h2",compact:!0})}),e.jsxs("details",{"data-testid":"kb-doc-history",className:"group",children:[e.jsxs("summary",{className:"flex min-h-9 cursor-pointer list-none items-center gap-1.5 font-medium [&::-webkit-details-marker]:hidden",children:[e.jsx(Ee,{size:14,"aria-hidden":!0,className:"text-outline transition-transform group-open:rotate-90"}),"Usage and history"]}),e.jsxs("div",{className:"mt-3 space-y-5 pl-5",children:[n.data?e.jsx(mn,{usage:n.data,testId:"kb-doc-usage"}):e.jsx("p",{className:"text-outline",children:n.error?"Usage unavailable":"Loading…"}),e.jsx("ol",{className:"space-y-2","data-testid":"kb-revisions",children:(l=a.data)==null?void 0:l.map(r=>e.jsxs("li",{"data-testid":"kb-revision",children:[e.jsxs("div",{children:["Revision ",r.revision," · ",r.actor,e.jsxs("span",{className:"text-outline",children:[" via ",r.source]})]}),e.jsxs("div",{className:"text-xs text-outline",children:[new Date(r.created_at).toLocaleString(),r.note?` · ${r.note}`:""]})]},r.revision))}),e.jsxs("dl",{className:"grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 text-xs text-outline",children:[e.jsx("dt",{children:"Search"}),e.jsx("dd",{"data-testid":"kb-index-state",children:us[t.index_state]??t.index_state}),e.jsx("dt",{children:"Origin"}),e.jsx("dd",{children:t.origin}),e.jsx("dt",{children:"Type"}),e.jsx("dd",{children:t.media_type}),e.jsx("dt",{children:"Size"}),e.jsx("dd",{children:Ge(t.size_bytes)}),e.jsx("dt",{children:"Updated"}),e.jsxs("dd",{children:[new Date(t.updated_at).toLocaleString()," by ",t.updated_by]}),e.jsx("dt",{children:"ID"}),e.jsx("dd",{className:"break-all font-mono",children:t.id})]})]})]})]})}function ft(t){return`${t.added} added · ${t.updated} updated · ${t.missing} missing${t.errors.length?` · ${t.errors.length} errors: ${t.errors.slice(0,3).join("; ")}`:""}`}const We=(t,s,n)=>`${t} ${t===1?s:n}`;function hn(){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 pn(t){const s=t.document_count-t.edited_count,n=s?`${We(s,"synced copy is","synced copies are")} removed from this knowledge base`:"No synced copies are removed",a=t.edited_count?`; ${We(t.edited_count,"edited copy is","edited copies are")} kept as documents`:"";return`Stop syncing ${t.root_path}? ${n}${a}. Files on disk are not touched.`}function gt(t){return t.replace(/[\\/]+$/,"").split(/[\\/]/).pop()||t}function fn({kb:t}){var R,v;const s=ea(t.id),n=V(),a=Q(),[i,l]=m.useState(!1),[r,o]=m.useState(""),[d,p]=m.useState("**/*.md"),[c,x]=m.useState(null),[k,j]=m.useState(null),[S,g]=m.useState(!1),[h,D]=m.useState(!1),b=s.data??[],u=b.filter(N=>N.last_error).length,C=b.reduce((N,f)=>N+f.document_count,0);function P(){l(!0),g(!0)}function T(){g(!1),o(""),a.setError(null),b.length===0&&l(!1)}async function K(){D(!0),a.setError(null);try{const{path:N}=await M.terminals.pickFolder(r.trim()||void 0);N&&o(N)}catch(N){a.setError(N instanceof Error?N.message:String(N))}finally{D(!1)}}async function H(N){N.preventDefault();const f=await a.run(()=>M.kb.addSource(t.id,{root_path:r.trim(),pattern:d.trim()||"**/*.md"}));f&&(o(""),g(!1),x(ft(f.scan)),await n())}return e.jsxs(Ne,{title:"Synced folders",testId:"kb-folders",toggleTestId:"kb-sources",expanded:i,onExpandedChange:N=>{l(N),g(N&&b.length===0)},summary:s.isLoading?e.jsx("span",{className:"text-outline",children:"Loading…"}):b.length===0?e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-outline","data-testid":"kb-folders-none",children:[e.jsx(ae,{tone:"off"}),"None"]}):e.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1.5","data-testid":"kb-folders-summary",children:[e.jsx(ae,{tone:u?"error":"ok"}),b.length===1?e.jsx("span",{className:"min-w-0 truncate",title:(R=b[0])==null?void 0:R.root_path,children:gt(((v=b[0])==null?void 0:v.root_path)??"")}):`${b.length} folders`,e.jsxs("span",{className:"shrink-0 text-outline",children:["· ",C," ",C===1?"document":"documents",u?` · ${u} failing`:""]})]}),actions:b.length===0&&!i?e.jsx(y,{size:"sm",variant:"outline","data-testid":"kb-folders-add",onClick:P,children:"Add folder"}):null,children:[e.jsxs("div",{className:"min-w-0 space-y-3",children:[e.jsx("p",{className:"max-w-prose text-outline",children:"Matching files are copied in and kept in sync: ORC rescans every minute while the daemon runs, or when you choose Scan now. A copy you edit here stops following its file. ORC never writes to the folder."}),b.length>0&&e.jsx("ul",{className:"divide-y divide-outline-variant","data-testid":"kb-sources-list",children:b.map(N=>e.jsxs("li",{"data-testid":"kb-source-row",className:"flex min-w-0 flex-wrap items-center gap-2 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1 basis-56",children:[e.jsx("div",{className:"font-medium",children:gt(N.root_path)}),e.jsx("div",{className:"break-all font-mono text-xs text-outline",children:N.root_path}),e.jsxs("div",{className:"text-xs text-outline",children:[N.pattern," · ",We(N.document_count,"document","documents"),N.edited_count?` (${N.edited_count} edited)`:""," ·"," ",N.last_scan_at?e.jsxs("span",{title:new Date(N.last_scan_at).toLocaleString(),children:["scanned ",Je(N.last_scan_at)]}):"not scanned yet"]}),N.last_error&&e.jsx("div",{className:"text-xs text-error",children:N.last_error})]}),e.jsxs(y,{variant:"ghost",size:"sm","data-testid":"kb-source-scan",disabled:a.pending,onClick:async()=>{const f=await a.run(()=>M.kb.scanSource(N.id));f&&x(ft(f)),await n()},children:[e.jsx(Vt,{size:14}),"Scan now"]}),e.jsx(y,{variant:"ghost",size:"sm",title:`Stop syncing ${N.root_path}`,"data-testid":"kb-source-remove",onClick:()=>j(N),children:"Stop syncing"})]},N.id))}),c&&e.jsx("p",{role:"status","data-testid":"kb-source-result",className:"text-outline",children:c}),S?e.jsxs("form",{onSubmit:H,className:"min-w-0 space-y-3","data-testid":"kb-source-form",children:[e.jsxs("div",{className:"grid min-w-0 gap-3 sm:grid-cols-[minmax(0,1fr)_12rem]",children:[e.jsx(L,{label:"Folder path",hint:hn(),children:e.jsxs("div",{className:"flex min-w-0 gap-2",children:[e.jsx(U,{"aria-label":"Folder path","data-testid":"kb-source-path-input",value:r,onChange:N=>o(N.target.value),className:"min-w-0 font-mono text-sm",autoFocus:!0}),e.jsxs(y,{type:"button",variant:"outline","data-testid":"kb-source-choose-folder",onClick:K,disabled:h,className:"shrink-0",children:[e.jsx(oa,{size:14}),h?"Choosing…":"Choose folder"]})]})}),e.jsx(L,{label:"File pattern",hint:"e.g. *.md, **/*.md",children:e.jsx(U,{"aria-label":"File pattern","data-testid":"kb-source-pattern-input",value:d,onChange:N=>p(N.target.value),className:"font-mono text-sm"})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(y,{type:"submit",size:"sm",variant:"outline","data-testid":"kb-source-add",disabled:!r.trim()||a.pending,children:"Add folder"}),e.jsx(y,{type:"button",size:"sm",variant:"ghost","data-testid":"kb-source-cancel",onClick:T,children:"Cancel"})]})]}):b.length>0&&e.jsxs(y,{size:"sm",variant:"ghost",className:"-ml-2","data-testid":"kb-folders-add-another",onClick:()=>g(!0),children:[e.jsx($e,{size:14}),"Add another folder"]}),e.jsx(oe,{error:a.error})]}),e.jsx(ze,{open:k!==null,title:"Stop syncing folder",description:k?pn(k):"",confirmLabel:"Stop syncing",variant:"warning",isPending:a.pending,onCancel:()=>j(null),onConfirm:async()=>{const N=k;j(null),N&&await a.run(()=>M.kb.removeSource(N.id)),await n()}})]})}const bt=8;function gn(t,s,n){return n==="title"?t.title.localeCompare(s.title):n==="updated"?t.updated_at-s.updated_at:t.reads-s.reads}function Be(t,s){if(t.key===s)return t.desc?"descending":"ascending"}function bn(t){const s=new Date(t);return s.toDateString()===new Date().toDateString()?s.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):s.toLocaleDateString([],{month:"short",day:"numeric",year:"numeric"})}function jn({kb:t,owner:s,listing:n,label:a,onLabel:i,onOpen:l,onNewDocument:r,onSettings:o}){const d=t.editable_by.includes("mcp");return e.jsxs("div",{"data-testid":"kb-overview",className:"w-full min-w-0 space-y-8 p-4 sm:p-8",children:[e.jsxs("header",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"break-words text-2xl font-medium","data-testid":"kb-overview-name",children:t.name}),t.description&&e.jsx("p",{className:"max-w-prose text-outline",children:t.description}),e.jsxs("p",{className:"text-sm text-outline","data-testid":"kb-overview-meta",children:[s," · ",t.document_count," ",t.document_count===1?"document":"documents"," ·"," ",d?"agents can edit":"agents read only"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(y,{size:"sm","data-testid":"kb-new-document",onClick:r,children:[e.jsx(wa,{size:16}),"New document"]}),e.jsxs(y,{size:"sm",variant:"ghost","data-testid":"kb-settings",onClick:o,children:[e.jsx(Ss,{size:16}),"Settings"]})]})]}),e.jsxs("section",{"aria-labelledby":"kb-setup-heading",className:"space-y-1",children:[e.jsx("h3",{id:"kb-setup-heading",className:"text-sm font-medium text-outline",children:"Setup"}),e.jsxs("div",{className:"divide-y divide-outline-variant border-y border-outline-variant",children:[e.jsx(qa,{kb:t}),e.jsx(fn,{kb:t}),e.jsx(yn,{kb:t,onSettings:o}),e.jsx(vn,{kb:t,onSettings:o}),e.jsx(cs,{kbId:t.id,onOpenDocument:l})]})]}),e.jsx(Nn,{kbId:t.id,onOpen:l}),e.jsx(kn,{listing:n,total:t.document_count,label:a,onLabel:i,onOpen:l,onNewDocument:r})]})}function yn({kb:t,onSettings:s}){const n=t.editable_by.includes("mcp");return e.jsx(Ne,{title:"Who can edit",testId:"kb-access",summary:e.jsxs("span",{className:"inline-flex min-w-0 flex-wrap items-center gap-x-1.5",children:[e.jsx(ae,{tone:n?"ok":"off"}),n?"Agents can edit":"Agents read only",e.jsxs("span",{className:"text-outline",children:["·"," ",t.editable_by.length?t.editable_by.map(a=>ns[a]).join(", "):"nobody, read only everywhere"]})]}),actions:e.jsx(y,{size:"sm",variant:"ghost","data-testid":"kb-access-change",onClick:s,children:"Change"})})}function vn({kb:t,onSettings:s}){var i,l;const n=Ot(),a=t.parser?((l=(i=n.data)==null?void 0:i.parsers.find(r=>r.id===t.parser))==null?void 0:l.label)??t.parser:"Workspace default parser";return e.jsx(Ne,{title:"Uploads",testId:"kb-uploads-setup",summary:e.jsxs("span",{className:"text-outline","data-testid":"kb-uploads-parser",children:[a," · ","PDF, Word, PowerPoint, Excel, HTML, Markdown and text become Markdown"]}),actions:e.jsx(y,{size:"sm",variant:"ghost","data-testid":"kb-parser-change",onClick:s,children:"Change"})})}function kn({listing:t,total:s,label:n,onLabel:a,onOpen:i,onNewDocument:l}){const[r,o]=m.useState(""),[d,p]=m.useState(!1),[c,x]=m.useState({key:"updated",desc:!0}),k=r.trim().toLowerCase(),j=((t==null?void 0:t.documents)??[]).filter(u=>(!n||u.labels.includes(n))&&(!k||u.title.toLowerCase().includes(k)||u.path.toLowerCase().includes(k)||u.labels.some(C=>C.toLowerCase().includes(k)))).sort((u,C)=>gn(u,C,c.key)*(c.desc?-1:1));function S(u){x(C=>C.key===u?{key:u,desc:!C.desc}:{key:u,desc:u!=="title"})}function g(u,C){const P=c.desc?Cs:Ds;return e.jsxs("button",{type:"button","data-testid":`kb-sort-${u}`,className:"inline-flex min-h-8 items-center gap-1 hover:text-on-surface",onClick:()=>S(u),children:[C,c.key===u&&e.jsx(P,{size:12,"aria-hidden":!0})]})}const h=[...(t==null?void 0:t.labels)??[]].sort((u,C)=>C.count-u.count),D=d?h:h.filter((u,C)=>C<bt||u.label===n),b=h.length-D.length;return e.jsxs("section",{"aria-labelledby":"kb-documents-heading","data-testid":"kb-documents",className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("h3",{id:"kb-documents-heading",className:"mr-auto text-sm font-medium text-outline",children:["Documents",n?` labelled ${n}`:""]}),s>0&&e.jsx(U,{"aria-label":"Filter documents","data-testid":"kb-documents-filter",placeholder:"Filter by title, path or label",value:r,onChange:u=>o(u.target.value),className:"h-9 w-full sm:w-64"})]}),D.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5","data-testid":"kb-labels",children:[e.jsx("span",{className:"mr-1 text-xs text-outline",children:"Label"}),D.map(u=>e.jsxs("button",{type:"button","data-testid":"kb-label-filter","aria-pressed":n===u.label,className:B("min-h-8 rounded-full border px-2.5 text-xs",n===u.label?"border-primary bg-primary/10 text-primary":"border-outline-variant text-outline hover:text-on-surface"),onClick:()=>a(n===u.label?null:u.label),children:[u.label," ",e.jsx("span",{className:"tabular-nums",children:u.count})]},u.label)),(b>0||d)&&h.length>bt&&e.jsx("button",{type:"button","data-testid":"kb-labels-more",className:"min-h-8 px-2 text-xs text-primary hover:underline",onClick:()=>p(!d),children:d?"Fewer labels":`${b} more`})]}),s===0?e.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 rounded-md border border-dashed border-outline-variant px-6 py-10 text-center text-sm text-outline",children:[e.jsx(Ht,{size:22,className:"text-primary","aria-hidden":!0}),e.jsx("span",{children:"This knowledge base is empty. Drop PDF, Word, PowerPoint, Excel, HTML, Markdown or text files here, or"}),e.jsx(y,{size:"sm",variant:"outline",onClick:l,"data-testid":"kb-overview-new-document",children:"add a document"})]}):e.jsxs(e.Fragment,{children:[j.length===0&&t&&e.jsxs("p",{className:"py-4 text-sm text-outline","data-testid":"kb-documents-empty",children:["No documents match."," ",e.jsx("button",{type:"button","data-testid":"kb-documents-clear",className:"text-primary hover:underline",onClick:()=>{o(""),a(null)},children:"Clear filters"})]}),j.length>0&&e.jsxs("table",{className:"w-full table-fixed text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-outline-variant text-left text-xs text-outline",children:[e.jsx("th",{className:"py-1 pr-3 font-normal","aria-sort":Be(c,"title"),children:g("title","Title")}),e.jsx("th",{className:"hidden w-[30%] py-2 pr-3 font-normal md:table-cell",children:"Labels"}),e.jsx("th",{className:"w-24 py-1 pr-3 font-normal sm:w-28","aria-sort":Be(c,"updated"),children:g("updated","Updated")}),e.jsx("th",{className:"hidden w-16 py-1 text-right font-normal sm:table-cell","aria-sort":Be(c,"reads"),children:g("reads","Reads")})]})}),e.jsx("tbody",{children:j.map(u=>e.jsxs("tr",{className:"cursor-pointer border-b border-outline-variant/60 align-top hover:bg-surface-high",onClick:()=>i(u.id),children:[e.jsxs("td",{className:"min-w-0 py-2 pr-3",children:[e.jsxs("button",{type:"button","data-testid":"kb-document-row","data-document-title":u.title,className:"flex w-full min-w-0 items-center gap-1.5 text-left font-medium hover:text-primary",onClick:C=>{C.stopPropagation(),i(u.id)},children:[e.jsx("span",{className:"min-w-0 truncate",children:u.title}),u.origin==="external"&&e.jsx(Vt,{size:13,className:"shrink-0 text-outline","aria-label":"From a synced folder"})]}),e.jsx("span",{className:"block truncate font-mono text-xs text-outline",children:u.path}),(u.parse_state==="pending"||u.parse_state==="failed")&&e.jsx("span",{className:B("text-xs",u.parse_state==="failed"?"text-error":"text-outline"),children:u.parse_state==="failed"?"Parsing failed":"Parsing…"})]}),e.jsx("td",{className:"hidden py-2 pr-3 text-xs text-outline md:table-cell",children:e.jsx("span",{className:"line-clamp-2",children:u.labels.join(", ")})}),e.jsx("td",{className:"py-2 pr-3 text-xs text-outline tabular-nums",children:bn(u.updated_at)}),e.jsx("td",{className:"hidden py-2 text-right text-xs text-outline tabular-nums sm:table-cell",children:u.reads||""})]},u.id))})]}),e.jsx("p",{className:"text-xs text-outline",children:"Drop files anywhere on this page to upload."})]})]})}function Nn({kbId:t,onOpen:s}){const n=ta(t).data;return!n||!(n.stale.length||n.failed.length||n.unresolved_links.length)?null:e.jsxs("section",{"data-testid":"kb-maintenance",className:"space-y-1 text-sm",children:[e.jsx("h3",{className:"text-sm font-medium text-outline",children:"Needs attention"}),e.jsxs("ul",{className:"space-y-1",children:[n.failed.map(a=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"text-left text-error hover:underline",onClick:()=>s(a.id),children:["Parsing failed: ",a.title]})},a.id)),n.stale.map(a=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"text-left text-warning hover:underline",onClick:()=>s(a.id),children:["Stale summary: ",a.title]})},a.id)),n.unresolved_links.map(a=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"text-left text-outline hover:underline",onClick:()=>s(a.document_id),children:["[[",a.target,"]] in ",a.title," has no target"]})},`${a.document_id}-${a.target}`))]})]})}function wn(){const t=V(),[s,n]=m.useState([]),a=m.useRef(1),i=(o,d)=>n(p=>p.map(c=>c.id===o?{...c,...d}:c));async function l(o){i(o.id,{status:"uploading",progress:0,error:void 0});try{const d=await M.kb.upload(o.kbId,{file:o.file,...o.replace},p=>i(o.id,{progress:p}));i(o.id,{status:"done",progress:1,document:d}),await t()}catch(d){i(o.id,{status:"failed",error:d instanceof Error?d.message:"Upload failed"})}}function r(o,d,p={}){const c=d.map(x=>({id:a.current++,kbId:o,file:x,...p.replace?{replace:p.replace}:{},progress:0,status:"uploading"}));n(x=>[...x,...c]);for(const x of c)l(x)}return{uploads:s,add:r,retry:o=>{const d=s.find(p=>p.id===o);d&&l(d)},clearFinished:()=>n(o=>o.filter(d=>d.status==="uploading"))}}const jt="all",_n=200,yt=[{value:"reads",label:"Most read"},{value:"recent",label:"Recent"},{value:"priority",label:"Priority"}];function Te(t){return new Date(t*1e3).toLocaleString()}function Sn({projectId:t}){var N;const s=$s(),n=Kt(),{memoryProject:a,memoryName:i}=Es(),[l,r]=Ae("project",t),[o,d]=Ae("memoryQuery",""),[p,c]=Ae("memorySort","reads",yt.map(f=>f.value)),[x,k]=m.useState(o);m.useEffect(()=>k(o),[o]);const[j,S]=m.useState(null),[g,h]=m.useState(null),{data:D}=ke({status:"active"}),b=xa(),u=l==="unassigned",C=l===jt,P=ha({project_id:C?void 0:l,q:o||void 0,sort:p,limit:_n},{enabled:!u}),T=((N=P.data)==null?void 0:N.memories)??[],K=f=>{var E;return((E=D==null?void 0:D.find(F=>F.id===f))==null?void 0:E.name)??f},H=T.find(f=>f.project_id===a&&f.name===i),R=f=>s(`${Ms(f.project_id,f.name)}${n.search}`),v=()=>s(`${Ts}${n.search}`);return e.jsxs("div",{children:[e.jsx(Ps,{title:"Memories",meta:P.data?`${P.data.total} ${P.data.total===1?"memory":"memories"}`:void 0,action:e.jsxs(y,{"data-testid":"new-memory-button",size:"sm",onClick:()=>S("new"),className:"font-label text-sm",children:[e.jsx($e,{size:12,className:"mr-1"})," New memory"]})}),e.jsx("p",{className:"mb-4 text-sm leading-relaxed text-muted-foreground",children:"Short project facts agents load next session: ports, conventions, gotchas, decisions. Longer procedures belong in a skill."}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 mb-4",children:[e.jsxs(he,{value:l,onValueChange:f=>r(f),children:[e.jsx(pe,{"aria-label":"Project","data-testid":"memory-project-filter",className:"h-9 w-48 bg-background text-on-surface font-body text-sm",children:e.jsx(fe,{})}),e.jsxs(ge,{className:"bg-surface border-outline-variant",children:[e.jsx(J,{value:jt,className:"font-body text-sm",children:"All projects"}),u&&e.jsx(J,{value:"unassigned",className:"font-body text-sm",children:"Unassigned"}),D==null?void 0:D.map(f=>e.jsx(J,{value:f.id,"data-testid":`memory-project-option-${f.id}`,className:"font-body text-sm",children:f.name},f.id))]})]}),e.jsx("div",{className:"flex shrink-0 flex-wrap gap-1.5",children:yt.map(f=>e.jsx("button",{type:"button",onClick:()=>c(f.value),"data-testid":`memory-sort-${f.value}`,"aria-pressed":p===f.value,className:`font-label text-sm px-3 py-1.5 border transition-colors ${p===f.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:f.label},f.value))}),e.jsxs("div",{className:"relative min-w-[160px] flex-1",children:[e.jsx(Bt,{size:12,className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground"}),e.jsx(U,{"aria-label":"Search memories","data-testid":"memory-search-input",value:x,onChange:f=>k(f.target.value),onKeyDown:f=>f.key==="Enter"&&d(f.currentTarget.value),placeholder:"Search memories...",className:"pl-8 bg-background text-on-surface font-body text-sm placeholder:text-muted-foreground"})]}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>d(x),className:"font-label text-sm",children:"Search"})]}),u?e.jsx(nt,{message:"Memories belong to a project. Choose a project to see its memories."}):P.error?e.jsx(Qe,{message:P.error.message,onRetry:()=>void P.refetch()}):P.isLoading?e.jsx("div",{className:"space-y-2",children:[...Array(5)].map((f,E)=>e.jsx(Ye,{className:"h-10 w-full bg-surface-highest"},E))}):T.length===0?e.jsx(nt,{message:o?"No memories match your search":"No memories yet"}):e.jsx("div",{className:"overflow-hidden",children:e.jsxs(Rs,{children:[e.jsx(zs,{children:e.jsxs(it,{className:"border-b border-outline-variant hover:bg-transparent",children:[e.jsx(de,{className:"font-label text-sm text-muted-foreground",children:"Name"}),e.jsx(de,{className:"font-label text-sm text-muted-foreground",children:"Description"}),C&&e.jsx(de,{className:"font-label text-sm text-muted-foreground",children:"Project"}),e.jsx(de,{className:"font-label text-sm text-muted-foreground w-20",children:"Priority"}),e.jsx(de,{className:"font-label text-sm text-muted-foreground w-16",children:"Reads"}),e.jsx(de,{className:"font-label text-sm text-muted-foreground w-44",children:"Updated"})]})}),e.jsx(Ls,{children:T.map(f=>e.jsxs(it,{"data-testid":"memory-row","data-memory-name":f.name,"data-memory-project":f.project_id,className:"border-b border-outline-variant/50 hover:bg-surface-low cursor-pointer",onClick:()=>R(f),children:[e.jsx(ce,{className:"font-body text-sm font-medium text-on-surface",children:e.jsx("button",{type:"button",className:"min-h-11 text-left hover:text-primary",onClick:E=>{E.stopPropagation(),R(f)},children:f.name})}),e.jsx(ce,{className:"font-body text-sm text-muted-foreground max-w-md truncate",children:f.description}),C&&e.jsx(ce,{className:"font-body text-sm text-muted-foreground",children:K(f.project_id)}),e.jsx(ce,{children:e.jsx(xs,{priority:f.priority})}),e.jsx(ce,{"data-testid":"memory-read-count",className:"font-label text-sm text-muted-foreground",title:ms(f),children:f.read_count}),e.jsx(ce,{className:"font-label text-sm text-muted-foreground",children:Te(f.updated_at)})]},f.key))})]})}),a&&i&&e.jsx(Cn,{projectId:a,name:i,projectName:K(a),listItem:H,onClose:v,onEdit:S,onDelete:h},`${a}/${i}`),j&&e.jsx($n,{memory:j==="new"?null:j,defaultProjectId:C||u?"":l,onClose:()=>S(null),onCreated:f=>R(f)}),g&&e.jsx(ze,{open:!0,title:"Delete memory",description:`Delete "${g.name}"? It can be restored from its history.`,confirmLabel:"Delete",variant:"destructive",isPending:b.isPending,onConfirm:()=>b.mutate({projectId:g.project_id,name:g.name},{onSuccess:()=>{h(null),v()}}),onCancel:()=>h(null)}),b.error&&e.jsx("p",{role:"alert",className:"text-sm text-destructive mt-2",children:b.error.message})]})}function ms(t){const{mcp:s,cli:n,api:a,ui:i}=t.reads_by_source,l=t.last_read_at?` · last read ${Te(t.last_read_at)}`:"";return`mcp ${s} · cli ${n} · api ${a} · ui ${i}${l}`}function xs({priority:t}){return t===null?e.jsx("span",{"data-testid":"memory-priority",className:"font-label text-xs text-outline",children:"Unscored"}):e.jsxs("span",{"data-testid":"memory-priority",className:"font-label text-xs text-primary",children:["P",t]})}function Cn({projectId:t,name:s,projectName:n,listItem:a,onClose:i,onEdit:l,onDelete:r}){const{data:o,isLoading:d,error:p,refetch:c}=pa(t,s);return e.jsx(Mt,{open:!0,onOpenChange:x=>!x&&i(),children:e.jsxs(Tt,{"data-testid":"memory-detail",className:"w-screen max-w-full sm:w-[860px] sm:max-w-[96vw]",children:[e.jsxs(At,{children:[e.jsx(Ft,{children:s}),o&&e.jsx("p",{"data-testid":"memory-detail-description",className:"font-body text-sm text-muted-foreground mt-1",children:o.description})]}),e.jsx(It,{children:p?e.jsx(Qe,{message:p.message,onRetry:()=>void c()}):d||!o?e.jsx("div",{className:"space-y-3",children:[...Array(4)].map((x,k)=>e.jsx(Ye,{className:"h-8 w-full bg-surface-highest"},k))}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(y,{"data-testid":"memory-edit",size:"sm",variant:"outline",onClick:()=>l(o),children:[e.jsx(Wt,{size:12,className:"mr-1"})," Edit"]}),e.jsxs(y,{"data-testid":"memory-delete",size:"sm",variant:"outline",onClick:()=>r(o),children:[e.jsx(Re,{size:12,className:"mr-1"})," Delete"]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsx(ue,{label:"Project",children:n}),e.jsx(ue,{label:"Priority",children:e.jsx(xs,{priority:o.priority})}),e.jsx(ue,{label:"Reads",children:a?e.jsx("span",{title:ms(a),children:a.read_count}):"—"}),e.jsx(ue,{label:"Author",children:e.jsx("span",{"data-testid":"memory-detail-author",children:o.author})}),e.jsx(ue,{label:"Session",children:e.jsx("code",{className:"font-mono text-xs break-all",children:o.session_id??"—"})}),e.jsx(ue,{label:"Updated",children:Te(o.updated_at)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-sm text-muted-foreground mb-2",children:"Content"}),e.jsx("div",{"data-testid":"memory-detail-content",className:"whitespace-pre-wrap break-words font-body text-sm text-on-surface border border-outline-variant p-3",children:o.content})]}),e.jsx(Dn,{projectId:t,name:s,onDeleted:i})]})})]})})}function vt({label:t,snapshot:s}){return e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-outline mt-2",children:t}),s?e.jsxs("div",{className:"text-xs space-y-1",children:[e.jsxs("p",{children:[e.jsx("span",{className:"text-outline",children:"Priority:"})," ",s.priority===null?"unscored":s.priority]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-outline",children:"Description:"})," ",s.description]}),e.jsx("pre",{className:"whitespace-pre-wrap break-all",children:s.content})]}):e.jsx("p",{className:"text-xs italic text-muted-foreground",children:"(none)"})]})}function Dn({projectId:t,name:s,onDeleted:n}){var p;const a=ja(t,s),i=ya(),[l,r]=m.useState(""),o=((p=a.data)==null?void 0:p.changes)??[],d=o[0];return e.jsxs("section",{"data-testid":"memory-history-panel",className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:"History"}),a.error&&e.jsx("p",{role:"alert",children:a.error.message}),i.error&&e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:i.error.message}),o.length>1&&e.jsx(U,{"data-testid":"memory-revert-reason","aria-label":"Reason for reverting",value:l,onChange:c=>r(c.target.value),placeholder:"Reason for reverting..."}),o.map(c=>e.jsxs("details",{"data-testid":"memory-history-change",className:"border-b border-outline-variant p-3",children:[e.jsxs("summary",{className:"text-xs cursor-pointer",children:[c.action.replace("memory.","")," · ",Te(c.created_at)," ·"," ",c.author,c.session_id?` · ${c.session_id}`:"",c.reason?` · ${c.reason}`:""]}),e.jsx(vt,{label:"Before",snapshot:c.previous}),e.jsx(vt,{label:"After",snapshot:c.current}),d&&c.previous&&e.jsx(y,{"data-testid":"memory-revert-change",size:"sm",variant:"outline",className:"mt-2",disabled:!l.trim()||i.isPending,onClick:()=>i.mutate({name:s,project_id:t,change_id:c.id,expected_change_id:d.id,reason:l.trim()},{onSuccess:({memory:x})=>{r(""),x||n()}}),children:"Restore state before this change"})]},c.id))]})}function Ve(t){return[...t].length}function kt({value:t,max:s,testId:n}){const a=Ve(t);return e.jsx("span",{"data-testid":n,className:`text-xs ${s!==void 0&&a>s?"text-destructive":"text-muted-foreground"}`,children:s===void 0?a:`${a}/${s}`})}function $n({memory:t,defaultProjectId:s,onClose:n,onCreated:a}){var R;const{data:i}=ke({status:"active"}),[l,r]=m.useState((t==null?void 0:t.project_id)??s),[o,d]=m.useState((t==null?void 0:t.name)??""),[p,c]=m.useState((t==null?void 0:t.description)??""),[x,k]=m.useState((t==null?void 0:t.content)??""),[j,S]=m.useState((t==null?void 0:t.priority)===null||(t==null?void 0:t.priority)===void 0?"":String(t.priority)),[g,h]=m.useState(""),D=fa(),b=ga(),u=(R=ba().data)==null?void 0:R.content_max,C=t?b:D,P=j.trim()===""?null:Number(j),T=P===null||Number.isInteger(P)&&P>=0&&P<=Ce,K=!!l&&!!o.trim()&&!!p.trim()&&Ve(p)<=rt&&!!x.trim()&&(u===void 0||Ve(x)<=u)&&T;function H(){if(!K||C.isPending)return;if(!t){D.mutate({project_id:l,name:o.trim(),description:p.trim(),content:x.trim(),priority:P},{onSuccess:N=>{n(),a(N)}});return}const v={...p.trim()!==t.description&&{description:p.trim()},...x.trim()!==t.content&&{content:x.trim()},...P!==t.priority&&{priority:P}};if(Object.keys(v).length===0){n();return}b.mutate({name:t.name,project_id:t.project_id,...v,...g.trim()&&{reason:g.trim()}},{onSuccess:n})}return e.jsx($t,{open:!0,onOpenChange:v=>!v&&!C.isPending&&n(),children:e.jsxs(Et,{"data-testid":"memory-form-dialog",className:"bg-surface border-outline-variant w-[calc(100%_-_1rem)] max-w-2xl max-h-[94dvh] overflow-y-auto",children:[e.jsx(Pt,{children:e.jsx(Rt,{className:"font-headline text-base text-on-surface",children:t?`Edit ${t.name}`:"New memory"})}),e.jsxs("form",{onSubmit:v=>{v.preventDefault(),H()},className:"space-y-3 mt-2",children:[!t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(ie,{className:"font-label text-sm text-muted-foreground",children:"Project *"}),e.jsxs(he,{value:l,onValueChange:r,children:[e.jsx(pe,{"aria-label":"Memory project","data-testid":"memory-project-select",className:"bg-background text-on-surface font-body text-sm h-9",children:e.jsx(fe,{placeholder:"Choose a project"})}),e.jsx(ge,{className:"bg-surface border-outline-variant",children:i==null?void 0:i.map(v=>e.jsx(J,{value:v.id,className:"font-body text-sm",children:v.name},v.id))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(ie,{className:"font-label text-sm text-muted-foreground",children:"Name *"}),e.jsx(U,{"aria-label":"Name","data-testid":"memory-name-input",value:o,onChange:v=>d(v.target.value),placeholder:"api-port",maxLength:64,className:"bg-background text-on-surface font-body text-sm",autoFocus:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Lowercase words joined by hyphens, unique in the project."})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ie,{className:"font-label text-sm text-muted-foreground",children:"Description *"}),e.jsx(kt,{value:p,max:rt,testId:"memory-description-count"})]}),e.jsx(xe,{"aria-label":"Description","data-testid":"memory-description-input",value:p,onChange:v=>c(v.target.value),placeholder:"One line agents see in lists and context",className:"bg-background text-on-surface font-body text-sm resize-none",rows:2})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ie,{className:"font-label text-sm text-muted-foreground",children:"Content *"}),e.jsx(kt,{value:x,max:u,testId:"memory-content-count"})]}),e.jsx(xe,{"aria-label":"Content","data-testid":"memory-content-input",value:x,onChange:v=>k(v.target.value),placeholder:"The fact itself. Longer guidance belongs in a skill.",className:"bg-background text-on-surface font-body text-sm",rows:6})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(ie,{className:"font-label text-sm text-muted-foreground",children:["Priority (0-",Ce,", empty = unscored)"]}),e.jsx(U,{"aria-label":"Priority","data-testid":"memory-priority-input",type:"number",min:0,max:Ce,step:1,value:j,onChange:v=>S(v.target.value),className:"w-32 bg-background text-on-surface font-body text-sm"}),!T&&e.jsxs("p",{className:"text-xs text-destructive",children:["Priority must be a whole number from 0 to ",Ce,"."]})]}),t&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(ie,{className:"font-label text-sm text-muted-foreground",children:"Reason"}),e.jsx(U,{"aria-label":"Reason","data-testid":"memory-reason-input",value:g,onChange:v=>h(v.target.value),placeholder:"Why this changed (optional)",className:"bg-background text-on-surface font-body text-sm"})]}),C.error&&e.jsx("p",{role:"alert","data-testid":"memory-form-error",className:"text-sm text-destructive",children:C.error.message}),e.jsxs(le,{children:[e.jsx(y,{type:"button",variant:"ghost",size:"sm",onClick:n,disabled:C.isPending,className:"font-label text-sm text-muted-foreground",children:"Cancel"}),e.jsx(y,{"data-testid":"memory-submit",type:"submit",size:"sm",disabled:!K||C.isPending,className:"font-label text-sm",children:C.isPending?"Saving...":t?"Save":"Create"})]})]})]})})}function Qn({projectId:t}){const s=ma(t),{pathname:n}=Kt();return n.startsWith("/knowledge/memories")?e.jsx("div",{"data-testid":"knowledge-base-view",children:e.jsx(Sn,{projectId:t,embedded:!0})}):e.jsx("div",{"data-testid":"knowledge-base-view",className:"flex min-h-0 min-w-0 flex-1",children:e.jsx(Pn,{projectId:s==="all"||s==="unassigned"?void 0:s},s)})}function hs(t){return t.replace(/```[\w-]*/g," ").replace(/<\/?[a-z][^>]*>/gi," ").replace(/!?\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/(^|\s)#{1,6}\s+/g,"$1").replace(/(^|\n)\s*(?:>\s*)+/g,"$1").replace(/(^|\n)\s*(?:[-*+]|\d+[.)])\s+/g,"$1").replace(/\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?/g," ").replace(/(^|\s)(?:\*{3,}|_{3,})(?=\s|$)/g,"$1").replace(/`/g,"").replace(/(^|[\s(«])[*_~]+(?=\S)/g,"$1").replace(/(\S)[*_~]+(?=$|[\s).,;:!?»])/g,"$1").replace(/\s*\|[\s|]*/g," · ").replace(/\s+/g," ").replace(/^ · | · $/g,"").trim()}function En({text:t}){const s=hs(t).split(/«([^»]*)»/g);return e.jsx(e.Fragment,{children:s.map((n,a)=>a%2?e.jsx("mark",{className:"rounded-sm bg-primary/20 px-0.5 text-on-surface",children:n},a):e.jsx(m.Fragment,{children:n},a))})}function Pn({projectId:t}){var Se,Xe,Ze;const[s,n]=zt(),a=s.get("kb"),i=s.get("document"),l=s.get("label")??"",r=s.get("q")??"",o=s.get("searchAll")==="1",[d,p]=m.useState(r);m.useEffect(()=>p(r),[r]);const[c,x]=m.useState(null),[k,j]=m.useState(!1),S=Lt("lg"),[g,h]=m.useState(()=>typeof window<"u"&&window.innerWidth>=1600),[D,b]=m.useState(!1),[u,C]=m.useState(null),[P,T]=m.useState();function K(){x(null),T(void 0)}const H=ke(),R=sa(t),v=((Se=R.data)==null?void 0:Se.find(w=>w.id===a))??null,N=Le((v==null?void 0:v.id)??null),f=aa(i),E=R.data!==void 0&&(v!==null||R.data.length===0),F=na(r&&E?{query:r,...v&&!o?{kb_ids:[v.id]}:{},scope:t?"default":"all",limit:20}:null,t),G=wn();function I(w,A=!1){n(()=>{const te=new URLSearchParams(window.location.search);for(const[ne,et]of Object.entries(w))et?te.set(ne,et):te.delete(ne);return te},{replace:A})}const Y=()=>!i||Ws(He(i));function je(w){j(!1),!(w===a&&!i&&!r||!Y())&&(w!==a&&G.clearFinished(),I({kb:w,document:null,label:null,q:null}))}function X(w,A){j(!1),!(w!==i&&!Y())&&(I({document:w,q:null}),C(A??null))}function Z(w,A){I({document:w}),C(A??null)}function we(){j(!1);const w=d.trim();if(!w)return I({q:null});Y()&&I({q:w,document:null})}m.useEffect(()=>{S&&j(!1)},[S]),m.useEffect(()=>{R.data&&(a&&!R.data.some(w=>w.id===a)&&!i?I({kb:null},!0):!a&&R.data[0]&&I({kb:R.data[0].id},!0))}),m.useEffect(()=>{var w;f.data&&f.data.kb_id!==a&&((w=R.data)!=null&&w.some(A=>A.id===f.data.kb_id))&&I({kb:f.data.kb_id,label:null},!0)}),m.useEffect(()=>{if(!u||!f.data)return;const w=document.querySelector('[data-testid="kb-document"]'),A=[...(w==null?void 0:w.querySelectorAll("h1,h2,h3,h4,h5,h6"))??[]].find(te=>{var ne;return((ne=te.textContent)==null?void 0:ne.trim())===u});A&&(A.scrollIntoView({block:"start"}),C(null))});function $(w){w.preventDefault(),b(!1);const A=[...w.dataTransfer.files];!v||A.length===0||(A.length>1?G.add(v.id,A):(T(A[0]),x("new-document")))}const z=w=>{var A,te;return w===null?"Global":((te=(A=H.data)==null?void 0:A.find(ne=>ne.id===w))==null?void 0:te.name)??"Project"};if(R.error)return e.jsx(Qe,{message:R.error.message,onRetry:()=>R.refetch()});const ee=i?f.data&&v?e.jsx(xn,{kb:v,doc:f.data,detailsOpen:g,onDetailsOpenChange:h,onHome:()=>je(v.id),onOpen:X,onDeleted:()=>I({document:null}),onReplaceFile:w=>f.data&&G.add(f.data.kb_id,[w],{replace:{document_id:f.data.id,expected_revision:f.data.revision}})},f.data.id):f.error?e.jsxs(Ue,{children:[e.jsx("p",{role:"alert","data-testid":"kb-document-error",className:"text-sm text-error",children:f.error.message}),e.jsx(y,{variant:"outline",onClick:()=>I({document:null}),children:"Back"})]}):e.jsx(Ue,{children:e.jsx("p",{role:"status",className:"text-sm text-outline",children:"Loading document…"})}):r?e.jsx(Nt,{children:e.jsx(Ln,{query:r,search:F,onOpen:Z,onClear:()=>I({q:null})})}):v?e.jsx(Nt,{children:e.jsx(jn,{kb:v,owner:z(v.project_id),listing:N.data,label:l,onLabel:w=>I({label:w}),onOpen:X,onNewDocument:()=>x("new-document"),onSettings:()=>x("settings")})}):((Xe=R.data)==null?void 0:Xe.length)===0?e.jsxs(Ue,{testId:"empty-state",children:[e.jsx(Ut,{size:28,className:"text-primary"}),e.jsx("h2",{className:"text-xl font-medium",children:"Build a knowledge base"}),e.jsx("p",{className:"max-w-md text-outline",children:"Upload documents, write Markdown or sync a folder. Agents search it with citations through MCP, the CLI and the API, and you can see what they read."}),e.jsxs(y,{"data-testid":"kb-empty-create",onClick:()=>x("create"),children:[e.jsx($e,{size:16}),"New knowledge base"]})]}):null,_e=e.jsxs("nav",{id:"kb-sidebar-panel","aria-label":"Knowledge bases","data-testid":"kb-sidebar",className:"flex h-full min-h-0 flex-col border-outline-variant bg-background lg:w-72 lg:shrink-0 lg:border-r",children:[e.jsxs("form",{className:"flex shrink-0 items-center gap-1.5 border-b border-outline-variant p-3",onSubmit:w=>{w.preventDefault(),we()},children:[e.jsx(U,{"aria-label":"Search knowledge","data-testid":"kb-search-input",value:d,onChange:w=>p(w.target.value),placeholder:v&&!o?`Search ${v.name}`:"Search everything",className:"h-9 min-w-0 flex-1"}),e.jsx(y,{type:"submit",size:"icon",variant:"ghost","data-testid":"kb-search-submit","aria-label":"Search",children:e.jsx(Bt,{size:16})}),k&&e.jsx(y,{type:"button",size:"icon",variant:"ghost","data-testid":"kb-browser-close","aria-label":"Close knowledge browser",onClick:()=>j(!1),children:e.jsx(Pe,{size:16})})]}),v&&e.jsxs("label",{className:"flex shrink-0 items-center gap-2 border-b border-outline-variant px-3 py-2 text-xs text-outline",children:[e.jsx("input",{type:"checkbox","data-testid":"kb-search-all",checked:o,onChange:w=>I({searchAll:w.target.checked?"1":null})}),"Search all knowledge bases"]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:[e.jsxs("div",{className:"flex items-center justify-between px-2 pb-1",children:[e.jsx("h2",{className:"text-sm font-medium text-outline",children:"Knowledge bases"}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":"New knowledge base","data-testid":"kb-create",onClick:()=>x("create"),children:e.jsx($e,{size:16})})]}),R.isLoading&&e.jsx(Ye,{className:"mx-2 h-9"}),e.jsx(Rn,{bases:R.data??[],projectName:z,kbId:a,documentId:i,documents:((Ze=N.data)==null?void 0:Ze.documents)??[],onSelectKb:je,onOpenDocument:X})]}),e.jsx(zn,{})]});return e.jsx(As,{open:k&&!S,onOpenChange:j,children:e.jsxs("div",{"data-testid":"knowledge-bases",className:"relative flex min-h-0 min-w-0 flex-1",children:[e.jsx("h1",{"data-testid":"view-title",className:"sr-only",children:"Knowledge bases"}),S&&_e,!S&&e.jsxs(Fs,{children:[e.jsx(Is,{className:"fixed inset-0 z-50 bg-black/70"}),e.jsxs(Ks,{"data-testid":"kb-mobile-browser",className:"viewport-sheet fixed inset-x-0 z-50 bg-background",children:[e.jsx(Bs,{className:"sr-only",children:"Browse knowledge"}),e.jsx(Us,{className:"sr-only",children:"Search knowledge bases and choose a document"}),_e]})]}),e.jsxs("div",{"data-testid":"kb-dropzone",className:B("relative flex min-h-0 min-w-0 flex-1 flex-col",D&&"outline-2 -outline-offset-4 outline-dashed outline-primary"),onDragOver:w=>{v&&(w.preventDefault(),b(!0))},onDragLeave:()=>b(!1),onDrop:$,children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-outline-variant px-3 py-2 lg:hidden",children:[e.jsx(Os,{asChild:!0,children:e.jsxs(y,{"data-testid":"kb-browser-open",variant:"ghost",size:"sm","aria-expanded":k,"aria-controls":"kb-sidebar-panel",onClick:()=>j(!0),children:[e.jsx(qs,{size:16}),"Browse"]})}),v&&e.jsx("span",{className:"min-w-0 truncate text-sm text-outline",children:v.name})]}),i&&r&&e.jsx("div",{className:"flex shrink-0 items-center border-b border-outline-variant px-3 py-1",children:e.jsxs(y,{variant:"ghost",size:"sm","data-testid":"kb-search-back",className:"min-w-0",onClick:()=>Y()&&I({document:null}),children:[e.jsx(da,{size:14}),e.jsxs("span",{className:"truncate",children:["Back to results for “",r,"”"]})]})}),e.jsx("div",{className:"flex min-h-0 min-w-0 flex-1",children:ee}),e.jsx(Mn,{uploads:G,onOpen:X})]}),c==="create"&&e.jsx(Ya,{open:!0,projectId:t,onClose:()=>x(null),onCreated:w=>{x(null),j(!1),I({kb:w.id,document:null,label:null,q:null})}}),c==="settings"&&v&&e.jsx(Ja,{kb:v,onClose:()=>x(null),onDeleted:()=>{x(null),I({kb:null,document:null,label:null})}}),c==="new-document"&&v&&e.jsx(Za,{kb:v,initialFile:P,onClose:K,onUploadMany:w=>{K(),G.add(v.id,w)},onCreated:(w,A)=>{K(),I({document:w.id,editorMode:A?null:"edit"})}})]})})}function Rn({bases:t,projectName:s,kbId:n,documentId:a,documents:i,onSelectKb:l,onOpenDocument:r}){const[o,d]=m.useState(null);m.useEffect(()=>{a&&d(null)},[a]);const p=new Map;for(const x of t){const k=s(x.project_id);p.set(k,[...p.get(k)??[],x])}const c=[...p.entries()].sort(([x],[k])=>x==="Global"?-1:k==="Global"?1:x.localeCompare(k));return e.jsx("div",{"data-testid":"kb-list",className:"space-y-3",children:c.map(([x,k])=>e.jsxs("section",{"aria-label":x,children:[c.length>1&&e.jsx("h3",{className:"truncate px-2 pb-0.5 pt-1 text-xs text-outline",children:x}),e.jsx("ul",{className:"space-y-0.5",children:k.map(j=>{const S=j.id===n,g=S&&o!==j.id&&i.length>0;return e.jsxs("li",{children:[e.jsxs("button",{type:"button","data-testid":"kb-row","data-kb-name":j.name,"aria-current":S&&!a?"page":void 0,"aria-expanded":g,className:B("flex min-h-9 w-full items-center gap-2 rounded-md px-2 text-left text-sm hover:bg-surface-high",S&&"font-medium",S&&!a&&"bg-surface-high"),onClick:()=>{S&&d(h=>h===j.id?null:j.id),l(j.id)},children:[e.jsx(Ee,{size:14,"aria-hidden":!0,className:B("-mr-1 shrink-0 text-outline transition-transform motion-reduce:transition-none",g&&"rotate-90",j.document_count===0&&"invisible")}),e.jsx(Ut,{size:15,className:"shrink-0 text-outline","aria-hidden":!0}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:j.name}),e.jsx("span",{className:"text-xs font-normal tabular-nums text-outline",children:j.document_count})]}),g&&e.jsx("ul",{className:"ml-4 mt-0.5 space-y-0.5 border-l border-outline-variant pl-2",children:i.map(h=>e.jsx("li",{children:e.jsxs("button",{type:"button","data-testid":"kb-nav-document","data-document-title":h.title,"aria-current":h.id===a?"page":void 0,className:B("flex min-h-8 w-full items-center gap-2 rounded-md px-2 text-left text-sm hover:bg-surface-high",h.id===a?"bg-surface-high text-on-surface":"text-outline"),onClick:()=>r(h.id),children:[e.jsx(Ct,{size:14,className:"shrink-0","aria-hidden":!0}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:h.title})]})},h.id))})]},j.id)})})]},x))})}function zn(){const t=ia(),s=t.data,n=s?s.embedding.provider==="none"?{text:"Keyword search only",title:"Configure embeddings in Settings to also search by meaning"}:s.embedding.ready?{text:"Hybrid search",title:s.embedding.model??void 0}:{text:"Embeddings not ready",title:s.embedding.detail??""}:null,a=s?s.jobs.queued+s.jobs.running:0;return e.jsx("p",{role:"status","data-testid":"kb-status",className:"shrink-0 border-t border-outline-variant px-4 py-2 text-xs text-outline",children:s?e.jsxs(e.Fragment,{children:[e.jsx("span",{title:n==null?void 0:n.title,children:n==null?void 0:n.text}),a?` · ${a} processing`:""]}):t.error?"Knowledge status unavailable":"Loading…"})}function Nt({children:t}){return e.jsx("div",{className:"min-h-0 min-w-0 flex-1 overflow-y-auto",children:t})}function Ue({children:t,testId:s}){return e.jsx("div",{"data-testid":s,className:"mx-auto flex max-w-lg flex-1 flex-col items-start justify-center gap-4 p-6",children:t})}function Ln({query:t,search:s,onOpen:n,onClear:a}){const i=s.data;return e.jsxs("section",{"data-testid":"kb-search-results","aria-label":"Search results",className:"w-full min-w-0 space-y-4 p-4 sm:p-8",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("h2",{className:"mr-auto text-lg font-medium",children:["Results for “",t,"”"]}),i&&i.hits.length>0&&e.jsxs("span",{className:"text-xs text-outline","data-testid":"kb-search-count",children:[i.hits.length," ",i.hits.length===1?"result":"results"]}),e.jsxs(y,{variant:"ghost",size:"sm",onClick:a,"data-testid":"kb-search-clear",children:[e.jsx(Pe,{size:14}),"Clear"]})]}),(i==null?void 0:i.degraded)&&e.jsx("p",{role:"status",className:"text-sm text-warning",children:i.degraded}),s.isLoading&&e.jsx("p",{className:"text-sm text-outline",children:"Searching…"}),s.error&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:s.error.message}),(i==null?void 0:i.hits.length)===0&&e.jsx("p",{className:"text-sm text-outline","data-testid":"kb-search-empty",children:"Nothing matched. Try other words or search all knowledge bases."}),i==null?void 0:i.hits.map(l=>e.jsxs("article",{"data-testid":"kb-search-result",className:"space-y-2 border-b border-outline-variant pb-4",children:[e.jsxs("button",{type:"button",className:"block text-left",onClick:()=>{var r;return n(l.document_id,wt((r=l.passages[0])==null?void 0:r.heading_path))},children:[e.jsx("span",{className:"block font-medium text-primary hover:underline",children:l.title}),e.jsxs("span",{className:"block break-all text-xs text-outline",children:[l.kb_name," · ",l.path]})]}),l.labels.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1",children:l.labels.map(r=>e.jsx(os,{variant:"secondary",children:r},r))}),l.passages.map(r=>{var o,d,p,c;return e.jsxs("div",{"data-testid":"kb-search-passage",className:"cursor-pointer space-y-1 rounded-md p-2 hover:bg-surface-high",onClick:()=>n(l.document_id,wt(r.heading_path)),children:[(r.heading_path.length>0||((o=r.locator)==null?void 0:o.page)||((d=r.locator)==null?void 0:d.sheet))&&e.jsx("div",{className:"text-xs text-outline",children:[...r.heading_path.map(hs),...(p=r.locator)!=null&&p.page?[`page ${r.locator.page}`]:[],...(c=r.locator)!=null&&c.sheet?[`sheet ${r.locator.sheet}`]:[]].join(" › ")}),e.jsx("p",{className:"text-sm leading-relaxed",children:e.jsx(En,{text:r.snippet})})]},r.chunk_id)})]},l.document_id))]})}function Mn({uploads:t,onOpen:s}){if(!t.uploads.length)return null;const n=t.uploads.some(a=>a.status!=="uploading");return e.jsxs("section",{"data-testid":"kb-upload-queue","aria-label":"Uploads",className:"absolute bottom-4 right-4 z-10 flex max-h-72 w-80 max-w-[calc(100%-2rem)] flex-col rounded-lg border border-outline-variant bg-surface text-sm shadow-lg",children:[e.jsxs("div",{className:"flex shrink-0 items-center justify-between px-3 py-1.5",children:[e.jsx("span",{className:"font-medium",children:"Uploads"}),n&&e.jsx(y,{size:"sm",variant:"ghost",onClick:t.clearFinished,"data-testid":"kb-upload-clear",children:"Dismiss"})]}),e.jsx("div",{className:"min-h-0 space-y-1 overflow-y-auto px-3 pb-2",children:t.uploads.map(a=>e.jsx(An,{upload:a,onOpen:s,onRetry:()=>t.retry(a.id)},a.id))})]})}const Tn={pending:"Parsing…",ok:"Open",partial:"Open · partly parsed",failed:"Parse failed"};function An({upload:t,onOpen:s,onRetry:n}){var l;const i=((l=Le(t.status==="done"?t.kbId:null).data)==null?void 0:l.documents.find(r=>{var o;return r.id===((o=t.document)==null?void 0:o.id)}))??t.document;return e.jsxs("div",{"data-testid":"kb-upload-item","data-status":t.status,"data-parse-state":i==null?void 0:i.parse_state,className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t.file.name}),t.status==="uploading"&&e.jsx("span",{className:"h-1.5 w-24 overflow-hidden rounded-full bg-surface-high",role:"progressbar","aria-label":"Upload progress","aria-valuenow":Math.round(t.progress*100),children:e.jsx("span",{className:"block h-full bg-primary",style:{width:`${Math.round(t.progress*100)}%`}})}),t.status==="done"&&i&&e.jsx("button",{type:"button",className:B("hover:underline",i.parse_state==="failed"?"text-error":"text-primary"),onClick:()=>s(i.id),children:Tn[i.parse_state]}),t.status==="failed"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"alert",className:"text-error",children:t.error}),e.jsx(y,{size:"sm",variant:"ghost",onClick:n,"data-testid":"kb-upload-retry",children:"Retry"})]})]})}function wt(t){return t==null?void 0:t[t.length-1]}export{Qn as default};
|