orc-ai 0.1.65 → 0.1.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +1002 -879
  3. package/dist/skills/orc-platform/references/channels.md +1 -1
  4. package/dist/skills/orc-platform/references/chat-ui.md +1 -1
  5. package/dist/skills/orc-platform/references/execution.md +2 -2
  6. package/dist/skills/orc-platform/references/web.md +3 -3
  7. package/dist/web/assets/{Agents-CXxHOAVS.js → Agents-Btw9GSoH.js} +3 -3
  8. package/dist/web/assets/AreaChart-DcUZ3SzF.js +53 -0
  9. package/dist/web/assets/Audit-BrzyRS5i.js +1 -0
  10. package/dist/web/assets/BarChart-DAz5P98C.js +3 -0
  11. package/dist/web/assets/Chart-BNguc0T2.js +1 -0
  12. package/dist/web/assets/ChatAnalyticsCharts-B8DCNbHq.js +1 -0
  13. package/dist/web/assets/ChatUiRenderer-BR3sfc-Z.js +4 -0
  14. package/dist/web/assets/{ConfirmDialog-DKN0AVIw.js → ConfirmDialog-CtTOXkX8.js} +1 -1
  15. package/dist/web/assets/Dashboard-C5mM9PJs.js +1 -0
  16. package/dist/web/assets/{DocumentWorkspace-B9hQN2EX.js → DocumentWorkspace-BbG32kAW.js} +1 -1
  17. package/dist/web/assets/{FileEditor-BK8_4AJM.js → FileEditor-BCD6enuO.js} +1 -1
  18. package/dist/web/assets/IntegrationCallback-Bik_7SCS.js +1 -0
  19. package/dist/web/assets/JobWebhooks-RIKnoQh3.js +1 -0
  20. package/dist/web/assets/Jobs-CsSOIqGB.js +3 -0
  21. package/dist/web/assets/Knowledge-DKb5Bndb.js +1 -0
  22. package/dist/web/assets/{MarkdownRenderer-DM6lt7Sg.js → MarkdownRenderer-BCh_ruCd.js} +5 -5
  23. package/dist/web/assets/{NativeFolderField-D1ZqCzY1.js → NativeFolderField-D-0kw2x4.js} +1 -1
  24. package/dist/web/assets/{Notifications-Ciw_MC2q.js → Notifications-8mf4wQSZ.js} +1 -1
  25. package/dist/web/assets/PackageCatalog-DhD3xXBL.js +8 -0
  26. package/dist/web/assets/{PackageRunDialog-CW_N4ttU.js → PackageRunDialog-C4MAbUYz.js} +2 -2
  27. package/dist/web/assets/{PriorityBadge-CZt2elFq.js → PriorityBadge-CzL7cjTr.js} +1 -1
  28. package/dist/web/assets/Projects-CvtUb494.js +3 -0
  29. package/dist/web/assets/ReferenceLine-BPBQytfV.js +1 -0
  30. package/dist/web/assets/{ResponsiveFilters-BwU4JbGU.js → ResponsiveFilters-BDHgHwbe.js} +1 -1
  31. package/dist/web/assets/ResumeActions-CIHfpmTC.js +1 -0
  32. package/dist/web/assets/{Rules-Dqx8X4wX.js → Rules-D1bQTlzi.js} +4 -4
  33. package/dist/web/assets/ScratchpadDiagramEditor-DukGReMq.js +1 -0
  34. package/dist/web/assets/ScratchpadDiagramPreview-CICRpF10.js +1 -0
  35. package/dist/web/assets/Scratchpads-BPiujcq_.js +10 -0
  36. package/dist/web/assets/SessionContextChart-CfkrwDME.js +1 -0
  37. package/dist/web/assets/Settings-CM3tx3Gz.js +14 -0
  38. package/dist/web/assets/Skills-CwHwz6Er.js +3 -0
  39. package/dist/web/assets/{SourceEditor-CKe3Nz5k.js → SourceEditor-DGpMMbEA.js} +4 -4
  40. package/dist/web/assets/{TagInput-QqNDQOz_.js → TagInput-FeirXeiF.js} +1 -1
  41. package/dist/web/assets/TaskDetailSheet-CK2rs3F0.js +1 -0
  42. package/dist/web/assets/{Tasks-daCTnumY.js → Tasks-Dbxfmfm1.js} +7 -7
  43. package/dist/web/assets/Terminals-CeK7rAIg.js +1 -0
  44. package/dist/web/assets/Terminals-CmbOGMJQ.css +1 -0
  45. package/dist/web/assets/{ViewHeader-BiFirRWq.js → ViewHeader-CdTYgjcL.js} +1 -1
  46. package/dist/web/assets/Webhooks-1EQvtBPS.js +1 -0
  47. package/dist/web/assets/{badge-BEhHQEk0.js → badge-DkZMrS1S.js} +1 -1
  48. package/dist/web/assets/{button-BlVCkBiz.js → button-DeTgVWBh.js} +1 -1
  49. package/dist/web/assets/check-LRl-dSYs.js +1 -0
  50. package/dist/web/assets/chevron-down-DtC3kwL9.js +1 -0
  51. package/dist/web/assets/{circle-check-CrMHbBhC.js → circle-check-DmFYS6qN.js} +1 -1
  52. package/dist/web/assets/client-C0cF5m6-.js +1 -0
  53. package/dist/web/assets/{dist-BxZ8dALn.js → dist-CG7sCn9m.js} +1 -1
  54. package/dist/web/assets/dist-DxPLB3GS.js +1 -0
  55. package/dist/web/assets/{download-Cnjcb403.js → download-vwV9XGjB.js} +1 -1
  56. package/dist/web/assets/{highlighted-body-JLMTFACH-DqkWK4Ru.js → highlighted-body-JLMTFACH-DBFcem9W.js} +1 -1
  57. package/dist/web/assets/index-BoyulwgO.js +137 -0
  58. package/dist/web/assets/index-CMgQ_c5f.css +1 -0
  59. package/dist/web/assets/{maximize-2-ar3sWM7r.js → maximize-2-DkkQv64-.js} +1 -1
  60. package/dist/web/assets/mermaid-WFAXDIZX-DX9Leemp.js +1 -0
  61. package/dist/web/assets/scroll-area-Bz4B8g7w.js +1 -0
  62. package/dist/web/assets/{table-D2GMF--l.js → table-BghcPb3T.js} +1 -1
  63. package/dist/web/assets/{upload-Bbixlc7i.js → upload-DM_myzsG.js} +1 -1
  64. package/dist/web/assets/{useIntegrations-D5PIxedU.js → useIntegrations-CwksniBf.js} +1 -1
  65. package/dist/web/assets/{useJobs-DYaqHA8F.js → useJobs-CLj3jAlx.js} +1 -1
  66. package/dist/web/assets/{useListSelection-BKCFyGyf.js → useListSelection-BCmeXReo.js} +1 -1
  67. package/dist/web/assets/{useMemories-Ce1S_iFK.js → useMemories-xytUq8G9.js} +1 -1
  68. package/dist/web/assets/x-BbZ0euHI.js +1 -0
  69. package/dist/web/index.html +18 -15
  70. package/package.json +1 -1
  71. package/dist/web/assets/Audit-B38_H4W1.js +0 -1
  72. package/dist/web/assets/ChatUiRenderer-BYlgsVLZ.js +0 -4
  73. package/dist/web/assets/Dashboard-BZKUS4Tw.js +0 -1
  74. package/dist/web/assets/ErrorState-CpcyNx03.js +0 -1
  75. package/dist/web/assets/IntegrationCallback-DCf4a1AA.js +0 -1
  76. package/dist/web/assets/JobWebhooks-C2F4RzTr.js +0 -1
  77. package/dist/web/assets/Jobs-Dho4B9b-.js +0 -3
  78. package/dist/web/assets/Knowledge-CDhPBr8J.js +0 -1
  79. package/dist/web/assets/PackageCatalog-BuT4GoJo.js +0 -8
  80. package/dist/web/assets/Pager-B-GnS1ry.js +0 -1
  81. package/dist/web/assets/Projects-C27puQUE.js +0 -3
  82. package/dist/web/assets/ResumeActions-S3h5yKXv.js +0 -1
  83. package/dist/web/assets/ScratchpadDiagramEditor-iUkemC_h.js +0 -1
  84. package/dist/web/assets/ScratchpadDiagramPreview-Cmim9yNA.js +0 -1
  85. package/dist/web/assets/Scratchpads-DRIBlLwW.js +0 -10
  86. package/dist/web/assets/SessionContextChart-CXAR0czK.js +0 -53
  87. package/dist/web/assets/SessionHomeLink-DKoq9wT8.js +0 -1
  88. package/dist/web/assets/Sessions-DBthIWpR.js +0 -5
  89. package/dist/web/assets/Settings-DU-nfC2z.js +0 -14
  90. package/dist/web/assets/Skills-BPkciOfy.js +0 -3
  91. package/dist/web/assets/StatusBadge-Cz0GkMFG.js +0 -1
  92. package/dist/web/assets/TaskDetailSheet-BGAiFxPD.js +0 -1
  93. package/dist/web/assets/Terminals-CmRdwS_i.js +0 -2
  94. package/dist/web/assets/Terminals-D-D3Ovm0.css +0 -1
  95. package/dist/web/assets/Webhooks-8B-qbOiF.js +0 -1
  96. package/dist/web/assets/check-cnj-S1QW.js +0 -1
  97. package/dist/web/assets/chevron-down-CsfelGxA.js +0 -1
  98. package/dist/web/assets/chevron-up-COeKodk9.js +0 -1
  99. package/dist/web/assets/client-RPZmgRqE.js +0 -1
  100. package/dist/web/assets/dist-B-iYpxX5.js +0 -1
  101. package/dist/web/assets/dist-D8Wfxh48.js +0 -1
  102. package/dist/web/assets/dist-bytwC6rk.js +0 -1
  103. package/dist/web/assets/index-DMLXoHsj.css +0 -1
  104. package/dist/web/assets/index-DsVJrhHJ.js +0 -134
  105. package/dist/web/assets/live-sessions-DYGSpoN-.js +0 -1
  106. package/dist/web/assets/mermaid-WFAXDIZX-3nzsUtGy.js +0 -1
  107. package/dist/web/assets/scratchpad-kinds-BFBap9Ix.js +0 -1
  108. package/dist/web/assets/scratchpad-routes-DqBRARVl.js +0 -1
  109. package/dist/web/assets/scroll-area-BN-yOL-R.js +0 -1
  110. package/dist/web/assets/send-CwHls3BT.js +0 -1
  111. package/dist/web/assets/useSessions-D1nMvBf0.js +0 -1
  112. package/dist/web/assets/x-uOircJYm.js +0 -1
