@tencent-ai/codebuddy-code 2.134.0-dev.c172de2.202608121546 → 2.135.0

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/codebuddy-headless.js +118 -118
  3. package/dist/codebuddy.js +80 -80
  4. package/dist/web-ui/assets/{CanvasPaneStandaloneView-DgMTB0Mb.js → CanvasPaneStandaloneView-DeJD7bJv.js} +1 -1
  5. package/dist/web-ui/assets/{CanvasView-3QngUA7x.js → CanvasView-V2DzC5ig.js} +1 -1
  6. package/dist/web-ui/assets/{DocsView-BoczVSee.js → DocsView-BwjfIgJw.js} +1 -1
  7. package/dist/web-ui/assets/EditorView-DEmkNiHo.js +95 -0
  8. package/dist/web-ui/assets/{KeybindingsView-BiwRw-4R.js → KeybindingsView-CLga9s1T.js} +1 -1
  9. package/dist/web-ui/assets/{LogsView-B8XmcVTr.js → LogsView-Bd11aAMW.js} +2 -2
  10. package/dist/web-ui/assets/{MetricsView-lzImG0av.js → MetricsView-Byap1DzP.js} +4 -4
  11. package/dist/web-ui/assets/{RemoteControlView-Bv4Ym4nD.js → RemoteControlView-BqiUehl-.js} +4 -4
  12. package/dist/web-ui/assets/StatsView-Cr230NV8.js +12 -0
  13. package/dist/web-ui/assets/{TracesView-kF2Bi6Uu.js → TracesView-bKA1QIAI.js} +3 -3
  14. package/dist/web-ui/assets/{WorkersView-VzjZfrZu.js → WorkersView-DY0kEifB.js} +4 -4
  15. package/dist/web-ui/assets/{canvas-store-CX4TeurF.js → canvas-store-hkRzwbw-.js} +1 -1
  16. package/dist/web-ui/assets/{cssMode-CEfvy9LI.js → cssMode-DVvwMwN6.js} +1 -1
  17. package/dist/web-ui/assets/{editor.main-BeJ0HdEs.js → editor.main-vO8swxPL.js} +3 -3
  18. package/dist/web-ui/assets/{freemarker2-DnkFzY6t.js → freemarker2-BY-2-rq2.js} +1 -1
  19. package/dist/web-ui/assets/{handlebars-1NAOMqYh.js → handlebars-D_vy9gpm.js} +1 -1
  20. package/dist/web-ui/assets/{html-BP0ejrFF.js → html-GglpzIxT.js} +1 -1
  21. package/dist/web-ui/assets/{htmlMode-Djp_2npQ.js → htmlMode-DUBQpmgz.js} +1 -1
  22. package/dist/web-ui/assets/index-C74qhjeJ.css +32 -0
  23. package/dist/web-ui/assets/{index-DNUXcSh8.js → index-DC-fErwI.js} +216 -216
  24. package/dist/web-ui/assets/{javascript-J-jeSPRJ.js → javascript-C9og_HZL.js} +1 -1
  25. package/dist/web-ui/assets/{jsonMode-DwxnBMDi.js → jsonMode-Cs25xE2e.js} +1 -1
  26. package/dist/web-ui/assets/{liquid-p7dNfV0Z.js → liquid-BQ5j4ocH.js} +1 -1
  27. package/dist/web-ui/assets/{lspLanguageFeatures-DEpBaaQs.js → lspLanguageFeatures-k6vDy77A.js} +1 -1
  28. package/dist/web-ui/assets/{mdx-QX-6YS-2.js → mdx-BnZXGp9g.js} +1 -1
  29. package/dist/web-ui/assets/{minus-CjhfXa84.js → minus-CND1LKfM.js} +1 -1
  30. package/dist/web-ui/assets/{python-DXTI7QZI.js → python-B65aRwBG.js} +1 -1
  31. package/dist/web-ui/assets/{razor-BwsYliyu.js → razor-OgH9GFyd.js} +1 -1
  32. package/dist/web-ui/assets/{server-DTGjlz_2.js → server-C_x9ee7t.js} +1 -1
  33. package/dist/web-ui/assets/{tsMode-CAro1DF_.js → tsMode-DQdvo31S.js} +1 -1
  34. package/dist/web-ui/assets/{typescript-MzPA2Aci.js → typescript-B4pz8IUO.js} +1 -1
  35. package/dist/web-ui/assets/{worker-store-CeRgJcBb.js → worker-store-CC1BvZFl.js} +1 -1
  36. package/dist/web-ui/assets/{xml-_dZXiOu_.js → xml-BWp6ggOb.js} +1 -1
  37. package/dist/web-ui/assets/{yaml-BrzS0hUR.js → yaml-26TypAAl.js} +1 -1
  38. package/dist/web-ui/index.html +21 -5
  39. package/dist/web-ui/sw.js +1 -1
  40. package/package.json +2 -3
  41. package/product.cloudhosted.json +2 -2
  42. package/product.internal.json +2 -2
  43. package/product.ioa.json +2 -2
  44. package/product.json +2 -2
  45. package/product.selfhosted.json +2 -2
  46. package/vendor/shim/brokered-bin/codebuddy-toybox-dispatch +32 -0
  47. package/dist/web-ui/assets/EditorView-BUsQ-90n.js +0 -90
  48. package/dist/web-ui/assets/StatsView-BWPSIETb.js +0 -12
  49. package/dist/web-ui/assets/index-Bcw4ajER.css +0 -32
