@capybara-hq/plugin-memory 0.1.0-rc.1 → 0.1.0-rc.3

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.
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://capybarahq.com/schemas/plugin.v1.schema.json",
3
3
  "schemaVersion": 1,
4
4
  "name": "memory",
5
- "version": "0.1.0-rc.1",
5
+ "version": "0.1.0-rc.3",
6
6
  "publisher": "Capybara",
7
7
  "description": {
8
8
  "en": "Memory for agents: each agent remembers each member across conversations, with an index at run start, memory tools, hybrid search and a memory page",
@@ -18,7 +18,7 @@
18
18
  "entry": "./dist/index.mjs",
19
19
  "manifest": {
20
20
  "name": "memory",
21
- "version": "0.1.0-rc.1",
21
+ "version": "0.1.0-rc.3",
22
22
  "sdk": "^0.1.0-rc.19",
23
23
  "provides": [
24
24
  "context@1"
@@ -79,8 +79,8 @@
79
79
  "./dist/client/styles/memory.css"
80
80
  ],
81
81
  "integrity": {
82
- "./dist/client/client.mjs": "sha384-39CF00+4BxW9NA/1lgHdooTHvsjSoUGrB1sler9LxvdALiV/pFBoyhOJO/e1Xx5L",
83
- "./dist/client/styles/memory.css": "sha384-2kJzQZ84fDCzoeEsCBBIVXZcy8pzq+mUhMQZCOYt2shNPqxY0y+JeMCHqOuVIb8a"
82
+ "./dist/client/client.mjs": "sha384-w3Q/NS7M3ZgjV36jE10G1rNElrNIvn8m1OyNNV6zUIYcDhk172f6/La/mk5CQSFJ",
83
+ "./dist/client/styles/memory.css": "sha384-BQe777NlfcscoaVL9jDxkd8/fDSnC/ih1WwrWMpQecpcQalE+EOuqPGtCxDKB7PY"
84
84
  },
85
85
  "apiVersion": 1
86
86
  }
@@ -1 +1 @@
1
- import{defineClientExtension as $n,defineComponent as Gn}from"@capybara-hq/plugin-client";import{Badge as gn,Button as V,Icon as Q,KeyValue as pn,Select as Ke,Spinner as nn,Stack as Te,Text as W,useAccess as fn,useAction as bn,useClientStorage as vn,useLocale as ae,usePrefersReducedMotion as xn,useView as kn}from"@capybara-hq/plugin-client";import{useCallback as q,useEffect as U,useMemo as Nn,useRef as $,useState as F}from"react";var ye=["user","feedback","project","reference"],ln="agent",_e=e=>`dir:${e}`;function cn(e){return Math.min(18,4+1.2*Math.sqrt(Math.max(0,e)))}function dn(e,n){if(e===null)return .25;let t=Date.parse(e);if(Number.isNaN(t))return .25;let l=Math.max(0,(n-t)/864e5);return Math.max(.25,Math.exp(-l/30))}function Me(e){let n=2166136261;for(let t=0;t<e.length;t++)n^=e.charCodeAt(t),n=Math.imul(n,16777619);return(n>>>0)/4294967296}var un=e=>e<=0?0:120+(e-1)*80;function Ge(e,n){let t=[],l=new Map,d=[],a=o=>{let i=t.length;return t.push({...o,x:0,y:0,vx:0,vy:0,ring:0}),l.set(o.id,i),d.push([]),o.parent>=0&&d[o.parent]?.push(i),i};a({id:ln,kind:"agent",label:e.agentLabel,path:"",type:null,parent:-1,depth:0,pinned:!0,r:13,brightness:1,recent:!1,phase:0,memory:null});let s=o=>{let i=l.get(_e(o));if(i!==void 0)return i;let y=o.lastIndexOf("/"),g=y===-1?0:s(o.slice(0,y)),S=o.split("/")[0];return a({id:_e(o),kind:"dir",label:o.slice(y+1),path:o,type:ye.includes(S)?S:null,parent:g,depth:o.split("/").length,pinned:!1,r:4.5,brightness:1,recent:!1,phase:Me(o),memory:null})};for(let o of ye)s(o);let M=[...e.nodes].sort((o,i)=>o.path<i.path?-1:o.path>i.path?1:0);for(let o of M){if(l.has(o.id))continue;let i=o.dir===""?0:s(o.dir),y=o.path.slice(o.path.lastIndexOf("/")+1).replace(/\.md$/,""),g=dn(o.lastRecalledAt,n.now),S=o.lastRecalledAt===null?Number.NaN:Date.parse(o.lastRecalledAt);a({id:o.id,kind:"memory",label:y,path:o.path,type:o.type,parent:i,depth:(t[i]?.depth??0)+1,pinned:!1,r:cn(o.recalls),brightness:g,recent:!Number.isNaN(S)&&n.now-S<7*864e5,phase:Me(o.id),memory:o})}let I=[];for(let o=1;o<t.length;o++){let i=t[o];I.push({a:i.parent,b:o,kind:"tree",phase:i.phase})}let x=new Set;for(let o of e.edges){let i=l.get(o.from),y=l.get(o.to);if(i===void 0||y===void 0||i===y)continue;let g=o.kind==="semantic"?`s${Math.min(i,y)}~${Math.max(i,y)}`:`l${i}>${y}`;x.has(g)||(x.add(g),I.push({a:i,b:y,kind:o.kind,phase:Me(g)}))}let C=t.map(()=>new Set);for(let o of I)C[o.a]?.add(o.b),C[o.b]?.add(o.a);let v=new Array(t.length).fill(0);for(let o=t.length-1;o>=0;o--){let i=t[o]?.kind==="memory"?1:0,y=(d[o]??[]).reduce((g,S)=>g+(v[S]??0),0);v[o]=Math.max(1,i+y)}let h=(o,i,y)=>{let g=t[o],S=d[o]??[],R=i,X=S.reduce((Y,B)=>Y+(v[B]??1),0);S.forEach((Y,B)=>{let j=(y-i)*(v[Y]??1)/Math.max(1,X),_=t[Y],K=R+j/2+(_.phase-.5)*j*.3;_.ring=_.kind==="dir"?un(_.depth):(g.kind==="agent"?70:g.ring)+46+B%3*20+_.r,_.x=Math.cos(K)*_.ring,_.y=Math.sin(K)*_.ring,h(Y,R,R+j),R+=j})};h(0,-Math.PI/2,3*Math.PI/2);let r=n.previous??null;if(r!==null)for(let o of t){let i=r.index.get(o.id),y=i===void 0?void 0:r.nodes[i];y!==void 0&&(o.x=y.x,o.y=y.y)}return{nodes:t,edges:I,index:l,adjacency:C,alpha:r===null?1:.4}}function Se(e){let{nodes:n}=e,t=e.alpha,l=110,d=new Map;n.forEach((a,s)=>{let M=`${Math.floor(a.x/l)},${Math.floor(a.y/l)}`,I=d.get(M);I===void 0?d.set(M,[s]):I.push(s)});for(let a=0;a<n.length;a++){let s=n[a],M=Math.floor(s.x/l),I=Math.floor(s.y/l);for(let x=-1;x<=1;x++)for(let C=-1;C<=1;C++)for(let v of d.get(`${M+x},${I+C}`)??[]){if(v<=a)continue;let h=n[v],r=h.x-s.x,o=h.y-s.y,i=r*r+o*o;if(i===0&&(r=(s.phase-h.phase)*.1+.01,o=.01,i=r*r+o*o),i>l*l)continue;let y=Math.sqrt(i),g=60*t/y,S=s.r+h.r+6;y<S&&(g+=(S-y)*.5);let R=r/y*g,X=o/y*g;s.vx-=R,s.vy-=X,h.vx+=R,h.vy+=X}}for(let a of e.edges){if(a.kind==="semantic")continue;let s=n[a.a],M=n[a.b],I=M.x-s.x,x=M.y-s.y,C=Math.sqrt(I*I+x*x)||1,v=a.kind==="tree"?Math.max(30,M.ring-s.ring):90,h=(C-v)/C*t*(a.kind==="tree"?.12:.015);s.vx+=I*h*.5,s.vy+=x*h*.5,M.vx-=I*h*.5,M.vy-=x*h*.5}for(let a of n){if(a.kind==="agent")continue;let s=Math.sqrt(a.x*a.x+a.y*a.y)||1,M=(a.ring-s)/s*.08*t;a.vx+=a.x*M,a.vy+=a.y*M}for(let a of n){if(a.pinned){a.vx=0,a.vy=0,a.kind==="agent"&&(a.x=0,a.y=0);continue}a.vx*=.6,a.vy*=.6,a.x+=a.vx,a.y+=a.vy}return e.alpha+=(0-e.alpha)*.03,e.alpha}function Be(e,n=240){for(let t=0;t<n&&e.alpha>=.005;t++)Se(e);e.alpha=0}function Ie(e,n,t,l=3){let d=-1,a=Number.POSITIVE_INFINITY;for(let s=e.nodes.length-1;s>=0;s--){let M=e.nodes[s],I=Math.hypot(M.x-n,M.y-t);I<=M.r+l&&I<a&&(d=s,a=I)}return d}var Fe=.15,mn=4,ie=(e,n,t)=>({x:(n-e.x)/e.k,y:(t-e.y)/e.k});function Pe(e,n,t,l=48){let d=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY,M=Number.NEGATIVE_INFINITY;for(let v of e.nodes)d=Math.min(d,v.x-v.r),a=Math.min(a,v.y-v.r),s=Math.max(s,v.x+v.r),M=Math.max(M,v.y+v.r);let I=Math.max(1,s-d),x=Math.max(1,M-a),C=Math.min(1.6,Math.max(Fe,Math.min((n-2*l)/I,(t-2*l)/x)));return{k:C,x:n/2-(d+s)/2*C,y:t/2-(a+M)/2*C}}function Ye(e,n,t,l){let d=Math.min(mn,Math.max(Fe,e.k*l)),a=ie(e,n,t);return{k:d,x:n-a.x*d,y:t-a.y*d}}function He(e){let n=getComputedStyle(e),t=(a,s)=>n.getPropertyValue(a).trim()||s,l=t("--cb-ink","CanvasText"),d=t("--cb-accent",l);return{type:{user:t("--cx-memory-type-user",d),feedback:t("--cx-memory-type-feedback",t("--cb-warn",l)),project:t("--cx-memory-type-project",t("--cb-ok",l)),reference:t("--cx-memory-type-reference",l)},agent:t("--cx-memory-agent",d),ink:l,muted:t("--cb-muted","GrayText"),faint:t("--cb-faint","GrayText"),bg:t("--cb-bg","Canvas"),font:t("--cb-font","monospace")}}function $e(e,n){let t=Math.hypot(e.x,e.y),l=Math.atan2(n.y,n.x);return t<1?{x:(e.x+n.x)/2,y:(e.y+n.y)/2}:{x:Math.cos(l)*t,y:Math.sin(l)*t}}function hn(e,n,t,l){let d=1-l;return{x:d*d*e.x+2*d*l*n.x+l*l*t.x,y:d*d*e.y+2*d*l*n.y+l*l*t.y}}var we=(e,n)=>n.kind==="agent"?e.agent:n.type===null?e.muted:e.type[n.type];function je(e,n,t,l,d){let{nodes:a}=n,s=t.k;e.setTransform(d.dpr,0,0,d.dpr,0,0),e.clearRect(0,0,d.width,d.height),e.translate(t.x,t.y),e.scale(s,s);let M=new Set;if(d.hover>=0){M.add(d.hover);for(let r of n.adjacency[d.hover]??[])M.add(r)}let I=r=>d.highlight===null||d.highlight.has(r.id),x=r=>{let o=a[r];return M.size>0?M.has(r)?1:.15:d.highlight!==null?o.kind!=="memory"||I(o)?1:.15:1},C=r=>{if(!d.motion||r.kind!=="memory")return{x:r.x,y:r.y};let o=r.phase*Math.PI*2;return{x:r.x+Math.sin(d.time/1700+o)*1.4,y:r.y+Math.cos(d.time/2100+o)*1.4}},v=a.map(C),h=1/s;e.setLineDash([3*h,4*h]),e.lineWidth=h,e.strokeStyle=l.muted;for(let r of n.edges){if(r.kind!=="semantic")continue;let o=v[r.a],i=v[r.b];e.globalAlpha=.28*Math.min(x(r.a),x(r.b)),e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(i.x,i.y),e.stroke()}e.setLineDash([]);for(let r of n.edges){if(r.kind!=="tree")continue;let o=a[r.a],i=a[r.b],y=v[r.a],g=v[r.b],S=$e(o,i);e.globalAlpha=(i.kind==="dir"?.45:.22+.25*i.brightness)*Math.min(x(r.a),x(r.b)),e.strokeStyle=we(l,i),e.lineWidth=(i.kind==="dir"?1.4:1)*h,e.beginPath(),e.moveTo(y.x,y.y),e.quadraticCurveTo(S.x,S.y,g.x,g.y),e.stroke()}e.strokeStyle=l.ink,e.lineWidth=1.2*h;for(let r of n.edges){if(r.kind!=="link")continue;let o=v[r.a],i=v[r.b];e.globalAlpha=.5*Math.min(x(r.a),x(r.b)),e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(i.x,i.y),e.stroke()}if(d.motion)for(let r of n.edges){let o=a[r.b];if(r.kind==="semantic"||r.kind==="tree"&&!o.recent)continue;let i=(d.time/(r.kind==="link"?3200:2600)+r.phase)%1,y=v[r.a],g=v[r.b],S=r.kind==="tree"?hn(y,$e(a[r.a],o),g,i):{x:y.x+(g.x-y.x)*i,y:y.y+(g.y-y.y)*i};e.globalAlpha=Math.sin(Math.PI*i)*.9*Math.min(x(r.a),x(r.b)),e.fillStyle=r.kind==="link"?l.ink:we(l,o),e.beginPath(),e.arc(S.x,S.y,1.8*h,0,Math.PI*2),e.fill()}if(a.forEach((r,o)=>{let i=v[o],y=x(o),g=we(l,r);if(r.kind==="dir"){e.globalAlpha=y,e.fillStyle=l.bg,e.strokeStyle=g,e.lineWidth=1.4*h,e.beginPath(),e.arc(i.x,i.y,r.r,0,Math.PI*2),e.fill(),e.stroke();return}if(r.kind==="agent"){let S=d.motion?Math.sin(d.time/900)*2:0;e.fillStyle=g,e.globalAlpha=.12*y,e.beginPath(),e.arc(i.x,i.y,r.r*2.4+S,0,Math.PI*2),e.fill(),e.globalAlpha=.35*y,e.strokeStyle=g,e.lineWidth=h,e.beginPath(),e.arc(i.x,i.y,r.r+6+S/2,0,Math.PI*2),e.stroke(),e.globalAlpha=y,e.beginPath(),e.arc(i.x,i.y,r.r,0,Math.PI*2),e.fill();return}if(r.brightness>.4&&(e.globalAlpha=.14*r.brightness*y,e.fillStyle=g,e.beginPath(),e.arc(i.x,i.y,r.r*2.2,0,Math.PI*2),e.fill()),d.motion&&r.recent){let S=(d.time/2400+r.phase)%1;e.globalAlpha=(1-S)*.5*y,e.strokeStyle=g,e.lineWidth=h,e.beginPath(),e.arc(i.x,i.y,r.r+2+S*10,0,Math.PI*2),e.stroke()}e.globalAlpha=(.3+.7*r.brightness)*y,e.fillStyle=g,e.beginPath(),e.arc(i.x,i.y,r.r,0,Math.PI*2),e.fill(),d.highlight?.has(r.id)===!0&&(e.globalAlpha=.9,e.strokeStyle=g,e.lineWidth=1.5*h,e.beginPath(),e.arc(i.x,i.y,r.r+4,0,Math.PI*2),e.stroke()),r.id===d.selectedId&&(e.globalAlpha=1,e.strokeStyle=l.ink,e.lineWidth=2*h,e.beginPath(),e.arc(i.x,i.y,r.r+3.5,0,Math.PI*2),e.stroke())}),d.focus>=0){let r=a[d.focus],o=v[d.focus];r!==void 0&&o!==void 0&&(e.globalAlpha=1,e.strokeStyle=l.agent,e.setLineDash([3*h,3*h]),e.lineWidth=1.5*h,e.beginPath(),e.arc(o.x,o.y,r.r+7,0,Math.PI*2),e.stroke(),e.setLineDash([]))}e.textBaseline="middle",a.forEach((r,o)=>{let i=v[o],y=x(o);if(!(r.kind!=="memory"||s>=1.35||M.has(o)||o===d.focus||r.id===d.selectedId||(d.highlight?.has(r.id)??!1)))return;let S=r.kind==="agent"?12:11;if(e.font=`${r.kind==="dir"?"":"500 "}${S*h}px ${l.font}`,e.globalAlpha=(r.kind==="memory"?.9:r.kind==="dir"?.75:1)*y,e.fillStyle=r.kind==="dir"?l.muted:l.ink,r.kind==="agent")e.textAlign="center",e.fillText(r.label,i.x,i.y+r.r+18*h);else{e.textAlign="left";let R=r.kind==="dir"?`${r.label}/`:r.label;e.fillText(R,i.x+r.r+5*h,i.y)}}),e.globalAlpha=1}var Ve={zh:"已删除的记忆不会再出现在新的索引里,但之前对话中已出现的内容仍保留在那些对话的记录中。",en:"Deleted memories no longer appear in new indexes, but what earlier conversations already showed stays in those conversations' records."},Ce={user:{zh:"用户",en:"User"},feedback:{zh:"反馈",en:"Feedback"},project:{zh:"项目",en:"Project"},reference:{zh:"参考",en:"Reference"}},m={agent:{zh:"智能体",en:"Agent"},member:{zh:"成员",en:"Member"},search:{zh:"搜索记忆",en:"Search memories"},clearSearch:{zh:"清除搜索",en:"Clear search"},noHits:{zh:"没有找到相关的记忆。",en:"No matching memories."},graph:{zh:"图谱",en:"Graph"},list:{zh:"列表",en:"List"},view:{zh:"显示方式",en:"View"},fit:{zh:"适配视图",en:"Fit to view"},fullscreen:{zh:"全屏",en:"Full screen"},exitFullscreen:{zh:"退出全屏",en:"Exit full screen"},loading:{zh:"正在载入记忆…",en:"Loading memories…"},failed:{zh:"记忆载入失败。",en:"Could not load the memories."},retry:{zh:"重试",en:"Retry"},noAccess:{zh:"只有组织成员可以查看记忆。",en:"Only org members can see memories."},emptyTitle:{zh:"还没有记忆",en:"No memories yet"},emptyBody:{zh:"智能体在一对一对话中记下关于你的事情后,会出现在这里。",en:"When an agent remembers something about you in a one-to-one conversation, it shows up here."},emptyAgent:{zh:"这个智能体还没有关于你的记忆。",en:"This agent has no memories about you yet."},emptyOther:{zh:"这位成员和这个智能体之间还没有记忆。",en:"This member has no memories with this agent yet."},sizeLegend:{zh:"大小:被想起的次数",en:"Size: times recalled"},glowLegend:{zh:"亮度:最近一次被想起",en:"Brightness: last recalled"},linkLegend:{zh:"实线:记忆里写下的链接",en:"Solid: links written in memories"},semanticLegend:{zh:"虚线:语义相近",en:"Dashed: semantically close"},hint:{zh:"拖动节点 · 拖动空白处平移 · 滚轮缩放 · 方向键逐条浏览",en:"Drag nodes · drag the background to pan · scroll to zoom · arrow keys to step through"},path:{zh:"路径",en:"Path"},description:{zh:"描述",en:"Description"},body:{zh:"正文",en:"Body"},recalled:{zh:"被想起",en:"Recalled"},lastRecalled:{zh:"最近想起",en:"Last recalled"},never:{zh:"从未",en:"Never"},created:{zh:"创建于",en:"Created"},updated:{zh:"更新于",en:"Updated"},createdIn:{zh:"来自对话",en:"Written in"},openConversation:{zh:"打开对话",en:"Open the conversation"},links:{zh:"链接",en:"Links"},dangling:{zh:"尚未写下",en:"not written yet"},edit:{zh:"编辑",en:"Edit"},save:{zh:"保存",en:"Save"},cancel:{zh:"取消",en:"Cancel"},delete:{zh:"删除",en:"Delete"},close:{zh:"关闭",en:"Close"},confirmTitle:{zh:"删除这条记忆?",en:"Delete this memory?"},actionFailed:{zh:"操作没有完成:",en:"The action did not complete: "},readOnly:{zh:"管理员不能编辑其他成员的记忆。",en:"Admins cannot edit another member's memories."}},Ee=e=>({zh:`${e} 条记忆`,en:e===1?"1 memory":`${e} memories`}),We=(e,n)=>({zh:`正在载入 ${e} / ${n}`,en:`Loading ${e} of ${n}`}),ze=e=>({zh:`${e} 次`,en:e===1?"once":`${e} times`}),Xe=e=>({zh:`你正在查看 ${e} 的记忆。每次查看和删除都会记入审计日志;管理员不能编辑其他成员的记忆。`,en:`You are viewing ${e}'s memories. Every view and delete is recorded in the audit log; admins cannot edit another member's memories.`}),qe=e=>({zh:`记忆图谱,共 ${e} 条记忆。用方向键逐条浏览,回车打开,Esc 关闭。`,en:`Memory graph with ${e} memories. Use the arrow keys to step through them, Enter to open one and Escape to close it.`}),Ue=(e,n)=>({zh:`${e} / ${n} 字节`,en:`${e} / ${n} bytes`});function ge(e,n,t=Date.now()){if(e===null)return m.never[n];let l=Date.parse(e);if(Number.isNaN(l))return m.never[n];let d=new Intl.RelativeTimeFormat(n==="zh"?"zh-CN":"en",{numeric:"auto"}),a=Math.round((l-t)/1e3),s=Math.abs(a);return s<60?d.format(a,"second"):s<3600?d.format(Math.round(a/60),"minute"):s<86400?d.format(Math.round(a/3600),"hour"):s<86400*30?d.format(Math.round(a/86400),"day"):s<86400*365?d.format(Math.round(a/(86400*30)),"month"):d.format(Math.round(a/(86400*365)),"year")}function Ae(e,n){let t=Date.parse(e);return Number.isNaN(t)?e:new Intl.DateTimeFormat(n==="zh"?"zh-CN":"en",{dateStyle:"medium",timeStyle:"short"}).format(t)}import{Fragment as _n,jsx as c,jsxs as N}from"react/jsx-runtime";var De=8192,Ze=200,Mn=300,wn=200,Sn=300,oe=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function pe(e){return oe(e)&&Array.isArray(e.nodes)&&Array.isArray(e.edges)&&Array.isArray(e.agents)&&typeof e.canAdmin=="boolean"&&oe(e.selection)?e:null}function In(e){return oe(e)&&Array.isArray(e.nodes)&&Array.isArray(e.edges)&&!("selection"in e)?e:null}var Qe=e=>oe(e)&&oe(e.detail)?e.detail:null,Pn=e=>oe(e)&&Array.isArray(e.hits)?e.hits:null,Je=e=>`${e.kind}:${e.from}>${e.to}`;function Cn(e,n){let t=new Map(e.map(l=>[l.id,l]));for(let l of n)t.set(l.id,l);return[...t.values()]}function En(e,n){let t=new Map(e.map(l=>[Je(l),l]));for(let l of n)t.set(Je(l),l);return[...t.values()]}var en=(e,n)=>e.selection.agentId===n.selection.agentId&&e.selection.accountId===n.selection.accountId;function le(e){let n={accountId:e.selection.accountId};return e.selection.agentId!==null&&(n.agentId=e.selection.agentId),n}var zn=e=>e instanceof Error?e.message:String(e);function tn(){let{view:e,status:n,retry:t}=kn(),l=bn(),d=fn(),{locale:a,t:s}=ae(),M=xn(),I=vn(),[x,C]=F(null),v=$(0),h=$(null);h.current=x;let[r,o]=F(!1),[i,y]=F(null),[g,S]=F(null),[R,X]=F(null),[Y,B]=F(""),[j,_]=F(null),[K,ce]=F(()=>{let u=I.get("view");return u==="graph"||u==="list"?u:null}),[ve,de]=F(0),J=$(null),[ee,xe]=F(!1);U(()=>{let u=()=>xe(document.fullscreenElement===J.current);return document.addEventListener("fullscreenchange",u),()=>document.removeEventListener("fullscreenchange",u)},[]);let b=()=>{if(document.fullscreenElement===J.current){document.exitFullscreen();return}J.current?.requestFullscreen?.().catch(()=>{})},p=q((u,A)=>{C(E=>E!==null&&E.source===u||!A&&E!==null&&!en(E.source,u)?E:(v.current+=1,{source:u,nodes:u.nodes,edges:u.edges,cursor:u.cursor,pages:1,gen:v.current}))},[]),k=$(s);k.current=s;let f=q(u=>y(k.current(m.actionFailed)+zn(u)),[]),P=$(!1),T=$(void 0);U(()=>{if(T.current===e&&e!==null)return;T.current=e;let u=pe(e?.data);if(u!==null){p(u,!1);return}n==="ready"&&h.current===null&&!P.current&&(P.current=!0,l("select",{payload:{}}).then(A=>{let E=pe(A.view?.data);E!==null&&p(E,!0)}).catch(f))},[e,n,p,l,f]);let D=x?.gen,z=x?.cursor??null;U(()=>{let u=h.current;if(u===null||z===null||u.gen!==D)return;let A=!0,E=()=>C(L=>L!==null&&L.gen===u.gen?{...L,cursor:null}:L);return l("more",{payload:{...le(u.source),cursor:z}}).then(L=>{if(!A)return;let G=In(L.view?.data);if(G===null)return E();C(O=>{if(O===null||O.gen!==u.gen)return O;let re=G.cursor===O.cursor||O.pages+1>=wn?null:G.cursor;return{...O,nodes:Cn(O.nodes,G.nodes),edges:En(O.edges,G.edges),cursor:re,pages:O.pages+1}})}).catch(L=>{A&&(f(L),E())}),()=>{A=!1}},[D,z,l,f]);let w=x?.source??null,H=w?.editable??!1,Z=$(null),ne=q(()=>{Z.current=null,X(null),S(null)},[]),ue=$(0),Le=q(async u=>{ue.current+=1,o(!0),y(null);try{let A=await l("select",{payload:u}),E=pe(A.view?.data);E!==null&&(p(E,!0),ne(),_(null),B(""),de(L=>L+1))}catch(A){f(A)}finally{o(!1)}},[l,p,ne,f]),me=q(async u=>{let A=h.current;if(A!==null){Z.current=u,X(u),y(null);try{let E=await l("open",{payload:{...le(A.source),memoryId:u}});if(Z.current!==u)return;let L=Qe(E.view?.data);if(L===null){Z.current=null,X(null);return}S(L)}catch(E){f(E)}}},[l,f]),rn=q(async(u,A,E)=>{let L=h.current;if(L===null)return!1;try{let G=await l("edit",{payload:{...le(L.source),memoryId:u,description:A,body:E}}),O=Qe(G.view?.data);return O===null?!1:(S(O),C(re=>re===null?re:{...re,nodes:re.nodes.map(Ne=>Ne.id===O.id?{...Ne,description:O.description}:Ne)}),!0)}catch(G){return f(G),!1}},[l,f]),on=q(async u=>{let A=h.current;if(A!==null)try{let E=await l("delete",{payload:{...le(A.source),memoryId:u}}),L=pe(E.view?.data);if(L===null)return;p(L,!0),ne(),_(G=>G===null?G:G.filter(O=>O.id!==u))}catch(E){f(E)}},[l,p,ne,f]),ke=q(async u=>{let A=h.current;if(A===null||A.source.selection.agentId===null)return;let E=++ue.current;if(u.trim()===""){_(null);return}let L=()=>E!==ue.current||h.current===null||!en(h.current.source,A.source);try{let G=await l("search",{payload:{...le(A.source),query:u}});if(L())return;let O=Pn(G.view?.data);O!==null&&_(O)}catch(G){L()||f(G)}},[l,f]);if(U(()=>{if(Y.trim()===""){ue.current+=1,_(null);return}let u=setTimeout(()=>{ke(Y)},Sn);return()=>clearTimeout(u)},[Y,ke]),!d.atLeast("member"))return c(fe,{icon:"lock",title:s(m.noAccess)});if(x===null||w===null)return n==="failed"?c(fe,{icon:"circle-alert",title:s(m.failed),children:c(V,{onClick:t,children:s(m.retry)})}):N("div",{className:"cx-memory-state",children:[c(nn,{label:s(m.loading)}),c(W,{tone:"muted",children:s(m.loading)})]});if(w.selection.agentId===null&&w.agents.length===0&&!w.canAdmin)return c(fe,{icon:"empty",title:s(m.emptyTitle),body:s(m.emptyBody)});let te=x.nodes,he=K??(w.total>Mn?"list":"graph"),Re=u=>{ce(u),I.set("view",u)},an=w.agents.find(u=>u.id===w.selection.agentId)?.name??"",sn=w.members?.find(u=>u.id===w.selection.accountId)?.name??w.selection.accountId,Oe=j===null?null:new Set(j.map(u=>u.id)),se=te.length===0;return N("div",{ref:J,className:"cx-memory-page","data-panel":R!==null?"open":"closed","data-empty":se&&j===null?"true":"false","data-fullscreen":ee?"true":"false",children:[N("form",{className:"cx-memory-toolbar",onSubmit:u=>{u.preventDefault(),ke(Y)},children:[N("div",{className:"cx-memory-field",children:[c("span",{className:"cx-memory-field-label",children:s(m.agent)}),c(Ke,{value:w.selection.agentId??"","aria-label":s(m.agent),placeholder:"—",disabled:r||w.agents.length===0,options:w.agents.map(u=>({value:u.id,label:u.name})),onChange:u=>{Le({agentId:u.target.value,accountId:w.selection.accountId})}})]}),w.canAdmin&&w.members!==void 0?N("div",{className:"cx-memory-field",children:[c("span",{className:"cx-memory-field-label",children:s(m.member)}),c(Ke,{value:w.selection.accountId,"aria-label":s(m.member),disabled:r,options:w.members.map(u=>({value:u.id,label:u.name})),onChange:u=>{Le({accountId:u.target.value})}})]}):null,se?null:N("div",{className:"cx-memory-search",children:[c(Q,{name:"search",size:14}),c("input",{className:"cx-memory-input",type:"search",value:Y,placeholder:s(m.search),"aria-label":s(m.search),maxLength:500,disabled:w.selection.agentId===null,onChange:u=>B(u.target.value),onKeyDown:u=>{u.key==="Escape"&&B("")}})]}),N("div",{className:"cx-memory-toolbar-end",children:[c(W,{variant:"small",tone:"muted",children:x.cursor!==null?s(We(te.length,w.total)):s(Ee(Math.max(w.total,te.length)))}),se?null:N("fieldset",{className:"cx-memory-toggle",children:[c("legend",{className:"cx-memory-sr",children:s(m.view)}),c("button",{type:"button",className:"cx-memory-toggle-item","aria-pressed":he==="graph",onClick:()=>Re("graph"),children:s(m.graph)}),c("button",{type:"button",className:"cx-memory-toggle-item","aria-pressed":he==="list",onClick:()=>Re("list"),children:s(m.list)})]}),he==="graph"&&!se?c(V,{variant:"ghost",title:s(m.fit),"aria-label":s(m.fit),onClick:()=>de(u=>u+1),children:c(Q,{name:"zoom-in",size:14})}):null,c(V,{variant:"ghost",title:s(ee?m.exitFullscreen:m.fullscreen),"aria-label":s(ee?m.exitFullscreen:m.fullscreen),onClick:b,children:c(Q,{name:ee?"minimize-2":"maximize-2",size:14})})]})]}),H?null:N("div",{className:"cx-memory-banner",role:"note",children:[c(Q,{name:"admin",size:14}),c(W,{variant:"small",children:s(Xe(sn))})]}),i!==null?c("div",{className:"cx-memory-banner","data-tone":"fail",role:"alert",children:c(W,{variant:"small",tone:"fail",children:i})}):null,N("div",{className:"cx-memory-body",children:[N("div",{className:"cx-memory-main",children:[j!==null?c(Ln,{hits:j,onOpen:me,onClear:()=>B("")}):null,se?c(fe,{icon:"empty",title:s(m.emptyTitle),body:s(w.selection.agentId===null?m.emptyBody:H?m.emptyAgent:m.emptyOther)}):he==="graph"?c(Tn,{nodes:te,edges:x.edges,agentLabel:an,motion:!M,selectedId:R,highlight:Oe,fitSignal:ve,onOpen:u=>{me(u)},onEscape:ne,label:s(qe(te.length))}):c(Dn,{nodes:te,highlight:Oe,selectedId:R,onOpen:u=>{me(u)}})]}),R!==null?c(On,{detail:g?.id===R?g:null,editable:H,canDelete:H||w.canAdmin,locale:a,onClose:ne,onOpen:u=>{me(u)},onSave:rn,onDelete:on},R):null]})]})}function fe(e){return N("div",{className:"cx-memory-state",children:[c("span",{className:"cx-memory-state-icon","aria-hidden":"true",children:c(Q,{name:e.icon,size:16})}),c(W,{variant:"h3",children:e.title}),e.body!==void 0?c(W,{tone:"muted",children:e.body}):null,e.children]})}function be({type:e}){return c("span",{className:"cx-memory-dot","data-type":e,"aria-hidden":"true"})}function An(){let{t:e}=ae();return N("div",{className:"cx-memory-legend","aria-hidden":"true",children:[c("div",{className:"cx-memory-legend-row",children:ye.map(n=>N("span",{className:"cx-memory-legend-item",children:[c(be,{type:n}),e(Ce[n])]},n))}),N("div",{className:"cx-memory-legend-row",children:[N("span",{className:"cx-memory-legend-item",children:[c("span",{className:"cx-memory-legend-line","data-kind":"link"}),e(m.linkLegend)]}),N("span",{className:"cx-memory-legend-item",children:[c("span",{className:"cx-memory-legend-line","data-kind":"semantic"}),e(m.semanticLegend)]})]}),N("div",{className:"cx-memory-legend-row",children:[c("span",{className:"cx-memory-legend-item",children:e(m.sizeLegend)}),c("span",{className:"cx-memory-legend-item",children:e(m.glowLegend)})]})]})}function Tn(e){let{locale:n,t}=ae(),l=$(null),d=$(null),a=$(null),s=$({x:0,y:0,k:1}),M=$({w:0,h:0,dpr:1}),I=$(-1),x=$(-1),C=$(!1),v=$(null),h=$(e);h.current=e;let[r,o]=F(null),[i,y]=F(null),g=q((b=0)=>{let p=d.current,k=a.current;if(p===null||k===null)return;let f=p.getContext("2d");if(f===null)return;let{w:P,h:T,dpr:D}=M.current,z=h.current;je(f,k,s.current,He(p),{width:P,height:T,dpr:D,time:b,motion:z.motion,hover:I.current>=0?I.current:x.current,focus:x.current,selectedId:z.selectedId,highlight:z.highlight})},[]),S=q(()=>{let b=a.current,{w:p,h:k}=M.current;b===null||p===0||k===0||(s.current=Pe(b,p,k))},[]),{nodes:R,edges:X,agentLabel:Y,motion:B}=e;U(()=>{let b=a.current,p=Ge({nodes:R,edges:X,agentLabel:Y},{now:Date.now(),previous:b});B||Be(p),a.current=p,I.current=-1,x.current=-1,(b===null||!C.current)&&S(),B||g()},[R,X,Y,B,S,g]);let{fitSignal:j}=e;U(()=>{j!==0&&(C.current=!1,S(),g())},[j,S,g]);let{selectedId:_,highlight:K}=e;U(()=>{B||g()},[_,K,B,g]),U(()=>{let b=l.current,p=d.current;if(b===null||p===null)return;let k=()=>{let P=Math.max(1,Math.min(3,globalThis.devicePixelRatio||1)),T=b.clientWidth,D=b.clientHeight;M.current={w:T,h:D,dpr:P},p.width=Math.round(T*P),p.height=Math.round(D*P),C.current||S(),g()};if(k(),typeof ResizeObserver>"u")return;let f=new ResizeObserver(k);return f.observe(b),()=>f.disconnect()},[S,g]),U(()=>{if(!B)return;let b=0,p=k=>{let f=a.current;if(f!==null&&f.alpha>=.005){Se(f);let{w:P,h:T}=M.current;if(!C.current&&P>0&&T>0){let D=Pe(f,P,T),z=s.current;s.current={x:z.x+(D.x-z.x)*.12,y:z.y+(D.y-z.y)*.12,k:z.k+(D.k-z.k)*.12}}}g(k),b=requestAnimationFrame(p)};return b=requestAnimationFrame(p),()=>cancelAnimationFrame(b)},[B,g]),U(()=>{let b=d.current;if(b===null)return;let p=k=>{k.preventDefault();let f=b.getBoundingClientRect();C.current=!0,s.current=Ye(s.current,k.clientX-f.left,k.clientY-f.top,Math.exp(-k.deltaY*.0015)),h.current.motion||g()};return b.addEventListener("wheel",p,{passive:!1}),()=>b.removeEventListener("wheel",p)},[g]);let ce=b=>{let p=b.currentTarget.getBoundingClientRect();return{sx:b.clientX-p.left,sy:b.clientY-p.top}},ve=b=>{let p=a.current;if(p===null)return;let{sx:k,sy:f}=ce(b),P=ie(s.current,k,f),T=Ie(p,P.x,P.y,4/s.current.k);v.current={node:T,sx:k,sy:f,lastX:k,lastY:f,moved:!1},b.currentTarget.setPointerCapture?.(b.pointerId)},de=b=>{let p=a.current;if(p===null)return;let{sx:k,sy:f}=ce(b),P=v.current,T=h.current.motion;if(P!==null){if(!P.moved&&Math.hypot(k-P.sx,f-P.sy)<4)return;P.moved=!0,o(null);let w=P.node>=0?p.nodes[P.node]:void 0;if(w!==void 0&&w.kind!=="agent"){let H=ie(s.current,k,f);w.x=H.x,w.y=H.y,w.pinned=!0,T&&(p.alpha=Math.max(p.alpha,.25))}else{C.current=!0;let H=s.current;s.current={...H,x:H.x+k-P.lastX,y:H.y+f-P.lastY}}P.lastX=k,P.lastY=f,T||g();return}let D=ie(s.current,k,f),z=Ie(p,D.x,D.y,4/s.current.k);if(z!==I.current){I.current=z;let w=z>=0?p.nodes[z]?.memory??null:null;o(w===null?null:{x:k,y:f,node:w}),T||g()}},J=b=>{let p=v.current;v.current=null;let k=a.current;if(p===null||k===null)return;let f=p.node>=0?k.nodes[p.node]:void 0;if(p.moved){f!==void 0&&f.kind!=="agent"&&h.current.motion&&(f.pinned=!1);return}f?.memory&&h.current.onOpen(f.memory.id)},ee=()=>{v.current===null&&(I.current=-1,o(null),h.current.motion||g())},xe=b=>{let p=a.current;if(p===null)return;let k=p.nodes.flatMap((D,z)=>D.kind==="memory"?[z]:[]);if(k.length===0)return;let f=k.indexOf(x.current),P=-1;if(b.key==="ArrowRight"||b.key==="ArrowDown")P=k[(f+1)%k.length]??-1;else if(b.key==="ArrowLeft"||b.key==="ArrowUp")P=k[(f-1+k.length)%k.length]??-1;else if(b.key==="Home")P=k[0]??-1;else if(b.key==="End")P=k[k.length-1]??-1;else if(b.key==="Enter"||b.key===" "){let D=p.nodes[x.current]?.memory;D&&(b.preventDefault(),h.current.onOpen(D.id));return}else if(b.key==="Escape"){h.current.onEscape();return}else return;b.preventDefault(),x.current=P;let T=p.nodes[P];if(y(T?.memory??null),T!==void 0){let{w:D,h:z}=M.current,w=s.current,H=T.x*w.k+w.x,Z=T.y*w.k+w.y;D>0&&(H<40||Z<40||H>D-40||Z>z-40)&&(C.current=!0,s.current={...w,x:D/2-T.x*w.k,y:z/2-T.y*w.k})}h.current.motion||g()};return N("div",{className:"cx-memory-stage",ref:l,children:[c("canvas",{ref:d,className:"cx-memory-canvas",tabIndex:0,"aria-label":e.label,onPointerDown:ve,onPointerMove:de,onPointerUp:J,onPointerCancel:()=>{v.current=null},onPointerLeave:ee,onKeyDown:xe,onBlur:()=>{x.current=-1,y(null),h.current.motion||g()}}),c("div",{className:"cx-memory-sr cx-memory-live","aria-live":"polite",children:i!==null?`${i.path} — ${i.description}`:""}),r!==null?N("div",{className:"cx-memory-tip",style:{left:r.x+14,top:r.y+14},"aria-hidden":"true",children:[N("span",{className:"cx-memory-tip-path",children:[c(be,{type:r.node.type}),r.node.path]}),c("span",{className:"cx-memory-tip-desc",children:r.node.description}),N("span",{className:"cx-memory-tip-meta",children:[t(m.recalled)," ",t(ze(r.node.recalls))," · ",t(m.lastRecalled)," ",ge(r.node.lastRecalledAt,n)]})]}):null,c(An,{}),c("div",{className:"cx-memory-hint","aria-hidden":"true",children:t(m.hint)})]})}function Dn(e){let{locale:n,t}=ae(),l=Nn(()=>[...e.nodes].sort((a,s)=>a.path<s.path?-1:a.path>s.path?1:0),[e.nodes]),d=e.highlight===null?l:l.filter(a=>e.highlight?.has(a.id));return N("div",{className:"cx-memory-list",children:[N("div",{className:"cx-memory-list-head","aria-hidden":"true",children:[c("span",{children:t(m.path)}),c("span",{children:t(m.description)}),c("span",{children:t(m.recalled)}),c("span",{children:t(m.lastRecalled)})]}),c("ul",{className:"cx-memory-rows",children:d.map(a=>c("li",{children:N("button",{type:"button",className:"cx-memory-row","data-memory-id":a.id,"aria-current":a.id===e.selectedId?"true":void 0,onClick:()=>e.onOpen(a.id),children:[N("span",{className:"cx-memory-row-path",children:[c(be,{type:a.type}),a.path]}),c("span",{className:"cx-memory-row-desc",children:a.description}),c("span",{className:"cx-memory-row-num",children:a.recalls}),c("span",{className:"cx-memory-row-num",children:ge(a.lastRecalledAt,n)})]})},a.id))})]})}function Ln(e){let{t:n}=ae();return N("section",{className:"cx-memory-hits","aria-label":n(m.search),children:[N("div",{className:"cx-memory-hits-head",children:[c(W,{variant:"small",tone:"muted",children:e.hits.length===0?n(m.noHits):n(Ee(e.hits.length))}),c(V,{variant:"ghost",onClick:e.onClear,children:n(m.clearSearch)})]}),e.hits.map(t=>N("button",{type:"button",className:"cx-memory-hit",onClick:()=>e.onOpen(t.id),children:[c("span",{className:"cx-memory-hit-path",children:t.path}),c("span",{className:"cx-memory-hit-desc",children:t.description}),t.snippet!==""?c("span",{className:"cx-memory-hit-snippet",children:t.snippet}):null]},t.id))]})}var Rn=e=>new TextEncoder().encode(e).length;function On(e){let{t:n}=ae(),{detail:t,locale:l}=e,[d,a]=F("view"),[s,M]=F(""),[I,x]=F(""),[C,v]=F(!1);if(t===null)return c("aside",{className:"cx-memory-panel","aria-busy":"true",children:N("div",{className:"cx-memory-panel-head",children:[c(nn,{size:12}),c("span",{className:"cx-memory-grow"}),c(V,{variant:"ghost","aria-label":n(m.close),onClick:e.onClose,children:c(Q,{name:"x",size:14})})]})});let h=i=>i[l],r=Rn(I),o=s.trim()===""||s.length>Ze||/[\r\n]/.test(s)||r>De;return N("aside",{className:"cx-memory-panel","aria-label":t.path,children:[N("div",{className:"cx-memory-panel-head",children:[c(be,{type:t.type}),c("span",{className:"cx-memory-panel-path",children:t.path}),c(gn,{children:h(Ce[t.type])}),c("span",{className:"cx-memory-grow"}),c(V,{variant:"ghost","aria-label":n(m.close),onClick:e.onClose,children:c(Q,{name:"x",size:14})})]}),c("div",{className:"cx-memory-panel-body",children:d==="edit"?N("form",{className:"cx-memory-edit",onSubmit:i=>{i.preventDefault(),!o&&(v(!0),e.onSave(t.id,s,I).then(y=>{v(!1),y&&a("view")}))},children:[N("label",{className:"cx-memory-field","data-block":"true",children:[c("span",{className:"cx-memory-field-label",children:n(m.description)}),c("input",{className:"cx-memory-input",value:s,maxLength:Ze,onChange:i=>M(i.target.value)})]}),N("label",{className:"cx-memory-field","data-block":"true",children:[c("span",{className:"cx-memory-field-label",children:n(m.body)}),c("textarea",{className:"cx-memory-textarea",value:I,rows:12,onChange:i=>x(i.target.value)}),c("span",{className:"cx-memory-field-note","data-over":r>De,children:n(Ue(r,De))})]}),N(Te,{direction:"row",gap:8,justify:"end",children:[c(V,{onClick:()=>a("view"),children:n(m.cancel)}),c(V,{type:"submit",variant:"primary",loading:C,disabled:o,children:n(m.save)})]})]}):N(_n,{children:[c(W,{children:t.description}),c("div",{className:"cx-memory-markdown",children:t.body}),t.links.length>0?N("div",{className:"cx-memory-links",children:[c(W,{variant:"small",tone:"muted",children:n(m.links)}),t.links.map(i=>i.targetId!==null?N("button",{type:"button",className:"cx-memory-link",onClick:()=>e.onOpen(i.targetId),children:["[[",i.path,"]]"]},i.path):N("span",{className:"cx-memory-link","data-dangling":"true",children:["[[",i.path,"]] · ",n(m.dangling)]},i.path))]}):null,c(pn,{keyWidth:"12ch",rows:[{k:n(m.recalled),v:n(ze(t.recalls))},{k:n(m.lastRecalled),v:ge(t.lastRecalledAt,l)},{k:n(m.created),v:Ae(t.createdAt,l)},{k:n(m.updated),v:Ae(t.updatedAt,l)},...t.createdIn!==null?[{k:n(m.createdIn),v:e.editable?c("a",{className:"cx-memory-anchor",href:`/chat/${encodeURIComponent(t.createdIn)}`,children:n(m.openConversation)}):t.createdIn}]:[]]}),d==="confirm"?N("div",{className:"cx-memory-confirm",role:"alertdialog","aria-label":n(m.confirmTitle),children:[c(W,{variant:"h3",children:n(m.confirmTitle)}),c(W,{variant:"small",children:n(Ve)}),N(Te,{direction:"row",gap:8,justify:"end",children:[c(V,{onClick:()=>a("view"),children:n(m.cancel)}),c(V,{variant:"danger-solid",loading:C,onClick:()=>{v(!0),e.onDelete(t.id).finally(()=>v(!1))},children:n(m.delete)})]})]}):N(Te,{direction:"row",gap:8,justify:"end",children:[e.editable?c(V,{onClick:()=>{M(t.description),x(t.body),a("edit")},children:n(m.edit)}):null,e.canDelete?c(V,{variant:"danger",onClick:()=>a("confirm"),children:n(m.delete)}):null]}),e.editable?null:c(W,{variant:"small",tone:"muted",children:n(m.readOnly)})]})})]})}var Kn=$n({name:"memory",components:{overview:Gn("org.page",tn)}});export{Kn as default};
1
+ import{defineClientExtension as _n,defineComponent as $n}from"@capybara-hq/plugin-client";import{Badge as yn,Button as V,Icon as J,KeyValue as gn,Select as Ke,Spinner as en,Stack as Ae,Text as W,useAccess as pn,useAction as fn,useClientStorage as bn,useLocale as re,usePrefersReducedMotion as vn,useView as xn}from"@capybara-hq/plugin-client";import{useCallback as q,useEffect as K,useMemo as kn,useRef as G,useState as F}from"react";var he=["user","feedback","project","reference"],sn="agent",Oe=e=>`dir:${e}`;function ln(e){return Math.min(18,4+1.2*Math.sqrt(Math.max(0,e)))}function cn(e,n){if(e===null)return .25;let t=Date.parse(e);if(Number.isNaN(t))return .25;let l=Math.max(0,(n-t)/864e5);return Math.max(.25,Math.exp(-l/30))}function Ne(e){let n=2166136261;for(let t=0;t<e.length;t++)n^=e.charCodeAt(t),n=Math.imul(n,16777619);return(n>>>0)/4294967296}var dn=e=>e<=0?0:120+(e-1)*80;function $e(e,n){let t=[],l=new Map,d=[],a=o=>{let i=t.length;return t.push({...o,x:0,y:0,vx:0,vy:0,ring:0}),l.set(o.id,i),d.push([]),o.parent>=0&&d[o.parent]?.push(i),i};a({id:sn,kind:"agent",label:e.agentLabel,path:"",type:null,parent:-1,depth:0,pinned:!0,r:13,brightness:1,recent:!1,phase:0,memory:null});let s=o=>{let i=l.get(Oe(o));if(i!==void 0)return i;let g=o.lastIndexOf("/"),p=g===-1?0:s(o.slice(0,g)),w=o.split("/")[0];return a({id:Oe(o),kind:"dir",label:o.slice(g+1),path:o,type:he.includes(w)?w:null,parent:p,depth:o.split("/").length,pinned:!1,r:4.5,brightness:1,recent:!1,phase:Ne(o),memory:null})};for(let o of he)s(o);let M=[...e.nodes].sort((o,i)=>o.path<i.path?-1:o.path>i.path?1:0);for(let o of M){if(l.has(o.id))continue;let i=o.dir===""?0:s(o.dir),g=o.path.slice(o.path.lastIndexOf("/")+1).replace(/\.md$/,""),p=cn(o.lastRecalledAt,n.now),w=o.lastRecalledAt===null?Number.NaN:Date.parse(o.lastRecalledAt);a({id:o.id,kind:"memory",label:g,path:o.path,type:o.type,parent:i,depth:(t[i]?.depth??0)+1,pinned:!1,r:ln(o.recalls),brightness:p,recent:!Number.isNaN(w)&&n.now-w<7*864e5,phase:Ne(o.id),memory:o})}let S=[];for(let o=1;o<t.length;o++){let i=t[o];S.push({a:i.parent,b:o,kind:"tree",phase:i.phase})}let k=new Set;for(let o of e.edges){let i=l.get(o.from),g=l.get(o.to);if(i===void 0||g===void 0||i===g)continue;let p=o.kind==="semantic"?`s${Math.min(i,g)}~${Math.max(i,g)}`:`l${i}>${g}`;k.has(p)||(k.add(p),S.push({a:i,b:g,kind:o.kind,phase:Ne(p)}))}let C=t.map(()=>new Set);for(let o of S)C[o.a]?.add(o.b),C[o.b]?.add(o.a);let b=new Array(t.length).fill(0);for(let o=t.length-1;o>=0;o--){let i=t[o]?.kind==="memory"?1:0,g=(d[o]??[]).reduce((p,w)=>p+(b[w]??0),0);b[o]=Math.max(1,i+g)}let h=(o,i,g)=>{let p=t[o],w=d[o]??[],R=i,X=w.reduce((Y,B)=>Y+(b[B]??1),0);w.forEach((Y,B)=>{let j=(g-i)*(b[Y]??1)/Math.max(1,X),_=t[Y],Q=R+j/2+(_.phase-.5)*j*.3;_.ring=_.kind==="dir"?dn(_.depth):(p.kind==="agent"?70:p.ring)+46+B%3*20+_.r,_.x=Math.cos(Q)*_.ring,_.y=Math.sin(Q)*_.ring,h(Y,R,R+j),R+=j})};h(0,-Math.PI/2,3*Math.PI/2);let r=n.previous??null;if(r!==null)for(let o of t){let i=r.index.get(o.id),g=i===void 0?void 0:r.nodes[i];g!==void 0&&(o.x=g.x,o.y=g.y)}return{nodes:t,edges:S,index:l,adjacency:C,alpha:r===null?1:.4}}function we(e){let{nodes:n}=e,t=e.alpha,l=110,d=new Map;n.forEach((a,s)=>{let M=`${Math.floor(a.x/l)},${Math.floor(a.y/l)}`,S=d.get(M);S===void 0?d.set(M,[s]):S.push(s)});for(let a=0;a<n.length;a++){let s=n[a],M=Math.floor(s.x/l),S=Math.floor(s.y/l);for(let k=-1;k<=1;k++)for(let C=-1;C<=1;C++)for(let b of d.get(`${M+k},${S+C}`)??[]){if(b<=a)continue;let h=n[b],r=h.x-s.x,o=h.y-s.y,i=r*r+o*o;if(i===0&&(r=(s.phase-h.phase)*.1+.01,o=.01,i=r*r+o*o),i>l*l)continue;let g=Math.sqrt(i),p=60*t/g,w=s.r+h.r+6;g<w&&(p+=(w-g)*.5);let R=r/g*p,X=o/g*p;s.vx-=R,s.vy-=X,h.vx+=R,h.vy+=X}}for(let a of e.edges){if(a.kind==="semantic")continue;let s=n[a.a],M=n[a.b],S=M.x-s.x,k=M.y-s.y,C=Math.sqrt(S*S+k*k)||1,b=a.kind==="tree"?Math.max(30,M.ring-s.ring):90,h=(C-b)/C*t*(a.kind==="tree"?.12:.015);s.vx+=S*h*.5,s.vy+=k*h*.5,M.vx-=S*h*.5,M.vy-=k*h*.5}for(let a of n){if(a.kind==="agent")continue;let s=Math.sqrt(a.x*a.x+a.y*a.y)||1,M=(a.ring-s)/s*.08*t;a.vx+=a.x*M,a.vy+=a.y*M}for(let a of n){if(a.pinned){a.vx=0,a.vy=0,a.kind==="agent"&&(a.x=0,a.y=0);continue}a.vx*=.6,a.vy*=.6,a.x+=a.vx,a.y+=a.vy}return e.alpha+=(0-e.alpha)*.03,e.alpha}function Ge(e,n=240){for(let t=0;t<n&&e.alpha>=.005;t++)we(e);e.alpha=0}function Se(e,n,t,l=3){let d=-1,a=Number.POSITIVE_INFINITY;for(let s=e.nodes.length-1;s>=0;s--){let M=e.nodes[s],S=Math.hypot(M.x-n,M.y-t);S<=M.r+l&&S<a&&(d=s,a=S)}return d}var Be=.15,un=4,ae=(e,n,t)=>({x:(n-e.x)/e.k,y:(t-e.y)/e.k});function Ie(e,n,t,l=48){let d=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY,M=Number.NEGATIVE_INFINITY;for(let b of e.nodes)d=Math.min(d,b.x-b.r),a=Math.min(a,b.y-b.r),s=Math.max(s,b.x+b.r),M=Math.max(M,b.y+b.r);let S=Math.max(1,s-d),k=Math.max(1,M-a),C=Math.min(1.6,Math.max(Be,Math.min((n-2*l)/S,(t-2*l)/k)));return{k:C,x:n/2-(d+s)/2*C,y:t/2-(a+M)/2*C}}function Fe(e,n,t,l){let d=Math.min(un,Math.max(Be,e.k*l)),a=ae(e,n,t);return{k:d,x:n-a.x*d,y:t-a.y*d}}function Ye(e){let n=getComputedStyle(e),t=(a,s)=>n.getPropertyValue(a).trim()||s,l=t("--cb-ink","CanvasText"),d=t("--cb-accent",l);return{type:{user:t("--cx-memory-type-user",d),feedback:t("--cx-memory-type-feedback",t("--cb-warn",l)),project:t("--cx-memory-type-project",t("--cb-ok",l)),reference:t("--cx-memory-type-reference",l)},agent:t("--cx-memory-agent",d),ink:l,muted:t("--cb-muted","GrayText"),faint:t("--cb-faint","GrayText"),bg:t("--cb-bg","Canvas"),font:t("--cb-font","monospace")}}function _e(e,n){let t=Math.hypot(e.x,e.y),l=Math.atan2(n.y,n.x);return t<1?{x:(e.x+n.x)/2,y:(e.y+n.y)/2}:{x:Math.cos(l)*t,y:Math.sin(l)*t}}function mn(e,n,t,l){let d=1-l;return{x:d*d*e.x+2*d*l*n.x+l*l*t.x,y:d*d*e.y+2*d*l*n.y+l*l*t.y}}var Me=(e,n)=>n.kind==="agent"?e.agent:n.type===null?e.muted:e.type[n.type];function He(e,n,t,l,d){let{nodes:a}=n,s=t.k;e.setTransform(d.dpr,0,0,d.dpr,0,0),e.clearRect(0,0,d.width,d.height),e.translate(t.x,t.y),e.scale(s,s);let M=new Set;if(d.hover>=0){M.add(d.hover);for(let r of n.adjacency[d.hover]??[])M.add(r)}let S=r=>d.highlight===null||d.highlight.has(r.id),k=r=>{let o=a[r];return M.size>0?M.has(r)?1:.15:d.highlight!==null?o.kind!=="memory"||S(o)?1:.15:1},C=r=>{if(!d.motion||r.kind!=="memory")return{x:r.x,y:r.y};let o=r.phase*Math.PI*2;return{x:r.x+Math.sin(d.time/1700+o)*1.4,y:r.y+Math.cos(d.time/2100+o)*1.4}},b=a.map(C),h=1/s;e.setLineDash([3*h,4*h]),e.lineWidth=h,e.strokeStyle=l.muted;for(let r of n.edges){if(r.kind!=="semantic")continue;let o=b[r.a],i=b[r.b];e.globalAlpha=.28*Math.min(k(r.a),k(r.b)),e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(i.x,i.y),e.stroke()}e.setLineDash([]);for(let r of n.edges){if(r.kind!=="tree")continue;let o=a[r.a],i=a[r.b],g=b[r.a],p=b[r.b],w=_e(o,i);e.globalAlpha=(i.kind==="dir"?.45:.22+.25*i.brightness)*Math.min(k(r.a),k(r.b)),e.strokeStyle=Me(l,i),e.lineWidth=(i.kind==="dir"?1.4:1)*h,e.beginPath(),e.moveTo(g.x,g.y),e.quadraticCurveTo(w.x,w.y,p.x,p.y),e.stroke()}e.strokeStyle=l.ink,e.lineWidth=1.2*h;for(let r of n.edges){if(r.kind!=="link")continue;let o=b[r.a],i=b[r.b];e.globalAlpha=.5*Math.min(k(r.a),k(r.b)),e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(i.x,i.y),e.stroke()}if(d.motion)for(let r of n.edges){let o=a[r.b];if(r.kind==="semantic"||r.kind==="tree"&&!o.recent)continue;let i=(d.time/(r.kind==="link"?3200:2600)+r.phase)%1,g=b[r.a],p=b[r.b],w=r.kind==="tree"?mn(g,_e(a[r.a],o),p,i):{x:g.x+(p.x-g.x)*i,y:g.y+(p.y-g.y)*i};e.globalAlpha=Math.sin(Math.PI*i)*.9*Math.min(k(r.a),k(r.b)),e.fillStyle=r.kind==="link"?l.ink:Me(l,o),e.beginPath(),e.arc(w.x,w.y,1.8*h,0,Math.PI*2),e.fill()}if(a.forEach((r,o)=>{let i=b[o],g=k(o),p=Me(l,r);if(r.kind==="dir"){e.globalAlpha=g,e.fillStyle=l.bg,e.strokeStyle=p,e.lineWidth=1.4*h,e.beginPath(),e.arc(i.x,i.y,r.r,0,Math.PI*2),e.fill(),e.stroke();return}if(r.kind==="agent"){let w=d.motion?Math.sin(d.time/900)*2:0;e.fillStyle=p,e.globalAlpha=.12*g,e.beginPath(),e.arc(i.x,i.y,r.r*2.4+w,0,Math.PI*2),e.fill(),e.globalAlpha=.35*g,e.strokeStyle=p,e.lineWidth=h,e.beginPath(),e.arc(i.x,i.y,r.r+6+w/2,0,Math.PI*2),e.stroke(),e.globalAlpha=g,e.beginPath(),e.arc(i.x,i.y,r.r,0,Math.PI*2),e.fill();return}if(r.brightness>.4&&(e.globalAlpha=.14*r.brightness*g,e.fillStyle=p,e.beginPath(),e.arc(i.x,i.y,r.r*2.2,0,Math.PI*2),e.fill()),d.motion&&r.recent){let w=(d.time/2400+r.phase)%1;e.globalAlpha=(1-w)*.5*g,e.strokeStyle=p,e.lineWidth=h,e.beginPath(),e.arc(i.x,i.y,r.r+2+w*10,0,Math.PI*2),e.stroke()}e.globalAlpha=(.3+.7*r.brightness)*g,e.fillStyle=p,e.beginPath(),e.arc(i.x,i.y,r.r,0,Math.PI*2),e.fill(),d.highlight?.has(r.id)===!0&&(e.globalAlpha=.9,e.strokeStyle=p,e.lineWidth=1.5*h,e.beginPath(),e.arc(i.x,i.y,r.r+4,0,Math.PI*2),e.stroke()),r.id===d.selectedId&&(e.globalAlpha=1,e.strokeStyle=l.ink,e.lineWidth=2*h,e.beginPath(),e.arc(i.x,i.y,r.r+3.5,0,Math.PI*2),e.stroke())}),d.focus>=0){let r=a[d.focus],o=b[d.focus];r!==void 0&&o!==void 0&&(e.globalAlpha=1,e.strokeStyle=l.agent,e.setLineDash([3*h,3*h]),e.lineWidth=1.5*h,e.beginPath(),e.arc(o.x,o.y,r.r+7,0,Math.PI*2),e.stroke(),e.setLineDash([]))}e.textBaseline="middle",a.forEach((r,o)=>{let i=b[o],g=k(o);if(!(r.kind!=="memory"||s>=1.35||M.has(o)||o===d.focus||r.id===d.selectedId||(d.highlight?.has(r.id)??!1)))return;let w=r.kind==="agent"?12:11;if(e.font=`${r.kind==="dir"?"":"500 "}${w*h}px ${l.font}`,e.globalAlpha=(r.kind==="memory"?.9:r.kind==="dir"?.75:1)*g,e.fillStyle=r.kind==="dir"?l.muted:l.ink,r.kind==="agent")e.textAlign="center",e.fillText(r.label,i.x,i.y+r.r+18*h);else{e.textAlign="left";let R=r.kind==="dir"?`${r.label}/`:r.label;e.fillText(R,i.x+r.r+5*h,i.y)}}),e.globalAlpha=1}var je={zh:"已删除的记忆不会再出现在新的索引里,但之前对话中已出现的内容仍保留在那些对话的记录中。",en:"Deleted memories no longer appear in new indexes, but what earlier conversations already showed stays in those conversations' records."},Pe={user:{zh:"用户",en:"User"},feedback:{zh:"反馈",en:"Feedback"},project:{zh:"项目",en:"Project"},reference:{zh:"参考",en:"Reference"}},m={agent:{zh:"智能体",en:"Agent"},member:{zh:"成员",en:"Member"},search:{zh:"搜索记忆",en:"Search memories"},clearSearch:{zh:"清除搜索",en:"Clear search"},noHits:{zh:"没有找到相关的记忆。",en:"No matching memories."},graph:{zh:"图谱",en:"Graph"},list:{zh:"列表",en:"List"},view:{zh:"显示方式",en:"View"},fit:{zh:"适配视图",en:"Fit to view"},fullscreen:{zh:"全屏",en:"Full screen"},exitFullscreen:{zh:"退出全屏",en:"Exit full screen"},loading:{zh:"正在载入记忆…",en:"Loading memories…"},failed:{zh:"记忆载入失败。",en:"Could not load the memories."},retry:{zh:"重试",en:"Retry"},noAccess:{zh:"只有组织成员可以查看记忆。",en:"Only org members can see memories."},emptyTitle:{zh:"还没有记忆",en:"No memories yet"},emptyBody:{zh:"智能体在一对一对话中记下关于你的事情后,会出现在这里。",en:"When an agent remembers something about you in a one-to-one conversation, it shows up here."},emptyAgent:{zh:"这个智能体还没有关于你的记忆。",en:"This agent has no memories about you yet."},emptyOther:{zh:"这位成员和这个智能体之间还没有记忆。",en:"This member has no memories with this agent yet."},sizeLegend:{zh:"大小:被想起的次数",en:"Size: times recalled"},glowLegend:{zh:"亮度:最近一次被想起",en:"Brightness: last recalled"},linkLegend:{zh:"实线:记忆里写下的链接",en:"Solid: links written in memories"},semanticLegend:{zh:"虚线:语义相近",en:"Dashed: semantically close"},hint:{zh:"拖动节点 · 拖动空白处平移 · 滚轮缩放 · 方向键逐条浏览",en:"Drag nodes · drag the background to pan · scroll to zoom · arrow keys to step through"},path:{zh:"路径",en:"Path"},description:{zh:"描述",en:"Description"},body:{zh:"正文",en:"Body"},recalled:{zh:"被想起",en:"Recalled"},lastRecalled:{zh:"最近想起",en:"Last recalled"},never:{zh:"从未",en:"Never"},created:{zh:"创建于",en:"Created"},updated:{zh:"更新于",en:"Updated"},createdIn:{zh:"来自对话",en:"Written in"},openConversation:{zh:"打开对话",en:"Open the conversation"},links:{zh:"链接",en:"Links"},dangling:{zh:"尚未写下",en:"not written yet"},edit:{zh:"编辑",en:"Edit"},save:{zh:"保存",en:"Save"},cancel:{zh:"取消",en:"Cancel"},delete:{zh:"删除",en:"Delete"},close:{zh:"关闭",en:"Close"},confirmTitle:{zh:"删除这条记忆?",en:"Delete this memory?"},actionFailed:{zh:"操作没有完成:",en:"The action did not complete: "},readOnly:{zh:"管理员不能编辑其他成员的记忆。",en:"Admins cannot edit another member's memories."}},Ce=e=>({zh:`${e} 条记忆`,en:e===1?"1 memory":`${e} memories`}),Ve=(e,n)=>({zh:`正在载入 ${e} / ${n}`,en:`Loading ${e} of ${n}`}),Ee=e=>({zh:`${e} 次`,en:e===1?"once":`${e} times`}),We=e=>({zh:`你正在查看 ${e} 的记忆。每次查看和删除都会记入审计日志;管理员不能编辑其他成员的记忆。`,en:`You are viewing ${e}'s memories. Every view and delete is recorded in the audit log; admins cannot edit another member's memories.`}),Xe=e=>({zh:`记忆图谱,共 ${e} 条记忆。用方向键逐条浏览,回车打开,Esc 关闭。`,en:`Memory graph with ${e} memories. Use the arrow keys to step through them, Enter to open one and Escape to close it.`}),qe=(e,n)=>({zh:`${e} / ${n} 字节`,en:`${e} / ${n} bytes`});function ye(e,n,t=Date.now()){if(e===null)return m.never[n];let l=Date.parse(e);if(Number.isNaN(l))return m.never[n];let d=new Intl.RelativeTimeFormat(n==="zh"?"zh-CN":"en",{numeric:"auto"}),a=Math.round((l-t)/1e3),s=Math.abs(a);return s<60?d.format(a,"second"):s<3600?d.format(Math.round(a/60),"minute"):s<86400?d.format(Math.round(a/3600),"hour"):s<86400*30?d.format(Math.round(a/86400),"day"):s<86400*365?d.format(Math.round(a/(86400*30)),"month"):d.format(Math.round(a/(86400*365)),"year")}function ze(e,n){let t=Date.parse(e);return Number.isNaN(t)?e:new Intl.DateTimeFormat(n==="zh"?"zh-CN":"en",{dateStyle:"medium",timeStyle:"short"}).format(t)}import{Fragment as On,jsx as c,jsxs as N}from"react/jsx-runtime";var Te=8192,Ue=200,Nn=300,Mn=200,wn=300,te=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function ge(e){return te(e)&&Array.isArray(e.nodes)&&Array.isArray(e.edges)&&Array.isArray(e.agents)&&typeof e.canAdmin=="boolean"&&te(e.selection)?e:null}function Sn(e){return te(e)&&Array.isArray(e.nodes)&&Array.isArray(e.edges)&&!("selection"in e)?e:null}var Ze=e=>te(e)&&te(e.detail)?e.detail:null,In=e=>te(e)&&Array.isArray(e.hits)?e.hits:null,Qe=e=>`${e.kind}:${e.from}>${e.to}`;function Pn(e,n){let t=new Map(e.map(l=>[l.id,l]));for(let l of n)t.set(l.id,l);return[...t.values()]}function Cn(e,n){let t=new Map(e.map(l=>[Qe(l),l]));for(let l of n)t.set(Qe(l),l);return[...t.values()]}var Je=(e,n)=>e.selection.agentId===n.selection.agentId&&e.selection.accountId===n.selection.accountId;function se(e){let n={accountId:e.selection.accountId};return e.selection.agentId!==null&&(n.agentId=e.selection.agentId),n}var En=e=>e instanceof Error?e.message:String(e);function nn(){let{view:e,status:n,retry:t}=xn(),l=fn(),d=pn(),{locale:a,t:s}=re(),M=vn(),S=bn(),[k,C]=F(null),b=G(0),h=G(null);h.current=k;let[r,o]=F(!1),[i,g]=F(null),[p,w]=F(null),[R,X]=F(null),[Y,B]=F(""),[j,_]=F(null),[Q,ie]=F(()=>{let u=S.get("view");return u==="graph"||u==="list"?u:null}),[be,le]=F(0),[Z,ce]=F(!1);K(()=>{if(!Z)return;let u=z=>{if(z.key!=="Escape")return;let E=z.target;E instanceof Element&&E.closest("input, textarea, select")!==null||ce(!1)};return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[Z]);let ve=()=>ce(u=>!u),f=q((u,z)=>{C(E=>E!==null&&E.source===u||!z&&E!==null&&!Je(E.source,u)?E:(b.current+=1,{source:u,nodes:u.nodes,edges:u.edges,cursor:u.cursor,pages:1,gen:b.current}))},[]),v=G(s);v.current=s;let y=q(u=>g(v.current(m.actionFailed)+En(u)),[]),I=G(!1),P=G(void 0);K(()=>{if(P.current===e&&e!==null)return;P.current=e;let u=ge(e?.data);if(u!==null){f(u,!1);return}n==="ready"&&h.current===null&&!I.current&&(I.current=!0,l("select",{payload:{}}).then(z=>{let E=ge(z.view?.data);E!==null&&f(E,!0)}).catch(y))},[e,n,f,l,y]);let T=k?.gen,A=k?.cursor??null;K(()=>{let u=h.current;if(u===null||A===null||u.gen!==T)return;let z=!0,E=()=>C(D=>D!==null&&D.gen===u.gen?{...D,cursor:null}:D);return l("more",{payload:{...se(u.source),cursor:A}}).then(D=>{if(!z)return;let $=Sn(D.view?.data);if($===null)return E();C(O=>{if(O===null||O.gen!==u.gen)return O;let ne=$.cursor===O.cursor||O.pages+1>=Mn?null:$.cursor;return{...O,nodes:Pn(O.nodes,$.nodes),edges:Cn(O.edges,$.edges),cursor:ne,pages:O.pages+1}})}).catch(D=>{z&&(y(D),E())}),()=>{z=!1}},[T,A,l,y]);let x=k?.source??null,L=x?.editable??!1,H=G(null),U=q(()=>{H.current=null,X(null),w(null)},[]),de=G(0),De=q(async u=>{de.current+=1,o(!0),g(null);try{let z=await l("select",{payload:u}),E=ge(z.view?.data);E!==null&&(f(E,!0),U(),_(null),B(""),le(D=>D+1))}catch(z){y(z)}finally{o(!1)}},[l,f,U,y]),ue=q(async u=>{let z=h.current;if(z!==null){H.current=u,X(u),g(null);try{let E=await l("open",{payload:{...se(z.source),memoryId:u}});if(H.current!==u)return;let D=Ze(E.view?.data);if(D===null){H.current=null,X(null);return}w(D)}catch(E){y(E)}}},[l,y]),tn=q(async(u,z,E)=>{let D=h.current;if(D===null)return!1;try{let $=await l("edit",{payload:{...se(D.source),memoryId:u,description:z,body:E}}),O=Ze($.view?.data);return O===null?!1:(w(O),C(ne=>ne===null?ne:{...ne,nodes:ne.nodes.map(ke=>ke.id===O.id?{...ke,description:O.description}:ke)}),!0)}catch($){return y($),!1}},[l,y]),rn=q(async u=>{let z=h.current;if(z!==null)try{let E=await l("delete",{payload:{...se(z.source),memoryId:u}}),D=ge(E.view?.data);if(D===null)return;f(D,!0),U(),_($=>$===null?$:$.filter(O=>O.id!==u))}catch(E){y(E)}},[l,f,U,y]),xe=q(async u=>{let z=h.current;if(z===null||z.source.selection.agentId===null)return;let E=++de.current;if(u.trim()===""){_(null);return}let D=()=>E!==de.current||h.current===null||!Je(h.current.source,z.source);try{let $=await l("search",{payload:{...se(z.source),query:u}});if(D())return;let O=In($.view?.data);O!==null&&_(O)}catch($){D()||y($)}},[l,y]);if(K(()=>{if(Y.trim()===""){de.current+=1,_(null);return}let u=setTimeout(()=>{xe(Y)},wn);return()=>clearTimeout(u)},[Y,xe]),!d.atLeast("member"))return c(pe,{icon:"lock",title:s(m.noAccess)});if(k===null||x===null)return n==="failed"?c(pe,{icon:"circle-alert",title:s(m.failed),children:c(V,{onClick:t,children:s(m.retry)})}):N("div",{className:"cx-memory-state",children:[c(en,{label:s(m.loading)}),c(W,{tone:"muted",children:s(m.loading)})]});if(x.selection.agentId===null&&x.agents.length===0&&!x.canAdmin)return c(pe,{icon:"empty",title:s(m.emptyTitle),body:s(m.emptyBody)});let ee=k.nodes,me=Q??(x.total>Nn?"list":"graph"),Le=u=>{ie(u),S.set("view",u)},on=x.agents.find(u=>u.id===x.selection.agentId)?.name??"",an=x.members?.find(u=>u.id===x.selection.accountId)?.name??x.selection.accountId,Re=j===null?null:new Set(j.map(u=>u.id)),oe=ee.length===0;return N("div",{className:"cx-memory-page","data-panel":R!==null?"open":"closed","data-empty":oe&&j===null?"true":"false","data-fullscreen":Z?"true":"false",children:[N("form",{className:"cx-memory-toolbar",onSubmit:u=>{u.preventDefault(),xe(Y)},children:[N("div",{className:"cx-memory-field",children:[c("span",{className:"cx-memory-field-label",children:s(m.agent)}),c(Ke,{value:x.selection.agentId??"","aria-label":s(m.agent),placeholder:"—",disabled:r||x.agents.length===0,options:x.agents.map(u=>({value:u.id,label:u.name})),onChange:u=>{De({agentId:u.target.value,accountId:x.selection.accountId})}})]}),x.canAdmin&&x.members!==void 0?N("div",{className:"cx-memory-field",children:[c("span",{className:"cx-memory-field-label",children:s(m.member)}),c(Ke,{value:x.selection.accountId,"aria-label":s(m.member),disabled:r,options:x.members.map(u=>({value:u.id,label:u.name})),onChange:u=>{De({accountId:u.target.value})}})]}):null,oe?null:N("div",{className:"cx-memory-search",children:[c(J,{name:"search",size:14}),c("input",{className:"cx-memory-input",type:"search",value:Y,placeholder:s(m.search),"aria-label":s(m.search),maxLength:500,disabled:x.selection.agentId===null,onChange:u=>B(u.target.value),onKeyDown:u=>{u.key==="Escape"&&B("")}})]}),N("div",{className:"cx-memory-toolbar-end",children:[c(W,{variant:"small",tone:"muted",children:k.cursor!==null?s(Ve(ee.length,x.total)):s(Ce(Math.max(x.total,ee.length)))}),oe?null:N("fieldset",{className:"cx-memory-toggle",children:[c("legend",{className:"cx-memory-sr",children:s(m.view)}),c("button",{type:"button",className:"cx-memory-toggle-item","aria-pressed":me==="graph",onClick:()=>Le("graph"),children:s(m.graph)}),c("button",{type:"button",className:"cx-memory-toggle-item","aria-pressed":me==="list",onClick:()=>Le("list"),children:s(m.list)})]}),me==="graph"&&!oe?c(V,{variant:"ghost",title:s(m.fit),"aria-label":s(m.fit),onClick:()=>le(u=>u+1),children:c(J,{name:"zoom-in",size:14})}):null,c(V,{variant:"ghost",title:s(Z?m.exitFullscreen:m.fullscreen),"aria-label":s(Z?m.exitFullscreen:m.fullscreen),onClick:ve,children:c(J,{name:Z?"minimize-2":"maximize-2",size:14})})]})]}),L?null:N("div",{className:"cx-memory-banner",role:"note",children:[c(J,{name:"admin",size:14}),c(W,{variant:"small",children:s(We(an))})]}),i!==null?c("div",{className:"cx-memory-banner","data-tone":"fail",role:"alert",children:c(W,{variant:"small",tone:"fail",children:i})}):null,N("div",{className:"cx-memory-body",children:[N("div",{className:"cx-memory-main",children:[j!==null?c(Dn,{hits:j,onOpen:ue,onClear:()=>B("")}):null,oe?c(pe,{icon:"empty",title:s(m.emptyTitle),body:s(x.selection.agentId===null?m.emptyBody:L?m.emptyAgent:m.emptyOther)}):me==="graph"?c(An,{nodes:ee,edges:k.edges,agentLabel:on,motion:!M,selectedId:R,highlight:Re,fitSignal:be,onOpen:u=>{ue(u)},onEscape:U,label:s(Xe(ee.length))}):c(Tn,{nodes:ee,highlight:Re,selectedId:R,onOpen:u=>{ue(u)}})]}),R!==null?c(Rn,{detail:p?.id===R?p:null,editable:L,canDelete:L||x.canAdmin,locale:a,onClose:U,onOpen:u=>{ue(u)},onSave:tn,onDelete:rn},R):null]})]})}function pe(e){return N("div",{className:"cx-memory-state",children:[c("span",{className:"cx-memory-state-icon","aria-hidden":"true",children:c(J,{name:e.icon,size:16})}),c(W,{variant:"h3",children:e.title}),e.body!==void 0?c(W,{tone:"muted",children:e.body}):null,e.children]})}function fe({type:e}){return c("span",{className:"cx-memory-dot","data-type":e,"aria-hidden":"true"})}function zn(){let{t:e}=re();return N("div",{className:"cx-memory-legend","aria-hidden":"true",children:[c("div",{className:"cx-memory-legend-row",children:he.map(n=>N("span",{className:"cx-memory-legend-item",children:[c(fe,{type:n}),e(Pe[n])]},n))}),N("div",{className:"cx-memory-legend-row",children:[N("span",{className:"cx-memory-legend-item",children:[c("span",{className:"cx-memory-legend-line","data-kind":"link"}),e(m.linkLegend)]}),N("span",{className:"cx-memory-legend-item",children:[c("span",{className:"cx-memory-legend-line","data-kind":"semantic"}),e(m.semanticLegend)]})]}),N("div",{className:"cx-memory-legend-row",children:[c("span",{className:"cx-memory-legend-item",children:e(m.sizeLegend)}),c("span",{className:"cx-memory-legend-item",children:e(m.glowLegend)})]})]})}function An(e){let{locale:n,t}=re(),l=G(null),d=G(null),a=G(null),s=G({x:0,y:0,k:1}),M=G({w:0,h:0,dpr:1}),S=G(-1),k=G(-1),C=G(!1),b=G(null),h=G(e);h.current=e;let[r,o]=F(null),[i,g]=F(null),p=q((f=0)=>{let v=d.current,y=a.current;if(v===null||y===null)return;let I=v.getContext("2d");if(I===null)return;let{w:P,h:T,dpr:A}=M.current,x=h.current;He(I,y,s.current,Ye(v),{width:P,height:T,dpr:A,time:f,motion:x.motion,hover:S.current>=0?S.current:k.current,focus:k.current,selectedId:x.selectedId,highlight:x.highlight})},[]),w=q(()=>{let f=a.current,{w:v,h:y}=M.current;f===null||v===0||y===0||(s.current=Ie(f,v,y))},[]),{nodes:R,edges:X,agentLabel:Y,motion:B}=e;K(()=>{let f=a.current,v=$e({nodes:R,edges:X,agentLabel:Y},{now:Date.now(),previous:f});B||Ge(v),a.current=v,S.current=-1,k.current=-1,(f===null||!C.current)&&w(),B||p()},[R,X,Y,B,w,p]);let{fitSignal:j}=e;K(()=>{j!==0&&(C.current=!1,w(),p())},[j,w,p]);let{selectedId:_,highlight:Q}=e;K(()=>{B||p()},[_,Q,B,p]),K(()=>{let f=l.current,v=d.current;if(f===null||v===null)return;let y=()=>{let P=Math.max(1,Math.min(3,globalThis.devicePixelRatio||1)),T=f.clientWidth,A=f.clientHeight;M.current={w:T,h:A,dpr:P},v.width=Math.round(T*P),v.height=Math.round(A*P),C.current||w(),p()};if(y(),typeof ResizeObserver>"u")return;let I=new ResizeObserver(y);return I.observe(f),()=>I.disconnect()},[w,p]),K(()=>{if(!B)return;let f=0,v=y=>{let I=a.current;if(I!==null&&I.alpha>=.005){we(I);let{w:P,h:T}=M.current;if(!C.current&&P>0&&T>0){let A=Ie(I,P,T),x=s.current;s.current={x:x.x+(A.x-x.x)*.12,y:x.y+(A.y-x.y)*.12,k:x.k+(A.k-x.k)*.12}}}p(y),f=requestAnimationFrame(v)};return f=requestAnimationFrame(v),()=>cancelAnimationFrame(f)},[B,p]),K(()=>{let f=d.current;if(f===null)return;let v=y=>{y.preventDefault();let I=f.getBoundingClientRect();C.current=!0,s.current=Fe(s.current,y.clientX-I.left,y.clientY-I.top,Math.exp(-y.deltaY*.0015)),h.current.motion||p()};return f.addEventListener("wheel",v,{passive:!1}),()=>f.removeEventListener("wheel",v)},[p]);let ie=f=>{let v=f.currentTarget.getBoundingClientRect();return{sx:f.clientX-v.left,sy:f.clientY-v.top}},be=f=>{let v=a.current;if(v===null)return;let{sx:y,sy:I}=ie(f),P=ae(s.current,y,I),T=Se(v,P.x,P.y,4/s.current.k);b.current={node:T,sx:y,sy:I,lastX:y,lastY:I,moved:!1},f.currentTarget.setPointerCapture?.(f.pointerId)},le=f=>{let v=a.current;if(v===null)return;let{sx:y,sy:I}=ie(f),P=b.current,T=h.current.motion;if(P!==null){if(!P.moved&&Math.hypot(y-P.sx,I-P.sy)<4)return;P.moved=!0,o(null);let L=P.node>=0?v.nodes[P.node]:void 0;if(L!==void 0&&L.kind!=="agent"){let H=ae(s.current,y,I);L.x=H.x,L.y=H.y,L.pinned=!0,T&&(v.alpha=Math.max(v.alpha,.25))}else{C.current=!0;let H=s.current;s.current={...H,x:H.x+y-P.lastX,y:H.y+I-P.lastY}}P.lastX=y,P.lastY=I,T||p();return}let A=ae(s.current,y,I),x=Se(v,A.x,A.y,4/s.current.k);if(x!==S.current){S.current=x;let L=x>=0?v.nodes[x]?.memory??null:null;o(L===null?null:{x:y,y:I,node:L}),T||p()}},Z=f=>{let v=b.current;b.current=null;let y=a.current;if(v===null||y===null)return;let I=v.node>=0?y.nodes[v.node]:void 0;if(v.moved){I!==void 0&&I.kind!=="agent"&&h.current.motion&&(I.pinned=!1);return}I?.memory&&h.current.onOpen(I.memory.id)},ce=()=>{b.current===null&&(S.current=-1,o(null),h.current.motion||p())},ve=f=>{let v=a.current;if(v===null)return;let y=v.nodes.flatMap((A,x)=>A.kind==="memory"?[x]:[]);if(y.length===0)return;let I=y.indexOf(k.current),P=-1;if(f.key==="ArrowRight"||f.key==="ArrowDown")P=y[(I+1)%y.length]??-1;else if(f.key==="ArrowLeft"||f.key==="ArrowUp")P=y[(I-1+y.length)%y.length]??-1;else if(f.key==="Home")P=y[0]??-1;else if(f.key==="End")P=y[y.length-1]??-1;else if(f.key==="Enter"||f.key===" "){let A=v.nodes[k.current]?.memory;A&&(f.preventDefault(),h.current.onOpen(A.id));return}else if(f.key==="Escape"){h.current.onEscape();return}else return;f.preventDefault(),k.current=P;let T=v.nodes[P];if(g(T?.memory??null),T!==void 0){let{w:A,h:x}=M.current,L=s.current,H=T.x*L.k+L.x,U=T.y*L.k+L.y;A>0&&(H<40||U<40||H>A-40||U>x-40)&&(C.current=!0,s.current={...L,x:A/2-T.x*L.k,y:x/2-T.y*L.k})}h.current.motion||p()};return N("div",{className:"cx-memory-stage",ref:l,children:[c("canvas",{ref:d,className:"cx-memory-canvas",tabIndex:0,"aria-label":e.label,onPointerDown:be,onPointerMove:le,onPointerUp:Z,onPointerCancel:()=>{b.current=null},onPointerLeave:ce,onKeyDown:ve,onBlur:()=>{k.current=-1,g(null),h.current.motion||p()}}),c("div",{className:"cx-memory-sr cx-memory-live","aria-live":"polite",children:i!==null?`${i.path} — ${i.description}`:""}),r!==null?N("div",{className:"cx-memory-tip",style:{left:r.x+14,top:r.y+14},"aria-hidden":"true",children:[N("span",{className:"cx-memory-tip-path",children:[c(fe,{type:r.node.type}),r.node.path]}),c("span",{className:"cx-memory-tip-desc",children:r.node.description}),N("span",{className:"cx-memory-tip-meta",children:[t(m.recalled)," ",t(Ee(r.node.recalls))," · ",t(m.lastRecalled)," ",ye(r.node.lastRecalledAt,n)]})]}):null,c(zn,{}),c("div",{className:"cx-memory-hint","aria-hidden":"true",children:t(m.hint)})]})}function Tn(e){let{locale:n,t}=re(),l=kn(()=>[...e.nodes].sort((a,s)=>a.path<s.path?-1:a.path>s.path?1:0),[e.nodes]),d=e.highlight===null?l:l.filter(a=>e.highlight?.has(a.id));return N("div",{className:"cx-memory-list",children:[N("div",{className:"cx-memory-list-head","aria-hidden":"true",children:[c("span",{children:t(m.path)}),c("span",{children:t(m.description)}),c("span",{children:t(m.recalled)}),c("span",{children:t(m.lastRecalled)})]}),c("ul",{className:"cx-memory-rows",children:d.map(a=>c("li",{children:N("button",{type:"button",className:"cx-memory-row","data-memory-id":a.id,"aria-current":a.id===e.selectedId?"true":void 0,onClick:()=>e.onOpen(a.id),children:[N("span",{className:"cx-memory-row-path",children:[c(fe,{type:a.type}),a.path]}),c("span",{className:"cx-memory-row-desc",children:a.description}),c("span",{className:"cx-memory-row-num",children:a.recalls}),c("span",{className:"cx-memory-row-num",children:ye(a.lastRecalledAt,n)})]})},a.id))})]})}function Dn(e){let{t:n}=re();return N("section",{className:"cx-memory-hits","aria-label":n(m.search),children:[N("div",{className:"cx-memory-hits-head",children:[c(W,{variant:"small",tone:"muted",children:e.hits.length===0?n(m.noHits):n(Ce(e.hits.length))}),c(V,{variant:"ghost",onClick:e.onClear,children:n(m.clearSearch)})]}),e.hits.map(t=>N("button",{type:"button",className:"cx-memory-hit",onClick:()=>e.onOpen(t.id),children:[c("span",{className:"cx-memory-hit-path",children:t.path}),c("span",{className:"cx-memory-hit-desc",children:t.description}),t.snippet!==""?c("span",{className:"cx-memory-hit-snippet",children:t.snippet}):null]},t.id))]})}var Ln=e=>new TextEncoder().encode(e).length;function Rn(e){let{t:n}=re(),{detail:t,locale:l}=e,[d,a]=F("view"),[s,M]=F(""),[S,k]=F(""),[C,b]=F(!1);if(t===null)return c("aside",{className:"cx-memory-panel","aria-busy":"true",children:N("div",{className:"cx-memory-panel-head",children:[c(en,{size:12}),c("span",{className:"cx-memory-grow"}),c(V,{variant:"ghost","aria-label":n(m.close),onClick:e.onClose,children:c(J,{name:"x",size:14})})]})});let h=i=>i[l],r=Ln(S),o=s.trim()===""||s.length>Ue||/[\r\n]/.test(s)||r>Te;return N("aside",{className:"cx-memory-panel","aria-label":t.path,children:[N("div",{className:"cx-memory-panel-head",children:[c(fe,{type:t.type}),c("span",{className:"cx-memory-panel-path",children:t.path}),c(yn,{children:h(Pe[t.type])}),c("span",{className:"cx-memory-grow"}),c(V,{variant:"ghost","aria-label":n(m.close),onClick:e.onClose,children:c(J,{name:"x",size:14})})]}),c("div",{className:"cx-memory-panel-body",children:d==="edit"?N("form",{className:"cx-memory-edit",onSubmit:i=>{i.preventDefault(),!o&&(b(!0),e.onSave(t.id,s,S).then(g=>{b(!1),g&&a("view")}))},children:[N("label",{className:"cx-memory-field","data-block":"true",children:[c("span",{className:"cx-memory-field-label",children:n(m.description)}),c("input",{className:"cx-memory-input",value:s,maxLength:Ue,onChange:i=>M(i.target.value)})]}),N("label",{className:"cx-memory-field","data-block":"true",children:[c("span",{className:"cx-memory-field-label",children:n(m.body)}),c("textarea",{className:"cx-memory-textarea",value:S,rows:12,onChange:i=>k(i.target.value)}),c("span",{className:"cx-memory-field-note","data-over":r>Te,children:n(qe(r,Te))})]}),N(Ae,{direction:"row",gap:8,justify:"end",children:[c(V,{onClick:()=>a("view"),children:n(m.cancel)}),c(V,{type:"submit",variant:"primary",loading:C,disabled:o,children:n(m.save)})]})]}):N(On,{children:[c(W,{children:t.description}),c("div",{className:"cx-memory-markdown",children:t.body}),t.links.length>0?N("div",{className:"cx-memory-links",children:[c(W,{variant:"small",tone:"muted",children:n(m.links)}),t.links.map(i=>i.targetId!==null?N("button",{type:"button",className:"cx-memory-link",onClick:()=>e.onOpen(i.targetId),children:["[[",i.path,"]]"]},i.path):N("span",{className:"cx-memory-link","data-dangling":"true",children:["[[",i.path,"]] · ",n(m.dangling)]},i.path))]}):null,c(gn,{keyWidth:"12ch",rows:[{k:n(m.recalled),v:n(Ee(t.recalls))},{k:n(m.lastRecalled),v:ye(t.lastRecalledAt,l)},{k:n(m.created),v:ze(t.createdAt,l)},{k:n(m.updated),v:ze(t.updatedAt,l)},...t.createdIn!==null?[{k:n(m.createdIn),v:e.editable?c("a",{className:"cx-memory-anchor",href:`/chat/${encodeURIComponent(t.createdIn)}`,children:n(m.openConversation)}):t.createdIn}]:[]]}),d==="confirm"?N("div",{className:"cx-memory-confirm",role:"alertdialog","aria-label":n(m.confirmTitle),children:[c(W,{variant:"h3",children:n(m.confirmTitle)}),c(W,{variant:"small",children:n(je)}),N(Ae,{direction:"row",gap:8,justify:"end",children:[c(V,{onClick:()=>a("view"),children:n(m.cancel)}),c(V,{variant:"danger-solid",loading:C,onClick:()=>{b(!0),e.onDelete(t.id).finally(()=>b(!1))},children:n(m.delete)})]})]}):N(Ae,{direction:"row",gap:8,justify:"end",children:[e.editable?c(V,{onClick:()=>{M(t.description),k(t.body),a("edit")},children:n(m.edit)}):null,e.canDelete?c(V,{variant:"danger",onClick:()=>a("confirm"),children:n(m.delete)}):null]}),e.editable?null:c(W,{variant:"small",tone:"muted",children:n(m.readOnly)})]})})]})}var Kn=_n({name:"memory",components:{overview:$n("org.page",nn)}});export{Kn as default};
@@ -28,11 +28,18 @@
28
28
  height: auto;
29
29
  }
30
30
 
31
- /* 全屏: the page element is the fullscreen element and fills the screen. */
31
+ /*
32
+ * 全屏: the page fills the browser tab as an overlay of the web page (the shell behind it stays
33
+ * in the document), never the display's fullscreen; below the sheets and dialogs (40 and up).
34
+ */
32
35
  .cx-memory-page[data-fullscreen="true"] {
33
- height: 100dvh;
36
+ position: fixed;
37
+ inset: 0;
38
+ z-index: 30;
39
+ height: auto;
34
40
  padding: var(--cb-space-4);
35
41
  background: var(--cb-bg);
42
+ overflow: auto;
36
43
  }
37
44
 
38
45
  /* ---------- Top bar ---------- */
package/dist/index.mjs CHANGED
@@ -5060,7 +5060,7 @@ function registerTools(ctx, opts = {}) {
5060
5060
  // src/index.ts
5061
5061
  var index_default = defineExtension({
5062
5062
  name: "memory",
5063
- version: "0.1.0-rc.1",
5063
+ version: "0.1.0-rc.3",
5064
5064
  sdk: "^0.1.0-rc.19",
5065
5065
  provides: [CONTEXT_EXTENSION_POINT],
5066
5066
  ui: [
package/icon.svg CHANGED
@@ -1 +1 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#3D3D3A" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><title>Memory</title><style>@media (prefers-color-scheme:dark){svg{stroke:#D6D5D0}}</style><circle cx="12" cy="5" r="2"/><circle cx="5" cy="17" r="2"/><circle cx="19" cy="17" r="2"/><circle cx="12" cy="13" r="1.6"/><path d="M12 7v4.4M10.7 14.1l-4.2 1.9M13.3 14.1l4.2 1.9M7 17h10"/></svg>
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" shape-rendering="crispEdges"><title>Memory</title><style>@media (prefers-color-scheme: dark){path{fill:#FF6A13}}</style><path fill="#CC4609" d="M14 1.4h1.35v1.35h-1.35zM12.65 2.75h4.05v1.35h-4.05zM4.55 4.1h14.85v1.35h-14.85zM3.2 5.45h12.15v1.35h-12.15zM16.7 5.45h2.7v1.35h-2.7zM1.85 6.8h17.55v1.35h-17.55zM1.85 8.15h17.55v1.35h-17.55zM1.85 9.5h17.55v1.35h-17.55zM3.2 10.85h13.5v1.35h-13.5zM3.2 12.2h2.7v1.35h-2.7zM8.6 12.2h1.35v1.35h-1.35zM12.65 12.2h2.7v1.35h-2.7zM3.2 13.55h2.7v1.35h-2.7zM8.6 13.55h1.35v1.35h-1.35zM12.65 13.55h2.7v1.35h-2.7z"/><path fill="#CC4609" d="M17.1 15.1h3.45v1.15h-3.45zM17.1 16.25h3.45v1.15h-3.45zM14.8 18.55h2.3v1.15h-2.3zM20.55 18.55h2.3v1.15h-2.3zM14.8 19.7h2.3v1.15h-2.3zM20.55 19.7h2.3v1.15h-2.3z"/></svg>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-memory",
3
- "version": "0.1.0-rc.1",
3
+ "version": "0.1.0-rc.3",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "description": "Memory for agents: each agent remembers each member across conversations, with an index at run start, memory tools, hybrid search and a memory page",