@@ -0,0 +1 @@
1
+ import{a as e}from"./rolldown-runtime-DSDNlrLa.js";import{n as t,t as n}from"./jsx-runtime-CVMpzJz9.js";import{n as r}from"./QueryClientProvider-DlPztvhd.js";import{n as i,t as a}from"./useMutation-CRAWY7v2.js";import{f as o,h as s,p as c,t as l,u}from"./chunk-OB3PAWPO-BD6ylT0A.js";import{c as d,s as f,t as p}from"./button-DeTgVWBh.js";import{t as m}from"./x-BbZ0euHI.js";import{a as h,c as g,i as _,o as v,r as y,s as b,t as x}from"./dist-DxPLB3GS.js";import{P as S,n as C}from"./client-C0cF5m6-.js";import{t as w}from"./chevron-down-DtC3kwL9.js";import{t as T}from"./download-vwV9XGjB.js";import{t as E}from"./ResponsiveFilters-BDHgHwbe.js";import{t as D}from"./upload-DM_myzsG.js";import{a as O,c as k,d as A,f as j,g as M,h as N,i as P,m as F,o as I,t as L,u as R}from"./schemas-BQZhekae.js";import{$ as z,Ai as ee,B,Ci as V,Cn as H,Ei as te,Gi as ne,Ii as re,J as ie,Ji as ae,Mi as U,Ni as oe,On as se,Q as W,Qi as ce,Sn as le,Tn as ue,Tt as de,U as fe,X as pe,Y as me,Z as he,_i as G,at as ge,bi as _e,bn as ve,da as ye,di as be,et as K,fi as xe,gi as Se,gn as Ce,hn as we,it as Te,ki as Ee,kn as De,kr as Oe,kt as ke,la as Ae,li as je,nt as Me,pr as Ne,qi as Pe,ra as Fe,rr as Ie,sa as Le,tt as Re,ua as ze,v as Be,vi as Ve,vn as q,wn as He,x as Ue,y as We,yi as Ge,yn as Ke,z as qe}from"./index-BoyulwgO.js";import{n as Je}from"./wiki-links-A52THGx_.js";import{t as Ye}from"./ConfirmDialog-CtTOXkX8.js";import{t as Xe}from"./save-file-3ZpJah8W.js";import{t as Ze}from"./ViewHeader-CdTYgjcL.js";import{t as Qe}from"./view-params-YEmeZppw.js";import{t as $e}from"./EmptyState-YM4VSLR9.js";import{a as et,i as tt,n as nt,o as rt,r as it,t as at}from"./table-BghcPb3T.js";import{t as ot}from"./useProjectScope-DpgzthH7.js";import{a as st,c as ct,i as lt,n as ut,o as dt,r as ft,s as pt,t as mt}from"./useMemories-xytUq8G9.js";import{n as ht,t as gt}from"./DocumentWorkspace-BbG32kAW.js";import{_ as _t,a as vt,c as yt,d as bt,f as xt,g as St,i as Ct,l as wt,m as Tt,n as Et,o as Dt,p as Ot,r as J,s as kt,t as At,u as jt,v as Mt}from"./badge-DkZMrS1S.js";import{t as Nt}from"./TagInput-FeirXeiF.js";import{n as Pt,t as Ft}from"./NativeFolderField-D-0kw2x4.js";var It={name:`file-down`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 18v-6`,key:`17g6i2`}],[`path`,{d:`m9 15 3 3 3-3`,key:`1npd3o`}]]};It.node;var Lt=S(It),Rt={name:`file-up`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 12v6`,key:`3ahymv`}],[`path`,{d:`m15 15-3-3-3 3`,key:`15xj92`}]]};Rt.node;var zt=S(Rt),Bt={name:`folder-sync`,size:24,node:[[`path`,{d:`M9 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v.5`,key:`1dkoa9`}],[`path`,{d:`M12 10v4h4`,key:`1czhmt`}],[`path`,{d:`m12 14 1.535-1.605a5 5 0 0 1 8 1.5`,key:`lvuxfi`}],[`path`,{d:`M22 22v-4h-4`,key:`1ewp4q`}],[`path`,{d:`m22 18-1.535 1.605a5 5 0 0 1-8-1.5`,key:`14ync0`}]]};Bt.node;var Vt=S(Bt),Y=e(t(),1),X=[`mcp`,`api`,`cli`,`ui`],Ht=[`fetch`,`cited`,`search_hit`],Ut=F().trim().min(1).max(120),Wt=P(L(X)).max(X.length).transform(e=>X.filter(t=>e.includes(t)));A({name:Ut,description:F().trim().max(2e3).default(``),project_id:F().min(1).nullable(),editable_by:Wt.default([...X]),parser:F().min(1).max(40).nullable().default(null)}).strict(),A({name:Ut.optional(),description:F().trim().max(2e3).optional(),editable_by:Wt.optional(),parser:F().min(1).max(40).nullable().optional()}).strict();var Gt=[`default`,`project`,`global`,`all`],Kt=F().trim().min(1).max(500).refine(e=>!e.startsWith(`/`)&&!e.includes(`\\`)&&!e.includes(`:`)&&!e.includes(`\0`)&&e.split(`/`).every(e=>e&&e!==`.`&&e!==`..`),`Use a relative path with / separators and no . or .. segments`),qt=P(F().trim().min(1).max(60)).max(30),Jt=2097152;A({title:F().trim().min(1).max(300),path:Kt.optional(),description:F().trim().max(2e3).optional(),labels:qt.default([]),content:F().max(Jt),note:F().trim().max(1e3).optional(),derived_from:P(F().min(1)).max(50).default([])}).strict(),A({expected_revision:R().int().min(1),title:F().trim().min(1).max(300).optional(),path:Kt.optional(),description:F().trim().max(2e3).optional(),labels:qt.optional(),content:F().max(Jt).optional(),note:F().trim().max(1e3).optional(),derived_from:P(F().min(1)).max(50).optional()}).strict();var Yt=A({kind:L([`heading`,`paragraph`,`list_item`,`table`,`code`]),text:F(),level:R().int().min(1).max(6).optional(),rows:P(P(F())).optional(),heading_path:P(F()),locator:A({page:R().int().min(1).optional(),sheet:F().optional(),bbox:P(R()).length(4).optional()}).optional()});A({schema_version:k(1),parser:A({id:F(),version:F(),options:j(F(),M())}),source_sha256:F().regex(/^[0-9a-f]{64}$/),status:L([`ok`,`partial`,`failed`]),language:F().optional(),blocks:P(Yt),markdown:F(),warnings:P(F()),timings_ms:j(F(),R()).optional(),peak_rss_mb:R().optional()});var Xt=[`auto`,`lexical`,`semantic`,`hybrid`];A({query:F().trim().min(1).max(2e3),scope:L(Gt).default(`default`),kb_ids:P(F().min(1)).max(50).optional(),labels:P(F().min(1)).max(20).optional(),media_types:P(F().min(1)).max(20).optional(),mode:L(Xt).default(`auto`),limit:R().int().min(1).max(50).default(10)}).strict().omit({limit:!0,mode:!0}).extend({mode:L(Xt).default(`auto`),token_budget:R().int().min(500).max(32e3).default(6e3),max_per_document:R().int().min(1).max(10).default(3)}).strict();var Zt=A({old:F().min(1).max(Jt),new:F().max(Jt),replace_all:O().optional()}).strict(),Qt=A({start_line:R().int().min(1),end_line:R().int().min(0),new:F().max(Jt)}).strict();A({expected_revision:R().int().min(1),edits:P(N([Zt,Qt])).min(1).max(50),note:F().trim().min(1).max(1e3)}).strict();var $t=[`open`,`resolved`,`dismissed`];A({document_id:F().min(1).nullable().optional(),body:F().trim().min(1).max(1e4)}).strict(),A({status:L([`resolved`,`dismissed`]),reply:F().trim().min(1).max(4e3)}).strict();var en=I(`type`,[A({type:k(`cron`),cron:F().trim().min(1).max(120)}).strict(),A({type:k(`manual`)}).strict()]);A({instructions:F().trim().min(1).max(2e4).optional(),backend:F().min(1).max(64).regex(/^[a-z][a-z0-9_-]*$/).optional(),schedule:en.optional(),enabled:O().optional(),timeout_secs:R().int().min(60).max(7200).optional()}).strict();var tn=`0 3 * * *`,Z=n();function nn({title:e,testId:t,toggleTestId:n,summary:r,actions:i,expanded:a=!1,onExpandedChange:o,heading:s=`h3`,compact:c=!1,children:l}){let u=(0,Y.useId)(),d=l!==void 0&&o!==void 0;return(0,Z.jsxs)(`section`,{"data-testid":t,"data-expanded":d?a:void 0,"aria-labelledby":`${u}-heading`,className:`min-w-0 text-sm`,children:[(0,Z.jsxs)(`div`,{className:f(`grid min-h-12 min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-0.5 py-1.5`,!c&&`sm:grid-cols-[9rem_minmax(0,1fr)_auto]`),children:[(0,Z.jsx)(s,{id:`${u}-heading`,className:`min-w-0 font-medium`,children:d?(0,Z.jsxs)(`button`,{type:`button`,"data-testid":n,"aria-expanded":a,"aria-controls":u,className:`-ml-1 flex min-h-9 items-center gap-1.5 rounded px-1 text-left hover:bg-surface-high`,onClick:()=>o(!a),children:[(0,Z.jsx)(Fe,{size:14,"aria-hidden":!0,className:f(`shrink-0 text-outline transition-transform`,a&&`rotate-90`)}),e]}):(0,Z.jsx)(`span`,{className:`flex min-h-9 items-center pl-5`,children:e})}),(0,Z.jsx)(`div`,{className:f(`col-span-2 row-start-2 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 pl-5`,!c&&`sm:col-span-1 sm:col-start-2 sm:row-start-1 sm:pl-0`),children:r}),(0,Z.jsx)(`div`,{className:f(`col-start-2 row-start-1 flex items-center justify-end gap-1`,!c&&`sm:col-start-3`),children:i})]}),d&&a&&(0,Z.jsx)(`div`,{id:u,className:`min-w-0 pb-4 pl-5 pt-1`,children:l})]})}function rn({tone:e}){return(0,Z.jsx)(`span`,{"aria-hidden":!0,className:f(`size-1.5 shrink-0 rounded-full`,e===`ok`&&`bg-secondary`,e===`warning`&&`bg-warning`,e===`error`&&`bg-error`,e===`off`&&`bg-muted-foreground`,e===`progress`&&`bg-progress`)})}var an=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],on=/^\d+$/,sn=e=>e.padStart(2,`0`),cn=e=>/^\*\/(\d+)$/.exec(e)?.[1],ln=(e,t)=>e===`1`?`Every ${t}`:`Every ${e} ${t}s`;function un(e){let[t=``,n=``,r,i,a=``,...o]=e.trim().split(/\s+/);if(o.length||r!==`*`||i!==`*`)return e;if(n===`*`&&a===`*`){if(t===`*`)return`Every minute`;let n=cn(t);return n?ln(n,`minute`):on.test(t)?Number(t)?`Every hour at :${sn(t)}`:`Every hour`:e}if(!on.test(t))return e;let s=cn(n);if(s&&a===`*`)return`${ln(s,`hour`)}${Number(t)?` at :${sn(t)}`:``}`;if(!on.test(n))return e;let c=`${sn(n)}:${sn(t)}`;return a===`*`?`Daily at ${c}`:a===`1-5`?`Weekdays at ${c}`:a===`0,6`||a===`6,0`?`Weekends at ${c}`:/^[0-7]$/.test(a)?`${an[Number(a)%7]}s at ${c}`:e}var dn=[{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 fn(e,t){let n=e=>{let n=t.names.indexOf(e.toUpperCase()),r=n>=0?n+ +(t.min===1):on.test(e)?Number(e):NaN;return r>=t.min&&r<=t.max?r:NaN};return e.split(`,`).every(e=>{let t=/^(\*|[a-z0-9]+(?:-[a-z0-9]+)?)(?:\/(\d+))?$/i.exec(e);if(!t?.[1]||t[2]!==void 0&&Number(t[2])<1)return!1;if(t[1]===`*`)return!0;let[r=``,i]=t[1].split(`-`);return i===void 0?!Number.isNaN(n(r)):n(r)<=n(i)})}function pn(e){let t=e.trim().split(/\s+/).filter(Boolean);if(!t.length)return`Enter a cron expression.`;if(t.length!==5)return`A cron expression has 5 fields (minute hour day month weekday); this one has ${t.length}.`;for(let[e,n]of dn.entries()){let r=t[e]??``;if(!fn(r,n))return`The ${n.name} field "${r}" is not valid. Use a number from ${n.min} to ${n.max}, *, a range (1-5), a list (1,3) or a step (*/2).`}return null}function mn(e){let t=Math.max(0,Math.round((e-Date.now())/1e3));if(t<60)return`in under a minute`;if(t<3600)return`in ${Math.round(t/60)}m`;if(t<86400)return`in ${Math.round(t/3600)}h`;let n=new Date(e);return`${an[n.getDay()]?.slice(0,3)} ${sn(String(n.getHours()))}:${sn(String(n.getMinutes()))}`}function hn(e){let t=Math.max(0,Math.round((Date.now()-e)/1e3));return t<60?`just now`:t<3600?`${Math.round(t/60)}m ago`:t<86400?`${Math.round(t/3600)}h ago`:`${Math.round(t/86400)}d ago`}function gn(e){let t=e.last_run?.status;return t===`running`?`progress`:e.schedule.type===`cron`&&!e.enabled?`off`:t===`failed`?`error`:t===`completed`?`ok`:`off`}function _n({kb:e}){let t=vt(e.id),[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(!1),o=t.data;return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(nn,{title:`Digest`,testId:`kb-digest`,toggleTestId:`kb-digest-expand`,expanded:i,onExpandedChange:a,summary:t.error?(0,Z.jsx)(`span`,{role:`alert`,className:`text-error`,children:t.error.message}):t.isLoading?(0,Z.jsx)(`span`,{className:`text-outline`,children:`Loading…`}):o?(0,Z.jsx)(vn,{digest:o}):(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-outline`,"data-testid":`kb-digest-off`,children:[(0,Z.jsx)(rn,{tone:`off`}),`Off, documents change only when someone edits them`]}),actions:o?(0,Z.jsx)(yn,{kb:e,digest:o,onStarted:()=>a(!0)}):t.data===null?(0,Z.jsx)(p,{size:`sm`,variant:`outline`,"data-testid":`kb-digest-add`,onClick:()=>r(`edit`),children:`Set up`}):null,children:o?(0,Z.jsx)(bn,{kb:e,digest:o,onEdit:()=>r(`edit`)}):(0,Z.jsx)(`p`,{className:`max-w-prose text-outline`,children:`A digest is an agent that reads new memories, sessions and open comments, then keeps the documents in this knowledge base current. It can run on a schedule or only when you start it.`})}),n===`edit`&&(0,Z.jsx)(Wn,{kb:e,digest:o??null,onClose:()=>r(null),onRemove:()=>r(`remove`)}),n===`remove`&&(0,Z.jsx)(Gn,{kb:e,onClose:()=>r(null)})]})}function vn({digest:e}){let t=e.last_run,n=e.schedule.type===`manual`||e.enabled;return(0,Z.jsxs)(`span`,{"data-testid":`kb-digest-summary`,className:`inline-flex min-w-0 flex-wrap items-center gap-x-1.5`,children:[(0,Z.jsx)(rn,{tone:gn(e)}),(0,Z.jsx)(`span`,{"data-testid":`kb-digest-enabled`,children:n?`On`:`Paused`}),(0,Z.jsxs)(`span`,{children:[`·`,` `,e.schedule.type===`manual`?`runs when you start it`:(0,Z.jsx)(`span`,{title:e.schedule.cron,children:un(e.schedule.cron)})]}),e.next_run_at!==null&&(0,Z.jsxs)(`span`,{className:`text-outline`,"data-testid":`kb-digest-next-run`,children:[`·`,` `,(0,Z.jsxs)(`span`,{title:new Date(e.next_run_at).toLocaleString(),children:[`next run `,mn(e.next_run_at)]})]}),(0,Z.jsxs)(`span`,{className:`text-outline`,"data-testid":`kb-digest-last-run`,"data-status":t?.status??`never`,children:[`·`,` `,t?t.status===`running`?`running now`:(0,Z.jsxs)(`span`,{title:new Date(t.at).toLocaleString(),children:[`last run`,` `,(0,Z.jsx)(`span`,{className:t.status===`failed`?`text-error`:void 0,children:t.status===`completed`?`succeeded`:t.status}),` `,hn(t.at)]}):`not run yet`]})]})}function yn({kb:e,digest:t,onStarted:n}){let r=J(),i=Q(),a=t.last_run?.status===`running`;async function o(){await i.run(()=>C.kb.runDigest(e.id))&&(n(),await r())}return(0,Z.jsxs)(Z.Fragment,{children:[i.error&&(0,Z.jsx)(`span`,{role:`alert`,className:`text-error`,"data-testid":`kb-digest-error`,children:i.error}),(0,Z.jsx)(p,{size:`sm`,variant:`outline`,"data-testid":`kb-digest-run`,onClick:o,disabled:i.pending||a,children:a?`Running…`:`Run now`})]})}function bn({kb:e,digest:t,onEdit:n}){let r=J(),i=Q(),a=Dt(e.id,t);async function o(){await i.run(()=>C.kb.setDigest(e.id,{enabled:!t.enabled}))&&await r()}return(0,Z.jsxs)(`div`,{className:`min-w-0 space-y-3`,children:[(0,Z.jsxs)(`p`,{className:`max-w-prose text-outline`,children:[`The `,(0,Z.jsx)(`span`,{className:`font-mono text-on-surface`,children:t.backend}),` agent reads new memories, sessions and open comments, then updates documents here.`,` `,(0,Z.jsx)(`span`,{"data-testid":`kb-digest-open-comments`,children:t.open_comments}),` open`,` `,t.open_comments===1?`comment waits`:`comments wait`,` for the next run.`]}),(0,Z.jsxs)(`div`,{className:`-ml-2 flex flex-wrap items-center gap-1`,children:[(0,Z.jsx)(p,{size:`sm`,variant:`ghost`,"data-testid":`kb-digest-edit`,onClick:n,children:`Edit instructions and schedule`}),t.schedule.type===`cron`&&(0,Z.jsx)(p,{size:`sm`,variant:`ghost`,"data-testid":`kb-digest-toggle`,onClick:o,disabled:i.pending,children:t.enabled?`Pause schedule`:`Resume schedule`}),(0,Z.jsx)(p,{size:`sm`,variant:`ghost`,asChild:!0,children:(0,Z.jsx)(l,{to:`/jobs/${encodeURIComponent(t.job_id)}`,"data-testid":`kb-digest-job`,children:`Job history`})})]}),i.error&&(0,Z.jsx)(`p`,{role:`alert`,className:`text-error`,"data-testid":`kb-digest-error`,children:i.error}),(0,Z.jsx)(Sn,{runs:a.data??[]})]})}var xn={failed:`error`,success:`ok`,running:`progress`};function Sn({runs:e}){return e.length?(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`h4`,{className:`text-xs font-medium text-outline`,children:`Recent runs`}),(0,Z.jsx)(`ol`,{"data-testid":`kb-digest-runs`,className:`divide-y divide-outline-variant`,children:e.map(e=>(0,Z.jsxs)(`li`,{"data-testid":`kb-digest-run-row`,"data-status":e.status,className:`min-w-0 wrap-break-word py-1.5`,children:[(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,Z.jsx)(rn,{tone:xn[e.status]??`off`}),e.status]}),(0,Z.jsxs)(`span`,{className:`text-outline`,children:[` · `,e.started_at?(0,Z.jsx)(`span`,{title:new Date(e.started_at).toLocaleString(),children:hn(e.started_at)}):`not started`,e.trigger_by?` · ${e.trigger_by}`:``]}),e.session_id&&(0,Z.jsx)(l,{to:`/audit/${encodeURIComponent(e.session_id)}`,className:`ml-2 text-primary hover:underline`,children:`Session`}),(e.error||e.summary)&&(0,Z.jsx)(`span`,{className:`block truncate text-xs text-outline`,title:e.error??e.summary??``,children:e.error??e.summary})]},e.run_id))})]}):(0,Z.jsx)(`p`,{className:`text-outline`,children:`No runs yet.`})}var Cn=`__global__`,wn=`__auto__`;function Tn(e){return e instanceof Error?e.message:`Request failed`}function Q(){let[e,t]=(0,Y.useState)(!1),[n,r]=(0,Y.useState)(null);async function i(e){t(!0),r(null);try{return await e()}catch(e){r(Tn(e));return}finally{t(!1)}}return{pending:e,error:n,run:i,setError:r}}function $({label:e,children:t,hint:n}){return(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(Te,{className:`text-sm text-muted-foreground`,children:e}),t,n&&(0,Z.jsx)(`p`,{className:`text-xs text-outline`,children:n})]})}function En({error:e}){return e?(0,Z.jsx)(`p`,{role:`alert`,"data-testid":`kb-dialog-error`,className:`text-sm text-error`,children:e}):null}function Dn({open:e,onClose:t,title:n,wide:r,size:i,children:a}){return(0,Z.jsx)(we,{open:e,onOpenChange:e=>!e&&t(),children:(0,Z.jsxs)(Ce,{className:`bg-surface border-outline-variant ${i===`xl`?`w-[calc(100%-1rem)] max-w-4xl`:r?`max-w-3xl`:`max-w-md`}`,children:[(0,Z.jsx)(Ke,{children:(0,Z.jsx)(ve,{className:`text-base text-on-surface`,children:n})}),a]})})}function On({value:e,onChange:t}){let n=xt();return(0,Z.jsxs)(W,{value:e??wn,onValueChange:e=>t(e===wn?null:e),children:[(0,Z.jsx)(Re,{"aria-label":`Parser`,"data-testid":`kb-parser-select`,children:(0,Z.jsx)(Me,{})}),(0,Z.jsxs)(z,{children:[(0,Z.jsx)(K,{value:wn,children:`Workspace default`}),(n.data?.parsers??[]).map(e=>(0,Z.jsxs)(K,{value:e.id,disabled:!e.installed,children:[e.label,e.installed?``:` (not installed)`]},e.id))]})]})}var kn={ui:`Web UI`,cli:`CLI`,api:`REST API`,mcp:`Agents (MCP)`};function An({value:e,onChange:t}){return(0,Z.jsxs)(`fieldset`,{className:`space-y-2 rounded-md border border-outline-variant p-3`,children:[(0,Z.jsx)(`legend`,{className:`px-1 text-sm text-muted-foreground`,children:`Who can change documents`}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-2`,children:X.map(n=>(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,"data-testid":`kb-editable-${n}`,checked:e.includes(n),onChange:r=>t(X.filter(t=>t===n?r.target.checked:e.includes(t)))}),kn[n]]},n))}),(0,Z.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 jn({open:e,projectId:t,onClose:n,onCreated:r}){let i=Oe(),a=J(),o=Q(),[s,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(t??Cn),[m,h]=(0,Y.useState)([...X]),[g,_]=(0,Y.useState)(null);async function v(e){e.preventDefault();let t=await o.run(()=>C.kb.create({name:s.trim(),description:l.trim(),project_id:d===Cn?null:d,editable_by:m,parser:g}));t&&(await a(),r(t))}return(0,Z.jsx)(Dn,{open:e,onClose:n,title:`New knowledge base`,children:(0,Z.jsxs)(`form`,{onSubmit:v,className:`space-y-4`,children:[(0,Z.jsx)($,{label:`Name`,children:(0,Z.jsx)(G,{"aria-label":`Name`,"data-testid":`kb-name-input`,value:s,onChange:e=>c(e.target.value),placeholder:`e.g. Runbooks`,autoFocus:!0})}),(0,Z.jsx)($,{label:`Description`,children:(0,Z.jsx)(Se,{"aria-label":`Description`,value:l,onChange:e=>u(e.target.value),rows:2})}),(0,Z.jsx)($,{label:`Belongs to`,hint:`Project knowledge bases are visible in that project; global ones in every project.`,children:(0,Z.jsxs)(W,{value:d,onValueChange:f,children:[(0,Z.jsx)(Re,{"aria-label":`Belongs to`,"data-testid":`kb-owner-select`,children:(0,Z.jsx)(Me,{})}),(0,Z.jsxs)(z,{children:[(0,Z.jsx)(K,{value:Cn,children:`Global (all projects)`}),(i.data??[]).map(e=>(0,Z.jsx)(K,{value:e.id,children:e.name},e.id))]})]})}),(0,Z.jsx)(An,{value:m,onChange:h}),(0,Z.jsx)($,{label:`Parser for uploads`,children:(0,Z.jsx)(On,{value:g,onChange:_})}),(0,Z.jsx)(En,{error:o.error}),(0,Z.jsxs)(q,{children:[(0,Z.jsx)(p,{type:`button`,variant:`ghost`,onClick:n,children:`Cancel`}),(0,Z.jsx)(p,{type:`submit`,"data-testid":`kb-create-submit`,disabled:!s.trim()||o.pending,children:o.pending?`Creating…`:`Create`})]})]})})}function Mn({kb:e,onClose:t,onDeleted:n}){let r=Oe(),i=J(),a=Q(),[o,s]=(0,Y.useState)(e.name),[c,l]=(0,Y.useState)(e.description),[u,d]=(0,Y.useState)(e.editable_by),[f,m]=(0,Y.useState)(e.parser),[h,g]=(0,Y.useState)(!1);async function _(n){n.preventDefault(),await a.run(()=>C.kb.update(e.id,{name:o.trim(),description:c.trim(),editable_by:u,parser:f}))&&(await i(),t())}return(0,Z.jsxs)(Dn,{open:!0,onClose:t,title:`Knowledge base settings`,children:[(0,Z.jsxs)(`form`,{onSubmit:_,className:`space-y-4`,children:[(0,Z.jsx)($,{label:`Name`,children:(0,Z.jsx)(G,{"aria-label":`Name`,"data-testid":`kb-name-input`,value:o,onChange:e=>s(e.target.value)})}),(0,Z.jsx)($,{label:`Description`,children:(0,Z.jsx)(Se,{"aria-label":`Description`,value:c,onChange:e=>l(e.target.value),rows:2})}),(0,Z.jsxs)(`div`,{className:`space-y-1 text-sm`,children:[(0,Z.jsx)(`div`,{className:`font-medium`,children:`Belongs to`}),(0,Z.jsxs)(`p`,{className:`text-outline`,"data-testid":`kb-settings-owner`,children:[e.project_id===null?`Global, visible in every project`:`${r.data?.find(t=>t.id===e.project_id)?.name??`A project`}, visible in that project`,`. Set when the knowledge base is created.`]})]}),(0,Z.jsx)(An,{value:u,onChange:d}),(0,Z.jsx)($,{label:`Parser for uploads`,hint:`Applies to new uploads and reparses.`,children:(0,Z.jsx)(On,{value:f,onChange:m})}),(0,Z.jsx)(En,{error:a.error}),(0,Z.jsxs)(q,{className:`gap-2 sm:justify-between`,children:[(0,Z.jsxs)(p,{type:`button`,variant:`ghost`,className:`text-error`,"data-testid":`kb-delete`,onClick:()=>g(!0),children:[(0,Z.jsx)(_e,{size:14}),`Delete`]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(p,{type:`button`,variant:`ghost`,onClick:t,children:`Cancel`}),(0,Z.jsx)(p,{type:`submit`,"data-testid":`kb-settings-save`,disabled:!o.trim()||a.pending,children:`Save`})]})]})]}),(0,Z.jsx)(Ye,{open:h,title:`Delete knowledge base`,description:`Delete "${e.name}" with its ${e.document_count} documents, revisions and uploaded files? Registered folders on disk are not touched.`,isPending:a.pending,onCancel:()=>g(!1),onConfirm:async()=>{let t=await a.run(()=>C.kb.remove(e.id));g(!1),t!==void 0&&(await i(),n())}})]})}function Nn(e){return`${e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`untitled`}.md`}function Pn(e){return e.match(/^#\s+(.+?)\s*#*\s*$/m)?.[1]?.trim()??``}var Fn=/\.(md|markdown|txt)$/i;function In({kb:e,initialFile:t,onClose:n,onCreated:r,onUploadMany:i}){let a=J(),o=Q(),s=jt(e.id),[c,l]=(0,Y.useState)(``),[u,f]=(0,Y.useState)(``),[h,g]=(0,Y.useState)(``),[_,v]=(0,Y.useState)([]),[y,b]=(0,Y.useState)(null),[x,S]=(0,Y.useState)(!1),w=(0,Y.useRef)(null),T=y?``:Pn(u),E=c.trim()||T,O=y?y.name:Nn(E),k=y!==null||u.trim()!==``;async function A(e){let t=e.name.replace(/\.[^.]+$/,``);if(!Fn.test(e.name)){b(e),l(t),g(``);return}S(!0);let n=await o.run(()=>e.text());S(!1),n!==void 0&&(b(null),f(n),l(Pn(n)||t),g(/\.txt$/i.test(e.name)?Nn(t):e.name))}function j(e){let t=[...e??[]];t.length>1?i(t):t[0]&&A(t[0])}(0,Y.useEffect)(()=>{t&&A(t)},[]);async function M(t){t.preventDefault();let n=await o.run(()=>y?C.kb.upload(e.id,{file:y,title:E,path:h.trim()||void 0,labels:_}):C.kb.createDocument(e.id,{title:E,path:h.trim()||O,labels:_,content:k?u:`# ${E}\n\n`}));n&&(await a(),r(n,k))}return(0,Z.jsx)(Dn,{open:!0,onClose:n,title:`New document in ${e.name}`,size:`xl`,children:(0,Z.jsxs)(`form`,{onSubmit:M,className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-sm text-outline`,children:[(0,Z.jsx)(`span`,{children:`Write or paste below, or start from a file.`}),(0,Z.jsxs)(p,{type:`button`,size:`sm`,variant:`outline`,"data-testid":`kb-doc-choose-file`,disabled:x||o.pending,onClick:()=>w.current?.click(),children:[(0,Z.jsx)(D,{size:16}),x?`Reading…`:`Upload file`]}),(0,Z.jsx)(`input`,{ref:w,type:`file`,multiple:!0,hidden:!0,"data-testid":`kb-doc-file-input`,onChange:e=>{j(e.target.files),e.target.value=``}})]}),(0,Z.jsx)($,{label:`Title`,hint:T&&!c.trim()?`Taken from the first heading.`:void 0,children:(0,Z.jsx)(G,{"aria-label":`Title`,"data-testid":`kb-doc-title-input`,value:c,onChange:e=>l(e.target.value),placeholder:T||`e.g. Deploy runbook`,autoFocus:!0})}),y?(0,Z.jsx)($,{label:`File`,hint:`Converted to searchable text after it is added. The original file is kept.`,children:(0,Z.jsxs)(`div`,{"data-testid":`kb-doc-file`,className:`flex items-center gap-3 rounded-md border border-surface-highest bg-surface p-3`,children:[(0,Z.jsx)(Pe,{size:20,className:`shrink-0 text-outline`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm`,title:y.name,children:y.name}),(0,Z.jsx)(`span`,{className:`shrink-0 text-xs text-outline`,children:d(y.size)}),(0,Z.jsx)(p,{type:`button`,size:`icon`,variant:`ghost`,"aria-label":`Remove ${y.name}`,"data-testid":`kb-doc-file-remove`,onClick:()=>{b(null),l(``)},children:(0,Z.jsx)(m,{size:16})})]})}):(0,Z.jsx)($,{label:`Content`,hint:`Markdown. Leave empty to start writing in the editor.`,children:(0,Z.jsx)(ke,{path:h.trim()||O,value:u,onChange:f,testId:`kb-doc-content-input`,label:`Content`,placeholder:`Write or paste Markdown`,initialMode:`edit`,height:`45vh`})}),(0,Z.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,Z.jsx)($,{label:`Labels`,hint:`Enter, comma or space adds a label.`,children:(0,Z.jsx)(Nt,{"aria-label":`Labels`,"data-testid":`kb-doc-labels-input`,value:_,onChange:v,suggestions:s.data?.labels.map(e=>e.label)})}),(0,Z.jsx)($,{label:`Path`,hint:`Optional. Folders come from the path, e.g. guides/setup.md.`,children:(0,Z.jsx)(G,{"aria-label":`Path`,"data-testid":`kb-doc-path-input`,value:h,onChange:e=>g(e.target.value),placeholder:O,className:`font-mono text-sm`})})]}),(0,Z.jsx)(En,{error:o.error}),(0,Z.jsxs)(q,{children:[(0,Z.jsx)(p,{type:`button`,variant:`ghost`,onClick:n,children:`Cancel`}),(0,Z.jsx)(p,{type:`submit`,"data-testid":`kb-doc-create-submit`,disabled:!E||o.pending,children:`Create`})]})]})})}function Ln({doc:e,linkedFrom:t,onClose:n,onSaved:r}){let i=J(),a=Q(),[o,s]=(0,Y.useState)(e.title),[c,l]=(0,Y.useState)(e.path),u=jt(e.kb_id),[d,f]=(0,Y.useState)(e.labels),[m,h]=(0,Y.useState)(e.description),g=o.trim()!==e.title||c.trim()!==e.path;async function _(t){t.preventDefault(),await a.run(()=>C.kb.updateDocument(e.id,{expected_revision:e.revision,title:o.trim(),path:c.trim(),labels:d,description:m.trim()}))&&(await i(),r())}return(0,Z.jsx)(Dn,{open:!0,onClose:n,title:`Document properties`,children:(0,Z.jsxs)(`form`,{onSubmit:_,className:`space-y-4`,children:[(0,Z.jsx)($,{label:`Title`,children:(0,Z.jsx)(G,{"aria-label":`Title`,"data-testid":`kb-doc-title-input`,value:o,onChange:e=>s(e.target.value)})}),(0,Z.jsx)($,{label:`Path`,children:(0,Z.jsx)(G,{"aria-label":`Path`,"data-testid":`kb-doc-path-input`,value:c,onChange:e=>l(e.target.value),className:`font-mono text-sm`})}),(0,Z.jsx)($,{label:`Labels`,hint:`Enter, comma or space adds a label.`,children:(0,Z.jsx)(Nt,{"aria-label":`Labels`,"data-testid":`kb-doc-labels-input`,value:d,onChange:f,suggestions:u.data?.labels.map(e=>e.label)})}),(0,Z.jsx)($,{label:`Description`,children:(0,Z.jsx)(Se,{"aria-label":`Description`,value:m,onChange:e=>h(e.target.value),rows:2})}),g&&t>0&&(0,Z.jsxs)(`p`,{role:`status`,className:`text-sm text-warning`,"data-testid":`kb-rename-warning`,children:[t===1?`1 document links`:`${t} documents link`,` to this document. Links that use the old title or path will show as missing.`]}),(0,Z.jsx)(En,{error:a.error}),(0,Z.jsxs)(q,{children:[(0,Z.jsx)(p,{type:`button`,variant:`ghost`,onClick:n,children:`Cancel`}),(0,Z.jsx)(p,{type:`submit`,"data-testid":`kb-doc-properties-save`,disabled:!o.trim()||a.pending,children:`Save`})]})]})})}var Rn={daily:`Every day`,weekly:`Once a week`,custom:`Custom cron`,manual:`Manual only`};function zn(e){let t=e.type===`cron`?e.cron:tn,n={plan:`custom`,time:`03:00`,day:`1`,cron:t},r=/^(\d{1,2}) (\d{1,2}) \* \* (\*|[0-6])$/.exec(t.trim().split(/\s+/).join(` `)),[i,a]=[Number(r?.[1]),Number(r?.[2])],o=r&&i<=59&&a<=23?`${String(a).padStart(2,`0`)}:${String(i).padStart(2,`0`)}`:null;return e.type===`manual`?{...n,plan:`manual`,time:o??n.time}:!r?.[3]||!o?n:r[3]===`*`?{...n,plan:`daily`,time:o}:{...n,plan:`weekly`,time:o,day:r[3]}}function Bn({plan:e,time:t,day:n,cron:r}){if(e===`manual`)return null;if(e===`custom`)return r.trim();let[i,a]=t.split(`:`).map(Number);return`${a} ${i} * * ${e===`weekly`?n:`*`}`}function Vn(e){return e.plan===`manual`?null:e.plan===`custom`?pn(e.cron):/^\d{2}:\d{2}$/.test(e.time)?null:`Pick a time.`}function Hn(e){let t=un(e);return t===e?`Runs on this cron schedule`:an.some(e=>t.startsWith(e))?`Runs ${t}`:`Runs ${t.charAt(0).toLowerCase()}${t.slice(1)}`}function Un({value:e,onChange:t}){let n=Bn(e),r=Vn(e),i=n=>t({...e,...n});return(0,Z.jsxs)(`fieldset`,{className:`space-y-3 rounded-md border border-outline-variant p-3`,children:[(0,Z.jsx)(`legend`,{className:`px-1 text-sm text-muted-foreground`,children:`When it runs`}),(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,Z.jsx)($,{label:`Schedule`,children:(0,Z.jsxs)(W,{value:e.plan,onValueChange:e=>i({plan:e,...e===`custom`&&n?{cron:n}:{}}),children:[(0,Z.jsx)(Re,{"aria-label":`Schedule`,"data-testid":`kb-digest-schedule`,children:(0,Z.jsx)(Me,{})}),(0,Z.jsx)(z,{children:Object.keys(Rn).map(e=>(0,Z.jsx)(K,{value:e,children:Rn[e]},e))})]})}),e.plan===`weekly`&&(0,Z.jsx)($,{label:`Day`,children:(0,Z.jsxs)(W,{value:e.day,onValueChange:e=>i({day:e}),children:[(0,Z.jsx)(Re,{"aria-label":`Day`,"data-testid":`kb-digest-day`,children:(0,Z.jsx)(Me,{})}),(0,Z.jsx)(z,{children:an.map((e,t)=>(0,Z.jsx)(K,{value:String(t),children:e},e))})]})}),(e.plan===`daily`||e.plan===`weekly`)&&(0,Z.jsx)($,{label:`Time`,children:(0,Z.jsx)(G,{type:`time`,"aria-label":`Time`,"data-testid":`kb-digest-time`,value:e.time,onChange:e=>i({time:e.target.value})})}),e.plan===`custom`&&(0,Z.jsx)(`div`,{className:`sm:col-span-2`,children:(0,Z.jsx)($,{label:`Cron expression`,hint:`minute hour day month weekday, e.g. 0 */6 * * *`,children:(0,Z.jsx)(G,{"aria-label":`Cron expression`,"aria-invalid":r!==null,"data-testid":`kb-digest-cron`,value:e.cron,onChange:e=>i({cron:e.target.value}),className:`font-mono`,autoComplete:`off`})})})]}),(0,Z.jsx)(`p`,{"aria-live":`polite`,"data-testid":`kb-digest-schedule-preview`,"data-valid":r===null,className:`text-sm ${r?`text-error`:`text-outline`}`,children:r||(n?(0,Z.jsxs)(Z.Fragment,{children:[Hn(n),` `,(0,Z.jsxs)(`span`,{className:`font-mono text-xs`,children:[`(`,n,`)`]}),`, in the ORC server's time zone.`]}):`Runs only when you start it.`)})]})}function Wn({kb:e,digest:t,onClose:n,onRemove:r}){let i=J(),a=Q(),o=fe(),s=kt(!t),[c,l]=(0,Y.useState)(t?.instructions??null),[u,d]=(0,Y.useState)(t?.backend??`__default__`),[f,m]=(0,Y.useState)(()=>zn(t?.schedule??{type:`cron`,cron:`0 3 * * *`}));(0,Y.useEffect)(()=>{c===null&&s.data&&l(s.data.instructions)},[c,s.data]);let h=Vn(f);async function g(t){if(t.preventDefault(),h)return a.setError(h);let r=u===`__default__`?o.data?.default_backend:u,s=Bn(f);await a.run(()=>C.kb.setDigest(e.id,{instructions:c?.trim()??``,...r?{backend:r}:{},schedule:s?{type:`cron`,cron:s}:{type:`manual`}}))&&(await i(),n())}let _=c!==null;return(0,Z.jsx)(Dn,{open:!0,onClose:n,title:t?`Digest settings`:`Set up a digest`,wide:!0,children:(0,Z.jsxs)(`form`,{onSubmit:g,className:`min-w-0 space-y-4`,children:[!e.editable_by.includes(`mcp`)&&(0,Z.jsx)(`p`,{className:`text-sm text-warning`,"data-testid":`kb-digest-mcp-hint`,children:`The digest writes through MCP. Allow Agents (MCP) in this knowledge base's settings first.`}),(0,Z.jsx)(Un,{value:f,onChange:m}),(0,Z.jsx)(B,{value:u,onChange:d,testId:`kb-digest-backend`}),(0,Z.jsx)($,{label:`Instructions`,children:_?(0,Z.jsx)(ke,{path:`digest.md`,value:c,onChange:l,testId:`kb-digest-instructions`,label:`Instructions`,initialMode:`edit`,height:320}):s.error?(0,Z.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:Tn(s.error)}):(0,Z.jsx)(`p`,{role:`status`,className:`text-sm text-outline`,children:`Loading template…`})}),(0,Z.jsx)(En,{error:a.error}),(0,Z.jsxs)(q,{className:`gap-2 sm:justify-between`,children:[t&&r?(0,Z.jsxs)(p,{type:`button`,variant:`ghost`,className:`text-error`,"data-testid":`kb-digest-remove`,onClick:r,children:[(0,Z.jsx)(_e,{size:14}),`Remove digest`]}):(0,Z.jsx)(`span`,{}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(p,{type:`button`,variant:`ghost`,onClick:n,children:`Cancel`}),(0,Z.jsx)(p,{type:`submit`,"data-testid":`kb-digest-save`,disabled:!_||!c?.trim()||h!==null||a.pending,children:a.pending?`Saving…`:`Save`})]})]})]})})}function Gn({kb:e,onClose:t}){let n=r(),i=Q();async function a(){await i.run(()=>C.kb.removeDigest(e.id,e.name))!==void 0&&(n.setQueryData([Et,e.id],{digest:null}),await n.invalidateQueries({queryKey:[`kb`]}),t())}return(0,Z.jsx)(Dn,{open:!0,onClose:t,title:`Remove digest?`,children:(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-outline`,children:`Documents and comments stay. The digest's instructions, schedule, job and run history are removed.`}),(0,Z.jsx)(En,{error:i.error}),(0,Z.jsxs)(q,{children:[(0,Z.jsx)(p,{type:`button`,variant:`ghost`,onClick:t,children:`Cancel`}),(0,Z.jsx)(p,{type:`button`,variant:`destructive`,"data-testid":`kb-digest-remove-confirm`,onClick:a,disabled:i.pending,autoFocus:!0,children:i.pending?`Removing…`:`Remove digest`})]})]})})}var Kn={open:`bg-warning`,resolved:`bg-secondary`,dismissed:`bg-muted-foreground`};function qn({status:e}){return(0,Z.jsx)(`span`,{"aria-hidden":!0,className:f(`size-1.5 shrink-0 rounded-full`,Kn[e])})}function Jn({kbId:e,documentId:t,onOpenDocument:n,heading:r=`h3`,compact:i=!1}){let[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(null),l=Ct(e,{...t?{document_id:t}:{},...s?{status:s}:{}}),u=l.data?.counts,d=u?u.open+u.resolved+u.dismissed:0;function p(e){c(a&&s===e?null:e),o(!0)}return(0,Z.jsx)(nn,{title:`Comments`,testId:`kb-comments`,toggleTestId:`kb-comments-toggle`,heading:r,compact:i,expanded:a,onExpandedChange:o,summary:(0,Z.jsxs)(Z.Fragment,{children:[u&&d===0&&(0,Z.jsx)(`span`,{className:`text-outline`,"data-testid":`kb-comments-none`,children:`None yet`}),u&&$t.filter(e=>u[e]>0).map(e=>(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`kb-comments-count-${e}`,"aria-pressed":a&&s===e,"aria-label":`${u[e]} ${e} ${u[e]===1?`comment`:`comments`}`,className:f(`inline-flex min-h-8 items-center gap-1.5 rounded px-1.5`,a&&s===e?`bg-surface-highest text-on-surface`:`text-outline hover:bg-surface-high`),onClick:()=>p(e),children:[(0,Z.jsx)(qn,{status:e}),(0,Z.jsx)(`span`,{className:`tabular-nums text-on-surface`,children:u[e]}),e]},e)),l.error&&(0,Z.jsx)(`span`,{role:`alert`,className:`text-error`,"data-testid":`kb-comments-error`,children:l.error.message})]}),children:(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)(Yn,{kbId:e,documentId:t}),s&&l.data?.comments.length===0&&(0,Z.jsxs)(`p`,{className:`text-outline`,"data-testid":`kb-comments-empty`,children:[`No `,s,` comments.`]}),(0,Z.jsx)(`ul`,{className:`divide-y divide-outline-variant`,children:l.data?.comments.map(e=>(0,Z.jsx)(Xn,{comment:e,showDocument:!t,onOpenDocument:n},e.id))})]})})}function Yn({kbId:e,documentId:t}){let n=J(),r=Q(),[i,a]=(0,Y.useState)(``);async function o(o){o.preventDefault(),await r.run(()=>C.kb.addComment(e,{body:i.trim(),...t?{document_id:t}:{}}))&&(a(``),await n())}return(0,Z.jsxs)(`form`,{onSubmit:o,className:`space-y-2`,children:[(0,Z.jsx)(Se,{"aria-label":t?`Comment on this document`:`Comment on this knowledge base`,placeholder:t?`Ask for a change to this document`:`Ask for a change`,"data-testid":`kb-comment-input`,value:i,onChange:e=>a(e.target.value),rows:2,maxLength:1e4}),i.trim()&&(0,Z.jsx)(p,{type:`submit`,size:`sm`,variant:`outline`,"data-testid":`kb-comment-add`,disabled:r.pending,children:`Add comment`}),r.error&&(0,Z.jsx)(`p`,{role:`alert`,className:`text-error`,"data-testid":`kb-comment-add-error`,children:r.error})]})}function Xn({comment:e,showDocument:t,onOpenDocument:n}){let r=J(),i=Q(),[a,o]=(0,Y.useState)(null),[s,c]=(0,Y.useState)(``);async function l(t){if(t.preventDefault(),!a)return;let n=a;await i.run(()=>C.kb.closeComment(e.id,{status:n,reply:s.trim()}))&&(o(null),c(``),await r())}async function u(){await i.run(()=>C.kb.reopenComment(e.id))&&await r()}return(0,Z.jsxs)(`li`,{"data-testid":`kb-comment`,"data-status":e.status,className:`min-w-0 space-y-1 py-2`,children:[(0,Z.jsxs)(`p`,{className:`flex min-w-0 flex-wrap items-center gap-x-2 text-xs text-outline`,children:[(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-on-surface`,children:[(0,Z.jsx)(qn,{status:e.status}),(0,Z.jsx)(`span`,{"data-testid":`kb-comment-status`,children:e.status})]}),(0,Z.jsxs)(`span`,{className:`min-w-0 wrap-break-word`,children:[e.source===e.author?e.author:`${e.author} via ${e.source}`,` ·`,` `,new Date(e.created_at).toLocaleString(),t&&e.document_id&&(0,Z.jsxs)(Z.Fragment,{children:[` · on `,n?(0,Z.jsx)(`button`,{type:`button`,className:`text-primary hover:underline`,onClick:()=>e.document_id&&n(e.document_id),children:e.document_title??`a deleted document`}):e.document_title??`a deleted document`]})]})]}),(0,Z.jsx)(`p`,{className:`whitespace-pre-wrap wrap-break-word`,children:e.body}),e.reply&&(0,Z.jsxs)(`p`,{className:`wrap-break-word text-xs`,"data-testid":`kb-comment-reply-text`,children:[(0,Z.jsxs)(`span`,{className:`text-outline`,children:[e.status===`dismissed`?`Dismissed`:`Resolved`,e.resolved_by?` by ${e.resolved_by}`:``,`:`]}),` `,e.reply]}),a?(0,Z.jsxs)(`form`,{onSubmit:l,className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(G,{"aria-label":a===`resolved`?`Resolution reply`:`Reason for dismissing`,placeholder:a===`resolved`?`What changed`:`Why not`,"data-testid":`kb-comment-reply`,value:s,onChange:e=>c(e.target.value),maxLength:4e3,autoFocus:!0,className:`min-w-0 flex-1 basis-48`}),(0,Z.jsx)(p,{type:`submit`,size:`sm`,"data-testid":`kb-comment-close-submit`,disabled:!s.trim()||i.pending,children:a===`resolved`?`Resolve`:`Dismiss`}),(0,Z.jsx)(p,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>{o(null),c(``),i.setError(null)},children:`Cancel`})]}):e.status===`open`?(0,Z.jsxs)(`div`,{className:`-ml-2 flex flex-wrap`,children:[(0,Z.jsx)(p,{size:`sm`,variant:`ghost`,"data-testid":`kb-comment-resolve`,onClick:()=>o(`resolved`),children:`Resolve`}),(0,Z.jsx)(p,{size:`sm`,variant:`ghost`,"data-testid":`kb-comment-dismiss`,onClick:()=>o(`dismissed`),children:`Dismiss`})]}):(0,Z.jsx)(p,{size:`sm`,variant:`ghost`,className:`-ml-2`,"data-testid":`kb-comment-reopen`,onClick:u,disabled:i.pending,children:`Reopen`}),i.error&&(0,Z.jsx)(`p`,{role:`alert`,className:`text-xs text-error`,"data-testid":`kb-comment-error`,children:i.error})]})}var Zn=e=>`kb:${e}`,Qn={pending:`Processing`,partial:`Partially parsed`,failed:`Failed`,lexical_ready:`Keyword search ready`,semantic_pending:`Embedding`,semantic_ready:`Semantic search ready`};function $n(e){let t=[...e.currentTarget.querySelectorAll(`[role="menuitem"]:not(:disabled)`)],n=t.indexOf(document.activeElement),r=e.key===`ArrowDown`?(n+1)%t.length:e.key===`ArrowUp`?(n-1+t.length)%t.length:e.key===`Home`?0:e.key===`End`?t.length-1:null;r!==null&&t.length&&(e.preventDefault(),t[r]?.focus())}function er({usage:e,testId:t}){return(0,Z.jsxs)(`div`,{"data-testid":t,className:`space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`text-sm`,children:[(0,Z.jsx)(`span`,{"data-testid":`${t}-reads`,className:`font-medium`,children:e.reads}),` `,`reads · `,e.exposures,` search appearances · `,e.distinct_sessions,` sessions`]}),(0,Z.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{className:`text-outline`,children:[(0,Z.jsx)(`th`,{className:`py-1 text-left font-normal`,children:`Source`}),Ht.map(e=>(0,Z.jsx)(`th`,{className:`py-1 text-right font-normal`,children:e===`search_hit`?`listed`:e},e))]})}),(0,Z.jsx)(`tbody`,{children:X.map(n=>(0,Z.jsxs)(`tr`,{"data-testid":`${t}-${n}`,className:`border-t border-outline-variant/50`,children:[(0,Z.jsx)(`td`,{className:`py-1 uppercase`,children:n}),Ht.map(t=>(0,Z.jsx)(`td`,{className:`py-1 text-right tabular-nums`,children:e.totals[n][t]},t))]},n))})]}),(0,Z.jsxs)(`div`,{className:`text-xs text-outline`,children:[`Last 7 days `,e.window.days_7,` · last 30 days `,e.window.days_30]})]})}function tr({kb:e,doc:t,onHome:n,onOpen:r,onDeleted:i,onReplaceFile:a,detailsOpen:o,onDetailsOpenChange:c}){let l=J(),[u]=s(),m=u.get(`editorMode`),h=Ct(t.kb_id,{document_id:t.id}).data?.counts.open??0,[g,_]=(0,Y.useState)(!1),[v,y]=(0,Y.useState)(!1),[b,x]=(0,Y.useState)(!1),S=Ne(`lg`),[w,E]=(0,Y.useState)(null),D=(0,Y.useRef)(null),[O,k]=(0,Y.useState)(null),[A,j]=(0,Y.useState)(!1),M=(0,Y.useRef)(null),N=(0,Y.useRef)(t.revision),P=new Map(t.links.filter(e=>e.document_id).map(e=>[Je(e.target),e.document_id])),F={slugs:[...P.keys()],select:e=>{let t=P.get(e);t&&r(t)}};async function I(e){j(!0),k(null);try{return await e(),await l(),!0}catch(e){return k(e instanceof Error?e.message:`Request failed`),!1}finally{j(!1)}}async function L(){await I(async()=>Xe(await C.kb.original(t.id),t.original_name??t.path.split(`/`).pop()??`document`))}function R(){let e=(t.path.split(`/`).pop()??`document`).replace(/\.(md|markdown)$/i,``);Xe(new Blob([t.content],{type:`text/markdown;charset=utf-8`}),`${e}.md`)}let z=t.origin===`upload`,ee=z||t.origin===`external`&&!t.editable,B=w?.backlinks.filter(e=>!t.backlinks.some(t=>t.document_id===e.document_id))??[],V=(e,t,n,r,i=!1)=>(0,Z.jsxs)(`button`,{type:`button`,role:`menuitem`,"data-testid":e,disabled:A,className:f(`flex min-h-9 w-full items-center gap-2 rounded px-2 text-left text-sm outline-hidden hover:bg-surface-highest focus-visible:bg-surface-highest disabled:opacity-50`,i&&`text-error`),onClick:()=>{x(!1),r()},children:[t,n]});return(0,Z.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-y-auto lg:flex-row lg:overflow-hidden`,children:[(0,Z.jsx)(`article`,{"data-testid":`kb-document`,className:`min-w-0 lg:min-h-0 lg:flex-1 lg:overflow-y-auto`,children:(0,Z.jsxs)(`div`,{className:`w-full min-w-0 px-4 pb-16 pt-4 sm:px-8 sm:pt-6`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,Z.jsxs)(`nav`,{"aria-label":`Breadcrumb`,className:`flex min-w-0 flex-1 basis-48 items-center gap-1 text-sm text-outline`,children:[(0,Z.jsx)(`button`,{type:`button`,"data-testid":`kb-breadcrumb-kb`,className:`min-w-0 max-w-[60%] truncate hover:text-on-surface hover:underline`,onClick:n,children:e.name}),(0,Z.jsx)(Fe,{size:14,className:`shrink-0`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`min-w-0 truncate font-mono text-xs`,"data-testid":`kb-document-path`,title:t.path,children:t.path})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,Z.jsxs)(p,{size:`sm`,variant:o?`secondary`:`ghost`,"aria-pressed":o,"data-testid":`kb-details-toggle`,onClick:()=>c(!o),children:[(0,Z.jsx)(oe,{size:14}),`Details`,h>0&&(0,Z.jsxs)(`span`,{"data-testid":`kb-details-open-comments`,title:`${h} open ${h===1?`comment`:`comments`}`,className:`inline-flex items-center gap-1 text-xs tabular-nums text-outline`,children:[(0,Z.jsx)(rn,{tone:`warning`}),h]})]}),(0,Z.jsxs)(je,{open:b,onOpenChange:x,children:[(0,Z.jsx)(xe,{asChild:!0,children:(0,Z.jsx)(p,{size:`icon`,variant:`ghost`,"aria-label":`Document actions`,"aria-haspopup":`menu`,"data-testid":`kb-doc-menu`,children:(0,Z.jsx)(ce,{size:16})})}),(0,Z.jsxs)(be,{"data-testid":`kb-doc-actions-menu`,align:`end`,sideOffset:4,collisionPadding:8,role:`menu`,"aria-label":`Document actions`,className:`z-50 w-52 rounded-md border border-outline-variant bg-surface-high p-1 shadow-lg`,onOpenAutoFocus:e=>{e.preventDefault(),e.currentTarget.querySelector(`[role="menuitem"]:not(:disabled)`)?.focus()},onKeyDown:$n,children:[V(`kb-doc-properties`,(0,Z.jsx)(U,{size:14}),`Title and labels`,()=>{D.current={title:t.title,backlinks:t.backlinks},_(!0)}),!ee&&V(`kb-doc-download-markdown`,(0,Z.jsx)(Lt,{size:14}),`Download Markdown`,R),ee&&V(`kb-doc-download`,(0,Z.jsx)(T,{size:14}),`Download original`,()=>void L()),z&&V(`kb-doc-reparse`,(0,Z.jsx)(Ee,{size:14}),`Parse again`,()=>void I(()=>C.kb.reparse(t.id))),z&&V(`kb-doc-replace`,(0,Z.jsx)(zt,{size:14}),`Replace file`,()=>M.current?.click()),t.origin!==`external`&&V(`kb-doc-delete`,(0,Z.jsx)(_e,{size:14}),`Delete document`,()=>y(!0),!0)]})]})]})]}),(0,Z.jsxs)(`header`,{className:`mb-2 mt-4 space-y-2`,children:[(0,Z.jsx)(`h1`,{"data-testid":`kb-document-title`,className:`wrap-break-word text-3xl font-medium`,children:t.title}),t.description&&(0,Z.jsx)(`p`,{className:`text-outline`,children:t.description}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1.5 text-xs text-outline`,children:[t.labels.length>0&&(0,Z.jsx)(`span`,{className:`flex flex-wrap gap-1`,children:t.labels.map(e=>(0,Z.jsx)(At,{variant:`secondary`,"data-testid":`kb-document-label`,children:e},e))}),t.parse_state!==`ok`&&(0,Z.jsxs)(`span`,{className:f(`inline-flex items-center gap-1.5`,t.parse_state===`failed`&&`text-error`),children:[(0,Z.jsx)(rn,{tone:t.parse_state===`failed`?`error`:t.parse_state===`partial`?`warning`:`progress`}),(0,Z.jsx)(`span`,{"data-testid":`kb-parse-state`,children:Qn[t.parse_state]})]}),t.folder_sync&&(0,Z.jsx)(`span`,{"data-testid":`kb-folder-sync`,title:t.folder_sync===`following`?`Copied from a synced folder; scans pick up changes to the file`:`Edited in ORC; scans no longer change this copy`,children:t.folder_sync===`following`?`Follows folder file`:`Edited, no longer synced`}),t.stale&&(0,Z.jsx)(`span`,{className:`text-warning`,"data-testid":`kb-document-stale`,children:`Stale: a source changed`}),(0,Z.jsxs)(`span`,{children:[`Updated `,new Date(t.updated_at).toLocaleDateString(),` by `,t.updated_by]})]})]}),t.warnings.length>0&&(0,Z.jsx)(`ul`,{"data-testid":`kb-document-warnings`,className:`mb-2 space-y-1 text-sm text-warning`,children:t.warnings.map(e=>(0,Z.jsxs)(`li`,{className:`flex gap-2`,children:[(0,Z.jsx)(Ge,{size:14,className:`mt-0.5 shrink-0`}),e]},e))}),z&&(0,Z.jsxs)(`p`,{className:`mb-2 text-sm text-outline`,children:[`Text parsed from `,t.original_name??`the upload`,` (`,d(t.size_bytes),t.parser?`, ${t.parser.id} ${t.parser.version}`:``,`). Replace the file to change it.`]}),t.folder_sync===`following`&&(m===`edit`||m===`split`)&&(0,Z.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.`}),O&&(0,Z.jsx)(`p`,{role:`alert`,"data-testid":`kb-document-error`,className:`mb-2 text-sm text-error`,children:O}),w&&B.length>0&&(0,Z.jsxs)(`div`,{role:`status`,"data-testid":`kb-rename-broken-links`,className:`mb-2 flex flex-wrap items-center gap-x-2 text-sm text-warning`,children:[(0,Z.jsx)(Ge,{size:14,className:`shrink-0`,"aria-hidden":!0}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[B.length===1?`1 document`:`${B.length} documents`,` linked to “`,w.title,`” by its old title or path; those links now show as missing:`,` `,B.map((e,t)=>(0,Z.jsxs)(`span`,{children:[t>0&&`, `,(0,Z.jsx)(`button`,{type:`button`,className:`underline underline-offset-2 hover:text-on-surface`,onClick:()=>r(e.document_id),children:e.title})]},e.document_id))]}),(0,Z.jsx)(p,{size:`sm`,variant:`ghost`,onClick:()=>E(null),children:`Dismiss`})]}),(0,Z.jsx)(gt,{documentId:Zn(t.id),path:t.editable?t.path:`${t.path}.md`,content:t.content,wikiLinks:F,testId:`kb-document-content`,layout:`page`,pageTitle:t.title,hideFrontmatter:!0,onSave:t.editable?async(e,n)=>{try{let r=await C.kb.updateDocument(t.id,{expected_revision:n===t.content?t.revision:N.current,content:e});return N.current=r.revision,e}finally{await l()}}:void 0},Zn(t.id))]})}),o&&S&&(0,Z.jsx)(rr,{doc:t,onOpen:r}),!S&&(0,Z.jsx)(H,{open:o,onOpenChange:c,children:(0,Z.jsxs)(ue,{defaultWidth:360,resizeKey:`kb-properties`,"aria-describedby":void 0,children:[(0,Z.jsx)(se,{className:`py-3`,children:(0,Z.jsx)(De,{children:`Details`})}),(0,Z.jsx)(He,{className:`p-0 sm:p-0`,children:(0,Z.jsx)(rr,{doc:t,onOpen:(e,t)=>{c(!1),r(e,t)}})})]})}),(0,Z.jsx)(`input`,{ref:M,type:`file`,hidden:!0,"data-testid":`kb-doc-replace-input`,onChange:e=>{let t=e.target.files?.[0];t&&a(t),e.target.value=``}}),g&&(0,Z.jsx)(Ln,{doc:t,linkedFrom:t.backlinks.length,onClose:()=>_(!1),onSaved:()=>{_(!1),E(D.current)}}),(0,Z.jsx)(Ye,{open:v,title:`Delete document`,description:`Delete "${t.title}" and its revision history${z?` and uploaded file`:``}?`,isPending:A,onCancel:()=>y(!1),onConfirm:async()=>{y(!1),await I(()=>C.kb.removeDocument(t.id))&&i()}})]})}function nr({title:e,children:t}){return(0,Z.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`h2`,{className:`text-sm font-medium text-outline`,children:e}),t]})}function rr({doc:e,onOpen:t}){let n=wt(e.id),r=Ot(e.id),i=`block min-h-8 w-full wrap-break-word text-left text-primary hover:underline`;return(0,Z.jsxs)(`aside`,{"data-testid":`kb-document-details`,"aria-label":`Document details`,className:`w-full shrink-0 space-y-6 p-4 text-sm lg:min-h-0 lg:w-80 lg:overflow-y-auto lg:border-l lg:border-outline-variant`,children:[e.outline.length>0&&(0,Z.jsx)(nr,{title:`On this page`,children:(0,Z.jsx)(`nav`,{"aria-label":`Outline`,className:`space-y-0.5`,children:e.outline.map(n=>(0,Z.jsx)(`button`,{type:`button`,className:`block min-h-7 w-full truncate text-left text-outline hover:text-on-surface`,style:{paddingLeft:`${(n.level-1)*.75}rem`},onClick:()=>t(e.id,n.text),children:n.text},`${n.block}-${n.text}`))})}),e.links.length>0&&(0,Z.jsx)(nr,{title:`Links to (${e.links.length})`,children:e.links.map(e=>e.document_id?(0,Z.jsx)(`button`,{type:`button`,"data-testid":`kb-outgoing-link`,className:i,onClick:()=>t(e.document_id),children:e.title??e.target},e.target):(0,Z.jsxs)(`p`,{className:`py-1 text-outline`,"data-testid":`kb-unresolved-link`,children:[e.target,` `,(0,Z.jsx)(`span`,{className:`text-xs`,children:`(no such document)`})]},e.target))}),e.backlinks.length>0&&(0,Z.jsx)(nr,{title:`Linked from (${e.backlinks.length})`,children:e.backlinks.map(e=>(0,Z.jsx)(`button`,{type:`button`,"data-testid":`kb-backlink`,className:i,onClick:()=>t(e.document_id),children:e.title},e.document_id))}),(0,Z.jsx)(`div`,{className:`border-y border-outline-variant`,children:(0,Z.jsx)(Jn,{kbId:e.kb_id,documentId:e.id,heading:`h2`,compact:!0})}),(0,Z.jsxs)(`details`,{"data-testid":`kb-doc-history`,className:`group`,children:[(0,Z.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer list-none items-center gap-1.5 font-medium [&::-webkit-details-marker]:hidden`,children:[(0,Z.jsx)(Fe,{size:14,"aria-hidden":!0,className:`text-outline transition-transform group-open:rotate-90`}),`Usage and history`]}),(0,Z.jsxs)(`div`,{className:`mt-3 space-y-5 pl-5`,children:[n.data?(0,Z.jsx)(er,{usage:n.data,testId:`kb-doc-usage`}):(0,Z.jsx)(`p`,{className:`text-outline`,children:n.error?`Usage unavailable`:`Loading…`}),(0,Z.jsx)(`ol`,{className:`space-y-2`,"data-testid":`kb-revisions`,children:r.data?.map(e=>(0,Z.jsxs)(`li`,{"data-testid":`kb-revision`,children:[(0,Z.jsxs)(`div`,{children:[`Revision `,e.revision,` · `,e.actor,(0,Z.jsxs)(`span`,{className:`text-outline`,children:[` via `,e.source]})]}),(0,Z.jsxs)(`div`,{className:`text-xs text-outline`,children:[new Date(e.created_at).toLocaleString(),e.note?` · ${e.note}`:``]})]},e.revision))}),(0,Z.jsxs)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 text-xs text-outline`,children:[(0,Z.jsx)(`dt`,{children:`Search`}),(0,Z.jsx)(`dd`,{"data-testid":`kb-index-state`,children:Qn[e.index_state]??e.index_state}),(0,Z.jsx)(`dt`,{children:`Origin`}),(0,Z.jsx)(`dd`,{children:e.origin}),(0,Z.jsx)(`dt`,{children:`Type`}),(0,Z.jsx)(`dd`,{children:e.media_type}),(0,Z.jsx)(`dt`,{children:`Size`}),(0,Z.jsx)(`dd`,{children:d(e.size_bytes)}),(0,Z.jsx)(`dt`,{children:`Updated`}),(0,Z.jsxs)(`dd`,{children:[new Date(e.updated_at).toLocaleString(),` by `,e.updated_by]}),(0,Z.jsx)(`dt`,{children:`ID`}),(0,Z.jsx)(`dd`,{className:`break-all font-mono`,children:e.id})]})]})]})]})}function ir(e){return`${e.added} added · ${e.updated} updated · ${e.missing} missing${e.errors.length?` · ${e.errors.length} errors: ${e.errors.slice(0,3).join(`; `)}`:``}`}var ar=(e,t,n)=>`${e} ${e===1?t:n}`;function or(){return/win/i.test(navigator.platform)?`Choose a folder or type its full path, e.g. C:\\notes`:/mac/i.test(navigator.platform)?`Choose a folder or type its full path, e.g. /Users/you/notes`:`Choose a folder or type its full path, e.g. /home/you/notes`}function sr(e){let t=e.document_count-e.edited_count,n=t?`${ar(t,`synced copy is`,`synced copies are`)} removed from this knowledge base`:`No synced copies are removed`,r=e.edited_count?`; ${ar(e.edited_count,`edited copy is`,`edited copies are`)} kept as documents`:``;return`Stop syncing ${e.root_path}? ${n}${r}. Files on disk are not touched.`}function cr(e){return e.replace(/[\\/]+$/,``).split(/[\\/]/).pop()||e}function lr({kb:e}){let t=St(e.id),n=J(),r=Q(),[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(`**/*.md`),[u,d]=(0,Y.useState)(null),[f,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)(!1),y=t.data??[],b=y.filter(e=>e.last_error).length,x=y.reduce((e,t)=>e+t.document_count,0);function S(){a(!0),g(!0)}function w(){g(!1),s(``),r.setError(null),y.length===0&&a(!1)}async function T(){v(!0),r.setError(null);try{let{path:e}=await C.terminals.pickFolder(o.trim()||void 0);e&&s(e)}catch(e){r.setError(e instanceof Error?e.message:String(e))}finally{v(!1)}}async function E(t){t.preventDefault();let i=await r.run(()=>C.kb.addSource(e.id,{root_path:o.trim(),pattern:c.trim()||`**/*.md`}));i&&(s(``),g(!1),d(ir(i.scan)),await n())}return(0,Z.jsxs)(nn,{title:`Synced folders`,testId:`kb-folders`,toggleTestId:`kb-sources`,expanded:i,onExpandedChange:e=>{a(e),g(e&&y.length===0)},summary:t.isLoading?(0,Z.jsx)(`span`,{className:`text-outline`,children:`Loading…`}):y.length===0?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-outline`,"data-testid":`kb-folders-none`,children:[(0,Z.jsx)(rn,{tone:`off`}),`None`]}):(0,Z.jsxs)(`span`,{className:`inline-flex min-w-0 max-w-full items-center gap-1.5`,"data-testid":`kb-folders-summary`,children:[(0,Z.jsx)(rn,{tone:b?`error`:`ok`}),y.length===1?(0,Z.jsx)(`span`,{className:`min-w-0 truncate`,title:y[0]?.root_path,children:cr(y[0]?.root_path??``)}):`${y.length} folders`,(0,Z.jsxs)(`span`,{className:`shrink-0 text-outline`,children:[`· `,x,` `,x===1?`document`:`documents`,b?` · ${b} failing`:``]})]}),actions:y.length===0&&!i?(0,Z.jsx)(p,{size:`sm`,variant:`outline`,"data-testid":`kb-folders-add`,onClick:S,children:`Add folder`}):null,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 space-y-3`,children:[(0,Z.jsx)(`p`,{className:`max-w-prose text-outline`,children:`Matching files are copied in and kept in sync: ORC rescans every minute while the daemon runs, or when you choose Scan now. A copy you edit here stops following its file. ORC never writes to the folder.`}),y.length>0&&(0,Z.jsx)(`ul`,{className:`divide-y divide-outline-variant`,"data-testid":`kb-sources-list`,children:y.map(e=>(0,Z.jsxs)(`li`,{"data-testid":`kb-source-row`,className:`flex min-w-0 flex-wrap items-center gap-2 py-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1 basis-56`,children:[(0,Z.jsx)(`div`,{className:`font-medium`,children:cr(e.root_path)}),(0,Z.jsx)(`div`,{className:`break-all font-mono text-xs text-outline`,children:e.root_path}),(0,Z.jsxs)(`div`,{className:`text-xs text-outline`,children:[e.pattern,` · `,ar(e.document_count,`document`,`documents`),e.edited_count?` (${e.edited_count} edited)`:``,` ·`,` `,e.last_scan_at?(0,Z.jsxs)(`span`,{title:new Date(e.last_scan_at).toLocaleString(),children:[`scanned `,hn(e.last_scan_at)]}):`not scanned yet`]}),e.last_error&&(0,Z.jsx)(`div`,{className:`text-xs text-error`,children:e.last_error})]}),(0,Z.jsxs)(p,{variant:`ghost`,size:`sm`,"data-testid":`kb-source-scan`,disabled:r.pending,onClick:async()=>{let t=await r.run(()=>C.kb.scanSource(e.id));t&&d(ir(t)),await n()},children:[(0,Z.jsx)(Vt,{size:14}),`Scan now`]}),(0,Z.jsx)(p,{variant:`ghost`,size:`sm`,title:`Stop syncing ${e.root_path}`,"data-testid":`kb-source-remove`,onClick:()=>m(e),children:`Stop syncing`})]},e.id))}),u&&(0,Z.jsx)(`p`,{role:`status`,"data-testid":`kb-source-result`,className:`text-outline`,children:u}),h?(0,Z.jsxs)(`form`,{onSubmit:E,className:`min-w-0 space-y-3`,"data-testid":`kb-source-form`,children:[(0,Z.jsxs)(`div`,{className:`grid min-w-0 gap-3 sm:grid-cols-[minmax(0,1fr)_12rem]`,children:[(0,Z.jsx)($,{label:`Folder path`,hint:or(),children:(0,Z.jsxs)(`div`,{className:`flex min-w-0 gap-2`,children:[(0,Z.jsx)(G,{"aria-label":`Folder path`,"data-testid":`kb-source-path-input`,value:o,onChange:e=>s(e.target.value),className:`min-w-0 font-mono text-sm`,autoFocus:!0}),(0,Z.jsxs)(p,{type:`button`,variant:`outline`,"data-testid":`kb-source-choose-folder`,onClick:T,disabled:_,className:`shrink-0`,children:[(0,Z.jsx)(ne,{size:14}),_?`Choosing…`:`Choose folder`]})]})}),(0,Z.jsx)($,{label:`File pattern`,hint:`e.g. *.md, **/*.md`,children:(0,Z.jsx)(G,{"aria-label":`File pattern`,"data-testid":`kb-source-pattern-input`,value:c,onChange:e=>l(e.target.value),className:`font-mono text-sm`})})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsx)(p,{type:`submit`,size:`sm`,variant:`outline`,"data-testid":`kb-source-add`,disabled:!o.trim()||r.pending,children:`Add folder`}),(0,Z.jsx)(p,{type:`button`,size:`sm`,variant:`ghost`,"data-testid":`kb-source-cancel`,onClick:w,children:`Cancel`})]})]}):y.length>0&&(0,Z.jsxs)(p,{size:`sm`,variant:`ghost`,className:`-ml-2`,"data-testid":`kb-folders-add-another`,onClick:()=>g(!0),children:[(0,Z.jsx)(ee,{size:14}),`Add another folder`]}),(0,Z.jsx)(En,{error:r.error})]}),(0,Z.jsx)(Ye,{open:f!==null,title:`Stop syncing folder`,description:f?sr(f):``,confirmLabel:`Stop syncing`,variant:`warning`,isPending:r.pending,onCancel:()=>m(null),onConfirm:async()=>{let e=f;m(null),e&&await r.run(()=>C.kb.removeSource(e.id)),await n()}})]})}var ur=8;function dr(e,t,n){return n===`title`?e.title.localeCompare(t.title):n===`updated`?e.updated_at-t.updated_at:e.reads-t.reads}function fr(e,t){if(e.key===t)return e.desc?`descending`:`ascending`}function pr(e){let t=new Date(e);return t.toDateString()===new Date().toDateString()?t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):t.toLocaleDateString([],{month:`short`,day:`numeric`,year:`numeric`})}function mr({kb:e,owner:t,listing:n,label:r,onLabel:i,onOpen:a,onNewDocument:o,onSettings:s}){let c=e.editable_by.includes(`mcp`);return(0,Z.jsxs)(`div`,{"data-testid":`kb-overview`,className:`w-full min-w-0 space-y-6 p-4 sm:p-6`,children:[(0,Z.jsxs)(`header`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 space-y-1`,children:[(0,Z.jsx)(`h2`,{className:`wrap-break-word text-base font-medium`,"data-testid":`kb-overview-name`,children:e.name}),e.description&&(0,Z.jsx)(`p`,{className:`max-w-prose text-outline`,children:e.description}),(0,Z.jsxs)(`p`,{className:`text-xs text-outline`,"data-testid":`kb-overview-meta`,children:[t,` · `,e.document_count,` `,e.document_count===1?`document`:`documents`,` ·`,` `,c?`agents can edit`:`agents read only`]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsxs)(p,{size:`sm`,"data-testid":`kb-new-document`,onClick:o,children:[(0,Z.jsx)(ae,{size:16}),`New document`]}),(0,Z.jsxs)(p,{size:`sm`,variant:`ghost`,"data-testid":`kb-settings`,onClick:s,children:[(0,Z.jsx)(V,{size:16}),`Settings`]})]})]}),(0,Z.jsx)(vr,{kbId:e.id,onOpen:a}),(0,Z.jsx)(_r,{listing:n,total:e.document_count,label:r,onLabel:i,onOpen:a,onNewDocument:o}),(0,Z.jsxs)(`section`,{"aria-labelledby":`kb-setup-heading`,className:`space-y-1`,children:[(0,Z.jsx)(`h3`,{id:`kb-setup-heading`,className:`text-sm font-medium text-outline`,children:`Setup`}),(0,Z.jsxs)(`div`,{className:`divide-y divide-outline-variant border-y border-outline-variant`,children:[(0,Z.jsx)(_n,{kb:e}),(0,Z.jsx)(lr,{kb:e}),(0,Z.jsx)(hr,{kb:e,onSettings:s}),(0,Z.jsx)(gr,{kb:e,onSettings:s}),(0,Z.jsx)(Jn,{kbId:e.id,onOpenDocument:a})]})]})]})}function hr({kb:e,onSettings:t}){let n=e.editable_by.includes(`mcp`);return(0,Z.jsx)(nn,{title:`Who can edit`,testId:`kb-access`,summary:(0,Z.jsxs)(`span`,{className:`inline-flex min-w-0 flex-wrap items-center gap-x-1.5`,children:[(0,Z.jsx)(rn,{tone:n?`ok`:`off`}),n?`Agents can edit`:`Agents read only`,(0,Z.jsxs)(`span`,{className:`text-outline`,children:[`·`,` `,e.editable_by.length?e.editable_by.map(e=>kn[e]).join(`, `):`nobody, read only everywhere`]})]}),actions:(0,Z.jsx)(p,{size:`sm`,variant:`ghost`,"data-testid":`kb-access-change`,onClick:t,children:`Change`})})}function gr({kb:e,onSettings:t}){let n=xt(),r=e.parser?n.data?.parsers.find(t=>t.id===e.parser)?.label??e.parser:`Workspace default parser`;return(0,Z.jsx)(nn,{title:`Uploads`,testId:`kb-uploads-setup`,summary:(0,Z.jsxs)(`span`,{className:`text-outline`,"data-testid":`kb-uploads-parser`,children:[r,(0,Z.jsx)(Ve,{label:`Document uploads`,children:`PDF, Word, PowerPoint, Excel, HTML, Markdown and text are converted to searchable Markdown by the selected parser.`})]}),actions:(0,Z.jsx)(p,{size:`sm`,variant:`ghost`,"data-testid":`kb-parser-change`,onClick:t,children:`Change`})})}function _r({listing:e,total:t,label:n,onLabel:r,onOpen:i,onNewDocument:a}){let[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)({key:`updated`,desc:!0}),m=o.trim().toLowerCase(),h=(e?.documents??[]).filter(e=>(!n||e.labels.includes(n))&&(!m||e.title.toLowerCase().includes(m)||e.path.toLowerCase().includes(m)||e.labels.some(e=>e.toLowerCase().includes(m)))).sort((e,t)=>dr(e,t,u.key)*(u.desc?-1:1));function g(e){d(t=>t.key===e?{key:e,desc:!t.desc}:{key:e,desc:e!==`title`})}function _(e,t){let n=u.desc?ye:Ae;return(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`kb-sort-${e}`,className:`inline-flex min-h-8 items-center gap-1 hover:text-on-surface`,onClick:()=>g(e),children:[t,u.key===e&&(0,Z.jsx)(n,{size:12,"aria-hidden":!0})]})}let v=[...e?.labels??[]].sort((e,t)=>t.count-e.count),y=c?v:v.filter((e,t)=>t<ur||e.label===n),b=v.length-y.length;return(0,Z.jsxs)(`section`,{"aria-labelledby":`kb-documents-heading`,"data-testid":`kb-documents`,className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Z.jsxs)(`h3`,{id:`kb-documents-heading`,className:`mr-auto text-sm font-medium text-outline`,children:[`Documents`,n?` labelled ${n}`:``]}),t>0&&(0,Z.jsx)(G,{"aria-label":`Filter documents`,"data-testid":`kb-documents-filter`,placeholder:`Filter by title, path or label`,value:o,onChange:e=>s(e.target.value),className:`h-9 w-full sm:w-64`})]}),y.length>0&&(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,"data-testid":`kb-labels`,children:[(0,Z.jsx)(`span`,{className:`mr-1 text-xs text-outline`,children:`Label`}),y.map(e=>(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`kb-label-filter`,"aria-pressed":n===e.label,className:f(`min-h-8 rounded-full border px-2.5 text-xs`,n===e.label?`border-primary bg-primary/10 text-primary`:`border-outline-variant text-outline hover:text-on-surface`),onClick:()=>r(n===e.label?null:e.label),children:[e.label,` `,(0,Z.jsx)(`span`,{className:`tabular-nums`,children:e.count})]},e.label)),(b>0||c)&&v.length>ur&&(0,Z.jsx)(`button`,{type:`button`,"data-testid":`kb-labels-more`,className:`min-h-8 px-2 text-xs text-primary hover:underline`,onClick:()=>l(!c),children:c?`Fewer labels`:`${b} more`})]}),t===0?(0,Z.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-2 rounded-md border border-dashed border-outline-variant px-6 py-10 text-center text-sm text-outline`,children:[(0,Z.jsx)(D,{size:22,className:`text-primary`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{children:`This knowledge base is empty. Drop PDF, Word, PowerPoint, Excel, HTML, Markdown or text files here, or`}),(0,Z.jsx)(p,{size:`sm`,variant:`outline`,onClick:a,"data-testid":`kb-overview-new-document`,children:`add a document`})]}):(0,Z.jsxs)(Z.Fragment,{children:[h.length===0&&e&&(0,Z.jsxs)(`p`,{className:`py-4 text-sm text-outline`,"data-testid":`kb-documents-empty`,children:[`No documents match.`,` `,(0,Z.jsx)(`button`,{type:`button`,"data-testid":`kb-documents-clear`,className:`text-primary hover:underline`,onClick:()=>{s(``),r(null)},children:`Clear filters`})]}),h.length>0&&(0,Z.jsxs)(`table`,{className:`w-full table-fixed text-sm`,children:[(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{className:`border-b border-outline-variant text-left text-xs text-outline`,children:[(0,Z.jsx)(`th`,{className:`py-1 pr-3 font-normal`,"aria-sort":fr(u,`title`),children:_(`title`,`Title`)}),(0,Z.jsx)(`th`,{className:`hidden w-[30%] py-2 pr-3 font-normal md:table-cell`,children:`Labels`}),(0,Z.jsx)(`th`,{className:`w-24 py-1 pr-3 font-normal sm:w-28`,"aria-sort":fr(u,`updated`),children:_(`updated`,`Updated`)}),(0,Z.jsx)(`th`,{className:`hidden w-16 py-1 text-right font-normal sm:table-cell`,"aria-sort":fr(u,`reads`),children:_(`reads`,`Reads`)})]})}),(0,Z.jsx)(`tbody`,{children:h.map(e=>(0,Z.jsxs)(`tr`,{className:`cursor-pointer border-b border-outline-variant/60 align-top hover:bg-surface-high`,onClick:()=>i(e.id),children:[(0,Z.jsxs)(`td`,{className:`min-w-0 py-2 pr-3`,children:[(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`kb-document-row`,"data-document-title":e.title,className:`flex w-full min-w-0 items-center gap-1.5 text-left font-medium hover:text-primary`,onClick:t=>{t.stopPropagation(),i(e.id)},children:[(0,Z.jsx)(`span`,{className:`min-w-0 truncate`,children:e.title}),e.origin===`external`&&(0,Z.jsx)(Vt,{size:13,className:`shrink-0 text-outline`,"aria-label":`From a synced folder`})]}),(0,Z.jsx)(`span`,{className:`block truncate font-mono text-xs text-outline`,children:e.path}),(e.parse_state===`pending`||e.parse_state===`failed`)&&(0,Z.jsx)(`span`,{className:f(`text-xs`,e.parse_state===`failed`?`text-error`:`text-outline`),children:e.parse_state===`failed`?`Parsing failed`:`Parsing…`})]}),(0,Z.jsx)(`td`,{className:`hidden py-2 pr-3 text-xs text-outline md:table-cell`,children:(0,Z.jsx)(`span`,{className:`line-clamp-2`,children:e.labels.join(`, `)})}),(0,Z.jsx)(`td`,{className:`py-2 pr-3 text-xs text-outline tabular-nums`,children:pr(e.updated_at)}),(0,Z.jsx)(`td`,{className:`hidden py-2 text-right text-xs text-outline tabular-nums sm:table-cell`,children:e.reads||``})]},e.id))})]}),(0,Z.jsx)(`p`,{className:`text-xs text-outline`,children:`Drop files anywhere on this page to upload.`})]})]})}function vr({kbId:e,onOpen:t}){let n=bt(e).data;return!n||!(n.stale.length||n.failed.length||n.unresolved_links.length)?null:(0,Z.jsxs)(`section`,{"data-testid":`kb-maintenance`,className:`space-y-1 text-sm`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-outline`,children:`Needs attention`}),(0,Z.jsxs)(`ul`,{className:`space-y-1`,children:[n.failed.map(e=>(0,Z.jsx)(`li`,{children:(0,Z.jsxs)(`button`,{type:`button`,className:`text-left text-error hover:underline`,onClick:()=>t(e.id),children:[`Parsing failed: `,e.title]})},e.id)),n.stale.map(e=>(0,Z.jsx)(`li`,{children:(0,Z.jsxs)(`button`,{type:`button`,className:`text-left text-warning hover:underline`,onClick:()=>t(e.id),children:[`Stale summary: `,e.title]})},e.id)),n.unresolved_links.map(e=>(0,Z.jsx)(`li`,{children:(0,Z.jsxs)(`button`,{type:`button`,className:`text-left text-outline hover:underline`,onClick:()=>t(e.document_id),children:[`[[`,e.target,`]] in `,e.title,` has no target`]})},`${e.document_id}-${e.target}`))]})]})}function yr(){let e=J(),[t,n]=(0,Y.useState)([]),r=(0,Y.useRef)(1),i=(e,t)=>n(n=>n.map(n=>n.id===e?{...n,...t}:n));async function a(t){i(t.id,{status:`uploading`,progress:0,error:void 0});try{let n=await C.kb.upload(t.kbId,{file:t.file,...t.replace},e=>i(t.id,{progress:e}));i(t.id,{status:`done`,progress:1,document:n}),await e()}catch(e){i(t.id,{status:`failed`,error:e instanceof Error?e.message:`Upload failed`})}}function o(e,t,i={}){let o=t.map(t=>({id:r.current++,kbId:e,file:t,...i.replace?{replace:i.replace}:{},progress:0,status:`uploading`}));n(e=>[...e,...o]);for(let e of o)a(e)}return{uploads:t,add:o,retry:e=>{let n=t.find(t=>t.id===e);n&&a(n)},clearFinished:()=>n(e=>e.filter(e=>e.status===`uploading`))}}var br={new:``,installed:`Already in ORC`,duplicate:`Near copy already in ORC`,conflict:`Name taken in ORC (different content), select to replace`,invalid:`Invalid`},xr={new:``,identical:`Already in the folder`,near:`Near copy in the folder, select to overwrite`,conflict:`Different memory with this name in the folder, select to overwrite`,duplicate:`Already in the folder under another name`},Sr=`__folder__`;function Cr({mode:e,initialProjectId:t,projects:n,onClose:o}){let[s,c]=(0,Y.useState)(t??``),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(``),[m,h]=(0,Y.useState)(``),[g,_]=(0,Y.useState)({}),v=r(),y=i({queryKey:[`memory-transfer`,`sources`,s],queryFn:()=>C.memories.nativeSources(s),enabled:!!s}),b=y.data?.sources??[],x=l??b.find(e=>e.project_match)?.dir??``,S=x===Sr?m:x,w=i({queryKey:[`memory-transfer`,e,s,S],queryFn:async()=>{if(e===`import`){let e=await C.memories.previewImport(s,S);return{dir:e.dir,rows:e.memories.map(e=>({...e,selectable:e.status===`new`||e.can_replace}))}}let t=await C.memories.previewExport(s,S);return{dir:t.dir,index:t.index,rows:t.memories.map(e=>({...e,selectable:e.status===`new`||e.can_overwrite,...e.status===`duplicate`?{error:e.reason}:{}}))}},enabled:!!(s&&S)}),T=a({mutationFn:async t=>{if(e===`import`){let e=await C.memories.importNative(s,S,t.map(e=>({name:e.name,...e.status===`new`?{}:{replace:!0}})));return{done:[...e.imported.map(e=>`Imported ${e}`),...e.replaced.map(e=>`Replaced ${e}`)],skipped:e.skipped}}let n=await C.memories.exportNative(s,S,t.map(e=>e.name),t.filter(e=>e.status!==`new`).map(e=>e.name));return{done:n.exported.map(e=>`${e.replaced?`Replaced`:`Wrote`} ${e.file}`),skipped:n.skipped}},onSuccess:async t=>{_({}),await v.invalidateQueries({queryKey:[`memory-transfer`]}),e===`import`&&await v.invalidateQueries({queryKey:[`memories`]}),t.skipped.length||o()}}),E=T.isPending,D=s&&S?w.data?.rows??[]:[],O=D.filter(e=>e.selectable&&g[e.name]),k=D.filter(e=>e.status===`new`),A=e===`import`?br:xr,j=e===`import`?`Import`:`Export`,M=`memory-${e}`,N=y.error||w.error||T.error;return(0,Z.jsx)(we,{open:!0,onOpenChange:e=>!e&&!E&&o(),children:(0,Z.jsxs)(Ce,{closeDisabled:E,"data-testid":`${M}-dialog`,className:`flex min-w-0 w-[min(800px,calc(100vw-2rem))] max-w-none max-h-[calc(var(--app-height,100dvh)-2rem)] flex-col gap-0 overflow-hidden p-0`,children:[(0,Z.jsxs)(Ke,{className:`shrink-0 flex-row items-center gap-1 border-b px-4 py-3 pr-12 sm:px-6`,children:[(0,Z.jsx)(ve,{children:e===`import`?`Import native memories`:`Export memories`}),(0,Z.jsx)(Ve,{label:`memory ${e}`,children:e===`import`?`Reads Claude Code memory files (~/.claude/projects/<project>/memory/*.md), Codex notes (~/.codex/memories/extensions/ad_hoc/notes) or any folder of memory files into this project. Near copies are flagged so a small edit does not create a duplicate.`:`Writes this project's memories as memory files: Claude Code folders also get a MEMORY.md index, and Codex merges its notes into its memory. Existing files are only replaced when you select them, and a backup is kept.`})]}),(0,Z.jsxs)(`div`,{className:`min-h-0 min-w-0 flex-1 space-y-4 overflow-y-auto overscroll-contain px-4 py-4 sm:px-6`,"data-testid":`${M}-body`,children:[(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`label`,{htmlFor:`${M}-project`,className:`text-sm font-medium`,children:e===`import`?`Into project`:`From project`}),(0,Z.jsxs)(`select`,{id:`${M}-project`,"data-testid":`${M}-project`,className:`block h-11 w-full rounded-md border border-input bg-background px-3 text-sm sm:h-8`,value:s,disabled:E,onChange:e=>{c(e.target.value),u(null),_({}),T.reset()},children:[(0,Z.jsx)(`option`,{value:``,children:`Choose a project`}),n.map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`label`,{htmlFor:`${M}-source`,className:`text-sm font-medium`,children:e===`import`?`Source`:`Destination`}),(0,Z.jsxs)(`select`,{id:`${M}-source`,"data-testid":`${M}-source`,className:`block h-11 w-full rounded-md border border-input bg-background px-3 text-sm sm:h-8`,value:x,disabled:E||!s||y.isLoading,onChange:e=>{u(e.target.value),_({}),T.reset()},children:[(0,Z.jsx)(`option`,{value:``,children:`Choose a folder`}),b.map(e=>(0,Z.jsxs)(`option`,{value:e.dir,children:[e.label,` · `,e.count,` `,e.count===1?`memory`:`memories`,e.project_match?` · this project`:``]},e.dir)),(0,Z.jsx)(`option`,{value:Sr,children:`Custom folder`})]}),x===Sr&&(0,Z.jsxs)(`form`,{className:`flex flex-col gap-2 sm:flex-row sm:items-end`,onSubmit:e=>{e.preventDefault(),_({}),h(d.trim())},children:[(0,Z.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Z.jsx)(Pt,{id:`${M}-folder`,label:`Folder`,value:d,disabled:E,onChange:f})}),(0,Z.jsx)(p,{type:`submit`,variant:`outline`,"data-testid":`${M}-folder-apply`,disabled:E||!d.trim(),children:e===`import`?`Scan`:`Compare`})]})]}),w.isLoading&&s&&S&&(0,Z.jsx)(`p`,{role:`status`,children:`Reading the folder…`}),w.data&&s&&S&&(0,Z.jsxs)(`section`,{"data-testid":`${M}-plan`,className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,Z.jsxs)(`p`,{className:`min-w-0 flex-1 text-xs text-outline wrap-break-word`,children:[w.data.dir,w.data.index?` · MEMORY.md index is updated`:``]}),(0,Z.jsxs)(p,{size:`sm`,variant:`outline`,"data-testid":`${M}-select-new`,disabled:E||!k.length,onClick:()=>_({...g,...Object.fromEntries(k.map(e=>[e.name,!0]))}),children:[`Select all new (`,k.length,`)`]})]}),!D.length&&(0,Z.jsx)(`p`,{role:`status`,children:e===`import`?`No memory files in this folder.`:`This project has no memories.`}),(0,Z.jsx)(`div`,{className:`divide-y divide-border`,children:D.map(e=>(0,Z.jsxs)(`label`,{className:`flex min-h-11 min-w-0 items-start gap-3 py-2 text-sm`,"data-testid":`${M}-item`,"data-memory-name":e.name,"data-status":e.status,children:[(0,Z.jsx)(`input`,{type:`checkbox`,"aria-label":`${j} ${e.name}`,className:`mt-1 shrink-0`,"data-testid":`${M}-select`,checked:e.selectable&&!!g[e.name],disabled:E||!e.selectable,onChange:t=>_({...g,[e.name]:t.target.checked})}),(0,Z.jsxs)(`span`,{className:`min-w-0 wrap-break-word`,children:[(0,Z.jsx)(`span`,{className:`font-medium`,children:e.name}),A[e.status]&&(0,Z.jsx)(`span`,{className:`ml-2 text-xs text-outline`,children:A[e.status]}),(0,Z.jsx)(`span`,{className:`mt-0.5 line-clamp-2 text-xs leading-4 text-outline`,children:e.description}),(0,Z.jsx)(Ft,{match:e.match}),e.error&&(0,Z.jsx)(`span`,{className:`block text-xs text-destructive`,children:e.error})]})]},e.name))})]}),T.data?.skipped.map(e=>(0,Z.jsxs)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:[`Skipped `,e.name,`: `,e.reason]},e.name)),N&&(0,Z.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:N.message})]}),(0,Z.jsxs)(q,{className:`shrink-0 border-t px-4 py-3 sm:px-6`,children:[(0,Z.jsx)(p,{variant:`ghost`,disabled:E,onClick:o,children:`Close`}),(0,Z.jsx)(p,{"data-testid":`${M}-submit`,disabled:E||!O.length,onClick:()=>T.mutate(O),children:E?`${j===`Import`?`Importing`:`Exporting`}…`:`${j} selected${O.length?` (${O.length})`:``}`})]})]})})}var wr=`all`,Tr=200,Er=[{value:`reads`,label:`Most read`},{value:`recent`,label:`Recent`},{value:`priority`,label:`Priority`}];function Dr(e){return new Date(e*1e3).toLocaleString()}function Or({projectId:e}){let t=o(),n=u(),{memoryProject:r,memoryName:i}=c(),[a,s]=Qe(`project`,e),[l,d]=Qe(`memoryQuery`,``),[f,m]=Qe(`memorySort`,`reads`,Er.map(e=>e.value)),[h,g]=(0,Y.useState)(l);(0,Y.useEffect)(()=>g(l),[l]);let _=(0,Y.useRef)(d);_.current=d,(0,Y.useEffect)(()=>{if(h===l)return;let e=window.setTimeout(()=>_.current(h,{replace:!0}),250);return()=>window.clearTimeout(e)},[h,l]);let v=Ne(`lg`),[y,b]=(0,Y.useState)(null),[x,S]=(0,Y.useState)(null),{data:C}=Oe({status:`active`}),O=ut(),[k,A]=(0,Y.useState)(!1),[j,M]=(0,Y.useState)(null),N=a===`unassigned`,P=a===wr,F=ft({project_id:P?void 0:a,q:l||void 0,sort:f,limit:Tr},{enabled:!N}),I=F.data?.memories??[],L=e=>C?.find(t=>t.id===e)?.name??e,R=P||N?null:a,B=I.find(e=>e.project_id===r&&e.name===i),V=e=>t(`${We(e.project_id,e.name)}${n.search}`),H=()=>t(`${Be}${n.search}`),ne=P||!N&&r===a;return(0,Y.useEffect)(()=>{r&&i&&!ne&&t(`${Be}${n.search}`,{replace:!0})},[r,i,ne,t,n.search]),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(Ze,{title:`Memories`,help:`Short project facts such as ports, conventions and decisions that agents can read in later sessions. Longer procedures belong in a skill.`,meta:F.data?`${F.data.total} ${F.data.total===1?`memory`:`memories`}`:void 0,action:(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsxs)(je,{open:k,onOpenChange:A,children:[(0,Z.jsx)(xe,{asChild:!0,children:(0,Z.jsxs)(p,{"data-testid":`memory-transfer-menu`,"aria-label":`Import or export memories`,size:`sm`,variant:`ghost`,children:[(0,Z.jsx)(T,{size:14}),(0,Z.jsx)(`span`,{className:`hidden sm:inline`,children:`Import / export`}),(0,Z.jsx)(w,{size:12,className:`hidden sm:block`})]})}),(0,Z.jsxs)(be,{"aria-label":`Import or export memories`,align:`end`,className:`w-64 space-y-1 p-1`,children:[(0,Z.jsxs)(p,{"data-testid":`memory-import-button`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,onClick:()=>{A(!1),M(`import`)},children:[(0,Z.jsx)(T,{size:12,className:`mr-1`}),` Import native memories`]}),(0,Z.jsxs)(p,{"data-testid":`memory-export-button`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,onClick:()=>{A(!1),M(`export`)},children:[(0,Z.jsx)(D,{size:12,className:`mr-1`}),` Export to native memory`]})]})]}),(0,Z.jsxs)(p,{"data-testid":`new-memory-button`,size:`sm`,onClick:()=>b(`new`),className:`font-label text-sm`,children:[(0,Z.jsx)(ee,{size:12,className:`mr-1`}),` New memory`]})]})}),(0,Z.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-2`,children:[(0,Z.jsxs)(E,{activeCount:Number(f!==`reads`)+Number(a!==wr),children:[(0,Z.jsxs)(W,{value:a,onValueChange:e=>s(e),children:[(0,Z.jsx)(Re,{"aria-label":`Project`,"data-testid":`memory-project-filter`,className:`h-9 w-48 bg-background text-on-surface font-body text-sm`,children:(0,Z.jsx)(Me,{})}),(0,Z.jsxs)(z,{className:`bg-surface border-outline-variant`,children:[(0,Z.jsx)(K,{value:wr,className:`font-body text-sm`,children:`All projects`}),N&&(0,Z.jsx)(K,{value:`unassigned`,className:`font-body text-sm`,children:`Unassigned`}),C?.map(e=>(0,Z.jsx)(K,{value:e.id,"data-testid":`memory-project-option-${e.id}`,className:`font-body text-sm`,children:e.name},e.id))]})]}),(0,Z.jsx)(`div`,{className:`flex shrink-0 flex-wrap gap-1.5`,children:Er.map(e=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>m(e.value),"data-testid":`memory-sort-${e.value}`,"aria-pressed":f===e.value,className:`font-label text-sm px-3 py-1.5 border transition-colors ${f===e.value?`bg-surface-highest text-on-surface border-transparent`:`bg-transparent border-transparent text-muted-foreground hover:bg-surface-low hover:text-on-surface`}`,children:e.label},e.value))})]}),(0,Z.jsxs)(`div`,{className:`relative order-first min-w-0 flex-1 lg:max-w-md`,children:[(0,Z.jsx)(te,{size:12,className:`absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground`}),(0,Z.jsx)(G,{"aria-label":`Search memories`,"data-testid":`memory-search-input`,value:h,onChange:e=>g(e.target.value),onKeyDown:e=>e.key===`Enter`&&d(e.currentTarget.value),placeholder:`Search memories...`,className:`pl-8 bg-background text-on-surface font-body text-sm placeholder:text-muted-foreground`})]})]}),N?(0,Z.jsx)($e,{message:`Memories belong to a project. Choose a project to see its memories.`}):F.error?(0,Z.jsx)(de,{message:F.error.message,onRetry:()=>void F.refetch()}):F.isLoading?(0,Z.jsx)(`div`,{className:`space-y-2`,children:[...[,,,,,]].map((e,t)=>(0,Z.jsx)(le,{className:`h-10 w-full bg-surface-highest`},t))}):I.length===0?(0,Z.jsx)($e,{message:l?`No memories match your search`:`No memories yet`}):v?(0,Z.jsx)(`div`,{className:`overflow-hidden`,children:(0,Z.jsxs)(at,{children:[(0,Z.jsx)(et,{children:(0,Z.jsxs)(rt,{className:`border-b border-outline-variant hover:bg-transparent`,children:[(0,Z.jsx)(tt,{className:`font-label text-sm text-muted-foreground`,children:`Name`}),(0,Z.jsx)(tt,{className:`font-label text-sm text-muted-foreground`,children:`Description`}),P&&(0,Z.jsx)(tt,{className:`font-label text-sm text-muted-foreground`,children:`Project`}),(0,Z.jsx)(tt,{className:`font-label text-sm text-muted-foreground w-20`,children:`Priority`}),(0,Z.jsx)(tt,{className:`font-label text-sm text-muted-foreground w-16`,children:`Reads`}),(0,Z.jsx)(tt,{className:`font-label text-sm text-muted-foreground w-44`,children:`Updated`})]})}),(0,Z.jsx)(nt,{children:I.map(e=>(0,Z.jsxs)(rt,{"data-testid":`memory-row`,"data-memory-name":e.name,"data-memory-project":e.project_id,className:`border-b border-outline-variant/50 hover:bg-surface-low cursor-pointer`,onClick:()=>V(e),children:[(0,Z.jsx)(it,{className:`font-body text-sm font-medium text-on-surface`,children:(0,Z.jsx)(`button`,{type:`button`,className:`min-h-11 text-left hover:text-primary`,onClick:t=>{t.stopPropagation(),V(e)},children:e.name})}),(0,Z.jsx)(it,{className:`font-body text-sm text-muted-foreground max-w-md truncate`,children:e.description}),P&&(0,Z.jsx)(it,{className:`font-body text-sm text-muted-foreground`,children:L(e.project_id)}),(0,Z.jsx)(it,{children:(0,Z.jsx)(Ar,{priority:e.priority})}),(0,Z.jsx)(it,{"data-testid":`memory-read-count`,className:`font-label text-sm text-muted-foreground`,title:kr(e),children:e.read_count}),(0,Z.jsx)(it,{className:`font-label text-sm text-muted-foreground`,children:Dr(e.updated_at)})]},e.key))})]})}):(0,Z.jsx)(`div`,{className:`divide-y divide-outline-variant`,children:I.map(e=>(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`memory-row`,"data-memory-name":e.name,"data-memory-project":e.project_id,onClick:()=>V(e),className:`flex w-full min-w-0 items-start justify-between gap-3 px-2 py-3 text-left hover:bg-surface`,children:[(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block wrap-break-word text-sm font-medium`,children:e.name}),(0,Z.jsx)(`span`,{className:`mt-1 line-clamp-2 wrap-break-word text-sm text-muted-foreground`,children:e.description}),(0,Z.jsxs)(`span`,{className:`mt-1 flex flex-wrap items-center gap-x-2 text-xs text-muted-foreground`,children:[P&&(0,Z.jsx)(`span`,{children:L(e.project_id)}),(0,Z.jsxs)(`span`,{"data-testid":`memory-read-count`,title:kr(e),children:[e.read_count,` reads`]})]})]}),(0,Z.jsx)(Ar,{priority:e.priority})]},e.key))}),r&&i&&ne&&(0,Z.jsx)(jr,{projectId:r,name:i,projectName:L(r),listItem:B,onClose:H,onEdit:b,onDelete:S},`${r}/${i}`),y&&(0,Z.jsx)(Ir,{memory:y===`new`?null:y,defaultProjectId:P||N?``:a,onClose:()=>b(null),onCreated:e=>V(e)}),j&&(0,Z.jsx)(Cr,{mode:j,initialProjectId:R,projects:C??[],onClose:()=>M(null)}),x&&(0,Z.jsx)(Ye,{open:!0,title:`Delete memory`,description:`Delete "${x.name}"? It can be restored from its history.`,confirmLabel:`Delete`,variant:`destructive`,isPending:O.isPending,onConfirm:()=>O.mutate({projectId:x.project_id,name:x.name},{onSuccess:()=>{S(null),H()}}),onCancel:()=>S(null)}),O.error&&(0,Z.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive mt-2`,children:O.error.message})]})}function kr(e){let{mcp:t,cli:n,api:r,ui:i}=e.reads_by_source;return`mcp ${t} · cli ${n} · api ${r} · ui ${i}${e.last_read_at?` · last read ${Dr(e.last_read_at)}`:``}`}function Ar({priority:e}){return e===null?(0,Z.jsx)(`span`,{"data-testid":`memory-priority`,className:`font-label text-xs text-outline`,children:`Unscored`}):(0,Z.jsxs)(`span`,{"data-testid":`memory-priority`,className:`font-label text-xs text-primary`,children:[`P`,e]})}function jr({projectId:e,name:t,projectName:n,listItem:r,onClose:i,onEdit:a,onDelete:o}){let{data:s,isLoading:c,error:l,refetch:u}=lt(e,t);return(0,Z.jsx)(H,{open:!0,onOpenChange:e=>!e&&i(),children:(0,Z.jsxs)(ue,{"data-testid":`memory-detail`,defaultWidth:860,resizeKey:`memories`,children:[(0,Z.jsxs)(se,{children:[(0,Z.jsx)(De,{children:t}),s&&(0,Z.jsx)(`p`,{"data-testid":`memory-detail-description`,className:`font-body text-sm text-muted-foreground mt-1`,children:s.description})]}),(0,Z.jsx)(He,{children:l?(0,Z.jsx)(de,{message:l.message,onRetry:()=>void u()}):c||!s?(0,Z.jsx)(`div`,{className:`space-y-3`,children:[...[,,,,]].map((e,t)=>(0,Z.jsx)(le,{className:`h-8 w-full bg-surface-highest`},t))}):(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsxs)(p,{"data-testid":`memory-edit`,size:`sm`,variant:`outline`,onClick:()=>a(s),children:[(0,Z.jsx)(U,{size:12,className:`mr-1`}),` Edit`]}),(0,Z.jsxs)(p,{"data-testid":`memory-delete`,size:`sm`,variant:`outline`,onClick:()=>o(s),children:[(0,Z.jsx)(_e,{size:12,className:`mr-1`}),` Delete`]})]}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,Z.jsx)(qe,{label:`Project`,children:n}),(0,Z.jsx)(qe,{label:`Priority`,children:(0,Z.jsx)(Ar,{priority:s.priority})}),(0,Z.jsx)(qe,{label:`Reads`,children:r?(0,Z.jsx)(`span`,{title:kr(r),children:r.read_count}):`-`}),(0,Z.jsx)(qe,{label:`Author`,children:(0,Z.jsx)(`span`,{"data-testid":`memory-detail-author`,children:s.author})}),(0,Z.jsx)(qe,{label:`Session`,children:(0,Z.jsx)(`code`,{className:`font-mono text-xs break-all`,children:s.session_id??`-`})}),(0,Z.jsx)(qe,{label:`Updated`,children:Dr(s.updated_at)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`font-label text-sm text-muted-foreground mb-2`,children:`Content`}),(0,Z.jsx)(`div`,{"data-testid":`memory-detail-content`,className:`wrap-break-word font-body text-sm text-on-surface`,children:(0,Z.jsx)(Ie,{readable:!0,children:s.content})})]}),(0,Z.jsx)(Nr,{projectId:e,name:t,onDeleted:i})]})})]})})}function Mr({label:e,snapshot:t}){return(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`text-xs text-outline mt-2`,children:e}),t?(0,Z.jsxs)(`div`,{className:`text-xs space-y-1`,children:[(0,Z.jsxs)(`p`,{children:[(0,Z.jsx)(`span`,{className:`text-outline`,children:`Priority:`}),` `,t.priority===null?`unscored`:t.priority]}),(0,Z.jsxs)(`p`,{children:[(0,Z.jsx)(`span`,{className:`text-outline`,children:`Description:`}),` `,t.description]}),(0,Z.jsx)(`pre`,{className:`whitespace-pre-wrap break-all`,children:t.content})]}):(0,Z.jsx)(`p`,{className:`text-xs italic text-muted-foreground`,children:`(none)`})]})}function Nr({projectId:e,name:t,onDeleted:n}){let r=st(e,t),i=pt(),[a,o]=(0,Y.useState)(``),s=r.data?.changes??[],c=s[0];return(0,Z.jsxs)(`section`,{"data-testid":`memory-history-panel`,className:`space-y-3`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium`,children:`History`}),r.error&&(0,Z.jsx)(`p`,{role:`alert`,children:r.error.message}),i.error&&(0,Z.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:i.error.message}),s.length>1&&(0,Z.jsx)(G,{"data-testid":`memory-revert-reason`,"aria-label":`Reason for reverting`,value:a,onChange:e=>o(e.target.value),placeholder:`Reason for reverting...`}),s.map(r=>(0,Z.jsxs)(`details`,{"data-testid":`memory-history-change`,className:`border-b border-outline-variant p-3`,children:[(0,Z.jsxs)(`summary`,{className:`text-xs cursor-pointer`,children:[r.action.replace(`memory.`,``),` · `,Dr(r.created_at),` ·`,` `,r.author,r.session_id?` · ${r.session_id}`:``,r.reason?` · ${r.reason}`:``]}),(0,Z.jsx)(Mr,{label:`Before`,snapshot:r.previous}),(0,Z.jsx)(Mr,{label:`After`,snapshot:r.current}),c&&r.previous&&(0,Z.jsx)(p,{"data-testid":`memory-revert-change`,size:`sm`,variant:`outline`,className:`mt-2`,disabled:!a.trim()||i.isPending,onClick:()=>i.mutate({name:t,project_id:e,change_id:r.id,expected_change_id:c.id,reason:a.trim()},{onSuccess:({memory:e})=>{o(``),e||n()}}),children:`Restore state before this change`})]},r.id))]})}function Pr(e){return[...e].length}function Fr({value:e,max:t,testId:n}){let r=Pr(e);return(0,Z.jsx)(`span`,{"data-testid":n,className:`text-xs ${t!==void 0&&r>t?`text-destructive`:`text-muted-foreground`}`,children:t===void 0?r:`${r}/${t}`})}function Ir({memory:e,defaultProjectId:t,onClose:n,onCreated:r}){let{data:i}=Oe({status:`active`}),[a,o]=(0,Y.useState)(e?.project_id??t),[s,c]=(0,Y.useState)(e?.name??``),[l,u]=(0,Y.useState)(e?.description??``),[d,f]=(0,Y.useState)(e?.content??``),[m,h]=(0,Y.useState)(e?.priority===null||e?.priority===void 0?``:String(e.priority)),[g,_]=(0,Y.useState)(``),v=mt(),y=ct(),b=(0,Y.useRef)(JSON.stringify([a,s,l,d,m,g])),x=dt().data?.content_max,S=e?y:v,C=he([{id:`details`,label:`Details`},{id:`content`,label:`Content`}]),w=m.trim()===``?null:Number(m),T=w===null||Number.isInteger(w)&&w>=0&&w<=100,E=!!a&&!!s.trim()&&!!l.trim()&&Pr(l)<=300&&!!d.trim()&&(x===void 0||Pr(d)<=x)&&T;function D(t){if(S.isPending)return;if(!E){!a||!s.trim()||!l.trim()||Pr(l)>300||!T?C.invalid(`details`,a?T?`Enter a name and description within the displayed limits.`:`Priority must be a whole number from 0 to 100.`:`Choose a project.`):C.invalid(`content`,`Enter memory content within the displayed limit.`);return}if(!e){v.mutate({project_id:a,name:s.trim(),description:l.trim(),content:d.trim(),priority:w},{onSuccess:e=>{t(),r(e)}});return}let n={...l.trim()!==e.description&&{description:l.trim()},...d.trim()!==e.content&&{content:d.trim()},...w!==e.priority&&{priority:w}};Object.keys(n).length===0?t():y.mutate({name:e.name,project_id:e.project_id,...n,...g.trim()&&{reason:g.trim()}},{onSuccess:t})}return(0,Z.jsx)(ge,{open:!0,onClose:n,busy:S.isPending,dirty:JSON.stringify([a,s,l,d,m,g])!==b.current,testId:`memory-form-dialog`,className:C.step===`content`?`h-[min(85dvh,calc(var(--app-height,100dvh)-2rem))]`:void 0,children:(t,n)=>(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Ke,{children:(0,Z.jsx)(ve,{className:`font-headline text-base text-on-surface`,children:e?`Edit ${e.name}`:`New memory`})}),(0,Z.jsx)(`form`,{noValidate:!0,ref:C.form,onSubmit:e=>C.submit(e,()=>D(n)),className:C.step===`content`?`min-h-0 flex-1`:`min-h-0`,children:(0,Z.jsxs)(pe,{steps:C,children:[(0,Z.jsxs)(`div`,{className:C.step===`content`?`work-form-body flex min-h-0 flex-1 flex-col gap-4`:`work-form-body space-y-4`,children:[(0,Z.jsxs)(me,{steps:C,id:`details`,children:[!e&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(Te,{className:`font-label text-sm text-muted-foreground`,children:`Project *`}),(0,Z.jsxs)(W,{value:a,onValueChange:o,children:[(0,Z.jsx)(Re,{"aria-label":`Memory project`,"data-testid":`memory-project-select`,className:`bg-background text-on-surface font-body text-sm h-9`,children:(0,Z.jsx)(Me,{placeholder:`Choose a project`})}),(0,Z.jsx)(z,{className:`bg-surface border-outline-variant`,children:i?.map(e=>(0,Z.jsx)(K,{value:e.id,className:`font-body text-sm`,children:e.name},e.id))})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(Te,{className:`font-label text-sm text-muted-foreground`,children:`Name *`}),(0,Z.jsx)(G,{"aria-label":`Name`,"data-testid":`memory-name-input`,value:s,onChange:e=>c(e.target.value),placeholder:`api-port`,maxLength:64,required:!0,className:`bg-background text-on-surface font-body text-sm`,autoFocus:!0}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Lowercase words joined by hyphens, unique in the project.`})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(Te,{className:`font-label text-sm text-muted-foreground`,children:`Description *`}),(0,Z.jsx)(Fr,{value:l,max:300,testId:`memory-description-count`})]}),(0,Z.jsx)(Se,{"aria-label":`Description`,"data-testid":`memory-description-input`,value:l,onChange:e=>u(e.target.value),placeholder:`One line agents see in lists and context`,className:`bg-background text-on-surface font-body text-sm resize-none`,rows:2,required:!0})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(Te,{className:`font-label text-sm text-muted-foreground`,children:[`Priority (0-`,100,`, empty = unscored)`]}),(0,Z.jsx)(G,{"aria-label":`Priority`,"data-testid":`memory-priority-input`,type:`number`,min:0,max:100,step:1,value:m,onChange:e=>h(e.target.value),className:`w-32 bg-background text-on-surface font-body text-sm`}),!T&&(0,Z.jsxs)(`p`,{className:`text-xs text-destructive`,children:[`Priority must be a whole number from 0 to `,100,`.`]})]}),e&&(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(Te,{className:`font-label text-sm text-muted-foreground`,children:`Reason`}),(0,Z.jsx)(G,{"aria-label":`Reason`,"data-testid":`memory-reason-input`,value:g,onChange:e=>_(e.target.value),placeholder:`Why this changed (optional)`,className:`bg-background text-on-surface font-body text-sm`})]})]}),(0,Z.jsx)(me,{steps:C,id:`content`,className:`flex min-h-0 flex-1 flex-col`,children:(0,Z.jsx)(Ue,{label:`Content`,"aria-label":`Content`,"data-testid":`memory-content-input`,value:d,onChange:f,placeholder:`The fact itself. Longer guidance belongs in a skill.`,accessory:(0,Z.jsx)(Fr,{value:d,max:x,testId:`memory-content-count`}),fill:!0,disabled:S.isPending,required:!0})}),C.error&&(0,Z.jsx)(`p`,{role:`alert`,"data-testid":`memory-step-error`,className:`text-sm text-destructive`,children:C.error}),S.error&&(0,Z.jsx)(`p`,{role:`alert`,"data-testid":`memory-form-error`,className:`text-sm text-destructive md:col-span-2`,children:S.error.message})]}),(0,Z.jsxs)(q,{className:`work-form-footer`,children:[(0,Z.jsx)(p,{type:`button`,variant:`ghost`,size:`sm`,onClick:t,disabled:S.isPending,className:`font-label text-sm text-muted-foreground`,children:`Cancel`}),(0,Z.jsx)(ie,{steps:C,busy:S.isPending,children:(0,Z.jsx)(p,{"data-testid":`memory-submit`,type:`submit`,size:`sm`,disabled:S.isPending,className:`font-label text-sm`,children:S.isPending?`Saving...`:e?`Save`:`Create`})})]})]})})]})})}function Lr({projectId:e}){let t=ot(e),{pathname:n}=u();return n.startsWith(`/knowledge/memories`)?(0,Z.jsx)(`div`,{"data-testid":`knowledge-base-view`,children:(0,Z.jsx)(Or,{projectId:e,embedded:!0})}):(0,Z.jsx)(`div`,{"data-testid":`knowledge-base-view`,className:`flex min-h-0 min-w-0 flex-1`,children:(0,Z.jsx)(Br,{projectId:t===`all`||t===`unassigned`?void 0:t,globalOnly:t===`unassigned`},t)})}function Rr(e){return e.replace(/```[\w-]*/g,` `).replace(/<\/?[a-z][^>]*>/gi,` `).replace(/!?\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/(^|\s)#{1,6}\s+/g,`$1`).replace(/(^|\n)\s*(?:>\s*)+/g,`$1`).replace(/(^|\n)\s*(?:[-*+]|\d+[.)])\s+/g,`$1`).replace(/\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?/g,` `).replace(/(^|\s)(?:\*{3,}|_{3,})(?=\s|$)/g,`$1`).replace(/`/g,``).replace(/(^|[\s(«])[*_~]+(?=\S)/g,`$1`).replace(/(\S)[*_~]+(?=$|[\s).,;:!?»])/g,`$1`).replace(/\s*\|[\s|]*/g,` · `).replace(/\s+/g,` `).replace(/^ · | · $/g,``).trim()}function zr({text:e}){let t=Rr(e).split(/«([^»]*)»/g);return(0,Z.jsx)(Z.Fragment,{children:t.map((e,t)=>t%2?(0,Z.jsx)(`mark`,{className:`rounded-xs bg-primary/20 px-0.5 text-on-surface`,children:e},t):(0,Z.jsx)(Y.Fragment,{children:e},t))})}function Br({projectId:e,globalOnly:t=!1}){let[n,r]=s(),{pathname:i}=u(),a=n.get(`kb`),o=n.get(`document`),c=n.get(`label`)??``,l=n.get(`q`)??``,d=n.get(`searchAll`)===`1`,[S,C]=(0,Y.useState)(l);(0,Y.useEffect)(()=>C(l),[l]);let[w,T]=(0,Y.useState)(null),[E,D]=(0,Y.useState)(!1),O=Ne(`lg`),[k,A]=(0,Y.useState)(()=>typeof window<`u`&&window.innerWidth>=1600),[j,M]=(0,Y.useState)(!1),[N,P]=(0,Y.useState)(null),[F,I]=(0,Y.useState)();function L(){T(null),I(void 0)}let R=Oe(),z=Mt(e,t),B=z.data?.find(e=>e.id===a)??null,V=jt(B?.id??null),H=yt(z.data===void 0?null:o),ne=z.data!==void 0&&(B!==null||z.data.length===0),ie=Tt(l&&ne?{query:l,...B&&!d?{kb_ids:[B.id]}:{},scope:e?`default`:t?`global`:`all`,limit:20}:null,e),ae=yr();function U(e,t=!1){window.location.pathname===i&&r(()=>{let t=new URLSearchParams(window.location.search);for(let[n,r]of Object.entries(e))r?t.set(n,r):t.delete(n);return t},{replace:t})}let oe=()=>!o||ht(Zn(o));function se(e){D(!1),(e!==a||o||l)&&oe()&&(e!==a&&ae.clearFinished(),U({kb:e,document:null,label:null,q:null}))}function W(e,t){D(!1),(e===o||oe())&&(U({document:e,q:null}),P(t??null))}function ce(e,t){U({document:e}),P(t??null)}function ue(){D(!1);let e=S.trim();if(!e)return U({q:null});oe()&&U({q:e,document:null})}(0,Y.useEffect)(()=>{O&&D(!1)},[O]),(0,Y.useEffect)(()=>{z.data&&(o&&H.data&&!z.data.some(e=>e.id===H.data.kb_id)?U({kb:z.data[0]?.id??null,document:null,label:null,q:null},!0):a&&!z.data.some(e=>e.id===a)&&(!o||H.error)?U({kb:null,document:null},!0):!a&&z.data[0]&&U({kb:z.data[0].id},!0))}),(0,Y.useEffect)(()=>{H.data&&H.data.kb_id!==a&&z.data?.some(e=>e.id===H.data.kb_id)&&U({kb:H.data.kb_id,label:null},!0)}),(0,Y.useEffect)(()=>{if(!N||!H.data)return;let e=[...document.querySelector(`[data-testid="kb-document"]`)?.querySelectorAll(`h1,h2,h3,h4,h5,h6`)??[]].find(e=>e.textContent?.trim()===N);e&&(e.scrollIntoView({block:`start`}),P(null))});function fe(e){e.preventDefault(),M(!1);let t=[...e.dataTransfer.files];B&&t.length!==0&&(t.length>1?ae.add(B.id,t):(I(t[0]),T(`new-document`)))}let pe=e=>e===null?`Global`:R.data?.find(t=>t.id===e)?.name??`Project`;if(z.error)return(0,Z.jsx)(de,{message:z.error.message,onRetry:()=>z.refetch()});let me=o?H.data&&B&&H.data.kb_id===B.id?(0,Z.jsx)(tr,{kb:B,doc:H.data,detailsOpen:k,onDetailsOpenChange:A,onHome:()=>se(B.id),onOpen:W,onDeleted:()=>U({document:null}),onReplaceFile:e=>H.data&&ae.add(H.data.kb_id,[e],{replace:{document_id:H.data.id,expected_revision:H.data.revision}})},H.data.id):H.error?(0,Z.jsxs)(Wr,{children:[(0,Z.jsx)(`p`,{role:`alert`,"data-testid":`kb-document-error`,className:`text-sm text-error`,children:H.error.message}),(0,Z.jsx)(p,{variant:`outline`,onClick:()=>U({document:null}),children:`Back`})]}):(0,Z.jsx)(Wr,{children:(0,Z.jsx)(`p`,{role:`status`,className:`text-sm text-outline`,children:`Loading document…`})}):l?(0,Z.jsx)(Ur,{children:(0,Z.jsx)(Gr,{query:l,search:ie,onOpen:ce,onClear:()=>U({q:null})})}):B?(0,Z.jsx)(Ur,{children:(0,Z.jsx)(mr,{kb:B,owner:pe(B.project_id),listing:V.data,label:c,onLabel:e=>U({label:e}),onOpen:W,onNewDocument:()=>T(`new-document`),onSettings:()=>T(`settings`)})}):z.data?.length===0?(0,Z.jsxs)(Wr,{testId:`empty-state`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-outline`,children:`No knowledge bases configured`}),(0,Z.jsxs)(p,{"data-testid":`kb-empty-create`,onClick:()=>T(`create`),children:[(0,Z.jsx)(ee,{size:16}),`New knowledge base`]})]}):null,he=(0,Z.jsxs)(`nav`,{id:`kb-sidebar-panel`,"aria-label":`Knowledge bases`,"data-testid":`kb-sidebar`,className:`flex h-full min-h-0 flex-col border-outline-variant bg-background lg:w-72 lg:shrink-0 lg:border-r`,children:[(0,Z.jsxs)(`form`,{className:`flex shrink-0 items-center gap-1.5 border-b border-outline-variant p-3`,onSubmit:e=>{e.preventDefault(),ue()},children:[(0,Z.jsx)(G,{"aria-label":`Search knowledge`,"data-testid":`kb-search-input`,value:S,onChange:e=>C(e.target.value),placeholder:B&&!d?`Search ${B.name}`:`Search everything`,className:`h-9 min-w-0 flex-1`}),(0,Z.jsx)(p,{type:`submit`,size:`icon`,variant:`ghost`,"data-testid":`kb-search-submit`,"aria-label":`Search`,children:(0,Z.jsx)(te,{size:16})}),E&&(0,Z.jsx)(p,{type:`button`,size:`icon`,variant:`ghost`,"data-testid":`kb-browser-close`,"aria-label":`Close knowledge browser`,onClick:()=>D(!1),children:(0,Z.jsx)(m,{size:16})})]}),B&&(0,Z.jsxs)(`label`,{className:`flex shrink-0 items-center gap-2 border-b border-outline-variant px-3 py-2 text-xs text-outline`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,"data-testid":`kb-search-all`,checked:d,onChange:e=>U({searchAll:e.target.checked?`1`:null})}),`Search all knowledge bases`]}),(0,Z.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-2 pb-1`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1`,children:[(0,Z.jsx)(`h2`,{className:`text-sm font-medium text-outline`,children:`Knowledge bases`}),(0,Z.jsx)(Ve,{label:`Knowledge bases`,children:`Upload documents, write Markdown or sync a folder. Agents search this knowledge with citations, and document details show what they read.`})]}),(0,Z.jsx)(p,{size:`icon`,variant:`ghost`,"aria-label":`New knowledge base`,"data-testid":`kb-create`,onClick:()=>T(`create`),children:(0,Z.jsx)(ee,{size:16})})]}),z.isLoading&&(0,Z.jsx)(le,{className:`mx-2 h-9`}),(0,Z.jsx)(Vr,{bases:z.data??[],projectName:pe,kbId:a,documentId:o,documents:V.data?.documents??[],onSelectKb:se,onOpenDocument:W})]}),(0,Z.jsx)(Hr,{})]});return(0,Z.jsx)(x,{open:E&&!O,onOpenChange:D,children:(0,Z.jsxs)(`div`,{"data-testid":`knowledge-bases`,className:`relative flex min-h-0 min-w-0 flex-1`,children:[(0,Z.jsx)(`h1`,{"data-testid":`view-title`,className:`sr-only`,children:`Knowledge bases`}),O&&he,!O&&(0,Z.jsxs)(v,{children:[(0,Z.jsx)(h,{className:`fixed inset-0 z-50 bg-black/70`}),(0,Z.jsxs)(y,{"data-testid":`kb-mobile-browser`,className:`viewport-sheet fixed inset-x-0 z-50 bg-background`,children:[(0,Z.jsx)(b,{className:`sr-only`,children:`Browse knowledge`}),(0,Z.jsx)(_,{className:`sr-only`,children:`Search knowledge bases and choose a document`}),he]})]}),(0,Z.jsxs)(`div`,{"data-testid":`kb-dropzone`,className:f(`relative flex min-h-0 min-w-0 flex-1 flex-col`,j&&`outline-2 -outline-offset-4 outline-dashed outline-primary`),onDragOver:e=>{B&&(e.preventDefault(),M(!0))},onDragLeave:()=>M(!1),onDrop:fe,children:[(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-outline-variant px-3 py-2 lg:hidden`,children:[(0,Z.jsx)(g,{asChild:!0,children:(0,Z.jsxs)(p,{"data-testid":`kb-browser-open`,variant:`ghost`,size:`sm`,"aria-expanded":E,"aria-controls":`kb-sidebar-panel`,onClick:()=>D(!0),children:[(0,Z.jsx)(re,{size:16}),`Browse`]})}),B&&(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-sm text-outline`,children:B.name})]}),o&&l&&(0,Z.jsx)(`div`,{className:`flex shrink-0 items-center border-b border-outline-variant px-3 py-1`,children:(0,Z.jsxs)(p,{variant:`ghost`,size:`sm`,"data-testid":`kb-search-back`,className:`min-w-0`,onClick:()=>oe()&&U({document:null}),children:[(0,Z.jsx)(ze,{size:14}),(0,Z.jsxs)(`span`,{className:`truncate`,children:[`Back to results for “`,l,`”`]})]})}),(0,Z.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1`,children:me}),(0,Z.jsx)(Kr,{uploads:ae,onOpen:W})]}),w===`create`&&(0,Z.jsx)(jn,{open:!0,projectId:e,onClose:()=>T(null),onCreated:e=>{T(null),D(!1),U({kb:e.id,document:null,label:null,q:null})}}),w===`settings`&&B&&(0,Z.jsx)(Mn,{kb:B,onClose:()=>T(null),onDeleted:()=>{T(null),U({kb:null,document:null,label:null})}}),w===`new-document`&&B&&(0,Z.jsx)(In,{kb:B,initialFile:F,onClose:L,onUploadMany:e=>{L(),ae.add(B.id,e)},onCreated:(e,t)=>{L(),U({document:e.id,editorMode:t?null:`edit`})}})]})})}function Vr({bases:e,projectName:t,kbId:n,documentId:r,documents:i,onSelectKb:a,onOpenDocument:o}){let[s,c]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{r&&c(null)},[r]);let l=new Map;for(let n of e){let e=t(n.project_id);l.set(e,[...l.get(e)??[],n])}let u=[...l.entries()].sort(([e],[t])=>e===`Global`?-1:t===`Global`?1:e.localeCompare(t));return(0,Z.jsx)(`div`,{"data-testid":`kb-list`,className:`space-y-3`,children:u.map(([e,t])=>(0,Z.jsxs)(`section`,{"aria-label":e,children:[u.length>1&&(0,Z.jsx)(`h3`,{className:`truncate px-2 pb-0.5 pt-1 text-xs text-outline`,children:e}),(0,Z.jsx)(`ul`,{className:`space-y-0.5`,children:t.map(e=>{let t=e.id===n,l=t&&s!==e.id&&i.length>0;return(0,Z.jsxs)(`li`,{children:[(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`kb-row`,"data-kb-name":e.name,"aria-current":t&&!r?`page`:void 0,"aria-expanded":l,className:f(`flex min-h-9 w-full items-center gap-2 rounded-md px-2 text-left text-sm hover:bg-surface-high`,t&&`font-medium`,t&&!r&&`bg-surface-high`),onClick:()=>{t&&c(t=>t===e.id?null:e.id),a(e.id)},children:[(0,Z.jsx)(Fe,{size:14,"aria-hidden":!0,className:f(`-mr-1 shrink-0 text-outline transition-transform motion-reduce:transition-none`,l&&`rotate-90`,e.document_count===0&&`invisible`)}),(0,Z.jsx)(Le,{size:15,className:`shrink-0 text-outline`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),(0,Z.jsx)(`span`,{className:`text-xs font-normal tabular-nums text-outline`,children:e.document_count})]}),l&&(0,Z.jsx)(`ul`,{className:`ml-4 mt-0.5 space-y-0.5 border-l border-outline-variant pl-2`,children:i.map(e=>(0,Z.jsx)(`li`,{children:(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`kb-nav-document`,"data-document-title":e.title,"aria-current":e.id===r?`page`:void 0,className:f(`flex min-h-8 w-full items-center gap-2 rounded-md px-2 text-left text-sm hover:bg-surface-high`,e.id===r?`bg-surface-high text-on-surface`:`text-outline`),onClick:()=>o(e.id),children:[(0,Z.jsx)(Pe,{size:14,className:`shrink-0`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.title})]})},e.id))})]},e.id)})})]},e))})}function Hr(){let e=_t(),t=e.data,n=t?t.embedding.provider===`none`?{text:`Keyword search only`,title:`Configure embeddings in Settings to also search by meaning`}:t.embedding.ready?{text:`Hybrid search`,title:t.embedding.model??void 0}:{text:`Embeddings not ready`,title:t.embedding.detail??``}:null,r=t?t.jobs.queued+t.jobs.running:0;return(0,Z.jsx)(`p`,{role:`status`,"data-testid":`kb-status`,className:`shrink-0 border-t border-outline-variant px-4 py-2 text-xs text-outline`,children:t?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{title:n?.title,children:n?.text}),r?` · ${r} processing`:``]}):e.error?`Knowledge status unavailable`:`Loading…`})}function Ur({children:e}){return(0,Z.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto`,children:e})}function Wr({children:e,testId:t}){return(0,Z.jsx)(`div`,{"data-testid":t,className:`mx-auto flex max-w-lg flex-1 flex-col items-start justify-center gap-4 p-6`,children:e})}function Gr({query:e,search:t,onOpen:n,onClear:r}){let i=t.data;return(0,Z.jsxs)(`section`,{"data-testid":`kb-search-results`,"aria-label":`Search results`,className:`w-full min-w-0 space-y-4 p-4 sm:p-8`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsxs)(`h2`,{className:`mr-auto text-lg font-medium`,children:[`Results for “`,e,`”`]}),i&&i.hits.length>0&&(0,Z.jsxs)(`span`,{className:`text-xs text-outline`,"data-testid":`kb-search-count`,children:[i.hits.length,` `,i.hits.length===1?`result`:`results`]}),(0,Z.jsxs)(p,{variant:`ghost`,size:`sm`,onClick:r,"data-testid":`kb-search-clear`,children:[(0,Z.jsx)(m,{size:14}),`Clear`]})]}),i?.degraded&&(0,Z.jsx)(`p`,{role:`status`,className:`text-sm text-warning`,children:i.degraded}),t.isLoading&&(0,Z.jsx)(`p`,{className:`text-sm text-outline`,children:`Searching…`}),t.error&&(0,Z.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:t.error.message}),i?.hits.length===0&&(0,Z.jsx)(`p`,{className:`text-sm text-outline`,"data-testid":`kb-search-empty`,children:`Nothing matched. Try other words or search all knowledge bases.`}),i?.hits.map(e=>(0,Z.jsxs)(`article`,{"data-testid":`kb-search-result`,className:`space-y-2 border-b border-outline-variant pb-4`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`block text-left`,onClick:()=>n(e.document_id,Yr(e.passages[0]?.heading_path)),children:[(0,Z.jsx)(`span`,{className:`block font-medium text-primary hover:underline`,children:e.title}),(0,Z.jsxs)(`span`,{className:`block break-all text-xs text-outline`,children:[e.kb_name,` · `,e.path]})]}),e.labels.length>0&&(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.labels.map(e=>(0,Z.jsx)(At,{variant:`secondary`,children:e},e))}),e.passages.map(t=>(0,Z.jsxs)(`div`,{"data-testid":`kb-search-passage`,className:`cursor-pointer space-y-1 rounded-md p-2 hover:bg-surface-high`,onClick:()=>n(e.document_id,Yr(t.heading_path)),children:[(t.heading_path.length>0||t.locator?.page||t.locator?.sheet)&&(0,Z.jsx)(`div`,{className:`text-xs text-outline`,children:[...t.heading_path.map(Rr),...t.locator?.page?[`page ${t.locator.page}`]:[],...t.locator?.sheet?[`sheet ${t.locator.sheet}`]:[]].join(` › `)}),(0,Z.jsx)(`p`,{className:`text-sm leading-relaxed`,children:(0,Z.jsx)(zr,{text:t.snippet})})]},t.chunk_id))]},e.document_id))]})}function Kr({uploads:e,onOpen:t}){if(!e.uploads.length)return null;let n=e.uploads.some(e=>e.status!==`uploading`);return(0,Z.jsxs)(`section`,{"data-testid":`kb-upload-queue`,"aria-label":`Uploads`,className:`absolute bottom-4 right-4 z-10 flex max-h-72 w-80 max-w-[calc(100%-2rem)] flex-col rounded-lg border border-outline-variant bg-surface text-sm shadow-lg`,children:[(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between px-3 py-1.5`,children:[(0,Z.jsx)(`span`,{className:`font-medium`,children:`Uploads`}),n&&(0,Z.jsx)(p,{size:`sm`,variant:`ghost`,onClick:e.clearFinished,"data-testid":`kb-upload-clear`,children:`Dismiss`})]}),(0,Z.jsx)(`div`,{className:`min-h-0 space-y-1 overflow-y-auto px-3 pb-2`,children:e.uploads.map(n=>(0,Z.jsx)(Jr,{upload:n,onOpen:t,onRetry:()=>e.retry(n.id)},n.id))})]})}var qr={pending:`Parsing…`,ok:`Open`,partial:`Open · partly parsed`,failed:`Parse failed`};function Jr({upload:e,onOpen:t,onRetry:n}){let r=jt(e.status===`done`?e.kbId:null).data?.documents.find(t=>t.id===e.document?.id)??e.document;return(0,Z.jsxs)(`div`,{"data-testid":`kb-upload-item`,"data-status":e.status,"data-parse-state":r?.parse_state,className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.file.name}),e.status===`uploading`&&(0,Z.jsx)(`span`,{className:`h-1.5 w-24 overflow-hidden rounded-full bg-surface-high`,role:`progressbar`,"aria-label":`Upload progress`,"aria-valuenow":Math.round(e.progress*100),children:(0,Z.jsx)(`span`,{className:`block h-full bg-primary`,style:{width:`${Math.round(e.progress*100)}%`}})}),e.status===`done`&&r&&(0,Z.jsx)(`button`,{type:`button`,className:f(`hover:underline`,r.parse_state===`failed`?`text-error`:`text-primary`),onClick:()=>t(r.id),children:qr[r.parse_state]}),e.status===`failed`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{role:`alert`,className:`text-error`,children:e.error}),(0,Z.jsx)(p,{size:`sm`,variant:`ghost`,onClick:n,"data-testid":`kb-upload-retry`,children:`Retry`})]})]})}function Yr(e){return e?.[e.length-1]}export{Lr as default};