/*! Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one or more contributor license agreements. * Licensed under the Elastic License 2.0; you may not use this file except in compliance with the Elastic License 2.0. */ (window.observabilityAIAssistant_bundle_jsonpfunction=window.observabilityAIAssistant_bundle_jsonpfunction||[]).push([[5],{107:function(e,t,s){"use strict";s.r(t),s.d(t,"Insight",(function(){return P}));var n=s(0),i=s.n(n),a=s(18),o=s(3),c=s(22),l=s(11),r=s(44),u=s(38),b=s(39),j=s(47),d=s(42),O=s(6),x=s(41),g=s(45),m=s(60),p=s(4),v=s.n(p),h=s(5),f=s(1);function A(e){return Object(f.jsx)(o.EuiButton,v()({"data-test-subj":"observabilityAiAssistantStartChatButton",fill:!0,iconType:"discuss",size:"s"},e),h.i18n.translate("xpack.observabilityAiAssistant.insight.response.startChat",{defaultMessage:"Start chat"}))}var C=s(61),E=s(48),y=s(55),I=s(66);function S(e){return Object(f.jsx)(i.a.Fragment,null,e.body,e.error?Object(f.jsx)(i.a.Fragment,null,e.body?Object(f.jsx)(o.EuiSpacer,{size:"xs"}):null,Object(f.jsx)(I.a,null)):null,e.controls?Object(f.jsx)(i.a.Fragment,null,Object(f.jsx)(o.EuiSpacer,{size:"m"}),Object(f.jsx)(o.EuiHorizontalRule,{margin:"none"}),Object(f.jsx)(o.EuiSpacer,{size:"s"}),e.controls):null)}var w=s(65);function k(e){return Object(f.jsx)(o.EuiCallOut,{title:h.i18n.translate("xpack.observabilityAiAssistant.missingCredentialsCallout.title",{defaultMessage:"Missing credentials"}),color:"primary",iconType:"iInCircle"},h.i18n.translate("xpack.observabilityAiAssistant.missingCredentialsCallout.description",{defaultMessage:"You haven’t authorised OpenAI in order to generate responses from the Elastic Assistant. Authorise the model in order to proceed."}),Object(f.jsx)(o.EuiSpacer,{size:"m"}),Object(f.jsx)(o.EuiButton,{"data-test-subj":"observabilityAiAssistantMissingCredentialsCalloutConnectAssistantButton",fill:!0,color:"primary",href:e.connectorsManagementHref},h.i18n.translate("xpack.observabilityAiAssistant.missingCredentialsCallout.buttonLabel",{defaultMessage:"Connect Assistant"})))}var F=s(46),M=s(54),z={name:"1lztzw8",styles:"margin-top:2px;margin-bottom:1px"},T={name:"xyzkeb",styles:"align-self:flex-start"};function B({title:e,description:t=h.i18n.translate("xpack.observabilityAiAssistant.insight.defaultDescription",{defaultMessage:"Get helpful insights from our Elastic AI Assistant."}),controls:s,children:i,actions:a,onToggle:c,loading:l}){const{euiTheme:r}=Object(o.useEuiTheme)(),[u,b]=Object(n.useState)(!1),j=()=>{b(!u)};return Object(f.jsx)(o.EuiPanel,{hasBorder:!0,hasShadow:!1},Object(f.jsx)(o.EuiAccordion,{id:"obsAiAssistantInsight",arrowProps:{css:{alignSelf:"flex-start"}},buttonContent:Object(f.jsx)(o.EuiFlexGroup,{wrap:!0,responsive:!1,gutterSize:"m"},Object(f.jsx)(o.EuiFlexItem,{grow:!1},Object(f.jsx)(o.EuiSpacer,{size:"xs"}),Object(f.jsx)(F.a,{size:"xs"})),Object(f.jsx)(o.EuiFlexItem,null,Object(f.jsx)(o.EuiText,{css:z},Object(f.jsx)("h5",null,e)),Object(f.jsx)(o.EuiText,{size:"s",css:Object(f.css)({color:r.colors.subduedText},"","")},Object(f.jsx)("span",null,t)))),isLoading:l,isDisabled:l,extraAction:null!=a&&a.length||s?Object(f.jsx)(o.EuiFlexGroup,{direction:"row",gutterSize:"s",responsive:!1},s&&Object(f.jsx)(o.EuiFlexItem,{grow:!1},s),null!=a&&a.length?Object(f.jsx)(o.EuiFlexItem,null,Object(f.jsx)(o.EuiPopover,{anchorPosition:"downLeft",button:Object(f.jsx)(o.EuiButtonIcon,{"aria-label":h.i18n.translate("xpack.observabilityAiAssistant.insight.actions",{defaultMessage:"Actions"}),color:"text",css:T,"data-test-subj":"observabilityAiAssistantInsightBaseButtonIcon",disabled:0===(null==a?void 0:a.length),display:"empty",iconType:"boxesHorizontal",size:"s",onClick:j}),panelPaddingSize:"s",closePopover:j,isOpen:u},Object(f.jsx)(o.EuiContextMenuPanel,{size:"s",items:null==a?void 0:a.map((({id:e,icon:t,label:s,handler:n})=>Object(f.jsx)(o.EuiContextMenuItem,{key:e,icon:t,onClick:n},s)))}))):null):null,onToggle:c},Object(f.jsx)(o.EuiSpacer,{size:"m"}),Object(f.jsx)(M.a,null),Object(f.jsx)(o.EuiPanel,{hasBorder:!1,hasShadow:!1,color:"subdued"},i)))}function L({title:e,initialMessages:t,connectorId:s}){var r,u;const b=Object(x.a)(),[d,O]=Object(n.useState)(),[g,p]=Object(n.useState)(!1),[v,h]=Object(n.useState)(),[y,I]=Object(n.useState)(),{conversation:k,displayedMessages:F,setDisplayedMessages:M,save:z,saveTitle:T}=Object(j.a)({conversationId:y,connectorId:s,chatService:b}),B=y?(null===(r=k.value)||void 0===r?void 0:r.conversation.title)||"":e,L=Object(n.useCallback)((()=>{let e;p(!0);const n=b.chat({messages:t,connectorId:s,function:"none"}).subscribe({next:t=>{e=t,O((()=>t))},complete:()=>{M((t=>t.concat({"@timestamp":(new Date).toISOString(),message:{...e.message}}))),p(!1)}});h(n)}),[t,M,s,b]);Object(n.useEffect)((()=>{L()}),[L]),Object(n.useEffect)((()=>{M(t)}),[t,M]);const[P,D]=Object(n.useState)(!1),G=Object(n.useMemo)((()=>d?F.concat({"@timestamp":(new Date).toISOString(),message:{...d.message}}):F),[d,F]),H=Object(a.last)(G);return Object(f.jsx)(i.a.Fragment,null,Object(f.jsx)(S,{body:Object(f.jsx)(w.a,{content:null!==(u=null==H?void 0:H.message.content)&&void 0!==u?u:"",loading:g}),error:null==d?void 0:d.error,controls:g?Object(f.jsx)(C.a,{onClick:()=>{null==v||v.unsubscribe(),p(!1),M((e=>e.concat({"@timestamp":(new Date).toISOString(),message:{...d.message}}))),O((e=>({message:{role:l.a.Assistant,...null==e?void 0:e.message},aborted:!0,error:new c.AbortError})))}}):Object(f.jsx)(o.EuiFlexGroup,{direction:"row"},Object(f.jsx)(o.EuiFlexItem,{grow:!1},Object(f.jsx)(m.a,{onClick:()=>{L()}})),Object(f.jsx)(o.EuiFlexItem,{grow:!1},Object(f.jsx)(A,{onClick:()=>{D((()=>!0))}})))}),Object(f.jsx)(E.a,{title:B,isOpen:P,onClose:()=>{D((()=>!1))},messages:F,conversationId:y,startedFrom:"contextualInsight",onChatComplete:e=>{z(e).then((e=>{I(e.conversation.id)})).catch((()=>{}))},onChatUpdate:e=>{M(e)},onChatTitleSave:e=>{T(e)}}))}function P({messages:e,title:t}){var s;const[i,a]=Object(n.useState)(!1),o=Object(d.a)(),c=Object(O.a)(),l=Object(b.a)((({signal:e})=>c.start({signal:e})),[c]),{services:{http:j}}=Object(u.a)();let x=null;return i&&o.selectedConnector?x=Object(f.jsx)(L,{title:t,initialMessages:e,connectorId:o.selectedConnector}):o.loading||null!==(s=o.connectors)&&void 0!==s&&s.length||(x=Object(f.jsx)(k,{connectorsManagementHref:Object(g.a)(j)})),Object(f.jsx)(B,{title:t,onToggle:e=>{a((t=>t||e))},controls:Object(f.jsx)(y.a,o),loading:o.loading||l.loading},l.value?Object(f.jsx)(r.b,{value:l.value},x):null)}},48:function(e,t,s){"use strict";s.d(t,"a",(function(){return m}));var n=s(1),i=s(3),a=s(36),o=s(5),c=(s(0),s(49)),l=s(42),r=s(38),u=s(50),b=s(51),j=s(45),d=s(56),O=s(58);const x=Object(a.css)({name:"1hs1hlf",styles:"max-height:100%"}),g=Object(a.css)({name:"umwchj",styles:"overflow-y:auto"});function m({title:e,messages:t,conversationId:s,isOpen:a,startedFrom:m,onClose:p,onChatUpdate:v,onChatComplete:h,onChatTitleSave:f}){const{euiTheme:A}=Object(i.useEuiTheme)(),{services:{http:C}}=Object(r.a)(),E=Object(c.a)(),y=Object(l.a)(),I=Object(b.a)(),S=Object(u.a)();return a?Object(n.jsx)(i.EuiFlyout,{onClose:p},Object(n.jsx)(i.EuiFlexGroup,{responsive:!1,gutterSize:"none",direction:"column",className:x},Object(n.jsx)(i.EuiFlexItem,{grow:!1},Object(n.jsx)(i.EuiPanel,{hasShadow:!1,hasBorder:!1,borderRadius:"none",css:Object(n.css)({borderBottom:`solid 1px ${A.border.color}`},"","")},s?Object(n.jsx)(i.EuiLink,{"data-test-subj":"observabilityAiAssistantChatFlyoutOpenConversationLink",href:I.link("/conversations/{conversationId}",{path:{conversationId:s}})},o.i18n.translate("xpack.observabilityAiAssistant.conversationDeepLinkLabel",{defaultMessage:"Open conversation"})):Object(n.jsx)(i.EuiLink,{"data-test-subj":"observabilityAiAssistantChatFlyoutGoToConversationsLink",href:I.link("/conversations/new")},o.i18n.translate("xpack.observabilityAiAssistant.conversationListDeepLinkLabel",{defaultMessage:"Go to conversations"})))),Object(n.jsx)(i.EuiFlexItem,{grow:!0,className:g},Object(n.jsx)(O.a,{loading:!1,connectors:y,title:e,messages:t,currentUser:E,connectorsManagementHref:Object(j.a)(C),modelsManagementHref:Object(d.a)(C),conversationId:s,knowledgeBase:S,startedFrom:m,onChatUpdate:e=>{v&&v(e)},onChatComplete:e=>{h&&h(e)},onSaveTitle:e=>{f(e)}})))):null}}}]);