@@ -1,16 +1,16 @@
1
- import{a as n,j as e}from"./markdown-DIY6o85n.js";import{c as T,u as J,q as A,as as P,x as E,h as V,ae as R,at as I,au as q,P as $,W as X,av as Y,aw as Z}from"./index-DNUXcSh8.js";import"./vendor-D35k0Cos.js";/**
1
+ import{a as n,j as e}from"./markdown-DIY6o85n.js";import{c as W,u as J,q as A,ay as P,y as E,h as V,ak as R,az as I,aA as q,P as T,Z,aB as X,aC as Y}from"./index-DC-fErwI.js";import"./vendor-D35k0Cos.js";/**
2
2
  * @license lucide-react v1.18.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const ee=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],te=T("arrow-right",ee);/**
6
+ */const ee=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],te=W("arrow-right",ee);/**
7
7
  * @license lucide-react v1.18.0 - ISC
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */const re=[["path",{d:"M9 17H7A5 5 0 0 1 7 7",key:"10o201"}],["path",{d:"M15 7h2a5 5 0 0 1 4 8",key:"1d3206"}],["line",{x1:"8",x2:"12",y1:"12",y2:"12",key:"rvw6j4"}],["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}]],L=T("link-2-off",re);/**
11
+ */const re=[["path",{d:"M9 17H7A5 5 0 0 1 7 7",key:"10o201"}],["path",{d:"M15 7h2a5 5 0 0 1 4 8",key:"1d3206"}],["line",{x1:"8",x2:"12",y1:"12",y2:"12",key:"rvw6j4"}],["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}]],L=W("link-2-off",re);/**
12
12
  * @license lucide-react v1.18.0 - ISC
13
13
  *
14
14
  * This source code is licensed under the ISC license.
15
15
  * See the LICENSE file in the root directory of this source tree.
16
- */const se=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]],oe=T("link-2",se);function xe({onNavigate:i}){const{t:r}=J(),[s,b]=n.useState(A);if(n.useEffect(()=>{const c=()=>b(A());return window.addEventListener("hashchange",c),()=>window.removeEventListener("hashchange",c)},[]),s==="add-wechat"||s!=null&&s.startsWith("rebind-wechat/")){const c=s!=null&&s.startsWith("rebind-wechat/")?s.split("/")[1]:void 0;return e.jsx(ae,{onBack:()=>P("remote-control"),t:r,existingInstanceId:c})}return s==="add-wecom"?e.jsx(ce,{onBack:()=>P("remote-control"),t:r}):e.jsx(ne,{onNavigate:i,t:r})}function ne({onNavigate:i,t:r}){const[s,b]=n.useState([]),[c,w]=n.useState(!0),[p,N]=n.useState(null),[y,g]=n.useState(null),[f,k]=n.useState(!1),[j,o]=n.useState(!1),[l,v]=n.useState(!1),x=n.useCallback(async()=>{var t,d,a;try{const u=await E("/api/v1/channels");if(u.ok){const h=await u.json(),S=((t=h.capabilities)==null?void 0:t.remoteControlEnabled)??!1;k(S),b((h.clients||[]).filter(C=>!C.hidden&&!C.instanceId.startsWith("_pending"))),o(S&&((d=h.capabilities)==null?void 0:d.canAddWechatBot)!==!1),v(S&&((a=h.capabilities)==null?void 0:a.canAddWecomBot)!==!1)}}catch{}finally{w(!1)}},[]);n.useEffect(()=>{x();const t=setInterval(x,5e3);return()=>clearInterval(t)},[x]);const m=n.useCallback(async(t,d,a)=>{const u=`${d}:${a}:${t}`;g(u),N(null);try{const h=t==="delete"?"DELETE":"POST",S=t==="delete"?`/api/v1/channels/${d}/${a}`:`/api/v1/channels/${d}/${a}/${t}`,C=await E(S,{method:h});if(!C.ok){const G=await C.json().catch(()=>({}));throw new Error(G.error||`Failed: ${C.status}`)}const K=await C.json().catch(()=>({}));if(t==="unbind"&&d==="wechat"&&K.needsQrScan){I("remote-control",`rebind-wechat/${a}`);return}await x()}catch(h){N((h==null?void 0:h.message)||"Action failed")}finally{g(null)}},[x]),F=t=>t==="connected"?"text-green-500":t==="connecting"?"text-yellow-500":t==="error"?"text-red-500":"text-text-tertiary",B=t=>r(t==="connected"?"remoteControl.connected":t==="connecting"?"remoteControl.connecting":"remoteControl.disconnected"),M=t=>t==="wechat"?e.jsx(Z,{size:18,className:"text-green-500"}):t==="wecom"?e.jsx(q,{size:18,className:"text-accent-brand"}):e.jsx(L,{size:18,className:"text-text-tertiary"}),H=t=>t==="wechat"?r("channel.wechat")+r("remoteControl.bot"):t==="wecom"?r("channel.wecom")+r("remoteControl.bot"):t,_=t=>`${H(t.clientType)} #${t.instanceId.slice(0,4)}`,D=s.filter(t=>t.clientType==="wechat"),O=s.filter(t=>t.clientType==="wecom"),z=s.filter(t=>t.clientType!=="wechat"&&t.clientType!=="wecom"),Q=j||l,U=t=>{const d=`${t.clientType}:${t.instanceId}`,a=t.status==="connected",u=y==null?void 0:y.startsWith(d);return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg bg-bg-secondary hover:bg-bg-hover transition-colors cursor-pointer",onClick:()=>{u||m(a?"stop":"start",t.clientType,t.instanceId)},children:[M(t.clientType),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-text-primary truncate",children:_(t)}),e.jsx("span",{className:`text-xs ${F(t.status)}`,children:B(t.status)})]}),e.jsxs("div",{className:"flex items-center gap-1",onClick:h=>h.stopPropagation(),children:[e.jsx("button",{className:`p-1.5 rounded-md text-text-tertiary transition-colors ${a?"hover:text-orange-500":"hover:text-green-500"} hover:bg-bg-hover`,title:r(a?"remoteControl.disconnect":"remoteControl.connect"),disabled:!!u,onClick:()=>m(a?"stop":"start",t.clientType,t.instanceId),children:a?e.jsx(L,{size:14}):e.jsx(oe,{size:14})}),a&&e.jsx("button",{className:"p-1.5 rounded-md text-text-tertiary hover:text-orange-500 hover:bg-bg-hover transition-colors",title:r("remoteControl.unbind"),disabled:!!u,onClick:()=>m("unbind",t.clientType,t.instanceId),children:e.jsx(X,{size:14})}),e.jsx("button",{className:"p-1.5 rounded-md text-text-tertiary hover:text-red-500 hover:bg-bg-hover transition-colors",title:r("remoteControl.delete"),disabled:!!u,onClick:()=>m("delete",t.clientType,t.instanceId),children:e.jsx(Y,{size:14})})]})]},d)},W=(t,d,a,u)=>e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-medium text-text-secondary mb-2",children:t}),d.length===0?e.jsx("div",{className:"py-4 text-center text-xs text-text-tertiary",children:r("remoteControl.noChannels")}):e.jsx("div",{className:"space-y-2",children:d.map(U)}),a&&e.jsxs("button",{className:"flex items-center gap-1.5 mt-2 px-3 py-1.5 text-xs text-text-tertiary hover:text-text-primary hover:bg-bg-hover rounded-md transition-colors",onClick:a,children:[e.jsx($,{size:12}),u||r("remoteControl.add")]})]});return!c&&!f?e.jsx(e.Fragment,{}):e.jsxs("div",{className:"flex flex-col h-full overflow-y-auto",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-border-primary",children:[e.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:r("remoteControl.title")}),e.jsx("p",{className:"text-sm text-text-tertiary mt-1",children:r("remoteControl.subtitle")})]}),e.jsxs("div",{className:"px-6 py-4 flex-1 space-y-6",children:[p&&e.jsx("div",{className:"p-3 rounded-lg bg-red-500/10 text-red-500 text-sm",children:p}),c?e.jsx("div",{className:"text-sm text-text-tertiary py-4",children:r("remoteControl.connecting")}):s.length===0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"py-8 text-center",children:[e.jsx(q,{size:32,className:"mx-auto mb-3 text-text-tertiary opacity-50"}),e.jsx("p",{className:"text-sm text-text-tertiary",children:r("remoteControl.noChannels")}),e.jsx("p",{className:"text-xs text-text-tertiary mt-1",children:r("remoteControl.noChannelsHint")})]}),Q&&e.jsxs("div",{className:"flex gap-3",children:[j&&e.jsxs("button",{className:"flex items-center gap-2 px-4 py-2 rounded-lg bg-bg-secondary hover:bg-bg-hover text-sm text-text-primary transition-colors border border-border-primary",onClick:()=>I("remote-control","add-wechat"),children:[e.jsx($,{size:14}),r("remoteControl.addWeChat")]}),l&&e.jsxs("button",{className:"flex items-center gap-2 px-4 py-2 rounded-lg bg-bg-secondary hover:bg-bg-hover text-sm text-text-primary transition-colors border border-border-primary",onClick:()=>I("remote-control","add-wecom"),children:[e.jsx($,{size:14}),r("remoteControl.addWeCom")]})]})]}):e.jsxs(e.Fragment,{children:[W(r("channel.wechat")+r("remoteControl.bot"),D,j?()=>I("remote-control","add-wechat"):void 0,r("remoteControl.addWeChat")),W(r("channel.wecom")+r("remoteControl.bot"),O,l?()=>I("remote-control","add-wecom"):void 0,r("remoteControl.addWeCom")),z.length>0&&W(r("remoteControl.plugin"),z)]}),e.jsx("hr",{className:"border-border-primary"}),e.jsxs("div",{className:"flex items-center gap-4 p-4 rounded-lg bg-bg-secondary hover:bg-bg-hover cursor-pointer transition-colors border border-border-primary",onClick:()=>{i?i("plugins"):window.location.hash="#/plugins"},children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"text-sm font-medium text-text-primary",children:r("remoteControl.installMore")}),e.jsx("p",{className:"text-xs text-text-tertiary mt-1",children:r("remoteControl.installMoreHint")})]}),e.jsx(te,{size:16,className:"text-text-tertiary"})]})]})]})}function ae({onBack:i,t:r,existingInstanceId:s}){const[b,c]=n.useState(null),[w,p]=n.useState(r("remoteControl.fetchingQr")),[N,y]=n.useState(s??null),[g,f]=n.useState(null),[k,j]=n.useState(!1);return n.useEffect(()=>{let o=!1;return(async()=>{try{let l=s;if(!l){const v=await E("/api/v1/channels/wechat",{method:"POST"});if(!v.ok)throw new Error((await v.json().catch(()=>({}))).error||"Failed");const x=await v.json();if(o)return;l=x.instanceId,y(l)}for(let v=0;v<180&&!o;v++){await new Promise(x=>setTimeout(x,1e3));try{const x=await fetch(`/api/v1/channels/wechat/${l}/qr`,{headers:V()});if(!x.ok)continue;const m=await x.json();if(o)return;if(m.qrUrl&&c(m.qrUrl),m.message&&p(m.message),m.type==="confirmed"){j(!0),p(r("remoteControl.connected")),setTimeout(()=>{o||i()},1500);return}if(m.type==="error"){f(m.message);return}}catch{}}!o&&!k&&f("Timeout")}catch(l){o||f((l==null?void 0:l.message)||"Failed")}})(),()=>{o=!0}},[s]),e.jsxs("div",{className:"flex flex-col h-full overflow-y-auto",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-border-primary flex items-center gap-3",children:[e.jsx("button",{onClick:i,className:"p-1 rounded-md hover:bg-bg-hover transition-colors",children:e.jsx(R,{size:18})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:r("remoteControl.addWeChat")}),e.jsx("p",{className:"text-sm text-text-tertiary",children:r("remoteControl.scanQr")})]})]}),e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center px-6 py-8",children:g?e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("p",{className:"text-red-500",children:g}),e.jsx("button",{onClick:i,className:"px-4 py-2 rounded-lg bg-bg-secondary hover:bg-bg-hover text-sm border border-border-primary",children:r("remoteControl.cancel")})]}):b?e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("div",{className:"inline-block p-4 bg-white rounded-xl",children:e.jsx("img",{src:`https://api.qrserver.com/v1/create-qr-code/?size=240x240&data=${encodeURIComponent(b)}`,alt:"QR Code",className:"w-60 h-60"})}),e.jsx("p",{className:"text-sm text-text-secondary",children:w})]}):e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("div",{className:"w-8 h-8 mx-auto border-2 border-accent-brand border-t-transparent rounded-full animate-spin"}),e.jsx("p",{className:"text-sm text-text-tertiary",children:w})]})})]})}function ce({onBack:i,t:r}){const[s,b]=n.useState(""),[c,w]=n.useState(""),[p,N]=n.useState("botId"),[y,g]=n.useState(!1),[f,k]=n.useState(null),j=n.useCallback(async()=>{if(!(!s.trim()||!c.trim())){g(!0),k(null);try{const o=await E("/api/v1/channels/wecom",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({botId:s.trim(),secret:c.trim()})});if(!o.ok){const l=await o.json().catch(()=>({}));throw new Error(l.error||"Failed")}i()}catch(o){k((o==null?void 0:o.message)||"Failed")}finally{g(!1)}}},[s,c,i]);return e.jsxs("div",{className:"flex flex-col h-full overflow-y-auto",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-border-primary flex items-center gap-3",children:[e.jsx("button",{onClick:i,className:"p-1 rounded-md hover:bg-bg-hover transition-colors",children:e.jsx(R,{size:18})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:r("remoteControl.addWeCom")}),e.jsx("p",{className:"text-sm text-text-tertiary",children:r("remoteControl.wecomBotIdHint")})]})]}),e.jsxs("div",{className:"px-6 py-8 max-w-md mx-auto w-full space-y-6",children:[f&&e.jsx("div",{className:"p-3 rounded-lg bg-red-500/10 text-red-500 text-sm",children:f}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-text-primary",children:"Bot ID"}),e.jsx("input",{type:"text",className:"w-full px-3 py-2 rounded-lg bg-bg-secondary border border-border-primary text-sm text-text-primary placeholder-text-tertiary focus:outline-none focus:border-accent-brand transition-colors",placeholder:r("channel.botIdPlaceholder"),value:s,onChange:o=>b(o.target.value),autoFocus:!0,disabled:p==="secret",onKeyDown:o=>{o.key==="Enter"&&s.trim()&&N("secret")}})]}),p==="secret"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-text-primary",children:"Secret"}),e.jsx("input",{type:"password",className:"w-full px-3 py-2 rounded-lg bg-bg-secondary border border-border-primary text-sm text-text-primary placeholder-text-tertiary focus:outline-none focus:border-accent-brand transition-colors",placeholder:r("channel.secretPlaceholder"),value:c,onChange:o=>w(o.target.value),autoFocus:!0,onKeyDown:o=>{o.key==="Enter"&&c.trim()&&j()}}),e.jsx("p",{className:"text-xs text-text-tertiary",children:r("remoteControl.wecomSecretHint")})]}),e.jsxs("div",{className:"flex gap-3 pt-2",children:[p==="botId"?e.jsx("button",{className:"px-4 py-2 rounded-lg bg-accent-brand text-accent-brand-foreground text-sm hover:bg-accent-brand/90 transition-colors disabled:opacity-50",disabled:!s.trim(),onClick:()=>N("secret"),children:r("remoteControl.next")}):e.jsx("button",{className:"px-4 py-2 rounded-lg bg-accent-brand text-accent-brand-foreground text-sm hover:bg-accent-brand/90 transition-colors disabled:opacity-50",disabled:!c.trim()||y,onClick:j,children:r(y?"remoteControl.connecting":"remoteControl.connect")}),e.jsx("button",{className:"px-4 py-2 rounded-lg bg-bg-secondary border border-border-primary text-sm text-text-secondary hover:bg-bg-hover transition-colors",onClick:i,children:r("remoteControl.cancel")})]})]})]})}export{xe as RemoteControlView};
16
+ */const se=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]],oe=W("link-2",se);function xe({onNavigate:i}){const{t:r}=J(),[s,b]=n.useState(A);if(n.useEffect(()=>{const c=()=>b(A());return window.addEventListener("hashchange",c),()=>window.removeEventListener("hashchange",c)},[]),s==="add-wechat"||s!=null&&s.startsWith("rebind-wechat/")){const c=s!=null&&s.startsWith("rebind-wechat/")?s.split("/")[1]:void 0;return e.jsx(ae,{onBack:()=>P("remote-control"),t:r,existingInstanceId:c})}return s==="add-wecom"?e.jsx(ce,{onBack:()=>P("remote-control"),t:r}):e.jsx(ne,{onNavigate:i,t:r})}function ne({onNavigate:i,t:r}){const[s,b]=n.useState([]),[c,w]=n.useState(!0),[p,N]=n.useState(null),[y,g]=n.useState(null),[f,k]=n.useState(!1),[j,o]=n.useState(!1),[l,v]=n.useState(!1),x=n.useCallback(async()=>{var t,d,a;try{const u=await E("/api/v1/channels");if(u.ok){const h=await u.json(),S=((t=h.capabilities)==null?void 0:t.remoteControlEnabled)??!1;k(S),b((h.clients||[]).filter(C=>!C.hidden&&!C.instanceId.startsWith("_pending"))),o(S&&((d=h.capabilities)==null?void 0:d.canAddWechatBot)!==!1),v(S&&((a=h.capabilities)==null?void 0:a.canAddWecomBot)!==!1)}}catch{}finally{w(!1)}},[]);n.useEffect(()=>{x();const t=setInterval(x,5e3);return()=>clearInterval(t)},[x]);const m=n.useCallback(async(t,d,a)=>{const u=`${d}:${a}:${t}`;g(u),N(null);try{const h=t==="delete"?"DELETE":"POST",S=t==="delete"?`/api/v1/channels/${d}/${a}`:`/api/v1/channels/${d}/${a}/${t}`,C=await E(S,{method:h});if(!C.ok){const G=await C.json().catch(()=>({}));throw new Error(G.error||`Failed: ${C.status}`)}const K=await C.json().catch(()=>({}));if(t==="unbind"&&d==="wechat"&&K.needsQrScan){I("remote-control",`rebind-wechat/${a}`);return}await x()}catch(h){N((h==null?void 0:h.message)||"Action failed")}finally{g(null)}},[x]),B=t=>t==="connected"?"text-green-500":t==="connecting"?"text-yellow-500":t==="error"?"text-red-500":"text-text-tertiary",F=t=>r(t==="connected"?"remoteControl.connected":t==="connecting"?"remoteControl.connecting":"remoteControl.disconnected"),M=t=>t==="wechat"?e.jsx(Y,{size:18,className:"text-green-500"}):t==="wecom"?e.jsx(q,{size:18,className:"text-accent-brand"}):e.jsx(L,{size:18,className:"text-text-tertiary"}),H=t=>t==="wechat"?r("channel.wechat")+r("remoteControl.bot"):t==="wecom"?r("channel.wecom")+r("remoteControl.bot"):t,_=t=>`${H(t.clientType)} #${t.instanceId.slice(0,4)}`,D=s.filter(t=>t.clientType==="wechat"),O=s.filter(t=>t.clientType==="wecom"),z=s.filter(t=>t.clientType!=="wechat"&&t.clientType!=="wecom"),Q=j||l,U=t=>{const d=`${t.clientType}:${t.instanceId}`,a=t.status==="connected",u=y==null?void 0:y.startsWith(d);return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg bg-bg-secondary hover:bg-bg-hover transition-colors cursor-pointer",onClick:()=>{u||m(a?"stop":"start",t.clientType,t.instanceId)},children:[M(t.clientType),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-text-primary truncate",children:_(t)}),e.jsx("span",{className:`text-xs ${B(t.status)}`,children:F(t.status)})]}),e.jsxs("div",{className:"flex items-center gap-1",onClick:h=>h.stopPropagation(),children:[e.jsx("button",{className:`p-1.5 rounded-md text-text-tertiary transition-colors ${a?"hover:text-orange-500":"hover:text-green-500"} hover:bg-bg-hover`,title:r(a?"remoteControl.disconnect":"remoteControl.connect"),disabled:!!u,onClick:()=>m(a?"stop":"start",t.clientType,t.instanceId),children:a?e.jsx(L,{size:14}):e.jsx(oe,{size:14})}),a&&e.jsx("button",{className:"p-1.5 rounded-md text-text-tertiary hover:text-orange-500 hover:bg-bg-hover transition-colors",title:r("remoteControl.unbind"),disabled:!!u,onClick:()=>m("unbind",t.clientType,t.instanceId),children:e.jsx(Z,{size:14})}),e.jsx("button",{className:"p-1.5 rounded-md text-text-tertiary hover:text-red-500 hover:bg-bg-hover transition-colors",title:r("remoteControl.delete"),disabled:!!u,onClick:()=>m("delete",t.clientType,t.instanceId),children:e.jsx(X,{size:14})})]})]},d)},$=(t,d,a,u)=>e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-medium text-text-secondary mb-2",children:t}),d.length===0?e.jsx("div",{className:"py-4 text-center text-xs text-text-tertiary",children:r("remoteControl.noChannels")}):e.jsx("div",{className:"space-y-2",children:d.map(U)}),a&&e.jsxs("button",{className:"flex items-center gap-1.5 mt-2 px-3 py-1.5 text-xs text-text-tertiary hover:text-text-primary hover:bg-bg-hover rounded-md transition-colors",onClick:a,children:[e.jsx(T,{size:12}),u||r("remoteControl.add")]})]});return!c&&!f?e.jsx(e.Fragment,{}):e.jsxs("div",{className:"flex flex-col h-full overflow-y-auto",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-border-primary",children:[e.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:r("remoteControl.title")}),e.jsx("p",{className:"text-sm text-text-tertiary mt-1",children:r("remoteControl.subtitle")})]}),e.jsxs("div",{className:"px-6 py-4 flex-1 space-y-6",children:[p&&e.jsx("div",{className:"p-3 rounded-lg bg-red-500/10 text-red-500 text-sm",children:p}),c?e.jsx("div",{className:"text-sm text-text-tertiary py-4",children:r("remoteControl.connecting")}):s.length===0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"py-8 text-center",children:[e.jsx(q,{size:32,className:"mx-auto mb-3 text-text-tertiary opacity-50"}),e.jsx("p",{className:"text-sm text-text-tertiary",children:r("remoteControl.noChannels")}),e.jsx("p",{className:"text-xs text-text-tertiary mt-1",children:r("remoteControl.noChannelsHint")})]}),Q&&e.jsxs("div",{className:"flex gap-3",children:[j&&e.jsxs("button",{className:"flex items-center gap-2 px-4 py-2 rounded-lg bg-bg-secondary hover:bg-bg-hover text-sm text-text-primary transition-colors border border-border-primary",onClick:()=>I("remote-control","add-wechat"),children:[e.jsx(T,{size:14}),r("remoteControl.addWeChat")]}),l&&e.jsxs("button",{className:"flex items-center gap-2 px-4 py-2 rounded-lg bg-bg-secondary hover:bg-bg-hover text-sm text-text-primary transition-colors border border-border-primary",onClick:()=>I("remote-control","add-wecom"),children:[e.jsx(T,{size:14}),r("remoteControl.addWeCom")]})]})]}):e.jsxs(e.Fragment,{children:[$(r("channel.wechat")+r("remoteControl.bot"),D,j?()=>I("remote-control","add-wechat"):void 0,r("remoteControl.addWeChat")),$(r("channel.wecom")+r("remoteControl.bot"),O,l?()=>I("remote-control","add-wecom"):void 0,r("remoteControl.addWeCom")),z.length>0&&$(r("remoteControl.plugin"),z)]}),e.jsx("hr",{className:"border-border-primary"}),e.jsxs("div",{className:"flex items-center gap-4 p-4 rounded-lg bg-bg-secondary hover:bg-bg-hover cursor-pointer transition-colors border border-border-primary",onClick:()=>{i?i("plugins"):window.location.hash="#/plugins"},children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"text-sm font-medium text-text-primary",children:r("remoteControl.installMore")}),e.jsx("p",{className:"text-xs text-text-tertiary mt-1",children:r("remoteControl.installMoreHint")})]}),e.jsx(te,{size:16,className:"text-text-tertiary"})]})]})]})}function ae({onBack:i,t:r,existingInstanceId:s}){const[b,c]=n.useState(null),[w,p]=n.useState(r("remoteControl.fetchingQr")),[N,y]=n.useState(s??null),[g,f]=n.useState(null),[k,j]=n.useState(!1);return n.useEffect(()=>{let o=!1;return(async()=>{try{let l=s;if(!l){const v=await E("/api/v1/channels/wechat",{method:"POST"});if(!v.ok)throw new Error((await v.json().catch(()=>({}))).error||"Failed");const x=await v.json();if(o)return;l=x.instanceId,y(l)}for(let v=0;v<180&&!o;v++){await new Promise(x=>setTimeout(x,1e3));try{const x=await fetch(`/api/v1/channels/wechat/${l}/qr`,{headers:V()});if(!x.ok)continue;const m=await x.json();if(o)return;if(m.qrUrl&&c(m.qrUrl),m.message&&p(m.message),m.type==="confirmed"){j(!0),p(r("remoteControl.connected")),setTimeout(()=>{o||i()},1500);return}if(m.type==="error"){f(m.message);return}}catch{}}!o&&!k&&f("Timeout")}catch(l){o||f((l==null?void 0:l.message)||"Failed")}})(),()=>{o=!0}},[s]),e.jsxs("div",{className:"flex flex-col h-full overflow-y-auto",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-border-primary flex items-center gap-3",children:[e.jsx("button",{onClick:i,className:"p-1 rounded-md hover:bg-bg-hover transition-colors",children:e.jsx(R,{size:18})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:r("remoteControl.addWeChat")}),e.jsx("p",{className:"text-sm text-text-tertiary",children:r("remoteControl.scanQr")})]})]}),e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center px-6 py-8",children:g?e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("p",{className:"text-red-500",children:g}),e.jsx("button",{onClick:i,className:"px-4 py-2 rounded-lg bg-bg-secondary hover:bg-bg-hover text-sm border border-border-primary",children:r("remoteControl.cancel")})]}):b?e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("div",{className:"inline-block p-4 bg-white rounded-xl",children:e.jsx("img",{src:`https://api.qrserver.com/v1/create-qr-code/?size=240x240&data=${encodeURIComponent(b)}`,alt:"QR Code",className:"w-60 h-60"})}),e.jsx("p",{className:"text-sm text-text-secondary",children:w})]}):e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("div",{className:"w-8 h-8 mx-auto border-2 border-accent-brand border-t-transparent rounded-full animate-spin"}),e.jsx("p",{className:"text-sm text-text-tertiary",children:w})]})})]})}function ce({onBack:i,t:r}){const[s,b]=n.useState(""),[c,w]=n.useState(""),[p,N]=n.useState("botId"),[y,g]=n.useState(!1),[f,k]=n.useState(null),j=n.useCallback(async()=>{if(!(!s.trim()||!c.trim())){g(!0),k(null);try{const o=await E("/api/v1/channels/wecom",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({botId:s.trim(),secret:c.trim()})});if(!o.ok){const l=await o.json().catch(()=>({}));throw new Error(l.error||"Failed")}i()}catch(o){k((o==null?void 0:o.message)||"Failed")}finally{g(!1)}}},[s,c,i]);return e.jsxs("div",{className:"flex flex-col h-full overflow-y-auto",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-border-primary flex items-center gap-3",children:[e.jsx("button",{onClick:i,className:"p-1 rounded-md hover:bg-bg-hover transition-colors",children:e.jsx(R,{size:18})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:r("remoteControl.addWeCom")}),e.jsx("p",{className:"text-sm text-text-tertiary",children:r("remoteControl.wecomBotIdHint")})]})]}),e.jsxs("div",{className:"px-6 py-8 max-w-md mx-auto w-full space-y-6",children:[f&&e.jsx("div",{className:"p-3 rounded-lg bg-red-500/10 text-red-500 text-sm",children:f}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-text-primary",children:"Bot ID"}),e.jsx("input",{type:"text",className:"w-full px-3 py-2 rounded-lg bg-bg-secondary border border-border-primary text-sm text-text-primary placeholder-text-tertiary focus:outline-none focus:border-accent-brand transition-colors",placeholder:r("channel.botIdPlaceholder"),value:s,onChange:o=>b(o.target.value),autoFocus:!0,disabled:p==="secret",onKeyDown:o=>{o.key==="Enter"&&s.trim()&&N("secret")}})]}),p==="secret"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-text-primary",children:"Secret"}),e.jsx("input",{type:"password",className:"w-full px-3 py-2 rounded-lg bg-bg-secondary border border-border-primary text-sm text-text-primary placeholder-text-tertiary focus:outline-none focus:border-accent-brand transition-colors",placeholder:r("channel.secretPlaceholder"),value:c,onChange:o=>w(o.target.value),autoFocus:!0,onKeyDown:o=>{o.key==="Enter"&&c.trim()&&j()}}),e.jsx("p",{className:"text-xs text-text-tertiary",children:r("remoteControl.wecomSecretHint")})]}),e.jsxs("div",{className:"flex gap-3 pt-2",children:[p==="botId"?e.jsx("button",{className:"px-4 py-2 rounded-lg bg-accent-brand text-accent-brand-foreground text-sm hover:bg-accent-brand/90 transition-colors disabled:opacity-50",disabled:!s.trim(),onClick:()=>N("secret"),children:r("remoteControl.next")}):e.jsx("button",{className:"px-4 py-2 rounded-lg bg-accent-brand text-accent-brand-foreground text-sm hover:bg-accent-brand/90 transition-colors disabled:opacity-50",disabled:!c.trim()||y,onClick:j,children:r(y?"remoteControl.connecting":"remoteControl.connect")}),e.jsx("button",{className:"px-4 py-2 rounded-lg bg-bg-secondary border border-border-primary text-sm text-text-secondary hover:bg-bg-hover transition-colors",onClick:i,children:r("remoteControl.cancel")})]})]})]})}export{xe as RemoteControlView};
@@ -0,0 +1,12 @@
1
+ import{a as g,j as e}from"./markdown-DIY6o85n.js";import{c as O,e as W,aD as $,u as D,i as U,aE as B,aF as K,aG as w,aH as J,aI as V,ax as q,r as X,aJ as Y,Z as Q}from"./index-DC-fErwI.js";import"./vendor-D35k0Cos.js";/**
2
+ * @license lucide-react v1.18.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const ee=[["path",{d:"m18 16 4-4-4-4",key:"1inbqp"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}],["path",{d:"m14.5 4-5 16",key:"e7oirm"}]],te=O("code-xml",ee);/**
7
+ * @license lucide-react v1.18.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const se=[["path",{d:"M16 7h6v6",key:"box55l"}],["path",{d:"m22 7-8.5 8.5-5-5L2 17",key:"1t1m79"}]],ae=O("trending-up",se),ne=W((t,n)=>({stats:null,statsLoading:!1,statsError:null,sessionStats:null,sessionLoading:!1,sessionError:null,fetchStats:async()=>{t({statsLoading:!n().stats,statsError:null});try{t({stats:await $("/api/v1/stats"),statsLoading:!1})}catch(a){t({statsError:a.message,statsLoading:!1})}},fetchSessionStats:async()=>{t({sessionLoading:!n().sessionStats,sessionError:null});try{t({sessionStats:await $("/api/v1/stats/session"),sessionLoading:!1})}catch(a){t({sessionError:a.message,sessionLoading:!1})}},fetchAll:async()=>{await Promise.all([n().fetchStats(),n().fetchSessionStats()])}}));function k(t){return t>=1e6?(t/1e6).toFixed(1)+"M":t>=1e3?(t/1e3).toFixed(1)+"k":t.toString()}function I(t){if(t<=0)return"-";const n=Math.floor(t/1e3),a=Math.floor(n/60),r=Math.floor(a/60);return r>0?`${r}h ${a%60}m ${n%60}s`:a>0?`${a}m ${n%60}s`:`${n}s`}function F(t){return t.replace(/^anthropic\./,"").replace(/^openai\./,"").replace(/-\d{8}$/,"").replace(/@.*$/,"")}function oe(t){return new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric"})}const re=["#ebedf0","#9be9a8","#40c463","#30a14e","#216e39"],ie=["#161b22","#0e4429","#006d32","#26a641","#39d353"],z=["#3b82f6","#10b981","#8b5cf6"],le=[{name:"The Little Prince",tokens:22e3},{name:"The Old Man and the Sea",tokens:35e3},{name:"A Christmas Carol",tokens:37e3},{name:"Animal Farm",tokens:39e3},{name:"Fahrenheit 451",tokens:6e4},{name:"The Great Gatsby",tokens:62e3},{name:"Brave New World",tokens:83e3},{name:"Harry Potter and the Philosopher's Stone",tokens:103e3},{name:"1984",tokens:123e3},{name:"Pride and Prejudice",tokens:156e3},{name:"Dune",tokens:244e3},{name:"A Game of Thrones",tokens:381e3},{name:"The Lord of the Rings",tokens:576e3},{name:"War and Peace",tokens:73e4}],ce=[{name:"朝花夕拾",tokens:18e3},{name:"骆驼祥子",tokens:6e4},{name:"活着",tokens:72e3},{name:"围城",tokens:84e3},{name:"三体",tokens:126e3},{name:"射雕英雄传",tokens:234e3},{name:"红楼梦",tokens:438e3},{name:"三国演义",tokens:48e4},{name:"西游记",tokens:492e3},{name:"水浒传",tokens:576e3},{name:"平凡的世界",tokens:6e5},{name:"金庸全集",tokens:636e4}],de=[{en:"a TED talk",zh:"一场 TED 演讲",minutes:18},{en:"an episode of The Office",zh:"一集《办公室》",minutes:22},{en:"listening to Abbey Road",zh:"听一遍《Abbey Road》专辑",minutes:47},{en:"a yoga class",zh:"一节瑜伽课",minutes:60},{en:"a World Cup soccer match",zh:"一场世界杯比赛",minutes:90},{en:"a half marathon (average time)",zh:"一场半程马拉松",minutes:120},{en:"the movie Inception",zh:"电影《盗梦空间》",minutes:148},{en:"watching Titanic",zh:"电影《泰坦尼克号》",minutes:195},{en:"a transatlantic flight",zh:"一趟跨大西洋航班",minutes:420},{en:"a full night of sleep",zh:"一整晚的睡眠",minutes:480}];function xe(t,n,a,r){var m;const s=[],o=r==="zh"?ce:le;if(n>0){for(const l of o)if(n>=l.tokens){const h=n/l.tokens;s.push(h>=2?a("stats.funFact.moreTokens").replace("{times}",String(Math.floor(h))).replace("{book}",l.name):a("stats.funFact.sameTokens").replace("{book}",l.name))}}if(t.longestSession){const l=t.longestSession.duration/6e4;for(const h of de){const u=l/h.minutes;if(u>=2){const d=r==="zh"?h.zh:h.en;s.push(a("stats.funFact.longerSession").replace("{times}",String(Math.floor(u))).replace("{activity}",d))}}}if(s.length===0)return"";const i=Math.floor((((m=t.longestSession)==null?void 0:m.duration)??0)/6e4),c=Math.abs(Math.trunc(n+i))%s.length;return s[c]}function me({dailyModelTokens:t,topModels:n}){const a=g.useMemo(()=>{const o={top:20,right:20,bottom:40,left:60},i=700-o.left-o.right,c=220-o.top-o.bottom;let m=0;for(const y of t)for(const b of n){const p=y.tokensByModel[b.id]||0;p>m&&(m=p)}m===0&&(m=1);const l=n.map((y,b)=>{const p=t.map((N,E)=>{const T=o.left+E/Math.max(t.length-1,1)*i,A=N.tokensByModel[y.id]||0,C=o.top+c-A/m*c;return`${T},${C}`});return t.some(N=>(N.tokensByModel[y.id]||0)>0)?{path:`M${p.join("L")}`,color:z[b%z.length],id:y.id,label:y.label}:null}).filter(Boolean),h=Array.from({length:5},(y,b)=>{const p=m*(1-b/4);return{y:o.top+b/4*c,label:k(Math.round(p))}}),u=Math.min(5,t.length),d=Math.max(1,Math.floor((t.length-1)/(u-1))),M=Array.from({length:u},(y,b)=>{const p=Math.min(b*d,t.length-1);return{x:o.left+p/Math.max(t.length-1,1)*i,label:oe(t[p].date)}});return{W:700,H:220,PAD:o,CW:i,CH:c,lines:l,yGridLines:h,xLabels:M}},[t,n]);return e.jsxs("div",{children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("svg",{viewBox:`0 0 ${a.W} ${a.H}`,className:"w-full min-w-[500px]",style:{maxHeight:"240px"},children:[a.yGridLines.map((r,s)=>e.jsxs("g",{children:[e.jsx("line",{x1:a.PAD.left,y1:r.y,x2:a.W-a.PAD.right,y2:r.y,className:"stroke-border-primary",strokeWidth:.5,strokeDasharray:"4 4"}),e.jsx("text",{x:a.PAD.left-8,y:r.y+4,textAnchor:"end",className:"fill-text-tertiary",fontSize:10,children:r.label})]},s)),a.lines.map((r,s)=>e.jsx("path",{d:r.path,fill:"none",stroke:r.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"},s)),a.xLabels.map((r,s)=>e.jsx("text",{x:r.x,y:a.H-10,textAnchor:"middle",className:"fill-text-tertiary",fontSize:10,children:r.label},s))]})}),e.jsx("div",{className:"flex gap-4 mt-2 justify-center",children:a.lines.map(r=>e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-text-secondary",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full",style:{backgroundColor:r.color}}),e.jsx("span",{children:r.label})]},r.id))})]})}function he({stats:t}){const{t:n}=D(),a=g.useMemo(()=>Object.entries(t.modelUsage).map(([s,o])=>{const i=o.inputTokens>0?o.cacheReadInputTokens/o.inputTokens*100:0;return{name:s,shortName:o.displayName||F(s),inputTokens:o.inputTokens,outputTokens:o.outputTokens,cacheReadInputTokens:o.cacheReadInputTokens,cacheHitRate:i,total:o.inputTokens+o.outputTokens,costUSD:o.costUSD}}).sort((s,o)=>o.total-s.total),[t.modelUsage]),r=g.useMemo(()=>a.reduce((s,o)=>s+o.total,0),[a]);return a.length===0?e.jsx("div",{className:"text-center py-12 text-text-tertiary",children:n("stats.noData")}):e.jsxs(e.Fragment,{children:[t.dailyModelTokens.length>=2&&e.jsxs("div",{className:"mb-6",children:[e.jsx("h2",{className:"text-sm font-medium text-text-primary mb-3",children:n("stats.tokensPerDay")}),e.jsx(me,{dailyModelTokens:t.dailyModelTokens,topModels:a.slice(0,3).map(s=>({id:s.name,label:s.shortName}))})]}),e.jsx("h2",{className:"text-sm font-medium text-text-primary mb-3",children:n("stats.allModels")}),e.jsx("div",{className:"space-y-3",children:a.map(s=>{const o=r>0?s.total/r*100:0;return e.jsxs("div",{className:"bg-bg-secondary rounded-lg p-3 border border-border-primary",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm font-medium text-text-primary",children:s.shortName}),e.jsxs("span",{className:"text-xs text-text-tertiary",children:[o.toFixed(1),"%"]})]}),e.jsx("div",{className:"h-1.5 bg-bg-tertiary rounded-full mb-2",children:e.jsx("div",{className:"h-full rounded-full bg-accent-brand transition-all duration-500",style:{width:`${Math.min(o,100)}%`}})}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2 text-xs text-text-secondary",children:[e.jsxs("span",{children:[n("stats.input"),": ",k(s.inputTokens)]}),e.jsxs("span",{children:[n("stats.output"),": ",k(s.outputTokens)]}),s.cacheReadInputTokens>0&&e.jsxs("span",{children:[n("stats.cacheHitRate"),": ",s.cacheHitRate.toFixed(1),"%"]}),s.costUSD>0&&e.jsxs("span",{children:[n("stats.cost"),": $",s.costUSD.toFixed(2)]})]})]},s.name)})})]})}function ue({dailyActivity:t}){const{t:n}=D(),r=U(i=>i.resolved)==="dark"?ie:re,s=g.useMemo(()=>{const u=new Map;for(const x of t)u.set(x.date,x.messageCount);const d=t.map(x=>x.messageCount).filter(x=>x>0).sort((x,L)=>x-L),M=d.length>0?d[Math.floor(d.length*.25)]:0,y=d.length>0?d[Math.floor(d.length*.5)]:0,b=d.length>0?d[Math.floor(d.length*.75)]:0,p=x=>x===0||d.length===0?0:x>=b?4:x>=y?3:x>=M?2:1,v=new Date;v.setHours(0,0,0,0);const N=new Date(v);N.setDate(v.getDate()-v.getDay());const E=new Date(N);E.setDate(E.getDate()-357);const T=[],A=[];let C=-1;const f=new Date(E);for(let x=0;x<52;x++)for(let L=0;L<7;L++){if(f>v){f.setDate(f.getDate()+1);continue}const G=f.getFullYear(),H=String(f.getMonth()+1).padStart(2,"0"),R=String(f.getDate()).padStart(2,"0"),_=`${G}-${H}-${R}`,P=u.get(_)||0;if(L===0&&f.getMonth()!==C){const Z=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];A.push({text:Z[f.getMonth()],x:32+x*14}),C=f.getMonth()}T.push({key:_,x:32+x*14,y:20+L*14,level:p(P),date:_,count:P}),f.setDate(f.getDate()+1)}return{cells:T,monthLabels:A,width:770,height:128,CELL_SIZE:12,TOP_PADDING:20,LEFT_PADDING:32,CELL_GAP:2}},[t]),o=["","Mon","","Wed","","Fri",""];return e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("svg",{width:s.width,height:s.height+30,viewBox:`0 0 ${s.width} ${s.height+30}`,className:"min-w-[500px]",children:[s.monthLabels.map((i,c)=>e.jsx("text",{x:i.x,y:s.TOP_PADDING-6,className:"fill-text-tertiary",fontSize:10,children:i.text},c)),o.map((i,c)=>i?e.jsx("text",{x:s.LEFT_PADDING-6,y:s.TOP_PADDING+c*(s.CELL_SIZE+s.CELL_GAP)+s.CELL_SIZE-2,className:"fill-text-tertiary",fontSize:10,textAnchor:"end",children:i},c):null),s.cells.map(i=>e.jsx("rect",{x:i.x,y:i.y,width:s.CELL_SIZE,height:s.CELL_SIZE,rx:2,fill:r[i.level],children:e.jsxs("title",{children:[i.date,": ",i.count," ",n("stats.heatmap.messages")]})},i.key)),(()=>{const i=s.height+4,c=s.LEFT_PADDING;return e.jsxs("g",{children:[e.jsx("text",{x:c,y:i+10,className:"fill-text-tertiary",fontSize:10,children:n("stats.heatmap.less")}),r.map((m,l)=>e.jsx("rect",{x:c+30+l*(s.CELL_SIZE+2),y:i,width:s.CELL_SIZE,height:s.CELL_SIZE,rx:2,fill:m},l)),e.jsx("text",{x:c+30+5*(s.CELL_SIZE+2)+4,y:i+10,className:"fill-text-tertiary",fontSize:10,children:n("stats.heatmap.more")})]})})()]})})}function pe({sessionStats:t}){const{t:n}=D(),a=g.useMemo(()=>Object.values(t.tokenUsageByModel).reduce((r,s)=>r+s.inputTokens+s.outputTokens,0),[t.tokenUsageByModel]);return e.jsxs("div",{className:"flex flex-wrap gap-3 mb-6 p-3 bg-bg-secondary/50 rounded-xl border border-border-primary/50",children:[e.jsx(S,{label:n("stats.session.title"),icon:e.jsx(te,{size:12})}),e.jsx(S,{label:n("stats.session.apiDuration"),value:I(t.apiDuration)}),e.jsx(S,{label:n("stats.session.wallTime"),value:I(t.runningTime)}),e.jsx(S,{label:n("stats.session.linesAdded"),value:`+${t.fileChangeStats.totalAddedLines}`,valueClass:"text-green-500"}),e.jsx(S,{label:n("stats.session.linesDeleted"),value:`-${t.fileChangeStats.totalDeletedLines}`,valueClass:"text-red-500"}),e.jsx(S,{label:n("stats.session.tokens"),value:k(a)})]})}function S({label:t,value:n,icon:a,valueClass:r}){return e.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[a,e.jsx("span",{className:"text-text-tertiary",children:t}),n&&e.jsx("span",{className:`font-medium text-text-primary ${r||""}`,children:n})]})}function j({icon:t,label:n,value:a}){return e.jsxs("div",{className:"bg-bg-secondary rounded-xl p-4 border border-border-primary",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"text-text-tertiary",children:t}),e.jsx("span",{className:"text-xs font-medium text-text-secondary",children:n})]}),e.jsx("div",{className:"text-lg font-semibold text-text-primary",style:{fontVariantNumeric:"tabular-nums"},children:a})]})}function fe({stats:t,sessionStats:n}){const{t:a,resolved:r}=D(),s=g.useMemo(()=>Object.entries(t.modelUsage).sort(([,l],[,h])=>h.inputTokens+h.outputTokens-(l.inputTokens+l.outputTokens)),[t.modelUsage]),o=g.useMemo(()=>s.reduce((l,[,h])=>l+h.inputTokens+h.outputTokens,0),[s]),i=g.useMemo(()=>{const l=s.reduce((u,[,d])=>u+d.inputTokens,0),h=s.reduce((u,[,d])=>u+d.cacheReadInputTokens,0);return l>0?h/l*100:0},[s]),c=s[0],m=g.useMemo(()=>xe(t,o,a,r),[t,o,a,r]);return e.jsxs(e.Fragment,{children:[n&&e.jsx(pe,{sessionStats:n}),t.dailyActivity.length>0&&e.jsx("div",{className:"mb-6",children:e.jsx(ue,{dailyActivity:t.dailyActivity})}),c&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mb-4",children:[e.jsx(j,{icon:e.jsx(B,{size:16}),label:a("stats.favoriteModel"),value:c[1].displayName||F(c[0])}),e.jsx(j,{icon:e.jsx(K,{size:16}),label:a("stats.totalTokens"),value:k(o)}),e.jsx(j,{icon:e.jsx(w,{size:16}),label:a("stats.cacheHitRate"),value:`${i.toFixed(1)}%`})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4 mb-6",children:[e.jsx(j,{icon:e.jsx(J,{size:16}),label:a("stats.sessions"),value:k(t.totalSessions)}),e.jsx(j,{icon:e.jsx(V,{size:16}),label:a("stats.longestSession"),value:t.longestSession?I(t.longestSession.duration):a("stats.na")}),e.jsx(j,{icon:e.jsx(ae,{size:16}),label:a("stats.activeDays"),value:`${t.activeDays}/${t.totalDays}`}),e.jsx(j,{icon:e.jsx(w,{size:16}),label:a("stats.currentStreak"),value:`${t.streaks.currentStreak} ${a("stats.days")}`}),e.jsx(j,{icon:e.jsx(w,{size:16}),label:a("stats.longestStreak"),value:`${t.streaks.longestStreak} ${a("stats.days")}`}),e.jsx(j,{icon:e.jsx(q,{size:16}),label:a("stats.peakHour"),value:t.peakActivityHour!==null?`${t.peakActivityHour}:00-${t.peakActivityHour+1}:00`:a("stats.na")})]}),m&&e.jsx("div",{className:"p-3 bg-bg-secondary/50 rounded-lg border border-border-primary/50 text-sm text-accent-brand",children:m})]})}function ge({toolUsage:t}){var s;const{t:n}=D(),a=t.slice(0,20),r=((s=a[0])==null?void 0:s.count)||0;return a.length===0?e.jsx("div",{className:"text-center py-12 text-text-tertiary",children:n("stats.noData")}):e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-sm font-medium text-text-primary mb-4",children:n("stats.topTools")}),e.jsx("div",{className:"space-y-2",children:a.map(o=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-text-secondary w-28 text-right truncate font-mono",children:o.toolName}),e.jsx("div",{className:"flex-1 h-6 bg-bg-tertiary rounded overflow-hidden",children:e.jsx("div",{className:"h-full bg-accent-brand/60 rounded transition-all duration-500 flex items-center pl-2",style:{width:`${Math.max(o.count/r*100,2)}%`},children:o.count/r>.15&&e.jsx("span",{className:"text-[10px] text-text-primary font-mono",children:k(o.count)})})}),o.count/r<=.15&&e.jsx("span",{className:"text-xs text-text-tertiary w-12 font-mono",children:k(o.count)})]},o.toolName))})]})}function Ne(){const{t}=D(),{stats:n,statsLoading:a,statsError:r,sessionStats:s,fetchAll:o}=ne(),[i,c]=g.useState("overview");if(g.useEffect(()=>{o()},[o]),a&&!n)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(X,{size:"large",text:t("stats.loading")})});if(r&&!n)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-text-secondary mb-4",children:r}),e.jsx("button",{onClick:o,className:"px-4 py-2 bg-accent-brand text-accent-brand-foreground rounded-lg text-sm",children:t("stats.refresh")})]})});const m=[{key:"overview",label:t("stats.tab.overview")},{key:"models",label:t("stats.tab.models")},{key:"tools",label:t("stats.tab.tools")}];return e.jsxs("div",{className:"flex-1 overflow-auto p-4 md:p-6",children:[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("stats.title")})]}),e.jsxs("button",{onClick:o,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm text-text-secondary
12
+ hover:text-text-primary hover:bg-bg-hover rounded-lg transition-colors`,title:t("stats.refresh"),children:[e.jsx(Q,{size:14}),e.jsx("span",{children:t("stats.refresh")})]})]}),e.jsx("div",{className:"flex gap-1 mb-6 bg-bg-secondary rounded-lg p-1 w-fit",children:m.map(l=>e.jsx("button",{onClick:()=>c(l.key),className:`px-4 py-1.5 text-sm rounded-md transition-colors ${i===l.key?"bg-bg-primary text-text-primary font-medium shadow-sm":"text-text-secondary hover:text-text-primary"}`,children:l.label},l.key))}),n?e.jsxs(e.Fragment,{children:[i==="overview"&&e.jsx(fe,{stats:n,sessionStats:s}),i==="models"&&e.jsx(he,{stats:n}),i==="tools"&&e.jsx(ge,{toolUsage:n.toolUsage}),e.jsx("div",{className:"mt-8 text-xs text-text-tertiary text-center",children:t("stats.timeRange").replace("{days}",String(n.totalDays))})]}):e.jsx("div",{className:"text-center py-12 text-text-tertiary",children:t("stats.noData")})]})}export{Ne as StatsView};
@@ -1,4 +1,4 @@
1
- import{j as e,a as f}from"./markdown-DIY6o85n.js";import{c as oe,e as Ee,x as ce,h as ie,aE as xe,G as Ae,aA as ge,ay as ze,aF as Le,u as X,i as Ce,j as Re,o as _e,k as Fe,aG as te,X as Xe,C as Ye,I as Oe,l as Pe,n as ue,m as Te,aH as We,W as ye,av as He,ae as Be,aI as Ve}from"./index-DNUXcSh8.js";import{u as qe}from"./worker-store-CeRgJcBb.js";import"./vendor-D35k0Cos.js";/**
1
+ import{j as e,a as f}from"./markdown-DIY6o85n.js";import{c as oe,e as Ee,y as ce,h as ie,aK as xe,G as Ae,aG as ge,aE as ze,aL as Le,u as Y,i as Ce,j as Re,o as _e,k as Xe,aM as te,X as Ye,C as Fe,I as Oe,l as Pe,n as ue,m as Te,aN as We,Z as ye,aB as He,ak as Be,aO as Ve}from"./index-DC-fErwI.js";import{u as qe}from"./worker-store-CC1BvZFl.js";import"./vendor-D35k0Cos.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,x 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{}}})),Y={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:ge,tool:ge,handoff:Ae,guardrail:Qe,response:Ie,custom:xe};function st({workers:t,selectedPid:n,onSelect:s}){var c;const{t:u}=X(),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 J({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 V({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}=X(),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=Y[o]||Y.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}=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(Ge,{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"?_e:Fe,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=Y[S.type]||Y.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,F=(m-C)/2;x.forEach((H,se)=>v.set(H.id,{x:F+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(F=>{const H=Math.max(.1,Math.min(5,F.zoom*T));return{zoom:H,panX:x-(x-F.panX)*(H/F.zoom),panY:C-(C-F.panY)*(H/F.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}))},[$]),_=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]),q=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",G=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:q,onMouseUp:U,onMouseLeave:U,onTouchStart:N,onTouchMove:R,onTouchEnd:_,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=Y[r.type]||Y.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),F=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:G,fontFamily:"monospace",children:[C,F]}),e.jsxs("title",{children:[x," — ",C,F]})]},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(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:()=>{Oe(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(V,{label:s("traces.spanDetail.type"),value:t.type}),e.jsx(V,{label:s("traces.spanDetail.duration"),value:t.duration!=null?P(t.duration):"--"}),e.jsx(V,{label:s("traces.selfTime"),value:i!=null?P(i):"--"}),e.jsx(V,{label:"Status",value:t.status}),t.model&&e.jsx(V,{label:s("traces.spanDetail.model"),value:t.model}),(t.inputTokens!=null||t.outputTokens!=null)&&e.jsx(V,{label:s("traces.spanDetail.tokens"),value:`${t.inputTokens||0} in / ${t.outputTokens||0} out`}),t.toolName&&e.jsx(V,{label:"Tool",value:t.toolName}),t.fromAgent&&e.jsx(V,{label:"From",value:t.fromAgent}),t.toAgent&&e.jsx(V,{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(_=>new Date(_.startedAt).getTime()),k=t.spans.filter(_=>_.endedAt).map(_=>new Date(_.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(Pe,{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[d.span.type]||Y.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?_.dark:_.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 G;const N=k*B,R=new Date(d.span.startedAt).getTime(),_=d.span.endedAt?new Date(d.span.endedAt).getTime():R+A,O=(R-I)/A*900,q=Math.max((_-R)/A*900,gt),U=Y[d.span.type]||Y.custom,W=a?U.dark:U.light,Z=((G=t.bottleneck)==null?void 0:G.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:q,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:q+2,height:ne+2,fill:"none",stroke:"#f59e0b",strokeWidth:1.5,strokeDasharray:"4,2",rx:3}),q>36&&d.span.duration!=null&&e.jsx("text",{x:O+q/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=Y[h.type]||Y.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 kt(){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}=qe(),{sessionId:d}=We(),[k,N]=f.useState("list"),[R,_]=f.useState("timeline"),[O,q]=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 G=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:ye,title:t("traces.refresh"),onClick:ee,spin:u}),s.length>0&&e.jsx(de,{icon:He,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:()=>G(j.traceId)},j.traceId))}),y.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsxs("button",{onClick:()=>q(!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:()=>G(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,F=(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(Be,{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),_("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:ye,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(J,{label:t("traces.duration"),value:T.duration!=null?P(T.duration):"--"}),e.jsx(J,{label:"Spans",value:String(T.spanCount||0)}),C+F>0&&e.jsx(J,{label:"Tokens",value:`${ae(C)} in / ${ae(F)} out`}),C>0&&e.jsx(J,{label:"Cache",value:`${se.toFixed(0)}%`,accent:se>0}),H.length>0&&e.jsx(J,{label:t("traces.spanDetail.model"),value:H.join(", ")}),x.toolCount>0&&e.jsx(J,{label:"Tools",value:`${x.toolCount}${x.errorCount>0?` (${x.errorCount} err)`:""}`}),he>0&&e.jsx(J,{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),_("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:()=>_(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(Ve,{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{kt 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:ge,tool:ge,handoff:Ae,guardrail:Qe,response:Ie,custom:xe};function st({workers:t,selectedPid:n,onSelect:s}){var c;const{t:u}=Y(),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 J({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 V({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}=Y(),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}=Y();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(Ge,{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"?_e:Xe,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}=Y(),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}=Y(),[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}=Y(),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}=Y(),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,X=(m-C)/2;x.forEach((H,se)=>v.set(H.id,{x: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(X=>{const H=Math.max(.1,Math.min(5,X.zoom*T));return{zoom:H,panX:x-(x-X.panX)*(H/X.zoom),panY:C-(C-X.panY)*(H/X.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}))},[$]),_=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]),q=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",G=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:q,onMouseUp:U,onMouseLeave:U,onTouchStart:N,onTouchMove:R,onTouchEnd:_,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),X=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:G,fontFamily:"monospace",children:[C,X]}),e.jsxs("title",{children:[x," — ",C,X]})]},r.id)})]})})]})}function mt({span:t,onClose:n}){const{t:s}=Y(),[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:()=>{Oe(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(Fe,{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(V,{label:s("traces.spanDetail.type"),value:t.type}),e.jsx(V,{label:s("traces.spanDetail.duration"),value:t.duration!=null?P(t.duration):"--"}),e.jsx(V,{label:s("traces.selfTime"),value:i!=null?P(i):"--"}),e.jsx(V,{label:"Status",value:t.status}),t.model&&e.jsx(V,{label:s("traces.spanDetail.model"),value:t.model}),(t.inputTokens!=null||t.outputTokens!=null)&&e.jsx(V,{label:s("traces.spanDetail.tokens"),value:`${t.inputTokens||0} in / ${t.outputTokens||0} out`}),t.toolName&&e.jsx(V,{label:"Tool",value:t.toolName}),t.fromAgent&&e.jsx(V,{label:"From",value:t.fromAgent}),t.toAgent&&e.jsx(V,{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}=Y(),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}=Y(),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(_=>new Date(_.startedAt).getTime()),k=t.spans.filter(_=>_.endedAt).map(_=>new Date(_.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(Pe,{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,_=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?_.dark:_.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 G;const N=k*B,R=new Date(d.span.startedAt).getTime(),_=d.span.endedAt?new Date(d.span.endedAt).getTime():R+A,O=(R-I)/A*900,q=Math.max((_-R)/A*900,gt),U=F[d.span.type]||F.custom,W=a?U.dark:U.light,Z=((G=t.bottleneck)==null?void 0:G.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:q,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:q+2,height:ne+2,fill:"none",stroke:"#f59e0b",strokeWidth:1.5,strokeDasharray:"4,2",rx:3}),q>36&&d.span.duration!=null&&e.jsx("text",{x:O+q/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}=Y(),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}=Y(),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 kt(){var me;const{t}=Y(),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}=qe(),{sessionId:d}=We(),[k,N]=f.useState("list"),[R,_]=f.useState("timeline"),[O,q]=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 G=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:ye,title:t("traces.refresh"),onClick:ee,spin:u}),s.length>0&&e.jsx(de,{icon:He,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:()=>G(j.traceId)},j.traceId))}),y.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsxs("button",{onClick:()=>q(!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:()=>G(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,X=(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(Be,{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),_("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:ye,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(J,{label:t("traces.duration"),value:T.duration!=null?P(T.duration):"--"}),e.jsx(J,{label:"Spans",value:String(T.spanCount||0)}),C+X>0&&e.jsx(J,{label:"Tokens",value:`${ae(C)} in / ${ae(X)} out`}),C>0&&e.jsx(J,{label:"Cache",value:`${se.toFixed(0)}%`,accent:se>0}),H.length>0&&e.jsx(J,{label:t("traces.spanDetail.model"),value:H.join(", ")}),x.toolCount>0&&e.jsx(J,{label:"Tools",value:`${x.toolCount}${x.errorCount>0?` (${x.errorCount} err)`:""}`}),he>0&&e.jsx(J,{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),_("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:()=>_(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(Ve,{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{kt as TracesView};
@@ -1,10 +1,10 @@
1
- import{a as o,j as e}from"./markdown-DIY6o85n.js";import{c as S,u as p,aJ as L,aq as y,W as R,E as j,L as g,b as $,al as W,F as D,aK as E,ao as I,ar as M}from"./index-DNUXcSh8.js";import{u as _,g as A}from"./worker-store-CeRgJcBb.js";import{S as v}from"./server-DTGjlz_2.js";import"./vendor-D35k0Cos.js";/**
1
+ import{a as o,j as e}from"./markdown-DIY6o85n.js";import{c as S,u as p,a0 as L,aw as y,Z as R,E as j,L as g,b as $,ar as D,F as W,aP as E,au as I,ax as M}from"./index-DC-fErwI.js";import{u as P,g as _}from"./worker-store-CC1BvZFl.js";import{S as v}from"./server-C_x9ee7t.js";import"./vendor-D35k0Cos.js";/**
2
2
  * @license lucide-react v1.18.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const K=[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]],P=S("play",K);function F(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 U=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}=_();o.useEffect(()=>{i(),l();const x=setInterval(()=>{i(),l()},U);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:"flex-1 overflow-auto p-4 md:p-6",children:[m&&e.jsx(L,{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
6
+ */const A=[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]],F=S("play",A);function K(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 U=1e4;function X(){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()},U);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:"flex-1 overflow-auto p-4 md:p-6",children:[m&&e.jsx(L,{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
7
7
  hover:text-text-primary hover:bg-bg-hover rounded-lg transition-colors`,title:t("workers.refresh"),children:[e.jsx(R,{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(T,{daemon:a,onStart:()=>d(),onStop:u,onRestart:f}),e.jsx(V,{workers:s,onViewLogs:w,onKill:C})]})}function T({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
8
8
  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($,{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
9
- 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(W,{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
10
- daemon-start-btn transition-all disabled:opacity-70`,children:[l==="start"?e.jsx(g,{size:14,className:"animate-spin"}):e.jsx(P,{size:14}),n(l==="start"?"workers.daemon.starting":"workers.daemon.start")]})})]})})}function V({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(q,{worker:n,onViewLogs:s,onKill:a},`${n.pid}-${n.hostname}`))})]})}const H={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 q({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 ${H[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(D,{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(E,{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(I,{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(M,{size:14}),label:"Started",value:O(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 J(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=F(t.url);if(J(s))return s;const a=A(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 O(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};
9
+ 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(D,{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
10
+ daemon-start-btn transition-all disabled:opacity-70`,children:[l==="start"?e.jsx(g,{size:14,className:"animate-spin"}):e.jsx(F,{size:14}),n(l==="start"?"workers.daemon.starting":"workers.daemon.start")]})})]})})}function V({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(q,{worker:n,onViewLogs:s,onKill:a},`${n.pid}-${n.hostname}`))})]})}const H={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 q({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 ${H[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(E,{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(I,{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(M,{size:14}),label:"Started",value:Y(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 O(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=K(t.url);if(O(s))return s;const a=_(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 Y(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{X as WorkersView};
@@ -1 +1 @@
1
- import{e as z,f as L,a as d,h as B}from"./index-DNUXcSh8.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
+ import{e as z,f as L,a as d,h as B}from"./index-DC-fErwI.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-BeJ0HdEs.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-DEpBaaQs.js";import{h as U,i as T,j as x,t as j,k as M}from"./lspLanguageFeatures-DEpBaaQs.js";import"./index-DNUXcSh8.js";import"./markdown-DIY6o85n.js";import"./vendor-D35k0Cos.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};
1
+ import{c,l as s}from"./editor.main-vO8swxPL.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-k6vDy77A.js";import{h as U,i as T,j as x,t as j,k as M}from"./lspLanguageFeatures-k6vDy77A.js";import"./index-DC-fErwI.js";import"./markdown-DIY6o85n.js";import"./vendor-D35k0Cos.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};