ltcai 12.0.0 → 12.2.0

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 (74) hide show
  1. package/README.md +43 -52
  2. package/docs/CHANGELOG.md +41 -0
  3. package/docs/CI_AND_RELEASE_GATES.md +20 -11
  4. package/docs/COMMUNITY_AND_PLUGINS.md +1 -1
  5. package/docs/DEVELOPMENT.md +11 -11
  6. package/docs/ONBOARDING.md +1 -1
  7. package/docs/OPERATIONS.md +1 -1
  8. package/docs/ROADMAP.md +2 -2
  9. package/docs/TRUST_MODEL.md +1 -1
  10. package/docs/WHY_LATTICE.md +1 -1
  11. package/docs/kg-schema.md +1 -1
  12. package/lattice_brain/__init__.py +1 -1
  13. package/latticeai/__init__.py +1 -1
  14. package/latticeai/services/architecture_readiness.py +1 -1
  15. package/latticeai/services/product_readiness.py +1 -1
  16. package/package.json +1 -1
  17. package/scripts/check_current_release_docs.mjs +1 -1
  18. package/scripts/release_screen_claims.json +34 -0
  19. package/src-tauri/Cargo.lock +10 -10
  20. package/src-tauri/Cargo.toml +1 -1
  21. package/src-tauri/tauri.conf.json +1 -1
  22. package/static/app/asset-manifest.json +45 -45
  23. package/static/app/assets/{Act-Cf1L2709.js → Act-BjGgeuQd.js} +2 -2
  24. package/static/app/assets/{AdminConsole-DPAbLTYV.js → AdminConsole-C6hcJGMr.js} +1 -1
  25. package/static/app/assets/{Brain-DqamGrj-.js → Brain-CNQnIaA8.js} +2 -2
  26. package/static/app/assets/BrainHome-CGJ6O69l.js +2 -0
  27. package/static/app/assets/{BrainSignals-CQPPfyyH.js → BrainSignals-DONPljxz.js} +1 -1
  28. package/static/app/assets/{Capture-DGdIH_Zc.js → Capture-BMCC5544.js} +1 -1
  29. package/static/app/assets/{Chronicle-C-UlCJoJ.js → Chronicle-DF6sOonx.js} +1 -1
  30. package/static/app/assets/{CommandPalette-WNT4EqUX.js → CommandPalette-DiWyutdM.js} +1 -1
  31. package/static/app/assets/{DigitalBrainExplorer-CEBH5Cwc.js → DigitalBrainExplorer-BL3V6Dqz.js} +1 -1
  32. package/static/app/assets/{Library-C6xd1dlf.js → Library-B-ue9hXL.js} +1 -1
  33. package/static/app/assets/{LivingBrain-BEk-0ohw.js → LivingBrain-b1RiM5Rh.js} +1 -1
  34. package/static/app/assets/{ProductFlow-CZLm5iXh.js → ProductFlow-wZIKJW7G.js} +1 -1
  35. package/static/app/assets/{ReviewCard-CEHG6evf.js → ReviewCard-D1fGTEn7.js} +1 -1
  36. package/static/app/assets/{RunsListPanel-CLtEJSRW.js → RunsListPanel-DAirtLkS.js} +1 -1
  37. package/static/app/assets/System-BEI1eoC4.js +1 -0
  38. package/static/app/assets/{WorkflowGraph-Dj10RuGE.js → WorkflowGraph-qrI6GU4R.js} +1 -1
  39. package/static/app/assets/{WorkflowsPanel-Kyeh_LIT.js → WorkflowsPanel-CIMNTw-O.js} +2 -2
  40. package/static/app/assets/{actHelpers-CtSmK9Dw.js → actHelpers-BMukIRnQ.js} +1 -1
  41. package/static/app/assets/arrow-left-iVa1goff.js +1 -0
  42. package/static/app/assets/{bot-DhUGRel2.js → bot-Dkd-DbiP.js} +1 -1
  43. package/static/app/assets/brain-BsexlNOA.js +1 -0
  44. package/static/app/assets/{button-CmaEqG1T.js → button-BA0N_zId.js} +1 -1
  45. package/static/app/assets/circle-check-BxaDWjPR.js +1 -0
  46. package/static/app/assets/{circle-pause-l96izbxj.js → circle-pause-918Kuvk0.js} +1 -1
  47. package/static/app/assets/{circle-play-CrZa25_q.js → circle-play-CS0IbVDV.js} +1 -1
  48. package/static/app/assets/{cpu-BaXudqwl.js → cpu-BpvoWsjk.js} +1 -1
  49. package/static/app/assets/{download-hCVFPiyc.js → download-BvkMLLLN.js} +1 -1
  50. package/static/app/assets/{folder-open-CHL82Yp7.js → folder-open-YmGugIBf.js} +1 -1
  51. package/static/app/assets/{hard-drive-DDzET7lk.js → hard-drive-BOzmS-cq.js} +1 -1
  52. package/static/app/assets/{index-CB93CZWW.css → index-C8gwOf0C.css} +1 -1
  53. package/static/app/assets/{index-D2H-wSl6.js → index-CfeqZ9Ri.js} +3 -3
  54. package/static/app/assets/{input-Df1CAY_I.js → input-CFfCfMjO.js} +1 -1
  55. package/static/app/assets/{link-2-xNnTIX1_.js → link-2-CcYzeM7M.js} +1 -1
  56. package/static/app/assets/{permissionCopy-D3aWHco-.js → permissionCopy-B23r24oX.js} +1 -1
  57. package/static/app/assets/{primitives-BioD2slS.js → primitives-BDryQl6H.js} +1 -1
  58. package/static/app/assets/search-DHsPwmPw.js +1 -0
  59. package/static/app/assets/{share-2-FkzGf8Df.js → share-2-B-gPv2ec.js} +1 -1
  60. package/static/app/assets/{shield-alert-B3dwzik4.js → shield-alert-CfyRO1p0.js} +1 -1
  61. package/static/app/assets/{sourceMeta-DQSY_tah.js → sourceMeta-C4LDEy1S.js} +1 -1
  62. package/static/app/assets/{textarea-P8o6pvOP.js → textarea-BdVMYEb1.js} +1 -1
  63. package/static/app/assets/{useFocusTrap-hswOIkXE.js → useFocusTrap-CV73DLHn.js} +1 -1
  64. package/static/app/assets/{useMutation-OJLrYSRA.js → useMutation-B8QKq2NW.js} +1 -1
  65. package/static/app/assets/workspace-BmfVs66W.js +1 -0
  66. package/static/app/index.html +2 -2
  67. package/static/sw.js +1 -1
  68. package/static/app/assets/BrainHome-MHe2_RYs.js +0 -2
  69. package/static/app/assets/System-CAxwBUXw.js +0 -1
  70. package/static/app/assets/arrow-left-CRl5EO4D.js +0 -1
  71. package/static/app/assets/brain-CLkhHsHF.js +0 -1
  72. package/static/app/assets/circle-check-CFgejkOS.js +0 -1
  73. package/static/app/assets/search-BzBw8YcW.js +0 -1
  74. package/static/app/assets/workspace-BCuk3Ku9.js +0 -1
@@ -0,0 +1,2 @@
1
+ import{i as e,n as t,t as n}from"./jsx-runtime-bzQ4Vb5N.js";import{n as r}from"./QueryClientProvider-B3OjqSyJ.js";import{t as i}from"./useMutation-B8QKq2NW.js";import{i as a,n as o,r as s,t as c}from"./LivingBrain-b1RiM5Rh.js";import{t as l}from"./bot-Dkd-DbiP.js";import{C as u,D as d,E as f,O as p,S as m,T as h,_ as g,a as _,b as v,c as y,d as b,f as x,g as S,h as C,i as w,k as T,l as E,m as D,n as O,o as k,p as A,r as ee,s as j,t as te,u as M,v as ne,w as N,x as re,y as P}from"./BrainSignals-DONPljxz.js";import{b as ie,r as ae,y as F}from"./primitives-BDryQl6H.js";import{t as I}from"./circle-check-BxaDWjPR.js";import{t as oe}from"./cpu-BpvoWsjk.js";import{t as L}from"./download-BvkMLLLN.js";import{n as R,r as se,t as ce}from"./hard-drive-BOzmS-cq.js";import{o as le,t as ue}from"./ReviewCard-D1fGTEn7.js";import{t as z}from"./folder-open-YmGugIBf.js";import{t as B}from"./link-2-CcYzeM7M.js";import{a as V,i as de,n as H,r as fe}from"./permissionCopy-B23r24oX.js";import{t as pe}from"./search-DHsPwmPw.js";import{t as me}from"./shield-alert-CfyRO1p0.js";import{n as he,t as ge}from"./useFocusTrap-CV73DLHn.js";import{A as _e,E as ve,H as U,I as ye,L as be,N as xe,R as W,S as G,W as Se,a as Ce,c as we,j as Te,k as Ee,n as K,o as q,p as De,s as Oe,v as J,z as ke}from"./index-CfeqZ9Ri.js";import"./brain-BsexlNOA.js";import{t as Y}from"./button-BA0N_zId.js";import"./workspace-BmfVs66W.js";var Ae=W(`activity`,[[`path`,{d:`M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2`,key:`169zse`}]]),je=W(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),Me=W(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),Ne=W(`chart-spline`,[[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`M7 16c.5-2 1.5-7 4-7 2 0 2 3 4 3 2.5 0 4.5-5 5-7`,key:`lw07rv`}]]),Pe=W(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),Fe=W(`copy`,[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),Ie=W(`database-zap`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 15 21.84`,key:`14ibmq`}],[`path`,{d:`M21 5V8`,key:`1marbg`}],[`path`,{d:`M21 12L18 17H22L19 22`,key:`zafso`}],[`path`,{d:`M3 12A9 3 0 0 0 14.59 14.87`,key:`1y4wr8`}]]),Le=W(`eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),Re=W(`file-check-corner`,[[`path`,{d:`M10.5 22H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v6`,key:`g5mvt7`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`m14 20 2 2 4-4`,key:`15kota`}]]),ze=W(`file-text`,[[`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:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),Be=W(`file-up`,[[`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`}]]),Ve=W(`git-pull-request-arrow`,[[`circle`,{cx:`5`,cy:`6`,r:`3`,key:`1qnov2`}],[`path`,{d:`M5 9v12`,key:`ih889a`}],[`circle`,{cx:`19`,cy:`18`,r:`3`,key:`1qljk2`}],[`path`,{d:`m15 9-3-3 3-3`,key:`1lwv8l`}],[`path`,{d:`M12 6h5a2 2 0 0 1 2 2v7`,key:`1yj91y`}]]),He=W(`image-plus`,[[`path`,{d:`M16 5h6`,key:`1vod17`}],[`path`,{d:`M19 2v6`,key:`4bpg5p`}],[`path`,{d:`M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5`,key:`1ue2ih`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}]]),Ue=W(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]),We=W(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),Ge=W(`map`,[[`path`,{d:`M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z`,key:`169xi5`}],[`path`,{d:`M15 5.764v15`,key:`1pn4in`}],[`path`,{d:`M9 3.236v15`,key:`1uimfh`}]]),Ke=W(`message-circle-plus`,[[`path`,{d:`M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719`,key:`1sd12s`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}],[`path`,{d:`M12 8v8`,key:`napkw2`}]]),qe=W(`message-square-text`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M7 11h10`,key:`1twpyw`}],[`path`,{d:`M7 15h6`,key:`d9of3u`}],[`path`,{d:`M7 7h8`,key:`af5zfr`}]]),Je=W(`pencil-line`,[[`path`,{d:`M13 21h8`,key:`1jsn5i`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}],[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}]]),Ye=W(`plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),Xe=W(`repeat-2`,[[`path`,{d:`m2 9 3-3 3 3`,key:`1ltn5i`}],[`path`,{d:`M13 18H7a2 2 0 0 1-2-2V6`,key:`1r6tfw`}],[`path`,{d:`m22 15-3 3-3-3`,key:`4rnwn2`}],[`path`,{d:`M11 6h6a2 2 0 0 1 2 2v10`,key:`2f72bc`}]]),Ze=W(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),Qe=W(`search-check`,[[`path`,{d:`m8 11 2 2 4-4`,key:`1sed1v`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]),$e=W(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]),et=W(`sliders-horizontal`,[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]),tt=W(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),nt=W(`trash-2`,[[`path`,{d:`M10 11v6`,key:`nco0om`}],[`path`,{d:`M14 11v6`,key:`outv1u`}],[`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`,key:`miytrc`}],[`path`,{d:`M3 6h18`,key:`d0wm0j`}],[`path`,{d:`M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`,key:`e791ji`}]]),X=e(t());function rt(e){if(e.status!==`awaiting_approval`)return null;let t=typeof e.run_id==`string`?e.run_id:``,n=typeof e.approval?.token==`string`?e.approval.token:``;return!t||!n?null:{runId:t,token:n,expiresAt:typeof e.approval?.expires_at==`string`?e.approval.expires_at:``,planSummary:typeof e.approval?.plan_summary==`string`?e.approval.plan_summary:``,plan:e.plan&&typeof e.plan==`object`?e.plan:null,status:`pending`}}function it(e){if(!e||typeof e!=`object`)return``;let t=e,n=(t.detail&&typeof t.detail==`object`&&!Array.isArray(t.detail)?t.detail:t).replan;if(!n||typeof n!=`object`||Array.isArray(n))return``;let r=n.message;return typeof r==`string`?r.trim():``}async function at(e,t){let n=await J.resumeAgentApproval({run_id:e.runId,approval_token:e.token,approve:t.approve,...t.editedPlan?{edited_plan:t.editedPlan}:{}});if(!n.ok){if(n.status===410||n.status===404){let e=it(n.data);return{kind:`expired`,...e?{replanMessage:e}:{}}}return{kind:`error`,reason:n.error||String(n.status||``)}}let r=n.data;return r.status===`cancelled`?{kind:`cancelled`}:{kind:`finished`,payload:r}}var Z=n();function ot(e,t){if(!t)return``;let n=new Date(t);return Number.isNaN(n.getTime())?``:n.toLocaleTimeString(e===`ko`?`ko-KR`:`en-US`,{hour:`2-digit`,minute:`2-digit`})}function st(e){let t=Math.max(0,Math.floor(e/1e3)),n=Math.floor(t/60),r=t%60;return`${n}:${String(r).padStart(2,`0`)}`}var ct=12e4;function lt({language:e,approval:t,onResolved:n,onReplan:r}){let[i,a]=X.useState(!1),[o,s]=X.useState(!1),[c,l]=X.useState(``),[u,d]=X.useState(!1),f=X.useRef(null);X.useEffect(()=>{t.status===`pending`&&f.current?.focus()},[]);let p=t.status===`pending`,m=X.useMemo(()=>{if(!t.expiresAt)return null;let e=Date.parse(t.expiresAt);return Number.isFinite(e)?e:null},[t.expiresAt]),[h,g]=X.useState(()=>Date.now());X.useEffect(()=>{if(!p||m===null)return;g(Date.now());let e=window.setInterval(()=>g(Date.now()),1e3);return()=>window.clearInterval(e)},[p,m]);let _=m===null?null:m-h,v=p&&_!==null&&_>0&&_<ct,y=X.useRef(!1);X.useEffect(()=>{!p||_===null||_>0||y.current||(y.current=!0,n({kind:`expired`}))},[p,_,n]);async function b(e){if(!i){a(!0);try{n(await at(t,e))}finally{a(!1)}}}function x(){l(JSON.stringify(t.plan??{goal:t.planSummary,steps:[]},null,2)),d(!1),s(!0)}function S(){let e;try{e=JSON.parse(c)}catch{d(!0);return}if(!e||typeof e!=`object`||Array.isArray(e)){d(!0);return}d(!1),b({approve:!0,editedPlan:e})}if(t.status!==`pending`){let n=t.status===`approved`?`brain.approval.resolved`:t.status===`cancelled`?`brain.approval.cancelled`:t.status===`expired`?`brain.approval.expired`:`brain.approval.error`,i=t.status===`expired`&&t.replanMessage||``;return(0,Z.jsxs)(`div`,{className:`brain-approval-note is-${t.status}`,role:t.status===`approved`?`status`:`alert`,"data-testid":`agent-approval-note`,children:[(0,Z.jsx)(`span`,{children:G(e,n,{reason:t.errorReason||``})}),i&&r?(0,Z.jsx)(`button`,{type:`button`,className:`brain-approval-replan`,"data-testid":`approval-replan`,onClick:()=>r(i),children:G(e,`brain.approval.expiredReplan`)}):null]})}let C=ot(e,t.expiresAt);return(0,Z.jsxs)(`section`,{className:`brain-approval-card ${v?`is-urgent`:``}`,"aria-label":G(e,`brain.approval.aria`),"data-testid":`agent-approval-card`,children:[(0,Z.jsxs)(`header`,{className:`brain-approval-head`,children:[(0,Z.jsx)(me,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,Z.jsx)(`strong`,{children:G(e,`brain.approval.title`)}),_===null?null:(0,Z.jsx)(`span`,{className:`brain-approval-countdown ${v?`is-urgent`:``}`,"data-testid":`approval-countdown`,children:G(e,`brain.approval.countdown`,{time:st(_)})})]}),t.planSummary?(0,Z.jsxs)(`div`,{className:`brain-approval-summary`,children:[(0,Z.jsx)(`span`,{className:`brain-approval-summary-label`,children:G(e,`brain.approval.summaryLabel`)}),(0,Z.jsx)(`pre`,{"data-testid":`approval-plan-summary`,children:t.planSummary})]}):null,C?(0,Z.jsx)(`small`,{className:`brain-approval-expiry`,children:G(e,`brain.approval.expiry`,{time:C})}):null,v?(0,Z.jsx)(`small`,{className:`brain-approval-urgency`,role:`alert`,"data-testid":`approval-urgency`,children:G(e,`brain.approval.countdown.warning`)}):null,o?(0,Z.jsxs)(`div`,{className:`brain-approval-editor`,children:[(0,Z.jsx)(`label`,{htmlFor:`brain-approval-plan-editor`,children:G(e,`brain.approval.edit.label`)}),(0,Z.jsx)(`textarea`,{id:`brain-approval-plan-editor`,"data-testid":`approval-edit-textarea`,value:c,rows:8,spellCheck:!1,onChange:e=>l(e.target.value)}),u?(0,Z.jsx)(`small`,{className:`brain-approval-edit-error`,role:`alert`,children:G(e,`brain.approval.edit.invalid`)}):null,(0,Z.jsxs)(`div`,{className:`brain-approval-actions`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`brain-approval-primary`,"data-testid":`approval-edit-run`,disabled:i,onClick:S,children:i?G(e,`brain.approval.running`):G(e,`brain.approval.edit.run`)}),(0,Z.jsx)(`button`,{type:`button`,disabled:i,onClick:()=>s(!1),children:G(e,`brain.approval.edit.close`)})]})]}):(0,Z.jsxs)(`div`,{className:`brain-approval-actions`,children:[(0,Z.jsx)(`button`,{ref:f,type:`button`,className:`brain-approval-primary`,"data-testid":`approval-approve`,disabled:i,onClick:()=>void b({approve:!0}),children:i?G(e,`brain.approval.running`):G(e,`brain.approval.approve`)}),(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`approval-edit`,disabled:i,onClick:x,children:[(0,Z.jsx)(Je,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),G(e,`brain.approval.edit`)]}),(0,Z.jsx)(`button`,{type:`button`,"data-testid":`approval-cancel`,disabled:i,onClick:()=>void b({approve:!1}),children:G(e,`brain.approval.cancel`)})]})]})}function ut(e){return e.event===`blocked`?`blocked`:e.event===`parse_error`||e.ok===!1?`error`:e.event===`proposed`?`proposed`:e.event===`tool`?`ok`:e.phase===`rollback`?`error`:`info`}function dt(e){if(e.phase===`rollback`)return`brain.steps.rollback`;switch(e.event){case`planned`:return`brain.steps.planned`;case`tool`:return e.ok===!1?`brain.steps.tool.failed`:`brain.steps.tool`;case`proposed`:return`brain.steps.proposed`;case`blocked`:return`brain.steps.blocked`;case`parse_error`:return`brain.steps.parseError`;case`verdict`:return`brain.steps.verdict`;case`final`:return`brain.steps.final`;case`state`:return`brain.steps.state`;default:return`brain.steps.step`}}function ft(e){return e.split(/[\\/]/).filter(Boolean).pop()||e}function pt(e,t){return t?t.startsWith(`mcp.`)?`${G(e,`brain.steps.action.mcp`)} · ${t}`:t.startsWith(`skill.`)?`${G(e,`brain.steps.action.skill`)} · ${t}`:t:``}function mt(e,t){return[pt(e,t.action),t.path?ft(t.path):``,t.decision,t.verdict,t.state].filter(Boolean).join(` · `)}function ht({language:e,steps:t,streaming:n}){if(!t.length)return null;let r=(0,Z.jsx)(`ol`,{className:`brain-step-list`,children:t.slice(-30).map((t,n)=>{let r=ut(t),i=mt(e,t);return(0,Z.jsxs)(`li`,{className:`brain-step-item is-${r}`,children:[(0,Z.jsx)(`span`,{className:`brain-step-dot`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`brain-step-label`,children:G(e,dt(t))}),i?(0,Z.jsx)(`span`,{className:`brain-step-meta`,children:i}):null,t.detail?(0,Z.jsx)(`small`,{className:`brain-step-detail`,children:t.detail}):null]},n)})});return n?(0,Z.jsxs)(`section`,{className:`brain-step-timeline is-live`,"aria-label":G(e,`brain.steps.aria`),"data-testid":`agent-step-timeline`,children:[(0,Z.jsxs)(`p`,{className:`brain-step-live-head`,role:`status`,children:[(0,Z.jsx)(`span`,{className:`brain-step-dot is-live`,"aria-hidden":`true`}),G(e,`brain.steps.live`,{count:t.length})]}),r]}):(0,Z.jsxs)(`details`,{className:`brain-step-timeline`,"aria-label":G(e,`brain.steps.aria`),"data-testid":`agent-step-timeline`,children:[(0,Z.jsx)(`summary`,{children:G(e,`brain.steps.summary`,{count:t.length})}),r]})}function gt({language:e,summary:t}){if(t.total<1)return null;let n=Object.entries(t.repairs).sort((e,t)=>t[1]-e[1]).slice(0,3).map(([e,t])=>`${e} ×${t}`);return t.parseRecovered>0&&n.push(`parse ×${t.parseRecovered}`),(0,Z.jsx)(`p`,{className:`brain-loop-repairs`,role:`note`,"data-testid":`loop-repairs-note`,title:n.join(`, `)||void 0,children:G(e,`brain.agent.repairs`,{count:t.total})})}function _t({language:e,explanation:t}){return(0,Z.jsxs)(`div`,{className:`brain-run-explanation is-${t.ok?`ok`:`caution`} strain-${t.strainLevel}`,role:`note`,"data-testid":`run-explanation`,"data-code":t.code,children:[t.headline?(0,Z.jsx)(`strong`,{children:t.headline}):null,t.details.length?(0,Z.jsx)(`ul`,{children:t.details.map(e=>(0,Z.jsx)(`li`,{children:e},e))}):null,(0,Z.jsx)(`small`,{children:G(e,`brain.agent.explanation.why`)})]})}function vt(e,t){return`${e}-cite-${t}`}function yt({language:e,proof:t,messageId:n}){let r=e=>{let t=document.getElementById(vt(n,e));t&&(t.scrollIntoView({behavior:`smooth`,block:`nearest`}),t.focus())};return(0,Z.jsx)(`span`,{className:`brain-inline-citations`,"aria-label":G(e,`brain.answerProof.citationsLabel`,{count:t.citations.length}),children:t.citations.map((t,i)=>(0,Z.jsx)(`button`,{type:`button`,className:`brain-inline-citation`,"aria-label":G(e,`brain.answerProof.marker`,{index:i+1}),"aria-controls":vt(n,t.id),title:t.title,onClick:()=>r(t.id),children:i+1},t.id))})}function bt({language:e,proof:t,messageId:n,onUseEvidence:r}){let[i,a]=X.useState(null);return(0,Z.jsxs)(`section`,{className:`brain-answer-proof`,role:`group`,"aria-label":G(e,`brain.answerProof.aria`),children:[(0,Z.jsxs)(`div`,{className:`brain-answer-proof-head`,children:[(0,Z.jsx)(`span`,{children:G(e,`brain.answerProof.title`)}),(0,Z.jsx)(`strong`,{children:t.provenAcrossModels?G(e,`brain.answerProof.modelProven`,{model:t.model}):G(e,`brain.answerProof.modelPending`,{model:t.model})}),t.citations.length?(0,Z.jsx)(`small`,{className:`brain-answer-proof-count`,children:G(e,`brain.answerProof.citationsLabel`,{count:t.citations.length})}):null]}),t.citations.length?(0,Z.jsx)(`ol`,{children:t.citations.map((r,i)=>(0,Z.jsx)(`li`,{id:vt(n,r.id),tabIndex:-1,"aria-label":G(e,`brain.answerProof.citationItem`,{index:i+1,title:r.title}),children:(0,Z.jsxs)(`button`,{type:`button`,className:`brain-citation-open`,"aria-haspopup":`dialog`,"aria-label":G(e,`brain.sourceModal.openAria`,{title:r.title}),"data-testid":`citation-open`,onClick:()=>a(r),children:[(0,Z.jsx)(`span`,{className:`brain-answer-proof-index`,"aria-hidden":`true`,children:i+1}),(0,Z.jsx)(`span`,{children:r.source}),(0,Z.jsx)(`strong`,{children:r.title}),(0,Z.jsx)(xt,{language:e,citation:r}),r.locator?(0,Z.jsx)(`em`,{className:`brain-citation-locator`,"data-testid":`citation-locator`,children:r.locator}):null,(0,Z.jsx)(`small`,{children:r.snippet||t.query}),(0,Z.jsx)(Ct,{language:e,citation:r}),(0,Z.jsx)(`span`,{className:`brain-citation-open-hint`,"aria-hidden":`true`,children:G(e,`brain.sourceModal.open`)})]})},r.id))}):(0,Z.jsx)(`small`,{children:G(e,`brain.answerProof.empty`)}),r&&t.citations.length?(0,Z.jsx)(St,{language:e,query:t.query,sourceIds:t.citations.map(e=>e.id),onUseEvidence:r}):null,i?(0,Z.jsx)(Et,{language:e,citation:i,onClose:()=>a(null)}):null]})}function xt({language:e,citation:t}){return t.kind===`Image`||t.kind===`ImageText`?(0,Z.jsxs)(`span`,{className:`brain-citation-visual`,"data-testid":`citation-visual`,children:[t.thumbnail?(0,Z.jsx)(`img`,{className:`brain-citation-thumb`,src:t.thumbnail,alt:t.caption||G(e,`brain.answerProof.imageAlt`,{title:t.title}),width:48,height:48,loading:`lazy`}):(0,Z.jsx)(`span`,{className:`brain-citation-thumb is-missing`,"aria-hidden":`true`,children:G(e,`brain.answerProof.imageBadge`)}),(0,Z.jsx)(`span`,{className:`brain-citation-visual-text`,children:t.caption?(0,Z.jsx)(`em`,{"data-testid":`citation-caption`,children:t.caption}):(0,Z.jsx)(`em`,{className:`is-muted`,"data-testid":`citation-caption-absent`,children:G(e,`brain.answerProof.noCaption`)})})]}):null}function St({language:e,query:t,sourceIds:n,onUseEvidence:r}){let[i,a]=X.useState({status:`idle`}),o=X.useCallback(()=>{a({status:`loading`}),J.evidenceActions(t,n,e).then(e=>{let t=e.data;a({status:`ready`,actions:e.ok?t.actions:[],reason:e.ok?t.reason:e.error||``})})},[e,t,n]);return i.status===`idle`?(0,Z.jsx)(`div`,{className:`brain-evidence-actions`,children:(0,Z.jsx)(`button`,{type:`button`,className:`brain-evidence-action-trigger`,"data-testid":`evidence-actions-open`,onClick:o,children:G(e,`brain.evidenceActions.open`)})}):i.status===`loading`?(0,Z.jsx)(`div`,{className:`brain-evidence-actions`,children:(0,Z.jsx)(`small`,{role:`status`,children:G(e,`brain.evidenceActions.loading`)})}):i.actions.length?(0,Z.jsxs)(`div`,{className:`brain-evidence-actions`,"data-testid":`evidence-actions`,children:[(0,Z.jsx)(`small`,{children:G(e,`brain.evidenceActions.title`)}),(0,Z.jsx)(`div`,{className:`brain-evidence-action-list`,children:i.actions.map(t=>(0,Z.jsx)(`button`,{type:`button`,className:`brain-evidence-action`,"data-testid":`evidence-action-${t.id}`,title:t.suggested_path||void 0,onClick:()=>r(t.prompt),children:t.label[e===`ko`?`ko`:`en`]},t.id))})]}):(0,Z.jsx)(`div`,{className:`brain-evidence-actions`,children:(0,Z.jsx)(`small`,{className:`is-error`,role:`status`,children:i.reason||G(e,`brain.evidenceActions.unavailable`)})})}function Ct({language:e,citation:t}){let n=t.matchedTerms.length>0;return(0,Z.jsxs)(`span`,{className:`brain-citation-why`,"aria-label":G(e,`brain.answerProof.why.aria`),children:[(0,Z.jsx)(`em`,{className:`brain-citation-confidence is-${t.confidence}`,children:G(e,`brain.answerProof.confidence.${t.confidence}`)}),n?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`brain-citation-why-label`,children:G(e,`brain.answerProof.matched`)}),t.matchedTerms.slice(0,4).map(e=>(0,Z.jsx)(`mark`,{children:e},e))]}):(0,Z.jsx)(`span`,{className:`brain-citation-why-label`,children:G(e,`brain.answerProof.matched.none`)})]})}var wt=[`source`,`source_uri`,`origin`,`relative_path`,`path`,`filename`,`conversation_id`,`provenance_id`];function Tt(e){let t=S(e)?e:{},n=S(t.node)?t.node:null;if(!n)return null;let r=S(n.metadata)?n.metadata:{},i=wt.flatMap(e=>{let t=d(r,[e]);return t?[{key:e,value:t}]:[]});return{title:d(n,[`title`,`label`,`id`]),type:d(n,[`type`]),summary:d(n,[`summary`,`content`,`text`]),provenance:i}}function Et({language:e,citation:t,onClose:n}){let r=ge(n),[i,a]=X.useState({status:`loading`});X.useEffect(()=>{let e=!1;return a({status:`loading`}),J.graphNode(t.id).then(t=>{if(e)return;let n=t.ok?Tt(t.data):null;a(n?{status:`ready`,node:n}:{status:`error`,reason:t.error||String(t.status||``)})}),()=>{e=!0}},[t.id]);let o=i.status===`ready`&&i.node.title?i.node.title:t.title;return(0,Z.jsx)(`div`,{className:`file-preview-backdrop`,role:`presentation`,onMouseDown:e=>{e.target===e.currentTarget&&n()},children:(0,Z.jsxs)(`div`,{ref:r,className:`file-preview-modal source-chunk-modal`,role:`dialog`,"aria-modal":`true`,"aria-label":G(e,`brain.sourceModal.aria`,{title:o}),"data-testid":`source-chunk-modal`,children:[(0,Z.jsxs)(`header`,{className:`file-preview-head`,children:[(0,Z.jsx)(`strong`,{className:`file-preview-name`,children:o}),(0,Z.jsxs)(`div`,{className:`file-preview-actions`,children:[i.status===`ready`&&i.node.type?(0,Z.jsx)(`span`,{className:`source-chunk-type`,children:i.node.type}):null,(0,Z.jsx)(`button`,{type:`button`,className:`file-preview-close`,"aria-label":G(e,`brain.sourceModal.close`),onClick:n,children:(0,Z.jsx)(ve,{className:`h-4 w-4`,"aria-hidden":`true`})})]})]}),(0,Z.jsx)(`div`,{className:`file-preview-body source-chunk-body`,children:i.status===`loading`?(0,Z.jsx)(`p`,{className:`file-preview-note`,role:`status`,children:G(e,`brain.sourceModal.loading`)}):i.status===`error`?(0,Z.jsx)(`p`,{className:`file-preview-note is-error`,role:`alert`,children:G(e,`brain.sourceModal.error`,{reason:i.reason})}):(0,Z.jsxs)(Z.Fragment,{children:[i.node.summary?(0,Z.jsx)(`pre`,{className:`source-chunk-text`,"data-testid":`source-chunk-text`,children:i.node.summary}):(0,Z.jsx)(`p`,{className:`file-preview-note`,children:G(e,`brain.sourceModal.empty`)}),i.node.provenance.length?(0,Z.jsxs)(`div`,{className:`source-chunk-provenance`,"data-testid":`source-chunk-provenance`,children:[(0,Z.jsx)(`small`,{children:G(e,`brain.sourceModal.provenance`)}),(0,Z.jsx)(`ul`,{children:i.node.provenance.map(e=>(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(`span`,{children:e.key}),(0,Z.jsx)(`code`,{children:e.value})]},e.key))})]}):null]})})]})})}function Dt({language:e}){let t=r(),[n,i]=X.useState(!1),[a,o]=X.useState(``),[s,c]=X.useState(``),[l,u]=X.useState(``),[d,f]=X.useState(null),m=U({queryKey:[`portability`],queryFn:J.graphPortability}),h=U({queryKey:[`backupHealth`],queryFn:J.backupHealth}),g=X.useCallback(e=>f(e),[]),_=a.trim()?Nt(a.trim(),e):``,v=s.trim()?Pt(s,e):``,y=!s||s===l,b=!!s.trim()&&y&&!v,x=!!a.trim()&&!_,S=Ot(()=>J.graphExport(),void 0,g),C=Ot(()=>J.graphBackup(),()=>{t.invalidateQueries({queryKey:[`backupHealth`]}),t.invalidateQueries({queryKey:[`portability`]})},g),w=Ot(()=>J.brainArchive({path:a.trim()||null,passphrase:s}),()=>void t.invalidateQueries({queryKey:[`backupHealth`]}),g),T=Ot(()=>J.brainArchiveInspect({path:a.trim(),passphrase:s||null}),void 0,g),E=Ot(()=>J.brainArchiveRestore({path:a.trim(),passphrase:s,dry_run:!0,confirm:!1}),void 0,g),D=At(m.data?.data),O=jt(h.data?.data,e);return(0,Z.jsxs)(`section`,{className:`brain-care-panel ${n?`is-expanded`:`is-collapsed`}`,"aria-label":G(e,`care.title`),children:[(0,Z.jsxs)(`button`,{className:`brain-care-summary`,type:`button`,"aria-expanded":n,"aria-controls":`brain-care-details`,onClick:()=>i(e=>!e),children:[(0,Z.jsxs)(`span`,{className:`brain-care-summary-main`,children:[(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(Ee,{className:`h-3.5 w-3.5`}),` `,G(e,`care.title`)]}),(0,Z.jsx)(`strong`,{children:G(e,`care.subtitle`)})]}),(0,Z.jsxs)(`div`,{className:`brain-care-proof`,"aria-label":G(e,`care.ownershipModel`),children:[(0,Z.jsx)(`span`,{children:G(e,`care.private`)}),(0,Z.jsx)(`span`,{children:D}),(0,Z.jsx)(`span`,{children:O})]}),(0,Z.jsx)(ye,{className:`brain-care-toggle h-4 w-4`,"aria-hidden":`true`})]}),n?(0,Z.jsxs)(`div`,{id:`brain-care-details`,className:`brain-care-details`,children:[(0,Z.jsxs)(`div`,{className:`brain-care-actions`,children:[(0,Z.jsx)(kt,{icon:(0,Z.jsx)(L,{className:`h-3.5 w-3.5`}),label:G(e,`care.export`),detail:G(e,`care.export.detail`),pendingLabel:G(e,`care.working`),pending:S.isPending,onClick:()=>S.mutate()}),(0,Z.jsx)(kt,{icon:(0,Z.jsx)(p,{className:`h-3.5 w-3.5`}),label:G(e,`care.backup`),detail:G(e,`care.backup.detail`),pendingLabel:G(e,`care.working`),pending:C.isPending,onClick:()=>C.mutate()}),(0,Z.jsx)(kt,{icon:(0,Z.jsx)(je,{className:`h-3.5 w-3.5`}),label:G(e,`care.archive`),detail:G(e,`care.archive.detail`),pendingLabel:G(e,`care.working`),pending:w.isPending,disabled:!b,onClick:()=>w.mutate()})]}),(0,Z.jsxs)(`div`,{className:`brain-care-archive`,children:[(0,Z.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),placeholder:G(e,`care.path.placeholder`),"aria-label":G(e,`care.path.label`)}),(0,Z.jsx)(`input`,{type:`password`,value:s,onChange:e=>c(e.target.value),placeholder:G(e,`care.passphrase.placeholder`),"aria-label":G(e,`care.passphrase.label`)}),(0,Z.jsx)(`input`,{type:`password`,value:l,onChange:e=>u(e.target.value),placeholder:G(e,`care.passphrase.confirmPlaceholder`),"aria-label":G(e,`care.passphrase.confirmLabel`)}),(0,Z.jsxs)(`div`,{className:`brain-care-guidance`,role:`status`,children:[_?(0,Z.jsx)(`span`,{className:`is-error`,children:_}):a.trim()?(0,Z.jsx)(`span`,{children:G(e,`care.path.ready`)}):null,v?(0,Z.jsx)(`span`,{className:`is-error`,children:v}):s?(0,Z.jsx)(`span`,{children:G(e,`care.passphrase.strong`)}):null,y?null:(0,Z.jsx)(`span`,{className:`is-error`,children:G(e,`care.passphrase.mismatch`)})]}),(0,Z.jsxs)(`div`,{className:`brain-care-archive-actions`,children:[(0,Z.jsxs)(Y,{variant:`outline`,size:`sm`,disabled:!x||T.isPending,onClick:()=>T.mutate(),children:[(0,Z.jsx)(Le,{className:`h-3.5 w-3.5`}),` `,G(e,`care.inspect`)]}),(0,Z.jsxs)(Y,{variant:`outline`,size:`sm`,disabled:!x||!s.trim()||!y||E.isPending,onClick:()=>E.mutate(),children:[(0,Z.jsx)(_e,{className:`h-3.5 w-3.5`}),` `,G(e,`care.restorePreview`)]})]})]}),d?(0,Z.jsx)(`div`,{className:`brain-care-result ${d.ok?`is-ok`:`is-error`}`,role:`status`,children:(0,Z.jsx)(Mt,{result:d,language:e})}):(0,Z.jsx)(`p`,{className:`brain-care-note`,children:G(e,`care.note`)})]}):null]})}function Ot(e,t,n){return i({mutationFn:e,onSuccess:e=>{n?.(e),t?.()}})}function kt({icon:e,label:t,detail:n,pendingLabel:r,pending:i,disabled:a,onClick:o}){return(0,Z.jsxs)(`button`,{className:`brain-care-button`,type:`button`,disabled:a||i,onClick:o,children:[e,(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`strong`,{children:i?r:t}),(0,Z.jsx)(`small`,{children:n})]})]})}function At(e){return d(S(e)?e:{},[`archive_format`,`format`,`graph_schema_version`,`schema_version`],`.latticebrain`)}function jt(e,t){let n=S(e)?e:{},r=n.count||n.backups||n.available;return r!=null&&r!==``?G(t,`care.backup.count`,{count:String(r)}):G(t,`care.backup.ready`)}function Mt({result:e,language:t}){if(!e.ok)return(0,Z.jsxs)(`div`,{className:`brain-care-result-summary`,children:[(0,Z.jsx)(`strong`,{children:G(t,`care.result.error`)}),e.error&&e.error!==G(t,`care.result.error`)?(0,Z.jsx)(`span`,{children:e.error}):null]});let n=S(e.data)?e.data:{},r=d(n,[`path`,`archive_path`,`backup_path`,`export_path`,`latest_backup`]),i=d(n,[`message`,`status`,`result`],G(t,`care.result.completed`)),a={memories:d(n,[`nodes`,`total_nodes`,`memories`,`memory_count`]),links:d(n,[`edges`,`total_edges`,`relationships`,`relationship_count`]),conversations:d(n,[`conversations`,`conversation_count`])};return(0,Z.jsxs)(`div`,{className:`brain-care-result-summary`,children:[(0,Z.jsx)(`strong`,{children:i}),r?(0,Z.jsx)(`span`,{children:G(t,`care.result.path`,{path:r})}):null,a.memories||a.links||a.conversations?(0,Z.jsx)(`span`,{children:G(t,`care.result.contents`,{memories:a.memories||`0`,links:a.links||`0`,conversations:a.conversations||`0`})}):null,n.dry_run===!0?(0,Z.jsx)(`span`,{children:G(t,`care.result.dryRun`)}):null]})}function Nt(e,t){return/[<>:"|?*]/.test(e)?G(t,`care.path.invalidChars`):/\.(latticebrain|zip|json)$/i.test(e)?``:G(t,`care.path.extension`)}function Pt(e,t){return e.length<12?G(t,`care.passphrase.tooShort`):[/[a-z]/,/[A-Z]/,/\d/,/[^A-Za-z0-9]/].filter(t=>t.test(e)).length<3?G(t,`care.passphrase.tooSimple`):``}var Ft=[`freshness`,`connectivity`,`embedding_coverage`,`consistency`],It=new Set([`rebuild_vector_index`,`review_orphans`,`refresh_stale_knowledge`,`resolve_contradictions`]);function Lt({language:e}){let t=r(),[n,a]=X.useState(!1),o=U({queryKey:[`brainHealth`],queryFn:J.brainHealth,enabled:n}),s=U({queryKey:[`brainInsights`],queryFn:J.brainInsights,enabled:n}),c=U({queryKey:[`brainContradictions`],queryFn:J.brainContradictions,enabled:n}),[l,u]=X.useState(null),d=i({mutationFn:()=>J.brainConsolidate(!1),onSuccess:e=>{e.ok&&S(e.data)&&u(e.data)}}),f=i({mutationFn:()=>J.brainConsolidate(!0),onSuccess:e=>{e.ok&&S(e.data)&&u(e.data),t.invalidateQueries({queryKey:[`brainHealth`]})}}),p=o.data?.ok&&S(o.data.data)?o.data.data:null,m=n&&!o.isPending&&(o.isError||!o.data?.ok||o.data?.source===`unavailable`),h=()=>{o.refetch(),s.refetch(),c.refetch()},g=s.data?.ok&&S(s.data.data)?s.data.data:null,_=c.data?.ok&&S(c.data.data)?Number(c.data.data.count||0):0,v=p&&typeof p.overall_score==`number`?p.overall_score:null,y=p&&typeof p.grade==`string`?p.grade:null,b=p&&S(p.dimensions)?p.dimensions:{},x=p&&Array.isArray(p.recommended_actions)?p.recommended_actions:[],C=g&&S(g.activity)?g.activity:{},w=g&&S(g.attention)?g.attention:{};return(0,Z.jsxs)(`section`,{className:`brain-care-panel brain-intelligence-panel ${n?`is-expanded`:`is-collapsed`}`,"aria-label":G(e,`intelligence.title`),children:[(0,Z.jsxs)(`button`,{className:`brain-care-summary`,type:`button`,"aria-expanded":n,"aria-controls":`brain-intelligence-details`,onClick:()=>a(e=>!e),children:[(0,Z.jsxs)(`span`,{className:`brain-care-summary-main`,children:[(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(F,{className:`h-3.5 w-3.5`}),` `,G(e,`intelligence.title`)]}),(0,Z.jsx)(`strong`,{children:G(e,`intelligence.subtitle`)})]}),n&&v!==null?(0,Z.jsxs)(`div`,{className:`brain-care-proof`,children:[(0,Z.jsxs)(`span`,{children:[G(e,`intelligence.score`),`: `,v]}),(0,Z.jsx)(`span`,{children:Rt(y,e)})]}):null,(0,Z.jsx)(ye,{className:`brain-care-toggle h-4 w-4`,"aria-hidden":`true`})]}),n?(0,Z.jsx)(`div`,{id:`brain-intelligence-details`,className:`brain-care-details`,children:o.isPending?(0,Z.jsx)(`p`,{className:`brain-care-note`,children:G(e,`intelligence.loading`)}):m?(0,Z.jsxs)(`div`,{className:`grid gap-2`,role:`alert`,children:[(0,Z.jsx)(`p`,{className:`brain-care-note`,children:G(e,`intelligence.loadError`)}),o.data?.error?(0,Z.jsx)(`small`,{className:`text-xs text-muted-foreground opacity-75`,children:o.data.error}):null,(0,Z.jsx)(`div`,{children:(0,Z.jsx)(Y,{variant:`outline`,size:`sm`,onClick:h,children:G(e,`common.retry`)})})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`brain-intelligence-dimensions`,role:`list`,children:Ft.map(t=>{let n=S(b[t])?b[t]:{},r=typeof n.score==`number`?n.score:null;return(0,Z.jsxs)(`div`,{className:`brain-intelligence-dimension`,role:`listitem`,children:[(0,Z.jsx)(`small`,{children:G(e,`intelligence.dim.${t}`)}),(0,Z.jsx)(`strong`,{children:r===null?`—`:r})]},t)})}),(0,Z.jsxs)(`div`,{className:`brain-intelligence-insights`,role:`status`,children:[(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(Ae,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),` `,G(e,`intelligence.insights.recent`,{count:String(Q(C.recent_nodes))})]}),(0,Z.jsx)(`span`,{children:G(e,`intelligence.insights.stale`,{count:String(Q(w.stale_nodes))})}),(0,Z.jsx)(`span`,{children:G(e,`intelligence.insights.orphans`,{count:String(Q(w.orphan_nodes))})}),(0,Z.jsx)(`span`,{children:G(e,`intelligence.contradictions`,{count:String(_)})})]}),x.length?(0,Z.jsxs)(`div`,{className:`brain-intelligence-actions`,children:[(0,Z.jsx)(`small`,{children:G(e,`intelligence.actions`)}),(0,Z.jsx)(`ul`,{children:x.map((t,n)=>{let r=S(t)?t:{},i=String(r.id||``);return(0,Z.jsx)(`li`,{children:It.has(i)?G(e,`intelligence.action.${i}`):String(r.reason||i)},`${i}-${n}`)})})]}):null,(0,Z.jsxs)(`div`,{className:`brain-care-archive-actions`,children:[(0,Z.jsx)(Y,{variant:`outline`,size:`sm`,disabled:d.isPending,onClick:()=>d.mutate(),children:d.isPending?G(e,`intelligence.consolidate.working`):G(e,`intelligence.consolidate`)}),l&&Q(l.duplicate_memory_count)>0&&l.mode!==`applied`?(0,Z.jsx)(Y,{variant:`outline`,size:`sm`,disabled:f.isPending,onClick:()=>f.mutate(),children:G(e,`intelligence.consolidate.apply`)}):null]}),l?(0,Z.jsx)(`p`,{className:`brain-care-note`,role:`status`,children:l.mode===`applied`?G(e,`intelligence.consolidate.applied`,{count:String(Q(l.pruned))}):Q(l.duplicate_memory_count)>0||Q(l.duplicate_edge_count)>0?G(e,`intelligence.consolidate.found`,{memories:String(Q(l.duplicate_memory_count)),edges:String(Q(l.duplicate_edge_count))}):G(e,`intelligence.consolidate.none`)}):null]})}):null]})}function Rt(e,t){return G(t,`intelligence.grade.${e&&new Set([`excellent`,`good`,`attention`,`critical`]).has(e)?e:`unknown`}`)}function Q(e){let t=Number(e);return Number.isFinite(t)?t:0}var zt=[`recent`,`contradictions`,`stale`,`frequent`];function Bt(e,t){for(let n of t){let t=e[n];if(typeof t==`string`&&t.trim())return t.trim();if(typeof t==`number`&&Number.isFinite(t))return String(t)}return``}function Vt(e){let t=De(e)?e:{},n=De(t.beds)?t.beds:{};return{available:t.available===!0,beds:zt.map(e=>{let t=De(n[e])?n[e]:{},r=Number(t.count),i=we(t.items).flatMap(t=>{let n=De(t)?t:{},r=Bt(n,[`id`]),i=Bt(n,[`title`,`summary`,`label`]);return!r||!i?[]:[{id:r,title:i,type:Bt(n,[`type`,`kind`]),detail:e===`frequent`?Bt(n,[`degree`]):Bt(n,[`updated_at`,`detail`])}]});return{id:e,count:Number.isFinite(r)&&r>0?Math.round(r):i.length,items:i}})}}function Ht({language:e}){let[t,n]=X.useState(!1),r=U({queryKey:[`knowledgeGarden`],queryFn:()=>J.brainGarden(),enabled:t,staleTime:6e4}),i=X.useMemo(()=>r.data?.ok?Vt(r.data.data):null,[r.data]);return(0,Z.jsxs)(`details`,{className:`brain-garden`,"data-testid":`knowledge-garden`,open:t,onToggle:e=>n(e.currentTarget.open),children:[(0,Z.jsx)(`summary`,{children:G(e,`brain.garden.title`)}),t?r.isLoading?(0,Z.jsx)(`p`,{role:`status`,children:G(e,`brain.garden.loading`)}):!i||!i.available?(0,Z.jsx)(`p`,{role:`status`,className:`is-muted`,children:G(e,`brain.garden.unavailable`)}):(0,Z.jsx)(`div`,{className:`brain-garden-beds`,children:i.beds.map(t=>(0,Z.jsxs)(`section`,{"data-testid":`garden-bed-${t.id}`,children:[(0,Z.jsxs)(`h4`,{children:[G(e,`brain.garden.bed.${t.id}`),(0,Z.jsx)(`span`,{className:`brain-garden-count`,children:t.count})]}),t.items.length?(0,Z.jsx)(`ul`,{children:t.items.map(e=>(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(`strong`,{children:e.title}),e.type?(0,Z.jsx)(`em`,{children:e.type}):null,e.detail?(0,Z.jsx)(`small`,{children:e.detail}):null]},e.id))}):(0,Z.jsx)(`p`,{className:`is-muted`,children:G(e,`brain.garden.empty.${t.id}`)})]},t.id))}):null]})}var Ut={"review-pending":`briefing.action.reviewPending`,"enable-drafts":`briefing.action.enableDrafts`,"install-suggestion":`briefing.action.installSuggestion`,"connect-knowledge":`briefing.action.connectKnowledge`,"check-health":`briefing.action.checkHealth`,"ask-brain":`briefing.action.askBrain`};function Wt(e,t){let n=(e.sections||{})[t];return n&&typeof n==`object`?n:{}}function Gt(e){e&&(e.closest(`details`)?.setAttribute(`open`,``),window.setTimeout(()=>e.scrollIntoView?.({behavior:`smooth`,block:`center`}),0))}function Kt({language:e,variant:t=`drawer`}){let[n,r]=X.useState(t===`home`),i=X.useRef(null),o=U({queryKey:[`commandBriefing`],queryFn:J.commandBriefing,enabled:n});X.useEffect(()=>{let e=()=>{r(!0),Gt(i.current)};return window.addEventListener(`lattice:open-briefing`,e),()=>window.removeEventListener(`lattice:open-briefing`,e)},[]);let s=o.data?.data||{},c=!!o.data&&(!o.data?.ok||Object.keys(s.sections||{}).length===0),l=Wt(s,`knowledge`),u=Wt(s,`conversations`),d=Wt(s,`automations`),f=Wt(s,`review`),p=Wt(s,`health`),m=Wt(s,`suggestions`),h=we(s.quick_actions),g=we(l.recent);return(0,Z.jsxs)(`section`,{ref:i,className:`brain-care-panel daily-briefing-panel ${n?`is-expanded`:`is-collapsed`} ${t===`home`?`is-home`:``}`,"aria-label":G(e,`briefing.title`),"data-testid":`daily-briefing`,children:[(0,Z.jsxs)(`button`,{className:`brain-care-summary`,type:`button`,"aria-expanded":n,"aria-controls":`daily-briefing-details`,onClick:()=>r(e=>!e),children:[(0,Z.jsxs)(`span`,{className:`brain-care-summary-main`,children:[(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(he,{className:`h-3.5 w-3.5`}),` `,G(e,`briefing.title`)]}),(0,Z.jsx)(`strong`,{children:G(e,`briefing.subtitle`)})]}),(0,Z.jsx)(ye,{className:`brain-care-toggle h-4 w-4`,"aria-hidden":`true`})]}),n?(0,Z.jsx)(`div`,{id:`daily-briefing-details`,className:`brain-care-details`,children:o.isPending?(0,Z.jsx)(`p`,{className:`brain-care-note`,children:G(e,`briefing.loading`)}):c?(0,Z.jsx)(`p`,{className:`brain-care-note`,"data-testid":`daily-briefing-empty`,children:G(e,`briefing.empty`)}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`daily-briefing-stats`,role:`list`,children:[(0,Z.jsxs)(`div`,{role:`listitem`,className:`daily-briefing-stat`,children:[(0,Z.jsx)(`strong`,{children:String(u.questions??0)}),(0,Z.jsx)(`span`,{children:G(e,`briefing.stat.questions`)})]}),(0,Z.jsxs)(`div`,{role:`listitem`,className:`daily-briefing-stat`,children:[(0,Z.jsxs)(`strong`,{children:[String(d.enabled??0),`/`,String(d.total??0)]}),(0,Z.jsx)(`span`,{children:G(e,`briefing.stat.automations`)})]}),(0,Z.jsxs)(`div`,{role:`listitem`,className:`daily-briefing-stat`,children:[(0,Z.jsx)(`strong`,{children:String(f.pending??0)}),(0,Z.jsx)(`span`,{children:G(e,`briefing.stat.review`)})]}),(0,Z.jsxs)(`div`,{role:`listitem`,className:`daily-briefing-stat`,children:[(0,Z.jsx)(`strong`,{children:p.available&&p.grade?String(p.grade):`—`}),(0,Z.jsx)(`span`,{children:G(e,`briefing.stat.health`)})]})]}),g.length>0?(0,Z.jsxs)(`div`,{className:`daily-briefing-recent`,children:[(0,Z.jsx)(`p`,{className:`command-palette-group`,children:G(e,`briefing.recent`)}),(0,Z.jsx)(`ul`,{children:g.slice(0,3).map(e=>(0,Z.jsx)(`li`,{title:String(e.title||``),children:String(e.title||e.id||``)},String(e.id)))})]}):null,Number(m.count??0)>0?(0,Z.jsx)(`p`,{className:`brain-care-note`,children:G(e,`briefing.suggestions`,{count:String(m.count)})}):null,h.length>0?(0,Z.jsx)(`div`,{className:`daily-briefing-actions`,children:h.map(t=>{let n=Ut[t.id];return n?(0,Z.jsxs)(`button`,{type:`button`,className:`daily-briefing-action`,onClick:()=>q(t.target),children:[(0,Z.jsx)(`span`,{children:G(e,n,{count:String(t.count||0)})}),(0,Z.jsx)(a,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})]},t.id):null})}):null]})}):null]})}function qt({language:e}){let t=r(),[n,a]=X.useState(!1),o=U({queryKey:[`pendingProposals`],queryFn:J.proposals,enabled:n}),s=async()=>{await Promise.all([t.invalidateQueries({queryKey:[`pendingProposals`]}),t.invalidateQueries({queryKey:[`reviewItems`]})])},[c,l]=X.useState({}),u=i({mutationFn:e=>J.approveReviewItem(e),onSuccess:async(e,t)=>{if(!e.ok&&e.status===409){l(e=>({...e,[t]:!0}));return}e.ok&&(l(e=>{let n={...e};return delete n[t],n}),await s())}}),d=i({mutationFn:e=>J.rejectProposal(e),onSuccess:s}),f=we((o.data?.data||{}).items),p=u.isPending||d.isPending,m=o.isError||(o.data?!o.data.ok:!1);return(0,Z.jsxs)(`section`,{className:`brain-care-panel pending-proposals-panel ${n?`is-expanded`:`is-collapsed`}`,"aria-label":G(e,`proposals.title`),"data-testid":`pending-proposals`,children:[(0,Z.jsxs)(`button`,{className:`brain-care-summary`,type:`button`,"aria-expanded":n,"aria-controls":`pending-proposals-details`,onClick:()=>a(e=>!e),children:[(0,Z.jsxs)(`span`,{className:`brain-care-summary-main`,children:[(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(Ve,{className:`h-3.5 w-3.5`}),` `,G(e,`proposals.title`)]}),(0,Z.jsx)(`strong`,{children:G(e,`proposals.subtitle`)})]}),(0,Z.jsx)(ye,{className:`brain-care-toggle h-4 w-4`,"aria-hidden":`true`})]}),n?(0,Z.jsxs)(`div`,{id:`pending-proposals-details`,className:`brain-care-details`,children:[o.isPending?(0,Z.jsx)(`p`,{className:`brain-care-note`,children:G(e,`proposals.loading`)}):m?(0,Z.jsxs)(`div`,{className:`grid gap-2`,role:`alert`,children:[(0,Z.jsx)(`p`,{className:`brain-care-note`,children:G(e,`proposals.error`)}),o.data?.error?(0,Z.jsx)(`small`,{className:`text-xs text-muted-foreground opacity-75`,children:o.data.error}):null,(0,Z.jsx)(`button`,{type:`button`,className:`daily-briefing-action`,onClick:()=>void o.refetch(),children:(0,Z.jsx)(`span`,{children:G(e,`common.retry`)})})]}):f.length===0?(0,Z.jsx)(`p`,{className:`brain-care-note`,children:G(e,`proposals.empty`)}):(0,Z.jsx)(`div`,{className:`pending-proposals-list`,children:f.map(t=>{let n=t.payload||{},r=we(n.diff),i=String(n.tier||`small`);return(0,Z.jsxs)(`article`,{className:`pending-proposal`,children:[(0,Z.jsxs)(`header`,{children:[(0,Z.jsx)(`strong`,{title:String(n.path||t.title),children:String(n.path||t.title)}),(0,Z.jsx)(`span`,{className:`pending-proposal-tier`,children:G(e,t.kind===`file_delete`?`proposals.kind.delete`:i===`large`?`proposals.tier.large`:`proposals.tier.small`)})]}),(0,Z.jsx)(`p`,{className:`brain-care-note`,children:t.summary}),r.length>0?(0,Z.jsx)(ue,{language:e,diff:r}):null,c[t.id]?(0,Z.jsx)(le,{language:e,itemId:t.id}):null,(0,Z.jsxs)(`div`,{className:`pending-proposal-actions`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`daily-briefing-action`,disabled:p,onClick:()=>u.mutate(t.id),children:[(0,Z.jsx)(be,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{children:G(e,`proposals.approve`)})]}),(0,Z.jsxs)(`button`,{type:`button`,className:`daily-briefing-action pending-proposal-reject`,disabled:p,onClick:()=>d.mutate(t.id),children:[(0,Z.jsx)(ve,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{children:G(e,`proposals.reject`)})]})]})]},t.id)})}),(0,Z.jsx)(`p`,{className:`brain-care-note`,children:G(e,`proposals.note`)})]}):null]})}function Jt({language:e,draft:t,streaming:n,imageData:r,uploadingDocument:i,onDraftChange:a,onImageDataChange:o,onUploadDocument:s,onSend:c,onStop:l,attachments:u}){let d=X.useRef(null),f=X.useRef(null),[p,m]=X.useState(!1),h=X.useId(),g=X.useRef(null),_=X.useRef(0);X.useEffect(()=>{let e=d.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,152)}px`)},[t]);let v=()=>{g.current!==null&&(window.clearTimeout(g.current),g.current=null)},y=()=>{v(),g.current=window.setTimeout(()=>{let e=f.current;e&&(e.contains(document.activeElement)||e.querySelector(`.brain-ingestion-dock-popover`)||i||m(!1))},240)};return X.useEffect(()=>v,[]),X.useEffect(()=>{if(!p)return;let e=e=>{let t=e.target;t&&f.current?.contains(t)||m(!1)};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[p]),(0,Z.jsxs)(`div`,{className:`brain-composer`,"aria-busy":n,children:[(0,Z.jsx)(`textarea`,{ref:d,rows:1,value:t,onChange:e=>a(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),c())},"aria-label":G(e,`brain.placeholder`),"aria-describedby":`brain-composer-hint`,"aria-keyshortcuts":`Control+K Meta+K`,placeholder:G(e,`brain.placeholder`)}),(0,Z.jsx)(`nav`,{className:`brain-composer-can`,"aria-label":G(e,`brain.composer.can.aria`),children:[[`brain.composer.can.search`,`brain.composer.can.search.prompt`],[`brain.composer.can.read`,`brain.composer.can.read.prompt`],[`brain.composer.can.memory`,`brain.composer.can.memory.prompt`],[`brain.composer.can.skill`,`brain.composer.can.skill.prompt`]].map(([t,r])=>(0,Z.jsx)(`button`,{type:`button`,className:`brain-composer-can-chip`,disabled:n,onClick:()=>a(G(e,r)),children:G(e,t)},t))}),(0,Z.jsxs)(`div`,{className:`brain-composer-actions`,children:[(0,Z.jsxs)(`div`,{ref:f,className:`brain-attach ${p?`is-open`:``}`,onPointerEnter:e=>{e.pointerType===`mouse`&&(v(),m(e=>(e||(_.current=Date.now()),!0)))},onPointerLeave:e=>{e.pointerType===`mouse`&&y()},onKeyDown:e=>{e.key!==`Escape`||!p||f.current?.querySelector(`.brain-ingestion-dock-popover`)||(e.preventDefault(),e.stopPropagation(),m(!1))},children:[(0,Z.jsxs)(`button`,{type:`button`,className:`brain-attach-toggle`,"aria-expanded":p,"aria-controls":p?h:void 0,"aria-label":G(e,`brain.composer.attach.aria`),"data-testid":`brain-attach-toggle`,onClick:()=>{m(e=>e?Date.now()-_.current<350:(_.current=Date.now(),!0))},children:[(0,Z.jsx)(Ye,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{children:G(e,`brain.composer.attach`)})]}),p?(0,Z.jsxs)(`div`,{id:h,className:`brain-composer-attachments`,"data-testid":`brain-attach-menu`,role:`group`,"aria-label":G(e,`brain.composer.attachments`),children:[(0,Z.jsxs)(`label`,{className:`brain-document-input ${i?`is-disabled`:``}`,children:[(0,Z.jsx)(Be,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{children:i?G(e,`brain.upload.uploading`):G(e,`brain.upload.ctaShort`)}),(0,Z.jsx)(`input`,{type:`file`,accept:`.pdf,.docx,.xlsx,.pptx,.txt,.md,.csv,application/pdf,text/plain,text/markdown,text/csv`,className:`sr-only`,disabled:i,onChange:e=>{let t=e.target.files?.[0];e.currentTarget.value=``,t&&s(t)}})]}),(0,Z.jsxs)(`label`,{className:`brain-image-input`,children:[(0,Z.jsx)(He,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{children:G(e,`brain.image`)}),(0,Z.jsx)(`input`,{type:`file`,accept:`image/*`,className:`sr-only`,onChange:async e=>{let t=e.target.files?.[0];e.currentTarget.value=``,t&&o(await Yt(t))}})]}),u]}):null,r?(0,Z.jsx)(`span`,{className:`brain-quiet-success`,children:G(e,`brain.imageAttached`)}):null]}),(0,Z.jsx)(`span`,{id:`brain-composer-hint`,className:`brain-composer-hint`,children:G(e,`brain.composer.hint`)}),n&&l?(0,Z.jsxs)(Y,{onClick:l,variant:`outline`,className:`brain-composer-submit`,children:[(0,Z.jsx)(tt,{className:`h-4 w-4`,"aria-hidden":`true`}),` `,G(e,`brain.stop`)]}):(0,Z.jsxs)(Y,{onClick:c,disabled:!t.trim()||n,className:`brain-composer-submit`,children:[(0,Z.jsx)($e,{className:`h-4 w-4`,"aria-hidden":`true`}),` `,G(e,`brain.send`)]})]})]})}function Yt(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result||``)),r.onerror=()=>n(r.error),r.readAsDataURL(e)})}var Xt=Se(),$=[`features`];function Zt({language:e}){let t=r(),[n,a]=X.useState(``),o=U({queryKey:$,queryFn:J.features}),s=i({mutationFn:e=>J.setFeature(e.id,e.value),onMutate:async e=>{await t.cancelQueries({queryKey:$});let n=t.getQueryData($);return t.setQueryData($,t=>en(t,e.id,e.value)),a(``),{previous:n}},onSuccess:(n,r,i)=>{if(n.ok){a(G(e,`brain.features.saved`)),t.invalidateQueries({queryKey:$});return}t.setQueryData($,i?.previous),a(n.error||G(e,`brain.features.failed`))},onError:(n,r,i)=>{t.setQueryData($,i?.previous),a(G(e,`brain.features.failed`))}}),c=o.data?.ok?o.data.data:void 0,l=c?.features??[],u=new Set(l.filter(e=>e.current===!0).map(e=>e.id));return(0,Z.jsxs)(`section`,{className:`brain-features-panel`,"aria-label":G(e,`brain.features.aria`),"aria-busy":s.isPending,children:[(0,Z.jsxs)(`header`,{className:`brain-features-head`,children:[(0,Z.jsx)(`strong`,{children:G(e,`brain.features.title`)}),(0,Z.jsx)(`p`,{children:c?.note||G(e,`brain.features.note`)})]}),o.isLoading?(0,Z.jsx)(`p`,{className:`brain-features-loading`,children:G(e,`ui.loading`)}):null,!o.isLoading&&l.length===0?(0,Z.jsx)(ae,{title:G(e,`brain.features.empty`),detail:o.data?.error}):null,l.length?(0,Z.jsx)(`ul`,{className:`brain-features-list`,children:l.map(t=>(0,Z.jsx)(Qt,{feature:t,language:e,dormant:!!t.parent&&!u.has(String(t.parent)),busy:s.isPending,onChange:e=>s.mutate({id:t.id,value:e})},t.id))}):null,(0,Z.jsx)(`p`,{className:`brain-features-notice`,role:`status`,"aria-live":`polite`,children:n})]})}function Qt({feature:e,language:t,dormant:n,busy:r,onChange:i}){let a=e.current===!0,o=!!e.caution,[s,c]=X.useState(!1),[l,u]=X.useState(!1),d=X.useRef(null);X.useEffect(()=>{a&&(c(!1),u(!1))},[a]);function f(){if(!r){if(a){c(!1),i(!1);return}if(o){c(!0),u(!1);return}i(!0)}}function p(){r||!l||(i(!0),c(!1),u(!1),window.requestAnimationFrame(()=>d.current?.focus()))}return(0,Z.jsxs)(`li`,{className:`brain-feature-row${e.parent?` is-child`:``}${a?` is-on`:``}`,"data-testid":`feature-row-${e.id}`,children:[(0,Z.jsxs)(`div`,{className:`brain-feature-copy`,children:[(0,Z.jsxs)(`span`,{className:`brain-feature-name`,children:[e.label,e.source===`env`?(0,Z.jsx)(`em`,{className:`brain-feature-source`,title:G(t,`brain.features.source.env.detail`,{flag:e.env_var}),children:G(t,`brain.features.source.env`)}):null,n?(0,Z.jsx)(`em`,{className:`brain-feature-source`,children:G(t,`brain.features.dormant`)}):null]}),(0,Z.jsx)(`span`,{className:`brain-feature-summary`,children:e.summary}),e.caution?(0,Z.jsxs)(`span`,{className:`brain-feature-caution`,children:[(0,Z.jsx)(Ue,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),e.caution]}):null,s?(0,Z.jsxs)(`div`,{className:`brain-feature-preview`,"data-testid":`feature-preview-${e.id}`,children:[(0,Z.jsx)(`p`,{className:`brain-feature-preview-title`,children:G(t,`brain.features.preview.title`)}),(0,Z.jsx)(`p`,{className:`brain-feature-preview-body`,children:e.summary}),(0,Z.jsx)(`p`,{className:`brain-feature-preview-caution`,children:e.caution}),(0,Z.jsx)(`p`,{className:`brain-feature-preview-limit`,children:G(t,`brain.features.preview.limit`)}),(0,Z.jsxs)(`label`,{className:`brain-feature-preview-ack`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,"data-testid":`feature-preview-ack-${e.id}`,checked:l,onChange:e=>u(e.target.checked)}),G(t,`brain.features.preview.ack`)]}),(0,Z.jsxs)(`div`,{className:`brain-feature-preview-actions`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`brain-feature-preview-confirm`,"data-testid":`feature-preview-confirm-${e.id}`,"aria-disabled":!l,onClick:p,children:G(t,`brain.features.preview.confirm`)}),(0,Z.jsx)(`button`,{type:`button`,"data-testid":`feature-preview-cancel-${e.id}`,onClick:()=>{c(!1),u(!1)},children:G(t,`brain.features.preview.cancel`)})]})]}):null]}),e.kind===`choice`?(0,Z.jsx)($t,{feature:e,language:t,busy:r,onChange:i}):(0,Z.jsxs)(`button`,{ref:d,type:`button`,role:`switch`,"aria-checked":a,"aria-label":e.label,className:`brain-feature-switch`,"data-testid":`feature-switch-${e.id}`,onClick:f,children:[(0,Z.jsx)(`span`,{className:`brain-feature-switch-track`,"aria-hidden":`true`,children:(0,Z.jsx)(`span`,{className:`brain-feature-switch-thumb`})}),(0,Z.jsx)(`span`,{className:`brain-feature-state`,children:G(t,a?`brain.features.on`:`brain.features.off`)})]})]})}function $t({feature:e,language:t,busy:n,onChange:r}){return(0,Z.jsx)(`div`,{className:`brain-feature-choices`,role:`radiogroup`,"aria-label":e.label,"data-testid":`feature-choices-${e.id}`,children:e.choices.map(i=>(0,Z.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":e.current===i.id,className:e.current===i.id?`is-active`:``,"data-testid":`feature-choice-${e.id}-${i.id}`,disabled:!i.available,title:i.detail||void 0,onClick:()=>{n||r(i.id)},children:[i.label,i.available?null:(0,Z.jsx)(`em`,{children:G(t,`brain.features.installRequired`)})]},i.id))})}function en(e,t,n){let r=e;return!r?.ok||!r.data?e:{...r,data:{...r.data,features:r.data.features.map(e=>e.id===t?{...e,current:n,source:`user`}:e)}}}var tn=[{x:62,y:26},{x:78,y:26},{x:93,y:26},{x:62,y:45},{x:78,y:45},{x:93,y:45},{x:70,y:64},{x:86,y:64}];function nn(e){let t=String(e??``).trim();return!t||/^[A-Za-z][\w-]*[-_]?\d{6,}$/.test(t)||/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(t)||/^\d+$/.test(t)?``:t}var rn=[`chat`,`file`,`folder`,`note`,`web`],an={chat:qe,file:Be,folder:z,note:ze,web:se};function on(e){return!!(e&&e.stage!==`complete`&&e.stage!==`error`)}X.memo(function({language:e,brainState:t,intensity:n,graph:r,readiness:i,brief:o,memories:s,ingestionStates:l,emergenceEvents:u,streaming:d,onExploreBrain:f}){let p=u[0],m=X.useMemo(()=>{let e=new Map;for(let t of r.edges)e.set(t.source,(e.get(t.source)??0)+1),e.set(t.target,(e.get(t.target)??0)+1);let t=new Set(p?.nodeIds??[]);return[...r.nodes].sort((n,r)=>Number(t.has(r.id))-Number(t.has(n.id))||(e.get(r.id)??0)-(e.get(n.id)??0)||r.importance-n.importance).slice(0,tn.length)},[r.edges,r.nodes,p?.nodeIds]),h=X.useMemo(()=>new Map(m.map((e,t)=>[e.id,tn[t]])),[m]),g=X.useMemo(()=>r.edges.filter(e=>h.has(e.source)&&h.has(e.target)).slice(0,16),[r.edges,h]),_=rn.map(e=>l[e]).find(e=>on(e)),v=X.useMemo(()=>new Set(p?.nodeIds??[]),[p]),y=d||!!_,b=d?`chat`:_?.sourceType,x=nn(_?.label)||nn(p?.label)||nn(o.focus.title)||nn(s[0]?.title)||G(e,`brain.flow.source.empty`),S=_?G(e,`brain.ingest.stage.${_.stage}.hint`):p?G(e,`brain.flow.status.emerged`,{memories:p.newMemories,entities:p.newEntities}):m.length?G(e,`brain.flow.status.ready`,{focus:nn(o.focus.title)||nn(m[0]?.label)||`Brain`}):G(e,`brain.flow.status.empty`),C=Math.max(i.signals.memoryCount,s.length),w=Math.max(i.signals.conceptCount,r.nodes.length),T=Math.max(i.signals.relationshipCount,r.edges.length);return(0,Z.jsxs)(`section`,{className:`brain-knowledge-flow ${y?`is-absorbing`:``}`,"data-source":b||`idle`,"data-stage":_?.stage||(p?`connected`:`ready`),"data-brain-state":t,"aria-labelledby":`brain-home-title`,children:[(0,Z.jsxs)(`header`,{className:`brain-flow-heading`,children:[(0,Z.jsxs)(`div`,{className:`brain-flow-heading-copy`,children:[(0,Z.jsx)(`span`,{className:`brain-home-kicker`,children:G(e,`brain.home.kicker`)}),(0,Z.jsx)(`h1`,{id:`brain-home-title`,children:G(e,`brain.firstScreen.title`)}),(0,Z.jsx)(`p`,{children:G(e,`brain.firstScreen.body`)})]}),(0,Z.jsxs)(`div`,{className:`brain-flow-vital`,"data-state":t,children:[(0,Z.jsxs)(`span`,{"aria-hidden":`true`,children:[(0,Z.jsx)(`i`,{}),(0,Z.jsx)(`i`,{})]}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`small`,{children:G(e,`brain.flow.vital`)}),(0,Z.jsx)(`strong`,{children:G(e,`brain.living.state.${t}`)})]})]})]}),(0,Z.jsxs)(`div`,{className:`brain-flow-canvas`,"data-testid":`brain-knowledge-flow`,children:[(0,Z.jsxs)(`div`,{className:`brain-flow-sources`,"aria-label":G(e,`brain.flow.sources.aria`),children:[(0,Z.jsx)(`span`,{className:`brain-flow-column-label`,children:G(e,`brain.flow.sources`)}),rn.map(t=>{let n=an[t],r=l[t],i=t===b,a=r?.stage===`complete`;return(0,Z.jsxs)(`span`,{className:`brain-flow-source ${i?`is-active`:``} ${a?`is-remembered`:``}`,"aria-current":i?`step`:void 0,children:[(0,Z.jsx)(n,{className:`h-4 w-4`,"aria-hidden":`true`}),G(e,`brain.ingest.type.${t}`)]},t)})]}),(0,Z.jsxs)(`svg`,{className:`brain-flow-transfer`,viewBox:`0 0 100 100`,preserveAspectRatio:`none`,"aria-hidden":`true`,children:[(0,Z.jsx)(`path`,{className:`brain-flow-transfer-path`,d:`M20 50 C28 50 31 50 38 50`}),(0,Z.jsx)(`path`,{className:`brain-flow-transfer-path is-output`,d:`M54 50 C59 50 62 50 67 50`}),y?Array.from({length:4}).map((e,t)=>(0,Z.jsx)(`circle`,{className:`brain-flow-particle`,r:`0.8`,style:{animationDelay:`${t*240}ms`},children:(0,Z.jsx)(`animateMotion`,{dur:`1.7s`,repeatCount:`indefinite`,path:`M20 50 C28 50 31 50 43 50`})},t)):null,m.length?Array.from({length:3}).map((e,t)=>(0,Z.jsx)(`circle`,{className:`brain-flow-particle is-output`,r:`0.66`,children:(0,Z.jsx)(`animateMotion`,{begin:`${t*1.15}s`,dur:y?`2.1s`:`4.2s`,repeatCount:`indefinite`,path:`M51 50 C58 46 61 44 70 42`})},`output-${t}`)):null]}),(0,Z.jsxs)(`div`,{className:`brain-flow-organism`,children:[(0,Z.jsx)(`span`,{className:`brain-flow-column-label`,children:G(e,`brain.flow.memory`)}),(0,Z.jsx)(c,{state:t,intensity:y?Math.max(n,.9):n,size:`large`,depth:i.depth,showLabel:!1,onInteract:f}),(0,Z.jsxs)(`span`,{className:`brain-flow-organism-vital`,"aria-hidden":`true`,children:[(0,Z.jsx)(`i`,{}),G(e,`brain.living.state.${t}`)]})]}),(0,Z.jsxs)(`div`,{className:`brain-flow-graph`,"aria-label":G(e,`brain.flow.graph.aria`,{concepts:w,relationships:T}),children:[(0,Z.jsx)(`span`,{className:`brain-flow-column-label`,children:G(e,`brain.flow.graph`)}),(0,Z.jsx)(`svg`,{className:`brain-flow-edges`,viewBox:`0 0 100 100`,preserveAspectRatio:`none`,"aria-hidden":`true`,children:g.map((e,t)=>{let n=h.get(e.source),r=h.get(e.target);return!n||!r?null:(0,Z.jsx)(`line`,{x1:n.x,y1:n.y,x2:r.x,y2:r.y,vectorEffect:`non-scaling-stroke`,style:{animationDelay:`${t*-.72}s`}},e.id)})}),m.length?m.map((t,n)=>{let r=tn[n];return(0,Z.jsxs)(`button`,{type:`button`,className:`brain-flow-node ${v.has(t.id)?`is-emerging`:``}`,style:{left:`${r.x}%`,top:`${r.y}%`},"aria-label":G(e,`brain.flow.node.aria`,{label:t.label,type:t.type}),title:t.summary||t.type,onClick:f,children:[(0,Z.jsx)(`span`,{children:t.type}),(0,Z.jsx)(`strong`,{children:t.label})]},t.id)}):(0,Z.jsxs)(`div`,{className:`brain-flow-empty-graph`,children:[(0,Z.jsx)(V,{className:`h-5 w-5`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{children:G(e,`brain.flow.graph.empty`)})]}),(0,Z.jsx)(`ul`,{className:`sr-only`,children:g.map(e=>{let t=m.find(t=>t.id===e.source),n=m.find(t=>t.id===e.target);return!t||!n?null:(0,Z.jsxs)(`li`,{children:[t.label,` — `,e.label,` — `,n.label]},`accessible-${e.id}`)})})]}),(0,Z.jsxs)(`div`,{className:`brain-flow-live-status`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:[(0,Z.jsx)(`span`,{className:`brain-flow-status-icon`,"aria-hidden":`true`,children:y?(0,Z.jsx)(F,{className:`h-4 w-4`}):(0,Z.jsx)(I,{className:`h-4 w-4`})}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`strong`,{children:x}),(0,Z.jsx)(`small`,{children:S})]})]}),(0,Z.jsxs)(`ol`,{className:`brain-flow-path`,"aria-label":G(e,`brain.flow.path.aria`),children:[(0,Z.jsxs)(`li`,{"data-active":!!b,children:[(0,Z.jsx)(`span`,{children:G(e,`brain.flow.path.input`)}),(0,Z.jsx)(`strong`,{children:b?G(e,`brain.ingest.type.${b}`):G(e,`brain.flow.path.waiting`)})]}),(0,Z.jsx)(a,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,Z.jsxs)(`li`,{"data-active":y,children:[(0,Z.jsx)(`span`,{children:G(e,`brain.flow.path.memory`)}),(0,Z.jsx)(`strong`,{children:G(e,`brain.flow.path.memoryCount`,{count:C})})]}),(0,Z.jsx)(a,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(`span`,{children:G(e,`brain.flow.path.connections`)}),(0,Z.jsx)(`strong`,{children:G(e,`brain.flow.path.graphCount`,{concepts:w,relationships:T})})]}),(0,Z.jsx)(a,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(`span`,{children:G(e,`brain.flow.path.automation`)}),(0,Z.jsx)(`strong`,{children:G(e,`brain.flow.path.actionCount`,{count:o.proactiveActions.length})})]})]})]})]})});function sn({language:e,brief:t,activities:n,streaming:r,onAction:i,compact:o=!1}){let s=X.useRef(null),c=t.proactiveActions.slice(0,3),u=t.evidence.filter(e=>e.value>0).slice(0,3),d=t.focus.title||G(e,`brain.brief.focus.empty`),f=()=>{let e=s.current;e&&(e.removeAttribute(`open`),e.querySelector(`summary`)?.focus())};if(o){let t=c[0];return(0,Z.jsxs)(`section`,{className:`brain-memory-automation is-compact ${c.length>1?`has-more-actions`:c.length===1?`has-single-action`:`has-no-actions`}`,"data-testid":`brain-automation-dock`,"aria-labelledby":`brain-memory-automation-compact-title`,children:[(0,Z.jsxs)(`div`,{className:`brain-automation-compact-head`,children:[(0,Z.jsx)(`span`,{className:`brain-memory-automation-mark`,"aria-hidden":`true`,children:(0,Z.jsx)(l,{className:`h-4 w-4`})}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`small`,{children:G(e,`brain.automation.kicker`)}),(0,Z.jsx)(`strong`,{id:`brain-memory-automation-compact-title`,children:G(e,`brain.automation.title`)})]}),c.length>1?(0,Z.jsxs)(`details`,{ref:s,className:`brain-automation-more`,"data-testid":`brain-automation-more`,onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),f())},children:[(0,Z.jsx)(`summary`,{"aria-label":G(e,`brain.automation.more`),children:(0,Z.jsx)(xe,{className:`h-4 w-4`,"aria-hidden":`true`})}),(0,Z.jsxs)(`div`,{className:`brain-automation-more-popover`,children:[(0,Z.jsxs)(`header`,{className:`brain-automation-more-head`,children:[(0,Z.jsx)(`strong`,{children:G(e,`brain.automation.title`)}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":G(e,`brain.automation.close`),onClick:f,children:(0,Z.jsx)(ve,{className:`h-4 w-4`,"aria-hidden":`true`})})]}),(0,Z.jsx)(`div`,{className:`brain-automation-actions`,children:c.map(t=>(0,Z.jsxs)(`button`,{type:`button`,disabled:r,onClick:()=>i(t),children:[(0,Z.jsx)(`span`,{className:`brain-automation-action-icon`,"aria-hidden":`true`,children:ln(t.intent)}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`strong`,{children:G(e,t.labelKey)}),(0,Z.jsx)(`small`,{children:G(e,t.detailKey)})]}),(0,Z.jsx)(`em`,{children:G(e,un(t.intent))}),(0,Z.jsx)(a,{className:`h-4 w-4`,"aria-hidden":`true`})]},t.id))}),(0,Z.jsxs)(`div`,{className:`brain-automation-guard`,children:[(0,Z.jsx)(Ee,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{children:G(e,`brain.automation.guard`)})]}),n.length?(0,Z.jsx)(`ol`,{className:`brain-automation-activity`,"aria-label":G(e,`brain.proactive.trail.aria`),"aria-live":`polite`,children:n.slice(0,3).map(t=>(0,Z.jsxs)(`li`,{"data-status":t.status,children:[(0,Z.jsx)(I,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),(0,Z.jsx)(`strong`,{children:G(e,t.labelKey)}),(0,Z.jsx)(`span`,{children:G(e,`brain.proactive.status.${t.status}`)})]},t.id))}):null]})]}):null]}),(0,Z.jsx)(`span`,{className:`brain-automation-compact-focus`,title:d,children:d}),t?(0,Z.jsxs)(`button`,{type:`button`,className:`brain-automation-primary-action`,disabled:r,onClick:()=>i(t),children:[(0,Z.jsx)(`span`,{"aria-hidden":`true`,children:ln(t.intent)}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`strong`,{children:G(e,t.labelKey)}),(0,Z.jsx)(`small`,{children:G(e,un(t.intent))})]}),(0,Z.jsx)(a,{className:`h-4 w-4`,"aria-hidden":`true`})]}):(0,Z.jsx)(`p`,{className:`brain-automation-empty`,children:G(e,`brain.automation.empty`)})]})}return(0,Z.jsxs)(`section`,{className:`brain-memory-automation`,"aria-labelledby":`brain-memory-automation-title`,children:[(0,Z.jsxs)(`div`,{className:`brain-memory-automation-head`,children:[(0,Z.jsx)(`div`,{className:`brain-memory-automation-mark`,"aria-hidden":`true`,children:(0,Z.jsx)(l,{className:`h-5 w-5`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{children:G(e,`brain.automation.kicker`)}),(0,Z.jsx)(`h2`,{id:`brain-memory-automation-title`,children:G(e,`brain.automation.title`)}),(0,Z.jsx)(`p`,{children:G(e,`brain.automation.body`)})]})]}),(0,Z.jsxs)(`div`,{className:`brain-automation-grounding`,children:[(0,Z.jsx)(B,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`small`,{children:G(e,`brain.automation.basedOn`)}),(0,Z.jsx)(`strong`,{children:d}),t.focus.empty?null:(0,Z.jsx)(`em`,{children:t.focus.source})]}),u.length?(0,Z.jsx)(`div`,{className:`brain-automation-evidence`,"aria-label":G(e,`brain.brief.evidence.aria`),children:u.map(t=>(0,Z.jsxs)(`span`,{title:G(e,t.detailKey),children:[(0,Z.jsx)(`strong`,{children:t.value}),` `,G(e,t.labelKey)]},t.id))}):null]}),c.length?(0,Z.jsx)(`div`,{className:`brain-automation-actions`,children:c.map(t=>(0,Z.jsxs)(`button`,{type:`button`,disabled:r,onClick:()=>i(t),children:[(0,Z.jsx)(`span`,{className:`brain-automation-action-icon`,"aria-hidden":`true`,children:ln(t.intent)}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`strong`,{children:G(e,t.labelKey)}),(0,Z.jsx)(`small`,{children:G(e,t.detailKey)})]}),(0,Z.jsx)(`em`,{children:G(e,un(t.intent))}),(0,Z.jsx)(a,{className:`h-4 w-4`,"aria-hidden":`true`})]},t.id))}):(0,Z.jsx)(`p`,{className:`brain-automation-empty`,children:G(e,`brain.automation.empty`)}),(0,Z.jsxs)(`div`,{className:`brain-automation-guard`,children:[(0,Z.jsx)(Ee,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{children:G(e,`brain.automation.guard`)})]}),n.length?(0,Z.jsx)(`ol`,{className:`brain-automation-activity`,"aria-label":G(e,`brain.proactive.trail.aria`),"aria-live":`polite`,children:n.slice(0,3).map(t=>(0,Z.jsxs)(`li`,{"data-status":t.status,children:[(0,Z.jsx)(I,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),(0,Z.jsx)(`strong`,{children:G(e,t.labelKey)}),(0,Z.jsx)(`span`,{children:G(e,`brain.proactive.status.${t.status}`)})]},t.id))}):null]})}function cn({language:e,state:t,concepts:n,relationshipCount:r,onExploreBrain:i}){return(0,Z.jsxs)(`div`,{className:`brain-conversation-trace ${on(t)?`is-active`:``}`,role:`status`,"aria-live":`polite`,children:[(0,Z.jsxs)(`span`,{className:`brain-conversation-trace-source`,children:[(0,Z.jsx)(qe,{className:`h-4 w-4`,"aria-hidden":`true`}),G(e,`brain.flow.conversation`)]}),(0,Z.jsx)(a,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),(0,Z.jsxs)(`span`,{className:`brain-conversation-trace-memory`,children:[(0,Z.jsx)(F,{className:`h-4 w-4`,"aria-hidden":`true`}),t?G(e,`brain.ingest.stage.${t.stage}.hint`):G(e,`brain.flow.conversation.ready`)]}),(0,Z.jsx)(a,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),(0,Z.jsxs)(`button`,{type:`button`,onClick:i,children:[(0,Z.jsx)(V,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{children:n.slice(0,3).map(e=>e.label).join(` · `)||G(e,`brain.flow.graph.empty.short`)}),(0,Z.jsx)(`small`,{children:G(e,`brain.flow.relationships`,{count:r})})]})]})}function ln(e){return e===`delegate`?(0,Z.jsx)(l,{className:`h-4 w-4`}):e===`review`?(0,Z.jsx)(Qe,{className:`h-4 w-4`}):e===`route`?(0,Z.jsx)(V,{className:`h-4 w-4`}):(0,Z.jsx)(qe,{className:`h-4 w-4`})}function un(e){return e===`delegate`?`brain.automation.intent.delegate`:e===`review`?`brain.automation.intent.review`:e===`route`?`brain.automation.intent.route`:`brain.automation.intent.ask`}function dn({memories:e,concepts:t,readiness:n,proof:r,onOpenDepth:i}){let a=ke(e=>e.language),o=e.filter(e=>e.agentGenerated).slice(0,3),s=e.filter(e=>!e.agentGenerated),c=s.slice(0,3),l=s.slice(3,6),u=t.slice(0,4),d=r.proofs.hasDurableEvidence||r.modelContinuity.proven,f=r.recall.items.length>0,p=r.modelContinuity.proven&&r.claims.keepsContextAcrossModels?r.modelContinuity.activeModel||G(a,`brain.proof.noModel`):G(a,`brain.proof.modelPending`);return(0,Z.jsxs)(`section`,{className:`brain-overview-panel`,"aria-label":G(a,`brain.aria.overview`),children:[(0,Z.jsxs)(`div`,{className:`brain-overview-head`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{children:G(a,`brain.overview.kicker`)}),(0,Z.jsx)(`strong`,{children:G(a,`brain.overview.title`)})]}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>i(5),children:G(a,`brain.overview.graph`)})]}),(0,Z.jsxs)(`div`,{className:`brain-overview-grid`,children:[(0,Z.jsx)(pn,{title:G(a,`brain.overview.agent`),empty:G(a,`brain.overview.agentEmpty`),items:o.map(e=>e.title),featured:o.length>0,onOpen:()=>i(2)}),(0,Z.jsx)(pn,{title:G(a,`brain.overview.recent`),empty:G(a,`brain.overview.recentEmpty`),items:c.map(e=>e.title),onOpen:()=>i(2)}),(0,Z.jsx)(pn,{title:G(a,`brain.overview.older`),empty:G(a,`brain.overview.olderEmpty`),items:l.map(e=>e.title),onOpen:()=>i(2)}),(0,Z.jsx)(pn,{title:G(a,`brain.overview.topics`),empty:G(a,`brain.overview.topicsEmpty`),items:u.map(e=>e.label),onOpen:()=>i(3)})]}),(0,Z.jsxs)(`div`,{className:`brain-readiness-strip`,"data-state":n.state,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{children:G(a,`brain.readiness.kicker`)}),(0,Z.jsx)(`strong`,{children:G(a,n.titleKey)})]}),(0,Z.jsx)(`div`,{className:`brain-readiness-meter`,"aria-label":G(a,`brain.readiness.aria`),children:(0,Z.jsx)(`i`,{style:{width:`${n.score}%`}})}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>i(n.depth),children:G(a,n.actionKey)})]}),(0,Z.jsxs)(`div`,{className:`brain-proof-strip`,"aria-label":G(a,`brain.proof.aria`),children:[(0,Z.jsx)(fn,{icon:(0,Z.jsx)(Ie,{className:`h-4 w-4`}),label:G(a,`brain.proof.context`),value:d?G(a,`brain.proof.contextValue`,{count:r.proofs.durableItems}):G(a,`brain.proof.contextEmpty`)}),(0,Z.jsx)(fn,{icon:(0,Z.jsx)(Xe,{className:`h-4 w-4`}),label:G(a,`brain.proof.model`),value:p}),(0,Z.jsx)(fn,{icon:(0,Z.jsx)(T,{className:`h-4 w-4`}),label:G(a,`brain.proof.store`),value:G(a,`brain.proof.storeValue`,{topics:r.proofs.graphConcepts,vectors:r.proofs.vectorItems})})]}),f?(0,Z.jsxs)(`button`,{type:`button`,className:`brain-recall-proof`,onClick:()=>i(2),children:[(0,Z.jsx)(`span`,{children:G(a,`brain.proof.recall`)}),(0,Z.jsx)(`strong`,{children:r.recall.items[0].title}),(0,Z.jsx)(`small`,{children:r.recall.items[0].snippet||r.recall.query})]}):(0,Z.jsxs)(`div`,{className:`brain-recall-proof is-empty`,role:`status`,children:[(0,Z.jsx)(`span`,{children:G(a,`brain.proof.recallEmpty.kicker`)}),(0,Z.jsx)(`strong`,{children:G(a,d?`brain.proof.recallPending`:`brain.proof.recallEmpty.title`)}),(0,Z.jsx)(`small`,{children:G(a,d?`brain.proof.recallPending.detail`:`brain.proof.recallEmpty.detail`)})]})]})}function fn({icon:e,label:t,value:n}){return(0,Z.jsxs)(`div`,{className:`brain-proof-point`,children:[e,(0,Z.jsx)(`span`,{children:t}),(0,Z.jsx)(`strong`,{children:n})]})}function pn({title:e,empty:t,items:n,featured:r=!1,onOpen:i}){return(0,Z.jsxs)(`button`,{type:`button`,className:`brain-overview-column${r?` is-featured`:``}`,onClick:i,children:[(0,Z.jsx)(`span`,{children:e}),n.length?n.slice(0,3).map(e=>(0,Z.jsx)(`strong`,{children:e},e)):(0,Z.jsx)(`em`,{children:t})]})}var mn={chat:`brain.ingest.type.chat`,file:`brain.ingest.type.file`,folder:`brain.ingest.type.folder`,note:`brain.ingest.type.note`,web:`brain.ingest.type.web`};function hn({language:e,uploadingDocument:t,ingestionStates:n,onUploadDocument:r,onPickFolder:i,onConnectFolder:a,onIngestNote:o,onIngestWeb:s}){let[c,l]=X.useState(``),[u,d]=X.useState(``),[f,p]=X.useState(``);return(0,Z.jsxs)(`section`,{className:`brain-ingestion-panel`,"aria-label":G(e,`brain.ingest.aria`),children:[(0,Z.jsxs)(`div`,{className:`brain-ingestion-head`,children:[(0,Z.jsx)(`span`,{children:G(e,`brain.ingest.kicker`)}),(0,Z.jsx)(`strong`,{children:G(e,`brain.ingest.title`)})]}),(0,Z.jsxs)(`div`,{className:`brain-ingestion-grid`,children:[(0,Z.jsxs)(`label`,{className:`brain-ingest-tile is-primary ${_n(n.file)} ${t?`is-disabled`:``}`,children:[(0,Z.jsx)(Be,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{children:t?G(e,`brain.upload.uploading`):G(e,`brain.ingest.file`)}),(0,Z.jsx)(`small`,{children:G(e,`brain.ingest.file.detail`)}),(0,Z.jsx)(`input`,{type:`file`,accept:`.pdf,.docx,.xlsx,.pptx,.txt,.md,.csv,application/pdf,text/plain,text/markdown,text/csv`,className:`sr-only`,disabled:t,onChange:e=>{let t=e.target.files?.[0];e.currentTarget.value=``,t&&r(t)}}),(0,Z.jsx)(yn,{language:e,state:n.file,ctaKey:`brain.ingest.cta.file`})]}),(0,Z.jsxs)(`form`,{className:`brain-ingest-tile ${_n(n.folder)}`,onSubmit:e=>{e.preventDefault(),a(c),l(``)},children:[(0,Z.jsx)(R,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{children:G(e,`brain.ingest.folder`)}),(0,Z.jsxs)(`button`,{type:`button`,className:`brain-ingest-folder-picker`,onClick:i,children:[(0,Z.jsx)(z,{className:`h-4 w-4`,"aria-hidden":`true`}),G(e,`capture.local.choose`)]}),(0,Z.jsx)(`input`,{value:c,onChange:e=>l(e.target.value),placeholder:G(e,`brain.ingest.folder.placeholder`)}),(0,Z.jsx)(yn,{language:e,state:n.folder,ctaKey:`brain.ingest.cta.folder`})]}),(0,Z.jsxs)(`form`,{className:`brain-ingest-tile ${_n(n.note)}`,onSubmit:e=>{e.preventDefault(),o(u),d(``)},children:[(0,Z.jsx)(ze,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{children:G(e,`brain.ingest.note`)}),(0,Z.jsx)(`input`,{value:u,onChange:e=>d(e.target.value),placeholder:G(e,`brain.ingest.note.placeholder`)}),(0,Z.jsx)(yn,{language:e,state:n.note,ctaKey:`brain.ingest.cta.note`})]}),(0,Z.jsxs)(`form`,{className:`brain-ingest-tile ${_n(n.web)}`,onSubmit:e=>{e.preventDefault(),s(f),p(``)},children:[(0,Z.jsx)(se,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{children:G(e,`brain.ingest.web`)}),(0,Z.jsx)(`input`,{value:f,onChange:e=>p(e.target.value),placeholder:G(e,`brain.ingest.web.placeholder`)}),(0,Z.jsx)(yn,{language:e,state:n.web,ctaKey:`brain.ingest.cta.web`})]})]})]})}function gn({language:e,uploadingDocument:t,ingestionStates:n,onUploadDocument:r,onPickFolder:i,onConnectFolder:a,onIngestNote:o,onIngestWeb:s,variant:c=`panel`}){let[l,u]=X.useState(null),[d,f]=X.useState(``),[p,m]=X.useState(``),[h,g]=X.useState(``),_=X.useId(),v=e=>{u(t=>t===e?null:e)},y=e=>{if(e===`folder`){if(!d.trim())return;a(d),f(``)}else if(e===`note`){if(!p.trim())return;o(p),m(``)}else{if(!h.trim())return;s(h),g(``)}u(null)};return(0,Z.jsxs)(`section`,{className:`brain-ingestion-dock${c===`inline`?` is-inline`:``}`,"data-testid":`brain-ingestion-dock`,"aria-label":G(e,`brain.ingest.aria`),onKeyDown:e=>{e.key===`Escape`&&u(null)},children:[c===`inline`?null:(0,Z.jsxs)(`div`,{className:`brain-ingestion-dock-head`,children:[(0,Z.jsx)(F,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`small`,{children:G(e,`brain.ingest.kicker`)}),(0,Z.jsx)(`strong`,{children:G(e,`brain.ingest.dock.title`)})]})]}),(0,Z.jsxs)(`div`,{className:`brain-ingestion-dock-actions`,children:[(0,Z.jsxs)(`label`,{className:`brain-ingestion-dock-action ${_n(n.file)} ${t?`is-disabled`:``}`,children:[(0,Z.jsx)(Be,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{children:G(e,`brain.ingest.type.file`)}),(0,Z.jsx)(`i`,{"aria-hidden":`true`}),(0,Z.jsx)(`input`,{type:`file`,accept:`.pdf,.docx,.xlsx,.pptx,.txt,.md,.csv,application/pdf,text/plain,text/markdown,text/csv`,className:`sr-only`,disabled:t,onChange:e=>{let t=e.target.files?.[0];e.currentTarget.value=``,t&&r(t)}})]}),[[`folder`,z],[`note`,ze],[`web`,se]].map(([t,r])=>(0,Z.jsxs)(`button`,{type:`button`,className:`brain-ingestion-dock-action ${_n(n[t])}`,"aria-expanded":l===t,"aria-controls":l===t?_:void 0,onClick:()=>v(t),children:[(0,Z.jsx)(r,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{children:G(e,`brain.ingest.type.${t}`)}),(0,Z.jsx)(`i`,{"aria-hidden":`true`})]},t))]}),l?(0,Z.jsxs)(`div`,{id:_,className:`brain-ingestion-dock-popover`,children:[(0,Z.jsxs)(`header`,{children:[(0,Z.jsx)(`span`,{children:G(e,`brain.ingest.${l}`)}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":G(e,`brain.ingest.dock.close`),onClick:()=>u(null),children:(0,Z.jsx)(ve,{className:`h-4 w-4`,"aria-hidden":`true`})})]}),l===`folder`?(0,Z.jsxs)(`button`,{type:`button`,className:`brain-ingestion-dock-picker`,onClick:i,children:[(0,Z.jsx)(z,{className:`h-4 w-4`,"aria-hidden":`true`}),G(e,`capture.local.choose`)]}):null,(0,Z.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),y(l)},children:[(0,Z.jsx)(`input`,{autoFocus:!0,value:l===`folder`?d:l===`note`?p:h,onChange:e=>{l===`folder`?f(e.target.value):l===`note`?m(e.target.value):g(e.target.value)},placeholder:G(e,`brain.ingest.${l}.placeholder`),"aria-label":G(e,`brain.ingest.${l}.placeholder`)}),(0,Z.jsx)(`button`,{type:`submit`,"aria-label":G(e,`brain.action.add`),children:(0,Z.jsx)(Me,{className:`h-4 w-4`,"aria-hidden":`true`})})]}),(0,Z.jsx)(yn,{language:e,state:n[l],ctaKey:`brain.ingest.cta.${l}`})]}):null]})}function _n(e){return e?e.stage===`error`?`is-failed`:e.stage===`complete`?`is-emerged`:`is-ingesting`:``}var vn={preparing:`brain.ingest.stage.preparing.hint`,parsing:`brain.ingest.stage.parsing.hint`,embedding:`brain.ingest.stage.embedding.hint`,indexing:`brain.ingest.stage.indexing.hint`,complete:`brain.ingest.stage.complete.hint`,error:`brain.ingest.stage.error`};function yn({language:e,state:t,ctaKey:n}){if(!t)return(0,Z.jsx)(`small`,{className:`brain-ingest-cta`,children:G(e,n)});let r=t.stage===`error`,i=t.stage===`complete`,a=t.newMemories>0||t.newEntities>0;return(0,Z.jsxs)(`div`,{className:`brain-ingest-progress`,role:`status`,"aria-live":`polite`,"aria-label":G(e,`brain.ingest.progress.aria`,{label:t.label}),children:[(0,Z.jsx)(`div`,{className:`brain-ingest-stage-badges`,"aria-hidden":`true`,children:(0,Z.jsxs)(`span`,{className:`brain-ingest-stage-badge ${r?`is-failed`:i?`is-done`:`is-active`}`,children:[!r&&!i?(0,Z.jsx)(ie,{className:`h-3 w-3 brain-ingest-spin`}):null,G(e,`brain.ingest.stage.${t.stage}`)]})}),(0,Z.jsx)(`small`,{className:`brain-ingest-stage-hint ${r?`is-failed`:i?`is-emerged`:``}`,children:r?G(e,`brain.ingest.stage.error`):i?a?G(e,`brain.ingest.result`,{memories:t.newMemories,entities:t.newEntities}):G(e,`brain.ingest.result.empty`):G(e,vn[t.stage])}),i&&a?(0,Z.jsxs)(`span`,{className:`lattice-inflow`,"aria-hidden":`true`,children:[(0,Z.jsx)(`i`,{}),(0,Z.jsx)(`i`,{}),(0,Z.jsx)(`i`,{})]}):null,i?(0,Z.jsx)(bn,{language:e,state:t}):null]})}function bn({language:e,state:t}){let n=t.extraction;if(!n||n.level!==`low`)return null;let r=n.warnings.slice(0,3);return(0,Z.jsxs)(`div`,{className:`brain-ingest-quality-note`,role:`note`,"data-testid":`extraction-quality-note`,children:[(0,Z.jsx)(`p`,{children:G(e,`brain.ingest.quality.low`)}),r.length?(0,Z.jsx)(`ul`,{children:r.map(e=>(0,Z.jsx)(`li`,{children:e},e))}):null]})}function xn(e,t,n){let r=Math.floor((n-t)/6e4);return r<1?G(e,`brain.timeline.justNow`):G(e,`brain.timeline.minutesAgo`,{count:r})}function Sn({language:e,emergenceEvents:t}){let n=Date.now();return(0,Z.jsxs)(`section`,{className:`brain-emergence-timeline`,"aria-label":G(e,`brain.timeline.aria`),"aria-live":`polite`,children:[(0,Z.jsxs)(`div`,{className:`brain-emergence-head`,children:[(0,Z.jsx)(F,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(`strong`,{children:G(e,`brain.timeline.emergenceTitle`)}),(0,Z.jsx)(`span`,{children:G(e,`brain.timeline.recent`)})]}),t.length===0?(0,Z.jsx)(`p`,{className:`brain-emergence-empty`,children:G(e,`brain.timeline.empty`)}):(0,Z.jsx)(`ol`,{className:`brain-emergence-list`,children:t.map(t=>(0,Z.jsxs)(`li`,{className:`brain-emergence-item`,children:[(0,Z.jsx)(`span`,{className:`brain-emergence-type`,children:G(e,mn[t.sourceType])}),(0,Z.jsx)(`span`,{className:`brain-emergence-label`,children:t.label}),(0,Z.jsxs)(`span`,{className:`brain-emergence-counts`,children:[(0,Z.jsx)(`strong`,{children:G(e,`brain.timeline.newMemories`,{count:t.newMemories})}),(0,Z.jsx)(`strong`,{children:G(e,`brain.timeline.newEntities`,{count:t.newEntities})})]}),(0,Z.jsx)(`time`,{className:`brain-emergence-at`,children:xn(e,t.at,n)})]},t.id))})]})}function Cn({language:e,brainState:t,intensity:n,readiness:r,memories:i,concepts:a,relationshipCount:o,onExploreBrain:s,onOpenDepth:l}){let[u,d]=X.useState(null),f=X.useMemo(()=>{let e=i.filter(e=>e.kind===`Conversation`),t=i.filter(e=>e.kind!==`Conversation`).sort((e,t)=>Number(t.agentGenerated)-Number(e.agentGenerated));return[{id:`now`,depth:1,labelKey:`brain.rings.1`,emptyKey:`brain.rings.empty.now`,position:`top`,count:e.length,items:e.slice(0,3).map(e=>e.title)},{id:`memories`,depth:2,labelKey:`brain.rings.2`,emptyKey:`brain.rings.empty.memories`,position:`left`,count:t.length,items:t.slice(0,3).map(e=>e.title)},{id:`topics`,depth:3,labelKey:`brain.rings.3`,emptyKey:`brain.rings.empty.topics`,position:`bottom`,count:a.length,items:a.slice(0,3).map(e=>e.label)},{id:`graph`,depth:5,labelKey:`brain.rings.5`,emptyKey:`brain.rings.empty.graph`,position:`right`,count:o,items:[]}]},[i,a,o]);X.useEffect(()=>{if(u===null)return;let e=e=>{e.key===`Escape`&&d(null)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u]);let p=f.find(e=>e.id===u)??null;return(0,Z.jsxs)(`div`,{className:`brain-rings`,"aria-label":G(e,`brain.rings.aria`),children:[(0,Z.jsxs)(`div`,{className:`brain-concentric-container`,children:[(0,Z.jsx)(`div`,{className:`brain-orbit-field`,"aria-hidden":`true`,children:f.map((e,t)=>(0,Z.jsx)(`div`,{className:`brain-concentric-ring ring-${t+1} ${e.count>0?`is-populated`:`is-dormant`}`},e.id))}),f.map(t=>(0,Z.jsxs)(`button`,{type:`button`,className:`ring-label ring-label-${t.position} ${t.count>0?`is-populated`:``} ${u===t.id?`is-active`:``}`,"aria-expanded":u===t.id,"aria-controls":`brain-ring-peek`,"aria-label":G(e,`brain.rings.peek.aria`,{label:G(e,t.labelKey),count:t.count}),onClick:()=>d(e=>e===t.id?null:t.id),children:[G(e,t.labelKey),(0,Z.jsx)(`em`,{children:t.count})]},t.id)),(0,Z.jsx)(`div`,{className:`brain-center-orb`,children:(0,Z.jsx)(c,{state:t,intensity:n,size:`large`,depth:r.depth||Math.max(1,Math.floor(r.score/20)),showLabel:!1,className:`brain-home-presence`,onInteract:s})})]}),p?(0,Z.jsxs)(`section`,{id:`brain-ring-peek`,className:`brain-ring-peek`,"aria-label":G(e,`brain.rings.peek.title`,{label:G(e,p.labelKey)}),children:[(0,Z.jsxs)(`header`,{children:[(0,Z.jsx)(`strong`,{children:G(e,p.labelKey)}),(0,Z.jsx)(`span`,{children:G(e,`brain.rings.count`,{count:p.count})}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>d(null),"aria-label":G(e,`brain.rings.close`),children:`×`})]}),p.items.length?(0,Z.jsx)(`ul`,{children:p.items.map(e=>(0,Z.jsx)(`li`,{children:e},e))}):(0,Z.jsx)(`p`,{children:G(e,p.count>0?`brain.rings.peek.summary`:p.emptyKey,{count:p.count})}),(0,Z.jsx)(`button`,{type:`button`,className:`brain-ring-peek-deeper`,onClick:()=>l(p.depth),children:G(e,`brain.rings.deeper`)})]}):null]})}function wn({language:e}){let t=G(e,`brain.noModel.banner`);return(0,Z.jsxs)(`div`,{className:`brain-model-missing`,role:`note`,"aria-label":t,title:t,children:[(0,Z.jsx)(oe,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`brain-model-missing-text`,children:G(e,`brain.noModel.pill`)}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>q(`/models`),children:[G(e,`brain.noModel.cta`),(0,Z.jsx)(a,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})]})]})}function Tn(e,t){if(!t)return``;let n=e===`ko`?`ko-KR`:`en-US`,r=new Date(t),i=new Date;return r.getFullYear()===i.getFullYear()&&r.getMonth()===i.getMonth()&&r.getDate()===i.getDate()?r.toLocaleTimeString(n,{hour:`2-digit`,minute:`2-digit`}):r.toLocaleDateString(n,{month:`short`,day:`numeric`})}var En=5,Dn=20;function On({language:e,items:t,busyId:n,onResume:r,onDelete:i}){let[a,o]=X.useState(null),[s,c]=X.useState(!1),l=t.slice(0,s?Dn:En),u=Math.min(t.length,Dn)-En;return l.length?(0,Z.jsxs)(`section`,{className:`brain-history-panel`,"aria-label":G(e,`brain.history.aria`),children:[(0,Z.jsxs)(`div`,{className:`brain-history-head`,children:[(0,Z.jsx)(Te,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,Z.jsx)(`strong`,{children:G(e,`brain.history.title`)}),(0,Z.jsx)(`span`,{children:G(e,`brain.history.hint`)})]}),(0,Z.jsx)(`ul`,{className:`brain-history-list`,children:l.map(t=>{let s=n===t.id,c=a===t.id;return(0,Z.jsxs)(`li`,{className:`brain-history-item${s?` is-busy`:``}`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`brain-history-resume`,disabled:s,"aria-label":G(e,`brain.history.resumeAria`,{title:t.title}),onClick:()=>r(t.id),children:[s?(0,Z.jsx)(ie,{className:`h-3.5 w-3.5 brain-ingest-spin`,"aria-hidden":`true`}):null,(0,Z.jsx)(`span`,{className:`brain-history-title`,children:t.title}),(0,Z.jsxs)(`small`,{children:[G(e,`brain.history.messages`,{count:t.messageCount}),t.updatedAt?` · ${Tn(e,t.updatedAt)}`:``]})]}),(0,Z.jsxs)(`button`,{type:`button`,className:`brain-history-delete${c?` is-confirming`:``}`,disabled:s,"aria-label":c?G(e,`brain.history.deleteConfirm`):G(e,`brain.history.deleteAria`,{title:t.title}),onClick:()=>{c?(o(null),i(t.id)):o(t.id)},onBlur:()=>o(e=>e===t.id?null:e),children:[(0,Z.jsx)(nt,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),c?(0,Z.jsx)(`span`,{children:G(e,`brain.history.deleteConfirm`)}):null]})]},t.id)})}),u>0?(0,Z.jsx)(`button`,{type:`button`,className:`brain-history-more`,"aria-expanded":s,onClick:()=>c(e=>!e),children:s?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Pe,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),G(e,`brain.history.showLess`)]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(ye,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),G(e,`brain.history.showMore`,{count:u})]})}):null]}):null}function kn(e,t){if(e.id===`ask_brain`){Ce();return}if(e.id===`verify_model`){t();return}e.route&&q(e.route)}function An({language:e,brief:t,showEvidence:n=!0,onAction:r}){let i=t.focus.title||G(e,`brain.brief.focus.empty`),a=t.focus.detail||G(e,`brain.brief.focus.empty.detail`),o=t.nextActions.slice(0,3);return(0,Z.jsxs)(`section`,{className:`brain-brief-panel`,"aria-label":G(e,`brain.brief.aria`),children:[(0,Z.jsxs)(`div`,{className:`brain-brief-copy`,children:[(0,Z.jsx)(`span`,{children:G(e,`brain.brief.kicker`)}),(0,Z.jsx)(`strong`,{children:G(e,t.headlineKey)}),(0,Z.jsx)(`p`,{children:G(e,t.bodyKey,{focus:i})})]}),(0,Z.jsxs)(`div`,{className:`brain-brief-focus`,children:[(0,Z.jsx)(F,{className:`h-4 w-4`}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{children:G(e,`brain.brief.focus`)}),(0,Z.jsx)(`strong`,{children:i}),(0,Z.jsx)(`small`,{children:a})]})]}),n?(0,Z.jsx)(`div`,{className:`brain-brief-evidence`,"aria-label":G(e,`brain.brief.evidence.aria`),children:t.evidence.slice(0,3).map(t=>(0,Z.jsxs)(`span`,{title:G(e,t.detailKey),children:[(0,Z.jsx)(`strong`,{children:t.value}),G(e,t.labelKey)]},t.id))}):null,o.length?(0,Z.jsx)(`div`,{className:`brain-brief-actions`,"aria-label":G(e,`brain.brief.actions`),children:o.map(t=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>r(t),children:[jn(t.id),(0,Z.jsx)(`span`,{children:G(e,t.labelKey)}),(0,Z.jsx)(`small`,{children:G(e,t.detailKey)})]},t.id))}):null]})}function jn(e){return e===`add_source`?(0,Z.jsx)(Be,{className:`h-4 w-4`}):e===`inspect_topics`?(0,Z.jsx)(pe,{className:`h-4 w-4`}):e===`verify_model`?(0,Z.jsx)(Xe,{className:`h-4 w-4`}):e===`backup_brain`?(0,Z.jsx)(ce,{className:`h-4 w-4`}):(0,Z.jsx)(a,{className:`h-4 w-4`})}function Mn({language:e,proof:t,modelName:n,onVerify:r}){return(0,Z.jsxs)(`section`,{className:`brain-model-demo`,"aria-label":G(e,`brain.modelDemo.aria`),children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{children:G(e,`brain.modelDemo.kicker`)}),(0,Z.jsx)(`strong`,{children:t.modelContinuity.proven?G(e,`brain.modelDemo.proven`):G(e,`brain.modelDemo.pending`)}),(0,Z.jsx)(`small`,{children:G(e,`brain.modelDemo.detail`,{model:t.modelContinuity.activeModel||n})})]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:r,children:[(0,Z.jsx)(Xe,{className:`h-3.5 w-3.5`}),G(e,`brain.modelDemo.verify`)]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>q(`/models`),children:[(0,Z.jsx)(oe,{className:`h-3.5 w-3.5`}),G(e,`brain.modelDemo.change`)]})]})}var Nn={conversations:`brain.dock.tab.conversations`,stats:`brain.dock.tab.stats`,map:`brain.dock.tab.map`,features:`brain.dock.tab.features`},Pn={conversations:Te,stats:Ne,map:V,features:et};function Fn({language:e,brainState:t,intensity:n,readiness:r,memories:i,concepts:a,relationshipCount:o,emergenceEvents:s,proactiveActivities:c,pastConversations:l,historyBusyId:u,streaming:d,modelName:f,proof:p,brief:m,onOpenDepth:h,onExploreBrain:g,onVerifyModelContinuity:v,onProactiveAction:y,onResumeConversation:b,onDeleteConversation:x,onRequestDetails:S}){let C=ke(e=>e.mode)===`basic`,[w,T]=X.useState(null),E=w!==null,D=ge(()=>{let e=document.getElementById(`brain-ring-peek`);if(e){e.querySelector(`header button`)?.click();return}T(null)},E),O=e=>{e!==`conversations`&&e!==`features`&&S(),T(t=>t===e&&E?null:e)},k=[`conversations`,`stats`,`map`,`features`];return(0,Z.jsxs)(`div`,{className:`brain-home-dock`,"data-testid":`brain-home-dock`,children:[(0,Z.jsx)(`div`,{className:`brain-home-dock-rail`,role:`group`,"aria-label":G(e,`brain.dock.aria`),children:k.map(t=>{let n=Pn[t];return(0,Z.jsxs)(`button`,{type:`button`,className:t===`conversations`?`is-continuity`:void 0,"data-testid":`brain-dock-${t}`,"aria-expanded":E&&w===t,onClick:()=>O(t),children:[(0,Z.jsx)(n,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{children:G(e,Nn[t])}),t===`conversations`&&l.length?(0,Z.jsx)(`small`,{className:`brain-dock-count`,children:l.length}):null]},t)})}),E?(0,Xt.createPortal)((0,Z.jsxs)(`div`,{className:`brain-home-dock-layer`,children:[(0,Z.jsx)(`div`,{className:`brain-home-dock-scrim`,"aria-hidden":`true`,onClick:()=>T(null)}),(0,Z.jsxs)(`aside`,{ref:D,className:`brain-home-drawer`,role:`dialog`,"aria-modal":`true`,"aria-label":G(e,`brain.dock.drawerAria`),"data-testid":`brain-home-drawer`,children:[(0,Z.jsxs)(`header`,{className:`brain-home-drawer-head`,children:[(0,Z.jsx)(`div`,{className:`brain-home-drawer-tabs`,role:`group`,"aria-label":G(e,`brain.dock.aria`),children:k.map(t=>(0,Z.jsx)(`button`,{type:`button`,"aria-pressed":w===t,className:w===t?`is-active`:``,"data-testid":`brain-drawer-tab-${t}`,onClick:()=>O(t),children:G(e,Nn[t])},t))}),(0,Z.jsx)(`button`,{type:`button`,className:`brain-home-drawer-close`,"aria-label":G(e,`brain.home.shelf.close`),onClick:()=>T(null),children:(0,Z.jsx)(ve,{className:`h-4 w-4`,"aria-hidden":`true`})})]}),(0,Z.jsxs)(`div`,{className:`brain-home-drawer-body`,children:[w===`conversations`?(0,Z.jsx)(On,{language:e,items:l,busyId:u,onResume:b,onDelete:x}):null,w===`stats`?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(sn,{language:e,brief:m,activities:c,streaming:d,onAction:y}),(0,Z.jsx)(An,{language:e,brief:m,showEvidence:!C,onAction:e=>kn(e,v)}),C?null:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Sn,{language:e,emergenceEvents:s}),(0,Z.jsx)(Mn,{language:e,proof:p,modelName:f,onVerify:v}),(0,Z.jsx)(dn,{memories:i,concepts:a,readiness:r,proof:p,onOpenDepth:h})]}),(0,Z.jsx)(Kt,{language:e,variant:`home`}),(0,Z.jsx)(_,{language:e}),(0,Z.jsx)(te,{language:e}),(0,Z.jsx)(qt,{language:e}),(0,Z.jsx)(Lt,{language:e}),(0,Z.jsx)(Dt,{language:e})]}):null,w===`map`?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Cn,{language:e,brainState:t,intensity:n,readiness:r,memories:i,concepts:a,relationshipCount:o,onExploreBrain:g,onOpenDepth:h}),(0,Z.jsx)(Ht,{language:e}),(0,Z.jsxs)(`button`,{type:`button`,className:`brain-home-drawer-map-cta`,onClick:g,children:[(0,Z.jsx)(V,{className:`h-4 w-4`,"aria-hidden":`true`}),G(e,`brain.hero.stats.mapCta`)]})]}):null,w===`features`?(0,Z.jsx)(Zt,{language:e}):null]})]})]}),document.body):null]})}var In=X.memo(function({language:e,brainState:t,intensity:n,readiness:r,memories:i,graph:a,relationshipCount:o,onExploreBrain:s,trailing:l}){let u=Math.max(r.signals.memoryCount,i.length),d=Math.max(r.signals.conceptCount,a.nodes.length),f=u===0&&d===0;return(0,Z.jsxs)(`section`,{className:`brain-hero`,"data-testid":`brain-knowledge-flow`,"aria-labelledby":`brain-home-title`,children:[(0,Z.jsxs)(`div`,{className:`brain-hero-organism`,"data-growth":r.state,"data-testid":`brain-hero-organism`,children:[(0,Z.jsx)(`i`,{className:`brain-growth-ring is-inner`,"aria-hidden":`true`}),(0,Z.jsx)(`i`,{className:`brain-growth-ring is-mid`,"aria-hidden":`true`}),(0,Z.jsx)(`i`,{className:`brain-growth-ring is-outer`,"aria-hidden":`true`}),(0,Z.jsx)(`div`,{className:`brain-hero-orb`,children:(0,Z.jsx)(c,{state:t,intensity:n,size:`normal`,depth:r.depth,showLabel:!1,onInteract:s})})]}),(0,Z.jsx)(`p`,{className:`brain-hero-growing`,children:G(e,`brain.home.growing`)}),(0,Z.jsxs)(`div`,{className:`brain-hero-header-text`,children:[(0,Z.jsx)(`h1`,{id:`brain-home-title`,children:G(e,`brain.home.askTitle`)}),f?(0,Z.jsx)(`p`,{className:`brain-hero-line`,children:G(e,`brain.hero.empty`)}):(0,Z.jsxs)(`p`,{className:`brain-hero-line`,children:[G(e,`brain.hero.line`),(0,Z.jsx)(Ln,{language:e,memories:u,concepts:d,relationships:o,onExploreBrain:s})]})]}),l?(0,Z.jsx)(`div`,{className:`brain-hero-trailing`,children:l}):null]})});function Ln({language:e,memories:t,concepts:n,relationships:r,onExploreBrain:i}){let[a,o]=X.useState(!1),s=X.useRef(null),c=X.useRef(null),l=X.useId(),u=X.useRef(0),d=()=>{c.current!==null&&(window.clearTimeout(c.current),c.current=null)},f=()=>{d(),c.current=window.setTimeout(()=>o(!1),160)};X.useEffect(()=>{if(!a)return;let e=e=>{let t=e.target;t&&s.current?.contains(t)||o(!1)};return document.addEventListener(`pointerdown`,e,!0),document.addEventListener(`focusin`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0),document.removeEventListener(`focusin`,e,!0)}},[a]),X.useEffect(()=>d,[]);let p=[{key:`memories`,label:G(e,`brain.hero.stats.memories`),value:t,tone:`is-memory`},{key:`concepts`,label:G(e,`brain.hero.stats.concepts`),value:n,tone:`is-knowledge`},{key:`relationships`,label:G(e,`brain.hero.stats.relationships`),value:r,tone:`is-core`}],m=Math.max(1,...p.map(e=>e.value));return(0,Z.jsxs)(`span`,{ref:s,className:`brain-hero-stats`,"data-testid":`brain-hero-stats`,onPointerEnter:e=>{e.pointerType===`mouse`&&(d(),o(e=>(e||(u.current=Date.now()),!0)))},onPointerLeave:e=>{e.pointerType===`mouse`&&f()},onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),o(!1))},children:[(0,Z.jsxs)(`button`,{type:`button`,className:`brain-hero-stats-badge`,"aria-expanded":a,"aria-controls":a?l:void 0,"aria-label":G(e,`brain.hero.stats.aria`,{memories:t,concepts:n}),onClick:()=>{o(e=>e?Date.now()-u.current<350:(u.current=Date.now(),!0))},children:[(0,Z.jsxs)(`span`,{className:`brain-hero-stat`,children:[G(e,`brain.hero.stats.memories`),` `,(0,Z.jsx)(`strong`,{children:t})]}),(0,Z.jsx)(`i`,{"aria-hidden":`true`}),(0,Z.jsxs)(`span`,{className:`brain-hero-stat`,children:[G(e,`brain.hero.stats.concepts`),` `,(0,Z.jsx)(`strong`,{children:n})]})]}),a?(0,Z.jsxs)(`span`,{id:l,className:`brain-hero-stats-popover`,role:`group`,"aria-label":G(e,`brain.hero.stats.popoverAria`),"data-testid":`brain-hero-stats-popover`,children:[(0,Z.jsx)(`strong`,{className:`brain-hero-stats-title`,children:G(e,`brain.hero.stats.title`)}),(0,Z.jsx)(`span`,{className:`brain-hero-stats-graph`,"aria-hidden":`true`,children:p.map(e=>(0,Z.jsxs)(`span`,{className:`brain-hero-stats-row`,children:[(0,Z.jsx)(`span`,{className:`brain-hero-stats-label`,children:e.label}),(0,Z.jsx)(`span`,{className:`brain-hero-stats-track`,children:(0,Z.jsx)(`span`,{className:`brain-hero-stats-fill ${e.tone}`,style:{width:`${Math.max(6,Math.round(e.value/m*100))}%`}})}),(0,Z.jsx)(`span`,{className:`brain-hero-stats-value`,children:e.value})]},e.key))}),(0,Z.jsx)(`span`,{className:`brain-hero-stats-hint`,children:G(e,`brain.hero.hint`)}),(0,Z.jsxs)(`button`,{type:`button`,className:`brain-hero-stats-cta`,onClick:i,children:[(0,Z.jsx)(Ge,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),G(e,`brain.hero.stats.mapCta`)]})]}):null]})}var Rn={low:`is-low`,medium:`is-medium`,high:`is-high`};function zn({language:e}){let t=r(),[n,a]=X.useState(null),o=U({queryKey:[`permissionMode`],queryFn:J.permissionMode}),s=i({mutationFn:e=>J.setPermissionMode(e.mode,e.ack),onSuccess:e=>{e.ok&&(t.invalidateQueries({queryKey:[`permissionMode`]}),a(null))}}),c=o.data?.ok?o.data.data:void 0,l=c?.catalog??[],u=c?.mode??``,d=l.find(e=>e.id===n);function f(e){if(e.id!==u){if(e.requires_ack){a(e.id);return}a(null),s.mutate({mode:e.id,ack:!1})}}return(0,Z.jsxs)(`div`,{className:`brain-quick-controls`,"data-testid":`brain-quick-controls`,children:[l.length?(0,Z.jsxs)(`div`,{className:`brain-quick-dial`,role:`radiogroup`,"aria-label":G(e,`system.permission.title`),children:[(0,Z.jsx)(`span`,{className:`brain-quick-label`,children:G(e,`system.permission.title`)}),(0,Z.jsx)(`div`,{className:`brain-quick-segments`,children:l.map(t=>(0,Z.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":t.id===u,className:t.id===u?`is-active`:``,"data-testid":`quick-mode-${t.id}`,title:fe(t,e),disabled:s.isPending,onClick:()=>f(t),children:[(0,Z.jsx)(`i`,{className:`brain-quick-dot ${Rn[t.risk]||`is-medium`}`,"aria-hidden":`true`}),H(t,e)]},t.id))})]}):null,d?(0,Z.jsxs)(`div`,{className:`brain-quick-confirm`,role:`alertdialog`,"data-testid":`quick-mode-confirm`,children:[(0,Z.jsx)(me,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,Z.jsx)(`p`,{children:de(d,e)}),(0,Z.jsx)(`button`,{type:`button`,className:`is-primary`,"data-testid":`quick-mode-confirm-apply`,disabled:s.isPending,onClick:()=>s.mutate({mode:d.id,ack:!0}),children:H(d,e)}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>a(null),children:G(e,`ui.cancel`)})]}):null,s.data&&!s.data.ok?(0,Z.jsx)(`p`,{className:`brain-quick-error`,role:`status`,children:s.data.error||G(e,`ui.requestUnavailable`)}):null]})}function Bn({language:e,cloudAnswer:t}){let n=t.model?G(e,`brain.cloud.chip.model`,{model:t.model}):G(e,`brain.cloud.chip`),r=t.expansion?.stagedForReview&&t.expansion.candidateCount>0?G(e,`brain.cloud.detail`,{nodes:t.sentNodeCount,proposals:t.expansion.candidateCount}):G(e,`brain.cloud.detail.nodes`,{nodes:t.sentNodeCount});return(0,Z.jsxs)(`details`,{className:`brain-cloud-answer`,"data-testid":`cloud-answer-chip`,children:[(0,Z.jsxs)(`summary`,{className:`brain-cloud-answer-chip`,"aria-label":G(e,`brain.cloud.chip.expandAria`),children:[(0,Z.jsx)(`span`,{"aria-hidden":`true`,children:n}),(0,Z.jsx)(`span`,{className:`sr-only`,children:G(e,`brain.cloud.chip.aria`)})]}),(0,Z.jsx)(`p`,{className:`brain-cloud-answer-detail`,children:r})]})}function Vn(e=0){let t=document.getElementById(`network-boundary-panel`);if(t){t.scrollIntoView({behavior:`smooth`,block:`start`});return}e<8&&window.setTimeout(()=>Vn(e+1),50)}function Hn(){q(`/settings`),Vn()}function Un({language:e}){let t=K(e=>e.preferLocalOnly),n=K(e=>e.setPreferLocalOnly),r=U({queryKey:[`networkBoundary`],queryFn:J.networkBoundary});return r.data?.ok&&r.data.data.allows_cloud?(0,Z.jsxs)(`div`,{className:`brain-cloud-hint`,"data-testid":`cloud-boundary-hint`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`brain-cloud-hint-link`,"data-testid":`cloud-boundary-allowed`,"aria-label":G(e,`brain.cloud.allowed.aria`),onClick:Hn,children:G(e,`brain.cloud.allowed`)}),(0,Z.jsxs)(`label`,{className:`brain-cloud-hint-toggle`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,"data-testid":`cloud-local-only-toggle`,checked:t,onChange:e=>n(e.target.checked),"aria-label":G(e,`brain.cloud.localOnly.aria`)}),G(e,`brain.cloud.localOnly`)]})]}):null}var Wn=new Set([`html`,`htm`,`md`,`markdown`,`txt`,`json`,`css`,`js`,`csv`,`py`,`yaml`,`yml`,`xml`,`sql`,`sh`]);function Gn(e){let t=e.lastIndexOf(`.`);return t>=0?e.slice(t+1).toLowerCase():``}function Kn(e){return typeof e.previewable==`boolean`?e.previewable:Wn.has(Gn(e.filename))}function qn(e){let t=Gn(e);return t===`html`||t===`htm`?`html`:t===`md`||t===`markdown`?`markdown`:t===`json`?`json`:`text`}var Jn=`<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:;">`;function Yn(e){return/<head[^>]*>/i.test(e)?e.replace(/<head[^>]*>/i,e=>`${e}${Jn}`):`${Jn}${e}`}function Xn(e){try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function Zn({language:e,file:t,onClose:n}){let r=ge(n),[i,a]=X.useState({status:`loading`}),[o,s]=X.useState(!1),c=qn(t.filename);X.useEffect(()=>{let e=!1;return J.readWorkspaceFile(t.path).then(t=>{e||(t.ok?a({status:`ready`,content:t.data.content}):a({status:`error`,reason:t.error||String(t.status||``)}))}),()=>{e=!0}},[t.path]);async function l(){o||(s(!0),await J.downloadWorkspaceFile(t.path,t.filename),s(!1))}return(0,Z.jsx)(`div`,{className:`file-preview-backdrop`,role:`presentation`,onMouseDown:e=>{e.target===e.currentTarget&&n()},children:(0,Z.jsxs)(`div`,{ref:r,className:`file-preview-modal`,role:`dialog`,"aria-modal":`true`,"aria-label":G(e,`brain.preview.aria`,{name:t.filename}),"data-testid":`file-preview-modal`,children:[(0,Z.jsxs)(`header`,{className:`file-preview-head`,children:[(0,Z.jsx)(`strong`,{className:`file-preview-name`,children:t.filename}),(0,Z.jsxs)(`div`,{className:`file-preview-actions`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>void l(),disabled:o,children:[(0,Z.jsx)(L,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),o?G(e,`brain.files.downloading`):G(e,`brain.files.download`)]}),(0,Z.jsx)(`button`,{type:`button`,className:`file-preview-close`,"aria-label":G(e,`brain.preview.close`),onClick:n,children:(0,Z.jsx)(ve,{className:`h-4 w-4`,"aria-hidden":`true`})})]})]}),(0,Z.jsx)(`div`,{className:`file-preview-body`,children:i.status===`loading`?(0,Z.jsx)(`p`,{className:`file-preview-note`,role:`status`,children:G(e,`brain.preview.loading`)}):i.status===`error`?(0,Z.jsx)(`p`,{className:`file-preview-note is-error`,role:`alert`,children:G(e,`brain.preview.error`,{reason:i.reason})}):c===`html`?(0,Z.jsx)(`iframe`,{className:`file-preview-frame`,sandbox:``,title:G(e,`brain.preview.aria`,{name:t.filename}),srcDoc:Yn(i.content)}):c===`markdown`?(0,Z.jsx)(`div`,{className:`file-preview-markdown`,"data-testid":`file-preview-markdown`,children:(0,Z.jsx)(Qn,{language:e,content:i.content})}):(0,Z.jsx)(`pre`,{className:`file-preview-code`,"data-testid":`file-preview-code`,children:c===`json`?Xn(i.content):i.content})}),c===`html`?(0,Z.jsxs)(`footer`,{className:`file-preview-foot`,role:`note`,children:[(0,Z.jsx)(Ee,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),G(e,`brain.preview.sandboxNote`)]}):null]})})}function Qn({language:e,content:t}){return(0,Z.jsx)(Z.Fragment,{children:X.useMemo(()=>nr(t),[t]).map((t,n)=>t.kind===`code`?(0,Z.jsx)(ar,{language:e,code:t.value,lang:t.lang},n):t.value.trim()?(0,Z.jsx)(tr,{value:t.value},n):null)})}function $n(e){let t=[],n=[],r=()=>{n.length&&(t.push({kind:`paragraph`,lines:n}),n=[])};for(let i of e.split(`
2
+ `)){let e=i.trim();if(!e){r();continue}let a=/^(#{1,4})\s+(.+)$/.exec(e);if(a){r(),t.push({kind:`heading`,depth:a[1].length,text:a[2]});continue}let o=/^[-*•]\s+(.+)$/.exec(e);if(o){r();let e=t[t.length-1];e?.kind===`list`&&!e.ordered?e.items.push(o[1]):t.push({kind:`list`,ordered:!1,items:[o[1]]});continue}let s=/^\d+[.)]\s+(.+)$/.exec(e);if(s){r();let e=t[t.length-1];e?.kind===`list`&&e.ordered?e.items.push(s[1]):t.push({kind:`list`,ordered:!0,items:[s[1]]});continue}let c=/^>\s?(.*)$/.exec(e);if(c){r();let e=t[t.length-1];e?.kind===`quote`?e.lines.push(c[1]):t.push({kind:`quote`,lines:[c[1]]});continue}if(/^([-_*])\1{2,}$/.test(e)){r();continue}n.push(e)}return r(),t}function er(e){let t=/(\*\*[^*]+\*\*|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^)\s]+\))/g,n=[],r=0,i=0;for(let a=t.exec(e);a;a=t.exec(e)){a.index>r&&n.push(e.slice(r,a.index));let t=a[0];if(t.startsWith(`**`))n.push((0,Z.jsx)(`strong`,{children:t.slice(2,-2)},i++));else if(t.startsWith("`"))n.push((0,Z.jsx)(`code`,{children:t.slice(1,-1)},i++));else{let e=/^\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)$/.exec(t);e?n.push((0,Z.jsx)(`a`,{href:e[2],target:`_blank`,rel:`noreferrer noopener`,children:e[1]},i++)):n.push(t)}r=a.index+t.length}return r<e.length&&n.push(e.slice(r)),n}function tr({value:e}){return(0,Z.jsx)(`div`,{className:`brain-md`,children:X.useMemo(()=>$n(e),[e]).map((e,t)=>{if(e.kind===`heading`)return(0,Z.jsx)(`p`,{className:`brain-md-heading is-depth-${Math.min(e.depth,3)}`,children:er(e.text)},t);if(e.kind===`list`){let n=e.items.map((e,t)=>(0,Z.jsx)(`li`,{children:er(e)},t));return e.ordered?(0,Z.jsx)(`ol`,{children:n},t):(0,Z.jsx)(`ul`,{children:n},t)}return e.kind===`quote`?(0,Z.jsx)(`blockquote`,{children:er(e.lines.join(` `))},t):(0,Z.jsx)(`p`,{children:e.lines.map((e,t)=>(0,Z.jsxs)(X.Fragment,{children:[t>0?(0,Z.jsx)(`br`,{}):null,er(e)]},t))},t)})})}function nr(e){let t=[],n=/```([\w.+-]*)\n([\s\S]*?)(?:```|$)/g,r=0;for(let i=n.exec(e);i;i=n.exec(e))i.index>r&&t.push({kind:`text`,value:e.slice(r,i.index)}),t.push({kind:`code`,value:i[2].replace(/\n$/,``),lang:i[1]||void 0}),r=i.index+i[0].length;return r<e.length&&t.push({kind:`text`,value:e.slice(r)}),t.length?t:[{kind:`text`,value:e}]}var rr={python:`py`,py:`py`,javascript:`js`,js:`js`,typescript:`ts`,ts:`ts`,tsx:`tsx`,jsx:`jsx`,html:`html`,css:`css`,json:`json`,markdown:`md`,md:`md`,bash:`sh`,sh:`sh`,shell:`sh`,zsh:`sh`,sql:`sql`,yaml:`yml`,yml:`yml`,toml:`toml`,csv:`csv`,xml:`xml`,text:`txt`,txt:`txt`};function ir(e){let t=rr[(e||``).toLowerCase()]||`txt`,n=new Date;return`chat-${[n.getFullYear(),String(n.getMonth()+1).padStart(2,`0`),String(n.getDate()).padStart(2,`0`)].join(``)+`-`+[String(n.getHours()).padStart(2,`0`),String(n.getMinutes()).padStart(2,`0`),String(n.getSeconds()).padStart(2,`0`)].join(``)}.${t}`}function ar({language:e,code:t,lang:n}){let[r,i]=X.useState(!1),[a,o]=X.useState(`idle`),[s,c]=X.useState(null),[l,u]=X.useState(``);async function d(){try{await navigator.clipboard?.writeText(t),i(!0),window.setTimeout(()=>i(!1),2e3)}catch{}}async function f(){if(a===`saving`)return;o(`saving`),u(``);let r=ir(n),i=await J.saveChatFile(r,t);if(!i.ok){o(`error`),u(i.error||G(e,`common.error.unknown`));return}let s=i.data,l=s.path||r;c({path:l,filename:l.split(`/`).pop()||r,bytes:s.bytes||0}),o(`saved`)}return(0,Z.jsxs)(`div`,{className:`brain-code-block`,children:[(0,Z.jsxs)(`div`,{className:`brain-code-head`,children:[(0,Z.jsx)(`span`,{className:`brain-code-lang`,children:n||`text`}),(0,Z.jsxs)(`div`,{className:`brain-code-actions`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>void d(),children:r?G(e,`brain.code.copied`):G(e,`brain.code.copy`)}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>void f(),disabled:a===`saving`,children:[(0,Z.jsx)(Ze,{className:`h-3 w-3`,"aria-hidden":`true`}),a===`saving`?G(e,`brain.code.saving`):G(e,`brain.code.save`)]})]})]}),(0,Z.jsx)(`pre`,{children:(0,Z.jsx)(`code`,{children:t})}),a===`saved`&&s?(0,Z.jsx)(cr,{language:e,files:[s],compact:!0}):null,a===`error`?(0,Z.jsx)(`small`,{className:`brain-code-save-error`,role:`alert`,children:G(e,`brain.code.saveError`,{reason:l})}):null]})}function or(e){return e?e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`:``}function sr({language:e,ingest:t}){let n=t.status===`ok`?`brain.files.brainOk`:t.status===`pending`?`brain.files.brainPending`:t.status===`failed`?`brain.files.brainFailed`:null;return n?(0,Z.jsx)(`span`,{className:`brain-created-file-brain is-${t.status}`,role:`note`,"data-testid":`brain-ingest-chip`,title:t.status===`failed`&&t.detail?t.detail:void 0,children:G(e,n)}):null}function cr({language:e,files:t,compact:n=!1}){let[r,i]=X.useState(null),[a,o]=X.useState(``),[s,c]=X.useState(null);async function l(t){if(r)return;i(t.path),o(``);let n=await J.downloadWorkspaceFile(t.path,t.filename);n.ok||o(n.error||G(e,`common.error.unknown`)),i(null)}return(0,Z.jsxs)(`section`,{className:`brain-created-files lattice-success-pulse ${n?`is-compact`:``}`,"aria-label":G(e,`brain.files.title`),children:[(0,Z.jsxs)(`div`,{className:`brain-created-files-head`,children:[(0,Z.jsx)(Re,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,Z.jsx)(`strong`,{children:G(e,`brain.files.title`)})]}),(0,Z.jsx)(`ul`,{children:t.map(t=>(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(`span`,{className:`brain-created-file-name`,children:t.filename}),t.bytes?(0,Z.jsx)(`small`,{children:or(t.bytes)}):null,t.repaired?(0,Z.jsx)(`span`,{className:`brain-created-file-repaired`,role:`note`,children:G(e,`brain.files.repaired`)}):null,t.brainIngest?(0,Z.jsx)(sr,{language:e,ingest:t.brainIngest}):null,Kn(t)?(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>c(t),children:[(0,Z.jsx)(Le,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),G(e,`brain.preview.open`)]}):null,(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>void l(t),disabled:r===t.path,children:[(0,Z.jsx)(L,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),r===t.path?G(e,`brain.files.downloading`):G(e,`brain.files.download`)]})]},t.path))}),s?(0,Z.jsx)(Zn,{language:e,file:s,onClose:()=>c(null)}):null,(0,Z.jsx)(`small`,{className:`brain-created-files-hint`,children:G(e,`brain.files.hint`)}),a?(0,Z.jsx)(`small`,{className:`brain-created-files-error`,role:`alert`,children:G(e,`brain.files.downloadError`,{reason:a})}):null]})}function lr({language:e,modelName:t,modelReady:n,messages:r,pastConversations:i,historyBusyId:a,starterPrompts:o,memoryFeedback:s,ingestionStates:l,emergenceEvents:u,proactiveActivities:d,draft:f,streaming:p,imageData:m,streamRef:h,memories:g,graph:_,concepts:v,relationshipCount:y,readiness:b,proof:x,brief:S,uploadingDocument:C,onOpenDepth:T,onDraftChange:E,onImageDataChange:D,onUploadDocument:k,onPickFolder:A,onConnectFolder:j,onIngestNote:M,onIngestWeb:ne,onVerifyModelContinuity:N,onSend:re,onSendText:P,onCreateActionItem:ie,onProactiveAction:ae,onApprovalResolved:oe,onStop:L,onRegenerate:R,onNewConversation:se,onResumeConversation:ce,onDeleteConversation:le,brainState:ue,intensity:z,onExploreBrain:B,onRequestDetails:V}){let de=r.length>0,H=ke(e=>e.mode)===`basic`,fe=pr(r),pe=S.suggestedQuestions.slice(0,3),me=X.useMemo(()=>r.flatMap(e=>e.approval?[e.approval.runId]:[]),[r]),he=(0,Z.jsx)(gn,{language:e,variant:`inline`,uploadingDocument:C,ingestionStates:l,onUploadDocument:k,onPickFolder:A,onConnectFolder:j,onIngestNote:M,onIngestWeb:ne});return(0,Z.jsx)(`section`,{className:`brain-conversation`,"aria-label":G(e,`brain.aria.conversation`),children:(0,Z.jsx)(`div`,{className:`brain-chat-home-layout`,children:(0,Z.jsxs)(`section`,{className:`brain-chat-home-card ${de?`has-messages`:`is-empty-home`}`,"aria-label":G(e,`brain.chatHome.aria`),children:[(0,Z.jsx)(ee,{language:e}),(0,Z.jsx)(w,{language:e}),(0,Z.jsx)(O,{language:e,knownRunIds:me}),de?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`header`,{className:`brain-chat-header`,children:[(0,Z.jsxs)(`div`,{className:`brain-header-presence`,children:[(0,Z.jsx)(c,{state:ue,intensity:z,size:`trace`,showLabel:!1,onInteract:B}),(0,Z.jsxs)(`div`,{className:`brain-header-title`,children:[(0,Z.jsx)(`strong`,{children:G(e,`brain.title`)}),(0,Z.jsxs)(`span`,{children:[G(e,`brain.firstScreen.state.${b.state}`),H?``:` (${b.score}%)`]})]})]}),(0,Z.jsxs)(`div`,{className:`brain-header-actions`,children:[H?null:(0,Z.jsx)(`div`,{className:`brain-model-pill`,children:t}),(0,Z.jsxs)(`button`,{type:`button`,className:`brain-deeper-btn`,onClick:se,children:[(0,Z.jsx)(Ke,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),G(e,`brain.newChat`)]}),(0,Z.jsx)(`button`,{type:`button`,className:`brain-deeper-btn`,onClick:B,children:G(e,`brain.firstScreen.action.graph`)})]})]}),(0,Z.jsx)(cn,{language:e,state:l.chat,concepts:v,relationshipCount:y,onExploreBrain:B}),(0,Z.jsx)(`div`,{ref:h,className:`brain-stream`,children:r.map((t,n)=>{let i=`brain-msg-${n}`,a=t.role===`assistant`?t.proof:void 0,o=t.role===`assistant`&&!!t.content.trim()&&!p,s=o&&n===fe;return(0,Z.jsxs)(`div`,{className:`brain-message ${t.role}`,children:[(0,Z.jsxs)(`div`,{className:`brain-message-bubble`,children:[t.role===`assistant`?(0,Z.jsx)(Qn,{language:e,content:t.content}):t.content,a&&a.citations.length?(0,Z.jsx)(yt,{language:e,proof:a,messageId:i}):null,t.role===`assistant`&&t.contextQuality?.limited?(0,Z.jsx)(fr,{language:e,reason:H?null:t.contextQuality.reason}):null,t.role===`assistant`&&t.content.trim()&&t.grounding?(0,Z.jsx)(dr,{language:e,grounding:t.grounding}):null,t.role===`assistant`&&t.cloudAnswer?(0,Z.jsx)(Bn,{language:e,cloudAnswer:t.cloudAnswer}):null]}),t.role===`assistant`&&t.approval?(0,Z.jsx)(lt,{language:e,approval:t.approval,onResolved:e=>oe(n,e),onReplan:P}):null,t.role===`assistant`&&t.agentSteps?.length?(0,Z.jsx)(ht,{language:e,steps:t.agentSteps,streaming:p&&n===r.length-1}):null,o?(0,Z.jsx)(mr,{language:e,content:t.content,canRegenerate:n===fe,onRegenerate:R,canFollowUp:s,onFollowUp:P,onCreateActionItem:ie}):null,t.files?.length?(0,Z.jsx)(cr,{language:e,files:t.files}):null,t.role===`assistant`&&t.agentState?(0,Z.jsx)(ur,{language:e,state:t.agentState}):null,t.role===`assistant`&&t.loopSummary?(0,Z.jsx)(gt,{language:e,summary:t.loopSummary}):null,t.role===`assistant`&&t.runExplanation?(0,Z.jsx)(_t,{language:e,explanation:t.runExplanation}):null,a?(0,Z.jsx)(bt,{language:e,proof:a,messageId:i,onUseEvidence:P}):null]},`${t.role}-${n}`)})}),(0,Z.jsx)(sn,{language:e,brief:S,activities:d,streaming:p,onAction:ae}),n?null:(0,Z.jsx)(wn,{language:e}),(0,Z.jsx)(Un,{language:e}),(0,Z.jsx)(Jt,{language:e,draft:f,streaming:p,imageData:m,uploadingDocument:C,onDraftChange:E,onImageDataChange:D,onUploadDocument:k,onSend:re,onStop:L,attachments:he})]}):(0,Z.jsxs)(`div`,{className:`brain-centered-home`,"data-testid":`brain-home-stage`,children:[(0,Z.jsxs)(`section`,{className:`brain-home-station`,"data-testid":`brain-home-station`,children:[(0,Z.jsx)(In,{language:e,brainState:ue,intensity:z,readiness:b,memories:g,graph:_,relationshipCount:y,onExploreBrain:B,trailing:n?null:(0,Z.jsx)(wn,{language:e})}),(0,Z.jsxs)(`div`,{className:`brain-writing-desk`,children:[(0,Z.jsxs)(`div`,{className:`brain-composer-wrapper`,children:[(0,Z.jsx)(Un,{language:e}),(0,Z.jsx)(Jt,{language:e,draft:f,streaming:p,imageData:m,uploadingDocument:C,onDraftChange:E,onImageDataChange:D,onUploadDocument:k,onSend:re,onStop:L,attachments:he})]}),(0,Z.jsx)(`div`,{className:`brain-station-toolbar`,role:`group`,"aria-label":G(e,`brain.station.toolbar.aria`),children:(0,Z.jsx)(zn,{language:e})})]})]}),(0,Z.jsx)(`section`,{className:`brain-secondary-deck`,"data-testid":`brain-secondary-deck`,"aria-label":G(e,`brain.suggestions.aria`),children:pe.length?(0,Z.jsxs)(`div`,{className:`brain-home-prompt-strip`,children:[(0,Z.jsxs)(`div`,{className:`brain-home-prompt-strip-label`,children:[(0,Z.jsx)(F,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{children:G(e,`brain.suggestions.title`)})]}),(0,Z.jsx)(`div`,{className:`brain-prompt-grid`,children:pe.map(t=>{let n=G(e,t.promptKey,t.params);return(0,Z.jsxs)(`button`,{type:`button`,disabled:p,title:G(e,t.detailKey),onClick:()=>{E(``),P(n)},children:[(0,Z.jsx)(`strong`,{children:G(e,t.labelKey)}),(0,Z.jsx)(`span`,{children:G(e,t.detailKey)})]},t.id)})})]}):(0,Z.jsxs)(`div`,{className:`brain-home-prompt-strip`,children:[(0,Z.jsxs)(`div`,{className:`brain-home-prompt-strip-label`,children:[(0,Z.jsx)(F,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{children:G(e,`brain.suggestions.title`)})]}),(0,Z.jsx)(`div`,{className:`brain-prompt-pills-row`,children:o.slice(0,3).map(e=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>E(e),className:`brain-prompt-pill`,children:e},e))})]})}),(0,Z.jsx)(`footer`,{className:`brain-home-quiet`,children:(0,Z.jsx)(Fn,{language:e,brainState:ue,intensity:z,readiness:b,memories:g,concepts:v,relationshipCount:y,emergenceEvents:u,proactiveActivities:d,pastConversations:i,historyBusyId:a,streaming:p,modelName:t,proof:x,brief:S,onOpenDepth:T,onExploreBrain:B,onVerifyModelContinuity:N,onProactiveAction:ae,onResumeConversation:ce,onDeleteConversation:le,onRequestDetails:V})})]}),s?(0,Z.jsxs)(`div`,{className:`brain-save-feedback`,role:`status`,children:[(0,Z.jsx)(Ie,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(`span`,{children:s}),(0,Z.jsx)(`small`,{children:G(e,`brain.saved.detail`)})]}):null,de?(0,Z.jsxs)(`details`,{className:`brain-utility-drawer`,onToggle:e=>e.currentTarget.open&&V(),children:[(0,Z.jsx)(`summary`,{children:G(e,H?`brain.chatHome.utility.basic`:`brain.chatHome.utility`)}),(0,Z.jsxs)(`div`,{className:`brain-utility-tools`,"aria-label":G(e,`brain.chatHome.contextAria`),children:[(0,Z.jsx)(Oe,{compact:!0}),H?null:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`brain-model-pill`,children:t}),(0,Z.jsxs)(`button`,{className:`brain-admin-link`,type:`button`,onClick:()=>q(`/admin`),children:[(0,Z.jsx)(Ee,{className:`h-3.5 w-3.5`}),G(e,`brain.admin`)]})]}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(I,{className:`h-3.5 w-3.5`}),G(e,`brain.local`)]}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(I,{className:`h-3.5 w-3.5`}),G(e,`brain.private`)]}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(I,{className:`h-3.5 w-3.5`}),G(e,`brain.portable`)]})]}),(0,Z.jsxs)(`div`,{className:`brain-utility-grid`,children:[(0,Z.jsx)(hn,{language:e,uploadingDocument:C,ingestionStates:l,onUploadDocument:k,onPickFolder:A,onConnectFolder:j,onIngestNote:M,onIngestWeb:ne}),(0,Z.jsx)(te,{language:e}),H?null:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Sn,{language:e,emergenceEvents:u}),(0,Z.jsx)(Mn,{language:e,proof:x,modelName:t,onVerify:N}),(0,Z.jsx)(dn,{memories:g,concepts:v,readiness:b,proof:x,onOpenDepth:T})]}),(0,Z.jsx)(Kt,{language:e}),(0,Z.jsx)(qt,{language:e}),(0,Z.jsx)(Lt,{language:e}),(0,Z.jsx)(Ht,{language:e}),(0,Z.jsx)(Dt,{language:e})]})]}):null]})})})}function ur({language:e,state:t}){return(0,Z.jsx)(`p`,{className:`brain-agent-state-note ${t===`FAILED`?`is-failed`:`is-review`}`,role:`alert`,"data-testid":`agent-state-note`,children:G(e,t===`FAILED`?`brain.agent.failed`:`brain.agent.needsReview`)})}function dr({language:e,grounding:t}){let n=t.status===`supported`;return(0,Z.jsx)(`span`,{className:`brain-grounding-badge ${n?`is-supported`:`is-none`}`,role:`note`,"data-testid":`grounding-badge`,title:t.reason||void 0,children:G(e,n?`brain.grounding.supported`:`brain.grounding.none`)})}function fr({language:e,reason:t}){return(0,Z.jsxs)(`p`,{className:`brain-context-quality-note`,role:`note`,"data-testid":`context-quality-note`,children:[(0,Z.jsx)(`span`,{children:G(e,`brain.contextQuality.limited`)}),t?(0,Z.jsx)(`small`,{children:G(e,`brain.contextQuality.reason`,{reason:t})}):null]})}function pr(e){for(let t=e.length-1;t>=0;--t)if(e[t].role===`assistant`)return t;return-1}function mr({language:e,content:t,canRegenerate:n,onRegenerate:r,canFollowUp:i,onFollowUp:a,onCreateActionItem:o}){let[c,l]=X.useState(!1),u=X.useMemo(()=>[{labelKey:`brain.message.followup.checklist`,promptKey:`brain.message.followup.checklist.prompt`},{labelKey:`brain.message.followup.evidence`,promptKey:`brain.message.followup.evidence.prompt`},{labelKey:`brain.message.followup.next`,promptKey:`brain.message.followup.next.prompt`}],[]);async function d(){try{await navigator.clipboard?.writeText(t),l(!0),window.setTimeout(()=>l(!1),2e3)}catch{}}return(0,Z.jsxs)(`div`,{className:`brain-message-actions`,children:[(0,Z.jsxs)(`button`,{type:`button`,"aria-label":G(e,`brain.message.copyAria`),onClick:()=>void d(),children:[(0,Z.jsx)(Fe,{className:`h-3 w-3`,"aria-hidden":`true`}),c?G(e,`brain.message.copied`):G(e,`brain.message.copy`)]}),n?(0,Z.jsxs)(`button`,{type:`button`,"aria-label":G(e,`brain.message.regenerateAria`),onClick:r,children:[(0,Z.jsx)(s,{className:`h-3 w-3`,"aria-hidden":`true`}),G(e,`brain.message.regenerate`)]}):null,i?(0,Z.jsxs)(`button`,{type:`button`,"aria-label":G(e,`brain.message.saveTaskAria`),onClick:()=>o(t),children:[(0,Z.jsx)(We,{className:`h-3 w-3`,"aria-hidden":`true`}),G(e,`brain.message.saveTask`)]}):null,i?(0,Z.jsx)(`div`,{className:`brain-message-followups`,"aria-label":G(e,`brain.message.followup.aria`),children:u.map(t=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>a(G(e,t.promptKey)),children:G(e,t.labelKey)},t.promptKey))}):null]})}var hr=64;function gr(e){if(e.scrollHeight-e.clientHeight<=1)return!1;let t=e.ownerDocument.defaultView?.getComputedStyle(e).overflowY;return t===`auto`||t===`scroll`||t===`overlay`}function _r(e){for(let t=e;t;t=t.parentElement)if(gr(t))return{element:t,isDocument:!1};let t=e?.ownerDocument,n=t?.scrollingElement??t?.documentElement??null;return n instanceof HTMLElement?{element:n,isDocument:!0}:null}function vr(e){return e.scrollHeight-e.clientHeight-e.scrollTop<=hr}function yr(e){let t=X.useRef(null),n=X.useRef(null),r=X.useRef(!0),i=X.useRef(0),a=X.useCallback(()=>{let e=n.current;return e&&e.element.isConnected?e:(n.current=_r(t.current),n.current)},[]);return X.useEffect(()=>{let e=e=>{let t=n.current;if(!t||!(t.isDocument&&e.target===t.element.ownerDocument||e.target===t.element))return;let a=t.element.scrollTop,o=a<i.current-1;i.current=a,o?r.current=vr(t.element):vr(t.element)&&(r.current=!0)};return document.addEventListener(`scroll`,e,{capture:!0,passive:!0}),()=>document.removeEventListener(`scroll`,e,{capture:!0})},[]),X.useEffect(()=>{let e=a();!e||!r.current||(e.element.scrollTop=e.element.scrollHeight,i.current=e.element.scrollTop)},[e,a]),t}function br({language:e,modelReady:t,onBrainChange:n,setMemoryFeedback:a,beginIngestion:s,completeIngestion:c,failIngestion:l,setLastRecallQuery:d,attachAnswerProof:p}){let _=r(),v=K(e=>e.messages),y=K(e=>e.setMessages),b=K(e=>e.conversationId),S=K(e=>e.setConversationId),C=K(e=>e.preferLocalOnly),[w,T]=X.useState(``),[E,D]=X.useState(null),[O,A]=X.useState(!1),[ee,j]=X.useState([]),te=yr(v),M=X.useRef(null),N=X.useRef(null),ie=i({mutationFn:async t=>{let n=await J.runAgent(t,[`planner`,`executor`,`reviewer`]);if(!n.ok)throw Error(n.error||G(e,`ui.status.unavailable`));return n},onSuccess:()=>{_.invalidateQueries({queryKey:[`memoryManager`]}),_.invalidateQueries({queryKey:[`memoryBrainBrief`]}),_.invalidateQueries({queryKey:[`graphPreview`]}),_.invalidateQueries({queryKey:[`graph`]}),_.invalidateQueries({queryKey:[`agentRuntime`]}),a(G(e,`brain.delegate.done`)),window.setTimeout(()=>a(null),4200)},onError:t=>a(G(e,`brain.delegate.failed`,{reason:String(t)}))});X.useEffect(()=>{O?n(`thinking`,.94):w.trim().length>4?n(`listening`,.76):n(`idle`,.58)},[w,n,O]),X.useEffect(()=>()=>{N.current!==null&&window.clearTimeout(N.current),M.current?.abort()},[]);async function ae(){let e=w.trim();!e||O||(T(``),await I(e))}async function F(){if(O)return;let e=[...v].reverse().find(e=>e.role===`user`);e&&(y(e=>{let t=[...e];return t[t.length-1]?.role===`assistant`&&t.pop(),t[t.length-1]?.role===`user`&&t.pop(),t}),await I(e.content))}async function I(r){if(!r||O)return;let i=b||`brain-${Date.now()}`;if(b||S(i),!t){y(t=>[...t,{role:`user`,content:r},{role:`assistant`,content:G(e,`brain.noModel.message`)}]),D(null),a(G(e,`brain.noModel.status`));return}y(e=>[...e,{role:`user`,content:r},{role:`assistant`,content:``}]),D(null),A(!0),a(null),s(`chat`,r.slice(0,120)),n(`thinking`,.96);let v=new AbortController;M.current=v;try{let t=await J.streamChat({message:r,conversation_id:i,image_data:E||void 0,...C?{network_mode:`local_only`}:{}},{signal:v.signal,onChunk:(e,t)=>{y(e=>{let n=[...e];return n[n.length-1]={...n[n.length-1],role:`assistant`,content:t},n})},onHybridContext:e=>{let t=m(e);t&&y(e=>{let n=[...e],r=n[n.length-1];return r?.role===`assistant`?(n[n.length-1]={...r,hybridContext:t},n):e})},onHybridDone:e=>{let t=u(e);t&&y(e=>{let n=[...e],r=n[n.length-1];return r?.role===`assistant`?(n[n.length-1]={...r,content:t.answer||r.content,cloudAnswer:x(t,r.hybridContext?.nodeIds.length||0)},n):e})},onAgentStep:e=>{let t=g(e);t&&y(e=>{let n=[...e],r=n[n.length-1];return n[n.length-1]={...r,role:`assistant`,agentSteps:[...r.agentSteps||[],t]},n})},onAgent:t=>{let n=rt(t);if(n){y(e=>{let t=[...e];return t[t.length-1]={...t[t.length-1],approval:n},t});return}let r=k(t),i=t.final_state===`NEEDS_REVIEW`||t.final_state===`FAILED`?t.final_state:void 0,a=h(t.loop),o=f(t.explanation,e),s=ne(t.steps);!r.length&&!i&&!a&&!o&&!s.length||y(e=>{let t=[...e],n=t[t.length-1],c=n.agentSteps?.length?n.agentSteps:s;return t[t.length-1]={...n,...r.length?{files:r}:{},...i?{agentState:i}:{},...a?{loopSummary:a}:{},...o?{runExplanation:o}:{},...c.length?{agentSteps:c}:{}},t})},onTrace:e=>{e&&(n(`recalling`,.9),o(),N.current!==null&&window.clearTimeout(N.current),N.current=window.setTimeout(()=>n(`thinking`,.9),900))}});if(t.error)y(n=>xr(n,`${G(e,`brain.unavailable`)}: ${t.error}`)),l(`chat`,String(t.error));else{let n=P(`contextQuality`in t?t.contextQuality:null)||P(t.trace),i=re(`grounding`in t?t.grounding:null)||re(t.trace),s=m(`hybridContext`in t?t.hybridContext:null),l=u(`hybridDone`in t?t.hybridDone:null);(n||i||s||l)&&y(e=>{let t=[...e];for(let e=t.length-1;e>=0;--e)if(t[e].role===`assistant`){let r=t[e];t[e]={...r,...n?{contextQuality:n}:{},...i?{grounding:i}:{},...s&&!r.hybridContext?{hybridContext:s}:{},...l&&!r.cloudAnswer?{content:l.answer||r.content,cloudAnswer:x(l,r.hybridContext?.nodeIds.length||s?.nodeIds.length||0)}:{}};break}return t}),d(r);let f=await c(`chat`);a(G(e,`brain.saved`,{topics:f.entities,memories:f.memories})),o(),p(r)}}catch(t){let n=t instanceof DOMException&&t.name===`AbortError`;y(r=>{let i=[...r],a=i[i.length-1];return a?.role===`assistant`&&!a.content.trim()&&(i[i.length-1]={...a,content:n?G(e,`brain.stopped.empty`):`${G(e,`brain.unavailable`)}: ${t instanceof Error?t.message:String(t)}`}),i}),a(n?G(e,`brain.stopped`):null),l(`chat`,n?`stopped`:t instanceof Error?t.message:String(t))}finally{N.current!==null&&(window.clearTimeout(N.current),N.current=null),M.current===v&&(M.current=null),A(!1);for(let e of[`chatHistory`,`memoryManager`,`graphPreview`,`graph`,`memoryBrainProof`,`memoryBrainBrief`])_.invalidateQueries({queryKey:[e]})}}function oe(t,n){if(y(r=>{let i=r[t];if(!i?.approval)return r;let a=[...r];if(n.kind===`finished`){let r=n.payload,o=k(r),s=r.final_state===`NEEDS_REVIEW`||r.final_state===`FAILED`?r.final_state:void 0,c=typeof r.response==`string`?r.response.trim():``,l=h(r.loop),u=f(r.explanation,e),d=ne(r.steps),p=i.agentSteps?.length?i.agentSteps:d;a[t]={...i,content:c||i.content,...o.length?{files:o}:{},...s?{agentState:s}:{},...l?{loopSummary:l}:{},...u?{runExplanation:u}:{},...p.length?{agentSteps:p}:{},approval:{...i.approval,status:`approved`}}}else n.kind===`error`?a[t]={...i,approval:{...i.approval,status:`error`,errorReason:n.reason}}:a[t]={...i,approval:{...i.approval,status:n.kind,...n.kind===`expired`&&n.replanMessage?{replanMessage:n.replanMessage}:{}}};return a}),n.kind===`finished`){o();for(let e of[`chatHistory`,`memoryManager`,`graphPreview`,`graph`,`memoryBrainProof`,`memoryBrainBrief`,`agentRuntime`])_.invalidateQueries({queryKey:[e]})}}async function L(t){let n=t.trim();if(!n)return!1;let r=([...v].reverse().find(e=>e.role===`user`)?.content||G(e,`brain.action.defaultTitle`)).trim().slice(0,96),i=await J.createReviewItem({title:r,summary:n.slice(0,420),source:`chat_followup`,kind:`task_draft`,payload:{answer_preview:n.slice(0,2e3),conversation_id:b||``},provenance:{conversation_id:b||``,source_detail:`brain_chat`}});return a(i.ok?G(e,`brain.action.saved`):G(e,`brain.action.saveFailed`,{reason:i.error||String(i.status||``)})),i.ok}function R(e,t,n,r=`${e.id}-${Date.now()}`){let i=Date.now();return j(a=>{let o=a.find(e=>e.id===r);return[{id:r,actionId:e.id,labelKey:e.labelKey,intent:e.intent,status:t,startedAt:o?.startedAt??i,completedAt:t===`running`?void 0:i,detail:n},...a.filter(e=>e.id!==r)].slice(0,6)}),r}async function se(e){let t=e.prompt.trim(),n=R(e,`running`);if(e.intent===`route`&&e.route){window.location.hash=e.route,R(e,`completed`,e.route,n);return}if(!t){R(e,`failed`,`empty prompt`,n);return}try{e.intent===`delegate`?(await ie.mutateAsync(t),R(e,`completed`,`agent`,n)):e.intent===`review`?R(e,await L(t)?`completed`:`failed`,`review`,n):(await I(t),R(e,`completed`,`chat`,n))}catch(t){R(e,`failed`,t instanceof Error?t.message:String(t),n)}}return{messages:v,conversationId:b,draft:w,setDraft:T,imageData:E,setImageData:D,streaming:O,streamRef:te,proactiveActivities:ee,send:ae,sendText:I,regenerate:F,createActionItem:L,handleProactiveAction:se,handleApprovalResolved:oe,stopStreaming:()=>M.current?.abort()}}function xr(e,t){let n=[...e];return n[n.length-1]={role:`assistant`,content:t},n}function Sr({language:e,setMemoryFeedback:t}){let n=r(),i=K(e=>e.conversationId),a=K(e=>e.setConversationId),o=K(e=>e.setMessages),s=K(e=>e.resetConversation),[c,l]=X.useState(null),u=U({queryKey:[`chatHistory`],queryFn:J.chatHistory});return{historyQ:u,pastConversations:X.useMemo(()=>M(u.data?.data),[u.data]),historyBusyId:c,resetConversation:s,resumeConversation:X.useCallback(async(n,r)=>{if(!(c||r)){l(n),t(G(e,`brain.history.loading`));try{let r=await J.conversation(n);if(!r.ok){t(G(e,`brain.history.loadFailed`,{reason:r.error||`unavailable`}));return}let i=v(r.data);if(!i.length){t(G(e,`brain.history.loadFailed`,{reason:G(e,`brain.history.emptyConversation`)}));return}a(n),o(i),t(G(e,`brain.history.resumed`))}finally{l(null)}}},[c,e,a,t,o]),deleteConversation:X.useCallback(async r=>{if(!c){l(r);try{let a=await J.deleteConversation(r);if(!a.ok){t(G(e,`brain.history.deleteFailed`,{reason:a.error||`unavailable`}));return}i===r&&s(),t(G(e,`brain.history.deleted`)),n.invalidateQueries({queryKey:[`chatHistory`]}),n.invalidateQueries({queryKey:[`memoryManager`]})}finally{l(null)}}},[i,c,e,n,s,t])}}function Cr(){let e=window;return!!(e.__TAURI__?.core?.invoke||e.latticeDesktop?.selectFolder||e.__TAURI_INTERNALS__&&window.location.protocol===`tauri:`)}function wr(e){return e instanceof DOMException&&e.name===`AbortError`}function Tr(e){return(e[0]?.webkitRelativePath||``).split(`/`).filter(Boolean)[0]||``}async function Er(e){let t=[];if(typeof e.values==`function`){for await(let n of e.values())t.push(n);return t}if(typeof e.entries==`function`)for await(let[,n]of e.entries())t.push(n);return t}async function Dr(e){let t=[];for(let n of await Er(e)){if(n.kind===`file`){t.push(await n.getFile());continue}t.push(...await Dr(n))}return t}async function Or(){try{if(Cr()){let e=await J.selectFolder();if(e)return{kind:`path`,path:e}}let e=window.showDirectoryPicker;if(typeof e==`function`){let t=await e.call(window);return{kind:`files`,files:await Dr(t),name:t.name}}return{kind:`unavailable`}}catch(e){return wr(e)?{kind:`cancelled`}:{kind:`unavailable`}}}var kr={chat:null,file:null,folder:null,note:null,web:null};function Ar({language:e,brainReadiness:t,memoryFragments:n,graphModel:i,memoriesFetched:a,graphFetched:s,requestDetails:c,setLastRecallQuery:l,setMemoryFeedback:u,onBrainChange:d}){let f=r(),[p,m]=X.useState(!1),[h,g]=X.useState(kr),[_,v]=X.useState([]),[y,b]=X.useState(!1),x=X.useRef({});X.useEffect(()=>{if(!_[0]?.id)return;b(!0);let e=window.setTimeout(()=>b(!1),1650);return()=>window.clearTimeout(e)},[_]);let S=X.useCallback((e,t)=>{g(n=>{let r=n[e];return r?{...n,[e]:{...r,stage:t}}:n})},[]),C=X.useCallback((e,r)=>{c(),x.current[e]={memories:Math.max(t.signals.memoryCount,n.length),entities:Math.max(t.signals.conceptCount,i.nodes.length),label:r,memoryKnown:a,graphKnown:s,nodeIds:new Set(i.nodes.map(e=>e.id))},g(t=>({...t,[e]:{sourceType:e,label:r,stage:`preparing`,startedAt:Date.now(),completedAt:null,newMemories:0,newEntities:0,nodeIds:[]}}))},[t.signals.conceptCount,t.signals.memoryCount,s,i.nodes,a,n.length,c]),w=X.useCallback((e,t,n,r,i)=>{let a=x.current[e],o=a?.label??``,s=a?.graphKnown?r.nodes.filter(e=>!a.nodeIds.has(e.id)).map(e=>e.id):[],c=i.nodeIds.filter(e=>!a?.graphKnown||!a.nodeIds.has(e)),l=Array.from(new Set([...s,...c])).slice(0,24),u=a?.memoryKnown?Math.max(0,t-a.memories):0,d=a?.graphKnown?Math.max(l.length,Math.max(0,n-a.entities)):l.length;delete x.current[e],g(t=>{let n=t[e];return n?{...t,[e]:{...n,stage:`complete`,completedAt:Date.now(),newMemories:u,newEntities:d,nodeIds:l,chunkCount:i.chunkCount,duplicate:i.duplicate,provenanceId:i.provenanceId,extraction:i.extraction}}:t}),v(t=>[{id:`${e}-${Date.now()}`,sourceType:e,label:o,newMemories:u,newEntities:d,nodeIds:l,at:Date.now()},...t].slice(0,10))},[]),T=X.useCallback(async(e,r=null)=>{S(e,`indexing`);let a=D(r),[o,s]=await Promise.all([J.memoryManager(),J.graphPreview(48)]),c=s.ok?N(s.data):i,l=o.ok?E(o.data,n.length,c.nodes.length):t;return o.ok&&f.setQueryData([`memoryManager`],o),s.ok&&f.setQueryData([`graphPreview`],s),w(e,Math.max(l.signals.memoryCount,n.length),Math.max(l.signals.conceptCount,c.nodes.length),c,a),await Promise.all([f.invalidateQueries({queryKey:[`chatHistory`]}),f.invalidateQueries({queryKey:[`graph`]}),f.invalidateQueries({queryKey:[`memoryBrainProof`]}),f.invalidateQueries({queryKey:[`memoryBrainBrief`]}),f.invalidateQueries({queryKey:[`vectorFreshness`]}),f.invalidateQueries({queryKey:[`ingestionJobs`]})]),{memories:Math.max(l.signals.memoryCount,n.length),entities:Math.max(l.signals.conceptCount,c.nodes.length)}},[t,i,n.length,f,w,S]),O=X.useCallback((e,t)=>{delete x.current[e],g(n=>{let r=n[e];return r?{...n,[e]:{...r,stage:`error`,completedAt:Date.now(),error:t}}:n})},[]),k=X.useCallback(async t=>{if(!p){m(!0),u(G(e,`brain.upload.pending`,{name:t.name})),d(`recalling`,.86),C(`file`,t.name);try{let n=await J.uploadDocument(t);if(!n.ok){let t=n.error||`unavailable`;u(G(e,`brain.upload.failed`,{reason:t})),O(`file`,t);return}u(G(e,`brain.upload.saved`,{name:t.name})),l(t.name),await T(`file`,n.data),o()}finally{m(!1)}}},[C,T,O,e,d,l,u,p]),A=X.useCallback(async t=>{let n=t.trim();if(!n)return;u(G(e,`brain.ingest.folder.pending`,{path:n})),d(`recalling`,.84),C(`folder`,n);let r=await J.connectFolder(n);if(!r.ok){let t=r.error||`unavailable`;u(G(e,`brain.ingest.folder.failed`,{reason:t})),O(`folder`,t);return}u(G(e,`brain.ingest.folder.saved`,{path:n})),l(n),await T(`folder`,r.data),o()},[C,T,O,e,d,l,u]);return{ingestionStates:h,emergenceEvents:_,synthesisActive:y,uploadingDocument:p,beginIngestion:C,completeIngestion:T,failIngestion:O,uploadDocument:k,pickFolder:X.useCallback(async()=>{let t=await Or();if(t.kind===`cancelled`)return;if(t.kind===`unavailable`){u(G(e,`brain.ingest.folder.unavailable`));return}if(t.kind===`path`){await A(t.path);return}let n=t.name||Tr(t.files);if(!t.files.length){u(G(e,`brain.ingest.folder.empty`)),O(`folder`,`empty`);return}u(G(e,`brain.ingest.folder.reading`)),d(`recalling`,.84),C(`folder`,n);let r=0,i=null;for(let e of t.files){let t=await J.uploadDocument(e);t.ok&&(r+=1,i=t)}if(!r){u(G(e,`brain.ingest.folder.empty`)),O(`folder`,`empty`);return}u(G(e,`brain.ingest.folder.browserSaved`,{name:n,count:r})),l(n),await T(`folder`,i?.data),o()},[C,T,A,O,e,d,l,u]),connectFolder:A,ingestNote:X.useCallback(async t=>{let n=t.trim();if(!n)return;u(G(e,`brain.ingest.note.pending`)),d(`recalling`,.84),C(`note`,n.slice(0,80));let r=await J.ingestNote(n,n.slice(0,80));if(!r.ok){let t=r.error||`unavailable`;u(G(e,`brain.ingest.note.failed`,{reason:t})),O(`note`,t);return}u(G(e,`brain.ingest.note.saved`)),l(n.slice(0,120)),await T(`note`,r.data),o()},[C,T,O,e,d,l,u]),ingestWeb:X.useCallback(async t=>{let n=t.trim();if(!n)return;u(G(e,`brain.ingest.web.pending`,{url:n})),d(`recalling`,.84),C(`web`,n);let r=await J.browserReadUrl(n),i=r.data&&typeof r.data==`object`?r.data:{},a=typeof i.status==`string`?i.status:``;if(!r.ok||a!==`ok`){let t=r.error||(typeof i.detail==`string`?i.detail:a)||`unavailable`;u(G(e,`brain.ingest.web.failed`,{reason:t})),O(`web`,t);return}u(G(e,`brain.ingest.web.saved`,{url:n})),l(n),await T(`web`,r.data),o()},[C,T,O,e,d,l,u]),resetChatIngestion:()=>g(e=>({...e,chat:null}))}}function jr({language:e,messages:t,modelName:n,setMemoryFeedback:r}){let i=K(e=>e.setMessages),[a,o]=X.useState(``),[s,c]=X.useState(!1),l=U({queryKey:[`memoryBrainProof`,a],queryFn:()=>J.memoryBrainProof(a,3),enabled:s||!!a||t.length>0}),u=U({queryKey:[`memoryBrainBrief`,a],queryFn:()=>J.memoryBrainBrief(a,3)}),d=X.useMemo(()=>y(l.data,n),[l.data,n]),f=X.useMemo(()=>j(u.data?.data),[u.data]),p=X.useCallback(async t=>{let a=await J.memoryBrainProof(t,4);if(!a.ok)return r(G(e,`brain.proof.unavailable`,{reason:a.error||G(e,`ui.status.unavailable`)})),!1;let o=Mr(y(a,n),t,n);return i(e=>{let t=[...e];for(let e=t.length-1;e>=0;--e)if(t[e].role===`assistant`){t[e]={...t[e],proof:o};break}return t}),!0},[e,n,r,i]);return{brainProof:d,brainBrief:f,lastRecallQuery:a,setLastRecallQuery:o,requestDetails:()=>c(!0),attachAnswerProof:p,verifyModelContinuity:X.useCallback(async()=>{let i=[...t].reverse().find(e=>e.role===`user`),s=a||i?.content||``;if(!s.trim()){r(G(e,`brain.modelDemo.needQuestion`));return}r(G(e,`brain.modelDemo.checking`,{model:n})),await p(s)&&(o(s),r(G(e,`brain.modelDemo.done`,{model:n})))},[p,e,a,t,n,r])}}function Mr(e,t,n){return{query:t,model:e.modelContinuity.activeModel||n,provenAcrossModels:e.modelContinuity.proven&&e.claims.keepsContextAcrossModels,citations:e.recall.items.slice(0,4).map(e=>({id:e.id,source:e.source,title:e.title,snippet:e.snippet,matchedTerms:e.matchedTerms,confidence:e.confidence,score:e.score,locator:e.locator,kind:e.kind,caption:e.caption,thumbnail:e.thumbnail}))}}function Nr(e){let t=e.dataTransfer?.types;return t?Array.from(t).includes(`Files`):!1}function Pr(e){let[t,n]=X.useState(!1),r=X.useRef(0),i=X.useRef(e);return i.current=e,X.useEffect(()=>{let e=e=>{Nr(e)&&(e.preventDefault(),r.current+=1,n(!0))},t=e=>{Nr(e)&&(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`copy`))},a=e=>{Nr(e)&&(r.current=Math.max(0,r.current-1),r.current===0&&n(!1))},o=e=>{if(r.current=0,n(!1),!Nr(e))return;e.preventDefault();let t=Array.from(e.dataTransfer?.files||[]);t.length&&i.current(t)},s=()=>{r.current=0,n(!1)};return window.addEventListener(`dragenter`,e),window.addEventListener(`dragover`,t),window.addEventListener(`dragleave`,a),window.addEventListener(`drop`,o),window.addEventListener(`dragend`,s),()=>{window.removeEventListener(`dragenter`,e),window.removeEventListener(`dragover`,t),window.removeEventListener(`dragleave`,a),window.removeEventListener(`drop`,o),window.removeEventListener(`dragend`,s)}},[]),t}function Fr({brainState:e,intensity:t,onBrainChange:n}){let r=ke(e=>e.language),i=K(e=>e.messages),[a,s]=X.useState(null),c=U({queryKey:[`memoryManager`],queryFn:J.memoryManager}),l=U({queryKey:[`graphPreview`],queryFn:()=>J.graphPreview(48)}),u=U({queryKey:[`models`],queryFn:J.models}),d=Sr({language:r,setMemoryFeedback:s}),f=X.useMemo(()=>b(c.data?.data,d.historyQ.data?.data,r),[d.historyQ.data,c.data]),p=X.useMemo(()=>N(l.data?.data),[l.data]),m=X.useMemo(()=>p.nodes.slice(0,10),[p.nodes]),h=X.useMemo(()=>E(c.data?.data,f.length,m.length),[m.length,c.data,f.length]),g=X.useMemo(()=>A(u.data?.data),[u.data]),_=X.useMemo(()=>C(u.data?.data),[u.data]),v=jr({language:r,messages:i,modelName:g,setMemoryFeedback:s}),y=Ar({language:r,brainReadiness:h,memoryFragments:f,graphModel:p,memoriesFetched:c.isFetched,graphFetched:l.isFetched,requestDetails:v.requestDetails,setLastRecallQuery:v.setLastRecallQuery,setMemoryFeedback:s,onBrainChange:n}),x=br({language:r,modelReady:_,onBrainChange:n,setMemoryFeedback:s,beginIngestion:y.beginIngestion,completeIngestion:y.completeIngestion,failIngestion:y.failIngestion,setLastRecallQuery:v.setLastRecallQuery,attachAnswerProof:v.attachAnswerProof}),S=X.useMemo(()=>[G(r,`brain.prompt.remember`),G(r,`brain.prompt.know`),G(r,`brain.prompt.plan`)],[r]),w=X.useCallback(e=>{o(),n(`recalling`,.82),window.location.hash=e<=2?`/memory`:`/knowledge-graph`},[n]),T=X.useRef(y.uploadDocument);T.current=y.uploadDocument;let D=Pr(X.useCallback(e=>{(async()=>{for(let t of e.slice(0,5))await T.current(t)})()},[])),O=X.useCallback(()=>{x.streaming&&x.stopStreaming(),d.resetConversation(),y.resetChatIngestion(),s(null),n(`idle`,.58)},[x,d,y,n]),k=x.proactiveActivities.some(e=>e.status===`running`),ee=Object.values(y.ingestionStates).some(e=>e&&e.stage!==`complete`&&e.stage!==`error`),j=k?`acting`:x.streaming&&e===`recalling`?`recalling`:x.streaming?`thinking`:ee?`recalling`:y.synthesisActive?`synthesizing`:x.draft.trim()?`listening`:`idle`,te=j===`idle`?.62:j===`listening`?.76:Math.max(.92,t);return(0,Z.jsxs)(`main`,{className:`brain-home`,"aria-label":G(r,`brain.aria.home`),children:[D?(0,Z.jsx)(`div`,{className:`brain-drop-overlay`,role:`status`,"data-testid":`brain-drop-overlay`,children:(0,Z.jsxs)(`div`,{className:`brain-drop-overlay-card`,children:[(0,Z.jsx)(`strong`,{children:G(r,`brain.dnd.title`)}),(0,Z.jsx)(`span`,{children:G(r,`brain.dnd.detail`)})]})}):null,(0,Z.jsx)(lr,{language:r,brainState:j,intensity:te,modelName:g,modelReady:_,messages:x.messages,pastConversations:d.pastConversations,historyBusyId:d.historyBusyId,starterPrompts:S,memoryFeedback:a,ingestionStates:y.ingestionStates,emergenceEvents:y.emergenceEvents,proactiveActivities:x.proactiveActivities,draft:x.draft,streaming:x.streaming,imageData:x.imageData,streamRef:x.streamRef,memories:f,graph:p,concepts:m,relationshipCount:Math.max(h.signals.relationshipCount,p.edges.length),readiness:h,proof:v.brainProof,brief:v.brainBrief,uploadingDocument:y.uploadingDocument,onOpenDepth:w,onDraftChange:x.setDraft,onImageDataChange:x.setImageData,onUploadDocument:e=>void y.uploadDocument(e),onPickFolder:()=>void y.pickFolder(),onConnectFolder:e=>void y.connectFolder(e),onIngestNote:e=>void y.ingestNote(e),onIngestWeb:e=>void y.ingestWeb(e),onVerifyModelContinuity:()=>void v.verifyModelContinuity(),onSend:()=>void x.send(),onSendText:e=>void x.sendText(e),onCreateActionItem:e=>void x.createActionItem(e),onProactiveAction:e=>void x.handleProactiveAction(e),onApprovalResolved:x.handleApprovalResolved,onStop:x.stopStreaming,onRegenerate:()=>void x.regenerate(),onNewConversation:O,onResumeConversation:e=>void d.resumeConversation(e,x.streaming),onDeleteConversation:e=>void d.deleteConversation(e),onExploreBrain:()=>w(5),onRequestDetails:v.requestDetails})]})}export{Fr as BrainHome};
@@ -1 +1 @@
1
- import{i as e,n as t,t as n}from"./jsx-runtime-bzQ4Vb5N.js";import{n as r}from"./QueryClientProvider-B3OjqSyJ.js";import{t as i}from"./useMutation-OJLrYSRA.js";import{t as a}from"./circle-check-CFgejkOS.js";import{t as o}from"./circle-pause-l96izbxj.js";import{A as s,E as c,H as l,O as u,R as d,S as f,c as p,f as m,l as h,p as g,v as _}from"./index-D2H-wSl6.js";var ee=d(`brain-circuit`,[[`path`,{d:`M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z`,key:`l5xja`}],[`path`,{d:`M9 13a4.5 4.5 0 0 0 3-4`,key:`10igwf`}],[`path`,{d:`M6.003 5.125A3 3 0 0 0 6.401 6.5`,key:`105sqy`}],[`path`,{d:`M3.477 10.896a4 4 0 0 1 .585-.396`,key:`ql3yin`}],[`path`,{d:`M6 18a4 4 0 0 1-1.967-.516`,key:`2e4loj`}],[`path`,{d:`M12 13h4`,key:`1ku699`}],[`path`,{d:`M12 18h6a2 2 0 0 1 2 2v1`,key:`105ag5`}],[`path`,{d:`M12 8h8`,key:`1lhi5i`}],[`path`,{d:`M16 8V5a2 2 0 0 1 2-2`,key:`u6izg6`}],[`circle`,{cx:`16`,cy:`13`,r:`.5`,key:`ry7gng`}],[`circle`,{cx:`18`,cy:`3`,r:`.5`,key:`1aiba7`}],[`circle`,{cx:`20`,cy:`21`,r:`.5`,key:`yhc1fs`}],[`circle`,{cx:`20`,cy:`8`,r:`.5`,key:`1e43v0`}]]),te=d(`clock-3`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6h4`,key:`135r8i`}]]),v=d(`database-backup`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 12a9 3 0 0 0 5 2.69`,key:`1ui2ym`}],[`path`,{d:`M21 9.3V5`,key:`6k6cib`}],[`path`,{d:`M3 5v14a9 3 0 0 0 6.47 2.88`,key:`i62tjy`}],[`path`,{d:`M12 12v4h4`,key:`1bxaet`}],[`path`,{d:`M13 20a5 5 0 0 0 9-3 4.5 4.5 0 0 0-4.5-4.5c-1.33 0-2.54.54-3.41 1.41L12 16`,key:`1f4ei9`}]]),y=d(`folder-sync`,[[`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`}]]),b=e(t());function ne(e){return p(e).flatMap(e=>{let t=V(e,[`id`,`conversation_id`]);return t?[{id:t,title:V(e,[`title`,`summary`,`last_message`],t).trim(),messageCount:Math.max(0,Math.round(G(e,[`message_count`,`messages`]))),updatedAt:U(e,[`updated_at`,`updatedAt`,`created_at`,`createdAt`])}]:[]}).sort((e,t)=>(t.updatedAt??0)-(e.updatedAt??0))}function re(e){return p((B(e)?e:{}).messages).flatMap(e=>{let t=V(e,[`role`]),n=typeof e.content==`string`?e.content:``;return t!==`user`&&t!==`assistant`||!n.trim()?[]:[{role:t,content:n}]})}function ie(e,t,n){let r=V(e,[`id`]);if(r){let e=`brain.memoryTier.${r}`,n=f(t,e);if(n!==e)return n}return n}function ae(e,t,n=`ko`){let r=B(e)?e:{},i=(p(r.sources).length?p(r.sources):p(r.tiers)).map((e,t)=>({id:V(e,[`id`,`source`,`label`],`memory-${t}`),title:ie(e,n,V(e,[`title`,`label`,`source`,`path`,`name`],`Workspace memory`)),kind:H(e,[`type`,`source_type`,`kind`,`health`],`Memory`),tags:[],agentGenerated:!1})),a=p(r.recent_memories||r.recentMemories).map((e,t)=>{let n=B(e.metadata)?e.metadata:{},r=W(e,[`tags`]),i=V(e,[`content`,`summary`,`detail`]),a=V(n,[`source`]),o=r.includes(`agent-synthesis`)||a===`agent_runtime`||a===`agent_runtime_synthesis`;return{id:V(e,[`id`],`recent-memory-${t}`),title:i?i.replace(/\s+/g,` `).slice(0,96):H(e,[`kind`],`Memory`),kind:H(e,[`kind`],`Memory`),detail:i,tags:r,agentGenerated:o}}),o=p(t).map((e,t)=>({id:V(e,[`id`,`conversation_id`],`conversation-${t}`),title:V(e,[`title`,`summary`,`id`],`Conversation`),kind:`Conversation`,tags:[],agentGenerated:!1}));return R([...a,...i,...o]).slice(0,12)}function oe(e){let t=B(e)?e:{},n=p(t.nodes),r=p(t.edges),i=n.flatMap(e=>{let t=V(e,[`id`,`node_id`,`title`,`label`]);if(!t)return[];let n=B(e.metadata)?e.metadata:{},r=H(e,[`type`,`kind`,`category`],`Concept`),i=V(e,[`title`,`label`,`name`],t.replace(/^[^:]+:/,``)),a=V(e,[`summary`,`description`,`snippet`])||V(n,[`summary`,`description`,`relative_path`,`filename`]),o=h(G(e,[`importance_norm`,`importance`,`score`])||.5,.08,1),s=U(e,[`created_at`,`createdAt`,`added_at`,`addedAt`,`timestamp`,`updated_at`,`updatedAt`])??U(n,[`created_at`,`createdAt`,`added_at`,`addedAt`,`timestamp`,`updated_at`,`updatedAt`]);return[{id:t,label:i,type:r,summary:a,importance:o,...s===void 0?{}:{createdAt:s}}]}).sort((e,t)=>t.importance-e.importance),a=new Set(i.map(e=>e.id));return{nodes:i,edges:r.flatMap((e,t)=>{let n=V(e,[`from`,`source`,`source_id`]),r=V(e,[`to`,`target`,`target_id`]);return!n||!r||!a.has(n)||!a.has(r)?[]:[{id:V(e,[`id`],`edge-${t}`),source:n,target:r,label:H(e,[`type`,`label`,`relationship`],`Relates`),weight:G(e,[`weight`,`score`,`confidence`])||1}]})}}function se(e){let t=B(e)?e:{},n=[t,t.knowledge_graph,t.ingestion,t.result].filter(B),r=new Set,i=0,a,o;for(let e of n){let t=V(e,[`node_id`,`graph_node`,`graph_node_id`]);t&&r.add(t);for(let t of p(e.indexed_nodes))if(typeof t==`string`&&t.trim())r.add(t.trim());else if(B(t)){let e=V(t,[`node_id`,`graph_node_id`,`id`]);e&&r.add(e)}i=Math.max(i,G(e,[`chunk_count`,`chunks`,`indexed_count`])),typeof e.duplicate==`boolean`&&(a=e.duplicate),o||=V(e,[`provenance_id`])}let s;for(let e of n){let t=ce(e);if(t){s=t;break}}return{nodeIds:Array.from(r),chunkCount:i,...a===void 0?{}:{duplicate:a},...o?{provenanceId:o}:{},...s?{extraction:s}:{}}}function ce(e){let t=B(e)?e:{},n=B(t.extraction_quality)?t.extraction_quality:null;if(!n)return null;let r=V(n,[`level`]);if(r!==`high`&&r!==`medium`&&r!==`low`)return null;let i=W(t,[`warnings`]).length?W(t,[`warnings`]):W(n,[`warnings`]);return{score:G(n,[`score`]),level:r,reasons:W(n,[`reasons`]),warnings:i}}function le(e){let t=B(e)?e:{},n=B(t.context_quality)?t.context_quality:null,r=!n&&B(t.trace)&&B(t.trace.context_quality)?t.trace.context_quality:null,i=n||r||(typeof t.mode==`string`&&typeof t.limited==`boolean`?t:null);if(!i)return null;let a=V(i,[`mode`]);if(!a)return null;let o=typeof i.reason==`string`&&i.reason.trim()?i.reason.trim():null;return{mode:a,nodes:Math.max(0,Math.round(G(i,[`nodes`]))),limited:K(i,[`limited`],!1),reason:o}}function ue(e){let t=B(e)?e:{},n=(B(t.grounding)?t.grounding:null)||(typeof t.status==`string`&&`label`in t?t:null);if(!n)return null;let r=V(n,[`status`]);return[`supported`,`unsupported`,`no_context`].includes(r)?{status:r,reason:typeof n.reason==`string`&&n.reason.trim()?n.reason.trim():null}:null}function de(e){if(!B(e))return null;let t=V(e,[`type`]);if(t&&t!==`hybrid_context`)return null;let n=Array.isArray(e.node_ids)||Array.isArray(e.nodeIds);return t!==`hybrid_context`&&!n?null:{nodeIds:W(e,[`node_ids`,`nodeIds`]),keywords:W(e,[`keywords`])}}function fe(e){if(!B(e))return null;let t=V(e,[`type`]);return t&&t!==`hybrid_done`||t!==`hybrid_done`&&!(`answer`in e)&&!(`kg_expansion`in e)&&!(`kgExpansion`in e)?null:{answer:typeof e.answer==`string`?e.answer:``,provider:V(e,[`provider`]),model:V(e,[`model`]),sentNodeIds:W(e,[`sent_node_ids`,`sentNodeIds`]),expansion:pe(e.kg_expansion??e.kgExpansion)}}function pe(e){if(!B(e))return null;let t=V(e,[`status`]),n=B(e.plan)?e.plan:{},r=B(n.provenance)?n.provenance:{},i=G(e,[`candidate_count`,`candidateCount`]),a=G(r,[`candidate_count`,`candidateCount`]),o=Array.isArray(n.new_nodes)?n.new_nodes.length:0,s=Math.max(0,Math.round(i||a||o)),c=t===`staged`||t===`queued_for_review`||!!e.review_item_id;return{status:t||`staged`,candidateCount:s,stagedForReview:c}}function me(e,t=0){return{provider:e.provider,model:e.model,sentNodeCount:e.sentNodeIds.length||t,expansion:e.expansion}}function x(e){if(!B(e))return null;let t=V(e,[`status`]);if(t!==`ok`&&t!==`pending`&&t!==`failed`)return null;let n=V(e,[`detail`]);return{status:t,...n?{detail:n}:{}}}function he(e){let t=!!e.generation?.repaired,n=new Map;for(let t of e.artifacts||[])t&&typeof t.path==`string`&&n.set(t.path,!!t.previewable);let r=new Map,i=null;if(Array.isArray(e.brain_ingest))for(let t of e.brain_ingest){let e=x(t);e&&B(t)&&typeof t.path==`string`&&r.set(t.path,e)}else i=x(e.brain_ingest);let a=e.created_files||[];return a.map(e=>{let o=r.get(e.path)||(a.length===1?i:null);return{path:e.path,filename:e.filename||e.path.split(`/`).pop()||e.path,bytes:e.bytes||0,repaired:t,...n.has(e.path)?{previewable:n.get(e.path)}:{},...o?{brainIngest:o}:{}}})}function S(e){if(!B(e))return null;let t=V(e,[`phase`]),n=V(e,[`event`]);if(!t||!n)return null;let r=Number(e.step);return{phase:t,event:n,...V(e,[`action`])?{action:V(e,[`action`])}:{},...V(e,[`path`])?{path:V(e,[`path`])}:{},...Number.isFinite(r)?{step:Math.round(r)}:{},...typeof e.ok==`boolean`?{ok:e.ok}:{},...V(e,[`decision`])?{decision:V(e,[`decision`])}:{},...V(e,[`verdict`])?{verdict:V(e,[`verdict`])}:{},...V(e,[`state`])?{state:V(e,[`state`])}:{},...V(e,[`detail`,`error`])?{detail:V(e,[`detail`,`error`])}:{}}}function C(e){return p(e).flatMap(e=>{if(!B(e))return[];let t=V(e,[`action`,`tool`]),n=V(e,[`state`]),r=V(e,[`error`]);if(!t&&!n&&!r)return[];let i=V(B(e.args)?e.args:{},[`path`,`target`,`file`]);return t?[{phase:`execute`,event:`tool`,action:t,...i?{path:i}:{},ok:!r,...r?{detail:r}:{}}]:r?[{phase:`execute`,event:`state`,...n?{state:n}:{},ok:!1,detail:r}]:[{phase:`terminal`,event:`state`,state:n}]})}function w(e){if(!B(e))return null;let t={};if(B(e.repairs))for(let[n,r]of Object.entries(e.repairs)){let e=Number(r);Number.isFinite(e)&&e>0&&(t[n]=Math.round(e))}let n=Math.max(0,Math.round(G(e,[`parse_errors`,`parseErrors`]))),r=Math.max(0,Math.round(G(e,[`parse_recovered`,`parseRecovered`]))),i=Object.values(t).reduce((e,t)=>e+t,0)+r;return i<1?null:{repairs:t,parseErrors:n,parseRecovered:r,total:i}}function T(e,t){if(!B(e))return null;let n=e=>{if(!B(e))return``;let n=e[t];return typeof n==`string`?n:``},r=n(e.headline),i=p(e.details).map(n).filter(Boolean),a=V(e,[`code`]);if(!r&&!i.length)return null;let o=B(e.model_strain)?V(e.model_strain,[`level`]):``,s=o===`light`||o===`moderate`||o===`heavy`?o:`none`,c=e.ok===!0;return c&&!i.length?null:{code:a,ok:c,headline:r,details:i,strainLevel:s}}function E(e){return p((B(e)?e:{}).pending).flatMap(e=>{let t=V(e,[`run_id`,`runId`]);return t?[{runId:t,goal:V(e,[`goal`]),expiresAt:V(e,[`expires_at`,`expiresAt`])}]:[]})}function D(e){let t=B(e)?e:{},n=p(t.watches).flatMap(e=>{if(!B(e))return[];let t=V(e,[`id`]),n=V(e,[`path`]);if(!t&&!n)return[];let r=B(e.last_result)?e.last_result:null,i=p(e.last_errors).flatMap(e=>{if(typeof e==`string`&&e.trim())return[{path:``,detail:e.trim()}];if(!B(e))return[];let t=V(e,[`detail`,`reason`,`error`]),n=V(e,[`path`,`source`,`file`]);return!t&&!n?[]:[{path:n,detail:t}]});return[{id:t||n,path:n,enabled:K(e,[`enabled`],!1),lastScanAt:V(e,[`last_scan_at`,`lastScanAt`]),lastResult:r?{status:V(r,[`status`]),ingested:Math.max(0,Math.round(G(r,[`ingested`]))),failed:Math.max(0,Math.round(G(r,[`failed`])))}:null,trackedFiles:Math.max(0,Math.round(G(e,[`tracked_files`,`trackedFiles`]))),lastErrors:i.slice(0,3)}]});return{enabledCount:Math.max(0,Math.round(G(t,[`enabled_count`,`enabledCount`]))),polling:K(t,[`polling`],!1),intervalSeconds:Math.max(0,Math.round(G(t,[`interval_seconds`,`intervalSeconds`]))),watches:n}}function O(e){let t=B(e)?e:{};return{status:V(t,[`status`],`unavailable`),pendingItems:Math.max(0,Math.round(G(t,[`pending_items`,`pendingItems`]))),totalItems:Math.max(0,Math.round(G(t,[`total_items`,`totalItems`]))),detail:V(t,[`detail`])}}function k(e){return typeof e==`string`?e.trim():B(e)?[V(e,[`source`,`path`,`file`]),V(e,[`detail`,`reason`,`error`])].filter(Boolean).join(` — `):``}function A(e){return p((B(e)?e:{}).jobs).flatMap(e=>{let t=V(e,[`job_id`,`jobId`,`id`]);if(!t)return[];let n=V(e,[`created_at`,`createdAt`]),r=V(e,[`updated_at`,`updatedAt`]);return[{jobId:t,status:V(e,[`status`],`queued`),total:Math.max(0,Math.round(G(e,[`total`]))),processed:Math.max(0,Math.round(G(e,[`processed`]))),failed:Math.max(0,Math.round(G(e,[`failed`]))),errors:p(e.errors).map(k).filter(Boolean).slice(0,10),...n?{createdAt:n}:{},...r?{updatedAt:r}:{}}]})}function j(e,t){for(let n of[`recommended`,`cloud`,`loaded`,`loaded_models`,`models`])for(let r of p(e[n])){if(V(r,[`id`,`model_id`,`name`])!==t)continue;let e=V(r,[`display_name`,`model_name`,`name`]);if(e&&e!==t)return e}return``}function M(e){let t=B(e)?e:{},n=V(t,[`current`,`current_model`,`local_model`]);if(n)return j(t,n)||m(n);let r=p(t.loaded||t.loaded_models).find(e=>e.id||e.name||e.model_id);if(!r)return`local mind`;let i=V(r,[`display_name`,`model_name`,`name`]),a=V(r,[`id`,`model_id`]);return i&&i!==a?i:a?j(t,a)||m(a):`local mind`}function N(e){let t=B(e)?e:{};return V(t,[`current`,`current_model`,`local_model`])?!0:p(t.loaded||t.loaded_models).some(e=>e.id||e.name||e.model_id)}function P(e,t,n){let r=B(e)?e:{},i=B(r.brain_readiness)?r.brain_readiness:{},a=V(i,[`state`]),o=G(i,[`depth`]),s=G(i,[`score`]);if((a===`quiet`||a===`forming`||a===`alive`)&&ve(o)){let e=B(i.signals)?i.signals:{};return{score:h(Math.round(s||0),0,100),state:a,depth:o,titleKey:V(i,[`title_key`,`titleKey`],`brain.readiness.${a}`),actionKey:V(i,[`action_key`,`actionKey`],_e(a)),source:`memory_service`,signals:{memoryCount:G(e,[`memory_count`,`memoryCount`]),conceptCount:G(e,[`concept_count`,`conceptCount`]),relationshipCount:G(e,[`relationship_count`,`relationshipCount`]),healthySources:G(e,[`healthy_sources`,`healthySources`])}}}return ge(t,n)}function F(e,t=``){let n=B(e)&&typeof e.ok==`boolean`&&`data`in e?e:null;if(n&&!n.ok)return I(t);let r=n?n.data:e,i=B(r)?r:{},a=B(i.model_continuity)?i.model_continuity:{},o=B(i.proofs)?i.proofs:{},s=B(i.recall)?i.recall:{},c=B(i.claims)?i.claims:{},l=G(o,[`durable_items`,`durableItems`]);return{status:V(i,[`status`],`quiet`),modelContinuity:{activeModel:V(a,[`active_model`,`activeModel`],t),brainOwner:V(a,[`brain_owner`,`brainOwner`],`lattice_brain`),capability:K(a,[`capability`],!0),survivesModelSwitch:K(a,[`survives_model_switch`,`survivesModelSwitch`],!1),proven:K(a,[`proven`],!1),contextStore:V(a,[`context_store`,`contextStore`],`workspace + conversation + graph + vector`)},proofs:{durableItems:l,hasDurableEvidence:K(o,[`has_durable_evidence`,`hasDurableEvidence`],l>0),workspaceMemories:G(o,[`workspace_memories`,`workspaceMemories`]),conversations:G(o,[`conversations`]),graphConcepts:G(o,[`graph_concepts`,`graphConcepts`]),vectorItems:G(o,[`vector_items`,`vectorItems`]),healthySources:G(o,[`healthy_sources`,`healthySources`])},recall:{query:V(s,[`query`]),count:G(s,[`count`]),items:p(s.items).map((e,t)=>({id:V(e,[`id`],`recall-${t}`),source:H(e,[`source`],`Memory`),title:V(e,[`title`],`Memory`),snippet:V(e,[`snippet`]),score:G(e,[`score`]),matchedTerms:W(e,[`matched_terms`,`matchedTerms`]),confidence:be(e,G(e,[`score`])),locator:V(e,[`locator`]),kind:V(e,[`kind`]),caption:V(e,[`caption`]),thumbnail:ye(e)}))},claims:{canRecallUserContext:K(c,[`can_recall_user_context`,`canRecallUserContext`],!1),keepsContextAcrossModels:K(c,[`keeps_context_across_models`,`keepsContextAcrossModels`],!1),isKnowledgeStore:K(c,[`is_knowledge_store`,`isKnowledgeStore`],!1)}}}function I(e){return{status:`unavailable`,modelContinuity:{activeModel:e,brainOwner:``,capability:!1,survivesModelSwitch:!1,proven:!1,contextStore:``},proofs:{durableItems:0,hasDurableEvidence:!1,workspaceMemories:0,conversations:0,graphConcepts:0,vectorItems:0,healthySources:0},recall:{query:``,count:0,items:[]},claims:{canRecallUserContext:!1,keepsContextAcrossModels:!1,isKnowledgeStore:!1}}}function L(e){let t=B(e)?e:{},n=B(t.focus)?t.focus:{},r=p(t.next_actions||t.nextActions),i=p(t.suggested_questions||t.suggestedQuestions),a=p(t.proactive_actions||t.proactiveActions),o=p(t.evidence),s=r.length?r:[{id:`add_source`,label_key:`brain.brief.action.add`,detail_key:`brain.brief.action.add.detail`,route:`/capture`,priority:10},{id:`ask_brain`,label_key:`brain.brief.action.ask`,detail_key:`brain.brief.action.ask.detail`,route:``,priority:9}],c=o.length?o:[{id:`durable`,label_key:`brain.brief.evidence.durable`,value:0,detail_key:`brain.brief.evidence.durable.detail`},{id:`graph`,label_key:`brain.brief.evidence.graph`,value:0,detail_key:`brain.brief.evidence.graph.detail`},{id:`sources`,label_key:`brain.brief.evidence.sources`,value:0,detail_key:`brain.brief.evidence.sources.detail`}];return{status:V(t,[`status`],`quiet`),score:h(Math.round(G(t,[`score`])),0,100),headlineKey:V(t,[`headline_key`,`headlineKey`],`brain.brief.headline.quiet`),bodyKey:V(t,[`body_key`,`bodyKey`],`brain.brief.body.quiet`),focus:{kind:V(n,[`kind`],`empty`),title:V(n,[`title`]),detail:V(n,[`detail`]),source:H(n,[`source`],`Memory`),score:G(n,[`score`]),empty:K(n,[`empty`],!V(n,[`title`]))},nextActions:s.map(e=>({id:V(e,[`id`],`ask_brain`),labelKey:V(e,[`label_key`,`labelKey`],`brain.brief.action.ask`),detailKey:V(e,[`detail_key`,`detailKey`],`brain.brief.action.ask.detail`),route:V(e,[`route`]),priority:G(e,[`priority`])})),suggestedQuestions:i.map(e=>({id:V(e,[`id`],`suggested-question`),labelKey:V(e,[`label_key`,`labelKey`],`brain.suggestion.focus.label`),detailKey:V(e,[`detail_key`,`detailKey`],`brain.suggestion.focus.detail`),promptKey:V(e,[`prompt_key`,`promptKey`],`brain.suggestion.focus.prompt`),params:z(e.params),priority:G(e,[`priority`])})).sort((e,t)=>t.priority-e.priority),proactiveActions:a.map(e=>({id:V(e,[`id`],`proactive-action`),intent:V(e,[`intent`],`ask`),labelKey:V(e,[`label_key`,`labelKey`],`brain.proactive.evidence.label`),detailKey:V(e,[`detail_key`,`detailKey`],`brain.proactive.evidence.detail`),prompt:V(e,[`prompt`]),route:V(e,[`route`]),priority:G(e,[`priority`]),context:z(e.context)})).sort((e,t)=>t.priority-e.priority),evidence:c.map(e=>({id:V(e,[`id`],`evidence`),labelKey:V(e,[`label_key`,`labelKey`],`brain.brief.evidence.durable`),value:G(e,[`value`]),detailKey:V(e,[`detail_key`,`detailKey`],`brain.brief.evidence.durable.detail`)})),generatedAt:V(t,[`generated_at`,`generatedAt`])}}function R(e){let t=new Set;return e.filter(e=>t.has(e.id)?!1:(t.add(e.id),!0))}function z(e){return B(e)?Object.entries(e).reduce((e,[t,n])=>((typeof n==`string`||typeof n==`number`)&&(e[t]=n),e),{}):{}}function ge(e,t){let n=Math.min(100,Math.round(e*12+t*10));return e<1?{score:Math.max(12,n),state:`quiet`,depth:2,titleKey:`brain.readiness.quiet`,actionKey:`brain.readiness.start`,source:`frontend_fallback`,signals:{memoryCount:e,conceptCount:t,relationshipCount:0,healthySources:0}}:t<3?{score:Math.max(38,n),state:`forming`,depth:3,titleKey:`brain.readiness.forming`,actionKey:`brain.readiness.grow`,source:`frontend_fallback`,signals:{memoryCount:e,conceptCount:t,relationshipCount:0,healthySources:0}}:{score:Math.max(72,n),state:`alive`,depth:5,titleKey:`brain.readiness.alive`,actionKey:`brain.readiness.map`,source:`frontend_fallback`,signals:{memoryCount:e,conceptCount:t,relationshipCount:0,healthySources:0}}}function _e(e){return e===`quiet`?`brain.readiness.start`:e===`forming`?`brain.readiness.grow`:`brain.readiness.map`}function ve(e){return e>=1&&e<=5&&Number.isInteger(e)}var B=g;function V(e,t,n=``){for(let n of t){let t=e[n];if(typeof t==`string`&&t.trim())return t;if(typeof t==`number`&&Number.isFinite(t))return String(t)}return n}function H(e,t,n=``){return V(e,t,n).replace(/[_-]+/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function U(e,t){for(let n of t){let t=e[n];if(typeof t==`number`&&Number.isFinite(t))return t<0xe8d4a51000?t*1e3:t;if(typeof t==`string`&&t.trim()){let e=Number(t);if(Number.isFinite(e)&&/^\d+$/.test(t.trim()))return e<0xe8d4a51000?e*1e3:e;let n=Date.parse(t);if(Number.isFinite(n))return n}}}function W(e,t){for(let n of t){let t=e[n];if(Array.isArray(t))return t.filter(e=>typeof e==`string`&&e.trim().length>0)}return[]}function ye(e){let t=e.thumbnail;return typeof t==`string`&&t.startsWith(`data:image/`)?t:``}function be(e,t){let n=e.confidence;return n===`high`||n===`medium`||n===`low`?n:t>=.65?`high`:t>=.3?`medium`:`low`}function G(e,t){for(let n of t){let t=Number(e[n]);if(Number.isFinite(t))return t}return 0}function K(e,t,n){for(let n of t){let t=e[n];if(typeof t==`boolean`)return t}return n}var q=n();function J(){let e=l({queryKey:[`vectorFreshness`],queryFn:_.brainVectorFreshness,staleTime:6e4,refetchOnWindowFocus:!1,retry:!1});return b.useMemo(()=>e.data?.ok?O(e.data.data):null,[e.data])}function xe({language:e}){let t=r(),n=J(),a=i({mutationFn:()=>_.memoryRebuild(),onSuccess:async()=>{await t.invalidateQueries({queryKey:[`vectorFreshness`]})}});if(!n||n.status!==`stale_embedder`)return null;let o=a.isSuccess&&a.data&&!a.data.ok;return(0,q.jsxs)(`div`,{className:`brain-stale-embedder`,role:`status`,"data-testid":`stale-embedder-notice`,children:[(0,q.jsx)(u,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`strong`,{children:f(e,`brain.freshness.staleEmbedder`)}),(0,q.jsx)(`small`,{children:f(e,`brain.freshness.staleEmbedder.detail`)}),o?(0,q.jsx)(`small`,{className:`is-error`,children:f(e,`brain.freshness.reindex.failed`)}):null]}),(0,q.jsx)(`button`,{type:`button`,"data-testid":`stale-embedder-reindex`,disabled:a.isPending,onClick:()=>a.mutate(),children:f(e,a.isPending?`brain.freshness.reindex.running`:`brain.freshness.reindex`)})]})}function Se({language:e}){let t=J();return!t||t.status!==`pending`||t.pendingItems<1?null:(0,q.jsxs)(`p`,{className:`brain-freshness-chip`,role:`status`,"data-testid":`vector-freshness-chip`,children:[(0,q.jsx)(te,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),(0,q.jsx)(`span`,{children:f(e,`brain.freshness.pending`,{count:t.pendingItems})})]})}var Y=new Set([`queued`,`running`]),X=new Set([`failed`,`partial`]);function Z(e){return Y.has(e.status)}function Ce(e){return e===`queued`||e===`running`||e===`completed`||e===`failed`||e===`partial`?`brain.jobs.status.${e}`:`brain.jobs.status.queued`}var we=new Set([`completed`,`partial`]),Q=3;function Te({language:e,job:t,freshness:n,onDismiss:r}){let i=n&&n.totalItems>0&&(n.status===`ready`||n.status===`pending`)?Math.max(0,Math.min(100,Math.round((n.totalItems-n.pendingItems)/n.totalItems*100))):null,o=t.errors.slice(0,Q);return(0,q.jsxs)(`div`,{className:`brain-jobs-report lattice-success-pulse is-${t.status}`,role:`status`,"data-testid":`ingestion-job-report`,children:[(0,q.jsxs)(`div`,{className:`brain-jobs-report-head`,children:[(0,q.jsx)(a,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,q.jsx)(`strong`,{children:f(e,t.status===`partial`?`brain.jobs.report.titlePartial`:`brain.jobs.report.title`)}),r?(0,q.jsx)(`button`,{type:`button`,className:`brain-jobs-report-dismiss`,"aria-label":f(e,`brain.jobs.report.dismiss`),onClick:r,children:(0,q.jsx)(c,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})}):null]}),(0,q.jsxs)(`div`,{className:`brain-jobs-report-stats`,children:[t.processed>0?(0,q.jsx)(`span`,{className:`brain-jobs-report-stat`,children:f(e,`brain.jobs.report.documents`,{count:t.processed})}):null,t.failed>0?(0,q.jsx)(`span`,{className:`brain-jobs-report-stat is-failed`,children:f(e,`brain.jobs.failedCount`,{count:t.failed})}):null,i===null?null:(0,q.jsx)(`span`,{className:`brain-jobs-report-stat`,children:f(e,`brain.jobs.report.vector`,{percent:i})})]}),o.length?(0,q.jsxs)(`div`,{className:`brain-jobs-report-samples`,children:[(0,q.jsx)(`small`,{children:f(e,`brain.jobs.report.skipped`)}),(0,q.jsx)(`ul`,{children:o.map(e=>(0,q.jsx)(`li`,{children:e},e))})]}):null]})}function Ee({language:e}){let t=r(),n=J(),a=l({queryKey:[`ingestionJobs`],queryFn:_.ingestionJobs,refetchOnWindowFocus:!1,retry:!1,refetchInterval:e=>{let t=e.state.data;return t?.ok&&A(t.data).some(Z)?4e3:!1}}),o=i({mutationFn:e=>_.resumeIngestionJob(e),onSettled:()=>void t.invalidateQueries({queryKey:[`ingestionJobs`]})}),c=b.useMemo(()=>a.data?.ok?A(a.data.data):[],[a.data]),d=b.useRef(new Map),[p,m]=b.useState([]);b.useEffect(()=>{let e=d.current,t=[];for(let n of c){let r=e.get(n.jobId);r&&Y.has(r)&&we.has(n.status)&&t.push(n.jobId),e.set(n.jobId,n.status)}t.length&&m(e=>[...t,...e.filter(e=>!t.includes(e))].slice(0,2))},[c]);let h=p.map(e=>c.find(t=>t.jobId===e)).filter(e=>!!e),g=c.filter(e=>Z(e)||X.has(e.status)).slice(0,4);return!g.length&&!h.length?null:(0,q.jsxs)(`section`,{className:`brain-jobs-panel`,"aria-label":f(e,`brain.jobs.aria`),"data-testid":`ingestion-jobs-panel`,children:[h.map(t=>(0,q.jsx)(Te,{language:e,job:t,freshness:n,onDismiss:()=>m(e=>e.filter(e=>e!==t.jobId))},t.jobId)),g.length?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`header`,{className:`brain-jobs-head`,children:(0,q.jsx)(`strong`,{children:f(e,`brain.jobs.title`)})}),(0,q.jsx)(`ul`,{className:`brain-jobs-list`,children:g.map(t=>{let n=Math.max(t.total,t.processed,1),r=Math.min(100,Math.round(t.processed/n*100)),i=X.has(t.status),a=o.isPending&&o.variables===t.jobId;return(0,q.jsxs)(`li`,{className:`brain-jobs-item is-${t.status}`,children:[(0,q.jsxs)(`div`,{className:`brain-jobs-item-row`,children:[(0,q.jsx)(`span`,{className:`brain-jobs-status`,children:f(e,Ce(t.status))}),(0,q.jsx)(`span`,{className:`brain-jobs-counts`,children:f(e,`brain.jobs.progress`,{processed:t.processed,total:t.total})}),t.failed>0?(0,q.jsxs)(`span`,{className:`brain-jobs-failed`,children:[(0,q.jsx)(u,{className:`h-3 w-3`,"aria-hidden":`true`}),f(e,`brain.jobs.failedCount`,{count:t.failed})]}):null]}),(0,q.jsx)(`div`,{className:`brain-jobs-bar`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":r,"aria-label":f(e,`brain.jobs.progressAria`,{processed:t.processed,total:t.total}),children:(0,q.jsx)(`span`,{className:`brain-jobs-bar-fill`,style:{width:`${r}%`}})}),i?(0,q.jsxs)(`button`,{type:`button`,className:`brain-jobs-resume`,disabled:o.isPending,onClick:()=>o.mutate(t.jobId),children:[(0,q.jsx)(s,{className:`h-3 w-3`,"aria-hidden":`true`}),a?f(e,`brain.jobs.resuming`):f(e,`brain.jobs.resume`)]}):null]},t.jobId)})})]}):null]})}function $(e){return e.split(/[\\/]/).filter(Boolean).pop()||e}function De(e,t){if(!t)return f(e,`brain.watch.scan.never`);let n=Date.parse(t);if(!Number.isFinite(n))return f(e,`brain.watch.scan.never`);let r=Math.max(0,Date.now()-n),i=Math.floor(r/6e4);if(i<1)return f(e,`brain.watch.scan.now`);if(i<60)return f(e,`brain.watch.scan.minutes`,{count:i});let a=Math.floor(i/60);return a<24?f(e,`brain.watch.scan.hours`,{count:a}):f(e,`brain.watch.scan.days`,{count:Math.floor(a/24)})}var Oe=4;function ke({language:e}){let t=l({queryKey:[`ingestionWatch`],queryFn:_.ingestionWatchStatus,staleTime:3e4,refetchOnWindowFocus:!1,retry:!1}),n=b.useMemo(()=>t.data?.ok?D(t.data.data):null,[t.data]);if(!n||n.enabledCount<1)return null;let r=n.watches.filter(e=>e.enabled).slice(0,Oe);return r.length?(0,q.jsxs)(`section`,{className:`brain-watch-card`,"aria-label":f(e,`brain.watch.aria`),"data-testid":`watch-health-card`,children:[(0,q.jsxs)(`header`,{className:`brain-watch-head`,children:[(0,q.jsx)(y,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),(0,q.jsx)(`strong`,{children:f(e,`brain.watch.title`)})]}),n.polling?null:(0,q.jsxs)(`p`,{className:`brain-watch-note`,role:`note`,"data-testid":`watch-polling-note`,children:[(0,q.jsx)(o,{className:`h-3 w-3`,"aria-hidden":`true`}),f(e,`brain.watch.notLive`)]}),(0,q.jsx)(`ul`,{className:`brain-watch-list`,children:r.map(t=>(0,q.jsx)(Ae,{language:e,watch:t},t.id))})]}):null}function Ae({language:e,watch:t}){return(0,q.jsxs)(`li`,{className:`brain-watch-item`,children:[(0,q.jsxs)(`div`,{className:`brain-watch-item-row`,children:[(0,q.jsx)(`span`,{className:`brain-watch-path`,title:t.path,children:$(t.path)}),(0,q.jsx)(`small`,{className:`brain-watch-scan`,children:De(e,t.lastScanAt)})]}),(0,q.jsxs)(`div`,{className:`brain-watch-item-row`,children:[t.lastResult&&t.lastResult.ingested>0?(0,q.jsx)(`span`,{className:`brain-watch-stat`,children:f(e,`brain.watch.ingested`,{count:t.lastResult.ingested})}):null,t.lastResult&&t.lastResult.failed>0?(0,q.jsxs)(`span`,{className:`brain-watch-stat is-failed`,children:[(0,q.jsx)(u,{className:`h-3 w-3`,"aria-hidden":`true`}),f(e,`brain.jobs.failedCount`,{count:t.lastResult.failed})]}):null,t.trackedFiles>0?(0,q.jsx)(`small`,{className:`brain-watch-tracked`,children:f(e,`brain.watch.tracked`,{count:t.trackedFiles})}):null]}),t.lastErrors.length?(0,q.jsxs)(`div`,{className:`brain-watch-errors`,children:[(0,q.jsx)(`small`,{children:f(e,`brain.watch.errors`)}),(0,q.jsx)(`ul`,{children:t.lastErrors.slice(0,3).map((e,t)=>(0,q.jsx)(`li`,{children:[e.path?$(e.path):``,e.detail].filter(Boolean).join(` — `)},`${e.path}-${t}`))})]}):null]})}function je(e,t){if(!t)return``;let n=new Date(t);return Number.isNaN(n.getTime())?``:n.toLocaleTimeString(e===`ko`?`ko-KR`:`en-US`,{hour:`2-digit`,minute:`2-digit`})}function Me({language:e,knownRunIds:t}){let n=l({queryKey:[`agentApprovals`],queryFn:_.agentApprovals,staleTime:1/0,refetchOnWindowFocus:!1,retry:!1}),r=b.useMemo(()=>n.data?.ok?E(n.data.data):[],[n.data]),i=b.useMemo(()=>new Set(t),[t]),a=r.filter(e=>!i.has(e.runId));return a.length?(0,q.jsx)(`aside`,{className:`brain-pending-approvals`,role:`note`,"aria-label":f(e,`brain.approval.pendingNotice.aria`),"data-testid":`pending-approvals-notice`,children:a.slice(0,2).map(t=>{let n=je(e,t.expiresAt);return(0,q.jsxs)(`p`,{children:[(0,q.jsx)(`span`,{children:t.goal?f(e,`brain.approval.pendingNotice`,{goal:t.goal}):f(e,`brain.approval.pendingNotice.generic`)}),(0,q.jsx)(`small`,{children:n?f(e,`brain.approval.pendingNotice.expiry`,{time:n}):f(e,`brain.approval.pendingNotice.hint`)})]},t.runId)})}):null}export{fe as C,V as D,T as E,v as O,de as S,w as T,S as _,ke as a,re as b,F as c,ae as d,me as f,B as g,N as h,Se as i,ee as k,P as l,se as m,Me as n,he as o,M as p,xe as r,L as s,Ee as t,ne as u,C as v,oe as w,ue as x,le as y};
1
+ import{i as e,n as t,t as n}from"./jsx-runtime-bzQ4Vb5N.js";import{n as r}from"./QueryClientProvider-B3OjqSyJ.js";import{t as i}from"./useMutation-B8QKq2NW.js";import{t as a}from"./circle-check-BxaDWjPR.js";import{t as o}from"./circle-pause-918Kuvk0.js";import{A as s,E as c,H as l,O as u,R as d,S as f,c as p,f as m,l as h,p as g,v as _}from"./index-CfeqZ9Ri.js";var ee=d(`brain-circuit`,[[`path`,{d:`M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z`,key:`l5xja`}],[`path`,{d:`M9 13a4.5 4.5 0 0 0 3-4`,key:`10igwf`}],[`path`,{d:`M6.003 5.125A3 3 0 0 0 6.401 6.5`,key:`105sqy`}],[`path`,{d:`M3.477 10.896a4 4 0 0 1 .585-.396`,key:`ql3yin`}],[`path`,{d:`M6 18a4 4 0 0 1-1.967-.516`,key:`2e4loj`}],[`path`,{d:`M12 13h4`,key:`1ku699`}],[`path`,{d:`M12 18h6a2 2 0 0 1 2 2v1`,key:`105ag5`}],[`path`,{d:`M12 8h8`,key:`1lhi5i`}],[`path`,{d:`M16 8V5a2 2 0 0 1 2-2`,key:`u6izg6`}],[`circle`,{cx:`16`,cy:`13`,r:`.5`,key:`ry7gng`}],[`circle`,{cx:`18`,cy:`3`,r:`.5`,key:`1aiba7`}],[`circle`,{cx:`20`,cy:`21`,r:`.5`,key:`yhc1fs`}],[`circle`,{cx:`20`,cy:`8`,r:`.5`,key:`1e43v0`}]]),te=d(`clock-3`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6h4`,key:`135r8i`}]]),v=d(`database-backup`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 12a9 3 0 0 0 5 2.69`,key:`1ui2ym`}],[`path`,{d:`M21 9.3V5`,key:`6k6cib`}],[`path`,{d:`M3 5v14a9 3 0 0 0 6.47 2.88`,key:`i62tjy`}],[`path`,{d:`M12 12v4h4`,key:`1bxaet`}],[`path`,{d:`M13 20a5 5 0 0 0 9-3 4.5 4.5 0 0 0-4.5-4.5c-1.33 0-2.54.54-3.41 1.41L12 16`,key:`1f4ei9`}]]),y=d(`folder-sync`,[[`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`}]]),b=e(t());function ne(e){return p(e).flatMap(e=>{let t=V(e,[`id`,`conversation_id`]);return t?[{id:t,title:V(e,[`title`,`summary`,`last_message`],t).trim(),messageCount:Math.max(0,Math.round(G(e,[`message_count`,`messages`]))),updatedAt:U(e,[`updated_at`,`updatedAt`,`created_at`,`createdAt`])}]:[]}).sort((e,t)=>(t.updatedAt??0)-(e.updatedAt??0))}function re(e){return p((B(e)?e:{}).messages).flatMap(e=>{let t=V(e,[`role`]),n=typeof e.content==`string`?e.content:``;return t!==`user`&&t!==`assistant`||!n.trim()?[]:[{role:t,content:n}]})}function ie(e,t,n){let r=V(e,[`id`]);if(r){let e=`brain.memoryTier.${r}`,n=f(t,e);if(n!==e)return n}return n}function ae(e,t,n=`ko`){let r=B(e)?e:{},i=(p(r.sources).length?p(r.sources):p(r.tiers)).map((e,t)=>({id:V(e,[`id`,`source`,`label`],`memory-${t}`),title:ie(e,n,V(e,[`title`,`label`,`source`,`path`,`name`],`Workspace memory`)),kind:H(e,[`type`,`source_type`,`kind`,`health`],`Memory`),tags:[],agentGenerated:!1})),a=p(r.recent_memories||r.recentMemories).map((e,t)=>{let n=B(e.metadata)?e.metadata:{},r=W(e,[`tags`]),i=V(e,[`content`,`summary`,`detail`]),a=V(n,[`source`]),o=r.includes(`agent-synthesis`)||a===`agent_runtime`||a===`agent_runtime_synthesis`;return{id:V(e,[`id`],`recent-memory-${t}`),title:i?i.replace(/\s+/g,` `).slice(0,96):H(e,[`kind`],`Memory`),kind:H(e,[`kind`],`Memory`),detail:i,tags:r,agentGenerated:o}}),o=p(t).map((e,t)=>({id:V(e,[`id`,`conversation_id`],`conversation-${t}`),title:V(e,[`title`,`summary`,`id`],`Conversation`),kind:`Conversation`,tags:[],agentGenerated:!1}));return R([...a,...i,...o]).slice(0,12)}function oe(e){let t=B(e)?e:{},n=p(t.nodes),r=p(t.edges),i=n.flatMap(e=>{let t=V(e,[`id`,`node_id`,`title`,`label`]);if(!t)return[];let n=B(e.metadata)?e.metadata:{},r=H(e,[`type`,`kind`,`category`],`Concept`),i=V(e,[`title`,`label`,`name`],t.replace(/^[^:]+:/,``)),a=V(e,[`summary`,`description`,`snippet`])||V(n,[`summary`,`description`,`relative_path`,`filename`]),o=h(G(e,[`importance_norm`,`importance`,`score`])||.5,.08,1),s=U(e,[`created_at`,`createdAt`,`added_at`,`addedAt`,`timestamp`,`updated_at`,`updatedAt`])??U(n,[`created_at`,`createdAt`,`added_at`,`addedAt`,`timestamp`,`updated_at`,`updatedAt`]);return[{id:t,label:i,type:r,summary:a,importance:o,...s===void 0?{}:{createdAt:s}}]}).sort((e,t)=>t.importance-e.importance),a=new Set(i.map(e=>e.id));return{nodes:i,edges:r.flatMap((e,t)=>{let n=V(e,[`from`,`source`,`source_id`]),r=V(e,[`to`,`target`,`target_id`]);return!n||!r||!a.has(n)||!a.has(r)?[]:[{id:V(e,[`id`],`edge-${t}`),source:n,target:r,label:H(e,[`type`,`label`,`relationship`],`Relates`),weight:G(e,[`weight`,`score`,`confidence`])||1}]})}}function se(e){let t=B(e)?e:{},n=[t,t.knowledge_graph,t.ingestion,t.result].filter(B),r=new Set,i=0,a,o;for(let e of n){let t=V(e,[`node_id`,`graph_node`,`graph_node_id`]);t&&r.add(t);for(let t of p(e.indexed_nodes))if(typeof t==`string`&&t.trim())r.add(t.trim());else if(B(t)){let e=V(t,[`node_id`,`graph_node_id`,`id`]);e&&r.add(e)}i=Math.max(i,G(e,[`chunk_count`,`chunks`,`indexed_count`])),typeof e.duplicate==`boolean`&&(a=e.duplicate),o||=V(e,[`provenance_id`])}let s;for(let e of n){let t=ce(e);if(t){s=t;break}}return{nodeIds:Array.from(r),chunkCount:i,...a===void 0?{}:{duplicate:a},...o?{provenanceId:o}:{},...s?{extraction:s}:{}}}function ce(e){let t=B(e)?e:{},n=B(t.extraction_quality)?t.extraction_quality:null;if(!n)return null;let r=V(n,[`level`]);if(r!==`high`&&r!==`medium`&&r!==`low`)return null;let i=W(t,[`warnings`]).length?W(t,[`warnings`]):W(n,[`warnings`]);return{score:G(n,[`score`]),level:r,reasons:W(n,[`reasons`]),warnings:i}}function le(e){let t=B(e)?e:{},n=B(t.context_quality)?t.context_quality:null,r=!n&&B(t.trace)&&B(t.trace.context_quality)?t.trace.context_quality:null,i=n||r||(typeof t.mode==`string`&&typeof t.limited==`boolean`?t:null);if(!i)return null;let a=V(i,[`mode`]);if(!a)return null;let o=typeof i.reason==`string`&&i.reason.trim()?i.reason.trim():null;return{mode:a,nodes:Math.max(0,Math.round(G(i,[`nodes`]))),limited:K(i,[`limited`],!1),reason:o}}function ue(e){let t=B(e)?e:{},n=(B(t.grounding)?t.grounding:null)||(typeof t.status==`string`&&`label`in t?t:null);if(!n)return null;let r=V(n,[`status`]);return[`supported`,`unsupported`,`no_context`].includes(r)?{status:r,reason:typeof n.reason==`string`&&n.reason.trim()?n.reason.trim():null}:null}function de(e){if(!B(e))return null;let t=V(e,[`type`]);if(t&&t!==`hybrid_context`)return null;let n=Array.isArray(e.node_ids)||Array.isArray(e.nodeIds);return t!==`hybrid_context`&&!n?null:{nodeIds:W(e,[`node_ids`,`nodeIds`]),keywords:W(e,[`keywords`])}}function fe(e){if(!B(e))return null;let t=V(e,[`type`]);return t&&t!==`hybrid_done`||t!==`hybrid_done`&&!(`answer`in e)&&!(`kg_expansion`in e)&&!(`kgExpansion`in e)?null:{answer:typeof e.answer==`string`?e.answer:``,provider:V(e,[`provider`]),model:V(e,[`model`]),sentNodeIds:W(e,[`sent_node_ids`,`sentNodeIds`]),expansion:pe(e.kg_expansion??e.kgExpansion)}}function pe(e){if(!B(e))return null;let t=V(e,[`status`]),n=B(e.plan)?e.plan:{},r=B(n.provenance)?n.provenance:{},i=G(e,[`candidate_count`,`candidateCount`]),a=G(r,[`candidate_count`,`candidateCount`]),o=Array.isArray(n.new_nodes)?n.new_nodes.length:0,s=Math.max(0,Math.round(i||a||o)),c=t===`staged`||t===`queued_for_review`||!!e.review_item_id;return{status:t||`staged`,candidateCount:s,stagedForReview:c}}function me(e,t=0){return{provider:e.provider,model:e.model,sentNodeCount:e.sentNodeIds.length||t,expansion:e.expansion}}function x(e){if(!B(e))return null;let t=V(e,[`status`]);if(t!==`ok`&&t!==`pending`&&t!==`failed`)return null;let n=V(e,[`detail`]);return{status:t,...n?{detail:n}:{}}}function he(e){let t=!!e.generation?.repaired,n=new Map;for(let t of e.artifacts||[])t&&typeof t.path==`string`&&n.set(t.path,!!t.previewable);let r=new Map,i=null;if(Array.isArray(e.brain_ingest))for(let t of e.brain_ingest){let e=x(t);e&&B(t)&&typeof t.path==`string`&&r.set(t.path,e)}else i=x(e.brain_ingest);let a=e.created_files||[];return a.map(e=>{let o=r.get(e.path)||(a.length===1?i:null);return{path:e.path,filename:e.filename||e.path.split(`/`).pop()||e.path,bytes:e.bytes||0,repaired:t,...n.has(e.path)?{previewable:n.get(e.path)}:{},...o?{brainIngest:o}:{}}})}function S(e){if(!B(e))return null;let t=V(e,[`phase`]),n=V(e,[`event`]);if(!t||!n)return null;let r=Number(e.step);return{phase:t,event:n,...V(e,[`action`])?{action:V(e,[`action`])}:{},...V(e,[`path`])?{path:V(e,[`path`])}:{},...Number.isFinite(r)?{step:Math.round(r)}:{},...typeof e.ok==`boolean`?{ok:e.ok}:{},...V(e,[`decision`])?{decision:V(e,[`decision`])}:{},...V(e,[`verdict`])?{verdict:V(e,[`verdict`])}:{},...V(e,[`state`])?{state:V(e,[`state`])}:{},...V(e,[`detail`,`error`])?{detail:V(e,[`detail`,`error`])}:{}}}function C(e){return p(e).flatMap(e=>{if(!B(e))return[];let t=V(e,[`action`,`tool`]),n=V(e,[`state`]),r=V(e,[`error`]);if(!t&&!n&&!r)return[];let i=V(B(e.args)?e.args:{},[`path`,`target`,`file`]);return t?[{phase:`execute`,event:`tool`,action:t,...i?{path:i}:{},ok:!r,...r?{detail:r}:{}}]:r?[{phase:`execute`,event:`state`,...n?{state:n}:{},ok:!1,detail:r}]:[{phase:`terminal`,event:`state`,state:n}]})}function w(e){if(!B(e))return null;let t={};if(B(e.repairs))for(let[n,r]of Object.entries(e.repairs)){let e=Number(r);Number.isFinite(e)&&e>0&&(t[n]=Math.round(e))}let n=Math.max(0,Math.round(G(e,[`parse_errors`,`parseErrors`]))),r=Math.max(0,Math.round(G(e,[`parse_recovered`,`parseRecovered`]))),i=Object.values(t).reduce((e,t)=>e+t,0)+r;return i<1?null:{repairs:t,parseErrors:n,parseRecovered:r,total:i}}function T(e,t){if(!B(e))return null;let n=e=>{if(!B(e))return``;let n=e[t];return typeof n==`string`?n:``},r=n(e.headline),i=p(e.details).map(n).filter(Boolean),a=V(e,[`code`]);if(!r&&!i.length)return null;let o=B(e.model_strain)?V(e.model_strain,[`level`]):``,s=o===`light`||o===`moderate`||o===`heavy`?o:`none`,c=e.ok===!0;return c&&!i.length?null:{code:a,ok:c,headline:r,details:i,strainLevel:s}}function E(e){return p((B(e)?e:{}).pending).flatMap(e=>{let t=V(e,[`run_id`,`runId`]);return t?[{runId:t,goal:V(e,[`goal`]),expiresAt:V(e,[`expires_at`,`expiresAt`])}]:[]})}function D(e){let t=B(e)?e:{},n=p(t.watches).flatMap(e=>{if(!B(e))return[];let t=V(e,[`id`]),n=V(e,[`path`]);if(!t&&!n)return[];let r=B(e.last_result)?e.last_result:null,i=p(e.last_errors).flatMap(e=>{if(typeof e==`string`&&e.trim())return[{path:``,detail:e.trim()}];if(!B(e))return[];let t=V(e,[`detail`,`reason`,`error`]),n=V(e,[`path`,`source`,`file`]);return!t&&!n?[]:[{path:n,detail:t}]});return[{id:t||n,path:n,enabled:K(e,[`enabled`],!1),lastScanAt:V(e,[`last_scan_at`,`lastScanAt`]),lastResult:r?{status:V(r,[`status`]),ingested:Math.max(0,Math.round(G(r,[`ingested`]))),failed:Math.max(0,Math.round(G(r,[`failed`])))}:null,trackedFiles:Math.max(0,Math.round(G(e,[`tracked_files`,`trackedFiles`]))),lastErrors:i.slice(0,3)}]});return{enabledCount:Math.max(0,Math.round(G(t,[`enabled_count`,`enabledCount`]))),polling:K(t,[`polling`],!1),intervalSeconds:Math.max(0,Math.round(G(t,[`interval_seconds`,`intervalSeconds`]))),watches:n}}function O(e){let t=B(e)?e:{};return{status:V(t,[`status`],`unavailable`),pendingItems:Math.max(0,Math.round(G(t,[`pending_items`,`pendingItems`]))),totalItems:Math.max(0,Math.round(G(t,[`total_items`,`totalItems`]))),detail:V(t,[`detail`])}}function k(e){return typeof e==`string`?e.trim():B(e)?[V(e,[`source`,`path`,`file`]),V(e,[`detail`,`reason`,`error`])].filter(Boolean).join(` — `):``}function A(e){return p((B(e)?e:{}).jobs).flatMap(e=>{let t=V(e,[`job_id`,`jobId`,`id`]);if(!t)return[];let n=V(e,[`created_at`,`createdAt`]),r=V(e,[`updated_at`,`updatedAt`]);return[{jobId:t,status:V(e,[`status`],`queued`),total:Math.max(0,Math.round(G(e,[`total`]))),processed:Math.max(0,Math.round(G(e,[`processed`]))),failed:Math.max(0,Math.round(G(e,[`failed`]))),errors:p(e.errors).map(k).filter(Boolean).slice(0,10),...n?{createdAt:n}:{},...r?{updatedAt:r}:{}}]})}function j(e,t){for(let n of[`recommended`,`cloud`,`loaded`,`loaded_models`,`models`])for(let r of p(e[n])){if(V(r,[`id`,`model_id`,`name`])!==t)continue;let e=V(r,[`display_name`,`model_name`,`name`]);if(e&&e!==t)return e}return``}function M(e){let t=B(e)?e:{},n=V(t,[`current`,`current_model`,`local_model`]);if(n)return j(t,n)||m(n);let r=p(t.loaded||t.loaded_models).find(e=>e.id||e.name||e.model_id);if(!r)return`local mind`;let i=V(r,[`display_name`,`model_name`,`name`]),a=V(r,[`id`,`model_id`]);return i&&i!==a?i:a?j(t,a)||m(a):`local mind`}function N(e){let t=B(e)?e:{};return V(t,[`current`,`current_model`,`local_model`])?!0:p(t.loaded||t.loaded_models).some(e=>e.id||e.name||e.model_id)}function P(e,t,n){let r=B(e)?e:{},i=B(r.brain_readiness)?r.brain_readiness:{},a=V(i,[`state`]),o=G(i,[`depth`]),s=G(i,[`score`]);if((a===`quiet`||a===`forming`||a===`alive`)&&ve(o)){let e=B(i.signals)?i.signals:{};return{score:h(Math.round(s||0),0,100),state:a,depth:o,titleKey:V(i,[`title_key`,`titleKey`],`brain.readiness.${a}`),actionKey:V(i,[`action_key`,`actionKey`],_e(a)),source:`memory_service`,signals:{memoryCount:G(e,[`memory_count`,`memoryCount`]),conceptCount:G(e,[`concept_count`,`conceptCount`]),relationshipCount:G(e,[`relationship_count`,`relationshipCount`]),healthySources:G(e,[`healthy_sources`,`healthySources`])}}}return ge(t,n)}function F(e,t=``){let n=B(e)&&typeof e.ok==`boolean`&&`data`in e?e:null;if(n&&!n.ok)return I(t);let r=n?n.data:e,i=B(r)?r:{},a=B(i.model_continuity)?i.model_continuity:{},o=B(i.proofs)?i.proofs:{},s=B(i.recall)?i.recall:{},c=B(i.claims)?i.claims:{},l=G(o,[`durable_items`,`durableItems`]);return{status:V(i,[`status`],`quiet`),modelContinuity:{activeModel:V(a,[`active_model`,`activeModel`],t),brainOwner:V(a,[`brain_owner`,`brainOwner`],`lattice_brain`),capability:K(a,[`capability`],!0),survivesModelSwitch:K(a,[`survives_model_switch`,`survivesModelSwitch`],!1),proven:K(a,[`proven`],!1),contextStore:V(a,[`context_store`,`contextStore`],`workspace + conversation + graph + vector`)},proofs:{durableItems:l,hasDurableEvidence:K(o,[`has_durable_evidence`,`hasDurableEvidence`],l>0),workspaceMemories:G(o,[`workspace_memories`,`workspaceMemories`]),conversations:G(o,[`conversations`]),graphConcepts:G(o,[`graph_concepts`,`graphConcepts`]),vectorItems:G(o,[`vector_items`,`vectorItems`]),healthySources:G(o,[`healthy_sources`,`healthySources`])},recall:{query:V(s,[`query`]),count:G(s,[`count`]),items:p(s.items).map((e,t)=>({id:V(e,[`id`],`recall-${t}`),source:H(e,[`source`],`Memory`),title:V(e,[`title`],`Memory`),snippet:V(e,[`snippet`]),score:G(e,[`score`]),matchedTerms:W(e,[`matched_terms`,`matchedTerms`]),confidence:be(e,G(e,[`score`])),locator:V(e,[`locator`]),kind:V(e,[`kind`]),caption:V(e,[`caption`]),thumbnail:ye(e)}))},claims:{canRecallUserContext:K(c,[`can_recall_user_context`,`canRecallUserContext`],!1),keepsContextAcrossModels:K(c,[`keeps_context_across_models`,`keepsContextAcrossModels`],!1),isKnowledgeStore:K(c,[`is_knowledge_store`,`isKnowledgeStore`],!1)}}}function I(e){return{status:`unavailable`,modelContinuity:{activeModel:e,brainOwner:``,capability:!1,survivesModelSwitch:!1,proven:!1,contextStore:``},proofs:{durableItems:0,hasDurableEvidence:!1,workspaceMemories:0,conversations:0,graphConcepts:0,vectorItems:0,healthySources:0},recall:{query:``,count:0,items:[]},claims:{canRecallUserContext:!1,keepsContextAcrossModels:!1,isKnowledgeStore:!1}}}function L(e){let t=B(e)?e:{},n=B(t.focus)?t.focus:{},r=p(t.next_actions||t.nextActions),i=p(t.suggested_questions||t.suggestedQuestions),a=p(t.proactive_actions||t.proactiveActions),o=p(t.evidence),s=r.length?r:[{id:`add_source`,label_key:`brain.brief.action.add`,detail_key:`brain.brief.action.add.detail`,route:`/capture`,priority:10},{id:`ask_brain`,label_key:`brain.brief.action.ask`,detail_key:`brain.brief.action.ask.detail`,route:``,priority:9}],c=o.length?o:[{id:`durable`,label_key:`brain.brief.evidence.durable`,value:0,detail_key:`brain.brief.evidence.durable.detail`},{id:`graph`,label_key:`brain.brief.evidence.graph`,value:0,detail_key:`brain.brief.evidence.graph.detail`},{id:`sources`,label_key:`brain.brief.evidence.sources`,value:0,detail_key:`brain.brief.evidence.sources.detail`}];return{status:V(t,[`status`],`quiet`),score:h(Math.round(G(t,[`score`])),0,100),headlineKey:V(t,[`headline_key`,`headlineKey`],`brain.brief.headline.quiet`),bodyKey:V(t,[`body_key`,`bodyKey`],`brain.brief.body.quiet`),focus:{kind:V(n,[`kind`],`empty`),title:V(n,[`title`]),detail:V(n,[`detail`]),source:H(n,[`source`],`Memory`),score:G(n,[`score`]),empty:K(n,[`empty`],!V(n,[`title`]))},nextActions:s.map(e=>({id:V(e,[`id`],`ask_brain`),labelKey:V(e,[`label_key`,`labelKey`],`brain.brief.action.ask`),detailKey:V(e,[`detail_key`,`detailKey`],`brain.brief.action.ask.detail`),route:V(e,[`route`]),priority:G(e,[`priority`])})),suggestedQuestions:i.map(e=>({id:V(e,[`id`],`suggested-question`),labelKey:V(e,[`label_key`,`labelKey`],`brain.suggestion.focus.label`),detailKey:V(e,[`detail_key`,`detailKey`],`brain.suggestion.focus.detail`),promptKey:V(e,[`prompt_key`,`promptKey`],`brain.suggestion.focus.prompt`),params:z(e.params),priority:G(e,[`priority`])})).sort((e,t)=>t.priority-e.priority),proactiveActions:a.map(e=>({id:V(e,[`id`],`proactive-action`),intent:V(e,[`intent`],`ask`),labelKey:V(e,[`label_key`,`labelKey`],`brain.proactive.evidence.label`),detailKey:V(e,[`detail_key`,`detailKey`],`brain.proactive.evidence.detail`),prompt:V(e,[`prompt`]),route:V(e,[`route`]),priority:G(e,[`priority`]),context:z(e.context)})).sort((e,t)=>t.priority-e.priority),evidence:c.map(e=>({id:V(e,[`id`],`evidence`),labelKey:V(e,[`label_key`,`labelKey`],`brain.brief.evidence.durable`),value:G(e,[`value`]),detailKey:V(e,[`detail_key`,`detailKey`],`brain.brief.evidence.durable.detail`)})),generatedAt:V(t,[`generated_at`,`generatedAt`])}}function R(e){let t=new Set;return e.filter(e=>t.has(e.id)?!1:(t.add(e.id),!0))}function z(e){return B(e)?Object.entries(e).reduce((e,[t,n])=>((typeof n==`string`||typeof n==`number`)&&(e[t]=n),e),{}):{}}function ge(e,t){let n=Math.min(100,Math.round(e*12+t*10));return e<1?{score:Math.max(12,n),state:`quiet`,depth:2,titleKey:`brain.readiness.quiet`,actionKey:`brain.readiness.start`,source:`frontend_fallback`,signals:{memoryCount:e,conceptCount:t,relationshipCount:0,healthySources:0}}:t<3?{score:Math.max(38,n),state:`forming`,depth:3,titleKey:`brain.readiness.forming`,actionKey:`brain.readiness.grow`,source:`frontend_fallback`,signals:{memoryCount:e,conceptCount:t,relationshipCount:0,healthySources:0}}:{score:Math.max(72,n),state:`alive`,depth:5,titleKey:`brain.readiness.alive`,actionKey:`brain.readiness.map`,source:`frontend_fallback`,signals:{memoryCount:e,conceptCount:t,relationshipCount:0,healthySources:0}}}function _e(e){return e===`quiet`?`brain.readiness.start`:e===`forming`?`brain.readiness.grow`:`brain.readiness.map`}function ve(e){return e>=1&&e<=5&&Number.isInteger(e)}var B=g;function V(e,t,n=``){for(let n of t){let t=e[n];if(typeof t==`string`&&t.trim())return t;if(typeof t==`number`&&Number.isFinite(t))return String(t)}return n}function H(e,t,n=``){return V(e,t,n).replace(/[_-]+/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function U(e,t){for(let n of t){let t=e[n];if(typeof t==`number`&&Number.isFinite(t))return t<0xe8d4a51000?t*1e3:t;if(typeof t==`string`&&t.trim()){let e=Number(t);if(Number.isFinite(e)&&/^\d+$/.test(t.trim()))return e<0xe8d4a51000?e*1e3:e;let n=Date.parse(t);if(Number.isFinite(n))return n}}}function W(e,t){for(let n of t){let t=e[n];if(Array.isArray(t))return t.filter(e=>typeof e==`string`&&e.trim().length>0)}return[]}function ye(e){let t=e.thumbnail;return typeof t==`string`&&t.startsWith(`data:image/`)?t:``}function be(e,t){let n=e.confidence;return n===`high`||n===`medium`||n===`low`?n:t>=.65?`high`:t>=.3?`medium`:`low`}function G(e,t){for(let n of t){let t=Number(e[n]);if(Number.isFinite(t))return t}return 0}function K(e,t,n){for(let n of t){let t=e[n];if(typeof t==`boolean`)return t}return n}var q=n();function J(){let e=l({queryKey:[`vectorFreshness`],queryFn:_.brainVectorFreshness,staleTime:6e4,refetchOnWindowFocus:!1,retry:!1});return b.useMemo(()=>e.data?.ok?O(e.data.data):null,[e.data])}function xe({language:e}){let t=r(),n=J(),a=i({mutationFn:()=>_.memoryRebuild(),onSuccess:async()=>{await t.invalidateQueries({queryKey:[`vectorFreshness`]})}});if(!n||n.status!==`stale_embedder`)return null;let o=a.isSuccess&&a.data&&!a.data.ok;return(0,q.jsxs)(`div`,{className:`brain-stale-embedder`,role:`status`,"data-testid":`stale-embedder-notice`,children:[(0,q.jsx)(u,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`strong`,{children:f(e,`brain.freshness.staleEmbedder`)}),(0,q.jsx)(`small`,{children:f(e,`brain.freshness.staleEmbedder.detail`)}),o?(0,q.jsx)(`small`,{className:`is-error`,children:f(e,`brain.freshness.reindex.failed`)}):null]}),(0,q.jsx)(`button`,{type:`button`,"data-testid":`stale-embedder-reindex`,disabled:a.isPending,onClick:()=>a.mutate(),children:f(e,a.isPending?`brain.freshness.reindex.running`:`brain.freshness.reindex`)})]})}function Se({language:e}){let t=J();return!t||t.status!==`pending`||t.pendingItems<1?null:(0,q.jsxs)(`p`,{className:`brain-freshness-chip`,role:`status`,"data-testid":`vector-freshness-chip`,children:[(0,q.jsx)(te,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),(0,q.jsx)(`span`,{children:f(e,`brain.freshness.pending`,{count:t.pendingItems})})]})}var Y=new Set([`queued`,`running`]),X=new Set([`failed`,`partial`]);function Z(e){return Y.has(e.status)}function Ce(e){return e===`queued`||e===`running`||e===`completed`||e===`failed`||e===`partial`?`brain.jobs.status.${e}`:`brain.jobs.status.queued`}var we=new Set([`completed`,`partial`]),Q=3;function Te({language:e,job:t,freshness:n,onDismiss:r}){let i=n&&n.totalItems>0&&(n.status===`ready`||n.status===`pending`)?Math.max(0,Math.min(100,Math.round((n.totalItems-n.pendingItems)/n.totalItems*100))):null,o=t.errors.slice(0,Q);return(0,q.jsxs)(`div`,{className:`brain-jobs-report lattice-success-pulse is-${t.status}`,role:`status`,"data-testid":`ingestion-job-report`,children:[(0,q.jsxs)(`div`,{className:`brain-jobs-report-head`,children:[(0,q.jsx)(a,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,q.jsx)(`strong`,{children:f(e,t.status===`partial`?`brain.jobs.report.titlePartial`:`brain.jobs.report.title`)}),r?(0,q.jsx)(`button`,{type:`button`,className:`brain-jobs-report-dismiss`,"aria-label":f(e,`brain.jobs.report.dismiss`),onClick:r,children:(0,q.jsx)(c,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})}):null]}),(0,q.jsxs)(`div`,{className:`brain-jobs-report-stats`,children:[t.processed>0?(0,q.jsx)(`span`,{className:`brain-jobs-report-stat`,children:f(e,`brain.jobs.report.documents`,{count:t.processed})}):null,t.failed>0?(0,q.jsx)(`span`,{className:`brain-jobs-report-stat is-failed`,children:f(e,`brain.jobs.failedCount`,{count:t.failed})}):null,i===null?null:(0,q.jsx)(`span`,{className:`brain-jobs-report-stat`,children:f(e,`brain.jobs.report.vector`,{percent:i})})]}),o.length?(0,q.jsxs)(`div`,{className:`brain-jobs-report-samples`,children:[(0,q.jsx)(`small`,{children:f(e,`brain.jobs.report.skipped`)}),(0,q.jsx)(`ul`,{children:o.map(e=>(0,q.jsx)(`li`,{children:e},e))})]}):null]})}function Ee({language:e}){let t=r(),n=J(),a=l({queryKey:[`ingestionJobs`],queryFn:_.ingestionJobs,refetchOnWindowFocus:!1,retry:!1,refetchInterval:e=>{let t=e.state.data;return t?.ok&&A(t.data).some(Z)?4e3:!1}}),o=i({mutationFn:e=>_.resumeIngestionJob(e),onSettled:()=>void t.invalidateQueries({queryKey:[`ingestionJobs`]})}),c=b.useMemo(()=>a.data?.ok?A(a.data.data):[],[a.data]),d=b.useRef(new Map),[p,m]=b.useState([]);b.useEffect(()=>{let e=d.current,t=[];for(let n of c){let r=e.get(n.jobId);r&&Y.has(r)&&we.has(n.status)&&t.push(n.jobId),e.set(n.jobId,n.status)}t.length&&m(e=>[...t,...e.filter(e=>!t.includes(e))].slice(0,2))},[c]);let h=p.map(e=>c.find(t=>t.jobId===e)).filter(e=>!!e),g=c.filter(e=>Z(e)||X.has(e.status)).slice(0,4);return!g.length&&!h.length?null:(0,q.jsxs)(`section`,{className:`brain-jobs-panel`,"aria-label":f(e,`brain.jobs.aria`),"data-testid":`ingestion-jobs-panel`,children:[h.map(t=>(0,q.jsx)(Te,{language:e,job:t,freshness:n,onDismiss:()=>m(e=>e.filter(e=>e!==t.jobId))},t.jobId)),g.length?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`header`,{className:`brain-jobs-head`,children:(0,q.jsx)(`strong`,{children:f(e,`brain.jobs.title`)})}),(0,q.jsx)(`ul`,{className:`brain-jobs-list`,children:g.map(t=>{let n=Math.max(t.total,t.processed,1),r=Math.min(100,Math.round(t.processed/n*100)),i=X.has(t.status),a=o.isPending&&o.variables===t.jobId;return(0,q.jsxs)(`li`,{className:`brain-jobs-item is-${t.status}`,children:[(0,q.jsxs)(`div`,{className:`brain-jobs-item-row`,children:[(0,q.jsx)(`span`,{className:`brain-jobs-status`,children:f(e,Ce(t.status))}),(0,q.jsx)(`span`,{className:`brain-jobs-counts`,children:f(e,`brain.jobs.progress`,{processed:t.processed,total:t.total})}),t.failed>0?(0,q.jsxs)(`span`,{className:`brain-jobs-failed`,children:[(0,q.jsx)(u,{className:`h-3 w-3`,"aria-hidden":`true`}),f(e,`brain.jobs.failedCount`,{count:t.failed})]}):null]}),(0,q.jsx)(`div`,{className:`brain-jobs-bar`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":r,"aria-label":f(e,`brain.jobs.progressAria`,{processed:t.processed,total:t.total}),children:(0,q.jsx)(`span`,{className:`brain-jobs-bar-fill`,style:{width:`${r}%`}})}),i?(0,q.jsxs)(`button`,{type:`button`,className:`brain-jobs-resume`,disabled:o.isPending,onClick:()=>o.mutate(t.jobId),children:[(0,q.jsx)(s,{className:`h-3 w-3`,"aria-hidden":`true`}),a?f(e,`brain.jobs.resuming`):f(e,`brain.jobs.resume`)]}):null]},t.jobId)})})]}):null]})}function $(e){return e.split(/[\\/]/).filter(Boolean).pop()||e}function De(e,t){if(!t)return f(e,`brain.watch.scan.never`);let n=Date.parse(t);if(!Number.isFinite(n))return f(e,`brain.watch.scan.never`);let r=Math.max(0,Date.now()-n),i=Math.floor(r/6e4);if(i<1)return f(e,`brain.watch.scan.now`);if(i<60)return f(e,`brain.watch.scan.minutes`,{count:i});let a=Math.floor(i/60);return a<24?f(e,`brain.watch.scan.hours`,{count:a}):f(e,`brain.watch.scan.days`,{count:Math.floor(a/24)})}var Oe=4;function ke({language:e}){let t=l({queryKey:[`ingestionWatch`],queryFn:_.ingestionWatchStatus,staleTime:3e4,refetchOnWindowFocus:!1,retry:!1}),n=b.useMemo(()=>t.data?.ok?D(t.data.data):null,[t.data]);if(!n||n.enabledCount<1)return null;let r=n.watches.filter(e=>e.enabled).slice(0,Oe);return r.length?(0,q.jsxs)(`section`,{className:`brain-watch-card`,"aria-label":f(e,`brain.watch.aria`),"data-testid":`watch-health-card`,children:[(0,q.jsxs)(`header`,{className:`brain-watch-head`,children:[(0,q.jsx)(y,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),(0,q.jsx)(`strong`,{children:f(e,`brain.watch.title`)})]}),n.polling?null:(0,q.jsxs)(`p`,{className:`brain-watch-note`,role:`note`,"data-testid":`watch-polling-note`,children:[(0,q.jsx)(o,{className:`h-3 w-3`,"aria-hidden":`true`}),f(e,`brain.watch.notLive`)]}),(0,q.jsx)(`ul`,{className:`brain-watch-list`,children:r.map(t=>(0,q.jsx)(Ae,{language:e,watch:t},t.id))})]}):null}function Ae({language:e,watch:t}){return(0,q.jsxs)(`li`,{className:`brain-watch-item`,children:[(0,q.jsxs)(`div`,{className:`brain-watch-item-row`,children:[(0,q.jsx)(`span`,{className:`brain-watch-path`,title:t.path,children:$(t.path)}),(0,q.jsx)(`small`,{className:`brain-watch-scan`,children:De(e,t.lastScanAt)})]}),(0,q.jsxs)(`div`,{className:`brain-watch-item-row`,children:[t.lastResult&&t.lastResult.ingested>0?(0,q.jsx)(`span`,{className:`brain-watch-stat`,children:f(e,`brain.watch.ingested`,{count:t.lastResult.ingested})}):null,t.lastResult&&t.lastResult.failed>0?(0,q.jsxs)(`span`,{className:`brain-watch-stat is-failed`,children:[(0,q.jsx)(u,{className:`h-3 w-3`,"aria-hidden":`true`}),f(e,`brain.jobs.failedCount`,{count:t.lastResult.failed})]}):null,t.trackedFiles>0?(0,q.jsx)(`small`,{className:`brain-watch-tracked`,children:f(e,`brain.watch.tracked`,{count:t.trackedFiles})}):null]}),t.lastErrors.length?(0,q.jsxs)(`div`,{className:`brain-watch-errors`,children:[(0,q.jsx)(`small`,{children:f(e,`brain.watch.errors`)}),(0,q.jsx)(`ul`,{children:t.lastErrors.slice(0,3).map((e,t)=>(0,q.jsx)(`li`,{children:[e.path?$(e.path):``,e.detail].filter(Boolean).join(` — `)},`${e.path}-${t}`))})]}):null]})}function je(e,t){if(!t)return``;let n=new Date(t);return Number.isNaN(n.getTime())?``:n.toLocaleTimeString(e===`ko`?`ko-KR`:`en-US`,{hour:`2-digit`,minute:`2-digit`})}function Me({language:e,knownRunIds:t}){let n=l({queryKey:[`agentApprovals`],queryFn:_.agentApprovals,staleTime:1/0,refetchOnWindowFocus:!1,retry:!1}),r=b.useMemo(()=>n.data?.ok?E(n.data.data):[],[n.data]),i=b.useMemo(()=>new Set(t),[t]),a=r.filter(e=>!i.has(e.runId));return a.length?(0,q.jsx)(`aside`,{className:`brain-pending-approvals`,role:`note`,"aria-label":f(e,`brain.approval.pendingNotice.aria`),"data-testid":`pending-approvals-notice`,children:a.slice(0,2).map(t=>{let n=je(e,t.expiresAt);return(0,q.jsxs)(`p`,{children:[(0,q.jsx)(`span`,{children:t.goal?f(e,`brain.approval.pendingNotice`,{goal:t.goal}):f(e,`brain.approval.pendingNotice.generic`)}),(0,q.jsx)(`small`,{children:n?f(e,`brain.approval.pendingNotice.expiry`,{time:n}):f(e,`brain.approval.pendingNotice.hint`)})]},t.runId)})}):null}export{fe as C,V as D,T as E,v as O,de as S,w as T,S as _,ke as a,re as b,F as c,ae as d,me as f,B as g,N as h,Se as i,ee as k,P as l,se as m,Me as n,he as o,M as p,xe as r,L as s,Ee as t,ne as u,C as v,oe as w,ue as x,le as y};
@@ -1 +1 @@
1
- import{i as e,n as t,t as n}from"./jsx-runtime-bzQ4Vb5N.js";import{n as r}from"./QueryClientProvider-B3OjqSyJ.js";import{t as i}from"./useMutation-OJLrYSRA.js";import{_ as a,b as o,c as s,g as c,h as l,i as u,m as d,n as f,p,t as m,u as h,v as g,x as _,y as v}from"./primitives-BioD2slS.js";import{t as y}from"./circle-check-CFgejkOS.js";import{n as b,r as x,t as S}from"./hard-drive-DDzET7lk.js";import{t as ee}from"./folder-open-CHL82Yp7.js";import{t as C}from"./share-2-FkzGf8Df.js";import{A as w,H as T,R as E,S as D,c as O,d as k,o as te,p as A,v as j,z as M}from"./index-D2H-wSl6.js";import{t as N}from"./button-CmaEqG1T.js";import{t as P}from"./input-Df1CAY_I.js";import"./workspace-BCuk3Ku9.js";var F=E(`clipboard-paste`,[[`path`,{d:`M11 14h10`,key:`1w8e9d`}],[`path`,{d:`M16 4h2a2 2 0 0 1 2 2v1.344`,key:`1e62lh`}],[`path`,{d:`m17 18 4-4-4-4`,key:`z2g111`}],[`path`,{d:`M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113`,key:`bjbb7m`}],[`rect`,{x:`8`,y:`2`,width:`8`,height:`4`,rx:`1`,key:`ublpy`}]]),I=E(`scan-line`,[[`path`,{d:`M3 7V5a2 2 0 0 1 2-2h2`,key:`aa7l1z`}],[`path`,{d:`M17 3h2a2 2 0 0 1 2 2v2`,key:`4qcy5o`}],[`path`,{d:`M21 17v2a2 2 0 0 1-2 2h-2`,key:`6vwrx8`}],[`path`,{d:`M7 21H5a2 2 0 0 1-2-2v-2`,key:`ioqczr`}],[`path`,{d:`M7 12h10`,key:`b7w52i`}]]),L=E(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),R=e(t()),z=n();function B(e,t){for(let n of t){let t=e[n];if(typeof t==`string`&&t.trim())return t.trim()}return``}function V(e,t){let n=Number(e[t]);return Number.isFinite(n)&&n>0?Math.round(n):0}function H(e){let t=A(e)?e:{},n=A(t.vector_freshness_global)?t.vector_freshness_global:{};return{vectorStatus:B(n,[`status`])||`unavailable`,vectorPending:V(n,`pending_items`),folders:O(t.folders).flatMap(e=>{let t=A(e)?e:{},n=B(t,[`id`]);if(!n)return[];let r=A(t.files)?t.files:{},i=t.coverage,a=O(t.deleted),o=V(r,`deleted`);return[{id:n,label:B(t,[`label`,`root_path`])||n,rootPath:B(t,[`root_path`,`label`])||``,status:B(t,[`status`]),watchActive:t.watch_active===!0,total:V(r,`total`),indexed:V(r,`indexed`),failed:V(r,`failed`),deleted:o>0?o:a.length,coverage:typeof i==`number`&&Number.isFinite(i)?i:null,errors:O(t.recent_errors).flatMap(e=>{let t=A(e)?e:{},n=B(t,[`detail`]);return n?[{path:B(t,[`path`]),detail:n}]:[]})}]})}}function ne(e){let t=A(e)?e:{},n=A(t.would_remove)?t.would_remove:{},r=e=>{let t=Number(n[e]);return Number.isFinite(t)&&t>0?Math.round(t):0},i=O(t.files).length;return{nodes:r(`nodes`),edges:r(`edges`),chunks:r(`chunks`),vectors:r(`vectors`),files:i}}function re({language:e}){let t=r(),[n,a]=R.useState(null),[o,s]=R.useState(null),[c,l]=R.useState(``),u=T({queryKey:[`folderMemoryHealth`],queryFn:()=>j.localFolderHealth(),staleTime:3e4}),d=R.useMemo(()=>u.data?.ok?H(u.data.data):null,[u.data]),f=i({mutationFn:e=>j.pruneFolderDeleted(e,!1),onSuccess:(t,n)=>{if(!t.ok){l(t.error||D(e,`capture.folderHealth.prune.error`,{reason:String(t.status)}));return}a(n),s(ne(t.data)),l(``)},onError:t=>{l(D(e,`capture.folderHealth.prune.error`,{reason:String(t)}))}}),p=i({mutationFn:e=>j.pruneFolderDeleted(e,!0),onSuccess:n=>{if(!n.ok){l(n.error||D(e,`capture.folderHealth.prune.error`,{reason:String(n.status)}));return}a(null),s(null),l(``),t.invalidateQueries({queryKey:[`folderMemoryHealth`]})},onError:t=>{l(D(e,`capture.folderHealth.prune.error`,{reason:String(t)}))}});return!d||!d.folders.length?null:(0,z.jsxs)(`section`,{className:`folder-memory-health`,"data-testid":`folder-memory-health`,children:[(0,z.jsx)(`h3`,{children:D(e,`capture.folderHealth.title`)}),(0,z.jsx)(`ul`,{children:d.folders.map(t=>(0,z.jsxs)(`li`,{"data-testid":`folder-health-${t.id}`,children:[(0,z.jsxs)(`div`,{className:`folder-memory-head`,children:[(0,z.jsx)(`strong`,{children:t.label}),(0,z.jsx)(`span`,{className:`folder-memory-coverage`,children:t.coverage===null?D(e,`capture.folderHealth.unknown`):D(e,`capture.folderHealth.coverage`,{percent:Math.round(t.coverage*100),indexed:t.indexed,total:t.total})})]}),t.coverage===null?null:(0,z.jsx)(`div`,{className:`folder-memory-bar`,role:`progressbar`,"aria-valuenow":Math.round(t.coverage*100),"aria-valuemin":0,"aria-valuemax":100,children:(0,z.jsx)(`span`,{style:{width:`${Math.round(t.coverage*100)}%`}})}),t.watchActive?(0,z.jsx)(`small`,{children:D(e,`capture.folderHealth.watching`)}):null,t.failed>0?(0,z.jsxs)(`details`,{className:`folder-memory-errors`,children:[(0,z.jsx)(`summary`,{children:D(e,`capture.folderHealth.failed`,{count:t.failed})}),(0,z.jsx)(`ul`,{children:t.errors.map(e=>(0,z.jsxs)(`li`,{children:[(0,z.jsx)(`code`,{children:e.path}),(0,z.jsx)(`span`,{children:e.detail})]},`${t.id}-${e.path}-${e.detail}`))})]}):null,t.deleted>0&&t.rootPath?(0,z.jsx)(`div`,{className:`folder-memory-prune`,"data-testid":`folder-prune-${t.id}`,children:n===t.rootPath&&o?(0,z.jsxs)(`div`,{className:`folder-memory-prune-preview`,"data-testid":`folder-prune-preview-${t.id}`,children:[(0,z.jsx)(`p`,{children:D(e,`capture.folderHealth.prune.previewTitle`)}),(0,z.jsxs)(`ul`,{children:[(0,z.jsx)(`li`,{children:D(e,`capture.folderHealth.prune.files`,{count:o.files})}),(0,z.jsx)(`li`,{children:D(e,`capture.folderHealth.prune.nodes`,{count:o.nodes})}),(0,z.jsx)(`li`,{children:D(e,`capture.folderHealth.prune.edges`,{count:o.edges})}),(0,z.jsx)(`li`,{children:D(e,`capture.folderHealth.prune.chunks`,{count:o.chunks})}),(0,z.jsx)(`li`,{children:D(e,`capture.folderHealth.prune.vectors`,{count:o.vectors})})]}),(0,z.jsxs)(`div`,{className:`folder-memory-prune-actions`,children:[(0,z.jsx)(`button`,{type:`button`,"data-testid":`folder-prune-confirm-${t.id}`,disabled:p.isPending,onClick:()=>p.mutate(t.rootPath),children:D(e,`capture.folderHealth.prune.confirm`)}),(0,z.jsx)(`button`,{type:`button`,"data-testid":`folder-prune-cancel-${t.id}`,onClick:()=>{a(null),s(null)},children:D(e,`capture.folderHealth.prune.cancel`)})]})]}):(0,z.jsx)(`button`,{type:`button`,className:`folder-memory-prune-open`,"data-testid":`folder-prune-open-${t.id}`,disabled:f.isPending,onClick:()=>f.mutate(t.rootPath),children:D(e,`capture.folderHealth.prune`,{count:t.deleted})})}):null]},t.id))}),d.vectorPending>0?(0,z.jsx)(`small`,{className:`folder-memory-vector`,children:D(e,`capture.folderHealth.vectorGlobal`,{count:d.vectorPending})}):null,c?(0,z.jsx)(`small`,{className:`folder-memory-prune-error`,"data-testid":`folder-prune-error`,children:c}):null]})}var U=[{id:`files`,labelKey:`capture.method.files`,icon:L,path:`capture`},{id:`local`,labelKey:`capture.method.local`,icon:b,path:`my-computer`},{id:`browser`,labelKey:`capture.method.browser`,icon:x,path:`capture-browser`}];function W(e){return U.some(t=>t.id===e)?e:`files`}function G({initialTab:e}){let t=M(e=>e.language),[n,r]=R.useState(()=>W(e));R.useEffect(()=>{r(W(e))},[e]);let i=e=>{r(e),te(`/`+U.find(t=>t.id===e).path)};return(0,z.jsxs)(`div`,{className:`product-page capture-page space-y-5`,children:[(0,z.jsxs)(`header`,{className:`page-hero`,children:[(0,z.jsxs)(`div`,{className:`page-kicker`,children:[(0,z.jsx)(L,{className:`h-4 w-4`}),` `,D(t,`capture.kicker`)]}),(0,z.jsx)(`h1`,{className:`page-title`,children:D(t,`capture.title`)}),(0,z.jsx)(`p`,{className:`page-copy`,children:D(t,`capture.body`)})]}),(0,z.jsxs)(`section`,{className:`capture-station`,"aria-label":D(t,`capture.station.aria`),children:[(0,z.jsxs)(`div`,{className:`capture-station-head`,children:[(0,z.jsx)(`h2`,{children:D(t,`capture.station.title`)}),(0,z.jsx)(`p`,{children:D(t,`capture.station.detail`)})]}),(0,z.jsx)(`div`,{className:`capture-method-switch`,role:`group`,"aria-label":D(t,`capture.method.aria`),children:U.map(({id:e,labelKey:r,icon:a})=>(0,z.jsxs)(`button`,{type:`button`,"aria-pressed":n===e,className:n===e?`is-active`:``,"data-testid":`capture-method-${e}`,onClick:()=>i(e),children:[(0,z.jsx)(a,{className:`h-4 w-4`,"aria-hidden":`true`}),D(t,r)]},e))}),(0,z.jsxs)(`div`,{className:`capture-station-body`,children:[n===`files`?(0,z.jsx)(K,{}):null,n===`local`?(0,z.jsx)(Q,{}):null,n===`browser`?(0,z.jsx)(ue,{}):null]})]}),(0,z.jsxs)(`div`,{className:`capture-secondary`,children:[(0,z.jsx)(fe,{}),(0,z.jsx)(q,{})]})]})}function K(){let e=M(e=>e.language),t=r(),[n,a]=R.useState([]),o=i({mutationFn:e=>J(e,a),onSuccess:()=>{t.invalidateQueries({queryKey:[`documents`]}),t.invalidateQueries({queryKey:[`graphStats`]}),t.invalidateQueries({queryKey:[`memoryManager`]})}}),s=R.useCallback(e=>{let t=Array.from(e);t.length&&o.mutate(t)},[o]);return(0,z.jsxs)(`div`,{className:`space-y-4`,children:[(0,z.jsxs)(`label`,{className:`capture-dropzone`,onDragOver:e=>e.preventDefault(),onDrop:e=>{e.preventDefault(),s(e.dataTransfer.files)},children:[(0,z.jsx)(`div`,{className:`capture-dropzone-mark`,children:(0,z.jsx)(L,{className:`h-6 w-6`})}),(0,z.jsxs)(`div`,{className:`space-y-1`,children:[(0,z.jsx)(`span`,{className:`text-lg font-semibold block`,children:D(e,`capture.files.drop`)}),(0,z.jsx)(`span`,{className:`max-w-md text-sm text-muted-foreground block`,children:D(e,`capture.files.dropDetail`)})]}),(0,z.jsx)(`input`,{type:`file`,multiple:!0,className:`sr-only`,onChange:e=>e.target.files&&s(e.target.files)})]}),(0,z.jsx)(Y,{queue:n,onRetry:e=>s([e])})]})}function q(){let e=M(e=>e.language),t=M(e=>e.mode),n=T({queryKey:[`documents`],queryFn:()=>j.documents(200)}),r=T({queryKey:[`localSources`],queryFn:j.localSources}),i=T({queryKey:[`localAgent`],queryFn:j.localAgent});return(0,z.jsxs)(`div`,{className:`capture-secondary-column space-y-4`,children:[(0,z.jsx)(f,{title:D(e,`capture.files.uploaded`),result:n.data,children:t=>(0,z.jsxs)(`div`,{className:`space-y-3`,children:[(0,z.jsx)(u,{items:t.documents||t,titleKey:`filename`,metaKey:`ingest_state`,limit:12}),(0,z.jsx)(`div`,{className:`rounded-md border border-border bg-background/55 p-3 text-sm text-muted-foreground`,children:D(e,`capture.files.completed`)})]})}),(0,z.jsx)(re,{language:e}),(0,z.jsx)(f,{title:D(e,`capture.local.sources`),result:r.data,children:t=>(0,z.jsxs)(`div`,{className:`space-y-3`,children:[(0,z.jsx)(u,{items:t.sources,titleKey:`path`,metaKey:`status`}),O(t.sources).map(t=>(0,z.jsx)(m,{label:D(e,`capture.local.stop`,{source:String(t.path||t.id||D(e,`capture.local.source`))}),action:()=>j.localWatchStop(String(t.id||t.source_id)),invalidate:[`localSources`]},String(t.id||t.source_id||t.path)))]})}),t===`basic`?null:(0,z.jsx)(f,{title:D(e,`capture.local.access`),result:i.data,children:e=>(0,z.jsx)(h,{value:e})})]})}async function J(e,t){let n=e.map(e=>({id:`${e.name}-${e.size}-${e.lastModified}-${Date.now()}`,file:e,name:oe(e),size:e.size,status:`queued`}));t(e=>[...n,...e].slice(0,12));let r=[];for(let e of n){t(t=>t.map(t=>t.id===e.id?{...t,status:`uploading`}:t));let n=await j.uploadDocument(e.file);r.push(n),t(t=>t.map(t=>t.id===e.id?{...t,status:n.ok?`done`:`failed`,result:n}:t))}return r}function Y({queue:e,onRetry:t}){let n=M(e=>e.language);return e.length?(0,z.jsx)(`div`,{className:`mt-4 space-y-2`,children:e.map(e=>{let r=ie(e,n);return(0,z.jsxs)(`div`,{className:`rounded-md border border-border bg-background/55 p-3 text-sm`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 font-medium`,children:[e.status===`done`?(0,z.jsx)(y,{className:`h-4 w-4 text-emerald-400`}):e.status===`failed`?(0,z.jsx)(_,{className:`h-4 w-4 text-amber-400`}):(0,z.jsx)(o,{className:`h-4 w-4 animate-spin text-primary`}),e.name]}),(0,z.jsxs)(`div`,{className:`mt-1 text-xs text-muted-foreground`,children:[Math.max(1,Math.round(e.size/1024)),` KB · `,r]})]}),e.status===`failed`?(0,z.jsxs)(N,{size:`sm`,variant:`outline`,onClick:()=>t(e.file),children:[(0,z.jsx)(w,{className:`h-3.5 w-3.5`}),` `,D(n,`capture.retry`)]}):null]}),e.result?(0,z.jsx)(s,{result:e.result,successLabel:D(n,`capture.files.success`)}):null]},e.id)})}):null}function ie(e,t){if(e.status===`queued`)return D(t,`capture.files.queued`);if(e.status===`uploading`)return D(t,`capture.files.uploading`);if(!e.result?.ok)return e.result?.error||D(t,`capture.files.failed`);let n=e.result.data||{},r=String(n.node_id||n.graph_node||n.provenance_id||``);return r?D(t,`capture.files.capturedWithNode`,{node:r}):D(t,`capture.files.captured`)}var ae={webkitdirectory:``,directory:``};function oe(e){return e.webkitRelativePath||e.name}function se(e){return(e[0]?.webkitRelativePath||``).split(`/`).filter(Boolean)[0]||``}function X(){let e=window;return!!(e.__TAURI__?.core?.invoke||e.latticeDesktop?.selectFolder||e.__TAURI_INTERNALS__&&window.location.protocol===`tauri:`)}function ce(e){return e instanceof DOMException&&e.name===`AbortError`}async function le(e){let t=[];if(typeof e.values==`function`){for await(let n of e.values())t.push(n);return t}if(typeof e.entries==`function`)for await(let[,n]of e.entries())t.push(n);return t}async function Z(e){let t=[];for(let n of await le(e)){if(n.kind===`file`){t.push(await n.getFile());continue}t.push(...await Z(n))}return t}function Q(){let e=M(e=>e.language),t=r(),n=R.useRef(null),[a,c]=R.useState(``),[l,u]=R.useState(null),[d,f]=R.useState(``),[p,m]=R.useState(!1),[h,g]=R.useState([]),_=i({mutationFn:e=>j.connectFolder(e.trim()),onSuccess:()=>{u(null),t.invalidateQueries({queryKey:[`localSources`]}),t.invalidateQueries({queryKey:[`graphStats`]}),t.invalidateQueries({queryKey:[`memoryManager`]})}}),v=i({mutationFn:e=>J(e,g),onSuccess:()=>{t.invalidateQueries({queryKey:[`documents`]}),t.invalidateQueries({queryKey:[`graphStats`]}),t.invalidateQueries({queryKey:[`memoryManager`]})}}),y=R.useCallback((t,n)=>{if(!t.length){u(D(e,`capture.local.emptyFolder`));return}u(null),f(n||se(t)||D(e,`capture.local.browserFolder`)),v.mutate(t)},[v,e]),x=R.useCallback(async()=>{if(!p){m(!0),u(null);try{let t=window.showDirectoryPicker;if(!X()&&typeof t==`function`){let e=await t.call(window);y(await Z(e),e.name);return}if(X()){let e=await j.selectFolder();if(e){f(``),c(e),_.mutate(e);return}}if(typeof t==`function`){let e=await t.call(window);y(await Z(e),e.name);return}if(n.current){n.current.click();return}u(D(e,`capture.local.pickUnavailable`))}catch(t){ce(t)||u(D(e,`capture.local.pickUnavailable`))}finally{m(!1)}}},[y,p,_,e]),S=R.useCallback(()=>{let e=a.trim();e&&(u(null),f(``),_.mutate(e))},[_,a]),C=(v.data||[]).find(e=>!e.ok)?.error,w=!!(v.error||C);return(0,z.jsxs)(`div`,{className:`space-y-3`,children:[(0,z.jsxs)(`div`,{className:`capture-intake-lead`,children:[(0,z.jsx)(b,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:D(e,`capture.local.title`)}),(0,z.jsx)(`p`,{children:D(e,`capture.local.description`)})]})]}),(0,z.jsxs)(`form`,{className:`space-y-3`,onSubmit:e=>{e.preventDefault(),S()},children:[(0,z.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,z.jsx)(P,{value:a,onChange:e=>c(e.target.value),placeholder:D(e,`capture.local.placeholder`)}),(0,z.jsxs)(N,{type:`button`,variant:`outline`,disabled:p||_.isPending||v.isPending,onClick:()=>void x(),children:[p?(0,z.jsx)(o,{className:`h-4 w-4 animate-spin`}):(0,z.jsx)(ee,{className:`h-4 w-4`}),p?D(e,`capture.local.choosing`):D(e,`capture.local.choose`)]})]}),(0,z.jsx)(`input`,{ref:n,type:`file`,multiple:!0,className:`sr-only`,"aria-hidden":`true`,tabIndex:-1,...ae,onChange:e=>{let t=Array.from(e.currentTarget.files||[]);e.currentTarget.value=``,y(t)}}),(0,z.jsxs)(N,{type:`submit`,disabled:!a.trim()||_.isPending,children:[_.isPending?(0,z.jsx)(o,{className:`h-4 w-4 animate-spin`}):(0,z.jsx)(I,{className:`h-4 w-4`}),D(e,`capture.local.connect`)]})]}),l?(0,z.jsx)(s,{result:{ok:!1,status:0,data:{},source:`unavailable`,error:l}}):null,_.data?(0,z.jsx)(s,{result:_.data,successLabel:D(e,`capture.local.success`)}):null,d?(0,z.jsx)(s,{result:{ok:v.isPending||!w,status:w?0:200,data:{folder:d},source:w?`unavailable`:`live`,error:v.error?D(e,`capture.local.browserImportFailed`):C},successLabel:v.isPending?D(e,`capture.local.browserImporting`):D(e,`capture.local.browserImportSuccess`,{folder:d})}):null,(0,z.jsx)(Y,{queue:h,onRetry:e=>y([e],d)})]})}function ue(){let e=M(e=>e.language),t=r(),[n,a]=R.useState(``),c=i({mutationFn:e=>j.browserReadUrl(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`graphStats`]}),t.invalidateQueries({queryKey:[`memoryManager`]})}}),l=R.useCallback(()=>{let e=$(n);e&&(a(e),c.mutate(e))},[c,n]),u=R.useCallback(async()=>{let e=$(await navigator.clipboard?.readText().catch(()=>``)||``);e&&(a(e),c.mutate(e))},[c]);return(0,z.jsxs)(`div`,{className:`space-y-3`,children:[(0,z.jsxs)(`div`,{className:`capture-intake-lead`,children:[(0,z.jsx)(x,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:D(e,`capture.browser.title`)}),(0,z.jsx)(`p`,{children:D(e,`capture.browser.description`)})]})]}),(0,z.jsxs)(`form`,{className:`flex flex-col gap-2 sm:flex-row`,onSubmit:e=>{e.preventDefault(),l()},children:[(0,z.jsx)(P,{value:n,onChange:e=>a(e.target.value),placeholder:D(e,`capture.browser.placeholder`),inputMode:`url`}),(0,z.jsxs)(N,{type:`button`,variant:`outline`,disabled:c.isPending,onClick:()=>void u(),children:[(0,z.jsx)(F,{className:`h-4 w-4`}),` `,D(e,`capture.browser.paste`)]}),(0,z.jsxs)(N,{type:`submit`,disabled:!n.trim()||c.isPending,children:[c.isPending?(0,z.jsx)(o,{className:`h-4 w-4 animate-spin`}):(0,z.jsx)(I,{className:`h-4 w-4`}),D(e,`capture.browser.capture`)]})]}),c.data?(0,z.jsx)(s,{result:c.data,successLabel:D(e,`capture.browser.success`)}):null]})}function $(e){let t=e.trim();return t?/^https?:\/\//i.test(t)?t:/^[\w.-]+\.[a-z]{2,}([/:?#].*)?$/i.test(t)?`https://${t}`:t:``}function de(e,t,n){let r=A(e)?e:{},i=A(t)?t:{},a=A(n)?n:{};A(i.pipelines)&&i.pipelines;let o=(...e)=>{for(let t of e){if(typeof t==`number`&&Number.isFinite(t)&&t>=0)return Math.round(t);let e=Number(t);if(Number.isFinite(e)&&e>0)return Math.round(e)}},s=o(r.received),c=o(r.extracted),l=o(r.connected),u=o(c,i.total,i.total_items,a.nodes,a.total_nodes)||0,d=o(l,a.edges,a.total_edges)||0,f=o(i.pending,i.pending_items)||0,p=(e,t)=>{let n=r.stages||{};for(let t of e){let e=n[t],r=typeof e==`object`&&e?e.status:e;if(r===`done`||r===`working`||r===`waiting`||r===`error`)return r}return t},m=s===void 0?f?`working`:u?`done`:`waiting`:s>0?`done`:`waiting`,h=c===void 0?u?`done`:`waiting`:c>0?`done`:`waiting`,g=l===void 0?d?`done`:`waiting`:l>0?`done`:`waiting`,_=p([`read`,`received`],m),v=p([`understand`,`extracted`],h),y=p([`connect`,`connected`],g);return{remembered:u,connections:d,waiting:f,received:s??f,extracted:c??u,connected:l??d,steps:[{key:`read`,state:_,count:s??(u||f)},{key:`understand`,state:v,count:c??u},{key:`connect`,state:y,count:l??d}]}}function fe(){let e=M(e=>e.language),t=M(e=>e.mode),n=T({queryKey:[`index`],queryFn:j.indexStatus}),r=T({queryKey:[`graphStats`],queryFn:j.graphStats}),i=T({queryKey:[`pipelineStatus`],queryFn:j.pipelineStatus}),o=de(i.data?.data||i.data,n.data?.data,r.data?.data),s={read:I,understand:v,connect:C},u=!!(o.remembered||o.connections||o.received&&o.received>0);return(0,z.jsxs)(`div`,{className:`capture-secondary-column space-y-4`,children:[(0,z.jsxs)(p,{children:[(0,z.jsxs)(c,{children:[(0,z.jsxs)(a,{className:`flex items-center gap-2`,children:[(0,z.jsx)(I,{className:`h-4 w-4`}),` `,D(e,`capture.pipeline.journey.title`)]}),(0,z.jsx)(l,{children:D(e,`capture.pipeline.journey.detail`)})]}),(0,z.jsxs)(d,{className:`space-y-4`,children:[(0,z.jsx)(`ol`,{className:`capture-journey flex flex-col md:flex-row gap-3 items-stretch`,"aria-label":D(e,`capture.pipeline.journey.aria`),children:o.steps.map(({key:t,state:n,count:r})=>{let i=s[t];return(0,z.jsxs)(`li`,{className:`capture-journey-step is-${n} flex-1 p-3 rounded-lg border border-border/60 bg-muted/20 flex flex-col justify-between`,children:[(0,z.jsxs)(`div`,{className:`capture-journey-step-header flex items-center gap-2`,children:[(0,z.jsx)(`span`,{className:`capture-journey-mark`,"aria-hidden":`true`,children:(0,z.jsx)(i,{className:`h-4 w-4`})}),(0,z.jsxs)(`div`,{className:`capture-journey-copy min-w-0 flex-1`,children:[(0,z.jsx)(`strong`,{className:`block text-sm`,children:D(e,`capture.pipeline.step.${t}`)}),(0,z.jsx)(`small`,{className:`block text-xs text-muted-foreground`,children:D(e,`capture.pipeline.step.${t}.detail`)})]})]}),(0,z.jsxs)(`div`,{className:`capture-journey-step-meta flex items-center justify-between gap-2 mt-3 pt-2 border-t border-border/40 text-xs`,children:[(0,z.jsx)(g,{variant:`muted`,className:`capture-journey-count`,children:D(e,`ui.value.records`,{count:r})}),(0,z.jsx)(`span`,{className:`capture-journey-state`,children:D(e,`capture.pipeline.step.${n}`)})]})]},t)})}),u?(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-sm pt-2`,children:[(0,z.jsx)(g,{variant:`success`,children:D(e,`capture.pipeline.count.remembered`,{count:k(o.extracted)})}),(0,z.jsx)(g,{variant:`muted`,children:D(e,`capture.pipeline.count.connections`,{count:k(o.connected)})}),(0,z.jsx)(g,{variant:o.waiting?`warning`:`muted`,children:o.waiting?D(e,`capture.pipeline.count.waiting`,{count:k(o.waiting)}):D(e,`capture.pipeline.count.none`)})]}):(0,z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:D(e,`capture.pipeline.empty`)})]})]}),(0,z.jsxs)(p,{children:[(0,z.jsxs)(c,{children:[(0,z.jsxs)(a,{className:`flex items-center gap-2`,children:[(0,z.jsx)(S,{className:`h-4 w-4`}),` `,D(e,`capture.pipeline.refresh`)]}),(0,z.jsx)(l,{children:D(e,`capture.pipeline.description`)})]}),(0,z.jsx)(d,{children:(0,z.jsx)(m,{label:D(e,`capture.pipeline.rebuild`),action:()=>j.rebuildIndex(),invalidate:[`index`]})})]}),t===`basic`?null:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(f,{title:D(e,`capture.pipeline.status`),result:n.data,children:e=>(0,z.jsx)(h,{value:e})}),(0,z.jsx)(f,{title:D(e,`capture.pipeline.growth`),result:r.data,children:e=>(0,z.jsx)(h,{value:e})})]})]})}export{G as CapturePage};
1
+ import{i as e,n as t,t as n}from"./jsx-runtime-bzQ4Vb5N.js";import{n as r}from"./QueryClientProvider-B3OjqSyJ.js";import{t as i}from"./useMutation-B8QKq2NW.js";import{_ as a,b as o,c as s,g as c,h as l,i as u,m as d,n as f,p,t as m,u as h,v as g,x as _,y as v}from"./primitives-BDryQl6H.js";import{t as y}from"./circle-check-BxaDWjPR.js";import{n as b,r as x,t as S}from"./hard-drive-BOzmS-cq.js";import{t as ee}from"./folder-open-YmGugIBf.js";import{t as C}from"./share-2-B-gPv2ec.js";import{A as w,H as T,R as E,S as D,c as O,d as k,o as te,p as A,v as j,z as M}from"./index-CfeqZ9Ri.js";import{t as N}from"./button-BA0N_zId.js";import{t as P}from"./input-CFfCfMjO.js";import"./workspace-BmfVs66W.js";var F=E(`clipboard-paste`,[[`path`,{d:`M11 14h10`,key:`1w8e9d`}],[`path`,{d:`M16 4h2a2 2 0 0 1 2 2v1.344`,key:`1e62lh`}],[`path`,{d:`m17 18 4-4-4-4`,key:`z2g111`}],[`path`,{d:`M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113`,key:`bjbb7m`}],[`rect`,{x:`8`,y:`2`,width:`8`,height:`4`,rx:`1`,key:`ublpy`}]]),I=E(`scan-line`,[[`path`,{d:`M3 7V5a2 2 0 0 1 2-2h2`,key:`aa7l1z`}],[`path`,{d:`M17 3h2a2 2 0 0 1 2 2v2`,key:`4qcy5o`}],[`path`,{d:`M21 17v2a2 2 0 0 1-2 2h-2`,key:`6vwrx8`}],[`path`,{d:`M7 21H5a2 2 0 0 1-2-2v-2`,key:`ioqczr`}],[`path`,{d:`M7 12h10`,key:`b7w52i`}]]),L=E(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),R=e(t()),z=n();function B(e,t){for(let n of t){let t=e[n];if(typeof t==`string`&&t.trim())return t.trim()}return``}function V(e,t){let n=Number(e[t]);return Number.isFinite(n)&&n>0?Math.round(n):0}function H(e){let t=A(e)?e:{},n=A(t.vector_freshness_global)?t.vector_freshness_global:{};return{vectorStatus:B(n,[`status`])||`unavailable`,vectorPending:V(n,`pending_items`),folders:O(t.folders).flatMap(e=>{let t=A(e)?e:{},n=B(t,[`id`]);if(!n)return[];let r=A(t.files)?t.files:{},i=t.coverage,a=O(t.deleted),o=V(r,`deleted`);return[{id:n,label:B(t,[`label`,`root_path`])||n,rootPath:B(t,[`root_path`,`label`])||``,status:B(t,[`status`]),watchActive:t.watch_active===!0,total:V(r,`total`),indexed:V(r,`indexed`),failed:V(r,`failed`),deleted:o>0?o:a.length,coverage:typeof i==`number`&&Number.isFinite(i)?i:null,errors:O(t.recent_errors).flatMap(e=>{let t=A(e)?e:{},n=B(t,[`detail`]);return n?[{path:B(t,[`path`]),detail:n}]:[]})}]})}}function ne(e){let t=A(e)?e:{},n=A(t.would_remove)?t.would_remove:{},r=e=>{let t=Number(n[e]);return Number.isFinite(t)&&t>0?Math.round(t):0},i=O(t.files).length;return{nodes:r(`nodes`),edges:r(`edges`),chunks:r(`chunks`),vectors:r(`vectors`),files:i}}function re({language:e}){let t=r(),[n,a]=R.useState(null),[o,s]=R.useState(null),[c,l]=R.useState(``),u=T({queryKey:[`folderMemoryHealth`],queryFn:()=>j.localFolderHealth(),staleTime:3e4}),d=R.useMemo(()=>u.data?.ok?H(u.data.data):null,[u.data]),f=i({mutationFn:e=>j.pruneFolderDeleted(e,!1),onSuccess:(t,n)=>{if(!t.ok){l(t.error||D(e,`capture.folderHealth.prune.error`,{reason:String(t.status)}));return}a(n),s(ne(t.data)),l(``)},onError:t=>{l(D(e,`capture.folderHealth.prune.error`,{reason:String(t)}))}}),p=i({mutationFn:e=>j.pruneFolderDeleted(e,!0),onSuccess:n=>{if(!n.ok){l(n.error||D(e,`capture.folderHealth.prune.error`,{reason:String(n.status)}));return}a(null),s(null),l(``),t.invalidateQueries({queryKey:[`folderMemoryHealth`]})},onError:t=>{l(D(e,`capture.folderHealth.prune.error`,{reason:String(t)}))}});return!d||!d.folders.length?null:(0,z.jsxs)(`section`,{className:`folder-memory-health`,"data-testid":`folder-memory-health`,children:[(0,z.jsx)(`h3`,{children:D(e,`capture.folderHealth.title`)}),(0,z.jsx)(`ul`,{children:d.folders.map(t=>(0,z.jsxs)(`li`,{"data-testid":`folder-health-${t.id}`,children:[(0,z.jsxs)(`div`,{className:`folder-memory-head`,children:[(0,z.jsx)(`strong`,{children:t.label}),(0,z.jsx)(`span`,{className:`folder-memory-coverage`,children:t.coverage===null?D(e,`capture.folderHealth.unknown`):D(e,`capture.folderHealth.coverage`,{percent:Math.round(t.coverage*100),indexed:t.indexed,total:t.total})})]}),t.coverage===null?null:(0,z.jsx)(`div`,{className:`folder-memory-bar`,role:`progressbar`,"aria-valuenow":Math.round(t.coverage*100),"aria-valuemin":0,"aria-valuemax":100,children:(0,z.jsx)(`span`,{style:{width:`${Math.round(t.coverage*100)}%`}})}),t.watchActive?(0,z.jsx)(`small`,{children:D(e,`capture.folderHealth.watching`)}):null,t.failed>0?(0,z.jsxs)(`details`,{className:`folder-memory-errors`,children:[(0,z.jsx)(`summary`,{children:D(e,`capture.folderHealth.failed`,{count:t.failed})}),(0,z.jsx)(`ul`,{children:t.errors.map(e=>(0,z.jsxs)(`li`,{children:[(0,z.jsx)(`code`,{children:e.path}),(0,z.jsx)(`span`,{children:e.detail})]},`${t.id}-${e.path}-${e.detail}`))})]}):null,t.deleted>0&&t.rootPath?(0,z.jsx)(`div`,{className:`folder-memory-prune`,"data-testid":`folder-prune-${t.id}`,children:n===t.rootPath&&o?(0,z.jsxs)(`div`,{className:`folder-memory-prune-preview`,"data-testid":`folder-prune-preview-${t.id}`,children:[(0,z.jsx)(`p`,{children:D(e,`capture.folderHealth.prune.previewTitle`)}),(0,z.jsxs)(`ul`,{children:[(0,z.jsx)(`li`,{children:D(e,`capture.folderHealth.prune.files`,{count:o.files})}),(0,z.jsx)(`li`,{children:D(e,`capture.folderHealth.prune.nodes`,{count:o.nodes})}),(0,z.jsx)(`li`,{children:D(e,`capture.folderHealth.prune.edges`,{count:o.edges})}),(0,z.jsx)(`li`,{children:D(e,`capture.folderHealth.prune.chunks`,{count:o.chunks})}),(0,z.jsx)(`li`,{children:D(e,`capture.folderHealth.prune.vectors`,{count:o.vectors})})]}),(0,z.jsxs)(`div`,{className:`folder-memory-prune-actions`,children:[(0,z.jsx)(`button`,{type:`button`,"data-testid":`folder-prune-confirm-${t.id}`,disabled:p.isPending,onClick:()=>p.mutate(t.rootPath),children:D(e,`capture.folderHealth.prune.confirm`)}),(0,z.jsx)(`button`,{type:`button`,"data-testid":`folder-prune-cancel-${t.id}`,onClick:()=>{a(null),s(null)},children:D(e,`capture.folderHealth.prune.cancel`)})]})]}):(0,z.jsx)(`button`,{type:`button`,className:`folder-memory-prune-open`,"data-testid":`folder-prune-open-${t.id}`,disabled:f.isPending,onClick:()=>f.mutate(t.rootPath),children:D(e,`capture.folderHealth.prune`,{count:t.deleted})})}):null]},t.id))}),d.vectorPending>0?(0,z.jsx)(`small`,{className:`folder-memory-vector`,children:D(e,`capture.folderHealth.vectorGlobal`,{count:d.vectorPending})}):null,c?(0,z.jsx)(`small`,{className:`folder-memory-prune-error`,"data-testid":`folder-prune-error`,children:c}):null]})}var U=[{id:`files`,labelKey:`capture.method.files`,icon:L,path:`capture`},{id:`local`,labelKey:`capture.method.local`,icon:b,path:`my-computer`},{id:`browser`,labelKey:`capture.method.browser`,icon:x,path:`capture-browser`}];function W(e){return U.some(t=>t.id===e)?e:`files`}function G({initialTab:e}){let t=M(e=>e.language),[n,r]=R.useState(()=>W(e));R.useEffect(()=>{r(W(e))},[e]);let i=e=>{r(e),te(`/`+U.find(t=>t.id===e).path)};return(0,z.jsxs)(`div`,{className:`product-page capture-page space-y-5`,children:[(0,z.jsxs)(`header`,{className:`page-hero`,children:[(0,z.jsxs)(`div`,{className:`page-kicker`,children:[(0,z.jsx)(L,{className:`h-4 w-4`}),` `,D(t,`capture.kicker`)]}),(0,z.jsx)(`h1`,{className:`page-title`,children:D(t,`capture.title`)}),(0,z.jsx)(`p`,{className:`page-copy`,children:D(t,`capture.body`)})]}),(0,z.jsxs)(`section`,{className:`capture-station`,"aria-label":D(t,`capture.station.aria`),children:[(0,z.jsxs)(`div`,{className:`capture-station-head`,children:[(0,z.jsx)(`h2`,{children:D(t,`capture.station.title`)}),(0,z.jsx)(`p`,{children:D(t,`capture.station.detail`)})]}),(0,z.jsx)(`div`,{className:`capture-method-switch`,role:`group`,"aria-label":D(t,`capture.method.aria`),children:U.map(({id:e,labelKey:r,icon:a})=>(0,z.jsxs)(`button`,{type:`button`,"aria-pressed":n===e,className:n===e?`is-active`:``,"data-testid":`capture-method-${e}`,onClick:()=>i(e),children:[(0,z.jsx)(a,{className:`h-4 w-4`,"aria-hidden":`true`}),D(t,r)]},e))}),(0,z.jsxs)(`div`,{className:`capture-station-body`,children:[n===`files`?(0,z.jsx)(K,{}):null,n===`local`?(0,z.jsx)(Q,{}):null,n===`browser`?(0,z.jsx)(ue,{}):null]})]}),(0,z.jsxs)(`div`,{className:`capture-secondary`,children:[(0,z.jsx)(fe,{}),(0,z.jsx)(q,{})]})]})}function K(){let e=M(e=>e.language),t=r(),[n,a]=R.useState([]),o=i({mutationFn:e=>J(e,a),onSuccess:()=>{t.invalidateQueries({queryKey:[`documents`]}),t.invalidateQueries({queryKey:[`graphStats`]}),t.invalidateQueries({queryKey:[`memoryManager`]})}}),s=R.useCallback(e=>{let t=Array.from(e);t.length&&o.mutate(t)},[o]);return(0,z.jsxs)(`div`,{className:`space-y-4`,children:[(0,z.jsxs)(`label`,{className:`capture-dropzone`,onDragOver:e=>e.preventDefault(),onDrop:e=>{e.preventDefault(),s(e.dataTransfer.files)},children:[(0,z.jsx)(`div`,{className:`capture-dropzone-mark`,children:(0,z.jsx)(L,{className:`h-6 w-6`})}),(0,z.jsxs)(`div`,{className:`space-y-1`,children:[(0,z.jsx)(`span`,{className:`text-lg font-semibold block`,children:D(e,`capture.files.drop`)}),(0,z.jsx)(`span`,{className:`max-w-md text-sm text-muted-foreground block`,children:D(e,`capture.files.dropDetail`)})]}),(0,z.jsx)(`input`,{type:`file`,multiple:!0,className:`sr-only`,onChange:e=>e.target.files&&s(e.target.files)})]}),(0,z.jsx)(Y,{queue:n,onRetry:e=>s([e])})]})}function q(){let e=M(e=>e.language),t=M(e=>e.mode),n=T({queryKey:[`documents`],queryFn:()=>j.documents(200)}),r=T({queryKey:[`localSources`],queryFn:j.localSources}),i=T({queryKey:[`localAgent`],queryFn:j.localAgent});return(0,z.jsxs)(`div`,{className:`capture-secondary-column space-y-4`,children:[(0,z.jsx)(f,{title:D(e,`capture.files.uploaded`),result:n.data,children:t=>(0,z.jsxs)(`div`,{className:`space-y-3`,children:[(0,z.jsx)(u,{items:t.documents||t,titleKey:`filename`,metaKey:`ingest_state`,limit:12}),(0,z.jsx)(`div`,{className:`rounded-md border border-border bg-background/55 p-3 text-sm text-muted-foreground`,children:D(e,`capture.files.completed`)})]})}),(0,z.jsx)(re,{language:e}),(0,z.jsx)(f,{title:D(e,`capture.local.sources`),result:r.data,children:t=>(0,z.jsxs)(`div`,{className:`space-y-3`,children:[(0,z.jsx)(u,{items:t.sources,titleKey:`path`,metaKey:`status`}),O(t.sources).map(t=>(0,z.jsx)(m,{label:D(e,`capture.local.stop`,{source:String(t.path||t.id||D(e,`capture.local.source`))}),action:()=>j.localWatchStop(String(t.id||t.source_id)),invalidate:[`localSources`]},String(t.id||t.source_id||t.path)))]})}),t===`basic`?null:(0,z.jsx)(f,{title:D(e,`capture.local.access`),result:i.data,children:e=>(0,z.jsx)(h,{value:e})})]})}async function J(e,t){let n=e.map(e=>({id:`${e.name}-${e.size}-${e.lastModified}-${Date.now()}`,file:e,name:oe(e),size:e.size,status:`queued`}));t(e=>[...n,...e].slice(0,12));let r=[];for(let e of n){t(t=>t.map(t=>t.id===e.id?{...t,status:`uploading`}:t));let n=await j.uploadDocument(e.file);r.push(n),t(t=>t.map(t=>t.id===e.id?{...t,status:n.ok?`done`:`failed`,result:n}:t))}return r}function Y({queue:e,onRetry:t}){let n=M(e=>e.language);return e.length?(0,z.jsx)(`div`,{className:`mt-4 space-y-2`,children:e.map(e=>{let r=ie(e,n);return(0,z.jsxs)(`div`,{className:`rounded-md border border-border bg-background/55 p-3 text-sm`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 font-medium`,children:[e.status===`done`?(0,z.jsx)(y,{className:`h-4 w-4 text-emerald-400`}):e.status===`failed`?(0,z.jsx)(_,{className:`h-4 w-4 text-amber-400`}):(0,z.jsx)(o,{className:`h-4 w-4 animate-spin text-primary`}),e.name]}),(0,z.jsxs)(`div`,{className:`mt-1 text-xs text-muted-foreground`,children:[Math.max(1,Math.round(e.size/1024)),` KB · `,r]})]}),e.status===`failed`?(0,z.jsxs)(N,{size:`sm`,variant:`outline`,onClick:()=>t(e.file),children:[(0,z.jsx)(w,{className:`h-3.5 w-3.5`}),` `,D(n,`capture.retry`)]}):null]}),e.result?(0,z.jsx)(s,{result:e.result,successLabel:D(n,`capture.files.success`)}):null]},e.id)})}):null}function ie(e,t){if(e.status===`queued`)return D(t,`capture.files.queued`);if(e.status===`uploading`)return D(t,`capture.files.uploading`);if(!e.result?.ok)return e.result?.error||D(t,`capture.files.failed`);let n=e.result.data||{},r=String(n.node_id||n.graph_node||n.provenance_id||``);return r?D(t,`capture.files.capturedWithNode`,{node:r}):D(t,`capture.files.captured`)}var ae={webkitdirectory:``,directory:``};function oe(e){return e.webkitRelativePath||e.name}function se(e){return(e[0]?.webkitRelativePath||``).split(`/`).filter(Boolean)[0]||``}function X(){let e=window;return!!(e.__TAURI__?.core?.invoke||e.latticeDesktop?.selectFolder||e.__TAURI_INTERNALS__&&window.location.protocol===`tauri:`)}function ce(e){return e instanceof DOMException&&e.name===`AbortError`}async function le(e){let t=[];if(typeof e.values==`function`){for await(let n of e.values())t.push(n);return t}if(typeof e.entries==`function`)for await(let[,n]of e.entries())t.push(n);return t}async function Z(e){let t=[];for(let n of await le(e)){if(n.kind===`file`){t.push(await n.getFile());continue}t.push(...await Z(n))}return t}function Q(){let e=M(e=>e.language),t=r(),n=R.useRef(null),[a,c]=R.useState(``),[l,u]=R.useState(null),[d,f]=R.useState(``),[p,m]=R.useState(!1),[h,g]=R.useState([]),_=i({mutationFn:e=>j.connectFolder(e.trim()),onSuccess:()=>{u(null),t.invalidateQueries({queryKey:[`localSources`]}),t.invalidateQueries({queryKey:[`graphStats`]}),t.invalidateQueries({queryKey:[`memoryManager`]})}}),v=i({mutationFn:e=>J(e,g),onSuccess:()=>{t.invalidateQueries({queryKey:[`documents`]}),t.invalidateQueries({queryKey:[`graphStats`]}),t.invalidateQueries({queryKey:[`memoryManager`]})}}),y=R.useCallback((t,n)=>{if(!t.length){u(D(e,`capture.local.emptyFolder`));return}u(null),f(n||se(t)||D(e,`capture.local.browserFolder`)),v.mutate(t)},[v,e]),x=R.useCallback(async()=>{if(!p){m(!0),u(null);try{let t=window.showDirectoryPicker;if(!X()&&typeof t==`function`){let e=await t.call(window);y(await Z(e),e.name);return}if(X()){let e=await j.selectFolder();if(e){f(``),c(e),_.mutate(e);return}}if(typeof t==`function`){let e=await t.call(window);y(await Z(e),e.name);return}if(n.current){n.current.click();return}u(D(e,`capture.local.pickUnavailable`))}catch(t){ce(t)||u(D(e,`capture.local.pickUnavailable`))}finally{m(!1)}}},[y,p,_,e]),S=R.useCallback(()=>{let e=a.trim();e&&(u(null),f(``),_.mutate(e))},[_,a]),C=(v.data||[]).find(e=>!e.ok)?.error,w=!!(v.error||C);return(0,z.jsxs)(`div`,{className:`space-y-3`,children:[(0,z.jsxs)(`div`,{className:`capture-intake-lead`,children:[(0,z.jsx)(b,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:D(e,`capture.local.title`)}),(0,z.jsx)(`p`,{children:D(e,`capture.local.description`)})]})]}),(0,z.jsxs)(`form`,{className:`space-y-3`,onSubmit:e=>{e.preventDefault(),S()},children:[(0,z.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,z.jsx)(P,{value:a,onChange:e=>c(e.target.value),placeholder:D(e,`capture.local.placeholder`)}),(0,z.jsxs)(N,{type:`button`,variant:`outline`,disabled:p||_.isPending||v.isPending,onClick:()=>void x(),children:[p?(0,z.jsx)(o,{className:`h-4 w-4 animate-spin`}):(0,z.jsx)(ee,{className:`h-4 w-4`}),p?D(e,`capture.local.choosing`):D(e,`capture.local.choose`)]})]}),(0,z.jsx)(`input`,{ref:n,type:`file`,multiple:!0,className:`sr-only`,"aria-hidden":`true`,tabIndex:-1,...ae,onChange:e=>{let t=Array.from(e.currentTarget.files||[]);e.currentTarget.value=``,y(t)}}),(0,z.jsxs)(N,{type:`submit`,disabled:!a.trim()||_.isPending,children:[_.isPending?(0,z.jsx)(o,{className:`h-4 w-4 animate-spin`}):(0,z.jsx)(I,{className:`h-4 w-4`}),D(e,`capture.local.connect`)]})]}),l?(0,z.jsx)(s,{result:{ok:!1,status:0,data:{},source:`unavailable`,error:l}}):null,_.data?(0,z.jsx)(s,{result:_.data,successLabel:D(e,`capture.local.success`)}):null,d?(0,z.jsx)(s,{result:{ok:v.isPending||!w,status:w?0:200,data:{folder:d},source:w?`unavailable`:`live`,error:v.error?D(e,`capture.local.browserImportFailed`):C},successLabel:v.isPending?D(e,`capture.local.browserImporting`):D(e,`capture.local.browserImportSuccess`,{folder:d})}):null,(0,z.jsx)(Y,{queue:h,onRetry:e=>y([e],d)})]})}function ue(){let e=M(e=>e.language),t=r(),[n,a]=R.useState(``),c=i({mutationFn:e=>j.browserReadUrl(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`graphStats`]}),t.invalidateQueries({queryKey:[`memoryManager`]})}}),l=R.useCallback(()=>{let e=$(n);e&&(a(e),c.mutate(e))},[c,n]),u=R.useCallback(async()=>{let e=$(await navigator.clipboard?.readText().catch(()=>``)||``);e&&(a(e),c.mutate(e))},[c]);return(0,z.jsxs)(`div`,{className:`space-y-3`,children:[(0,z.jsxs)(`div`,{className:`capture-intake-lead`,children:[(0,z.jsx)(x,{className:`h-4 w-4`,"aria-hidden":`true`}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:D(e,`capture.browser.title`)}),(0,z.jsx)(`p`,{children:D(e,`capture.browser.description`)})]})]}),(0,z.jsxs)(`form`,{className:`flex flex-col gap-2 sm:flex-row`,onSubmit:e=>{e.preventDefault(),l()},children:[(0,z.jsx)(P,{value:n,onChange:e=>a(e.target.value),placeholder:D(e,`capture.browser.placeholder`),inputMode:`url`}),(0,z.jsxs)(N,{type:`button`,variant:`outline`,disabled:c.isPending,onClick:()=>void u(),children:[(0,z.jsx)(F,{className:`h-4 w-4`}),` `,D(e,`capture.browser.paste`)]}),(0,z.jsxs)(N,{type:`submit`,disabled:!n.trim()||c.isPending,children:[c.isPending?(0,z.jsx)(o,{className:`h-4 w-4 animate-spin`}):(0,z.jsx)(I,{className:`h-4 w-4`}),D(e,`capture.browser.capture`)]})]}),c.data?(0,z.jsx)(s,{result:c.data,successLabel:D(e,`capture.browser.success`)}):null]})}function $(e){let t=e.trim();return t?/^https?:\/\//i.test(t)?t:/^[\w.-]+\.[a-z]{2,}([/:?#].*)?$/i.test(t)?`https://${t}`:t:``}function de(e,t,n){let r=A(e)?e:{},i=A(t)?t:{},a=A(n)?n:{};A(i.pipelines)&&i.pipelines;let o=(...e)=>{for(let t of e){if(typeof t==`number`&&Number.isFinite(t)&&t>=0)return Math.round(t);let e=Number(t);if(Number.isFinite(e)&&e>0)return Math.round(e)}},s=o(r.received),c=o(r.extracted),l=o(r.connected),u=o(c,i.total,i.total_items,a.nodes,a.total_nodes)||0,d=o(l,a.edges,a.total_edges)||0,f=o(i.pending,i.pending_items)||0,p=(e,t)=>{let n=r.stages||{};for(let t of e){let e=n[t],r=typeof e==`object`&&e?e.status:e;if(r===`done`||r===`working`||r===`waiting`||r===`error`)return r}return t},m=s===void 0?f?`working`:u?`done`:`waiting`:s>0?`done`:`waiting`,h=c===void 0?u?`done`:`waiting`:c>0?`done`:`waiting`,g=l===void 0?d?`done`:`waiting`:l>0?`done`:`waiting`,_=p([`read`,`received`],m),v=p([`understand`,`extracted`],h),y=p([`connect`,`connected`],g);return{remembered:u,connections:d,waiting:f,received:s??f,extracted:c??u,connected:l??d,steps:[{key:`read`,state:_,count:s??(u||f)},{key:`understand`,state:v,count:c??u},{key:`connect`,state:y,count:l??d}]}}function fe(){let e=M(e=>e.language),t=M(e=>e.mode),n=T({queryKey:[`index`],queryFn:j.indexStatus}),r=T({queryKey:[`graphStats`],queryFn:j.graphStats}),i=T({queryKey:[`pipelineStatus`],queryFn:j.pipelineStatus}),o=de(i.data?.data||i.data,n.data?.data,r.data?.data),s={read:I,understand:v,connect:C},u=!!(o.remembered||o.connections||o.received&&o.received>0);return(0,z.jsxs)(`div`,{className:`capture-secondary-column space-y-4`,children:[(0,z.jsxs)(p,{children:[(0,z.jsxs)(c,{children:[(0,z.jsxs)(a,{className:`flex items-center gap-2`,children:[(0,z.jsx)(I,{className:`h-4 w-4`}),` `,D(e,`capture.pipeline.journey.title`)]}),(0,z.jsx)(l,{children:D(e,`capture.pipeline.journey.detail`)})]}),(0,z.jsxs)(d,{className:`space-y-4`,children:[(0,z.jsx)(`ol`,{className:`capture-journey flex flex-col md:flex-row gap-3 items-stretch`,"aria-label":D(e,`capture.pipeline.journey.aria`),children:o.steps.map(({key:t,state:n,count:r})=>{let i=s[t];return(0,z.jsxs)(`li`,{className:`capture-journey-step is-${n} flex-1 p-3 rounded-lg border border-border/60 bg-muted/20 flex flex-col justify-between`,children:[(0,z.jsxs)(`div`,{className:`capture-journey-step-header flex items-center gap-2`,children:[(0,z.jsx)(`span`,{className:`capture-journey-mark`,"aria-hidden":`true`,children:(0,z.jsx)(i,{className:`h-4 w-4`})}),(0,z.jsxs)(`div`,{className:`capture-journey-copy min-w-0 flex-1`,children:[(0,z.jsx)(`strong`,{className:`block text-sm`,children:D(e,`capture.pipeline.step.${t}`)}),(0,z.jsx)(`small`,{className:`block text-xs text-muted-foreground`,children:D(e,`capture.pipeline.step.${t}.detail`)})]})]}),(0,z.jsxs)(`div`,{className:`capture-journey-step-meta flex items-center justify-between gap-2 mt-3 pt-2 border-t border-border/40 text-xs`,children:[(0,z.jsx)(g,{variant:`muted`,className:`capture-journey-count`,children:D(e,`ui.value.records`,{count:r})}),(0,z.jsx)(`span`,{className:`capture-journey-state`,children:D(e,`capture.pipeline.step.${n}`)})]})]},t)})}),u?(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-sm pt-2`,children:[(0,z.jsx)(g,{variant:`success`,children:D(e,`capture.pipeline.count.remembered`,{count:k(o.extracted)})}),(0,z.jsx)(g,{variant:`muted`,children:D(e,`capture.pipeline.count.connections`,{count:k(o.connected)})}),(0,z.jsx)(g,{variant:o.waiting?`warning`:`muted`,children:o.waiting?D(e,`capture.pipeline.count.waiting`,{count:k(o.waiting)}):D(e,`capture.pipeline.count.none`)})]}):(0,z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:D(e,`capture.pipeline.empty`)})]})]}),(0,z.jsxs)(p,{children:[(0,z.jsxs)(c,{children:[(0,z.jsxs)(a,{className:`flex items-center gap-2`,children:[(0,z.jsx)(S,{className:`h-4 w-4`}),` `,D(e,`capture.pipeline.refresh`)]}),(0,z.jsx)(l,{children:D(e,`capture.pipeline.description`)})]}),(0,z.jsx)(d,{children:(0,z.jsx)(m,{label:D(e,`capture.pipeline.rebuild`),action:()=>j.rebuildIndex(),invalidate:[`index`]})})]}),t===`basic`?null:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(f,{title:D(e,`capture.pipeline.status`),result:n.data,children:e=>(0,z.jsx)(h,{value:e})}),(0,z.jsx)(f,{title:D(e,`capture.pipeline.growth`),result:r.data,children:e=>(0,z.jsx)(h,{value:e})})]})]})}export{G as CapturePage};