@mingxy/cerebro 1.18.9 → 1.18.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,56 +1,56 @@
1
- {
2
- "name": "@mingxy/cerebro",
3
- "version": "1.18.9",
4
- "description": "Cerebro persistent memory plugin for OpenCode — auto-recall, auto-capture, 9 memory tools with clustering, project-scoped memory isolation",
5
- "type": "module",
6
- "main": "src/index.ts",
7
- "exports": {
8
- ".": {
9
- "types": "./src/index.ts",
10
- "default": "./src/index.ts"
11
- },
12
- "./tui": {
13
- "types": "./src/tui.tsx",
14
- "default": "./src/tui.tsx"
15
- }
16
- },
17
- "oc-plugin": [
18
- "server",
19
- "tui"
20
- ],
21
- "scripts": {
22
- "build:web": "bash ../../scripts/build-plugin-web.sh",
23
- "prepublishOnly": "npm run build:web && npx tsc --noEmit"
24
- },
25
- "keywords": [
26
- "opencode",
27
- "memory",
28
- "ai-agent",
29
- "persistent-memory",
30
- "cerebro",
31
- "clustering",
32
- "project-isolation"
33
- ],
34
- "author": "mingxy-cerebro",
35
- "files": [
36
- "src/",
37
- "web/"
38
- ],
39
- "license": "Apache-2.0",
40
- "homepage": "https://github.com/mingxy-cerebro/cerebro-server",
41
- "repository": {
42
- "type": "git",
43
- "url": "https://github.com/mingxy-cerebro/cerebro-server.git",
44
- "directory": "plugins/opencode"
45
- },
46
- "dependencies": {
47
- "@opencode-ai/plugin": "^1.0.162",
48
- "@opentui/core": "^0.1.92",
49
- "@opentui/solid": "^0.1.92",
50
- "solid-js": "^1.9.10"
51
- },
52
- "devDependencies": {
53
- "@types/node": "^25.5.0",
54
- "typescript": "^5.7.0"
55
- }
56
- }
1
+ {
2
+ "name": "@mingxy/cerebro",
3
+ "version": "1.18.10",
4
+ "description": "Cerebro persistent memory plugin for OpenCode — auto-recall, auto-capture, 9 memory tools with clustering, project-scoped memory isolation",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./src/index.ts",
10
+ "default": "./src/index.ts"
11
+ },
12
+ "./tui": {
13
+ "types": "./src/tui.tsx",
14
+ "default": "./src/tui.tsx"
15
+ }
16
+ },
17
+ "oc-plugin": [
18
+ "server",
19
+ "tui"
20
+ ],
21
+ "scripts": {
22
+ "build:web": "bash ../../scripts/build-plugin-web.sh",
23
+ "prepublishOnly": "npm run build:web && npx tsc --noEmit"
24
+ },
25
+ "keywords": [
26
+ "opencode",
27
+ "memory",
28
+ "ai-agent",
29
+ "persistent-memory",
30
+ "cerebro",
31
+ "clustering",
32
+ "project-isolation"
33
+ ],
34
+ "author": "mingxy-cerebro",
35
+ "files": [
36
+ "src/",
37
+ "web/"
38
+ ],
39
+ "license": "Apache-2.0",
40
+ "homepage": "https://github.com/mingxy-cerebro/cerebro-server",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "https://github.com/mingxy-cerebro/cerebro-server.git",
44
+ "directory": "plugins/opencode"
45
+ },
46
+ "dependencies": {
47
+ "@opencode-ai/plugin": "^1.0.162",
48
+ "@opentui/core": "^0.1.92",
49
+ "@opentui/solid": "^0.1.92",
50
+ "solid-js": "^1.9.10"
51
+ },
52
+ "devDependencies": {
53
+ "@types/node": "^25.5.0",
54
+ "typescript": "^5.7.0"
55
+ }
56
+ }
@@ -161,4 +161,4 @@ $1`).replace(/(\s-\s)/g,`
161
161
  `)?e:e.replace(/(#{1,3}\s+[^#])/g,`
162
162
  $1`).replace(/(\d+\.\s+[^\d])/g,`
163
163
  $1`).replace(/(\s-\s)/g,`
164
- - `).trim()}function Yme(e){return new Date(e).toLocaleString(`zh-CN`,{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function Xme(e){return e?e.length<=16?e:e.slice(0,8)+`...`+e.slice(-8):`—`}function Zme(e,n=80){return e?e.length<=n?e:e.slice(0,n)+`...`:`—`}function Qme({type:e}){return e===`auto`?(0,K.jsxs)(hJ,{variant:`secondary`,className:`text-xs bg-blue-100 text-blue-700 hover:bg-blue-100 border-blue-200`,children:[(0,K.jsx)(ih,{className:`size-3 mr-1`}),`自动注入`]}):(0,K.jsxs)(hJ,{variant:`outline`,className:`text-xs bg-emerald-50 text-emerald-700 hover:bg-emerald-50 border-emerald-200`,children:[(0,K.jsx)(Mm,{className:`size-3 mr-1`}),`手动注入`]})}function $me({category:e}){return(0,K.jsx)(hJ,{variant:`outline`,className:`text-xs font-normal ${SJ(e)}`,children:e||`未分类`})}function h9({label:e,value:n,max:r=1}){let i=Math.max(0,Math.min(n,r))/r*100;return(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,K.jsx)(`span`,{className:`font-medium`,children:n===0?`—`:`${i.toFixed(1)}%`})]}),(0,K.jsx)(`div`,{className:`h-1.5 w-full rounded-full bg-muted overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full bg-primary transition-all`,style:{width:`${i}%`}})})]})}function ehe({relevance:e,isKept:n}){return n?e===`high`?(0,K.jsx)(hJ,{variant:`outline`,className:`text-xs bg-emerald-500/10 text-emerald-600 border-emerald-500/30`,children:`🟢 高相关`}):e===`medium`?(0,K.jsx)(hJ,{variant:`outline`,className:`text-xs bg-yellow-500/10 text-yellow-600 border-yellow-500/30`,children:`🟡 中相关`}):(0,K.jsx)(hJ,{variant:`outline`,className:`text-xs bg-muted text-muted-foreground border-border`,children:e||`—`}):(0,K.jsx)(hJ,{variant:`outline`,className:`text-xs bg-red-500/10 text-red-600 border-red-500/30`,children:`🔴 被精炼掉`})}function the({item:e,memory:n,memoryLoading:r,vaultUnlocked:i,memoryUnlocked:a,onUnlock:o,onLock:s,onVaultUnlock:c}){let[l,u]=(0,y.useState)(`refine`),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(null),_=ob(e=>e.unlock),v=ob(e=>e.isUnlocked),b=n?.visibility===`private`||(n?.tags||[]).some(e=>e===`私密`||e.toLowerCase()===`private`),x=b&&!a,S=async()=>{n&&(x?i||v?o?.(n.id):f(!0):(s?.(n.id),f(!1)))},C=async()=>{if(!p.trim()){g(`请输入密码`);return}await _(p)?(f(!1),m(``),g(null),c?.(),n&&o?.(n.id)):g(`密码错误`)};return(0,K.jsxs)(`div`,{className:`rounded-md border bg-muted/50 p-3 space-y-3 ${e.is_kept?`border-border`:`border-dashed border-red-500/30 opacity-75`}`,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,K.jsx)(ehe,{relevance:e.refine_relevance,isKept:e.is_kept}),(0,K.jsx)($me,{category:n?.category}),b&&(0,K.jsxs)(hJ,{variant:`secondary`,className:`text-xs bg-amber-100 text-amber-700 hover:bg-amber-100 border-amber-200`,children:[(0,K.jsx)(Em,{className:`size-3 mr-1`}),`私密`]}),(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground font-mono`,children:[e.memory_id?.slice(0,8),`...`]})]}),b&&(0,K.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),S()},className:`text-xs text-amber-500 hover:text-amber-600 flex items-center gap-1 shrink-0`,children:[x?(0,K.jsx)(Em,{className:`size-3`}):(0,K.jsx)(Tm,{className:`size-3`}),x?`解锁`:`锁定`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-border pb-1`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>u(`refine`),className:`text-xs px-2 py-1 rounded transition-colors ${l===`refine`?`bg-primary/10 text-primary font-medium`:`text-muted-foreground hover:text-foreground`}`,children:`精炼`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>u(`raw`),className:`text-xs px-2 py-1 rounded transition-colors ${l===`raw`?`bg-primary/10 text-primary font-medium`:`text-muted-foreground hover:text-foreground`}`,children:`原始`})]}),l===`refine`?(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`text-sm text-foreground`,children:[(0,K.jsx)(`span`,{className:`font-medium`,children:`推理说明:`}),(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:e.refine_reasoning||`—`})]}),(0,K.jsx)(h9,{label:`相似度得分`,value:e.score,max:1})]}):(0,K.jsx)(`div`,{className:`space-y-2`,children:r?(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(Tb,{className:`h-4 w-3/4`}),(0,K.jsx)(Tb,{className:`h-4 w-1/2`})]}):n?(0,K.jsx)(K.Fragment,{children:x?(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,K.jsx)(Em,{className:`size-4`}),(0,K.jsx)(`span`,{children:`私密记忆内容已隐藏`})]}),d&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(hb,{type:`password`,placeholder:`输入 Vault 密码...`,value:p,onChange:e=>{m(e.target.value),g(null)},onKeyDown:e=>e.key===`Enter`&&C(),className:h?`border-destructive flex-1`:`flex-1`}),(0,K.jsx)(J,{size:`sm`,onClick:C,children:`解锁`})]}),h&&(0,K.jsx)(`p`,{className:`text-xs text-destructive`,children:h})]})]}):(0,K.jsx)(`div`,{className:`prose prose-sm dark:prose-invert max-w-none`,children:(0,K.jsx)(p0,{remarkPlugins:[Y4],children:Jme(n.content||n.l0_abstract||`—`)})})}):(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`记忆内容加载失败`})})]})}function nhe({event:e,initialItems:n,isLast:r,defaultExpanded:i,vaultUnlocked:a,unlockedMemories:o,manuallyLocked:s,onUnlock:c,onLock:l,onVaultUnlock:u}){let[d,f]=(0,y.useState)(i||!1),[p,m]=(0,y.useState)(!0),[h,g]=(0,y.useState)(n??null),[_,v]=(0,y.useState)(new Map),[b,x]=(0,y.useState)(new Set);(0,y.useEffect)(()=>{n&&h===null&&g(n)},[n,h]);let S=(0,y.useCallback)(async e=>{if(!(_.has(e)||b.has(e)))try{x(n=>new Set(n).add(e));let n=await ib.get(`/v1/memories/${e}`);v(r=>{let i=new Map(r);return i.set(e,n),i})}catch(e){console.error(`Failed to fetch memory:`,e)}finally{x(n=>{let r=new Set(n);return r.delete(e),r})}},[_,b]);(0,y.useEffect)(()=>{!d||!h||h.length===0||h.forEach(e=>{!_.has(e.memory_id)&&!b.has(e.memory_id)&&S(e.memory_id)})},[d,h,_,b,S]);let C=e=>a&&!s.has(e)||o.has(e);return(0,K.jsxs)(`div`,{className:`flex gap-4`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col items-center`,children:[(0,K.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full bg-primary ring-4 ring-primary/20`}),!r&&(0,K.jsx)(`div`,{className:`w-px flex-1 bg-border mt-1`})]}),(0,K.jsx)(`div`,{className:`flex-1 pb-6`,children:(0,K.jsxs)(`div`,{className:`rounded-lg border border-border bg-card transition-colors hover:bg-muted/50`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>f(!d),className:`w-full text-left p-4 cursor-pointer`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,K.jsx)(Qme,{type:e.recall_type}),(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground flex items-center gap-1`,children:[(0,K.jsx)(nm,{className:`size-3`}),Yme(e.created_at)]})]}),d?(0,K.jsx)($p,{className:`size-4 text-muted-foreground`}):(0,K.jsx)(Xp,{className:`size-4 text-muted-foreground`})]}),(0,K.jsxs)(`div`,{className:`mt-2 text-sm text-muted-foreground flex items-center gap-1.5`,children:[(0,K.jsx)(Vm,{className:`size-3.5`}),(0,K.jsx)(`span`,{className:`line-clamp-1`,title:e.query_text||`—`,children:Zme(e.query_text)})]})]}),d&&(0,K.jsxs)(`div`,{className:`px-4 pb-4 space-y-4 border-t border-border pt-4`,children:[e.profile_content&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`h4`,{className:`text-xs font-medium text-muted-foreground flex items-center gap-1`,children:[(0,K.jsx)(Gp,{className:`size-3`}),`画像注入内容`]}),(0,K.jsx)(`div`,{className:`rounded-md border border-indigo-500/20 bg-indigo-500/5 p-3`,children:(0,K.jsx)(`div`,{className:`prose prose-sm dark:prose-invert max-w-none text-sm text-indigo-700 dark:text-indigo-300`,children:(0,K.jsx)(p0,{remarkPlugins:[Y4],children:e.profile_content.replace(/<\/?cerebro-profile>/g,``).trim()})})})]}),e.injected_content&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>m(!p),className:`flex items-center gap-1 text-xs font-medium text-muted-foreground hover:text-foreground transition-colors cursor-pointer`,children:[(0,K.jsx)(rm,{className:`size-3`}),`注入内容`,p?(0,K.jsx)($p,{className:`size-3`}):(0,K.jsx)(Xp,{className:`size-3`})]}),p&&(0,K.jsx)(`div`,{className:`rounded-md border border-emerald-500/20 bg-emerald-500/5 p-3 max-h-96 overflow-y-auto`,children:(0,K.jsx)(`div`,{className:`prose prose-sm dark:prose-invert max-w-none text-sm text-emerald-700 dark:text-emerald-300`,children:(0,K.jsx)(p0,{remarkPlugins:[Y4],children:e.injected_content.replace(/<\/?cerebro-context>/g,``).trim()})})})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,K.jsxs)(`h4`,{className:`text-xs font-medium text-muted-foreground flex items-center gap-1`,children:[(0,K.jsx)(Gp,{className:`size-3`}),`关联记忆`]})}),h&&h.length>0?(0,K.jsx)(`div`,{className:`space-y-3`,children:h.map(e=>(0,K.jsx)(the,{item:e,memory:_.get(e.memory_id)||null,memoryLoading:b.has(e.memory_id),vaultUnlocked:a,memoryUnlocked:C(e.memory_id),onUnlock:c,onLock:l,onVaultUnlock:u},e.id))}):(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`暂无召回项`})]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`h4`,{className:`text-xs font-medium text-muted-foreground flex items-center gap-1`,children:[(0,K.jsx)(Jp,{className:`size-3`}),`匹配指标`]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,K.jsx)(h9,{label:`最大相似度`,value:e.max_score}),(0,K.jsx)(h9,{label:`LLM 置信度`,value:e.llm_confidence})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground flex-wrap`,children:[(0,K.jsx)(`span`,{className:`font-medium text-foreground`,children:`统计:`}),(0,K.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:[`保留 `,e.kept_count,` 条`]}),(0,K.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,children:[`精炼掉 `,e.discarded_count,` 条`]}),e.injected_count!=null&&e.injected_count>0&&(0,K.jsxs)(`span`,{className:`text-blue-600 dark:text-blue-400`,children:[`实际注入 `,e.injected_count,` 条`]}),e.profile_injected&&(0,K.jsx)(`span`,{className:`text-indigo-600 dark:text-indigo-400`,children:`👤 画像已注入`})]})]})]})})]})}function rhe(){let{id:e}=it(),n=et(),r=Ze(),i=()=>{let e=r.state;e?.from?n(e.from,{replace:!0}):n(-1)},a=e?decodeURIComponent(e):``,[o,s]=(0,y.useState)([]),[c,l]=(0,y.useState)(new Map),[u,d]=(0,y.useState)(!0),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(1),[g,_]=(0,y.useState)(!1),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(``),[C,w]=(0,y.useState)(null),T=ob(e=>e.unlock),E=ob(e=>e.lock),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(new Set),[j,M]=(0,y.useState)(new Set),[N,P]=(0,y.useState)(null),F=Math.ceil(o.length/10),I=o.slice((m-1)*10,m*10);(0,y.useEffect)(()=>{if(!a)return;async function e(){try{d(!0),p(null);let e=await ib.get(`/v1/recall-events`,{params:{session_id:a,limit:1e4,offset:0,expand:`items`}});if(s((e?.events||[]).sort((e,n)=>new Date(n.created_at).getTime()-new Date(e.created_at).getTime())),e?.event_items){let n=new Map;e.event_items.forEach(e=>n.set(e.id,e.items||[])),l(n)}}catch(e){console.error(`Failed to fetch session detail:`,e),p(`加载 Session 详情失败`),G.error(`加载 Session 详情失败`)}finally{d(!1)}}e()},[a]);let L=()=>{_(!0)},R=async()=>{try{await ib.delete(`/v1/session-recalls/session/${a}`),G.success(`Session 记录已删除`),n(-1)}catch(e){console.error(`Failed to delete session records:`,e),G.error(`删除失败`)}finally{_(!1)}},z=async()=>{if(!x.trim()){w(`请输入密码`);return}if(!await T(x)){w(`密码错误`);return}O(!0),N&&(A(e=>new Set(e).add(N)),P(null)),w(null),b(!1),S(``)},ee=()=>{O(!1),A(new Set),M(new Set),E()},B=e=>{k.has(e)||D&&!j.has(e)?(M(n=>new Set(n).add(e)),A(n=>{let r=new Set(n);return r.delete(e),r})):D?M(n=>{let r=new Set(n);return r.delete(e),r}):(P(e),b(!0))},V={total:o.length,auto:o.filter(e=>e.recall_type===`auto`).length,manual:o.filter(e=>e.recall_type===`manual`).length,totalKept:o.reduce((e,n)=>e+n.kept_count,0),totalDiscarded:o.reduce((e,n)=>e+n.discarded_count,0)};return u?(0,K.jsxs)(`div`,{className:`space-y-6 max-w-3xl`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Tb,{className:`h-8 w-8`}),(0,K.jsx)(Tb,{className:`h-6 w-32`})]}),(0,K.jsx)(Tb,{className:`h-4 w-1/2`}),(0,K.jsx)(`div`,{className:`space-y-4`,children:[1,2,3].map(e=>(0,K.jsxs)(`div`,{className:`flex gap-4`,children:[(0,K.jsx)(Tb,{className:`h-3 w-3 rounded-full`}),(0,K.jsx)(`div`,{className:`flex-1 space-y-2`,children:(0,K.jsx)(Tb,{className:`h-20 w-full`})})]},e))})]}):f?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(J,{variant:`ghost`,size:`sm`,onClick:()=>i(),children:[(0,K.jsx)(Bp,{className:`size-4 mr-1.5`}),`返回`]}),(0,K.jsx)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-sm text-destructive`,children:f})]}):(0,K.jsxs)(`div`,{className:`space-y-6 max-w-3xl`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,K.jsxs)(J,{variant:`ghost`,size:`sm`,onClick:()=>i(),children:[(0,K.jsx)(Bp,{className:`size-4 mr-1.5`}),`返回`]})})}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:[`Session 详情 - `,Xme(a)]}),(0,K.jsx)(`div`,{className:`flex items-center gap-3 text-sm text-muted-foreground flex-wrap`,children:(0,K.jsx)(`code`,{className:`font-mono text-xs bg-muted px-1.5 py-0.5 rounded`,children:a})})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,K.jsx)(bb,{children:(0,K.jsxs)(wb,{className:`pt-4 text-center`,children:[(0,K.jsx)(`div`,{className:`text-2xl font-semibold`,children:V.total}),(0,K.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`总召回事件`})]})}),(0,K.jsx)(bb,{children:(0,K.jsxs)(wb,{className:`pt-4 text-center`,children:[(0,K.jsx)(`div`,{className:`text-2xl font-semibold`,children:V.auto}),(0,K.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`自动注入`})]})}),(0,K.jsx)(bb,{children:(0,K.jsxs)(wb,{className:`pt-4 text-center`,children:[(0,K.jsx)(`div`,{className:`text-2xl font-semibold`,children:V.manual}),(0,K.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`手动注入`})]})})]}),(V.totalKept>0||V.totalDiscarded>0)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[(0,K.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400 font-medium`,children:[`共保留 `,V.totalKept,` 条记忆`]}),(0,K.jsxs)(`span`,{className:`text-red-600 dark:text-red-400 font-medium`,children:[`共精炼掉 `,V.totalDiscarded,` 条记忆`]})]}),(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-2`,children:[(0,K.jsx)(`h2`,{className:`text-sm font-medium text-muted-foreground`,children:`召回事件时间线`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`共 `,o.length,` 个事件`]}),F>1&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>h(e=>Math.max(1,e-1)),disabled:m===1,children:(0,K.jsx)(Zp,{className:`size-3`})}),(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground min-w-[3ch] text-center`,children:[m,`/`,F]}),(0,K.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>h(e=>Math.min(F,e+1)),disabled:m===F,children:(0,K.jsx)(Qp,{className:`size-3`})})]}),D?(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:ee,children:[(0,K.jsx)(Em,{className:`size-3.5 mr-1`}),`锁定 Vault`]}):(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>b(!v),children:[(0,K.jsx)(Tm,{className:`size-3.5 mr-1`}),`解锁 Vault`]})]})]}),v&&(0,K.jsxs)(`div`,{className:`space-y-2 max-w-md`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(hb,{type:`password`,placeholder:`输入 Vault 密码...`,value:x,onChange:e=>{S(e.target.value),w(null)},onKeyDown:e=>e.key===`Enter`&&z(),className:C?`border-destructive flex-1`:`flex-1`}),(0,K.jsx)(J,{size:`sm`,onClick:z,children:`解锁`})]}),C&&(0,K.jsx)(`p`,{className:`text-xs text-destructive`,children:C})]}),o.length===0?(0,K.jsx)(`div`,{className:`rounded-lg border border-border bg-card p-8 text-center text-sm text-muted-foreground`,children:`暂无召回事件`}):(0,K.jsxs)(K.Fragment,{children:[I.map((e,n)=>(0,K.jsx)(nhe,{event:e,initialItems:c.get(e.id),isLast:n===I.length-1&&m===F,defaultExpanded:n===0&&m===1,vaultUnlocked:D,unlockedMemories:k,manuallyLocked:j,onUnlock:B,onLock:B,onVaultUnlock:()=>O(!0)},e.id)),F>1&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2 pt-4`,children:[(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`共 `,o.length,` 个事件`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(J,{variant:`outline`,size:`sm`,onClick:()=>h(e=>Math.max(1,e-1)),disabled:m===1,children:(0,K.jsx)(Zp,{className:`size-4`})}),(0,K.jsxs)(`span`,{className:`text-sm text-muted-foreground`,children:[m,` / `,F]}),(0,K.jsx)(J,{variant:`outline`,size:`sm`,onClick:()=>h(e=>Math.min(F,e+1)),disabled:m===F,children:(0,K.jsx)(Qp,{className:`size-4`})})]})]})]})]}),o.length>0&&(0,K.jsx)(`div`,{className:`pt-4 border-t border-border`,children:(0,K.jsxs)(J,{variant:`outline`,size:`sm`,className:`text-destructive hover:bg-destructive/10 hover:text-destructive`,onClick:L,children:[(0,K.jsx)(Xm,{className:`size-3.5 mr-1`}),`删除 Session 所有记录`]})}),(0,K.jsx)(aJ,{open:g,onOpenChange:e=>!e&&_(!1),children:(0,K.jsxs)(oJ,{children:[(0,K.jsxs)(sJ,{children:[(0,K.jsx)(lJ,{children:`确认删除 Session 记录`}),(0,K.jsx)(uJ,{children:`此操作将删除该 Session 的所有召回记录,不可撤销。确定要继续吗?`})]}),(0,K.jsxs)(cJ,{children:[(0,K.jsx)(fJ,{onClick:()=>_(!1),children:`取消`}),(0,K.jsx)(dJ,{onClick:R,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`删除`})]})]})})]})}function g9({...e}){return(0,K.jsx)(yg,{"data-slot":`dialog`,...e})}function ihe({...e}){return(0,K.jsx)(xg,{"data-slot":`dialog-trigger`,...e})}function ahe({...e}){return(0,K.jsx)(tg,{"data-slot":`dialog-portal`,...e})}function ohe({className:e,...n}){return(0,K.jsx)(Ah,{"data-slot":`dialog-overlay`,className:wp(`fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0`,e),...n})}function _9({className:e,children:n,showCloseButton:r=!0,...i}){return(0,K.jsxs)(ahe,{children:[(0,K.jsx)(ohe,{}),(0,K.jsxs)($h,{"data-slot":`dialog-content`,className:wp(`fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95`,e),...i,children:[n,r&&(0,K.jsxs)(jh,{"data-slot":`dialog-close`,render:(0,K.jsx)(J,{variant:`ghost`,className:`absolute top-2 right-2`,size:`icon-sm`}),children:[(0,K.jsx)(rh,{}),(0,K.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function v9({className:e,...n}){return(0,K.jsx)(`div`,{"data-slot":`dialog-header`,className:wp(`flex flex-col gap-2`,e),...n})}function y9({className:e,showCloseButton:n=!1,children:r,...i}){return(0,K.jsxs)(`div`,{"data-slot":`dialog-footer`,className:wp(`-mx-4 -mb-4 flex flex-col-reverse gap-2 rounded-b-xl border-t bg-muted/50 p-4 sm:flex-row sm:justify-end`,e),...i,children:[r,n&&(0,K.jsx)(jh,{render:(0,K.jsx)(J,{variant:`outline`}),children:`Close`})]})}function b9({className:e,...n}){return(0,K.jsx)(bg,{"data-slot":`dialog-title`,className:wp(`text-base leading-none font-medium`,e),...n})}function x9({className:e,...n}){return(0,K.jsx)(Mh,{"data-slot":`dialog-description`,className:wp(`text-sm text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground`,e),...n})}function she(){let[e,n]=(0,y.useState)([]),[r,i]=(0,y.useState)(!0),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`team`),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(`member`),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)({}),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(`member`),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(null),[I,L]=(0,y.useState)(!1),R=hh(e=>e.currentUserId),z=hh(e=>e.users.find(e=>e.id===R)),ee=e.find(e=>e.id===p),B=e=>z?e.owner_id===z.apiKey||e.members.some(e=>e.user_id===z.apiKey&&(e.role===`admin`||e.role===`Admin`)):!1;(0,y.useEffect)(()=>{async function e(){if(!ee?.members?.length)return;T(!0);let e={};await Promise.all(ee.members.map(async n=>{try{let r=await ib.get(`/v1/tenants/${encodeURIComponent(n.user_id)}`);r&&(e[n.user_id]={name:r.name,created_at:r.created_at})}catch{}})),C(e),T(!1)}p&&e()},[p,ee?.members]),(0,y.useEffect)(()=>{async function e(){try{i(!0),n(await ib.get(`/v1/spaces`)||[])}catch(e){console.error(`Failed to fetch spaces:`,e),G.error(`加载空间列表失败`)}finally{i(!1)}}e()},[]);async function V(){if(!s.trim()){G.error(`请输入空间名称`);return}try{await ib.post(`/v1/spaces`,{name:s.trim(),space_type:l}),G.success(`空间创建成功`),o(!1),c(``),n(await ib.get(`/v1/spaces`)||[])}catch(e){console.error(`Failed to create space:`,e),G.error(`空间创建失败`)}}async function H(){if(!d)return;let r=e.find(e=>e.id===d)?.members.map(e=>e.user_id).filter(e=>e!==z?.apiKey)||[];try{await ib.delete(`/v1/spaces/${encodeURIComponent(d)}`),G.success(`空间已删除`),n(e=>e.filter(e=>e.id!==d)),hh.getState().removeUsersByApiKeys(r)}catch(e){console.error(`Failed to delete space:`,e),G.error(`空间删除失败`)}finally{f(null)}}async function U(){if(p){N(!0);try{let e=await ib.post(`/v1/tenants`,{name:O.trim()||void 0}),r=e.id,i=e.api_key;await ib.post(`/v1/spaces/${encodeURIComponent(p)}/members`,{user_id:r,role:A}),F(i),G.success(`新用户创建并加入空间成功`),n(await ib.get(`/v1/spaces`)||[])}catch(e){console.error(`Failed to create user:`,e);let n=e.response?.data?.error||e.message||``;G.error(`创建用户失败:${n||`请稍后重试`}`)}finally{N(!1)}}}async function te(e){if(p)try{await ib.delete(`/v1/spaces/${encodeURIComponent(p)}/members/${encodeURIComponent(e)}`),G.success(`成员已移除`),n(await ib.get(`/v1/spaces`)||[])}catch(e){console.error(`Failed to remove member:`,e);let n=e.response?.data?.error||e.message||``;G.error(`移除成员失败:${n||`请稍后重试`}`)}}async function W(){if(!p||!h.trim()){G.error(`请输入用户ID`);return}let e=h.trim();if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)){G.error(`用户ID格式不正确,请输入有效的 UUID(如:c60beb98-7aab-4985-8c1d-29ffd6aff75a)`);return}x(!0);try{await ib.post(`/v1/spaces/${encodeURIComponent(p)}/members`,{user_id:e,role:_}),G.success(`成员添加成功`),g(``),n(await ib.get(`/v1/spaces`)||[])}catch(e){console.error(`Failed to add member:`,e);let n=e.response?.data?.error||e.message||``;n.includes(`not found`)||n.includes(`不存在`)?G.error(`该用户不存在,请确认用户ID正确`):n.includes(`permission`)||n.includes(`权限`)?G.error(`您没有权限添加成员`):G.error(`添加成员失败:${n||`请检查用户ID是否正确`}`)}finally{x(!1)}}return r?(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`空间管理`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`管理您的记忆空间`})]}),(0,K.jsx)(Tb,{className:`h-9 w-24`})]}),(0,K.jsx)(`div`,{className:`grid gap-4`,children:[1,2].map(e=>(0,K.jsx)(Tb,{className:`h-32 w-full`},e))})]}):(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`空间管理`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`管理您的记忆空间`})]}),(0,K.jsxs)(g9,{open:a,onOpenChange:o,children:[(0,K.jsx)(ihe,{render:(0,K.jsxs)(J,{size:`sm`,children:[(0,K.jsx)(Lm,{className:`size-4 mr-1.5`}),`新建空间`]})}),(0,K.jsxs)(_9,{children:[(0,K.jsx)(v9,{children:(0,K.jsx)(b9,{children:`新建空间`})}),(0,K.jsxs)(`div`,{className:`space-y-4 pt-2`,children:[(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium`,children:`空间名称`}),(0,K.jsx)(hb,{placeholder:`输入空间名称`,value:s,onChange:e=>c(e.target.value)})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium`,children:`空间类型`}),(0,K.jsxs)(r9,{value:l,onValueChange:e=>u(e||`team`),children:[(0,K.jsx)(a9,{children:(0,K.jsx)(i9,{})}),(0,K.jsxs)(o9,{children:[(0,K.jsx)(s9,{value:`team`,children:`团队`}),(0,K.jsx)(s9,{value:`personal`,children:`个人`}),(0,K.jsx)(s9,{value:`shared`,children:`共享`})]})]})]}),(0,K.jsx)(J,{className:`w-full`,onClick:V,children:`创建`})]})]})]})]}),e.length===0?(0,K.jsxs)(`div`,{className:`text-center py-12 text-muted-foreground border border-dashed border-border rounded-lg`,children:[(0,K.jsx)(`p`,{children:`暂无空间`}),(0,K.jsx)(`p`,{className:`text-sm mt-1`,children:`点击右上角按钮创建新空间`})]}):(0,K.jsx)(`div`,{className:`grid gap-4`,children:e.map(e=>(0,K.jsxs)(bb,{className:`group transition-colors hover:bg-accent/50`,children:[(0,K.jsx)(xb,{className:`pb-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold`,children:e.name}),(0,K.jsx)(hJ,{variant:`outline`,children:e.space_type})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,K.jsx)(Um,{className:`size-3`}),e.members.length,` 成员`]}),(0,K.jsxs)(J,{variant:`ghost`,size:`sm`,className:`h-7 opacity-0 group-hover:opacity-100 transition-opacity`,onClick:()=>{m(e.id),g(``),v(`member`)},children:[(0,K.jsx)(eh,{className:`size-3.5 mr-1`}),`管理成员`]}),e.space_type!==`personal`&&B(e)&&(0,K.jsx)(J,{variant:`ghost`,size:`icon`,className:`size-7 opacity-0 group-hover:opacity-100 transition-opacity`,onClick:()=>f(e.id),children:(0,K.jsx)(Xm,{className:`size-3.5 text-destructive`})})]})]})}),(0,K.jsxs)(wb,{className:`pt-0 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm text-muted-foreground flex-wrap`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(nh,{className:`size-3.5`}),e.members.map(e=>e.role).join(`, `)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(qp,{className:`size-3.5`}),new Date(e.created_at).toLocaleDateString(`zh-CN`)]})]}),(0,K.jsxs)(`p`,{className:`text-xs text-muted-foreground font-mono`,children:[`ID: `,e.id]})]})]},e.id))}),(0,K.jsx)(aJ,{open:!!d,onOpenChange:e=>!e&&f(null),children:(0,K.jsxs)(oJ,{children:[(0,K.jsxs)(sJ,{children:[(0,K.jsx)(lJ,{children:`确认删除空间`}),(0,K.jsx)(uJ,{children:`此操作不可撤销。空间内的数据不会被删除,但空间配置将被移除。`})]}),(0,K.jsxs)(cJ,{children:[(0,K.jsx)(fJ,{onClick:()=>f(null),children:`取消`}),(0,K.jsx)(dJ,{onClick:H,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`删除`})]})]})}),(0,K.jsx)(g9,{open:!!p,onOpenChange:e=>!e&&m(null),children:(0,K.jsxs)(_9,{style:{width:680,maxWidth:`95vw`},children:[(0,K.jsx)(v9,{children:(0,K.jsxs)(b9,{children:[`管理成员 - `,ee?.name]})}),(0,K.jsxs)(`div`,{className:`space-y-4 pt-2`,children:[(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium`,children:`当前成员`}),w&&(0,K.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`加载用户信息中...`}),(0,K.jsxs)(`div`,{className:`space-y-1`,children:[ee?.members.map(e=>{let n=S[e.user_id];return(0,K.jsxs)(`div`,{className:`grid grid-cols-[auto_1fr_80px_60px] items-center gap-3 text-sm border rounded-md px-3 py-2`,children:[(0,K.jsx)(th,{className:`size-3.5 text-muted-foreground`}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`div`,{className:`font-mono text-xs truncate`,title:e.user_id,children:e.user_id}),n&&(0,K.jsxs)(`div`,{className:`text-xs text-muted-foreground truncate`,children:[n.name,` · `,new Date(n.created_at).toLocaleDateString(`zh-CN`)]})]}),(0,K.jsx)(hJ,{variant:`outline`,className:`justify-self-center`,children:e.role}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 justify-self-end`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>{navigator.clipboard.writeText(e.user_id),G.success(`API Key 已复制`)},className:`text-muted-foreground hover:text-foreground transition-colors`,title:`复制 API Key`,children:(0,K.jsx)(im,{className:`size-3.5`})}),ee&&B(ee)&&e.user_id!==z?.apiKey&&e.user_id!==ee?.owner_id&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>te(e.user_id),className:`text-muted-foreground hover:text-destructive transition-colors`,title:`移除成员`,children:(0,K.jsx)(Xm,{className:`size-3.5`})})]})]},e.user_id)}),(!ee?.members||ee.members.length===0)&&(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`暂无成员`})]})]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium`,children:`添加成员`}),(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>{D(!0),F(null),k(``),j(`member`)},children:[(0,K.jsx)(nee,{className:`size-3.5 mr-1.5`}),`创建新用户`]})]}),E&&(0,K.jsxs)(`div`,{className:`rounded-lg border border-border bg-muted/30 p-3 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium`,children:`创建新用户`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>{D(!1),F(null)},className:`text-xs text-muted-foreground hover:text-foreground`,children:`取消`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(hb,{placeholder:`用户名(可选)`,value:O,onChange:e=>k(e.target.value),className:`flex-1`}),(0,K.jsxs)(r9,{value:A,onValueChange:e=>j(e||`member`),children:[(0,K.jsx)(a9,{className:`w-28`,children:(0,K.jsx)(i9,{})}),(0,K.jsxs)(o9,{children:[(0,K.jsx)(s9,{value:`admin`,children:`管理员`}),(0,K.jsx)(s9,{value:`member`,children:`成员`}),(0,K.jsx)(s9,{value:`reader`,children:`只读`})]})]})]}),(0,K.jsx)(J,{size:`sm`,className:`w-full`,onClick:U,disabled:M,children:M?`生成中...`:`生成用户并添加到空间`}),P&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`新用户 API Key(请复制保存):`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`code`,{className:`flex-1 text-xs bg-background border rounded px-2 py-1.5 font-mono truncate`,children:P}),(0,K.jsx)(J,{size:`sm`,variant:`outline`,onClick:()=>{navigator.clipboard.writeText(P),L(!0),setTimeout(()=>L(!1),2e3)},children:I?(0,K.jsx)(Yp,{className:`size-3.5`}):(0,K.jsx)(im,{className:`size-3.5`})})]})]})]}),!E&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(hb,{placeholder:`输入对方 API Key(UUID格式)`,value:h,onChange:e=>g(e.target.value),className:`flex-1`}),(0,K.jsxs)(r9,{value:_,onValueChange:e=>v(e||`member`),children:[(0,K.jsx)(a9,{className:`w-28`,children:(0,K.jsx)(i9,{})}),(0,K.jsxs)(o9,{children:[(0,K.jsx)(s9,{value:`admin`,children:`管理员`}),(0,K.jsx)(s9,{value:`member`,children:`成员`}),(0,K.jsx)(s9,{value:`reader`,children:`只读`})]})]}),(0,K.jsx)(J,{size:`sm`,onClick:W,disabled:b,children:b?`添加中...`:`添加`})]})]})]})]})})]})}var S9=[`#8b5cf6`,`#ec4899`,`#06b6d4`,`#f59e0b`,`#10b981`,`#ef4444`,`#6366f1`,`#f97316`];function C9(e,n){if(!e)return[];let r=Object.entries(e).map(([e,n])=>({name:e,value:n})).sort((e,n)=>n.value-e.value);return n?r.slice(0,n):r}function che(){let e=et(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)([]),[o,s]=(0,y.useState)(!0);(0,y.useEffect)(()=>{async function e(){try{s(!0);let[e,n]=await Promise.all([ib.get(`/v1/stats`),ib.get(`/v1/memories`)]);r(e),a(n?.memories||[])}catch(e){G.error(`加载统计数据失败: `+e.message)}finally{s(!1)}}e()},[]);let c=(0,y.useMemo)(()=>{if(!n?.timeline?.length)return 0;let e=new Date().toISOString().split(`T`)[0];return n.timeline.find(n=>n.date===e)?.count??0},[n]),l=(0,y.useMemo)(()=>C9(n?.by_category,8),[n]),u=(0,y.useMemo)(()=>C9(n?.by_type),[n]),d=(0,y.useMemo)(()=>C9(n?.by_tier),[n]),f=(0,y.useMemo)(()=>C9(n?.by_state),[n]),p=(0,y.useMemo)(()=>!n||!n.total||!n.total_access_count?`0%`:`${Math.min(100,Math.round(n.total_access_count/Math.max(1,n.total)*100))}%`,[n]),m=(0,y.useMemo)(()=>{let e=[];for(let n of i)if(n.tier_history)try{let r=JSON.parse(n.tier_history);for(let i of r)e.push({memoryId:n.id,...i})}catch{}return e.sort((e,n)=>n.at.localeCompare(e.at)),e.slice(0,50)},[i]),h={access_via_get:`访问触发`,access_via_search:`搜索触发`,access_via_recall:`召回触发`,access_via_cross_space_search:`跨空间搜索触发`,scheduled_evaluation:`定时评估`};return o?(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(Tb,{className:`h-8 w-48`}),(0,K.jsx)(Tb,{className:`h-8 w-24`})]}),(0,K.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2 lg:grid-cols-4`,children:[(0,K.jsx)(Tb,{className:`h-24`}),(0,K.jsx)(Tb,{className:`h-24`}),(0,K.jsx)(Tb,{className:`h-24`}),(0,K.jsx)(Tb,{className:`h-24`})]}),(0,K.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,K.jsx)(Tb,{className:`h-80`}),(0,K.jsx)(Tb,{className:`h-80`}),(0,K.jsx)(Tb,{className:`h-80`}),(0,K.jsx)(Tb,{className:`h-80`})]})]}):(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-semibold tracking-tight flex items-center gap-2`,children:[(0,K.jsx)(Jp,{className:`size-5`}),`统计分析`]}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`记忆库数据洞察与可视化`})]}),(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>e(`/memories`),children:[(0,K.jsx)(Bp,{className:`size-4 mr-1.5`}),`返回记忆`]})]}),(0,K.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2 lg:grid-cols-4`,children:[(0,K.jsxs)(bb,{children:[(0,K.jsxs)(xb,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,K.jsx)(Sb,{className:`text-sm font-medium text-muted-foreground`,children:`总记忆数`}),(0,K.jsx)(Kp,{className:`size-4 text-muted-foreground`})]}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`text-2xl font-bold`,children:n?.total??0})})]}),(0,K.jsxs)(bb,{children:[(0,K.jsxs)(xb,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,K.jsx)(Sb,{className:`text-sm font-medium text-muted-foreground`,children:`今日新增`}),(0,K.jsx)(Zm,{className:`size-4 text-muted-foreground`})]}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`text-2xl font-bold`,children:c})})]}),(0,K.jsxs)(bb,{children:[(0,K.jsxs)(xb,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,K.jsx)(Sb,{className:`text-sm font-medium text-muted-foreground`,children:`空间数`}),(0,K.jsx)(bm,{className:`size-4 text-muted-foreground`})]}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`text-2xl font-bold`,children:n?.total_spaces??Object.keys(n?.by_space??{}).length})})]}),(0,K.jsxs)(bb,{children:[(0,K.jsxs)(xb,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,K.jsx)(Sb,{className:`text-sm font-medium text-muted-foreground`,children:`活跃度`}),(0,K.jsx)(iee,{className:`size-4 text-muted-foreground`})]}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`text-2xl font-bold`,children:p})})]})]}),(0,K.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,K.jsxs)(bb,{children:[(0,K.jsxs)(xb,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,K.jsx)(Sb,{className:`text-sm font-medium text-muted-foreground`,children:`平均重要性`}),(0,K.jsx)(Km,{className:`size-4 text-muted-foreground`})]}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`text-2xl font-bold`,children:n?.avg_importance?`${(n.avg_importance*100).toFixed(0)}%`:`—`})})]}),(0,K.jsxs)(bb,{children:[(0,K.jsxs)(xb,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,K.jsx)(Sb,{className:`text-sm font-medium text-muted-foreground`,children:`平均置信度`}),(0,K.jsx)(Jp,{className:`size-4 text-muted-foreground`})]}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`text-2xl font-bold`,children:n?.avg_confidence?`${(n.avg_confidence*100).toFixed(0)}%`:`—`})})]})]}),(0,K.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{children:(0,K.jsx)(Sb,{className:`text-base`,children:`分类分布`})}),(0,K.jsxs)(wb,{children:[(0,K.jsx)(oD,{width:`100%`,height:280,children:(0,K.jsxs)(Xq,{children:[(0,K.jsx)(bB,{data:l,cx:`50%`,cy:`50%`,innerRadius:60,outerRadius:100,paddingAngle:2,dataKey:`value`,children:l.map((e,n)=>(0,K.jsx)(sD,{fill:S9[n%S9.length]},`cell-${e.name}`))}),(0,K.jsx)(VE,{})]})}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2 mt-4 justify-center`,children:l.map((e,n)=>(0,K.jsxs)(hJ,{variant:`secondary`,style:{backgroundColor:`${S9[n%S9.length]}20`,color:S9[n%S9.length]},children:[e.name,` (`,e.value,`)`]},e.name))})]})]}),(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{children:(0,K.jsx)(Sb,{className:`text-base`,children:`记忆类型分布`})}),(0,K.jsx)(wb,{children:(0,K.jsx)(oD,{width:`100%`,height:280,children:(0,K.jsxs)(Yq,{data:u,children:[(0,K.jsx)(KW,{strokeDasharray:`3 3`,stroke:`#333`}),(0,K.jsx)(oK,{dataKey:`name`,tick:{fontSize:12}}),(0,K.jsx)(CK,{tick:{fontSize:12}}),(0,K.jsx)(VE,{}),(0,K.jsx)(HV,{dataKey:`value`,fill:`#8b5cf6`,radius:[4,4,0,0]})]})})})]}),(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{children:(0,K.jsx)(Sb,{className:`text-base`,children:`层级分布`})}),(0,K.jsx)(wb,{children:(0,K.jsx)(oD,{width:`100%`,height:280,children:(0,K.jsxs)(Xq,{children:[(0,K.jsx)(bB,{data:d,cx:`50%`,cy:`50%`,outerRadius:100,dataKey:`value`,label:({name:e,value:n})=>`${e}: ${n}`,children:d.map((e,n)=>(0,K.jsx)(sD,{fill:S9[n%S9.length]},`tier-${e.name}`))}),(0,K.jsx)(VE,{})]})})})]}),(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{children:(0,K.jsx)(Sb,{className:`text-base`,children:`状态分布`})}),(0,K.jsx)(wb,{children:(0,K.jsx)(oD,{width:`100%`,height:280,children:(0,K.jsxs)(Yq,{data:f,children:[(0,K.jsx)(KW,{strokeDasharray:`3 3`,stroke:`#333`}),(0,K.jsx)(oK,{dataKey:`name`,tick:{fontSize:12}}),(0,K.jsx)(CK,{tick:{fontSize:12}}),(0,K.jsx)(VE,{}),(0,K.jsx)(HV,{dataKey:`value`,fill:`#10b981`,radius:[4,4,0,0]})]})})})]})]}),(0,K.jsxs)(bb,{className:`mt-4`,children:[(0,K.jsx)(xb,{children:(0,K.jsxs)(Sb,{className:`flex items-center gap-1.5 text-base`,children:[(0,K.jsx)(mm,{className:`size-4 text-muted-foreground`}),`Tier 变更日志`]})}),(0,K.jsx)(wb,{children:m.length===0?(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground py-4 text-center`,children:`暂无变更记录`}):(0,K.jsx)(`div`,{className:`space-y-1`,children:m.map(n=>{let r={peripheral:0,working:1,core:2};return(0,K.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2 text-sm py-2 border-b last:border-b-0 hover:bg-muted/50 px-2 rounded cursor-pointer w-full text-left`,onClick:()=>e(`/memories/${n.memoryId}`),children:[(r[n.from]??0)<(r[n.to]??0)?(0,K.jsx)(Up,{className:`size-4 text-emerald-500 shrink-0`}):(0,K.jsx)(zp,{className:`size-4 text-red-500 shrink-0`}),(0,K.jsx)(`span`,{className:`text-muted-foreground text-xs w-36 shrink-0`,children:new Date(n.at).toLocaleString(`zh-CN`)}),(0,K.jsxs)(`span`,{className:`text-muted-foreground font-mono text-xs`,children:[n.memoryId.slice(0,8),`...`]}),(0,K.jsx)(hJ,{variant:`outline`,className:EJ(n.from),children:wJ(n.from)}),(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`→`}),(0,K.jsx)(hJ,{variant:`outline`,className:EJ(n.to),children:wJ(n.to)}),(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:[h[n.reason]||n.reason,` · #`,n.access_count]})]},n.memoryId+n.at)})})})]})]})}var lhe={access_via_get:`访问触发`,access_via_search:`搜索触发`,access_via_recall:`召回触发`,access_via_cross_space_search:`跨空间搜索触发`,scheduled_evaluation:`定时评估`},w9=20;function uhe(){let e=et(),n=Ze(),[r,i]=(0,y.useState)([]),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(1),[l,u]=(0,y.useState)(`all`),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(0);(0,y.useEffect)(()=>{n.state?.from===`tier-history`&&n.state?.page&&c(n.state.page)},[n.state]),(0,y.useEffect)(()=>{let e=setTimeout(()=>{m(d)},300);return()=>clearTimeout(e)},[d]);let S=(0,y.useCallback)(async e=>{o(!0);try{let n=(e-1)*w9,r={limit:String(w9),offset:String(n)};l===`promote`?r.filter=`promote`:l===`demote`&&(r.filter=`demote`),p.trim()&&(r.search=p.trim());let a=await ib.get(`/v1/tier-changes`,{params:r});i(a.changes),x(a.totalCount)}catch(e){console.error(`Failed to fetch tier history:`,e)}finally{o(!1)}},[l,p]);(0,y.useEffect)(()=>{S(s)},[S,s]);let C=Math.max(1,Math.ceil(b/w9)),w=Math.min(s,C),T={peripheral:0,working:1,core:2},E=async()=>{if(!h)return;let e=h;v(!0);try{await ib.post(`/v1/tier-changes/delete`,{memory_id:e.memoryId,from:e.from,to:e.to,at:e.at,reason:e.reason}),G.success(`已删除该条变更记录`),i(n=>n.filter(n=>!(n.memoryId===e.memoryId&&n.from===e.from&&n.to===e.to&&n.at===e.at))),x(e=>Math.max(0,e-1))}catch(e){console.error(`Failed to delete tier history entry:`,e),G.error(`删除失败`)}finally{v(!1),g(null)}},D=n=>{e(`/memories/${n}`,{state:{from:`tier-history`,page:w}})};return(0,K.jsxs)(`div`,{className:`space-y-6 max-w-5xl mx-auto`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-semibold tracking-tight flex items-center gap-2`,children:[(0,K.jsx)(mm,{className:`size-5`}),`等级变更历史`]}),(0,K.jsxs)(`span`,{className:`text-sm text-muted-foreground`,children:[`共 `,b,` 条记录`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1 min-w-[200px] max-w-xs`,children:[(0,K.jsx)(Vm,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 size-4 text-muted-foreground`}),(0,K.jsx)(`input`,{type:`text`,placeholder:`搜索标题、ID、原因...`,value:d,onChange:e=>{f(e.target.value),c(1)},className:`w-full h-9 pl-8 pr-3 rounded-md border border-input bg-background text-sm focus:outline-none focus:ring-1 focus:ring-ring`})]}),(0,K.jsxs)(r9,{value:l,onValueChange:e=>{e&&(u(e),c(1))},children:[(0,K.jsx)(a9,{className:`w-[130px]`,children:(0,K.jsx)(i9,{})}),(0,K.jsxs)(o9,{children:[(0,K.jsx)(s9,{value:`all`,children:`全部`}),(0,K.jsx)(s9,{value:`promote`,children:`仅晋升`}),(0,K.jsx)(s9,{value:`demote`,children:`仅降级`})]})]})]}),!a&&r.length>0&&C>1&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`第 `,w,` / `,C,` 页`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(J,{variant:`outline`,size:`sm`,className:`h-7 px-2`,disabled:w<=1,onClick:()=>c(w-1),children:(0,K.jsx)(Zp,{className:`size-4`})}),Array.from({length:C},(e,n)=>n+1).filter(e=>e===1||e===C||Math.abs(e-w)<=2).map((e,n,r)=>(0,K.jsxs)(`span`,{className:`flex items-center`,children:[n>0&&r[n-1]!==e-1&&(0,K.jsx)(`span`,{className:`px-1 text-xs text-muted-foreground`,children:`...`}),(0,K.jsx)(J,{variant:e===w?`default`:`outline`,size:`sm`,className:`h-7 w-7 px-0`,onClick:()=>c(e),children:e})]},e)),(0,K.jsx)(J,{variant:`outline`,size:`sm`,className:`h-7 px-2`,disabled:w>=C,onClick:()=>c(w+1),children:(0,K.jsx)(Qp,{className:`size-4`})})]})]}),(0,K.jsx)(bb,{children:(0,K.jsxs)(wb,{className:`p-0`,children:[a?(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground py-12 text-center`,children:`加载中...`}):r.length===0?(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground py-12 text-center`,children:`暂无变更记录`}):(0,K.jsx)(`div`,{className:`divide-y`,children:r.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 hover:bg-muted/30 transition-colors`,children:[(T[e.from]??0)<(T[e.to]??0)?(0,K.jsx)(Up,{className:`size-4 text-emerald-500 shrink-0`}):(0,K.jsx)(zp,{className:`size-4 text-red-500 shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground w-36 shrink-0`,children:new Date(e.at).toLocaleString(`zh-CN`)}),(0,K.jsx)(hJ,{variant:`outline`,className:EJ(e.from),children:wJ(e.from)}),(0,K.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`→`}),(0,K.jsx)(hJ,{variant:`outline`,className:EJ(e.to),children:wJ(e.to)}),(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground w-20 shrink-0`,children:lhe[e.reason]||e.reason}),(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground w-16 shrink-0`,children:[`#`,e.accessCount]}),(0,K.jsx)(`button`,{type:`button`,className:`flex-1 min-w-0 text-left text-sm truncate hover:underline cursor-pointer`,onClick:()=>D(e.memoryId),title:e.memoryTitle,children:e.memoryTitle}),(0,K.jsxs)(`span`,{className:`text-xs font-mono text-muted-foreground shrink-0`,children:[e.memoryId.slice(0,8),`...`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,K.jsx)(J,{variant:`ghost`,size:`sm`,className:`h-7 px-2`,onClick:()=>D(e.memoryId),title:`查看详情`,children:(0,K.jsx)(om,{className:`size-3.5`})}),(0,K.jsx)(J,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-red-500 hover:text-red-600 hover:bg-red-500/10`,onClick:()=>g(e),title:`删除此条记录`,children:(0,K.jsx)(Xm,{className:`size-3.5`})})]})]},`${e.memoryId}-${e.at}-${e.from}-${e.to}`))}),C>1&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-t`,children:[(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`第 `,w,` / `,C,` 页,共 `,b,` 条`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(J,{variant:`outline`,size:`sm`,className:`h-7 px-2`,disabled:w<=1,onClick:()=>c(w-1),children:(0,K.jsx)(Zp,{className:`size-4`})}),Array.from({length:C},(e,n)=>n+1).filter(e=>e===1||e===C||Math.abs(e-w)<=2).map((e,n,r)=>(0,K.jsxs)(`span`,{className:`flex items-center`,children:[n>0&&r[n-1]!==e-1&&(0,K.jsx)(`span`,{className:`px-1 text-xs text-muted-foreground`,children:`...`}),(0,K.jsx)(J,{variant:e===w?`default`:`outline`,size:`sm`,className:`h-7 w-7 px-0`,onClick:()=>c(e),children:e})]},e)),(0,K.jsx)(J,{variant:`outline`,size:`sm`,className:`h-7 px-2`,disabled:w>=C,onClick:()=>c(w+1),children:(0,K.jsx)(Qp,{className:`size-4`})})]})]})]})}),(0,K.jsx)(aJ,{open:!!h,onOpenChange:e=>{e||g(null)},children:(0,K.jsxs)(oJ,{children:[(0,K.jsxs)(sJ,{children:[(0,K.jsx)(lJ,{children:`确认删除变更记录`}),(0,K.jsxs)(uJ,{children:[`确定要删除这条 `,h&&`${wJ(h.from)} → ${wJ(h.to)}`,` 的变更记录吗?记忆本身不会被删除。`]})]}),(0,K.jsxs)(cJ,{children:[(0,K.jsx)(fJ,{onClick:()=>g(null),disabled:_,children:`取消`}),(0,K.jsx)(dJ,{disabled:_,onClick:e=>{e.preventDefault(),E()},className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:_?`删除中...`:`确认删除`})]})]})})]})}async function dhe(){return ib.get(`/v1/clusters/stats`)}async function fhe(e,n,r){return ib.post(`/v1/clusters/trigger`,{space_id:e,batch_size:n,mode:r})}async function phe(){return ib.get(`/v1/clusters/jobs`)}async function mhe(e){return ib.delete(`/v1/clusters/jobs/${e}`)}async function hhe(e,n){let r={};return e!==void 0&&(r.limit=String(e)),n!==void 0&&(r.offset=String(n)),ib.get(`/v1/clusters`,{params:r})}async function ghe(e){return ib.delete(`/v1/clusters/${e}`)}async function _he(e){return ib.get(`/v1/clusters/${e}`)}async function vhe(e){return ib.post(`/v1/clusters/batch-delete`,{cluster_ids:e})}async function yhe(){return ib.delete(`/v1/clusters/all`,{timeout:3e5})}async function T9(){return ib.get(`/v1/scheduler/status`)}async function bhe(){return ib.post(`/v1/scheduler/clustering/pause`)}async function xhe(){return ib.post(`/v1/scheduler/clustering/resume`)}var E9=null,D9=new Map,O9=new Set,k9=null;function She(){let e=hh.getState().users.find(e=>e.id===hh.getState().currentUserId);return e?.apiKey?`/v1/events?api_key=${encodeURIComponent(e.apiKey)}&tenant_id=${encodeURIComponent(e.apiKey)}`:null}function A9(){if(E9)return;let e=She();e&&(E9=new EventSource(e),E9.onmessage=e=>{try{let n=JSON.parse(e.data),r=D9.get(n.event_type);r&&r.forEach(e=>e(n)),O9.forEach(e=>e(n))}catch{}},E9.onerror=()=>{E9?.close(),E9=null,k9&&clearTimeout(k9),k9=setTimeout(A9,5e3)})}function Che(){k9&&=(clearTimeout(k9),null),E9?.close(),E9=null}function j9(e,n){let r=(0,y.useRef)(n);r.current=n,(0,y.useEffect)(()=>{D9.has(e)||D9.set(e,new Set);let n=(e=>r.current(e));return D9.get(e).add(n),A9(),()=>{D9.get(e)?.delete(n),D9.get(e)?.size===0&&D9.delete(e),D9.size===0&&O9.size===0&&Che()}},[e])}function whe(){let[e,n]=(0,y.useState)(null),[r,i]=(0,y.useState)([]),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)({paused:!1,running:!1}),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(!1),b=async()=>{try{o(!0);let[e,r,a]=await Promise.all([dhe(),phe(),T9().catch(()=>null)]);n(e),i(r.jobs||[]),a&&m(a.clustering)}catch(e){console.error(`Failed to load cluster data:`,e),G.error(`加载簇数据失败`)}finally{o(!1)}};(0,y.useEffect)(()=>{b()},[]),j9(`cluster.stage`,e=>{let n=e.data;n&&f({stage:String(n.stage||``),message:String(n.message||``),processed:typeof n.processed==`number`?n.processed:void 0,total:typeof n.total==`number`?n.total:void 0})}),j9(`cluster.started`,e=>{let n=e.data;n&&f({stage:`started`,message:String(n.message||`开始归簇 ${n.total||0} 条记忆`),processed:0,total:typeof n.total==`number`?n.total:void 0})}),j9(`cluster.memory_progress`,e=>{let n=e.data;n&&f(e=>({stage:String(n.stage||e?.stage||`clustering`),message:n.stage===`creating_cluster`?`创建新簇...`:n.stage===`linking`?`关联已有簇...`:`处理中 ${n.processed??e?.processed??0}/${n.total??e?.total??`?`}`,processed:typeof n.processed==`number`?n.processed:e?.processed,total:typeof n.total==`number`?n.total:e?.total}))}),j9(`cluster.batch_done`,e=>{let n=e.data;n&&f(e=>({stage:e?.stage||`batch_done`,message:`批次 ${n.batch} 完成 · 已处理 ${n.processed}/${n.total}`,processed:typeof n.processed==`number`?n.processed:e?.processed,total:typeof n.total==`number`?n.total:e?.total})),b()}),j9(`cluster.complete`,()=>{f(null),b(),G.success(`归簇任务完成`)}),j9(`cluster.failed`,e=>{let n=e.data;f(null),b(),G.error(`归簇任务失败: ${n?.error||`未知错误`}`)});let x=async(e=`incremental`)=>{try{c(!0);let n=await fhe(void 0,void 0,e);G.success(n.message),b()}catch(e){console.error(`Failed to trigger clustering:`,e),G.error(`触发归簇失败`)}finally{c(!1)}},S=async()=>{try{g(!0),p.paused?(await xhe(),G.success(`归簇调度已恢复`)):(await bhe(),G.success(`归簇调度已暂停`)),m((await T9()).clustering)}catch{G.error(`操作失败`)}finally{g(!1)}},C=async e=>{try{u(e),await mhe(e),G.success(`任务已删除`),b()}catch(e){console.error(`Failed to delete job:`,e),G.error(`删除任务失败`)}finally{u(null)}},w=e=>{switch(e){case`running`:return(0,K.jsx)(wm,{className:`h-4 w-4 animate-spin text-blue-500`});case`completed`:return(0,K.jsx)(em,{className:`h-4 w-4 text-green-500`});case`failed`:return(0,K.jsx)(tm,{className:`h-4 w-4 text-red-500`});default:return(0,K.jsx)(nm,{className:`h-4 w-4 text-muted-foreground`})}},T=e=>({pending:`bg-yellow-100 text-yellow-800`,running:`bg-blue-100 text-blue-800`,completed:`bg-green-100 text-green-800`,failed:`bg-red-100 text-red-800`})[e]||`bg-gray-100 text-gray-800`;return(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`簇管理`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`管理记忆归簇任务和查看统计`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:b,disabled:a,children:[(0,K.jsx)(zm,{className:`h-4 w-4 mr-1`}),`刷新`]}),(0,K.jsxs)(J,{variant:p.paused?`default`:`outline`,size:`sm`,onClick:S,disabled:h,children:[h?(0,K.jsx)(wm,{className:`h-4 w-4 mr-1 animate-spin`}):p.paused?(0,K.jsx)(Im,{className:`h-4 w-4 mr-1`}):(0,K.jsx)(Nm,{className:`h-4 w-4 mr-1`}),p.paused?`恢复调度`:`暂停调度`]}),(0,K.jsx)(J,{size:`sm`,onClick:()=>x(`incremental`),disabled:s,children:s?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(wm,{className:`h-4 w-4 mr-1 animate-spin`}),`处理中...`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Im,{className:`h-4 w-4 mr-1`}),`增量归簇`]})}),(0,K.jsx)(J,{variant:`destructive`,size:`sm`,onClick:()=>v(!0),disabled:s,children:s?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(wm,{className:`h-4 w-4 mr-1 animate-spin`}),`处理中...`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(ih,{className:`h-4 w-4 mr-1`}),`全局重建`]})})]})]}),(0,K.jsx)(`div`,{className:`flex items-center gap-3 text-sm text-muted-foreground`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(Rp,{className:`h-3.5 w-3.5`}),(0,K.jsx)(`span`,{children:`调度器:`}),p.running?(0,K.jsx)(hJ,{className:`bg-emerald-100 text-emerald-700`,children:`运行中`}):p.paused?(0,K.jsx)(hJ,{className:`bg-amber-100 text-amber-700`,children:`已暂停`}):(0,K.jsx)(hJ,{className:`bg-slate-100 text-slate-600`,children:`空闲`})]})}),a?(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[1,2,3].map(e=>(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsx)(Tb,{className:`h-4 w-24`})}),(0,K.jsx)(wb,{children:(0,K.jsx)(Tb,{className:`h-8 w-16`})})]},e))}):e?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsx)(Sb,{className:`text-sm font-medium`,children:`总簇数`})}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`text-2xl font-bold`,children:e.total_clusters})})]}),(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsx)(Sb,{className:`text-sm font-medium`,children:`已归簇记忆`})}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`text-2xl font-bold`,children:e.total_memories_in_clusters})})]}),(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsx)(Sb,{className:`text-sm font-medium`,children:`未归簇记忆`})}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`text-2xl font-bold text-amber-600`,children:e.orphaned_memories})})]})]}),d&&(0,K.jsxs)(bb,{className:`border-blue-200 bg-blue-50/50`,children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(ree,{className:`h-4 w-4 text-blue-500 animate-pulse`}),(0,K.jsx)(Sb,{className:`text-sm font-medium text-blue-700`,children:`实时进度`})]})}),(0,K.jsxs)(wb,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-sm text-blue-600`,children:d.message}),d.total!=null&&d.total>0&&(0,K.jsx)(`div`,{className:`w-full bg-blue-200 rounded-full h-2`,children:(0,K.jsx)(`div`,{className:`bg-blue-500 h-2 rounded-full transition-all duration-300`,style:{width:`${Math.min(100,(d.processed||0)/d.total*100)}%`}})})]})]}),(0,K.jsxs)(bb,{children:[(0,K.jsxs)(xb,{children:[(0,K.jsx)(Sb,{children:`归簇任务历史`}),(0,K.jsx)(Cb,{children:`最近执行的归簇任务记录`})]}),(0,K.jsx)(wb,{children:r.length===0?(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-8`,children:`暂无归簇任务记录`}):(0,K.jsx)(`div`,{className:`space-y-3`,children:r.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 rounded-lg border`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[w(e.status),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`p`,{className:`text-sm font-medium`,children:[`任务 `,e.id.slice(0,8)]}),(0,K.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[e.total_memories,` 条记忆 · 处理 `,e.processed_memories,` 条`]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(hJ,{variant:`outline`,className:T(e.status),children:e.status===`running`?`进行中`:e.status===`completed`?`已完成`:e.status===`failed`?`失败`:`待处理`}),e.created_at&&(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:new Date(e.created_at).toLocaleString(`zh-CN`)}),(0,K.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-destructive`,onClick:()=>C(e.id),disabled:l===e.id,children:l===e.id?(0,K.jsx)(wm,{className:`h-3.5 w-3.5 animate-spin`}):(0,K.jsx)(Xm,{className:`h-3.5 w-3.5`})})]})]},e.id))})})]})]}):(0,K.jsx)(bb,{children:(0,K.jsx)(wb,{className:`py-8 text-center`,children:(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`无法加载统计数据`})})}),(0,K.jsx)(aJ,{open:_,onOpenChange:v,children:(0,K.jsxs)(oJ,{children:[(0,K.jsxs)(sJ,{children:[(0,K.jsx)(lJ,{children:`确认全局重建?`}),(0,K.jsx)(uJ,{children:`全局重建会清空所有簇并用 K-Means 重新聚类,此操作不可撤销。`})]}),(0,K.jsxs)(cJ,{children:[(0,K.jsx)(fJ,{children:`取消`}),(0,K.jsx)(dJ,{variant:`destructive`,onClick:()=>{v(!1),x(`rebuild`)},children:`确认重建`})]})]})})]})}var M9=function(e){return e.checked=`data-checked`,e.unchecked=`data-unchecked`,e.indeterminate=`data-indeterminate`,e.disabled=`data-disabled`,e.readonly=`data-readonly`,e.required=`data-required`,e.valid=`data-valid`,e.invalid=`data-invalid`,e.touched=`data-touched`,e.dirty=`data-dirty`,e.filled=`data-filled`,e.focused=`data-focused`,e}({});function N9(e){return y.useMemo(()=>({checked(n){return e.indeterminate?{}:n?{[M9.checked]:``}:{[M9.unchecked]:``}},...lb}),[e.indeterminate])}function P9(e,n,r,i=!0,a){let[o,s]=y.useState(),c=vd(a?`${a}-label`:void 0),l=e??n??o;return Nr(()=>{let a=e||n||!i?void 0:The(r.current,c);o!==a&&s(a)}),l}function The(e,n){let r=Ehe(e);if(r)return!r.id&&n&&(r.id=n),r.id||void 0}function Ehe(e){if(!e)return;let n=e.parentElement;if(n&&n.tagName===`LABEL`)return n;let r=e.id;if(r){let n=e.nextElementSibling;if(n&&n.htmlFor===r)return n}let i=e.labels;return i&&i[0]}var F9=y.createContext(void 0);function Dhe(){let e=y.useContext(F9);if(e===void 0)throw Error(Fr(14));return e}var Ohe=`data-parent`,khe=y.forwardRef(function(e,n){let{checked:r,className:i,defaultChecked:a=!1,"aria-labelledby":o,disabled:s=!1,form:c,id:l,indeterminate:u=!1,inputRef:d,name:f,onCheckedChange:p,parent:m=!1,readOnly:h=!1,render:g,required:_=!1,uncheckedValue:v,value:b,nativeButton:x=!1,style:S,...C}=e,{clearErrors:w}=db(),{disabled:T,name:E,setDirty:D,setFilled:O,setFocused:k,setTouched:A,state:j,validationMode:M,validityData:N,shouldValidateOnChange:P,validation:F}=ub(),I=Xee(),{labelId:L,controlId:R,registerControlId:z,getDescriptionProps:ee}=fb(),B=Qee(),V=B?.parent,H=V&&B.allValues,U=T||I.disabled||B?.disabled||s,te=E??f,W=b??te,ne=vd(),re=vd(),ie=R;H?ie=m?re:`${V.id}-${W}`:l&&(ie=l);let ae={};H&&(m?ae=B.parent.getParentProps():W&&(ae=B.parent.getChildProps(W)));let oe=Sa(p),{checked:se=r,indeterminate:ce=u,onCheckedChange:le,...ue}=ae,de=B?.value,fe=B?.setValue,pe=B?.defaultValue,me=y.useRef(null),he=wr(()=>Symbol(`checkbox-control`)),ge=y.useRef(!1),{getButtonProps:_e,buttonRef:ve}=vh({disabled:U,native:x}),ye=B?.validation??F,[be,xe]=Hg({controlled:W&&de&&!m?de.includes(W):se,default:W&&pe&&!m?pe.includes(W):a,name:`Checkbox`,state:`checked`});Nr(()=>{z!==fi&&(ge.current=!0,z(he.current,ie))},[ie,B,z,m,he]),y.useEffect(()=>{let e=he.current;return()=>{!ge.current||z===fi||(ge.current=!1,z(e,void 0))}},[z,he]),pb(me,{enabled:!B,id:ne,value:be});let Se=y.useRef(null),Ce=fa(d,Se,ye.inputRef),we=P9(o,L,Se,!x,ie??void 0);Nr(()=>{Se.current&&(Se.current.indeterminate=ce,be&&O(!0))},[be,ce,O]),fg(be,()=>{B&&!m||(w(te),O(be),D(be!==N.initialValue),P()?ye.commit(be):ye.commit(be,!0))});let Te=Ls({checked:be,disabled:U,form:c,name:m?void 0:te,id:x?void 0:ie??void 0,required:_,ref:Ce,style:te?Ma:ja,tabIndex:-1,type:`checkbox`,"aria-hidden":!0,onChange(e){if(e.nativeEvent.defaultPrevented)return;if(h){e.preventDefault();return}let n=e.currentTarget.checked,r=Fi(bi,e.nativeEvent);le?.(n,r),oe(n,r),!r.isCanceled&&(xe(n),W&&de&&fe&&!m&&!H&&fe(n?[...de,W]:de.filter(e=>e!==W),r))},onFocus(){me.current?.focus()}},b===void 0?mi:{value:(B?be&&b:b)||``},ee,B?ye.getValidationProps:ye.getInputValidationProps),Ee=H?!!se:be,De=H&&ce||u;y.useEffect(()=>{if(!V||!W)return;let e=V.disabledStatesRef.current;return e.set(W,U),()=>{e.delete(W)}},[V,U,W]);let Oe=y.useMemo(()=>({...j,checked:Ee,disabled:U,readOnly:h,required:_,indeterminate:De}),[j,Ee,U,h,_,De]),ke=N9(Oe),Ae=Zs(`span`,e,{state:Oe,ref:[ve,me,n,B?.registerControlRef],props:[{id:x?ie??void 0:ne,role:`checkbox`,"aria-checked":ce?`mixed`:be,"aria-readonly":h||void 0,"aria-required":_||void 0,"aria-labelledby":we,[Ohe]:m?``:void 0,onFocus(){k(!0)},onBlur(){let e=Se.current;e&&(A(!0),k(!1),M===`onBlur`&&ye.commit(B?de:e.checked))},onClick(e){h||U||(e.preventDefault(),Se.current?.dispatchEvent(new PointerEvent(`click`,{bubbles:!0,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey})))}},ee,ye.getValidationProps,C,ue,_e],stateAttributesMapping:ke});return(0,K.jsxs)(F9.Provider,{value:Oe,children:[Ae,!be&&!B&&te&&!m&&v!==void 0&&(0,K.jsx)(`input`,{type:`hidden`,form:c,name:te,value:v}),(0,K.jsx)(`input`,{...Te,suppressHydrationWarning:!0})]})}),Ahe=y.forwardRef(function(e,n){let{render:r,className:i,style:a,keepMounted:o=!1,...s}=e,c=Dhe(),l=c.checked||c.indeterminate,{mounted:u,transitionStatus:d,setMounted:f}=ou(l),p=y.useRef(null),m={...c,transitionStatus:d};fu({open:l,ref:p,onComplete(){l||f(!1)}});let h=N9(c),g=y.useMemo(()=>({...h,...uu,...lb}),[h]),_=o||u,v=Zs(`span`,e,{ref:[n,p],state:m,stateAttributesMapping:g,props:s});return _?v:null});function I9({className:e,...n}){return(0,K.jsx)(khe,{"data-slot":`checkbox`,className:wp(`peer relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input transition-colors outline-none group-has-disabled/field:opacity-50 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground dark:data-checked:bg-primary`,e),...n,children:(0,K.jsx)(Ahe,{"data-slot":`checkbox-indicator`,className:`grid place-content-center text-current transition-none [&>svg]:size-3.5`,children:(0,K.jsx)(Yp,{})})})}function jhe(e){return new Date(e).toLocaleString(`zh-CN`,{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function Mhe(e,n=100){return e?e.length<=n?e:e.slice(0,n)+`...`:`—`}var L9=12;function Nhe(){let e=et(),[n,r]=(0,y.useState)([]),[i,a]=(0,y.useState)(!0),[o,s]=(0,y.useState)(`all`),[c,l]=(0,y.useState)(1),[u,d]=(0,y.useState)(0),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(!1),[g,_]=(0,y.useState)(new Set),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)(null),[D,O]=(0,y.useState)([]),k=async e=>{try{a(!0);let n=await hhe(L9,(e-1)*L9);r(n.clusters||[]),d(n.total||0),_(new Set)}catch(e){console.error(`Failed to load clusters:`,e),G.error(`加载簇列表失败`)}finally{a(!1)}};(0,y.useEffect)(()=>{k(c)},[c]),j9(`cluster.complete`,()=>{E(null),setTimeout(()=>O([]),3e3),k(c)}),j9(`cluster.batch_done`,()=>{k(c)}),j9(`cluster.memory_progress`,e=>{let n=e.data;if(E(e=>({processed:n.processed??e?.processed??0,total:n.total??e?.total??0,pct:n.pct??e?.pct??0})),n.content_preview){let e={assign_existing:`→ 加入已有簇`,create_new:`→ 创建新簇`,skip:`⊘ 跳过`},r={assigning:`匹配中`,linking:`关联中`,creating_cluster:`建簇中`};O(i=>[{time:new Date().toLocaleTimeString(`zh-CN`),preview:n.content_preview||``,action:e[n.action||``]||n.action||``,stage:r[n.stage||``]||n.stage||``},...i].slice(0,50))}});let A=(0,y.useMemo)(()=>{let e=new Set(n.map(e=>e.category).filter(Boolean));return Array.from(e).sort()},[n]),j=(0,y.useMemo)(()=>o===`all`?n:n.filter(e=>e.category===o),[n,o]),M=Math.max(1,Math.ceil(u/L9)),N=Math.min(c,M),P=async()=>{if(f){h(!0);try{await ghe(f.id),G.success(`已删除簇「${f.title||`未命名`}」`),p(null),k(N)}catch(e){console.error(`Failed to delete cluster:`,e),G.error(`删除失败`)}finally{h(!1)}}},F=e=>{_(n=>{let r=new Set(n);return r.has(e)?r.delete(e):r.add(e),r})},I=()=>{g.size===j.length&&j.length>0?_(new Set):_(new Set(j.map(e=>e.id)))},L=async()=>{if(g.size!==0){b(!0);try{let e=await vhe(Array.from(g));G.success(`已删除 ${e.deleted} 个簇,解绑 ${e.unlinked_memories} 条记忆`),_(new Set),k(N)}catch(e){console.error(`Failed to batch delete clusters:`,e),G.error(`批量删除失败`)}finally{b(!1)}}},R=async()=>{w(!0);try{let e=await yhe();G.success(`已删除 ${e.deleted} 个簇,解绑 ${e.unlinked_memories} 条记忆`),S(!1),_(new Set),k(N)}catch(e){console.error(`Failed to delete all clusters:`,e),G.error(`全部删除失败`)}finally{w(!1)}};return(0,K.jsxs)(`div`,{className:`space-y-6`,children:[T&&(0,K.jsxs)(`div`,{className:`bg-primary/5 border border-primary/20 rounded-lg p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium text-primary`,children:`🔄 归簇进行中...`}),(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[T.processed??0,` / `,T.total??0,T.pct!==0||T.processed!==0?` (${T.pct??0}%)`:``]})]}),(0,K.jsx)(`div`,{className:`w-full bg-primary/10 rounded-full h-2`,children:(0,K.jsx)(`div`,{className:`bg-primary rounded-full h-2 transition-all duration-300`,style:{width:`${T.pct}%`}})}),D.length>0&&(0,K.jsx)(`div`,{className:`mt-2 max-h-48 overflow-y-auto text-xs font-mono space-y-0.5`,children:D.map((e,n)=>(0,K.jsxs)(`div`,{className:`flex items-start gap-2 text-muted-foreground`,children:[(0,K.jsx)(`span`,{className:`text-[10px] shrink-0 opacity-50`,children:e.time}),(0,K.jsx)(`span`,{className:`truncate flex-1`,children:e.preview}),(0,K.jsx)(`span`,{className:`shrink-0 font-medium ${e.action.includes(`创建`)?`text-green-600`:e.action.includes(`加入`)?`text-blue-600`:`text-muted-foreground`}`,children:e.action})]},n))})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`簇列表`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`浏览所有记忆簇及其成员`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[A.length>1&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(dm,{className:`size-3.5 text-muted-foreground`}),(0,K.jsxs)(`select`,{value:o,onChange:e=>s(e.target.value),className:`h-9 rounded-md border border-input bg-background px-3 text-sm`,children:[(0,K.jsx)(`option`,{value:`all`,children:`全部分类`}),A.map(e=>(0,K.jsx)(`option`,{value:e,children:CJ(e)},e))]})]}),(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>k(N),disabled:i,children:[(0,K.jsx)(zm,{className:`size-4 mr-1`}),`刷新`]})]})]}),!i&&j.length>0&&M>1&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`第 `,N,` / `,M,` 页,共 `,u,` 个簇`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(J,{variant:`outline`,size:`sm`,className:`h-7 px-2`,disabled:N<=1,onClick:()=>l(N-1),children:(0,K.jsx)(Zp,{className:`size-4`})}),Array.from({length:M},(e,n)=>n+1).filter(e=>e===1||e===M||Math.abs(e-N)<=2).map((e,n,r)=>(0,K.jsxs)(`span`,{className:`flex items-center`,children:[n>0&&r[n-1]!==e-1&&(0,K.jsx)(`span`,{className:`px-1 text-xs text-muted-foreground`,children:`...`}),(0,K.jsx)(J,{variant:e===N?`default`:`outline`,size:`sm`,className:`h-7 w-7 px-0`,onClick:()=>l(e),children:e})]},e)),(0,K.jsx)(J,{variant:`outline`,size:`sm`,className:`h-7 px-2`,disabled:N>=M,onClick:()=>l(N+1),children:(0,K.jsx)(Qp,{className:`size-4`})})]})]}),!i&&j.length===0&&(0,K.jsxs)(`div`,{className:`rounded-lg border border-border bg-card p-12 text-center space-y-4`,children:[(0,K.jsx)(_m,{className:`size-12 text-muted-foreground mx-auto`}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-muted-foreground`,children:o===`all`?`暂无簇数据`:`未找到匹配的簇`}),(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o===`all`?`启动归簇任务后,簇将在此处展示`:`尝试切换分类筛选`})]})]}),!i&&j.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between rounded-lg border border-border bg-card p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(I9,{checked:g.size===j.length&&j.length>0,onCheckedChange:I,"aria-label":`全选`}),(0,K.jsxs)(`span`,{className:`text-sm text-muted-foreground`,children:[`已选 `,g.size,` 个`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(J,{variant:`outline`,size:`sm`,disabled:g.size===0||v,onClick:L,children:[(0,K.jsx)(Xm,{className:`size-4 mr-1`}),v?`删除中...`:`删除所选 (${g.size})`]}),(0,K.jsxs)(J,{variant:`outline`,size:`sm`,className:`text-red-500 hover:text-red-600 hover:bg-red-500/10`,disabled:C,onClick:()=>S(!0),children:[(0,K.jsx)(Xm,{className:`size-4 mr-1`}),C?`删除中...`:`全部删除`]})]})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:i?[1,2,3,4,5,6].map(e=>(0,K.jsxs)(bb,{className:`cursor-pointer`,children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsx)(Tb,{className:`h-5 w-3/4`})}),(0,K.jsxs)(wb,{className:`space-y-3`,children:[(0,K.jsx)(Tb,{className:`h-4 w-full`}),(0,K.jsx)(Tb,{className:`h-4 w-2/3`}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(Tb,{className:`h-5 w-12`}),(0,K.jsx)(Tb,{className:`h-5 w-16`})]})]})]},e)):j.map(n=>(0,K.jsxs)(bb,{className:`cursor-pointer hover:bg-muted/50 transition-colors group`,onClick:()=>e(`/clusters/${n.id}`),children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,K.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,K.jsx)(I9,{checked:g.has(n.id),onCheckedChange:()=>F(n.id),"aria-label":`选择 ${n.title||`未命名簇`}`})}),(0,K.jsx)(Sb,{className:`text-base font-semibold line-clamp-1`,children:n.title||`未命名簇`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,K.jsx)(hJ,{variant:`outline`,className:`text-xs ${SJ(n.category)}`,children:CJ(n.category)}),(0,K.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity text-red-500 hover:text-red-600 hover:bg-red-500/10`,onClick:e=>{e.stopPropagation(),p(n)},title:`删除此簇`,children:(0,K.jsx)(Xm,{className:`size-3`})})]})]})}),(0,K.jsxs)(wb,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground line-clamp-3`,children:Mhe(n.summary,150)}),(n.keywords?.length??0)>0&&(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[n.keywords.slice(0,5).map(e=>(0,K.jsx)(hJ,{variant:`secondary`,className:`text-xs font-normal`,children:e},e)),n.keywords.length>5&&(0,K.jsxs)(hJ,{variant:`secondary`,className:`text-xs font-normal`,children:[`+`,n.keywords.length-5]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground pt-1`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(nh,{className:`size-3`}),n.member_count,` 条记忆`]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(nm,{className:`size-3`}),jhe(n.updated_at)]})]})]})]},n.id))}),!i&&j.length>0&&(0,K.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`共 `,u,` 个簇`,o!==`all`&&` (筛选自 ${n.length} 个)`]}),(0,K.jsx)(aJ,{open:!!f,onOpenChange:e=>{e||p(null)},children:(0,K.jsxs)(oJ,{children:[(0,K.jsxs)(sJ,{children:[(0,K.jsx)(lJ,{children:`确认删除簇`}),(0,K.jsxs)(uJ,{children:[`确定要删除簇「`,f?.title||`未命名`,`」吗?该簇内的记忆将被解绑但不会被删除。`]})]}),(0,K.jsxs)(cJ,{children:[(0,K.jsx)(fJ,{onClick:()=>p(null),disabled:m,children:`取消`}),(0,K.jsx)(dJ,{disabled:m,onClick:e=>{e.preventDefault(),P()},className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:m?`删除中...`:`确认删除`})]})]})}),(0,K.jsx)(aJ,{open:x,onOpenChange:S,children:(0,K.jsxs)(oJ,{children:[(0,K.jsxs)(sJ,{children:[(0,K.jsx)(lJ,{children:`确认删除全部簇`}),(0,K.jsx)(uJ,{children:`确定要删除所有簇吗?此操作不可撤销,簇内的记忆将被解绑但不会被删除。`})]}),(0,K.jsxs)(cJ,{children:[(0,K.jsx)(fJ,{onClick:()=>S(!1),disabled:C,children:`取消`}),(0,K.jsx)(dJ,{disabled:C,onClick:e=>{e.preventDefault(),R()},className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:C?`删除中...`:`确认删除全部`})]})]})})]})}function R9(e){return new Date(e).toLocaleString(`zh-CN`,{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function Phe(e){return new Date(e).toLocaleDateString(`zh-CN`)}var z9=160;function Fhe({content:e,collapsed:n}){return(0,K.jsx)(`div`,{className:`prose prose-sm dark:prose-invert max-w-none text-sm leading-relaxed`,style:n?{maxHeight:`${z9}px`,overflow:`hidden`}:void 0,children:(0,K.jsx)(p0,{remarkPlugins:[Y4],children:e})})}function Ihe({content:e}){let[n,r]=(0,y.useState)(!1),[i,a]=(0,y.useState)(!1);return(0,K.jsxs)(`div`,{ref:(0,y.useCallback)(e=>{e&&a(e.scrollHeight>z9+20)},[e]),children:[(0,K.jsx)(Fhe,{content:e,collapsed:!n&&i}),i&&(0,K.jsx)(J,{variant:`ghost`,size:`sm`,className:`mt-1 h-7 text-xs text-muted-foreground hover:text-foreground`,onClick:()=>r(e=>!e),children:n?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)($p,{className:`size-3 mr-1`}),`收起`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Xp,{className:`size-3 mr-1`}),`展开全文`]})})]})}function Lhe(){let{id:e}=it(),n=et(),[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(null);if((0,y.useEffect)(()=>{if(!e)return;let n=e;async function r(){try{o(!0),c(null),i(await _he(n))}catch(e){console.error(`Failed to load cluster detail:`,e),c(`加载簇详情失败`),G.error(`加载簇详情失败`)}finally{o(!1)}}r()},[e]),a)return(0,K.jsxs)(`div`,{className:`space-y-6 max-w-5xl mx-auto`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Tb,{className:`size-8`}),(0,K.jsx)(Tb,{className:`h-6 w-32`})]}),(0,K.jsx)(Tb,{className:`h-8 w-3/4`}),(0,K.jsx)(Tb,{className:`h-4 w-1/2`}),(0,K.jsx)(`div`,{className:`space-y-3`,children:[1,2,3].map(e=>(0,K.jsx)(Tb,{className:`h-20 w-full rounded-lg`},e))})]});if(s||!r)return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(J,{variant:`ghost`,size:`sm`,onClick:()=>n(`/clusters/list`),children:[(0,K.jsx)(Bp,{className:`size-4 mr-1.5`}),`返回列表`]}),(0,K.jsx)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-sm text-destructive`,children:s||`簇不存在`})]});let{cluster:l,members:u}=r;return(0,K.jsxs)(`div`,{className:`space-y-6 max-w-5xl mx-auto`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(J,{variant:`ghost`,size:`sm`,onClick:()=>n(`/clusters/list`),children:[(0,K.jsx)(Bp,{className:`size-4 mr-1.5`}),`返回列表`]}),(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,K.jsx)(hJ,{variant:`outline`,className:`text-xs ${SJ(l.category)}`,children:CJ(l.category)})})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:l.title||`未命名簇`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm text-muted-foreground flex-wrap`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(qp,{className:`size-3.5`}),`创建于 `,R9(l.created_at)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(nm,{className:`size-3.5`}),`更新于 `,R9(l.updated_at)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(nh,{className:`size-3.5`}),l.member_count,` 条成员记忆`]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(pm,{className:`size-3.5`}),l.id.slice(0,8),`...`]}),l.importance>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(Jp,{className:`size-3.5`}),`重要性 `,l.importance.toFixed(2)]})]})]}),l.keywords&&l.keywords.length>0&&(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsxs)(Sb,{className:`flex items-center gap-1.5 text-base`,children:[(0,K.jsx)(Jm,{className:`size-4 text-muted-foreground`}),`关键词`]})}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:l.keywords.map(e=>(0,K.jsx)(hJ,{variant:`secondary`,className:`font-normal`,children:e},e))})})]}),(0,K.jsx)(m7,{}),(0,K.jsxs)(bb,{className:`border-primary/20 bg-primary/5 dark:bg-primary/10`,children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsxs)(Sb,{className:`flex items-center gap-1.5 text-base`,children:[(0,K.jsx)(km,{className:`size-4 text-primary`}),`合并后摘要`,(0,K.jsx)(hJ,{variant:`outline`,className:`text-xs ml-1 text-primary border-primary/30`,children:`Merged`})]})}),(0,K.jsx)(wb,{children:l.summary?(0,K.jsx)(`div`,{className:`prose prose-sm dark:prose-invert max-w-none text-sm leading-relaxed`,children:(0,K.jsx)(p0,{remarkPlugins:[Y4],children:l.summary})}):(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`暂无合并摘要`})})]}),(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold flex items-center gap-2`,children:[(0,K.jsx)(lm,{className:`size-5 text-muted-foreground`}),`原始记忆`,(0,K.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,u.length,` 条)`]})]}),u.length===0?(0,K.jsx)(`div`,{className:`rounded-lg border border-border bg-card p-8 text-center space-y-2`,children:(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`此簇暂无成员记忆`})}):(0,K.jsx)(`div`,{className:`space-y-3`,children:u.map((e,n)=>(0,K.jsxs)(`div`,{className:`rounded-lg border border-border bg-card p-4 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,K.jsxs)(`span`,{className:`font-mono bg-muted px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,n+1]}),(0,K.jsx)(hJ,{variant:`outline`,className:`text-xs ${SJ(e.category)}`,children:CJ(e.category)}),e.importance>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(Jp,{className:`size-3`}),e.importance.toFixed(2)]}),(0,K.jsxs)(`span`,{className:`ml-auto flex items-center gap-1`,children:[(0,K.jsx)(qp,{className:`size-3`}),Phe(e.created_at)]})]}),(0,K.jsx)(Ihe,{content:e.content||`—`})]},e.id))})]})]})}async function Rhe(){return ib.get(`/v1/stats/config`)}async function zhe(e=50){return ib.get(`/v1/tier-changes`,{params:{limit:e}})}async function Bhe(){return ib.post(`/v1/lifecycle/trigger`,{})}var B9=6,Vhe={access_via_get:`访问触发`,access_via_search:`搜索触发`,access_via_recall:`召回触发`,access_via_cross_space_search:`跨空间搜索触发`,scheduled_evaluation:`定时评估`},V9={peripheral:0,working:1,core:2};function Hhe(){let e=new Date,n=B9-e.getHours()%B9,r=new Date(e.getTime()+n*36e5);return r.setMinutes(0,0,0),r.toLocaleString(`zh-CN`)}function Uhe(e,n){let r=[];for(let i=0;i<=120;i+=2){let a=Math.log(2)/n,o=Math.exp(-a*i**+e);r.push({day:`D${i}`,Core:e<1?Math.max(o,.9):o*.95,Working:o,Peripheral:o*.85})}return r}function Whe(){return(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[1,2].map(e=>(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsx)(Tb,{className:`h-4 w-28`})}),(0,K.jsxs)(wb,{className:`space-y-2`,children:[(0,K.jsx)(Tb,{className:`h-4 w-full`}),(0,K.jsx)(Tb,{className:`h-4 w-3/4`}),(0,K.jsx)(Tb,{className:`h-4 w-1/2`})]})]},e))})}function Ghe(){return(0,K.jsx)(`div`,{className:`space-y-2`,children:[1,2,3,4].map(e=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3`,children:[(0,K.jsx)(Tb,{className:`h-4 w-4`}),(0,K.jsx)(Tb,{className:`h-3 w-24`}),(0,K.jsx)(Tb,{className:`h-5 w-14`}),(0,K.jsx)(Tb,{className:`h-3 w-4`}),(0,K.jsx)(Tb,{className:`h-5 w-14`}),(0,K.jsx)(Tb,{className:`h-3 flex-1`})]},e))})}function Khe(){let[e,n]=(0,y.useState)(null),[r,i]=(0,y.useState)([]),[a,o]=(0,y.useState)(0),[s,c]=(0,y.useState)(!0),[l,u]=(0,y.useState)(!0),[d,f]=(0,y.useState)(20),[p,m]=(0,y.useState)(!1),h=async()=>{try{c(!0),n(await Rhe())}catch(e){console.error(`Failed to load lifecycle config:`,e),G.error(`加载生命周期配置失败`)}finally{c(!1)}},g=async()=>{try{u(!0);let e=await zhe(d);i(e.changes||[]),o(e.totalCount||0)}catch(e){console.error(`Failed to load tier changes:`,e),G.error(`加载升降级历史失败`)}finally{u(!1)}};(0,y.useEffect)(()=>{h(),g()},[]),(0,y.useEffect)(()=>{g()},[d]);let _=()=>{h(),g()},v=async()=>{try{m(!0);let e=await Bhe();G.success(e.message),h(),g()}catch(e){console.error(`Failed to trigger lifecycle:`,e),G.error(`触发生命周期失败`)}finally{m(!1)}},b=e?Uhe(e.decay.tiers?.working?.beta??1,e.decay.half_life_days):[],x=r.filter(e=>(V9[e.from]??0)<(V9[e.to]??0)).length,S=r.filter(e=>(V9[e.from]??0)>=(V9[e.to]??0)).length;return(0,K.jsxs)(`div`,{className:`space-y-6 max-w-6xl mx-auto`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-semibold tracking-tight flex items-center gap-2`,children:[(0,K.jsx)(Ym,{className:`size-5`}),`生命周期管理`]}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`记忆衰减、升降级、自动遗忘的生命周期策略`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:_,disabled:s&&l,children:[(0,K.jsx)(zm,{className:`h-4 w-4 mr-1`}),`刷新`]}),(0,K.jsxs)(J,{variant:`default`,size:`sm`,onClick:v,disabled:p,children:[p?(0,K.jsx)(wm,{className:`h-4 w-4 mr-1 animate-spin`}):(0,K.jsx)(ih,{className:`h-4 w-4 mr-1`}),`立即执行`]})]})]}),(0,K.jsxs)(bb,{children:[(0,K.jsxs)(xb,{className:`pb-3`,children:[(0,K.jsxs)(Sb,{className:`text-sm font-medium flex items-center gap-2`,children:[(0,K.jsx)(nm,{className:`size-4 text-violet-500`}),`调度器状态`]}),(0,K.jsx)(Cb,{children:`自动评估与遗忘任务的运行状态`})]}),(0,K.jsxs)(wb,{children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,K.jsxs)(`div`,{className:`p-3 rounded-lg border`,children:[(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`调度间隔`}),(0,K.jsxs)(`p`,{className:`text-lg font-semibold mt-1`,children:[`每 `,B9,` 小时`]})]}),(0,K.jsxs)(`div`,{className:`p-3 rounded-lg border`,children:[(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`预计下次运行`}),(0,K.jsx)(`p`,{className:`text-sm font-semibold mt-1`,children:Hhe()})]}),(0,K.jsxs)(`div`,{className:`p-3 rounded-lg border`,children:[(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`启动时运行`}),(0,K.jsx)(`div`,{className:`mt-1`,children:(0,K.jsx)(hJ,{variant:`outline`,className:`bg-emerald-500/10 text-emerald-600 border-emerald-500/30`,children:`已启用`})})]})]}),(0,K.jsx)(`div`,{className:`mt-4 p-3 rounded-lg border border-dashed text-xs text-muted-foreground space-y-1`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(om,{className:`size-3.5`}),(0,K.jsx)(`span`,{children:`调度器将自动执行:Weibull 衰减计算、Tier 评估升降级、关键词 TTL 检测、Superseded 归档清理`})]})})]})]}),s?(0,K.jsx)(Whe,{}):e?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{className:`pb-3`,children:(0,K.jsxs)(Sb,{className:`text-sm font-medium flex items-center gap-2`,children:[(0,K.jsx)(Rp,{className:`size-4 text-blue-500`}),`衰减参数`]})}),(0,K.jsxs)(wb,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 text-sm`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`默认半衰期`}),(0,K.jsxs)(`p`,{className:`font-semibold`,children:[e.decay.half_life_days,` 天`]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`Stale 阈值`}),(0,K.jsx)(`p`,{className:`font-semibold`,children:`0.3`})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`权重分配`}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(hJ,{variant:`outline`,className:`bg-blue-500/10 text-blue-600 border-blue-500/30 text-xs`,children:[`时效 `,e.decay.recency_weight]}),(0,K.jsxs)(hJ,{variant:`outline`,className:`bg-emerald-500/10 text-emerald-600 border-emerald-500/30 text-xs`,children:[`频率 `,e.decay.frequency_weight]}),(0,K.jsxs)(hJ,{variant:`outline`,className:`bg-violet-500/10 text-violet-600 border-violet-500/30 text-xs`,children:[`内在 `,e.decay.intrinsic_weight]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Tier 衰减速率 (β)`}),(0,K.jsx)(`div`,{className:`flex gap-2`,children:Object.entries(e.decay.tiers||{}).map(([e,n])=>(0,K.jsxs)(hJ,{variant:`outline`,className:`text-xs ${EJ(e)}`,children:[wJ(e),` β=`,n.beta]},e))})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Tier 底线分数`}),(0,K.jsx)(`div`,{className:`flex gap-2`,children:Object.entries(e.decay.tiers||{}).map(([e,n])=>(0,K.jsxs)(hJ,{variant:`outline`,className:`text-xs ${EJ(e)}`,children:[wJ(e),` ≥`,n.floor]},e))})]})]})]}),(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{className:`pb-3`,children:(0,K.jsxs)(Sb,{className:`text-sm font-medium flex items-center gap-2`,children:[(0,K.jsx)(Zm,{className:`size-4 text-emerald-500`}),`升降级规则`]})}),(0,K.jsxs)(wb,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`p-3 rounded-lg border space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,K.jsx)(Up,{className:`size-4 text-emerald-500`}),(0,K.jsx)(hJ,{variant:`outline`,className:EJ(`peripheral`),children:wJ(`peripheral`)}),(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`→`}),(0,K.jsx)(hJ,{variant:`outline`,className:EJ(`working`),children:wJ(`working`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 text-xs`,children:[(0,K.jsxs)(`span`,{className:`text-muted-foreground`,children:[`访问 ≥`,e.promotion.peripheral_to_working.min_access_count,`次`]}),(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,K.jsxs)(`span`,{className:`text-muted-foreground`,children:[`综合 ≥`,e.promotion.peripheral_to_working.min_composite]})]})]}),(0,K.jsxs)(`div`,{className:`p-3 rounded-lg border space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,K.jsx)(Up,{className:`size-4 text-emerald-500`}),(0,K.jsx)(hJ,{variant:`outline`,className:EJ(`working`),children:wJ(`working`)}),(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`→`}),(0,K.jsx)(hJ,{variant:`outline`,className:EJ(`core`),children:wJ(`core`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 text-xs`,children:[(0,K.jsxs)(`span`,{className:`text-muted-foreground`,children:[`访问 ≥`,e.promotion.working_to_core.min_access_count,`次`]}),(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,K.jsxs)(`span`,{className:`text-muted-foreground`,children:[`综合 ≥`,e.promotion.working_to_core.min_composite]}),e.promotion.working_to_core.min_importance!=null&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,K.jsxs)(`span`,{className:`text-muted-foreground`,children:[`重要性 ≥`,e.promotion.working_to_core.min_importance]})]})]})]}),(0,K.jsx)(`div`,{className:`p-3 rounded-lg border border-dashed space-y-1 text-xs text-muted-foreground`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(zp,{className:`size-3.5 text-red-400`}),(0,K.jsx)(`span`,{children:`不满足条件时自动降级至低等级`})]})})]})]})]}),b.length>0&&(0,K.jsxs)(bb,{children:[(0,K.jsxs)(xb,{className:`pb-2`,children:[(0,K.jsxs)(Sb,{className:`text-sm font-medium flex items-center gap-2`,children:[(0,K.jsx)(ih,{className:`size-4 text-amber-500`}),`衰减曲线预览`]}),(0,K.jsx)(Cb,{children:`基于当前配置参数生成的理论衰减趋势`})]}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`h-64`,children:(0,K.jsx)(oD,{width:`100%`,height:`100%`,children:(0,K.jsxs)(Jq,{data:b,children:[(0,K.jsx)(KW,{strokeDasharray:`3 3`,className:`opacity-30`}),(0,K.jsx)(oK,{dataKey:`day`,tick:{fontSize:11},interval:14,label:{value:`天数`,position:`insideBottomRight`,offset:-5,fontSize:11}}),(0,K.jsx)(CK,{domain:[0,1],tick:{fontSize:11},label:{value:`分数`,angle:-90,position:`insideLeft`,fontSize:11}}),(0,K.jsx)(VE,{contentStyle:{fontSize:12,borderRadius:8},formatter:e=>[e.toFixed(3)]}),(0,K.jsx)(FT,{iconType:`line`,wrapperStyle:{fontSize:12}}),(0,K.jsx)(bG,{type:`monotone`,dataKey:`Core`,stroke:`#f59e0b`,strokeWidth:2,dot:!1,name:`核心 (Core)`}),(0,K.jsx)(bG,{type:`monotone`,dataKey:`Working`,stroke:`#10b981`,strokeWidth:2,dot:!1,name:`工作区 (Working)`}),(0,K.jsx)(bG,{type:`monotone`,dataKey:`Peripheral`,stroke:`#94a3b8`,strokeWidth:2,dot:!1,name:`边缘 (Peripheral)`})]})})})})]})]}):(0,K.jsx)(bb,{children:(0,K.jsx)(wb,{className:`py-8 text-center`,children:(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`无法加载生命周期配置`})})}),(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(Sb,{className:`text-sm font-medium`,children:`升降级历史`}),(0,K.jsx)(Cb,{children:`最近的 Tier 变更记录`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(hJ,{variant:`outline`,className:`bg-emerald-500/10 text-emerald-600 border-emerald-500/30 text-xs`,children:[`↑ 升级 `,x]}),(0,K.jsxs)(hJ,{variant:`outline`,className:`bg-red-500/10 text-red-600 border-red-500/30 text-xs`,children:[`↓ 降级 `,S]}),(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`共 `,a,` 条`]})]})]})}),(0,K.jsx)(wb,{className:`p-0`,children:l?(0,K.jsx)(Ghe,{}):r.length===0?(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground py-12 text-center`,children:`暂无变更记录`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`divide-y`,children:r.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 hover:bg-muted/30 transition-colors`,children:[(V9[e.from]??0)<(V9[e.to]??0)?(0,K.jsx)(Up,{className:`size-4 text-emerald-500 shrink-0`}):(0,K.jsx)(zp,{className:`size-4 text-red-500 shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground w-36 shrink-0`,children:new Date(e.at).toLocaleString(`zh-CN`)}),(0,K.jsx)(hJ,{variant:`outline`,className:EJ(e.from),children:wJ(e.from)}),(0,K.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`→`}),(0,K.jsx)(hJ,{variant:`outline`,className:EJ(e.to),children:wJ(e.to)}),(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground w-20 shrink-0`,children:Vhe[e.reason]||e.reason}),(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground w-12 shrink-0`,children:[`#`,e.accessCount]}),(0,K.jsx)(`span`,{className:`text-xs flex-1 min-w-0 truncate text-muted-foreground`,children:e.memoryTitle||e.memoryId?.slice(0,12)||`—`}),(0,K.jsx)(`span`,{className:`text-xs font-mono text-muted-foreground shrink-0`,children:e.memoryId?`${e.memoryId.slice(0,8)}...`:`—`})]},`${e.memoryId}-${e.at}-${e.from}-${e.to}`))}),r.length<a&&(0,K.jsx)(`div`,{className:`flex items-center justify-center px-4 py-3 border-t`,children:(0,K.jsx)(J,{variant:`ghost`,size:`sm`,onClick:()=>f(e=>e+20),children:`加载更多`})})]})})]})]})}function qhe(){let e=et(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(!1),u=(0,y.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),e.type===`dragenter`||e.type===`dragover`?l(!0):e.type===`dragleave`&&l(!1)},[]),d=(0,y.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),l(!1),e.dataTransfer.files&&e.dataTransfer.files[0]&&(r(e.dataTransfer.files[0]),s(null))},[]);return(0,K.jsxs)(`div`,{className:`space-y-6 max-w-3xl`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(J,{variant:`ghost`,size:`icon`,onClick:()=>e(`/memories`),children:(0,K.jsx)(Bp,{className:`h-4 w-4`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`批量导入`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`从 JSON、CSV 或 Markdown 文件导入记忆`})]})]}),(0,K.jsx)(bb,{className:`border-2 border-dashed p-8 transition-colors ${c?`border-primary bg-primary/5`:`border-border`}`,onDragEnter:u,onDragLeave:u,onDragOver:u,onDrop:d,children:(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-4 text-center`,children:[(0,K.jsx)($m,{className:`h-10 w-10 text-muted-foreground`}),(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium`,children:n?n.name:`拖拽文件到此处,或点击选择`}),(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`支持 JSON、CSV、Markdown 格式`})]}),(0,K.jsx)(`input`,{type:`file`,accept:`.json,.csv,.md,.markdown`,onChange:e=>{e.target.files&&e.target.files[0]&&(r(e.target.files[0]),s(null))},className:`hidden`,id:`file-upload`}),(0,K.jsx)(J,{variant:`outline`,size:`sm`,onClick:()=>document.getElementById(`file-upload`)?.click(),children:`选择文件`})]})}),n&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border border-border bg-card p-4`,children:[(e=>e.endsWith(`.json`)?(0,K.jsx)(sm,{className:`h-8 w-8 text-blue-500`}):e.endsWith(`.csv`)?(0,K.jsx)(cm,{className:`h-8 w-8 text-green-500`}):e.endsWith(`.md`)||e.endsWith(`.markdown`)?(0,K.jsx)(lm,{className:`h-8 w-8 text-purple-500`}):(0,K.jsx)(lm,{className:`h-8 w-8 text-muted-foreground`}))(n.name),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium truncate`,children:n.name}),(0,K.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[(n.size/1024).toFixed(1),` KB`]})]}),(0,K.jsx)(J,{onClick:async()=>{if(!n){G.error(`请先选择文件`);return}let e=new FormData;e.append(`file`,n);let r=n.name.endsWith(`.json`)?`json`:n.name.endsWith(`.csv`)?`csv`:`md`;e.append(`format`,r),a(!0);try{let n=await ib.post(`/v1/imports`,e,{headers:{"Content-Type":`multipart/form-data`}});s({success:!0,imported:n.imported||0,failed:n.failed||0,errors:n.errors}),G.success(`成功导入 ${n.imported||0} 条记忆`)}catch(e){let n=e.response?.data?.error||e.message||`导入失败`;s({success:!1,imported:0,failed:0,errors:[n]}),G.error(n)}finally{a(!1)}},disabled:i,size:`sm`,children:i?`导入中...`:`开始导入`})]}),o&&(0,K.jsxs)(bb,{className:`p-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[o.success?(0,K.jsx)(em,{className:`h-5 w-5 text-green-500`}):(0,K.jsx)(tm,{className:`h-5 w-5 text-red-500`}),(0,K.jsx)(`h3`,{className:`font-semibold`,children:o.success?`导入成功`:`导入失败`})]}),o.success&&(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{className:`rounded-lg bg-green-500/10 p-4 text-center`,children:[(0,K.jsx)(`p`,{className:`text-2xl font-bold text-green-500`,children:o.imported}),(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`成功导入`})]}),(0,K.jsxs)(`div`,{className:`rounded-lg bg-red-500/10 p-4 text-center`,children:[(0,K.jsx)(`p`,{className:`text-2xl font-bold text-red-500`,children:o.failed}),(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`导入失败`})]})]}),o.errors&&o.errors.length>0&&(0,K.jsxs)(`div`,{className:`mt-4 space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-red-500`,children:`错误信息:`}),o.errors.map(e=>(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e},e))]})]}),(0,K.jsxs)(bb,{className:`p-6`,children:[(0,K.jsx)(`h3`,{className:`font-semibold mb-3`,children:`支持格式说明`}),(0,K.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(sm,{className:`h-4 w-4 text-blue-500 mt-0.5`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`font-medium`,children:`JSON`}),(0,K.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`标准 JSON 数组格式,每条记忆包含 content, tags, category 等字段`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(cm,{className:`h-4 w-4 text-green-500 mt-0.5`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`font-medium`,children:`CSV`}),(0,K.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`包含列:content, tags, category, importance, confidence`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(lm,{className:`h-4 w-4 text-purple-500 mt-0.5`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`font-medium`,children:`Markdown`}),(0,K.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`每条记忆用标题分隔,支持 frontmatter 元数据`})]})]})]})]})]})}function Jhe(){let{theme:e,setTheme:n}=Sr(),{hasPassword:r,setPassword:i,lock:a}=ob(),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(!1);return(0,K.jsxs)(`div`,{className:`space-y-6 max-w-2xl`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`系统设置`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`管理您的偏好设置和数据`})]}),(0,K.jsxs)(bb,{className:`p-6`,children:[(0,K.jsx)(`h3`,{className:`font-semibold mb-4`,children:`外观`}),(0,K.jsx)(`div`,{className:`space-y-4`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(gb,{className:`text-sm font-medium`,children:`主题模式`}),(0,K.jsxs)(`div`,{className:`flex gap-2 mt-2`,children:[(0,K.jsxs)(J,{variant:e===`light`?`default`:`outline`,size:`sm`,onClick:()=>n(`light`),className:`gap-2`,children:[(0,K.jsx)(qm,{className:`h-4 w-4`}),`亮色`]}),(0,K.jsxs)(J,{variant:e===`dark`?`default`:`outline`,size:`sm`,onClick:()=>n(`dark`),className:`gap-2`,children:[(0,K.jsx)(jm,{className:`h-4 w-4`}),`暗黑`]}),(0,K.jsxs)(J,{variant:e===`system`?`default`:`outline`,size:`sm`,onClick:()=>n(`system`),className:`gap-2`,children:[(0,K.jsx)(Am,{className:`h-4 w-4`}),`跟随系统`]})]})]})})]}),(0,K.jsxs)(bb,{className:`p-6`,children:[(0,K.jsx)(`h3`,{className:`font-semibold mb-4`,children:`私密空间 Vault`}),(0,K.jsxs)(`div`,{className:`space-y-4`,children:[r?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Vault 密码已设置。私密记忆需要输入密码才能查看。`}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>l(!c),children:[(0,K.jsx)(Em,{className:`h-4 w-4 mr-2`}),`修改密码`]}),(0,K.jsxs)(J,{variant:`destructive`,size:`sm`,onClick:()=>p(!0),children:[(0,K.jsx)(Xm,{className:`h-4 w-4 mr-2`}),`重置 Vault`]})]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`尚未设置 Vault 密码。设置后,私密记忆将受到密码保护。`}),(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>l(!0),children:[(0,K.jsx)(Em,{className:`h-4 w-4 mr-2`}),`设置 Vault 密码`]})]}),c&&(0,K.jsxs)(`div`,{className:`flex gap-2 mt-4`,children:[(0,K.jsx)(`input`,{type:`password`,placeholder:`输入新密码`,value:o,onChange:e=>s(e.target.value),className:`flex-1 rounded-md border border-input bg-background px-3 py-2 text-sm`}),(0,K.jsx)(J,{size:`sm`,onClick:()=>{if(!o||o.length<4){G.error(`密码至少需要 4 位`);return}i(o),G.success(`Vault 密码已设置`),s(``),l(!1)},children:`确认`})]})]})]}),(0,K.jsxs)(bb,{className:`p-6`,children:[(0,K.jsx)(`h3`,{className:`font-semibold mb-4`,children:`数据管理`}),(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm font-medium`,children:`导出记忆数据`}),(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`从服务端导出所有记忆为 JSON 文件`})]}),(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:async()=>{d(!0);try{let e=await ib.get(`/v1/memories`,{params:{limit:1e4}}),n={memories:e.memories||[],total_count:e.total_count||0,exportedAt:new Date().toISOString()},r=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=`omem-memories-${new Date().toISOString().slice(0,10)}.json`,a.click(),URL.revokeObjectURL(i),G.success(`已导出 ${n.total_count} 条记忆`)}catch(e){console.error(`Failed to export memories:`,e),G.error(`导出记忆数据失败`)}finally{d(!1)}},disabled:u,children:[(0,K.jsx)(eee,{className:`h-4 w-4 mr-2`}),u?`导出中...`:`导出`]})]}),(0,K.jsx)(m7,{}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm font-medium`,children:`导出本地配置`}),(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`将登录信息、主题等本地设置导出备份`})]}),(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>{let e={auth:JSON.parse(sessionStorage.getItem(`omem-auth`)||`{}`),vault:`已迁移到服务端存储`,theme:localStorage.getItem(`omem-theme`)||`system`,exportedAt:new Date().toISOString()},n=new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`omem-config-${new Date().toISOString().slice(0,10)}.json`,i.click(),URL.revokeObjectURL(r),G.success(`本地配置已导出`)},children:[(0,K.jsx)(tee,{className:`h-4 w-4 mr-2`}),`导出`]})]}),(0,K.jsx)(m7,{}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm font-medium`,children:`清除缓存`}),(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`清除所有本地存储的数据(不可逆)`})]}),(0,K.jsxs)(J,{variant:`destructive`,size:`sm`,onClick:()=>{sessionStorage.clear(),G.success(`缓存已清除`,{description:`所有本地数据已清除,刷新页面后生效`})},children:[(0,K.jsx)(Xm,{className:`h-4 w-4 mr-2`}),`清除`]})]})]})]}),(0,K.jsxs)(bb,{className:`p-6`,children:[(0,K.jsx)(`h3`,{className:`font-semibold mb-4`,children:`关于`}),(0,K.jsxs)(`div`,{className:`space-y-2 text-sm`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(vm,{className:`h-4 w-4 text-muted-foreground`}),(0,K.jsx)(`span`,{children:`omem-web v0.1.0`})]}),(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`omem 自部署版 Web 管理端`}),(0,K.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`备案号:`,(0,K.jsx)(`a`,{href:`https://beian.miit.gov.cn`,target:`_blank`,rel:`noopener noreferrer`,className:`underline`,children:`吉ICP备2026003061号`})]})]})]}),(0,K.jsx)(aJ,{open:f,onOpenChange:p,children:(0,K.jsxs)(oJ,{children:[(0,K.jsxs)(sJ,{children:[(0,K.jsx)(lJ,{children:`确认重置 Vault`}),(0,K.jsx)(uJ,{children:`此操作不可恢复。重置后所有受 Vault 保护的私密记忆将无法访问。`})]}),(0,K.jsxs)(cJ,{children:[(0,K.jsx)(fJ,{onClick:()=>p(!1),children:`取消`}),(0,K.jsx)(dJ,{onClick:async()=>{try{await ib.delete(`/v1/vault/password`),a(),G.success(`Vault 已重置`),l(!1),p(!1)}catch{G.error(`重置 Vault 失败`)}},className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`确认重置`})]})]})})]})}function H9(e){return`/v2/profile${e}`}var U9={getPreferences(e){return ib.get(H9(`/preferences`),{params:e?{project_path:e}:void 0})},getPreference(e){return ib.get(H9(`/preferences/${e}`))},createPreference(e){return ib.post(H9(`/preferences`),e)},updatePreference(e,n){return ib.put(H9(`/preferences/${e}`),n)},deletePreference(e){return ib.delete(H9(`/preferences/${e}`))},getStats(e){return ib.get(H9(`/stats`),{params:e?{project_path:e}:void 0})},getInjection(e){return ib.get(H9(`/inject`),{params:e?{project_path:e}:void 0})},triggerInduction(e,n){return ib.post(H9(`/induction/trigger`),{candidate_texts:e??[],project_path:n})},getInductionRuns(e){return ib.get(H9(`/induction/runs`),{params:e?{project_path:e}:void 0})},getVersions(e){return ib.get(H9(`/versions`),{params:e?{project_path:e}:void 0})},getChangelog(e){return ib.get(H9(`/changelog`),{params:e?{project_path:e}:void 0})}};function W9(e){let n=e.toLowerCase();return n.includes(`喜欢`)||n.includes(`偏好`)||n.includes(`习惯`)?{type:`preference`,icon:Sm,color:`text-amber-600 dark:text-amber-400`,bgColor:`bg-amber-50 dark:bg-amber-500/10 border-amber-200 dark:border-amber-500/30`,label:`偏好`}:n.includes(`项目`)||n.includes(`工程`)||n.includes(`开发`)?{type:`project`,icon:ih,color:`text-blue-600 dark:text-blue-400`,bgColor:`bg-blue-50 dark:bg-blue-500/10 border-blue-200 dark:border-blue-500/30`,label:`项目`}:n.includes(`技能`)||n.includes(`能力`)||n.includes(`精通`)||n.includes(`熟练`)?{type:`skill`,icon:Gm,color:`text-violet-600 dark:text-violet-400`,bgColor:`bg-violet-50 dark:bg-violet-500/10 border-violet-200 dark:border-violet-500/30`,label:`技能`}:n.includes(`笔记`)||n.includes(`记录`)||n.includes(`文档`)?{type:`note`,icon:Wp,color:`text-slate-600 dark:text-slate-400`,bgColor:`bg-slate-50 dark:bg-slate-500/10 border-slate-200 dark:border-slate-500/30`,label:`笔记`}:{type:`fact`,icon:th,color:`text-emerald-600 dark:text-emerald-400`,bgColor:`bg-emerald-50 dark:bg-emerald-500/10 border-emerald-200 dark:border-emerald-500/30`,label:`事实`}}function Yhe(){return{type:`private`,icon:Em,color:`text-amber-600 dark:text-amber-400`,bgColor:`bg-amber-50 dark:bg-amber-500/10 border-amber-200 dark:border-amber-500/30`,label:`私密`}}function G9(e){return e.replace(/^#+\s*/,``).trim()}function Xhe(e,n){return n===`private`?!0:e.some(e=>e===`私密`||e.toLowerCase()===`private`)}function Zhe(e){return new Date(e).toLocaleString(`zh-CN`,{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function K9(e){let n=Date.now()-new Date(e).getTime(),r=Math.floor(n/6e4);if(r<1)return`刚刚`;if(r<60)return`${r} 分钟前`;let i=Math.floor(r/60);if(i<24)return`${i} 小时前`;let a=Math.floor(i/24);return a<30?`${a} 天前`:Zhe(e)}function q9({content:e}){let[n,r]=(0,y.useState)(!1),i=(0,y.useRef)(null),[a,o]=(0,y.useState)(!1);return(0,y.useEffect)(()=>{let e=i.current;if(!e)return;let n=new ResizeObserver(()=>o(e.scrollHeight>e.clientHeight));return n.observe(e),()=>n.disconnect()},[]),(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:wp(`relative`,!n&&`max-h-60 overflow-hidden`),children:[(0,K.jsx)(`div`,{ref:i,className:`prose prose-sm dark:prose-invert max-w-none`,children:(0,K.jsx)(p0,{remarkPlugins:[Y4],children:e})}),!n&&a&&(0,K.jsx)(`div`,{className:`absolute bottom-0 left-0 right-0 h-10 bg-gradient-to-t from-background to-transparent pointer-events-none`})]}),a&&(0,K.jsx)(J,{variant:`ghost`,size:`sm`,className:`mt-1 h-auto py-1 px-2 text-xs text-muted-foreground hover:text-foreground`,onClick:()=>r(!n),children:n?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)($p,{className:`size-3 mr-1`}),`收起`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Xp,{className:`size-3 mr-1`}),`展开全文`]})})]})}var Qhe=[{name:`communication_style`,display:`沟通风格`},{name:`tone`,display:`语气偏好`},{name:`code_style`,display:`代码风格`},{name:`error_handling`,display:`错误处理`},{name:`naming_convention`,display:`命名规范`},{name:`testing_strategy`,display:`测试策略`},{name:`workflow_preference`,display:`工作流偏好`},{name:`commit_style`,display:`提交风格`},{name:`emoji_preference`,display:`Emoji偏好`},{name:`self_reference`,display:`自称方式`},{name:`address_style`,display:`称呼方式`},{name:`language`,display:`语言`},{name:`framework_preference`,display:`框架偏好`},{name:`preferred_tools`,display:`工具偏好`}],$he={communication_style:`沟通风格`,coding_preferences:`编码偏好`,project_context:`项目上下文`,tool_preferences:`工具偏好`,domain_knowledge:`领域知识`,work_style:`工作风格`,language_preference:`语言偏好`,framework_preferences:`框架偏好`},ege={communication_style:Rp,coding_preferences:ih,project_context:um,tool_preferences:bm,domain_knowledge:Wp,work_style:Rm,language_preference:Sm,framework_preferences:Gm};function tge(e){return $he[e]||e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function nge(e){return ege[e]||bm}var rge={global:{className:`bg-blue-50 dark:bg-blue-500/10 text-blue-700 dark:text-blue-300 border-blue-200 dark:border-blue-500/30`,label:`全局`},project:{className:`bg-violet-50 dark:bg-violet-500/10 text-violet-700 dark:text-violet-300 border-violet-200 dark:border-violet-500/30`,label:`项目`},session:{className:`bg-emerald-50 dark:bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 border-emerald-200 dark:border-emerald-500/30`,label:`会话`}};function ige(){let e=et(),n=ob(e=>e.unlock),r=ob(e=>e.hasPassword),i=ob(e=>e.isUnlocked),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)([]),[d,f]=(0,y.useState)([]),[p,m]=(0,y.useState)(!0),[h,g]=(0,y.useState)(`preferences`),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(``),[E,D]=(0,y.useState)(null),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(new Set),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(null),[I,L]=(0,y.useState)(!1),[R,z]=(0,y.useState)(null),[ee,B]=(0,y.useState)(!1),[V,H]=(0,y.useState)(``),[U,te]=(0,y.useState)(`all`),[W,ne]=(0,y.useState)(1),[re,ie]=(0,y.useState)(1);(0,y.useEffect)(()=>{async function e(){try{m(!0);let e=_||void 0,[n,r,i,a]=await Promise.all([ib.get(`/v1/profile`).catch(()=>null),U9.getStats(e).catch(()=>null),U9.getPreferences(e).catch(()=>[]),U9.getChangelog(e).catch(()=>[])]);n&&o(n),r&&c(r),u(Array.isArray(i)?i:[]),f(Array.isArray(a)?a:[])}catch(e){console.error(`Failed to load profile:`,e),G.error(`加载画像数据失败`)}finally{m(!1)}}e()},[_]);let ae=async()=>{if(!w.trim()){D(`请输入密码`);return}k(!0);let e=await n(w);if(k(!1),!e){D(`密码错误`);return}S&&j(e=>new Set(e).add(S)),x(!1),C(null),T(``),D(null),G.success(`已解锁`)},oe=e=>{if(i){j(n=>new Set(n).add(e));return}if(!r){G.error(`请先在设置中设置密码`);return}C(e),T(``),D(null),x(!0)},se=a?.static_facts||[],ce=a?.dynamic_context||[],le=(0,y.useMemo)(()=>se.map(e=>{let n=Xhe(e.tags||[],e.visibility),r=n?Yhe():W9(e.content);return{fact:e.content,factObj:e,isPrivate:n,meta:r}}),[se]),ue=(0,y.useMemo)(()=>{let e=new Map;for(let n of l){if(U!==`all`&&n.scope!==U)continue;if(V.trim()){let e=V.toLowerCase();if(!n.value.toLowerCase().includes(e)&&!n.slot.toLowerCase().includes(e)&&!(n.project_path||``).toLowerCase().includes(e))continue}let r=e.get(n.slot)||[];r.push(n),e.set(n.slot,r)}return e},[l,V,U]),de=(0,y.useMemo)(()=>Array.from(ue.entries()),[ue]),fe=Math.max(1,Math.ceil(de.length/5)),pe=(0,y.useMemo)(()=>{let e=(W-1)*5;return de.slice(e,e+5)},[de,W]),me=async()=>{let e=_||void 0,[n,r]=await Promise.all([U9.getPreferences(e),U9.getStats(e).catch(()=>null)]);u(Array.isArray(n)?n:[]),r&&c(r)},he=async e=>{if(!(!(`slot`in e)||!e.slot))try{L(!0),await U9.createPreference(e),G.success(`偏好已创建`),N(!1),await me()}catch{G.error(`创建失败`)}finally{L(!1)}},ge=async(e,n)=>{try{L(!0),await U9.updatePreference(e,n),G.success(`偏好已更新`),F(null);let r=_||void 0,i=await U9.getPreferences(r);u(Array.isArray(i)?i:[])}catch{G.error(`更新失败`)}finally{L(!1)}},_e=async()=>{if(R)try{B(!0),await U9.deletePreference(R.id),G.success(`偏好已删除`),z(null),await me()}catch{G.error(`删除失败`)}finally{B(!1)}},ve=(0,y.useMemo)(()=>{let e=new Set;for(let n of l)n.project_path&&e.add(n.project_path);return Array.from(e).sort()},[l]),ye=l.length;return(0,K.jsxs)(`div`,{className:`min-h-screen bg-gradient-to-b from-background via-background to-muted/30`,children:[(0,K.jsxs)(`div`,{className:`max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 py-6 space-y-6`,children:[(0,K.jsxs)(J,{variant:`ghost`,size:`sm`,className:`text-muted-foreground hover:text-foreground -ml-2`,onClick:()=>e(-1),children:[(0,K.jsx)(Bp,{className:`size-4 mr-1.5`}),`返回`]}),(0,K.jsxs)(`div`,{className:`relative overflow-hidden rounded-2xl bg-gradient-to-br from-amber-50 via-orange-50 to-rose-50 dark:from-amber-500/10 dark:via-orange-500/5 dark:to-rose-500/10 border border-amber-200/50 dark:border-amber-500/20 p-6 md:p-8`,children:[(0,K.jsx)(`div`,{className:`absolute top-0 right-0 -mt-8 -mr-8 w-48 h-48 bg-amber-400/15 dark:bg-amber-500/10 rounded-full blur-3xl`}),(0,K.jsx)(`div`,{className:`absolute bottom-0 left-0 -mb-6 -ml-6 w-36 h-36 bg-orange-400/10 dark:bg-orange-500/8 rounded-full blur-3xl`}),(0,K.jsxs)(`div`,{className:`relative z-10 flex flex-col md:flex-row md:items-center md:justify-between gap-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center size-14 rounded-2xl bg-gradient-to-br from-amber-400 to-orange-500 shadow-lg shadow-amber-500/25`,children:(0,K.jsx)(th,{className:`size-7 text-white`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl md:text-3xl font-bold tracking-tight text-foreground`,children:`用户画像`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:`偏好 · 记忆 · 洞察`})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2.5 px-4 py-2.5 rounded-xl bg-white/80 dark:bg-card/80 border border-amber-200/60 dark:border-amber-500/20 shadow-sm`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center size-8 rounded-lg bg-amber-100 dark:bg-amber-500/15`,children:(0,K.jsx)(bm,{className:`size-4 text-amber-600 dark:text-amber-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-lg font-bold leading-none text-foreground`,children:ye}),(0,K.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`条偏好`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2.5 px-4 py-2.5 rounded-xl bg-white/80 dark:bg-card/80 border border-orange-200/60 dark:border-orange-500/20 shadow-sm`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center size-8 rounded-lg bg-orange-100 dark:bg-orange-500/15`,children:(0,K.jsx)(Jp,{className:`size-4 text-orange-600 dark:text-orange-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-lg font-bold leading-none text-foreground`,children:s?.total??0}),(0,K.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`归纳总量`})]})]}),s?.last_induction_at&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2.5 px-4 py-2.5 rounded-xl bg-white/80 dark:bg-card/80 border border-rose-200/60 dark:border-rose-500/20 shadow-sm`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center size-8 rounded-lg bg-rose-100 dark:bg-rose-500/15`,children:(0,K.jsx)(nm,{className:`size-4 text-rose-600 dark:text-rose-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm font-semibold leading-none text-foreground`,children:K9(s.last_induction_at)}),(0,K.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`最近归纳`})]})]})]})]})]}),(0,K.jsxs)(x7,{value:h,onValueChange:g,className:`space-y-4`,children:[(0,K.jsxs)(S7,{className:`bg-muted/60 p-1 h-auto`,children:[(0,K.jsxs)(C7,{value:`preferences`,className:`data-[state=active]:bg-background data-[state=active]:shadow-sm gap-1.5 px-4 py-2 text-sm`,children:[(0,K.jsx)(Gm,{className:`size-3.5`}),`偏好管理`]}),(0,K.jsxs)(C7,{value:`overview`,className:`data-[state=active]:bg-background data-[state=active]:shadow-sm gap-1.5 px-4 py-2 text-sm`,children:[(0,K.jsx)(th,{className:`size-3.5`}),`画像概览`]}),(0,K.jsxs)(C7,{value:`changelog`,className:`data-[state=active]:bg-background data-[state=active]:shadow-sm gap-1.5 px-4 py-2 text-sm`,children:[(0,K.jsx)(mm,{className:`size-3.5`}),`变更历史`]})]}),(0,K.jsxs)(w7,{value:`preferences`,className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center gap-3`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1 w-full sm:max-w-xs`,children:[(0,K.jsx)(Vm,{className:`absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground`}),(0,K.jsx)(hb,{placeholder:`搜索偏好...`,value:V,onChange:e=>{H(e.target.value),ne(1)},className:`pl-9 h-9 bg-muted/40`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[ve.length>0&&(0,K.jsxs)(r9,{value:_,onValueChange:e=>e!=null&&v(e),children:[(0,K.jsxs)(a9,{className:`h-9 w-[180px] text-xs`,children:[(0,K.jsx)(um,{className:`size-3.5 mr-1.5 text-muted-foreground`}),(0,K.jsx)(i9,{placeholder:`全部项目`})]}),(0,K.jsxs)(o9,{children:[(0,K.jsx)(s9,{value:`__all__`,children:`全部项目`}),ve.map(e=>(0,K.jsx)(s9,{value:e,children:e.split(`/`).pop()||e},e))]})]}),(0,K.jsxs)(r9,{value:U,onValueChange:e=>{e!=null&&(te(e),ne(1))},children:[(0,K.jsx)(a9,{className:`h-9 w-[100px] text-xs`,children:(0,K.jsx)(i9,{placeholder:`范围`})}),(0,K.jsxs)(o9,{children:[(0,K.jsx)(s9,{value:`all`,children:`全部范围`}),(0,K.jsx)(s9,{value:`global`,children:`全局`}),(0,K.jsx)(s9,{value:`project`,children:`项目`}),(0,K.jsx)(s9,{value:`session`,children:`会话`})]})]})]}),(0,K.jsxs)(J,{className:`ml-auto h-9 gap-1.5 bg-gradient-to-r from-amber-500 to-orange-500 hover:from-amber-600 hover:to-orange-600 text-white shadow-sm`,onClick:()=>N(!0),children:[(0,K.jsx)(Lm,{className:`size-4`}),`新建偏好`]})]}),p?(0,K.jsx)(`div`,{className:`space-y-4`,children:[1,2,3].map(e=>(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(Tb,{className:`h-5 w-24 rounded-md`}),(0,K.jsx)(Tb,{className:`h-24 w-full rounded-xl`})]},e))}):ue.size===0?(0,K.jsx)(bb,{className:`border-dashed`,children:(0,K.jsxs)(wb,{className:`py-16 flex flex-col items-center gap-3 text-muted-foreground`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center size-12 rounded-2xl bg-muted`,children:(0,K.jsx)(Gm,{className:`size-6`})}),(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium`,children:`暂无偏好数据`}),(0,K.jsx)(`p`,{className:`text-xs mt-1`,children:`点击「新建偏好」开始构建你的画像`})]})]})}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{id:`pref-slot-list`,className:`space-y-4`,children:pe.map(([e,n])=>(0,K.jsx)(age,{slot:e,preferences:n,onEdit:e=>F(e),onDelete:e=>z(e)},e))}),fe>1&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between pt-2`,children:[(0,K.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`第 `,W,` / `,fe,` 页 · 共 `,de.length,` 个分组`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(J,{variant:`outline`,size:`icon`,className:`size-8`,disabled:W<=1,onClick:()=>{ne(e=>Math.max(1,e-1)),document.getElementById(`pref-slot-list`)?.scrollIntoView({behavior:`smooth`,block:`start`})},children:(0,K.jsx)(Zp,{className:`size-4`})}),Array.from({length:fe},(e,n)=>n+1).map(e=>(0,K.jsx)(J,{variant:e===W?`default`:`outline`,size:`icon`,className:wp(`size-8 text-xs`,e===W&&`bg-gradient-to-r from-amber-500 to-orange-500 text-white border-0`),onClick:()=>{ne(e),document.getElementById(`pref-slot-list`)?.scrollIntoView({behavior:`smooth`,block:`start`})},children:e},e)),(0,K.jsx)(J,{variant:`outline`,size:`icon`,className:`size-8`,disabled:W>=fe,onClick:()=>{ne(e=>Math.min(fe,e+1)),document.getElementById(`pref-slot-list`)?.scrollIntoView({behavior:`smooth`,block:`start`})},children:(0,K.jsx)(Qp,{className:`size-4`})})]})]})]})]}),(0,K.jsx)(w7,{value:`overview`,className:`space-y-6`,children:p?(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[1,2,3,4].map(e=>(0,K.jsx)(Tb,{className:`h-48 w-full rounded-xl`},e))}):(0,K.jsxs)(K.Fragment,{children:[le.length>0&&(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Um,{className:`size-5 text-amber-500`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold`,children:`画像特征`}),(0,K.jsxs)(hJ,{variant:`secondary`,className:`text-[10px]`,children:[le.length,` 条`]})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:le.map(({fact:e,factObj:n,isPrivate:r,meta:i})=>{let a=i.icon,o=A.has(e),s=r&&o&&n?.l2_content||G9(e);return(0,K.jsx)(bb,{className:wp(`relative overflow-hidden border transition-all duration-200 hover:shadow-md`,r&&!o&&`border-amber-200 dark:border-amber-500/30`),children:(0,K.jsxs)(wb,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsx)(`div`,{className:wp(`flex items-center justify-center size-8 rounded-lg border`,i.bgColor),children:(0,K.jsx)(a,{className:wp(`size-4`,i.color)})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r&&(0,K.jsxs)(hJ,{variant:`outline`,className:`text-[10px] gap-1 bg-amber-50 dark:bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-200 dark:border-amber-500/30`,children:[(0,K.jsx)(Em,{className:`size-2.5`}),`私密`]}),(0,K.jsx)(hJ,{variant:`outline`,className:wp(`text-[10px]`,i.bgColor,i.color),children:i.label})]})]}),(0,K.jsx)(`div`,{className:wp(r&&!o&&`blur-[6px] select-none opacity-40`),children:(0,K.jsx)(q9,{content:s})}),r&&!o&&(0,K.jsx)(`button`,{type:`button`,className:`mt-3 w-full flex items-center justify-center gap-2 px-3 py-2 rounded-lg bg-amber-50 dark:bg-amber-500/10 text-amber-700 dark:text-amber-300 text-xs font-medium hover:bg-amber-100 dark:hover:bg-amber-500/20 transition-colors border border-amber-200 dark:border-amber-500/30 cursor-pointer`,onClick:()=>oe(e),children:o?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(am,{className:`size-3.5`}),`已解锁`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Em,{className:`size-3.5`}),`点击解锁私密内容`]})})]})},`sf-${e.slice(0,40)}`)})})]}),ce.length>0&&(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(m7,{}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Rp,{className:`size-5 text-blue-500`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold`,children:`静态偏好`}),(0,K.jsxs)(hJ,{variant:`secondary`,className:`text-[10px]`,children:[ce.length,` 条`]})]}),(0,K.jsxs)(`div`,{className:`relative pl-6 space-y-3`,children:[(0,K.jsx)(`div`,{className:`absolute left-[11px] top-2 bottom-2 w-px bg-gradient-to-b from-blue-300 via-orange-300 to-transparent dark:from-blue-500/40 dark:via-orange-500/40 dark:to-transparent`}),ce.map((e,n)=>{let r=W9(e),i=r.icon;return(0,K.jsxs)(`div`,{className:`relative group`,children:[(0,K.jsx)(`div`,{className:`absolute -left-6 top-2.5 size-[22px] rounded-full bg-gradient-to-br from-blue-400 to-orange-400 ring-[3px] ring-background flex items-center justify-center shadow-sm group-hover:scale-110 transition-transform`,children:(0,K.jsx)(`span`,{className:`text-[9px] font-bold text-white`,children:n+1})}),(0,K.jsx)(bb,{className:`overflow-hidden hover:shadow-sm transition-shadow`,children:(0,K.jsxs)(wb,{className:`p-3.5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsx)(`div`,{className:wp(`flex items-center justify-center size-5 rounded-md border`,r.bgColor),children:(0,K.jsx)(i,{className:wp(`size-3`,r.color)})}),(0,K.jsx)(`span`,{className:wp(`text-[10px] font-medium px-1.5 py-0.5 rounded border`,r.bgColor,r.color),children:r.label})]}),(0,K.jsx)(q9,{content:G9(e)})]})})]},`dc-${n}`)})]})]}),le.length===0&&ce.length===0&&(0,K.jsx)(bb,{className:`border-dashed`,children:(0,K.jsxs)(wb,{className:`py-16 flex flex-col items-center gap-3 text-muted-foreground`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center size-12 rounded-2xl bg-muted`,children:(0,K.jsx)(th,{className:`size-6`})}),(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium`,children:`暂无画像数据`}),(0,K.jsx)(`p`,{className:`text-xs mt-1`,children:`存储更多记忆后,系统将自动构建您的用户画像`})]})]})})]})}),(0,K.jsx)(w7,{value:`changelog`,className:`space-y-4`,children:p?(0,K.jsx)(`div`,{className:`space-y-3`,children:[1,2,3].map(e=>(0,K.jsx)(Tb,{className:`h-20 w-full rounded-xl`},e))}):d.length===0?(0,K.jsx)(bb,{className:`border-dashed`,children:(0,K.jsxs)(wb,{className:`py-16 flex flex-col items-center gap-3 text-muted-foreground`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center size-12 rounded-2xl bg-muted`,children:(0,K.jsx)(mm,{className:`size-6`})}),(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium`,children:`暂无变更记录`}),(0,K.jsx)(`p`,{className:`text-xs mt-1`,children:`偏好变更时将自动记录在这里`})]})]})}):(()=>{let e=Math.ceil(d.length/10),n=d.slice((re-1)*10,re*10);return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`relative pl-6 space-y-3`,children:[(0,K.jsx)(`div`,{className:`absolute left-[11px] top-2 bottom-2 w-px bg-gradient-to-b from-violet-300 via-sky-300 to-transparent dark:from-violet-500/40 dark:via-sky-500/40 dark:to-transparent`}),n.map(e=>{let n=e.action===`created`,r=e.action===`updated`,i=n?{bg:`from-emerald-400 to-teal-400`,color:`text-emerald-700 dark:text-emerald-300`,badgeClass:`bg-emerald-50 dark:bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 border-emerald-200 dark:border-emerald-500/30`,symbol:`+`,label:`创建`}:r?{bg:`from-blue-400 to-sky-400`,color:`text-blue-700 dark:text-blue-300`,badgeClass:`bg-blue-50 dark:bg-blue-500/10 text-blue-700 dark:text-blue-300 border-blue-200 dark:border-blue-500/30`,symbol:`~`,label:`更新`}:{bg:`from-rose-400 to-red-400`,color:`text-rose-700 dark:text-rose-300`,badgeClass:`bg-rose-50 dark:bg-rose-500/10 text-rose-700 dark:text-rose-300 border-rose-200 dark:border-rose-500/30`,symbol:`−`,label:`删除`};return(0,K.jsxs)(`div`,{className:`relative group min-w-0`,children:[(0,K.jsx)(`div`,{className:wp(`absolute -left-6 top-2.5 size-[22px] rounded-full bg-gradient-to-br ring-[3px] ring-background flex items-center justify-center shadow-sm group-hover:scale-110 transition-transform`,i.bg),children:(0,K.jsx)(`span`,{className:`text-[9px] font-bold text-white`,children:i.symbol})}),(0,K.jsx)(bb,{className:`overflow-hidden hover:shadow-sm transition-shadow min-w-0`,children:(0,K.jsxs)(wb,{className:`p-4 space-y-2 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,K.jsxs)(hJ,{variant:`outline`,className:wp(`text-[10px] gap-1 shrink-0`,i.badgeClass),children:[n?(0,K.jsx)(Lm,{className:`size-2.5`}):r?(0,K.jsx)(Pm,{className:`size-2.5`}):(0,K.jsx)(Xm,{className:`size-2.5`}),i.label]}),e.source&&(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground truncate`,children:e.source}),(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto shrink-0`,children:K9(e.created_at)})]}),e.old_value&&(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground line-through break-all`,children:e.old_value}),e.new_value&&(0,K.jsx)(`p`,{className:`text-sm leading-relaxed break-words`,children:e.new_value})]})})]},e.id)})]}),e>1&&(0,K.jsxs)(`div`,{className:`flex items-center justify-center gap-2 pt-2`,children:[(0,K.jsxs)(J,{variant:`outline`,size:`sm`,className:`h-7 text-xs gap-1`,disabled:re<=1,onClick:()=>ie(e=>Math.max(1,e-1)),children:[(0,K.jsx)(Zp,{className:`size-3`}),`上一页`]}),(0,K.jsx)(`div`,{className:`flex items-center gap-1`,children:Array.from({length:e},(e,n)=>n+1).map(e=>(0,K.jsx)(J,{variant:re===e?`default`:`ghost`,size:`sm`,className:`h-7 w-7 text-xs p-0`,onClick:()=>ie(e),children:e},e))}),(0,K.jsxs)(J,{variant:`outline`,size:`sm`,className:`h-7 text-xs gap-1`,disabled:re>=e,onClick:()=>ie(n=>Math.min(e,n+1)),children:[`下一页`,(0,K.jsx)(Qp,{className:`size-3`})]})]})]})})()})]})]}),(0,K.jsx)(aJ,{open:!!R,onOpenChange:e=>{!e&&!ee&&z(null)},children:(0,K.jsxs)(oJ,{children:[(0,K.jsxs)(sJ,{children:[(0,K.jsx)(lJ,{children:`确认删除偏好`}),(0,K.jsxs)(uJ,{children:[`确定要删除这条偏好吗?此操作不可撤销。`,R&&(0,K.jsx)(`span`,{className:`block mt-2 px-3 py-2 rounded-lg bg-muted text-sm text-foreground truncate`,children:R.value})]})]}),(0,K.jsxs)(cJ,{children:[(0,K.jsx)(fJ,{disabled:ee,children:`取消`}),(0,K.jsx)(dJ,{disabled:ee,onClick:_e,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:ee?`删除中...`:`删除`})]})]})}),(0,K.jsx)(J9,{open:M,onOpenChange:N,saving:I,onSubmit:he,title:`新建偏好`}),(0,K.jsx)(J9,{open:!!P,onOpenChange:e=>{e||F(null)},saving:I,onSubmit:e=>{P&&ge(P.id,e)},pref:P,title:`编辑偏好`}),(0,K.jsx)(g9,{open:b,onOpenChange:e=>{e||(x(!1),T(``),D(null))},children:(0,K.jsxs)(_9,{className:`sm:max-w-sm`,children:[(0,K.jsxs)(v9,{children:[(0,K.jsxs)(b9,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Em,{className:`size-4 text-amber-500`}),`解锁私密记忆`]}),(0,K.jsx)(x9,{children:`请输入您的 Vault 密码以解锁受保护的内容。`})]}),(0,K.jsx)(`div`,{className:`space-y-3`,children:(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{className:`text-xs`,children:`密码`}),(0,K.jsx)(hb,{type:`password`,placeholder:`输入 Vault 密码...`,value:w,onChange:e=>{T(e.target.value),D(null)},onKeyDown:e=>e.key===`Enter`&&ae(),className:E?`border-destructive`:``,autoFocus:!0}),E&&(0,K.jsx)(`p`,{className:`text-xs text-destructive`,children:E})]})}),(0,K.jsxs)(y9,{children:[(0,K.jsx)(J,{variant:`outline`,onClick:()=>x(!1),disabled:O,children:`取消`}),(0,K.jsx)(J,{onClick:ae,disabled:O||!w.trim(),children:O?`解锁中...`:`解锁`})]})]})})]})}function age({slot:e,preferences:n,onEdit:r,onDelete:i}){let[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(4),l=nge(e),u=n.slice(0,s),d=s<n.length;return(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2.5 w-full group cursor-pointer text-left border-none bg-transparent p-0`,onClick:()=>{o(!a),c(4)},children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center size-7 rounded-lg bg-gradient-to-br from-amber-100 to-orange-100 dark:from-amber-500/15 dark:to-orange-500/15 border border-amber-200/60 dark:border-amber-500/20`,children:(0,K.jsx)(l,{className:`size-3.5 text-amber-600 dark:text-amber-400`})}),(0,K.jsx)(`span`,{className:`text-sm font-semibold text-foreground`,children:tge(e)}),(0,K.jsx)(hJ,{variant:`secondary`,className:`text-[10px]`,children:n.length}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(Qp,{className:wp(`size-4 text-muted-foreground transition-transform duration-200`,!a&&`rotate-90`)})]}),!a&&(0,K.jsxs)(`div`,{className:`space-y-2.5 pl-9`,children:[(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-2.5`,children:u.map(e=>(0,K.jsx)(oge,{pref:e,onEdit:r,onDelete:i},e.id))}),d&&(0,K.jsxs)(`button`,{type:`button`,className:`w-full flex items-center justify-center gap-1.5 py-2 text-xs text-muted-foreground hover:text-foreground transition-colors rounded-lg hover:bg-muted/50 cursor-pointer`,onClick:()=>c(e=>Math.min(e+4,n.length)),children:[(0,K.jsx)(Xp,{className:`size-3.5`}),`加载更多(剩余 `,n.length-s,` 条)`]})]})]})}function oge({pref:e,onEdit:n,onDelete:r}){let i=rge[e.scope]||{className:`bg-slate-50 dark:bg-slate-500/10 text-slate-700 dark:text-slate-300 border-slate-200 dark:border-slate-500/30`,label:e.scope};return(0,K.jsx)(bb,{className:`group hover:shadow-md transition-all duration-200 border-border/60`,children:(0,K.jsxs)(wb,{className:`p-3.5 space-y-2.5`,children:[(0,K.jsx)(`p`,{className:`text-sm leading-relaxed whitespace-pre-wrap break-words`,children:e.value}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,K.jsx)(hJ,{variant:`outline`,className:wp(`text-[10px] gap-1`,i.className),children:i.label}),e.project_path&&(0,K.jsxs)(hJ,{variant:`outline`,className:`text-[10px] gap-1 bg-violet-50 dark:bg-violet-500/10 text-violet-700 dark:text-violet-300 border-violet-200 dark:border-violet-500/30`,children:[(0,K.jsx)(um,{className:`size-2.5`}),e.project_path.split(`/`).pop()]}),(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:K9(e.updated_at)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity pt-1 border-t border-border/40`,children:[(0,K.jsxs)(`span`,{className:`text-[10px] text-muted-foreground mr-auto`,children:[`置信度 `,(e.confidence*100).toFixed(0),`%`]}),(0,K.jsx)(J,{variant:`ghost`,size:`icon`,className:`size-7 text-muted-foreground hover:text-foreground`,onClick:()=>n(e),children:(0,K.jsx)(Pm,{className:`size-3.5`})}),(0,K.jsx)(J,{variant:`ghost`,size:`icon`,className:`size-7 text-muted-foreground hover:text-destructive`,onClick:()=>r(e),children:(0,K.jsx)(Xm,{className:`size-3.5`})})]})]})})}function J9({open:e,onOpenChange:n,saving:r,onSubmit:i,pref:a,title:o}){let s=!!a,[c,l]=(0,y.useState)(a?.slot||``),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(a?.value||``),[m,h]=(0,y.useState)(String(a?.confidence??.8)),[g,_]=(0,y.useState)(a?.scope||`global`),[v,b]=(0,y.useState)(a?.project_path||``);(0,y.useEffect)(()=>{if(e){let e=a?.slot||``;l(e),d(e.startsWith(`custom:`)?e.slice(7):``),p(a?.value||``),h(String(a?.confidence??.8)),_(a?.scope||`global`),b(a?.project_path||``)}},[e,a]);let x=c===`__custom__`;return(0,K.jsx)(g9,{open:e,onOpenChange:n,children:(0,K.jsxs)(_9,{className:`sm:max-w-md`,children:[(0,K.jsxs)(v9,{children:[(0,K.jsxs)(b9,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Gm,{className:`size-4 text-amber-500`}),o]}),(0,K.jsx)(x9,{children:s?`修改偏好信息。`:`添加一条新的偏好。`})]}),(0,K.jsxs)(`div`,{className:`space-y-4 py-1`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{className:`text-xs`,children:`Slot (类别)`}),s?(0,K.jsx)(hb,{value:c,disabled:!0,className:`h-9 bg-muted/60`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(r9,{value:c||void 0,onValueChange:e=>e!=null&&l(e),children:[(0,K.jsx)(a9,{className:`h-9 w-full`,children:(0,K.jsx)(i9,{placeholder:`选择类别...`})}),(0,K.jsxs)(o9,{children:[Qhe.map(e=>(0,K.jsx)(s9,{value:e.name,children:e.display},e.name)),(0,K.jsx)(s9,{value:`__custom__`,children:`自定义 (custom:...)`})]})]}),x&&(0,K.jsx)(hb,{placeholder:`自定义 slot 名 (小写字母+数字+下划线)`,value:u,onChange:e=>{d(e.target.value.replace(/[^a-z0-9_]/g,``))},className:`h-9`,maxLength:50})]})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{className:`text-xs`,children:`范围`}),(0,K.jsxs)(r9,{value:g,onValueChange:e=>e!=null&&_(e),children:[(0,K.jsx)(a9,{className:`h-9`,children:(0,K.jsx)(i9,{})}),(0,K.jsxs)(o9,{children:[(0,K.jsx)(s9,{value:`global`,children:`全局`}),(0,K.jsx)(s9,{value:`project`,children:`项目`}),(0,K.jsx)(s9,{value:`session`,children:`会话`})]})]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{className:`text-xs`,children:`内容`}),(0,K.jsx)(d9,{placeholder:`偏好内容...`,value:f,onChange:e=>p(e.target.value),rows:3,className:`resize-none`,maxLength:500})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{className:`text-xs`,children:`置信度 (0-1)`}),(0,K.jsx)(hb,{type:`number`,min:`0`,max:`1`,step:`0.1`,value:m,onChange:e=>h(e.target.value),className:`h-9`})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{className:`text-xs`,children:`项目路径 (可选)`}),(0,K.jsx)(hb,{placeholder:`例: /path/to/project`,value:v,onChange:e=>b(e.target.value),className:`h-9`,maxLength:200})]})]})]}),(0,K.jsxs)(y9,{children:[(0,K.jsx)(J,{variant:`outline`,onClick:()=>n(!1),disabled:r,children:`取消`}),(0,K.jsx)(J,{onClick:()=>{let e=x?`custom:${u.trim()}`:c.trim();if(!e||!f.trim()){G.error(`请填写 Slot 和内容`);return}if(x&&!u.trim()){G.error(`请填写自定义 Slot 名`);return}if(s){let e={};f!==(a?.value||``)&&(e.value=f.trim()),m!==String(a?.confidence??.8)&&(e.confidence=parseFloat(m)),g!==(a?.scope||`global`)&&(e.scope=g),v!==(a?.project_path||``)&&(e.project_path=v.trim()||void 0),i(e)}else i({slot:e,value:f.trim(),confidence:parseFloat(m)||.8,scope:g,project_path:v.trim()||void 0})},disabled:r||!f.trim()||(x?!u.trim():!c.trim()),className:`bg-gradient-to-r from-amber-500 to-orange-500 hover:from-amber-600 hover:to-orange-600 text-white`,children:r?s?`保存中...`:`创建中...`:s?`保存`:`创建`})]})]})})}var Y9=y.createContext(void 0);function sge(){let e=y.useContext(Y9);if(e===void 0)throw Error(Fr(63));return e}var X9=function(e){return e.checked=`data-checked`,e.unchecked=`data-unchecked`,e.disabled=`data-disabled`,e.readonly=`data-readonly`,e.required=`data-required`,e.valid=`data-valid`,e.invalid=`data-invalid`,e.touched=`data-touched`,e.dirty=`data-dirty`,e.filled=`data-filled`,e.focused=`data-focused`,e}({}),Z9={...lb,checked(e){return e?{[X9.checked]:``}:{[X9.unchecked]:``}}},cge=y.forwardRef(function(e,n){let{checked:r,className:i,defaultChecked:a,"aria-labelledby":o,form:s,id:c,inputRef:l,name:u,nativeButton:d=!1,onCheckedChange:f,readOnly:p=!1,required:m=!1,disabled:h=!1,render:g,uncheckedValue:_,value:v,style:b,...x}=e,{clearErrors:S}=db(),{state:C,setTouched:w,setDirty:T,validityData:E,setFilled:D,setFocused:O,shouldValidateOnChange:k,validationMode:A,disabled:j,name:M,validation:N}=ub(),{labelId:P}=fb(),F=j||h,I=M??u,L=Sa(f),R=y.useRef(null),z=fa(R,l,N.inputRef),ee=y.useRef(null),B=vd(),V=mb({id:c,implicit:!1,controlRef:ee}),H=d?void 0:V,[U,te]=Hg({controlled:r,default:!!a,name:`Switch`,state:`checked`});pb(ee,{id:B,value:U}),Nr(()=>{R.current&&D(R.current.checked)},[R,D]),fg(U,()=>{S(I),T(U!==E.initialValue),D(U),k()?N.commit(U):N.commit(U,!0)});let{getButtonProps:W,buttonRef:ne}=vh({disabled:F,native:d}),re=P9(o,P,R,!d,H),ie={id:d?V:B,role:`switch`,"aria-checked":U,"aria-readonly":p||void 0,"aria-required":m||void 0,"aria-labelledby":re,onFocus(){F||O(!0)},onBlur(){let e=R.current;!e||F||(w(!0),O(!1),A===`onBlur`&&N.commit(e.checked))},onClick(e){p||F||(e.preventDefault(),R.current?.dispatchEvent(new PointerEvent(`click`,{bubbles:!0,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey})))}},ae=y.useMemo(()=>Ls({checked:U,disabled:F,form:s,id:H,name:I,required:m,style:I?Ma:ja,tabIndex:-1,type:`checkbox`,"aria-hidden":!0,ref:z,onChange(e){if(e.nativeEvent.defaultPrevented)return;if(p){e.preventDefault();return}let n=e.currentTarget.checked,r=Fi(bi,e.nativeEvent);L?.(n,r),!r.isCanceled&&te(n)},onFocus(){ee.current?.focus()}},N.getInputValidationProps,v===void 0?mi:{value:v}),[U,F,s,z,H,I,L,p,m,te,N,v]),oe=y.useMemo(()=>({...C,checked:U,disabled:F,readOnly:p,required:m}),[C,U,F,p,m]),se=Zs(`span`,e,{state:oe,ref:[n,ee,ne],props:[ie,N.getValidationProps,x,W],stateAttributesMapping:Z9});return(0,K.jsxs)(Y9.Provider,{value:oe,children:[se,!U&&I&&_!==void 0&&(0,K.jsx)(`input`,{type:`hidden`,form:s,name:I,value:_}),(0,K.jsx)(`input`,{...ae,suppressHydrationWarning:!0})]})}),lge=y.forwardRef(function(e,n){let{render:r,className:i,style:a,...o}=e,{state:s}=ub(),c=sge();return Zs(`span`,e,{state:{...s,...c},ref:n,stateAttributesMapping:Z9,props:o})});function uge({className:e,size:n=`default`,...r}){return(0,K.jsx)(cge,{"data-slot":`switch`,"data-size":n,className:wp(`peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent transition-all outline-none after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-[size=default]:h-[18.4px] data-[size=default]:w-[32px] data-[size=sm]:h-[14px] data-[size=sm]:w-[24px] dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:bg-primary data-unchecked:bg-input dark:data-unchecked:bg-input/80 data-disabled:cursor-not-allowed data-disabled:opacity-50`,e),...r,children:(0,K.jsx)(lge,{"data-slot":`switch-thumb`,className:`pointer-events-none block rounded-full bg-background ring-0 transition-transform group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 group-data-[size=default]/switch:data-checked:translate-x-[calc(100%-2px)] group-data-[size=sm]/switch:data-checked:translate-x-[calc(100%-2px)] dark:data-checked:bg-primary-foreground group-data-[size=default]/switch:data-unchecked:translate-x-0 group-data-[size=sm]/switch:data-unchecked:translate-x-0 dark:data-unchecked:bg-foreground`})})}var Q9={list(){return ib.get(`/v1/categories`)},get(e){return ib.get(`/v1/categories/${encodeURIComponent(e)}`)},create(e){return ib.post(`/v1/categories`,e)},update(e,n){return ib.put(`/v1/categories/${encodeURIComponent(e)}`,n)},delete(e){return ib.delete(`/v1/categories/${encodeURIComponent(e)}`)},listAliases(){return ib.get(`/v1/categories/aliases`)},createAlias(e,n){return ib.post(`/v1/categories/aliases`,{alias:e,target:n})},deleteAlias(e){return ib.delete(`/v1/categories/aliases/${encodeURIComponent(e)}`)}},$9={name:``,display_name:``,description:``,decision_rule:``,always_merge:!1,append_only:!1,temporal_versioned:!1,merge_supported:!1,admission_weight:.5,importance_base:.5,prompt_format:``,default_visibility:`global`,default_scope:`global`,default_ttl_days:0,sort_order:100,is_active:!0};function dge(){let[e,n]=(0,y.useState)([]),[r,i]=(0,y.useState)([]),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)($9),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)(``),[S,C]=(0,y.useState)(null),w=(0,y.useCallback)(async()=>{try{let e=await Q9.list();n(Array.isArray(e)?e:[])}catch{G.error(`加载分类失败`)}},[]),T=(0,y.useCallback)(async()=>{try{let e=await Q9.listAliases();i(Array.isArray(e)?e:[])}catch{G.error(`加载别名失败`)}},[]);(0,y.useEffect)(()=>{Promise.all([w(),T()]).finally(()=>o(!1))},[w,T]);let E=()=>{c(null),f($9),u(!0)},D=e=>{c(e),f({name:e.name,display_name:e.display_name,description:e.description,decision_rule:e.decision_rule||``,always_merge:e.always_merge,append_only:e.append_only,temporal_versioned:e.temporal_versioned,merge_supported:e.merge_supported,admission_weight:e.admission_weight,importance_base:e.importance_base,prompt_format:e.prompt_format||``,default_visibility:e.default_visibility,default_scope:e.default_scope,default_ttl_days:e.default_ttl_days||0,sort_order:e.sort_order,is_active:e.is_active}),u(!0)};return a?(0,K.jsx)(`div`,{className:`flex items-center justify-center h-64 text-muted-foreground`,children:`加载中...`}):(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-bold`,children:`分类字典`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`管理记忆分类和别名映射`})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(J,{variant:`outline`,onClick:()=>g(!0),children:[(0,K.jsx)(Cm,{className:`size-4 mr-1`}),`添加别名`]}),(0,K.jsxs)(J,{onClick:E,children:[(0,K.jsx)(Lm,{className:`size-4 mr-1`}),`新建分类`]})]})]}),(0,K.jsx)(m7,{}),r.length>0&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold flex items-center gap-2`,children:[(0,K.jsx)(Cm,{className:`size-4`}),`别名映射 (`,r.length,`)`]}),(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3`,children:r.map(e=>(0,K.jsxs)(bb,{className:`p-3 flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(`code`,{className:`bg-muted px-1.5 py-0.5 rounded text-xs`,children:e.alias}),(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`→`}),(0,K.jsx)(`code`,{className:`bg-muted px-1.5 py-0.5 rounded text-xs`,children:e.target})]}),(0,K.jsx)(J,{variant:`ghost`,size:`icon`,className:`size-7 text-destructive hover:text-destructive`,onClick:()=>C(e.alias),children:(0,K.jsx)(rh,{className:`size-3.5`})})]},e.alias))}),(0,K.jsx)(m7,{})]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold flex items-center gap-2`,children:[(0,K.jsx)(Jm,{className:`size-4`}),`分类列表 (`,e.length,`)`]}),(0,K.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{className:`bg-muted/50`,children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`text-left p-3 font-medium`,children:`名称`}),(0,K.jsx)(`th`,{className:`text-left p-3 font-medium`,children:`显示名`}),(0,K.jsx)(`th`,{className:`text-left p-3 font-medium hidden md:table-cell`,children:`描述`}),(0,K.jsx)(`th`,{className:`text-center p-3 font-medium`,children:`权重`}),(0,K.jsx)(`th`,{className:`text-center p-3 font-medium`,children:`状态`}),(0,K.jsx)(`th`,{className:`text-right p-3 font-medium`,children:`操作`})]})}),(0,K.jsx)(`tbody`,{className:`divide-y`,children:e.map(e=>(0,K.jsxs)(`tr`,{className:`hover:bg-muted/30`,children:[(0,K.jsx)(`td`,{className:`p-3`,children:(0,K.jsx)(`code`,{className:`bg-muted px-1.5 py-0.5 rounded text-xs`,children:e.name})}),(0,K.jsx)(`td`,{className:`p-3 font-medium`,children:e.display_name}),(0,K.jsx)(`td`,{className:`p-3 text-muted-foreground hidden md:table-cell max-w-[200px] truncate`,children:e.description}),(0,K.jsx)(`td`,{className:`p-3 text-center`,children:(0,K.jsx)(`span`,{className:`text-xs`,children:e.admission_weight.toFixed(2)})}),(0,K.jsx)(`td`,{className:`p-3 text-center`,children:(0,K.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full ${e.is_active?`bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400`:`bg-gray-100 text-gray-500 dark:bg-gray-800 dark:text-gray-400`}`,children:e.is_active?`启用`:`禁用`})}),(0,K.jsx)(`td`,{className:`p-3 text-right`,children:(0,K.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,K.jsx)(J,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:()=>D(e),children:(0,K.jsx)(Fm,{className:`size-3.5`})}),(0,K.jsx)(J,{variant:`ghost`,size:`icon`,className:`size-7 text-destructive hover:text-destructive`,onClick:()=>m(e.name),children:(0,K.jsx)(Xm,{className:`size-3.5`})})]})})]},e.name))})]})})]}),(0,K.jsx)(g9,{open:l,onOpenChange:u,children:(0,K.jsxs)(_9,{className:`max-w-lg max-h-[80vh] overflow-y-auto`,children:[(0,K.jsx)(v9,{children:(0,K.jsx)(b9,{children:s?`编辑分类`:`新建分类`})}),(0,K.jsxs)(`div`,{className:`space-y-4 py-2`,children:[!s&&(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`名称 (name)`}),(0,K.jsx)(hb,{value:d.name,onChange:e=>f(n=>({...n,name:e.target.value.toLowerCase()})),placeholder:`e.g. preferences`,maxLength:50})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`显示名 (display_name)`}),(0,K.jsx)(hb,{value:d.display_name,onChange:e=>f(n=>({...n,display_name:e.target.value})),placeholder:`e.g. 偏好设置`,maxLength:100})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`描述`}),(0,K.jsx)(hb,{value:d.description,onChange:e=>f(n=>({...n,description:e.target.value})),placeholder:`分类描述`,maxLength:500})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`决策规则 (decision_rule)`}),(0,K.jsx)(hb,{value:d.decision_rule,onChange:e=>f(n=>({...n,decision_rule:e.target.value})),placeholder:`可选`,maxLength:200})]}),(0,K.jsx)(m7,{}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`准入权重`}),(0,K.jsx)(hb,{type:`number`,step:.05,min:0,max:1,value:d.admission_weight,onChange:e=>f(n=>({...n,admission_weight:+e.target.value}))})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`重要性基数`}),(0,K.jsx)(hb,{type:`number`,step:.05,min:0,max:1,value:d.importance_base,onChange:e=>f(n=>({...n,importance_base:+e.target.value}))})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`排序`}),(0,K.jsx)(hb,{type:`number`,value:d.sort_order,onChange:e=>f(n=>({...n,sort_order:+e.target.value}))})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`默认TTL (天)`}),(0,K.jsx)(hb,{type:`number`,value:d.default_ttl_days,onChange:e=>f(n=>({...n,default_ttl_days:+e.target.value}))})]})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`提示格式 (prompt_format)`}),(0,K.jsx)(hb,{value:d.prompt_format,onChange:e=>f(n=>({...n,prompt_format:e.target.value})),placeholder:`可选`,maxLength:500})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`默认可见性`}),(0,K.jsxs)(`select`,{className:`w-full h-9 rounded-md border border-input bg-background px-3 text-sm`,value:d.default_visibility,onChange:e=>f(n=>({...n,default_visibility:e.target.value})),children:[(0,K.jsx)(`option`,{value:`global`,children:`global`}),(0,K.jsx)(`option`,{value:`project`,children:`project`}),(0,K.jsx)(`option`,{value:`private`,children:`private`})]})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`默认作用域`}),(0,K.jsxs)(`select`,{className:`w-full h-9 rounded-md border border-input bg-background px-3 text-sm`,value:d.default_scope,onChange:e=>f(n=>({...n,default_scope:e.target.value})),children:[(0,K.jsx)(`option`,{value:`global`,children:`global`}),(0,K.jsx)(`option`,{value:`project`,children:`project`})]})]})]}),(0,K.jsx)(m7,{}),(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-3`,children:[[`always_merge`,`始终合并`],[`append_only`,`仅追加`],[`temporal_versioned`,`时序版本`],[`merge_supported`,`支持合并`],[`is_active`,`启用`]].map(([e,n])=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border p-3`,children:[(0,K.jsx)(gb,{className:`text-sm`,children:n}),(0,K.jsx)(uge,{checked:d[e],onCheckedChange:n=>f(r=>({...r,[e]:n}))})]},e))})]}),(0,K.jsxs)(y9,{children:[(0,K.jsx)(J,{variant:`outline`,onClick:()=>u(!1),children:`取消`}),(0,K.jsx)(J,{onClick:async()=>{if(!d.name.trim()||!d.display_name.trim()){G.error(`名称和显示名为必填项`);return}try{let e={...d,decision_rule:d.decision_rule||null,prompt_format:d.prompt_format||null,default_ttl_days:d.default_ttl_days||null};s?(await Q9.update(s.name,e),G.success(`分类已更新`)):(await Q9.create(e),G.success(`分类已创建`)),u(!1),w()}catch(e){let n=e instanceof Error?e.message:`操作失败`;G.error(n)}},children:s?`保存`:`创建`})]})]})}),(0,K.jsx)(aJ,{open:!!p,onOpenChange:()=>m(null),children:(0,K.jsxs)(oJ,{children:[(0,K.jsxs)(sJ,{children:[(0,K.jsx)(lJ,{children:`确认删除分类`}),(0,K.jsxs)(uJ,{children:[`确定要删除分类 "`,p,`" 吗?此操作不可撤销。`]})]}),(0,K.jsxs)(cJ,{children:[(0,K.jsx)(fJ,{children:`取消`}),(0,K.jsx)(dJ,{onClick:async()=>{if(p)try{await Q9.delete(p),G.success(`分类已删除`),m(null),w()}catch{G.error(`删除失败`)}},children:`删除`})]})]})}),(0,K.jsx)(g9,{open:h,onOpenChange:g,children:(0,K.jsxs)(_9,{className:`max-w-sm`,children:[(0,K.jsx)(v9,{children:(0,K.jsx)(b9,{children:`添加别名`})}),(0,K.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`别名`}),(0,K.jsx)(hb,{value:_,onChange:e=>v(e.target.value),placeholder:`e.g. likes`,maxLength:50})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`目标分类`}),(0,K.jsxs)(`select`,{className:`w-full h-9 rounded-md border border-input bg-background px-3 text-sm`,value:b,onChange:e=>x(e.target.value),children:[(0,K.jsx)(`option`,{value:``,children:`选择分类...`}),e.map(e=>(0,K.jsxs)(`option`,{value:e.name,children:[e.display_name,` (`,e.name,`)`]},e.name))]})]})]}),(0,K.jsxs)(y9,{children:[(0,K.jsx)(J,{variant:`outline`,onClick:()=>g(!1),children:`取消`}),(0,K.jsx)(J,{onClick:async()=>{if(!_.trim()||!b.trim()){G.error(`别名和目标分类为必填项`);return}try{await Q9.createAlias(_,b),G.success(`别名已创建`),g(!1),v(``),x(``),T()}catch(e){let n=e instanceof Error?e.message:`创建别名失败`;G.error(n)}},children:`创建`})]})]})}),(0,K.jsx)(aJ,{open:!!S,onOpenChange:()=>C(null),children:(0,K.jsxs)(oJ,{children:[(0,K.jsxs)(sJ,{children:[(0,K.jsx)(lJ,{children:`确认删除别名`}),(0,K.jsxs)(uJ,{children:[`确定要删除别名 "`,S,`" 吗?`]})]}),(0,K.jsxs)(cJ,{children:[(0,K.jsx)(fJ,{children:`取消`}),(0,K.jsx)(dJ,{onClick:async()=>{if(S)try{await Q9.deleteAlias(S),G.success(`别名已删除`),C(null),T()}catch{G.error(`删除别名失败`)}},children:`删除`})]})]})})]})}function fge(){let e=et();return(0,K.jsx)(`div`,{className:`flex h-screen w-full flex-col items-center justify-center bg-background text-foreground`,children:(0,K.jsxs)(`div`,{className:`text-center space-y-6`,children:[(0,K.jsx)(`div`,{className:`text-8xl font-bold text-muted-foreground/30`,children:`404`}),(0,K.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`页面不存在`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground max-w-sm`,children:`您访问的页面可能已经删除、移动,或者从未存在过。`}),(0,K.jsxs)(`div`,{className:`flex items-center justify-center gap-3`,children:[(0,K.jsxs)(J,{variant:`outline`,onClick:()=>e(-1),children:[(0,K.jsx)(Bp,{className:`h-4 w-4 mr-2`}),`返回上一页`]}),(0,K.jsxs)(J,{onClick:()=>e(`/dashboard`),children:[(0,K.jsx)(hm,{className:`h-4 w-4 mr-2`}),`返回首页`]})]})]})})}var pge=class extends y.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){console.error(`ErrorBoundary caught an error:`,e,n)}handleRefresh=()=>{window.location.reload()};handleGoHome=()=>{window.location.href=`/`};render(){return this.state.hasError?(0,K.jsx)(`div`,{className:`flex h-screen w-full flex-col items-center justify-center bg-background text-foreground`,children:(0,K.jsxs)(`div`,{className:`text-center space-y-6 max-w-md px-4`,children:[(0,K.jsx)(`div`,{className:`text-6xl font-bold text-destructive/30`,children:`⚠️`}),(0,K.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`出错了`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`应用遇到了意外错误。请尝试刷新页面,或返回首页。`}),this.state.error&&(0,K.jsx)(`div`,{className:`rounded-lg bg-muted p-4 text-left`,children:(0,K.jsx)(`p`,{className:`text-xs font-mono text-muted-foreground break-all`,children:this.state.error.message})}),(0,K.jsxs)(`div`,{className:`flex items-center justify-center gap-3`,children:[(0,K.jsxs)(J,{variant:`outline`,onClick:this.handleRefresh,children:[(0,K.jsx)(Rm,{className:`h-4 w-4 mr-2`}),`刷新页面`]}),(0,K.jsxs)(J,{onClick:this.handleGoHome,children:[(0,K.jsx)(hm,{className:`h-4 w-4 mr-2`}),`返回首页`]})]})]})}):this.props.children}};function mge({children:e}){let n=hh(e=>e.isAuthenticated),r=typeof window<`u`&&window.localStorage.getItem(`e2e_bypass_auth`)===`true`;return n||r?e:(0,K.jsx)(Ot,{to:`/login`,replace:!0})}function hge(){return(0,K.jsx)(pge,{children:(0,K.jsxs)(Mt,{children:[(0,K.jsx)(At,{path:`/login`,element:(0,K.jsx)(yb,{})}),(0,K.jsxs)(At,{path:`/*`,element:(0,K.jsx)(mge,{children:(0,K.jsx)(Hee,{})}),children:[(0,K.jsx)(At,{index:!0,element:(0,K.jsx)(Ot,{to:`/dashboard`,replace:!0})}),(0,K.jsx)(At,{path:`dashboard`,element:(0,K.jsx)(iJ,{})}),(0,K.jsx)(At,{path:`memories`,element:(0,K.jsx)(jJ,{})}),(0,K.jsx)(At,{path:`memories/:id`,element:(0,K.jsx)(Lme,{})}),(0,K.jsx)(At,{path:`memories/new`,element:(0,K.jsx)(f9,{})}),(0,K.jsx)(At,{path:`memories/:id/edit`,element:(0,K.jsx)(f9,{})}),(0,K.jsx)(At,{path:`memories/:id/edit-insight`,element:(0,K.jsx)(Hme,{})}),(0,K.jsx)(At,{path:`vault`,element:(0,K.jsx)(Gme,{})}),(0,K.jsx)(At,{path:`spaces`,element:(0,K.jsx)(she,{})}),(0,K.jsx)(At,{path:`sessions`,element:(0,K.jsx)(qme,{})}),(0,K.jsx)(At,{path:`sessions/:id`,element:(0,K.jsx)(rhe,{})}),(0,K.jsx)(At,{path:`analytics`,element:(0,K.jsx)(che,{})}),(0,K.jsx)(At,{path:`tier-history`,element:(0,K.jsx)(uhe,{})}),(0,K.jsx)(At,{path:`clusters`,element:(0,K.jsx)(whe,{})}),(0,K.jsx)(At,{path:`clusters/list`,element:(0,K.jsx)(Nhe,{})}),(0,K.jsx)(At,{path:`clusters/:id`,element:(0,K.jsx)(Lhe,{})}),(0,K.jsx)(At,{path:`lifecycle`,element:(0,K.jsx)(Khe,{})}),(0,K.jsx)(At,{path:`import`,element:(0,K.jsx)(qhe,{})}),(0,K.jsx)(At,{path:`profile`,element:(0,K.jsx)(ige,{})}),(0,K.jsx)(At,{path:`settings`,element:(0,K.jsx)(Jhe,{})}),(0,K.jsx)(At,{path:`categories`,element:(0,K.jsx)(dge,{})}),(0,K.jsx)(At,{path:`*`,element:(0,K.jsx)(fge,{})})]})]})})}(0,x.createRoot)(document.getElementById(`root`)).render((0,K.jsx)(y.StrictMode,{children:(0,K.jsx)(Sn,{children:(0,K.jsx)(xr,{defaultTheme:`dark`,storageKey:`omem-theme`,children:(0,K.jsxs)(Ep,{children:[(0,K.jsx)(Ap,{children:(0,K.jsx)(hge,{})}),(0,K.jsx)(vr,{position:`top-right`,richColors:!0,closeButton:!0})]})})})}));
164
+ - `).trim()}function Yme(e){return new Date(e).toLocaleString(`zh-CN`,{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function Xme(e){return e?e.length<=16?e:e.slice(0,8)+`...`+e.slice(-8):`—`}function Zme(e,n=80){return e?e.length<=n?e:e.slice(0,n)+`...`:`—`}function Qme({type:e}){return e===`auto`?(0,K.jsxs)(hJ,{variant:`secondary`,className:`text-xs bg-blue-100 text-blue-700 hover:bg-blue-100 border-blue-200`,children:[(0,K.jsx)(ih,{className:`size-3 mr-1`}),`自动注入`]}):(0,K.jsxs)(hJ,{variant:`outline`,className:`text-xs bg-emerald-50 text-emerald-700 hover:bg-emerald-50 border-emerald-200`,children:[(0,K.jsx)(Mm,{className:`size-3 mr-1`}),`手动注入`]})}function $me({category:e}){return(0,K.jsx)(hJ,{variant:`outline`,className:`text-xs font-normal ${SJ(e)}`,children:e||`未分类`})}function h9({label:e,value:n,max:r=1}){let i=Math.max(0,Math.min(n,r))/r*100;return(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,K.jsx)(`span`,{className:`font-medium`,children:n===0?`—`:`${i.toFixed(1)}%`})]}),(0,K.jsx)(`div`,{className:`h-1.5 w-full rounded-full bg-muted overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full bg-primary transition-all`,style:{width:`${i}%`}})})]})}function ehe({relevance:e,isKept:n}){return n?e===`high`?(0,K.jsx)(hJ,{variant:`outline`,className:`text-xs bg-emerald-500/10 text-emerald-600 border-emerald-500/30`,children:`🟢 高相关`}):e===`medium`?(0,K.jsx)(hJ,{variant:`outline`,className:`text-xs bg-yellow-500/10 text-yellow-600 border-yellow-500/30`,children:`🟡 中相关`}):(0,K.jsx)(hJ,{variant:`outline`,className:`text-xs bg-muted text-muted-foreground border-border`,children:e||`—`}):(0,K.jsx)(hJ,{variant:`outline`,className:`text-xs bg-red-500/10 text-red-600 border-red-500/30`,children:`🔴 被精炼掉`})}function the({item:e,memory:n,memoryLoading:r,vaultUnlocked:i,memoryUnlocked:a,onUnlock:o,onLock:s,onVaultUnlock:c}){let[l,u]=(0,y.useState)(`refine`),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(null),_=ob(e=>e.unlock),v=ob(e=>e.isUnlocked),b=n?.visibility===`private`||(n?.tags||[]).some(e=>e===`私密`||e.toLowerCase()===`private`),x=b&&!a,S=async()=>{n&&(x?i||v?o?.(n.id):f(!0):(s?.(n.id),f(!1)))},C=async()=>{if(!p.trim()){g(`请输入密码`);return}await _(p)?(f(!1),m(``),g(null),c?.(),n&&o?.(n.id)):g(`密码错误`)};return(0,K.jsxs)(`div`,{className:`rounded-md border bg-muted/50 p-3 space-y-3 ${e.is_kept?`border-border`:`border-dashed border-red-500/30 opacity-75`}`,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,K.jsx)(ehe,{relevance:e.refine_relevance,isKept:e.is_kept}),(0,K.jsx)($me,{category:n?.category}),b&&(0,K.jsxs)(hJ,{variant:`secondary`,className:`text-xs bg-amber-100 text-amber-700 hover:bg-amber-100 border-amber-200`,children:[(0,K.jsx)(Em,{className:`size-3 mr-1`}),`私密`]}),(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground font-mono`,children:[e.memory_id?.slice(0,8),`...`]})]}),b&&(0,K.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),S()},className:`text-xs text-amber-500 hover:text-amber-600 flex items-center gap-1 shrink-0`,children:[x?(0,K.jsx)(Em,{className:`size-3`}):(0,K.jsx)(Tm,{className:`size-3`}),x?`解锁`:`锁定`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-border pb-1`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>u(`refine`),className:`text-xs px-2 py-1 rounded transition-colors ${l===`refine`?`bg-primary/10 text-primary font-medium`:`text-muted-foreground hover:text-foreground`}`,children:`精炼`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>u(`raw`),className:`text-xs px-2 py-1 rounded transition-colors ${l===`raw`?`bg-primary/10 text-primary font-medium`:`text-muted-foreground hover:text-foreground`}`,children:`原始`})]}),l===`refine`?(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`text-sm text-foreground`,children:[(0,K.jsx)(`span`,{className:`font-medium`,children:`推理说明:`}),(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:e.refine_reasoning||`—`})]}),(0,K.jsx)(h9,{label:`相似度得分`,value:e.score,max:1})]}):(0,K.jsx)(`div`,{className:`space-y-2`,children:r?(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(Tb,{className:`h-4 w-3/4`}),(0,K.jsx)(Tb,{className:`h-4 w-1/2`})]}):n?(0,K.jsx)(K.Fragment,{children:x?(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,K.jsx)(Em,{className:`size-4`}),(0,K.jsx)(`span`,{children:`私密记忆内容已隐藏`})]}),d&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(hb,{type:`password`,placeholder:`输入 Vault 密码...`,value:p,onChange:e=>{m(e.target.value),g(null)},onKeyDown:e=>e.key===`Enter`&&C(),className:h?`border-destructive flex-1`:`flex-1`}),(0,K.jsx)(J,{size:`sm`,onClick:C,children:`解锁`})]}),h&&(0,K.jsx)(`p`,{className:`text-xs text-destructive`,children:h})]})]}):(0,K.jsx)(`div`,{className:`prose prose-sm dark:prose-invert max-w-none`,children:(0,K.jsx)(p0,{remarkPlugins:[Y4],children:Jme(n.content||n.l0_abstract||`—`)})})}):(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`记忆内容加载失败`})})]})}function nhe({event:e,initialItems:n,isLast:r,defaultExpanded:i,vaultUnlocked:a,unlockedMemories:o,manuallyLocked:s,onUnlock:c,onLock:l,onVaultUnlock:u}){let[d,f]=(0,y.useState)(i||!1),[p,m]=(0,y.useState)(!0),[h,g]=(0,y.useState)(n??null),[_,v]=(0,y.useState)(new Map),[b,x]=(0,y.useState)(new Set);(0,y.useEffect)(()=>{n&&h===null&&g(n)},[n,h]);let S=(0,y.useCallback)(async e=>{if(!(_.has(e)||b.has(e)))try{x(n=>new Set(n).add(e));let n=await ib.get(`/v1/memories/${e}`);v(r=>{let i=new Map(r);return i.set(e,n),i})}catch(e){console.error(`Failed to fetch memory:`,e)}finally{x(n=>{let r=new Set(n);return r.delete(e),r})}},[_,b]);(0,y.useEffect)(()=>{!d||!h||h.length===0||h.forEach(e=>{!_.has(e.memory_id)&&!b.has(e.memory_id)&&S(e.memory_id)})},[d,h,_,b,S]);let C=e=>a&&!s.has(e)||o.has(e);return(0,K.jsxs)(`div`,{className:`flex gap-4`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col items-center`,children:[(0,K.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full bg-primary ring-4 ring-primary/20`}),!r&&(0,K.jsx)(`div`,{className:`w-px flex-1 bg-border mt-1`})]}),(0,K.jsx)(`div`,{className:`flex-1 pb-6`,children:(0,K.jsxs)(`div`,{className:`rounded-lg border border-border bg-card transition-colors hover:bg-muted/50`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>f(!d),className:`w-full text-left p-4 cursor-pointer`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,K.jsx)(Qme,{type:e.recall_type}),(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground flex items-center gap-1`,children:[(0,K.jsx)(nm,{className:`size-3`}),Yme(e.created_at)]})]}),d?(0,K.jsx)($p,{className:`size-4 text-muted-foreground`}):(0,K.jsx)(Xp,{className:`size-4 text-muted-foreground`})]}),(0,K.jsxs)(`div`,{className:`mt-2 text-sm text-muted-foreground flex items-center gap-1.5`,children:[(0,K.jsx)(Vm,{className:`size-3.5`}),(0,K.jsx)(`span`,{className:`line-clamp-1`,title:e.query_text||`—`,children:Zme(e.query_text)})]})]}),d&&(0,K.jsxs)(`div`,{className:`px-4 pb-4 space-y-4 border-t border-border pt-4`,children:[e.profile_content&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`h4`,{className:`text-xs font-medium text-muted-foreground flex items-center gap-1`,children:[(0,K.jsx)(Gp,{className:`size-3`}),`画像注入内容`]}),(0,K.jsx)(`div`,{className:`rounded-md border border-indigo-500/20 bg-indigo-500/5 p-3`,children:(0,K.jsx)(`div`,{className:`prose prose-sm dark:prose-invert max-w-none text-sm text-indigo-700 dark:text-indigo-300`,children:(0,K.jsx)(p0,{remarkPlugins:[Y4],children:e.profile_content.replace(/<\/?cerebro-profile>/g,``).trim()})})})]}),e.injected_content&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>m(!p),className:`flex items-center gap-1 text-xs font-medium text-muted-foreground hover:text-foreground transition-colors cursor-pointer`,children:[(0,K.jsx)(rm,{className:`size-3`}),`注入内容`,p?(0,K.jsx)($p,{className:`size-3`}):(0,K.jsx)(Xp,{className:`size-3`})]}),p&&(0,K.jsx)(`div`,{className:`rounded-md border border-emerald-500/20 bg-emerald-500/5 p-3 max-h-96 overflow-y-auto`,children:(0,K.jsx)(`div`,{className:`prose prose-sm dark:prose-invert max-w-none text-sm text-emerald-700 dark:text-emerald-300`,children:(0,K.jsx)(p0,{remarkPlugins:[Y4],children:e.injected_content.replace(/<\/?cerebro-context>/g,``).trim()})})})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,K.jsxs)(`h4`,{className:`text-xs font-medium text-muted-foreground flex items-center gap-1`,children:[(0,K.jsx)(Gp,{className:`size-3`}),`关联记忆`]})}),h&&h.length>0?(0,K.jsx)(`div`,{className:`space-y-3`,children:h.map(e=>(0,K.jsx)(the,{item:e,memory:_.get(e.memory_id)||null,memoryLoading:b.has(e.memory_id),vaultUnlocked:a,memoryUnlocked:C(e.memory_id),onUnlock:c,onLock:l,onVaultUnlock:u},e.id))}):(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`暂无召回项`})]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`h4`,{className:`text-xs font-medium text-muted-foreground flex items-center gap-1`,children:[(0,K.jsx)(Jp,{className:`size-3`}),`匹配指标`]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,K.jsx)(h9,{label:`最大相似度`,value:e.max_score}),(0,K.jsx)(h9,{label:`LLM 置信度`,value:e.llm_confidence})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground flex-wrap`,children:[(0,K.jsx)(`span`,{className:`font-medium text-foreground`,children:`统计:`}),(0,K.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:[`保留 `,e.kept_count,` 条`]}),(0,K.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,children:[`精炼掉 `,e.discarded_count,` 条`]}),e.injected_count!=null&&e.injected_count>0&&(0,K.jsxs)(`span`,{className:`text-blue-600 dark:text-blue-400`,children:[`实际注入 `,e.injected_count,` 条`]}),e.profile_injected&&(0,K.jsx)(`span`,{className:`text-indigo-600 dark:text-indigo-400`,children:`👤 画像已注入`})]})]})]})})]})}function rhe(){let{id:e}=it(),n=et(),r=Ze(),i=()=>{let e=r.state;e?.from?n(e.from,{replace:!0}):n(-1)},a=e?decodeURIComponent(e):``,[o,s]=(0,y.useState)([]),[c,l]=(0,y.useState)(new Map),[u,d]=(0,y.useState)(!0),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(1),[g,_]=(0,y.useState)(!1),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(``),[C,w]=(0,y.useState)(null),T=ob(e=>e.unlock),E=ob(e=>e.lock),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(new Set),[j,M]=(0,y.useState)(new Set),[N,P]=(0,y.useState)(null),F=Math.ceil(o.length/10),I=o.slice((m-1)*10,m*10);(0,y.useEffect)(()=>{if(!a)return;async function e(){try{d(!0),p(null);let e=await ib.get(`/v1/recall-events`,{params:{session_id:a,limit:1e4,offset:0,expand:`items`}});if(s((e?.events||[]).sort((e,n)=>new Date(n.created_at).getTime()-new Date(e.created_at).getTime())),e?.event_items){let n=new Map;e.event_items.forEach(e=>n.set(e.id,e.items||[])),l(n)}}catch(e){console.error(`Failed to fetch session detail:`,e),p(`加载 Session 详情失败`),G.error(`加载 Session 详情失败`)}finally{d(!1)}}e()},[a]);let L=()=>{_(!0)},R=async()=>{try{await ib.delete(`/v1/session-recalls/session/${a}`),G.success(`Session 记录已删除`),n(-1)}catch(e){console.error(`Failed to delete session records:`,e),G.error(`删除失败`)}finally{_(!1)}},z=async()=>{if(!x.trim()){w(`请输入密码`);return}if(!await T(x)){w(`密码错误`);return}O(!0),N&&(A(e=>new Set(e).add(N)),P(null)),w(null),b(!1),S(``)},ee=()=>{O(!1),A(new Set),M(new Set),E()},B=e=>{k.has(e)||D&&!j.has(e)?(M(n=>new Set(n).add(e)),A(n=>{let r=new Set(n);return r.delete(e),r})):D?M(n=>{let r=new Set(n);return r.delete(e),r}):(P(e),b(!0))},V={total:o.length,auto:o.filter(e=>e.recall_type===`auto`).length,manual:o.filter(e=>e.recall_type===`manual`).length,totalKept:o.reduce((e,n)=>e+n.kept_count,0),totalDiscarded:o.reduce((e,n)=>e+n.discarded_count,0)};return u?(0,K.jsxs)(`div`,{className:`space-y-6 max-w-3xl`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Tb,{className:`h-8 w-8`}),(0,K.jsx)(Tb,{className:`h-6 w-32`})]}),(0,K.jsx)(Tb,{className:`h-4 w-1/2`}),(0,K.jsx)(`div`,{className:`space-y-4`,children:[1,2,3].map(e=>(0,K.jsxs)(`div`,{className:`flex gap-4`,children:[(0,K.jsx)(Tb,{className:`h-3 w-3 rounded-full`}),(0,K.jsx)(`div`,{className:`flex-1 space-y-2`,children:(0,K.jsx)(Tb,{className:`h-20 w-full`})})]},e))})]}):f?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(J,{variant:`ghost`,size:`sm`,onClick:()=>i(),children:[(0,K.jsx)(Bp,{className:`size-4 mr-1.5`}),`返回`]}),(0,K.jsx)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-sm text-destructive`,children:f})]}):(0,K.jsxs)(`div`,{className:`space-y-6 max-w-3xl`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,K.jsxs)(J,{variant:`ghost`,size:`sm`,onClick:()=>i(),children:[(0,K.jsx)(Bp,{className:`size-4 mr-1.5`}),`返回`]})})}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:[`Session 详情 - `,Xme(a)]}),(0,K.jsx)(`div`,{className:`flex items-center gap-3 text-sm text-muted-foreground flex-wrap`,children:(0,K.jsx)(`code`,{className:`font-mono text-xs bg-muted px-1.5 py-0.5 rounded`,children:a})})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,K.jsx)(bb,{children:(0,K.jsxs)(wb,{className:`pt-4 text-center`,children:[(0,K.jsx)(`div`,{className:`text-2xl font-semibold`,children:V.total}),(0,K.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`总召回事件`})]})}),(0,K.jsx)(bb,{children:(0,K.jsxs)(wb,{className:`pt-4 text-center`,children:[(0,K.jsx)(`div`,{className:`text-2xl font-semibold`,children:V.auto}),(0,K.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`自动注入`})]})}),(0,K.jsx)(bb,{children:(0,K.jsxs)(wb,{className:`pt-4 text-center`,children:[(0,K.jsx)(`div`,{className:`text-2xl font-semibold`,children:V.manual}),(0,K.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`手动注入`})]})})]}),(V.totalKept>0||V.totalDiscarded>0)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[(0,K.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400 font-medium`,children:[`共保留 `,V.totalKept,` 条记忆`]}),(0,K.jsxs)(`span`,{className:`text-red-600 dark:text-red-400 font-medium`,children:[`共精炼掉 `,V.totalDiscarded,` 条记忆`]})]}),(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-2`,children:[(0,K.jsx)(`h2`,{className:`text-sm font-medium text-muted-foreground`,children:`召回事件时间线`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`共 `,o.length,` 个事件`]}),F>1&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>h(e=>Math.max(1,e-1)),disabled:m===1,children:(0,K.jsx)(Zp,{className:`size-3`})}),(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground min-w-[3ch] text-center`,children:[m,`/`,F]}),(0,K.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>h(e=>Math.min(F,e+1)),disabled:m===F,children:(0,K.jsx)(Qp,{className:`size-3`})})]}),D?(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:ee,children:[(0,K.jsx)(Em,{className:`size-3.5 mr-1`}),`锁定 Vault`]}):(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>b(!v),children:[(0,K.jsx)(Tm,{className:`size-3.5 mr-1`}),`解锁 Vault`]})]})]}),v&&(0,K.jsxs)(`div`,{className:`space-y-2 max-w-md`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(hb,{type:`password`,placeholder:`输入 Vault 密码...`,value:x,onChange:e=>{S(e.target.value),w(null)},onKeyDown:e=>e.key===`Enter`&&z(),className:C?`border-destructive flex-1`:`flex-1`}),(0,K.jsx)(J,{size:`sm`,onClick:z,children:`解锁`})]}),C&&(0,K.jsx)(`p`,{className:`text-xs text-destructive`,children:C})]}),o.length===0?(0,K.jsx)(`div`,{className:`rounded-lg border border-border bg-card p-8 text-center text-sm text-muted-foreground`,children:`暂无召回事件`}):(0,K.jsxs)(K.Fragment,{children:[I.map((e,n)=>(0,K.jsx)(nhe,{event:e,initialItems:c.get(e.id),isLast:n===I.length-1&&m===F,defaultExpanded:n===0&&m===1,vaultUnlocked:D,unlockedMemories:k,manuallyLocked:j,onUnlock:B,onLock:B,onVaultUnlock:()=>O(!0)},e.id)),F>1&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2 pt-4`,children:[(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`共 `,o.length,` 个事件`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(J,{variant:`outline`,size:`sm`,onClick:()=>h(e=>Math.max(1,e-1)),disabled:m===1,children:(0,K.jsx)(Zp,{className:`size-4`})}),(0,K.jsxs)(`span`,{className:`text-sm text-muted-foreground`,children:[m,` / `,F]}),(0,K.jsx)(J,{variant:`outline`,size:`sm`,onClick:()=>h(e=>Math.min(F,e+1)),disabled:m===F,children:(0,K.jsx)(Qp,{className:`size-4`})})]})]})]})]}),o.length>0&&(0,K.jsx)(`div`,{className:`pt-4 border-t border-border`,children:(0,K.jsxs)(J,{variant:`outline`,size:`sm`,className:`text-destructive hover:bg-destructive/10 hover:text-destructive`,onClick:L,children:[(0,K.jsx)(Xm,{className:`size-3.5 mr-1`}),`删除 Session 所有记录`]})}),(0,K.jsx)(aJ,{open:g,onOpenChange:e=>!e&&_(!1),children:(0,K.jsxs)(oJ,{children:[(0,K.jsxs)(sJ,{children:[(0,K.jsx)(lJ,{children:`确认删除 Session 记录`}),(0,K.jsx)(uJ,{children:`此操作将删除该 Session 的所有召回记录,不可撤销。确定要继续吗?`})]}),(0,K.jsxs)(cJ,{children:[(0,K.jsx)(fJ,{onClick:()=>_(!1),children:`取消`}),(0,K.jsx)(dJ,{onClick:R,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`删除`})]})]})})]})}function g9({...e}){return(0,K.jsx)(yg,{"data-slot":`dialog`,...e})}function ihe({...e}){return(0,K.jsx)(xg,{"data-slot":`dialog-trigger`,...e})}function ahe({...e}){return(0,K.jsx)(tg,{"data-slot":`dialog-portal`,...e})}function ohe({className:e,...n}){return(0,K.jsx)(Ah,{"data-slot":`dialog-overlay`,className:wp(`fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0`,e),...n})}function _9({className:e,children:n,showCloseButton:r=!0,...i}){return(0,K.jsxs)(ahe,{children:[(0,K.jsx)(ohe,{}),(0,K.jsxs)($h,{"data-slot":`dialog-content`,className:wp(`fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95`,e),...i,children:[n,r&&(0,K.jsxs)(jh,{"data-slot":`dialog-close`,render:(0,K.jsx)(J,{variant:`ghost`,className:`absolute top-2 right-2`,size:`icon-sm`}),children:[(0,K.jsx)(rh,{}),(0,K.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function v9({className:e,...n}){return(0,K.jsx)(`div`,{"data-slot":`dialog-header`,className:wp(`flex flex-col gap-2`,e),...n})}function y9({className:e,showCloseButton:n=!1,children:r,...i}){return(0,K.jsxs)(`div`,{"data-slot":`dialog-footer`,className:wp(`-mx-4 -mb-4 flex flex-col-reverse gap-2 rounded-b-xl border-t bg-muted/50 p-4 sm:flex-row sm:justify-end`,e),...i,children:[r,n&&(0,K.jsx)(jh,{render:(0,K.jsx)(J,{variant:`outline`}),children:`Close`})]})}function b9({className:e,...n}){return(0,K.jsx)(bg,{"data-slot":`dialog-title`,className:wp(`text-base leading-none font-medium`,e),...n})}function x9({className:e,...n}){return(0,K.jsx)(Mh,{"data-slot":`dialog-description`,className:wp(`text-sm text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground`,e),...n})}function she(){let[e,n]=(0,y.useState)([]),[r,i]=(0,y.useState)(!0),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`team`),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(`member`),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)({}),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(`member`),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(null),[I,L]=(0,y.useState)(!1),R=hh(e=>e.currentUserId),z=hh(e=>e.users.find(e=>e.id===R)),ee=e.find(e=>e.id===p),B=e=>z?e.owner_id===z.apiKey||e.members.some(e=>e.user_id===z.apiKey&&(e.role===`admin`||e.role===`Admin`)):!1;(0,y.useEffect)(()=>{async function e(){if(!ee?.members?.length)return;T(!0);let e={};await Promise.all(ee.members.map(async n=>{try{let r=await ib.get(`/v1/tenants/${encodeURIComponent(n.user_id)}`);r&&(e[n.user_id]={name:r.name,created_at:r.created_at})}catch{}})),C(e),T(!1)}p&&e()},[p,ee?.members]),(0,y.useEffect)(()=>{async function e(){try{i(!0),n(await ib.get(`/v1/spaces`)||[])}catch(e){console.error(`Failed to fetch spaces:`,e),G.error(`加载空间列表失败`)}finally{i(!1)}}e()},[]);async function V(){if(!s.trim()){G.error(`请输入空间名称`);return}try{await ib.post(`/v1/spaces`,{name:s.trim(),space_type:l}),G.success(`空间创建成功`),o(!1),c(``),n(await ib.get(`/v1/spaces`)||[])}catch(e){console.error(`Failed to create space:`,e),G.error(`空间创建失败`)}}async function H(){if(!d)return;let r=e.find(e=>e.id===d)?.members.map(e=>e.user_id).filter(e=>e!==z?.apiKey)||[];try{await ib.delete(`/v1/spaces/${encodeURIComponent(d)}`),G.success(`空间已删除`),n(e=>e.filter(e=>e.id!==d)),hh.getState().removeUsersByApiKeys(r)}catch(e){console.error(`Failed to delete space:`,e),G.error(`空间删除失败`)}finally{f(null)}}async function U(){if(p){N(!0);try{let e=await ib.post(`/v1/tenants`,{name:O.trim()||void 0}),r=e.id,i=e.api_key;await ib.post(`/v1/spaces/${encodeURIComponent(p)}/members`,{user_id:r,role:A}),F(i),G.success(`新用户创建并加入空间成功`),n(await ib.get(`/v1/spaces`)||[])}catch(e){console.error(`Failed to create user:`,e);let n=e.response?.data?.error||e.message||``;G.error(`创建用户失败:${n||`请稍后重试`}`)}finally{N(!1)}}}async function te(e){if(p)try{await ib.delete(`/v1/spaces/${encodeURIComponent(p)}/members/${encodeURIComponent(e)}`),G.success(`成员已移除`),n(await ib.get(`/v1/spaces`)||[])}catch(e){console.error(`Failed to remove member:`,e);let n=e.response?.data?.error||e.message||``;G.error(`移除成员失败:${n||`请稍后重试`}`)}}async function W(){if(!p||!h.trim()){G.error(`请输入用户ID`);return}let e=h.trim();if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)){G.error(`用户ID格式不正确,请输入有效的 UUID(如:c60beb98-7aab-4985-8c1d-29ffd6aff75a)`);return}x(!0);try{await ib.post(`/v1/spaces/${encodeURIComponent(p)}/members`,{user_id:e,role:_}),G.success(`成员添加成功`),g(``),n(await ib.get(`/v1/spaces`)||[])}catch(e){console.error(`Failed to add member:`,e);let n=e.response?.data?.error||e.message||``;n.includes(`not found`)||n.includes(`不存在`)?G.error(`该用户不存在,请确认用户ID正确`):n.includes(`permission`)||n.includes(`权限`)?G.error(`您没有权限添加成员`):G.error(`添加成员失败:${n||`请检查用户ID是否正确`}`)}finally{x(!1)}}return r?(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`空间管理`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`管理您的记忆空间`})]}),(0,K.jsx)(Tb,{className:`h-9 w-24`})]}),(0,K.jsx)(`div`,{className:`grid gap-4`,children:[1,2].map(e=>(0,K.jsx)(Tb,{className:`h-32 w-full`},e))})]}):(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`空间管理`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`管理您的记忆空间`})]}),(0,K.jsxs)(g9,{open:a,onOpenChange:o,children:[(0,K.jsx)(ihe,{render:(0,K.jsxs)(J,{size:`sm`,children:[(0,K.jsx)(Lm,{className:`size-4 mr-1.5`}),`新建空间`]})}),(0,K.jsxs)(_9,{children:[(0,K.jsx)(v9,{children:(0,K.jsx)(b9,{children:`新建空间`})}),(0,K.jsxs)(`div`,{className:`space-y-4 pt-2`,children:[(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium`,children:`空间名称`}),(0,K.jsx)(hb,{placeholder:`输入空间名称`,value:s,onChange:e=>c(e.target.value)})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium`,children:`空间类型`}),(0,K.jsxs)(r9,{value:l,onValueChange:e=>u(e||`team`),children:[(0,K.jsx)(a9,{children:(0,K.jsx)(i9,{})}),(0,K.jsxs)(o9,{children:[(0,K.jsx)(s9,{value:`team`,children:`团队`}),(0,K.jsx)(s9,{value:`personal`,children:`个人`}),(0,K.jsx)(s9,{value:`shared`,children:`共享`})]})]})]}),(0,K.jsx)(J,{className:`w-full`,onClick:V,children:`创建`})]})]})]})]}),e.length===0?(0,K.jsxs)(`div`,{className:`text-center py-12 text-muted-foreground border border-dashed border-border rounded-lg`,children:[(0,K.jsx)(`p`,{children:`暂无空间`}),(0,K.jsx)(`p`,{className:`text-sm mt-1`,children:`点击右上角按钮创建新空间`})]}):(0,K.jsx)(`div`,{className:`grid gap-4`,children:e.map(e=>(0,K.jsxs)(bb,{className:`group transition-colors hover:bg-accent/50`,children:[(0,K.jsx)(xb,{className:`pb-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold`,children:e.name}),(0,K.jsx)(hJ,{variant:`outline`,children:e.space_type})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,K.jsx)(Um,{className:`size-3`}),e.members.length,` 成员`]}),(0,K.jsxs)(J,{variant:`ghost`,size:`sm`,className:`h-7 opacity-0 group-hover:opacity-100 transition-opacity`,onClick:()=>{m(e.id),g(``),v(`member`)},children:[(0,K.jsx)(eh,{className:`size-3.5 mr-1`}),`管理成员`]}),e.space_type!==`personal`&&B(e)&&(0,K.jsx)(J,{variant:`ghost`,size:`icon`,className:`size-7 opacity-0 group-hover:opacity-100 transition-opacity`,onClick:()=>f(e.id),children:(0,K.jsx)(Xm,{className:`size-3.5 text-destructive`})})]})]})}),(0,K.jsxs)(wb,{className:`pt-0 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm text-muted-foreground flex-wrap`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(nh,{className:`size-3.5`}),e.members.map(e=>e.role).join(`, `)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(qp,{className:`size-3.5`}),new Date(e.created_at).toLocaleDateString(`zh-CN`)]})]}),(0,K.jsxs)(`p`,{className:`text-xs text-muted-foreground font-mono`,children:[`ID: `,e.id]})]})]},e.id))}),(0,K.jsx)(aJ,{open:!!d,onOpenChange:e=>!e&&f(null),children:(0,K.jsxs)(oJ,{children:[(0,K.jsxs)(sJ,{children:[(0,K.jsx)(lJ,{children:`确认删除空间`}),(0,K.jsx)(uJ,{children:`此操作不可撤销。空间内的数据不会被删除,但空间配置将被移除。`})]}),(0,K.jsxs)(cJ,{children:[(0,K.jsx)(fJ,{onClick:()=>f(null),children:`取消`}),(0,K.jsx)(dJ,{onClick:H,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`删除`})]})]})}),(0,K.jsx)(g9,{open:!!p,onOpenChange:e=>!e&&m(null),children:(0,K.jsxs)(_9,{style:{width:680,maxWidth:`95vw`},children:[(0,K.jsx)(v9,{children:(0,K.jsxs)(b9,{children:[`管理成员 - `,ee?.name]})}),(0,K.jsxs)(`div`,{className:`space-y-4 pt-2`,children:[(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium`,children:`当前成员`}),w&&(0,K.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`加载用户信息中...`}),(0,K.jsxs)(`div`,{className:`space-y-1`,children:[ee?.members.map(e=>{let n=S[e.user_id];return(0,K.jsxs)(`div`,{className:`grid grid-cols-[auto_1fr_80px_60px] items-center gap-3 text-sm border rounded-md px-3 py-2`,children:[(0,K.jsx)(th,{className:`size-3.5 text-muted-foreground`}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`div`,{className:`font-mono text-xs truncate`,title:e.user_id,children:e.user_id}),n&&(0,K.jsxs)(`div`,{className:`text-xs text-muted-foreground truncate`,children:[n.name,` · `,new Date(n.created_at).toLocaleDateString(`zh-CN`)]})]}),(0,K.jsx)(hJ,{variant:`outline`,className:`justify-self-center`,children:e.role}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 justify-self-end`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>{navigator.clipboard.writeText(e.user_id),G.success(`API Key 已复制`)},className:`text-muted-foreground hover:text-foreground transition-colors`,title:`复制 API Key`,children:(0,K.jsx)(im,{className:`size-3.5`})}),ee&&B(ee)&&e.user_id!==z?.apiKey&&e.user_id!==ee?.owner_id&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>te(e.user_id),className:`text-muted-foreground hover:text-destructive transition-colors`,title:`移除成员`,children:(0,K.jsx)(Xm,{className:`size-3.5`})})]})]},e.user_id)}),(!ee?.members||ee.members.length===0)&&(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`暂无成员`})]})]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium`,children:`添加成员`}),(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>{D(!0),F(null),k(``),j(`member`)},children:[(0,K.jsx)(nee,{className:`size-3.5 mr-1.5`}),`创建新用户`]})]}),E&&(0,K.jsxs)(`div`,{className:`rounded-lg border border-border bg-muted/30 p-3 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium`,children:`创建新用户`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>{D(!1),F(null)},className:`text-xs text-muted-foreground hover:text-foreground`,children:`取消`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(hb,{placeholder:`用户名(可选)`,value:O,onChange:e=>k(e.target.value),className:`flex-1`}),(0,K.jsxs)(r9,{value:A,onValueChange:e=>j(e||`member`),children:[(0,K.jsx)(a9,{className:`w-28`,children:(0,K.jsx)(i9,{})}),(0,K.jsxs)(o9,{children:[(0,K.jsx)(s9,{value:`admin`,children:`管理员`}),(0,K.jsx)(s9,{value:`member`,children:`成员`}),(0,K.jsx)(s9,{value:`reader`,children:`只读`})]})]})]}),(0,K.jsx)(J,{size:`sm`,className:`w-full`,onClick:U,disabled:M,children:M?`生成中...`:`生成用户并添加到空间`}),P&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`新用户 API Key(请复制保存):`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`code`,{className:`flex-1 text-xs bg-background border rounded px-2 py-1.5 font-mono truncate`,children:P}),(0,K.jsx)(J,{size:`sm`,variant:`outline`,onClick:()=>{navigator.clipboard.writeText(P),L(!0),setTimeout(()=>L(!1),2e3)},children:I?(0,K.jsx)(Yp,{className:`size-3.5`}):(0,K.jsx)(im,{className:`size-3.5`})})]})]})]}),!E&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(hb,{placeholder:`输入对方 API Key(UUID格式)`,value:h,onChange:e=>g(e.target.value),className:`flex-1`}),(0,K.jsxs)(r9,{value:_,onValueChange:e=>v(e||`member`),children:[(0,K.jsx)(a9,{className:`w-28`,children:(0,K.jsx)(i9,{})}),(0,K.jsxs)(o9,{children:[(0,K.jsx)(s9,{value:`admin`,children:`管理员`}),(0,K.jsx)(s9,{value:`member`,children:`成员`}),(0,K.jsx)(s9,{value:`reader`,children:`只读`})]})]}),(0,K.jsx)(J,{size:`sm`,onClick:W,disabled:b,children:b?`添加中...`:`添加`})]})]})]})]})})]})}var S9=[`#8b5cf6`,`#ec4899`,`#06b6d4`,`#f59e0b`,`#10b981`,`#ef4444`,`#6366f1`,`#f97316`];function C9(e,n){if(!e)return[];let r=Object.entries(e).map(([e,n])=>({name:e,value:n})).sort((e,n)=>n.value-e.value);return n?r.slice(0,n):r}function che(){let e=et(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)([]),[o,s]=(0,y.useState)(!0);(0,y.useEffect)(()=>{async function e(){try{s(!0);let[e,n]=await Promise.all([ib.get(`/v1/stats`),ib.get(`/v1/memories`)]);r(e),a(n?.memories||[])}catch(e){G.error(`加载统计数据失败: `+e.message)}finally{s(!1)}}e()},[]);let c=(0,y.useMemo)(()=>{if(!n?.timeline?.length)return 0;let e=new Date().toISOString().split(`T`)[0];return n.timeline.find(n=>n.date===e)?.count??0},[n]),l=(0,y.useMemo)(()=>C9(n?.by_category,8),[n]),u=(0,y.useMemo)(()=>C9(n?.by_type),[n]),d=(0,y.useMemo)(()=>C9(n?.by_tier),[n]),f=(0,y.useMemo)(()=>C9(n?.by_state),[n]),p=(0,y.useMemo)(()=>!n||!n.total||!n.total_access_count?`0%`:`${Math.min(100,Math.round(n.total_access_count/Math.max(1,n.total)*100))}%`,[n]),m=(0,y.useMemo)(()=>{let e=[];for(let n of i)if(n.tier_history)try{let r=JSON.parse(n.tier_history);for(let i of r)e.push({memoryId:n.id,...i})}catch{}return e.sort((e,n)=>n.at.localeCompare(e.at)),e.slice(0,50)},[i]),h={access_via_get:`访问触发`,access_via_search:`搜索触发`,access_via_recall:`召回触发`,access_via_cross_space_search:`跨空间搜索触发`,scheduled_evaluation:`定时评估`};return o?(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(Tb,{className:`h-8 w-48`}),(0,K.jsx)(Tb,{className:`h-8 w-24`})]}),(0,K.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2 lg:grid-cols-4`,children:[(0,K.jsx)(Tb,{className:`h-24`}),(0,K.jsx)(Tb,{className:`h-24`}),(0,K.jsx)(Tb,{className:`h-24`}),(0,K.jsx)(Tb,{className:`h-24`})]}),(0,K.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,K.jsx)(Tb,{className:`h-80`}),(0,K.jsx)(Tb,{className:`h-80`}),(0,K.jsx)(Tb,{className:`h-80`}),(0,K.jsx)(Tb,{className:`h-80`})]})]}):(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-semibold tracking-tight flex items-center gap-2`,children:[(0,K.jsx)(Jp,{className:`size-5`}),`统计分析`]}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`记忆库数据洞察与可视化`})]}),(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>e(`/memories`),children:[(0,K.jsx)(Bp,{className:`size-4 mr-1.5`}),`返回记忆`]})]}),(0,K.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2 lg:grid-cols-4`,children:[(0,K.jsxs)(bb,{children:[(0,K.jsxs)(xb,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,K.jsx)(Sb,{className:`text-sm font-medium text-muted-foreground`,children:`总记忆数`}),(0,K.jsx)(Kp,{className:`size-4 text-muted-foreground`})]}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`text-2xl font-bold`,children:n?.total??0})})]}),(0,K.jsxs)(bb,{children:[(0,K.jsxs)(xb,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,K.jsx)(Sb,{className:`text-sm font-medium text-muted-foreground`,children:`今日新增`}),(0,K.jsx)(Zm,{className:`size-4 text-muted-foreground`})]}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`text-2xl font-bold`,children:c})})]}),(0,K.jsxs)(bb,{children:[(0,K.jsxs)(xb,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,K.jsx)(Sb,{className:`text-sm font-medium text-muted-foreground`,children:`空间数`}),(0,K.jsx)(bm,{className:`size-4 text-muted-foreground`})]}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`text-2xl font-bold`,children:n?.total_spaces??Object.keys(n?.by_space??{}).length})})]}),(0,K.jsxs)(bb,{children:[(0,K.jsxs)(xb,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,K.jsx)(Sb,{className:`text-sm font-medium text-muted-foreground`,children:`活跃度`}),(0,K.jsx)(iee,{className:`size-4 text-muted-foreground`})]}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`text-2xl font-bold`,children:p})})]})]}),(0,K.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,K.jsxs)(bb,{children:[(0,K.jsxs)(xb,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,K.jsx)(Sb,{className:`text-sm font-medium text-muted-foreground`,children:`平均重要性`}),(0,K.jsx)(Km,{className:`size-4 text-muted-foreground`})]}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`text-2xl font-bold`,children:n?.avg_importance?`${(n.avg_importance*100).toFixed(0)}%`:`—`})})]}),(0,K.jsxs)(bb,{children:[(0,K.jsxs)(xb,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,K.jsx)(Sb,{className:`text-sm font-medium text-muted-foreground`,children:`平均置信度`}),(0,K.jsx)(Jp,{className:`size-4 text-muted-foreground`})]}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`text-2xl font-bold`,children:n?.avg_confidence?`${(n.avg_confidence*100).toFixed(0)}%`:`—`})})]})]}),(0,K.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{children:(0,K.jsx)(Sb,{className:`text-base`,children:`分类分布`})}),(0,K.jsxs)(wb,{children:[(0,K.jsx)(oD,{width:`100%`,height:280,children:(0,K.jsxs)(Xq,{children:[(0,K.jsx)(bB,{data:l,cx:`50%`,cy:`50%`,innerRadius:60,outerRadius:100,paddingAngle:2,dataKey:`value`,children:l.map((e,n)=>(0,K.jsx)(sD,{fill:S9[n%S9.length]},`cell-${e.name}`))}),(0,K.jsx)(VE,{})]})}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2 mt-4 justify-center`,children:l.map((e,n)=>(0,K.jsxs)(hJ,{variant:`secondary`,style:{backgroundColor:`${S9[n%S9.length]}20`,color:S9[n%S9.length]},children:[e.name,` (`,e.value,`)`]},e.name))})]})]}),(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{children:(0,K.jsx)(Sb,{className:`text-base`,children:`记忆类型分布`})}),(0,K.jsx)(wb,{children:(0,K.jsx)(oD,{width:`100%`,height:280,children:(0,K.jsxs)(Yq,{data:u,children:[(0,K.jsx)(KW,{strokeDasharray:`3 3`,stroke:`#333`}),(0,K.jsx)(oK,{dataKey:`name`,tick:{fontSize:12}}),(0,K.jsx)(CK,{tick:{fontSize:12}}),(0,K.jsx)(VE,{}),(0,K.jsx)(HV,{dataKey:`value`,fill:`#8b5cf6`,radius:[4,4,0,0]})]})})})]}),(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{children:(0,K.jsx)(Sb,{className:`text-base`,children:`层级分布`})}),(0,K.jsx)(wb,{children:(0,K.jsx)(oD,{width:`100%`,height:280,children:(0,K.jsxs)(Xq,{children:[(0,K.jsx)(bB,{data:d,cx:`50%`,cy:`50%`,outerRadius:100,dataKey:`value`,label:({name:e,value:n})=>`${e}: ${n}`,children:d.map((e,n)=>(0,K.jsx)(sD,{fill:S9[n%S9.length]},`tier-${e.name}`))}),(0,K.jsx)(VE,{})]})})})]}),(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{children:(0,K.jsx)(Sb,{className:`text-base`,children:`状态分布`})}),(0,K.jsx)(wb,{children:(0,K.jsx)(oD,{width:`100%`,height:280,children:(0,K.jsxs)(Yq,{data:f,children:[(0,K.jsx)(KW,{strokeDasharray:`3 3`,stroke:`#333`}),(0,K.jsx)(oK,{dataKey:`name`,tick:{fontSize:12}}),(0,K.jsx)(CK,{tick:{fontSize:12}}),(0,K.jsx)(VE,{}),(0,K.jsx)(HV,{dataKey:`value`,fill:`#10b981`,radius:[4,4,0,0]})]})})})]})]}),(0,K.jsxs)(bb,{className:`mt-4`,children:[(0,K.jsx)(xb,{children:(0,K.jsxs)(Sb,{className:`flex items-center gap-1.5 text-base`,children:[(0,K.jsx)(mm,{className:`size-4 text-muted-foreground`}),`Tier 变更日志`]})}),(0,K.jsx)(wb,{children:m.length===0?(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground py-4 text-center`,children:`暂无变更记录`}):(0,K.jsx)(`div`,{className:`space-y-1`,children:m.map(n=>{let r={peripheral:0,working:1,core:2};return(0,K.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2 text-sm py-2 border-b last:border-b-0 hover:bg-muted/50 px-2 rounded cursor-pointer w-full text-left`,onClick:()=>e(`/memories/${n.memoryId}`),children:[(r[n.from]??0)<(r[n.to]??0)?(0,K.jsx)(Up,{className:`size-4 text-emerald-500 shrink-0`}):(0,K.jsx)(zp,{className:`size-4 text-red-500 shrink-0`}),(0,K.jsx)(`span`,{className:`text-muted-foreground text-xs w-36 shrink-0`,children:new Date(n.at).toLocaleString(`zh-CN`)}),(0,K.jsxs)(`span`,{className:`text-muted-foreground font-mono text-xs`,children:[n.memoryId.slice(0,8),`...`]}),(0,K.jsx)(hJ,{variant:`outline`,className:EJ(n.from),children:wJ(n.from)}),(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`→`}),(0,K.jsx)(hJ,{variant:`outline`,className:EJ(n.to),children:wJ(n.to)}),(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:[h[n.reason]||n.reason,` · #`,n.access_count]})]},n.memoryId+n.at)})})})]})]})}var lhe={access_via_get:`访问触发`,access_via_search:`搜索触发`,access_via_recall:`召回触发`,access_via_cross_space_search:`跨空间搜索触发`,scheduled_evaluation:`定时评估`},w9=20;function uhe(){let e=et(),n=Ze(),[r,i]=(0,y.useState)([]),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(1),[l,u]=(0,y.useState)(`all`),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(0);(0,y.useEffect)(()=>{n.state?.from===`tier-history`&&n.state?.page&&c(n.state.page)},[n.state]),(0,y.useEffect)(()=>{let e=setTimeout(()=>{m(d)},300);return()=>clearTimeout(e)},[d]);let S=(0,y.useCallback)(async e=>{o(!0);try{let n=(e-1)*w9,r={limit:String(w9),offset:String(n)};l===`promote`?r.filter=`promote`:l===`demote`&&(r.filter=`demote`),p.trim()&&(r.search=p.trim());let a=await ib.get(`/v1/tier-changes`,{params:r});i(a.changes),x(a.totalCount)}catch(e){console.error(`Failed to fetch tier history:`,e)}finally{o(!1)}},[l,p]);(0,y.useEffect)(()=>{S(s)},[S,s]);let C=Math.max(1,Math.ceil(b/w9)),w=Math.min(s,C),T={peripheral:0,working:1,core:2},E=async()=>{if(!h)return;let e=h;v(!0);try{await ib.post(`/v1/tier-changes/delete`,{memory_id:e.memoryId,from:e.from,to:e.to,at:e.at,reason:e.reason}),G.success(`已删除该条变更记录`),i(n=>n.filter(n=>!(n.memoryId===e.memoryId&&n.from===e.from&&n.to===e.to&&n.at===e.at))),x(e=>Math.max(0,e-1))}catch(e){console.error(`Failed to delete tier history entry:`,e),G.error(`删除失败`)}finally{v(!1),g(null)}},D=n=>{e(`/memories/${n}`,{state:{from:`tier-history`,page:w}})};return(0,K.jsxs)(`div`,{className:`space-y-6 max-w-5xl mx-auto`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-semibold tracking-tight flex items-center gap-2`,children:[(0,K.jsx)(mm,{className:`size-5`}),`等级变更历史`]}),(0,K.jsxs)(`span`,{className:`text-sm text-muted-foreground`,children:[`共 `,b,` 条记录`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1 min-w-[200px] max-w-xs`,children:[(0,K.jsx)(Vm,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 size-4 text-muted-foreground`}),(0,K.jsx)(`input`,{type:`text`,placeholder:`搜索标题、ID、原因...`,value:d,onChange:e=>{f(e.target.value),c(1)},className:`w-full h-9 pl-8 pr-3 rounded-md border border-input bg-background text-sm focus:outline-none focus:ring-1 focus:ring-ring`})]}),(0,K.jsxs)(r9,{value:l,onValueChange:e=>{e&&(u(e),c(1))},children:[(0,K.jsx)(a9,{className:`w-[130px]`,children:(0,K.jsx)(i9,{})}),(0,K.jsxs)(o9,{children:[(0,K.jsx)(s9,{value:`all`,children:`全部`}),(0,K.jsx)(s9,{value:`promote`,children:`仅晋升`}),(0,K.jsx)(s9,{value:`demote`,children:`仅降级`})]})]})]}),!a&&r.length>0&&C>1&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`第 `,w,` / `,C,` 页`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(J,{variant:`outline`,size:`sm`,className:`h-7 px-2`,disabled:w<=1,onClick:()=>c(w-1),children:(0,K.jsx)(Zp,{className:`size-4`})}),Array.from({length:C},(e,n)=>n+1).filter(e=>e===1||e===C||Math.abs(e-w)<=2).map((e,n,r)=>(0,K.jsxs)(`span`,{className:`flex items-center`,children:[n>0&&r[n-1]!==e-1&&(0,K.jsx)(`span`,{className:`px-1 text-xs text-muted-foreground`,children:`...`}),(0,K.jsx)(J,{variant:e===w?`default`:`outline`,size:`sm`,className:`h-7 w-7 px-0`,onClick:()=>c(e),children:e})]},e)),(0,K.jsx)(J,{variant:`outline`,size:`sm`,className:`h-7 px-2`,disabled:w>=C,onClick:()=>c(w+1),children:(0,K.jsx)(Qp,{className:`size-4`})})]})]}),(0,K.jsx)(bb,{children:(0,K.jsxs)(wb,{className:`p-0`,children:[a?(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground py-12 text-center`,children:`加载中...`}):r.length===0?(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground py-12 text-center`,children:`暂无变更记录`}):(0,K.jsx)(`div`,{className:`divide-y`,children:r.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 hover:bg-muted/30 transition-colors`,children:[(T[e.from]??0)<(T[e.to]??0)?(0,K.jsx)(Up,{className:`size-4 text-emerald-500 shrink-0`}):(0,K.jsx)(zp,{className:`size-4 text-red-500 shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground w-36 shrink-0`,children:new Date(e.at).toLocaleString(`zh-CN`)}),(0,K.jsx)(hJ,{variant:`outline`,className:EJ(e.from),children:wJ(e.from)}),(0,K.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`→`}),(0,K.jsx)(hJ,{variant:`outline`,className:EJ(e.to),children:wJ(e.to)}),(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground w-20 shrink-0`,children:lhe[e.reason]||e.reason}),(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground w-16 shrink-0`,children:[`#`,e.accessCount]}),(0,K.jsx)(`button`,{type:`button`,className:`flex-1 min-w-0 text-left text-sm truncate hover:underline cursor-pointer`,onClick:()=>D(e.memoryId),title:e.memoryTitle,children:e.memoryTitle}),(0,K.jsxs)(`span`,{className:`text-xs font-mono text-muted-foreground shrink-0`,children:[e.memoryId.slice(0,8),`...`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,K.jsx)(J,{variant:`ghost`,size:`sm`,className:`h-7 px-2`,onClick:()=>D(e.memoryId),title:`查看详情`,children:(0,K.jsx)(om,{className:`size-3.5`})}),(0,K.jsx)(J,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-red-500 hover:text-red-600 hover:bg-red-500/10`,onClick:()=>g(e),title:`删除此条记录`,children:(0,K.jsx)(Xm,{className:`size-3.5`})})]})]},`${e.memoryId}-${e.at}-${e.from}-${e.to}`))}),C>1&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-t`,children:[(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`第 `,w,` / `,C,` 页,共 `,b,` 条`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(J,{variant:`outline`,size:`sm`,className:`h-7 px-2`,disabled:w<=1,onClick:()=>c(w-1),children:(0,K.jsx)(Zp,{className:`size-4`})}),Array.from({length:C},(e,n)=>n+1).filter(e=>e===1||e===C||Math.abs(e-w)<=2).map((e,n,r)=>(0,K.jsxs)(`span`,{className:`flex items-center`,children:[n>0&&r[n-1]!==e-1&&(0,K.jsx)(`span`,{className:`px-1 text-xs text-muted-foreground`,children:`...`}),(0,K.jsx)(J,{variant:e===w?`default`:`outline`,size:`sm`,className:`h-7 w-7 px-0`,onClick:()=>c(e),children:e})]},e)),(0,K.jsx)(J,{variant:`outline`,size:`sm`,className:`h-7 px-2`,disabled:w>=C,onClick:()=>c(w+1),children:(0,K.jsx)(Qp,{className:`size-4`})})]})]})]})}),(0,K.jsx)(aJ,{open:!!h,onOpenChange:e=>{e||g(null)},children:(0,K.jsxs)(oJ,{children:[(0,K.jsxs)(sJ,{children:[(0,K.jsx)(lJ,{children:`确认删除变更记录`}),(0,K.jsxs)(uJ,{children:[`确定要删除这条 `,h&&`${wJ(h.from)} → ${wJ(h.to)}`,` 的变更记录吗?记忆本身不会被删除。`]})]}),(0,K.jsxs)(cJ,{children:[(0,K.jsx)(fJ,{onClick:()=>g(null),disabled:_,children:`取消`}),(0,K.jsx)(dJ,{disabled:_,onClick:e=>{e.preventDefault(),E()},className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:_?`删除中...`:`确认删除`})]})]})})]})}async function dhe(){return ib.get(`/v1/clusters/stats`)}async function fhe(e,n,r){return ib.post(`/v1/clusters/trigger`,{space_id:e,batch_size:n,mode:r})}async function phe(){return ib.get(`/v1/clusters/jobs`)}async function mhe(e){return ib.delete(`/v1/clusters/jobs/${e}`)}async function hhe(e,n){let r={};return e!==void 0&&(r.limit=String(e)),n!==void 0&&(r.offset=String(n)),ib.get(`/v1/clusters`,{params:r})}async function ghe(e){return ib.delete(`/v1/clusters/${e}`)}async function _he(e){return ib.get(`/v1/clusters/${e}`)}async function vhe(e){return ib.post(`/v1/clusters/batch-delete`,{cluster_ids:e})}async function yhe(){return ib.delete(`/v1/clusters/all`,{timeout:3e5})}async function T9(){return ib.get(`/v1/scheduler/status`)}async function bhe(){return ib.post(`/v1/scheduler/clustering/pause`)}async function xhe(){return ib.post(`/v1/scheduler/clustering/resume`)}var E9=null,D9=new Map,O9=new Set,k9=null;function She(){let e=hh.getState().users.find(e=>e.id===hh.getState().currentUserId);return e?.apiKey?`/v1/events?api_key=${encodeURIComponent(e.apiKey)}&tenant_id=${encodeURIComponent(e.apiKey)}`:null}function A9(){if(E9)return;let e=She();e&&(E9=new EventSource(e),E9.onmessage=e=>{try{let n=JSON.parse(e.data),r=D9.get(n.event_type);r&&r.forEach(e=>e(n)),O9.forEach(e=>e(n))}catch{}},E9.onerror=()=>{E9?.close(),E9=null,k9&&clearTimeout(k9),k9=setTimeout(A9,5e3)})}function Che(){k9&&=(clearTimeout(k9),null),E9?.close(),E9=null}function j9(e,n){let r=(0,y.useRef)(n);r.current=n,(0,y.useEffect)(()=>{D9.has(e)||D9.set(e,new Set);let n=(e=>r.current(e));return D9.get(e).add(n),A9(),()=>{D9.get(e)?.delete(n),D9.get(e)?.size===0&&D9.delete(e),D9.size===0&&O9.size===0&&Che()}},[e])}function whe(){let[e,n]=(0,y.useState)(null),[r,i]=(0,y.useState)([]),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)({paused:!1,running:!1}),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(!1),b=async()=>{try{o(!0);let[e,r,a]=await Promise.all([dhe(),phe(),T9().catch(()=>null)]);n(e),i(r.jobs||[]),a&&m(a.clustering)}catch(e){console.error(`Failed to load cluster data:`,e),G.error(`加载簇数据失败`)}finally{o(!1)}};(0,y.useEffect)(()=>{b()},[]),j9(`cluster.stage`,e=>{let n=e.data;n&&f({stage:String(n.stage||``),message:String(n.message||``),processed:typeof n.processed==`number`?n.processed:void 0,total:typeof n.total==`number`?n.total:void 0})}),j9(`cluster.started`,e=>{let n=e.data;n&&f({stage:`started`,message:String(n.message||`开始归簇 ${n.total||0} 条记忆`),processed:0,total:typeof n.total==`number`?n.total:void 0})}),j9(`cluster.memory_progress`,e=>{let n=e.data;n&&f(e=>({stage:String(n.stage||e?.stage||`clustering`),message:n.stage===`creating_cluster`?`创建新簇...`:n.stage===`linking`?`关联已有簇...`:`处理中 ${n.processed??e?.processed??0}/${n.total??e?.total??`?`}`,processed:typeof n.processed==`number`?n.processed:e?.processed,total:typeof n.total==`number`?n.total:e?.total}))}),j9(`cluster.batch_done`,e=>{let n=e.data;n&&f(e=>({stage:e?.stage||`batch_done`,message:`批次 ${n.batch} 完成 · 已处理 ${n.processed}/${n.total}`,processed:typeof n.processed==`number`?n.processed:e?.processed,total:typeof n.total==`number`?n.total:e?.total})),b()}),j9(`cluster.complete`,()=>{f(null),b(),G.success(`归簇任务完成`)}),j9(`cluster.failed`,e=>{let n=e.data;f(null),b(),G.error(`归簇任务失败: ${n?.error||`未知错误`}`)});let x=async(e=`incremental`)=>{try{c(!0);let n=await fhe(void 0,void 0,e);G.success(n.message),b()}catch(e){console.error(`Failed to trigger clustering:`,e),G.error(`触发归簇失败`)}finally{c(!1)}},S=async()=>{try{g(!0),p.paused?(await xhe(),G.success(`归簇调度已恢复`)):(await bhe(),G.success(`归簇调度已暂停`)),m((await T9()).clustering)}catch{G.error(`操作失败`)}finally{g(!1)}},C=async e=>{try{u(e),await mhe(e),G.success(`任务已删除`),b()}catch(e){console.error(`Failed to delete job:`,e),G.error(`删除任务失败`)}finally{u(null)}},w=e=>{switch(e){case`running`:return(0,K.jsx)(wm,{className:`h-4 w-4 animate-spin text-blue-500`});case`completed`:return(0,K.jsx)(em,{className:`h-4 w-4 text-green-500`});case`failed`:return(0,K.jsx)(tm,{className:`h-4 w-4 text-red-500`});default:return(0,K.jsx)(nm,{className:`h-4 w-4 text-muted-foreground`})}},T=e=>({pending:`bg-yellow-100 text-yellow-800`,running:`bg-blue-100 text-blue-800`,completed:`bg-green-100 text-green-800`,failed:`bg-red-100 text-red-800`})[e]||`bg-gray-100 text-gray-800`;return(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`簇管理`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`管理记忆归簇任务和查看统计`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:b,disabled:a,children:[(0,K.jsx)(zm,{className:`h-4 w-4 mr-1`}),`刷新`]}),(0,K.jsxs)(J,{variant:p.paused?`default`:`outline`,size:`sm`,onClick:S,disabled:h,children:[h?(0,K.jsx)(wm,{className:`h-4 w-4 mr-1 animate-spin`}):p.paused?(0,K.jsx)(Im,{className:`h-4 w-4 mr-1`}):(0,K.jsx)(Nm,{className:`h-4 w-4 mr-1`}),p.paused?`恢复调度`:`暂停调度`]}),(0,K.jsx)(J,{size:`sm`,onClick:()=>x(`incremental`),disabled:s,children:s?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(wm,{className:`h-4 w-4 mr-1 animate-spin`}),`处理中...`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Im,{className:`h-4 w-4 mr-1`}),`增量归簇`]})}),(0,K.jsx)(J,{variant:`destructive`,size:`sm`,onClick:()=>v(!0),disabled:s,children:s?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(wm,{className:`h-4 w-4 mr-1 animate-spin`}),`处理中...`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(ih,{className:`h-4 w-4 mr-1`}),`全局重建`]})})]})]}),(0,K.jsx)(`div`,{className:`flex items-center gap-3 text-sm text-muted-foreground`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(Rp,{className:`h-3.5 w-3.5`}),(0,K.jsx)(`span`,{children:`调度器:`}),p.running?(0,K.jsx)(hJ,{className:`bg-emerald-100 text-emerald-700`,children:`运行中`}):p.paused?(0,K.jsx)(hJ,{className:`bg-amber-100 text-amber-700`,children:`已暂停`}):(0,K.jsx)(hJ,{className:`bg-slate-100 text-slate-600`,children:`空闲`})]})}),a?(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[1,2,3].map(e=>(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsx)(Tb,{className:`h-4 w-24`})}),(0,K.jsx)(wb,{children:(0,K.jsx)(Tb,{className:`h-8 w-16`})})]},e))}):e?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsx)(Sb,{className:`text-sm font-medium`,children:`总簇数`})}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`text-2xl font-bold`,children:e.total_clusters})})]}),(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsx)(Sb,{className:`text-sm font-medium`,children:`已归簇记忆`})}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`text-2xl font-bold`,children:e.total_memories_in_clusters})})]}),(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsx)(Sb,{className:`text-sm font-medium`,children:`未归簇记忆`})}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`text-2xl font-bold text-amber-600`,children:e.orphaned_memories})})]})]}),d&&(0,K.jsxs)(bb,{className:`border-blue-200 bg-blue-50/50`,children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(ree,{className:`h-4 w-4 text-blue-500 animate-pulse`}),(0,K.jsx)(Sb,{className:`text-sm font-medium text-blue-700`,children:`实时进度`})]})}),(0,K.jsxs)(wb,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-sm text-blue-600`,children:d.message}),d.total!=null&&d.total>0&&(0,K.jsx)(`div`,{className:`w-full bg-blue-200 rounded-full h-2`,children:(0,K.jsx)(`div`,{className:`bg-blue-500 h-2 rounded-full transition-all duration-300`,style:{width:`${Math.min(100,(d.processed||0)/d.total*100)}%`}})})]})]}),(0,K.jsxs)(bb,{children:[(0,K.jsxs)(xb,{children:[(0,K.jsx)(Sb,{children:`归簇任务历史`}),(0,K.jsx)(Cb,{children:`最近执行的归簇任务记录`})]}),(0,K.jsx)(wb,{children:r.length===0?(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-8`,children:`暂无归簇任务记录`}):(0,K.jsx)(`div`,{className:`space-y-3`,children:r.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 rounded-lg border`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[w(e.status),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`p`,{className:`text-sm font-medium`,children:[`任务 `,e.id.slice(0,8)]}),(0,K.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[e.total_memories,` 条记忆 · 处理 `,e.processed_memories,` 条`]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(hJ,{variant:`outline`,className:T(e.status),children:e.status===`running`?`进行中`:e.status===`completed`?`已完成`:e.status===`failed`?`失败`:`待处理`}),e.created_at&&(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:new Date(e.created_at).toLocaleString(`zh-CN`)}),(0,K.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-destructive`,onClick:()=>C(e.id),disabled:l===e.id,children:l===e.id?(0,K.jsx)(wm,{className:`h-3.5 w-3.5 animate-spin`}):(0,K.jsx)(Xm,{className:`h-3.5 w-3.5`})})]})]},e.id))})})]})]}):(0,K.jsx)(bb,{children:(0,K.jsx)(wb,{className:`py-8 text-center`,children:(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`无法加载统计数据`})})}),(0,K.jsx)(aJ,{open:_,onOpenChange:v,children:(0,K.jsxs)(oJ,{children:[(0,K.jsxs)(sJ,{children:[(0,K.jsx)(lJ,{children:`确认全局重建?`}),(0,K.jsx)(uJ,{children:`全局重建会清空所有簇并用 K-Means 重新聚类,此操作不可撤销。`})]}),(0,K.jsxs)(cJ,{children:[(0,K.jsx)(fJ,{children:`取消`}),(0,K.jsx)(dJ,{variant:`destructive`,onClick:()=>{v(!1),x(`rebuild`)},children:`确认重建`})]})]})})]})}var M9=function(e){return e.checked=`data-checked`,e.unchecked=`data-unchecked`,e.indeterminate=`data-indeterminate`,e.disabled=`data-disabled`,e.readonly=`data-readonly`,e.required=`data-required`,e.valid=`data-valid`,e.invalid=`data-invalid`,e.touched=`data-touched`,e.dirty=`data-dirty`,e.filled=`data-filled`,e.focused=`data-focused`,e}({});function N9(e){return y.useMemo(()=>({checked(n){return e.indeterminate?{}:n?{[M9.checked]:``}:{[M9.unchecked]:``}},...lb}),[e.indeterminate])}function P9(e,n,r,i=!0,a){let[o,s]=y.useState(),c=vd(a?`${a}-label`:void 0),l=e??n??o;return Nr(()=>{let a=e||n||!i?void 0:The(r.current,c);o!==a&&s(a)}),l}function The(e,n){let r=Ehe(e);if(r)return!r.id&&n&&(r.id=n),r.id||void 0}function Ehe(e){if(!e)return;let n=e.parentElement;if(n&&n.tagName===`LABEL`)return n;let r=e.id;if(r){let n=e.nextElementSibling;if(n&&n.htmlFor===r)return n}let i=e.labels;return i&&i[0]}var F9=y.createContext(void 0);function Dhe(){let e=y.useContext(F9);if(e===void 0)throw Error(Fr(14));return e}var Ohe=`data-parent`,khe=y.forwardRef(function(e,n){let{checked:r,className:i,defaultChecked:a=!1,"aria-labelledby":o,disabled:s=!1,form:c,id:l,indeterminate:u=!1,inputRef:d,name:f,onCheckedChange:p,parent:m=!1,readOnly:h=!1,render:g,required:_=!1,uncheckedValue:v,value:b,nativeButton:x=!1,style:S,...C}=e,{clearErrors:w}=db(),{disabled:T,name:E,setDirty:D,setFilled:O,setFocused:k,setTouched:A,state:j,validationMode:M,validityData:N,shouldValidateOnChange:P,validation:F}=ub(),I=Xee(),{labelId:L,controlId:R,registerControlId:z,getDescriptionProps:ee}=fb(),B=Qee(),V=B?.parent,H=V&&B.allValues,U=T||I.disabled||B?.disabled||s,te=E??f,W=b??te,ne=vd(),re=vd(),ie=R;H?ie=m?re:`${V.id}-${W}`:l&&(ie=l);let ae={};H&&(m?ae=B.parent.getParentProps():W&&(ae=B.parent.getChildProps(W)));let oe=Sa(p),{checked:se=r,indeterminate:ce=u,onCheckedChange:le,...ue}=ae,de=B?.value,fe=B?.setValue,pe=B?.defaultValue,me=y.useRef(null),he=wr(()=>Symbol(`checkbox-control`)),ge=y.useRef(!1),{getButtonProps:_e,buttonRef:ve}=vh({disabled:U,native:x}),ye=B?.validation??F,[be,xe]=Hg({controlled:W&&de&&!m?de.includes(W):se,default:W&&pe&&!m?pe.includes(W):a,name:`Checkbox`,state:`checked`});Nr(()=>{z!==fi&&(ge.current=!0,z(he.current,ie))},[ie,B,z,m,he]),y.useEffect(()=>{let e=he.current;return()=>{!ge.current||z===fi||(ge.current=!1,z(e,void 0))}},[z,he]),pb(me,{enabled:!B,id:ne,value:be});let Se=y.useRef(null),Ce=fa(d,Se,ye.inputRef),we=P9(o,L,Se,!x,ie??void 0);Nr(()=>{Se.current&&(Se.current.indeterminate=ce,be&&O(!0))},[be,ce,O]),fg(be,()=>{B&&!m||(w(te),O(be),D(be!==N.initialValue),P()?ye.commit(be):ye.commit(be,!0))});let Te=Ls({checked:be,disabled:U,form:c,name:m?void 0:te,id:x?void 0:ie??void 0,required:_,ref:Ce,style:te?Ma:ja,tabIndex:-1,type:`checkbox`,"aria-hidden":!0,onChange(e){if(e.nativeEvent.defaultPrevented)return;if(h){e.preventDefault();return}let n=e.currentTarget.checked,r=Fi(bi,e.nativeEvent);le?.(n,r),oe(n,r),!r.isCanceled&&(xe(n),W&&de&&fe&&!m&&!H&&fe(n?[...de,W]:de.filter(e=>e!==W),r))},onFocus(){me.current?.focus()}},b===void 0?mi:{value:(B?be&&b:b)||``},ee,B?ye.getValidationProps:ye.getInputValidationProps),Ee=H?!!se:be,De=H&&ce||u;y.useEffect(()=>{if(!V||!W)return;let e=V.disabledStatesRef.current;return e.set(W,U),()=>{e.delete(W)}},[V,U,W]);let Oe=y.useMemo(()=>({...j,checked:Ee,disabled:U,readOnly:h,required:_,indeterminate:De}),[j,Ee,U,h,_,De]),ke=N9(Oe),Ae=Zs(`span`,e,{state:Oe,ref:[ve,me,n,B?.registerControlRef],props:[{id:x?ie??void 0:ne,role:`checkbox`,"aria-checked":ce?`mixed`:be,"aria-readonly":h||void 0,"aria-required":_||void 0,"aria-labelledby":we,[Ohe]:m?``:void 0,onFocus(){k(!0)},onBlur(){let e=Se.current;e&&(A(!0),k(!1),M===`onBlur`&&ye.commit(B?de:e.checked))},onClick(e){h||U||(e.preventDefault(),Se.current?.dispatchEvent(new PointerEvent(`click`,{bubbles:!0,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey})))}},ee,ye.getValidationProps,C,ue,_e],stateAttributesMapping:ke});return(0,K.jsxs)(F9.Provider,{value:Oe,children:[Ae,!be&&!B&&te&&!m&&v!==void 0&&(0,K.jsx)(`input`,{type:`hidden`,form:c,name:te,value:v}),(0,K.jsx)(`input`,{...Te,suppressHydrationWarning:!0})]})}),Ahe=y.forwardRef(function(e,n){let{render:r,className:i,style:a,keepMounted:o=!1,...s}=e,c=Dhe(),l=c.checked||c.indeterminate,{mounted:u,transitionStatus:d,setMounted:f}=ou(l),p=y.useRef(null),m={...c,transitionStatus:d};fu({open:l,ref:p,onComplete(){l||f(!1)}});let h=N9(c),g=y.useMemo(()=>({...h,...uu,...lb}),[h]),_=o||u,v=Zs(`span`,e,{ref:[n,p],state:m,stateAttributesMapping:g,props:s});return _?v:null});function I9({className:e,...n}){return(0,K.jsx)(khe,{"data-slot":`checkbox`,className:wp(`peer relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input transition-colors outline-none group-has-disabled/field:opacity-50 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground dark:data-checked:bg-primary`,e),...n,children:(0,K.jsx)(Ahe,{"data-slot":`checkbox-indicator`,className:`grid place-content-center text-current transition-none [&>svg]:size-3.5`,children:(0,K.jsx)(Yp,{})})})}function jhe(e){return new Date(e).toLocaleString(`zh-CN`,{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function Mhe(e,n=100){return e?e.length<=n?e:e.slice(0,n)+`...`:`—`}var L9=12;function Nhe(){let e=et(),[n,r]=(0,y.useState)([]),[i,a]=(0,y.useState)(!0),[o,s]=(0,y.useState)(`all`),[c,l]=(0,y.useState)(1),[u,d]=(0,y.useState)(0),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(!1),[g,_]=(0,y.useState)(new Set),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)(null),[D,O]=(0,y.useState)([]),k=async e=>{try{a(!0);let n=await hhe(L9,(e-1)*L9);r(n.clusters||[]),d(n.total||0),_(new Set)}catch(e){console.error(`Failed to load clusters:`,e),G.error(`加载簇列表失败`)}finally{a(!1)}};(0,y.useEffect)(()=>{k(c)},[c]),j9(`cluster.complete`,()=>{E(null),setTimeout(()=>O([]),3e3),k(c)}),j9(`cluster.batch_done`,()=>{k(c)}),j9(`cluster.memory_progress`,e=>{let n=e.data;if(E(e=>({processed:n.processed??e?.processed??0,total:n.total??e?.total??0,pct:n.pct??e?.pct??0})),n.content_preview){let e={assign_existing:`→ 加入已有簇`,create_new:`→ 创建新簇`,skip:`⊘ 跳过`},r={assigning:`匹配中`,linking:`关联中`,creating_cluster:`建簇中`};O(i=>[{time:new Date().toLocaleTimeString(`zh-CN`),preview:n.content_preview||``,action:e[n.action||``]||n.action||``,stage:r[n.stage||``]||n.stage||``},...i].slice(0,50))}});let A=(0,y.useMemo)(()=>{let e=new Set(n.map(e=>e.category).filter(Boolean));return Array.from(e).sort()},[n]),j=(0,y.useMemo)(()=>o===`all`?n:n.filter(e=>e.category===o),[n,o]),M=Math.max(1,Math.ceil(u/L9)),N=Math.min(c,M),P=async()=>{if(f){h(!0);try{await ghe(f.id),G.success(`已删除簇「${f.title||`未命名`}」`),p(null),k(N)}catch(e){console.error(`Failed to delete cluster:`,e),G.error(`删除失败`)}finally{h(!1)}}},F=e=>{_(n=>{let r=new Set(n);return r.has(e)?r.delete(e):r.add(e),r})},I=()=>{g.size===j.length&&j.length>0?_(new Set):_(new Set(j.map(e=>e.id)))},L=async()=>{if(g.size!==0){b(!0);try{let e=await vhe(Array.from(g));G.success(`已删除 ${e.deleted} 个簇,解绑 ${e.unlinked_memories} 条记忆`),_(new Set),k(N)}catch(e){console.error(`Failed to batch delete clusters:`,e),G.error(`批量删除失败`)}finally{b(!1)}}},R=async()=>{w(!0);try{let e=await yhe();G.success(`已删除 ${e.deleted} 个簇,解绑 ${e.unlinked_memories} 条记忆`),S(!1),_(new Set),k(N)}catch(e){console.error(`Failed to delete all clusters:`,e),G.error(`全部删除失败`)}finally{w(!1)}};return(0,K.jsxs)(`div`,{className:`space-y-6`,children:[T&&(0,K.jsxs)(`div`,{className:`bg-primary/5 border border-primary/20 rounded-lg p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium text-primary`,children:`🔄 归簇进行中...`}),(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[T.processed??0,` / `,T.total??0,T.pct!==0||T.processed!==0?` (${T.pct??0}%)`:``]})]}),(0,K.jsx)(`div`,{className:`w-full bg-primary/10 rounded-full h-2`,children:(0,K.jsx)(`div`,{className:`bg-primary rounded-full h-2 transition-all duration-300`,style:{width:`${T.pct}%`}})}),D.length>0&&(0,K.jsx)(`div`,{className:`mt-2 max-h-48 overflow-y-auto text-xs font-mono space-y-0.5`,children:D.map((e,n)=>(0,K.jsxs)(`div`,{className:`flex items-start gap-2 text-muted-foreground`,children:[(0,K.jsx)(`span`,{className:`text-[10px] shrink-0 opacity-50`,children:e.time}),(0,K.jsx)(`span`,{className:`truncate flex-1`,children:e.preview}),(0,K.jsx)(`span`,{className:`shrink-0 font-medium ${e.action.includes(`创建`)?`text-green-600`:e.action.includes(`加入`)?`text-blue-600`:`text-muted-foreground`}`,children:e.action})]},n))})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`簇列表`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`浏览所有记忆簇及其成员`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[A.length>1&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(dm,{className:`size-3.5 text-muted-foreground`}),(0,K.jsxs)(`select`,{value:o,onChange:e=>s(e.target.value),className:`h-9 rounded-md border border-input bg-background px-3 text-sm`,children:[(0,K.jsx)(`option`,{value:`all`,children:`全部分类`}),A.map(e=>(0,K.jsx)(`option`,{value:e,children:CJ(e)},e))]})]}),(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>k(N),disabled:i,children:[(0,K.jsx)(zm,{className:`size-4 mr-1`}),`刷新`]})]})]}),!i&&j.length>0&&M>1&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`第 `,N,` / `,M,` 页,共 `,u,` 个簇`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(J,{variant:`outline`,size:`sm`,className:`h-7 px-2`,disabled:N<=1,onClick:()=>l(N-1),children:(0,K.jsx)(Zp,{className:`size-4`})}),Array.from({length:M},(e,n)=>n+1).filter(e=>e===1||e===M||Math.abs(e-N)<=2).map((e,n,r)=>(0,K.jsxs)(`span`,{className:`flex items-center`,children:[n>0&&r[n-1]!==e-1&&(0,K.jsx)(`span`,{className:`px-1 text-xs text-muted-foreground`,children:`...`}),(0,K.jsx)(J,{variant:e===N?`default`:`outline`,size:`sm`,className:`h-7 w-7 px-0`,onClick:()=>l(e),children:e})]},e)),(0,K.jsx)(J,{variant:`outline`,size:`sm`,className:`h-7 px-2`,disabled:N>=M,onClick:()=>l(N+1),children:(0,K.jsx)(Qp,{className:`size-4`})})]})]}),!i&&j.length===0&&(0,K.jsxs)(`div`,{className:`rounded-lg border border-border bg-card p-12 text-center space-y-4`,children:[(0,K.jsx)(_m,{className:`size-12 text-muted-foreground mx-auto`}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-muted-foreground`,children:o===`all`?`暂无簇数据`:`未找到匹配的簇`}),(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o===`all`?`启动归簇任务后,簇将在此处展示`:`尝试切换分类筛选`})]})]}),!i&&j.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between rounded-lg border border-border bg-card p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(I9,{checked:g.size===j.length&&j.length>0,onCheckedChange:I,"aria-label":`全选`}),(0,K.jsxs)(`span`,{className:`text-sm text-muted-foreground`,children:[`已选 `,g.size,` 个`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(J,{variant:`outline`,size:`sm`,disabled:g.size===0||v,onClick:L,children:[(0,K.jsx)(Xm,{className:`size-4 mr-1`}),v?`删除中...`:`删除所选 (${g.size})`]}),(0,K.jsxs)(J,{variant:`outline`,size:`sm`,className:`text-red-500 hover:text-red-600 hover:bg-red-500/10`,disabled:C,onClick:()=>S(!0),children:[(0,K.jsx)(Xm,{className:`size-4 mr-1`}),C?`删除中...`:`全部删除`]})]})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:i?[1,2,3,4,5,6].map(e=>(0,K.jsxs)(bb,{className:`cursor-pointer`,children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsx)(Tb,{className:`h-5 w-3/4`})}),(0,K.jsxs)(wb,{className:`space-y-3`,children:[(0,K.jsx)(Tb,{className:`h-4 w-full`}),(0,K.jsx)(Tb,{className:`h-4 w-2/3`}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(Tb,{className:`h-5 w-12`}),(0,K.jsx)(Tb,{className:`h-5 w-16`})]})]})]},e)):j.map(n=>(0,K.jsxs)(bb,{className:`cursor-pointer hover:bg-muted/50 transition-colors group`,onClick:()=>e(`/clusters/${n.id}`),children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,K.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,K.jsx)(I9,{checked:g.has(n.id),onCheckedChange:()=>F(n.id),"aria-label":`选择 ${n.title||`未命名簇`}`})}),(0,K.jsx)(Sb,{className:`text-base font-semibold line-clamp-1`,children:n.title||`未命名簇`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,K.jsx)(hJ,{variant:`outline`,className:`text-xs ${SJ(n.category)}`,children:CJ(n.category)}),(0,K.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity text-red-500 hover:text-red-600 hover:bg-red-500/10`,onClick:e=>{e.stopPropagation(),p(n)},title:`删除此簇`,children:(0,K.jsx)(Xm,{className:`size-3`})})]})]})}),(0,K.jsxs)(wb,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground line-clamp-3`,children:Mhe(n.summary,150)}),(n.keywords?.length??0)>0&&(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[n.keywords.slice(0,5).map(e=>(0,K.jsx)(hJ,{variant:`secondary`,className:`text-xs font-normal`,children:e},e)),n.keywords.length>5&&(0,K.jsxs)(hJ,{variant:`secondary`,className:`text-xs font-normal`,children:[`+`,n.keywords.length-5]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground pt-1`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(nh,{className:`size-3`}),n.member_count,` 条记忆`]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(nm,{className:`size-3`}),jhe(n.updated_at)]})]})]})]},n.id))}),!i&&j.length>0&&(0,K.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`共 `,u,` 个簇`,o!==`all`&&` (筛选自 ${n.length} 个)`]}),(0,K.jsx)(aJ,{open:!!f,onOpenChange:e=>{e||p(null)},children:(0,K.jsxs)(oJ,{children:[(0,K.jsxs)(sJ,{children:[(0,K.jsx)(lJ,{children:`确认删除簇`}),(0,K.jsxs)(uJ,{children:[`确定要删除簇「`,f?.title||`未命名`,`」吗?该簇内的记忆将被解绑但不会被删除。`]})]}),(0,K.jsxs)(cJ,{children:[(0,K.jsx)(fJ,{onClick:()=>p(null),disabled:m,children:`取消`}),(0,K.jsx)(dJ,{disabled:m,onClick:e=>{e.preventDefault(),P()},className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:m?`删除中...`:`确认删除`})]})]})}),(0,K.jsx)(aJ,{open:x,onOpenChange:S,children:(0,K.jsxs)(oJ,{children:[(0,K.jsxs)(sJ,{children:[(0,K.jsx)(lJ,{children:`确认删除全部簇`}),(0,K.jsx)(uJ,{children:`确定要删除所有簇吗?此操作不可撤销,簇内的记忆将被解绑但不会被删除。`})]}),(0,K.jsxs)(cJ,{children:[(0,K.jsx)(fJ,{onClick:()=>S(!1),disabled:C,children:`取消`}),(0,K.jsx)(dJ,{disabled:C,onClick:e=>{e.preventDefault(),R()},className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:C?`删除中...`:`确认删除全部`})]})]})})]})}function R9(e){return new Date(e).toLocaleString(`zh-CN`,{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function Phe(e){return new Date(e).toLocaleDateString(`zh-CN`)}var z9=160;function Fhe({content:e,collapsed:n}){return(0,K.jsx)(`div`,{className:`prose prose-sm dark:prose-invert max-w-none text-sm leading-relaxed`,style:n?{maxHeight:`${z9}px`,overflow:`hidden`}:void 0,children:(0,K.jsx)(p0,{remarkPlugins:[Y4],children:e})})}function Ihe({content:e}){let[n,r]=(0,y.useState)(!1),[i,a]=(0,y.useState)(!1);return(0,K.jsxs)(`div`,{ref:(0,y.useCallback)(e=>{e&&a(e.scrollHeight>z9+20)},[e]),children:[(0,K.jsx)(Fhe,{content:e,collapsed:!n&&i}),i&&(0,K.jsx)(J,{variant:`ghost`,size:`sm`,className:`mt-1 h-7 text-xs text-muted-foreground hover:text-foreground`,onClick:()=>r(e=>!e),children:n?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)($p,{className:`size-3 mr-1`}),`收起`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Xp,{className:`size-3 mr-1`}),`展开全文`]})})]})}function Lhe(){let{id:e}=it(),n=et(),[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(null);if((0,y.useEffect)(()=>{if(!e)return;let n=e;async function r(){try{o(!0),c(null),i(await _he(n))}catch(e){console.error(`Failed to load cluster detail:`,e),c(`加载簇详情失败`),G.error(`加载簇详情失败`)}finally{o(!1)}}r()},[e]),a)return(0,K.jsxs)(`div`,{className:`space-y-6 max-w-5xl mx-auto`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Tb,{className:`size-8`}),(0,K.jsx)(Tb,{className:`h-6 w-32`})]}),(0,K.jsx)(Tb,{className:`h-8 w-3/4`}),(0,K.jsx)(Tb,{className:`h-4 w-1/2`}),(0,K.jsx)(`div`,{className:`space-y-3`,children:[1,2,3].map(e=>(0,K.jsx)(Tb,{className:`h-20 w-full rounded-lg`},e))})]});if(s||!r)return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(J,{variant:`ghost`,size:`sm`,onClick:()=>n(`/clusters/list`),children:[(0,K.jsx)(Bp,{className:`size-4 mr-1.5`}),`返回列表`]}),(0,K.jsx)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-sm text-destructive`,children:s||`簇不存在`})]});let{cluster:l,members:u}=r;return(0,K.jsxs)(`div`,{className:`space-y-6 max-w-5xl mx-auto`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(J,{variant:`ghost`,size:`sm`,onClick:()=>n(`/clusters/list`),children:[(0,K.jsx)(Bp,{className:`size-4 mr-1.5`}),`返回列表`]}),(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,K.jsx)(hJ,{variant:`outline`,className:`text-xs ${SJ(l.category)}`,children:CJ(l.category)})})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:l.title||`未命名簇`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm text-muted-foreground flex-wrap`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(qp,{className:`size-3.5`}),`创建于 `,R9(l.created_at)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(nm,{className:`size-3.5`}),`更新于 `,R9(l.updated_at)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(nh,{className:`size-3.5`}),l.member_count,` 条成员记忆`]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(pm,{className:`size-3.5`}),l.id.slice(0,8),`...`]}),l.importance>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(Jp,{className:`size-3.5`}),`重要性 `,l.importance.toFixed(2)]})]})]}),l.keywords&&l.keywords.length>0&&(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsxs)(Sb,{className:`flex items-center gap-1.5 text-base`,children:[(0,K.jsx)(Jm,{className:`size-4 text-muted-foreground`}),`关键词`]})}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:l.keywords.map(e=>(0,K.jsx)(hJ,{variant:`secondary`,className:`font-normal`,children:e},e))})})]}),(0,K.jsx)(m7,{}),(0,K.jsxs)(bb,{className:`border-primary/20 bg-primary/5 dark:bg-primary/10`,children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsxs)(Sb,{className:`flex items-center gap-1.5 text-base`,children:[(0,K.jsx)(km,{className:`size-4 text-primary`}),`合并后摘要`,(0,K.jsx)(hJ,{variant:`outline`,className:`text-xs ml-1 text-primary border-primary/30`,children:`Merged`})]})}),(0,K.jsx)(wb,{children:l.summary?(0,K.jsx)(`div`,{className:`prose prose-sm dark:prose-invert max-w-none text-sm leading-relaxed`,children:(0,K.jsx)(p0,{remarkPlugins:[Y4],children:l.summary})}):(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`暂无合并摘要`})})]}),(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold flex items-center gap-2`,children:[(0,K.jsx)(lm,{className:`size-5 text-muted-foreground`}),`原始记忆`,(0,K.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,u.length,` 条)`]})]}),u.length===0?(0,K.jsx)(`div`,{className:`rounded-lg border border-border bg-card p-8 text-center space-y-2`,children:(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`此簇暂无成员记忆`})}):(0,K.jsx)(`div`,{className:`space-y-3`,children:u.map((e,n)=>(0,K.jsxs)(`div`,{className:`rounded-lg border border-border bg-card p-4 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,K.jsxs)(`span`,{className:`font-mono bg-muted px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,n+1]}),(0,K.jsx)(hJ,{variant:`outline`,className:`text-xs ${SJ(e.category)}`,children:CJ(e.category)}),e.importance>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(Jp,{className:`size-3`}),e.importance.toFixed(2)]}),(0,K.jsxs)(`span`,{className:`ml-auto flex items-center gap-1`,children:[(0,K.jsx)(qp,{className:`size-3`}),Phe(e.created_at)]})]}),(0,K.jsx)(Ihe,{content:e.content||`—`})]},e.id))})]})]})}async function Rhe(){return ib.get(`/v1/stats/config`)}async function zhe(e=50){return ib.get(`/v1/tier-changes`,{params:{limit:e}})}async function Bhe(){return ib.post(`/v1/lifecycle/trigger`,{})}var B9=6,Vhe={access_via_get:`访问触发`,access_via_search:`搜索触发`,access_via_recall:`召回触发`,access_via_cross_space_search:`跨空间搜索触发`,scheduled_evaluation:`定时评估`},V9={peripheral:0,working:1,core:2};function Hhe(){let e=new Date,n=B9-e.getHours()%B9,r=new Date(e.getTime()+n*36e5);return r.setMinutes(0,0,0),r.toLocaleString(`zh-CN`)}function Uhe(e,n){let r=[];for(let i=0;i<=120;i+=2){let a=Math.log(2)/n,o=Math.exp(-a*i**+e);r.push({day:`D${i}`,Core:e<1?Math.max(o,.9):o*.95,Working:o,Peripheral:o*.85})}return r}function Whe(){return(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[1,2].map(e=>(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsx)(Tb,{className:`h-4 w-28`})}),(0,K.jsxs)(wb,{className:`space-y-2`,children:[(0,K.jsx)(Tb,{className:`h-4 w-full`}),(0,K.jsx)(Tb,{className:`h-4 w-3/4`}),(0,K.jsx)(Tb,{className:`h-4 w-1/2`})]})]},e))})}function Ghe(){return(0,K.jsx)(`div`,{className:`space-y-2`,children:[1,2,3,4].map(e=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3`,children:[(0,K.jsx)(Tb,{className:`h-4 w-4`}),(0,K.jsx)(Tb,{className:`h-3 w-24`}),(0,K.jsx)(Tb,{className:`h-5 w-14`}),(0,K.jsx)(Tb,{className:`h-3 w-4`}),(0,K.jsx)(Tb,{className:`h-5 w-14`}),(0,K.jsx)(Tb,{className:`h-3 flex-1`})]},e))})}function Khe(){let[e,n]=(0,y.useState)(null),[r,i]=(0,y.useState)([]),[a,o]=(0,y.useState)(0),[s,c]=(0,y.useState)(!0),[l,u]=(0,y.useState)(!0),[d,f]=(0,y.useState)(20),[p,m]=(0,y.useState)(!1),h=async()=>{try{c(!0),n(await Rhe())}catch(e){console.error(`Failed to load lifecycle config:`,e),G.error(`加载生命周期配置失败`)}finally{c(!1)}},g=async()=>{try{u(!0);let e=await zhe(d);i(e.changes||[]),o(e.totalCount||0)}catch(e){console.error(`Failed to load tier changes:`,e),G.error(`加载升降级历史失败`)}finally{u(!1)}};(0,y.useEffect)(()=>{h(),g()},[]),(0,y.useEffect)(()=>{g()},[d]);let _=()=>{h(),g()},v=async()=>{try{m(!0);let e=await Bhe();G.success(e.message),h(),g()}catch(e){console.error(`Failed to trigger lifecycle:`,e),G.error(`触发生命周期失败`)}finally{m(!1)}},b=e?Uhe(e.decay.tiers?.working?.beta??1,e.decay.half_life_days):[],x=r.filter(e=>(V9[e.from]??0)<(V9[e.to]??0)).length,S=r.filter(e=>(V9[e.from]??0)>=(V9[e.to]??0)).length;return(0,K.jsxs)(`div`,{className:`space-y-6 max-w-6xl mx-auto`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-semibold tracking-tight flex items-center gap-2`,children:[(0,K.jsx)(Ym,{className:`size-5`}),`生命周期管理`]}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`记忆衰减、升降级、自动遗忘的生命周期策略`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:_,disabled:s&&l,children:[(0,K.jsx)(zm,{className:`h-4 w-4 mr-1`}),`刷新`]}),(0,K.jsxs)(J,{variant:`default`,size:`sm`,onClick:v,disabled:p,children:[p?(0,K.jsx)(wm,{className:`h-4 w-4 mr-1 animate-spin`}):(0,K.jsx)(ih,{className:`h-4 w-4 mr-1`}),`立即执行`]})]})]}),(0,K.jsxs)(bb,{children:[(0,K.jsxs)(xb,{className:`pb-3`,children:[(0,K.jsxs)(Sb,{className:`text-sm font-medium flex items-center gap-2`,children:[(0,K.jsx)(nm,{className:`size-4 text-violet-500`}),`调度器状态`]}),(0,K.jsx)(Cb,{children:`自动评估与遗忘任务的运行状态`})]}),(0,K.jsxs)(wb,{children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,K.jsxs)(`div`,{className:`p-3 rounded-lg border`,children:[(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`调度间隔`}),(0,K.jsxs)(`p`,{className:`text-lg font-semibold mt-1`,children:[`每 `,B9,` 小时`]})]}),(0,K.jsxs)(`div`,{className:`p-3 rounded-lg border`,children:[(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`预计下次运行`}),(0,K.jsx)(`p`,{className:`text-sm font-semibold mt-1`,children:Hhe()})]}),(0,K.jsxs)(`div`,{className:`p-3 rounded-lg border`,children:[(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`启动时运行`}),(0,K.jsx)(`div`,{className:`mt-1`,children:(0,K.jsx)(hJ,{variant:`outline`,className:`bg-emerald-500/10 text-emerald-600 border-emerald-500/30`,children:`已启用`})})]})]}),(0,K.jsx)(`div`,{className:`mt-4 p-3 rounded-lg border border-dashed text-xs text-muted-foreground space-y-1`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(om,{className:`size-3.5`}),(0,K.jsx)(`span`,{children:`调度器将自动执行:Weibull 衰减计算、Tier 评估升降级、关键词 TTL 检测、Superseded 归档清理`})]})})]})]}),s?(0,K.jsx)(Whe,{}):e?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{className:`pb-3`,children:(0,K.jsxs)(Sb,{className:`text-sm font-medium flex items-center gap-2`,children:[(0,K.jsx)(Rp,{className:`size-4 text-blue-500`}),`衰减参数`]})}),(0,K.jsxs)(wb,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 text-sm`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`默认半衰期`}),(0,K.jsxs)(`p`,{className:`font-semibold`,children:[e.decay.half_life_days,` 天`]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`Stale 阈值`}),(0,K.jsx)(`p`,{className:`font-semibold`,children:`0.3`})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`权重分配`}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(hJ,{variant:`outline`,className:`bg-blue-500/10 text-blue-600 border-blue-500/30 text-xs`,children:[`时效 `,e.decay.recency_weight]}),(0,K.jsxs)(hJ,{variant:`outline`,className:`bg-emerald-500/10 text-emerald-600 border-emerald-500/30 text-xs`,children:[`频率 `,e.decay.frequency_weight]}),(0,K.jsxs)(hJ,{variant:`outline`,className:`bg-violet-500/10 text-violet-600 border-violet-500/30 text-xs`,children:[`内在 `,e.decay.intrinsic_weight]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Tier 衰减速率 (β)`}),(0,K.jsx)(`div`,{className:`flex gap-2`,children:Object.entries(e.decay.tiers||{}).map(([e,n])=>(0,K.jsxs)(hJ,{variant:`outline`,className:`text-xs ${EJ(e)}`,children:[wJ(e),` β=`,n.beta]},e))})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Tier 底线分数`}),(0,K.jsx)(`div`,{className:`flex gap-2`,children:Object.entries(e.decay.tiers||{}).map(([e,n])=>(0,K.jsxs)(hJ,{variant:`outline`,className:`text-xs ${EJ(e)}`,children:[wJ(e),` ≥`,n.floor]},e))})]})]})]}),(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{className:`pb-3`,children:(0,K.jsxs)(Sb,{className:`text-sm font-medium flex items-center gap-2`,children:[(0,K.jsx)(Zm,{className:`size-4 text-emerald-500`}),`升降级规则`]})}),(0,K.jsxs)(wb,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`p-3 rounded-lg border space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,K.jsx)(Up,{className:`size-4 text-emerald-500`}),(0,K.jsx)(hJ,{variant:`outline`,className:EJ(`peripheral`),children:wJ(`peripheral`)}),(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`→`}),(0,K.jsx)(hJ,{variant:`outline`,className:EJ(`working`),children:wJ(`working`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 text-xs`,children:[(0,K.jsxs)(`span`,{className:`text-muted-foreground`,children:[`访问 ≥`,e.promotion.peripheral_to_working.min_access_count,`次`]}),(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,K.jsxs)(`span`,{className:`text-muted-foreground`,children:[`综合 ≥`,e.promotion.peripheral_to_working.min_composite]})]})]}),(0,K.jsxs)(`div`,{className:`p-3 rounded-lg border space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,K.jsx)(Up,{className:`size-4 text-emerald-500`}),(0,K.jsx)(hJ,{variant:`outline`,className:EJ(`working`),children:wJ(`working`)}),(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`→`}),(0,K.jsx)(hJ,{variant:`outline`,className:EJ(`core`),children:wJ(`core`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 text-xs`,children:[(0,K.jsxs)(`span`,{className:`text-muted-foreground`,children:[`访问 ≥`,e.promotion.working_to_core.min_access_count,`次`]}),(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,K.jsxs)(`span`,{className:`text-muted-foreground`,children:[`综合 ≥`,e.promotion.working_to_core.min_composite]}),e.promotion.working_to_core.min_importance!=null&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,K.jsxs)(`span`,{className:`text-muted-foreground`,children:[`重要性 ≥`,e.promotion.working_to_core.min_importance]})]})]})]}),(0,K.jsx)(`div`,{className:`p-3 rounded-lg border border-dashed space-y-1 text-xs text-muted-foreground`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(zp,{className:`size-3.5 text-red-400`}),(0,K.jsx)(`span`,{children:`不满足条件时自动降级至低等级`})]})})]})]})]}),b.length>0&&(0,K.jsxs)(bb,{children:[(0,K.jsxs)(xb,{className:`pb-2`,children:[(0,K.jsxs)(Sb,{className:`text-sm font-medium flex items-center gap-2`,children:[(0,K.jsx)(ih,{className:`size-4 text-amber-500`}),`衰减曲线预览`]}),(0,K.jsx)(Cb,{children:`基于当前配置参数生成的理论衰减趋势`})]}),(0,K.jsx)(wb,{children:(0,K.jsx)(`div`,{className:`h-64`,children:(0,K.jsx)(oD,{width:`100%`,height:`100%`,children:(0,K.jsxs)(Jq,{data:b,children:[(0,K.jsx)(KW,{strokeDasharray:`3 3`,className:`opacity-30`}),(0,K.jsx)(oK,{dataKey:`day`,tick:{fontSize:11},interval:14,label:{value:`天数`,position:`insideBottomRight`,offset:-5,fontSize:11}}),(0,K.jsx)(CK,{domain:[0,1],tick:{fontSize:11},label:{value:`分数`,angle:-90,position:`insideLeft`,fontSize:11}}),(0,K.jsx)(VE,{contentStyle:{fontSize:12,borderRadius:8},formatter:e=>[e.toFixed(3)]}),(0,K.jsx)(FT,{iconType:`line`,wrapperStyle:{fontSize:12}}),(0,K.jsx)(bG,{type:`monotone`,dataKey:`Core`,stroke:`#f59e0b`,strokeWidth:2,dot:!1,name:`核心 (Core)`}),(0,K.jsx)(bG,{type:`monotone`,dataKey:`Working`,stroke:`#10b981`,strokeWidth:2,dot:!1,name:`工作区 (Working)`}),(0,K.jsx)(bG,{type:`monotone`,dataKey:`Peripheral`,stroke:`#94a3b8`,strokeWidth:2,dot:!1,name:`边缘 (Peripheral)`})]})})})})]})]}):(0,K.jsx)(bb,{children:(0,K.jsx)(wb,{className:`py-8 text-center`,children:(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`无法加载生命周期配置`})})}),(0,K.jsxs)(bb,{children:[(0,K.jsx)(xb,{className:`pb-2`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(Sb,{className:`text-sm font-medium`,children:`升降级历史`}),(0,K.jsx)(Cb,{children:`最近的 Tier 变更记录`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(hJ,{variant:`outline`,className:`bg-emerald-500/10 text-emerald-600 border-emerald-500/30 text-xs`,children:[`↑ 升级 `,x]}),(0,K.jsxs)(hJ,{variant:`outline`,className:`bg-red-500/10 text-red-600 border-red-500/30 text-xs`,children:[`↓ 降级 `,S]}),(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`共 `,a,` 条`]})]})]})}),(0,K.jsx)(wb,{className:`p-0`,children:l?(0,K.jsx)(Ghe,{}):r.length===0?(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground py-12 text-center`,children:`暂无变更记录`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`divide-y`,children:r.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 hover:bg-muted/30 transition-colors`,children:[(V9[e.from]??0)<(V9[e.to]??0)?(0,K.jsx)(Up,{className:`size-4 text-emerald-500 shrink-0`}):(0,K.jsx)(zp,{className:`size-4 text-red-500 shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground w-36 shrink-0`,children:new Date(e.at).toLocaleString(`zh-CN`)}),(0,K.jsx)(hJ,{variant:`outline`,className:EJ(e.from),children:wJ(e.from)}),(0,K.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`→`}),(0,K.jsx)(hJ,{variant:`outline`,className:EJ(e.to),children:wJ(e.to)}),(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground w-20 shrink-0`,children:Vhe[e.reason]||e.reason}),(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground w-12 shrink-0`,children:[`#`,e.accessCount]}),(0,K.jsx)(`span`,{className:`text-xs flex-1 min-w-0 truncate text-muted-foreground`,children:e.memoryTitle||e.memoryId?.slice(0,12)||`—`}),(0,K.jsx)(`span`,{className:`text-xs font-mono text-muted-foreground shrink-0`,children:e.memoryId?`${e.memoryId.slice(0,8)}...`:`—`})]},`${e.memoryId}-${e.at}-${e.from}-${e.to}`))}),r.length<a&&(0,K.jsx)(`div`,{className:`flex items-center justify-center px-4 py-3 border-t`,children:(0,K.jsx)(J,{variant:`ghost`,size:`sm`,onClick:()=>f(e=>e+20),children:`加载更多`})})]})})]})]})}function qhe(){let e=et(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(!1),u=(0,y.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),e.type===`dragenter`||e.type===`dragover`?l(!0):e.type===`dragleave`&&l(!1)},[]),d=(0,y.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),l(!1),e.dataTransfer.files&&e.dataTransfer.files[0]&&(r(e.dataTransfer.files[0]),s(null))},[]);return(0,K.jsxs)(`div`,{className:`space-y-6 max-w-3xl`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(J,{variant:`ghost`,size:`icon`,onClick:()=>e(`/memories`),children:(0,K.jsx)(Bp,{className:`h-4 w-4`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`批量导入`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`从 JSON、CSV 或 Markdown 文件导入记忆`})]})]}),(0,K.jsx)(bb,{className:`border-2 border-dashed p-8 transition-colors ${c?`border-primary bg-primary/5`:`border-border`}`,onDragEnter:u,onDragLeave:u,onDragOver:u,onDrop:d,children:(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-4 text-center`,children:[(0,K.jsx)($m,{className:`h-10 w-10 text-muted-foreground`}),(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium`,children:n?n.name:`拖拽文件到此处,或点击选择`}),(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`支持 JSON、CSV、Markdown 格式`})]}),(0,K.jsx)(`input`,{type:`file`,accept:`.json,.csv,.md,.markdown`,onChange:e=>{e.target.files&&e.target.files[0]&&(r(e.target.files[0]),s(null))},className:`hidden`,id:`file-upload`}),(0,K.jsx)(J,{variant:`outline`,size:`sm`,onClick:()=>document.getElementById(`file-upload`)?.click(),children:`选择文件`})]})}),n&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border border-border bg-card p-4`,children:[(e=>e.endsWith(`.json`)?(0,K.jsx)(sm,{className:`h-8 w-8 text-blue-500`}):e.endsWith(`.csv`)?(0,K.jsx)(cm,{className:`h-8 w-8 text-green-500`}):e.endsWith(`.md`)||e.endsWith(`.markdown`)?(0,K.jsx)(lm,{className:`h-8 w-8 text-purple-500`}):(0,K.jsx)(lm,{className:`h-8 w-8 text-muted-foreground`}))(n.name),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium truncate`,children:n.name}),(0,K.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[(n.size/1024).toFixed(1),` KB`]})]}),(0,K.jsx)(J,{onClick:async()=>{if(!n){G.error(`请先选择文件`);return}let e=new FormData;e.append(`file`,n);let r=n.name.endsWith(`.json`)?`json`:n.name.endsWith(`.csv`)?`csv`:`md`;e.append(`format`,r),a(!0);try{let n=await ib.post(`/v1/imports`,e,{headers:{"Content-Type":`multipart/form-data`}});s({success:!0,imported:n.imported||0,failed:n.failed||0,errors:n.errors}),G.success(`成功导入 ${n.imported||0} 条记忆`)}catch(e){let n=e.response?.data?.error||e.message||`导入失败`;s({success:!1,imported:0,failed:0,errors:[n]}),G.error(n)}finally{a(!1)}},disabled:i,size:`sm`,children:i?`导入中...`:`开始导入`})]}),o&&(0,K.jsxs)(bb,{className:`p-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[o.success?(0,K.jsx)(em,{className:`h-5 w-5 text-green-500`}):(0,K.jsx)(tm,{className:`h-5 w-5 text-red-500`}),(0,K.jsx)(`h3`,{className:`font-semibold`,children:o.success?`导入成功`:`导入失败`})]}),o.success&&(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{className:`rounded-lg bg-green-500/10 p-4 text-center`,children:[(0,K.jsx)(`p`,{className:`text-2xl font-bold text-green-500`,children:o.imported}),(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`成功导入`})]}),(0,K.jsxs)(`div`,{className:`rounded-lg bg-red-500/10 p-4 text-center`,children:[(0,K.jsx)(`p`,{className:`text-2xl font-bold text-red-500`,children:o.failed}),(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`导入失败`})]})]}),o.errors&&o.errors.length>0&&(0,K.jsxs)(`div`,{className:`mt-4 space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-red-500`,children:`错误信息:`}),o.errors.map(e=>(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e},e))]})]}),(0,K.jsxs)(bb,{className:`p-6`,children:[(0,K.jsx)(`h3`,{className:`font-semibold mb-3`,children:`支持格式说明`}),(0,K.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(sm,{className:`h-4 w-4 text-blue-500 mt-0.5`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`font-medium`,children:`JSON`}),(0,K.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`标准 JSON 数组格式,每条记忆包含 content, tags, category 等字段`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(cm,{className:`h-4 w-4 text-green-500 mt-0.5`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`font-medium`,children:`CSV`}),(0,K.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`包含列:content, tags, category, importance, confidence`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(lm,{className:`h-4 w-4 text-purple-500 mt-0.5`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`font-medium`,children:`Markdown`}),(0,K.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`每条记忆用标题分隔,支持 frontmatter 元数据`})]})]})]})]})]})}function Jhe(){let{theme:e,setTheme:n}=Sr(),{hasPassword:r,setPassword:i,lock:a}=ob(),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(!1);return(0,K.jsxs)(`div`,{className:`space-y-6 max-w-2xl`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`系统设置`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`管理您的偏好设置和数据`})]}),(0,K.jsxs)(bb,{className:`p-6`,children:[(0,K.jsx)(`h3`,{className:`font-semibold mb-4`,children:`外观`}),(0,K.jsx)(`div`,{className:`space-y-4`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(gb,{className:`text-sm font-medium`,children:`主题模式`}),(0,K.jsxs)(`div`,{className:`flex gap-2 mt-2`,children:[(0,K.jsxs)(J,{variant:e===`light`?`default`:`outline`,size:`sm`,onClick:()=>n(`light`),className:`gap-2`,children:[(0,K.jsx)(qm,{className:`h-4 w-4`}),`亮色`]}),(0,K.jsxs)(J,{variant:e===`dark`?`default`:`outline`,size:`sm`,onClick:()=>n(`dark`),className:`gap-2`,children:[(0,K.jsx)(jm,{className:`h-4 w-4`}),`暗黑`]}),(0,K.jsxs)(J,{variant:e===`system`?`default`:`outline`,size:`sm`,onClick:()=>n(`system`),className:`gap-2`,children:[(0,K.jsx)(Am,{className:`h-4 w-4`}),`跟随系统`]})]})]})})]}),(0,K.jsxs)(bb,{className:`p-6`,children:[(0,K.jsx)(`h3`,{className:`font-semibold mb-4`,children:`私密空间 Vault`}),(0,K.jsxs)(`div`,{className:`space-y-4`,children:[r?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Vault 密码已设置。私密记忆需要输入密码才能查看。`}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>l(!c),children:[(0,K.jsx)(Em,{className:`h-4 w-4 mr-2`}),`修改密码`]}),(0,K.jsxs)(J,{variant:`destructive`,size:`sm`,onClick:()=>p(!0),children:[(0,K.jsx)(Xm,{className:`h-4 w-4 mr-2`}),`重置 Vault`]})]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`尚未设置 Vault 密码。设置后,私密记忆将受到密码保护。`}),(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>l(!0),children:[(0,K.jsx)(Em,{className:`h-4 w-4 mr-2`}),`设置 Vault 密码`]})]}),c&&(0,K.jsxs)(`div`,{className:`flex gap-2 mt-4`,children:[(0,K.jsx)(`input`,{type:`password`,placeholder:`输入新密码`,value:o,onChange:e=>s(e.target.value),className:`flex-1 rounded-md border border-input bg-background px-3 py-2 text-sm`}),(0,K.jsx)(J,{size:`sm`,onClick:()=>{if(!o||o.length<4){G.error(`密码至少需要 4 位`);return}i(o),G.success(`Vault 密码已设置`),s(``),l(!1)},children:`确认`})]})]})]}),(0,K.jsxs)(bb,{className:`p-6`,children:[(0,K.jsx)(`h3`,{className:`font-semibold mb-4`,children:`数据管理`}),(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm font-medium`,children:`导出记忆数据`}),(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`从服务端导出所有记忆为 JSON 文件`})]}),(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:async()=>{d(!0);try{let e=await ib.get(`/v1/memories`,{params:{limit:1e4}}),n={memories:e.memories||[],total_count:e.total_count||0,exportedAt:new Date().toISOString()},r=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=`omem-memories-${new Date().toISOString().slice(0,10)}.json`,a.click(),URL.revokeObjectURL(i),G.success(`已导出 ${n.total_count} 条记忆`)}catch(e){console.error(`Failed to export memories:`,e),G.error(`导出记忆数据失败`)}finally{d(!1)}},disabled:u,children:[(0,K.jsx)(eee,{className:`h-4 w-4 mr-2`}),u?`导出中...`:`导出`]})]}),(0,K.jsx)(m7,{}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm font-medium`,children:`导出本地配置`}),(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`将登录信息、主题等本地设置导出备份`})]}),(0,K.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>{let e={auth:JSON.parse(sessionStorage.getItem(`omem-auth`)||`{}`),vault:`已迁移到服务端存储`,theme:localStorage.getItem(`omem-theme`)||`system`,exportedAt:new Date().toISOString()},n=new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`omem-config-${new Date().toISOString().slice(0,10)}.json`,i.click(),URL.revokeObjectURL(r),G.success(`本地配置已导出`)},children:[(0,K.jsx)(tee,{className:`h-4 w-4 mr-2`}),`导出`]})]}),(0,K.jsx)(m7,{}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm font-medium`,children:`清除缓存`}),(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`清除所有本地存储的数据(不可逆)`})]}),(0,K.jsxs)(J,{variant:`destructive`,size:`sm`,onClick:()=>{sessionStorage.clear(),G.success(`缓存已清除`,{description:`所有本地数据已清除,刷新页面后生效`})},children:[(0,K.jsx)(Xm,{className:`h-4 w-4 mr-2`}),`清除`]})]})]})]}),(0,K.jsxs)(bb,{className:`p-6`,children:[(0,K.jsx)(`h3`,{className:`font-semibold mb-4`,children:`关于`}),(0,K.jsxs)(`div`,{className:`space-y-2 text-sm`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(vm,{className:`h-4 w-4 text-muted-foreground`}),(0,K.jsx)(`span`,{children:`omem-web v0.1.0`})]}),(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`omem 自部署版 Web 管理端`}),(0,K.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`备案号:`,(0,K.jsx)(`a`,{href:`https://beian.miit.gov.cn`,target:`_blank`,rel:`noopener noreferrer`,className:`underline`,children:`吉ICP备2026003061号`})]})]})]}),(0,K.jsx)(aJ,{open:f,onOpenChange:p,children:(0,K.jsxs)(oJ,{children:[(0,K.jsxs)(sJ,{children:[(0,K.jsx)(lJ,{children:`确认重置 Vault`}),(0,K.jsx)(uJ,{children:`此操作不可恢复。重置后所有受 Vault 保护的私密记忆将无法访问。`})]}),(0,K.jsxs)(cJ,{children:[(0,K.jsx)(fJ,{onClick:()=>p(!1),children:`取消`}),(0,K.jsx)(dJ,{onClick:async()=>{try{await ib.delete(`/v1/vault/password`),a(),G.success(`Vault 已重置`),l(!1),p(!1)}catch{G.error(`重置 Vault 失败`)}},className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`确认重置`})]})]})})]})}function H9(e){return`/v2/profile${e}`}var U9={getPreferences(e){return ib.get(H9(`/preferences`),{params:e?{project_path:e}:void 0})},getPreference(e){return ib.get(H9(`/preferences/${e}`))},createPreference(e){return ib.post(H9(`/preferences`),e)},updatePreference(e,n){return ib.put(H9(`/preferences/${e}`),n)},deletePreference(e){return ib.delete(H9(`/preferences/${e}`))},getStats(e){return ib.get(H9(`/stats`),{params:e?{project_path:e}:void 0})},getInjection(e){return ib.get(H9(`/inject`),{params:e?{project_path:e}:void 0})},triggerInduction(e,n){return ib.post(H9(`/induction/trigger`),{candidate_texts:e??[],project_path:n})},getInductionRuns(e){return ib.get(H9(`/induction/runs`),{params:e?{project_path:e}:void 0})},getVersions(e){return ib.get(H9(`/versions`),{params:e?{project_path:e}:void 0})},getChangelog(e){return ib.get(H9(`/changelog`),{params:e?{project_path:e}:void 0})}};function W9(e){let n=e.toLowerCase();return n.includes(`喜欢`)||n.includes(`偏好`)||n.includes(`习惯`)?{type:`preference`,icon:Sm,color:`text-amber-600 dark:text-amber-400`,bgColor:`bg-amber-50 dark:bg-amber-500/10 border-amber-200 dark:border-amber-500/30`,label:`偏好`}:n.includes(`项目`)||n.includes(`工程`)||n.includes(`开发`)?{type:`project`,icon:ih,color:`text-blue-600 dark:text-blue-400`,bgColor:`bg-blue-50 dark:bg-blue-500/10 border-blue-200 dark:border-blue-500/30`,label:`项目`}:n.includes(`技能`)||n.includes(`能力`)||n.includes(`精通`)||n.includes(`熟练`)?{type:`skill`,icon:Gm,color:`text-violet-600 dark:text-violet-400`,bgColor:`bg-violet-50 dark:bg-violet-500/10 border-violet-200 dark:border-violet-500/30`,label:`技能`}:n.includes(`笔记`)||n.includes(`记录`)||n.includes(`文档`)?{type:`note`,icon:Wp,color:`text-slate-600 dark:text-slate-400`,bgColor:`bg-slate-50 dark:bg-slate-500/10 border-slate-200 dark:border-slate-500/30`,label:`笔记`}:{type:`fact`,icon:th,color:`text-emerald-600 dark:text-emerald-400`,bgColor:`bg-emerald-50 dark:bg-emerald-500/10 border-emerald-200 dark:border-emerald-500/30`,label:`事实`}}function Yhe(){return{type:`private`,icon:Em,color:`text-amber-600 dark:text-amber-400`,bgColor:`bg-amber-50 dark:bg-amber-500/10 border-amber-200 dark:border-amber-500/30`,label:`私密`}}function G9(e){return e.replace(/^#+\s*/,``).trim()}function Xhe(e,n){return n===`private`?!0:e.some(e=>e===`私密`||e.toLowerCase()===`private`)}function Zhe(e){return new Date(e).toLocaleString(`zh-CN`,{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function K9(e){let n=Date.now()-new Date(e).getTime(),r=Math.floor(n/6e4);if(r<1)return`刚刚`;if(r<60)return`${r} 分钟前`;let i=Math.floor(r/60);if(i<24)return`${i} 小时前`;let a=Math.floor(i/24);return a<30?`${a} 天前`:Zhe(e)}function q9({content:e}){let[n,r]=(0,y.useState)(!1),i=(0,y.useRef)(null),[a,o]=(0,y.useState)(!1);return(0,y.useEffect)(()=>{let e=i.current;if(!e)return;let n=new ResizeObserver(()=>o(e.scrollHeight>e.clientHeight));return n.observe(e),()=>n.disconnect()},[]),(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:wp(`relative`,!n&&`max-h-60 overflow-hidden`),children:[(0,K.jsx)(`div`,{ref:i,className:`prose prose-sm dark:prose-invert max-w-none`,children:(0,K.jsx)(p0,{remarkPlugins:[Y4],children:e})}),!n&&a&&(0,K.jsx)(`div`,{className:`absolute bottom-0 left-0 right-0 h-10 bg-gradient-to-t from-background to-transparent pointer-events-none`})]}),a&&(0,K.jsx)(J,{variant:`ghost`,size:`sm`,className:`mt-1 h-auto py-1 px-2 text-xs text-muted-foreground hover:text-foreground`,onClick:()=>r(!n),children:n?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)($p,{className:`size-3 mr-1`}),`收起`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Xp,{className:`size-3 mr-1`}),`展开全文`]})})]})}var Qhe=[{name:`communication_style`,display:`沟通风格`},{name:`tone`,display:`语气偏好`},{name:`code_style`,display:`代码风格`},{name:`error_handling`,display:`错误处理`},{name:`naming_convention`,display:`命名规范`},{name:`testing_strategy`,display:`测试策略`},{name:`workflow_preference`,display:`工作流偏好`},{name:`commit_style`,display:`提交风格`},{name:`emoji_preference`,display:`Emoji偏好`},{name:`self_reference`,display:`自称方式`},{name:`address_style`,display:`称呼方式`},{name:`language`,display:`语言`},{name:`framework_preference`,display:`框架偏好`},{name:`preferred_tools`,display:`工具偏好`}],$he={communication_style:`沟通风格`,coding_preferences:`编码偏好`,project_context:`项目上下文`,tool_preferences:`工具偏好`,domain_knowledge:`领域知识`,work_style:`工作风格`,language_preference:`语言偏好`,framework_preferences:`框架偏好`},ege={communication_style:Rp,coding_preferences:ih,project_context:um,tool_preferences:bm,domain_knowledge:Wp,work_style:Rm,language_preference:Sm,framework_preferences:Gm};function tge(e){return $he[e]||e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function nge(e){return ege[e]||bm}var rge={global:{className:`bg-blue-50 dark:bg-blue-500/10 text-blue-700 dark:text-blue-300 border-blue-200 dark:border-blue-500/30`,label:`全局`},project:{className:`bg-violet-50 dark:bg-violet-500/10 text-violet-700 dark:text-violet-300 border-violet-200 dark:border-violet-500/30`,label:`项目`},session:{className:`bg-emerald-50 dark:bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 border-emerald-200 dark:border-emerald-500/30`,label:`会话`}};function ige(){let e=et(),n=ob(e=>e.unlock),r=ob(e=>e.hasPassword),i=ob(e=>e.isUnlocked),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)([]),[d,f]=(0,y.useState)([]),[p,m]=(0,y.useState)(!0),[h,g]=(0,y.useState)(`preferences`),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(``),[E,D]=(0,y.useState)(null),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(new Set),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(null),[I,L]=(0,y.useState)(!1),[R,z]=(0,y.useState)(null),[ee,B]=(0,y.useState)(!1),[V,H]=(0,y.useState)(``),[U,te]=(0,y.useState)(`all`),[W,ne]=(0,y.useState)(1);(0,y.useEffect)(()=>{async function e(){try{m(!0);let e=_||void 0,[n,r,i,a]=await Promise.all([ib.get(`/v1/profile`).catch(()=>null),U9.getStats(e).catch(()=>null),U9.getPreferences(e).catch(()=>[]),U9.getChangelog(e).catch(()=>[])]);n&&o(n),r&&c(r),u(Array.isArray(i)?i:[]),f(Array.isArray(a)?a:[])}catch(e){console.error(`Failed to load profile:`,e),G.error(`加载画像数据失败`)}finally{m(!1)}}e()},[_]);let re=async()=>{if(!w.trim()){D(`请输入密码`);return}k(!0);let e=await n(w);if(k(!1),!e){D(`密码错误`);return}S&&j(e=>new Set(e).add(S)),x(!1),C(null),T(``),D(null),G.success(`已解锁`)},ie=e=>{if(i){j(n=>new Set(n).add(e));return}if(!r){G.error(`请先在设置中设置密码`);return}C(e),T(``),D(null),x(!0)},ae=a?.static_facts||[],oe=a?.dynamic_context||[],se=(0,y.useMemo)(()=>ae.map(e=>{let n=Xhe(e.tags||[],e.visibility),r=n?Yhe():W9(e.content);return{fact:e.content,factObj:e,isPrivate:n,meta:r}}),[ae]),ce=(0,y.useMemo)(()=>{let e=new Map;for(let n of l){if(U!==`all`&&n.scope!==U)continue;if(V.trim()){let e=V.toLowerCase();if(!n.value.toLowerCase().includes(e)&&!n.slot.toLowerCase().includes(e)&&!(n.project_path||``).toLowerCase().includes(e))continue}let r=e.get(n.slot)||[];r.push(n),e.set(n.slot,r)}return e},[l,V,U]),le=(0,y.useMemo)(()=>Array.from(ce.entries()),[ce]),ue=Math.max(1,Math.ceil(le.length/5)),de=(0,y.useMemo)(()=>{let e=(W-1)*5;return le.slice(e,e+5)},[le,W]),fe=async()=>{let e=_||void 0,[n,r]=await Promise.all([U9.getPreferences(e),U9.getStats(e).catch(()=>null)]);u(Array.isArray(n)?n:[]),r&&c(r)},pe=async e=>{if(!(!(`slot`in e)||!e.slot))try{L(!0),await U9.createPreference(e),G.success(`偏好已创建`),N(!1),await fe()}catch{G.error(`创建失败`)}finally{L(!1)}},me=async(e,n)=>{try{L(!0),await U9.updatePreference(e,n),G.success(`偏好已更新`),F(null);let r=_||void 0,i=await U9.getPreferences(r);u(Array.isArray(i)?i:[])}catch{G.error(`更新失败`)}finally{L(!1)}},he=async()=>{if(R)try{B(!0),await U9.deletePreference(R.id),G.success(`偏好已删除`),z(null),await fe()}catch{G.error(`删除失败`)}finally{B(!1)}},ge=(0,y.useMemo)(()=>{let e=new Set;for(let n of l)n.project_path&&e.add(n.project_path);return Array.from(e).sort()},[l]),_e=l.length;return(0,K.jsxs)(`div`,{className:`min-h-screen bg-gradient-to-b from-background via-background to-muted/30`,children:[(0,K.jsxs)(`div`,{className:`max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 py-6 space-y-6`,children:[(0,K.jsxs)(J,{variant:`ghost`,size:`sm`,className:`text-muted-foreground hover:text-foreground -ml-2`,onClick:()=>e(-1),children:[(0,K.jsx)(Bp,{className:`size-4 mr-1.5`}),`返回`]}),(0,K.jsxs)(`div`,{className:`relative overflow-hidden rounded-2xl bg-gradient-to-br from-amber-50 via-orange-50 to-rose-50 dark:from-amber-500/10 dark:via-orange-500/5 dark:to-rose-500/10 border border-amber-200/50 dark:border-amber-500/20 p-6 md:p-8`,children:[(0,K.jsx)(`div`,{className:`absolute top-0 right-0 -mt-8 -mr-8 w-48 h-48 bg-amber-400/15 dark:bg-amber-500/10 rounded-full blur-3xl`}),(0,K.jsx)(`div`,{className:`absolute bottom-0 left-0 -mb-6 -ml-6 w-36 h-36 bg-orange-400/10 dark:bg-orange-500/8 rounded-full blur-3xl`}),(0,K.jsxs)(`div`,{className:`relative z-10 flex flex-col md:flex-row md:items-center md:justify-between gap-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center size-14 rounded-2xl bg-gradient-to-br from-amber-400 to-orange-500 shadow-lg shadow-amber-500/25`,children:(0,K.jsx)(th,{className:`size-7 text-white`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl md:text-3xl font-bold tracking-tight text-foreground`,children:`用户画像`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:`偏好 · 记忆 · 洞察`})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2.5 px-4 py-2.5 rounded-xl bg-white/80 dark:bg-card/80 border border-amber-200/60 dark:border-amber-500/20 shadow-sm`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center size-8 rounded-lg bg-amber-100 dark:bg-amber-500/15`,children:(0,K.jsx)(bm,{className:`size-4 text-amber-600 dark:text-amber-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-lg font-bold leading-none text-foreground`,children:_e}),(0,K.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`条偏好`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2.5 px-4 py-2.5 rounded-xl bg-white/80 dark:bg-card/80 border border-orange-200/60 dark:border-orange-500/20 shadow-sm`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center size-8 rounded-lg bg-orange-100 dark:bg-orange-500/15`,children:(0,K.jsx)(Jp,{className:`size-4 text-orange-600 dark:text-orange-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-lg font-bold leading-none text-foreground`,children:s?.total??0}),(0,K.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`归纳总量`})]})]}),s?.last_induction_at&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2.5 px-4 py-2.5 rounded-xl bg-white/80 dark:bg-card/80 border border-rose-200/60 dark:border-rose-500/20 shadow-sm`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center size-8 rounded-lg bg-rose-100 dark:bg-rose-500/15`,children:(0,K.jsx)(nm,{className:`size-4 text-rose-600 dark:text-rose-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm font-semibold leading-none text-foreground`,children:K9(s.last_induction_at)}),(0,K.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`最近归纳`})]})]})]})]})]}),(0,K.jsxs)(x7,{value:h,onValueChange:g,className:`space-y-4`,children:[(0,K.jsxs)(S7,{className:`bg-muted/60 p-1 h-auto`,children:[(0,K.jsxs)(C7,{value:`preferences`,className:`data-[state=active]:bg-background data-[state=active]:shadow-sm gap-1.5 px-4 py-2 text-sm`,children:[(0,K.jsx)(Gm,{className:`size-3.5`}),`偏好管理`]}),(0,K.jsxs)(C7,{value:`overview`,className:`data-[state=active]:bg-background data-[state=active]:shadow-sm gap-1.5 px-4 py-2 text-sm`,children:[(0,K.jsx)(th,{className:`size-3.5`}),`画像概览`]}),(0,K.jsxs)(C7,{value:`changelog`,className:`data-[state=active]:bg-background data-[state=active]:shadow-sm gap-1.5 px-4 py-2 text-sm`,children:[(0,K.jsx)(mm,{className:`size-3.5`}),`变更历史`]})]}),(0,K.jsxs)(w7,{value:`preferences`,className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center gap-3`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1 w-full sm:max-w-xs`,children:[(0,K.jsx)(Vm,{className:`absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground`}),(0,K.jsx)(hb,{placeholder:`搜索偏好...`,value:V,onChange:e=>{H(e.target.value),ne(1)},className:`pl-9 h-9 bg-muted/40`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[ge.length>0&&(0,K.jsxs)(r9,{value:_,onValueChange:e=>e!=null&&v(e),children:[(0,K.jsxs)(a9,{className:`h-9 w-[180px] text-xs`,children:[(0,K.jsx)(um,{className:`size-3.5 mr-1.5 text-muted-foreground`}),(0,K.jsx)(i9,{placeholder:`全部项目`})]}),(0,K.jsxs)(o9,{children:[(0,K.jsx)(s9,{value:`__all__`,children:`全部项目`}),ge.map(e=>(0,K.jsx)(s9,{value:e,children:e.split(`/`).pop()||e},e))]})]}),(0,K.jsxs)(r9,{value:U,onValueChange:e=>{e!=null&&(te(e),ne(1))},children:[(0,K.jsx)(a9,{className:`h-9 w-[100px] text-xs`,children:(0,K.jsx)(i9,{placeholder:`范围`})}),(0,K.jsxs)(o9,{children:[(0,K.jsx)(s9,{value:`all`,children:`全部范围`}),(0,K.jsx)(s9,{value:`global`,children:`全局`}),(0,K.jsx)(s9,{value:`project`,children:`项目`}),(0,K.jsx)(s9,{value:`session`,children:`会话`})]})]})]}),(0,K.jsxs)(J,{className:`ml-auto h-9 gap-1.5 bg-gradient-to-r from-amber-500 to-orange-500 hover:from-amber-600 hover:to-orange-600 text-white shadow-sm`,onClick:()=>N(!0),children:[(0,K.jsx)(Lm,{className:`size-4`}),`新建偏好`]})]}),p?(0,K.jsx)(`div`,{className:`space-y-4`,children:[1,2,3].map(e=>(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(Tb,{className:`h-5 w-24 rounded-md`}),(0,K.jsx)(Tb,{className:`h-24 w-full rounded-xl`})]},e))}):ce.size===0?(0,K.jsx)(bb,{className:`border-dashed`,children:(0,K.jsxs)(wb,{className:`py-16 flex flex-col items-center gap-3 text-muted-foreground`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center size-12 rounded-2xl bg-muted`,children:(0,K.jsx)(Gm,{className:`size-6`})}),(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium`,children:`暂无偏好数据`}),(0,K.jsx)(`p`,{className:`text-xs mt-1`,children:`点击「新建偏好」开始构建你的画像`})]})]})}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{id:`pref-slot-list`,className:`space-y-4`,children:de.map(([e,n])=>(0,K.jsx)(age,{slot:e,preferences:n,onEdit:e=>F(e),onDelete:e=>z(e)},e))}),ue>1&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between pt-2`,children:[(0,K.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`第 `,W,` / `,ue,` 页 · 共 `,le.length,` 个分组`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(J,{variant:`outline`,size:`icon`,className:`size-8`,disabled:W<=1,onClick:()=>{ne(e=>Math.max(1,e-1)),document.getElementById(`pref-slot-list`)?.scrollIntoView({behavior:`smooth`,block:`start`})},children:(0,K.jsx)(Zp,{className:`size-4`})}),Array.from({length:ue},(e,n)=>n+1).map(e=>(0,K.jsx)(J,{variant:e===W?`default`:`outline`,size:`icon`,className:wp(`size-8 text-xs`,e===W&&`bg-gradient-to-r from-amber-500 to-orange-500 text-white border-0`),onClick:()=>{ne(e),document.getElementById(`pref-slot-list`)?.scrollIntoView({behavior:`smooth`,block:`start`})},children:e},e)),(0,K.jsx)(J,{variant:`outline`,size:`icon`,className:`size-8`,disabled:W>=ue,onClick:()=>{ne(e=>Math.min(ue,e+1)),document.getElementById(`pref-slot-list`)?.scrollIntoView({behavior:`smooth`,block:`start`})},children:(0,K.jsx)(Qp,{className:`size-4`})})]})]})]})]}),(0,K.jsx)(w7,{value:`overview`,className:`space-y-6`,children:p?(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[1,2,3,4].map(e=>(0,K.jsx)(Tb,{className:`h-48 w-full rounded-xl`},e))}):(0,K.jsxs)(K.Fragment,{children:[se.length>0&&(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Um,{className:`size-5 text-amber-500`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold`,children:`画像特征`}),(0,K.jsxs)(hJ,{variant:`secondary`,className:`text-[10px]`,children:[se.length,` 条`]})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:se.map(({fact:e,factObj:n,isPrivate:r,meta:i})=>{let a=i.icon,o=A.has(e),s=r&&o&&n?.l2_content||G9(e);return(0,K.jsx)(bb,{className:wp(`relative overflow-hidden border transition-all duration-200 hover:shadow-md`,r&&!o&&`border-amber-200 dark:border-amber-500/30`),children:(0,K.jsxs)(wb,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsx)(`div`,{className:wp(`flex items-center justify-center size-8 rounded-lg border`,i.bgColor),children:(0,K.jsx)(a,{className:wp(`size-4`,i.color)})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r&&(0,K.jsxs)(hJ,{variant:`outline`,className:`text-[10px] gap-1 bg-amber-50 dark:bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-200 dark:border-amber-500/30`,children:[(0,K.jsx)(Em,{className:`size-2.5`}),`私密`]}),(0,K.jsx)(hJ,{variant:`outline`,className:wp(`text-[10px]`,i.bgColor,i.color),children:i.label})]})]}),(0,K.jsx)(`div`,{className:wp(r&&!o&&`blur-[6px] select-none opacity-40`),children:(0,K.jsx)(q9,{content:s})}),r&&!o&&(0,K.jsx)(`button`,{type:`button`,className:`mt-3 w-full flex items-center justify-center gap-2 px-3 py-2 rounded-lg bg-amber-50 dark:bg-amber-500/10 text-amber-700 dark:text-amber-300 text-xs font-medium hover:bg-amber-100 dark:hover:bg-amber-500/20 transition-colors border border-amber-200 dark:border-amber-500/30 cursor-pointer`,onClick:()=>ie(e),children:o?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(am,{className:`size-3.5`}),`已解锁`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Em,{className:`size-3.5`}),`点击解锁私密内容`]})})]})},`sf-${e.slice(0,40)}`)})})]}),oe.length>0&&(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(m7,{}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Rp,{className:`size-5 text-blue-500`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold`,children:`静态偏好`}),(0,K.jsxs)(hJ,{variant:`secondary`,className:`text-[10px]`,children:[oe.length,` 条`]})]}),(0,K.jsxs)(`div`,{className:`relative pl-6 space-y-3`,children:[(0,K.jsx)(`div`,{className:`absolute left-[11px] top-2 bottom-2 w-px bg-gradient-to-b from-blue-300 via-orange-300 to-transparent dark:from-blue-500/40 dark:via-orange-500/40 dark:to-transparent`}),oe.map((e,n)=>{let r=W9(e),i=r.icon;return(0,K.jsxs)(`div`,{className:`relative group`,children:[(0,K.jsx)(`div`,{className:`absolute -left-6 top-2.5 size-[22px] rounded-full bg-gradient-to-br from-blue-400 to-orange-400 ring-[3px] ring-background flex items-center justify-center shadow-sm group-hover:scale-110 transition-transform`,children:(0,K.jsx)(`span`,{className:`text-[9px] font-bold text-white`,children:n+1})}),(0,K.jsx)(bb,{className:`overflow-hidden hover:shadow-sm transition-shadow`,children:(0,K.jsxs)(wb,{className:`p-3.5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsx)(`div`,{className:wp(`flex items-center justify-center size-5 rounded-md border`,r.bgColor),children:(0,K.jsx)(i,{className:wp(`size-3`,r.color)})}),(0,K.jsx)(`span`,{className:wp(`text-[10px] font-medium px-1.5 py-0.5 rounded border`,r.bgColor,r.color),children:r.label})]}),(0,K.jsx)(q9,{content:G9(e)})]})})]},`dc-${n}`)})]})]}),se.length===0&&oe.length===0&&(0,K.jsx)(bb,{className:`border-dashed`,children:(0,K.jsxs)(wb,{className:`py-16 flex flex-col items-center gap-3 text-muted-foreground`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center size-12 rounded-2xl bg-muted`,children:(0,K.jsx)(th,{className:`size-6`})}),(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium`,children:`暂无画像数据`}),(0,K.jsx)(`p`,{className:`text-xs mt-1`,children:`存储更多记忆后,系统将自动构建您的用户画像`})]})]})})]})}),(0,K.jsx)(w7,{value:`changelog`,className:`space-y-4`,children:p?(0,K.jsx)(`div`,{className:`space-y-3`,children:[1,2,3].map(e=>(0,K.jsx)(Tb,{className:`h-20 w-full rounded-xl`},e))}):d.length===0?(0,K.jsx)(bb,{className:`border-dashed`,children:(0,K.jsxs)(wb,{className:`py-16 flex flex-col items-center gap-3 text-muted-foreground`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center size-12 rounded-2xl bg-muted`,children:(0,K.jsx)(mm,{className:`size-6`})}),(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium`,children:`暂无变更记录`}),(0,K.jsx)(`p`,{className:`text-xs mt-1`,children:`偏好变更时将自动记录在这里`})]})]})}):(0,K.jsxs)(`div`,{className:`relative pl-6 space-y-3 overflow-hidden`,children:[(0,K.jsx)(`div`,{className:`absolute left-[11px] top-2 bottom-2 w-px bg-gradient-to-b from-violet-300 via-sky-300 to-transparent dark:from-violet-500/40 dark:via-sky-500/40 dark:to-transparent`}),d.map(e=>{let n=e.action===`created`,r=e.action===`updated`,i=n?{bg:`from-emerald-400 to-teal-400`,color:`text-emerald-700 dark:text-emerald-300`,badgeClass:`bg-emerald-50 dark:bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 border-emerald-200 dark:border-emerald-500/30`,symbol:`+`,label:`创建`}:r?{bg:`from-blue-400 to-sky-400`,color:`text-blue-700 dark:text-blue-300`,badgeClass:`bg-blue-50 dark:bg-blue-500/10 text-blue-700 dark:text-blue-300 border-blue-200 dark:border-blue-500/30`,symbol:`~`,label:`更新`}:{bg:`from-rose-400 to-red-400`,color:`text-rose-700 dark:text-rose-300`,badgeClass:`bg-rose-50 dark:bg-rose-500/10 text-rose-700 dark:text-rose-300 border-rose-200 dark:border-rose-500/30`,symbol:`−`,label:`删除`};return(0,K.jsxs)(`div`,{className:`relative group`,children:[(0,K.jsx)(`div`,{className:wp(`absolute -left-6 top-2.5 size-[22px] rounded-full bg-gradient-to-br ring-[3px] ring-background flex items-center justify-center shadow-sm group-hover:scale-110 transition-transform`,i.bg),children:(0,K.jsx)(`span`,{className:`text-[9px] font-bold text-white`,children:i.symbol})}),(0,K.jsx)(bb,{className:`overflow-hidden hover:shadow-sm transition-shadow`,children:(0,K.jsxs)(wb,{className:`p-4 space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,K.jsxs)(hJ,{variant:`outline`,className:wp(`text-[10px] gap-1`,i.badgeClass),children:[n?(0,K.jsx)(Lm,{className:`size-2.5`}):r?(0,K.jsx)(Pm,{className:`size-2.5`}):(0,K.jsx)(Xm,{className:`size-2.5`}),i.label]}),e.source&&(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.source}),(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:K9(e.created_at)})]}),e.old_value&&(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground line-through truncate`,children:e.old_value}),e.new_value&&(0,K.jsx)(`p`,{className:`text-sm leading-relaxed`,children:e.new_value})]})})]},e.id)})]})})]})]}),(0,K.jsx)(aJ,{open:!!R,onOpenChange:e=>{!e&&!ee&&z(null)},children:(0,K.jsxs)(oJ,{children:[(0,K.jsxs)(sJ,{children:[(0,K.jsx)(lJ,{children:`确认删除偏好`}),(0,K.jsxs)(uJ,{children:[`确定要删除这条偏好吗?此操作不可撤销。`,R&&(0,K.jsx)(`span`,{className:`block mt-2 px-3 py-2 rounded-lg bg-muted text-sm text-foreground truncate`,children:R.value})]})]}),(0,K.jsxs)(cJ,{children:[(0,K.jsx)(fJ,{disabled:ee,children:`取消`}),(0,K.jsx)(dJ,{disabled:ee,onClick:he,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:ee?`删除中...`:`删除`})]})]})}),(0,K.jsx)(J9,{open:M,onOpenChange:N,saving:I,onSubmit:pe,title:`新建偏好`}),(0,K.jsx)(J9,{open:!!P,onOpenChange:e=>{e||F(null)},saving:I,onSubmit:e=>{P&&me(P.id,e)},pref:P,title:`编辑偏好`}),(0,K.jsx)(g9,{open:b,onOpenChange:e=>{e||(x(!1),T(``),D(null))},children:(0,K.jsxs)(_9,{className:`sm:max-w-sm`,children:[(0,K.jsxs)(v9,{children:[(0,K.jsxs)(b9,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Em,{className:`size-4 text-amber-500`}),`解锁私密记忆`]}),(0,K.jsx)(x9,{children:`请输入您的 Vault 密码以解锁受保护的内容。`})]}),(0,K.jsx)(`div`,{className:`space-y-3`,children:(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{className:`text-xs`,children:`密码`}),(0,K.jsx)(hb,{type:`password`,placeholder:`输入 Vault 密码...`,value:w,onChange:e=>{T(e.target.value),D(null)},onKeyDown:e=>e.key===`Enter`&&re(),className:E?`border-destructive`:``,autoFocus:!0}),E&&(0,K.jsx)(`p`,{className:`text-xs text-destructive`,children:E})]})}),(0,K.jsxs)(y9,{children:[(0,K.jsx)(J,{variant:`outline`,onClick:()=>x(!1),disabled:O,children:`取消`}),(0,K.jsx)(J,{onClick:re,disabled:O||!w.trim(),children:O?`解锁中...`:`解锁`})]})]})})]})}function age({slot:e,preferences:n,onEdit:r,onDelete:i}){let[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(4),l=nge(e),u=n.slice(0,s),d=s<n.length;return(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2.5 w-full group cursor-pointer text-left border-none bg-transparent p-0`,onClick:()=>{o(!a),c(4)},children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center size-7 rounded-lg bg-gradient-to-br from-amber-100 to-orange-100 dark:from-amber-500/15 dark:to-orange-500/15 border border-amber-200/60 dark:border-amber-500/20`,children:(0,K.jsx)(l,{className:`size-3.5 text-amber-600 dark:text-amber-400`})}),(0,K.jsx)(`span`,{className:`text-sm font-semibold text-foreground`,children:tge(e)}),(0,K.jsx)(hJ,{variant:`secondary`,className:`text-[10px]`,children:n.length}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(Qp,{className:wp(`size-4 text-muted-foreground transition-transform duration-200`,!a&&`rotate-90`)})]}),!a&&(0,K.jsxs)(`div`,{className:`space-y-2.5 pl-9`,children:[(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-2.5`,children:u.map(e=>(0,K.jsx)(oge,{pref:e,onEdit:r,onDelete:i},e.id))}),d&&(0,K.jsxs)(`button`,{type:`button`,className:`w-full flex items-center justify-center gap-1.5 py-2 text-xs text-muted-foreground hover:text-foreground transition-colors rounded-lg hover:bg-muted/50 cursor-pointer`,onClick:()=>c(e=>Math.min(e+4,n.length)),children:[(0,K.jsx)(Xp,{className:`size-3.5`}),`加载更多(剩余 `,n.length-s,` 条)`]})]})]})}function oge({pref:e,onEdit:n,onDelete:r}){let i=rge[e.scope]||{className:`bg-slate-50 dark:bg-slate-500/10 text-slate-700 dark:text-slate-300 border-slate-200 dark:border-slate-500/30`,label:e.scope};return(0,K.jsx)(bb,{className:`group hover:shadow-md transition-all duration-200 border-border/60`,children:(0,K.jsxs)(wb,{className:`p-3.5 space-y-2.5`,children:[(0,K.jsx)(`p`,{className:`text-sm leading-relaxed whitespace-pre-wrap break-words`,children:e.value}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,K.jsx)(hJ,{variant:`outline`,className:wp(`text-[10px] gap-1`,i.className),children:i.label}),e.project_path&&(0,K.jsxs)(hJ,{variant:`outline`,className:`text-[10px] gap-1 bg-violet-50 dark:bg-violet-500/10 text-violet-700 dark:text-violet-300 border-violet-200 dark:border-violet-500/30`,children:[(0,K.jsx)(um,{className:`size-2.5`}),e.project_path.split(`/`).pop()]}),(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:K9(e.updated_at)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity pt-1 border-t border-border/40`,children:[(0,K.jsxs)(`span`,{className:`text-[10px] text-muted-foreground mr-auto`,children:[`置信度 `,(e.confidence*100).toFixed(0),`%`]}),(0,K.jsx)(J,{variant:`ghost`,size:`icon`,className:`size-7 text-muted-foreground hover:text-foreground`,onClick:()=>n(e),children:(0,K.jsx)(Pm,{className:`size-3.5`})}),(0,K.jsx)(J,{variant:`ghost`,size:`icon`,className:`size-7 text-muted-foreground hover:text-destructive`,onClick:()=>r(e),children:(0,K.jsx)(Xm,{className:`size-3.5`})})]})]})})}function J9({open:e,onOpenChange:n,saving:r,onSubmit:i,pref:a,title:o}){let s=!!a,[c,l]=(0,y.useState)(a?.slot||``),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(a?.value||``),[m,h]=(0,y.useState)(String(a?.confidence??.8)),[g,_]=(0,y.useState)(a?.scope||`global`),[v,b]=(0,y.useState)(a?.project_path||``);(0,y.useEffect)(()=>{if(e){let e=a?.slot||``;l(e),d(e.startsWith(`custom:`)?e.slice(7):``),p(a?.value||``),h(String(a?.confidence??.8)),_(a?.scope||`global`),b(a?.project_path||``)}},[e,a]);let x=c===`__custom__`;return(0,K.jsx)(g9,{open:e,onOpenChange:n,children:(0,K.jsxs)(_9,{className:`sm:max-w-md`,children:[(0,K.jsxs)(v9,{children:[(0,K.jsxs)(b9,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Gm,{className:`size-4 text-amber-500`}),o]}),(0,K.jsx)(x9,{children:s?`修改偏好信息。`:`添加一条新的偏好。`})]}),(0,K.jsxs)(`div`,{className:`space-y-4 py-1`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{className:`text-xs`,children:`Slot (类别)`}),s?(0,K.jsx)(hb,{value:c,disabled:!0,className:`h-9 bg-muted/60`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(r9,{value:c||void 0,onValueChange:e=>e!=null&&l(e),children:[(0,K.jsx)(a9,{className:`h-9 w-full`,children:(0,K.jsx)(i9,{placeholder:`选择类别...`})}),(0,K.jsxs)(o9,{children:[Qhe.map(e=>(0,K.jsx)(s9,{value:e.name,children:e.display},e.name)),(0,K.jsx)(s9,{value:`__custom__`,children:`自定义 (custom:...)`})]})]}),x&&(0,K.jsx)(hb,{placeholder:`自定义 slot 名 (小写字母+数字+下划线)`,value:u,onChange:e=>{d(e.target.value.replace(/[^a-z0-9_]/g,``))},className:`h-9`,maxLength:50})]})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{className:`text-xs`,children:`范围`}),(0,K.jsxs)(r9,{value:g,onValueChange:e=>e!=null&&_(e),children:[(0,K.jsx)(a9,{className:`h-9`,children:(0,K.jsx)(i9,{})}),(0,K.jsxs)(o9,{children:[(0,K.jsx)(s9,{value:`global`,children:`全局`}),(0,K.jsx)(s9,{value:`project`,children:`项目`}),(0,K.jsx)(s9,{value:`session`,children:`会话`})]})]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{className:`text-xs`,children:`内容`}),(0,K.jsx)(d9,{placeholder:`偏好内容...`,value:f,onChange:e=>p(e.target.value),rows:3,className:`resize-none`,maxLength:500})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{className:`text-xs`,children:`置信度 (0-1)`}),(0,K.jsx)(hb,{type:`number`,min:`0`,max:`1`,step:`0.1`,value:m,onChange:e=>h(e.target.value),className:`h-9`})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{className:`text-xs`,children:`项目路径 (可选)`}),(0,K.jsx)(hb,{placeholder:`例: /path/to/project`,value:v,onChange:e=>b(e.target.value),className:`h-9`,maxLength:200})]})]})]}),(0,K.jsxs)(y9,{children:[(0,K.jsx)(J,{variant:`outline`,onClick:()=>n(!1),disabled:r,children:`取消`}),(0,K.jsx)(J,{onClick:()=>{let e=x?`custom:${u.trim()}`:c.trim();if(!e||!f.trim()){G.error(`请填写 Slot 和内容`);return}if(x&&!u.trim()){G.error(`请填写自定义 Slot 名`);return}if(s){let e={};f!==(a?.value||``)&&(e.value=f.trim()),m!==String(a?.confidence??.8)&&(e.confidence=parseFloat(m)),g!==(a?.scope||`global`)&&(e.scope=g),v!==(a?.project_path||``)&&(e.project_path=v.trim()||void 0),i(e)}else i({slot:e,value:f.trim(),confidence:parseFloat(m)||.8,scope:g,project_path:v.trim()||void 0})},disabled:r||!f.trim()||(x?!u.trim():!c.trim()),className:`bg-gradient-to-r from-amber-500 to-orange-500 hover:from-amber-600 hover:to-orange-600 text-white`,children:r?s?`保存中...`:`创建中...`:s?`保存`:`创建`})]})]})})}var Y9=y.createContext(void 0);function sge(){let e=y.useContext(Y9);if(e===void 0)throw Error(Fr(63));return e}var X9=function(e){return e.checked=`data-checked`,e.unchecked=`data-unchecked`,e.disabled=`data-disabled`,e.readonly=`data-readonly`,e.required=`data-required`,e.valid=`data-valid`,e.invalid=`data-invalid`,e.touched=`data-touched`,e.dirty=`data-dirty`,e.filled=`data-filled`,e.focused=`data-focused`,e}({}),Z9={...lb,checked(e){return e?{[X9.checked]:``}:{[X9.unchecked]:``}}},cge=y.forwardRef(function(e,n){let{checked:r,className:i,defaultChecked:a,"aria-labelledby":o,form:s,id:c,inputRef:l,name:u,nativeButton:d=!1,onCheckedChange:f,readOnly:p=!1,required:m=!1,disabled:h=!1,render:g,uncheckedValue:_,value:v,style:b,...x}=e,{clearErrors:S}=db(),{state:C,setTouched:w,setDirty:T,validityData:E,setFilled:D,setFocused:O,shouldValidateOnChange:k,validationMode:A,disabled:j,name:M,validation:N}=ub(),{labelId:P}=fb(),F=j||h,I=M??u,L=Sa(f),R=y.useRef(null),z=fa(R,l,N.inputRef),ee=y.useRef(null),B=vd(),V=mb({id:c,implicit:!1,controlRef:ee}),H=d?void 0:V,[U,te]=Hg({controlled:r,default:!!a,name:`Switch`,state:`checked`});pb(ee,{id:B,value:U}),Nr(()=>{R.current&&D(R.current.checked)},[R,D]),fg(U,()=>{S(I),T(U!==E.initialValue),D(U),k()?N.commit(U):N.commit(U,!0)});let{getButtonProps:W,buttonRef:ne}=vh({disabled:F,native:d}),re=P9(o,P,R,!d,H),ie={id:d?V:B,role:`switch`,"aria-checked":U,"aria-readonly":p||void 0,"aria-required":m||void 0,"aria-labelledby":re,onFocus(){F||O(!0)},onBlur(){let e=R.current;!e||F||(w(!0),O(!1),A===`onBlur`&&N.commit(e.checked))},onClick(e){p||F||(e.preventDefault(),R.current?.dispatchEvent(new PointerEvent(`click`,{bubbles:!0,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey})))}},ae=y.useMemo(()=>Ls({checked:U,disabled:F,form:s,id:H,name:I,required:m,style:I?Ma:ja,tabIndex:-1,type:`checkbox`,"aria-hidden":!0,ref:z,onChange(e){if(e.nativeEvent.defaultPrevented)return;if(p){e.preventDefault();return}let n=e.currentTarget.checked,r=Fi(bi,e.nativeEvent);L?.(n,r),!r.isCanceled&&te(n)},onFocus(){ee.current?.focus()}},N.getInputValidationProps,v===void 0?mi:{value:v}),[U,F,s,z,H,I,L,p,m,te,N,v]),oe=y.useMemo(()=>({...C,checked:U,disabled:F,readOnly:p,required:m}),[C,U,F,p,m]),se=Zs(`span`,e,{state:oe,ref:[n,ee,ne],props:[ie,N.getValidationProps,x,W],stateAttributesMapping:Z9});return(0,K.jsxs)(Y9.Provider,{value:oe,children:[se,!U&&I&&_!==void 0&&(0,K.jsx)(`input`,{type:`hidden`,form:s,name:I,value:_}),(0,K.jsx)(`input`,{...ae,suppressHydrationWarning:!0})]})}),lge=y.forwardRef(function(e,n){let{render:r,className:i,style:a,...o}=e,{state:s}=ub(),c=sge();return Zs(`span`,e,{state:{...s,...c},ref:n,stateAttributesMapping:Z9,props:o})});function uge({className:e,size:n=`default`,...r}){return(0,K.jsx)(cge,{"data-slot":`switch`,"data-size":n,className:wp(`peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent transition-all outline-none after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-[size=default]:h-[18.4px] data-[size=default]:w-[32px] data-[size=sm]:h-[14px] data-[size=sm]:w-[24px] dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:bg-primary data-unchecked:bg-input dark:data-unchecked:bg-input/80 data-disabled:cursor-not-allowed data-disabled:opacity-50`,e),...r,children:(0,K.jsx)(lge,{"data-slot":`switch-thumb`,className:`pointer-events-none block rounded-full bg-background ring-0 transition-transform group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 group-data-[size=default]/switch:data-checked:translate-x-[calc(100%-2px)] group-data-[size=sm]/switch:data-checked:translate-x-[calc(100%-2px)] dark:data-checked:bg-primary-foreground group-data-[size=default]/switch:data-unchecked:translate-x-0 group-data-[size=sm]/switch:data-unchecked:translate-x-0 dark:data-unchecked:bg-foreground`})})}var Q9={list(){return ib.get(`/v1/categories`)},get(e){return ib.get(`/v1/categories/${encodeURIComponent(e)}`)},create(e){return ib.post(`/v1/categories`,e)},update(e,n){return ib.put(`/v1/categories/${encodeURIComponent(e)}`,n)},delete(e){return ib.delete(`/v1/categories/${encodeURIComponent(e)}`)},listAliases(){return ib.get(`/v1/categories/aliases`)},createAlias(e,n){return ib.post(`/v1/categories/aliases`,{alias:e,target:n})},deleteAlias(e){return ib.delete(`/v1/categories/aliases/${encodeURIComponent(e)}`)}},$9={name:``,display_name:``,description:``,decision_rule:``,always_merge:!1,append_only:!1,temporal_versioned:!1,merge_supported:!1,admission_weight:.5,importance_base:.5,prompt_format:``,default_visibility:`global`,default_scope:`global`,default_ttl_days:0,sort_order:100,is_active:!0};function dge(){let[e,n]=(0,y.useState)([]),[r,i]=(0,y.useState)([]),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)($9),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)(``),[S,C]=(0,y.useState)(null),w=(0,y.useCallback)(async()=>{try{let e=await Q9.list();n(Array.isArray(e)?e:[])}catch{G.error(`加载分类失败`)}},[]),T=(0,y.useCallback)(async()=>{try{let e=await Q9.listAliases();i(Array.isArray(e)?e:[])}catch{G.error(`加载别名失败`)}},[]);(0,y.useEffect)(()=>{Promise.all([w(),T()]).finally(()=>o(!1))},[w,T]);let E=()=>{c(null),f($9),u(!0)},D=e=>{c(e),f({name:e.name,display_name:e.display_name,description:e.description,decision_rule:e.decision_rule||``,always_merge:e.always_merge,append_only:e.append_only,temporal_versioned:e.temporal_versioned,merge_supported:e.merge_supported,admission_weight:e.admission_weight,importance_base:e.importance_base,prompt_format:e.prompt_format||``,default_visibility:e.default_visibility,default_scope:e.default_scope,default_ttl_days:e.default_ttl_days||0,sort_order:e.sort_order,is_active:e.is_active}),u(!0)};return a?(0,K.jsx)(`div`,{className:`flex items-center justify-center h-64 text-muted-foreground`,children:`加载中...`}):(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-bold`,children:`分类字典`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`管理记忆分类和别名映射`})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(J,{variant:`outline`,onClick:()=>g(!0),children:[(0,K.jsx)(Cm,{className:`size-4 mr-1`}),`添加别名`]}),(0,K.jsxs)(J,{onClick:E,children:[(0,K.jsx)(Lm,{className:`size-4 mr-1`}),`新建分类`]})]})]}),(0,K.jsx)(m7,{}),r.length>0&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold flex items-center gap-2`,children:[(0,K.jsx)(Cm,{className:`size-4`}),`别名映射 (`,r.length,`)`]}),(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3`,children:r.map(e=>(0,K.jsxs)(bb,{className:`p-3 flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(`code`,{className:`bg-muted px-1.5 py-0.5 rounded text-xs`,children:e.alias}),(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`→`}),(0,K.jsx)(`code`,{className:`bg-muted px-1.5 py-0.5 rounded text-xs`,children:e.target})]}),(0,K.jsx)(J,{variant:`ghost`,size:`icon`,className:`size-7 text-destructive hover:text-destructive`,onClick:()=>C(e.alias),children:(0,K.jsx)(rh,{className:`size-3.5`})})]},e.alias))}),(0,K.jsx)(m7,{})]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold flex items-center gap-2`,children:[(0,K.jsx)(Jm,{className:`size-4`}),`分类列表 (`,e.length,`)`]}),(0,K.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{className:`bg-muted/50`,children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`text-left p-3 font-medium`,children:`名称`}),(0,K.jsx)(`th`,{className:`text-left p-3 font-medium`,children:`显示名`}),(0,K.jsx)(`th`,{className:`text-left p-3 font-medium hidden md:table-cell`,children:`描述`}),(0,K.jsx)(`th`,{className:`text-center p-3 font-medium`,children:`权重`}),(0,K.jsx)(`th`,{className:`text-center p-3 font-medium`,children:`状态`}),(0,K.jsx)(`th`,{className:`text-right p-3 font-medium`,children:`操作`})]})}),(0,K.jsx)(`tbody`,{className:`divide-y`,children:e.map(e=>(0,K.jsxs)(`tr`,{className:`hover:bg-muted/30`,children:[(0,K.jsx)(`td`,{className:`p-3`,children:(0,K.jsx)(`code`,{className:`bg-muted px-1.5 py-0.5 rounded text-xs`,children:e.name})}),(0,K.jsx)(`td`,{className:`p-3 font-medium`,children:e.display_name}),(0,K.jsx)(`td`,{className:`p-3 text-muted-foreground hidden md:table-cell max-w-[200px] truncate`,children:e.description}),(0,K.jsx)(`td`,{className:`p-3 text-center`,children:(0,K.jsx)(`span`,{className:`text-xs`,children:e.admission_weight.toFixed(2)})}),(0,K.jsx)(`td`,{className:`p-3 text-center`,children:(0,K.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full ${e.is_active?`bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400`:`bg-gray-100 text-gray-500 dark:bg-gray-800 dark:text-gray-400`}`,children:e.is_active?`启用`:`禁用`})}),(0,K.jsx)(`td`,{className:`p-3 text-right`,children:(0,K.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,K.jsx)(J,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:()=>D(e),children:(0,K.jsx)(Fm,{className:`size-3.5`})}),(0,K.jsx)(J,{variant:`ghost`,size:`icon`,className:`size-7 text-destructive hover:text-destructive`,onClick:()=>m(e.name),children:(0,K.jsx)(Xm,{className:`size-3.5`})})]})})]},e.name))})]})})]}),(0,K.jsx)(g9,{open:l,onOpenChange:u,children:(0,K.jsxs)(_9,{className:`max-w-lg max-h-[80vh] overflow-y-auto`,children:[(0,K.jsx)(v9,{children:(0,K.jsx)(b9,{children:s?`编辑分类`:`新建分类`})}),(0,K.jsxs)(`div`,{className:`space-y-4 py-2`,children:[!s&&(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`名称 (name)`}),(0,K.jsx)(hb,{value:d.name,onChange:e=>f(n=>({...n,name:e.target.value.toLowerCase()})),placeholder:`e.g. preferences`,maxLength:50})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`显示名 (display_name)`}),(0,K.jsx)(hb,{value:d.display_name,onChange:e=>f(n=>({...n,display_name:e.target.value})),placeholder:`e.g. 偏好设置`,maxLength:100})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`描述`}),(0,K.jsx)(hb,{value:d.description,onChange:e=>f(n=>({...n,description:e.target.value})),placeholder:`分类描述`,maxLength:500})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`决策规则 (decision_rule)`}),(0,K.jsx)(hb,{value:d.decision_rule,onChange:e=>f(n=>({...n,decision_rule:e.target.value})),placeholder:`可选`,maxLength:200})]}),(0,K.jsx)(m7,{}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`准入权重`}),(0,K.jsx)(hb,{type:`number`,step:.05,min:0,max:1,value:d.admission_weight,onChange:e=>f(n=>({...n,admission_weight:+e.target.value}))})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`重要性基数`}),(0,K.jsx)(hb,{type:`number`,step:.05,min:0,max:1,value:d.importance_base,onChange:e=>f(n=>({...n,importance_base:+e.target.value}))})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`排序`}),(0,K.jsx)(hb,{type:`number`,value:d.sort_order,onChange:e=>f(n=>({...n,sort_order:+e.target.value}))})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`默认TTL (天)`}),(0,K.jsx)(hb,{type:`number`,value:d.default_ttl_days,onChange:e=>f(n=>({...n,default_ttl_days:+e.target.value}))})]})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`提示格式 (prompt_format)`}),(0,K.jsx)(hb,{value:d.prompt_format,onChange:e=>f(n=>({...n,prompt_format:e.target.value})),placeholder:`可选`,maxLength:500})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`默认可见性`}),(0,K.jsxs)(`select`,{className:`w-full h-9 rounded-md border border-input bg-background px-3 text-sm`,value:d.default_visibility,onChange:e=>f(n=>({...n,default_visibility:e.target.value})),children:[(0,K.jsx)(`option`,{value:`global`,children:`global`}),(0,K.jsx)(`option`,{value:`project`,children:`project`}),(0,K.jsx)(`option`,{value:`private`,children:`private`})]})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`默认作用域`}),(0,K.jsxs)(`select`,{className:`w-full h-9 rounded-md border border-input bg-background px-3 text-sm`,value:d.default_scope,onChange:e=>f(n=>({...n,default_scope:e.target.value})),children:[(0,K.jsx)(`option`,{value:`global`,children:`global`}),(0,K.jsx)(`option`,{value:`project`,children:`project`})]})]})]}),(0,K.jsx)(m7,{}),(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-3`,children:[[`always_merge`,`始终合并`],[`append_only`,`仅追加`],[`temporal_versioned`,`时序版本`],[`merge_supported`,`支持合并`],[`is_active`,`启用`]].map(([e,n])=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border p-3`,children:[(0,K.jsx)(gb,{className:`text-sm`,children:n}),(0,K.jsx)(uge,{checked:d[e],onCheckedChange:n=>f(r=>({...r,[e]:n}))})]},e))})]}),(0,K.jsxs)(y9,{children:[(0,K.jsx)(J,{variant:`outline`,onClick:()=>u(!1),children:`取消`}),(0,K.jsx)(J,{onClick:async()=>{if(!d.name.trim()||!d.display_name.trim()){G.error(`名称和显示名为必填项`);return}try{let e={...d,decision_rule:d.decision_rule||null,prompt_format:d.prompt_format||null,default_ttl_days:d.default_ttl_days||null};s?(await Q9.update(s.name,e),G.success(`分类已更新`)):(await Q9.create(e),G.success(`分类已创建`)),u(!1),w()}catch(e){let n=e instanceof Error?e.message:`操作失败`;G.error(n)}},children:s?`保存`:`创建`})]})]})}),(0,K.jsx)(aJ,{open:!!p,onOpenChange:()=>m(null),children:(0,K.jsxs)(oJ,{children:[(0,K.jsxs)(sJ,{children:[(0,K.jsx)(lJ,{children:`确认删除分类`}),(0,K.jsxs)(uJ,{children:[`确定要删除分类 "`,p,`" 吗?此操作不可撤销。`]})]}),(0,K.jsxs)(cJ,{children:[(0,K.jsx)(fJ,{children:`取消`}),(0,K.jsx)(dJ,{onClick:async()=>{if(p)try{await Q9.delete(p),G.success(`分类已删除`),m(null),w()}catch{G.error(`删除失败`)}},children:`删除`})]})]})}),(0,K.jsx)(g9,{open:h,onOpenChange:g,children:(0,K.jsxs)(_9,{className:`max-w-sm`,children:[(0,K.jsx)(v9,{children:(0,K.jsx)(b9,{children:`添加别名`})}),(0,K.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`别名`}),(0,K.jsx)(hb,{value:_,onChange:e=>v(e.target.value),placeholder:`e.g. likes`,maxLength:50})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(gb,{children:`目标分类`}),(0,K.jsxs)(`select`,{className:`w-full h-9 rounded-md border border-input bg-background px-3 text-sm`,value:b,onChange:e=>x(e.target.value),children:[(0,K.jsx)(`option`,{value:``,children:`选择分类...`}),e.map(e=>(0,K.jsxs)(`option`,{value:e.name,children:[e.display_name,` (`,e.name,`)`]},e.name))]})]})]}),(0,K.jsxs)(y9,{children:[(0,K.jsx)(J,{variant:`outline`,onClick:()=>g(!1),children:`取消`}),(0,K.jsx)(J,{onClick:async()=>{if(!_.trim()||!b.trim()){G.error(`别名和目标分类为必填项`);return}try{await Q9.createAlias(_,b),G.success(`别名已创建`),g(!1),v(``),x(``),T()}catch(e){let n=e instanceof Error?e.message:`创建别名失败`;G.error(n)}},children:`创建`})]})]})}),(0,K.jsx)(aJ,{open:!!S,onOpenChange:()=>C(null),children:(0,K.jsxs)(oJ,{children:[(0,K.jsxs)(sJ,{children:[(0,K.jsx)(lJ,{children:`确认删除别名`}),(0,K.jsxs)(uJ,{children:[`确定要删除别名 "`,S,`" 吗?`]})]}),(0,K.jsxs)(cJ,{children:[(0,K.jsx)(fJ,{children:`取消`}),(0,K.jsx)(dJ,{onClick:async()=>{if(S)try{await Q9.deleteAlias(S),G.success(`别名已删除`),C(null),T()}catch{G.error(`删除别名失败`)}},children:`删除`})]})]})})]})}function fge(){let e=et();return(0,K.jsx)(`div`,{className:`flex h-screen w-full flex-col items-center justify-center bg-background text-foreground`,children:(0,K.jsxs)(`div`,{className:`text-center space-y-6`,children:[(0,K.jsx)(`div`,{className:`text-8xl font-bold text-muted-foreground/30`,children:`404`}),(0,K.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`页面不存在`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground max-w-sm`,children:`您访问的页面可能已经删除、移动,或者从未存在过。`}),(0,K.jsxs)(`div`,{className:`flex items-center justify-center gap-3`,children:[(0,K.jsxs)(J,{variant:`outline`,onClick:()=>e(-1),children:[(0,K.jsx)(Bp,{className:`h-4 w-4 mr-2`}),`返回上一页`]}),(0,K.jsxs)(J,{onClick:()=>e(`/dashboard`),children:[(0,K.jsx)(hm,{className:`h-4 w-4 mr-2`}),`返回首页`]})]})]})})}var pge=class extends y.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){console.error(`ErrorBoundary caught an error:`,e,n)}handleRefresh=()=>{window.location.reload()};handleGoHome=()=>{window.location.href=`/`};render(){return this.state.hasError?(0,K.jsx)(`div`,{className:`flex h-screen w-full flex-col items-center justify-center bg-background text-foreground`,children:(0,K.jsxs)(`div`,{className:`text-center space-y-6 max-w-md px-4`,children:[(0,K.jsx)(`div`,{className:`text-6xl font-bold text-destructive/30`,children:`⚠️`}),(0,K.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`出错了`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`应用遇到了意外错误。请尝试刷新页面,或返回首页。`}),this.state.error&&(0,K.jsx)(`div`,{className:`rounded-lg bg-muted p-4 text-left`,children:(0,K.jsx)(`p`,{className:`text-xs font-mono text-muted-foreground break-all`,children:this.state.error.message})}),(0,K.jsxs)(`div`,{className:`flex items-center justify-center gap-3`,children:[(0,K.jsxs)(J,{variant:`outline`,onClick:this.handleRefresh,children:[(0,K.jsx)(Rm,{className:`h-4 w-4 mr-2`}),`刷新页面`]}),(0,K.jsxs)(J,{onClick:this.handleGoHome,children:[(0,K.jsx)(hm,{className:`h-4 w-4 mr-2`}),`返回首页`]})]})]})}):this.props.children}};function mge({children:e}){let n=hh(e=>e.isAuthenticated),r=typeof window<`u`&&window.localStorage.getItem(`e2e_bypass_auth`)===`true`;return n||r?e:(0,K.jsx)(Ot,{to:`/login`,replace:!0})}function hge(){return(0,K.jsx)(pge,{children:(0,K.jsxs)(Mt,{children:[(0,K.jsx)(At,{path:`/login`,element:(0,K.jsx)(yb,{})}),(0,K.jsxs)(At,{path:`/*`,element:(0,K.jsx)(mge,{children:(0,K.jsx)(Hee,{})}),children:[(0,K.jsx)(At,{index:!0,element:(0,K.jsx)(Ot,{to:`/dashboard`,replace:!0})}),(0,K.jsx)(At,{path:`dashboard`,element:(0,K.jsx)(iJ,{})}),(0,K.jsx)(At,{path:`memories`,element:(0,K.jsx)(jJ,{})}),(0,K.jsx)(At,{path:`memories/:id`,element:(0,K.jsx)(Lme,{})}),(0,K.jsx)(At,{path:`memories/new`,element:(0,K.jsx)(f9,{})}),(0,K.jsx)(At,{path:`memories/:id/edit`,element:(0,K.jsx)(f9,{})}),(0,K.jsx)(At,{path:`memories/:id/edit-insight`,element:(0,K.jsx)(Hme,{})}),(0,K.jsx)(At,{path:`vault`,element:(0,K.jsx)(Gme,{})}),(0,K.jsx)(At,{path:`spaces`,element:(0,K.jsx)(she,{})}),(0,K.jsx)(At,{path:`sessions`,element:(0,K.jsx)(qme,{})}),(0,K.jsx)(At,{path:`sessions/:id`,element:(0,K.jsx)(rhe,{})}),(0,K.jsx)(At,{path:`analytics`,element:(0,K.jsx)(che,{})}),(0,K.jsx)(At,{path:`tier-history`,element:(0,K.jsx)(uhe,{})}),(0,K.jsx)(At,{path:`clusters`,element:(0,K.jsx)(whe,{})}),(0,K.jsx)(At,{path:`clusters/list`,element:(0,K.jsx)(Nhe,{})}),(0,K.jsx)(At,{path:`clusters/:id`,element:(0,K.jsx)(Lhe,{})}),(0,K.jsx)(At,{path:`lifecycle`,element:(0,K.jsx)(Khe,{})}),(0,K.jsx)(At,{path:`import`,element:(0,K.jsx)(qhe,{})}),(0,K.jsx)(At,{path:`profile`,element:(0,K.jsx)(ige,{})}),(0,K.jsx)(At,{path:`settings`,element:(0,K.jsx)(Jhe,{})}),(0,K.jsx)(At,{path:`categories`,element:(0,K.jsx)(dge,{})}),(0,K.jsx)(At,{path:`*`,element:(0,K.jsx)(fge,{})})]})]})})}(0,x.createRoot)(document.getElementById(`root`)).render((0,K.jsx)(y.StrictMode,{children:(0,K.jsx)(Sn,{children:(0,K.jsx)(xr,{defaultTheme:`dark`,storageKey:`omem-theme`,children:(0,K.jsxs)(Ep,{children:[(0,K.jsx)(Ap,{children:(0,K.jsx)(hge,{})}),(0,K.jsx)(vr,{position:`top-right`,richColors:!0,closeButton:!0})]})})})}));
package/web/index.html CHANGED
@@ -6,7 +6,7 @@
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <script>window.__OMEM_API_URL__ = "__OMEM_API_URL__";</script>
8
8
  <title>omem - 记忆管理</title>
9
- <script type="module" crossorigin src="/assets/index-MUY9xCa2.js"></script>
9
+ <script type="module" crossorigin src="/assets/index-DmWQKvrX.js"></script>
10
10
  <link rel="stylesheet" crossorigin href="/assets/index-BASbdDDa.css">
11
11
  </head>
12
12
  <body>