"use strict";(self.webpackChunkantreklabs_iyzitrace_app=self.webpackChunkantreklabs_iyzitrace_app||[]).push([[8848],{58848:(e,t,a)=>{a.r(t),a.d(t,{default:()=>Y});var n=a(85959),s=a.n(n),r=a(80478),i=a(48371),o=a(99168),l=a(35065),c=a(99658),d=a(82932),u=a(12340),m=a(95201),p=a(63802),g=a(61882),f=a(41780),v=a(14971),x=a(60811),h=a(64020),b=a(73389),y=a(89210),k=a(20184),E=a(20256),w=a(55500),A=a(92081),N=a(46089),S=a(18531),z=a(87781),I=a(62661),T=a(26940),D=a(70995),C=a(44993),$=a(14330);function P(e,t,a,n,s,r,i){try{var o=e[r](i),l=o.value}catch(e){return void a(e)}o.done?t(l):Promise.resolve(l).then(n,s)}function O(e){return function(){var t=this,a=arguments;return new Promise(function(n,s){var r=e.apply(t,a);function i(e){P(r,n,s,i,o,"next",e)}function o(e){P(r,n,s,i,o,"throw",e)}i(void 0)})}}function R(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function M(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{},n=Object.keys(a);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(a).filter(function(e){return Object.getOwnPropertyDescriptor(a,e).enumerable}))),n.forEach(function(t){R(e,t,a[t])})}return e}const{TextArea:q}=o.A,B=N.keyframes`
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
`,j=N.keyframes`
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
`,_=N.keyframes`
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
`,L=N.keyframes`
  0%, 100% { opacity: 0; }
  50% { opacity: 1; }
`,K={container:N.css`
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 25%, #f093fb 50%, #4facfe 75%, #667eea 100%);
    background-size: 400% 400%;
    animation: ${B} 15s ease infinite;
    padding: 40px 20px;
  `,innerContainer:N.css`
    max-width: 1400px;
    margin: 0 auto;
    animation: ${j} 0.6s ease-out;
  `,header:N.css`
    text-align: center;
    margin-bottom: 40px;
    color: white;
  `,title:N.css`
    font-size: 48px;
    font-weight: 700;
    margin: 0 0 16px 0;
    background: linear-gradient(135deg, #fff 0%, #f0f0f0 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 30px rgba(255,255,255,0.3);
    letter-spacing: -1px;
  `,subtitle:N.css`
    font-size: 18px;
    color: rgba(255, 255, 255, 0.9);
    margin: 0;
    font-weight: 300;
  `,quickActionsGrid:N.css`
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
  `,quickActionCard:N.css`
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 24px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    
    &:hover {
      transform: translateY(-8px);
      box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
      border-color: #667eea;
      animation: ${_} 0.6s ease;
    }
  `,quickActionIcon:N.css`
    font-size: 36px;
    margin-bottom: 12px;
    display: block;
  `,quickActionTitle:N.css`
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 8px 0;
    color: #1a1a1a;
  `,quickActionDesc:N.css`
    font-size: 14px;
    color: #666;
    margin: 0;
  `,mainCard:N.css`
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.3);
  `,chatContainer:N.css`
    height: 600px;
    display: flex;
    flex-direction: column;
  `,messagesArea:N.css`
    flex: 1;
    overflow-y: auto;
    padding: 32px;
    background: linear-gradient(180deg, #fafafa 0%, #ffffff 100%);
    
    &::-webkit-scrollbar {
      width: 8px;
    }
    
    &::-webkit-scrollbar-track {
      background: #f0f0f0;
      border-radius: 10px;
    }
    
    &::-webkit-scrollbar-thumb {
      background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
      border-radius: 10px;
    }
  `,emptyState:N.css`
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #999;
    text-align: center;
  `,emptyIcon:N.css`
    font-size: 72px;
    margin-bottom: 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  `,emptyTitle:N.css`
    font-size: 24px;
    font-weight: 600;
    color: #333;
    margin: 0 0 12px 0;
  `,emptyDesc:N.css`
    font-size: 16px;
    color: #666;
    max-width: 500px;
  `,message:N.css`
    margin-bottom: 24px;
    animation: ${j} 0.4s ease-out;
  `,userMessage:N.css`
    display: flex;
    justify-content: flex-end;
    gap: 12px;
  `,aiMessage:N.css`
    display: flex;
    justify-content: flex-start;
    gap: 12px;
  `,messageAvatar:N.css`
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
  `,userAvatar:N.css`
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
  `,aiAvatar:N.css`
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
  `,messageBubble:N.css`
    max-width: 70%;
    padding: 16px 20px;
    border-radius: 16px;
    position: relative;
  `,userBubble:N.css`
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
  `,aiBubble:N.css`
    background: white;
    color: #333;
    border: 1px solid #e8e8e8;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  `,messageContent:N.css`
    font-size: 15px;
    line-height: 1.6;
    word-wrap: break-word;
    
    p { margin: 0 0 12px 0; }
    p:last-child { margin: 0; }
    
    h1, h2, h3, h4 {
      margin: 16px 0 12px 0;
      font-weight: 600;
    }
    
    ul, ol {
      margin: 12px 0;
      padding-left: 24px;
    }
    
    li { margin: 6px 0; }
    
    code {
      background: rgba(0, 0, 0, 0.05);
      padding: 2px 6px;
      border-radius: 4px;
      font-family: 'Monaco', 'Menlo', monospace;
      font-size: 13px;
    }
    
    pre {
      background: #1e1e1e;
      color: #d4d4d4;
      padding: 16px;
      border-radius: 8px;
      overflow-x: auto;
      margin: 12px 0;
      
      code {
        background: transparent;
        padding: 0;
        color: inherit;
      }
    }
    
    blockquote {
      border-left: 4px solid #667eea;
      padding-left: 16px;
      margin: 12px 0;
      color: #666;
      font-style: italic;
    }
  `,messageActions:N.css`
    display: flex;
    gap: 8px;
    margin-top: 12px;
  `,messageActionBtn:N.css`
    font-size: 12px;
    padding: 4px 12px;
    height: auto;
  `,messageMetadata:N.css`
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    font-size: 12px;
    color: #999;
  `,inputArea:N.css`
    padding: 24px;
    background: white;
    border-top: 1px solid #e8e8e8;
  `,inputRow:N.css`
    display: flex;
    gap: 12px;
    align-items: flex-end;
  `,textAreaWrapper:N.css`
    flex: 1;
  `,sendButton:N.css`
    height: 48px;
    min-width: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
    transition: all 0.3s ease;
    flex-shrink: 0;
    
    &:hover:not(:disabled) {
      transform: translateY(-2px);
      box-shadow: 0 6px 24px rgba(102, 126, 234, 0.6);
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    }
    
    &:active:not(:disabled) {
      transform: translateY(0);
    }
    
    &:disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }
  `,cancelButton:N.css`
    height: 48px;
    min-width: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #ff4d4f 0%, #ff7875 100%);
    border: none;
    box-shadow: 0 4px 16px rgba(255, 77, 79, 0.4);
    transition: all 0.3s ease;
    flex-shrink: 0;
    color: white;
    
    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 6px 24px rgba(255, 77, 79, 0.6);
      background: linear-gradient(135deg, #ff4d4f 0%, #ff7875 100%) !important;
      color: white !important;
    }
    
    &:active {
      transform: translateY(0);
    }
  `,contextBar:N.css`
    padding: 16px 24px;
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.08) 0%, rgba(118, 75, 162, 0.08) 100%);
    border-bottom: 1px solid #e8e8e8;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
  `,contextSection:N.css`
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    
    span {
      color: #333;
      font-weight: 500;
    }
  `,statsBar:N.css`
    padding: 16px 24px;
    background: linear-gradient(90deg, #f6f8ff 0%, #f8f6ff 100%);
    border-bottom: 1px solid #e8e8e8;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
  `,statsGrid:N.css`
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
  `,statItem:N.css`
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #666;
  `,statValue:N.css`
    font-weight: 600;
    color: #333;
  `,loadingDots:N.css`
    display: inline-flex;
    gap: 4px;
    
    span {
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background: #667eea;
      animation: ${L} 1.4s infinite;
      
      &:nth-child(2) { animation-delay: 0.2s; }
      &:nth-child(3) { animation-delay: 0.4s; }
    }
  `,suggestedQuestions:N.css`
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 16px;
  `,suggestionChip:N.css`
    background: rgba(102, 126, 234, 0.1);
    border: 1px solid rgba(102, 126, 234, 0.3);
    color: #667eea;
    border-radius: 20px;
    padding: 8px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 13px;
    
    &:hover {
      background: rgba(102, 126, 234, 0.2);
      border-color: #667eea;
      transform: translateY(-2px);
    }
  `,settingsPanel:N.css`
    .ant-collapse-header {
      background: #fafafa !important;
      border-radius: 8px !important;
    }
  `,statusCard:N.css`
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 20px 24px;
    margin-bottom: 32px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
  `,statusLeft:N.css`
    display: flex;
    align-items: center;
    gap: 16px;
  `,statusIcon:N.css`
    font-size: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
  `,statusInfo:N.css`
    display: flex;
    flex-direction: column;
    gap: 4px;
  `,statusTitle:N.css`
    font-size: 18px;
    font-weight: 600;
    color: #1a1a1a;
    margin: 0;
  `,statusDesc:N.css`
    font-size: 14px;
    color: #666;
    margin: 0;
  `,statusBadge:N.css`
    padding: 6px 16px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 13px;
  `,statusBadgeActive:N.css`
    background: linear-gradient(135deg, #52c41a 0%, #73d13d 100%);
    color: white;
  `,statusBadgeInactive:N.css`
    background: linear-gradient(135deg, #8c8c8c 0%, #bfbfbf 100%);
    color: white;
  `},Y=()=>{const[e,t]=(0,n.useState)([]),[a,o]=(0,n.useState)(""),[N,P]=(0,n.useState)(!1),[R,B]=(0,n.useState)(!1),[j,_]=(0,n.useState)([]),[L,Y]=(0,n.useState)([]),[F,G]=(0,n.useState)(!0),[J,U]=(0,n.useState)(!0),[V,W]=(0,n.useState)(!0),[H,X]=(0,n.useState)(!0),[Q,Z]=(0,n.useState)(!0),[ee,te]=(0,n.useState)(0),[ae,ne]=(0,n.useState)(0),[se,re]=(0,n.useState)("deepseek/deepseek-chat"),[ie,oe]=(0,n.useState)(!1),le=(0,n.useRef)(null),ce=(0,n.useRef)(null);(0,n.useEffect)(()=>{O(function*(){try{var e;const n=yield(0,$.Xs)();oe(n);const s=yield(0,S.getBackendSrv)().get("/api/plugins/antreklabs-iyzitrace-app/settings"),r=null==s||null===(e=s.jsonData)||void 0===e?void 0:e.aiConfig;var t,a;const i={apiKey:(null==r?void 0:r.apiKey)||"",model:(null==r?void 0:r.model)||"deepseek/deepseek-chat",baseUrl:"https://openrouter.ai/api/v1",temperature:null!==(t=null==r?void 0:r.temperature)&&void 0!==t?t:.7,maxTokens:null!==(a=null==r?void 0:r.maxTokens)&&void 0!==a?a:1500};(0,I.D$)(i),re(i.model),B(!0),l.Ay.success("🤖 AI Service initialized successfully!")}catch(e){l.Ay.error("Failed to initialize AI service. Please configure in Settings.")}})()},[]),(0,n.useEffect)(()=>{O(function*(){try{const e=new C.cI({from:String(Date.now()-864e5),to:String(Date.now())}),[t,a]=yield Promise.all([(0,T._m)(e),(0,D.JM)(e)]);_(t),Y(a)}catch(e){}})()},[]),(0,n.useEffect)(()=>{var e;null===(e=le.current)||void 0===e||e.scrollIntoView({behavior:"smooth"})},[e]);const de=[{id:"overview",title:"🎯 Quick Overview",description:"Get instant system health summary",icon:s().createElement(h.A,{className:`${K.quickActionIcon} ai-quick-icon-purple`}),color:"#667eea",action:()=>O(function*(){0!==j.length?yield ue("Provide a quick overview of system health",!0):l.Ay.warning("No region data available")})()},{id:"service-health",title:"❤️ Service Health",description:"Analyze all services performance",icon:s().createElement(k.A,{className:`${K.quickActionIcon} ai-quick-icon-red`}),color:"#f5576c",action:()=>O(function*(){0!==L.length?yield ue("Analyze service health and identify issues",!0):l.Ay.warning("No service data available")})()},{id:"anomalies",title:"🔥 Find Anomalies",description:"Detect unusual patterns and issues",icon:s().createElement(p.A,{className:`${K.quickActionIcon} ai-quick-icon-orange`}),color:"#ff6b6b",action:()=>O(function*(){yield ue("Identify any anomalies, unusual patterns, or critical issues in the system",!0)})()},{id:"recommendations",title:"⚡ Recommendations",description:"Get optimization suggestions",icon:s().createElement(A.A,{className:`${K.quickActionIcon} ai-quick-icon-yellow`}),color:"#feca57",action:()=>O(function*(){yield ue("Provide specific recommendations for improving system performance and reliability",!0)})()}],ue=(e,a=!1)=>O(function*(){if(!e.trim()||N||!R)return;const n={id:Date.now().toString(),role:"user",content:e,timestamp:new Date};t(e=>[...e,n]),a||o(""),P(!0);try{const a={};if(F&&j.length>0){const e=j.map(e=>{const t=M({},e);return J?J&&t.infrastructures&&(V?V&&t.infrastructures&&(H?H&&!Q&&(t.infrastructures=t.infrastructures.map(e=>{const t=M({},e);return t.services&&(t.services=t.services.map(e=>{const t=M({},e);return delete t.operations,t})),t})):t.infrastructures=t.infrastructures.map(e=>{const t=M({},e);return delete t.services,t})):t.infrastructures=t.infrastructures.map(e=>{const t=M({},e);return delete t.applications,t})):delete t.infrastructures,t});a.regions=e}if(H&&L.length>0){const e=Q?L:L.map(e=>{const t=M({},e);return delete t.operations,t});a.services=e}const n=yield(0,I.ai)({prompt:e,context:Object.keys(a).length>0?a:void 0}),s={id:(Date.now()+1).toString(),role:"ai",content:n.content,timestamp:new Date,tokens:n.usage};t(e=>[...e,s]),ne(e=>e+1),n.usage&&te(e=>e+n.usage.totalTokens)}catch(e){const a=e;l.Ay.error(a.message||"Failed to get AI response");const n={id:(Date.now()+1).toString(),role:"ai",content:`❌ Error: ${a.message||"Something went wrong"}`,timestamp:new Date};t(e=>[...e,n])}finally{P(!1)}})(),me=()=>{ue(a)};return s().createElement(S.PluginPage,{layout:z.PageLayoutType.Canvas},s().createElement("div",{className:K.container},s().createElement("div",{className:K.innerContainer},s().createElement("div",{className:K.header},s().createElement("h1",{className:K.title},s().createElement(E.A,null)," IyziTrace AI Assistant"),s().createElement("p",{className:K.subtitle},"Intelligent observability insights powered by AI • Analyze, detect, and optimize in seconds")),s().createElement("div",{className:K.statusCard},s().createElement("div",{className:K.statusLeft},s().createElement("div",{className:K.statusIcon},s().createElement(E.A,{style:{color:ie?"#52c41a":"#8c8c8c"}})),s().createElement("div",{className:K.statusInfo},s().createElement("h3",{className:K.statusTitle},"AI Assistant Configuration"),s().createElement("p",{className:K.statusDesc},ie?"API key is configured and ready to use":"API key is not configured. Please configure in Settings."))),s().createElement("div",{className:`${K.statusBadge} ${ie?K.statusBadgeActive:K.statusBadgeInactive}`},ie?"Active":"Inactive")),s().createElement("div",{className:K.quickActionsGrid},de.map(e=>s().createElement("div",{key:e.id,className:K.quickActionCard,onClick:()=>e.action()},e.icon,s().createElement("h3",{className:K.quickActionTitle},e.title),s().createElement("p",{className:K.quickActionDesc},e.description)))),s().createElement(i.A,{className:K.mainCard,bordered:!1},s().createElement("div",{className:K.statsBar},s().createElement("div",{className:K.statsGrid},s().createElement("div",{className:K.statItem},s().createElement(y.A,{className:"ai-context-icon-purple"}),s().createElement("span",null,"Requests: ",s().createElement("span",{className:K.statValue},ae))),s().createElement("div",{className:K.statItem},s().createElement(m.A,{className:"ai-context-icon-red"}),s().createElement("span",null,"Tokens: ",s().createElement("span",{className:K.statValue},ee.toLocaleString())))),s().createElement(c.A,null,s().createElement(r.Ay,{size:"small",icon:s().createElement(b.A,null),onClick:()=>{t([]),te(0),ne(0),l.Ay.info("Chat cleared")}},"Clear"))),s().createElement("div",{className:K.contextBar},s().createElement("div",{className:K.contextSection},s().createElement("span",{className:"ai-context-label"},"Context:"),s().createElement(c.A,{size:4},s().createElement(d.A,{size:"small",checked:F,onChange:G}),s().createElement("span",{className:"ai-context-text"},"Regions (",j.length,")")),s().createElement(c.A,{size:4},s().createElement(d.A,{size:"small",checked:J,onChange:U}),s().createElement("span",{className:"ai-context-text"},"Infrastructures (",j.reduce((e,t)=>{var a;return e+((null===(a=t.infrastructures)||void 0===a?void 0:a.length)||0)},0),")")),s().createElement(c.A,{size:4},s().createElement(d.A,{size:"small",checked:V,onChange:W}),s().createElement("span",{className:"ai-context-text"},"Applications (",j.reduce((e,t)=>{if(!t.infrastructures)return e;return e+t.infrastructures.reduce((e,t)=>{var a;return e+((null===(a=t.applications)||void 0===a?void 0:a.length)||0)},0)},0),")")),s().createElement(c.A,{size:4},s().createElement(d.A,{size:"small",checked:H,onChange:X}),s().createElement("span",{className:"ai-context-text"},"Services (",L.length,")")),s().createElement(c.A,{size:4},s().createElement(d.A,{size:"small",checked:Q,onChange:Z}),s().createElement("span",{className:"ai-context-text"},"Operations (",L.reduce((e,t)=>{var a;return e+((null===(a=t.operations)||void 0===a?void 0:a.length)||0)},0),")"))),s().createElement(u.A,{icon:s().createElement(E.A,null),className:"ai-model-tag"},se)),s().createElement("div",{className:K.chatContainer},s().createElement("div",{className:K.messagesArea},0===e.length?s().createElement("div",{className:K.emptyState},s().createElement(E.A,{className:K.emptyIcon}),s().createElement("h2",{className:K.emptyTitle},"Welcome to IyziTrace AI"),s().createElement("p",{className:K.emptyDesc},"Ask me anything about your observability data, system health, or performance issues. I can analyze metrics, detect anomalies, and provide actionable recommendations."),s().createElement("div",{className:K.suggestedQuestions},["What services have the highest latency?","Are there any critical issues?","Show me error rate trends","Which services are degraded?","Analyze infrastructure health"].map((e,t)=>s().createElement("div",{key:t,className:K.suggestionChip,onClick:()=>o(e)},e)))):s().createElement(s().Fragment,null,e.map(e=>s().createElement("div",{key:e.id,className:`${K.message} ${"user"===e.role?K.userMessage:K.aiMessage}`},"ai"===e.role&&s().createElement("div",{className:`${K.messageAvatar} ${K.aiAvatar}`},s().createElement(E.A,null)),s().createElement("div",null,s().createElement("div",{className:`${K.messageBubble} ${"user"===e.role?K.userBubble:K.aiBubble}`},s().createElement("div",{className:K.messageContent},(e=>{let t=e.replace(/\*\*(.*?)\*\*/g,"<strong>$1</strong>").replace(/\*(.*?)\*/g,"<em>$1</em>").replace(/`(.*?)`/g,"<code>$1</code>").replace(/\n/g,"<br />");return s().createElement("div",{dangerouslySetInnerHTML:{__html:t}})})(e.content)),"ai"===e.role&&s().createElement(s().Fragment,null,e.tokens&&s().createElement("div",{className:K.messageMetadata},s().createElement("span",null,s().createElement(v.A,null)," ",e.tokens.totalTokens," tokens"),s().createElement("span",null,"•"),s().createElement("span",null,s().createElement(g.A,null)," ",e.timestamp.toLocaleTimeString())),s().createElement("div",{className:K.messageActions},s().createElement(r.Ay,{size:"small",icon:s().createElement(x.A,null),onClick:()=>{return t=e.content,navigator.clipboard.writeText(t),void l.Ay.success("Copied to clipboard!");var t},className:K.messageActionBtn},"Copy"))))),"user"===e.role&&s().createElement("div",{className:`${K.messageAvatar} ${K.userAvatar}`},"👤"))),N&&s().createElement("div",{className:`${K.message} ${K.aiMessage}`},s().createElement("div",{className:`${K.messageAvatar} ${K.aiAvatar}`},s().createElement(E.A,null)),s().createElement("div",{className:`${K.messageBubble} ${K.aiBubble}`},s().createElement("div",{className:K.loadingDots},s().createElement("span",null),s().createElement("span",null),s().createElement("span",null)))),s().createElement("div",{ref:le}))),s().createElement("div",{className:K.inputArea},s().createElement("div",{className:K.inputRow},s().createElement("div",{className:K.textAreaWrapper},s().createElement(q,{ref:ce,value:a,onChange:e=>o(e.target.value),onKeyPress:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),me())},placeholder:"Ask me anything about your observability data...",autoSize:{minRows:1,maxRows:4},disabled:N||!R,className:"ai-chat-input"})),N?s().createElement(r.Ay,{icon:s().createElement(f.A,null),onClick:()=>{(0,I.qX)(),P(!1),l.Ay.info("Request cancelled")},className:K.cancelButton}):s().createElement(r.Ay,{type:"primary",icon:s().createElement(w.A,null),onClick:me,disabled:!a.trim()||!R,className:K.sendButton}))))))))}},62661:(e,t,a)=>{function n(e,t,a,n,s,r,i){try{var o=e[r](i),l=o.value}catch(e){return void a(e)}o.done?t(l):Promise.resolve(l).then(n,s)}function s(e){return function(){var t=this,a=arguments;return new Promise(function(s,r){var i=e.apply(t,a);function o(e){n(i,s,r,o,l,"next",e)}function l(e){n(i,s,r,o,l,"throw",e)}o(void 0)})}}function r(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}a.d(t,{D$:()=>c,ai:()=>g,qX:()=>l});let i={apiKey:"",model:"deepseek/deepseek-chat",baseUrl:"https://openrouter.ai/api/v1",temperature:.7,maxTokens:150,timeout:1e4},o=null;const l=()=>{o&&(o.abort(),o=null)},c=e=>{if(!e.apiKey)throw new Error("AI Service: apiKey is required");i=function(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{},n=Object.keys(a);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(a).filter(function(e){return Object.getOwnPropertyDescriptor(a,e).enumerable}))),n.forEach(function(t){r(e,t,a[t])})}return e}({},i,e)},d=e=>Math.ceil(e.length/4),u=(e,t=5e3)=>{const a=e.filter(e=>{var t;return"error"===(null===(t=e.status)||void 0===t?void 0:t.value)}),n=e.filter(e=>{var t;return"degraded"===(null===(t=e.status)||void 0===t?void 0:t.value)}),s=e.filter(e=>{var t,a;return((null===(t=e.metrics)||void 0===t?void 0:t.p95DurationMs)||0)>1e3&&"error"!==(null===(a=e.status)||void 0===a?void 0:a.value)}),r=[...a.slice(0,5),...n.slice(0,5),...s.slice(0,5)];0===r.length&&r.push(...e.sort((e,t)=>{var a,n;return((null===(a=t.metrics)||void 0===a?void 0:a.avgDurationMs)||0)-((null===(n=e.metrics)||void 0===n?void 0:n.avgDurationMs)||0)}).slice(0,10));const i=r.map(e=>{var t,a,n,s,r,i;const o={name:e.name,status:null===(t=e.status)||void 0===t?void 0:t.value};return(null===(a=e.metrics)||void 0===a?void 0:a.avgDurationMs)&&(o.avgLatency=e.metrics.avgDurationMs),(null===(n=e.metrics)||void 0===n?void 0:n.p95DurationMs)&&e.metrics.p95DurationMs>500&&(o.p95=e.metrics.p95DurationMs),(null===(s=e.metrics)||void 0===s?void 0:s.p99DurationMs)&&e.metrics.p99DurationMs>1e3&&(o.p99=e.metrics.p99DurationMs),(null===(i=e.status)||void 0===i||null===(r=i.metrics)||void 0===r?void 0:r.errorPercentage)&&(o.errorRate=e.status.metrics.errorPercentage),o});let o=JSON.stringify(i,null,2);const l=`\nTotal Services: ${e.length} | Showing: ${i.length} (prioritized by issues)`;if(o=l+"\n"+o,d(o)>t){const e=i.slice(0,Math.min(10,i.length));o=l+"\n"+JSON.stringify(e,null,2)+"\n(... truncated to save tokens)"}return o},m=(e,t=1e4)=>{if(!e)return"";const a=[];let n=0;if(e.regions&&e.regions.length>0){const s="📍 **Regions Data:**\n"+((e,t=5e3)=>{const a=[];e.forEach(e=>{var t,n;const s=(null===(t=e.infrastructures)||void 0===t?void 0:t.length)||0,r=[];null===(n=e.infrastructures)||void 0===n||n.forEach(e=>{e.services&&r.push(...e.services)});const i=r.filter(e=>{var t;return"healthy"===(null===(t=e.status)||void 0===t?void 0:t.value)}).length,o=r.filter(e=>{var t;return"error"===(null===(t=e.status)||void 0===t?void 0:t.value)}).length,l=r.filter(e=>{var t;return"degraded"===(null===(t=e.status)||void 0===t?void 0:t.value)}).length,c=r.length>0?(r.reduce((e,t)=>{var a;return e+((null===(a=t.metrics)||void 0===a?void 0:a.avgDurationMs)||0)},0)/r.length).toFixed(2):0;if(o>0||l>0||parseFloat(c)>500||a.length<3){const t={region:e.name,infrastructures:s,services:{total:r.length,healthy:i},avgLatency:c};if(l>0&&(t.services.degraded=l),o>0&&(t.services.error=o),o>0||l>0){const e=r.filter(e=>{var t,a;return"error"===(null===(t=e.status)||void 0===t?void 0:t.value)||"degraded"===(null===(a=e.status)||void 0===a?void 0:a.value)}).slice(0,3).map(e=>{var t,a,n,s;return{name:e.name,status:null===(t=e.status)||void 0===t?void 0:t.value,latency:null===(a=e.metrics)||void 0===a?void 0:a.avgDurationMs,errorRate:null===(s=e.status)||void 0===s||null===(n=s.metrics)||void 0===n?void 0:n.errorPercentage}});e.length>0&&(t.issues=e)}a.push(t)}});let n=JSON.stringify(a,null,2);if(d(n)>t){const e=a.slice(0,Math.min(5,a.length));n=JSON.stringify(e,null,2)+"\n(... truncated to save tokens)"}return n})(e.regions,5e3),r=d(s);n+r<t&&(a.push(s),n+=r)}if(e.services&&e.services.length>0&&n<t){const s="🔧 **Services Data:**\n"+u(e.services,5e3),r=d(s);if(n+r<t)a.push(s),n+=r;else{const t="🔧 **Services Data:**\n"+u(e.services,2e3);a.push(t),n+=d(t)}}if(e.timeRange&&n<t&&a.push(`⏰ **Time Range:** ${e.timeRange.from} to ${e.timeRange.to}`),e.customData&&n<.8*t){const t=JSON.stringify(e.customData,null,2);d(t)<1e3&&a.push("📊 **Additional Data:**\n"+t)}return a.join("\n\n")},p="You are an observability AI for IyziTrace platform. Analyze metrics, traces, and service topology.\n\n**Guidelines:**\n- Prioritize errors, high latency (P95>1000ms), degraded services\n- Be specific: reference exact values, service names\n- Provide actionable recommendations\n- Use emojis: 🔴 critical, 🟡 warning, 🟢 healthy\n- Keep responses concise (2-4 paragraphs)\n\n**Response format:**\n1. Brief summary\n2. Key findings with severity\n3. Actionable recommendations",g=e=>s(function*(){const{prompt:t,context:a,maxTokens:n,temperature:r}=e;if(!t||0===t.trim().length)throw{message:"Prompt cannot be empty",code:"INVALID_PROMPT"};const c=d(p),u=d(t),g=n||i.maxTokens||150,f=3e4,v=f-c-u-g-1e3,x=m(a,Math.max(1e3,v)),h=x?`${t}\n\n---\n\n${x}`:t,b=c+d(h)+g;if(b>f)throw{message:`Request too large. Estimated ${b} tokens, limit is 30000. Try reducing the amount of data or being more specific in your question.`,code:"TOKEN_LIMIT_EXCEEDED",details:{estimated:b,limit:f}};const y=[{role:"system",content:p},{role:"user",content:h}];return yield((e,t)=>s(function*(){l(),o=new AbortController;const a=o.signal;if(!i.apiKey)throw{message:"AI Service not initialized. Call initAI() first.",code:"NOT_INITIALIZED"};const n=(null==t?void 0:t.maxTokens)||i.maxTokens,s=(null==t?void 0:t.temperature)||i.temperature,r={model:i.model,messages:e.map(e=>({role:e.role,content:e.content})),temperature:s,max_tokens:n,stream:!1};try{const e=setTimeout(()=>{l()},i.timeout),t=yield fetch(`${i.baseUrl}/chat/completions`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i.apiKey}`,"HTTP-Referer":window.location.origin,"X-Title":"IyziTrace Observability Platform"},body:JSON.stringify(r),signal:a});if(clearTimeout(e),o=null,!t.ok){var c,d;const e=yield t.json().catch(()=>({}));throw{message:(null===(c=e.error)||void 0===c?void 0:c.message)||`HTTP ${t.status}: ${t.statusText}`,code:(null===(d=e.error)||void 0===d?void 0:d.code)||"HTTP_ERROR",status:t.status,details:e}}const n=yield t.json();if(!n.choices||!n.choices[0]||!n.choices[0].message)throw{message:"Invalid response format from OpenRouter",code:"INVALID_RESPONSE",details:n};const s=n.choices[0].message.content,u=n.usage;return{content:s.trim(),usage:u?{promptTokens:u.prompt_tokens,completionTokens:u.completion_tokens,totalTokens:u.total_tokens}:void 0,model:n.model,finishReason:n.choices[0].finish_reason}}catch(e){if("AbortError"===e.name)throw{message:"Request was cancelled",code:"CANCELLED"};if("TimeoutError"===e.name)throw{message:"Request timed out",code:"TIMEOUT"};if(e.code)throw e;throw{message:e.message||"Unknown error occurred",code:"UNKNOWN_ERROR",details:e}}})())(y,{maxTokens:n,temperature:r})})()}}]);
//# sourceMappingURL=8848.js.map?_cache=89ba5839c4d8197cee74