UNPKG

@progress/kendo-react-conversational-ui

Version:

React Chat component allows the user to participate in chat sessions with users or chat bots. KendoReact Conversational UI components

9 lines (8 loc) 3.64 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),q=require("../AIPromptContent.js"),w=require("../AIPromptContext.js"),m=require("../../messages/index.js"),v=require("./AIPromptViewRender.js"),n=require("@progress/kendo-react-layout"),r=require("@progress/kendo-svg-icons"),a=require("@progress/kendo-react-buttons"),x=require("@progress/kendo-react-intl"),A=require("./constants.js"),O=g=>{const[y,d]=e.useState(""),o=e.useRef(null),[l]=w.useAIPromptContext(),{outputs:s,showOutputRating:R,outputCard:I}=g,{header:u,body:p,actions:C}=I||{},b=x.useLocalization(),h=t=>{l.onPromptRequest&&l.onPromptRequest.call(null,t.prompt,{...t,isRetry:!0}),E()},P=t=>{t!=null&&t.responseContent&&navigator.clipboard.writeText(t.responseContent),d(t.id),setTimeout(()=>{d("")},1e3)},k=(t,i)=>{l.onPromptRequest&&l.onPromptRequest.call(null,t.prompt,{...t,ratingType:i,isRetry:!1}),E()},E=()=>{o&&o.current&&o.current.scrollTo({top:0,behavior:"smooth"})},T=e.createElement(n.Card,null,e.createElement(n.CardHeader,null,e.createElement(n.CardTitle,null,e.createElement("span",{className:"k-skeleton k-skeleton-text k-skeleton-pulse",style:{width:"200px"}})),e.createElement(n.CardSubtitle,null,e.createElement("span",{className:"k-skeleton k-skeleton-text k-skeleton-pulse",style:{width:"100%"}}))),e.createElement(n.CardBody,null,e.createElement("span",{className:"k-skeleton k-skeleton-rect k-skeleton-pulse",style:{height:"80px"}})),e.createElement(n.CardActions,null,e.createElement("span",{className:"k-skeleton k-skeleton-text k-skeleton-pulse",style:{width:"100%"}}))),c=s==null?void 0:s.map((t,i)=>e.createElement(n.Card,{key:`${t.id}_${i}`},e.createElement(n.CardHeader,null,u?u(t):e.createElement(e.Fragment,null,t.title&&e.createElement(n.CardTitle,null,t.title),t.subTitle&&e.createElement(n.CardSubtitle,null,t.subTitle))),e.createElement(n.CardBody,null,p?p(t):t.responseContent),e.createElement(n.CardActions,null,C?C(t):e.createElement(e.Fragment,null,e.createElement(a.Button,{size:"medium",themeColor:"primary",fillMode:"flat",rounded:"medium",title:"Copy",svgIcon:y===t.id?r.checkIcon:r.copyIcon,onClick:()=>P(t)},"Copy"),e.createElement(a.Button,{size:"medium",themeColor:"base",fillMode:"flat",rounded:"medium",title:"Retry",svgIcon:r.arrowRotateCwIcon,onClick:()=>h(t)},"Retry"),R&&e.createElement(e.Fragment,null,e.createElement("span",{className:"k-spacer"}),e.createElement(a.Button,{size:"medium",themeColor:t.ratingType==="positive"?"primary":"base",fillMode:"flat",rounded:"medium",title:"Rate up",svgIcon:r.thumbUpOutlineIcon,onClick:()=>k(t,"positive")}),e.createElement(a.Button,{size:"medium",themeColor:t.ratingType==="negative"?"primary":"base",fillMode:"flat",rounded:"medium",title:"Rate down",svgIcon:r.thumbDownOutlineIcon,onClick:()=>k(t,"negative")})))))),f=e.createElement(n.Card,null,e.createElement(n.CardBody,null,b.toLanguageString(m.aIPromptNoOutputs,m.messages[m.aIPromptNoOutputs])));return e.createElement(v.AIPromptViewRender,{name:A.outputViewDefaults.name},e.createElement(q.AIPromptContent,{ref:o,streaming:l.streaming,onCancel:l.onCancel},e.createElement("div",{className:"k-card-list"},l.loading&&T,c,(!c||c.length===0)&&!l.loading&&f)))};exports.AIPromptOutputView=O;