agentic-ui-libs 0.2.0-beta.7 → 0.2.0-beta.8

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.
@@ -1 +1 @@
1
- {"version":3,"file":"DebugCard.d.ts","sourceRoot":"","sources":["../../../../src/features/debug-logs/components/DebugCard.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAWpC,UAAU,cAAc;IACtB,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;IACvC,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC/B;AAID,wBAAgB,SAAS,CAAC,EACxB,IAAI,EACJ,QAAQ,EACR,UAAkB,EAClB,WAAW,EACX,eAAe,EAChB,EAAE,cAAc,2CA8bhB;AAED,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"DebugCard.d.ts","sourceRoot":"","sources":["../../../../src/features/debug-logs/components/DebugCard.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAWpC,UAAU,cAAc;IACtB,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;IACvC,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC/B;AAID,wBAAgB,SAAS,CAAC,EACxB,IAAI,EACJ,QAAQ,EACR,UAAkB,EAClB,WAAW,EACX,eAAe,EAChB,EAAE,cAAc,2CAgchB;AAED,eAAe,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -27634,7 +27634,7 @@ function t0({
27634
27634
  }
27635
27635
  ),
27636
27636
  /* @__PURE__ */ p.jsx("div", { className: "flex-shrink-0", children: h() }),
27637
- /* @__PURE__ */ p.jsx("span", { className: "font-semibold text-gray-900 text-xs truncate w-full", children: e.name }),
27637
+ /* @__PURE__ */ p.jsx("span", { className: "font-semibold text-gray-900 text-xs truncate w-full", children: e.type === "tool" ? y(e.name) : e.name }),
27638
27638
  /* @__PURE__ */ p.jsxs("div", { className: "flex items-center gap-[12px] text-[10px] text-gray-500", children: [
27639
27639
  e.duration && /* @__PURE__ */ p.jsxs("div", { className: "flex items-center gap-[4px]", children: [
27640
27640
  /* @__PURE__ */ p.jsx(im, { className: "w-[12px] h-[12px]" }),
@@ -262,7 +262,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
262
262
  </svg>`,MCP:`<svg width="14" height="14" viewBox="0 0 22 23" fill="none" xmlns="http://www.w3.org/2000/svg">
263
263
  <path d="M1.8125 10.7455L10.647 1.91124C11.8411 0.717087 13.7773 0.717087 14.9714 1.91124C16.1655 3.10539 16.1655 5.0415 14.9714 6.23565M14.9714 6.23565L8.29911 12.9077M14.9714 6.23565C16.1655 5.0415 18.1018 5.0415 19.2958 6.23565C20.4899 7.4298 20.4899 9.36593 19.2958 10.56L11.7665 18.0893C11.3443 18.5115 11.3443 19.1961 11.7665 19.6182L13.164 21.0158M16.9479 8.58236L10.2756 15.2547C9.08153 16.4488 7.1453 16.4488 5.95123 15.2547C4.75716 14.0605 4.75716 12.1244 5.95123 10.9303L12.6234 4.25814" stroke="#101828" stroke-width="2.00016" stroke-linecap="round" stroke-linejoin="round"/>
264
264
  </svg>`},MB=(e,t)=>{const r=e.toLowerCase();if(r.includes("code"))return Rt.inlineTool;if(r.includes("workflow")||r.includes("library"))return Rt.toolLibrary;if(r.includes("knowledge"))return Rt.KNOWLEDGE;if(r.includes("mcp"))return Rt.MCP;if(Rt[e])return Rt[e];const n=t.toLowerCase();return n.includes("code")||n.includes("inline")||n.includes("calculate")?Rt.inlineTool:n.includes("library")||n.includes("workflow")?Rt.toolLibrary:n.includes("knowledge")||n.includes("document")||n.includes("fetch")?Rt.KNOWLEDGE:n.includes("mcp")||n.includes("protocol")?Rt.MCP:Rt.toolLibrary},wi=({icon:e,iconSource:t="agent",size:r="small",className:n="",name:a="Unknown",toolType:i,provider:o,modelName:s})=>{const[l,u]=T.useState(!1),[c,f]=T.useState(!1),[d,h]=T.useState(!1),m=EB(e),y=kB[r];if(t==="model"){const w=jb(o),b=()=>{h(!0)};if(d){const A=o?o.charAt(0).toUpperCase():"🤖";return p.jsx("div",{className:`${y} rounded-full bg-gray-500 flex items-center justify-center ${n}`,children:p.jsx("span",{className:"text-white text-xs font-bold",children:A})})}return p.jsx("img",{src:w,alt:s||a,className:`${y} rounded ${n}`,onError:b})}if(m!=null&&m.name&&m.name!=="fallback"&&!l){const w=$B(m,t),b=()=>{u(!0)};return p.jsx("img",{src:w,alt:a,className:`${y} rounded-full object-cover ${n}`,onError:b})}if(l&&!c&&t==="agent"){const w=`${window.location.origin}/agenticai/assets/agent-avatars/agent1.svg`,b=()=>{f(!0)};return p.jsx("img",{src:w,alt:a,className:`${y} rounded-full object-cover ${n}`,onError:b})}if(t==="model"){const w=jb(o),b=()=>{h(!0)};if(d){const A=o?o.charAt(0).toUpperCase():"🤖";return p.jsx("div",{className:`${y} rounded-full bg-gray-500 flex items-center justify-center ${n}`,children:p.jsx("span",{className:"text-white text-xs font-bold",children:A})})}return p.jsx("img",{src:w,alt:s||a,className:`${y} rounded ${n}`,onError:b})}const v=m||CB(a,t);if(t==="workflowtool"){const w=i||v.type||"toolLibrary",b=MB(w,a);return p.jsx("div",{className:`${y} rounded-full flex items-center justify-center bg-gray-100 ${n}`,children:p.jsx("div",{dangerouslySetInnerHTML:{__html:b}})})}const x=`${window.location.origin}/agenticai/assets/agent-avatars/agent1.svg`;return p.jsx("img",{src:x,alt:a,className:`${y} rounded-full object-cover ${n}`})},_b=({data:e,className:t})=>{const[r,n]=T.useState(5),a=()=>{n(o=>Math.min(o+10,e.length))},i=o=>o>=1e3?`${Math.floor(o/1e3)}k`:o.toString();return p.jsxs("div",{className:se("w-full",t),children:[p.jsxs("div",{className:"grid grid-cols-4 items-center gap-4 px-[16px] py-[12px] bg-gray-50 border-b border-gray-200 text-xs font-medium text-gray-600",children:[p.jsx("div",{className:"text-left",children:"Name"}),p.jsx("div",{className:"text-center",children:"Runs"}),p.jsx("div",{className:"text-center",children:"Response Time"}),p.jsx("div",{className:"text-center",children:"Tokens"})]}),p.jsx("div",{className:"divide-y divide-gray-100",children:e.slice(0,r).map((o,s)=>p.jsxs("div",{className:"grid grid-cols-4 items-center gap-4 px-[16px] py-[12px] cursor-pointer transition-colors duration-150 border-b border-gray-200",children:[p.jsxs("div",{className:"flex items-center gap-[8px]",children:[p.jsx("div",{className:"flex-shrink-0",children:p.jsx(wi,{icon:o.icon,iconSource:"agent",size:"small",name:o.name||"Unknown Agent"})}),p.jsx("div",{className:"min-w-0 flex-1 w-full",children:p.jsx("div",{className:"text-xs font-medium text-gray-700 truncate",children:o.name||"Unknown Agent"})})]}),p.jsx("div",{className:"text-center font-medium text-xs text-gray-700",children:o.runs?i(o.runs):"-"}),p.jsx("div",{className:"text-center font-medium text-xs text-gray-700",children:o.responseTime||"-"}),p.jsx("div",{className:"text-center font-medium text-xs text-gray-700",children:o.tokens?i(o.tokens):"-"})]},o.id||s))}),r<e.length&&p.jsx("div",{className:"flex justify-center",children:p.jsx("button",{onClick:a,className:"px-[16px] py-[8px] text-xs font-medium text-gray-700 bg-white border border-gray-300 rounded-md hover:bg-gray-50 transition-colors duration-150",children:"Load 10 more"})})]})};function NB(e){const t=(e==null?void 0:e.toLowerCase())||"";return["inlinetool","inlineTool","code tool","code","tool","event","EVENT"].includes(e)||["inlinetool","inlineTool","code tool","code","tool","event"].includes(t)?"bg-orange-100 text-orange-800 border-orange-200":["toollibrary","toolLibrary","workflow tool"].includes(e)||["toollibrary","toollibrary","workflow tool"].includes(t)?"bg-blue-100 text-blue-800 border-blue-200":["mcp","MCP","mcpTool","mcpTool"].includes(e)||["mcp","mcptool"].includes(t)?"bg-green-100 text-green-800 border-green-200":["knowledge","KNOWLEDGE","knowledge tool"].includes(e)||["knowledge","knowledge tool"].includes(t)?"bg-purple-100 text-purple-800 border-purple-200":"bg-gray-100 text-gray-800 border-gray-200"}function DB(e){const t=(e==null?void 0:e.toLowerCase())||"";return["inlinetool","code tool","code","tool","event","inlineTool"].includes(t)?"Code Tool":["toollibrary","workflow tool"].includes(t)?"Workflow Tool":["mcp","mcptool"].includes(t)?"MCP Tool":["knowledge","knowledge tool","knowledge"].includes(t)||e==="KNOWLEDGE"?"Knowledge":e==="inlineTool"?"Code Tool":e==="toolLibrary"?"Workflow Tool":e==="KNOWLEDGE"?"Knowledge":e==="MCP"||e==="mcpTool"?"MCP Tool":"Code Tool"}const Eb=({data:e,className:t})=>{const[r,n]=T.useState(5),a=()=>{n(o=>Math.min(o+10,e.length))},i=o=>o>=1e3?`${Math.floor(o/1e3)}k`:o.toString();return p.jsxs("div",{className:se("w-full",t),children:[p.jsxs("div",{className:"grid grid-cols-4 items-center gap-4 px-[16px] py-[12px] bg-gray-50 border-b border-gray-200 text-xs font-medium text-gray-600",children:[p.jsx("div",{className:"text-left",children:"Name"}),p.jsx("div",{className:"text-center",children:"Type"}),p.jsx("div",{className:"text-center",children:"Runs"}),p.jsx("div",{className:"text-center",children:"Response Time"})]}),p.jsx("div",{className:"divide-y divide-gray-100",children:e.slice(0,r).map((o,s)=>p.jsxs("div",{className:"grid grid-cols-4 items-center gap-4 px-[16px] py-[12px] cursor-pointer transition-colors duration-150 border-b border-gray-200",children:[p.jsxs("div",{className:"flex items-center gap-[8px]",children:[p.jsx("div",{className:"flex-shrink-0",children:p.jsx(wi,{icon:o.icon,iconSource:"workflowtool",size:"small",name:o.name||"Unknown Tool",toolType:o.toolType||o.type})}),p.jsx("div",{className:"min-w-0 flex-1 w-full",children:p.jsx("div",{className:"text-xs font-medium text-gray-700 truncate",children:o.name||"Unknown Tool"})})]}),p.jsx("div",{className:"flex items-center justify-center",children:p.jsx("span",{className:se("inline-flex items-center px-[10px] py-[4px] rounded-full text-xs font-medium border",NB(o.toolType||o.type||"Default")),children:DB(o.toolType||o.type||"Default")})}),p.jsx("div",{className:"text-center font-medium text-xs text-gray-700",children:o.runs?i(o.runs):"-"}),p.jsx("div",{className:"text-center font-medium text-xs text-gray-700",children:o.responseTime||"-"})]},o.id||s))}),r<e.length&&p.jsx("div",{className:"flex justify-center",children:p.jsx("button",{onClick:a,className:"px-[16px] py-[8px] text-xs font-medium text-gray-700 bg-white border border-gray-300 rounded-md hover:bg-gray-50 transition-colors duration-150",children:"Load 10 more"})})]})},IB=e=>{if(!e)return"/assets/icons/models/custom-api.svg";const t=e.toLowerCase(),r={openai:"Open AI.svg","open ai":"Open AI.svg",chatopenai:"Open AI.svg",gpt:"Open AI.svg",anthropic:"Anthropic.svg",claude:"Anthropic.svg",google:"Google.svg",gemini:"Google.svg",chatgooglegenerativeai:"Google.svg",googlegenerativeai:"Google.svg",palm:"Google.svg",azurechatopenai:"Azure Open AI.svg","azure open ai":"Azure Open AI.svg",azureopenai:"Azure Open AI.svg","azure openai":"Azure Open AI.svg",azure:"Azure Open AI.svg",aws:"AWS Bedrock.svg",bedrock:"AWS Bedrock.svg","aws bedrock":"AWS Bedrock.svg",awsbedrock:"AWS Bedrock.svg",amazon:"AWS Bedrock.svg",cohere:"Cohere.svg",api:"API.svg",custom:"custom-api.svg","custom-api":"custom-api.svg",customapi:"custom-api.svg"};if(r[t])return`assets/icons/models/${r[t]}`;for(const[n,a]of Object.entries(r))if(t.includes(n)||n.includes(t))return`assets/icons/models/${a}`;return"assets/icons/models/custom-api.svg"},LB=e=>{if(!e)return"";const t=e.toLowerCase(),r={openai:"OpenAI","open ai":"OpenAI",chatopenai:"OpenAI",gpt:"OpenAI",anthropic:"Anthropic",claude:"Anthropic",google:"Google",gemini:"Google Gemini",chatgooglegenerativeai:"Google Gemini",googlegenerativeai:"Google Gemini",palm:"Google PaLM",azurechatopenai:"Azure OpenAI","azure open ai":"Azure OpenAI",azureopenai:"Azure OpenAI","azure openai":"Azure OpenAI",azure:"Azure OpenAI",aws:"AWS Bedrock",bedrock:"AWS Bedrock","aws bedrock":"AWS Bedrock",awsbedrock:"AWS Bedrock",amazon:"AWS Bedrock",cohere:"Cohere",meta:"Meta",llama:"Meta LLaMA",mistral:"Mistral",huggingface:"Hugging Face",together:"Together AI",replicate:"Replicate"};if(r[t])return r[t];for(const[n,a]of Object.entries(r))if(t.includes(n)||n.includes(t))return a;return e.charAt(0).toUpperCase()+e.slice(1)},RB=({provider:e})=>{const[t,r]=T.useState(!1),n=IB(e),a=()=>{r(!0)};if(t){const i=e?e.charAt(0).toUpperCase():"🤖";return p.jsx("div",{className:"w-6 h-6 rounded-full bg-gray-500 flex items-center justify-center",children:p.jsx("span",{className:"text-white text-xs font-bold",children:i})})}return p.jsx("img",{src:n,alt:e||"Model",className:"w-6 h-6 rounded",onError:a})},Cb=({data:e,className:t})=>{const[r,n]=T.useState(5),a=()=>{n(o=>Math.min(o+10,e.length))},i=o=>o>=1e3?`${Math.floor(o/1e3)}k`:o.toString();return p.jsxs("div",{className:se("w-full",t),children:[p.jsxs("div",{className:"grid grid-cols-4 items-center gap-4 px-[16px] py-[12px] bg-gray-50 border-b border-gray-200 text-xs font-medium text-gray-600",children:[p.jsx("div",{className:"text-left",children:"Model Name"}),p.jsx("div",{className:"text-center",children:"Runs"}),p.jsx("div",{className:"text-center",children:"Tokens"}),p.jsx("div",{className:"text-center",children:"Response Time"})]}),p.jsx("div",{className:"divide-y divide-gray-100",children:e.slice(0,r).map((o,s)=>p.jsxs("div",{className:"grid grid-cols-4 items-center gap-4 px-[16px] py-[12px] cursor-pointer transition-colors duration-150 border-b border-gray-200",children:[p.jsxs("div",{className:"flex items-center gap-[8px]",children:[p.jsx("div",{className:"flex-shrink-0",children:p.jsx(RB,{provider:o.provider})}),p.jsxs("div",{className:"min-w-0 flex-1 w-full",children:[p.jsx("div",{className:"text-xs font-medium text-gray-700 truncate",children:o.name||o.modelName||"Unknown Model"}),o.provider&&p.jsx("div",{className:"text-xs text-gray-500 truncate",children:LB(o.provider)})]})]}),p.jsx("div",{className:"text-center font-medium text-xs text-gray-700",children:i(o.runs||0)}),p.jsx("div",{className:"text-center font-medium text-xs text-gray-700",children:i(o.tokens||o.totalTokens||0)}),p.jsx("div",{className:"text-center font-medium text-xs text-gray-700",children:o.responseTime||(o.avgResponseTime?`${o.avgResponseTime}ms`:"N/A")})]},o.id||s))}),r<e.length&&p.jsx("div",{className:"flex justify-center",children:p.jsx("button",{onClick:a,className:"px-[16px] py-[8px] text-xs font-medium text-gray-700 bg-white border border-gray-300 rounded-md hover:bg-gray-50 transition-colors duration-150",children:"Load 10 more"})})]})},BB=e=>{switch(e){case"agentRuns":return{title:"Agent Runs",entityName:"Agents"};case"toolRuns":return{title:"Tool Runs",entityName:"Tools"};case"modelRuns":return{title:"Model Runs",entityName:"Models"};default:return{title:"Runs",entityName:"Items"}}},FB=e=>e>=1e3?`${Math.floor(e/1e3)}k`:e.toString(),$b=({isOpen:e,onClose:t,date:r,metricType:n,data:a,totalRuns:i,className:o})=>{var O;const s=BB(n),[l,u]=T.useState(10),[c,f]=T.useState("all"),[d,h]=T.useState(!1),m=[{label:`All ${s.entityName}`,value:"all"},...a.map(S=>({label:S.name,value:S.id}))],y=c==="all"?a:a.filter(S=>S.id===c),v=()=>{f("all"),h(!1),u(10),t()};T.useEffect(()=>{const S=E=>{E.key==="Escape"&&v()},P=E=>{d&&(E.target.closest(".filter-dropdown")||h(!1))};return e&&(document.addEventListener("keydown",S),document.addEventListener("mousedown",P),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",S),document.removeEventListener("mousedown",P),document.body.style.overflow="unset"}},[e,d,v]),T.useEffect(()=>{e&&(f("all"),h(!1),u(10))},[e]);const x=S=>new Date(S).toLocaleDateString("en-US",{month:"long",day:"numeric",year:"numeric"}),w=()=>{u(S=>Math.min(S+10,y.length))},b=S=>{f(S),h(!1),u(10)};if(!e)return null;const A=y.slice(0,l),g=((O=m.find(S=>S.value===c))==null?void 0:O.label)||`All ${s.entityName}`;return p.jsxs(p.Fragment,{children:[p.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 z-40 transition-opacity duration-300",onClick:v}),p.jsxs("div",{className:se("fixed right-0 top-0 h-full w-[600px] bg-white shadow-[0px_20px_24px_-4px_rgba(16,24,40,0.08),0px_8px_8px_-4px_rgba(16,24,40,0.03)] z-50 transform transition-transform duration-300 ease-in-out",e?"translate-x-0":"translate-x-full",o),children:[p.jsxs("div",{className:"flex items-center justify-between px-6 py-3 border-b border-[#d0d5dd]",children:[p.jsx("h2",{className:"text-lg font-semibold text-[#101828]",children:s.title}),p.jsx("button",{onClick:v,className:"p-2 hover:bg-gray-100 rounded-lg transition-colors",children:p.jsx(Ef,{className:"h-5 w-5 text-[#101828]"})})]}),p.jsxs("div",{className:"flex flex-col h-[calc(100%-64px)] p-6 gap-6",children:[p.jsxs("div",{className:"flex items-center justify-between",children:[p.jsxs("div",{className:"text-sm font-medium text-[#344054]",children:[s.title," (",x(r),")"]}),p.jsxs("div",{className:"w-[210px] relative filter-dropdown",children:[p.jsxs("button",{onClick:()=>h(!d),className:"w-full bg-white border border-[#d0d5dd] rounded-lg px-3.5 py-2.5 flex items-center justify-between text-sm text-[#101828] hover:bg-gray-50 transition-colors",children:[p.jsx("span",{children:g}),p.jsx(cr,{className:"h-4 w-4 text-[#101828]"})]}),d&&p.jsx("div",{className:"absolute top-full left-0 right-0 mt-1 bg-white border border-[#d0d5dd] rounded-lg shadow-lg z-10 max-h-60 overflow-y-auto",children:m.map(S=>p.jsx("button",{onClick:()=>b(S.value),className:se("w-full px-3.5 py-2.5 text-left text-sm hover:bg-gray-50 transition-colors",c===S.value?"bg-blue-50 text-blue-700":"text-[#101828]"),children:S.label},S.value))})]})]}),p.jsxs("div",{className:"flex-1 overflow-hidden",children:[p.jsx("div",{className:"bg-[#f9fafb] border-b border-[#eaecf0] px-2 py-2",children:p.jsxs("div",{className:"grid grid-cols-4 gap-3 items-center",children:[p.jsx("div",{className:"col-span-2 px-0 py-2",children:p.jsx("div",{className:"text-xs font-medium text-[#475467]",children:"Name"})}),p.jsx("div",{className:"flex justify-center px-0 py-2",children:p.jsx("div",{className:"text-xs font-medium text-[#475467]",children:"Runs"})}),p.jsx("div",{className:"flex justify-center px-0 py-2",children:p.jsx("div",{className:"text-xs font-medium text-[#475467]",children:"Response Time"})})]})}),p.jsx("div",{className:"overflow-y-auto max-h-[calc(100%-40px)]",children:A.length===0?p.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-center",children:[p.jsxs("h3",{className:"text-md font-medium text-gray-900 mb-[8px]",children:["No ",s.title.toLowerCase()," for this date"]}),p.jsxs("p",{className:"text-xs text-gray-500",children:["There were no ",s.title.toLowerCase()," recorded on ",x(r),"."]})]}):p.jsxs(p.Fragment,{children:[A.map((S,P)=>p.jsxs("div",{className:"grid grid-cols-4 gap-3 items-center px-2 py-3 border-b border-[#eaecf0] hover:bg-gray-50 transition-colors",children:[p.jsxs("div",{className:"col-span-2 flex items-center gap-2",children:[p.jsx("div",{className:"flex-shrink-0",children:p.jsx(wi,{icon:S.icon,iconSource:n==="agentRuns"?"agent":n==="toolRuns"?"workflowtool":"model",size:"small",name:S.name,toolType:S.toolType||S.type,provider:S.provider,modelName:S.modelName})}),p.jsxs("div",{className:"min-w-0 flex-1",children:[p.jsx("div",{className:"text-sm font-medium text-[#101828] truncate",children:S.name}),n==="modelRuns"&&S.provider&&p.jsx("div",{className:"text-xs text-[#475467] truncate",children:S.provider})]})]}),p.jsx("div",{className:"flex justify-center",children:p.jsx("div",{className:"text-xs font-medium text-[#475467]",children:FB(S.runs)})}),p.jsx("div",{className:"flex justify-center",children:p.jsx("div",{className:"text-xs font-medium text-[#475467]",children:S.responseTime})})]},S.id||P)),l<y.length&&p.jsx("div",{className:"flex justify-center",children:p.jsx("button",{onClick:w,className:"bg-white border border-[#d0d5dd] rounded px-3 py-1 text-xs font-medium text-[#344054] hover:bg-gray-50 transition-colors",children:"Load 10 more"})})]})})]})]})]})]})};class kb{constructor(t=""){Bt(this,"API_PATH","/tracing/api/trpc/metrics.getMetrics");Bt(this,"baseUrl","");Bt(this,"endpoints",{});this.baseUrl=t,this.initializeEndpoints()}setBaseUrl(t){this.baseUrl=t,this.initializeEndpoints()}getEndpoint(t){return this.endpoints[t]||{endpoint:"",method:"GET"}}getBaseUrl(){return this.baseUrl}initializeEndpoints(){const t=`${this.baseUrl}${this.API_PATH}`;this.endpoints["usage-analytics.cards"]={endpoint:t,method:"GET",baseEndpoint:this.API_PATH},this.endpoints["usage-analytics.sessions.timeseries"]={endpoint:t,method:"GET",baseEndpoint:this.API_PATH},this.endpoints["usage-analytics.messages.timeseries"]={endpoint:t,method:"GET",baseEndpoint:this.API_PATH},this.endpoints["usage-analytics.users.timeseries"]={endpoint:t,method:"GET",baseEndpoint:this.API_PATH},this.endpoints["usage-analytics.tokens.timeseries"]={endpoint:t,method:"GET",baseEndpoint:this.API_PATH},this.endpoints["runs.cards"]={endpoint:t,method:"GET",baseEndpoint:this.API_PATH},this.endpoints["runs.agent-runs.timeseries"]={endpoint:t,method:"GET",baseEndpoint:this.API_PATH},this.endpoints["runs.model-runs.timeseries"]={endpoint:t,method:"GET",baseEndpoint:this.API_PATH},this.endpoints["runs.tool-runs.timeseries"]={endpoint:t,method:"GET",baseEndpoint:this.API_PATH}}getAvailableEndpoints(){return Object.keys(this.endpoints)}hasEndpoint(t){return t in this.endpoints}}class Mb{constructor(t){Bt(this,"endpointsService");Bt(this,"defaultHeaders");Bt(this,"timeout");this.endpointsService=new kb(t.baseUrl),this.defaultHeaders={"Content-Type":"application/json",...t.defaultHeaders},this.timeout=t.timeout||3e4}updateConfig(t){t.baseUrl&&this.endpointsService.setBaseUrl(t.baseUrl),t.defaultHeaders&&(this.defaultHeaders={...this.defaultHeaders,...t.defaultHeaders}),t.timeout&&(this.timeout=t.timeout)}async invoke(t,r,n,a){const i=this.endpointsService.getEndpoint(t);if(!i.endpoint)throw new Error(`Endpoint not found for service: ${t}`);const o=this.prepareRequest(i,r,n);try{const s=new AbortController,l=setTimeout(()=>s.abort(),(a==null?void 0:a.timeout)||this.timeout),u=await fetch(o.url,{method:o.method,headers:o.headers,body:o.body,signal:(a==null?void 0:a.signal)||s.signal});if(clearTimeout(l),!u.ok)throw new Error(`HTTP Error: ${u.status} ${u.statusText}`);return await u.json()}catch(s){throw s instanceof Error?s.name==="AbortError"?new Error("Request timeout"):s:new Error("Unknown error occurred during API call")}}prepareRequest(t,r,n){const a={...this.defaultHeaders,...n},i={};Object.entries(a).forEach(([l,u])=>{u!==void 0&&(i[l]=u)});let o=t.endpoint,s;if(t.method==="GET"&&r){const l=this.buildQueryParams(r);o+=`?${l}`}else r&&(s=JSON.stringify(r));return{url:o,method:t.method,headers:i,body:s}}buildQueryParams(t){const r={json:t},n=new URLSearchParams;return n.append("input",JSON.stringify(r)),n.append("rnd",Math.random().toString(36).substring(7)),n.toString()}getBaseUrl(){return this.endpointsService.getBaseUrl()}hasEndpoint(t){return this.endpointsService.hasEndpoint(t)}getAvailableEndpoints(){return this.endpointsService.getAvailableEndpoints()}}class Ht{constructor(t){Bt(this,"apiInvoker");Bt(this,"projectId");Bt(this,"environment");Bt(this,"defaultTimeRange");const r={baseUrl:t.baseUrl,defaultHeaders:t.headers,timeout:3e4};this.apiInvoker=new Mb(r),this.projectId=t.projectId,this.environment=t.environment,this.defaultTimeRange=t.defaultTimeRange}updateConfig(t){(t.baseUrl||t.headers)&&this.apiInvoker.updateConfig({baseUrl:t.baseUrl,defaultHeaders:t.headers}),t.projectId&&(this.projectId=t.projectId),t.environment&&(this.environment=t.environment),t.defaultTimeRange&&(this.defaultTimeRange=t.defaultTimeRange,console.log("🔄 API Service: Updated defaultTimeRange:",this.defaultTimeRange))}getDefaultTimeRange(){return this.defaultTimeRange||Ht.getDateRange(7)}async fetchEnvironments(){try{const r=`${this.apiInvoker.getBaseUrl()}/aaa/api/v1/apps/${this.projectId}/environments?rnd=${Math.random().toString(36).substring(2,8)}`;console.log("🌍 Fetching environments for project:",this.projectId),console.log("🔗 Environment API URL:",r);const n=await fetch(r,{method:"GET",headers:{"Content-Type":"application/json",...this.apiInvoker.defaultHeaders}});if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);const a=await n.json();return console.log("✅ Environments fetched successfully:",a.map(i=>({name:i.envName,enabled:i.isEnabled,status:i.status}))),a}catch(t){throw console.error("❌ Error fetching environments:",t),t}}async fetchUsageAnalyticsCards(t,r,n,a=[]){const i=n||Ht.getTimeDimension(t,r);console.log("📊 Fetching usage analytics cards:",{dateRange:{fromTimestamp:t,toTimestamp:r},providedTimeDimension:n,resolvedTimeDimension:i});const o={projectId:this.projectId,type:"cards",category:"usage-analytics",envId:this.environment,fromTimestamp:t,toTimestamp:r,filter:a,includeTrends:!0,timeDimension:i};return(await this.apiInvoker.invoke("usage-analytics.cards",o)).result.data.json}async fetchRunsCards(t,r,n,a=[]){const i=n||Ht.getTimeDimension(t,r);console.log("📊 Fetching runs cards:",{dateRange:{fromTimestamp:t,toTimestamp:r},providedTimeDimension:n,resolvedTimeDimension:i});const o={projectId:this.projectId,type:"cards",category:"runs",envId:this.environment,fromTimestamp:t,toTimestamp:r,filter:a,includeTrends:!0,timeDimension:i};return(await this.apiInvoker.invoke("runs.cards",o)).result.data.json}async fetchTimeSeriesData(t,r,n,a,i,o=[]){const s=i||Ht.getTimeDimension(n,a);console.log("📊 Fetching time series data:",{metric:t,category:r,dateRange:{fromTimestamp:n,toTimestamp:a},providedTimeDimension:i,resolvedTimeDimension:s});const l=`${r}.${t}.timeseries`,u={projectId:this.projectId,type:"time-series",category:r,envId:this.environment,fromTimestamp:n,toTimestamp:a,filter:o,metric:t,timeDimension:s};return(await this.apiInvoker.invoke(l,u)).result.data.json}transformUsageAnalyticsCards(t){const r=t.data.trends;console.log("Transforming usage analytics cards with trends:",r);const n=a=>a>0?"increase":"decrease";return[{title:"Users",value:t.data.users,metricType:"users",icon:"users",info:"Number of unique users who interacted with the app",highlighted:!0,change:r!=null&&r.users?{value:Math.abs(r.users.changePercent),type:n(r.users.changePercent)}:void 0},{title:"Sessions",value:t.data.sessions,metricType:"sessions",icon:"activity",info:"Number of conversations initiated with the app",highlighted:!1,change:r!=null&&r.sessions?{value:Math.abs(r.sessions.changePercent),type:n(r.sessions.changePercent)}:void 0},{title:"Messages",value:t.data.messages.total,metricType:"messages",icon:"message-circle",info:"Total messages exchanged between users and the app",highlighted:!1,change:r!=null&&r.messages?{value:Math.abs(r.messages.changePercent.total),type:n(r.messages.changePercent.total)}:void 0},{title:"Tokens",value:t.data.tokens.total,metricType:"tokens",icon:"coins",info:"Total input and output tokens processed by the app for all interactions",highlighted:!1,change:r!=null&&r.tokens?{value:Math.abs(r.tokens.changePercent.total),type:n(r.tokens.changePercent.total)}:void 0}]}transformRunsCards(t){const r=t.data.trends;console.log("Transforming runs cards with trends:",r);const n=a=>a>0?"increase":"decrease";return[{title:"Agent Runs",value:t.data.agentRuns,metricType:"agentRuns",icon:"bot",info:"Number of times the AI agents were executed to handle user requests",highlighted:!0,change:r!=null&&r.agentRuns?{value:Math.abs(r.agentRuns.changePercent),type:n(r.agentRuns.changePercent)}:void 0},{title:"Tool Runs",value:t.data.toolRuns.total,metricType:"toolRuns",icon:"wrench",info:"Number of times various tools were triggered by the AI agents to complete tasks",highlighted:!1,change:r!=null&&r.toolRuns?{value:Math.abs(r.toolRuns.changePercent.total),type:n(r.toolRuns.changePercent.total)}:void 0},{title:"Model Runs",value:t.data.modelRuns,metricType:"modelRuns",icon:"cpu",info:"Number of times the AI agents called various language models to generate responses",highlighted:!1,change:r!=null&&r.modelRuns?{value:Math.abs(r.modelRuns.changePercent),type:n(r.modelRuns.changePercent)}:void 0}]}transformTimeSeriesDataForMetric(t,r){var a;if(console.log("=== METRIC-SPECIFIC TRANSFORM DEBUG ==="),console.log("Raw TimeSeriesResponse:",JSON.stringify(t,null,2)),console.log("Metric type:",r),!t||!t.data||!Array.isArray(t.data))return console.error("Invalid time series data structure:",t),[];const n=t.data.map((i,o)=>{console.log(`Processing point ${o}:`,i);const s=new Date(i.timestamp),l=s.toISOString().split("T")[0],u=s.toLocaleDateString("en-US",{month:"short",day:"numeric"}),c={date:l,timestamp:u,formattedDate:u,count:i.count||0,value:i.count||0,input_tokens:i.input_tokens||0,output_tokens:i.output_tokens||0,total_tokens:(i.input_tokens||0)+(i.output_tokens||0),inputTokens:i.input_tokens||0,outputTokens:i.output_tokens||0,totalTokens:(i.input_tokens||0)+(i.output_tokens||0),listView:i.listView||[],index:o};switch(r){case"users":c.users=i.count||0;break;case"sessions":c.sessions=i.count||0;break;case"messages":c.messages=i.count||0;break;case"tokens":c.tokens=i.count||0,i.input_tokens||i.output_tokens?c.totalTokens=(i.input_tokens||0)+(i.output_tokens||0):c.totalTokens=i.count||0;break;case"agentRuns":c.agentRuns=i.count||0;break;case"toolRuns":c.toolRuns=i.count||0;break;case"modelRuns":c.modelRuns=i.count||0;break;default:c.users=i.count||0,c.sessions=i.count||0,c.messages=i.count||0,c.tokens=i.count||0,c.agentRuns=i.count||0,c.toolRuns=i.count||0,c.modelRuns=i.count||0}return console.log(`Transformed point ${o} for metric ${r}:`,c),c});return console.log("Final transformed data array:",JSON.stringify(n,null,2)),console.log("Sample transformed point for chart:",n[0]),console.log("Populated metric property:",r,"=",(a=n[0])==null?void 0:a[r||"count"]),console.log("=== END METRIC-SPECIFIC TRANSFORM DEBUG ==="),n}transformTimeSeriesData(t){return this.transformTimeSeriesDataForMetric(t)}transformAgentsListViewToTable(t){return Array.isArray(t)?t.map((r,n)=>{var o,s;let a="",i=null;if(r.icon)try{if(i=typeof r.icon=="string"?JSON.parse(r.icon):r.icon,i.name){const l=((o=r.agentName)==null?void 0:o.replace(/\s+/g,""))||`agent${n}`,u=((s=i.color)==null?void 0:s.replace("#",""))||"b6e3f4";a=`https://api.dicebear.com/7.x/avataaars/svg?seed=${l}&backgroundColor=${u}&backgroundType=solid`}}catch{console.warn("Failed to parse icon data:",r.icon)}return{id:`agent-${n+1}`,name:r.agentName||`Agent ${n+1}`,runs:r.count||0,responseTime:r.avgResponseTime?r.avgResponseTime<1e3?`${Math.round(r.avgResponseTime)}ms`:`${(r.avgResponseTime/1e3).toFixed(2)}s`:"0ms",tokens:r.tokens||Math.floor((r.count||0)*150),successRate:r.successRate?`${Math.round(r.successRate)}%`:"95%",lastRun:r.lastRun||new Date(Date.now()-Math.random()*7*24*60*60*1e3).toLocaleDateString(),avatar:a||`https://api.dicebear.com/7.x/avataaars/svg?seed=agent${n}&backgroundColor=b6e3f4,c0aede,d1d4f9&backgroundType=solid`,icon:r.icon||void 0}}):(console.warn("Invalid listView data for agents:",t),[])}transformToolsListViewToTable(t){return Array.isArray(t)?t.map((r,n)=>({id:`tool-${n+1}`,name:r.toolName||r.tool_name||`Tool ${n+1}`,type:r.type||r.toolType||r.tool_type||"Code Tool",runs:r.count||0,responseTime:r.avgResponseTime?r.avgResponseTime<1e3?`${Math.round(r.avgResponseTime)}ms`:`${(r.avgResponseTime/1e3).toFixed(2)}s`:"0ms",tokens:r.tokens||Math.floor((r.count||0)*50),successRate:r.successRate?`${Math.round(r.successRate)}%`:"92%",lastRun:r.lastRun||new Date(Date.now()-Math.random()*7*24*60*60*1e3).toLocaleDateString(),icon:r.icon||r.tool_icon||void 0})):(console.warn("Invalid listView data for tools:",t),[])}transformModelsListViewToTable(t){return Array.isArray(t)?t.map((r,n)=>({id:`model-${n+1}`,name:r.modelName||`Model ${n+1}`,modelName:r.modelName,provider:r.provider,runs:r.count||0,responseTime:r.avgResponseTime?r.avgResponseTime<1e3?`${Math.round(r.avgResponseTime)}ms`:`${(r.avgResponseTime/1e3).toFixed(2)}s`:"0ms",avgResponseTime:r.avgResponseTime,tokens:r.tokens||r.totalTokens||Math.floor((r.count||0)*300),totalTokens:r.totalTokens||r.tokens,successRate:r.successRate?`${Math.round(r.successRate)}%`:"98%",lastRun:r.lastRun||new Date(Date.now()-Math.random()*7*24*60*60*1e3).toLocaleDateString(),icon:r.icon})):(console.warn("Invalid listView data for models:",t),[])}extractAgentControlOptions(t){if(!Array.isArray(t))return[{label:"All Agents",value:"all"}];const r=[{label:"All Agents",value:"all"}];return t.forEach(n=>{var a;if(n.agentName){let i="";try{if(n.icon){const o=typeof n.icon=="string"?JSON.parse(n.icon):n.icon;if(o.name){const s=n.agentName.replace(/\s+/g,""),l=((a=o.color)==null?void 0:a.replace("#",""))||"b6e3f4";i=`https://api.dicebear.com/7.x/avataaars/svg?seed=${s}&backgroundColor=${l}&backgroundType=solid`}}}catch{console.warn("Failed to parse icon data for control:",n.icon)}r.push({label:n.agentName,value:n.agentName.replace(/\s+/g,"").toLowerCase(),avatar:i||`https://api.dicebear.com/7.x/avataaars/svg?seed=${n.agentName.replace(/\s+/g,"")}&backgroundColor=b6e3f4,c0aede,d1d4f9&backgroundType=solid`})}}),r}extractToolControlOptions(t){if(!Array.isArray(t))return[{label:"All Tools",value:"all"}];const r=[{label:"All Tools",value:"all"}];return t.forEach(n=>{const a=n.toolName||n.tool_name;if(a){let i=function(o){if(!o)return"Code Tool";const s=o.toLowerCase();return["inlinetool","code tool","code","event"].includes(s)?"Code Tool":["toollibrary","workflow tool"].includes(s)?"Workflow Tool":["mcp","mcptool"].includes(s)?"MCP Tool":["knowledge","knowledge tool"].includes(s)||o==="KNOWLEDGE"?"Knowledge":o==="inlineTool"?"Code Tool":o==="toolLibrary"?"Workflow Tool":o==="MCP"||o==="mcpTool"?"MCP Tool":"Code Tool"};r.push({label:a,value:a.replace(/[-]/g,""),icon:n.icon||n.tool_icon||void 0,type:n.type||i(n.toolType||n.tool_type)})}}),r}extractModelControlOptions(t){if(!Array.isArray(t))return[{label:"All Models",value:"all"}];const r=[{label:"All Models",value:"all"}];return t.forEach(n=>{n.modelName&&r.push({label:n.modelName,value:n.modelName.replace(/[-\.]/g,""),icon:n.icon,type:n.provider})}),r}async fetchTimeSeriesDataWithTableData(t,r,n,a,i,o=[]){const s=await this.fetchTimeSeriesData(t,r,n,a,i,o);let l=[];s.data.forEach(d=>{d.listView&&Array.isArray(d.listView)&&(l=[...l,...d.listView])});const u=this.aggregateListViewItems(l);let c=[],f=[];return t==="agent-runs"?(c=this.transformAgentsListViewToTable(u),f=this.extractAgentControlOptions(u)):t==="tool-runs"?(c=this.transformToolsListViewToTable(u),f=this.extractToolControlOptions(u)):t==="model-runs"&&(c=this.transformModelsListViewToTable(u),f=this.extractModelControlOptions(u)),{chartData:this.transformTimeSeriesDataForMetric(s,t.replace("-","")),tableData:c,controlOptions:f}}aggregateListViewItems(t){const r=new Map;return t.forEach(n=>{const a=n.agentName||n.toolName||n.modelName||"unknown";if(r.has(a)){const i=r.get(a);i.count=(i.count||0)+(n.count||0),i.avgResponseTime=i.avgResponseTime&&n.avgResponseTime?(i.avgResponseTime+n.avgResponseTime)/2:i.avgResponseTime||n.avgResponseTime,i.tokens=(i.tokens||0)+(n.tokens||0)}else r.set(a,{...n})}),Array.from(r.values())}async fetchEnhancedMetricsData(t,r,n,a=[]){try{const[i,o,s]=await Promise.all([this.fetchTimeSeriesDataWithTableData("agent-runs","runs",t,r,n,a),this.fetchTimeSeriesDataWithTableData("tool-runs","runs",t,r,n,a),this.fetchTimeSeriesDataWithTableData("model-runs","runs",t,r,n,a)]);return{agents:i,tools:o,models:s}}catch(i){throw console.error("Error fetching enhanced metrics data:",i),i}}async transformRunsCardsWithEnhancedData(t,r,n,a,i=[]){const o=t.data.trends,s=h=>h>0?"increase":"decrease",[l,u,c,f]=await Promise.all([this.fetchTimeSeriesDataWithTableData("agent-runs","runs",r,n,a,i),this.fetchTimeSeriesDataWithTableData("tool-runs","runs",r,n,a,i),this.fetchTimeSeriesDataWithTableData("model-runs","runs",r,n,a,i),this.fetchTimeSeriesData("tool-runs","runs",r,n,a,i)]),d=this.transformTimeSeriesDataForToolRuns(f);return[{title:"Agent Runs",value:t.data.agentRuns,metricType:"agentRuns",icon:"bot",highlighted:!0,info:"Number of times the AI agents were executed to handle user requests",change:o!=null&&o.agentRuns?{value:Math.abs(o.agentRuns.changePercent),type:s(o.agentRuns.changePercent)}:void 0,view:{type:"chart",chart:{type:"line",title:"Agent Runs",data:l.chartData,dataKey:"agentRuns",color:"#0BA5EC",yAxisLabel:"Number of Agent Runs",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:r.split("T")[0],end:n.split("T")[0]}},table:{title:"Agent Runs",data:l.tableData,columns:[{key:"name",title:"Name",width:200,align:"left"},{key:"runs",title:"Runs",width:100,align:"right",formatter:h=>`${Math.floor(h/1e3)}k`},{key:"responseTime",title:"Response Time",width:120,align:"right"},{key:"tokens",title:"Tokens",width:100,align:"right",formatter:h=>`${Math.floor(h/1e3)}k`}]}},controls:{dropdown:{label:"All Agents",options:l.controlOptions,defaultValue:["all"],multiSelect:!0,searchable:!0},toggle:{chartView:!0,tableView:!0}}},{title:"Tool Runs",value:t.data.toolRuns.total,metricType:"toolRuns",icon:"wrench",info:"Number of times various tools were triggered by the AI agents to complete tasks",highlighted:!1,change:o!=null&&o.toolRuns?{value:Math.abs(o.toolRuns.changePercent.total),type:s(o.toolRuns.changePercent.total)}:void 0,view:{type:"chart",chart:{type:"line",title:"Tool Runs",data:d,yAxisLabel:"Number of Tool Runs",lines:[{dataKey:"toolRuns",color:"#667085",label:"Tool Runs"},{dataKey:"codeTools",color:"#F38744",label:"Code Tools"},{dataKey:"workflowTools",color:"#2970FF",label:"Workflow Tools"},{dataKey:"knowledgeTools",color:"#7A5AF8",label:"Knowledge"},{dataKey:"mcpTools",color:"#47CD89",label:"MCP Tools"}],height:300,showGrid:!0,showLegend:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:r.split("T")[0],end:n.split("T")[0]}},table:{title:"Tool Runs",data:u.tableData,columns:[{key:"name",title:"Name",width:200,align:"left"},{key:"type",title:"Type",width:150,align:"left"},{key:"runs",title:"Runs",width:100,align:"right",formatter:h=>`${Math.floor(h/1e3)}k`},{key:"responseTime",title:"Response Time",width:120,align:"right"}]}},controls:{dropdown:{label:"All Tools",options:u.controlOptions,defaultValue:["all"],multiSelect:!0,searchable:!0},toggle:{chartView:!0,tableView:!0}}},{title:"Model Runs",value:t.data.modelRuns,metricType:"modelRuns",icon:"cpu",highlighted:!1,info:"Number of times the AI agents called various language models to generate responses",change:o!=null&&o.modelRuns?{value:Math.abs(o.modelRuns.changePercent),type:s(o.modelRuns.changePercent)}:void 0,view:{type:"chart",chart:{type:"line",title:"Model Runs",data:c.chartData,dataKey:"modelRuns",color:"#47CD89",yAxisLabel:"Number of Model Runs",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:r.split("T")[0],end:n.split("T")[0]}},table:{title:"Model Runs",data:c.tableData,columns:[{key:"name",title:"Model Name",width:200,align:"left"},{key:"runs",title:"Runs",width:100,align:"right",formatter:h=>`${Math.floor(h/1e3)}k`},{key:"tokens",title:"Tokens",width:120,align:"right",formatter:h=>`${Math.floor(h/1e3)}k`},{key:"responseTime",title:"Response Time",width:120,align:"right"}]}},controls:{dropdown:{label:"All Models",options:c.controlOptions,defaultValue:["all"],multiSelect:!0,searchable:!0},toggle:{chartView:!0,tableView:!0}}}]}async transformUsageAnalyticsCardsWithEnhancedData(t,r,n,a,i=[]){const o=t.data.trends,s=d=>d>0?"increase":"decrease",[l,u,c,f]=await Promise.all([this.fetchTimeSeriesData("users","usage-analytics",r,n,a,i),this.fetchTimeSeriesData("sessions","usage-analytics",r,n,a,i),this.fetchTimeSeriesData("messages","usage-analytics",r,n,a,i),this.fetchTimeSeriesData("tokens","usage-analytics",r,n,a,i)]);return[{title:"Users",value:t.data.users,metricType:"users",icon:"users",highlighted:!0,info:"Number of unique users who interacted with the app",change:o!=null&&o.users?{value:Math.abs(o.users.changePercent),type:s(o.users.changePercent)}:void 0,view:{type:"chart",chart:{type:"line",title:"Total Users",data:this.transformTimeSeriesDataForMetric(l,"users"),dataKey:"users",color:"#4E5BA6",yAxisLabel:"Number of Users",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:r.split("T")[0],end:n.split("T")[0]}}}},{title:"Sessions",value:t.data.sessions,metricType:"sessions",icon:"activity",highlighted:!1,info:"Number of conversations initiated with the app",change:o!=null&&o.sessions?{value:Math.abs(o.sessions.changePercent),type:s(o.sessions.changePercent)}:void 0,view:{type:"chart",chart:{type:"line",title:"Total Sessions",data:this.transformTimeSeriesDataForMetric(u,"sessions"),dataKey:"sessions",color:"#0BA5EC",yAxisLabel:"Number of Sessions",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:r.split("T")[0],end:n.split("T")[0]}}}},{title:"Messages",value:t.data.messages.total,metricType:"messages",icon:"message-circle",info:"Total messages exchanged between users and the app",highlighted:!1,change:o!=null&&o.messages?{value:Math.abs(o.messages.changePercent.total),type:s(o.messages.changePercent.total)}:void 0,view:{type:"chart",chart:{type:"line",title:"Total Messages",data:this.transformTimeSeriesDataForMetric(c,"messages"),dataKey:"messages",color:"#E478FA",yAxisLabel:"Number of Messages",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:r.split("T")[0],end:n.split("T")[0]}}}},{title:"Tokens",value:t.data.tokens.total,metricType:"tokens",icon:"coins",info:"Total input and output tokens processed by the app for all interactions",highlighted:!1,change:o!=null&&o.tokens?{value:Math.abs(o.tokens.changePercent.total),type:s(o.tokens.changePercent.total)}:void 0,view:{type:"chart",chart:{type:"line",title:"Token Usage Breakdown",data:this.transformTimeSeriesDataForMetric(f,"tokens"),yAxisLabel:"Number of Tokens",lines:[{dataKey:"totalTokens",color:"#FF692E",label:"Total Tokens"},{dataKey:"inputTokens",color:"#5925DC",label:"Input Tokens"},{dataKey:"outputTokens",color:"#E478FA",label:"Output Tokens"}],height:300,showGrid:!0,showLegend:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:r.split("T")[0],end:n.split("T")[0]}}}}]}transformTimeSeriesDataForToolRuns(t){if(console.log("=== TOOL RUNS SPECIFIC TRANSFORM DEBUG ==="),console.log("Raw TimeSeriesResponse for tool runs:",JSON.stringify(t,null,2)),!t||!t.data||!Array.isArray(t.data))return console.error("Invalid time series data structure:",t),[];const r=t.data.map((n,a)=>{console.log(`Processing point ${a}:`,n);const i=new Date(n.timestamp),o=i.toISOString().split("T")[0],s=i.toLocaleDateString("en-US",{month:"short",day:"numeric"}),l=n.count||0;let u=0,c=0,f=0,d=0;if(n.listView&&Array.isArray(n.listView)){n.listView.forEach(y=>{const v=y.count||0,x=(y.toolType||y.tool_type||"").toLowerCase(),w=(y.toolName||y.tool_name||"").toLowerCase();console.log("Processing listView item:",{toolType:x,toolName:w,count:v});const b=x.toLowerCase();["inlinetool","inlineTool","tool","code","codetool","event","EVENT"].includes(x)||["inlinetool","tool","code","codetool","event"].includes(b)?u+=v:["toollibrary","toolLibrary","workflow","workflowtool"].includes(x)||["toollibrary","workflow","workflowtool"].includes(b)?c+=v:["knowledge","KNOWLEDGE","knowledgetool"].includes(x)||["knowledge","knowledgetool"].includes(b)?f+=v:["mcp","MCP","mcptool","mcpTool"].includes(x)||["mcp","mcptool"].includes(b)?d+=v:(console.log(`Unknown tool type '${x}' for tool '${w}', defaulting to code tools`),u+=v)}),console.log(`Calculated breakdown for point ${a}:`,{codeTools:u,workflowTools:c,knowledgeTools:f,mcpTools:d,total:u+c+f+d,expectedTotal:l});const m=u+c+f+d;if(Math.abs(m-l)>1){console.warn(`Breakdown total (${m}) doesn't match expected total (${l}) for point ${a}`);const y=l-m;u+=y,console.log(`Adjusted codeTools by ${y} to balance total`)}}else console.log(`No listView data for point ${a}, assigning all ${l} to codeTools`),u=l;const h={date:o,timestamp:s,formattedDate:s,toolRuns:l,value:l,count:l,codeTools:u,workflowTools:c,knowledgeTools:f,mcpTools:d,input_tokens:n.input_tokens||0,output_tokens:n.output_tokens||0,total_tokens:(n.input_tokens||0)+(n.output_tokens||0),inputTokens:n.input_tokens||0,outputTokens:n.output_tokens||0,totalTokens:(n.input_tokens||0)+(n.output_tokens||0),listView:n.listView||[],index:a};return console.log(`Transformed tool runs point ${a}:`,h),h});return console.log("Final tool runs transformed data:",JSON.stringify(r,null,2)),console.log("=== END TOOL RUNS SPECIFIC TRANSFORM DEBUG ==="),r}async fetchAllCardsData(t,r,n=[]){try{const[a,i]=await Promise.all([this.fetchUsageAnalyticsCards(t,r,void 0,n),this.fetchRunsCards(t,r,void 0,n)]);return{usageAnalytics:this.transformUsageAnalyticsCards(a),runs:this.transformRunsCards(i)}}catch(a){throw console.error("Error fetching cards data:",a),a}}async fetchAllCardsDataWithEnhancedViews(t,r,n,a=[]){try{const[i,o]=await Promise.all([this.fetchUsageAnalyticsCards(t,r,n,a),this.fetchRunsCards(t,r,n,a)]),[s,l]=await Promise.all([this.transformUsageAnalyticsCardsWithEnhancedData(i,t,r,n,a),this.transformRunsCardsWithEnhancedData(o,t,r,n,a)]);return{usageAnalytics:s,runs:l}}catch(i){throw console.error("Error fetching enhanced cards data:",i),i}}async fetchDefaultTimeSeriesData(t,r,n,a=[]){try{const[i,o]=await Promise.all([this.fetchTimeSeriesData("sessions","usage-analytics",t,r,n,a),this.fetchTimeSeriesData("agent-runs","runs",t,r,n,a)]);return{sessions:this.transformTimeSeriesData(i),agentRuns:this.transformTimeSeriesData(o)}}catch(i){throw console.error("Error fetching default time series data:",i),i}}transformListViewForSlider(t,r){return Array.isArray(t)?t.map((n,a)=>{const i={id:`${r}-${a+1}`,runs:n.count||0,responseTime:n.avgResponseTime?n.avgResponseTime<1e3?`${Math.round(n.avgResponseTime)}ms`:`${(n.avgResponseTime/1e3).toFixed(2)}s`:"0ms",successRate:n.successRate?`${Math.round(n.successRate)}%`:void 0,tokens:n.totalTokens||n.tokens||0,icon:n.icon||n.tool_icon||void 0,aiModel:"gpt-4o"};switch(r){case"agentRuns":return{...i,name:n.agentName||`Agent ${a+1}`,type:"Agent",aiModel:this.extractAIModel(n)||"gpt-4o"};case"toolRuns":return{...i,name:n.toolName||n.tool_name||`Tool ${a+1}`,type:n.type||n.toolType||n.tool_type||"Code Tool",toolType:n.toolType||n.tool_type,aiModel:this.extractAIModel(n)||"gpt-4o"};case"modelRuns":return{...i,name:n.modelName||`Model ${a+1}`,modelName:n.modelName,provider:n.provider,type:n.provider||"Model",aiModel:n.modelName||n.model||"gpt-4o"};default:return{...i,name:`Item ${a+1}`,type:"Unknown",aiModel:"gpt-4o"}}}):(console.warn("Invalid listView data for slider:",t),[])}extractAIModel(t){if(t.modelName)return t.modelName;if(t.model)return t.model;if(t.llmModel)return t.llmModel;if(t.aiModel)return t.aiModel;const r=["gpt-4o","gpt-4o-mini","claude-3-5-haiku"];return r[Math.floor(Math.random()*r.length)]}static getDateRange(t=7){const r=new Date,n=new Date;return n.setDate(r.getDate()-t),{fromTimestamp:n.toISOString(),toTimestamp:r.toISOString()}}static getTimeDimension(t,r){const n=new Date(t),a=new Date(r),i=new Date(n.getFullYear(),n.getMonth(),n.getDate()),o=new Date(a.getFullYear(),a.getMonth(),a.getDate()),s=o.getTime()-i.getTime(),l=s/(1e3*60*60*24),u=i.toISOString().split("T")[0],c=o.toISOString().split("T")[0],f=u===c,d=new Date(n.getFullYear(),n.getMonth(),n.getDate()),h=f&&Math.abs(n.getTime()-d.getTime())<1e3,m=Math.abs(a.getTime()-n.getTime()),y=m<60*1e3;return console.log("🕐 TimeDimension calculation:",{fromTimestamp:t,toTimestamp:r,fromDateStr:u,toDateStr:c,diffInMs:s,diffInDays:l,isSameCalendarDay:f,isTodayPattern:h,timeDiffInMs:m,isVeryClose:y,fromStartOfDay:d.toISOString(),recommended:f||h||y||l<=1?"hour":l<=31?"day":l<=90?"week":"month"}),f||h||y||l<=1?"hour":"day"}getAvailableMetrics(){return{"usage-analytics":["sessions","messages","users","tokens"],runs:["agent-runs","model-runs","tool-runs"]}}}const Nb=({config:e,className:t,isLoading:r,context:n})=>{const{type:a,chart:i,table:o,layout:s="vertical"}=e,[l,u]=T.useState({isOpen:!1,date:"",metricType:"agentRuns",data:[],totalRuns:0}),c=(y,v)=>{console.log("Chart data point clicked in ViewRenderer:",{chartData:y,date:v,context:n});const x=n==null?void 0:n.metricType;if(!x||!["agentRuns","toolRuns","modelRuns"].includes(x)){console.log("Slider not applicable for metric type:",x);return}const w=y.listView||[];console.log("ListView data for clicked date:",w);const A=new Ht({baseUrl:"",projectId:"",environment:""}).transformListViewForSlider(w,x),g=y[x]||y.count||0;console.log("Opening slider with data:",{date:v,metricType:x,sliderData:A,totalRuns:g}),u({isOpen:!0,date:v,metricType:x,data:A,totalRuns:g})},f=()=>{u(y=>({...y,isOpen:!1}))},d=()=>i?(console.log("ViewRenderer - Chart config:",i),console.log("ViewRenderer - Chart data:",i.data),console.log("ViewRenderer - Context:",n),p.jsx("div",{className:"flex-1",children:p.jsx(Ab,{config:i,isLoading:r,onDataPointClick:c})})):null,h=()=>o?(n==null?void 0:n.metricType)==="agentRuns"?p.jsx("div",{className:"flex-1 min-h-[380px]",children:p.jsx(_b,{data:o.data})}):(n==null?void 0:n.metricType)==="toolRuns"?p.jsx("div",{className:"flex-1 min-h-[380px]",children:p.jsx(Eb,{data:o.data})}):(n==null?void 0:n.metricType)==="modelRuns"?p.jsx("div",{className:"flex-1 min-h-[380px]",children:p.jsx(Cb,{data:o.data})}):p.jsx("div",{className:"flex-1 min-h-[380px]",children:p.jsx(Pb,{config:o})}):null,m=()=>{switch(a){case"chart":return d();case"table":return h();case"mixed":return p.jsxs("div",{className:se("flex gap-6",s==="horizontal"?"flex-row":"flex-col"),children:[d(),h()]});default:return p.jsxs("div",{className:"p-4 text-center text-gray-500",children:["Unsupported view type: ",a]})}};return p.jsxs(p.Fragment,{children:[p.jsx("div",{className:se("w-full",t),children:m()}),p.jsx($b,{isOpen:l.isOpen,onClose:f,date:l.date,metricType:l.metricType,data:l.data,totalRuns:l.totalRuns})]})},Ms=({options:e,value:t,placeholder:r="Select an option",onChange:n,className:a,disabled:i=!1})=>{const[o,s]=T.useState(!1),[l,u]=T.useState(t||""),c=T.useRef(null),f=e.find(m=>m.value===l);T.useEffect(()=>{const m=y=>{c.current&&!c.current.contains(y.target)&&s(!1)};return o&&document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m)}},[o]);const d=m=>{i||(u(m),s(!1),n==null||n(m))},h=()=>{i||s(!o)};return p.jsxs("div",{ref:c,className:se("relative",a),children:[p.jsxs("button",{type:"button",className:se("flex h-[40px] text-left w-full items-center rounded-lg border border-gray-300 bg-white px-[14px] py-[10px] medium shadow-none outline-none focus-visible:border-ring focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:bg-gray-25 transition-colors",a),onClick:h,disabled:i,children:[p.jsxs("div",{className:"flex items-center gap-[8px] w-full",children:[p.jsx("span",{className:"text-xs font-medium text-gray-400 uppercase",children:"ENV"}),p.jsx("span",{className:se("truncate w-full",!f&&"text-gray-700 font-medium text-sm"),children:f?f.label:r})]}),p.jsx(cr,{className:se("h-[16px] w-[16px] text-gray-400 transition-transform duration-200",o&&"rotate-180")})]}),o&&!i&&p.jsx("div",{className:"absolute p-[4px] w-full top-full left-0 z-50 mt-1 bg-popover max-h-[300px] overflow-y-auto text-popover-foreground overflow-x-hidden overflow-y-auto rounded-md border shadow-md",children:e.map(m=>{const y=l===m.value;return p.jsxs("div",{role:"option",className:"relative group",children:[p.jsx("button",{className:se("focus:bg-gray-50 rounded-[4px] hover:bg-gray-50 focus:text-accent-foreground relative flex w-full cursor-pointer select-none items-center px-[14px] py-[10px] text-sm text-left outline-none transition-colors",m.disabled?"opacity-50 cursor-not-allowed text-gray-400":y?"bg-blue-50 text-blue-900 font-medium":"text-gray-900 hover:bg-gray-50"),onClick:()=>!m.disabled&&d(m.value),disabled:m.disabled,children:p.jsx("span",{className:"block whitespace-nowrap w-full",children:m.label})}),m.label.length>25&&p.jsx("div",{className:"absolute left-full top-0 ml-2 z-[60] opacity-0 group-hover:opacity-100 transition-opacity duration-200 pointer-events-none",children:p.jsxs("div",{className:"bg-gray-900 text-white text-xs rounded-md px-3 py-2 whitespace-nowrap shadow-lg",children:[m.label,p.jsx("div",{className:"absolute left-0 top-1/2 transform -translate-x-full -translate-y-1/2 w-0 h-0 border-t-4 border-b-4 border-r-4 border-transparent border-r-gray-900"})]})})]},m.value)})})]})},Db=({options:e,value:t,defaultValue:r,placeholder:n="Select...",multiSelect:a=!1,searchable:i=!1,onChange:o,className:s,maxItems:l=100,maxLabelLength:u=30})=>{const[c,f]=T.useState(!1),[d,h]=T.useState(""),[m,y]=T.useState(()=>{const N=t||r;return a?Array.isArray(N)?N:N?[N]:[]:N?[Array.isArray(N)?N[0]:N]:[]}),v=T.useRef(null);T.useEffect(()=>{const N=j=>{v.current&&!v.current.contains(j.target)&&f(!1)};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[]);const x=(N,j=u)=>N.length<=j?N:N.substring(0,j)+"...",w=i?e.filter(N=>N.label.toLowerCase().includes(d.toLowerCase())):e,b=w.slice(0,l),A=w.length>l,g=N=>{let j;if(a){if(N==="all"){S();return}if(m.includes(N))j=m.filter(k=>k!==N),j=j.filter(k=>k!=="all");else{j=m.filter(D=>D!=="all"),j=[...j,N];const k=w.filter(D=>D.value!=="all").map(D=>D.value),_=j.filter(D=>D!=="all");_.length===k.length&&(j=["all",..._])}}else j=[N],f(!1);y(j);const $=a?j:j[0]||"";o==null||o($)},O=()=>{if(!a)return{checked:!1,indeterminate:!1};const N=w.filter($=>$.value!=="all").map($=>$.value),j=m.filter($=>$!=="all"&&N.includes($));return m.includes("all")&&j.length===0?{checked:!1,indeterminate:!1}:j.length===0?{checked:!1,indeterminate:!1}:j.length===N.length?{checked:!0,indeterminate:!1}:{checked:!1,indeterminate:!0}},S=()=>{if(!a)return;const N=O(),j=w.filter($=>$.value!=="all").map($=>$.value);if(N.checked)y(["all"]),o==null||o(["all"]);else{const $=["all",...j];y($),o==null||o($)}},P=()=>{y(["all"]),o==null||o(a?["all"]:"all")},E=()=>{if(!a){if(m.length===0)return n;const k=e.find(_=>_.value===m[0]);return(k==null?void 0:k.label)||n}const N=m.filter(k=>k!=="all"),j=m.includes("all");if(N.length===0)return n;if(N.length===1){const k=e.find(_=>_.value===N[0]);return(k==null?void 0:k.label)||n}const $=e.filter(k=>k.value!=="all").length;return N.length===$?"All selected":`${N.length} selected`};return p.jsxs("div",{className:se("relative",s),ref:v,children:[p.jsxs("button",{type:"button",onClick:()=>f(!c),className:se("w-full flex items-center justify-between px-[12px] py-[8px] text-left text-xs","border border-gray-300 rounded-md bg-white hover:bg-gray-50","focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500","transition-colors duration-150"),children:[p.jsx("span",{className:se("truncate",m.length===0&&"text-gray-500"),children:E()}),p.jsx(cr,{className:se("w-[16px] h-[16px] text-gray-400 transition-transform duration-150",c&&"transform rotate-180")})]}),c&&p.jsxs("div",{className:"absolute z-50 min-w-[300px] w-max max-w-lg mt-[4px] bg-white border border-gray-200 rounded-md shadow-lg max-h-80 overflow-hidden",children:[i&&p.jsx("div",{className:"p-[12px] border-b border-gray-100",children:p.jsxs("div",{className:"relative",children:[p.jsx(_f,{className:"absolute left-[12px] top-1/2 transform -translate-y-1/2 w-[16px] h-[16px] text-gray-400"}),p.jsx("input",{type:"text",placeholder:`Search ${n.toLowerCase()}...`,value:d,onChange:N=>h(N.target.value),className:"w-full pl-[36px] pr-[12px] py-[8px] text-xs border border-gray-200 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})]})}),a&&p.jsxs("div",{className:"flex items-center justify-between px-[12px] py-[8px] border-b border-gray-100 bg-gray-50",children:[p.jsxs("button",{type:"button",onClick:S,className:"flex items-center text-xs font-medium text-gray-700 hover:text-gray-900",children:[p.jsx("div",{className:se("flex items-center justify-center w-[16px] h-[16px] mr-[8px] border transition-colors duration-150",(()=>{const N=O();return N.indeterminate||N.checked?"bg-blue-600 border-blue-600 text-white":"border-gray-300 bg-white"})()),children:(()=>{const N=O();return N.indeterminate?p.jsx("div",{className:"w-[8px] h-[4px] bg-white rounded"}):N.checked?p.jsx("svg",{className:"w-[12px] h-[12px]",fill:"currentColor",viewBox:"0 0 20 20",children:p.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})}):null})()}),"Select all"]}),p.jsx("button",{type:"button",onClick:P,className:"text-sm font-medium text-blue-600 hover:text-blue-800",children:"Clear"})]}),p.jsxs("div",{className:"max-h-60 overflow-y-auto",children:[b.length===0?p.jsx("div",{className:"px-[12px] py-[16px] text-sm text-gray-500 text-center",children:"No options found"}):b.map(N=>{let j;return N.value==="all"?null:(j=m.includes(N.value),p.jsxs("div",{className:"relative group",children:[p.jsxs("div",{onClick:()=>g(N.value),className:se("flex items-center px-[12px] py-[8px] cursor-pointer hover:bg-gray-50","transition-colors duration-150",j&&"bg-gray-50"),children:[a?p.jsx("div",{className:se("flex items-center justify-center w-[16px] h-[16px] mr-[12px] border","transition-colors duration-150",j?"bg-blue-600 border-blue-600 text-white":"border-gray-300 bg-white"),children:j&&p.jsx("svg",{className:"w-[12px] h-[12px]",fill:"currentColor",viewBox:"0 0 20 20",children:p.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})})}):p.jsx("div",{className:se("w-[16px] h-[16px] mr-[12px] rounded-full border-2 transition-colors duration-150",j?"border-blue-600 bg-blue-600":"border-gray-300"),children:j&&p.jsx("div",{className:"w-full h-full rounded-full bg-white scale-50"})}),p.jsx("span",{className:se("flex-1 text-xs whitespace-nowrap truncate",j?"font-medium text-gray-700":"text-gray-500"),children:x(N.label)})]}),N.label.length>u&&p.jsx("div",{className:"absolute left-full top-1/2 transform -translate-y-1/2 ml-2 z-[80] opacity-0 group-hover:opacity-100 transition-opacity duration-200 pointer-events-none",children:p.jsxs("div",{className:"bg-gray-900 text-white text-xs rounded-md px-[12px] py-[8px] shadow-lg max-w-xs break-words whitespace-normal",children:[N.label,p.jsx("div",{className:"absolute left-0 top-1/2 transform -translate-x-full -translate-y-1/2 w-0 h-0 border-t-4 border-b-4 border-r-4 border-transparent border-r-gray-900"})]})})]},N.value))}),A&&p.jsxs("div",{className:"px-[12px] py-[8px] text-xs text-gray-500 bg-gray-50 border-t border-gray-100",children:[p.jsxs("div",{className:"text-center font-medium",children:["+",w.length-l," more items"]}),i&&p.jsx("div",{className:"text-center mt-1 text-gray-400",children:"Use search above to find specific items"})]})]})]})]})},Ib=({config:e,className:t})=>{var s;const{dropdown:r,buttons:n,toggle:a}=e,i=l=>{const u=l.toLowerCase();return u.includes("agent")?"agent":u.includes("tool")?"workflowtool":"app"},o=l=>{const u=l.toLowerCase();return u.includes("agent")?{maxItems:50,maxLabelLength:25}:u.includes("tool")?{maxItems:30,maxLabelLength:20}:{maxItems:40,maxLabelLength:25}};return p.jsxs("div",{className:se("flex items-center gap-3",t),children:[r&&p.jsx(p.Fragment,{children:r.multiSelect?p.jsx(Db,{options:r.options,value:r.defaultValue,placeholder:r.label,multiSelect:r.multiSelect,searchable:r.searchable,onChange:r.onChange,className:"w-48",iconSource:i(r.label),maxItems:o(r.label).maxItems,maxLabelLength:o(r.label).maxLabelLength}):p.jsx(Ms,{options:r.options,value:Array.isArray(r.defaultValue)?r.defaultValue[0]:r.defaultValue||((s=r.options[0])==null?void 0:s.value),placeholder:r.label,onChange:l=>{var u;return(u=r.onChange)==null?void 0:u.call(r,l)},className:"w-48"})}),n&&n.length>0&&p.jsx("div",{className:"flex items-center border border-gray-200 rounded-lg overflow-hidden",children:n.map((l,u)=>p.jsx("button",{onClick:()=>{var c;return(c=l.onClick)==null?void 0:c.call(l,l.value)},className:se("px-[12px] py-[8px] text-xs font-medium transition-colors","hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-inset",l.active?"bg-white text-gray-900 shadow-[0 1px 3px 0 rgba(16, 24, 40, 0.08), 0 1px 2px 0 rgba(16, 24, 40, 0.08)]":"text-gray-500 bg-white",u>0&&"border-l border-gray-200"),children:l.icon&&p.jsx("span",{className:"mr-[8px]",children:l.icon})},l.value))}),a&&p.jsxs("div",{className:"flex items-center gap-[4px] border border-gray-200 bg-gray-50 overflow-hidden p-[2px] rounded-[6px]",children:[p.jsx("button",{onClick:()=>{var l;return(l=a.onToggle)==null?void 0:l.call(a,"chart")},className:se("px-[12px] py-[8px] rounded-[4px] text-xs font-medium transition-colors flex items-center gap-2","hover:bg-white ",a.chartView?"bg-white text-gray-900 shadow-md":"text-gray-500 bg-white"),children:p.jsx(g0,{className:"w-[16px] h-[16px]"})}),p.jsx("button",{onClick:()=>{var l;return(l=a.onToggle)==null?void 0:l.call(a,"table")},className:se("px-[12px] rounded-[4px] py-[8px] text-xs font-medium transition-colors flex items-center gap-2","hover:bg-white ",a.tableView?"bg-white text-gray-900 shadow-md":"text-gray-500 bg-white"),children:p.jsx(P0,{className:"w-[16px] h-[16px]"})})]})]})},Lb=({section:e,className:t,isLoading:r,isChartLoading:n,onMetricClick:a})=>{var V;const{id:i,title:o,description:s,metrics:l,view:u,controls:c,layout:f}=e,[d,h]=T.useState(u.type),[m,y]=T.useState("chart"),v=()=>i==="usage-analytics"?"users":i==="runs"?"agentRuns":"users",[x,w]=T.useState(v()),[b,A]=T.useState("all"),g=C=>{var F,W,G,X,Q;const R=P();(F=R==null?void 0:R.controls)!=null&&F.toggle?(y(C),(G=(W=R.controls.toggle).onToggle)==null||G.call(W,C)):(h(C),(Q=(X=c==null?void 0:c.toggle)==null?void 0:X.onToggle)==null||Q.call(X,C))},O=C=>{var W,G;const R=C.metricType||C.title.toLowerCase();w(R);const F=l.find(X=>(X.metricType||X.title.toLowerCase())===R);(G=(W=F==null?void 0:F.controls)==null?void 0:W.dropdown)!=null&&G.multiSelect?A(["all"]):A("all"),a==null||a(C)},S=C=>{var F,W,G;A(C);const R=l.find(X=>(X.metricType||X.title.toLowerCase())===x);(G=(W=(F=R==null?void 0:R.controls)==null?void 0:F.dropdown)==null?void 0:W.onChange)==null||G.call(W,C)},P=()=>l.find(C=>(C.metricType||C.title.toLowerCase())===x)||null,E=C=>Array.isArray(C)?C.filter(F=>F!=="all").length>0:C!=="all",N=C=>Array.isArray(C)?C.filter(R=>R!=="all"):C!=="all"?[C]:[],j=C=>{var G,X,Q,ae,te,q,Y,Z,L;const R=((X=(G=C.view)==null?void 0:G.chart)==null?void 0:X.data)||((Q=u.chart)==null?void 0:Q.data)||[];if(!E(b))return R;const F=C.metricType,W=N(b);if(W.length===1){const oe=W[0],K=P(),ue=(q=(te=(ae=K==null?void 0:K.controls)==null?void 0:ae.dropdown)==null?void 0:te.options)==null?void 0:q.find(me=>me.value===oe),ee=ue==null?void 0:ue.label;return console.log("🔍 Filtering chart data:",{metricType:F,singleFilter:oe,selectedLabel:ee,baseDataSample:R[0]}),R.map(me=>{let Ue=0;return me.listView&&Array.isArray(me.listView)&&(Ue=me.listView.filter(Ge=>F==="agentRuns"&&Ge.agentName?Ge.agentName===ee||Ge.agentName.toLowerCase()===(ee==null?void 0:ee.toLowerCase()):F==="toolRuns"&&Ge.toolName?Ge.toolName===ee||Ge.toolName.toLowerCase()===(ee==null?void 0:ee.toLowerCase()):F==="modelRuns"&&Ge.modelName?Ge.modelName===ee||Ge.modelName.toLowerCase()===(ee==null?void 0:ee.toLowerCase()):!1).reduce((Ge,ut)=>Ge+(ut.count||0),0)),console.log("📊 Filtered value for",ee,":",Ue),{...me,[F]:Ue}})}if(W.length>1){const oe=P(),ue=(((L=(Z=(Y=oe==null?void 0:oe.controls)==null?void 0:Y.dropdown)==null?void 0:Z.options)==null?void 0:L.filter(ee=>W.includes(ee.value)))||[]).map(ee=>ee.label);return R.map(ee=>{let me=0;return ee.listView&&Array.isArray(ee.listView)&&(me=ee.listView.filter(Be=>F==="agentRuns"&&Be.agentName?ue.some(Fe=>Be.agentName===Fe||Be.agentName.toLowerCase()===(Fe==null?void 0:Fe.toLowerCase())):F==="toolRuns"&&Be.toolName?ue.some(Fe=>Be.toolName===Fe||Be.toolName.toLowerCase()===(Fe==null?void 0:Fe.toLowerCase())):F==="modelRuns"&&Be.modelName?ue.some(Fe=>Be.modelName===Fe||Be.modelName.toLowerCase()===(Fe==null?void 0:Fe.toLowerCase())):!1).reduce((Be,Fe)=>Be+(Fe.count||0),0)),{...ee,[F]:me}})}return R},$=C=>{var G;if(!((G=C.view)!=null&&G.chart))return null;const R=j(C),F=()=>{var Q,ae,te,q,Y,Z;if(!E(b)||!((Q=C.controls)!=null&&Q.dropdown))return((te=(ae=C.view)==null?void 0:ae.chart)==null?void 0:te.title)||C.title;const X=N(b);if(X.length===1){const L=(q=C.controls.dropdown.options)==null?void 0:q.find(oe=>oe.value===X[0]);return L?`${L.label}`:((Z=(Y=C.view)==null?void 0:Y.chart)==null?void 0:Z.title)||C.title}return`${X.length} selected`},W=N(b);return C.metricType==="toolRuns"&&W.length===1?{...C.view.chart,data:R,title:F(),lines:void 0,dataKey:"toolRuns",color:"#f97316",showLegend:!1}:C.metricType==="modelRuns"&&W.length===1?{...C.view.chart,data:R,title:F(),dataKey:"modelRuns",color:"#10b981",showLegend:!1}:{...C.view.chart,data:R,title:F()}},k=(C,R)=>{if(!E(b))return C;const F=N(b);if(F.length===1){const W=F[0];if(i==="runs"&&R==="agentRuns")return C.map(G=>({...G,agentRuns:G[W]||0}));if(i==="runs"&&R==="toolRuns")return C.map(G=>({...G,toolRuns:G[W.replace(/[-]/g,"")]||0}));if(i==="runs"&&R==="modelRuns")return C.map(G=>({...G,modelRuns:G[W.replace(/[-\.]/g,"")]||0}))}return C},_=C=>{var G;const R=((G=u.chart)==null?void 0:G.data)||[],F=k(R,C),W=X=>{var ae,te;if(!E(b))return X;const Q=N(b);if(Q.length===1){const q=(te=(ae=c==null?void 0:c.dropdown)==null?void 0:ae.options)==null?void 0:te.find(Y=>Y.value===Q[0]);return q?`${q.label}`:X}return`${Q.length} selected`};switch(C){case"users":return{type:"line",title:"Total Users",data:R,dataKey:"users",color:"#8b5cf6",yAxisLabel:"Number of Users",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}};case"sessions":return{type:"line",title:"Total Sessions",data:R,dataKey:"sessions",color:"#06b6d4",yAxisLabel:"Number of Sessions",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}};case"messages":return{type:"line",title:"Total Messages",data:R,dataKey:"messages",color:"#ec4899",yAxisLabel:"Number of Messages",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}};case"tokens":return{type:"line",title:"Token Usage Breakdown",data:R,yAxisLabel:"Number of Tokens",lines:[{dataKey:"totalTokens",color:"#f59e0b",label:"Total Tokens"},{dataKey:"inputTokens",color:"#3b82f6",label:"Input Tokens"},{dataKey:"outputTokens",color:"#ec4899",label:"Output Tokens"}],height:300,showGrid:!0,showLegend:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}};case"agentRuns":return{type:"line",title:W("Agent Runs"),data:F,dataKey:"agentRuns",color:"#06b6d4",yAxisLabel:"Number of Agent Runs",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}};case"toolRuns":return N(b).length===1?{type:"line",title:W("Tool Runs"),data:k(R,"toolRuns"),dataKey:"toolRuns",color:"#f97316",yAxisLabel:"Number of Tool Runs",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}}:{type:"line",title:"Tool Runs",data:F,yAxisLabel:"Number of Tool Runs",lines:[{dataKey:"toolRuns",color:"#06b6d4",label:"Tool Runs"},{dataKey:"codeTools",color:"#f97316",label:"Code Tools"},{dataKey:"workflowTools",color:"#10b981",label:"Workflow Tools"},{dataKey:"knowledgeTools",color:"#8b5cf6",label:"Knowledge"},{dataKey:"mcpTools",color:"#ef4444",label:"MCP Tools"}],height:300,showGrid:!0,showLegend:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}};case"modelRuns":return N(b).length===1?{type:"line",title:W("Model Runs"),data:k(R,"modelRuns"),dataKey:"modelRuns",color:"#10b981",yAxisLabel:"Number of Model Runs",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}}:{type:"line",title:W("Model Runs"),data:F,dataKey:"modelRuns",color:"#10b981",yAxisLabel:"Number of Model Runs",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}};default:return null}},D=(()=>{const C=P();return C!=null&&C.controls?{...C.controls,dropdown:C.controls.dropdown?{...C.controls.dropdown,onChange:S}:void 0,toggle:C.controls.toggle?{...C.controls.toggle,chartView:m==="chart",tableView:m==="table",onToggle:g}:void 0}:c?{...c,dropdown:c.dropdown?{...c.dropdown,onChange:S}:void 0,toggle:c.toggle?{...c.toggle,chartView:d==="chart",tableView:d==="table",onToggle:g}:void 0}:void 0})(),B=(()=>{var F,W,G,X,Q,ae,te,q,Y,Z;const C=P();if(C!=null&&C.view){if((F=C.controls)!=null&&F.toggle){if(m==="table"&&C.view.table){let oe=C.view.table.data;if(C.metricType==="agentRuns"&&E(b)){const K=N(b);if(K.length>0){const ue=((X=(G=(W=C.controls)==null?void 0:W.dropdown)==null?void 0:G.options)==null?void 0:X.filter(ee=>K.includes(ee.value)))||[];ue.length>0&&(oe=oe.filter(ee=>ue.some(me=>ee.name===me.label||ee.name&&ee.name.toLowerCase().includes(me.label.toLowerCase()))))}}if(C.metricType==="toolRuns"&&E(b)){const K=N(b);if(K.length>0){const ue=((te=(ae=(Q=C.controls)==null?void 0:Q.dropdown)==null?void 0:ae.options)==null?void 0:te.filter(ee=>K.includes(ee.value)))||[];ue.length>0&&(oe=oe.filter(ee=>ue.some(me=>ee.name===me.label||ee.name&&ee.name.toLowerCase().includes(me.label.toLowerCase()))))}}if(C.metricType==="modelRuns"&&E(b)){const K=N(b);if(K.length>0){const ue=((Z=(Y=(q=C.controls)==null?void 0:q.dropdown)==null?void 0:Y.options)==null?void 0:Z.filter(ee=>K.includes(ee.value)))||[];ue.length>0&&(oe=oe.filter(ee=>ue.some(me=>ee.name===me.label||ee.name&&ee.name.toLowerCase().includes(me.label.toLowerCase()))))}}return{type:"table",table:{...C.view.table,data:oe}}}else if(m==="chart"&&C.view.chart)return{type:"chart",chart:$(C)||C.view.chart}}const L=$(C);return L?{...C.view,chart:L}:C.view}const R=_(x);return R?{type:"chart",chart:R}:{...u,type:d}})(),U=()=>l.map(C=>{const R=C.metricType||C.title.toLowerCase();return{...C,highlighted:C.highlighted||R===x}});return p.jsxs("div",{className:se("bg-white flex flex-col gap-[16px] rounded-lg border border-gray-200 py-[16px] px-[24px]",t),style:{gridColumn:f!=null&&f.span?`span ${f.span}`:void 0,order:f==null?void 0:f.order},children:[o&&p.jsxs("div",{className:"w-full",children:[p.jsx("h1",{className:"text-md font-medium text-gray-700",children:o}),s&&p.jsx("p",{className:"text-xs text-gray-500",children:s})]}),p.jsx("div",{className:"flex flex-col sm:flex-row gap-[16px]",children:r?p.jsxs(p.Fragment,{children:[p.jsx("div",{className:"flex-1",children:p.jsx(xi,{})}),p.jsx("div",{className:"flex-1",children:p.jsx(xi,{})}),p.jsx("div",{className:"flex-1",children:p.jsx(xi,{})}),p.jsx("div",{className:"flex-1",children:p.jsx(xi,{})})]}):U().map((C,R)=>p.jsx("div",{className:"flex-1",children:p.jsx(Rf,{data:C,onClick:O,isFirst:R===0})},`${i}-metric-${R}`))}),p.jsxs("div",{className:"flex items-center justify-between",children:[p.jsx("div",{children:P()&&p.jsx("h3",{className:"text-md font-medium text-gray-700",children:(V=P())==null?void 0:V.title})}),D&&p.jsx(Ib,{config:D})]}),p.jsx(Nb,{config:B,isLoading:r||n,context:{sectionId:i,metricType:x}})]})},ff=T.forwardRef(({className:e,variant:t="default",size:r="md",children:n,...a},i)=>{const o="inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",s={default:"bg-blue-600 hover:bg-blue-700 focus:bg-blue-700 focus:shadow-sm text-white py-2 px-3",outline:"border-gray-300 border bg-white text-gray-700 hover:text-gray-800 hover:bg-gray-50 focus:bg-gray-50 focus:shadow-sm",ghost:"border border-error-600 bg-error-500 text-white hover:border-error-600 hover:bg-error-600"},l={sm:"h-[32px] rounded-md gap-1.5 px-[14px] py-[10px]",md:"h-[40px] rounded-md px-[14px] py-[10px]",lg:"h-[48px] rounded-md px-[16px] py-[12px]"};return p.jsx("button",{className:se(o,s[t],l[r],e),ref:i,...a,children:n})});ff.displayName="Button";function Ns(e){"@babel/helpers - typeof";return Ns=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Ns(e)}function Et(e){if(e===null||e===!0||e===!1)return NaN;var t=Number(e);return isNaN(t)?t:t<0?Math.ceil(t):Math.floor(t)}function Me(e,t){if(t.length<e)throw new TypeError(e+" argument"+(e>1?"s":"")+" required, but only "+t.length+" present")}function Ve(e){Me(1,arguments);var t=Object.prototype.toString.call(e);return e instanceof Date||Ns(e)==="object"&&t==="[object Date]"?new Date(e.getTime()):typeof e=="number"||t==="[object Number]"?new Date(e):((typeof e=="string"||t==="[object String]")&&typeof console<"u"&&(console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments"),console.warn(new Error().stack)),new Date(NaN))}function WB(e,t){Me(2,arguments);var r=Ve(e),n=Et(t);return isNaN(n)?new Date(NaN):(n&&r.setDate(r.getDate()+n),r)}function df(e,t){Me(2,arguments);var r=Ve(e),n=Et(t);if(isNaN(n))return new Date(NaN);if(!n)return r;var a=r.getDate(),i=new Date(r.getTime());i.setMonth(r.getMonth()+n+1,0);var o=i.getDate();return a>=o?i:(r.setFullYear(i.getFullYear(),i.getMonth(),a),r)}function UB(e,t){Me(2,arguments);var r=Ve(e).getTime(),n=Et(t);return new Date(r+n)}var zB={};function Oi(){return zB}function VB(e,t){var r,n,a,i,o,s;Me(1,arguments);var l=Oi(),u=Et((r=(n=(a=(i=void 0)!==null&&i!==void 0?i:void 0)!==null&&a!==void 0?a:l.weekStartsOn)!==null&&n!==void 0?n:(o=l.locale)===null||o===void 0||(s=o.options)===null||s===void 0?void 0:s.weekStartsOn)!==null&&r!==void 0?r:0);if(!(u>=0&&u<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");var c=Ve(e),f=c.getDay(),d=(f<u?7:0)+f-u;return c.setDate(c.getDate()-d),c.setHours(0,0,0,0),c}function GB(e){var t=new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()));return t.setUTCFullYear(e.getFullYear()),e.getTime()-t.getTime()}function aa(e){Me(1,arguments);var t=Ve(e);return t.setHours(0,0,0,0),t}function Si(e,t){Me(2,arguments);var r=aa(e),n=aa(t);return r.getTime()===n.getTime()}function qB(e){return Me(1,arguments),e instanceof Date||Ns(e)==="object"&&Object.prototype.toString.call(e)==="[object Date]"}function KB(e){if(Me(1,arguments),!qB(e)&&typeof e!="number")return!1;var t=Ve(e);return!isNaN(Number(t))}function HB(e){Me(1,arguments);var t=Ve(e);return t.setHours(23,59,59,999),t}function YB(e){Me(1,arguments);var t=Ve(e);return t.setDate(1),t.setHours(0,0,0,0),t}function XB(e,t){Me(2,arguments);var r=Et(t);return UB(e,-r)}var JB=864e5;function ZB(e){Me(1,arguments);var t=Ve(e),r=t.getTime();t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0);var n=t.getTime(),a=r-n;return Math.floor(a/JB)+1}function Ds(e){Me(1,arguments);var t=1,r=Ve(e),n=r.getUTCDay(),a=(n<t?7:0)+n-t;return r.setUTCDate(r.getUTCDate()-a),r.setUTCHours(0,0,0,0),r}function Rb(e){Me(1,arguments);var t=Ve(e),r=t.getUTCFullYear(),n=new Date(0);n.setUTCFullYear(r+1,0,4),n.setUTCHours(0,0,0,0);var a=Ds(n),i=new Date(0);i.setUTCFullYear(r,0,4),i.setUTCHours(0,0,0,0);var o=Ds(i);return t.getTime()>=a.getTime()?r+1:t.getTime()>=o.getTime()?r:r-1}function QB(e){Me(1,arguments);var t=Rb(e),r=new Date(0);r.setUTCFullYear(t,0,4),r.setUTCHours(0,0,0,0);var n=Ds(r);return n}var eF=6048e5;function tF(e){Me(1,arguments);var t=Ve(e),r=Ds(t).getTime()-QB(t).getTime();return Math.round(r/eF)+1}function Is(e,t){var r,n,a,i,o,s,l,u;Me(1,arguments);var c=Oi(),f=Et((r=(n=(a=(i=t==null?void 0:t.weekStartsOn)!==null&&i!==void 0?i:t==null||(o=t.locale)===null||o===void 0||(s=o.options)===null||s===void 0?void 0:s.weekStartsOn)!==null&&a!==void 0?a:c.weekStartsOn)!==null&&n!==void 0?n:(l=c.locale)===null||l===void 0||(u=l.options)===null||u===void 0?void 0:u.weekStartsOn)!==null&&r!==void 0?r:0);if(!(f>=0&&f<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");var d=Ve(e),h=d.getUTCDay(),m=(h<f?7:0)+h-f;return d.setUTCDate(d.getUTCDate()-m),d.setUTCHours(0,0,0,0),d}function Bb(e,t){var r,n,a,i,o,s,l,u;Me(1,arguments);var c=Ve(e),f=c.getUTCFullYear(),d=Oi(),h=Et((r=(n=(a=(i=t==null?void 0:t.firstWeekContainsDate)!==null&&i!==void 0?i:t==null||(o=t.locale)===null||o===void 0||(s=o.options)===null||s===void 0?void 0:s.firstWeekContainsDate)!==null&&a!==void 0?a:d.firstWeekContainsDate)!==null&&n!==void 0?n:(l=d.locale)===null||l===void 0||(u=l.options)===null||u===void 0?void 0:u.firstWeekContainsDate)!==null&&r!==void 0?r:1);if(!(h>=1&&h<=7))throw new RangeError("firstWeekContainsDate must be between 1 and 7 inclusively");var m=new Date(0);m.setUTCFullYear(f+1,0,h),m.setUTCHours(0,0,0,0);var y=Is(m,t),v=new Date(0);v.setUTCFullYear(f,0,h),v.setUTCHours(0,0,0,0);var x=Is(v,t);return c.getTime()>=y.getTime()?f+1:c.getTime()>=x.getTime()?f:f-1}function rF(e,t){var r,n,a,i,o,s,l,u;Me(1,arguments);var c=Oi(),f=Et((r=(n=(a=(i=t==null?void 0:t.firstWeekContainsDate)!==null&&i!==void 0?i:t==null||(o=t.locale)===null||o===void 0||(s=o.options)===null||s===void 0?void 0:s.firstWeekContainsDate)!==null&&a!==void 0?a:c.firstWeekContainsDate)!==null&&n!==void 0?n:(l=c.locale)===null||l===void 0||(u=l.options)===null||u===void 0?void 0:u.firstWeekContainsDate)!==null&&r!==void 0?r:1),d=Bb(e,t),h=new Date(0);h.setUTCFullYear(d,0,f),h.setUTCHours(0,0,0,0);var m=Is(h,t);return m}var nF=6048e5;function aF(e,t){Me(1,arguments);var r=Ve(e),n=Is(r,t).getTime()-rF(r,t).getTime();return Math.round(n/nF)+1}function je(e,t){for(var r=e<0?"-":"",n=Math.abs(e).toString();n.length<t;)n="0"+n;return r+n}var jr={y:function(t,r){var n=t.getUTCFullYear(),a=n>0?n:1-n;return je(r==="yy"?a%100:a,r.length)},M:function(t,r){var n=t.getUTCMonth();return r==="M"?String(n+1):je(n+1,2)},d:function(t,r){return je(t.getUTCDate(),r.length)},a:function(t,r){var n=t.getUTCHours()/12>=1?"pm":"am";switch(r){case"a":case"aa":return n.toUpperCase();case"aaa":return n;case"aaaaa":return n[0];case"aaaa":default:return n==="am"?"a.m.":"p.m."}},h:function(t,r){return je(t.getUTCHours()%12||12,r.length)},H:function(t,r){return je(t.getUTCHours(),r.length)},m:function(t,r){return je(t.getUTCMinutes(),r.length)},s:function(t,r){return je(t.getUTCSeconds(),r.length)},S:function(t,r){var n=r.length,a=t.getUTCMilliseconds(),i=Math.floor(a*Math.pow(10,n-3));return je(i,r.length)}},ia={midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},iF={G:function(t,r,n){var a=t.getUTCFullYear()>0?1:0;switch(r){case"G":case"GG":case"GGG":return n.era(a,{width:"abbreviated"});case"GGGGG":return n.era(a,{width:"narrow"});case"GGGG":default:return n.era(a,{width:"wide"})}},y:function(t,r,n){if(r==="yo"){var a=t.getUTCFullYear(),i=a>0?a:1-a;return n.ordinalNumber(i,{unit:"year"})}return jr.y(t,r)},Y:function(t,r,n,a){var i=Bb(t,a),o=i>0?i:1-i;if(r==="YY"){var s=o%100;return je(s,2)}return r==="Yo"?n.ordinalNumber(o,{unit:"year"}):je(o,r.length)},R:function(t,r){var n=Rb(t);return je(n,r.length)},u:function(t,r){var n=t.getUTCFullYear();return je(n,r.length)},Q:function(t,r,n){var a=Math.ceil((t.getUTCMonth()+1)/3);switch(r){case"Q":return String(a);case"QQ":return je(a,2);case"Qo":return n.ordinalNumber(a,{unit:"quarter"});case"QQQ":return n.quarter(a,{width:"abbreviated",context:"formatting"});case"QQQQQ":return n.quarter(a,{width:"narrow",context:"formatting"});case"QQQQ":default:return n.quarter(a,{width:"wide",context:"formatting"})}},q:function(t,r,n){var a=Math.ceil((t.getUTCMonth()+1)/3);switch(r){case"q":return String(a);case"qq":return je(a,2);case"qo":return n.ordinalNumber(a,{unit:"quarter"});case"qqq":return n.quarter(a,{width:"abbreviated",context:"standalone"});case"qqqqq":return n.quarter(a,{width:"narrow",context:"standalone"});case"qqqq":default:return n.quarter(a,{width:"wide",context:"standalone"})}},M:function(t,r,n){var a=t.getUTCMonth();switch(r){case"M":case"MM":return jr.M(t,r);case"Mo":return n.ordinalNumber(a+1,{unit:"month"});case"MMM":return n.month(a,{width:"abbreviated",context:"formatting"});case"MMMMM":return n.month(a,{width:"narrow",context:"formatting"});case"MMMM":default:return n.month(a,{width:"wide",context:"formatting"})}},L:function(t,r,n){var a=t.getUTCMonth();switch(r){case"L":return String(a+1);case"LL":return je(a+1,2);case"Lo":return n.ordinalNumber(a+1,{unit:"month"});case"LLL":return n.month(a,{width:"abbreviated",context:"standalone"});case"LLLLL":return n.month(a,{width:"narrow",context:"standalone"});case"LLLL":default:return n.month(a,{width:"wide",context:"standalone"})}},w:function(t,r,n,a){var i=aF(t,a);return r==="wo"?n.ordinalNumber(i,{unit:"week"}):je(i,r.length)},I:function(t,r,n){var a=tF(t);return r==="Io"?n.ordinalNumber(a,{unit:"week"}):je(a,r.length)},d:function(t,r,n){return r==="do"?n.ordinalNumber(t.getUTCDate(),{unit:"date"}):jr.d(t,r)},D:function(t,r,n){var a=ZB(t);return r==="Do"?n.ordinalNumber(a,{unit:"dayOfYear"}):je(a,r.length)},E:function(t,r,n){var a=t.getUTCDay();switch(r){case"E":case"EE":case"EEE":return n.day(a,{width:"abbreviated",context:"formatting"});case"EEEEE":return n.day(a,{width:"narrow",context:"formatting"});case"EEEEEE":return n.day(a,{width:"short",context:"formatting"});case"EEEE":default:return n.day(a,{width:"wide",context:"formatting"})}},e:function(t,r,n,a){var i=t.getUTCDay(),o=(i-a.weekStartsOn+8)%7||7;switch(r){case"e":return String(o);case"ee":return je(o,2);case"eo":return n.ordinalNumber(o,{unit:"day"});case"eee":return n.day(i,{width:"abbreviated",context:"formatting"});case"eeeee":return n.day(i,{width:"narrow",context:"formatting"});case"eeeeee":return n.day(i,{width:"short",context:"formatting"});case"eeee":default:return n.day(i,{width:"wide",context:"formatting"})}},c:function(t,r,n,a){var i=t.getUTCDay(),o=(i-a.weekStartsOn+8)%7||7;switch(r){case"c":return String(o);case"cc":return je(o,r.length);case"co":return n.ordinalNumber(o,{unit:"day"});case"ccc":return n.day(i,{width:"abbreviated",context:"standalone"});case"ccccc":return n.day(i,{width:"narrow",context:"standalone"});case"cccccc":return n.day(i,{width:"short",context:"standalone"});case"cccc":default:return n.day(i,{width:"wide",context:"standalone"})}},i:function(t,r,n){var a=t.getUTCDay(),i=a===0?7:a;switch(r){case"i":return String(i);case"ii":return je(i,r.length);case"io":return n.ordinalNumber(i,{unit:"day"});case"iii":return n.day(a,{width:"abbreviated",context:"formatting"});case"iiiii":return n.day(a,{width:"narrow",context:"formatting"});case"iiiiii":return n.day(a,{width:"short",context:"formatting"});case"iiii":default:return n.day(a,{width:"wide",context:"formatting"})}},a:function(t,r,n){var a=t.getUTCHours(),i=a/12>=1?"pm":"am";switch(r){case"a":case"aa":return n.dayPeriod(i,{width:"abbreviated",context:"formatting"});case"aaa":return n.dayPeriod(i,{width:"abbreviated",context:"formatting"}).toLowerCase();case"aaaaa":return n.dayPeriod(i,{width:"narrow",context:"formatting"});case"aaaa":default:return n.dayPeriod(i,{width:"wide",context:"formatting"})}},b:function(t,r,n){var a=t.getUTCHours(),i;switch(a===12?i=ia.noon:a===0?i=ia.midnight:i=a/12>=1?"pm":"am",r){case"b":case"bb":return n.dayPeriod(i,{width:"abbreviated",context:"formatting"});case"bbb":return n.dayPeriod(i,{width:"abbreviated",context:"formatting"}).toLowerCase();case"bbbbb":return n.dayPeriod(i,{width:"narrow",context:"formatting"});case"bbbb":default:return n.dayPeriod(i,{width:"wide",context:"formatting"})}},B:function(t,r,n){var a=t.getUTCHours(),i;switch(a>=17?i=ia.evening:a>=12?i=ia.afternoon:a>=4?i=ia.morning:i=ia.night,r){case"B":case"BB":case"BBB":return n.dayPeriod(i,{width:"abbreviated",context:"formatting"});case"BBBBB":return n.dayPeriod(i,{width:"narrow",context:"formatting"});case"BBBB":default:return n.dayPeriod(i,{width:"wide",context:"formatting"})}},h:function(t,r,n){if(r==="ho"){var a=t.getUTCHours()%12;return a===0&&(a=12),n.ordinalNumber(a,{unit:"hour"})}return jr.h(t,r)},H:function(t,r,n){return r==="Ho"?n.ordinalNumber(t.getUTCHours(),{unit:"hour"}):jr.H(t,r)},K:function(t,r,n){var a=t.getUTCHours()%12;return r==="Ko"?n.ordinalNumber(a,{unit:"hour"}):je(a,r.length)},k:function(t,r,n){var a=t.getUTCHours();return a===0&&(a=24),r==="ko"?n.ordinalNumber(a,{unit:"hour"}):je(a,r.length)},m:function(t,r,n){return r==="mo"?n.ordinalNumber(t.getUTCMinutes(),{unit:"minute"}):jr.m(t,r)},s:function(t,r,n){return r==="so"?n.ordinalNumber(t.getUTCSeconds(),{unit:"second"}):jr.s(t,r)},S:function(t,r){return jr.S(t,r)},X:function(t,r,n,a){var i=a._originalDate||t,o=i.getTimezoneOffset();if(o===0)return"Z";switch(r){case"X":return Wb(o);case"XXXX":case"XX":return Xr(o);case"XXXXX":case"XXX":default:return Xr(o,":")}},x:function(t,r,n,a){var i=a._originalDate||t,o=i.getTimezoneOffset();switch(r){case"x":return Wb(o);case"xxxx":case"xx":return Xr(o);case"xxxxx":case"xxx":default:return Xr(o,":")}},O:function(t,r,n,a){var i=a._originalDate||t,o=i.getTimezoneOffset();switch(r){case"O":case"OO":case"OOO":return"GMT"+Fb(o,":");case"OOOO":default:return"GMT"+Xr(o,":")}},z:function(t,r,n,a){var i=a._originalDate||t,o=i.getTimezoneOffset();switch(r){case"z":case"zz":case"zzz":return"GMT"+Fb(o,":");case"zzzz":default:return"GMT"+Xr(o,":")}},t:function(t,r,n,a){var i=a._originalDate||t,o=Math.floor(i.getTime()/1e3);return je(o,r.length)},T:function(t,r,n,a){var i=a._originalDate||t,o=i.getTime();return je(o,r.length)}};function Fb(e,t){var r=e>0?"-":"+",n=Math.abs(e),a=Math.floor(n/60),i=n%60;if(i===0)return r+String(a);var o=t;return r+String(a)+o+je(i,2)}function Wb(e,t){if(e%60===0){var r=e>0?"-":"+";return r+je(Math.abs(e)/60,2)}return Xr(e,t)}function Xr(e,t){var r=t||"",n=e>0?"-":"+",a=Math.abs(e),i=je(Math.floor(a/60),2),o=je(a%60,2);return n+i+r+o}var Ub=function(t,r){switch(t){case"P":return r.date({width:"short"});case"PP":return r.date({width:"medium"});case"PPP":return r.date({width:"long"});case"PPPP":default:return r.date({width:"full"})}},zb=function(t,r){switch(t){case"p":return r.time({width:"short"});case"pp":return r.time({width:"medium"});case"ppp":return r.time({width:"long"});case"pppp":default:return r.time({width:"full"})}},oF=function(t,r){var n=t.match(/(P+)(p+)?/)||[],a=n[1],i=n[2];if(!i)return Ub(t,r);var o;switch(a){case"P":o=r.dateTime({width:"short"});break;case"PP":o=r.dateTime({width:"medium"});break;case"PPP":o=r.dateTime({width:"long"});break;case"PPPP":default:o=r.dateTime({width:"full"});break}return o.replace("{{date}}",Ub(a,r)).replace("{{time}}",zb(i,r))},sF={p:zb,P:oF},lF=["D","DD"],uF=["YY","YYYY"];function cF(e){return lF.indexOf(e)!==-1}function fF(e){return uF.indexOf(e)!==-1}function Vb(e,t,r){if(e==="YYYY")throw new RangeError("Use `yyyy` instead of `YYYY` (in `".concat(t,"`) for formatting years to the input `").concat(r,"`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));if(e==="YY")throw new RangeError("Use `yy` instead of `YY` (in `".concat(t,"`) for formatting years to the input `").concat(r,"`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));if(e==="D")throw new RangeError("Use `d` instead of `D` (in `".concat(t,"`) for formatting days of the month to the input `").concat(r,"`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));if(e==="DD")throw new RangeError("Use `dd` instead of `DD` (in `".concat(t,"`) for formatting days of the month to the input `").concat(r,"`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"))}var dF={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXWeeks:{one:"about 1 week",other:"about {{count}} weeks"},xWeeks:{one:"1 week",other:"{{count}} weeks"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}},pF=function(t,r,n){var a,i=dF[t];return typeof i=="string"?a=i:r===1?a=i.one:a=i.other.replace("{{count}}",r.toString()),n!=null&&n.addSuffix?n.comparison&&n.comparison>0?"in "+a:a+" ago":a};function pf(e){return function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=t.width?String(t.width):e.defaultWidth,n=e.formats[r]||e.formats[e.defaultWidth];return n}}var hF={full:"EEEE, MMMM do, y",long:"MMMM do, y",medium:"MMM d, y",short:"MM/dd/yyyy"},mF={full:"h:mm:ss a zzzz",long:"h:mm:ss a z",medium:"h:mm:ss a",short:"h:mm a"},vF={full:"{{date}} 'at' {{time}}",long:"{{date}} 'at' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},yF={date:pf({formats:hF,defaultWidth:"full"}),time:pf({formats:mF,defaultWidth:"full"}),dateTime:pf({formats:vF,defaultWidth:"full"})},gF={lastWeek:"'last' eeee 'at' p",yesterday:"'yesterday at' p",today:"'today at' p",tomorrow:"'tomorrow at' p",nextWeek:"eeee 'at' p",other:"P"},bF=function(t,r,n,a){return gF[t]};function Ti(e){return function(t,r){var n=r!=null&&r.context?String(r.context):"standalone",a;if(n==="formatting"&&e.formattingValues){var i=e.defaultFormattingWidth||e.defaultWidth,o=r!=null&&r.width?String(r.width):i;a=e.formattingValues[o]||e.formattingValues[i]}else{var s=e.defaultWidth,l=r!=null&&r.width?String(r.width):e.defaultWidth;a=e.values[l]||e.values[s]}var u=e.argumentCallback?e.argumentCallback(t):t;return a[u]}}var xF={narrow:["B","A"],abbreviated:["BC","AD"],wide:["Before Christ","Anno Domini"]},wF={narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1st quarter","2nd quarter","3rd quarter","4th quarter"]},OF={narrow:["J","F","M","A","M","J","J","A","S","O","N","D"],abbreviated:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],wide:["January","February","March","April","May","June","July","August","September","October","November","December"]},SF={narrow:["S","M","T","W","T","F","S"],short:["Su","Mo","Tu","We","Th","Fr","Sa"],abbreviated:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wide:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},TF={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"}},AF={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"}},PF=function(t,r){var n=Number(t),a=n%100;if(a>20||a<10)switch(a%10){case 1:return n+"st";case 2:return n+"nd";case 3:return n+"rd"}return n+"th"},jF={ordinalNumber:PF,era:Ti({values:xF,defaultWidth:"wide"}),quarter:Ti({values:wF,defaultWidth:"wide",argumentCallback:function(t){return t-1}}),month:Ti({values:OF,defaultWidth:"wide"}),day:Ti({values:SF,defaultWidth:"wide"}),dayPeriod:Ti({values:TF,defaultWidth:"wide",formattingValues:AF,defaultFormattingWidth:"wide"})};function Ai(e){return function(t){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=r.width,a=n&&e.matchPatterns[n]||e.matchPatterns[e.defaultMatchWidth],i=t.match(a);if(!i)return null;var o=i[0],s=n&&e.parsePatterns[n]||e.parsePatterns[e.defaultParseWidth],l=Array.isArray(s)?EF(s,function(f){return f.test(o)}):_F(s,function(f){return f.test(o)}),u;u=e.valueCallback?e.valueCallback(l):l,u=r.valueCallback?r.valueCallback(u):u;var c=t.slice(o.length);return{value:u,rest:c}}}function _F(e,t){for(var r in e)if(e.hasOwnProperty(r)&&t(e[r]))return r}function EF(e,t){for(var r=0;r<e.length;r++)if(t(e[r]))return r}function CF(e){return function(t){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=t.match(e.matchPattern);if(!n)return null;var a=n[0],i=t.match(e.parsePattern);if(!i)return null;var o=e.valueCallback?e.valueCallback(i[0]):i[0];o=r.valueCallback?r.valueCallback(o):o;var s=t.slice(a.length);return{value:o,rest:s}}}var $F=/^(\d+)(th|st|nd|rd)?/i,kF=/\d+/i,MF={narrow:/^(b|a)/i,abbreviated:/^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,wide:/^(before christ|before common era|anno domini|common era)/i},NF={any:[/^b/i,/^(a|c)/i]},DF={narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},IF={any:[/1/i,/2/i,/3/i,/4/i]},LF={narrow:/^[jfmasond]/i,abbreviated:/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,wide:/^(january|february|march|april|may|june|july|august|september|october|november|december)/i},RF={narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^f/i,/^mar/i,/^ap/i,/^may/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},BF={narrow:/^[smtwf]/i,short:/^(su|mo|tu|we|th|fr|sa)/i,abbreviated:/^(sun|mon|tue|wed|thu|fri|sat)/i,wide:/^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i},FF={narrow:[/^s/i,/^m/i,/^t/i,/^w/i,/^t/i,/^f/i,/^s/i],any:[/^su/i,/^m/i,/^tu/i,/^w/i,/^th/i,/^f/i,/^sa/i]},WF={narrow:/^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,any:/^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i},UF={any:{am:/^a/i,pm:/^p/i,midnight:/^mi/i,noon:/^no/i,morning:/morning/i,afternoon:/afternoon/i,evening:/evening/i,night:/night/i}},zF={ordinalNumber:CF({matchPattern:$F,parsePattern:kF,valueCallback:function(t){return parseInt(t,10)}}),era:Ai({matchPatterns:MF,defaultMatchWidth:"wide",parsePatterns:NF,defaultParseWidth:"any"}),quarter:Ai({matchPatterns:DF,defaultMatchWidth:"wide",parsePatterns:IF,defaultParseWidth:"any",valueCallback:function(t){return t+1}}),month:Ai({matchPatterns:LF,defaultMatchWidth:"wide",parsePatterns:RF,defaultParseWidth:"any"}),day:Ai({matchPatterns:BF,defaultMatchWidth:"wide",parsePatterns:FF,defaultParseWidth:"any"}),dayPeriod:Ai({matchPatterns:WF,defaultMatchWidth:"any",parsePatterns:UF,defaultParseWidth:"any"})},VF={code:"en-US",formatDistance:pF,formatLong:yF,formatRelative:bF,localize:jF,match:zF,options:{weekStartsOn:0,firstWeekContainsDate:1}},GF=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,qF=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,KF=/^'([^]*?)'?$/,HF=/''/g,YF=/[a-zA-Z]/;function Ls(e,t,r){var n,a,i,o,s,l,u,c,f,d,h,m,y,v;Me(2,arguments);var x=String(t),w=Oi(),b=(n=(a=void 0)!==null&&a!==void 0?a:w.locale)!==null&&n!==void 0?n:VF,A=Et((i=(o=(s=(l=void 0)!==null&&l!==void 0?l:void 0)!==null&&s!==void 0?s:w.firstWeekContainsDate)!==null&&o!==void 0?o:(u=w.locale)===null||u===void 0||(c=u.options)===null||c===void 0?void 0:c.firstWeekContainsDate)!==null&&i!==void 0?i:1);if(!(A>=1&&A<=7))throw new RangeError("firstWeekContainsDate must be between 1 and 7 inclusively");var g=Et((f=(d=(h=(m=void 0)!==null&&m!==void 0?m:void 0)!==null&&h!==void 0?h:w.weekStartsOn)!==null&&d!==void 0?d:(y=w.locale)===null||y===void 0||(v=y.options)===null||v===void 0?void 0:v.weekStartsOn)!==null&&f!==void 0?f:0);if(!(g>=0&&g<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");if(!b.localize)throw new RangeError("locale must contain localize property");if(!b.formatLong)throw new RangeError("locale must contain formatLong property");var O=Ve(e);if(!KB(O))throw new RangeError("Invalid time value");var S=GB(O),P=XB(O,S),E={firstWeekContainsDate:A,weekStartsOn:g,locale:b,_originalDate:O},N=x.match(qF).map(function(j){var $=j[0];if($==="p"||$==="P"){var k=sF[$];return k(j,b.formatLong)}return j}).join("").match(GF).map(function(j){if(j==="''")return"'";var $=j[0];if($==="'")return XF(j);var k=iF[$];if(k)return fF(j)&&Vb(j,t,String(e)),cF(j)&&Vb(j,t,String(e)),k(P,j,b.localize,E);if($.match(YF))throw new RangeError("Format string contains an unescaped latin alphabet character `"+$+"`");return j}).join("");return N}function XF(e){var t=e.match(KF);return t?t[1].replace(HF,"'"):e}function Gb(e,t){Me(2,arguments);var r=Ve(e),n=Ve(t);return r.getTime()<n.getTime()}function JF(e,t){Me(2,arguments);var r=Ve(e).getTime(),n=Ve(t.start).getTime(),a=Ve(t.end).getTime();if(!(n<=a))throw new RangeError("Invalid interval");return r>=n&&r<=a}function Rs(e,t){Me(2,arguments);var r=Et(t);return WB(e,-r)}function ZF(e,t){Me(2,arguments);var r=Et(t);return df(e,-r)}const hf=({children:e})=>{const[t,r]=T.useState(!1);return T.useEffect(()=>(r(!0),()=>r(!1)),[]),t?en.createPortal(e,document.body):null};function qb({className:e,defaultValue:t,onDateRangeChange:r}){console.log("🗓️ DateRangePicker component rendered with props:",{className:e,defaultValue:t,hasCallback:!!r});const n=[{label:"Today",value:"today",dateRange:{from:aa(new Date),to:new Date}},{label:"Yesterday",value:"yesterday",dateRange:{from:aa(Rs(new Date,1)),to:HB(Rs(new Date,1))}},{label:"This week",value:"thisWeek",dateRange:{from:VB(new Date),to:new Date}},{label:"Last 7 days",value:"7d",dateRange:{from:aa(Rs(new Date,6)),to:new Date}},{label:"This month",value:"thisMonth",dateRange:{from:YB(new Date),to:new Date}},{label:"Last 30 days",value:"30d",dateRange:{from:aa(Rs(new Date,29)),to:new Date}}],a=t?n.find(M=>M.value===t):null;console.log("📅 DateRangePicker initialization:",{defaultValue:t,defaultPreset:a==null?void 0:a.label,hasDateRange:!!(a!=null&&a.dateRange),allPresetValues:n.map(M=>M.value),foundPreset:!!a});const[i,o]=T.useState(a==null?void 0:a.dateRange),[s,l]=T.useState(a==null?void 0:a.dateRange),[u,c]=T.useState(!1),[f,d]=T.useState((a==null?void 0:a.label)||null),[h,m]=T.useState((a==null?void 0:a.label)||null),[y,v]=T.useState(new Date),[x,w]=T.useState(null),[b,A]=T.useState({top:0,left:0}),g=T.useRef(null),O=T.useRef(null);T.useEffect(()=>{var M,B;console.log("📅 DateRangePicker useEffect running:",{hasDefaultPreset:!!a,hasOnDateRangeChange:!!r,currentDate:i,currentLabel:f,defaultValue:t,defaultPresetLabel:a==null?void 0:a.label,defaultPresetValue:a==null?void 0:a.value}),a!=null&&a.dateRange&&r?(console.log("📅 DateRangePicker: Setting initial default value:",{label:a.label,dateRange:a.dateRange,from:(M=a.dateRange.from)==null?void 0:M.toLocaleDateString(),to:(B=a.dateRange.to)==null?void 0:B.toLocaleDateString()}),r(a.dateRange)):console.log("📅 DateRangePicker: NOT setting initial value because:",{hasDefaultPreset:!!a,hasDateRange:!!(a!=null&&a.dateRange),hasCallback:!!r,presetLabelsAvailable:n.map(U=>`${U.value}:${U.label}`)})},[]),T.useEffect(()=>{t&&(a!=null&&a.dateRange)&&(console.log("📅 DateRangePicker: DefaultValue changed, updating state:",{defaultValue:t,label:a.label}),o(a.dateRange),d(a.label),l(a.dateRange),m(a.label))},[t]);const S=()=>{if(!O.current)return;const M=O.current.getBoundingClientRect(),B=window.scrollY,U=window.scrollX,V=window.innerWidth,C=window.innerHeight,R=720,F=450;let W=M.bottom+B+8,G=M.left+U;G+R>V&&(G=M.right+U-R),G+R>V&&(G=V-R-20),W+F>C&&(W=M.top+B-F-8),G<20&&(G=20),W<20&&(W=20),A({top:W,left:G})};T.useEffect(()=>{const M=()=>{u&&S()};return u&&(window.addEventListener("resize",M),window.addEventListener("scroll",M)),()=>{window.removeEventListener("resize",M),window.removeEventListener("scroll",M)}},[u]);const P=(M,B)=>{if(l(M),m(B),w(null),M.from){const U=new Date(M.from.getFullYear(),M.from.getMonth(),1);v(U)}},E=M=>{if(!x)w(M),l({from:M,to:M}),m(null);else{const B=Gb(M,x)?M:x,U=Gb(M,x)?x:M;l({from:B,to:U}),w(null),m(null)}},N=()=>{o(s),d(h),r==null||r(s),c(!1),w(null)},j=()=>{l(void 0),m(null),o(void 0),d(null),r==null||r(void 0),c(!1),w(null)},$=M=>{M?(l(i),m(f),w(null),setTimeout(S,0)):(l(i),m(f),w(null)),c(M)},k=(M,B)=>(console.log("📅 formatDateRange called with:",{presetLabel:B,hasDateRange:!!(M!=null&&M.from)}),B||(M!=null&&M.from?!M.to||Si(M.from,M.to)?Ls(M.from,"MMM dd, yyyy"):`${Ls(M.from,"MMM dd, yyyy")} - ${Ls(M.to,"MMM dd, yyyy")}`:"Pick a date range")),_=(M=0)=>{const B=df(y,M),U=B.getFullYear(),V=B.getMonth(),C=new Date(U,V,1),F=new Date(U,V+1,0).getDate(),W=C.getDay(),G=["January","February","March","April","May","June","July","August","September","October","November","December"],X=["Su","Mo","Tu","We","Th","Fr","Sa"],Q=[],te=new Date(U,V-1,0).getDate();for(let Z=W-1;Z>=0;Z--){const L=te-Z,oe=new Date(U,V-1,L);Q.push(p.jsx("button",{onClick:()=>E(oe),className:"h-[32px] w-[32px] text-xs text-gray-400 hover:bg-gray-100 rounded-full flex items-center justify-center",children:L},`prev-${L}`))}for(let Z=1;Z<=F;Z++){const L=new Date(U,V,Z),oe=Si(L,new Date),K=(s==null?void 0:s.from)&&(s==null?void 0:s.to)&&JF(L,{start:s.from,end:s.to}),ue=(s==null?void 0:s.from)&&Si(L,s.from),ee=(s==null?void 0:s.to)&&Si(L,s.to),me=x&&Si(L,x);let Ue="h-[32px] w-[32px] text-xs hover:bg-gray-100 hover:text-gray-900 hover:font-medium rounded-full flex items-center justify-center transition-colors text-gray-700 ";oe&&(Ue+="font-semibold "),me||ue||ee?Ue+="!bg-blue-500 !text-white !hover:bg-blue-500 !hover:text-white font-semibold":K&&(Ue+="bg-blue-100 text-blue-900 hover:bg-blue-100 hover:text-blue-900 font-semibold"),Q.push(p.jsx("button",{onClick:()=>E(L),className:Ue,children:Z},`current-${Z}`))}const Y=Math.ceil((W+F)/7)*7-W-F;for(let Z=1;Z<=Y;Z++){const L=new Date(U,V+1,Z);Q.push(p.jsx("button",{onClick:()=>E(L),className:"h-[32px] w-[32px] text-sm text-gray-500 hover:bg-gray-100 rounded-full flex items-center justify-center",children:Z},`next-${Z}`))}return p.jsxs("div",{className:"p-[12px]",children:[p.jsxs("div",{className:"flex items-center justify-between mb-3",children:[M===0&&p.jsx("button",{onClick:()=>v(ZF(y,1)),className:"p-[4px] hover:bg-gray-100 rounded",children:p.jsx(x0,{className:"h-[16px] w-[16px]"})}),p.jsxs("div",{className:"font-semibold text-sm text-gray-700",children:[G[V]," ",U]}),M===1&&p.jsx("button",{onClick:()=>v(df(y,1)),className:"p-[4px] hover:bg-gray-100 rounded",children:p.jsx(ki,{className:"h-[16px] w-[16px]"})})]}),p.jsx("div",{className:"grid grid-cols-7 gap-1 mb-2",children:X.map(Z=>p.jsx("div",{className:"h-[32px] flex items-center justify-center text-xs font-medium text-gray-700 w-full text-center",children:Z},Z))}),p.jsx("div",{className:"grid grid-cols-7 gap-1",children:Q})]})},D=()=>"fixed bg-white border border-gray-200 rounded-lg shadow-xl z-[99999]";return p.jsxs("div",{className:`relative ${e}`,children:[p.jsxs("button",{ref:O,onClick:()=>$(!u),className:`min-w-[200px] px-[12px] py-[8px] text-left border border-gray-300 rounded-md shadow-sm bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 flex items-center ${i?"text-gray-900":"text-gray-500"}`,children:[p.jsx(Of,{className:"mr-2 h-[16px] w-[16px]"}),(()=>{const M=k(i,f);return console.log("📅 Button display text:",{displayText:M,date:i,selectedPresetLabel:f}),M})()]}),u&&p.jsxs(hf,{children:[p.jsx("div",{className:"fixed inset-0 z-[99998] bg-black bg-opacity-10",onClick:()=>$(!1)}),p.jsxs("div",{ref:g,className:D(),style:{top:b.top,left:b.left,width:"720px",minWidth:"720px",maxHeight:"90vh"},onClick:M=>M.stopPropagation(),children:[p.jsxs("div",{className:"flex",children:[p.jsxs("div",{className:"flex flex-col gap-1 p-[12px] border-r border-gray-200 w-[160px] flex-shrink-0",children:[p.jsx("div",{className:"text-sm font-medium text-gray-500 mb-2",children:"Quick Filters"}),n.map(M=>p.jsx("button",{onClick:()=>P(M.dateRange,M.label),className:`text-left px-[12px] py-[8px] text-sm text-gray-900 rounded hover:bg-gray-100 transition-colors ${h===M.label?"bg-gray-100 medium":""}`,children:M.label},M.label))]}),p.jsxs("div",{className:"flex flex-1",children:[_(0),_(1)]})]}),p.jsxs("div",{className:"border-t border-gray-200 bg-gray-50 p-[12px] flex justify-end gap-2",children:[p.jsx("button",{onClick:j,className:"px-[12px] py-[8px] text-sm border border-gray-300 rounded hover:bg-gray-50 transition-colors",children:"Clear"}),p.jsx("button",{onClick:N,disabled:!(s!=null&&s.from),className:"px-[12px] py-[8px] text-sm bg-blue-600 text-white rounded hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:"Apply"})]})]})]})]})}const QF=({config:e,appConfig:t,className:r,onExport:n,onDraftChange:a,onTimeRangeChange:i})=>{var k;const{title:o,subtitle:s,sections:l,globalControls:u,layout:c={columns:12,gap:24,responsive:!0}}=e,[f,d]=T.useState(!1),[h,m]=T.useState({}),[y,v]=T.useState(l),[x,w]=T.useState([]),[b,A]=T.useState(!1),g=T.useRef(null);T.useEffect(()=>{if(t)try{g.current=new Ht(t),O(),S()}catch(_){console.error("Failed to initialize API service:",_)}},[t]);const O=async()=>{if(!(!g.current||!t)){A(!0);try{const _=await g.current.fetchEnvironments();w(_),console.log("🌍 Environments loaded:",_.map(D=>D.envName))}catch(_){console.error("Error loading environments:",_)}finally{A(!1)}}},S=async()=>{if(!(!g.current||!t)){d(!0);try{const _=g.current.getDefaultTimeRange();console.log("📊 Loading dashboard data with date range:",{fromTimestamp:_.fromTimestamp,toTimestamp:_.toTimestamp,fromDate:new Date(_.fromTimestamp).toLocaleDateString(),toDate:new Date(_.toTimestamp).toLocaleDateString()});const D=await g.current.fetchAllCardsDataWithEnhancedViews(_.fromTimestamp,_.toTimestamp);console.log("✅ Enhanced cards data loaded successfully:",D),console.log("📈 Data covers period:",{from:new Date(_.fromTimestamp).toLocaleDateString(),to:new Date(_.toTimestamp).toLocaleDateString()});const M=l.map(B=>B.id==="usage-analytics"?(console.log("Updating usage-analytics section with enhanced data"),{...B,metrics:D.usageAnalytics}):B.id==="runs"?(console.log("Updating runs section with enhanced data including table and controls"),{...B,metrics:D.runs}):B);v(M)}catch(_){console.error("Error loading initial data:",_),v(l)}finally{d(!1)}}},P=async(_,D)=>{if(!(!g.current||!t||!D.metricType)){v(M=>M.map(B=>B.id===_?{...B,metrics:B.metrics.map(U=>({...U,highlighted:U.metricType===D.metricType}))}:B)),m(M=>({...M,[_]:!0}));try{const M=t.defaultTimeRange||Ht.getDateRange(7);let B,U;if(["users","sessions","messages","tokens"].includes(D.metricType))B="usage-analytics",U=D.metricType;else if(["agentRuns","toolRuns","modelRuns"].includes(D.metricType))B="runs",U=D.metricType==="agentRuns"?"agent-runs":D.metricType==="toolRuns"?"tool-runs":"model-runs";else return;const V=await g.current.fetchTimeSeriesData(U,B,M.fromTimestamp,M.toTimestamp),C=g.current.transformTimeSeriesDataForMetric(V,D.metricType);console.log("Time series response for",D.title,":",V),console.log("Transformed data for",D.title,":",C),console.log("Metric type used for transformation:",D.metricType);const F=(W=>({users:"users",sessions:"sessions",messages:"messages",tokens:"totalTokens",agentRuns:"agentRuns",toolRuns:"toolRuns",modelRuns:"modelRuns"})[W]||"count")(D.metricType||"count");console.log("Using dataKey for metric",D.metricType,":",F),v(W=>W.map(G=>{if(G.id===_){const X={...G,view:{...G.view,chart:G.view.chart?{...G.view.chart,data:C,dataKey:F,lines:[{dataKey:F,color:G.view.chart.color||"#3b82f6",label:D.title,strokeWidth:2}]}:{type:"line",data:C,dataKey:F,lines:[{dataKey:F,color:"#3b82f6",label:D.title,strokeWidth:2}],yAxisLabel:D.title}}};return console.log("Updated section for",_,":",X),console.log("Chart config set:",X.view.chart),X}return G}))}catch(M){console.error("Error loading metric data:",M)}finally{m(M=>({...M,[_]:!1}))}}},E=_=>{var D,M;if((M=(D=u==null?void 0:u.draft)==null?void 0:D.onChange)==null||M.call(D,_),a==null||a(_),t&&g.current){const B={...t,environment:_};g.current.updateConfig(B),S()}},N=_=>{var D,M;if(console.log("🗓️ Time range change requested:",_),typeof _=="string"&&((M=(D=u==null?void 0:u.timeRange)==null?void 0:D.onChange)==null||M.call(D,_)),i==null||i(_),t&&g.current){let B=null;if(typeof _=="object"&&_.from&&_.to)B={fromTimestamp:_.from.toISOString(),toTimestamp:_.to.toISOString()},console.log("📅 Converting DateRange to API format:",B);else if(typeof _=="string"){const V={"24h":1,"7d":7,"30d":30,"90d":90}[_];V&&(B=Ht.getDateRange(V),console.log(`📅 Converting preset "${_}" (${V} days) to API format:`,B))}if(B){const U={...t,defaultTimeRange:B};console.log("🔄 Updating API configuration with new date range:",U.defaultTimeRange),g.current.updateConfig(U),console.log("🚀 Reloading dashboard data with new date range..."),S()}else console.warn("⚠️ Unable to convert time range value to API format:",_)}},j=(_="csv")=>{var D,M;(M=(D=u==null?void 0:u.export)==null?void 0:D.onExport)==null||M.call(D,_),n==null||n()},$=Object.values(h).some(_=>_);return p.jsxs("div",{className:se("w-full h-full flex flex-col overflow-hidden",r),children:[p.jsxs("div",{className:"flex flex-col gap-2 w-full p-[24px] pb-[12px]",children:[p.jsx("h1",{className:"text-lg font-bold text-gray-900 w-full",children:o}),p.jsxs("div",{className:"flex items-center gap-2 w-full",children:[s&&p.jsx("p",{className:"text-gray-500 text-xs w-full",children:s}),p.jsxs("div",{className:"flex items-center gap-2 justify-end flex-shrink-0",children:[(f||$)&&p.jsxs("div",{className:"flex items-center gap-2 text-sm medium text-gray-500",children:[p.jsx(T0,{className:"h-[16px] w-[16px] animate-spin"}),"Loading..."]}),u&&p.jsxs(p.Fragment,{children:[u.draft&&p.jsx(Ms,{options:x.length>0?x.map(_=>({label:_.envName.charAt(0).toUpperCase()+_.envName.slice(1),value:_.envName})):u.draft.options,value:u.draft.defaultValue,placeholder:b?"Loading environments...":u.draft.label,onChange:E,className:"min-w-[200px]",disabled:f||$||b}),u.timeRange&&(u.timeRange.useDatePicker?(console.log("🗓️ Dashboard: Rendering DateRangePicker with defaultValue:",u.timeRange.defaultValue),p.jsx(qb,{defaultValue:u.timeRange.defaultValue,onDateRangeChange:_=>{console.log("🗓️ Dashboard: DateRangePicker callback received:",_),_&&N(_)}})):p.jsxs("div",{className:"flex items-center gap-2",children:[p.jsx(Of,{className:"h-4 w-4 text-gray-500"}),p.jsx(Ms,{options:u.timeRange.options||[],value:u.timeRange.defaultValue,placeholder:u.timeRange.label,onChange:N,className:"min-w-[200px]",disabled:f||$})]})),((k=u.export)==null?void 0:k.enabled)&&p.jsxs(ff,{variant:"outline",onClick:()=>j(),className:"gap-2",disabled:f||$,children:[p.jsx(w0,{className:"h-4 w-4"}),"Export"]})]})]})]})]}),p.jsx("div",{className:se("grid gap-6 p-[24px] pt-[8px] overflow-y-auto",c.responsive&&"grid-cols-1 lg:grid-cols-12"),style:{gridTemplateColumns:c.responsive?void 0:`repeat(${c.columns}, minmax(0, 1fr))`,gap:c.gap?`${c.gap}px`:void 0},children:y.map(_=>{var D,M,B,U;return p.jsx(Lb,{section:_,isLoading:f,isChartLoading:h[_.id]||!1,onMetricClick:V=>P(_.id,V),className:se(c.responsive&&((D=_.layout)==null?void 0:D.span)===12&&"lg:col-span-12",c.responsive&&((M=_.layout)==null?void 0:M.span)===6&&"lg:col-span-6",c.responsive&&((B=_.layout)==null?void 0:B.span)===4&&"lg:col-span-4",c.responsive&&((U=_.layout)==null?void 0:U.span)===3&&"lg:col-span-3")},_.id)})})]})};class Kb{static buildSessionTree(t,r){var i;const n=this.groupEventsByRun(t),a=[];for(const[o,s]of n.entries()){const l=this.buildRunTree(o,s);a.push(l)}return a.sort((o,s)=>new Date(o.startTime).getTime()-new Date(s.startTime).getTime()),{sessionId:r||((i=t[0])==null?void 0:i.sessionId)||"unknown",runs:a}}static groupEventsByRun(t){const r=new Map;return t.forEach(n=>{const a=n.runId;r.has(a)||r.set(a,[]),r.get(a).push(n)}),r}static buildRunTree(t,r){var y;const n=new Map;r.forEach(v=>{const x=`${v.data.id}|${v.data.name}|${v.data.toolName}`;n.has(x)||n.set(x,{});const w=n.get(x);v.type==="node_started"?w.started=v:v.type==="node_completed"&&(w.completed=v)});const a=[];for(const[,v]of n.entries()){const x=v.started,w=v.completed;if(!x)continue;const b=this.createTreeNodeFromEvents(x,w,t);a.push(b)}const i=this.buildNodeHierarchy(a),o=r.filter(v=>v.runId===t),s=Math.min(...o.map(v=>new Date(v.data.timestamp).getTime())),l=o.filter(v=>v.type==="node_completed"),u=l.length>0?Math.max(...l.map(v=>new Date(v.data.timestamp).getTime())):void 0,c=this.calculateRunStatus(o),f=u&&s?u-s:void 0,d=this.calculateRunTokens(o),h=this.extractUserInput(o),m=this.extractFinalOutput(o);return{runId:t,startTime:new Date(s).toISOString(),endTime:u?new Date(u).toISOString():void 0,status:c,rootNodes:i,duration:f,totalTokens:d>0?d:void 0,sessionId:((y=o[0])==null?void 0:y.sessionId)||"unknown",userInput:h,finalOutput:m}}static createTreeNodeFromEvents(t,r,n){const a=t.data.timestamp,i=r==null?void 0:r.data.timestamp,o=i&&a?new Date(i).getTime()-new Date(a).getTime():void 0,s=r||t,l=s.data.type==="llm"||s.data.type==="tool",u=l?t.data.input:void 0,c=l?r==null?void 0:r.data.output:void 0,f=this.extractLLMUsage(c),{toolInvocations:d,isResponse:h}=this.extractToolInvocations(c),m=s.data.type==="llm"?this.extractProvider(s.data.name||s.data.toolName):void 0;return{id:s.data.id,parentId:s.data.parentId,runId:n||"unknown",name:s.data.name,type:s.data.type,status:(r==null?void 0:r.data.status)||t.data.status,startTime:a,endTime:i,duration:o,icon:s.data.icon,input:u,output:c,children:[],level:0,isExpanded:!1,llmUsage:f,toolInvocations:d,isResponse:h,metadata:{...s.data.metadata,provider:m}}}static buildNodeHierarchy(t){const r=new Map;t.forEach(a=>r.set(a.id,a));const n=[];return t.forEach(a=>{if(a.parentId&&r.has(a.parentId)){const i=r.get(a.parentId);i.children.push(a),a.level=i.level+1}else n.push(a),a.level=0}),n.sort((a,i)=>new Date(a.startTime).getTime()-new Date(i.startTime).getTime()),n.forEach(a=>this.sortChildren(a)),n}static extractLLMUsage(t){var r;if(!(!t||typeof t!="object")&&(r=t.metadata)!=null&&r.usage_metadata)return t.metadata.usage_metadata}static extractToolInvocations(t){if(!t||typeof t!="object")return{};if(t.name&&t.tool_call_id){const r=t.name==="route_to_user"||t.toolName==="route_to_user";return{toolInvocations:[t],isResponse:r}}if(Array.isArray(t)){const r=t.filter(n=>n&&typeof n=="object"&&(n.name==="route_to_user"||n.toolName==="route_to_user")&&n.tool_call_id);if(r.length>0){const n=r.some(a=>a.name==="route_to_user"||a.toolName==="route_to_user");return{toolInvocations:r,isResponse:n}}}if(t.tool_calls&&Array.isArray(t.tool_calls)){const r=t.tool_calls.filter(n=>n&&typeof n=="object"&&(n.name==="route_to_user"||n.toolName==="route_to_user")&&n.tool_call_id);if(r.length>0){const n=r.some(a=>a.name==="route_to_user"||a.toolName==="route_to_user");return{toolInvocations:r,isResponse:n}}}return{}}static extractProvider(t){if(!t)return;const r=t.toLowerCase();if(r.includes("gemini"))return"google";if(r.includes("gpt")||r.includes("openai"))return"openai";if(r.includes("claude")||r.includes("anthropic"))return"anthropic";if(r.includes("azure"))return"azure";if(r.includes("cohere"))return"cohere";const n=t.split("-");if(n.length>0){const a=n[0].toLowerCase();if(["gemini","gpt","claude","cohere"].includes(a))return a==="gemini"?"google":a==="gpt"?"openai":a==="claude"?"anthropic":a}return"custom"}static sortChildren(t){t&&(t.children.sort((r,n)=>new Date(r.startTime).getTime()-new Date(n.startTime).getTime()),t.children.forEach(r=>this.sortChildren(r)))}static calculateRunStatus(t){const r=t.some(a=>a.data.status==="running"),n=t.some(a=>a.data.status==="failed");return r?"running":n?"failed":"completed"}static extractUserInput(t){const r=t.filter(n=>n.type==="node_started"&&n.data.type==="llm").sort((n,a)=>new Date(n.data.timestamp).getTime()-new Date(a.data.timestamp).getTime());if(r.length>0){const n=r[0];if(n.data.input){if(typeof n.data.input=="string")return n.data.input;if(typeof n.data.input=="object")return JSON.stringify(n.data.input)}}}static extractFinalOutput(t){var n,a,i,o,s,l,u,c,f,d;const r=t.filter(h=>h.type==="node_completed"&&h.data.type==="tool"&&(h.data.name==="route_to_user"||h.data.toolName==="route_to_user"));if(r.length>0&&console.log("Found route_to_user events:",r.length),r.length>0){const m=r[r.length-1].data.output;if(console.log("Route to user output structure:",JSON.stringify(m,null,2)),m)if(Array.isArray(m)){const y=m.find(v=>v&&typeof v=="object"&&(v.name==="route_to_user"||v.toolName==="route_to_user"));if(y){if((n=y.args)!=null&&n.message)return console.log("Found message in array format: routeToUserTool.args.message"),y.args.message;if(y.message)return console.log("Found message in array format: routeToUserTool.message"),y.message;if((a=y.output)!=null&&a.message)return console.log("Found message in array format: routeToUserTool.output.message"),y.output.message}}else{if((i=m.args)!=null&&i.message)return console.log("Found message at: output.args.message"),m.args.message;if(m.message)return console.log("Found message at: output.message"),m.message;if((o=m.output)!=null&&o.message)return console.log("Found message at: output.output.message"),m.output.message;if((s=m.input)!=null&&s.message)return console.log("Found message at: output.input.message"),m.input.message;if((u=(l=m.input)==null?void 0:l.args)!=null&&u.message)return console.log("Found message at: output.input.args.message"),m.input.args.message;if((c=m.data)!=null&&c.message)return console.log("Found message at: output.data.message"),m.data.message;if((f=m.result)!=null&&f.message)return console.log("Found message at: output.result.message"),m.result.message;if(typeof m=="string")try{const y=JSON.parse(m);if((d=y.args)!=null&&d.message)return console.log("Found message in parsed string: parsed.args.message"),y.args.message;if(y.message)return console.log("Found message in parsed string: parsed.message"),y.message}catch{if(m.length>10&&!m.includes("{")&&!m.includes("["))return console.log("Using output string directly as message"),m}try{return JSON.stringify(m)}catch{return m}}console.log("No message found in route_to_user output paths")}}static calculateRunTokens(t){let r=0;return t.forEach(n=>{const a=this.extractLLMUsage(n.data);a!=null&&a.total_tokens&&(r+=a.total_tokens)}),r}static updateTree(t,r,n){return this.buildSessionTree(n,t.sessionId)}static mergeEvents(t,r){return[...t,...r].sort((a,i)=>new Date(a.timestamp).getTime()-new Date(i.timestamp).getTime())}}const eW=({isOpen:e,onClose:t,title:r,data:n,initialViewMode:a="interactive",modalHeight:i="50vh"})=>{const[o,s]=T.useState(a),l=T.useMemo(()=>{if(n==null)return!1;if(typeof n=="string")try{return JSON.parse(n),!0}catch{return!1}return typeof n=="object"},[n]),u=c=>{c.target===c.currentTarget&&t()};return e?p.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center p-4",onClick:u,children:p.jsxs("div",{className:"bg-white rounded-lg shadow-xl max-w-6xl w-full flex flex-col",style:{height:i},children:[p.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-200",children:[p.jsxs("div",{className:"flex items-center gap-4",children:[p.jsxs("div",{className:"flex items-center gap-2",children:[p.jsx(Vs,{className:"w-5 h-5 text-gray-400"}),p.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:r})]}),l&&p.jsxs("div",{className:"flex items-center gap-1 ml-4 pl-4 border-l border-gray-200",children:[p.jsx("button",{onClick:()=>s("interactive"),className:`p-1.5 hover:bg-gray-200 rounded transition-colors ${o==="interactive"?"bg-gray-200":""}`,title:"Interactive JSON view (fold/unfold)",children:p.jsx(Pf,{className:"w-4 h-4 text-gray-400"})}),p.jsx("button",{onClick:()=>s("plain"),className:`p-1.5 hover:bg-gray-200 rounded transition-colors ${o==="plain"?"bg-gray-200":""}`,title:"Plain JSON view",children:p.jsx(wf,{className:"w-4 h-4 text-gray-400"})})]})]}),p.jsxs("div",{className:"flex items-center gap-2",children:[p.jsx("button",{onClick:async()=>{const c=typeof n=="string"?n:JSON.stringify(n,null,2);try{if(navigator.clipboard&&navigator.clipboard.writeText){await navigator.clipboard.writeText(c);return}const f=document.createElement("textarea");f.value=c,f.style.position="fixed",f.style.left="-999999px",f.style.top="-999999px",document.body.appendChild(f),f.focus(),f.select();try{document.execCommand("copy")}catch(d){console.warn("Copy to clipboard failed:",d)}finally{document.body.removeChild(f)}}catch(f){console.warn("Copy to clipboard failed:",f)}},className:"p-2 hover:bg-gray-100 rounded-lg transition-colors",title:"Copy content",children:p.jsx(fa,{className:"w-4 h-4 text-gray-500"})}),p.jsx("button",{onClick:t,className:"p-2 hover:bg-gray-100 rounded-lg transition-colors",title:"Close",children:p.jsx(Ef,{className:"w-4 h-4 text-gray-500"})})]})]}),p.jsx("div",{className:"flex-1 overflow-hidden",children:p.jsx(Jr,{data:n,showHeader:!1,className:"h-full border-0",defaultExpanded:!0,viewMode:o,onViewModeChange:s})})]})}):null},tW=({data:e,level:t=0,expandedKeys:r=new Set,onToggleKey:n,keyPath:a=""})=>{const i=t*16,o=(s,l,u)=>{const c=u?`${u}.${l}`:l||"";if(s===null)return p.jsx("span",{className:"text-gray-400 italic",children:"null"});if(s===void 0)return p.jsx("span",{className:"text-gray-400 italic",children:"undefined"});if(typeof s=="boolean")return p.jsx("span",{className:"text-purple-600 font-medium",children:String(s)});if(typeof s=="number")return p.jsx("span",{className:"text-blue-600 font-medium",children:s});if(typeof s=="string"){const f=s.length>100,d=f&&!r.has(`${c}._string`)?`${s.substring(0,100)}...`:s;return p.jsxs("div",{className:"inline",children:[p.jsxs("span",{className:"text-green-600",children:['"',d,'"']}),f&&p.jsx("button",{onClick:()=>n==null?void 0:n(`${c}._string`),className:"ml-2 text-xs text-blue-500 hover:text-blue-700 underline",children:r.has(`${c}._string`)?"Show less":"Show more"})]})}if(Array.isArray(s)){const f=r.has(c);return s.length===0?p.jsx("span",{className:"text-gray-500",children:"[]"}):p.jsxs("div",{children:[p.jsxs("div",{className:"flex items-center",children:[p.jsxs("button",{onClick:()=>n==null?void 0:n(c),className:"flex items-center gap-1 hover:bg-gray-100 p-1 rounded transition-colors",children:[f?p.jsx(cr,{className:"w-3 h-3 text-gray-400"}):p.jsx(ki,{className:"w-3 h-3 text-gray-400"}),p.jsxs("span",{className:"text-gray-600 text-xs",children:["Array[",s.length,"]"]})]}),!f&&p.jsx("span",{className:"text-gray-400 ml-2",children:"[...]"})]}),f&&p.jsx("div",{className:"ml-4 mt-1",children:s.map((h,m)=>p.jsxs("div",{className:"flex items-start gap-2 py-1",style:{marginLeft:`${i}px`},children:[p.jsxs("span",{className:"text-gray-400 text-xs mt-0.5 min-w-[20px]",children:[m,":"]}),p.jsx("div",{className:"flex-1",children:o(h,String(m),`${c}[${m}]`)})]},m))})]})}if(typeof s=="object"){const f=Object.keys(s),d=r.has(c);return f.length===0?p.jsx("span",{className:"text-gray-500",children:"{}"}):p.jsxs("div",{children:[p.jsxs("div",{className:"flex items-center",children:[p.jsxs("button",{onClick:()=>n==null?void 0:n(c),className:"flex items-center gap-1 hover:bg-gray-100 p-1 rounded transition-colors",children:[d?p.jsx(cr,{className:"w-3 h-3 text-gray-400"}):p.jsx(ki,{className:"w-3 h-3 text-gray-400"}),p.jsxs("span",{className:"text-gray-600 text-xs",children:["Object ","{",f.length," ",f.length===1?"key":"keys","}"]})]}),!d&&p.jsx("span",{className:"text-gray-400 ml-2",children:"{ ... }"})]}),d&&p.jsx("div",{className:"ml-4 mt-1",children:f.map(m=>p.jsxs("div",{className:"flex items-start gap-2 py-1",style:{marginLeft:`${i}px`},children:[p.jsxs("span",{className:"text-blue-700 text-xs mt-0.5 font-medium min-w-fit",children:['"',m,'":']}),p.jsx("div",{className:"flex-1",children:o(s[m],m,c)})]},m))})]})}return p.jsx("span",{className:"text-gray-600",children:String(s)})};return p.jsx("div",{className:"font-mono text-xs",children:o(e,"",a)})},Hb=e=>{const t=[];if(t.push(""),e==null)return t;let r=e;if(typeof e=="string")try{r=JSON.parse(e)}catch{return t}return typeof r=="object"&&!Array.isArray(r)&&Object.keys(r).forEach(n=>{t.push(n)}),Array.isArray(r)&&r.forEach((n,a)=>{t.push(`[${a}]`)}),t},Jr=({data:e,title:t="Data",className:r="",maxHeight:n="300px",showHeader:a=!0,defaultExpanded:i=!1,defaultViewMode:o="interactive",viewMode:s,onViewModeChange:l,modalHeight:u="50vh"})=>{const[c,f]=T.useState(!1),[d,h]=T.useState(o),m=T.useMemo(()=>i?new Set([""]):new Set(Hb(e)),[e,i]),[y,v]=T.useState(m);T.useEffect(()=>{i||v(new Set(Hb(e)))},[e,i]);const x=s!==void 0,w=x?s:d,b=N=>{x?l==null||l(N):h(N)},{isValidJson:A,displayContent:g}=T.useMemo(()=>{if(e==null)return{isValidJson:!1,displayContent:e===null?"null":"undefined"};if(typeof e=="string")try{return{isValidJson:!0,displayContent:JSON.parse(e)}}catch{return{isValidJson:!1,displayContent:e}}return typeof e=="object"?{isValidJson:!0,displayContent:e}:{isValidJson:!1,displayContent:String(e)}},[e]),O=T.useCallback(N=>{v(j=>{const $=new Set(j);return $.has(N)?$.delete(N):$.add(N),$})},[]),S=T.useCallback(async()=>{const N=A?JSON.stringify(g,null,2):g;try{if(navigator.clipboard&&navigator.clipboard.writeText){await navigator.clipboard.writeText(N);return}const j=document.createElement("textarea");j.value=N,j.style.position="fixed",j.style.left="-999999px",j.style.top="-999999px",document.body.appendChild(j),j.focus(),j.select();try{document.execCommand("copy")}catch($){console.warn("Copy to clipboard failed:",$)}finally{document.body.removeChild(j)}}catch(j){console.warn("Copy to clipboard failed:",j)}},[A,g]),P=T.useCallback(()=>{f(!0)},[]),E=T.useCallback(()=>{f(!1)},[]);return p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:`bg-white border border-gray-200 rounded-md overflow-hidden ${r}`,children:[a&&p.jsxs("div",{className:"bg-gray-50 border-b border-gray-200 px-4 py-2 flex items-center justify-between",children:[A&&p.jsxs("div",{className:"flex items-center gap-2",children:[p.jsx("button",{onClick:()=>b("interactive"),className:`p-1 hover:bg-gray-200 rounded transition-colors ${w==="interactive"?"bg-gray-200":""}`,title:"Interactive JSON view (fold/unfold)",children:p.jsx(Pf,{className:"w-4 h-4 text-gray-400"})}),p.jsx("button",{onClick:()=>b("plain"),className:`p-1 hover:bg-gray-200 rounded transition-colors ${w==="plain"?"bg-gray-200":""}`,title:"Plain JSON view",children:p.jsx(wf,{className:"w-4 h-4 text-gray-400"})})]}),p.jsx("div",{className:"flex-1"}),p.jsxs("div",{className:"flex items-center gap-2",children:[p.jsx("button",{onClick:P,className:"p-1 hover:bg-gray-200 rounded transition-colors",title:"Expand to full screen",children:p.jsx(jf,{className:"w-4 h-4 text-gray-400"})}),p.jsx("button",{onClick:S,className:"p-1 hover:bg-gray-200 rounded transition-colors",title:"Copy content",children:p.jsx(fa,{className:"w-4 h-4 text-gray-400"})})]})]}),p.jsxs("div",{className:"p-3 overflow-auto bg-white",style:{maxHeight:n},children:[A?w==="interactive"?p.jsx(tW,{data:g,expandedKeys:y,onToggleKey:O,keyPath:""}):p.jsx("div",{className:"font-mono text-xs text-gray-700 whitespace-pre",children:JSON.stringify(g,null,2)}):p.jsx("div",{className:"font-mono text-xs text-gray-700 whitespace-pre-wrap",children:g}),!g&&g!==0&&g!==!1&&p.jsx("div",{className:"text-center text-gray-400 text-sm py-8",children:"No data available"})]})]}),p.jsx(eW,{isOpen:c,onClose:E,title:t,data:g,initialViewMode:w,modalHeight:u})]})};function Yb({node:e,onToggle:t,isExpanded:r=!1,onNodeClick:n,selectedNodeIds:a}){const i=T.useMemo(()=>{var A,g;return((A=e.name)==null?void 0:A.toLowerCase().includes("guardrail"))||((g=e.metadata)==null?void 0:g.type)==="guardrail"?["summary","request"]:e.type==="llm"?["summary","request","response"]:e.type==="tool"?["request","response","logs"]:[]},[e.type,e.name,e.metadata]),[o,s]=T.useState(i[0]),l=a?a.has(e.id):!1,u=e.children&&e.children.length>0;T.useEffect(()=>{i.includes(o)||s(i[0])},[i,o]);const c=b=>{b.stopPropagation(),t&&t(e.id)},f=()=>{i.length===0&&u&&t?t(e.id):n&&n(e)},d=()=>{switch(e.status){case"completed":return p.jsx("svg",{className:"flex-shrink-0",width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:p.jsx("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M6 0.5C2.96243 0.5 0.5 2.96243 0.5 6C0.5 9.03757 2.96243 11.5 6 11.5C9.03757 11.5 11.5 9.03757 11.5 6C11.5 2.96243 9.03757 0.5 6 0.5ZM8.60355 4.85355C8.79882 4.65829 8.79882 4.34171 8.60355 4.14645C8.40829 3.95118 8.09171 3.95118 7.89645 4.14645L5.25 6.79289L4.10355 5.64645C3.90829 5.45118 3.59171 5.45118 3.39645 5.64645C3.20118 5.84171 3.20118 6.15829 3.39645 6.35355L4.89645 7.85355C5.09171 8.04882 5.40829 8.04882 5.60355 7.85355L8.60355 4.85355Z",fill:"#17B26A"})});case"failed":return p.jsx("div",{className:"w-[12px] h-[12px] rounded-full bg-red-500"});case"running":return p.jsx("div",{className:"w-[12px] h-[12px] rounded-full bg-yellow-500 animate-pulse"});default:return p.jsx("div",{className:"w-[12px] h-[12px] rounded-full bg-gray-400"})}},h=()=>{var A,g;let b="agent";switch(e.type){case"Agent":b="agent";break;case"llm":b="model";break;case"tool":b="workflowtool";break;default:b="agent"}return p.jsx(wi,{icon:e.icon,iconSource:b,size:"small",name:e.name,className:"w-[24px] h-[24px]",toolType:e.type==="tool"?(A=e.metadata)==null?void 0:A.type:void 0,provider:e.type==="llm"?(g=e.metadata)==null?void 0:g.provider:void 0,modelName:e.type==="llm"?e.name:void 0})},m=b=>b?b<1e3?`${b}ms`:`${(b/1e3).toFixed(2)}s`:"",y=b=>{if(!b)return"Tool";switch(b){case"route_to_user":return"Route to User";default:return b.split("_").map(A=>A.charAt(0).toUpperCase()+A.slice(1)).join(" ")}},v=()=>i,x=()=>{var g,O,S;const b=e.toolInvocations&&e.toolInvocations.length>0||e.children&&e.children.length>0,A=e.isResponse;return b?p.jsxs("div",{className:"space-y-2",children:[p.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[p.jsx("span",{className:"text-xs text-gray-600",children:A?"Responded":"Invoked"}),e.toolInvocations&&e.toolInvocations.length>0&&e.toolInvocations.map((P,E)=>p.jsxs("div",{className:"flex items-center gap-[4px] px-[8px] py-[2px] border border-gray-300 rounded-[4px] text-xs",children:[p.jsx(Vs,{className:"w-[12px] h-[12px] text-blue-500 flex-shrink-0"}),p.jsx("span",{className:"text-gray-600 truncate",children:y(P.name||P.toolName)})]},P.tool_call_id||E)),(!e.toolInvocations||e.toolInvocations.length===0)&&e.children&&e.children.length>0&&e.children.map((P,E)=>p.jsxs("div",{className:"flex items-center gap-[4px] px-[8px] py-[2px] border border-gray-300 rounded-[4px] text-xs",children:[P.type==="tool"?p.jsx(Vs,{className:"w-[12px] h-[12px] text-green-500 flex-shrink-0"}):p.jsx(b0,{className:"w-[12px] h-[12px] text-blue-500 flex-shrink-0"}),p.jsx("span",{className:"text-gray-600 truncate",children:P.name||"Unknown"})]},P.id||E))]}),((S=(O=(g=e.toolInvocations)==null?void 0:g[0])==null?void 0:O.args)==null?void 0:S.reason)&&p.jsxs("div",{children:[p.jsx("div",{className:"text-xs font-medium text-gray-400 mb-[4px]",children:"Reason"}),p.jsx("div",{className:"text-xs text-gray-600",children:e.toolInvocations[0].args.reason})]})]}):e.output&&!b?p.jsx("div",{className:"space-y-2",children:p.jsxs("div",{className:"flex items-center gap-2",children:[p.jsx("span",{className:"text-xs text-gray-600",children:"Generated"}),p.jsxs("div",{className:"flex items-center gap-[4px] px-[8px] py-[4px] border border-gray-200 rounded text-xs",children:[p.jsx(A0,{className:"w-[12px] h-[12px] text-purple-500"}),p.jsx("span",{className:"text-gray-600",children:"Response"})]})]})}):p.jsx("div",{className:"text-xs text-gray-500 italic",children:"No actions taken"})},w=()=>{switch(o){case"summary":return p.jsxs("div",{className:"space-y-2",children:[e.input&&p.jsxs("div",{className:"border-b border-gray-100 pb-[8px]",children:[p.jsx("div",{className:"text-xs font-medium text-gray-400 mb-[8px]",children:"Input"}),p.jsx(Jr,{data:e.input,title:"",showHeader:!1,maxHeight:"250px",defaultExpanded:!0,className:"border-0"})]}),p.jsxs("div",{className:"border-b border-gray-100 pb-2",children:[p.jsx("div",{className:"text-xs font-medium text-gray-400 mb-[4px]",children:"Action"}),x()]}),e.output&&p.jsxs("div",{className:"border-b border-gray-100 pb-[8px]",children:[p.jsx("div",{className:"text-xs font-medium text-gray-400 mb-[4px]",children:"Output"}),p.jsx(Jr,{data:e.output,title:"",showHeader:!1,maxHeight:"250px",defaultExpanded:!0,className:"border-0"})]}),e.llmUsage&&p.jsxs("div",{children:[p.jsx("div",{className:"text-xs font-medium text-gray-400 mb-[4px]",children:"Usage"}),p.jsxs("div",{className:"text-xs text-gray-600",children:["Input: ",e.llmUsage.input_tokens," tokens, Output: ",e.llmUsage.output_tokens," tokens, Total: ",e.llmUsage.total_tokens," tokens"]})]})]});case"request":return p.jsx(Jr,{data:e.input,title:"Request Data",maxHeight:"400px",defaultExpanded:!1,defaultViewMode:"interactive"});case"response":return p.jsx(Jr,{data:e.output,title:"Response Data",maxHeight:"400px",defaultExpanded:!1,defaultViewMode:"interactive"});case"logs":const b={executionLog:[e.startTime&&{timestamp:new Date(e.startTime).toISOString(),level:"INFO",message:`${e.type==="tool"?"Tool":"Node"} execution started`,context:{nodeId:e.id,name:e.name,type:e.type}},e.status==="completed"&&{timestamp:new Date(e.endTime||e.startTime).toISOString(),level:"INFO",message:"Response received",context:{status:e.status,duration:e.duration,llmUsage:e.llmUsage}},e.endTime&&{timestamp:new Date(e.endTime).toISOString(),level:"SUCCESS",message:`${e.type==="tool"?"Tool":"Node"} execution completed`,context:{endTime:e.endTime,totalDuration:e.duration?`${e.duration}ms`:"unknown"}}].filter(Boolean),metadata:{totalLogs:0,startTime:e.startTime,endTime:e.endTime,duration:e.duration,status:e.status}};return b.metadata.totalLogs=b.executionLog.length,p.jsx(Jr,{data:b,title:"Execution Logs",maxHeight:"400px",defaultExpanded:!0,defaultViewMode:"plain"});default:return null}};return p.jsxs("div",{className:"bg-white w-full border-t border-gray-200",children:[p.jsx("div",{className:`flex items-center py-[8px] px-[8px] relative transition-colors cursor-pointer w-full
265
- `,onClick:f,children:p.jsxs("div",{className:"flex items-center gap-[6px] w-full",children:[p.jsx("div",{className:"p-[2px] rounded hover:bg-gray-200 cursor-pointer flex-shrink-0 bg-white z-[2]",onClick:b=>{b.stopPropagation(),u?c(b):n&&n(e)},title:u?r?"Collapse":"Expand":"Show details",children:p.jsx(ki,{className:`w-[12px] h-[12px] text-gray-600 transition-transform ${u&&r||l&&i.length>0?"rotate-90":""}`})}),p.jsx("div",{className:"flex-shrink-0",children:h()}),p.jsx("span",{className:"font-semibold text-gray-900 text-xs truncate w-full",children:e.name}),p.jsxs("div",{className:"flex items-center gap-[12px] text-[10px] text-gray-500",children:[e.duration&&p.jsxs("div",{className:"flex items-center gap-[4px]",children:[p.jsx(Tf,{className:"w-[12px] h-[12px]"}),p.jsx("span",{className:"text-[10px] text-gray-500 whitespace-nowrap",children:m(e.duration)})]}),e.llmUsage&&p.jsxs("span",{className:"text-[10px] text-gray-500 whitespace-nowrap",children:[e.llmUsage.total_tokens," Tokens"]})]}),p.jsx("div",{className:"flex-shrink-0",children:d()})]})}),l&&i.length>0&&p.jsxs("div",{className:"w-full pl-[32px] relative",children:[p.jsx("div",{className:"absolute top-[-40px] left-[16px] w-[1px] border-l border-dashed border-gray-200 h-[calc(100%+40px)] z-[1]"}),p.jsxs("div",{className:"px-[4px] py-[8px] w-full border-t border-gray-200",children:[p.jsx("div",{className:"bg-gray-50 rounded-[4px] p-[4px] inline-flex gap-[4px] mb-[8px] border border-gray-200",children:v().map(b=>p.jsx("button",{onClick:()=>s(b),className:`px-[8px] py-[4px] text-xs font-medium rounded-[4px] text-gray-500 hover:text-gray-700 hover:shadow-tab hover:bg-white transition-colors ${o===b?"bg-white text-gray-900 shadow-tab":"text-gray-500 hover:text-gray-700 hover:bg-white"}`,children:b.charAt(0).toUpperCase()+b.slice(1)},b))}),p.jsx("div",{className:"px-[4px]",children:w()})]})]}),r&&u&&p.jsxs("div",{className:"w-full pl-[32px] relative",children:[p.jsx("div",{className:"absolute top-[-40px] left-[16px] w-[1px] border-l border-dashed border-gray-200 h-[calc(100%+40px)] z-[1]"}),e.children.map(b=>p.jsx(Yb,{node:b,onToggle:t,isExpanded:b.isExpanded,onNodeClick:n,selectedNodeIds:a},b.id))]})]})}const Xb=T.forwardRef(({executionEvents:e,sessionId:t,onNodeExpand:r,onNodeCollapse:n,className:a=""},i)=>{const[o,s]=T.useState(new Set),[l,u]=T.useState(new Set),[c,f]=T.useState(new Set),[d,h]=T.useState(e),m=T.useRef(e.length);T.useEffect(()=>{h(e),e.length===0?(s(new Set),u(new Set),f(new Set),x.current=!1,m.current=0):(e.length>m.current&&(x.current=!0),m.current=e.length)},[e]);const y=T.useRef(0),v=T.useRef(null),x=T.useRef(!1);T.useImperativeHandle(i,()=>({addEvent:k=>{h(_=>[..._,k]),x.current=!0},addEvents:k=>{h(_=>[..._,...k]),x.current=!0},clearEvents:()=>{h([]),s(new Set),u(new Set),f(new Set),x.current=!1}}),[]);const w=T.useMemo(()=>{const k=Kb.buildSessionTree(d,t);return v.current=k,k},[d,t]),b=T.useRef(null);T.useEffect(()=>{d.length>y.current&&b.current&&setTimeout(()=>{b.current&&b.current.scrollTo({top:b.current.scrollHeight,behavior:"smooth"})},100),y.current=d.length},[d.length]),T.useEffect(()=>{if(d.length>0&&w.runs.length>0){if(x.current){const _=$(w);s(new Set(_)),x.current=!1}f(_=>{const D=new Set(_);return w.runs.forEach(M=>{D.has(M.runId)||D.add(M.runId)}),D});const k=w.runs[w.runs.length-1];if(k.rootNodes.length>0){const _=k.rootNodes[k.rootNodes.length-1],D=j(_);D&&u(M=>{const B=new Set(M);return B.add(D.id),B})}}},[w]);const A=T.useCallback(k=>{s(_=>{const D=new Set(_);return D.has(k)?(D.delete(k),n==null||n(k)):(D.add(k),r==null||r(k)),D})},[r,n]),g=T.useCallback(k=>{u(_=>{const D=new Set(_);return D.has(k.id)?D.delete(k.id):D.add(k.id),D})},[]),O=T.useCallback(k=>{f(_=>{const D=new Set(_);return D.has(k)?D.delete(k):D.add(k),D})},[]),S=T.useCallback(k=>({...k,isExpanded:o.has(k.id),children:k.children.map(D=>S(D))}),[o]),P=k=>k?k<1e3?`${k}ms`:`${(k/1e3).toFixed(2)}s`:"",E=k=>k?k>=1e6?`${(k/1e6).toFixed(1)}M tokens`:k>=1e3?`${(k/1e3).toFixed(1)}K tokens`:`${k} tokens`:"",N=async k=>{try{if(navigator.clipboard&&navigator.clipboard.writeText){await navigator.clipboard.writeText(k);return}const _=document.createElement("textarea");_.value=k,_.style.position="fixed",_.style.left="-999999px",_.style.top="-999999px",document.body.appendChild(_),_.focus(),_.select();try{document.execCommand("copy")}catch(D){console.warn("Copy to clipboard failed:",D)}finally{document.body.removeChild(_)}}catch(_){console.warn("Copy to clipboard failed:",_)}},j=k=>k.children.length===0?k:j(k.children[k.children.length-1]),$=k=>{const _=[],D=M=>{_.push(M.id),M.children.forEach(B=>D(B))};return k.runs.forEach(M=>{M.rootNodes.forEach(B=>D(B))}),_};return w.runs.length?p.jsx("div",{className:`flex flex-col h-full bg-white ${a}`,children:p.jsxs("div",{className:"flex flex-col gap-[16px] p-[24px] overflow-y-auto overflow-x-hidden",ref:b,children:[p.jsxs("div",{className:"flex items-center w-full gap-[16px]",children:[p.jsx("div",{className:"text-xs text-gray-400 whitespace-nowrap flex-shrink-0",children:"Session initiated"}),p.jsx("div",{className:"flex-1 h-[1px] border-t border-dashed border-gray-300 w-full"}),p.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-400 flex-shrink-0",children:[p.jsx("span",{children:w.sessionId}),p.jsx("button",{className:"p-[4px] hover:bg-gray-100 rounded transition-colors",onClick:()=>N(w.sessionId),title:"Copy session ID",children:p.jsx(fa,{className:"w-[12px] h-[12px]"})}),p.jsx("button",{className:"p-[4px] hover:bg-gray-100 rounded transition-colors",title:"Open in external viewer",children:p.jsx(Af,{className:"w-[12px] h-[12px]"})})]})]}),w.runs.map(k=>p.jsxs("div",{className:"flex flex-col gap-1",children:[p.jsxs("div",{className:"rounded-[8px] border border-gray-300 bg-white overflow-hidden",children:[p.jsx("div",{className:"flex flex-col w-full",children:p.jsxs("div",{className:"flex items-center gap-2 p-[8px] bg-gray-50 cursor-pointer select-none",onClick:()=>O(k.runId),title:c.has(k.runId)?"Collapse run":"Expand run",children:[p.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",className:"flex-shrink-0",children:p.jsx("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M10.8277 1.33398C11.3643 1.33398 11.8072 1.33396 12.168 1.36343C12.5428 1.39405 12.8872 1.45978 13.2108 1.62463C13.7125 1.8803 14.1205 2.28825 14.3762 2.79001C14.541 3.11356 14.6067 3.45803 14.6374 3.83276C14.6668 4.19356 14.6668 4.63646 14.6668 5.1731V9.0235C14.6668 9.47003 14.6668 9.83861 14.6462 10.1404C14.6249 10.4532 14.5792 10.7426 14.4638 11.0211C14.1932 11.6746 13.674 12.1937 13.0206 12.4643C12.7421 12.5797 12.4527 12.6254 12.1399 12.6467C11.8381 12.6673 11.4695 12.6673 11.023 12.6673H11.0002C10.6424 12.6673 10.5714 12.6715 10.5136 12.6852C10.4129 12.7089 10.3191 12.7558 10.2397 12.8221C10.1941 12.8602 10.1481 12.9145 9.9335 13.2007L8.94888 14.5135C8.88665 14.5965 8.81628 14.6904 8.74857 14.7657C8.6739 14.8487 8.54979 14.971 8.36264 15.0438C8.1295 15.1344 7.87083 15.1344 7.6377 15.0438C7.45054 14.971 7.32641 14.8487 7.25174 14.7657C7.18403 14.6904 7.11368 14.5965 7.05145 14.5135L6.06683 13.2007C5.85221 12.9145 5.80624 12.8602 5.76065 12.8221C5.68119 12.7558 5.58739 12.7089 5.48666 12.6852C5.42887 12.6715 5.35786 12.6673 5.00015 12.6673H4.9773C4.53078 12.6673 4.16221 12.6673 3.86047 12.6467C3.54762 12.6254 3.25822 12.5797 2.97968 12.4643C2.32627 12.1937 1.80712 11.6746 1.53647 11.0211C1.42109 10.7426 1.37541 10.4532 1.35407 10.1404C1.33348 9.83861 1.33349 9.47003 1.3335 9.0235V5.17313C1.33349 4.63648 1.33347 4.19356 1.36295 3.83276C1.39356 3.45803 1.45929 3.11356 1.62415 2.79001C1.87981 2.28825 2.28776 1.8803 2.78952 1.62463C3.11308 1.45978 3.45755 1.39405 3.83228 1.36343C4.19307 1.33396 4.63599 1.33398 5.17264 1.33398H10.8277ZM10.4715 4.52924C10.2112 4.2689 9.78906 4.26889 9.52872 4.52924L6.66681 7.39114V5.6673C6.6668 5.29912 6.36834 5.00064 6.00015 5.00064C5.63197 5.00064 5.33351 5.29912 5.3335 5.6673V9.00064C5.3335 9.17745 5.40373 9.34702 5.52875 9.47205C5.65377 9.59707 5.82334 9.6673 6.00015 9.6673H9.3335L9.35068 9.66708C9.71092 9.65796 10.0002 9.36308 10.0002 9.00064C10.0001 8.63821 9.71092 8.34332 9.35068 8.3342L9.3335 8.33398H7.60962L10.4715 5.47205C10.7319 5.2117 10.7319 4.78958 10.4715 4.52924Z",fill:"#079455"})}),p.jsx("span",{className:"flex-1 text-xs text-gray-900 truncate",children:k.userInput||`Run ${k.runId}`}),p.jsx(cr,{className:`w-[16px] h-[16px] text-gray-400 flex-shrink-0 transition-transform ${c.has(k.runId)?"rotate-180":""}`})]})}),c.has(k.runId)&&p.jsx("div",{className:"bg-white w-full flex flex-col",children:k.rootNodes&&k.rootNodes.map(_=>p.jsx("div",{className:"w-full",children:p.jsx(Yb,{node:S(_),onToggle:A,isExpanded:o.has(_.id),onNodeClick:g,selectedNodeIds:l})},_.id))}),k.finalOutput&&p.jsxs("div",{className:"p-[8px] bg-gray-50 flex items-center gap-[8px] w-full border-t border-gray-200",children:[p.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",className:"flex-shrink-0",children:p.jsx("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M10.8277 1.33398C11.3643 1.33398 11.8072 1.33396 12.168 1.36343C12.5428 1.39405 12.8872 1.45978 13.2108 1.62463C13.7125 1.8803 14.1205 2.28825 14.3762 2.79001C14.541 3.11356 14.6067 3.45803 14.6374 3.83276C14.6668 4.19356 14.6668 4.63646 14.6668 5.1731V9.0235C14.6668 9.47003 14.6668 9.83861 14.6462 10.1404C14.6249 10.4532 14.5792 10.7426 14.4638 11.0211C14.1932 11.6746 13.674 12.1937 13.0206 12.4643C12.7421 12.5797 12.4527 12.6254 12.1399 12.6467C11.8381 12.6673 11.4695 12.6673 11.023 12.6673H11.0002C10.6424 12.6673 10.5714 12.6715 10.5136 12.6852C10.4129 12.7089 10.3191 12.7558 10.2397 12.8221C10.1941 12.8602 10.1481 12.9145 9.9335 13.2007L8.94888 14.5135C8.88665 14.5965 8.81628 14.6904 8.74857 14.7657C8.6739 14.8487 8.54979 14.971 8.36264 15.0438C8.1295 15.1344 7.87083 15.1344 7.6377 15.0438C7.45054 14.971 7.32641 14.8487 7.25174 14.7657C7.18403 14.6904 7.11368 14.5965 7.05145 14.5135L6.06683 13.2007C5.85221 12.9145 5.80624 12.8602 5.76065 12.8221C5.68119 12.7558 5.58739 12.7089 5.48666 12.6852C5.42887 12.6715 5.35786 12.6673 5.00015 12.6673H4.9773C4.53078 12.6673 4.16221 12.6673 3.86047 12.6467C3.54762 12.6254 3.25822 12.5797 2.97968 12.4643C2.32627 12.1937 1.80712 11.6746 1.53647 11.0211C1.42109 10.7426 1.37541 10.4532 1.35407 10.1404C1.33348 9.83861 1.33349 9.47003 1.3335 9.0235V5.17313C1.33349 4.63648 1.33347 4.19356 1.36295 3.83276C1.39356 3.45803 1.45929 3.11356 1.62415 2.79001C1.87981 2.28825 2.28776 1.8803 2.78952 1.62463C3.11308 1.45978 3.45755 1.39405 3.83228 1.36343C4.19307 1.33396 4.63599 1.33398 5.17264 1.33398H10.8277ZM6.66653 4.33398C6.29835 4.334 5.99988 4.63246 5.99988 5.00064C5.99988 5.36882 6.29835 5.66729 6.66653 5.6673H8.39041L5.52847 8.52924C5.26813 8.78958 5.26813 9.2117 5.52847 9.47205C5.78882 9.73239 6.21093 9.73239 6.47128 9.47205L9.33322 6.61011V8.33398C9.33323 8.70217 9.6317 9.00064 9.99988 9.00064C10.3681 9.00064 10.6665 8.70217 10.6665 8.33398V5.00064C10.6665 4.63821 10.3773 4.34333 10.0171 4.3342L9.99988 4.33398H6.66653Z",fill:"#155EEF"})}),p.jsx("span",{className:"flex-1 text-xs text-gray-900 truncate",title:k.finalOutput,children:k.finalOutput}),p.jsxs("div",{className:"flex items-center gap-[8px] flex-shrink-0",children:[k.duration&&p.jsxs("div",{className:"flex items-center gap-[4px]",children:[p.jsx(Tf,{className:"w-[12px] h-[12px] text-gray-400"}),p.jsx("span",{className:"text-[10px] text-gray-500 whitespace-nowrap",children:P(k.duration)})]}),k.totalTokens&&p.jsx("span",{className:"text-[10px] text-gray-500 whitespace-nowrap",children:E(k.totalTokens)}),k.status==="running"&&p.jsx("span",{className:"text-[10px] text-gray-500",children:"In progress"})]})]})]}),p.jsxs("div",{className:"flex items-center justify-end gap-2 py-1",children:[p.jsx("span",{className:"text-xs text-gray-400",children:k.runId}),p.jsxs("div",{className:"flex items-center gap-2",children:[p.jsx("button",{className:"p-1 hover:bg-gray-100 rounded transition-colors",onClick:()=>N(k.runId),title:"Copy run ID",children:p.jsx(fa,{className:"w-3 h-3 text-gray-400"})}),p.jsx("button",{className:"p-1 hover:bg-gray-100 rounded transition-colors",title:"Open run in external viewer",children:p.jsx(Af,{className:"w-3 h-3 text-gray-400"})})]})]})]},k.runId))]})}):p.jsx("div",{className:`flex flex-col h-full ${a}`,children:p.jsx("div",{className:"flex items-center justify-center h-full",children:p.jsx("p",{className:"text-gray-500 text-sm",children:"No execution events to display"})})})});Xb.displayName="DebugPanel";const Jb=({value:e,onChange:t,language:r="text",readOnly:n=!1,placeholder:a="",className:i,autoFocus:o=!1})=>{const[s,l]=T.useState(e),[u,c]=T.useState(!1),[f,d]=T.useState(!1),h=T.useRef(null);T.useEffect(()=>{l(e)},[e]);function m(){navigator.clipboard.writeText(s).then(()=>{d(!0),setTimeout(()=>d(!1),1500)})}function y(b){const A=b.target.value;l(A),t==null||t(A)}const v=()=>p.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b bg-gray-100",children:[p.jsx("span",{className:"text-xs font-mono uppercase text-gray-500",children:r}),p.jsxs("div",{className:"flex items-center gap-2",children:[p.jsx("button",{type:"button",className:"p-1 rounded hover:bg-gray-200",onClick:m,title:f?"Copied!":"Copy",children:p.jsx(fa,{size:16,className:f?"text-green-500":""})}),p.jsx("button",{type:"button",className:"p-1 rounded hover:bg-gray-200",onClick:()=>c(!u),title:u?"Minimize":"Maximize",children:u?p.jsx(S0,{size:16}):p.jsx(jf,{size:16})})]})]}),x=()=>p.jsx("textarea",{ref:h,spellCheck:!1,readOnly:n,placeholder:a,autoFocus:o,className:"flex-1 w-full h-full resize-none p-3 font-mono text-sm outline-none bg-transparent",value:s,onChange:y}),w=p.jsxs("div",{className:se("flex flex-col h-full w-full border rounded-md bg-background",i),style:{minHeight:"200px"},children:[p.jsx(v,{}),p.jsx(x,{})]});return u?p.jsx(hf,{children:p.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4",children:p.jsx("div",{className:"w-full h-full max-h-[calc(100vh-2rem)]",children:w})})}):w};Jb.displayName="CodeEditor";const Zb=T.forwardRef(({className:e,...t},r)=>p.jsx("span",{ref:r,className:se("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",e),...t}));Zb.displayName="Avatar";const Qb=T.forwardRef(({className:e,...t},r)=>p.jsx("img",{ref:r,className:se("aspect-square h-full w-full",e),...t}));Qb.displayName="AvatarImage";const e0=T.forwardRef(({className:e,...t},r)=>p.jsx("span",{ref:r,className:se("flex h-full w-full items-center justify-center rounded-full bg-muted",e),...t}));e0.displayName="AvatarFallback";const t0=T.forwardRef(({className:e,children:t,...r},n)=>p.jsx("div",{ref:n,className:se("rounded-lg border bg-card text-card-foreground shadow-sm",e),...r,children:t}));t0.displayName="Card";const rW=T.forwardRef(({className:e,children:t,...r},n)=>p.jsx("div",{ref:n,className:se("flex flex-col space-y-1.5 p-6",e),...r,children:t}));rW.displayName="CardHeader";const nW=T.forwardRef(({className:e,children:t,...r},n)=>p.jsx("h3",{ref:n,className:se("text-2xl font-semibold leading-none tracking-tight",e),...r,children:t}));nW.displayName="CardTitle";const aW=T.forwardRef(({className:e,children:t,...r},n)=>p.jsx("div",{ref:n,className:se("p-6 pt-0",e),...r,children:t}));aW.displayName="CardContent";const Bs=["Portfolio Analysis Expert","Mortgage Evaluator","Credit Risk Specialist","Asset Valuation Analyst","Liability Assessment Advisor"],Fs=["calculate-creditScore","calculate-risk","calculate-mortgage","analyse-expenses","fetch-statement"],Ws=["gpt-4o","gpt-4o-mini","gpt-3.5-turbo","claude-3-5-sonnet","claude-3-5-haiku","claude-3-opus","gemini-1.5-pro","gemini-1.5-flash","llama-3.1-405b","llama-3.1-70b"],iW=(e=30)=>{const t=[],r=new Date;for(let n=e-1;n>=0;n--){const a=new Date(r);a.setDate(r.getDate()-n);const i=600+Math.sin(n*.1)*100,o=Math.floor(i+Math.random()*100),s=Math.floor(o*3.5+Math.random()*200),l=Math.floor(s*2.9+Math.random()*500),u=Math.floor(l*.9+Math.random()*300),c=Math.floor(u*.6),f=u-c,d=Math.floor(s*.8+Math.random()*100),h=Math.floor(d*12+Math.random()*500),m=Math.floor(d*8+Math.random()*300),y=Math.floor(h*.3+Math.random()*100),v=Math.floor(h*.25+Math.random()*80),x=Math.floor(h*.2+Math.random()*60),w=Math.floor(h*.15+Math.random()*50),b={};Bs.forEach(O=>{const S=O.replace(/\s+/g,"").toLowerCase(),P=Math.floor(d/Bs.length);b[S]=Math.floor(P+Math.random()*(P*.5))});const A={};Fs.forEach(O=>{const S=O.replace(/[-]/g,""),P=Math.floor(h/Fs.length);A[S]=Math.floor(P+Math.random()*(P*.8))});const g={};Ws.forEach(O=>{const S=O.replace(/[-\.]/g,""),P=Math.floor(m/Ws.length);g[S]=Math.floor(P+Math.random()*(P*.6))}),t.push({date:a.toISOString().split("T")[0],users:o,sessions:s,messages:l,totalTokens:u,inputTokens:c,outputTokens:f,agentRuns:d,toolRuns:h,modelRuns:m,codeTools:y,workflowTools:v,knowledgeTools:x,mcpTools:w,...b,...A,...g,value:o})}return t},oW=()=>{const e=[],t=['{"name":"avatar14","color":"#F6D0FE","type":"human"}','{"name":"avatar2","color":"#3B82F6","type":"human"}','{"name":"avatar7","color":"#EF4444","type":"human"}','{"name":"avatar12","color":"#10B981","type":"human"}','{"name":"avatar8","color":"#F59E0B","type":"human"}'];return Bs.forEach((r,n)=>{e.push({id:`agent-${n+1}`,name:r,runs:Math.floor(Math.random()*8e3)+4e3,responseTime:`${Math.floor(Math.random()*120)+15}s`,tokens:Math.floor(Math.random()*4e5)+1e5,successRate:`${Math.floor(Math.random()*20)+80}%`,lastRun:new Date(Date.now()-Math.random()*7*24*60*60*1e3).toLocaleDateString(),avatar:`https://api.dicebear.com/7.x/avataaars/svg?seed=${r.replace(/\s+/g,"")}&backgroundColor=b6e3f4,c0aede,d1d4f9&backgroundType=solid`,icon:t[n]||t[0]})}),e},sW=()=>{const e=r=>r.includes("calculate-creditscore")?"Code Tool":r.includes("calculate-risk")?"Workflow Tool":r.includes("calculate-mortgage")?"MCP Tool":r.includes("analyse-expenses")?"Workflow Tool":r.includes("fetch-statement")?"Knowledge":"Code Tool",t=['{"name":"calculator","color":"#EF6820","type":"inlineTool"}','{"name":"workflow","color":"#155EEF","type":"toolLibrary"}','{"name":"mcptool","color":"#101828","type":"MCP"}','{"name":"expenses","color":"#155EEF","type":"toolLibrary"}','{"name":"knowledge","color":"#7A5AF8","type":"KNOWLEDGE"}'];return Fs.map((r,n)=>({id:`tool-${n+1}`,name:r,type:e(r),runs:Math.floor(Math.random()*8e3)+4e3,responseTime:`${Math.floor(Math.random()*90)+15}s`,tokens:Math.floor(Math.random()*2e4)+5e3,successRate:`${Math.floor(Math.random()*15)+85}%`,lastRun:new Date(Date.now()-Math.random()*7*24*60*60*1e3).toLocaleDateString(),icon:t[n]||t[0]}))},lW=()=>Ws.map((e,t)=>({id:`model-${t+1}`,name:e,runs:Math.floor(Math.random()*8e3)+4e3,responseTime:`${Math.floor(Math.random()*120)+15}s`,tokens:Math.floor(Math.random()*5e5)+1e5,successRate:`${Math.floor(Math.random()*15)+85}%`,lastRun:new Date(Date.now()-Math.random()*7*24*60*60*1e3).toLocaleDateString()})),Zr=iW(),uW=oW(),cW=sW(),fW=lW(),dW={id:"main-dashboard",title:"Dashboard",subtitle:"Monitor and review the usage of your agentic app.",version:"1.0.0",globalControls:{draft:{label:"Draft",options:[{label:"Current Draft",value:"current"},{label:"Previous Draft",value:"previous"},{label:"All Drafts",value:"all"}],defaultValue:"current"},timeRange:{label:"Time Range",options:[{label:"This month",value:"month"},{label:"Last 7 days",value:"week"},{label:"Last 30 days",value:"30days"},{label:"Last 90 days",value:"90days"}],defaultValue:"month"},export:{enabled:!0,formats:["csv","json","pdf"]}},layout:{columns:12,gap:24,responsive:!0},sections:[{id:"sessions",title:"Sessions",description:"User engagement and session analytics",metrics:[{title:"Users",value:3384,change:{value:6,type:"increase"},info:"Total number of unique users",metricType:"users",view:{type:"chart",chart:{type:"line",title:"Total Users",data:Zr,dataKey:"users",color:"#8b5cf6",yAxisLabel:"Number of Users",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}}}},{title:"Sessions",value:11847,change:{value:18,type:"increase"},info:"Total number of user sessions",metricType:"sessions",view:{type:"chart",chart:{type:"line",title:"Total Sessions",data:Zr,dataKey:"sessions",color:"#06b6d4",yAxisLabel:"Number of Sessions",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}}}},{title:"Messages",value:34563,change:{value:5,type:"increase"},info:"Total messages exchanged",metricType:"messages",view:{type:"chart",chart:{type:"line",title:"Total Messages",data:Zr,dataKey:"messages",color:"#e879f9",yAxisLabel:"Number of Messages",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}}}},{title:"Tokens",value:32044,change:{value:44,type:"increase"},info:"Total tokens processed",metricType:"tokens",view:{type:"chart",chart:{type:"line",title:"Token Usage Breakdown",data:Zr,yAxisLabel:"Number of Tokens",lines:[{dataKey:"totalTokens",color:"#f97316",label:"Total Tokens"},{dataKey:"inputTokens",color:"#3b82f6",label:"Input Tokens"},{dataKey:"outputTokens",color:"#e879f9",label:"Output Tokens"}],height:300,showGrid:!0,showLegend:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}}}}],view:{type:"chart"},layout:{span:12,order:1}},{id:"runs",title:"Runs",description:"Agent, tool, and model execution analytics",metrics:[{title:"Agent Runs",value:3384,change:{value:6,type:"increase"},info:"Number of agent executions",metricType:"agentRuns",view:{type:"chart",chart:{type:"line",title:"Agent Runs",data:Zr,dataKey:"agentRuns",color:"#06b6d4",yAxisLabel:"Number of Agent Runs",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}},table:{title:"Agent Runs",data:uW,columns:[{key:"name",title:"Name",width:200,align:"left"},{key:"runs",title:"Runs",width:100,align:"right",formatter:e=>`${Math.floor(e/1e3)}k`},{key:"responseTime",title:"Response Time",width:120,align:"right"},{key:"tokens",title:"Tokens",width:100,align:"right",formatter:e=>`${Math.floor(e/1e3)}k`}]}},controls:{dropdown:{label:"All Agents",options:[{label:"All Agents",value:"all"},...Bs.map(e=>({label:e,value:e.replace(/\s+/g,"").toLowerCase(),avatar:`https://api.dicebear.com/7.x/avataaars/svg?seed=${e.replace(/\s+/g,"")}&backgroundColor=b6e3f4,c0aede,d1d4f9&backgroundType=solid`}))],defaultValue:["all"],multiSelect:!0,searchable:!0},toggle:{chartView:!0,tableView:!0}}},{title:"Tool Runs",value:34563,change:{value:5,type:"increase"},info:"Number of tool executions",metricType:"toolRuns",view:{type:"chart",chart:{type:"line",title:"Tool Runs",data:Zr,yAxisLabel:"Number of Tool Runs",lines:[{dataKey:"toolRuns",color:"#06b6d4",label:"Tool Runs"},{dataKey:"codeTools",color:"#f97316",label:"Code Tools"},{dataKey:"workflowTools",color:"#10b981",label:"Workflow Tools"},{dataKey:"knowledgeTools",color:"#8b5cf6",label:"Knowledge"},{dataKey:"mcpTools",color:"#ef4444",label:"MCP Tools"}],height:300,showGrid:!0,showLegend:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}},table:{title:"Tool Runs",data:cW,columns:[{key:"name",title:"Name",width:200,align:"left"},{key:"type",title:"Type",width:150,align:"left"},{key:"runs",title:"Runs",width:100,align:"right",formatter:e=>`${Math.floor(e/1e3)}k`},{key:"responseTime",title:"Response Time",width:120,align:"right"}]}},controls:{dropdown:{label:"All Tools",options:[{label:"All Tools",value:"all"},...Fs.map((e,t)=>{const r=['{"name":"calculator","color":"#EF6820","type":"inlineTool"}','{"name":"workflow","color":"#155EEF","type":"toolLibrary"}','{"name":"mcptool","color":"#101828","type":"MCP"}','{"name":"expenses","color":"#155EEF","type":"toolLibrary"}','{"name":"knowledge","color":"#7A5AF8","type":"KNOWLEDGE"}'],n=a=>a.includes("calculate-creditscore")?"Code Tool":a.includes("calculate-risk")?"Workflow Tool":a.includes("calculate-mortgage")?"MCP Tool":a.includes("analyse-expenses")?"Workflow Tool":a.includes("fetch-statement")?"Knowledge":"Code Tool";return{label:e,value:e.replace(/[-]/g,""),icon:r[t]||r[0],type:n(e)}})],defaultValue:["all"],multiSelect:!0,searchable:!0},toggle:{chartView:!0,tableView:!0}}},{title:"Model Runs",value:32044,change:{value:44,type:"increase"},info:"Number of model inferences",metricType:"modelRuns",view:{type:"chart",chart:{type:"line",title:"Model Runs",data:Zr,dataKey:"modelRuns",color:"#10b981",yAxisLabel:"Number of Model Runs",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}},table:{title:"Model Runs",data:fW,columns:[{key:"name",title:"Model Name",width:200,align:"left"},{key:"runs",title:"Runs",width:100,align:"right",formatter:e=>`${Math.floor(e/1e3)}k`},{key:"tokens",title:"Tokens",width:120,align:"right",formatter:e=>`${Math.floor(e/1e3)}k`},{key:"responseTime",title:"Response Time",width:120,align:"right"}]}},controls:{dropdown:{label:"All Models",options:[{label:"All Models",value:"all"},...Ws.map(e=>{const t=r=>{const n=r.toLowerCase();return n.includes("gpt")||n.includes("openai")?"⚡":n.includes("claude")||n.includes("anthropic")?"A":n.includes("gemini")||n.includes("google")?"G":n.includes("llama")||n.includes("meta")?"M":"🤖"};return{label:e,value:e.replace(/[-\.]/g,""),icon:t(e)}})],defaultValue:["all"],multiSelect:!0,searchable:!0},toggle:{chartView:!0,tableView:!0}}}],view:{type:"chart"},layout:{span:12,order:2}}]},Yt={primary:["#8b5cf6","#06b6d4","#f97316","#10b981","#ec4899","#f59e0b","#3b82f6","#ef4444"],secondary:["#a78bfa","#22d3ee","#fb923c","#34d399","#f472b6","#fbbf24","#60a5fa","#f87171"],accent:["#6366f1","#8b5cf6","#d946ef","#06b6d4","#84cc16","#eab308"],semantic:{success:"#10b981",warning:"#f59e0b",error:"#ef4444",info:"#3b82f6"},gradients:{purple:["#8b5cf6","#a78bfa"],cyan:["#06b6d4","#22d3ee"],orange:["#f97316","#fb923c"],green:["#10b981","#34d399"],sunset:["#f97316","#ec4899"],ocean:["#06b6d4","#3b82f6"],forest:["#10b981","#84cc16"]}},pW={primary:["#7c3aed","#0891b2","#ea580c","#059669","#db2777","#d97706","#2563eb","#dc2626"],secondary:["#8b5cf6","#06b6d4","#f97316","#10b981","#ec4899","#f59e0b","#3b82f6","#ef4444"],accent:["#4f46e5","#7c3aed","#c026d3","#0891b2","#65a30d","#ca8a04"],semantic:{success:"#059669",warning:"#d97706",error:"#dc2626",info:"#2563eb"}},hW={primary:["#a78bfa","#22d3ee","#fb923c","#34d399","#f472b6","#fbbf24","#60a5fa","#f87171"],secondary:["#c4b5fd","#67e8f9","#fdba74","#6ee7b7","#f9a8d4","#fcd34d","#93c5fd","#fca5a5"],accent:["#818cf8","#a78bfa","#e879f9","#22d3ee","#a3e635","#facc15"],semantic:{success:"#34d399",warning:"#fbbf24",error:"#f87171",info:"#60a5fa"}},mW={primary:["#1f2937","#374151","#6b7280","#9ca3af","#3b82f6","#1d4ed8","#10b981","#f59e0b"],secondary:["#4b5563","#6b7280","#9ca3af","#d1d5db","#60a5fa","#3b82f6","#34d399","#fbbf24"],accent:["#2563eb","#1d4ed8","#059669","#0891b2","#d97706","#b45309"],semantic:{success:"#059669",warning:"#d97706",error:"#dc2626",info:"#1d4ed8"}},r0=(e,t)=>e.primary[t%e.primary.length],Pi=(e,t)=>e.semantic[t],vW=(e,t)=>{var r;return((r=e.gradients)==null?void 0:r[t])||[e.primary[0],e.primary[1]]},n0=(e,t=Yt)=>e.map((r,n)=>({...r,color:r0(t,n)})),Us=((e=30)=>{const t=[],r=new Date;for(let n=e-1;n>=0;n--){const a=new Date(r);a.setDate(r.getDate()-n);const i=600+Math.sin(n*.1)*100,o=Math.floor(i+Math.random()*100),s=Math.floor(o*3.5+Math.random()*200),l=Math.floor(s*2.9+Math.random()*500),u=Math.floor(l*.9+Math.random()*300),c=Math.floor(u*.6),f=u-c,d=Math.floor(s*.8+Math.random()*100),h=Math.floor(d*12+Math.random()*500),m=Math.floor(d*8+Math.random()*300);t.push({date:a.toISOString().split("T")[0],users:o,sessions:s,messages:l,totalTokens:u,inputTokens:c,outputTokens:f,agentRuns:d,toolRuns:h,modelRuns:m,value:o})}return t})(),yW={id:"enhanced-dashboard",title:"Enhanced Color Configuration Dashboard",subtitle:"Demonstrating all color configuration options",version:"1.0.0",globalControls:{draft:{label:"Draft",options:[{label:"Current Draft",value:"current"},{label:"Previous Draft",value:"previous"}],defaultValue:"current"},timeRange:{label:"Time Range",options:[{label:"Last 7 days",value:"week"},{label:"Last 30 days",value:"30days"}],defaultValue:"30days"},export:{enabled:!0,formats:["csv","json"]}},layout:{columns:12,gap:24,responsive:!0},sections:[{id:"manual-colors",title:"Manual Color Assignment",description:"Each line has manually assigned colors",metrics:[{title:"Total Users",value:3384,change:{value:6,type:"increase"},info:"Manually colored chart"}],view:{type:"chart",chart:{type:"line",title:"Manual Color Configuration",data:Us,lines:[{dataKey:"users",color:"#8b5cf6",label:"Users",strokeWidth:3},{dataKey:"sessions",color:"#06b6d4",label:"Sessions",strokeWidth:2},{dataKey:"messages",color:"#f97316",label:"Messages",strokeWidth:2,strokeDasharray:"5 5"}],dateRange:{start:"2025-05-06",end:"2025-06-05"},tooltip:{show:!0,style:"dark"},height:300,showLegend:!1}},layout:{span:6,order:1}},{id:"auto-colors",title:"Auto-Assigned Colors",description:"Colors automatically assigned from palette",metrics:[{title:"Agent Runs",value:3384,change:{value:6,type:"increase"},info:"Auto-colored from palette"}],view:{type:"chart",chart:{type:"line",title:"Auto Color Assignment",data:Us,lines:n0([{dataKey:"agentRuns",label:"Agent Runs"},{dataKey:"toolRuns",label:"Tool Runs"},{dataKey:"modelRuns",label:"Model Runs"},{dataKey:"totalTokens",label:"Total Tokens"}],Yt),dateRange:{start:"2025-05-06",end:"2025-06-05"},tooltip:{show:!0,style:"dark"},height:300,showLegend:!1}},layout:{span:6,order:2}},{id:"semantic-colors",title:"Semantic Colors",description:"Using semantic colors for different data types",metrics:[{title:"Success Rate",value:"94.2%",change:{value:2,type:"increase"},info:"Using semantic success color"},{title:"Error Rate",value:"5.8%",change:{value:1,type:"decrease"},info:"Using semantic error color"}],view:{type:"chart",chart:{type:"line",title:"Semantic Color Usage",data:Us,lines:[{dataKey:"users",color:Pi(Yt,"success"),label:"Successful Operations",strokeWidth:3},{dataKey:"sessions",color:Pi(Yt,"warning"),label:"Warning Events",strokeWidth:2},{dataKey:"messages",color:Pi(Yt,"error"),label:"Error Events",strokeWidth:2},{dataKey:"totalTokens",color:Pi(Yt,"info"),label:"Info Events",strokeWidth:2}],dateRange:{start:"2025-05-06",end:"2025-06-05"},tooltip:{show:!0,style:"dark"},height:300,showLegend:!1}},layout:{span:12,order:3}},{id:"single-custom",title:"Single Line Custom Color",description:"Single line chart with custom color and styling",metrics:[{title:"Total Messages",value:34563,change:{value:5,type:"increase"},info:"Custom styled single line"}],view:{type:"chart",chart:{type:"line",title:"Custom Single Line",data:Us,dataKey:"messages",color:"#ec4899",dateRange:{start:"2025-05-06",end:"2025-06-05"},tooltip:{show:!0,style:"dark"},height:250,showGrid:!0,curve:"monotone"}},layout:{span:12,order:4}}]},gW={manualColors:{line1:"#8b5cf6",line2:"#06b6d4",line3:"#f97316",line4:"#10b981"},paletteColors:Yt.primary,semanticColors:Yt.semantic,gradientColors:Yt.gradients},bW={baseUrl:window.location.protocol+"//"+window.location.hostname,dashboardType:"agenticDashboard",projectId:"aa-bdbfa4eb-c7c4-4350-be96-d778188c2c4b",environment:"draft",headers:{authorization:"Bearer 2amvsUbh87obVLVYjbNnXCbXnOr-plekM7-qjKt2EJIZnZuAV2KT9WSTG0L4U33X",accountId:"6290f982fb880154e99bbede","Content-Type":"application/json"},defaultTimeRange:{fromTimestamp:new Date(Date.now()-7*24*60*60*1e3).toISOString(),toTimestamp:new Date().toISOString()},refreshInterval:3e4},xW={id:"agentic-analytics-dashboard",title:"Dashboard",subtitle:"Monitor and review the usage of your agentic app",sections:[{id:"usage-analytics",title:"Session Analytics",metrics:[{title:"Users",value:0,metricType:"users",highlighted:!0},{title:"Sessions",value:0,metricType:"sessions",highlighted:!1},{title:"Messages",value:0,metricType:"messages",highlighted:!1},{title:"Tokens",value:0,metricType:"tokens",highlighted:!1}],view:{type:"chart",chart:{type:"line",title:"Usage Over Time",data:[],lines:[{dataKey:"count",color:"#3B82F6",label:"Count",strokeWidth:2}],xAxisLabel:"Date",yAxisLabel:"Count",tooltip:{show:!0,formatter:(e,t)=>[`${e}`,t]}}},layout:{span:12}},{id:"runs",title:"Execution Analytics",metrics:[{title:"Agent Runs",value:0,metricType:"agentRuns",highlighted:!0},{title:"Tool Runs",value:0,metricType:"toolRuns",highlighted:!1},{title:"Model Runs",value:0,metricType:"modelRuns",highlighted:!1}],view:{type:"chart",chart:{type:"line",title:"Execution Runs Over Time",data:[],lines:[{dataKey:"count",color:"#10B981",label:"Runs",strokeWidth:2}],xAxisLabel:"Date",yAxisLabel:"Count",tooltip:{show:!0,formatter:(e,t)=>[`${e}`,t]}}},layout:{span:12}}],globalControls:{draft:{label:"Environment",options:[{label:"Draft",value:"draft"},{label:"Production",value:"production"},{label:"Staging",value:"staging"}],defaultValue:"draft"},timeRange:{label:"Time Range",useDatePicker:!0,options:[{label:"Last 7 days",value:"7d"},{label:"Last 30 days",value:"30d"}],defaultValue:"7d"},export:{enabled:!1,formats:["csv","json"],onExport:e=>{console.log(`Exporting in ${e} format`)}}},layout:{columns:12,gap:24,responsive:!0}},wW=`
265
+ `,onClick:f,children:p.jsxs("div",{className:"flex items-center gap-[6px] w-full",children:[p.jsx("div",{className:"p-[2px] rounded hover:bg-gray-200 cursor-pointer flex-shrink-0 bg-white z-[2]",onClick:b=>{b.stopPropagation(),u?c(b):n&&n(e)},title:u?r?"Collapse":"Expand":"Show details",children:p.jsx(ki,{className:`w-[12px] h-[12px] text-gray-600 transition-transform ${u&&r||l&&i.length>0?"rotate-90":""}`})}),p.jsx("div",{className:"flex-shrink-0",children:h()}),p.jsx("span",{className:"font-semibold text-gray-900 text-xs truncate w-full",children:e.type==="tool"?y(e.name):e.name}),p.jsxs("div",{className:"flex items-center gap-[12px] text-[10px] text-gray-500",children:[e.duration&&p.jsxs("div",{className:"flex items-center gap-[4px]",children:[p.jsx(Tf,{className:"w-[12px] h-[12px]"}),p.jsx("span",{className:"text-[10px] text-gray-500 whitespace-nowrap",children:m(e.duration)})]}),e.llmUsage&&p.jsxs("span",{className:"text-[10px] text-gray-500 whitespace-nowrap",children:[e.llmUsage.total_tokens," Tokens"]})]}),p.jsx("div",{className:"flex-shrink-0",children:d()})]})}),l&&i.length>0&&p.jsxs("div",{className:"w-full pl-[32px] relative",children:[p.jsx("div",{className:"absolute top-[-40px] left-[16px] w-[1px] border-l border-dashed border-gray-200 h-[calc(100%+40px)] z-[1]"}),p.jsxs("div",{className:"px-[4px] py-[8px] w-full border-t border-gray-200",children:[p.jsx("div",{className:"bg-gray-50 rounded-[4px] p-[4px] inline-flex gap-[4px] mb-[8px] border border-gray-200",children:v().map(b=>p.jsx("button",{onClick:()=>s(b),className:`px-[8px] py-[4px] text-xs font-medium rounded-[4px] text-gray-500 hover:text-gray-700 hover:shadow-tab hover:bg-white transition-colors ${o===b?"bg-white text-gray-900 shadow-tab":"text-gray-500 hover:text-gray-700 hover:bg-white"}`,children:b.charAt(0).toUpperCase()+b.slice(1)},b))}),p.jsx("div",{className:"px-[4px]",children:w()})]})]}),r&&u&&p.jsxs("div",{className:"w-full pl-[32px] relative",children:[p.jsx("div",{className:"absolute top-[-40px] left-[16px] w-[1px] border-l border-dashed border-gray-200 h-[calc(100%+40px)] z-[1]"}),e.children.map(b=>p.jsx(Yb,{node:b,onToggle:t,isExpanded:b.isExpanded,onNodeClick:n,selectedNodeIds:a},b.id))]})]})}const Xb=T.forwardRef(({executionEvents:e,sessionId:t,onNodeExpand:r,onNodeCollapse:n,className:a=""},i)=>{const[o,s]=T.useState(new Set),[l,u]=T.useState(new Set),[c,f]=T.useState(new Set),[d,h]=T.useState(e),m=T.useRef(e.length);T.useEffect(()=>{h(e),e.length===0?(s(new Set),u(new Set),f(new Set),x.current=!1,m.current=0):(e.length>m.current&&(x.current=!0),m.current=e.length)},[e]);const y=T.useRef(0),v=T.useRef(null),x=T.useRef(!1);T.useImperativeHandle(i,()=>({addEvent:k=>{h(_=>[..._,k]),x.current=!0},addEvents:k=>{h(_=>[..._,...k]),x.current=!0},clearEvents:()=>{h([]),s(new Set),u(new Set),f(new Set),x.current=!1}}),[]);const w=T.useMemo(()=>{const k=Kb.buildSessionTree(d,t);return v.current=k,k},[d,t]),b=T.useRef(null);T.useEffect(()=>{d.length>y.current&&b.current&&setTimeout(()=>{b.current&&b.current.scrollTo({top:b.current.scrollHeight,behavior:"smooth"})},100),y.current=d.length},[d.length]),T.useEffect(()=>{if(d.length>0&&w.runs.length>0){if(x.current){const _=$(w);s(new Set(_)),x.current=!1}f(_=>{const D=new Set(_);return w.runs.forEach(M=>{D.has(M.runId)||D.add(M.runId)}),D});const k=w.runs[w.runs.length-1];if(k.rootNodes.length>0){const _=k.rootNodes[k.rootNodes.length-1],D=j(_);D&&u(M=>{const B=new Set(M);return B.add(D.id),B})}}},[w]);const A=T.useCallback(k=>{s(_=>{const D=new Set(_);return D.has(k)?(D.delete(k),n==null||n(k)):(D.add(k),r==null||r(k)),D})},[r,n]),g=T.useCallback(k=>{u(_=>{const D=new Set(_);return D.has(k.id)?D.delete(k.id):D.add(k.id),D})},[]),O=T.useCallback(k=>{f(_=>{const D=new Set(_);return D.has(k)?D.delete(k):D.add(k),D})},[]),S=T.useCallback(k=>({...k,isExpanded:o.has(k.id),children:k.children.map(D=>S(D))}),[o]),P=k=>k?k<1e3?`${k}ms`:`${(k/1e3).toFixed(2)}s`:"",E=k=>k?k>=1e6?`${(k/1e6).toFixed(1)}M tokens`:k>=1e3?`${(k/1e3).toFixed(1)}K tokens`:`${k} tokens`:"",N=async k=>{try{if(navigator.clipboard&&navigator.clipboard.writeText){await navigator.clipboard.writeText(k);return}const _=document.createElement("textarea");_.value=k,_.style.position="fixed",_.style.left="-999999px",_.style.top="-999999px",document.body.appendChild(_),_.focus(),_.select();try{document.execCommand("copy")}catch(D){console.warn("Copy to clipboard failed:",D)}finally{document.body.removeChild(_)}}catch(_){console.warn("Copy to clipboard failed:",_)}},j=k=>k.children.length===0?k:j(k.children[k.children.length-1]),$=k=>{const _=[],D=M=>{_.push(M.id),M.children.forEach(B=>D(B))};return k.runs.forEach(M=>{M.rootNodes.forEach(B=>D(B))}),_};return w.runs.length?p.jsx("div",{className:`flex flex-col h-full bg-white ${a}`,children:p.jsxs("div",{className:"flex flex-col gap-[16px] p-[24px] overflow-y-auto overflow-x-hidden",ref:b,children:[p.jsxs("div",{className:"flex items-center w-full gap-[16px]",children:[p.jsx("div",{className:"text-xs text-gray-400 whitespace-nowrap flex-shrink-0",children:"Session initiated"}),p.jsx("div",{className:"flex-1 h-[1px] border-t border-dashed border-gray-300 w-full"}),p.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-400 flex-shrink-0",children:[p.jsx("span",{children:w.sessionId}),p.jsx("button",{className:"p-[4px] hover:bg-gray-100 rounded transition-colors",onClick:()=>N(w.sessionId),title:"Copy session ID",children:p.jsx(fa,{className:"w-[12px] h-[12px]"})}),p.jsx("button",{className:"p-[4px] hover:bg-gray-100 rounded transition-colors",title:"Open in external viewer",children:p.jsx(Af,{className:"w-[12px] h-[12px]"})})]})]}),w.runs.map(k=>p.jsxs("div",{className:"flex flex-col gap-1",children:[p.jsxs("div",{className:"rounded-[8px] border border-gray-300 bg-white overflow-hidden",children:[p.jsx("div",{className:"flex flex-col w-full",children:p.jsxs("div",{className:"flex items-center gap-2 p-[8px] bg-gray-50 cursor-pointer select-none",onClick:()=>O(k.runId),title:c.has(k.runId)?"Collapse run":"Expand run",children:[p.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",className:"flex-shrink-0",children:p.jsx("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M10.8277 1.33398C11.3643 1.33398 11.8072 1.33396 12.168 1.36343C12.5428 1.39405 12.8872 1.45978 13.2108 1.62463C13.7125 1.8803 14.1205 2.28825 14.3762 2.79001C14.541 3.11356 14.6067 3.45803 14.6374 3.83276C14.6668 4.19356 14.6668 4.63646 14.6668 5.1731V9.0235C14.6668 9.47003 14.6668 9.83861 14.6462 10.1404C14.6249 10.4532 14.5792 10.7426 14.4638 11.0211C14.1932 11.6746 13.674 12.1937 13.0206 12.4643C12.7421 12.5797 12.4527 12.6254 12.1399 12.6467C11.8381 12.6673 11.4695 12.6673 11.023 12.6673H11.0002C10.6424 12.6673 10.5714 12.6715 10.5136 12.6852C10.4129 12.7089 10.3191 12.7558 10.2397 12.8221C10.1941 12.8602 10.1481 12.9145 9.9335 13.2007L8.94888 14.5135C8.88665 14.5965 8.81628 14.6904 8.74857 14.7657C8.6739 14.8487 8.54979 14.971 8.36264 15.0438C8.1295 15.1344 7.87083 15.1344 7.6377 15.0438C7.45054 14.971 7.32641 14.8487 7.25174 14.7657C7.18403 14.6904 7.11368 14.5965 7.05145 14.5135L6.06683 13.2007C5.85221 12.9145 5.80624 12.8602 5.76065 12.8221C5.68119 12.7558 5.58739 12.7089 5.48666 12.6852C5.42887 12.6715 5.35786 12.6673 5.00015 12.6673H4.9773C4.53078 12.6673 4.16221 12.6673 3.86047 12.6467C3.54762 12.6254 3.25822 12.5797 2.97968 12.4643C2.32627 12.1937 1.80712 11.6746 1.53647 11.0211C1.42109 10.7426 1.37541 10.4532 1.35407 10.1404C1.33348 9.83861 1.33349 9.47003 1.3335 9.0235V5.17313C1.33349 4.63648 1.33347 4.19356 1.36295 3.83276C1.39356 3.45803 1.45929 3.11356 1.62415 2.79001C1.87981 2.28825 2.28776 1.8803 2.78952 1.62463C3.11308 1.45978 3.45755 1.39405 3.83228 1.36343C4.19307 1.33396 4.63599 1.33398 5.17264 1.33398H10.8277ZM10.4715 4.52924C10.2112 4.2689 9.78906 4.26889 9.52872 4.52924L6.66681 7.39114V5.6673C6.6668 5.29912 6.36834 5.00064 6.00015 5.00064C5.63197 5.00064 5.33351 5.29912 5.3335 5.6673V9.00064C5.3335 9.17745 5.40373 9.34702 5.52875 9.47205C5.65377 9.59707 5.82334 9.6673 6.00015 9.6673H9.3335L9.35068 9.66708C9.71092 9.65796 10.0002 9.36308 10.0002 9.00064C10.0001 8.63821 9.71092 8.34332 9.35068 8.3342L9.3335 8.33398H7.60962L10.4715 5.47205C10.7319 5.2117 10.7319 4.78958 10.4715 4.52924Z",fill:"#079455"})}),p.jsx("span",{className:"flex-1 text-xs text-gray-900 truncate",children:k.userInput||`Run ${k.runId}`}),p.jsx(cr,{className:`w-[16px] h-[16px] text-gray-400 flex-shrink-0 transition-transform ${c.has(k.runId)?"rotate-180":""}`})]})}),c.has(k.runId)&&p.jsx("div",{className:"bg-white w-full flex flex-col",children:k.rootNodes&&k.rootNodes.map(_=>p.jsx("div",{className:"w-full",children:p.jsx(Yb,{node:S(_),onToggle:A,isExpanded:o.has(_.id),onNodeClick:g,selectedNodeIds:l})},_.id))}),k.finalOutput&&p.jsxs("div",{className:"p-[8px] bg-gray-50 flex items-center gap-[8px] w-full border-t border-gray-200",children:[p.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",className:"flex-shrink-0",children:p.jsx("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M10.8277 1.33398C11.3643 1.33398 11.8072 1.33396 12.168 1.36343C12.5428 1.39405 12.8872 1.45978 13.2108 1.62463C13.7125 1.8803 14.1205 2.28825 14.3762 2.79001C14.541 3.11356 14.6067 3.45803 14.6374 3.83276C14.6668 4.19356 14.6668 4.63646 14.6668 5.1731V9.0235C14.6668 9.47003 14.6668 9.83861 14.6462 10.1404C14.6249 10.4532 14.5792 10.7426 14.4638 11.0211C14.1932 11.6746 13.674 12.1937 13.0206 12.4643C12.7421 12.5797 12.4527 12.6254 12.1399 12.6467C11.8381 12.6673 11.4695 12.6673 11.023 12.6673H11.0002C10.6424 12.6673 10.5714 12.6715 10.5136 12.6852C10.4129 12.7089 10.3191 12.7558 10.2397 12.8221C10.1941 12.8602 10.1481 12.9145 9.9335 13.2007L8.94888 14.5135C8.88665 14.5965 8.81628 14.6904 8.74857 14.7657C8.6739 14.8487 8.54979 14.971 8.36264 15.0438C8.1295 15.1344 7.87083 15.1344 7.6377 15.0438C7.45054 14.971 7.32641 14.8487 7.25174 14.7657C7.18403 14.6904 7.11368 14.5965 7.05145 14.5135L6.06683 13.2007C5.85221 12.9145 5.80624 12.8602 5.76065 12.8221C5.68119 12.7558 5.58739 12.7089 5.48666 12.6852C5.42887 12.6715 5.35786 12.6673 5.00015 12.6673H4.9773C4.53078 12.6673 4.16221 12.6673 3.86047 12.6467C3.54762 12.6254 3.25822 12.5797 2.97968 12.4643C2.32627 12.1937 1.80712 11.6746 1.53647 11.0211C1.42109 10.7426 1.37541 10.4532 1.35407 10.1404C1.33348 9.83861 1.33349 9.47003 1.3335 9.0235V5.17313C1.33349 4.63648 1.33347 4.19356 1.36295 3.83276C1.39356 3.45803 1.45929 3.11356 1.62415 2.79001C1.87981 2.28825 2.28776 1.8803 2.78952 1.62463C3.11308 1.45978 3.45755 1.39405 3.83228 1.36343C4.19307 1.33396 4.63599 1.33398 5.17264 1.33398H10.8277ZM6.66653 4.33398C6.29835 4.334 5.99988 4.63246 5.99988 5.00064C5.99988 5.36882 6.29835 5.66729 6.66653 5.6673H8.39041L5.52847 8.52924C5.26813 8.78958 5.26813 9.2117 5.52847 9.47205C5.78882 9.73239 6.21093 9.73239 6.47128 9.47205L9.33322 6.61011V8.33398C9.33323 8.70217 9.6317 9.00064 9.99988 9.00064C10.3681 9.00064 10.6665 8.70217 10.6665 8.33398V5.00064C10.6665 4.63821 10.3773 4.34333 10.0171 4.3342L9.99988 4.33398H6.66653Z",fill:"#155EEF"})}),p.jsx("span",{className:"flex-1 text-xs text-gray-900 truncate",title:k.finalOutput,children:k.finalOutput}),p.jsxs("div",{className:"flex items-center gap-[8px] flex-shrink-0",children:[k.duration&&p.jsxs("div",{className:"flex items-center gap-[4px]",children:[p.jsx(Tf,{className:"w-[12px] h-[12px] text-gray-400"}),p.jsx("span",{className:"text-[10px] text-gray-500 whitespace-nowrap",children:P(k.duration)})]}),k.totalTokens&&p.jsx("span",{className:"text-[10px] text-gray-500 whitespace-nowrap",children:E(k.totalTokens)}),k.status==="running"&&p.jsx("span",{className:"text-[10px] text-gray-500",children:"In progress"})]})]})]}),p.jsxs("div",{className:"flex items-center justify-end gap-2 py-1",children:[p.jsx("span",{className:"text-xs text-gray-400",children:k.runId}),p.jsxs("div",{className:"flex items-center gap-2",children:[p.jsx("button",{className:"p-1 hover:bg-gray-100 rounded transition-colors",onClick:()=>N(k.runId),title:"Copy run ID",children:p.jsx(fa,{className:"w-3 h-3 text-gray-400"})}),p.jsx("button",{className:"p-1 hover:bg-gray-100 rounded transition-colors",title:"Open run in external viewer",children:p.jsx(Af,{className:"w-3 h-3 text-gray-400"})})]})]})]},k.runId))]})}):p.jsx("div",{className:`flex flex-col h-full ${a}`,children:p.jsx("div",{className:"flex items-center justify-center h-full",children:p.jsx("p",{className:"text-gray-500 text-sm",children:"No execution events to display"})})})});Xb.displayName="DebugPanel";const Jb=({value:e,onChange:t,language:r="text",readOnly:n=!1,placeholder:a="",className:i,autoFocus:o=!1})=>{const[s,l]=T.useState(e),[u,c]=T.useState(!1),[f,d]=T.useState(!1),h=T.useRef(null);T.useEffect(()=>{l(e)},[e]);function m(){navigator.clipboard.writeText(s).then(()=>{d(!0),setTimeout(()=>d(!1),1500)})}function y(b){const A=b.target.value;l(A),t==null||t(A)}const v=()=>p.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b bg-gray-100",children:[p.jsx("span",{className:"text-xs font-mono uppercase text-gray-500",children:r}),p.jsxs("div",{className:"flex items-center gap-2",children:[p.jsx("button",{type:"button",className:"p-1 rounded hover:bg-gray-200",onClick:m,title:f?"Copied!":"Copy",children:p.jsx(fa,{size:16,className:f?"text-green-500":""})}),p.jsx("button",{type:"button",className:"p-1 rounded hover:bg-gray-200",onClick:()=>c(!u),title:u?"Minimize":"Maximize",children:u?p.jsx(S0,{size:16}):p.jsx(jf,{size:16})})]})]}),x=()=>p.jsx("textarea",{ref:h,spellCheck:!1,readOnly:n,placeholder:a,autoFocus:o,className:"flex-1 w-full h-full resize-none p-3 font-mono text-sm outline-none bg-transparent",value:s,onChange:y}),w=p.jsxs("div",{className:se("flex flex-col h-full w-full border rounded-md bg-background",i),style:{minHeight:"200px"},children:[p.jsx(v,{}),p.jsx(x,{})]});return u?p.jsx(hf,{children:p.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4",children:p.jsx("div",{className:"w-full h-full max-h-[calc(100vh-2rem)]",children:w})})}):w};Jb.displayName="CodeEditor";const Zb=T.forwardRef(({className:e,...t},r)=>p.jsx("span",{ref:r,className:se("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",e),...t}));Zb.displayName="Avatar";const Qb=T.forwardRef(({className:e,...t},r)=>p.jsx("img",{ref:r,className:se("aspect-square h-full w-full",e),...t}));Qb.displayName="AvatarImage";const e0=T.forwardRef(({className:e,...t},r)=>p.jsx("span",{ref:r,className:se("flex h-full w-full items-center justify-center rounded-full bg-muted",e),...t}));e0.displayName="AvatarFallback";const t0=T.forwardRef(({className:e,children:t,...r},n)=>p.jsx("div",{ref:n,className:se("rounded-lg border bg-card text-card-foreground shadow-sm",e),...r,children:t}));t0.displayName="Card";const rW=T.forwardRef(({className:e,children:t,...r},n)=>p.jsx("div",{ref:n,className:se("flex flex-col space-y-1.5 p-6",e),...r,children:t}));rW.displayName="CardHeader";const nW=T.forwardRef(({className:e,children:t,...r},n)=>p.jsx("h3",{ref:n,className:se("text-2xl font-semibold leading-none tracking-tight",e),...r,children:t}));nW.displayName="CardTitle";const aW=T.forwardRef(({className:e,children:t,...r},n)=>p.jsx("div",{ref:n,className:se("p-6 pt-0",e),...r,children:t}));aW.displayName="CardContent";const Bs=["Portfolio Analysis Expert","Mortgage Evaluator","Credit Risk Specialist","Asset Valuation Analyst","Liability Assessment Advisor"],Fs=["calculate-creditScore","calculate-risk","calculate-mortgage","analyse-expenses","fetch-statement"],Ws=["gpt-4o","gpt-4o-mini","gpt-3.5-turbo","claude-3-5-sonnet","claude-3-5-haiku","claude-3-opus","gemini-1.5-pro","gemini-1.5-flash","llama-3.1-405b","llama-3.1-70b"],iW=(e=30)=>{const t=[],r=new Date;for(let n=e-1;n>=0;n--){const a=new Date(r);a.setDate(r.getDate()-n);const i=600+Math.sin(n*.1)*100,o=Math.floor(i+Math.random()*100),s=Math.floor(o*3.5+Math.random()*200),l=Math.floor(s*2.9+Math.random()*500),u=Math.floor(l*.9+Math.random()*300),c=Math.floor(u*.6),f=u-c,d=Math.floor(s*.8+Math.random()*100),h=Math.floor(d*12+Math.random()*500),m=Math.floor(d*8+Math.random()*300),y=Math.floor(h*.3+Math.random()*100),v=Math.floor(h*.25+Math.random()*80),x=Math.floor(h*.2+Math.random()*60),w=Math.floor(h*.15+Math.random()*50),b={};Bs.forEach(O=>{const S=O.replace(/\s+/g,"").toLowerCase(),P=Math.floor(d/Bs.length);b[S]=Math.floor(P+Math.random()*(P*.5))});const A={};Fs.forEach(O=>{const S=O.replace(/[-]/g,""),P=Math.floor(h/Fs.length);A[S]=Math.floor(P+Math.random()*(P*.8))});const g={};Ws.forEach(O=>{const S=O.replace(/[-\.]/g,""),P=Math.floor(m/Ws.length);g[S]=Math.floor(P+Math.random()*(P*.6))}),t.push({date:a.toISOString().split("T")[0],users:o,sessions:s,messages:l,totalTokens:u,inputTokens:c,outputTokens:f,agentRuns:d,toolRuns:h,modelRuns:m,codeTools:y,workflowTools:v,knowledgeTools:x,mcpTools:w,...b,...A,...g,value:o})}return t},oW=()=>{const e=[],t=['{"name":"avatar14","color":"#F6D0FE","type":"human"}','{"name":"avatar2","color":"#3B82F6","type":"human"}','{"name":"avatar7","color":"#EF4444","type":"human"}','{"name":"avatar12","color":"#10B981","type":"human"}','{"name":"avatar8","color":"#F59E0B","type":"human"}'];return Bs.forEach((r,n)=>{e.push({id:`agent-${n+1}`,name:r,runs:Math.floor(Math.random()*8e3)+4e3,responseTime:`${Math.floor(Math.random()*120)+15}s`,tokens:Math.floor(Math.random()*4e5)+1e5,successRate:`${Math.floor(Math.random()*20)+80}%`,lastRun:new Date(Date.now()-Math.random()*7*24*60*60*1e3).toLocaleDateString(),avatar:`https://api.dicebear.com/7.x/avataaars/svg?seed=${r.replace(/\s+/g,"")}&backgroundColor=b6e3f4,c0aede,d1d4f9&backgroundType=solid`,icon:t[n]||t[0]})}),e},sW=()=>{const e=r=>r.includes("calculate-creditscore")?"Code Tool":r.includes("calculate-risk")?"Workflow Tool":r.includes("calculate-mortgage")?"MCP Tool":r.includes("analyse-expenses")?"Workflow Tool":r.includes("fetch-statement")?"Knowledge":"Code Tool",t=['{"name":"calculator","color":"#EF6820","type":"inlineTool"}','{"name":"workflow","color":"#155EEF","type":"toolLibrary"}','{"name":"mcptool","color":"#101828","type":"MCP"}','{"name":"expenses","color":"#155EEF","type":"toolLibrary"}','{"name":"knowledge","color":"#7A5AF8","type":"KNOWLEDGE"}'];return Fs.map((r,n)=>({id:`tool-${n+1}`,name:r,type:e(r),runs:Math.floor(Math.random()*8e3)+4e3,responseTime:`${Math.floor(Math.random()*90)+15}s`,tokens:Math.floor(Math.random()*2e4)+5e3,successRate:`${Math.floor(Math.random()*15)+85}%`,lastRun:new Date(Date.now()-Math.random()*7*24*60*60*1e3).toLocaleDateString(),icon:t[n]||t[0]}))},lW=()=>Ws.map((e,t)=>({id:`model-${t+1}`,name:e,runs:Math.floor(Math.random()*8e3)+4e3,responseTime:`${Math.floor(Math.random()*120)+15}s`,tokens:Math.floor(Math.random()*5e5)+1e5,successRate:`${Math.floor(Math.random()*15)+85}%`,lastRun:new Date(Date.now()-Math.random()*7*24*60*60*1e3).toLocaleDateString()})),Zr=iW(),uW=oW(),cW=sW(),fW=lW(),dW={id:"main-dashboard",title:"Dashboard",subtitle:"Monitor and review the usage of your agentic app.",version:"1.0.0",globalControls:{draft:{label:"Draft",options:[{label:"Current Draft",value:"current"},{label:"Previous Draft",value:"previous"},{label:"All Drafts",value:"all"}],defaultValue:"current"},timeRange:{label:"Time Range",options:[{label:"This month",value:"month"},{label:"Last 7 days",value:"week"},{label:"Last 30 days",value:"30days"},{label:"Last 90 days",value:"90days"}],defaultValue:"month"},export:{enabled:!0,formats:["csv","json","pdf"]}},layout:{columns:12,gap:24,responsive:!0},sections:[{id:"sessions",title:"Sessions",description:"User engagement and session analytics",metrics:[{title:"Users",value:3384,change:{value:6,type:"increase"},info:"Total number of unique users",metricType:"users",view:{type:"chart",chart:{type:"line",title:"Total Users",data:Zr,dataKey:"users",color:"#8b5cf6",yAxisLabel:"Number of Users",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}}}},{title:"Sessions",value:11847,change:{value:18,type:"increase"},info:"Total number of user sessions",metricType:"sessions",view:{type:"chart",chart:{type:"line",title:"Total Sessions",data:Zr,dataKey:"sessions",color:"#06b6d4",yAxisLabel:"Number of Sessions",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}}}},{title:"Messages",value:34563,change:{value:5,type:"increase"},info:"Total messages exchanged",metricType:"messages",view:{type:"chart",chart:{type:"line",title:"Total Messages",data:Zr,dataKey:"messages",color:"#e879f9",yAxisLabel:"Number of Messages",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}}}},{title:"Tokens",value:32044,change:{value:44,type:"increase"},info:"Total tokens processed",metricType:"tokens",view:{type:"chart",chart:{type:"line",title:"Token Usage Breakdown",data:Zr,yAxisLabel:"Number of Tokens",lines:[{dataKey:"totalTokens",color:"#f97316",label:"Total Tokens"},{dataKey:"inputTokens",color:"#3b82f6",label:"Input Tokens"},{dataKey:"outputTokens",color:"#e879f9",label:"Output Tokens"}],height:300,showGrid:!0,showLegend:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}}}}],view:{type:"chart"},layout:{span:12,order:1}},{id:"runs",title:"Runs",description:"Agent, tool, and model execution analytics",metrics:[{title:"Agent Runs",value:3384,change:{value:6,type:"increase"},info:"Number of agent executions",metricType:"agentRuns",view:{type:"chart",chart:{type:"line",title:"Agent Runs",data:Zr,dataKey:"agentRuns",color:"#06b6d4",yAxisLabel:"Number of Agent Runs",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}},table:{title:"Agent Runs",data:uW,columns:[{key:"name",title:"Name",width:200,align:"left"},{key:"runs",title:"Runs",width:100,align:"right",formatter:e=>`${Math.floor(e/1e3)}k`},{key:"responseTime",title:"Response Time",width:120,align:"right"},{key:"tokens",title:"Tokens",width:100,align:"right",formatter:e=>`${Math.floor(e/1e3)}k`}]}},controls:{dropdown:{label:"All Agents",options:[{label:"All Agents",value:"all"},...Bs.map(e=>({label:e,value:e.replace(/\s+/g,"").toLowerCase(),avatar:`https://api.dicebear.com/7.x/avataaars/svg?seed=${e.replace(/\s+/g,"")}&backgroundColor=b6e3f4,c0aede,d1d4f9&backgroundType=solid`}))],defaultValue:["all"],multiSelect:!0,searchable:!0},toggle:{chartView:!0,tableView:!0}}},{title:"Tool Runs",value:34563,change:{value:5,type:"increase"},info:"Number of tool executions",metricType:"toolRuns",view:{type:"chart",chart:{type:"line",title:"Tool Runs",data:Zr,yAxisLabel:"Number of Tool Runs",lines:[{dataKey:"toolRuns",color:"#06b6d4",label:"Tool Runs"},{dataKey:"codeTools",color:"#f97316",label:"Code Tools"},{dataKey:"workflowTools",color:"#10b981",label:"Workflow Tools"},{dataKey:"knowledgeTools",color:"#8b5cf6",label:"Knowledge"},{dataKey:"mcpTools",color:"#ef4444",label:"MCP Tools"}],height:300,showGrid:!0,showLegend:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}},table:{title:"Tool Runs",data:cW,columns:[{key:"name",title:"Name",width:200,align:"left"},{key:"type",title:"Type",width:150,align:"left"},{key:"runs",title:"Runs",width:100,align:"right",formatter:e=>`${Math.floor(e/1e3)}k`},{key:"responseTime",title:"Response Time",width:120,align:"right"}]}},controls:{dropdown:{label:"All Tools",options:[{label:"All Tools",value:"all"},...Fs.map((e,t)=>{const r=['{"name":"calculator","color":"#EF6820","type":"inlineTool"}','{"name":"workflow","color":"#155EEF","type":"toolLibrary"}','{"name":"mcptool","color":"#101828","type":"MCP"}','{"name":"expenses","color":"#155EEF","type":"toolLibrary"}','{"name":"knowledge","color":"#7A5AF8","type":"KNOWLEDGE"}'],n=a=>a.includes("calculate-creditscore")?"Code Tool":a.includes("calculate-risk")?"Workflow Tool":a.includes("calculate-mortgage")?"MCP Tool":a.includes("analyse-expenses")?"Workflow Tool":a.includes("fetch-statement")?"Knowledge":"Code Tool";return{label:e,value:e.replace(/[-]/g,""),icon:r[t]||r[0],type:n(e)}})],defaultValue:["all"],multiSelect:!0,searchable:!0},toggle:{chartView:!0,tableView:!0}}},{title:"Model Runs",value:32044,change:{value:44,type:"increase"},info:"Number of model inferences",metricType:"modelRuns",view:{type:"chart",chart:{type:"line",title:"Model Runs",data:Zr,dataKey:"modelRuns",color:"#10b981",yAxisLabel:"Number of Model Runs",height:300,showGrid:!0,curve:"monotone",tooltip:{show:!0,style:"dark"},dateRange:{start:"2025-05-06",end:"2025-06-05"}},table:{title:"Model Runs",data:fW,columns:[{key:"name",title:"Model Name",width:200,align:"left"},{key:"runs",title:"Runs",width:100,align:"right",formatter:e=>`${Math.floor(e/1e3)}k`},{key:"tokens",title:"Tokens",width:120,align:"right",formatter:e=>`${Math.floor(e/1e3)}k`},{key:"responseTime",title:"Response Time",width:120,align:"right"}]}},controls:{dropdown:{label:"All Models",options:[{label:"All Models",value:"all"},...Ws.map(e=>{const t=r=>{const n=r.toLowerCase();return n.includes("gpt")||n.includes("openai")?"⚡":n.includes("claude")||n.includes("anthropic")?"A":n.includes("gemini")||n.includes("google")?"G":n.includes("llama")||n.includes("meta")?"M":"🤖"};return{label:e,value:e.replace(/[-\.]/g,""),icon:t(e)}})],defaultValue:["all"],multiSelect:!0,searchable:!0},toggle:{chartView:!0,tableView:!0}}}],view:{type:"chart"},layout:{span:12,order:2}}]},Yt={primary:["#8b5cf6","#06b6d4","#f97316","#10b981","#ec4899","#f59e0b","#3b82f6","#ef4444"],secondary:["#a78bfa","#22d3ee","#fb923c","#34d399","#f472b6","#fbbf24","#60a5fa","#f87171"],accent:["#6366f1","#8b5cf6","#d946ef","#06b6d4","#84cc16","#eab308"],semantic:{success:"#10b981",warning:"#f59e0b",error:"#ef4444",info:"#3b82f6"},gradients:{purple:["#8b5cf6","#a78bfa"],cyan:["#06b6d4","#22d3ee"],orange:["#f97316","#fb923c"],green:["#10b981","#34d399"],sunset:["#f97316","#ec4899"],ocean:["#06b6d4","#3b82f6"],forest:["#10b981","#84cc16"]}},pW={primary:["#7c3aed","#0891b2","#ea580c","#059669","#db2777","#d97706","#2563eb","#dc2626"],secondary:["#8b5cf6","#06b6d4","#f97316","#10b981","#ec4899","#f59e0b","#3b82f6","#ef4444"],accent:["#4f46e5","#7c3aed","#c026d3","#0891b2","#65a30d","#ca8a04"],semantic:{success:"#059669",warning:"#d97706",error:"#dc2626",info:"#2563eb"}},hW={primary:["#a78bfa","#22d3ee","#fb923c","#34d399","#f472b6","#fbbf24","#60a5fa","#f87171"],secondary:["#c4b5fd","#67e8f9","#fdba74","#6ee7b7","#f9a8d4","#fcd34d","#93c5fd","#fca5a5"],accent:["#818cf8","#a78bfa","#e879f9","#22d3ee","#a3e635","#facc15"],semantic:{success:"#34d399",warning:"#fbbf24",error:"#f87171",info:"#60a5fa"}},mW={primary:["#1f2937","#374151","#6b7280","#9ca3af","#3b82f6","#1d4ed8","#10b981","#f59e0b"],secondary:["#4b5563","#6b7280","#9ca3af","#d1d5db","#60a5fa","#3b82f6","#34d399","#fbbf24"],accent:["#2563eb","#1d4ed8","#059669","#0891b2","#d97706","#b45309"],semantic:{success:"#059669",warning:"#d97706",error:"#dc2626",info:"#1d4ed8"}},r0=(e,t)=>e.primary[t%e.primary.length],Pi=(e,t)=>e.semantic[t],vW=(e,t)=>{var r;return((r=e.gradients)==null?void 0:r[t])||[e.primary[0],e.primary[1]]},n0=(e,t=Yt)=>e.map((r,n)=>({...r,color:r0(t,n)})),Us=((e=30)=>{const t=[],r=new Date;for(let n=e-1;n>=0;n--){const a=new Date(r);a.setDate(r.getDate()-n);const i=600+Math.sin(n*.1)*100,o=Math.floor(i+Math.random()*100),s=Math.floor(o*3.5+Math.random()*200),l=Math.floor(s*2.9+Math.random()*500),u=Math.floor(l*.9+Math.random()*300),c=Math.floor(u*.6),f=u-c,d=Math.floor(s*.8+Math.random()*100),h=Math.floor(d*12+Math.random()*500),m=Math.floor(d*8+Math.random()*300);t.push({date:a.toISOString().split("T")[0],users:o,sessions:s,messages:l,totalTokens:u,inputTokens:c,outputTokens:f,agentRuns:d,toolRuns:h,modelRuns:m,value:o})}return t})(),yW={id:"enhanced-dashboard",title:"Enhanced Color Configuration Dashboard",subtitle:"Demonstrating all color configuration options",version:"1.0.0",globalControls:{draft:{label:"Draft",options:[{label:"Current Draft",value:"current"},{label:"Previous Draft",value:"previous"}],defaultValue:"current"},timeRange:{label:"Time Range",options:[{label:"Last 7 days",value:"week"},{label:"Last 30 days",value:"30days"}],defaultValue:"30days"},export:{enabled:!0,formats:["csv","json"]}},layout:{columns:12,gap:24,responsive:!0},sections:[{id:"manual-colors",title:"Manual Color Assignment",description:"Each line has manually assigned colors",metrics:[{title:"Total Users",value:3384,change:{value:6,type:"increase"},info:"Manually colored chart"}],view:{type:"chart",chart:{type:"line",title:"Manual Color Configuration",data:Us,lines:[{dataKey:"users",color:"#8b5cf6",label:"Users",strokeWidth:3},{dataKey:"sessions",color:"#06b6d4",label:"Sessions",strokeWidth:2},{dataKey:"messages",color:"#f97316",label:"Messages",strokeWidth:2,strokeDasharray:"5 5"}],dateRange:{start:"2025-05-06",end:"2025-06-05"},tooltip:{show:!0,style:"dark"},height:300,showLegend:!1}},layout:{span:6,order:1}},{id:"auto-colors",title:"Auto-Assigned Colors",description:"Colors automatically assigned from palette",metrics:[{title:"Agent Runs",value:3384,change:{value:6,type:"increase"},info:"Auto-colored from palette"}],view:{type:"chart",chart:{type:"line",title:"Auto Color Assignment",data:Us,lines:n0([{dataKey:"agentRuns",label:"Agent Runs"},{dataKey:"toolRuns",label:"Tool Runs"},{dataKey:"modelRuns",label:"Model Runs"},{dataKey:"totalTokens",label:"Total Tokens"}],Yt),dateRange:{start:"2025-05-06",end:"2025-06-05"},tooltip:{show:!0,style:"dark"},height:300,showLegend:!1}},layout:{span:6,order:2}},{id:"semantic-colors",title:"Semantic Colors",description:"Using semantic colors for different data types",metrics:[{title:"Success Rate",value:"94.2%",change:{value:2,type:"increase"},info:"Using semantic success color"},{title:"Error Rate",value:"5.8%",change:{value:1,type:"decrease"},info:"Using semantic error color"}],view:{type:"chart",chart:{type:"line",title:"Semantic Color Usage",data:Us,lines:[{dataKey:"users",color:Pi(Yt,"success"),label:"Successful Operations",strokeWidth:3},{dataKey:"sessions",color:Pi(Yt,"warning"),label:"Warning Events",strokeWidth:2},{dataKey:"messages",color:Pi(Yt,"error"),label:"Error Events",strokeWidth:2},{dataKey:"totalTokens",color:Pi(Yt,"info"),label:"Info Events",strokeWidth:2}],dateRange:{start:"2025-05-06",end:"2025-06-05"},tooltip:{show:!0,style:"dark"},height:300,showLegend:!1}},layout:{span:12,order:3}},{id:"single-custom",title:"Single Line Custom Color",description:"Single line chart with custom color and styling",metrics:[{title:"Total Messages",value:34563,change:{value:5,type:"increase"},info:"Custom styled single line"}],view:{type:"chart",chart:{type:"line",title:"Custom Single Line",data:Us,dataKey:"messages",color:"#ec4899",dateRange:{start:"2025-05-06",end:"2025-06-05"},tooltip:{show:!0,style:"dark"},height:250,showGrid:!0,curve:"monotone"}},layout:{span:12,order:4}}]},gW={manualColors:{line1:"#8b5cf6",line2:"#06b6d4",line3:"#f97316",line4:"#10b981"},paletteColors:Yt.primary,semanticColors:Yt.semantic,gradientColors:Yt.gradients},bW={baseUrl:window.location.protocol+"//"+window.location.hostname,dashboardType:"agenticDashboard",projectId:"aa-bdbfa4eb-c7c4-4350-be96-d778188c2c4b",environment:"draft",headers:{authorization:"Bearer 2amvsUbh87obVLVYjbNnXCbXnOr-plekM7-qjKt2EJIZnZuAV2KT9WSTG0L4U33X",accountId:"6290f982fb880154e99bbede","Content-Type":"application/json"},defaultTimeRange:{fromTimestamp:new Date(Date.now()-7*24*60*60*1e3).toISOString(),toTimestamp:new Date().toISOString()},refreshInterval:3e4},xW={id:"agentic-analytics-dashboard",title:"Dashboard",subtitle:"Monitor and review the usage of your agentic app",sections:[{id:"usage-analytics",title:"Session Analytics",metrics:[{title:"Users",value:0,metricType:"users",highlighted:!0},{title:"Sessions",value:0,metricType:"sessions",highlighted:!1},{title:"Messages",value:0,metricType:"messages",highlighted:!1},{title:"Tokens",value:0,metricType:"tokens",highlighted:!1}],view:{type:"chart",chart:{type:"line",title:"Usage Over Time",data:[],lines:[{dataKey:"count",color:"#3B82F6",label:"Count",strokeWidth:2}],xAxisLabel:"Date",yAxisLabel:"Count",tooltip:{show:!0,formatter:(e,t)=>[`${e}`,t]}}},layout:{span:12}},{id:"runs",title:"Execution Analytics",metrics:[{title:"Agent Runs",value:0,metricType:"agentRuns",highlighted:!0},{title:"Tool Runs",value:0,metricType:"toolRuns",highlighted:!1},{title:"Model Runs",value:0,metricType:"modelRuns",highlighted:!1}],view:{type:"chart",chart:{type:"line",title:"Execution Runs Over Time",data:[],lines:[{dataKey:"count",color:"#10B981",label:"Runs",strokeWidth:2}],xAxisLabel:"Date",yAxisLabel:"Count",tooltip:{show:!0,formatter:(e,t)=>[`${e}`,t]}}},layout:{span:12}}],globalControls:{draft:{label:"Environment",options:[{label:"Draft",value:"draft"},{label:"Production",value:"production"},{label:"Staging",value:"staging"}],defaultValue:"draft"},timeRange:{label:"Time Range",useDatePicker:!0,options:[{label:"Last 7 days",value:"7d"},{label:"Last 30 days",value:"30d"}],defaultValue:"7d"},export:{enabled:!1,formats:["csv","json"],onExport:e=>{console.log(`Exporting in ${e} format`)}}},layout:{columns:12,gap:24,responsive:!0}},wW=`
266
266
  // In your Angular component (usage-analytics.component.ts)
267
267
  import { Dashboard, apiEnabledDashboardConfig, agenticAppConfig } from '@agentic/ui-libs';
268
268
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentic-ui-libs",
3
- "version": "0.2.0-beta.7",
3
+ "version": "0.2.0-beta.8",
4
4
  "type": "module",
5
5
  "description": "A modular, config-driven analytics library for React and Angular applications",
6
6
  "main": "dist/index.js",
@@ -41,7 +41,7 @@
41
41
  "build:lib": "vite build --mode lib",
42
42
  "storybook": "storybook dev -p 6006",
43
43
  "build-storybook": "storybook build",
44
- "publish:beta": "npm version prerelease --preid=beta && npm publish --tag beta --access public"
44
+ "publish:beta": "npm run build && npm version prerelease --preid=beta && npm publish --tag beta --access public"
45
45
  },
46
46
  "keywords": [
47
47
  "analytics",