edgeone
Version:
Command-line interface for TencentCloud Pages Functions
2 lines (1 loc) • 9.98 kB
JavaScript
import{r as c,j as n,R as y}from"./react-hnpCyKql.js";import{i as I,g as E,L as f,N as m,M as h}from"./tea-Slf_ajmf.js";import{a as w,T as b,A as O,b as M}from"./agent-obs-Dvi4IpEy.js";import{c as F}from"./react-dom-ZzBHVjtL.js";import"./moment-BYRO94Ou.js";import"./highlight-ClXAL37H.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))r(o);new MutationObserver(o=>{for(const i of o)if(i.type==="childList")for(const l of i.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&r(l)}).observe(document,{childList:!0,subtree:!0});function s(o){const i={};return o.integrity&&(i.integrity=o.integrity),o.referrerPolicy&&(i.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?i.credentials="include":o.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(o){if(o.ep)return;o.ep=!0;const i=s(o);fetch(o.href,i)}})();const x="edgeone_studio_lang",T=["zh","en"];function P(){try{const t=window.localStorage.getItem(x);if(t&&T.includes(t))return t}catch{}return(navigator.language||"").toLowerCase().startsWith("zh")?"zh":"en"}const p=P();window.VERSION=p;const _=w[p]||w.zh||{};I.init({translation:_});const C=new Set;function A(e){return C.add(e),()=>C.delete(e)}function k(e){if(!T.includes(e)||e===S)return;const t=E();if(!t){try{window.localStorage.setItem(x,e)}catch{}window.location.reload();return}const s=w[e]||{};t.addResourceBundle(e,"translation",s,!0,!0),t.changeLanguage(e);try{window.localStorage.setItem(x,e)}catch{}S=e,C.forEach(r=>r(e))}let S=p;window.__EDGEONE_STUDIO_SWITCH_LANG__=k;const N=["/agent-metrics","/agent-traces","/agent-studio"],B="/agent-metrics";function v(){try{const e=window.location.pathname;for(const t of N)if(e===t||e.startsWith(`${t}/`))return t}catch{}return B}function j(){return`${v()}/v1`}async function z(e){const t=new URLSearchParams;t.set("limit",String(e.pageSize??10)),t.set("offset",String(((e.pageIndex??1)-1)*(e.pageSize??10))),e.keyword&&t.set("keyword",e.keyword),e.statuses&&e.statuses.length===1&&t.set("statusGroup",e.statuses[0]),e.timeRange&&t.set("timeRange",e.timeRange),e.customRange&&(t.set("startedAtMin",String(e.customRange[0].valueOf())),t.set("startedAtMax",String(e.customRange[1].valueOf())));const s=await fetch(`${j()}/traces.list?${t.toString()}`);if(!s.ok)throw new Error(`fetch traces failed: ${s.status}`);const r=await s.json();return{rows:r.Traces||[],pagination:{pageIndex:e.pageIndex??1,pageSize:e.pageSize??10,total:r.Total??0}}}const L="agent.request:";function U(e){var t;return(t=e==null?void 0:e.Spans)!=null&&t.length?{...e,Spans:e.Spans.map(s=>({...s,...typeof s.OperationName=="string"&&s.OperationName.startsWith(L)?{OperationName:s.OperationName.slice(L.length)}:{}}))}:e}async function D(e){const t=await fetch(`${j()}/traces/${encodeURIComponent(e)}.detail`);if(!t.ok)throw new Error(`fetch trace detail failed: ${t.status}`);const s=await t.json();return U(s)}async function W(e={}){const t=new URLSearchParams;e.timeRange&&t.set("timeRange",e.timeRange),e.startTimeMs&&t.set("startedAtMin",String(e.startTimeMs)),e.endTimeMs&&t.set("startedAtMax",String(e.endTimeMs));const s=await fetch(`${j()}/metrics?${t.toString()}`);if(!s.ok)throw new Error(`fetch metrics failed: ${s.status}`);return s.json()}const $={overview:"/agent-metrics",traces:"/agent-traces"},H={"/agent-metrics":"overview","/agent-traces":"traces","/agent-studio":"overview"},G={environment:"all",timeRange:"24hour",customRange:null,statuses:[],keyword:"",pageIndex:1,pageSize:10};function R(){try{return H[v()]??"overview"}catch{return"overview"}}function V(e){try{const t=$[e];if(v()===t)return;const r=new URL(window.location.href);r.pathname=t,window.history.pushState({tab:e},"",r.toString())}catch{}}function X({initialLang:e}){const[t,s]=c.useState(()=>R()),[r,o]=c.useState(e);c.useEffect(()=>A(o),[]);const[i,l]=c.useState(!1),[a,d]=c.useState(null),g=c.useCallback(u=>{s(u),V(u)},[]);return c.useEffect(()=>{const u=()=>s(R());return window.addEventListener("popstate",u),()=>window.removeEventListener("popstate",u)},[]),n.jsxs(f,{className:"agent-studio-app",children:[n.jsx(m,{left:n.jsx(m.Item,{type:"logo",children:n.jsx(K,{})}),right:n.jsx(m.Item,{type:"default",children:n.jsx(Z,{current:r})})}),n.jsxs(f.Body,{children:[n.jsx(f.Sider,{children:n.jsx(h,{theme:"dark",children:n.jsxs(h.Group,{title:"Observability",children:[n.jsx(h.Item,{title:"Agent Metrics",icon:n.jsx(Q,{}),selected:t==="overview",onClick:()=>g("overview")}),n.jsx(h.Item,{title:"Agent Traces",icon:n.jsx(Y,{}),selected:t==="traces",onClick:()=>g("traces")})]})})}),n.jsxs(f.Content,{children:[t==="overview"&&n.jsx(J,{}),t==="traces"&&n.jsx(q,{onRowClick:u=>{d(u.TraceId),l(!0)}})]},r)]}),n.jsx(b,{visible:i,traceId:a,fetchDetail:u=>D(u),onClose:()=>l(!1)})]})}function K(){return n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[n.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 28 28",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":!0,children:[n.jsx("path",{d:"M27.7784 16.4944C27.924 15.6849 28 14.8513 28 14C28 13.2803 27.9457 12.5734 27.841 11.8829C27.8005 11.6162 27.5679 11.424 27.2981 11.424H18.2935C17.999 11.424 17.7846 11.1446 17.8608 10.86L18.9267 6.88207C19.0054 6.58829 19.2716 6.384 19.5758 6.384H24.9239C25.2793 6.384 25.4903 5.99169 25.2795 5.70554C22.7306 2.24513 18.6275 0 14 0C6.26801 0 0 6.26801 0 14C0 17.5202 1.29921 20.7369 3.44429 23.1969C3.67271 23.4588 4.0922 23.3504 4.18175 23.0146L7.27934 11.3986C7.33622 11.1853 7.17545 10.976 6.95468 10.976H4.26421C3.96986 10.976 3.75549 10.697 3.83134 10.4126L4.70485 7.13693C4.77038 6.89118 4.99334 6.72137 5.24762 6.7161C8.17874 6.65542 11.0752 5.88815 13.647 4.4841C13.9129 4.33898 14.2342 4.58196 14.1561 4.87457L8.45823 26.2418C8.37314 26.5608 8.53186 26.8961 8.83881 27.0179C10.4359 27.6517 12.1773 28 14 28C18.4191 28 22.3599 25.9526 24.9257 22.7546C25.153 22.4713 24.9444 22.064 24.5811 22.064H15.4425C15.148 22.064 14.9336 21.7846 15.0098 21.5L16.0757 17.5221C16.1544 17.2283 16.4207 17.024 16.7248 17.024H27.1324C27.4479 17.024 27.7226 16.8049 27.7784 16.4944Z",fill:"url(#edgeone-logo-grad)"}),n.jsx("defs",{children:n.jsxs("linearGradient",{id:"edgeone-logo-grad",x1:"4.816",y1:"2.352",x2:"22.288",y2:"23.184",gradientUnits:"userSpaceOnUse",children:[n.jsx("stop",{stopColor:"#00DDFF"}),n.jsx("stop",{offset:"1",stopColor:"#0C60F2"})]})})]}),n.jsx("span",{style:{fontFamily:"Oxygen, system-ui, -apple-system, sans-serif",fontSize:18,fontWeight:700,color:"#FFFFFF",letterSpacing:"-0.18px",lineHeight:1.33},children:"EdgeOne Makers"})]})}function Q(){return n.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:[n.jsx("path",{d:"M2.5 2.5V15.8333C2.5 16.2754 2.67559 16.6993 2.98816 17.0118C3.30072 17.3244 3.72464 17.5 4.16667 17.5H17.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),n.jsx("path",{d:"M15 14.1667V7.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),n.jsx("path",{d:"M10.8335 14.1667V4.16675",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),n.jsx("path",{d:"M6.6665 14.1667V11.6667",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})}function Y(){return n.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",children:[n.jsx("path",{d:"M2.06202 12.3481C1.97868 12.1236 1.97868 11.8766 2.06202 11.6521C2.87372 9.68397 4.25153 8.00116 6.02079 6.81701C7.79004 5.63287 9.87106 5.00073 12 5.00073C14.129 5.00073 16.21 5.63287 17.9792 6.81701C19.7485 8.00116 21.1263 9.68397 21.938 11.6521C22.0214 11.8766 22.0214 12.1236 21.938 12.3481C21.1263 14.3163 19.7485 15.9991 17.9792 17.1832C16.21 18.3674 14.129 18.9995 12 18.9995C9.87106 18.9995 7.79004 18.3674 6.02079 17.1832C4.25153 15.9991 2.87372 14.3163 2.06202 12.3481Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),n.jsx("circle",{cx:"12",cy:"12",r:"3",stroke:"currentColor",strokeWidth:"2"})]})}function Z(e){const t=s=>{s!==e.current&&k(s)};return n.jsx("div",{style:{display:"inline-flex",gap:2,padding:2,background:"rgba(255, 255, 255, 0.08)",borderRadius:6,fontSize:12},children:["zh","en"].map(s=>{const r=s===e.current;return n.jsx("button",{onClick:()=>t(s),style:{border:"none",padding:"3px 12px",borderRadius:4,cursor:r?"default":"pointer",background:r?"#FFFFFF":"transparent",color:r?"#000000":"rgba(255, 255, 255, 0.55)",fontWeight:r?600:400,transition:"background-color 0.15s ease, color 0.15s ease"},children:s==="zh"?"中":"EN"},s)})})}function J(){const[e,t]=c.useState([]),[s,r]=c.useState([]),[o,i]=c.useState(!0),l=c.useCallback(a=>{i(!0);const d=a==null?void 0:a.customRange;return W({environment:a==null?void 0:a.environment,timeRange:d?null:a==null?void 0:a.timeRange,startTimeMs:d?d[0].valueOf():null,endTimeMs:d?d[1].valueOf():null}).then(g=>{t(g.overview),r(g.charts)}).finally(()=>i(!1))},[]);return c.useEffect(()=>{l()},[l]),n.jsxs(n.Fragment,{children:[n.jsx(f.Content.Header,{showBackButton:!1,title:"Metrics"}),n.jsx(f.Content.Body,{full:!0,children:n.jsx("div",{style:{padding:16},children:n.jsx(O,{overview:e,charts:s,loading:o,onFilterChange:a=>{l(a)},onRefresh:l})})})]})}function q(e){const[t,s]=c.useState([]),[r,o]=c.useState({pageIndex:1,pageSize:10,total:0}),[i,l]=c.useState(!0),a=c.useCallback(d=>(l(!0),z(d).then(g=>{s(g.rows),o(g.pagination)}).finally(()=>l(!1))),[]);return c.useEffect(()=>{a(G)},[a]),n.jsxs(n.Fragment,{children:[n.jsx(f.Content.Header,{showBackButton:!1,title:"Traces"}),n.jsx(f.Content.Body,{full:!0,children:n.jsx("div",{style:{padding:16},children:n.jsx(M,{rows:t,pagination:r,loading:i,onQueryChange:d=>{a(d)},onRefresh:a,onRowClick:e.onRowClick})})})]})}F.createRoot(document.getElementById("root")).render(n.jsx(y.StrictMode,{children:n.jsx(X,{initialLang:p})}));