@capybara-hq/plugin-memory 0.1.0-rc.3 → 0.1.0-rc.4
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/.capybara-plugin/plugin.json +3 -3
- package/dist/client/client.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
|
@@ -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.
|
|
5
|
+
"version": "0.1.0-rc.4",
|
|
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.
|
|
21
|
+
"version": "0.1.0-rc.4",
|
|
22
22
|
"sdk": "^0.1.0-rc.19",
|
|
23
23
|
"provides": [
|
|
24
24
|
"context@1"
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"./dist/client/styles/memory.css"
|
|
80
80
|
],
|
|
81
81
|
"integrity": {
|
|
82
|
-
"./dist/client/client.mjs": "sha384-
|
|
82
|
+
"./dist/client/client.mjs": "sha384-4jnFJ3sR7miPo4vheaPVsimsLDG7dHIo/lA8zTEwxlos206S2wvyEyCExA9Iilz3",
|
|
83
83
|
"./dist/client/styles/memory.css": "sha384-BQe777NlfcscoaVL9jDxkd8/fDSnC/ih1WwrWMpQecpcQalE+EOuqPGtCxDKB7PY"
|
|
84
84
|
},
|
|
85
85
|
"apiVersion": 1
|
package/dist/client/client.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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};
|
|
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=[],o=a=>{let i=t.length;return t.push({...a,x:0,y:0,vx:0,vy:0,ring:0}),l.set(a.id,i),d.push([]),a.parent>=0&&d[a.parent]?.push(i),i};o({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=a=>{let i=l.get(Oe(a));if(i!==void 0)return i;let g=a.lastIndexOf("/"),f=g===-1?0:s(a.slice(0,g)),w=a.split("/")[0];return o({id:Oe(a),kind:"dir",label:a.slice(g+1),path:a,type:he.includes(w)?w:null,parent:f,depth:a.split("/").length,pinned:!1,r:4.5,brightness:1,recent:!1,phase:Ne(a),memory:null})};for(let a of he)s(a);let M=[...e.nodes].sort((a,i)=>a.path<i.path?-1:a.path>i.path?1:0);for(let a of M){if(l.has(a.id))continue;let i=a.dir===""?0:s(a.dir),g=a.path.slice(a.path.lastIndexOf("/")+1).replace(/\.md$/,""),f=cn(a.lastRecalledAt,n.now),w=a.lastRecalledAt===null?Number.NaN:Date.parse(a.lastRecalledAt);o({id:a.id,kind:"memory",label:g,path:a.path,type:a.type,parent:i,depth:(t[i]?.depth??0)+1,pinned:!1,r:ln(a.recalls),brightness:f,recent:!Number.isNaN(w)&&n.now-w<7*864e5,phase:Ne(a.id),memory:a})}let S=[];for(let a=1;a<t.length;a++){let i=t[a];S.push({a:i.parent,b:a,kind:"tree",phase:i.phase})}let k=new Set;for(let a of e.edges){let i=l.get(a.from),g=l.get(a.to);if(i===void 0||g===void 0||i===g)continue;let f=a.kind==="semantic"?`s${Math.min(i,g)}~${Math.max(i,g)}`:`l${i}>${g}`;k.has(f)||(k.add(f),S.push({a:i,b:g,kind:a.kind,phase:Ne(f)}))}let C=t.map(()=>new Set);for(let a of S)C[a.a]?.add(a.b),C[a.b]?.add(a.a);let b=new Array(t.length).fill(0);for(let a=t.length-1;a>=0;a--){let i=t[a]?.kind==="memory"?1:0,g=(d[a]??[]).reduce((f,w)=>f+(b[w]??0),0);b[a]=Math.max(1,i+g)}let h=(a,i,g)=>{let f=t[a],w=d[a]??[],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):(f.kind==="agent"?70:f.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 a of t){let i=r.index.get(a.id),g=i===void 0?void 0:r.nodes[i];g!==void 0&&(a.x=g.x,a.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((o,s)=>{let M=`${Math.floor(o.x/l)},${Math.floor(o.y/l)}`,S=d.get(M);S===void 0?d.set(M,[s]):S.push(s)});for(let o=0;o<n.length;o++){let s=n[o],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<=o)continue;let h=n[b],r=h.x-s.x,a=h.y-s.y,i=r*r+a*a;if(i===0&&(r=(s.phase-h.phase)*.1+.01,a=.01,i=r*r+a*a),i>l*l)continue;let g=Math.sqrt(i),f=60*t/g,w=s.r+h.r+6;g<w&&(f+=(w-g)*.5);let R=r/g*f,X=a/g*f;s.vx-=R,s.vy-=X,h.vx+=R,h.vy+=X}}for(let o of e.edges){if(o.kind==="semantic")continue;let s=n[o.a],M=n[o.b],S=M.x-s.x,k=M.y-s.y,C=Math.sqrt(S*S+k*k)||1,b=o.kind==="tree"?Math.max(30,M.ring-s.ring):90,h=(C-b)/C*t*(o.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 o of n){if(o.kind==="agent")continue;let s=Math.sqrt(o.x*o.x+o.y*o.y)||1,M=(o.ring-s)/s*.08*t;o.vx+=o.x*M,o.vy+=o.y*M}for(let o of n){if(o.pinned){o.vx=0,o.vy=0,o.kind==="agent"&&(o.x=0,o.y=0);continue}o.vx*=.6,o.vy*=.6,o.x+=o.vx,o.y+=o.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,o=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<o&&(d=s,o=S)}return d}var Be=.15,un=4,oe=(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,o=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),o=Math.min(o,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-o),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-(o+M)/2*C}}function Fe(e,n,t,l){let d=Math.min(un,Math.max(Be,e.k*l)),o=oe(e,n,t);return{k:d,x:n-o.x*d,y:t-o.y*d}}function Ye(e){let n=getComputedStyle(e),t=(o,s)=>n.getPropertyValue(o).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:o}=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 a=o[r];return M.size>0?M.has(r)?1:.15:d.highlight!==null?a.kind!=="memory"||S(a)?1:.15:1},C=r=>{if(!d.motion||r.kind!=="memory")return{x:r.x,y:r.y};let a=r.phase*Math.PI*2;return{x:r.x+Math.sin(d.time/1700+a)*1.4,y:r.y+Math.cos(d.time/2100+a)*1.4}},b=o.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 a=b[r.a],i=b[r.b];e.globalAlpha=.28*Math.min(k(r.a),k(r.b)),e.beginPath(),e.moveTo(a.x,a.y),e.lineTo(i.x,i.y),e.stroke()}e.setLineDash([]);for(let r of n.edges){if(r.kind!=="tree")continue;let a=o[r.a],i=o[r.b],g=b[r.a],f=b[r.b],w=_e(a,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,f.x,f.y),e.stroke()}e.strokeStyle=l.ink,e.lineWidth=1.2*h;for(let r of n.edges){if(r.kind!=="link")continue;let a=b[r.a],i=b[r.b];e.globalAlpha=.5*Math.min(k(r.a),k(r.b)),e.beginPath(),e.moveTo(a.x,a.y),e.lineTo(i.x,i.y),e.stroke()}if(d.motion)for(let r of n.edges){let a=o[r.b];if(r.kind==="semantic"||r.kind==="tree"&&!a.recent)continue;let i=(d.time/(r.kind==="link"?3200:2600)+r.phase)%1,g=b[r.a],f=b[r.b],w=r.kind==="tree"?mn(g,_e(o[r.a],a),f,i):{x:g.x+(f.x-g.x)*i,y:g.y+(f.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,a),e.beginPath(),e.arc(w.x,w.y,1.8*h,0,Math.PI*2),e.fill()}if(o.forEach((r,a)=>{let i=b[a],g=k(a),f=Me(l,r);if(r.kind==="dir"){e.globalAlpha=g,e.fillStyle=l.bg,e.strokeStyle=f,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=f,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=f,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=f,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=f,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=f,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=f,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=o[d.focus],a=b[d.focus];r!==void 0&&a!==void 0&&(e.globalAlpha=1,e.strokeStyle=l.agent,e.setLineDash([3*h,3*h]),e.lineWidth=1.5*h,e.beginPath(),e.arc(a.x,a.y,r.r+7,0,Math.PI*2),e.stroke(),e.setLineDash([]))}e.textBaseline="middle",o.forEach((r,a)=>{let i=b[a],g=k(a);if(!(r.kind!=="memory"||s>=1.35||M.has(a)||a===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"}),o=Math.round((l-t)/1e3),s=Math.abs(o);return s<60?d.format(o,"second"):s<3600?d.format(Math.round(o/60),"minute"):s<86400?d.format(Math.round(o/3600),"hour"):s<86400*30?d.format(Math.round(o/86400),"day"):s<86400*365?d.format(Math.round(o/(86400*30)),"month"):d.format(Math.round(o/(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:o,t:s}=re(),M=vn(),S=bn(),[k,C]=F(null),b=G(0),h=G(null);h.current=k;let[r,a]=F(!1),[i,g]=F(null),[f,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"||z.defaultPrevented)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),p=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){p(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&&p(E,!0)}).catch(y))},[e,n,p,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,a(!0),g(null);try{let z=await l("select",{payload:u}),E=ge(z.view?.data);E!==null&&(p(E,!0),U(),_(null),B(""),le(D=>D+1))}catch(z){y(z)}finally{a(!1)}},[l,p,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;p(D,!0),U(),_($=>$===null?$:$.filter(O=>O.id!==u))}catch(E){y(E)}},[l,p,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)},an=x.agents.find(u=>u.id===x.selection.agentId)?.name??"",on=x.members?.find(u=>u.id===x.selection.accountId)?.name??x.selection.accountId,Re=j===null?null:new Set(j.map(u=>u.id)),ae=ee.length===0;return N("div",{className:"cx-memory-page","data-panel":R!==null?"open":"closed","data-empty":ae&&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,ae?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)))}),ae?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"&&!ae?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(on))})]}),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,ae?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:an,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:f?.id===R?f:null,editable:L,canDelete:L||x.canAdmin,locale:o,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),o=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,a]=F(null),[i,g]=F(null),f=q((p=0)=>{let v=d.current,y=o.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:p,motion:x.motion,hover:S.current>=0?S.current:k.current,focus:k.current,selectedId:x.selectedId,highlight:x.highlight})},[]),w=q(()=>{let p=o.current,{w:v,h:y}=M.current;p===null||v===0||y===0||(s.current=Ie(p,v,y))},[]),{nodes:R,edges:X,agentLabel:Y,motion:B}=e;K(()=>{let p=o.current,v=$e({nodes:R,edges:X,agentLabel:Y},{now:Date.now(),previous:p});B||Ge(v),o.current=v,S.current=-1,k.current=-1,(p===null||!C.current)&&w(),B||f()},[R,X,Y,B,w,f]);let{fitSignal:j}=e;K(()=>{j!==0&&(C.current=!1,w(),f())},[j,w,f]);let{selectedId:_,highlight:Q}=e;K(()=>{B||f()},[_,Q,B,f]),K(()=>{let p=l.current,v=d.current;if(p===null||v===null)return;let y=()=>{let P=Math.max(1,Math.min(3,globalThis.devicePixelRatio||1)),T=p.clientWidth,A=p.clientHeight;M.current={w:T,h:A,dpr:P},v.width=Math.round(T*P),v.height=Math.round(A*P),C.current||w(),f()};if(y(),typeof ResizeObserver>"u")return;let I=new ResizeObserver(y);return I.observe(p),()=>I.disconnect()},[w,f]),K(()=>{if(!B)return;let p=0,v=y=>{let I=o.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}}}f(y),p=requestAnimationFrame(v)};return p=requestAnimationFrame(v),()=>cancelAnimationFrame(p)},[B,f]),K(()=>{let p=d.current;if(p===null)return;let v=y=>{y.preventDefault();let I=p.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||f()};return p.addEventListener("wheel",v,{passive:!1}),()=>p.removeEventListener("wheel",v)},[f]);let ie=p=>{let v=p.currentTarget.getBoundingClientRect();return{sx:p.clientX-v.left,sy:p.clientY-v.top}},be=p=>{let v=o.current;if(v===null)return;let{sx:y,sy:I}=ie(p),P=oe(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},p.currentTarget.setPointerCapture?.(p.pointerId)},le=p=>{let v=o.current;if(v===null)return;let{sx:y,sy:I}=ie(p),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,a(null);let L=P.node>=0?v.nodes[P.node]:void 0;if(L!==void 0&&L.kind!=="agent"){let H=oe(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||f();return}let A=oe(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;a(L===null?null:{x:y,y:I,node:L}),T||f()}},Z=p=>{let v=b.current;b.current=null;let y=o.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,a(null),h.current.motion||f())},ve=p=>{let v=o.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(p.key==="ArrowRight"||p.key==="ArrowDown")P=y[(I+1)%y.length]??-1;else if(p.key==="ArrowLeft"||p.key==="ArrowUp")P=y[(I-1+y.length)%y.length]??-1;else if(p.key==="Home")P=y[0]??-1;else if(p.key==="End")P=y[y.length-1]??-1;else if(p.key==="Enter"||p.key===" "){let A=v.nodes[k.current]?.memory;A&&(p.preventDefault(),h.current.onOpen(A.id));return}else if(p.key==="Escape"){h.current.selectedId!==null&&p.preventDefault(),h.current.onEscape();return}else return;p.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||f()};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||f()}}),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((o,s)=>o.path<s.path?-1:o.path>s.path?1:0),[e.nodes]),d=e.highlight===null?l:l.filter(o=>e.highlight?.has(o.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(o=>c("li",{children:N("button",{type:"button",className:"cx-memory-row","data-memory-id":o.id,"aria-current":o.id===e.selectedId?"true":void 0,onClick:()=>e.onOpen(o.id),children:[N("span",{className:"cx-memory-row-path",children:[c(fe,{type:o.type}),o.path]}),c("span",{className:"cx-memory-row-desc",children:o.description}),c("span",{className:"cx-memory-row-num",children:o.recalls}),c("span",{className:"cx-memory-row-num",children:ye(o.lastRecalledAt,n)})]})},o.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,o]=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),a=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(),!a&&(b(!0),e.onSave(t.id,s,S).then(g=>{b(!1),g&&o("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:()=>o("view"),children:n(m.cancel)}),c(V,{type:"submit",variant:"primary",loading:C,disabled:a,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:()=>o("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),o("edit")},children:n(m.edit)}):null,e.canDelete?c(V,{variant:"danger",onClick:()=>o("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};
|
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.
|
|
5063
|
+
version: "0.1.0-rc.4",
|
|
5064
5064
|
sdk: "^0.1.0-rc.19",
|
|
5065
5065
|
provides: [CONTEXT_EXTENSION_POINT],
|
|
5066
5066
|
ui: [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/plugin-memory",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.4",
|
|
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",
|