@byfriends/vis-server 0.3.4 → 0.3.6
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/LICENSE +9 -16
- package/dist/public/assets/index-CE9cqWg9.js +5 -0
- package/dist/public/assets/vendor-react-DlPTGA9E.js +60 -0
- package/dist/public/assets/vendor-tanstack-DA7DPQma.js +4 -0
- package/dist/public/index.html +3 -3
- package/package.json +4 -4
- package/dist/public/assets/index-B-eI7eKY.js +0 -5
- package/dist/public/assets/vendor-react-CNwmIw-M.js +0 -299
- package/dist/public/assets/vendor-tanstack-CmEBlPtt.js +0 -4
package/LICENSE
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2026-2027 ByronFinn
|
|
4
4
|
|
|
5
|
-
Permission is hereby granted
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
Restrictions:
|
|
13
|
-
1. You may NOT redistribute modified versions of this software.
|
|
14
|
-
2. You may NOT use this software for commercial purposes.
|
|
15
|
-
3. You may NOT sublicense, sell, or offer this software as a service.
|
|
16
|
-
|
|
17
|
-
This software is source-available but NOT open source. The source code is
|
|
18
|
-
made publicly visible for review purposes only.
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
19
14
|
|
|
20
15
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
16
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
@@ -24,5 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
24
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
21
|
SOFTWARE.
|
|
27
|
-
|
|
28
|
-
For questions about licensing, contact: https://github.com/ByronFinn/byf/issues
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{r as x,u as F,j as e,L as R,b as Le,c as me,R as Pe,d as G,e as Ae,B as De}from"./vendor-react-DlPTGA9E.js";import{u as W,a as fe,b as Re,c as Me,Q as Be,d as Fe}from"./vendor-tanstack-DA7DPQma.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))o(a);new MutationObserver(a=>{for(const r of a)if(r.type==="childList")for(const l of r.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&o(l)}).observe(document,{childList:!0,subtree:!0});function n(a){const r={};return a.integrity&&(r.integrity=a.integrity),a.referrerPolicy&&(r.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?r.credentials="include":a.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function o(a){if(a.ep)return;a.ep=!0;const r=n(a);fetch(a.href,r)}})();const X="vis.theme";function We(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function qe(){try{const t=localStorage.getItem(X);if(t==="light"||t==="dark"||t==="auto")return t}catch{}return"auto"}function Ke(t){const s=document.documentElement;s.dataset.theme=t;const n=document.querySelector('meta[name="theme-color"]');n&&(n.content=t==="light"?"#fafbfc":"#0b0d12")}function Ue(){const[t,s]=x.useState(()=>qe()),[n,o]=x.useState(()=>We());x.useEffect(()=>{const i=window.matchMedia("(prefers-color-scheme: light)"),c=()=>{o(i.matches?"light":"dark")};return i.addEventListener("change",c),()=>{i.removeEventListener("change",c)}},[]);const a=t==="auto"?n:t;x.useEffect(()=>{Ke(a)},[a]);const r=x.useCallback(i=>{s(i);try{i==="auto"?localStorage.removeItem(X):localStorage.setItem(X,i)}catch{}},[]),l=x.useCallback(()=>{r(t==="auto"?"light":t==="light"?"dark":"auto")},[t,r]);return{choice:t,resolved:a,cycle:l,set:r}}const oe="byf-vis-auth-token";function ae(t){const s=t.replace(/^[#?]/,"");if(s.length===0)return null;const n=new URLSearchParams(s);return n.get("token")??n.get("vis_token")}function le(t){const s=t.has("token")||t.has("vis_token");return t.delete("token"),t.delete("vis_token"),s}function Ve(){const t=new URL(window.location.href),s=le(t.searchParams),n=t.hash.replace(/^#/,"");let o=!1;if(n.length>0){const a=new URLSearchParams(n);if(o=le(a),o){const r=a.toString();t.hash=r.length>0?r:""}}(s||o)&&window.history.replaceState(null,"",t.toString())}function ze(){if(typeof window>"u")return null;const t=ae(window.location.hash),s=ae(window.location.search),n=t??s;return n!==null&&n.length>0?(window.localStorage.setItem(oe,n),Ve(),n):window.localStorage.getItem(oe)}async function ee(t,s){const n={accept:"application/json"},o=ze();o!==null&&o.length>0&&(n.authorization=`Bearer ${o}`);const a=await fetch(t,{method:s,headers:n});if(!a.ok){let r=null;try{r=await a.json()}catch{}throw new Error(r?.error??`HTTP ${a.status} ${a.statusText}`)}return await a.json()}function B(t){return ee(t,"GET")}function He(t){return ee(t,"POST")}function Je(t){return ee(t,"DELETE")}const E=encodeURIComponent,L={listSessions:async()=>(await B("/api/sessions")).sessions,getSession:t=>B(`/api/sessions/${E(t)}`),getWire:(t,s)=>B(`/api/sessions/${E(t)}/wire?agent=${E(s)}`),getContext:(t,s)=>B(`/api/sessions/${E(t)}/context?agent=${E(s)}`),getAgentTree:t=>B(`/api/sessions/${E(t)}/agents`),deleteSession:t=>Je(`/api/sessions/${E(t)}`),revealSession:t=>He(`/api/sessions/${E(t)}/reveal`)};function he(){return W({queryKey:["sessions"],queryFn:()=>L.listSessions()})}function z(t){return W({queryKey:["session",t],queryFn:()=>L.getSession(t),enabled:!!t})}function Ye(){const t=fe();return Re({mutationFn:s=>L.deleteSession(s),onSuccess:(s,n)=>{t.setQueryData(["sessions"],o=>o?.filter(a=>a.sessionId!==n)),t.removeQueries({queryKey:["session",n]}),t.invalidateQueries({queryKey:["sessions"]})}})}function te(t){if(!t||!Number.isFinite(t))return"—";const s=Date.now()-t;if(s<0)return"just now";const n=Math.floor(s/1e3);if(n<60)return`${n}s ago`;const o=Math.floor(n/60);if(o<60)return`${o}m ago`;const a=Math.floor(o/60);if(a<24)return`${a}h ago`;const r=Math.floor(a/24);if(r<30)return`${r}d ago`;const l=Math.floor(r/30);return l<12?`${l}mo ago`:`${Math.floor(l/12)}y ago`}function ge(t){if(!t||!Number.isFinite(t))return"—";const s=new Date(t),n=o=>String(o).padStart(2,"0");return`${s.getFullYear()}-${n(s.getMonth()+1)}-${n(s.getDate())} ${n(s.getHours())}:${n(s.getMinutes())}:${n(s.getSeconds())}`}function Qe(t){if(!t||!Number.isFinite(t))return"--:--:--";const s=new Date(t),n=o=>String(o).padStart(2,"0");return`${n(s.getHours())}:${n(s.getMinutes())}:${n(s.getSeconds())}`}function ie({session:t,onDelete:s,deleting:n}){const{sessionId:o}=F(),a=o===t.sessionId,r=t.workDir?t.workDir.split("/").slice(-2).join("/"):"(no workspace)",l=t.sessionId.replace(/^session_/,"").slice(0,10),i=t.title,c=Math.max(0,t.agentCount-1);function d(f){f.preventDefault(),f.stopPropagation(),s(t)}return e.jsxs("div",{className:["group relative border-b border-border transition-colors",a?"bg-surface-2":"hover:bg-surface-1"].join(" "),children:[a?e.jsx("span",{className:"absolute inset-y-0 left-0 w-[2px] bg-[var(--color-cat-conversation)]"}):null,e.jsxs(R,{to:`/sessions/${t.sessionId}`,className:"block px-3 py-2 pr-10",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"inline-block h-[7px] w-[7px] shrink-0 rounded-full",style:{backgroundColor:"var(--color-fg-3)"}}),e.jsx("span",{className:"shrink-0 font-mono text-[12px] text-fg-0",children:l})]}),e.jsx("span",{className:"shrink-0 font-mono text-[10.5px] text-fg-3 tabular",children:te(t.updatedAt)})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-3 font-mono text-[10.5px] text-fg-2",children:[e.jsx("span",{className:"truncate",title:t.workDir??"",children:r}),e.jsxs("span",{className:"tabular text-fg-3",children:[t.mainWireRecordCount,"ev"]}),c>0?e.jsxs("span",{className:"tabular text-[var(--color-cat-subagent)]",children:[c,"sub"]}):null,t.health!=="ok"?e.jsx("span",{className:"tabular text-[var(--color-sev-error)]",children:t.health}):null]}),i?e.jsx("div",{className:"mt-1 truncate font-mono text-[11px] text-fg-1",title:i,children:i}):null,t.lastPrompt?e.jsxs("div",{className:"mt-1 truncate font-mono text-[10.5px] text-fg-3",title:t.lastPrompt,children:["prompt · ",t.lastPrompt]}):null]}),e.jsx("button",{type:"button",onClick:d,disabled:n,className:"absolute right-2 top-2 flex h-5 w-5 items-center justify-center border border-transparent text-fg-3 transition-colors hover:border-[var(--color-sev-error)] hover:text-[var(--color-sev-error)] disabled:cursor-not-allowed disabled:opacity-40",title:`Delete session ${t.sessionId}`,"aria-label":`Delete session ${t.sessionId}`,children:e.jsx(Ge,{})})]})}function Ge(){return e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 12 12","aria-hidden":"true",children:[e.jsx("path",{d:"M2 3 H10",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"square"}),e.jsx("path",{d:"M4 3 V2 H8 V3",stroke:"currentColor",strokeWidth:"1.2",fill:"none"}),e.jsx("path",{d:"M3 4 H9 L8.5 10 H3.5 Z",stroke:"currentColor",strokeWidth:"1.2",fill:"none"})]})}const Ze=[{value:"recent",label:"recent"},{value:"oldest",label:"oldest"},{value:"most_records",label:"most records"},{value:"most_subagents",label:"most subagents"}],Xe=[{value:"all",label:"any"},{value:"ok",label:"ok"},{value:"broken_state",label:"broken state"},{value:"broken_main_wire",label:"broken wire"},{value:"missing_main_wire",label:"no wire"},{value:"unsupported_protocol",label:"old proto"}];function et({search:t,onSearchChange:s,sortKey:n,onSortChange:o,healthFilter:a,onHealthChange:r,totalCount:l,filteredCount:i}){return e.jsxs("div",{className:"border-b border-border bg-surface-1 px-3 py-2",children:[e.jsx("div",{className:"relative",children:e.jsx("input",{type:"text",value:t,onChange:c=>{s(c.target.value)},placeholder:"search id / title / workspace",className:"w-full border border-border bg-surface-0 px-2 py-1 font-mono text-[12px] text-fg-0 placeholder:text-fg-3 focus:border-border-strong focus:outline-none"})}),e.jsxs("div",{className:"mt-2 grid grid-cols-2 gap-2",children:[e.jsxs("label",{className:"flex items-center gap-1.5 font-mono text-[10.5px] text-fg-2",children:[e.jsx("span",{className:"text-fg-3",children:"sort"}),e.jsx("select",{value:n,onChange:c=>{o(c.target.value)},className:"flex-1 border border-border bg-surface-0 px-1 py-0.5 text-fg-1 focus:border-border-strong focus:outline-none",children:Ze.map(c=>e.jsx("option",{value:c.value,children:c.label},c.value))})]}),e.jsxs("label",{className:"flex items-center gap-1.5 font-mono text-[10.5px] text-fg-2",children:[e.jsx("span",{className:"text-fg-3",children:"health"}),e.jsx("select",{value:a,onChange:c=>{r(c.target.value)},className:"flex-1 border border-border bg-surface-0 px-1 py-0.5 text-fg-1 focus:border-border-strong focus:outline-none",children:Xe.map(c=>e.jsx("option",{value:c.value,children:c.label},c.value))})]})]}),e.jsx("div",{className:"mt-2 flex items-center justify-end",children:e.jsxs("span",{className:"font-mono text-[10px] text-fg-3 tabular",children:[i," / ",l]})})]})}function tt(t){return t.workDir?t.workDir.split("/").slice(-2).join("/"):"(no workspace)"}function st(t,s){switch(s){case"recent":return t.toSorted((n,o)=>o.updatedAt-n.updatedAt);case"oldest":return t.toSorted((n,o)=>n.createdAt-o.createdAt);case"most_records":return t.toSorted((n,o)=>o.mainWireRecordCount-n.mainWireRecordCount);case"most_subagents":return t.toSorted((n,o)=>o.agentCount-1-(n.agentCount-1))}}function nt(){const{data:t,isLoading:s,error:n}=he(),o=Ye(),a=Le(),{sessionId:r}=F(),[l,i]=x.useState(""),[c,d]=x.useState("recent"),[f,k]=x.useState("all"),w=x.useMemo(()=>{if(!t)return[];const j=l.trim().toLowerCase();return t.filter(p=>f!=="all"&&p.health!==f?!1:j?[p.sessionId,p.title??"",p.lastPrompt??"",p.workDir??""].join(" ").toLowerCase().includes(j):!0)},[t,l,f]),g=x.useMemo(()=>{if(c!=="recent")return null;const j=new Map;for(const p of w){const h=tt(p),S=j.get(h);S===void 0?j.set(h,[p]):S.push(p)}return[...j.entries()].map(([p,h])=>{const S=h.toSorted((U,Y)=>Y.updatedAt-U.updatedAt);return[p,S]}).toSorted(([,p],[,h])=>{const S=p[0]?.updatedAt??0;return(h[0]?.updatedAt??0)-S})},[w,c]),q=x.useMemo(()=>g===null?st(w,c):null,[w,c,g]);async function K(j){const p=j.title??j.lastPrompt??j.sessionId;if(window.confirm(`Delete session "${p}"?
|
|
2
|
+
|
|
3
|
+
This removes its files from BYF_HOME.`))try{await o.mutateAsync(j.sessionId),r===j.sessionId&&a("/")}catch(h){window.alert(h instanceof Error?h.message:String(h))}}return e.jsxs("aside",{className:"flex h-full min-h-0 w-[320px] shrink-0 flex-col border-r border-border bg-surface-1",children:[e.jsx(et,{search:l,onSearchChange:i,sortKey:c,onSortChange:d,healthFilter:f,onHealthChange:k,totalCount:t?.length??0,filteredCount:w.length}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s?e.jsx("div",{className:"p-3 font-mono text-[11px] text-fg-3",children:"loading…"}):n?e.jsx("div",{className:"p-3 font-mono text-[11px] text-[var(--color-sev-error)]",children:n.message}):w.length===0?e.jsx("div",{className:"p-3 font-mono text-[11px] text-fg-3",children:"no sessions match"}):g!==null?g.map(([j,p])=>e.jsxs("div",{children:[e.jsxs("div",{className:"sticky top-0 z-10 border-b border-border bg-surface-1 px-3 py-1 font-mono text-[10px] uppercase tracking-[0.12em] text-fg-3",children:[j," ",e.jsxs("span",{className:"text-fg-3 tabular",children:["· ",p.length]})]}),p.map(h=>e.jsx(ie,{session:h,onDelete:S=>{K(S)},deleting:o.isPending&&o.variables===h.sessionId},h.sessionId))]},j)):q?.map(j=>e.jsx(ie,{session:j,onDelete:p=>{K(p)},deleting:o.isPending&&o.variables===j.sessionId},j.sessionId))})]})}function rt({children:t}){const s=fe(),{choice:n,resolved:o,cycle:a}=Ue();return e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("header",{className:"flex h-10 shrink-0 items-center justify-between border-b border-border bg-surface-1 px-4",children:[e.jsxs(R,{to:"/",className:"flex items-center gap-2",children:[e.jsx(at,{}),e.jsxs("span",{className:"font-mono text-[12px] uppercase tracking-[0.12em] text-fg-0",children:["byf ",e.jsx("span",{className:"text-fg-2",children:"vis"})]}),e.jsx("span",{className:"ml-2 font-mono text-[10px] uppercase tracking-[0.12em] text-fg-3",children:"debug · local files"})]}),e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-fg-2",children:[e.jsx(ot,{choice:n,resolved:o,onCycle:a}),e.jsxs("button",{onClick:()=>{s.invalidateQueries()},className:"flex items-center gap-1.5 border border-border px-2 py-0.5 font-mono text-[11px] text-fg-1 transition-colors hover:border-border-strong hover:text-fg-0",title:"Refresh — re-read all session data from disk",children:[e.jsx(lt,{}),"refresh"]})]})]}),e.jsxs("div",{className:"flex min-h-0 flex-1",children:[e.jsx(nt,{}),e.jsx("main",{className:"flex min-h-0 flex-1 flex-col",children:t})]})]})}function ot({choice:t,resolved:s,onCycle:n}){const o=t==="auto"?`auto · ${s}`:t,a=`Theme: ${o}. Click to cycle (auto → light → dark → auto).`;return e.jsxs("button",{onClick:n,className:"flex items-center gap-1.5 border border-border px-2 py-0.5 font-mono text-[11px] text-fg-1 transition-colors hover:border-border-strong hover:text-fg-0",title:a,"aria-label":`Theme ${o}`,children:[t==="auto"?e.jsx(dt,{}):s==="light"?e.jsx(it,{}):e.jsx(ct,{}),e.jsx("span",{className:"tabular",children:o})]})}function at(){return e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",children:[e.jsx("rect",{x:"1",y:"1",width:"6",height:"6",fill:"var(--color-cat-conversation)"}),e.jsx("rect",{x:"9",y:"1",width:"6",height:"6",fill:"var(--color-cat-subagent)"}),e.jsx("rect",{x:"1",y:"9",width:"6",height:"6",fill:"var(--color-cat-ephemeral)"}),e.jsx("rect",{x:"9",y:"9",width:"6",height:"6",fill:"var(--color-cat-approval)"})]})}function lt(){return e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 12 12","aria-hidden":"true",children:[e.jsx("path",{d:"M10 3 A5 5 0 1 0 10.8 7",stroke:"currentColor",strokeWidth:"1.2",fill:"none",strokeLinecap:"square"}),e.jsx("path",{d:"M7 1 L10 3 L7 5",stroke:"currentColor",strokeWidth:"1.2",fill:"none",strokeLinecap:"square",strokeLinejoin:"miter"})]})}function it(){return e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 12 12","aria-hidden":"true",children:[e.jsx("circle",{cx:"6",cy:"6",r:"2",fill:"currentColor"}),e.jsxs("g",{stroke:"currentColor",strokeWidth:"1",strokeLinecap:"round",children:[e.jsx("line",{x1:"6",y1:"0.5",x2:"6",y2:"2"}),e.jsx("line",{x1:"6",y1:"10",x2:"6",y2:"11.5"}),e.jsx("line",{x1:"0.5",y1:"6",x2:"2",y2:"6"}),e.jsx("line",{x1:"10",y1:"6",x2:"11.5",y2:"6"}),e.jsx("line",{x1:"2",y1:"2",x2:"3",y2:"3"}),e.jsx("line",{x1:"9",y1:"9",x2:"10",y2:"10"}),e.jsx("line",{x1:"10",y1:"2",x2:"9",y2:"3"}),e.jsx("line",{x1:"3",y1:"9",x2:"2",y2:"10"})]})]})}function ct(){return e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 12 12","aria-hidden":"true",children:e.jsx("path",{d:"M9 7.5 A4.5 4.5 0 1 1 4.5 3 A3.6 3.6 0 0 0 9 7.5 Z",fill:"currentColor"})})}function dt(){return e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 12 12","aria-hidden":"true",children:[e.jsx("path",{d:"M6 1 A5 5 0 1 1 6 11 Z",fill:"currentColor"}),e.jsx("circle",{cx:"6",cy:"6",r:"4.5",fill:"none",stroke:"currentColor",strokeWidth:"1"})]})}function xt(t,s){return W({queryKey:["context",t,s],queryFn:()=>L.getContext(t,s),enabled:t.length>0&&s.length>0})}const ut={conversation:"--color-cat-conversation",config:"--color-cat-config",lifecycle:"--color-cat-lifecycle",subagent:"--color-cat-subagent",approval:"--color-cat-approval",ephemeral:"--color-cat-ephemeral",meta:"--color-cat-meta",tools:"--color-cat-tools",user:"--color-user",assistant:"--color-assistant",tool:"--color-tool",compaction:"--color-compaction",turn:"--color-turn",info:"--color-sev-info",success:"--color-sev-success",warning:"--color-sev-warning",error:"--color-sev-error",neutral:"--color-fg-2"};function m({tone:t="neutral",variant:s="soft",children:n,title:o,className:a=""}){const r=`var(${ut[t]})`,l=s==="solid"?{backgroundColor:r,color:"var(--color-on-accent)"}:s==="outline"?{border:`1px solid ${r}`,color:r}:{backgroundColor:`color-mix(in oklab, ${r} 18%, transparent)`,color:r};return e.jsx("span",{className:`pill ${a}`,style:l,title:o,children:n})}function pt({message:t}){const s=mt(t);return e.jsxs("div",{className:"my-3 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"h-px flex-1 bg-[var(--color-compaction)] opacity-50"}),e.jsxs("span",{className:"font-mono text-[11px] uppercase tracking-[0.12em] text-[var(--color-compaction)]",children:["prior context compacted · line ",t.lineNo]}),e.jsx("span",{className:"h-px flex-1 bg-[var(--color-compaction)] opacity-50"})]}),s.length>0?e.jsx("pre",{className:"whitespace-pre-wrap break-words font-mono text-[12px] text-fg-2",children:s}):null]})}function mt(t){for(const s of t.message.content)if(s.type==="text")return s.text;return""}function T({value:t,label:s="copy",className:n=""}){const[o,a]=x.useState("idle");return e.jsx("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(t).then(()=>{a("ok")}).catch(()=>{a("err")}).finally(()=>setTimeout(()=>{a("idle")},1200))},className:`font-mono text-[10px] text-fg-3 transition-colors hover:text-fg-1 ${n}`,title:`Copy ${t}`,children:o==="idle"?s:o==="ok"?"✓ copied":"✗ err"})}function je({url:t,label:s="image_url"}){const[n,o]=x.useState(!1),[a,r]=x.useState(!1),l=t.startsWith("data:image/")||/^https?:\/\//.test(t),i=t.startsWith("data:image/")?`${t.length.toLocaleString()} chars`:new URL(t,window.location.href).hostname;return l?e.jsxs("div",{className:"border border-border bg-surface-0 p-2",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"font-mono text-[10px] text-fg-3",children:[s,e.jsxs("span",{className:"ml-2 text-fg-3",children:["· ",i]})]}),e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(T,{value:t,label:"copy url"}),e.jsx("a",{href:t,target:"_blank",rel:"noreferrer",className:"font-mono text-[10px] text-fg-3 hover:text-fg-1",children:"open in tab ↗"}),e.jsx("button",{type:"button",onClick:()=>{o(c=>!c)},className:"font-mono text-[10px] text-fg-3 hover:text-fg-1",children:n?"shrink":"expand"})]})]}),a?e.jsx("div",{className:"font-mono text-[11px] text-[var(--color-sev-error)]",children:"failed to load image"}):e.jsx("img",{src:t,alt:"content image",loading:"lazy",onError:()=>{r(!0)},className:"block max-w-full object-contain "+(n?"max-h-[80vh]":"max-h-[220px]")})]}):e.jsxs("div",{className:"border border-border bg-surface-0 p-2",children:[e.jsxs("div",{className:"mb-1 font-mono text-[10px] text-fg-3",children:[s," (unsupported scheme)"]}),e.jsx("span",{className:"break-all font-mono text-[12px] text-fg-1",children:t})]})}function ft({message:t}){const s=t.message.role;return s==="user"?e.jsx(ht,{m:t}):s==="assistant"?e.jsx(gt,{m:t}):s==="tool"?e.jsx(jt,{m:t}):e.jsx(bt,{m:t})}function H(){return"relative flex max-w-full min-w-0 flex-col border-l-[3px] bg-surface-1 px-3 py-2"}function ht({m:t}){const n=t.message.origin?.kind,o=n==="system_trigger"||n==="injection"||n==="hook_result";return e.jsxs("article",{className:H(),style:{borderLeftColor:"var(--color-user)"},children:[e.jsxs("header",{className:"mb-1 flex items-center gap-2",children:[e.jsx(m,{tone:"user",variant:"solid",children:"user"}),e.jsxs("span",{className:"font-mono text-[10px] text-fg-3 tabular",children:["line ",t.lineNo]}),o?e.jsx(m,{tone:"meta",variant:"outline",children:n}):null,t.message.isError?e.jsx(m,{tone:"error",variant:"outline",children:"error"}):null]}),e.jsx(J,{parts:t.message.content})]})}function gt({m:t}){const s=t.message.content.find(r=>r.type==="think"),n=s&&s.type==="think"?s.think:void 0,o=t.message.content.filter(r=>r.type!=="think"),a=t.message.toolCalls;return e.jsxs("article",{className:H(),style:{borderLeftColor:"var(--color-assistant)"},children:[e.jsxs("header",{className:"mb-1 flex items-center gap-2",children:[e.jsx(m,{tone:"assistant",variant:"solid",children:"assistant"}),e.jsxs("span",{className:"font-mono text-[10px] text-fg-3 tabular",children:["line ",t.lineNo]}),n?e.jsx(m,{tone:"config",variant:"outline",children:"think"}):null,a.length>0?e.jsxs(m,{tone:"tools",variant:"outline",children:[a.length," tool call",a.length>1?"s":""]}):null,t.message.partial?e.jsx(m,{tone:"warning",variant:"outline",children:"partial"}):null]}),n?e.jsx(be,{text:n}):null,e.jsx(J,{parts:o}),a.length>0?e.jsx("div",{className:"mt-2 space-y-1",children:a.map(r=>e.jsx(vt,{call:r},r.id))}):null]})}function jt({m:t}){const[s,n]=x.useState(t.message.isError===!0),o=t.message.content.reduce((r,l)=>l.type==="text"?r+l.text.length:r,0),a=Nt(t.message.content);return e.jsxs("article",{className:H(),style:{borderLeftColor:"var(--color-tool)"},children:[e.jsxs("button",{type:"button",onClick:()=>{n(r=>!r)},className:"flex w-full items-center gap-2 text-left",children:[e.jsx("span",{className:"text-fg-3",children:s?"▾":"▸"}),e.jsx(m,{tone:"tool",variant:"solid",children:"tool"}),t.message.toolCallId?e.jsxs("span",{className:"font-mono text-[11px] text-fg-1",children:["call ",t.message.toolCallId.slice(0,12)]}):null,e.jsxs("span",{className:"font-mono text-[10px] text-fg-3 tabular",children:["line ",t.lineNo]}),t.message.isError?e.jsx(m,{tone:"error",variant:"outline",children:"error"}):null,s?null:e.jsxs("span",{className:"ml-1 flex min-w-0 flex-1 items-center gap-2 font-mono text-[11px] text-fg-3",children:[e.jsx("span",{className:"truncate",children:a}),e.jsxs("span",{className:"shrink-0 tabular",children:["· ",o.toLocaleString()," chars"]})]})]}),s?e.jsx("div",{className:"mt-2 max-h-[60vh] overflow-auto",children:e.jsx(J,{parts:t.message.content})}):null]})}function bt({m:t}){return e.jsxs("article",{className:H(),style:{borderLeftColor:"var(--color-cat-config)"},children:[e.jsxs("header",{className:"mb-1 flex items-center gap-2",children:[e.jsx(m,{tone:"config",variant:"solid",children:"system"}),e.jsxs("span",{className:"font-mono text-[10px] text-fg-3 tabular",children:["line ",t.lineNo]})]}),e.jsx(J,{parts:t.message.content})]})}function be({text:t}){const[s,n]=x.useState(!1);return e.jsxs("div",{className:"mb-2 border border-border bg-surface-0",children:[e.jsxs("button",{onClick:()=>{n(o=>!o)},className:"flex w-full items-center gap-2 px-2 py-1 text-left font-mono text-[11px] text-fg-2 hover:text-fg-1",children:[e.jsx("span",{className:"text-fg-3",children:s?"▾":"▸"}),e.jsx("span",{className:"uppercase tracking-[0.08em]",children:"thinking"}),e.jsxs("span",{className:"text-fg-3 tabular",children:[t.length,"ch"]})]}),s?e.jsx("pre",{className:"border-t border-border px-2 py-1 whitespace-pre-wrap break-words font-mono text-[12px] text-fg-1",children:t}):null]})}function vt({call:t}){const[s,n]=x.useState(!1),o=t.arguments??"";return e.jsxs("div",{className:"border border-border bg-surface-0",children:[e.jsxs("button",{onClick:()=>{n(a=>!a)},className:"flex w-full items-center gap-2 px-2 py-1 text-left font-mono text-[11px] hover:bg-surface-2",children:[e.jsx("span",{className:"text-fg-3",children:s?"▾":"▸"}),e.jsx(m,{tone:"tools",variant:"soft",children:"call"}),e.jsx("span",{className:"text-fg-0",children:t.name}),e.jsx("span",{className:"truncate text-fg-3",children:ve(o,80)}),e.jsx("span",{className:"ml-auto text-fg-3 tabular text-[10px]",children:t.id.slice(0,10)})]}),s?e.jsx("pre",{className:"border-t border-border px-2 py-1 whitespace-pre-wrap break-words font-mono text-[12px] text-fg-1",children:wt(o)}):null]})}function J({parts:t}){return e.jsx("div",{className:"space-y-2",children:t.map((s,n)=>s.type==="text"?e.jsx("pre",{className:"whitespace-pre-wrap break-words font-mono text-[12.5px] leading-[1.55] text-fg-0",children:s.text},n):s.type==="think"?e.jsx(be,{text:s.think},n):s.type==="image_url"?e.jsx(je,{url:s.imageUrl.url},n):s.type==="audio_url"?e.jsxs("div",{className:"font-mono text-[11px] text-fg-2",children:["[audio: ",s.audioUrl.url,"]"]},n):s.type==="video_url"?e.jsxs("div",{className:"font-mono text-[11px] text-fg-2",children:["[video: ",s.videoUrl.url??"—","]"]},n):e.jsxs("div",{className:"font-mono text-[11px] text-fg-3",children:["[",s.type,"]"]},n))})}function ve(t,s){return t.length<=s?t:t.slice(0,s)+"…"}function Nt(t){for(const s of t){if(s.type==="text"&&s.text.length>0){const n=s.text.split(`
|
|
4
|
+
`,1)[0]??"";return ve(n,100)}if(s.type==="image_url")return"[image]";if(s.type==="audio_url")return"[audio]";if(s.type==="video_url")return"[video]"}return"(empty)"}function wt(t){try{return JSON.stringify(JSON.parse(t),null,2)}catch{return t}}function Ne({sessionId:t,initialAgentId:s="main"}){const[n,o]=x.useState(s);x.useEffect(()=>{o(s)},[t,s]);const{data:a}=z(t),{data:r,isLoading:l,error:i}=xt(t,n),c=a?.agents??[],d=r?.messages??[],f=r?.usage.byScope.session??yt,k=r?.config??{},w=r?.permission.mode??null;return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-3 border-b border-border bg-surface-1 px-3 py-2",children:[e.jsxs("label",{className:"flex items-center gap-2 font-mono text-[11px] text-fg-2",children:[e.jsx("span",{className:"text-fg-3",children:"agent"}),e.jsxs("select",{value:n,onChange:g=>{o(g.target.value)},className:"border border-border bg-surface-0 px-2 py-1 font-mono text-[12px] text-fg-0 focus:border-border-strong focus:outline-none",children:[c.length===0?e.jsx("option",{value:n,children:n}):null,c.map(g=>e.jsxs("option",{value:g.agentId,children:[g.agentId," (",g.type,g.parentAgentId?` ← ${g.parentAgentId}`:"",")"]},g.agentId))]})]}),e.jsxs("span",{className:"font-mono text-[11px] text-fg-2",children:[e.jsx("span",{className:"tabular text-fg-0",children:d.length}),e.jsx("span",{className:"ml-1 text-fg-3",children:"messages"})]}),k.modelAlias?e.jsxs("span",{className:"font-mono text-[11px] text-fg-2",children:[e.jsx("span",{className:"text-fg-3",children:"model"})," ",e.jsx("span",{className:"text-fg-0",children:k.modelAlias})]}):null,e.jsx("div",{className:"ml-auto flex items-center gap-2",children:w?e.jsxs(m,{tone:"approval",variant:"outline",children:["permission: ",w]}):null})]}),e.jsx(kt,{usage:f}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:e.jsxs("div",{className:"flex flex-col gap-3 px-3 py-4",children:[k.systemPrompt?e.jsx(Ct,{text:k.systemPrompt}):null,l?e.jsx("div",{className:"px-3 py-2 font-mono text-[12px] text-fg-3",children:"loading context…"}):i?e.jsx("div",{className:"px-3 py-2 font-mono text-[12px] text-[var(--color-sev-error)]",children:i.message}):d.length===0?e.jsx("div",{className:"px-3 py-2 font-mono text-[12px] text-fg-3",children:"no messages — session has only lifecycle/config records so far."}):d.map(g=>g.source==="compaction_summary"?e.jsx(pt,{message:g},g.lineNo):e.jsx(ft,{message:g},g.lineNo))]})})]})}const yt={inputOther:0,output:0,inputCacheRead:0,inputCacheCreation:0},V={inputCacheRead:"var(--color-sev-success)",inputOther:"var(--color-sev-info)",output:"var(--color-assistant)",inputCacheCreation:"var(--color-sev-warning)"};function kt({usage:t}){const s=t.inputOther+t.output+t.inputCacheRead+t.inputCacheCreation;if(s===0)return e.jsx("div",{className:"h-[2px] shrink-0 bg-border"});const n=o=>o/s*100;return e.jsxs("div",{className:"flex h-[3px] w-full shrink-0",title:`cache_read ${t.inputCacheRead.toLocaleString()} · input ${t.inputOther.toLocaleString()} · output ${t.output.toLocaleString()} · cache_create ${t.inputCacheCreation.toLocaleString()}`,children:[t.inputCacheRead>0?e.jsx("div",{style:{width:`${n(t.inputCacheRead)}%`,backgroundColor:V.inputCacheRead}}):null,t.inputOther>0?e.jsx("div",{style:{width:`${n(t.inputOther)}%`,backgroundColor:V.inputOther}}):null,t.output>0?e.jsx("div",{style:{width:`${n(t.output)}%`,backgroundColor:V.output}}):null,t.inputCacheCreation>0?e.jsx("div",{style:{width:`${n(t.inputCacheCreation)}%`,backgroundColor:V.inputCacheCreation}}):null]})}function Ct({text:t}){const[s,n]=x.useState(!1);return e.jsxs("article",{className:"relative flex max-w-full min-w-0 flex-col border-l-[3px] bg-surface-1",style:{borderLeftColor:"var(--color-cat-config)"},children:[e.jsxs("button",{type:"button",onClick:()=>{n(o=>!o)},className:"flex w-full items-center justify-between gap-3 px-3 py-2 text-left hover:bg-surface-2",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(m,{tone:"config",variant:"solid",children:"system"}),e.jsxs("span",{className:"font-mono text-[10px] text-fg-3 tabular",children:[t.length.toLocaleString()," chars"]})]}),e.jsx("span",{className:"font-mono text-[11px] text-fg-1",children:s?"▾ collapse":"▸ show full"})]}),e.jsxs("div",{className:"relative min-w-0 px-3 pb-2",children:[e.jsx("pre",{className:["min-w-0 whitespace-pre-wrap [overflow-wrap:anywhere] font-mono text-[12.5px] text-fg-0",s?"":"max-h-[9em] overflow-hidden"].join(" "),children:t}),s?null:e.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 bottom-0 h-14",style:{background:"linear-gradient(to bottom, transparent 0%, var(--color-surface-1) 85%)"}})]})]})}function we({tabs:t,defaultTab:s}){const[n,o]=me(),a=n.get("tab")??s;return e.jsx("div",{className:"flex h-9 shrink-0 items-stretch border-b border-border bg-surface-1",children:t.map(r=>{const l=r.id===a;return e.jsxs("button",{onClick:()=>{const i=new URLSearchParams(n);i.set("tab",r.id),o(i,{replace:!0})},className:["relative flex items-center gap-2 px-4 font-mono text-[11px] uppercase tracking-[0.08em] transition-colors",l?"text-fg-0":"text-fg-2 hover:text-fg-1"].join(" "),children:[r.label,r.count!==null&&r.count!==void 0?e.jsx("span",{className:"font-mono text-[10px] text-fg-3 tabular",children:r.count}):null,l?e.jsx("span",{className:"absolute inset-x-0 bottom-[-1px] h-[2px] bg-[var(--color-cat-conversation)]"}):null]},r.id)})})}function ye(t){const[s]=me();return s.get("tab")??t}const ce=200;function _({value:t,defaultOpenDepth:s=2}){return e.jsx("div",{className:"font-mono text-[12px] leading-[1.5]",children:e.jsx(_t,{value:t,depth:0,defaultOpenDepth:s,keyPath:""})})}const _t=x.memo(function t({value:s,depth:n,defaultOpenDepth:o,keyPath:a,keyLabel:r,isLast:l}){const[i,c]=x.useState(n<o);if(s===null)return e.jsx(O,{keyLabel:r,repr:"null",color:"text-fg-3",isLast:l});if(s===void 0)return e.jsx(O,{keyLabel:r,repr:"undefined",color:"text-fg-3",isLast:l});if(typeof s=="boolean")return e.jsx(O,{keyLabel:r,repr:String(s),color:"text-[var(--color-cat-config)]",isLast:l});if(typeof s=="number")return e.jsx(O,{keyLabel:r,repr:String(s),color:"text-[var(--color-sev-info)]",isLast:l});if(typeof s=="string")return s.length<=ce?e.jsx(O,{keyLabel:r,repr:JSON.stringify(s),color:"text-[var(--color-cat-ephemeral)]",isLast:l}):e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>{c(d=>!d)},className:"flex items-baseline gap-1 text-left hover:text-fg-0",children:[e.jsx("span",{className:"text-fg-3 w-3 shrink-0 inline-block",children:i?"▾":"▸"}),r!==void 0?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-1",children:r}),e.jsx("span",{className:"text-fg-3",children:":"})]}):null,e.jsx("span",{className:"truncate text-[var(--color-cat-ephemeral)]",children:`"${s.slice(0,ce)}…"`}),e.jsxs("span",{className:"text-fg-3 shrink-0",children:["(",s.length.toLocaleString()," chars)"]})]}),i?e.jsx("div",{className:"ml-[5px] my-1 border-l border-border pl-3",children:e.jsxs("div",{className:"relative border border-border bg-surface-0",children:[e.jsx("div",{className:"absolute top-1 right-1 z-10",children:e.jsx(T,{value:s,className:"border border-border bg-surface-1 px-1.5 py-0.5"})}),e.jsx("pre",{className:"max-h-[60vh] overflow-auto whitespace-pre-wrap break-words p-2 pr-16 font-mono text-[12px] leading-[1.55] text-fg-0",children:s})]})}):null]});if(Array.isArray(s))return s.length===0?e.jsx(O,{keyLabel:r,repr:"[]",color:"text-fg-3",isLast:l}):e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>{c(d=>!d)},className:"flex items-baseline gap-1 text-left hover:text-fg-0",children:[e.jsx("span",{className:"text-fg-3 w-3 shrink-0 inline-block",children:i?"▾":"▸"}),r!==void 0?e.jsx("span",{className:"text-fg-1",children:r}):null,r!==void 0?e.jsx("span",{className:"text-fg-3",children:":"}):null,e.jsxs("span",{className:"text-fg-3",children:["[",s.length,"]"]})]}),i?e.jsx("div",{className:"border-l border-border ml-[5px] pl-3",children:s.map((d,f)=>e.jsx(t,{value:d,depth:n+1,defaultOpenDepth:o,keyPath:`${a}[${f}]`,keyLabel:f,isLast:f===s.length-1},f))}):null]});if(typeof s=="object"){const d=Object.entries(s);return d.length===0?e.jsx(O,{keyLabel:r,repr:"{}",color:"text-fg-3",isLast:l}):e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>{c(f=>!f)},className:"flex items-baseline gap-1 text-left hover:text-fg-0",children:[e.jsx("span",{className:"text-fg-3 w-3 shrink-0 inline-block",children:i?"▾":"▸"}),r!==void 0?e.jsx("span",{className:"text-fg-1",children:r}):null,r!==void 0?e.jsx("span",{className:"text-fg-3",children:":"}):null,e.jsxs("span",{className:"text-fg-3",children:["{",d.length,"}"]})]}),i?e.jsx("div",{className:"border-l border-border ml-[5px] pl-3",children:d.map(([f,k],w)=>e.jsx(t,{value:k,depth:n+1,defaultOpenDepth:o,keyPath:`${a}.${f}`,keyLabel:f,isLast:w===d.length-1},f))}):null]})}return e.jsx(O,{keyLabel:r,repr:typeof s,color:"text-fg-3",isLast:l})});function O({keyLabel:t,repr:s,color:n}){return e.jsxs("div",{className:"flex items-baseline gap-1",children:[e.jsx("span",{className:"w-3 shrink-0"}),t!==void 0?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-1",children:t}),e.jsx("span",{className:"text-fg-3",children:":"})]}):null,e.jsx("span",{className:n,children:s})]})}function St({state:t}){const s=x.useMemo(()=>t??{},[t]),n=xe(s.createdAt),o=xe(s.updatedAt),a=s.agents!==void 0?Object.keys(s.agents):[],r=s.custom?.imported_from_byf_cli===!0;return e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"font-mono text-[11px] uppercase tracking-[0.12em] text-fg-3",children:"state.json"}),e.jsx(T,{value:JSON.stringify(s,null,2),label:"copy json"})]}),r?e.jsxs("div",{className:"mt-3 border border-[var(--color-sev-warning)] bg-[color-mix(in_oklab,var(--color-sev-warning)_10%,transparent)] px-3 py-2 font-mono text-[11px] text-[var(--color-sev-warning)]",children:["warning · this session is marked",e.jsx("code",{className:"mx-1 px-1 bg-surface-0",children:"imported_from_byf_cli"}),"and would normally be filtered out of the list."]}):null,e.jsxs("div",{className:"mt-3 grid grid-cols-1 gap-2 md:grid-cols-2",children:[e.jsxs(D,{label:"title",children:[s.title!==void 0&&s.title!==""?e.jsxs("span",{className:"font-mono text-[12px] text-fg-0",children:['"',s.title,'"']}):e.jsx("span",{className:"font-mono text-[12px] text-fg-3",children:"(none)"}),s.isCustomTitle===!0?e.jsx(m,{tone:"config",variant:"outline",children:"custom"}):null]}),e.jsx(D,{label:"forkedFrom",children:s.forkedFrom!==void 0&&s.forkedFrom!==""?e.jsx("span",{className:"font-mono text-[12px] text-fg-0 break-all",children:s.forkedFrom}):e.jsx("span",{className:"font-mono text-[12px] text-fg-3",children:"(none)"})}),e.jsx(D,{label:"createdAt",children:e.jsx(de,{ms:n,raw:s.createdAt})}),e.jsx(D,{label:"updatedAt",children:e.jsx(de,{ms:o,raw:s.updatedAt})}),e.jsx(D,{label:"lastPrompt",children:s.lastPrompt!==void 0&&s.lastPrompt!==""?e.jsx("span",{className:"font-mono text-[12px] text-fg-0 line-clamp-3",title:s.lastPrompt,children:s.lastPrompt}):e.jsx("span",{className:"font-mono text-[12px] text-fg-3",children:"(none)"})}),e.jsx(D,{label:`agents (${a.length})`,children:a.length===0?e.jsx("span",{className:"font-mono text-[12px] text-fg-3",children:"(none)"}):e.jsx("span",{className:"flex flex-wrap items-center gap-1",children:a.map(l=>e.jsx("span",{className:"border border-border bg-surface-1 px-1.5 py-0.5 font-mono text-[11px] text-fg-1",children:l},l))})})]}),e.jsxs("section",{className:"mt-6",children:[e.jsx("h3",{className:"font-mono text-[11px] uppercase tracking-[0.12em] text-fg-3",children:"custom"}),e.jsx("div",{className:"mt-2 border border-border bg-surface-0 p-3",children:s.custom===void 0||Object.keys(s.custom).length===0?e.jsx("span",{className:"font-mono text-[11px] text-fg-3",children:"(empty)"}):e.jsx(_,{value:s.custom,defaultOpenDepth:2})})]}),e.jsxs("section",{className:"mt-6",children:[e.jsx("h3",{className:"font-mono text-[11px] uppercase tracking-[0.12em] text-fg-3",children:"raw state.json"}),e.jsx("div",{className:"mt-2 border border-border bg-surface-0 p-3",children:e.jsx(_,{value:s,defaultOpenDepth:2})})]})]})}function D({label:t,children:s}){return e.jsxs("div",{className:"border border-border bg-surface-0 px-3 py-2",children:[e.jsx("div",{className:"font-mono text-[10px] uppercase tracking-[0.1em] text-fg-3",children:t}),e.jsx("div",{className:"mt-1 flex flex-wrap items-center gap-2",children:s})]})}function de({ms:t,raw:s}){return t===null?s!==void 0&&s!==""?e.jsx("span",{className:"font-mono text-[12px] text-fg-3 break-all",children:s}):e.jsx("span",{className:"font-mono text-[12px] text-fg-3",children:"(none)"}):e.jsxs("span",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"font-mono text-[12px] text-fg-0 tabular",children:ge(t)}),e.jsxs("span",{className:"font-mono text-[11px] text-fg-3",children:["(",te(t),")"]})]})}function xe(t){if(t===void 0||t==="")return null;const s=Date.parse(t);return Number.isFinite(s)?s:null}function $t(t,s=!0){return W({queryKey:["session",t,"agents"],queryFn:()=>L.getAgentTree(t),enabled:!!t&&s})}const It={main:"conversation",sub:"subagent",independent:"tools"};function ke({node:t,sessionId:s}){const{agentId:n}=F(),o=n===t.agentId,a=!t.wireExists;return e.jsxs("div",{className:"my-1",children:[e.jsx(R,{to:`/sessions/${s}/agents/${t.agentId}`,className:["relative flex items-start gap-3 border border-border bg-surface-0 px-3 py-2 transition-colors hover:bg-surface-1",o?"border-[var(--color-cat-subagent)]":""].join(" "),children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(m,{tone:It[t.type],variant:"soft",children:t.type}),e.jsx("span",{className:"font-mono text-[12px] text-fg-0",children:t.agentId}),t.parentAgentId!==null?e.jsxs("span",{className:"font-mono text-[10.5px] text-fg-3",children:["← ",t.parentAgentId]}):null,a?e.jsx(m,{tone:"warning",variant:"outline",children:"no wire"}):null,e.jsxs("span",{className:"ml-auto font-mono text-[10.5px] text-fg-3 tabular",children:[t.wireRecordCount," rec",t.wireRecordCount===1?"":"s",t.wireProtocolVersion!==null?` · v${t.wireProtocolVersion}`:""]})]}),e.jsx("div",{className:"mt-1 truncate font-mono text-[10.5px] text-fg-3",title:t.homedir,children:t.homedir})]})}),t.children.length>0?e.jsx("div",{className:"mt-1 border-l border-border pl-3 ml-3",children:t.children.map(r=>e.jsx(ke,{node:r,sessionId:s},r.agentId))}):null]})}function Et({tree:t,sessionId:s}){return t.length===0?e.jsx("div",{className:"p-6 font-mono text-[12px] text-fg-3",children:"no agents found in state.json"}):e.jsx("div",{className:"p-3",children:t.map(n=>e.jsx(ke,{node:n,sessionId:s},n.agentId))})}function Ot({sessionId:t}){const{data:s,isLoading:n,error:o}=$t(t);return n?e.jsx("div",{className:"p-6 font-mono text-[12px] text-fg-3",children:"loading agents…"}):o?e.jsx("div",{className:"p-6 font-mono text-[12px] text-[var(--color-sev-error)]",children:o.message}):s?e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:e.jsx(Et,{tree:s.tree,sessionId:t})}):null}function Tt(t,s,n=!0){return W({queryKey:["session",t,"wire",s],queryFn:()=>L.getWire(t,s),enabled:!!t&&!!s&&n})}const ue={error:0,warning:1,info:2};function Lt(t,s){const n=[],o=new Map,a=new Map;let r=null;for(const l of t){const i=l.data,c=l.lineNo;switch(i.type){case"context.append_loop_event":{const d=i.event;d.type==="tool.call"?o.set(d.toolCallId,{lineNo:c,name:d.name}):d.type==="tool.result"?o.get(d.toolCallId)!==void 0?o.delete(d.toolCallId):n.push({severity:"warning",kind:"missing_tool_result",lineNo:c,summary:`orphan tool.result for #${d.toolCallId.slice(-8)}`,detail:"no preceding tool.call seen"}):d.type==="step.begin"?a.set(d.uuid,{lineNo:c,step:d.step,turnId:d.turnId}):d.type==="step.end"&&a.delete(d.uuid);break}case"full_compaction.begin":r={lineNo:c,source:i.source};break;case"full_compaction.complete":case"full_compaction.cancel":r=null;break;case"permission.record_approval_result":i.result.decision==="rejected"&&n.push({severity:"info",kind:"rejected_approval",lineNo:c,summary:`${i.toolName}#${i.toolCallId.slice(-8)} rejected`,detail:i.result.feedback});break}}for(const[l,i]of o)n.push({severity:"warning",kind:"orphan_tool_call",lineNo:i.lineNo,summary:`${i.name}#${l.slice(-8)} has no tool.result`,detail:"tool.call recorded but no matching tool.result found"});for(const[l,i]of a)n.push({severity:"warning",kind:"incomplete_step",lineNo:i.lineNo,summary:`step ${i.step} (turn ${i.turnId}) has no step.end`,detail:`uuid ${l.slice(-8)}`});r!==null&&n.push({severity:"warning",kind:"incomplete_compaction",lineNo:r.lineNo,summary:`${r.source} compaction never completed`});for(const l of s)n.push({severity:"info",kind:"wire_warning",lineNo:null,summary:At(l)});return n.sort((l,i)=>{const c=ue[l.severity]-ue[i.severity];if(c!==0)return c;const d=l.lineNo??Number.POSITIVE_INFINITY,f=i.lineNo??Number.POSITIVE_INFINITY;return d-f}),n}function Pt(t){if(t.length===0)return null;for(const s of t)if(s.severity==="error")return"error";for(const s of t)if(s.severity==="warning")return"warning";return"info"}function At(t){const s=t.trim(),n=s.indexOf(`
|
|
5
|
+
`),o=n===-1?s:s.slice(0,n);return o.length>120?o.slice(0,120)+"…":o}const Dt={error:"var(--color-sev-error)",warning:"var(--color-sev-warning)",info:"var(--color-sev-info)"},Rt={orphan_tool_call:"orphan tool.call",missing_tool_result:"missing tool.result",incomplete_step:"incomplete step",incomplete_compaction:"incomplete compaction",rejected_approval:"approval rejected",wire_warning:"wire warning"};function Mt({issues:t,onClose:s,onJumpTo:n,isLineVisible:o}){return x.useEffect(()=>{const a=r=>{r.key==="Escape"&&s()};return window.addEventListener("keydown",a),()=>{window.removeEventListener("keydown",a)}},[s]),e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"close issues",onClick:s,className:"absolute inset-0 z-10 bg-black/20"}),e.jsxs("aside",{className:"absolute right-0 top-0 bottom-0 z-20 flex w-[360px] flex-col border-l border-border bg-surface-1 shadow-[-8px_0_32px_rgba(0,0,0,0.25)]",role:"dialog","aria-label":"issues",children:[e.jsxs("header",{className:"flex shrink-0 items-center justify-between border-b border-border px-3 py-2 font-mono text-[12px] text-fg-0",children:[e.jsxs("span",{children:["Issues ",e.jsx("span",{className:"text-fg-3",children:"·"})," ",e.jsx("span",{className:"tabular text-fg-2",children:t.length})]}),e.jsx("button",{type:"button",onClick:s,className:"font-mono text-[14px] text-fg-3 hover:text-fg-0",title:"close (ESC)",children:"×"})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:t.length===0?e.jsx("div",{className:"p-6 font-mono text-[12px] text-fg-3",children:"no issues detected"}):e.jsx("ul",{className:"divide-y divide-border",children:t.map((a,r)=>e.jsx(Bt,{issue:a,onJumpTo:n,onClose:s,isLineVisible:o},`${a.kind}-${a.lineNo??"w"}-${r}`))})})]})]})}function Bt({issue:t,onJumpTo:s,onClose:n,isLineVisible:o}){const a=Dt[t.severity],r=t.lineNo,l=r!==null&&o!==void 0&&!o(r),i=r!==null&&s!==void 0&&!l;return e.jsxs("li",{className:"px-3 py-2 hover:bg-surface-2",children:[e.jsxs("div",{className:"flex items-center gap-2 font-mono text-[11px]",children:[e.jsx("span",{className:"inline-block h-[8px] w-[8px] shrink-0 rounded-full",style:{backgroundColor:a},"aria-hidden":"true"}),e.jsx("span",{className:"text-fg-1",children:Rt[t.kind]}),r!==null?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-3",children:"·"}),e.jsxs("span",{className:"tabular text-fg-3",children:["line ",r]})]}):null,l?e.jsx("span",{className:"text-fg-3",children:"(filtered out)"}):null,r!==null?e.jsx("button",{type:"button",disabled:!i,onClick:()=>{i&&s?.(r),n()},className:"ml-auto text-fg-3 hover:text-fg-0 disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:text-fg-3",title:l?"record is filtered out":"scroll to + expand",children:"jump →"}):null]}),e.jsx("div",{className:"mt-1 break-words font-mono text-[12px] text-fg-0",children:t.summary}),t.detail!==void 0?e.jsx("div",{className:"mt-0.5 break-words font-mono text-[10.5px] text-fg-3",children:t.detail}):null]})}const Ft={metadata:"meta","config.update":"config","turn.prompt":"turn","turn.steer":"turn","turn.cancel":"warning","context.append_message":"assistant","context.append_loop_event":"meta","context.mark_last_user_prompt_blocked":"warning","context.observation_masking":"warning","context.output_offloaded":"meta","context.pruning":"warning","context.clear":"warning","context.apply_compaction":"compaction","tools.register_user_tool":"tools","tools.unregister_user_tool":"tools","tools.set_active_tools":"tools","tools.update_store":"meta","permission.set_mode":"approval","permission.record_approval_result":"approval","usage.record":"meta","full_compaction.begin":"compaction","full_compaction.cancel":"warning","full_compaction.complete":"success","background.stop":"warning"},Wt={metadata:"meta","config.update":"config","turn.prompt":"prompt","turn.steer":"steer","turn.cancel":"cancel","context.append_message":"message","context.append_loop_event":"loop","context.mark_last_user_prompt_blocked":"blocked","context.observation_masking":"mask","context.output_offloaded":"offload","context.pruning":"pruned","context.clear":"clear","context.apply_compaction":"compacted","tools.register_user_tool":"tool+","tools.unregister_user_tool":"tool-","tools.set_active_tools":"tools","tools.update_store":"store","permission.set_mode":"perm","permission.record_approval_result":"approval","usage.record":"usage","full_compaction.begin":"compact↻","full_compaction.cancel":"compact×","full_compaction.complete":"compact✓","background.stop":"bg-stop"};function qt({type:t}){const s=Wt[t]??t,n=Ft[t]??"neutral";return e.jsx(m,{tone:n,variant:"soft",title:t,children:s})}function Ce({label:t="payload",sizeBytes:s,preview:n,children:o,defaultOpen:a=!1}){const[r,l]=x.useState(a),i=_e(s);return e.jsxs("div",{className:"my-1 border border-border bg-surface-0",children:[e.jsxs("button",{onClick:()=>{l(c=>!c)},className:"flex w-full items-center justify-between gap-2 px-2 py-1 font-mono text-[11px] text-fg-2 hover:bg-surface-2 hover:text-fg-1",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-fg-3",children:r?"▾":"▸"}),e.jsx("span",{className:"uppercase tracking-[0.08em]",children:t}),e.jsx("span",{className:"text-fg-3 tabular",children:i})]}),!r&&n?e.jsxs("span",{className:"truncate text-fg-3 font-mono text-[11px]",children:[n.slice(0,120),n.length>120?"…":""]}):null]}),r?e.jsx("div",{className:"border-t border-border px-2 py-1 font-mono text-[12px]",children:o}):null]})}function _e(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`}function Z(t,s){let n;if(t==null)n="";else if(typeof t=="string")n=t;else if(typeof t=="number"||typeof t=="boolean"||typeof t=="bigint")n=String(t);else try{n=JSON.stringify(t)}catch{return"[unserializable]"}return n.length<=s?n:n.slice(0,s)+"…"}function Kt(t){for(const s of t)if(s.type==="text"&&typeof s.text=="string")return s.text;return"(non-text)"}function Ut(t){switch(t.type){case"step.begin":return`step ${t.step} (turn ${t.turnId})`;case"step.end":return`step ${t.step} → ${t.finishReason??"?"}`;case"content.part":{const s=t.part.type==="text"?t.part.text.length:t.part.type==="think"?t.part.think.length:0;return`${t.part.type}${s?` (${s}b)`:""}`}case"tool.call":return`${t.name}#${t.toolCallId.slice(-8)}`;case"tool.result":return`result#${t.toolCallId.slice(-8)}${t.result.isError===!0?" (error)":""}`;default:return t.type??"unknown"}}function Vt(t){switch(t.type){case"metadata":return{main:e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsxs(C,{children:["protocol v",t.protocol_version]}),e.jsx(v,{children:"·"}),e.jsxs(C,{children:["created ",new Date(t.created_at).toLocaleString()]})]})};case"config.update":{const s=[];return t.profileName!==void 0&&s.push(`profile=${t.profileName}`),t.modelAlias!==void 0&&s.push(`model=${t.modelAlias}`),t.cwd!==void 0&&s.push(`cwd=${t.cwd}`),t.thinkingLevel!==void 0&&s.push(`thinking=${t.thinkingLevel}`),t.systemPrompt!==void 0&&s.push(`system(${t.systemPrompt.length}b)`),{main:e.jsx("span",{className:"truncate text-fg-0",children:s.length===0?e.jsx(v,{children:"(no fields)"}):s.join(" · ")})}}case"turn.prompt":case"turn.steer":{const s=Kt(t.input);return{main:e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(m,{tone:"turn",variant:"soft",children:t.origin.kind}),e.jsxs("span",{className:"truncate text-fg-1",children:["→ ",Z(s,80)]})]})}}case"turn.cancel":return{main:e.jsx(C,{children:t.turnId!==void 0?`turn ${t.turnId}`:"(latest)"})};case"context.append_message":{const s=t.message,n=s.toolCalls.length>0?`${s.toolCalls.length} tool_call(s)`:"";return{main:e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(m,{tone:s.role==="user"?"user":s.role==="assistant"?"assistant":s.role==="tool"?"tool":"meta",variant:"soft",children:s.role}),e.jsxs(v,{children:["(",s.content.length," part",s.content.length===1?"":"s",")"]}),n?e.jsxs(v,{children:["· ",n]}):null,s.origin?.kind?e.jsxs(v,{children:["· origin=",s.origin.kind]}):null]}),right:s.isError===!0?e.jsx(m,{tone:"error",variant:"solid",children:"error"}):void 0}}case"context.append_loop_event":return{main:e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(C,{children:t.event.type}),e.jsx(v,{className:"truncate",children:Ut(t.event)})]})};case"context.mark_last_user_prompt_blocked":return{main:e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(m,{tone:"warning",variant:"soft",children:"blocked"}),e.jsxs(v,{children:["hook: ",t.hookEvent]})]})};case"context.clear":return{main:e.jsx(v,{children:"context cleared"})};case"context.apply_compaction":return{main:e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(m,{tone:"compaction",variant:"soft",children:"compacted"}),e.jsxs(v,{children:["summary ",t.summary.length,"b · ",t.tokensBefore,"→",t.tokensAfter," tok ·"," ",t.compactedCount," msgs"]})]})};case"tools.set_active_tools":{const s=t.names.slice(0,3).join(", "),n=t.names.length>3?` +${t.names.length-3} more`:"";return{main:e.jsxs(C,{className:"truncate",children:[s,n]}),right:e.jsxs(v,{children:[t.names.length," tools"]})}}case"tools.register_user_tool":return{main:e.jsx("span",{className:"flex items-center gap-2",children:e.jsxs(C,{className:"text-[var(--color-cat-tools)]",children:["+ ",t.name]})})};case"tools.unregister_user_tool":return{main:e.jsx("span",{className:"flex items-center gap-2",children:e.jsxs(C,{className:"text-[var(--color-sev-warning)]",children:["- ",t.name]})})};case"tools.update_store":{const s=typeof t.value=="object"&&t.value!==null?"(object)":Z(String(t.value),60);return{main:e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(C,{children:t.key}),e.jsxs(v,{children:["= ",s]})]})}}case"permission.set_mode":return{main:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(v,{children:"mode →"}),e.jsx(m,{tone:"approval",variant:"soft",children:t.mode})]})};case"permission.record_approval_result":{const s=t.result.decision==="approved"?"success":t.result.decision==="rejected"?"error":"neutral";return{main:e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsxs(C,{children:[t.toolName,"#",t.toolCallId.slice(-8)]}),e.jsx(m,{tone:s,variant:"soft",children:t.result.decision}),t.result.scope?e.jsxs(v,{children:["(",t.result.scope,")"]}):null]})}}case"usage.record":return{main:e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(C,{children:t.model}),e.jsxs(v,{children:["in ",t.usage.inputOther," / out ",t.usage.output," / cache r",t.usage.inputCacheRead," w",t.usage.inputCacheCreation]})]}),right:t.usageScope?e.jsx(m,{tone:"meta",variant:"outline",children:t.usageScope}):void 0};case"full_compaction.begin":return{main:e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(m,{tone:"compaction",variant:"soft",children:t.source}),t.instruction?e.jsxs(v,{className:"truncate",children:['"',Z(t.instruction,40),'"']}):null]})};case"full_compaction.cancel":return{main:e.jsx(v,{children:"cancelled"})};case"full_compaction.complete":return{main:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsxs(v,{children:[t.compactedCount," msgs · ",t.tokensBefore,"→",t.tokensAfter," tok"]}),e.jsxs(v,{children:["· summary ",_e(t.summary.length)]})]})};case"background.stop":return{main:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(C,{children:"task"}),e.jsx(C,{children:t.taskId})]})}}return{main:e.jsxs(v,{children:["(unknown record type: ",t.type,")"]})}}function C({children:t,className:s=""}){return e.jsx("span",{className:`font-mono text-[12px] text-fg-0 ${s}`,children:t})}function v({children:t,className:s=""}){return e.jsx("span",{className:`font-mono text-[11px] text-fg-3 ${s}`,children:t})}function zt({entry:t}){const[s,n]=x.useState("none"),o=!Ht(t.raw,t.data);return e.jsxs("div",{className:"pl-[120px] pr-2 py-1 font-mono text-[12px]",children:[Jt(t.data),e.jsxs("div",{className:"mt-2 flex items-center justify-end gap-3",children:[e.jsx(T,{value:JSON.stringify(t.raw,null,2),label:"copy raw"}),o?e.jsx(T,{value:JSON.stringify(t.data,null,2),label:"copy projected"}):null,e.jsx("button",{onClick:()=>{n(a=>a==="raw"?"none":"raw")},className:`font-mono text-[10px] ${s==="raw"?"text-fg-0":"text-fg-3 hover:text-fg-1"}`,title:"What this line looks like on disk (no vis-side transforms)",children:s==="raw"?"[ hide raw ]":"[ {…} raw ]"}),o?e.jsx("button",{onClick:()=>{n(a=>a==="projected"?"none":"projected")},className:`font-mono text-[10px] ${s==="projected"?"text-fg-0":"text-fg-3 hover:text-fg-1"}`,title:"Same line after vis applied the agent-core migration chain",children:s==="projected"?"[ hide projected ]":"[ {…} projected ]"}):null]}),s!=="none"?e.jsxs("div",{className:"mt-2 border border-border bg-surface-0 p-2",children:[e.jsxs("div",{className:"mb-1 font-mono text-[10px] uppercase tracking-[0.08em] text-fg-3",children:[s==="raw"?"as written on disk":"after vis migration",o&&s==="raw"?e.jsx("span",{className:"ml-2 text-[var(--color-sev-warning)]",children:"— differs from projected"}):null]}),e.jsx(_,{value:s==="raw"?t.raw:t.data,defaultOpenDepth:2})]}):null]})}function Ht(t,s){try{return JSON.stringify(t)===JSON.stringify(s)}catch{return!1}}function Jt(t){switch(t.type){case"context.append_message":return e.jsx(Yt,{message:t.message});case"context.append_loop_event":return e.jsx(Gt,{event:t.event});case"turn.prompt":case"turn.steer":return e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"grid grid-cols-[140px_1fr] gap-x-3 gap-y-[2px]",children:e.jsx(N,{label:"origin",wide:!0,children:e.jsx(_,{value:t.origin,defaultOpenDepth:2})})}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 text-fg-2",children:["input (",t.input.length," part",t.input.length===1?"":"s",")"]}),e.jsx("div",{className:"space-y-1",children:t.input.map((s,n)=>e.jsx(se,{part:s},n))})]})]});case"context.apply_compaction":case"full_compaction.complete":return e.jsxs("div",{className:"grid grid-cols-[140px_1fr] gap-x-3 gap-y-[2px]",children:[e.jsx(N,{label:"summary",wide:!0,children:e.jsx(Ce,{label:"summary",sizeBytes:t.summary.length,preview:t.summary,children:e.jsx("pre",{className:"whitespace-pre-wrap break-words text-fg-1",children:t.summary})})}),e.jsx(N,{label:"compactedCount",children:e.jsx("span",{className:"text-[var(--color-sev-info)]",children:t.compactedCount})}),e.jsx(N,{label:"tokensBefore",children:e.jsx("span",{className:"text-[var(--color-sev-info)]",children:t.tokensBefore})}),e.jsx(N,{label:"tokensAfter",children:e.jsx("span",{className:"text-[var(--color-sev-info)]",children:t.tokensAfter})})]});default:return e.jsx(_,{value:t,defaultOpenDepth:2})}}function Yt({message:t}){return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-[140px_1fr] gap-x-3 gap-y-[2px]",children:[e.jsx(N,{label:"role",children:e.jsxs("span",{className:"text-[var(--color-cat-ephemeral)]",children:['"',t.role,'"']})}),t.toolCallId?e.jsx(N,{label:"toolCallId",children:e.jsx($,{children:t.toolCallId})}):null,t.origin?e.jsx(N,{label:"origin",wide:!0,children:e.jsx(_,{value:t.origin,defaultOpenDepth:2})}):null,t.isError===!0?e.jsx(N,{label:"isError",children:e.jsx("span",{className:"text-[var(--color-sev-error)]",children:"true"})}):null,t.partial===!0?e.jsx(N,{label:"partial",children:e.jsx("span",{className:"text-[var(--color-sev-warning)]",children:"true"})}):null]}),t.content.length>0?e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 text-fg-2",children:["content (",t.content.length," part",t.content.length===1?"":"s",")"]}),e.jsx("div",{className:"space-y-1",children:t.content.map((s,n)=>e.jsx(se,{part:s},n))})]}):null,t.toolCalls.length>0?e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 text-fg-2",children:["toolCalls (",t.toolCalls.length,")"]}),e.jsx("div",{className:"space-y-1",children:t.toolCalls.map(s=>e.jsx(Qt,{call:s},s.id))})]}):null]})}function se({part:t}){switch(t.type){case"text":return e.jsxs("div",{className:"border border-border bg-surface-0 p-2",children:[e.jsxs("div",{className:"mb-1 text-fg-3",children:["text · ",t.text.length,"b"]}),e.jsx("pre",{className:"whitespace-pre-wrap break-words text-fg-1",children:t.text})]});case"think":return e.jsxs("div",{className:"border border-[var(--color-cat-config)]/40 bg-surface-0 p-2",children:[e.jsxs("div",{className:"mb-1 text-[var(--color-cat-config)]",children:["think · ",t.think.length,"b"]}),e.jsx("pre",{className:"whitespace-pre-wrap break-words text-fg-1",children:t.think})]});case"image_url":return e.jsx(je,{url:t.imageUrl.url});case"audio_url":return e.jsxs("div",{className:"border border-border bg-surface-0 p-2",children:[e.jsx("div",{className:"mb-1 text-fg-3",children:"audio_url"}),e.jsx($,{className:"break-all",children:t.audioUrl.url})]});case"video_url":return e.jsxs("div",{className:"border border-border bg-surface-0 p-2",children:[e.jsx("div",{className:"mb-1 text-fg-3",children:"video_url"}),e.jsx($,{className:"break-all",children:t.videoUrl.url})]});default:return e.jsx(_,{value:t,defaultOpenDepth:1})}}function Qt({call:t}){const s=t.arguments??"";let n=null;if(typeof s=="string"&&s.length>0)try{n=JSON.parse(s)}catch{n=null}return e.jsxs("div",{className:"border border-[var(--color-cat-tools)]/40 bg-surface-0 p-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx($,{className:"text-[var(--color-cat-tools)]",children:t.name}),e.jsxs($,{className:"text-fg-3 text-[10px]",children:["#",t.id]})]}),e.jsx("div",{className:"mt-1",children:n!==null?e.jsx(_,{value:n,defaultOpenDepth:1}):e.jsx("pre",{className:"whitespace-pre-wrap break-words text-fg-1",children:s})})]})}function Gt({event:t}){switch(t.type){case"tool.call":{let s=t.args;if(typeof t.args=="string")try{s=JSON.parse(t.args)}catch{s=t.args}return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-[140px_1fr] gap-x-3 gap-y-[2px]",children:[e.jsx(N,{label:"name",children:e.jsx($,{className:"text-[var(--color-cat-tools)]",children:t.name})}),e.jsx(N,{label:"toolCallId",children:e.jsx($,{children:t.toolCallId})}),e.jsx(N,{label:"step",children:e.jsx("span",{className:"text-[var(--color-sev-info)]",children:t.step})}),e.jsx(N,{label:"turnId",children:e.jsx($,{children:t.turnId})}),t.description?e.jsx(N,{label:"description",wide:!0,children:e.jsx("pre",{className:"whitespace-pre-wrap break-words text-fg-1",children:t.description})}):null]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-1 text-fg-2",children:"args"}),e.jsx(_,{value:s,defaultOpenDepth:2})]}),t.display?e.jsxs("div",{children:[e.jsx("div",{className:"mb-1 text-fg-2",children:"display"}),e.jsx(_,{value:t.display,defaultOpenDepth:1})]}):null]})}case"tool.result":{const s=t.result.isError===!0,n=t.result.output;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-[140px_1fr] gap-x-3 gap-y-[2px]",children:[e.jsx(N,{label:"toolCallId",children:e.jsx($,{children:t.toolCallId})}),e.jsx(N,{label:"parentUuid",children:e.jsx($,{children:t.parentUuid})}),e.jsx(N,{label:"isError",children:e.jsx("span",{className:s?"text-[var(--color-sev-error)]":"text-[var(--color-sev-success)]",children:String(s)})}),t.result.message!==void 0?e.jsx(N,{label:"message",wide:!0,children:e.jsx("pre",{className:"whitespace-pre-wrap break-words text-fg-1",children:t.result.message})}):null]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-1 text-fg-2",children:"output"}),typeof n=="string"?e.jsx(Ce,{label:"output",sizeBytes:n.length,preview:n,children:e.jsx("pre",{className:"whitespace-pre-wrap break-words text-fg-1",children:n})}):e.jsx("div",{className:"space-y-1",children:n.map((o,a)=>e.jsx(se,{part:o},a))})]})]})}case"step.begin":case"step.end":case"content.part":return e.jsx(_,{value:t,defaultOpenDepth:2});default:return e.jsx(_,{value:t,defaultOpenDepth:2})}}function $({children:t,className:s=""}){return e.jsx("span",{className:`font-mono text-[12px] text-fg-0 ${s}`,children:t})}function N({label:t,children:s,wide:n=!1}){return n?e.jsxs("div",{className:"col-span-2 flex items-baseline gap-3",children:[e.jsx("span",{className:"w-[140px] shrink-0 font-mono text-[11px] text-fg-2 text-right",children:t}),e.jsx("div",{className:"flex-1 min-w-0",children:s})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-mono text-[11px] text-fg-2 text-right",children:t}),e.jsx("div",{className:"font-mono text-[12px] text-fg-0 min-w-0 break-words",children:s})]})}const Zt=x.memo(function({entry:s,expanded:n,onToggle:o,onJumpTo:a,pair:r,highlighted:l,onHoverPair:i}){const c=s.data,d=Vt(c),f=es(c.time),k=x.useCallback(()=>{r!==void 0&&i!==void 0&&i(r.toolCallId)},[r,i]),w=x.useCallback(()=>{r!==void 0&&i!==void 0&&i(null)},[r,i]);return e.jsx("div",{onMouseEnter:k,onMouseLeave:w,className:["flex items-stretch border-b border-border",l?"bg-[color-mix(in_oklab,var(--color-cat-tools)_18%,transparent)]":n?"bg-surface-1":"bg-surface-0 hover:bg-surface-1"].join(" "),children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("button",{onClick:o,className:"flex w-full items-center gap-3 px-2 py-[5px] text-left min-h-[28px]",children:[e.jsx("span",{className:"font-mono text-[11px] text-fg-3 tabular w-[52px] shrink-0 text-right",children:s.lineNo}),e.jsx("span",{className:"font-mono text-[11px] text-fg-3 tabular w-[68px] shrink-0",title:f,children:c.time!==void 0?Qe(c.time):"--:--:--"}),e.jsx("span",{className:"shrink-0",children:e.jsx(qt,{type:c.type})}),e.jsx("span",{className:"flex-1 min-w-0 flex items-center gap-2",children:d.main}),e.jsxs("span",{className:"flex items-center gap-2 shrink-0",children:[d.right,r!==void 0?e.jsx(Xt,{pair:r,onJumpTo:a}):null,e.jsx(ts,{open:n})]})]}),n?e.jsx("div",{className:"border-t border-border bg-surface-1 px-2 pb-2 pt-1",children:e.jsx(zt,{entry:s,onJumpTo:a})}):null]})})});function Xt({pair:t,onJumpTo:s}){const n=t.kind==="call",o=n?t.resultLineNo:t.callLineNo,a=n?"→":"←",r=o===null,l=r?`${a} ?`:`${a} #${o}`,i=r?n?"no matching tool.result yet":"no preceding tool.call seen":n?`jump to tool.result on line ${o}`:`jump to tool.call on line ${o}`,c=`font-mono text-[10px] tabular ${r?"text-[var(--color-sev-error)]":"text-[var(--color-cat-tools)] hover:text-fg-0"}`;return r||o===null||s===void 0?e.jsx("span",{className:c,title:i,children:l}):e.jsx("span",{role:"link",tabIndex:0,className:`${c} cursor-pointer`,title:i,onClick:d=>{d.stopPropagation(),s(o)},onKeyDown:d=>{d.key==="Enter"&&(d.stopPropagation(),s(o))},children:l})}function es(t){if(t===void 0||!Number.isFinite(t))return"missing time";const s=new Date(t);return Number.isFinite(s.getTime())?s.toISOString():"invalid time"}function ts({open:t}){return e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",className:`text-fg-3 transition-transform ${t?"rotate-90":""}`,"aria-hidden":"true",children:e.jsx("path",{d:"M3 2 L7 5 L3 8",stroke:"currentColor",strokeWidth:"1",fill:"none"})})}function ss(t){const s=new Map,n=o=>{const a=s.get(o);if(a)return a;const r={callLineNo:null,resultLineNo:null};return s.set(o,r),r};for(const o of t){if(o.data.type!=="context.append_loop_event")continue;const a=o.data.event;a.type==="tool.call"?n(a.toolCallId).callLineNo=o.lineNo:a.type==="tool.result"&&(n(a.toolCallId).resultLineNo=o.lineNo)}return s}function ns(t,s){if(t.type!=="context.append_loop_event")return;const n=t.event;if(n.type!=="tool.call"&&n.type!=="tool.result")return;const o=s.get(n.toolCallId);if(o!==void 0)return{toolCallId:n.toolCallId,kind:n.type==="tool.call"?"call":"result",callLineNo:o.callLineNo,resultLineNo:o.resultLineNo}}function Se({sessionId:t,initialAgentId:s="main"}){const[n,o]=x.useState(s);x.useEffect(()=>{o(s)},[t,s]);const{data:a}=z(t),{data:r,isLoading:l,error:i}=Tt(t,n),c=x.useRef(null),[d,f]=x.useState(""),[k,w]=x.useState(new Set),[g,q]=x.useState(!1),[K,j]=x.useState(null),p=x.useMemo(()=>r?.records??[],[r?.records]),h=r?.warnings??[],S=x.useMemo(()=>ss(p),[p]),U=x.useMemo(()=>{const u=new Map;for(const b of p){const y=ns(b.data,S);y!==void 0&&u.set(b.lineNo,y)}return u},[p,S]),Y=x.useCallback(u=>{j(u)},[]),I=x.useMemo(()=>{if(d.length===0)return p;const u=d.toLowerCase();return p.filter(b=>{if(b.data.type.toLowerCase().includes(u))return!0;try{return JSON.stringify(b.data).toLowerCase().includes(u)}catch{return!1}})},[p,d]),P=x.useMemo(()=>Lt(p,h),[p,h]),A=Pt(P),M=Me({count:I.length,getScrollElement:()=>c.current,estimateSize:()=>28,overscan:10,getItemKey:u=>I[u]?.lineNo??u}),Ie=x.useCallback(u=>{w(b=>{const y=new Set(b);return y.has(u)?y.delete(u):y.add(u),y})},[]),Q=x.useMemo(()=>{const u=new Map;for(let b=0;b<I.length;b+=1){const y=I[b];y!==void 0&&u.set(y.lineNo,b)}return u},[I]),ne=x.useCallback(u=>{const b=Q.get(u);b!==void 0&&(M.scrollToIndex(b,{align:"center"}),w(y=>y.has(u)?y:new Set(y).add(u)))},[Q,M]),Ee=()=>{w(new Set(I.map(u=>u.lineNo)))},Oe=()=>{w(new Set)},re=a?.agents??[];return e.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-3 border-b border-border bg-surface-1 px-3 py-2",children:[e.jsxs("label",{className:"flex items-center gap-2 font-mono text-[11px] text-fg-2",children:[e.jsx("span",{className:"text-fg-3",children:"agent"}),e.jsxs("select",{value:n,onChange:u=>{o(u.target.value)},className:"border border-border bg-surface-0 px-2 py-1 font-mono text-[12px] text-fg-0 focus:border-border-strong focus:outline-none",children:[re.length===0?e.jsx("option",{value:n,children:n}):null,re.map(u=>e.jsxs("option",{value:u.agentId,children:[u.agentId," (",u.type,u.parentAgentId?` ← ${u.parentAgentId}`:"",")"]},u.agentId))]})]}),e.jsx("input",{type:"text",placeholder:"search records (substring)",value:d,onChange:u=>{f(u.target.value)},className:"w-80 border border-border bg-surface-0 px-2 py-1 font-mono text-[12px] text-fg-0 placeholder:text-fg-3 focus:border-border-strong focus:outline-none"}),e.jsxs("div",{className:"ml-auto flex items-center gap-3 font-mono text-[11px] text-fg-2",children:[e.jsxs("span",{className:"tabular",children:[I.length," / ",p.length," ev"]}),P.length>0&&A!==null?e.jsxs("button",{onClick:()=>{q(!0)},title:`${P.length} issue${P.length>1?"s":""} — click to inspect`,className:"flex items-center gap-1 border px-2 py-0.5",style:{borderColor:`var(--color-sev-${A})`,color:`var(--color-sev-${A})`,backgroundColor:`color-mix(in oklab, var(--color-sev-${A}) 10%, transparent)`},children:[e.jsx("span",{children:A==="error"||A==="warning"?"⚠":"ℹ"}),e.jsx("span",{className:"tabular",children:P.length})]}):null,e.jsx("button",{onClick:Ee,className:"border border-border px-2 py-0.5 text-fg-2 hover:border-border-strong hover:text-fg-0",children:"expand all"}),e.jsx("button",{onClick:Oe,className:"border border-border px-2 py-0.5 text-fg-2 hover:border-border-strong hover:text-fg-0",children:"collapse"})]})]}),h.length>0?e.jsxs("div",{className:"shrink-0 border-b border-[var(--color-sev-warning)] bg-[color-mix(in_oklab,var(--color-sev-warning)_8%,transparent)] px-3 py-1 font-mono text-[11px] text-[var(--color-sev-warning)]",children:[h.length," warning",h.length>1?"s":""," · first: ",h[0]]}):null,l?e.jsx("div",{className:"p-6 font-mono text-[12px] text-fg-3",children:"loading wire…"}):i?e.jsx("div",{className:"p-6 font-mono text-[12px] text-[var(--color-sev-error)]",children:i.message}):e.jsx("div",{ref:c,className:"min-h-0 flex-1 overflow-y-auto",children:I.length===0?e.jsx("div",{className:"p-6 font-mono text-[12px] text-fg-3",children:"no records match the current filter"}):e.jsx("div",{style:{height:M.getTotalSize(),position:"relative"},children:M.getVirtualItems().map(u=>{const b=I[u.index];if(!b)return null;const y=U.get(b.lineNo),Te=y!==void 0&&K===y.toolCallId;return e.jsx("div",{"data-index":u.index,ref:M.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${u.start}px)`},children:e.jsx(Zt,{entry:b,expanded:k.has(b.lineNo),onToggle:()=>{Ie(b.lineNo)},onJumpTo:ne,pair:y,highlighted:Te,onHoverPair:Y})},u.key)})})}),g?e.jsx(Mt,{issues:P,onClose:()=>{q(!1)},onJumpTo:ne,isLineVisible:u=>Q.has(u)}):null]})}function rs(){const{sessionId:t}=F(),s=ye("wire"),{data:n,isLoading:o,error:a}=z(t);if(!t)return e.jsx("div",{className:"p-6 text-fg-3",children:"(no session id)"});if(o)return e.jsx("div",{className:"p-6 font-mono text-[12px] text-fg-3",children:"loading session…"});if(a)return e.jsx("div",{className:"p-6 font-mono text-[12px] text-[var(--color-sev-error)]",children:a.message});if(!n)return null;const r=n.state??null,l=n.agents.find(d=>d.agentId==="main")??null,i=n.agents.filter(d=>d.agentId!=="main").length,c=l?.wireRecordCount??null;return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"shrink-0 border-b border-border bg-surface-1 px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"font-mono text-[14px] text-fg-0",children:n.sessionId}),e.jsx(T,{value:n.sessionId}),r?.title?e.jsxs("span",{className:"font-mono text-[12px] text-fg-1",children:['"',r.title,'"']}):null,e.jsxs("span",{className:"ml-auto flex items-center gap-2",children:[e.jsx(os,{sessionId:t}),e.jsx(T,{value:n.sessionDir,label:"copy path"})]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-3 font-mono text-[11px] text-fg-2",children:[r?.updatedAt?e.jsxs("span",{className:"text-fg-3 tabular",children:["updated ",te(Date.parse(r.updatedAt))," ·"," ",ge(Date.parse(r.updatedAt))]}):null,n.workDir?e.jsxs("span",{className:"text-fg-3 truncate",title:n.workDir,children:["· ",n.workDir]}):null]}),e.jsx("div",{className:"mt-1 truncate font-mono text-[10px] text-fg-3",title:n.sessionDir,children:n.sessionDir}),r?.lastPrompt?e.jsxs("div",{className:"mt-1 truncate font-mono text-[11px] text-fg-3",title:r.lastPrompt,children:["prompt · ",r.lastPrompt]}):null]}),e.jsx(we,{defaultTab:"wire",tabs:[{id:"wire",label:"Wire",count:c},{id:"context",label:"Context",count:null},{id:"agents",label:"Agents",count:i},{id:"state",label:"State",count:null}]}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[s==="wire"?e.jsx(Se,{sessionId:t}):null,s==="context"?e.jsx(Ne,{sessionId:t}):null,s==="agents"?e.jsx(Ot,{sessionId:t}):null,s==="state"?e.jsx(St,{state:n.state}):null]})]})}function os({sessionId:t}){const[s,n]=x.useState("idle"),[o,a]=x.useState(null);return e.jsx("button",{type:"button",onClick:()=>{n("opening"),a(null),L.revealSession(t).then(()=>{n("idle")}).catch(r=>{n("err"),a(r instanceof Error?r.message:String(r)),setTimeout(()=>{n("idle"),a(null)},2500)})},className:`border border-border px-2 py-0.5 font-mono text-[11px] ${s==="err"?"text-[var(--color-sev-error)]":"text-fg-2 hover:border-border-strong hover:text-fg-0"}`,title:s==="err"&&o?o:"reveal session folder in OS file manager",children:s==="opening"?"opening…":s==="err"?"✗ failed":"↗ open folder"})}function as(){const{data:t}=he(),s=t?.length??0;return e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxs("div",{className:"max-w-md px-8 text-center",children:[e.jsx("div",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-3",children:"byf vis"}),e.jsx("div",{className:"mt-3 font-mono text-[13px] text-fg-1",children:"select a session from the left rail to begin inspecting"}),e.jsx("div",{className:"mt-6 flex items-center justify-center gap-6 font-mono text-[11px] text-fg-2",children:e.jsxs("div",{children:[e.jsx("div",{className:"tabular text-[22px] text-fg-0",children:s}),e.jsx("div",{className:"text-fg-3",children:"sessions"})]})}),e.jsxs("div",{className:"mt-10 space-y-1 text-left font-mono text-[10.5px] text-fg-3",children:[e.jsxs("div",{children:[e.jsx("kbd",{className:"mr-2 border border-border px-1 text-fg-2",children:"/"}),"focus search"]}),e.jsxs("div",{children:[e.jsx("kbd",{className:"mr-2 border border-border px-1 text-fg-2",children:"esc"}),"close drawers"]})]})]})})}const ls={main:"conversation",sub:"subagent",independent:"tools"};function is(){const{sessionId:t,agentId:s}=F(),n=ye("wire"),{data:o,isLoading:a,error:r}=z(t);if(!t||!s)return null;if(a)return e.jsx("div",{className:"p-6 font-mono text-[12px] text-fg-3",children:"loading agent…"});if(r)return e.jsx("div",{className:"p-6 font-mono text-[12px] text-[var(--color-sev-error)]",children:r.message});if(!o)return null;const l=o.agents.find(i=>i.agentId===s)??null;return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"shrink-0 border-b border-border bg-surface-1 px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2 font-mono text-[11px] text-fg-2",children:[e.jsx(R,{to:`/sessions/${t}?tab=agents`,className:"hover:text-fg-0",children:"‹ back to agents"}),e.jsx("span",{className:"text-fg-3",children:"·"}),e.jsx(R,{to:`/sessions/${t}`,className:"hover:text-fg-0",children:"session"}),e.jsx("span",{className:"text-fg-3",children:"›"}),e.jsx("span",{className:"text-fg-0",children:s})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-3",children:[e.jsx("span",{className:"font-mono text-[14px] text-fg-0",children:s}),l!==null?e.jsxs(e.Fragment,{children:[e.jsx(m,{tone:ls[l.type],variant:"soft",children:l.type}),l.parentAgentId!==null?e.jsxs("span",{className:"font-mono text-[11px] text-fg-3",children:["parent ·"," ",e.jsx(R,{to:`/sessions/${t}/agents/${l.parentAgentId}`,className:"text-fg-1 hover:text-fg-0",children:l.parentAgentId})]}):null,e.jsxs("span",{className:"font-mono text-[11px] text-fg-3 tabular",children:[l.wireRecordCount," record",l.wireRecordCount===1?"":"s",l.wireProtocolVersion!==null?` · v${l.wireProtocolVersion}`:""]}),l.wireExists?null:e.jsx(m,{tone:"warning",variant:"outline",children:"no wire"})]}):e.jsx(m,{tone:"error",variant:"outline",children:"agent not found"})]})]}),e.jsx(we,{defaultTab:"wire",tabs:[{id:"wire",label:"Wire",count:l?.wireRecordCount??null},{id:"context",label:"Context",count:null}]}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[n==="wire"?l===null||!l.wireExists?e.jsx(pe,{children:"no wire records for this agent"}):e.jsx(Se,{sessionId:t,initialAgentId:s}):null,n==="context"?l===null||!l.wireExists?e.jsx(pe,{children:"no context for this agent"}):e.jsx(Ne,{sessionId:t,initialAgentId:s}):null]})]})}function pe({children:t}){return e.jsx("div",{className:"flex flex-1 items-center justify-center p-6 font-mono text-[12px] text-fg-3",children:t})}function cs(){return e.jsx(rt,{children:e.jsxs(Pe,{children:[e.jsx(G,{path:"/",element:e.jsx(as,{})}),e.jsx(G,{path:"/sessions/:sessionId",element:e.jsx(rs,{})}),e.jsx(G,{path:"/sessions/:sessionId/agents/:agentId",element:e.jsx(is,{})})]})})}const ds=new Be({defaultOptions:{queries:{staleTime:1/0,gcTime:1800*1e3,retry:!1,refetchOnWindowFocus:!1}}}),$e=document.querySelector("#root");if(!$e)throw new Error("#root not found");Ae.createRoot($e).render(e.jsx(x.StrictMode,{children:e.jsx(Fe,{client:ds,children:e.jsx(De,{children:e.jsx(cs,{})})})}));
|