@rizom/brain 0.2.0-alpha.89 → 0.2.0-alpha.90
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/dist/brain.js +46 -40
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/site.js +4 -4
- package/dist/site.js.map +1 -1
- package/dist/ui/app.js +2 -2
- package/dist/ui/app.js.map +3 -3
- package/package.json +1 -1
package/dist/ui/app.js
CHANGED
|
@@ -3972,6 +3972,6 @@ XID_Start XIDS`.split(/\s/).map((e)=>[AI(e),e])),Ist=new Map([["s",jc(383)],[jc(
|
|
|
3972
3972
|
${jna}
|
|
3973
3973
|
</iframe>`},"putIntoIFrame"),h9n=E((e,n,t,a,i)=>{let r=e.append("div");if(r.attr("id",t),a)r.attr("style",a);let o=r.append("svg").attr("id",n).attr("width","100%").attr("xmlns",Fna);if(i)o.attr("xmlns:xlink",i);return o.append("g"),e},"appendDivSvgG");function D0e(e,n){return e.append("iframe").attr("id",n).attr("style","width: 100%; height: 100%;").attr("sandbox","")}E(D0e,"sandboxedIframe");var Jna=E((e,n,t,a)=>{e.getElementById(n)?.remove(),e.getElementById(t)?.remove(),e.getElementById(a)?.remove()},"removeExistingElements"),Pna=E(async function(e,n,t){YJ();let a=q0e(n);n=a.code;let i=qt();if(be.debug(i),n.length>(i?.maxTextSize??vna))n=Ina;let r=`#${e}`,o="i"+e,s="#"+o,A="d"+e,u="#"+A,m=E(()=>{let q=qn(d?s:u).node();if(q&&"remove"in q)q.remove()},"removeTempElements"),l=qn(document.body),d=i.securityLevel===xna,b=i.securityLevel===Dna,f=i.fontFamily;if(t!==void 0){if(t)t.innerHTML="";if(d){let R=D0e(qn(t),o);l=qn(R.nodes()[0].contentDocument.body),l.node().style.margin="0"}else l=qn(t);h9n(l,e,A,`font-family: ${f}`,qna)}else{if(Jna(document,e,A,o),d){let R=D0e(qn(document.body),o);l=qn(R.nodes()[0].contentDocument.body),l.node().style.margin="0"}else l=qn("body");h9n(l,e,A)}let h,y;try{h=await x0e.fromText(n,{title:a.title})}catch(R){if(i.suppressErrorRendering)throw m(),R;h=await x0e.fromText("error"),y=R}let B=l.select(u).node(),k=h.type,C=B.firstChild,I=C.firstChild,_=h.renderer.getClasses?.(n,h),v=Ona(i,k,_,r),x=document.createElement("style");x.innerHTML=v,C.insertBefore(x,I);try{await h.renderer.draw(n,e,"11.15.0",h)}catch(R){if(i.suppressErrorRendering)m();else gea.draw(n,e,"11.15.0");throw R}let D=l.select(`${u} svg`),j=h.db.getAccTitle?.(),U=h.db.getAccDescription?.();r2n(k,D,j,U),l.select(`[id="${e}"]`).selectAll("foreignobject > *").attr("xmlns",Mna);let H=l.select(u).node().innerHTML;if(be.debug("config.arrowMarkerAbsolute",i.arrowMarkerAbsolute),H=Kna(H,d,Vp(i.arrowMarkerAbsolute)),d){let R=l.select(u+" svg").node();H=Yna(H,R)}else if(!b)H=Ol.sanitize(H,{ADD_TAGS:Nna,ADD_ATTR:Sna,HTML_INTEGRATION_POINTS:{foreignobject:!0}});if(kna(),y)throw y;return m(),{diagramType:k,svg:H,bindFunctions:h.db.bindFunctions}},"render");function a2n(e={}){let n=eo({},e);if(n?.fontFamily&&!n.themeVariables?.fontFamily){if(!n.themeVariables)n.themeVariables={};n.themeVariables.fontFamily=n.fontFamily}if(lJe(n),n?.theme&&n.theme in Hg)n.themeVariables=Hg[n.theme].getThemeVariables(n.themeVariables);else if(n)n.themeVariables=Hg.default.getThemeVariables(n.themeVariables);let t=typeof n==="object"?mJe(n):yce();K2(t.logLevel),YJ()}E(a2n,"initialize");var i2n=E((e,n={})=>{let{code:t}=F0e(e);return x0e.fromText(t,n)},"getDiagramFromText");function r2n(e,n,t,a){X9n(n,e),V9n(n,t,a,n.attr("id"))}E(r2n,"addA11yInfo");var r_=Object.freeze({render:Pna,parse:t2n,getDiagramFromText:i2n,initialize:a2n,getConfig:qt,setConfig:Bce,getSiteConfig:yce,updateSiteConfig:pJe,reset:E(()=>{t4()},"reset"),globalReset:E(()=>{t4(H0)},"globalReset"),defaultConfig:H0});K2(qt().logLevel);t4(qt());var $na=E((e,n,t)=>{if(be.warn(e),b3(e)){if(t)t(e.str,e.hash);n.push({...e,message:e.str,error:e})}else{if(t)t(e);if(e instanceof Error)n.push({str:e.message,message:e.message,hash:e.name,error:e})}},"handleError"),o2n=E(async function(e={querySelector:".mermaid"}){try{await Wna(e)}catch(n){if(b3(n))be.error(n.str);if(Mw.parseError)Mw.parseError(n);if(!e.suppressErrors)throw be.error("Use the suppressErrors option to suppress these errors"),n}},"run"),Wna=E(async function({postRenderCallback:e,querySelector:n,nodes:t}={querySelector:".mermaid"}){let a=r_.getConfig();be.debug(`${!e?"No ":""}Callback function found`);let i;if(t)i=t;else if(n)i=document.querySelectorAll(n);else throw Error("Nodes and querySelector are both undefined");if(be.debug(`Found ${i.length} diagrams`),a?.startOnLoad!==void 0)be.debug("Start On Load: "+a?.startOnLoad),r_.updateSiteConfig({startOnLoad:a?.startOnLoad});let r=new ea.InitIDGenerator(a.deterministicIds,a.deterministicIDSeed),o,s=[];for(let A of Array.from(i)){if(be.info("Rendering diagram: "+A.id),A.getAttribute("data-processed"))continue;A.setAttribute("data-processed","true");let u=`mermaid-${r.next()}`;o=A.innerHTML,o=Q3(ea.entityDecode(o)).trim().replace(/<br\s*\/?>/gi,"<br/>");let m=ea.detectInit(o);if(m)be.debug("Detected early reinit: ",m);try{let{svg:l,bindFunctions:d}=await u2n(u,o,A);if(A.innerHTML=l,e)await e(u);if(d)d(A)}catch(l){$na(l,s,Mw.parseError)}}if(s.length>0)throw s[0]},"runThrowsErrors"),c2n=E(function(e){r_.initialize(e)},"initialize"),Tna=E(async function(e,n,t){if(be.warn("mermaid.init is deprecated. Please use run instead."),e)c2n(e);let a={postRenderCallback:t,querySelector:".mermaid"};if(typeof n==="string")a.querySelector=n;else if(n)if(n instanceof HTMLElement)a.nodes=[n];else a.nodes=n;await o2n(a)},"init"),Xna=E(async(e,{lazyLoad:n=!0}={})=>{if(YJ(),bj(...e),n===!1)await yna()},"registerExternalDiagrams"),s2n=E(function(){if(Mw.startOnLoad){let{startOnLoad:e}=r_.getConfig();if(e)Mw.run().catch((n)=>be.error("Mermaid failed to initialize",n))}},"contentLoaded");if(typeof document<"u")window.addEventListener("load",s2n,!1);var Vna=E(function(e){Mw.parseError=e},"setParseErrorHandler"),KJ=[],I0e=!1,A2n=E(async()=>{if(I0e)return;I0e=!0;while(KJ.length>0){let e=KJ.shift();if(e)try{await e()}catch(n){be.error("Error executing queue",n)}}I0e=!1},"executeQueue"),eta=E(async(e,n)=>{return new Promise((t,a)=>{let i=E(()=>new Promise((r,o)=>{r_.parse(e,n).then((s)=>{r(s),t(s)},(s)=>{be.error("Error parsing",s),Mw.parseError?.(s),o(s),a(s)})}),"performCall");KJ.push(i),A2n().catch(a)})},"parse"),u2n=E((e,n,t)=>{return new Promise((a,i)=>{let r=E(()=>new Promise((o,s)=>{r_.render(e,n,t).then((A)=>{o(A),a(A)},(A)=>{be.error("Error parsing",A),Mw.parseError?.(A),s(A),i(A)})}),"performCall");KJ.push(r),A2n().catch(i)})},"render"),nta=E(()=>{return Object.keys(Vy).map((e)=>({id:e}))},"getRegisteredDiagramsMetadata"),Mw={startOnLoad:!0,mermaidAPI:r_,parse:eta,render:u2n,init:Tna,run:o2n,registerExternalDiagrams:Xna,registerLayoutLoaders:wbe,initialize:c2n,parseError:void 0,contentLoaded:s2n,setParseErrorHandler:Vna,detectType:n4,registerIconPacks:v3,getRegisteredDiagramsMetadata:nta},JJ=Mw;/*! Check if previously processed *//*!
|
|
3974
3974
|
* Wait for document loaded before starting the execution
|
|
3975
|
-
*/var m2n={startOnLoad:!1,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:!0};function tta(e={}){let n=!1,t={...m2n,...e.config},a={initialize(i){t={...m2n,...e.config,...i},JJ.initialize(t),n=!0},async render(i,r){return n||(JJ.initialize(t),n=!0),await JJ.render(i,r)}};return{name:"mermaid",type:"diagram",language:"mermaid",getMermaid(i){return i&&a.initialize(i),a}}}var l2n=tta();var jRn=ia(ms(),1);i$();var r8=ia(SA(),1);function I_e(...e){return e.filter(Boolean).join(" ")}var NRn=({className:e,from:n,...t})=>r8.jsxDEV("div",{className:I_e("web-chat-message group flex w-full max-w-[95%] flex-col gap-2",n==="user"?"is-user ml-auto justify-end":"is-assistant",e),"data-role":n,...t},void 0,!1,void 0,this),SRn=({className:e,...n})=>r8.jsxDEV("div",{className:I_e("web-chat-message-bubble is-user:dark flex w-fit min-w-0 max-w-full flex-col gap-2 overflow-hidden text-sm",e),...n},void 0,!1,void 0,this);function HRn({role:e,time:n}){return r8.jsxDEV("span",{className:"web-chat-message-header",children:[{assistant:"Brain",system:"System",user:"You"}[e],n?r8.jsxDEV("time",{children:n},void 0,!1,void 0,this):null]},void 0,!0,void 0,this)}var Opa={cjk:F7e,code:TZe,math:cYe,mermaid:l2n},x_e=jRn.memo(({className:e,...n})=>r8.jsxDEV(p$,{className:I_e("web-chat-markdown-response size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",e),plugins:Opa,...n},void 0,!1,void 0,this),(e,n)=>e.children===n.children&&n.isAnimating===e.isAnimating);x_e.displayName="MessageResponse";var rC=ia(ms(),1),vA=ia(SA(),1);function d$(...e){return e.filter(Boolean).join(" ")}function ZRn({children:e,className:n,onSubmit:t,...a}){let i=rC.useCallback((r)=>{r.preventDefault();let s=new FormData(r.currentTarget).get("message")??"";t({files:[],text:s},r)},[t]);return vA.jsxDEV("form",{className:d$("web-chat-prompt-input",n),onSubmit:i,...a,children:e},void 0,!1,void 0,this)}var ORn=rC.forwardRef(function({className:n,name:t="message",onKeyDown:a,...i},r){let[o,s]=rC.useState(!1),A=rC.useCallback((u)=>{if(a?.(u),u.defaultPrevented)return;if(u.key!=="Enter")return;if(u.shiftKey||o||u.nativeEvent.isComposing)return;if(u.preventDefault(),u.currentTarget.form?.querySelector('button[type="submit"]')?.disabled)return;u.currentTarget.form?.requestSubmit()},[o,a]);return vA.jsxDEV("textarea",{ref:r,className:d$("web-chat-prompt-textarea",n),name:t,onCompositionEnd:()=>s(!1),onCompositionStart:()=>s(!0),onKeyDown:A,...i},void 0,!1,void 0,this)});function KRn({children:e,className:n,...t}){return vA.jsxDEV("div",{className:d$("web-chat-prompt-footer",n),...t,children:e},void 0,!1,void 0,this)}function YRn(){return vA.jsxDEV("span",{className:"web-chat-prompt-hint",children:[vA.jsxDEV("kbd",{children:"Enter"},void 0,!1,void 0,this)," to send · ",vA.jsxDEV("kbd",{children:"Shift"},void 0,!1,void 0,this),"+",vA.jsxDEV("kbd",{children:"Enter"},void 0,!1,void 0,this)," newline"]},void 0,!0,void 0,this)}function Kpa(){return vA.jsxDEV("svg",{viewBox:"0 0 18 14",fill:"none",stroke:"currentColor",strokeWidth:"1.5","aria-hidden":"true",children:[vA.jsxDEV("path",{d:"M2 7h10M9 3c1.5 2 3 4 5 4-2 0-3.5 2-5 4",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this),vA.jsxDEV("circle",{cx:"2",cy:"7",r:"1.5",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function JRn({children:e,className:n,disabled:t=!1,onClick:a,onStop:i,status:r="ready",...o}){let s=r==="submitted"||r==="streaming",A=rC.useCallback((u)=>{if(s&&i){u.preventDefault(),i();return}a?.(u)},[s,a,i]);return vA.jsxDEV("button",{"aria-label":s?"Stop response":"Send message",className:d$("web-chat-prompt-submit",n),disabled:t&&!s,onClick:A,type:s&&i?"button":"submit",...o,children:e??(s?"Stop":vA.jsxDEV(vA.Fragment,{children:["Send",vA.jsxDEV(Kpa,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this))},void 0,!1,void 0,this)}var zt=ia(SA(),1),b$="brain:web-chat:conversation-id",Ypa="brain:theme";function Jpa(){if(typeof document>"u")return"dark";return document.documentElement.getAttribute("data-theme")==="light"?"light":"dark"}function Ppa(e){document.documentElement.setAttribute("data-theme",e);try{localStorage.setItem(Ypa,e)}catch{}}var D_e=86400000,PRn=48;function q_e(){return`web-${crypto.randomUUID()}`}function $pa(){try{let e=localStorage.getItem(b$);if(e)return e;let n=q_e();return localStorage.setItem(b$,n),n}catch{return q_e()}}function Wpa(e){return{id:e.id,role:e.role,parts:[{type:"text",text:e.content}]}}function F_e(e){if(typeof e!=="object"||e===null||!("data"in e))return;return e.data}function Tpa(e){let n=[],t=[],a=()=>{if(t.length===0)return;n.push({kind:"tools",tools:t}),t=[]};for(let i of e){if(i.type==="data-tool-result"){t.push(F_e(i));continue}if(a(),i.type==="text")n.push({kind:"text",text:i.text});else if(i.type==="data-confirmation")n.push({kind:"confirmation",data:F_e(i)});else if(i.type.startsWith("data-"))n.push({kind:"generic",type:i.type,data:F_e(i)})}return a(),n}function Xpa(e){return e==="submitted"||e==="streaming"}function Vpa(e){e.style.height="auto",e.style.height=`${e.scrollHeight}px`}function g$(e){requestAnimationFrame(()=>e?.focus())}function eda(e){let n=e.trim().split(/\r?\n/,1)[0]??"";if(!n)return"New conversation";if(n.length<=PRn)return n;return`${n.slice(0,PRn-1).trimEnd()}…`}function nda(e,n=new Date){let t=new Date(e);if(Number.isNaN(t.getTime()))return"—";let a=n.getTime()-t.getTime();if(a<D_e&&t.getDate()===n.getDate())return t.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"});let i=new Date(n.getTime()-D_e);if(t.getDate()===i.getDate())return"Yest";if(a<7*D_e)return t.toLocaleDateString(void 0,{weekday:"short"});return t.toLocaleDateString(void 0,{day:"numeric",month:"short"})}function tda(e){if(e==="submitted")return"the rhizome is listening";if(e==="streaming")return"the rhizome is listening";if(e==="error")return"a thread broke mid-growth";return""}function $Rn(){let[e,n]=nA.useState(""),[t,a]=nA.useState(()=>$pa()),[i,r]=nA.useState([]),[o,s]=nA.useState([]),[A,u]=nA.useState(()=>Jpa()),[m,l]=nA.useState(!1);function d(){l(!1)}function b(){let L=A==="light"?"dark":"light";u(L),Ppa(L)}let f=nA.useRef(null),h=nA.useRef(null),y=nA.useMemo(()=>new Nqe({api:"/api/chat",credentials:"include"}),[]),B=nA.useMemo(()=>new mz({id:t,messages:o,transport:y}),[t,o,y]),{messages:k,sendMessage:C,setMessages:I,status:_,error:v,stop:x,clearError:D}=A6e({chat:B});nA.useEffect(()=>{f.current?.scrollIntoView({block:"end",behavior:"smooth"})},[k,_]),nA.useEffect(()=>{if(h.current)Vpa(h.current)},[e]),nA.useEffect(()=>{g$(h.current),j()},[]);async function j(){let L=await fetch("/api/chat/sessions",{credentials:"include"});if(!L.ok)return;let G=await L.json();r(G.sessions)}function U(L){let G=new Date().toISOString(),z={id:t,title:eda(L),lastActiveAt:G};r((O)=>{let Z=O.find((Y)=>Y.id===t),J=Z&&Z.title!=="New conversation"?{...Z,lastActiveAt:G}:z,N=O.filter((Y)=>Y.id!==t);return[J,...N]})}async function H(L){let G=await fetch(`/api/chat/messages?id=${encodeURIComponent(L)}`,{credentials:"include"});if(!G.ok)return;let O=(await G.json()).messages.map(Wpa);localStorage.setItem(b$,L),I(O),s(O),a(L),n(""),d(),g$(h.current)}function R(L){let G=(L??e).trim();if(!G||Xpa(_))return;U(G),n(""),C({text:G}).finally(()=>j()),g$(h.current)}function q(){let L=q_e();localStorage.setItem(b$,L),I([]),s([]),a(L),n(""),d(),g$(h.current)}return zt.jsxDEV("div",{className:"web-chat-shell","data-web-chat-app":"true","data-web-chat-ui":"ai-elements-v0","data-conversation-id":t,"data-drawer-open":m?"true":"false",children:[zt.jsxDEV("div",{className:"web-chat-mobile-drawer-scrim","aria-hidden":"true",onClick:d},void 0,!1,void 0,this),zt.jsxDEV("button",{type:"button",className:"web-chat-mobile-drawer-close","aria-label":"Close sessions",onClick:d,children:zt.jsxDEV("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6","aria-hidden":"true",children:zt.jsxDEV("path",{d:"M4 4l8 8M12 4l-8 8",strokeLinecap:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),zt.jsxDEV("aside",{className:"web-chat-sessions","aria-label":"Sessions",children:[zt.jsxDEV("header",{className:"web-chat-sessions-header",children:[zt.jsxDEV("h2",{children:"Sessions"},void 0,!1,void 0,this),zt.jsxDEV("button",{className:"web-chat-sessions-new",type:"button","aria-label":"New conversation",onClick:q,children:zt.jsxDEV("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.75","aria-hidden":"true",children:zt.jsxDEV("path",{d:"M8 3v10M3 8h10",strokeLinecap:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i.length===0?zt.jsxDEV("p",{className:"web-chat-sessions-list-empty",children:"No traces yet."},void 0,!1,void 0,this):zt.jsxDEV("ul",{className:"web-chat-sessions-list",role:"listbox",children:i.map((L)=>zt.jsxDEV("li",{children:zt.jsxDEV("button",{className:"web-chat-session",type:"button",role:"option","aria-selected":L.id===t,"data-active":L.id===t?"true":"false",onClick:()=>void H(L.id),children:[zt.jsxDEV("span",{className:"web-chat-session-time",children:nda(L.lastActiveAt)},void 0,!1,void 0,this),zt.jsxDEV("div",{className:"web-chat-session-body",children:zt.jsxDEV("h3",{className:"web-chat-session-title",children:L.title},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},L.id,!1,void 0,this))},void 0,!1,void 0,this),zt.jsxDEV("footer",{className:"web-chat-sessions-footer",children:zt.jsxDEV("span",{className:"web-chat-sessions-footer-id",children:"brain · anchor"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),zt.jsxDEV("main",{className:"web-chat-app","aria-label":"Brain chat",children:[zt.jsxDEV("header",{className:"web-chat-header",children:[zt.jsxDEV("div",{children:[zt.jsxDEV("span",{className:"web-chat-header-eyebrow",children:["Anchor",k.length>0?zt.jsxDEV(zt.Fragment,{children:[" · ",zt.jsxDEV("strong",{children:[k.length," message",k.length===1?"":"s"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):null]},void 0,!0,void 0,this),zt.jsxDEV("h1",{children:["Brain ",zt.jsxDEV("em",{children:"Chat"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),zt.jsxDEV("p",{children:"A field log for talking with the rhizome."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),zt.jsxDEV("div",{className:"web-chat-header-actions",children:[zt.jsxDEV("button",{type:"button",className:"web-chat-mobile-trigger","aria-label":"Open sessions","aria-expanded":m,"data-active":m?"true":"false",onClick:()=>l(!0),children:zt.jsxDEV("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6","aria-hidden":"true",children:zt.jsxDEV("path",{d:"M2.5 4.5h11M2.5 8h11M2.5 11.5h7",strokeLinecap:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),zt.jsxDEV("button",{className:"web-chat-icon-action",type:"button",onClick:b,"aria-label":A==="light"?"Switch to dark mode":"Switch to light mode",title:A==="light"?"Switch to dark mode":"Switch to light mode",children:A==="light"?zt.jsxDEV("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5","aria-hidden":"true",children:zt.jsxDEV("path",{d:"M13 9.5A5 5 0 0 1 6.5 3a5 5 0 1 0 6.5 6.5Z",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this):zt.jsxDEV("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5","aria-hidden":"true",children:[zt.jsxDEV("circle",{cx:"8",cy:"8",r:"3"},void 0,!1,void 0,this),zt.jsxDEV("path",{d:"M8 1v1.5M8 13.5V15M1 8h1.5M13.5 8H15M3 3l1.1 1.1M11.9 11.9 13 13M3 13l1.1-1.1M11.9 4.1 13 3",strokeLinecap:"round"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),zt.jsxDEV("button",{className:"web-chat-secondary-action",type:"button",onClick:q,children:[zt.jsxDEV("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5","aria-hidden":"true",children:zt.jsxDEV("path",{d:"M8 3v10M3 8h10",strokeLinecap:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"New"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),zt.jsxDEV(Kqe,{children:zt.jsxDEV(Yqe,{children:[k.length===0?zt.jsxDEV(Jqe,{eyebrow:"No traces yet",title:"Begin a field note.",description:"Ask the brain about entities, notes, prompts, or recent work — the thread grows from the first message."},void 0,!1,void 0,this):k.map((L)=>zt.jsxDEV(NRn,{from:L.role,children:[zt.jsxDEV(HRn,{role:L.role},void 0,!1,void 0,this),zt.jsxDEV(SRn,{children:Tpa(L.parts).map((G,z)=>{if(G.kind==="text")return zt.jsxDEV(x_e,{children:G.text},z,!1,void 0,this);if(G.kind==="tools"){if(G.tools.length===1)return zt.jsxDEV(Xae,{data:G.tools[0]},z,!1,void 0,this);return zt.jsxDEV(Xqe,{tools:G.tools},z,!1,void 0,this)}if(G.kind==="confirmation")return zt.jsxDEV(Vqe,{conversationId:t,data:G.data},z,!1,void 0,this);return zt.jsxDEV(e7e,{type:G.type,data:G.data},z,!1,void 0,this)})},void 0,!1,void 0,this)]},L.id,!0,void 0,this)),zt.jsxDEV("div",{ref:f,"aria-hidden":"true"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),_!=="ready"?zt.jsxDEV("p",{className:"web-chat-status","data-status":_,children:[zt.jsxDEV("span",{className:"web-chat-status-rail","aria-hidden":"true"},void 0,!1,void 0,this),zt.jsxDEV("span",{className:"web-chat-status-phrase",children:tda(_)},void 0,!1,void 0,this),zt.jsxDEV("span",{className:"web-chat-status-meta",children:_},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null,v?zt.jsxDEV("div",{className:"web-chat-error",role:"alert",children:[zt.jsxDEV("span",{className:"web-chat-error-tag",children:"[ signal lost ]"},void 0,!1,void 0,this),zt.jsxDEV("p",{children:v.message},void 0,!1,void 0,this),zt.jsxDEV("button",{type:"button",onClick:D,children:"Dismiss"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null,zt.jsxDEV(ZRn,{onSubmit:(L)=>R(L.text),children:[zt.jsxDEV("label",{htmlFor:"web-chat-input",children:"Message"},void 0,!1,void 0,this),zt.jsxDEV(ORn,{id:"web-chat-input",ref:h,value:e,placeholder:"Plant a question…",onInput:(L)=>n(L.currentTarget.value)},void 0,!1,void 0,this),zt.jsxDEV(KRn,{children:[zt.jsxDEV(YRn,{},void 0,!1,void 0,this),zt.jsxDEV(JRn,{status:_,onStop:x,disabled:!e.trim()},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var XRn=ia(SA(),1),WRn=document.querySelector("[data-web-chat-root]");if(WRn)TRn.createRoot(WRn).render(XRn.jsxDEV($Rn,{},void 0,!1,void 0,this));
|
|
3975
|
+
*/var m2n={startOnLoad:!1,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:!0};function tta(e={}){let n=!1,t={...m2n,...e.config},a={initialize(i){t={...m2n,...e.config,...i},JJ.initialize(t),n=!0},async render(i,r){return n||(JJ.initialize(t),n=!0),await JJ.render(i,r)}};return{name:"mermaid",type:"diagram",language:"mermaid",getMermaid(i){return i&&a.initialize(i),a}}}var l2n=tta();var jRn=ia(ms(),1);i$();var r8=ia(SA(),1);function I_e(...e){return e.filter(Boolean).join(" ")}var NRn=({className:e,from:n,...t})=>r8.jsxDEV("div",{className:I_e("web-chat-message group flex w-full max-w-[95%] flex-col gap-2",n==="user"?"is-user ml-auto justify-end":"is-assistant",e),"data-role":n,...t},void 0,!1,void 0,this),SRn=({className:e,...n})=>r8.jsxDEV("div",{className:I_e("web-chat-message-bubble is-user:dark flex w-fit min-w-0 max-w-full flex-col gap-2 overflow-hidden text-sm",e),...n},void 0,!1,void 0,this);function HRn({role:e,time:n}){return r8.jsxDEV("span",{className:"web-chat-message-header",children:[{assistant:"Brain",system:"System",user:"You"}[e],n?r8.jsxDEV("time",{children:n},void 0,!1,void 0,this):null]},void 0,!0,void 0,this)}var Opa={cjk:F7e,code:TZe,math:cYe,mermaid:l2n},x_e=jRn.memo(({className:e,...n})=>r8.jsxDEV(p$,{className:I_e("web-chat-markdown-response size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",e),plugins:Opa,...n},void 0,!1,void 0,this),(e,n)=>e.children===n.children&&n.isAnimating===e.isAnimating);x_e.displayName="MessageResponse";var rC=ia(ms(),1),vA=ia(SA(),1);function d$(...e){return e.filter(Boolean).join(" ")}function ZRn({children:e,className:n,onSubmit:t,...a}){let i=rC.useCallback((r)=>{r.preventDefault();let s=new FormData(r.currentTarget).get("message")??"";t({files:[],text:s},r)},[t]);return vA.jsxDEV("form",{className:d$("web-chat-prompt-input",n),onSubmit:i,...a,children:e},void 0,!1,void 0,this)}var ORn=rC.forwardRef(function({className:n,name:t="message",onKeyDown:a,...i},r){let[o,s]=rC.useState(!1),A=rC.useCallback((u)=>{if(a?.(u),u.defaultPrevented)return;if(u.key!=="Enter")return;if(u.shiftKey||o||u.nativeEvent.isComposing)return;if(u.preventDefault(),u.currentTarget.form?.querySelector('button[type="submit"]')?.disabled)return;u.currentTarget.form?.requestSubmit()},[o,a]);return vA.jsxDEV("textarea",{ref:r,className:d$("web-chat-prompt-textarea",n),name:t,onCompositionEnd:()=>s(!1),onCompositionStart:()=>s(!0),onKeyDown:A,...i},void 0,!1,void 0,this)});function KRn({children:e,className:n,...t}){return vA.jsxDEV("div",{className:d$("web-chat-prompt-footer",n),...t,children:e},void 0,!1,void 0,this)}function YRn(){return vA.jsxDEV("span",{className:"web-chat-prompt-hint",children:[vA.jsxDEV("kbd",{children:"Enter"},void 0,!1,void 0,this)," to send · ",vA.jsxDEV("kbd",{children:"Shift"},void 0,!1,void 0,this),"+",vA.jsxDEV("kbd",{children:"Enter"},void 0,!1,void 0,this)," newline"]},void 0,!0,void 0,this)}function Kpa(){return vA.jsxDEV("svg",{viewBox:"0 0 18 14",fill:"none",stroke:"currentColor",strokeWidth:"1.5","aria-hidden":"true",children:[vA.jsxDEV("path",{d:"M2 7h10M9 3c1.5 2 3 4 5 4-2 0-3.5 2-5 4",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this),vA.jsxDEV("circle",{cx:"2",cy:"7",r:"1.5",fill:"currentColor",stroke:"none"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function JRn({children:e,className:n,disabled:t=!1,onClick:a,onStop:i,status:r="ready",...o}){let s=r==="submitted"||r==="streaming",A=rC.useCallback((u)=>{if(s&&i){u.preventDefault(),i();return}a?.(u)},[s,a,i]);return vA.jsxDEV("button",{"aria-label":s?"Stop response":"Send message",className:d$("web-chat-prompt-submit",n),disabled:t&&!s,onClick:A,type:s&&i?"button":"submit",...o,children:e??(s?"Stop":vA.jsxDEV(vA.Fragment,{children:["Send",vA.jsxDEV(Kpa,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this))},void 0,!1,void 0,this)}var zt=ia(SA(),1),b$="brain:web-chat:conversation-id",Ypa="brain:theme";function Jpa(){if(typeof document>"u")return"dark";return document.documentElement.getAttribute("data-theme")==="light"?"light":"dark"}function Ppa(e){document.documentElement.setAttribute("data-theme",e);try{localStorage.setItem(Ypa,e)}catch{}}var D_e=86400000,PRn=48;function q_e(){return`web-${crypto.randomUUID()}`}function $pa(){try{let e=localStorage.getItem(b$);if(e)return e;let n=q_e();return localStorage.setItem(b$,n),n}catch{return q_e()}}function Wpa(e){return{id:e.id,role:e.role,parts:[{type:"text",text:e.content}]}}function F_e(e){if(typeof e!=="object"||e===null||!("data"in e))return;return e.data}function Tpa(e){let n=[],t=[],a=()=>{if(t.length===0)return;n.push({kind:"tools",tools:t}),t=[]};for(let i of e){if(i.type==="data-tool-result"){t.push(F_e(i));continue}if(a(),i.type==="text")n.push({kind:"text",text:i.text});else if(i.type==="data-confirmation")n.push({kind:"confirmation",data:F_e(i)});else if(i.type.startsWith("data-"))n.push({kind:"generic",type:i.type,data:F_e(i)})}return a(),n}function Xpa(e){return e==="submitted"||e==="streaming"}function Vpa(e){e.style.height="auto",e.style.height=`${e.scrollHeight}px`}function g$(e){requestAnimationFrame(()=>e?.focus())}function eda(e){let n=e.trim().split(/\r?\n/,1)[0]??"";if(!n)return"New conversation";if(n.length<=PRn)return n;return`${n.slice(0,PRn-1).trimEnd()}…`}function nda(e,n=new Date){let t=new Date(e);if(Number.isNaN(t.getTime()))return"—";let a=n.getTime()-t.getTime();if(a<D_e&&t.getDate()===n.getDate())return t.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"});let i=new Date(n.getTime()-D_e);if(t.getDate()===i.getDate())return"Yest";if(a<7*D_e)return t.toLocaleDateString(void 0,{weekday:"short"});return t.toLocaleDateString(void 0,{day:"numeric",month:"short"})}function tda(e){if(e==="submitted")return"the rhizome is listening";if(e==="streaming")return"the rhizome is listening";if(e==="error")return"a thread broke mid-growth";return""}function $Rn(){let[e,n]=nA.useState(""),[t,a]=nA.useState(()=>$pa()),[i,r]=nA.useState([]),[o,s]=nA.useState([]),[A,u]=nA.useState(()=>Jpa()),[m,l]=nA.useState(!1);function d(){l(!1)}function b(){let L=A==="light"?"dark":"light";u(L),Ppa(L)}let f=nA.useRef(null),h=nA.useRef(null),y=nA.useMemo(()=>new Nqe({api:"/api/chat",credentials:"include"}),[]),B=nA.useMemo(()=>new mz({id:t,messages:o,transport:y}),[t,o,y]),{messages:k,sendMessage:C,setMessages:I,status:_,error:v,stop:x,clearError:D}=A6e({chat:B});nA.useEffect(()=>{f.current?.scrollIntoView({block:"end",behavior:"smooth"})},[k,_]),nA.useEffect(()=>{if(h.current)Vpa(h.current)},[e]),nA.useEffect(()=>{g$(h.current),j()},[]);async function j(){let L=await fetch("/api/chat/sessions",{credentials:"include"});if(!L.ok)return;let G=await L.json();r(G.sessions)}function U(L){let G=new Date().toISOString(),z={id:t,title:eda(L),lastActiveAt:G};r((O)=>{let Z=O.find((Y)=>Y.id===t),J=Z&&Z.title!=="New conversation"?{...Z,lastActiveAt:G}:z,N=O.filter((Y)=>Y.id!==t);return[J,...N]})}async function H(L){let G=await fetch(`/api/chat/messages?id=${encodeURIComponent(L)}`,{credentials:"include"});if(!G.ok)return;let O=(await G.json()).messages.map(Wpa);localStorage.setItem(b$,L),I(O),s(O),a(L),n(""),d(),g$(h.current)}function R(L){let G=(L??e).trim();if(!G||Xpa(_))return;U(G),n(""),C({text:G}).finally(()=>j()),g$(h.current)}function q(){let L=q_e();localStorage.setItem(b$,L),I([]),s([]),a(L),n(""),d(),g$(h.current)}return zt.jsxDEV("div",{className:"web-chat-shell","data-web-chat-app":"true","data-web-chat-ui":"ai-elements-v0","data-conversation-id":t,"data-drawer-open":m?"true":"false",children:[zt.jsxDEV("div",{className:"web-chat-mobile-drawer-scrim","aria-hidden":"true",onClick:d},void 0,!1,void 0,this),zt.jsxDEV("button",{type:"button",className:"web-chat-mobile-drawer-close","aria-label":"Close sessions",onClick:d,children:zt.jsxDEV("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6","aria-hidden":"true",children:zt.jsxDEV("path",{d:"M4 4l8 8M12 4l-8 8",strokeLinecap:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),zt.jsxDEV("aside",{className:"web-chat-sessions","aria-label":"Sessions",children:[zt.jsxDEV("header",{className:"web-chat-sessions-header",children:[zt.jsxDEV("h2",{children:"Sessions"},void 0,!1,void 0,this),zt.jsxDEV("button",{className:"web-chat-sessions-new",type:"button","aria-label":"New conversation",onClick:q,children:zt.jsxDEV("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.75","aria-hidden":"true",children:zt.jsxDEV("path",{d:"M8 3v10M3 8h10",strokeLinecap:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i.length===0?zt.jsxDEV("p",{className:"web-chat-sessions-list-empty",children:"No traces yet."},void 0,!1,void 0,this):zt.jsxDEV("ul",{className:"web-chat-sessions-list",role:"listbox",children:i.map((L)=>zt.jsxDEV("li",{children:zt.jsxDEV("button",{className:"web-chat-session",type:"button",role:"option","aria-selected":L.id===t,"data-active":L.id===t?"true":"false",onClick:()=>void H(L.id),children:[zt.jsxDEV("span",{className:"web-chat-session-time",children:nda(L.lastActiveAt)},void 0,!1,void 0,this),zt.jsxDEV("div",{className:"web-chat-session-body",children:zt.jsxDEV("h3",{className:"web-chat-session-title",children:L.title},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},L.id,!1,void 0,this))},void 0,!1,void 0,this),zt.jsxDEV("footer",{className:"web-chat-sessions-footer",children:zt.jsxDEV("span",{className:"web-chat-sessions-footer-id",children:"brain · anchor"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),zt.jsxDEV("main",{className:"web-chat-app","aria-label":"Brain chat",children:[zt.jsxDEV("header",{className:"web-chat-header",children:[zt.jsxDEV("button",{type:"button",className:"web-chat-mobile-trigger","aria-label":"Open sessions","aria-expanded":m,"data-active":m?"true":"false",onClick:()=>l(!0),children:zt.jsxDEV("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6","aria-hidden":"true",children:zt.jsxDEV("path",{d:"M2.5 4.5h11M2.5 8h11M2.5 11.5h7",strokeLinecap:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),zt.jsxDEV("div",{children:[zt.jsxDEV("span",{className:"web-chat-header-eyebrow",children:["Anchor",k.length>0?zt.jsxDEV(zt.Fragment,{children:[" · ",zt.jsxDEV("strong",{children:[k.length," message",k.length===1?"":"s"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):null]},void 0,!0,void 0,this),zt.jsxDEV("h1",{children:["Brain ",zt.jsxDEV("em",{children:"Chat"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),zt.jsxDEV("p",{children:"A field log for talking with the rhizome."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),zt.jsxDEV("div",{className:"web-chat-header-actions",children:[zt.jsxDEV("button",{className:"web-chat-icon-action",type:"button",onClick:b,"aria-label":A==="light"?"Switch to dark mode":"Switch to light mode",title:A==="light"?"Switch to dark mode":"Switch to light mode",children:A==="light"?zt.jsxDEV("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5","aria-hidden":"true",children:zt.jsxDEV("path",{d:"M13 9.5A5 5 0 0 1 6.5 3a5 5 0 1 0 6.5 6.5Z",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this):zt.jsxDEV("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5","aria-hidden":"true",children:[zt.jsxDEV("circle",{cx:"8",cy:"8",r:"3"},void 0,!1,void 0,this),zt.jsxDEV("path",{d:"M8 1v1.5M8 13.5V15M1 8h1.5M13.5 8H15M3 3l1.1 1.1M11.9 11.9 13 13M3 13l1.1-1.1M11.9 4.1 13 3",strokeLinecap:"round"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),zt.jsxDEV("button",{className:"web-chat-secondary-action",type:"button",onClick:q,children:[zt.jsxDEV("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5","aria-hidden":"true",children:zt.jsxDEV("path",{d:"M8 3v10M3 8h10",strokeLinecap:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"New"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),zt.jsxDEV(Kqe,{children:zt.jsxDEV(Yqe,{children:[k.length===0?zt.jsxDEV(Jqe,{eyebrow:"No traces yet",title:"Begin a field note.",description:"Ask the brain about entities, notes, prompts, or recent work — the thread grows from the first message."},void 0,!1,void 0,this):k.map((L)=>zt.jsxDEV(NRn,{from:L.role,children:[zt.jsxDEV(HRn,{role:L.role},void 0,!1,void 0,this),zt.jsxDEV(SRn,{children:Tpa(L.parts).map((G,z)=>{if(G.kind==="text")return zt.jsxDEV(x_e,{children:G.text},z,!1,void 0,this);if(G.kind==="tools"){if(G.tools.length===1)return zt.jsxDEV(Xae,{data:G.tools[0]},z,!1,void 0,this);return zt.jsxDEV(Xqe,{tools:G.tools},z,!1,void 0,this)}if(G.kind==="confirmation")return zt.jsxDEV(Vqe,{conversationId:t,data:G.data},z,!1,void 0,this);return zt.jsxDEV(e7e,{type:G.type,data:G.data},z,!1,void 0,this)})},void 0,!1,void 0,this)]},L.id,!0,void 0,this)),zt.jsxDEV("div",{ref:f,"aria-hidden":"true"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),_!=="ready"?zt.jsxDEV("p",{className:"web-chat-status","data-status":_,children:[zt.jsxDEV("span",{className:"web-chat-status-rail","aria-hidden":"true"},void 0,!1,void 0,this),zt.jsxDEV("span",{className:"web-chat-status-phrase",children:tda(_)},void 0,!1,void 0,this),zt.jsxDEV("span",{className:"web-chat-status-meta",children:_},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null,v?zt.jsxDEV("div",{className:"web-chat-error",role:"alert",children:[zt.jsxDEV("span",{className:"web-chat-error-tag",children:"[ signal lost ]"},void 0,!1,void 0,this),zt.jsxDEV("p",{children:v.message},void 0,!1,void 0,this),zt.jsxDEV("button",{type:"button",onClick:D,children:"Dismiss"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null,zt.jsxDEV(ZRn,{onSubmit:(L)=>R(L.text),children:[zt.jsxDEV("label",{htmlFor:"web-chat-input",children:"Message"},void 0,!1,void 0,this),zt.jsxDEV(ORn,{id:"web-chat-input",ref:h,value:e,placeholder:"Plant a question…",onInput:(L)=>n(L.currentTarget.value)},void 0,!1,void 0,this),zt.jsxDEV(KRn,{children:[zt.jsxDEV(YRn,{},void 0,!1,void 0,this),zt.jsxDEV(JRn,{status:_,onStop:x,disabled:!e.trim()},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var XRn=ia(SA(),1),WRn=document.querySelector("[data-web-chat-root]");if(WRn)TRn.createRoot(WRn).render(XRn.jsxDEV($Rn,{},void 0,!1,void 0,this));
|
|
3976
3976
|
|
|
3977
|
-
//# debugId=
|
|
3977
|
+
//# debugId=1E28245A0B1DEBE864756E2164756E21
|