@tencent-ai/agent-sdk 0.3.245-dev.cd0b453.202608251505 → 0.3.246
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/cli/CHANGELOG.md +33 -0
- package/cli/dist/codebuddy-headless.js +228 -293
- package/cli/dist/web-ui/assets/{CanvasPaneStandaloneView-Cmwt9Y8a.js → CanvasPaneStandaloneView-BD_qZwpK.js} +1 -1
- package/cli/dist/web-ui/assets/{CanvasView-kh-VwNZt.js → CanvasView-BAUxFLH1.js} +1 -1
- package/cli/dist/web-ui/assets/{ChangesView-LyTT64_e.js → ChangesView-Bvr-6a62.js} +1 -1
- package/cli/dist/web-ui/assets/{DocsView-DzT0XXMI.js → DocsView-BVidmMmQ.js} +1 -1
- package/cli/dist/web-ui/assets/EditorView-BWnNeB5q.js +75 -0
- package/cli/dist/web-ui/assets/{FileIcon-CiviXX19.js → FileIcon-BsViq6H0.js} +1 -1
- package/cli/dist/web-ui/assets/{KeybindingsView-CYLH1DTg.js → KeybindingsView-QuWWE_H3.js} +1 -1
- package/cli/dist/web-ui/assets/{LogsView-RDobPjF6.js → LogsView-DUMNTy8H.js} +3 -3
- package/cli/dist/web-ui/assets/{MetricsView-0TBamh3L.js → MetricsView-BY2YOvXi.js} +3 -3
- package/cli/dist/web-ui/assets/{PluginsView-CzAIf5_-.js → PluginsView-BzgBeIFp.js} +2 -2
- package/cli/dist/web-ui/assets/{RemoteControlView-CNsCKFhh.js → RemoteControlView-BuKYLVCs.js} +1 -1
- package/cli/dist/web-ui/assets/{SettingsView-B2RLsYo0.js → SettingsView-Bu_9EZ8x.js} +2 -2
- package/cli/dist/web-ui/assets/{SplitContainer-CJB8eH3c.js → SplitContainer-C2WbFxdL.js} +1 -1
- package/cli/dist/web-ui/assets/{StatsView-wHMAAyEJ.js → StatsView-h44ujqat.js} +2 -2
- package/cli/dist/web-ui/assets/{TasksView-DOFeNXmC.js → TasksView-D2q4JOBP.js} +2 -2
- package/cli/dist/web-ui/assets/{TerminalPaneView-BXNcwxsi.js → TerminalPaneView-lhajvnaH.js} +3 -3
- package/cli/dist/web-ui/assets/{TracesView-BtPCpydR.js → TracesView-B5i4emxN.js} +3 -3
- package/cli/dist/web-ui/assets/{WorkersView-sQMhvJ2l.js → WorkersView-Bw2bTNo6.js} +2 -2
- package/cli/dist/web-ui/assets/{canvas-store-0BnkCTHk.js → canvas-store-Smrtng_e.js} +1 -1
- package/cli/dist/web-ui/assets/{cssMode-jwjmt121.js → cssMode-EsOJVYiu.js} +1 -1
- package/cli/dist/web-ui/assets/{download-iNxRYv3J.js → download-BsdRqzY7.js} +1 -1
- package/cli/dist/web-ui/assets/{editor.main-CGYuAeQx.js → editor.main-q4R8cbC1.js} +3 -3
- package/cli/dist/web-ui/assets/{external-link-D5RWsA9l.js → external-link-Ea1Nar0e.js} +1 -1
- package/cli/dist/web-ui/assets/{freemarker2-CX3QfLDV.js → freemarker2-DVmHExbB.js} +1 -1
- package/cli/dist/web-ui/assets/{handlebars-C5TLi2Pr.js → handlebars-Cguwj4ew.js} +1 -1
- package/cli/dist/web-ui/assets/{html-VGWLEWVQ.js → html-DRfZqNG-.js} +1 -1
- package/cli/dist/web-ui/assets/{htmlMode-B7yDtJr6.js → htmlMode-mn7qxh39.js} +1 -1
- package/cli/dist/web-ui/assets/index-BOvl5ICo.css +1 -0
- package/cli/dist/web-ui/assets/{index-CHcoPr8x.js → index-CBmymKHy.js} +180 -175
- package/cli/dist/web-ui/assets/{javascript-rebq-3hM.js → javascript-Dv0-Ka9H.js} +1 -1
- package/cli/dist/web-ui/assets/{jsonMode-CisSEnRa.js → jsonMode-MVrw6wSj.js} +1 -1
- package/cli/dist/web-ui/assets/{liquid-C0GU_tuJ.js → liquid-2HR35IQO.js} +1 -1
- package/cli/dist/web-ui/assets/{lspLanguageFeatures-DdEy47qR.js → lspLanguageFeatures-BA4h_1Zp.js} +1 -1
- package/cli/dist/web-ui/assets/{markdown-DIY6o85n.js → markdown-CP9awqWt.js} +1 -1
- package/cli/dist/web-ui/assets/{mdx-DjEmR07p.js → mdx-CFi7brpM.js} +1 -1
- package/cli/dist/web-ui/assets/{minus-BHON617T.js → minus-Dw9-WG76.js} +1 -1
- package/cli/dist/web-ui/assets/{power-BoeeA3TI.js → power-BJk8Xq9U.js} +1 -1
- package/cli/dist/web-ui/assets/{python-YOuEQ1oe.js → python-BqoHrqNK.js} +1 -1
- package/cli/dist/web-ui/assets/{razor-DTO4iPoC.js → razor-CPnz313K.js} +1 -1
- package/cli/dist/web-ui/assets/{server-Gy9um44Z.js → server-D4446JKI.js} +1 -1
- package/cli/dist/web-ui/assets/{timer-CVn2LoSe.js → timer-D8MX3pYj.js} +1 -1
- package/cli/dist/web-ui/assets/{tsMode-J-jxLo7h.js → tsMode-DMOs1uPQ.js} +1 -1
- package/cli/dist/web-ui/assets/{typescript-BTZe1y3z.js → typescript-CP_zrnR8.js} +1 -1
- package/cli/dist/web-ui/assets/{vendor-D35k0Cos.js → vendor-iLJwFVtf.js} +1 -1
- package/cli/dist/web-ui/assets/{worker-store-CsMfXxjm.js → worker-store-qfd_N8Zm.js} +1 -1
- package/cli/dist/web-ui/assets/{xml-DaZe33xf.js → xml-BNASinsS.js} +1 -1
- package/cli/dist/web-ui/assets/{yaml-yofIoqGl.js → yaml-D_cB1VDT.js} +1 -1
- package/cli/dist/web-ui/assets/{zap-BeZalqcf.js → zap-yafQUspl.js} +1 -1
- package/cli/dist/web-ui/index.html +4 -4
- package/cli/dist/web-ui/sw.js +1 -1
- package/cli/package.json +2 -3
- package/cli/product.cloudhosted.json +4 -2
- package/cli/product.internal.json +4 -2
- package/cli/product.ioa.json +4 -2
- package/cli/product.json +383 -17
- package/cli/product.selfhosted.json +4 -2
- package/cli/vendor/shim/sitecustomize.py +43 -1
- package/package.json +2 -3
- package/cli/dist/web-ui/assets/EditorView-ZUnDw1V1.js +0 -75
- package/cli/dist/web-ui/assets/index-Ddq_addW.css +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as e,a as f}from"./markdown-
|
|
1
|
+
import{j as e,a as f}from"./markdown-CP9awqWt.js";import{c as oe,e as Ee,U as ce,h as ie,bj as xe,Y as Ae,b1 as ze,bk as Le,u as _,q as Ce,r as Re,aM as te,X as Xe,C as Ye,a1 as _e,t as Fe,j as ue,n as Te,aX as Oe,ab as ge,aO as Pe,A as We}from"./index-CBmymKHy.js";import{u as He}from"./worker-store-qfd_N8Zm.js";import{S as Be}from"./SplitContainer-C2WbFxdL.js";import{Z as ye}from"./zap-yafQUspl.js";import{o as qe,a as Ve}from"./one-light-daQKygYj.js";import"./vendor-iLJwFVtf.js";/**
|
|
2
2
|
* @license lucide-react v1.18.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -18,5 +18,5 @@ import{j as e,a as f}from"./markdown-DIY6o85n.js";import{c as oe,e as Ee,U as ce
|
|
|
18
18
|
*
|
|
19
19
|
* This source code is licensed under the ISC license.
|
|
20
20
|
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
-
*/const et=[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]],Ie=oe("network",et),tt=Ee((t,n)=>({traces:[],total:0,loading:!1,error:null,selectedTraceId:null,traceDetail:null,detailLoading:!1,selectedSpanId:null,workerPid:null,filterSessionId:null,statusFilter:"all",fetchTraces:async()=>{t({loading:!0,error:null});try{const{workerPid:s,filterSessionId:u,statusFilter:o}=n(),a=new URLSearchParams;a.set("limit","100"),s&&a.set("worker_pid",s),u&&a.set("session_id",u),o!=="all"&&a.set("status",o);const i=await ce(`/api/v1/traces?${a}`,{headers:ie()});if(!i.ok)throw new Error(`HTTP ${i.status}`);const c=(await i.json()).data||{};t({traces:c.traces||[],total:c.total||0,loading:!1})}catch(s){t({error:s.message,loading:!1})}},fetchTraceDetail:async s=>{t({detailLoading:!0,selectedTraceId:s,selectedSpanId:null});try{const{workerPid:u}=n(),o=new URLSearchParams;u&&o.set("worker_pid",u);const a=o.toString()?`?${o}`:"",i=await ce(`/api/v1/traces/${s}${a}`,{headers:ie()});if(!i.ok)throw new Error(`HTTP ${i.status}`);const p=await i.json();t({traceDetail:p.data||null,detailLoading:!1})}catch{t({traceDetail:null,detailLoading:!1})}},selectTrace:s=>{s===n().selectedTraceId?t({selectedTraceId:null,traceDetail:null,selectedSpanId:null}):s?n().fetchTraceDetail(s):t({selectedTraceId:null,traceDetail:null,selectedSpanId:null})},selectSpan:s=>t({selectedSpanId:s}),setWorkerPid:s=>{t({workerPid:s,selectedTraceId:null,traceDetail:null,selectedSpanId:null}),n().fetchTraces()},setFilterSessionId:s=>{t({filterSessionId:s,selectedTraceId:null,traceDetail:null,selectedSpanId:null}),n().fetchTraces()},setStatusFilter:s=>{t({statusFilter:s,selectedTraceId:null,traceDetail:null,selectedSpanId:null}),n().fetchTraces()},clearTraces:async()=>{try{const{workerPid:s}=n(),u=new URLSearchParams;s&&u.set("worker_pid",s);const o=u.toString()?`?${u}`:"";await ce(`/api/v1/traces${o}`,{method:"DELETE",headers:ie()}),t({traces:[],total:0,selectedTraceId:null,traceDetail:null,selectedSpanId:null})}catch{}}})),F={agent:{light:"#3b82f6",dark:"#60a5fa"},generation:{light:"#8b5cf6",dark:"#a78bfa"},function:{light:"#10b981",dark:"#34d399"},tool:{light:"#10b981",dark:"#34d399"},handoff:{light:"#f59e0b",dark:"#fbbf24"},guardrail:{light:"#f97316",dark:"#fb923c"},response:{light:"#6366f1",dark:"#818cf8"},custom:{light:"#6b7280",dark:"#9ca3af"}},$e={agent:Le,generation:ze,function:ye,tool:ye,handoff:Ae,guardrail:Qe,response:Ie,custom:xe};function st({workers:t,selectedPid:n,onSelect:s}){var c;const{t:u}=
|
|
22
|
-
`):t&&typeof t=="object"?JSON.stringify(t,null,2):String(t??"")}function be({label:t,content:n}){const[s,u]=f.useState(!1),o=f.useRef(null),[a,i]=f.useState(!1),p=Ce(h=>h.resolved),{t:c}=X();f.useEffect(()=>{const h=o.current;h&&i(h.scrollHeight>at)},[n]);const g=f.useMemo(()=>{const h=n.trim();if(h.startsWith("{")&&h.endsWith("}")||h.startsWith("[")&&h.endsWith("]"))try{const M=JSON.parse(h);return lt(M)?{type:"messages",messages:M}:{type:"json",formatted:JSON.stringify(M,null,2)}}catch{return{type:"text"}}return{type:"text"}},[n]),b=g.type==="messages"?c("traces.io.messages"):g.type==="json"?"JSON":null;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-text-tertiary",children:t}),b&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-blue/10 text-accent-blue",children:b}),a&&e.jsx("button",{onClick:()=>u(!s),className:"ml-auto flex items-center gap-0.5 text-[10px] text-text-tertiary hover:text-text-primary",children:s?e.jsxs(e.Fragment,{children:[e.jsx(Je,{size:10})," ",c("traces.io.collapse")]}):e.jsxs(e.Fragment,{children:[e.jsx(Ke,{size:10})," ",c("traces.io.expand")]})})]}),e.jsx("div",{ref:o,className:`rounded bg-bg-secondary overflow-auto ${s?"max-h-[80vh]":"max-h-40"}`,style:{transition:"max-height 0.2s ease"},children:g.type==="messages"?e.jsx(it,{messages:g.messages}):g.type==="json"?e.jsx("div",{className:"select-none [&_pre]:!bg-transparent [&_code]:!bg-transparent [&_span]:!bg-transparent",children:e.jsx(rt,{language:"json",style:p==="dark"?qe:Ve,customStyle:{margin:0,padding:"8px",background:"transparent",fontSize:"11px",lineHeight:"1.4"},wrapLongLines:!0,children:g.formatted})}):e.jsx("pre",{className:"p-2 text-text-primary font-mono text-xs whitespace-pre-wrap break-all",children:n})})]})}function it({messages:t}){return e.jsx("div",{className:"divide-y divide-border-default",children:t.map((n,s)=>e.jsx(dt,{role:n.role,content:n.content},s))})}function dt({role:t,content:n}){const[s,u]=f.useState(!1),{t:o}=X(),a=ct(n),i=a.length>300,p=i&&!s?a.slice(0,300)+"...":a,c=ot[t]||"bg-gray-500/15 text-gray-400";return e.jsxs("div",{className:"px-2 py-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-0.5",children:[e.jsx("span",{className:`text-[10px] px-1 py-px rounded font-medium ${c}`,children:t}),i&&e.jsx("button",{onClick:()=>u(!s),className:"text-[10px] text-text-tertiary hover:text-text-primary",children:s?o("traces.io.less"):o("traces.io.moreChars",{count:a.length-300})})]}),e.jsx("pre",{className:"text-text-primary font-mono text-[11px] whitespace-pre-wrap break-all leading-relaxed",children:p})]})}function le(t){const n=new Map,s=[];for(const a of t)n.set(a.spanId,{span:a,children:[],depth:0});for(const a of n.values())if(a.span.parentId&&a.span.parentId!==a.span.spanId&&n.has(a.span.parentId)){const i=n.get(a.span.parentId);i.children.push(a),a.depth=i.depth+1}else s.push(a);const u=new Set,o=[...s];for(;o.length;){const a=o.shift();if(!u.has(a.span.spanId)){u.add(a.span.spanId);for(const i of a.children)i.depth=a.depth+1,o.push(i)}}return s.length===0&&t.length>0?t.map(a=>({span:a,children:[],depth:0})):s}function pe(t,n){const s=[],u=new Set;function o(a){for(const i of a)u.has(i.span.spanId)||(u.add(i.span.spanId),s.push({span:i.span,depth:i.depth}),n!=null&&n.has(i.span.spanId)||o(i.children))}return o(t),s}function je(t,n){return n.some(s=>s.parentId===t)}function xt(t){var g;let n=0,s=0,u=0;const o=new Set;let a=0,i=0,p=0;for(const b of t)b.status==="error"&&p++,(b.type==="generation"||b.type==="response")&&(i++,n+=b.inputTokens||0,s+=b.outputTokens||0,b.model&&o.add(b.model),(g=b.attributes)!=null&&g.cached_tokens&&(u+=Number(b.attributes.cached_tokens)||0)),(b.type==="function"||b.type==="tool")&&a++;const c=n>0?u/n*100:0;return{totalInputTokens:n,totalOutputTokens:s,cacheHitRate:c,models:Array.from(o),toolCount:a,generationCount:i,errorCount:p}}function Me(t){return t==="error"?"red":t==="running"?"yellow":t==="cancelled"?"grey":"green"}function ut(t){return t==="error"?"accent-red":t==="running"?"accent-yellow":t==="cancelled"?"text-tertiary":"accent-green"}function De(t){return t==="error"?"traces.status.error":t==="running"?"traces.status.running":t==="cancelled"?"traces.status.cancelled":"traces.status.ok"}function P(t){return t<1?"<1ms":t<1e3?`${Math.round(t)}ms`:t<6e4?`${(t/1e3).toFixed(1)}s`:`${Math.floor(t/6e4)}m${(t%6e4/1e3).toFixed(0)}s`}function ae(t){return t>=1e6?`${(t/1e6).toFixed(1)}M tok`:t>=1e3?`${(t/1e3).toFixed(1)}k tok`:`${t} tok`}function pt(t){try{return new Date(t).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit"})}catch{return""}}function ht({summary:t,onJump:n}){const{t:s}=X(),[u,o]=f.useState(!0),a=t.groups,i=u?a:a.slice(0,3);return e.jsxs("div",{className:"mt-2 px-3 py-2 rounded-md border border-accent-red/30 bg-accent-red/[0.04]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{size:13,className:"text-accent-red shrink-0"}),e.jsx("span",{className:"text-xs font-medium text-accent-red",children:s("traces.errorSummaryTitle").replace("{count}",String(t.totalErrors))}),e.jsx("span",{className:"flex-1"}),a.length>3&&e.jsx("button",{onClick:()=>o(p=>!p),className:"text-[11px] text-accent-red opacity-80 hover:opacity-100",children:s(u?"traces.io.less":"traces.io.expand")})]}),e.jsx("div",{className:"mt-1.5 space-y-1",children:i.map(p=>e.jsxs("button",{onClick:()=>n(p.spanId),className:"w-full flex items-start gap-2 text-left px-2 py-1 rounded hover:bg-accent-red/10 transition-colors",title:s("traces.jumpToFirstError"),children:[e.jsxs("span",{className:"shrink-0 text-[10px] px-1 py-0 rounded bg-accent-red/15 text-accent-red font-mono",children:["×",p.count]}),e.jsx("span",{className:"shrink-0 text-xs text-accent-red font-medium truncate max-w-[140px]",children:p.where}),e.jsx("span",{className:"text-xs text-text-secondary font-mono truncate flex-1 min-w-0",children:p.sampleMessage})]},p.spanId))})]})}function ve({detail:t,selectedSpanId:n,onSelectSpan:s,theme:u}){const{t:o}=X(),a=u==="dark",i=f.useMemo(()=>pe(le(t.spans)),[t.spans]),{minTime:p,totalRange:c}=f.useMemo(()=>{const E=t.spans.map($=>new Date($.startedAt).getTime()),S=t.spans.filter($=>$.endedAt).map($=>new Date($.endedAt).getTime()),I=Math.min(...E),A=S.length?Math.max(...S):I+1e3;return{minTime:I,totalRange:A-I||1}},[t.spans]);if(!i.length)return e.jsx("div",{className:"text-sm text-text-tertiary py-8 text-center",children:o("traces.noSpans")});const g=Math.max(...i.map(E=>E.depth))+1,b=24,h=1,M=800,D=g*(b+h);return e.jsx("svg",{width:"100%",viewBox:`0 0 ${M} ${D}`,className:"block",style:{maxWidth:M},children:i.map(E=>{const S=E.span,I=new Date(S.startedAt).getTime(),A=S.endedAt?new Date(S.endedAt).getTime():I+c,$=(I-p)/c*M,z=Math.max((A-I)/c*M,1),L=E.depth*(b+h),d=F[S.type]||F.custom,k=a?d.dark:d.light,N=n===S.spanId;return e.jsxs("g",{onClick:()=>s(N?null:S.spanId),style:{cursor:"pointer"},children:[e.jsx("rect",{x:$,y:L,width:z,height:b,fill:k,rx:2,opacity:N?1:.8,stroke:N?a?"#60a5fa":"#3b82f6":"none",strokeWidth:N?1.5:0}),z>40&&e.jsx("text",{x:$+4,y:L+b/2,dominantBaseline:"central",fontSize:10,fill:"#fff",fontFamily:"monospace",children:S.name.length>z/6?S.name.slice(0,Math.floor(z/6)-1)+"…":S.name}),e.jsxs("title",{children:[S.name," — ",S.duration!=null?P(S.duration):"running",S.model?` (${S.model})`:""]})]},S.spanId)})})}function ke({detail:t,selectedSpanId:n,onSelectSpan:s,theme:u}){const{t:o}=X(),a=u==="dark",i=f.useRef(null),{groupNodes:p,groupEdges:c}=f.useMemo(()=>{const r=new Map,y=pe(le(t.spans));for(const v of y){const l=v.span,x=`${l.parentId||"root"}::${l.type}::${l.name.split("(")[0].trim()}`,C=r.get(x);C?(C.count++,C.totalDuration+=l.duration||0,C.totalTokens+=(l.inputTokens||0)+(l.outputTokens||0),l.status==="error"&&(C.hasError=!0)):r.set(x,{id:x,type:l.type,name:l.name.split("(")[0].trim(),count:1,totalDuration:l.duration||0,totalTokens:(l.inputTokens||0)+(l.outputTokens||0),hasError:l.status==="error",parentId:l.parentId,depth:v.depth,representativeSpanId:l.spanId})}const w=Array.from(r.values()),m=[];for(const v of w)if(v.parentId){const l=t.spans.find(x=>x.spanId===v.parentId);if(l){const x=`${l.parentId||"root"}::${l.type}::${l.name.split("(")[0].trim()}`;r.has(x)&&x!==v.id&&m.push({from:x,to:v.id})}}const T=new Set(m.map(v=>`${v.from}\0${v.to}`));return{groupNodes:w,groupEdges:Array.from(T).map(v=>{const[l,x]=v.split("\0");return{from:l,to:x}})}},[t.spans]),g=180,b=60,h=70,M=28,{positions:D,svgW:E,svgH:S}=f.useMemo(()=>{const r=new Map;for(const l of p)r.has(l.depth)||r.set(l.depth,[]),r.get(l.depth).push(l);const y=Array.from(r.entries()).sort((l,x)=>l[0]-x[0]),w=Math.max(1,...y.map(([,l])=>l.length)),m=Math.max(w*(g+M)+M,400),T=y.length*(b+h)+20,v=new Map;for(const[l,x]of y){const C=x.length*g+(x.length-1)*M,_=(m-C)/2;x.forEach((H,se)=>v.set(H.id,{x:_+se*(g+M),y:l*(b+h)+10}))}return{positions:v,svgW:m,svgH:T}},[p,g,b,h,M]),[I,A]=f.useState({zoom:1,panX:0,panY:0}),[$,z]=f.useState(!1),L=f.useRef({x:0,y:0,panX:0,panY:0}),d=f.useCallback(()=>{const r=i.current;if(!r||E<=0||S<=0)return;const y=r.clientWidth,w=r.clientHeight;if(y<=0||w<=0)return;const m=Math.min(y/E,w/S,1.5)*.9;A({zoom:m,panX:(y-E*m)/2,panY:(w-S*m)/2})},[E,S]);f.useEffect(()=>{d()},[d,p.length]),f.useEffect(()=>{const r=i.current;if(!r)return;const y=w=>{w.preventDefault();const m=r.getBoundingClientRect(),T=w.clientX-m.left,v=w.clientY-m.top,l=w.deltaY<0?1.06:.94;A(x=>{const C=Math.max(.1,Math.min(5,x.zoom*l));return{zoom:C,panX:T-(T-x.panX)*(C/x.zoom),panY:v-(v-x.panY)*(C/x.zoom)}})};return r.addEventListener("wheel",y,{passive:!1}),()=>r.removeEventListener("wheel",y)},[]);const k=f.useRef(null),N=f.useCallback(r=>{if(r.touches.length===2){const y=r.touches[0].clientX-r.touches[1].clientX,w=r.touches[0].clientY-r.touches[1].clientY;k.current={dist:Math.hypot(y,w),cx:(r.touches[0].clientX+r.touches[1].clientX)/2,cy:(r.touches[0].clientY+r.touches[1].clientY)/2}}else r.touches.length===1&&(z(!0),L.current={x:r.touches[0].clientX,y:r.touches[0].clientY,panX:I.panX,panY:I.panY})},[I.panX,I.panY]),R=f.useCallback(r=>{if(r.touches.length===2&&k.current){r.preventDefault();const y=r.touches[0].clientX-r.touches[1].clientX,w=r.touches[0].clientY-r.touches[1].clientY,m=Math.hypot(y,w),T=m/k.current.dist,v=i.current;if(v){const l=v.getBoundingClientRect(),x=k.current.cx-l.left,C=k.current.cy-l.top;A(_=>{const H=Math.max(.1,Math.min(5,_.zoom*T));return{zoom:H,panX:x-(x-_.panX)*(H/_.zoom),panY:C-(C-_.panY)*(H/_.zoom)}})}k.current.dist=m}else r.touches.length===1&&$&&A(y=>({...y,panX:L.current.panX+r.touches[0].clientX-L.current.x,panY:L.current.panY+r.touches[0].clientY-L.current.y}))},[$]),Y=f.useCallback(()=>{z(!1),k.current=null},[]),O=f.useCallback(r=>{r.button===0&&(z(!0),L.current={x:r.clientX,y:r.clientY,panX:I.panX,panY:I.panY})},[I.panX,I.panY]),V=f.useCallback(r=>{$&&A(y=>({...y,panX:L.current.panX+r.clientX-L.current.x,panY:L.current.panY+r.clientY-L.current.y}))},[$]),U=f.useCallback(()=>z(!1),[]),W=f.useMemo(()=>{if(!n)return new Set;const r=p.find(x=>x.representativeSpanId===n);if(!r)return new Set;const y=new Set([r.id]),w=new Map;for(const x of c)w.set(x.to,x.from);let m=r.id;for(;w.has(m)&&(m=w.get(m),!y.has(m));)y.add(m);const T=new Map;for(const x of c)T.has(x.from)||T.set(x.from,[]),T.get(x.from).push(x.to);const v=[r.id],l=new Set([r.id]);for(;v.length;){const x=v.shift();for(const C of T.get(x)||[])l.has(C)||(l.add(C),y.add(C),v.push(C))}return y},[n,p,c]),Z=f.useCallback((r,y)=>W.has(r)&&W.has(y),[W]);if(!p.length)return e.jsx("div",{className:"text-sm text-text-tertiary py-8 text-center",children:o("traces.noSpans")});const K=a?"#d1d5db":"#374151",J=a?"#9ca3af":"#6b7280",Q=a?"#4b5563":"#d1d5db",ee=a?"#60a5fa":"#3b82f6";return e.jsxs("div",{ref:i,className:"w-full h-full overflow-hidden relative touch-none",style:{cursor:$?"grabbing":"grab",minHeight:300},onMouseDown:O,onMouseMove:V,onMouseUp:U,onMouseLeave:U,onTouchStart:N,onTouchMove:R,onTouchEnd:Y,children:[e.jsx("button",{onClick:d,className:"absolute top-2 right-2 z-10 px-2 py-1 rounded-md bg-bg-secondary border border-border-default text-text-tertiary hover:text-text-primary text-xs",style:{cursor:"pointer"},children:o("traces.fit")}),e.jsx("svg",{width:"100%",height:"100%",style:{position:"absolute",left:0,top:0},children:e.jsxs("g",{transform:`translate(${I.panX},${I.panY}) scale(${I.zoom})`,children:[c.map((r,y)=>{const w=D.get(r.from),m=D.get(r.to);if(!w||!m)return null;const T=w.x+g/2,v=w.y+b,l=m.x+g/2,x=m.y,C=Z(r.from,r.to);return e.jsx("path",{d:`M${T},${v} C${T},${v+h/2} ${l},${x-h/2} ${l},${x}`,fill:"none",stroke:C?ee:Q,strokeWidth:C?2.5:1.5,opacity:W.size>0&&!C?.2:1},y)}),p.map(r=>{const y=D.get(r.id);if(!y)return null;const w=F[r.type]||F.custom,m=a?w.dark:w.light,T=n===r.representativeSpanId,v=W.has(r.id),l=W.size>0&&!v,x=r.count>1?`${r.name} x${r.count}`:r.name,C=P(r.totalDuration),_=r.totalTokens>0?` · ${ae(r.totalTokens)}`:"";return e.jsxs("g",{onClick:H=>{H.stopPropagation(),s(T?null:r.representativeSpanId)},style:{cursor:"pointer"},opacity:l?.25:1,children:[e.jsx("rect",{x:y.x,y:y.y,width:g,height:b,rx:8,fill:a?"#1f2937":"#fff",stroke:T?m:r.hasError?"#ef4444":v?ee:Q,strokeWidth:T?2.5:v?2:1}),e.jsx("rect",{x:y.x,y:y.y,width:6,height:b,rx:3,fill:m}),e.jsx("text",{x:y.x+16,y:y.y+24,fontSize:13,fill:K,fontWeight:r.count>1?600:500,fontFamily:"sans-serif",children:x.length>20?x.slice(0,19)+"…":x}),e.jsxs("text",{x:y.x+16,y:y.y+44,fontSize:11,fill:J,fontFamily:"monospace",children:[C,_]}),e.jsxs("title",{children:[x," — ",C,_]})]},r.id)})]})})]})}function mt({span:t,onClose:n}){const{t:s}=X(),[u,o]=f.useState("overview");if(!t)return null;const a=$e[t.type]||xe,i=t.duration;return e.jsxs("div",{className:"h-full flex flex-col border-t border-border-default bg-bg-primary overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 md:px-4 py-2 border-b border-border-default",children:[e.jsx(a,{size:14,className:"text-text-secondary shrink-0"}),e.jsx("span",{className:"font-medium text-text-primary text-sm truncate",children:t.name}),t.duration!=null&&e.jsx("span",{className:"text-xs text-text-tertiary",children:P(t.duration)}),t.status==="error"&&e.jsx(re,{color:"red",children:s("traces.status.error")}),t.status==="cancelled"&&e.jsx(re,{color:"grey",children:s("traces.status.cancelled")}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:n,className:"p-1 rounded hover:bg-bg-hover text-text-tertiary",children:e.jsx(Ye,{size:14})})]}),e.jsx("div",{className:"flex gap-1 px-4 pt-2",children:["overview","io","attrs"].map(p=>e.jsx("button",{onClick:()=>o(p),className:`px-2 py-0.5 rounded text-xs ${u===p?"bg-bg-hover text-text-primary font-medium":"text-text-tertiary hover:text-text-primary"}`,children:s(p==="overview"?"traces.spanDetail.overview":p==="io"?"traces.spanDetail.io":"traces.spanDetail.attributes")},p))}),e.jsxs("div",{className:"flex-1 overflow-auto px-3 md:px-4 py-3 text-xs",children:[u==="overview"&&e.jsxs("div",{children:[t.error&&(()=>{const c=t.status==="cancelled"?{bg:"bg-bg-hover",border:"border-border-default",text:"text-text-secondary",label:s("traces.spanDetail.cancelReason")}:{bg:"bg-accent-red/10",border:"border-accent-red/20",text:"text-accent-red",label:s("traces.spanDetail.error")};return e.jsxs("div",{className:`mb-3 px-3 py-2 rounded-md ${c.bg} border ${c.border}`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:`font-medium ${c.text}`,children:c.label}),e.jsx("span",{className:"flex-1"}),e.jsxs("button",{onClick:()=>{Xe(t.error||"")},className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] ${c.text} hover:${c.bg}`,title:s("traces.copyError"),children:[e.jsx(_e,{size:11}),s("traces.copyError")]})]}),e.jsx("pre",{className:`${c.text} font-mono whitespace-pre-wrap break-all max-h-32 overflow-auto`,children:t.error})]})})(),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(q,{label:s("traces.spanDetail.type"),value:t.type}),e.jsx(q,{label:s("traces.spanDetail.duration"),value:t.duration!=null?P(t.duration):"--"}),e.jsx(q,{label:s("traces.selfTime"),value:i!=null?P(i):"--"}),e.jsx(q,{label:"Status",value:t.status}),t.model&&e.jsx(q,{label:s("traces.spanDetail.model"),value:t.model}),(t.inputTokens!=null||t.outputTokens!=null)&&e.jsx(q,{label:s("traces.spanDetail.tokens"),value:`${t.inputTokens||0} in / ${t.outputTokens||0} out`}),t.toolName&&e.jsx(q,{label:"Tool",value:t.toolName}),t.fromAgent&&e.jsx(q,{label:"From",value:t.fromAgent}),t.toAgent&&e.jsx(q,{label:"To",value:t.toAgent})]})]}),u==="io"&&e.jsxs("div",{className:"space-y-3",children:[t.toolInput&&e.jsx(be,{label:s("traces.spanDetail.input"),content:t.toolInput}),t.toolOutput&&e.jsx(be,{label:s("traces.spanDetail.output"),content:t.toolOutput}),!t.toolInput&&!t.toolOutput&&e.jsx("div",{className:"text-text-tertiary",children:s("traces.noIO")})]}),u==="attrs"&&e.jsx("div",{className:"space-y-1",children:t.attributes&&Object.keys(t.attributes).length>0?Object.entries(t.attributes).map(([p,c])=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"shrink-0 text-text-tertiary w-32",children:p}),e.jsx("span",{className:"text-text-primary font-mono break-all",children:typeof c=="string"?c:JSON.stringify(c)})]},p)):e.jsx("div",{className:"text-text-tertiary",children:s("traces.noAttrs")})})]})]})}function ft({value:t,onChange:n}){const{t:s}=X(),u=[{key:"all",label:s("traces.filter.all"),activeClass:"bg-bg-hover text-text-primary"},{key:"error",label:s("traces.filter.error"),activeClass:"bg-accent-red/15 text-accent-red"},{key:"running",label:s("traces.filter.running"),activeClass:"bg-accent-yellow/15 text-accent-yellow"},{key:"cancelled",label:s("traces.filter.cancelled"),activeClass:"bg-bg-hover text-text-secondary"},{key:"ok",label:s("traces.filter.ok"),activeClass:"bg-accent-green/15 text-accent-green"}];return e.jsx("div",{className:"flex items-center gap-1 rounded-md border border-border-default p-0.5",children:u.map(o=>e.jsx("button",{onClick:()=>n(o.key),className:`px-2 py-0.5 rounded text-xs font-medium transition-colors ${t===o.key?o.activeClass:"text-text-tertiary hover:text-text-primary"}`,children:o.label},o.key))})}const B=28,ne=16,gt=2;function Ne({detail:t,selectedSpanId:n,onSelectSpan:s,theme:u}){const{t:o}=X(),a=u==="dark",[i,p]=f.useState(new Set),[c,g]=f.useState(""),[b,h]=f.useState(!1),M=f.useMemo(()=>le(t.spans),[t.spans]),E=f.useMemo(()=>pe(M,i),[M,i]).filter(d=>{var k;if(b&&d.span.status!=="error")return!1;if(c){const N=c.toLowerCase();return d.span.name.toLowerCase().includes(N)||((k=d.span.toolName)==null?void 0:k.toLowerCase().includes(N))}return!0}),S=d=>p(k=>{const N=new Set(k);return N.has(d)?N.delete(d):N.add(d),N}),{minTime:I,totalRange:A}=f.useMemo(()=>{const d=t.spans.map(Y=>new Date(Y.startedAt).getTime()),k=t.spans.filter(Y=>Y.endedAt).map(Y=>new Date(Y.endedAt).getTime()),N=Math.min(...d),R=k.length?Math.max(...k):N+1e3;return{minTime:N,totalRange:R-N||1}},[t.spans]),$=220,z=5,L=e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsxs("div",{className:"relative flex-1 max-w-xs",children:[e.jsx(Fe,{size:14,className:"absolute left-2 top-1/2 -translate-y-1/2 text-text-tertiary"}),e.jsx("input",{value:c,onChange:d=>g(d.target.value),placeholder:o("traces.search"),className:"w-full pl-7 pr-2 py-1 text-xs rounded-md border border-border-default bg-bg-primary text-text-primary"})]}),e.jsxs("button",{onClick:()=>h(d=>!d),className:`text-xs px-2 py-1 rounded-md border transition-colors inline-flex items-center gap-1 ${b?"border-accent-red/40 bg-accent-red/10 text-accent-red":"border-border-default text-text-tertiary hover:text-text-primary"}`,title:o("traces.onlyErrors"),children:[e.jsx(te,{size:12}),o("traces.onlyErrors")]}),e.jsx("button",{onClick:()=>p(new Set),className:"text-xs text-text-tertiary hover:text-text-primary",children:o("traces.expandAll")}),e.jsx("button",{onClick:()=>p(new Set(t.spans.filter(d=>je(d.spanId,t.spans)).map(d=>d.spanId))),className:"text-xs text-text-tertiary hover:text-text-primary",children:o("traces.collapseAll")})]});if(!E.length){const d=b||!!c;return e.jsxs("div",{children:[L,e.jsxs("div",{className:"text-sm text-text-tertiary py-8 text-center",children:[o(d?"traces.noSpansFiltered":"traces.noSpans"),d&&e.jsx("button",{onClick:()=>{h(!1),g("")},className:"ml-2 text-accent-brand hover:underline",children:o("traces.clearFilter")})]})]})}return e.jsxs("div",{children:[L,e.jsxs("div",{className:"flex overflow-x-auto",children:[e.jsx("div",{className:"shrink-0",style:{width:$},children:E.map(d=>{const k=je(d.span.spanId,t.spans),N=i.has(d.span.spanId),R=n===d.span.spanId,Y=F[d.span.type]||F.custom;return e.jsxs("div",{className:`flex items-center gap-1 cursor-pointer text-xs h-[${B}px] ${R?"bg-accent-brand/5":"hover:bg-bg-hover"}`,style:{paddingLeft:4+d.depth*16,height:B},onClick:()=>s(R?null:d.span.spanId),children:[k?e.jsx("button",{onClick:O=>{O.stopPropagation(),S(d.span.spanId)},className:"p-0.5",children:N?e.jsx(ue,{size:12}):e.jsx(Te,{size:12})}):e.jsx("span",{className:"w-4"}),e.jsx("span",{className:"w-2 h-2 rounded-sm shrink-0",style:{backgroundColor:a?Y.dark:Y.light}}),e.jsx("span",{className:"truncate text-text-primary",children:d.span.name})]},d.span.spanId)})}),e.jsx("div",{className:"flex-1 min-w-[300px]",children:e.jsxs("svg",{width:"100%",viewBox:`0 0 900 ${E.length*B+20}`,className:"block",children:[Array.from({length:z+1},(d,k)=>{const N=k/z*900;return e.jsx("line",{x1:N,y1:0,x2:N,y2:E.length*B,stroke:a?"#374151":"#e5e7eb",strokeWidth:.5,strokeDasharray:k?"2,2":void 0},k)}),E.map((d,k)=>{var J;const N=k*B,R=new Date(d.span.startedAt).getTime(),Y=d.span.endedAt?new Date(d.span.endedAt).getTime():R+A,O=(R-I)/A*900,V=Math.max((Y-R)/A*900,gt),U=F[d.span.type]||F.custom,W=a?U.dark:U.light,Z=((J=t.bottleneck)==null?void 0:J.spanId)===d.span.spanId,K=n===d.span.spanId;return e.jsxs("g",{onClick:()=>s(K?null:d.span.spanId),style:{cursor:"pointer"},children:[K&&e.jsx("rect",{x:0,y:N,width:900,height:B,fill:a?"#1e3a5f":"#dbeafe"}),e.jsx("rect",{x:O,y:N+(B-ne)/2,width:V,height:ne,fill:W,rx:3,opacity:d.span.status==="running"?.5:.85}),Z&&e.jsx("rect",{x:O-1,y:N+(B-ne)/2-1,width:V+2,height:ne+2,fill:"none",stroke:"#f59e0b",strokeWidth:1.5,strokeDasharray:"4,2",rx:3}),V>36&&d.span.duration!=null&&e.jsx("text",{x:O+V/2,y:N+B/2,dominantBaseline:"central",textAnchor:"middle",fontSize:9,fill:"#fff",fontFamily:"monospace",children:P(d.span.duration)}),e.jsxs("title",{children:[d.span.name," — ",d.span.duration!=null?P(d.span.duration):"running"]})]},d.span.spanId)}),Array.from({length:z+1},(d,k)=>e.jsx("text",{x:k/z*900,y:E.length*B+14,textAnchor:"middle",fontSize:9,fill:a?"#9ca3af":"#6b7280",fontFamily:"monospace",children:P(k/z*A)},`t${k}`))]})})]})]})}function we({trace:t,onClick:n}){var g,b,h;const{t:s}=X(),u=ut(t.status),o=t.prompt||t.name,a=pt(t.startedAt),i=t.category==="auxiliary",c=t.status==="error"||(t.errorCount||0)>0?"w-full flex items-start gap-3 px-3 py-2.5 rounded-lg border border-accent-red/30 border-l-2 border-l-accent-red bg-accent-red/[0.03] text-left hover:bg-accent-red/10 transition-colors group":"w-full flex items-start gap-3 px-3 py-2.5 rounded-lg border border-border-default text-left hover:bg-bg-hover transition-colors group";return e.jsxs("button",{onClick:n,className:c,children:[e.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 mt-1.5 bg-${u}`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[i&&e.jsx("span",{className:"shrink-0 text-[10px] px-1 py-0 rounded bg-bg-hover text-text-tertiary",children:s("traces.auto")}),e.jsx("span",{className:`font-medium text-sm truncate ${i?"text-text-secondary":"text-text-primary"}`,children:o}),e.jsx(re,{color:Me(t.status),children:s(De(t.status))}),(t.errorCount||0)>0&&e.jsxs("span",{className:"shrink-0 inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-accent-red/10 text-accent-red font-medium",children:[e.jsx(te,{size:11}),t.errorCount," ",s("traces.errors")]})]}),t.firstErrorMessage&&e.jsxs("div",{className:"mt-1 text-xs text-accent-red font-mono truncate",title:t.firstErrorMessage,children:[e.jsxs("span",{className:"text-text-tertiary mr-1",children:[t.firstErrorWhere||"error",":"]}),t.firstErrorMessage]}),e.jsxs("div",{className:"flex items-center gap-3 mt-0.5 text-xs text-text-tertiary",children:[e.jsx("span",{children:a}),e.jsx("span",{children:t.duration!=null?P(t.duration):"--"}),e.jsxs("span",{children:[t.spanCount," spans"]}),t.totalTokens>0&&e.jsx("span",{children:ae(t.totalTokens)}),(b=(g=t.modelInfo)==null?void 0:g.models)!=null&&b.length?e.jsx("span",{children:t.modelInfo.models.join(", ")}):null,(h=t.modelInfo)!=null&&h.callCount?e.jsx("span",{children:s("traces.llmCalls").replace("{count}",String(t.modelInfo.callCount))}):null,t.modelInfo&&t.modelInfo.totalCachedTokens>0&&t.modelInfo.totalInputTokens>0&&e.jsxs("span",{className:"text-accent-green",children:["Cache ",Math.round(t.modelInfo.totalCachedTokens/t.modelInfo.totalInputTokens*100),"%"]})]})]}),e.jsx(ue,{size:14,className:"text-text-tertiary shrink-0 mt-1.5 opacity-0 group-hover:opacity-100 transition-opacity"})]})}function Se({detail:t,selectedSpanId:n,onSelectSpan:s,theme:u}){const{t:o}=X(),a=u==="dark",i=f.useMemo(()=>le(t.spans),[t.spans]);function p(c,g,b){var z;const h=c.span,M=$e[h.type]||xe,D=F[h.type]||F.custom,E=n===h.spanId,S=((z=t.bottleneck)==null?void 0:z.spanId)===h.spanId,I=g?"└── ":"├── ",A=h.status==="error",$=h.error;return e.jsxs("div",{children:[e.jsxs("div",{className:`flex items-center gap-2 py-1 px-2 rounded cursor-pointer text-sm ${E?"bg-accent-brand/10":"hover:bg-bg-hover"} ${S?"ring-1 ring-accent-yellow":""} ${A?"bg-accent-red/5":""}`,onClick:()=>s(E?null:h.spanId),children:[c.depth>0&&e.jsxs("span",{className:"text-text-tertiary font-mono text-xs whitespace-pre",children:[b,I]}),e.jsx(M,{size:14,style:{color:A?void 0:a?D.dark:D.light},className:`shrink-0 ${A?"text-accent-red":""}`}),e.jsx("span",{className:`font-medium truncate ${A?"text-accent-red":"text-text-primary"}`,children:h.name}),h.duration!=null&&e.jsx("span",{className:"text-xs text-text-tertiary shrink-0",children:P(h.duration)}),(h.type==="generation"||h.type==="response")&&(h.inputTokens||h.outputTokens)&&e.jsxs("span",{className:"text-xs text-accent-purple shrink-0",children:[h.inputTokens||0,"→",h.outputTokens||0," tok"]}),h.model&&e.jsxs("span",{className:"text-xs text-text-tertiary shrink-0",children:["(",h.model,")"]}),A&&e.jsx("span",{className:"text-xs font-medium text-accent-red shrink-0",children:"error"}),S&&e.jsx("span",{className:"text-xs text-accent-yellow shrink-0",children:o("traces.bottleneck")})]}),A&&$&&e.jsx("div",{className:"ml-8 px-2 py-1 text-xs text-accent-red bg-accent-red/5 rounded cursor-pointer",style:{paddingLeft:(c.depth>0?b.length*6+28:8)+24},onClick:()=>s(h.spanId),children:$.length>200?$.substring(0,200)+"...":$}),c.children.length>0&&e.jsx("div",{className:"ml-2",children:c.children.map((L,d)=>p(L,d===c.children.length-1,b+(g?" ":"│ ")))})]},h.spanId)}return i.length?e.jsx("div",{className:"space-y-0.5",children:i.map((c,g)=>p(c,g===i.length-1,""))}):e.jsx("div",{className:"text-sm text-text-tertiary py-8 text-center",children:o("traces.noSpans")})}function St(){var me;const{t}=X(),n=Ce(j=>j.resolved),{traces:s,loading:u,error:o,selectedTraceId:a,traceDetail:i,detailLoading:p,selectedSpanId:c,workerPid:g,filterSessionId:b,statusFilter:h,fetchTraces:M,selectSpan:D,setWorkerPid:E,setFilterSessionId:S,setStatusFilter:I,clearTraces:A,fetchTraceDetail:$}=tt(),{workers:z,fetchWorkers:L}=He(),{sessionId:d}=Oe(),[k,N]=f.useState("list"),[R,Y]=f.useState("timeline"),[O,V]=f.useState(!1),U="traces-panel-ratio",[W,Z]=f.useState(()=>{const j=localStorage.getItem(U);return j?parseFloat(j):.6}),K=f.useCallback(j=>{Z(j),localStorage.setItem(U,String(j))},[]);f.useEffect(()=>{M(),L()},[M,L]);const J=f.useCallback(j=>{$(j),N("detail")},[$]),Q=f.useCallback(()=>{N("list"),D(null)},[D]),ee=f.useCallback(()=>{k==="detail"&&a?$(a):M()},[k,a,M,$]),r=f.useMemo(()=>s.filter(j=>j.category!=="auxiliary"),[s]),y=f.useMemo(()=>s.filter(j=>j.category==="auxiliary"),[s]),w=f.useMemo(()=>s.filter(j=>j.status==="error"||(j.errorCount||0)>0).length,[s]);if(k==="list")return e.jsxs("div",{className:"flex-1 overflow-auto p-4 md:p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx(Ie,{size:20,className:"text-text-secondary"}),e.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:t("traces.title")}),e.jsx("div",{className:"flex-1"}),e.jsx(ft,{value:h,onChange:I}),d&&e.jsxs("select",{value:b||"",onChange:j=>S(j.target.value||null),className:"px-2 py-1 rounded-md border border-border-default bg-bg-primary text-text-primary text-xs",children:[e.jsx("option",{value:"",children:t("traces.allSessions")}),e.jsxs("option",{value:d,children:[d.substring(0,8),"... (",t("traces.current"),")"]})]}),z.length>1&&e.jsx(st,{workers:z,selectedPid:g,onSelect:E}),e.jsx(de,{icon:ge,title:t("traces.refresh"),onClick:ee,spin:u}),s.length>0&&e.jsx(de,{icon:Pe,title:t("traces.clear"),onClick:()=>{confirm(t("traces.clearConfirm"))&&A()},danger:!0})]}),o&&e.jsx("div",{className:"mb-4 px-3 py-2 rounded-lg bg-accent-red/10 text-accent-red text-sm",children:o}),h!=="error"&&w>0&&e.jsxs("button",{onClick:()=>I("error"),className:"mb-3 w-full flex items-center gap-2 px-3 py-2 rounded-lg border border-accent-red/30 bg-accent-red/5 text-left hover:bg-accent-red/10 transition-colors",children:[e.jsx(te,{size:14,className:"text-accent-red shrink-0"}),e.jsx("span",{className:"text-sm text-accent-red font-medium",children:t("traces.errorBanner").replace("{count}",String(w))}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"text-xs text-accent-red opacity-70",children:t("traces.errorBannerCta")})]}),!u&&!s.length&&!o&&e.jsx("div",{className:"text-center py-16 text-text-tertiary text-sm",children:t(h==="error"?"traces.noErrors":"traces.noData")}),e.jsx("div",{className:"space-y-1",children:r.map(j=>e.jsx(we,{trace:j,onClick:()=>J(j.traceId)},j.traceId))}),y.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsxs("button",{onClick:()=>V(!O),className:"flex items-center gap-1.5 text-xs text-text-tertiary hover:text-text-secondary mb-1",children:[O?e.jsx(Te,{size:12}):e.jsx(ue,{size:12}),e.jsx("span",{children:t("traces.auxiliaryCount").replace("{count}",String(y.length))})]}),O&&e.jsx("div",{className:"space-y-1 opacity-70",children:y.map(j=>e.jsx(we,{trace:j,onClick:()=>J(j.traceId)},j.traceId))})]})]});const m=i;if(!m)return e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center gap-4",children:p?e.jsx("div",{className:"text-text-tertiary text-sm",children:t("traces.loading")}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-text-tertiary text-sm",children:t("traces.noData")}),e.jsx("button",{onClick:Q,className:"px-4 py-2 rounded-lg border border-border-default text-text-secondary text-sm hover:bg-bg-hover",children:t("traces.back")})]})});const T=m.trace,v=m.spans,l=T.modelInfo,x=xt(v),C=(l==null?void 0:l.totalInputTokens)||x.totalInputTokens,_=(l==null?void 0:l.totalOutputTokens)||x.totalOutputTokens,H=(me=l==null?void 0:l.models)!=null&&me.length?l.models:x.models,se=l!=null&&l.totalInputTokens&&l.totalCachedTokens?l.totalCachedTokens/l.totalInputTokens*100:x.cacheHitRate,he=(l==null?void 0:l.callCount)||x.generationCount;return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex-none border-b border-border-default bg-bg-primary px-4 py-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:Q,className:"p-1 rounded hover:bg-bg-hover text-text-tertiary",children:e.jsx(We,{size:16})}),e.jsx("span",{className:"font-medium text-text-primary truncate",children:T.prompt||T.name}),e.jsx("div",{className:"flex-1"}),e.jsx(re,{color:Me(T.status),children:t(De(T.status))}),m.errorSummary&&m.errorSummary.totalErrors>0&&e.jsxs("button",{onClick:()=>{var fe;const j=(fe=m.errorSummary)==null?void 0:fe.firstErrorSpanId;j&&(D(j),Y("tree"))},className:"shrink-0 inline-flex items-center gap-1 text-xs px-2 py-0.5 rounded bg-accent-red/10 text-accent-red font-medium hover:bg-accent-red/20 transition-colors",title:t("traces.jumpToFirstError"),children:[e.jsx(te,{size:12}),m.errorSummary.totalErrors," ",t("traces.errors")]}),e.jsx(de,{icon:ge,title:t("traces.refresh"),onClick:ee,spin:p})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-5 gap-y-1 mt-2 text-xs",children:[e.jsx(G,{label:t("traces.duration"),value:T.duration!=null?P(T.duration):"--"}),e.jsx(G,{label:"Spans",value:String(T.spanCount||0)}),C+_>0&&e.jsx(G,{label:"Tokens",value:`${ae(C)} in / ${ae(_)} out`}),C>0&&e.jsx(G,{label:"Cache",value:`${se.toFixed(0)}%`,accent:se>0}),H.length>0&&e.jsx(G,{label:t("traces.spanDetail.model"),value:H.join(", ")}),x.toolCount>0&&e.jsx(G,{label:"Tools",value:`${x.toolCount}${x.errorCount>0?` (${x.errorCount} err)`:""}`}),he>0&&e.jsx(G,{label:"LLM",value:t("traces.llmCalls").replace("{count}",String(he))})]}),m.errorSummary&&m.errorSummary.totalErrors>0&&e.jsx(ht,{summary:m.errorSummary,onJump:j=>{D(j),Y("tree")}}),e.jsxs("div",{className:"flex items-center gap-1 mt-2 overflow-x-auto",children:[["timeline","tree","flame","graph"].map(j=>e.jsx("button",{onClick:()=>Y(j),className:`px-3 py-1 rounded-md text-xs font-medium transition-colors whitespace-nowrap ${R===j?"bg-accent-brand/10 text-accent-brand":"text-text-tertiary hover:text-text-primary hover:bg-bg-hover"}`,children:t(`traces.tab.${j}`)},j)),e.jsx("div",{className:"flex-1"}),e.jsx("div",{className:"hidden md:flex",children:e.jsx(nt,{theme:n})})]})]}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx("div",{className:"h-full flex flex-col",children:c?e.jsxs(Be,{direction:"vertical",ratio:W,onRatioChange:K,children:[e.jsxs("div",{className:"w-full h-full overflow-auto p-2 md:p-4",children:[R==="timeline"&&e.jsx(Ne,{detail:m,selectedSpanId:c,onSelectSpan:D,theme:n}),R==="tree"&&e.jsx(Se,{detail:m,selectedSpanId:c,onSelectSpan:D,theme:n}),R==="flame"&&e.jsx(ve,{detail:m,selectedSpanId:c,onSelectSpan:D,theme:n}),R==="graph"&&e.jsx(ke,{detail:m,selectedSpanId:c,onSelectSpan:D,theme:n})]}),e.jsx("div",{className:"w-full h-full overflow-auto",children:e.jsx(mt,{span:m.spans.find(j=>j.spanId===c)||null,onClose:()=>D(null)})})]}):e.jsxs("div",{className:"flex-1 overflow-auto p-2 md:p-4",children:[R==="timeline"&&e.jsx(Ne,{detail:m,selectedSpanId:c,onSelectSpan:D,theme:n}),R==="tree"&&e.jsx(Se,{detail:m,selectedSpanId:c,onSelectSpan:D,theme:n}),R==="flame"&&e.jsx(ve,{detail:m,selectedSpanId:c,onSelectSpan:D,theme:n}),R==="graph"&&e.jsx(ke,{detail:m,selectedSpanId:c,onSelectSpan:D,theme:n})]})})})]})}export{St as TracesView};
|
|
21
|
+
*/const et=[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]],Ie=oe("network",et),tt=Ee((t,n)=>({traces:[],total:0,loading:!1,error:null,selectedTraceId:null,traceDetail:null,detailLoading:!1,selectedSpanId:null,workerPid:null,filterSessionId:null,statusFilter:"all",fetchTraces:async()=>{t({loading:!0,error:null});try{const{workerPid:s,filterSessionId:u,statusFilter:o}=n(),a=new URLSearchParams;a.set("limit","100"),s&&a.set("worker_pid",s),u&&a.set("session_id",u),o!=="all"&&a.set("status",o);const i=await ce(`/api/v1/traces?${a}`,{headers:ie()});if(!i.ok)throw new Error(`HTTP ${i.status}`);const c=(await i.json()).data||{};t({traces:c.traces||[],total:c.total||0,loading:!1})}catch(s){t({error:s.message,loading:!1})}},fetchTraceDetail:async s=>{t({detailLoading:!0,selectedTraceId:s,selectedSpanId:null});try{const{workerPid:u}=n(),o=new URLSearchParams;u&&o.set("worker_pid",u);const a=o.toString()?`?${o}`:"",i=await ce(`/api/v1/traces/${s}${a}`,{headers:ie()});if(!i.ok)throw new Error(`HTTP ${i.status}`);const p=await i.json();t({traceDetail:p.data||null,detailLoading:!1})}catch{t({traceDetail:null,detailLoading:!1})}},selectTrace:s=>{s===n().selectedTraceId?t({selectedTraceId:null,traceDetail:null,selectedSpanId:null}):s?n().fetchTraceDetail(s):t({selectedTraceId:null,traceDetail:null,selectedSpanId:null})},selectSpan:s=>t({selectedSpanId:s}),setWorkerPid:s=>{t({workerPid:s,selectedTraceId:null,traceDetail:null,selectedSpanId:null}),n().fetchTraces()},setFilterSessionId:s=>{t({filterSessionId:s,selectedTraceId:null,traceDetail:null,selectedSpanId:null}),n().fetchTraces()},setStatusFilter:s=>{t({statusFilter:s,selectedTraceId:null,traceDetail:null,selectedSpanId:null}),n().fetchTraces()},clearTraces:async()=>{try{const{workerPid:s}=n(),u=new URLSearchParams;s&&u.set("worker_pid",s);const o=u.toString()?`?${u}`:"";await ce(`/api/v1/traces${o}`,{method:"DELETE",headers:ie()}),t({traces:[],total:0,selectedTraceId:null,traceDetail:null,selectedSpanId:null})}catch{}}})),F={agent:{light:"#3b82f6",dark:"#60a5fa"},generation:{light:"#8b5cf6",dark:"#a78bfa"},function:{light:"#10b981",dark:"#34d399"},tool:{light:"#10b981",dark:"#34d399"},handoff:{light:"#f59e0b",dark:"#fbbf24"},guardrail:{light:"#f97316",dark:"#fb923c"},response:{light:"#6366f1",dark:"#818cf8"},custom:{light:"#6b7280",dark:"#9ca3af"}},$e={agent:Le,generation:ze,function:ye,tool:ye,handoff:Ae,guardrail:Qe,response:Ie,custom:xe};function st({workers:t,selectedPid:n,onSelect:s}){var c;const{t:u}=_(),o=(c=t.find(g=>g.isCurrent))==null?void 0:c.pid,a=t.find(g=>g.isCurrent),i=t.filter(g=>!g.isCurrent),p=n??(o!=null?String(o):"");return e.jsxs("select",{value:p,onChange:g=>{const b=g.target.value;s(b===String(o)?null:b||null)},className:"px-2 py-1 rounded-md border border-border-default bg-bg-primary text-text-primary text-xs",children:[e.jsx("option",{value:"all",children:u("traces.allInstances")}),a&&e.jsxs("option",{value:a.pid,children:["PID ",a.pid," — ",a.name||a.kind||"worker"," (",u("traces.current"),")"]}),i.map(g=>e.jsxs("option",{value:g.pid,children:["PID ",g.pid," — ",g.name||g.kind||"worker"]},g.pid))]})}function de({icon:t,title:n,onClick:s,spin:u,danger:o}){return e.jsx("button",{onClick:s,className:`p-1.5 rounded-md text-text-tertiary hover:bg-bg-hover transition-colors ${o?"hover:text-accent-red":"hover:text-text-primary"}`,title:n,children:e.jsx(t,{size:16,className:u?"animate-spin":""})})}function re({children:t,color:n}){const s=n==="red"?"text-accent-red bg-accent-red/10":n==="yellow"?"text-accent-yellow bg-accent-yellow/10":n==="grey"?"text-text-tertiary bg-bg-hover":"text-accent-green bg-accent-green/10";return e.jsx("span",{className:`shrink-0 text-xs px-1.5 py-0.5 rounded ${s}`,children:t})}function G({label:t,value:n,accent:s}){return e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsxs("span",{className:"text-text-tertiary",children:[t,":"]}),e.jsx("span",{className:`font-mono ${s?"text-accent-green font-medium":"text-text-primary"}`,children:n})]})}function q({label:t,value:n,className:s}){return e.jsxs("div",{className:s,children:[e.jsx("div",{className:"text-text-tertiary mb-0.5",children:t}),e.jsx("div",{className:"text-text-primary font-mono",children:n})]})}function nt({theme:t}){const{t:n}=_(),s=t==="dark",u=[["agent",n("traces.legend.agent")],["generation",n("traces.legend.generation")],["function",n("traces.legend.function")],["handoff",n("traces.legend.handoff")],["guardrail",n("traces.legend.guardrail")]];return e.jsx("div",{className:"flex items-center gap-3 text-xs text-text-tertiary",children:u.map(([o,a])=>{const i=F[o]||F.custom;return e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"w-2.5 h-2 rounded-sm",style:{backgroundColor:s?i.dark:i.light}}),e.jsx("span",{children:a})]},o)})})}const rt=Re,at=160,ot={system:"bg-purple-500/15 text-purple-400",user:"bg-blue-500/15 text-blue-400",assistant:"bg-green-500/15 text-green-400",tool:"bg-orange-500/15 text-orange-400"};function lt(t){return Array.isArray(t)&&t.length>0&&t.every(n=>n&&typeof n=="object"&&typeof n.role=="string")}function ct(t){return typeof t=="string"?t:Array.isArray(t)?t.filter(n=>n.type==="text"||typeof n=="string").map(n=>typeof n=="string"?n:n.text||"").join(`
|
|
22
|
+
`):t&&typeof t=="object"?JSON.stringify(t,null,2):String(t??"")}function be({label:t,content:n}){const[s,u]=f.useState(!1),o=f.useRef(null),[a,i]=f.useState(!1),p=Ce(h=>h.resolved),{t:c}=_();f.useEffect(()=>{const h=o.current;h&&i(h.scrollHeight>at)},[n]);const g=f.useMemo(()=>{const h=n.trim();if(h.startsWith("{")&&h.endsWith("}")||h.startsWith("[")&&h.endsWith("]"))try{const M=JSON.parse(h);return lt(M)?{type:"messages",messages:M}:{type:"json",formatted:JSON.stringify(M,null,2)}}catch{return{type:"text"}}return{type:"text"}},[n]),b=g.type==="messages"?c("traces.io.messages"):g.type==="json"?"JSON":null;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-text-tertiary",children:t}),b&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-blue/10 text-accent-blue",children:b}),a&&e.jsx("button",{onClick:()=>u(!s),className:"ml-auto flex items-center gap-0.5 text-[10px] text-text-tertiary hover:text-text-primary",children:s?e.jsxs(e.Fragment,{children:[e.jsx(Je,{size:10})," ",c("traces.io.collapse")]}):e.jsxs(e.Fragment,{children:[e.jsx(Ke,{size:10})," ",c("traces.io.expand")]})})]}),e.jsx("div",{ref:o,className:`rounded bg-bg-secondary overflow-auto ${s?"max-h-[80vh]":"max-h-40"}`,style:{transition:"max-height 0.2s ease"},children:g.type==="messages"?e.jsx(it,{messages:g.messages}):g.type==="json"?e.jsx("div",{className:"select-none [&_pre]:!bg-transparent [&_code]:!bg-transparent [&_span]:!bg-transparent",children:e.jsx(rt,{language:"json",style:p==="dark"?qe:Ve,customStyle:{margin:0,padding:"8px",background:"transparent",fontSize:"11px",lineHeight:"1.4"},wrapLongLines:!0,children:g.formatted})}):e.jsx("pre",{className:"p-2 text-text-primary font-mono text-xs whitespace-pre-wrap break-all",children:n})})]})}function it({messages:t}){return e.jsx("div",{className:"divide-y divide-border-default",children:t.map((n,s)=>e.jsx(dt,{role:n.role,content:n.content},s))})}function dt({role:t,content:n}){const[s,u]=f.useState(!1),{t:o}=_(),a=ct(n),i=a.length>300,p=i&&!s?a.slice(0,300)+"...":a,c=ot[t]||"bg-gray-500/15 text-gray-400";return e.jsxs("div",{className:"px-2 py-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-0.5",children:[e.jsx("span",{className:`text-[10px] px-1 py-px rounded font-medium ${c}`,children:t}),i&&e.jsx("button",{onClick:()=>u(!s),className:"text-[10px] text-text-tertiary hover:text-text-primary",children:s?o("traces.io.less"):o("traces.io.moreChars",{count:a.length-300})})]}),e.jsx("pre",{className:"text-text-primary font-mono text-[11px] whitespace-pre-wrap break-all leading-relaxed",children:p})]})}function le(t){const n=new Map,s=[];for(const a of t)n.set(a.spanId,{span:a,children:[],depth:0});for(const a of n.values())if(a.span.parentId&&a.span.parentId!==a.span.spanId&&n.has(a.span.parentId)){const i=n.get(a.span.parentId);i.children.push(a),a.depth=i.depth+1}else s.push(a);const u=new Set,o=[...s];for(;o.length;){const a=o.shift();if(!u.has(a.span.spanId)){u.add(a.span.spanId);for(const i of a.children)i.depth=a.depth+1,o.push(i)}}return s.length===0&&t.length>0?t.map(a=>({span:a,children:[],depth:0})):s}function pe(t,n){const s=[],u=new Set;function o(a){for(const i of a)u.has(i.span.spanId)||(u.add(i.span.spanId),s.push({span:i.span,depth:i.depth}),n!=null&&n.has(i.span.spanId)||o(i.children))}return o(t),s}function je(t,n){return n.some(s=>s.parentId===t)}function xt(t){var g;let n=0,s=0,u=0;const o=new Set;let a=0,i=0,p=0;for(const b of t)b.status==="error"&&p++,(b.type==="generation"||b.type==="response")&&(i++,n+=b.inputTokens||0,s+=b.outputTokens||0,b.model&&o.add(b.model),(g=b.attributes)!=null&&g.cached_tokens&&(u+=Number(b.attributes.cached_tokens)||0)),(b.type==="function"||b.type==="tool")&&a++;const c=n>0?u/n*100:0;return{totalInputTokens:n,totalOutputTokens:s,cacheHitRate:c,models:Array.from(o),toolCount:a,generationCount:i,errorCount:p}}function Me(t){return t==="error"?"red":t==="running"?"yellow":t==="cancelled"?"grey":"green"}function ut(t){return t==="error"?"accent-red":t==="running"?"accent-yellow":t==="cancelled"?"text-tertiary":"accent-green"}function De(t){return t==="error"?"traces.status.error":t==="running"?"traces.status.running":t==="cancelled"?"traces.status.cancelled":"traces.status.ok"}function P(t){return t<1?"<1ms":t<1e3?`${Math.round(t)}ms`:t<6e4?`${(t/1e3).toFixed(1)}s`:`${Math.floor(t/6e4)}m${(t%6e4/1e3).toFixed(0)}s`}function ae(t){return t>=1e6?`${(t/1e6).toFixed(1)}M tok`:t>=1e3?`${(t/1e3).toFixed(1)}k tok`:`${t} tok`}function pt(t){try{return new Date(t).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit"})}catch{return""}}function ht({summary:t,onJump:n}){const{t:s}=_(),[u,o]=f.useState(!0),a=t.groups,i=u?a:a.slice(0,3);return e.jsxs("div",{className:"mt-2 px-3 py-2 rounded-md border border-accent-red/30 bg-accent-red/[0.04]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{size:13,className:"text-accent-red shrink-0"}),e.jsx("span",{className:"text-xs font-medium text-accent-red",children:s("traces.errorSummaryTitle").replace("{count}",String(t.totalErrors))}),e.jsx("span",{className:"flex-1"}),a.length>3&&e.jsx("button",{onClick:()=>o(p=>!p),className:"text-[11px] text-accent-red opacity-80 hover:opacity-100",children:s(u?"traces.io.less":"traces.io.expand")})]}),e.jsx("div",{className:"mt-1.5 space-y-1",children:i.map(p=>e.jsxs("button",{onClick:()=>n(p.spanId),className:"w-full flex items-start gap-2 text-left px-2 py-1 rounded hover:bg-accent-red/10 transition-colors",title:s("traces.jumpToFirstError"),children:[e.jsxs("span",{className:"shrink-0 text-[10px] px-1 py-0 rounded bg-accent-red/15 text-accent-red font-mono",children:["×",p.count]}),e.jsx("span",{className:"shrink-0 text-xs text-accent-red font-medium truncate max-w-[140px]",children:p.where}),e.jsx("span",{className:"text-xs text-text-secondary font-mono truncate flex-1 min-w-0",children:p.sampleMessage})]},p.spanId))})]})}function ve({detail:t,selectedSpanId:n,onSelectSpan:s,theme:u}){const{t:o}=_(),a=u==="dark",i=f.useMemo(()=>pe(le(t.spans)),[t.spans]),{minTime:p,totalRange:c}=f.useMemo(()=>{const E=t.spans.map($=>new Date($.startedAt).getTime()),S=t.spans.filter($=>$.endedAt).map($=>new Date($.endedAt).getTime()),I=Math.min(...E),A=S.length?Math.max(...S):I+1e3;return{minTime:I,totalRange:A-I||1}},[t.spans]);if(!i.length)return e.jsx("div",{className:"text-sm text-text-tertiary py-8 text-center",children:o("traces.noSpans")});const g=Math.max(...i.map(E=>E.depth))+1,b=24,h=1,M=800,D=g*(b+h);return e.jsx("svg",{width:"100%",viewBox:`0 0 ${M} ${D}`,className:"block",style:{maxWidth:M},children:i.map(E=>{const S=E.span,I=new Date(S.startedAt).getTime(),A=S.endedAt?new Date(S.endedAt).getTime():I+c,$=(I-p)/c*M,z=Math.max((A-I)/c*M,1),L=E.depth*(b+h),d=F[S.type]||F.custom,k=a?d.dark:d.light,N=n===S.spanId;return e.jsxs("g",{onClick:()=>s(N?null:S.spanId),style:{cursor:"pointer"},children:[e.jsx("rect",{x:$,y:L,width:z,height:b,fill:k,rx:2,opacity:N?1:.8,stroke:N?a?"#60a5fa":"#3b82f6":"none",strokeWidth:N?1.5:0}),z>40&&e.jsx("text",{x:$+4,y:L+b/2,dominantBaseline:"central",fontSize:10,fill:"#fff",fontFamily:"monospace",children:S.name.length>z/6?S.name.slice(0,Math.floor(z/6)-1)+"…":S.name}),e.jsxs("title",{children:[S.name," — ",S.duration!=null?P(S.duration):"running",S.model?` (${S.model})`:""]})]},S.spanId)})})}function ke({detail:t,selectedSpanId:n,onSelectSpan:s,theme:u}){const{t:o}=_(),a=u==="dark",i=f.useRef(null),{groupNodes:p,groupEdges:c}=f.useMemo(()=>{const r=new Map,y=pe(le(t.spans));for(const v of y){const l=v.span,x=`${l.parentId||"root"}::${l.type}::${l.name.split("(")[0].trim()}`,C=r.get(x);C?(C.count++,C.totalDuration+=l.duration||0,C.totalTokens+=(l.inputTokens||0)+(l.outputTokens||0),l.status==="error"&&(C.hasError=!0)):r.set(x,{id:x,type:l.type,name:l.name.split("(")[0].trim(),count:1,totalDuration:l.duration||0,totalTokens:(l.inputTokens||0)+(l.outputTokens||0),hasError:l.status==="error",parentId:l.parentId,depth:v.depth,representativeSpanId:l.spanId})}const w=Array.from(r.values()),m=[];for(const v of w)if(v.parentId){const l=t.spans.find(x=>x.spanId===v.parentId);if(l){const x=`${l.parentId||"root"}::${l.type}::${l.name.split("(")[0].trim()}`;r.has(x)&&x!==v.id&&m.push({from:x,to:v.id})}}const T=new Set(m.map(v=>`${v.from}\0${v.to}`));return{groupNodes:w,groupEdges:Array.from(T).map(v=>{const[l,x]=v.split("\0");return{from:l,to:x}})}},[t.spans]),g=180,b=60,h=70,M=28,{positions:D,svgW:E,svgH:S}=f.useMemo(()=>{const r=new Map;for(const l of p)r.has(l.depth)||r.set(l.depth,[]),r.get(l.depth).push(l);const y=Array.from(r.entries()).sort((l,x)=>l[0]-x[0]),w=Math.max(1,...y.map(([,l])=>l.length)),m=Math.max(w*(g+M)+M,400),T=y.length*(b+h)+20,v=new Map;for(const[l,x]of y){const C=x.length*g+(x.length-1)*M,Y=(m-C)/2;x.forEach((H,se)=>v.set(H.id,{x:Y+se*(g+M),y:l*(b+h)+10}))}return{positions:v,svgW:m,svgH:T}},[p,g,b,h,M]),[I,A]=f.useState({zoom:1,panX:0,panY:0}),[$,z]=f.useState(!1),L=f.useRef({x:0,y:0,panX:0,panY:0}),d=f.useCallback(()=>{const r=i.current;if(!r||E<=0||S<=0)return;const y=r.clientWidth,w=r.clientHeight;if(y<=0||w<=0)return;const m=Math.min(y/E,w/S,1.5)*.9;A({zoom:m,panX:(y-E*m)/2,panY:(w-S*m)/2})},[E,S]);f.useEffect(()=>{d()},[d,p.length]),f.useEffect(()=>{const r=i.current;if(!r)return;const y=w=>{w.preventDefault();const m=r.getBoundingClientRect(),T=w.clientX-m.left,v=w.clientY-m.top,l=w.deltaY<0?1.06:.94;A(x=>{const C=Math.max(.1,Math.min(5,x.zoom*l));return{zoom:C,panX:T-(T-x.panX)*(C/x.zoom),panY:v-(v-x.panY)*(C/x.zoom)}})};return r.addEventListener("wheel",y,{passive:!1}),()=>r.removeEventListener("wheel",y)},[]);const k=f.useRef(null),N=f.useCallback(r=>{if(r.touches.length===2){const y=r.touches[0].clientX-r.touches[1].clientX,w=r.touches[0].clientY-r.touches[1].clientY;k.current={dist:Math.hypot(y,w),cx:(r.touches[0].clientX+r.touches[1].clientX)/2,cy:(r.touches[0].clientY+r.touches[1].clientY)/2}}else r.touches.length===1&&(z(!0),L.current={x:r.touches[0].clientX,y:r.touches[0].clientY,panX:I.panX,panY:I.panY})},[I.panX,I.panY]),R=f.useCallback(r=>{if(r.touches.length===2&&k.current){r.preventDefault();const y=r.touches[0].clientX-r.touches[1].clientX,w=r.touches[0].clientY-r.touches[1].clientY,m=Math.hypot(y,w),T=m/k.current.dist,v=i.current;if(v){const l=v.getBoundingClientRect(),x=k.current.cx-l.left,C=k.current.cy-l.top;A(Y=>{const H=Math.max(.1,Math.min(5,Y.zoom*T));return{zoom:H,panX:x-(x-Y.panX)*(H/Y.zoom),panY:C-(C-Y.panY)*(H/Y.zoom)}})}k.current.dist=m}else r.touches.length===1&&$&&A(y=>({...y,panX:L.current.panX+r.touches[0].clientX-L.current.x,panY:L.current.panY+r.touches[0].clientY-L.current.y}))},[$]),X=f.useCallback(()=>{z(!1),k.current=null},[]),O=f.useCallback(r=>{r.button===0&&(z(!0),L.current={x:r.clientX,y:r.clientY,panX:I.panX,panY:I.panY})},[I.panX,I.panY]),V=f.useCallback(r=>{$&&A(y=>({...y,panX:L.current.panX+r.clientX-L.current.x,panY:L.current.panY+r.clientY-L.current.y}))},[$]),U=f.useCallback(()=>z(!1),[]),W=f.useMemo(()=>{if(!n)return new Set;const r=p.find(x=>x.representativeSpanId===n);if(!r)return new Set;const y=new Set([r.id]),w=new Map;for(const x of c)w.set(x.to,x.from);let m=r.id;for(;w.has(m)&&(m=w.get(m),!y.has(m));)y.add(m);const T=new Map;for(const x of c)T.has(x.from)||T.set(x.from,[]),T.get(x.from).push(x.to);const v=[r.id],l=new Set([r.id]);for(;v.length;){const x=v.shift();for(const C of T.get(x)||[])l.has(C)||(l.add(C),y.add(C),v.push(C))}return y},[n,p,c]),Z=f.useCallback((r,y)=>W.has(r)&&W.has(y),[W]);if(!p.length)return e.jsx("div",{className:"text-sm text-text-tertiary py-8 text-center",children:o("traces.noSpans")});const K=a?"#d1d5db":"#374151",J=a?"#9ca3af":"#6b7280",Q=a?"#4b5563":"#d1d5db",ee=a?"#60a5fa":"#3b82f6";return e.jsxs("div",{ref:i,className:"w-full h-full overflow-hidden relative touch-none",style:{cursor:$?"grabbing":"grab",minHeight:300},onMouseDown:O,onMouseMove:V,onMouseUp:U,onMouseLeave:U,onTouchStart:N,onTouchMove:R,onTouchEnd:X,children:[e.jsx("button",{onClick:d,className:"absolute top-2 right-2 z-10 px-2 py-1 rounded-md bg-bg-secondary border border-border-default text-text-tertiary hover:text-text-primary text-xs",style:{cursor:"pointer"},children:o("traces.fit")}),e.jsx("svg",{width:"100%",height:"100%",style:{position:"absolute",left:0,top:0},children:e.jsxs("g",{transform:`translate(${I.panX},${I.panY}) scale(${I.zoom})`,children:[c.map((r,y)=>{const w=D.get(r.from),m=D.get(r.to);if(!w||!m)return null;const T=w.x+g/2,v=w.y+b,l=m.x+g/2,x=m.y,C=Z(r.from,r.to);return e.jsx("path",{d:`M${T},${v} C${T},${v+h/2} ${l},${x-h/2} ${l},${x}`,fill:"none",stroke:C?ee:Q,strokeWidth:C?2.5:1.5,opacity:W.size>0&&!C?.2:1},y)}),p.map(r=>{const y=D.get(r.id);if(!y)return null;const w=F[r.type]||F.custom,m=a?w.dark:w.light,T=n===r.representativeSpanId,v=W.has(r.id),l=W.size>0&&!v,x=r.count>1?`${r.name} x${r.count}`:r.name,C=P(r.totalDuration),Y=r.totalTokens>0?` · ${ae(r.totalTokens)}`:"";return e.jsxs("g",{onClick:H=>{H.stopPropagation(),s(T?null:r.representativeSpanId)},style:{cursor:"pointer"},opacity:l?.25:1,children:[e.jsx("rect",{x:y.x,y:y.y,width:g,height:b,rx:8,fill:a?"#1f2937":"#fff",stroke:T?m:r.hasError?"#ef4444":v?ee:Q,strokeWidth:T?2.5:v?2:1}),e.jsx("rect",{x:y.x,y:y.y,width:6,height:b,rx:3,fill:m}),e.jsx("text",{x:y.x+16,y:y.y+24,fontSize:13,fill:K,fontWeight:r.count>1?600:500,fontFamily:"sans-serif",children:x.length>20?x.slice(0,19)+"…":x}),e.jsxs("text",{x:y.x+16,y:y.y+44,fontSize:11,fill:J,fontFamily:"monospace",children:[C,Y]}),e.jsxs("title",{children:[x," — ",C,Y]})]},r.id)})]})})]})}function mt({span:t,onClose:n}){const{t:s}=_(),[u,o]=f.useState("overview");if(!t)return null;const a=$e[t.type]||xe,i=t.duration;return e.jsxs("div",{className:"h-full flex flex-col border-t border-border-default bg-bg-primary overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 md:px-4 py-2 border-b border-border-default",children:[e.jsx(a,{size:14,className:"text-text-secondary shrink-0"}),e.jsx("span",{className:"font-medium text-text-primary text-sm truncate",children:t.name}),t.duration!=null&&e.jsx("span",{className:"text-xs text-text-tertiary",children:P(t.duration)}),t.status==="error"&&e.jsx(re,{color:"red",children:s("traces.status.error")}),t.status==="cancelled"&&e.jsx(re,{color:"grey",children:s("traces.status.cancelled")}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:n,className:"p-1 rounded hover:bg-bg-hover text-text-tertiary",children:e.jsx(Xe,{size:14})})]}),e.jsx("div",{className:"flex gap-1 px-4 pt-2",children:["overview","io","attrs"].map(p=>e.jsx("button",{onClick:()=>o(p),className:`px-2 py-0.5 rounded text-xs ${u===p?"bg-bg-hover text-text-primary font-medium":"text-text-tertiary hover:text-text-primary"}`,children:s(p==="overview"?"traces.spanDetail.overview":p==="io"?"traces.spanDetail.io":"traces.spanDetail.attributes")},p))}),e.jsxs("div",{className:"flex-1 overflow-auto px-3 md:px-4 py-3 text-xs",children:[u==="overview"&&e.jsxs("div",{children:[t.error&&(()=>{const c=t.status==="cancelled"?{bg:"bg-bg-hover",border:"border-border-default",text:"text-text-secondary",label:s("traces.spanDetail.cancelReason")}:{bg:"bg-accent-red/10",border:"border-accent-red/20",text:"text-accent-red",label:s("traces.spanDetail.error")};return e.jsxs("div",{className:`mb-3 px-3 py-2 rounded-md ${c.bg} border ${c.border}`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:`font-medium ${c.text}`,children:c.label}),e.jsx("span",{className:"flex-1"}),e.jsxs("button",{onClick:()=>{_e(t.error||"")},className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] ${c.text} hover:${c.bg}`,title:s("traces.copyError"),children:[e.jsx(Ye,{size:11}),s("traces.copyError")]})]}),e.jsx("pre",{className:`${c.text} font-mono whitespace-pre-wrap break-all max-h-32 overflow-auto`,children:t.error})]})})(),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(q,{label:s("traces.spanDetail.type"),value:t.type}),e.jsx(q,{label:s("traces.spanDetail.duration"),value:t.duration!=null?P(t.duration):"--"}),e.jsx(q,{label:s("traces.selfTime"),value:i!=null?P(i):"--"}),e.jsx(q,{label:"Status",value:t.status}),t.model&&e.jsx(q,{label:s("traces.spanDetail.model"),value:t.model}),(t.inputTokens!=null||t.outputTokens!=null)&&e.jsx(q,{label:s("traces.spanDetail.tokens"),value:`${t.inputTokens||0} in / ${t.outputTokens||0} out`}),t.toolName&&e.jsx(q,{label:"Tool",value:t.toolName}),t.fromAgent&&e.jsx(q,{label:"From",value:t.fromAgent}),t.toAgent&&e.jsx(q,{label:"To",value:t.toAgent})]})]}),u==="io"&&e.jsxs("div",{className:"space-y-3",children:[t.toolInput&&e.jsx(be,{label:s("traces.spanDetail.input"),content:t.toolInput}),t.toolOutput&&e.jsx(be,{label:s("traces.spanDetail.output"),content:t.toolOutput}),!t.toolInput&&!t.toolOutput&&e.jsx("div",{className:"text-text-tertiary",children:s("traces.noIO")})]}),u==="attrs"&&e.jsx("div",{className:"space-y-1",children:t.attributes&&Object.keys(t.attributes).length>0?Object.entries(t.attributes).map(([p,c])=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"shrink-0 text-text-tertiary w-32",children:p}),e.jsx("span",{className:"text-text-primary font-mono break-all",children:typeof c=="string"?c:JSON.stringify(c)})]},p)):e.jsx("div",{className:"text-text-tertiary",children:s("traces.noAttrs")})})]})]})}function ft({value:t,onChange:n}){const{t:s}=_(),u=[{key:"all",label:s("traces.filter.all"),activeClass:"bg-bg-hover text-text-primary"},{key:"error",label:s("traces.filter.error"),activeClass:"bg-accent-red/15 text-accent-red"},{key:"running",label:s("traces.filter.running"),activeClass:"bg-accent-yellow/15 text-accent-yellow"},{key:"cancelled",label:s("traces.filter.cancelled"),activeClass:"bg-bg-hover text-text-secondary"},{key:"ok",label:s("traces.filter.ok"),activeClass:"bg-accent-green/15 text-accent-green"}];return e.jsx("div",{className:"flex items-center gap-1 rounded-md border border-border-default p-0.5",children:u.map(o=>e.jsx("button",{onClick:()=>n(o.key),className:`px-2 py-0.5 rounded text-xs font-medium transition-colors ${t===o.key?o.activeClass:"text-text-tertiary hover:text-text-primary"}`,children:o.label},o.key))})}const B=28,ne=16,gt=2;function Ne({detail:t,selectedSpanId:n,onSelectSpan:s,theme:u}){const{t:o}=_(),a=u==="dark",[i,p]=f.useState(new Set),[c,g]=f.useState(""),[b,h]=f.useState(!1),M=f.useMemo(()=>le(t.spans),[t.spans]),E=f.useMemo(()=>pe(M,i),[M,i]).filter(d=>{var k;if(b&&d.span.status!=="error")return!1;if(c){const N=c.toLowerCase();return d.span.name.toLowerCase().includes(N)||((k=d.span.toolName)==null?void 0:k.toLowerCase().includes(N))}return!0}),S=d=>p(k=>{const N=new Set(k);return N.has(d)?N.delete(d):N.add(d),N}),{minTime:I,totalRange:A}=f.useMemo(()=>{const d=t.spans.map(X=>new Date(X.startedAt).getTime()),k=t.spans.filter(X=>X.endedAt).map(X=>new Date(X.endedAt).getTime()),N=Math.min(...d),R=k.length?Math.max(...k):N+1e3;return{minTime:N,totalRange:R-N||1}},[t.spans]),$=220,z=5,L=e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsxs("div",{className:"relative flex-1 max-w-xs",children:[e.jsx(Fe,{size:14,className:"absolute left-2 top-1/2 -translate-y-1/2 text-text-tertiary"}),e.jsx("input",{value:c,onChange:d=>g(d.target.value),placeholder:o("traces.search"),className:"w-full pl-7 pr-2 py-1 text-xs rounded-md border border-border-default bg-bg-primary text-text-primary"})]}),e.jsxs("button",{onClick:()=>h(d=>!d),className:`text-xs px-2 py-1 rounded-md border transition-colors inline-flex items-center gap-1 ${b?"border-accent-red/40 bg-accent-red/10 text-accent-red":"border-border-default text-text-tertiary hover:text-text-primary"}`,title:o("traces.onlyErrors"),children:[e.jsx(te,{size:12}),o("traces.onlyErrors")]}),e.jsx("button",{onClick:()=>p(new Set),className:"text-xs text-text-tertiary hover:text-text-primary",children:o("traces.expandAll")}),e.jsx("button",{onClick:()=>p(new Set(t.spans.filter(d=>je(d.spanId,t.spans)).map(d=>d.spanId))),className:"text-xs text-text-tertiary hover:text-text-primary",children:o("traces.collapseAll")})]});if(!E.length){const d=b||!!c;return e.jsxs("div",{children:[L,e.jsxs("div",{className:"text-sm text-text-tertiary py-8 text-center",children:[o(d?"traces.noSpansFiltered":"traces.noSpans"),d&&e.jsx("button",{onClick:()=>{h(!1),g("")},className:"ml-2 text-accent-brand hover:underline",children:o("traces.clearFilter")})]})]})}return e.jsxs("div",{children:[L,e.jsxs("div",{className:"flex overflow-x-auto",children:[e.jsx("div",{className:"shrink-0",style:{width:$},children:E.map(d=>{const k=je(d.span.spanId,t.spans),N=i.has(d.span.spanId),R=n===d.span.spanId,X=F[d.span.type]||F.custom;return e.jsxs("div",{className:`flex items-center gap-1 cursor-pointer text-xs h-[${B}px] ${R?"bg-accent-brand/5":"hover:bg-bg-hover"}`,style:{paddingLeft:4+d.depth*16,height:B},onClick:()=>s(R?null:d.span.spanId),children:[k?e.jsx("button",{onClick:O=>{O.stopPropagation(),S(d.span.spanId)},className:"p-0.5",children:N?e.jsx(ue,{size:12}):e.jsx(Te,{size:12})}):e.jsx("span",{className:"w-4"}),e.jsx("span",{className:"w-2 h-2 rounded-sm shrink-0",style:{backgroundColor:a?X.dark:X.light}}),e.jsx("span",{className:"truncate text-text-primary",children:d.span.name})]},d.span.spanId)})}),e.jsx("div",{className:"flex-1 min-w-[300px]",children:e.jsxs("svg",{width:"100%",viewBox:`0 0 900 ${E.length*B+20}`,className:"block",children:[Array.from({length:z+1},(d,k)=>{const N=k/z*900;return e.jsx("line",{x1:N,y1:0,x2:N,y2:E.length*B,stroke:a?"#374151":"#e5e7eb",strokeWidth:.5,strokeDasharray:k?"2,2":void 0},k)}),E.map((d,k)=>{var J;const N=k*B,R=new Date(d.span.startedAt).getTime(),X=d.span.endedAt?new Date(d.span.endedAt).getTime():R+A,O=(R-I)/A*900,V=Math.max((X-R)/A*900,gt),U=F[d.span.type]||F.custom,W=a?U.dark:U.light,Z=((J=t.bottleneck)==null?void 0:J.spanId)===d.span.spanId,K=n===d.span.spanId;return e.jsxs("g",{onClick:()=>s(K?null:d.span.spanId),style:{cursor:"pointer"},children:[K&&e.jsx("rect",{x:0,y:N,width:900,height:B,fill:a?"#1e3a5f":"#dbeafe"}),e.jsx("rect",{x:O,y:N+(B-ne)/2,width:V,height:ne,fill:W,rx:3,opacity:d.span.status==="running"?.5:.85}),Z&&e.jsx("rect",{x:O-1,y:N+(B-ne)/2-1,width:V+2,height:ne+2,fill:"none",stroke:"#f59e0b",strokeWidth:1.5,strokeDasharray:"4,2",rx:3}),V>36&&d.span.duration!=null&&e.jsx("text",{x:O+V/2,y:N+B/2,dominantBaseline:"central",textAnchor:"middle",fontSize:9,fill:"#fff",fontFamily:"monospace",children:P(d.span.duration)}),e.jsxs("title",{children:[d.span.name," — ",d.span.duration!=null?P(d.span.duration):"running"]})]},d.span.spanId)}),Array.from({length:z+1},(d,k)=>e.jsx("text",{x:k/z*900,y:E.length*B+14,textAnchor:"middle",fontSize:9,fill:a?"#9ca3af":"#6b7280",fontFamily:"monospace",children:P(k/z*A)},`t${k}`))]})})]})]})}function we({trace:t,onClick:n}){var g,b,h;const{t:s}=_(),u=ut(t.status),o=t.prompt||t.name,a=pt(t.startedAt),i=t.category==="auxiliary",c=t.status==="error"||(t.errorCount||0)>0?"w-full flex items-start gap-3 px-3 py-2.5 rounded-lg border border-accent-red/30 border-l-2 border-l-accent-red bg-accent-red/[0.03] text-left hover:bg-accent-red/10 transition-colors group":"w-full flex items-start gap-3 px-3 py-2.5 rounded-lg border border-border-default text-left hover:bg-bg-hover transition-colors group";return e.jsxs("button",{onClick:n,className:c,children:[e.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 mt-1.5 bg-${u}`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[i&&e.jsx("span",{className:"shrink-0 text-[10px] px-1 py-0 rounded bg-bg-hover text-text-tertiary",children:s("traces.auto")}),e.jsx("span",{className:`font-medium text-sm truncate ${i?"text-text-secondary":"text-text-primary"}`,children:o}),e.jsx(re,{color:Me(t.status),children:s(De(t.status))}),(t.errorCount||0)>0&&e.jsxs("span",{className:"shrink-0 inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-accent-red/10 text-accent-red font-medium",children:[e.jsx(te,{size:11}),t.errorCount," ",s("traces.errors")]})]}),t.firstErrorMessage&&e.jsxs("div",{className:"mt-1 text-xs text-accent-red font-mono truncate",title:t.firstErrorMessage,children:[e.jsxs("span",{className:"text-text-tertiary mr-1",children:[t.firstErrorWhere||"error",":"]}),t.firstErrorMessage]}),e.jsxs("div",{className:"flex items-center gap-3 mt-0.5 text-xs text-text-tertiary",children:[e.jsx("span",{children:a}),e.jsx("span",{children:t.duration!=null?P(t.duration):"--"}),e.jsxs("span",{children:[t.spanCount," spans"]}),t.totalTokens>0&&e.jsx("span",{children:ae(t.totalTokens)}),(b=(g=t.modelInfo)==null?void 0:g.models)!=null&&b.length?e.jsx("span",{children:t.modelInfo.models.join(", ")}):null,(h=t.modelInfo)!=null&&h.callCount?e.jsx("span",{children:s("traces.llmCalls").replace("{count}",String(t.modelInfo.callCount))}):null,t.modelInfo&&t.modelInfo.totalCachedTokens>0&&t.modelInfo.totalInputTokens>0&&e.jsxs("span",{className:"text-accent-green",children:["Cache ",Math.round(t.modelInfo.totalCachedTokens/t.modelInfo.totalInputTokens*100),"%"]})]})]}),e.jsx(ue,{size:14,className:"text-text-tertiary shrink-0 mt-1.5 opacity-0 group-hover:opacity-100 transition-opacity"})]})}function Se({detail:t,selectedSpanId:n,onSelectSpan:s,theme:u}){const{t:o}=_(),a=u==="dark",i=f.useMemo(()=>le(t.spans),[t.spans]);function p(c,g,b){var z;const h=c.span,M=$e[h.type]||xe,D=F[h.type]||F.custom,E=n===h.spanId,S=((z=t.bottleneck)==null?void 0:z.spanId)===h.spanId,I=g?"└── ":"├── ",A=h.status==="error",$=h.error;return e.jsxs("div",{children:[e.jsxs("div",{className:`flex items-center gap-2 py-1 px-2 rounded cursor-pointer text-sm ${E?"bg-accent-brand/10":"hover:bg-bg-hover"} ${S?"ring-1 ring-accent-yellow":""} ${A?"bg-accent-red/5":""}`,onClick:()=>s(E?null:h.spanId),children:[c.depth>0&&e.jsxs("span",{className:"text-text-tertiary font-mono text-xs whitespace-pre",children:[b,I]}),e.jsx(M,{size:14,style:{color:A?void 0:a?D.dark:D.light},className:`shrink-0 ${A?"text-accent-red":""}`}),e.jsx("span",{className:`font-medium truncate ${A?"text-accent-red":"text-text-primary"}`,children:h.name}),h.duration!=null&&e.jsx("span",{className:"text-xs text-text-tertiary shrink-0",children:P(h.duration)}),(h.type==="generation"||h.type==="response")&&(h.inputTokens||h.outputTokens)&&e.jsxs("span",{className:"text-xs text-accent-purple shrink-0",children:[h.inputTokens||0,"→",h.outputTokens||0," tok"]}),h.model&&e.jsxs("span",{className:"text-xs text-text-tertiary shrink-0",children:["(",h.model,")"]}),A&&e.jsx("span",{className:"text-xs font-medium text-accent-red shrink-0",children:"error"}),S&&e.jsx("span",{className:"text-xs text-accent-yellow shrink-0",children:o("traces.bottleneck")})]}),A&&$&&e.jsx("div",{className:"ml-8 px-2 py-1 text-xs text-accent-red bg-accent-red/5 rounded cursor-pointer",style:{paddingLeft:(c.depth>0?b.length*6+28:8)+24},onClick:()=>s(h.spanId),children:$.length>200?$.substring(0,200)+"...":$}),c.children.length>0&&e.jsx("div",{className:"ml-2",children:c.children.map((L,d)=>p(L,d===c.children.length-1,b+(g?" ":"│ ")))})]},h.spanId)}return i.length?e.jsx("div",{className:"space-y-0.5",children:i.map((c,g)=>p(c,g===i.length-1,""))}):e.jsx("div",{className:"text-sm text-text-tertiary py-8 text-center",children:o("traces.noSpans")})}function St(){var me;const{t}=_(),n=Ce(j=>j.resolved),{traces:s,loading:u,error:o,selectedTraceId:a,traceDetail:i,detailLoading:p,selectedSpanId:c,workerPid:g,filterSessionId:b,statusFilter:h,fetchTraces:M,selectSpan:D,setWorkerPid:E,setFilterSessionId:S,setStatusFilter:I,clearTraces:A,fetchTraceDetail:$}=tt(),{workers:z,fetchWorkers:L}=He(),{sessionId:d}=Oe(),[k,N]=f.useState("list"),[R,X]=f.useState("timeline"),[O,V]=f.useState(!1),U="traces-panel-ratio",[W,Z]=f.useState(()=>{const j=localStorage.getItem(U);return j?parseFloat(j):.6}),K=f.useCallback(j=>{Z(j),localStorage.setItem(U,String(j))},[]);f.useEffect(()=>{M(),L()},[M,L]);const J=f.useCallback(j=>{$(j),N("detail")},[$]),Q=f.useCallback(()=>{N("list"),D(null)},[D]),ee=f.useCallback(()=>{k==="detail"&&a?$(a):M()},[k,a,M,$]),r=f.useMemo(()=>s.filter(j=>j.category!=="auxiliary"),[s]),y=f.useMemo(()=>s.filter(j=>j.category==="auxiliary"),[s]),w=f.useMemo(()=>s.filter(j=>j.status==="error"||(j.errorCount||0)>0).length,[s]);if(k==="list")return e.jsxs("div",{className:"flex-1 overflow-auto p-4 md:p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx(Ie,{size:20,className:"text-text-secondary"}),e.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:t("traces.title")}),e.jsx("div",{className:"flex-1"}),e.jsx(ft,{value:h,onChange:I}),d&&e.jsxs("select",{value:b||"",onChange:j=>S(j.target.value||null),className:"px-2 py-1 rounded-md border border-border-default bg-bg-primary text-text-primary text-xs",children:[e.jsx("option",{value:"",children:t("traces.allSessions")}),e.jsxs("option",{value:d,children:[d.substring(0,8),"... (",t("traces.current"),")"]})]}),z.length>1&&e.jsx(st,{workers:z,selectedPid:g,onSelect:E}),e.jsx(de,{icon:ge,title:t("traces.refresh"),onClick:ee,spin:u}),s.length>0&&e.jsx(de,{icon:Pe,title:t("traces.clear"),onClick:()=>{confirm(t("traces.clearConfirm"))&&A()},danger:!0})]}),o&&e.jsx("div",{className:"mb-4 px-3 py-2 rounded-lg bg-accent-red/10 text-accent-red text-sm",children:o}),h!=="error"&&w>0&&e.jsxs("button",{onClick:()=>I("error"),className:"mb-3 w-full flex items-center gap-2 px-3 py-2 rounded-lg border border-accent-red/30 bg-accent-red/5 text-left hover:bg-accent-red/10 transition-colors",children:[e.jsx(te,{size:14,className:"text-accent-red shrink-0"}),e.jsx("span",{className:"text-sm text-accent-red font-medium",children:t("traces.errorBanner").replace("{count}",String(w))}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"text-xs text-accent-red opacity-70",children:t("traces.errorBannerCta")})]}),!u&&!s.length&&!o&&e.jsx("div",{className:"text-center py-16 text-text-tertiary text-sm",children:t(h==="error"?"traces.noErrors":"traces.noData")}),e.jsx("div",{className:"space-y-1",children:r.map(j=>e.jsx(we,{trace:j,onClick:()=>J(j.traceId)},j.traceId))}),y.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsxs("button",{onClick:()=>V(!O),className:"flex items-center gap-1.5 text-xs text-text-tertiary hover:text-text-secondary mb-1",children:[O?e.jsx(Te,{size:12}):e.jsx(ue,{size:12}),e.jsx("span",{children:t("traces.auxiliaryCount").replace("{count}",String(y.length))})]}),O&&e.jsx("div",{className:"space-y-1 opacity-70",children:y.map(j=>e.jsx(we,{trace:j,onClick:()=>J(j.traceId)},j.traceId))})]})]});const m=i;if(!m)return e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center gap-4",children:p?e.jsx("div",{className:"text-text-tertiary text-sm",children:t("traces.loading")}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-text-tertiary text-sm",children:t("traces.noData")}),e.jsx("button",{onClick:Q,className:"px-4 py-2 rounded-lg border border-border-default text-text-secondary text-sm hover:bg-bg-hover",children:t("traces.back")})]})});const T=m.trace,v=m.spans,l=T.modelInfo,x=xt(v),C=(l==null?void 0:l.totalInputTokens)||x.totalInputTokens,Y=(l==null?void 0:l.totalOutputTokens)||x.totalOutputTokens,H=(me=l==null?void 0:l.models)!=null&&me.length?l.models:x.models,se=l!=null&&l.totalInputTokens&&l.totalCachedTokens?l.totalCachedTokens/l.totalInputTokens*100:x.cacheHitRate,he=(l==null?void 0:l.callCount)||x.generationCount;return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex-none border-b border-border-default bg-bg-primary px-4 py-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:Q,className:"p-1 rounded hover:bg-bg-hover text-text-tertiary",children:e.jsx(We,{size:16})}),e.jsx("span",{className:"font-medium text-text-primary truncate",children:T.prompt||T.name}),e.jsx("div",{className:"flex-1"}),e.jsx(re,{color:Me(T.status),children:t(De(T.status))}),m.errorSummary&&m.errorSummary.totalErrors>0&&e.jsxs("button",{onClick:()=>{var fe;const j=(fe=m.errorSummary)==null?void 0:fe.firstErrorSpanId;j&&(D(j),X("tree"))},className:"shrink-0 inline-flex items-center gap-1 text-xs px-2 py-0.5 rounded bg-accent-red/10 text-accent-red font-medium hover:bg-accent-red/20 transition-colors",title:t("traces.jumpToFirstError"),children:[e.jsx(te,{size:12}),m.errorSummary.totalErrors," ",t("traces.errors")]}),e.jsx(de,{icon:ge,title:t("traces.refresh"),onClick:ee,spin:p})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-5 gap-y-1 mt-2 text-xs",children:[e.jsx(G,{label:t("traces.duration"),value:T.duration!=null?P(T.duration):"--"}),e.jsx(G,{label:"Spans",value:String(T.spanCount||0)}),C+Y>0&&e.jsx(G,{label:"Tokens",value:`${ae(C)} in / ${ae(Y)} out`}),C>0&&e.jsx(G,{label:"Cache",value:`${se.toFixed(0)}%`,accent:se>0}),H.length>0&&e.jsx(G,{label:t("traces.spanDetail.model"),value:H.join(", ")}),x.toolCount>0&&e.jsx(G,{label:"Tools",value:`${x.toolCount}${x.errorCount>0?` (${x.errorCount} err)`:""}`}),he>0&&e.jsx(G,{label:"LLM",value:t("traces.llmCalls").replace("{count}",String(he))})]}),m.errorSummary&&m.errorSummary.totalErrors>0&&e.jsx(ht,{summary:m.errorSummary,onJump:j=>{D(j),X("tree")}}),e.jsxs("div",{className:"flex items-center gap-1 mt-2 overflow-x-auto",children:[["timeline","tree","flame","graph"].map(j=>e.jsx("button",{onClick:()=>X(j),className:`px-3 py-1 rounded-md text-xs font-medium transition-colors whitespace-nowrap ${R===j?"bg-accent-brand/10 text-accent-brand":"text-text-tertiary hover:text-text-primary hover:bg-bg-hover"}`,children:t(`traces.tab.${j}`)},j)),e.jsx("div",{className:"flex-1"}),e.jsx("div",{className:"hidden md:flex",children:e.jsx(nt,{theme:n})})]})]}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx("div",{className:"h-full flex flex-col",children:c?e.jsxs(Be,{direction:"vertical",ratio:W,onRatioChange:K,children:[e.jsxs("div",{className:"w-full h-full overflow-auto p-2 md:p-4",children:[R==="timeline"&&e.jsx(Ne,{detail:m,selectedSpanId:c,onSelectSpan:D,theme:n}),R==="tree"&&e.jsx(Se,{detail:m,selectedSpanId:c,onSelectSpan:D,theme:n}),R==="flame"&&e.jsx(ve,{detail:m,selectedSpanId:c,onSelectSpan:D,theme:n}),R==="graph"&&e.jsx(ke,{detail:m,selectedSpanId:c,onSelectSpan:D,theme:n})]}),e.jsx("div",{className:"w-full h-full overflow-auto",children:e.jsx(mt,{span:m.spans.find(j=>j.spanId===c)||null,onClose:()=>D(null)})})]}):e.jsxs("div",{className:"flex-1 overflow-auto p-2 md:p-4",children:[R==="timeline"&&e.jsx(Ne,{detail:m,selectedSpanId:c,onSelectSpan:D,theme:n}),R==="tree"&&e.jsx(Se,{detail:m,selectedSpanId:c,onSelectSpan:D,theme:n}),R==="flame"&&e.jsx(ve,{detail:m,selectedSpanId:c,onSelectSpan:D,theme:n}),R==="graph"&&e.jsx(ke,{detail:m,selectedSpanId:c,onSelectSpan:D,theme:n})]})})})]})}export{St as TracesView};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{a as o,j as e}from"./markdown-
|
|
1
|
+
import{a as o,j as e}from"./markdown-CP9awqWt.js";import{u as p,af as S,aH as y,ab as L,L as g,b as R,as as $,bl as D,F as W,aF as E,aI as I}from"./index-CBmymKHy.js";import{u as P,g as F}from"./worker-store-qfd_N8Zm.js";import{S as v}from"./server-D4446JKI.js";import{E as j}from"./external-link-Ea1Nar0e.js";import{P as M}from"./power-BJk8Xq9U.js";import"./vendor-iLJwFVtf.js";function A(t){try{const s=new URL(t),a=window.location.hostname;return s.hostname===a?t:(s.hostname=a,s.toString())}catch(s){return console.warn("Failed to resolve worker URL, using original:",t,s),t}}const K=1e4;function Z(){const{t}=p(),{workers:s,daemon:a,loading:r,error:n,fetchWorkers:i,fetchDaemonStatus:l,killWorker:c,startDaemon:d,stopDaemon:u,restartDaemon:f}=P();o.useEffect(()=>{i(),l();const x=setInterval(()=>{i(),l()},K);return()=>clearInterval(x)},[i,l]);const k=o.useCallback(()=>{i(),l()},[i,l]),w=o.useCallback(x=>{window.location.hash=`#/logs?worker=${x.pid}`},[]),[m,h]=o.useState(null),C=o.useCallback(async x=>{h(x)},[]),z=o.useCallback(async()=>{m&&(await c(String(m.pid)),h(null))},[m,c]);return e.jsxs("div",{className:"h-full min-h-0 flex-1 overflow-auto p-4 md:p-6",children:[m&&e.jsx(S,{title:t("workers.action.kill.confirm"),danger:!0,onConfirm:z,onCancel:()=>h(null)}),e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{size:20,className:"text-accent-brand"}),e.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:t("workers.title")})]}),e.jsxs("button",{onClick:k,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm text-text-secondary
|
|
2
2
|
hover:text-text-primary hover:bg-bg-hover rounded-lg transition-colors`,title:t("workers.refresh"),children:[e.jsx(L,{size:14,className:r?"animate-spin":""}),e.jsx("span",{children:t("workers.refresh")})]})]}),n&&e.jsx("div",{className:"mb-4 p-3 rounded-xl error-banner text-sm",children:n}),e.jsx(U,{daemon:a,onStart:()=>d(),onStop:u,onRestart:f}),e.jsx(_,{workers:s,onViewLogs:w,onKill:C})]})}function U({daemon:t,onStart:s,onStop:a,onRestart:r}){const{t:n}=p(),i=(t==null?void 0:t.status)==="running",[l,c]=o.useState(null),d=o.useCallback(async(u,f)=>{c(u);try{await f()}finally{c(null)}},[]);return e.jsx("div",{className:`bg-bg-secondary rounded-xl p-4 md:p-5 border mb-6 transition-colors worker-card-hover ${i?"border-green-400/40 ring-1 ring-green-400/10":"border-border-default"}`,children:e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{size:18,className:i?"text-green-500":"text-text-tertiary"}),e.jsx("span",{className:"text-base font-semibold text-text-primary",children:n("workers.daemon")}),(t==null?void 0:t.pid)&&e.jsxs("span",{className:"text-xs text-text-tertiary font-mono bg-bg-tertiary px-2 py-0.5 rounded-md ml-2 border border-border-default/50",children:["PID ",t.pid]})]}),e.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"relative flex h-2.5 w-2.5",children:[i&&e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"}),e.jsx("span",{className:`relative inline-flex rounded-full h-2.5 w-2.5 ${i?"bg-green-500":"bg-gray-400"}`})]}),e.jsx("span",{className:"text-sm font-medium text-text-secondary",children:n(i?"workers.daemon.running":"workers.daemon.stopped")})]}),(t==null?void 0:t.endpoint)&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-border-primary",children:"|"}),e.jsx(j,{size:14,className:"text-text-tertiary ml-1"}),e.jsx("a",{href:t.endpoint,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-accent-brand hover:underline",children:t.endpoint})]})]})]}),e.jsx("div",{className:"flex items-center gap-2 mt-2 md:mt-0",children:i?e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>d("stop",a),disabled:l!==null,className:`flex items-center gap-1.5 px-4 py-2 text-sm font-medium rounded-lg border border-border-default
|
|
3
3
|
bg-bg-primary text-text-secondary daemon-stop-btn transition-all disabled:opacity-50`,children:[l==="stop"?e.jsx(g,{size:14,className:"animate-spin"}):e.jsx(R,{size:14}),n("workers.daemon.stop")]}),e.jsxs("button",{onClick:()=>d("restart",r),disabled:l!==null,className:`flex items-center gap-1.5 px-4 py-2 text-sm font-medium rounded-lg border border-border-default
|
|
4
4
|
bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-bg-hover transition-all disabled:opacity-50`,children:[l==="restart"?e.jsx(g,{size:14,className:"animate-spin"}):e.jsx($,{size:14}),n("workers.daemon.restart")]})]}):e.jsxs("button",{onClick:()=>d("start",s),disabled:l!==null,className:`flex items-center gap-1.5 px-4 py-2 text-sm font-medium rounded-lg shadow-sm
|
|
5
|
-
daemon-start-btn transition-all disabled:opacity-70`,children:[l==="start"?e.jsx(g,{size:14,className:"animate-spin"}):e.jsx(D,{size:14}),n(l==="start"?"workers.daemon.starting":"workers.daemon.start")]})})]})})}function _({workers:t,onViewLogs:s,onKill:a}){const{t:r}=p();return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(y,{size:18,className:"text-text-secondary"}),e.jsxs("h2",{className:"text-base font-medium text-text-primary",children:[r("workers.active")," (",t.length,")"]})]}),t.length===0?e.jsx("div",{className:"text-center py-12 text-text-tertiary",children:r("workers.empty")}):e.jsx("div",{className:"space-y-4",children:[...t].sort((n,i)=>(i.isCurrent?1:0)-(n.isCurrent?1:0)).map(n=>e.jsx(V,{worker:n,onViewLogs:s,onKill:a},`${n.pid}-${n.hostname}`))})]})}const T={interactive:"kind-badge kind-badge-blue",bg:"kind-badge kind-badge-purple",daemon:"kind-badge kind-badge-green","daemon-worker":"kind-badge kind-badge-orange"};function V({worker:t,onViewLogs:s,onKill:a}){const{t:r}=p();return e.jsxs("div",{className:"group bg-bg-secondary rounded-xl p-4 md:p-5 border border-border-default transition-colors worker-card-hover",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:`inline-block px-2.5 py-0.5 text-xs font-medium rounded-md ${T[t.kind]||"bg-gray-100 text-gray-600"}`,children:t.kind}),t.isCurrent&&e.jsx("span",{className:"text-[10px] uppercase font-bold tracking-wider px-1.5 py-0.5 rounded current-badge",children:"current"}),e.jsxs("span",{className:"text-xs text-text-tertiary font-mono",children:["PID ",t.pid]}),t.name&&t.name!=="-"&&e.jsx("span",{className:"text-sm font-medium text-text-primary",children:t.name})]}),e.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[t.url&&e.jsx("a",{href:N(t),target:"_blank",rel:"noopener noreferrer",className:"p-1.5 rounded-md text-text-tertiary hover:text-accent-brand hover:bg-bg-hover transition-colors",title:r("workers.action.open"),children:e.jsx(j,{size:14})}),!t.manual&&e.jsx("button",{onClick:()=>s(t),className:"p-1.5 rounded-md text-text-tertiary hover:text-text-primary hover:bg-bg-hover transition-colors",title:r("workers.action.logs"),children:e.jsx(
|
|
5
|
+
daemon-start-btn transition-all disabled:opacity-70`,children:[l==="start"?e.jsx(g,{size:14,className:"animate-spin"}):e.jsx(D,{size:14}),n(l==="start"?"workers.daemon.starting":"workers.daemon.start")]})})]})})}function _({workers:t,onViewLogs:s,onKill:a}){const{t:r}=p();return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(y,{size:18,className:"text-text-secondary"}),e.jsxs("h2",{className:"text-base font-medium text-text-primary",children:[r("workers.active")," (",t.length,")"]})]}),t.length===0?e.jsx("div",{className:"text-center py-12 text-text-tertiary",children:r("workers.empty")}):e.jsx("div",{className:"space-y-4",children:[...t].sort((n,i)=>(i.isCurrent?1:0)-(n.isCurrent?1:0)).map(n=>e.jsx(V,{worker:n,onViewLogs:s,onKill:a},`${n.pid}-${n.hostname}`))})]})}const T={interactive:"kind-badge kind-badge-blue",bg:"kind-badge kind-badge-purple",daemon:"kind-badge kind-badge-green","daemon-worker":"kind-badge kind-badge-orange"};function V({worker:t,onViewLogs:s,onKill:a}){const{t:r}=p();return e.jsxs("div",{className:"group bg-bg-secondary rounded-xl p-4 md:p-5 border border-border-default transition-colors worker-card-hover",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:`inline-block px-2.5 py-0.5 text-xs font-medium rounded-md ${T[t.kind]||"bg-gray-100 text-gray-600"}`,children:t.kind}),t.isCurrent&&e.jsx("span",{className:"text-[10px] uppercase font-bold tracking-wider px-1.5 py-0.5 rounded current-badge",children:"current"}),e.jsxs("span",{className:"text-xs text-text-tertiary font-mono",children:["PID ",t.pid]}),t.name&&t.name!=="-"&&e.jsx("span",{className:"text-sm font-medium text-text-primary",children:t.name})]}),e.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[t.url&&e.jsx("a",{href:N(t),target:"_blank",rel:"noopener noreferrer",className:"p-1.5 rounded-md text-text-tertiary hover:text-accent-brand hover:bg-bg-hover transition-colors",title:r("workers.action.open"),children:e.jsx(j,{size:14})}),!t.manual&&e.jsx("button",{onClick:()=>s(t),className:"p-1.5 rounded-md text-text-tertiary hover:text-text-primary hover:bg-bg-hover transition-colors",title:r("workers.action.logs"),children:e.jsx(W,{size:14})}),!t.isCurrent&&e.jsx("button",{onClick:()=>a(t),className:"p-1.5 rounded-md text-text-tertiary daemon-kill-btn transition-colors",title:r("workers.action.kill"),children:e.jsx(M,{size:14})})]})]}),e.jsxs("div",{className:"flex flex-col md:flex-row md:items-start justify-between gap-3 md:gap-6",children:[e.jsxs("div",{className:"flex flex-col gap-1.5 flex-1 min-w-0",children:[e.jsx(E,{path:t.cwd,displayMode:"basename",className:"text-[13px] text-text-secondary font-mono truncate max-w-full"}),t.url&&e.jsxs("a",{href:N(t),target:"_blank",rel:"noopener noreferrer",className:"text-xs text-text-tertiary hover:text-accent-brand truncate inline-flex items-center gap-1",title:t.url,children:[e.jsx(j,{size:10,className:"flex-none"}),t.url]})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-8 gap-y-3 shrink-0",children:[e.jsx(b,{icon:e.jsx(I,{size:14}),label:"Started",value:q(t.startedAt)}),t.version&&e.jsx(b,{icon:e.jsx(y,{size:14}),label:"Version",value:t.version}),t.hostname&&e.jsx(b,{icon:e.jsx(v,{size:14}),label:"Host",value:t.hostname})]})]})]})}function b({icon:t,label:s,value:a,valueClassName:r}){return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-text-tertiary",children:[t,e.jsx("span",{className:"text-[11px] font-medium uppercase tracking-wider",children:s})]}),e.jsx("div",{className:`text-sm font-semibold text-text-primary ${r||""}`,children:a})]})}function H(t){try{const s=new URL(t).hostname;return s==="127.0.0.1"||s==="localhost"||s==="::1"}catch{return!1}}function N(t){if(!t.url)return"#";const s=A(t.url);if(H(s))return s;const a=F(String(t.pid));if(!a)return s;try{const r=new URL(s);return r.searchParams.set("password",a),r.toString()}catch(r){return console.warn("Failed to build worker URL with password:",s,r),s}}function q(t){const s=Math.floor((Date.now()-t)/1e3);if(s<60)return`${s}s ago`;const a=Math.floor(s/60);if(a<60)return`${a}m ago`;const r=Math.floor(a/60);return r<24?`${r}h ${a%60}m`:`${Math.floor(r/24)}d ${r%24}h`}export{Z as WorkersView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{e as z,f as L,a as d,h as B}from"./index-
|
|
1
|
+
import{e as z,f as L,a as d,h as B}from"./index-CBmymKHy.js";const E=400,Z=300,A=200,G=150,N=.1,P=5,a=20,R=3,W=8,X=10,D=32,b=D;function M(){return B({"Content-Type":"application/json"})}async function C(i){try{const o=await fetch(`/api/v1/pty/${i}`,{headers:M()});if(!o.ok)return null;const n=await o.json(),e=n.data??n;return typeof(e==null?void 0:e.cwd)=="string"?e.cwd:null}catch{return null}}function _(i){const o=Object.values(i);if(o.length===0)return;const e={...d.getState().panes};let t=!1;for(const s of o){const r=e[s.paneId];r?s.ptySessionId&&r.ptySessionId!==s.ptySessionId&&(e[s.paneId]={...r,ptySessionId:s.ptySessionId},t=!0):(e[s.paneId]={id:s.paneId,ptySessionId:s.ptySessionId??null,ptyStatus:"disconnected",errorMessage:null},t=!0)}t&&d.setState({panes:e})}const O=z()(L((i,o)=>({viewport:{panX:0,panY:0,zoom:1},tiles:{},nextZIndex:1,selectedTileIds:[],setViewport:n=>{i({viewport:n})},addTile:()=>{const n=`tile-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,e=`canvas-pane-${n}`,{nextZIndex:t,viewport:s}=o(),r=s.zoom||1,l=(-s.panX+window.innerWidth/2)/r-E/2,c=(-s.panY+window.innerHeight/2)/r-Z/2,S=Math.round(l/a)*a,w=Math.round(c/a)*a,I={id:n,type:"terminal",x:S,y:w,width:E,height:Z,zIndex:t,paneId:e,windowState:"normal",ptySessionId:null,cwd:null},x=d.getState();if(!x.panes[e]){const p={...x.panes,[e]:{id:e,ptySessionId:null,ptyStatus:"disconnected",errorMessage:null}};d.setState({panes:p})}return i(p=>({tiles:{...p.tiles,[n]:I},nextZIndex:p.nextZIndex+1})),n},duplicateTile:n=>{var T,y,v,g;const e=o().tiles[n];if(!e)return null;const t=`tile-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,s=`canvas-pane-${t}`,{nextZIndex:r}=o(),l=((T=e.prevBounds)==null?void 0:T.width)??e.width,c=((y=e.prevBounds)==null?void 0:y.height)??e.height,S=((v=e.prevBounds)==null?void 0:v.x)??e.x,w=((g=e.prevBounds)==null?void 0:g.y)??e.y,I=a*2,x=Math.round((S+I)/a)*a,p=Math.round((w+I)/a)*a,H={id:t,type:"terminal",x,y:p,width:l,height:c,zIndex:r,paneId:s,windowState:"normal",ptySessionId:null,cwd:e.cwd??null},f=d.getState();f.panes[s]||d.setState({panes:{...f.panes,[s]:{id:s,ptySessionId:null,ptyStatus:"disconnected",errorMessage:null}}}),i(u=>({tiles:{...u.tiles,[t]:H},nextZIndex:u.nextZIndex+1}));const h=d.getState().panes[e.paneId],m=h==null?void 0:h.ptySessionId;return m&&C(m).then(u=>{u&&(o().updateTile(e.id,{cwd:u}),o().updateTile(t,{cwd:u}))}),t},removeTile:n=>{const e=o().tiles[n];if(e){const t=d.getState(),s=t.panes[e.paneId];if(s!=null&&s.ptySessionId&&fetch(`/api/v1/pty/${s.ptySessionId}`,{method:"DELETE",headers:M()}).catch(()=>{}),t.panes[e.paneId]){const{[e.paneId]:r,...l}=t.panes;d.setState({panes:l})}}i(t=>{const{[n]:s,...r}=t.tiles;return{tiles:r,selectedTileIds:t.selectedTileIds.filter(l=>l!==n)}})},updateTile:(n,e)=>{i(t=>{const s=t.tiles[n];return s?{tiles:{...t.tiles,[n]:{...s,...e}}}:t})},selectTile:n=>i({selectedTileIds:[n]}),deselectAll:()=>i({selectedTileIds:[]}),selectTiles:n=>i({selectedTileIds:n}),bringToFront:n=>{i(e=>{const t=e.tiles[n];return t?{tiles:{...e.tiles,[n]:{...t,zIndex:e.nextZIndex}},nextZIndex:e.nextZIndex+1}:e})},maximizeTile:n=>{i(e=>{const t=e.tiles[n];if(!t)return e;const s=t.windowState==="normal"?{x:t.x,y:t.y,width:t.width,height:t.height}:t.prevBounds;return{tiles:{...e.tiles,[n]:{...t,windowState:"maximized",prevBounds:s,zIndex:e.nextZIndex}},nextZIndex:e.nextZIndex+1}})},minimizeTile:n=>{i(e=>{const t=e.tiles[n];if(!t)return e;const s=t.windowState==="normal"?{x:t.x,y:t.y,width:t.width,height:t.height}:t.prevBounds;return{tiles:{...e.tiles,[n]:{...t,height:b,windowState:"minimized",prevBounds:s}}}})},restoreTile:n=>{i(e=>{const t=e.tiles[n];return!t||!t.prevBounds?t?{tiles:{...e.tiles,[n]:{...t,windowState:"normal"}}}:e:{tiles:{...e.tiles,[n]:{...t,x:t.prevBounds.x,y:t.prevBounds.y,width:t.prevBounds.width,height:t.prevBounds.height,windowState:"normal",prevBounds:void 0}}}})},toggleMaximize:n=>{const e=o().tiles[n];e&&(e.windowState==="maximized"?o().restoreTile(n):o().maximizeTile(n))},toggleMinimize:n=>{const e=o().tiles[n];e&&(e.windowState==="minimized"?o().restoreTile(n):o().minimizeTile(n))},setTilePty:(n,e,t)=>{let s=null;if(i(r=>{const l=r.tiles[n];if(!l)return r;s=l.paneId;const c={...l,ptySessionId:e};return t!==void 0&&(c.cwd=t),{tiles:{...r.tiles,[n]:c}}}),s){const r=d.getState(),l=r.panes[s];l&&l.ptySessionId!==e&&d.setState({panes:{...r.panes,[s]:{...l,ptySessionId:e}}})}},loadFromStorage:()=>{}}),{namespace:"canvas",fields:["viewport","tiles","nextZIndex"],scope:"workspace",debounceMs:1e3,onLoad:(i,o)=>{const n={};i.viewport&&(n.viewport=i.viewport),i.tiles&&(n.tiles=i.tiles),i.nextZIndex!==void 0&&(n.nextZIndex=i.nextZIndex),Object.keys(n).length>0&&(o(n),n.tiles&&_(n.tiles))}}));_(O.getState().tiles);export{R as C,a as G,N as M,W as R,X as S,D as T,P as a,A as b,G as c,O as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c,l as s}from"./editor.main-
|
|
1
|
+
import{c,l as s}from"./editor.main-q4R8cbC1.js";import{C as h,H as u,D as p,a as m,R as f,b as _,c as w,d as k,F as v,e as D,S as P,f as R,g as I}from"./lspLanguageFeatures-BA4h_1Zp.js";import{h as U,i as T,j as x,t as j,k as M}from"./lspLanguageFeatures-BA4h_1Zp.js";import"./index-CBmymKHy.js";import"./markdown-CP9awqWt.js";import"./vendor-iLJwFVtf.js";const C=120*1e3;class A{constructor(n){this._defaults=n,this._worker=null,this._client=null,this._idleCheckInterval=window.setInterval(()=>this._checkIfIdle(),30*1e3),this._lastUsedTime=0,this._configChangeListener=this._defaults.onDidChange(()=>this._stopWorker())}_stopWorker(){this._worker&&(this._worker.dispose(),this._worker=null),this._client=null}dispose(){clearInterval(this._idleCheckInterval),this._configChangeListener.dispose(),this._stopWorker()}_checkIfIdle(){if(!this._worker)return;Date.now()-this._lastUsedTime>C&&this._stopWorker()}_getClient(){return this._lastUsedTime=Date.now(),this._client||(this._worker=c({moduleId:"vs/language/css/cssWorker",createWorker:()=>new Worker(new URL("/assets/css.worker-B4z49cGk.js",import.meta.url),{type:"module"}),label:this._defaults.languageId,createData:{options:this._defaults.options,languageId:this._defaults.languageId}}),this._client=this._worker.getProxy()),this._client}getLanguageServiceWorker(...n){let e;return this._getClient().then(a=>{e=a}).then(a=>{if(this._worker)return this._worker.withSyncedResources(n)}).then(a=>e)}}function b(o){const n=[],e=[],a=new A(o);n.push(a);const r=(...t)=>a.getLanguageServiceWorker(...t);function l(){const{languageId:t,modeConfiguration:i}=o;g(e),i.completionItems&&e.push(s.registerCompletionItemProvider(t,new h(r,["/","-",":"]))),i.hovers&&e.push(s.registerHoverProvider(t,new u(r))),i.documentHighlights&&e.push(s.registerDocumentHighlightProvider(t,new p(r))),i.definitions&&e.push(s.registerDefinitionProvider(t,new m(r))),i.references&&e.push(s.registerReferenceProvider(t,new f(r))),i.documentSymbols&&e.push(s.registerDocumentSymbolProvider(t,new _(r))),i.rename&&e.push(s.registerRenameProvider(t,new w(r))),i.colors&&e.push(s.registerColorProvider(t,new k(r))),i.foldingRanges&&e.push(s.registerFoldingRangeProvider(t,new v(r))),i.diagnostics&&e.push(new D(t,r,o.onDidChange)),i.selectionRanges&&e.push(s.registerSelectionRangeProvider(t,new P(r))),i.documentFormattingEdits&&e.push(s.registerDocumentFormattingEditProvider(t,new R(r))),i.documentRangeFormattingEdits&&e.push(s.registerDocumentRangeFormattingEditProvider(t,new I(r)))}return l(),n.push(d(e)),d(n)}function d(o){return{dispose:()=>g(o)}}function g(o){for(;o.length;)o.pop().dispose()}export{h as CompletionAdapter,m as DefinitionAdapter,D as DiagnosticsAdapter,k as DocumentColorAdapter,R as DocumentFormattingEditProvider,p as DocumentHighlightAdapter,U as DocumentLinkAdapter,I as DocumentRangeFormattingEditProvider,_ as DocumentSymbolAdapter,v as FoldingRangeAdapter,u as HoverAdapter,f as ReferenceAdapter,w as RenameAdapter,P as SelectionRangeAdapter,A as WorkerManager,T as fromPosition,x as fromRange,b as setupMode,j as toRange,M as toTextEdit};
|