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

89 lines (88 loc) 4.02 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ import t from "react"; import { AIPromptContent as v } from "../AIPromptContent.mjs"; import { useAIPromptContext as T } from "../AIPromptContext.mjs"; import { aIPromptNoOutputs as u, messages as P } from "../../messages/index.mjs"; import { AIPromptViewRender as k } from "./AIPromptViewRender.mjs"; import { Card as C, CardHeader as w, CardTitle as O, CardSubtitle as z, CardBody as f, CardActions as x } from "@progress/kendo-react-layout"; import { commentIcon as A, copyIcon as q, checkIcon as M, rotateIcon as F, thumbUpOutlineIcon as N, thumbDownOutlineIcon as S } from "@progress/kendo-svg-icons"; import { Button as o } from "@progress/kendo-react-buttons"; import { useLocalization as V } from "@progress/kendo-react-intl"; const _ = { name: "Output view", buttonText: "Output", buttonIcon: A }, K = (g) => { const [E, i] = t.useState(""), r = t.useRef(null), [n] = T(), { outputs: l, showOutputRating: y, outputCard: b } = g, { header: m, body: c, actions: s } = b || {}, h = V(), I = (e) => { n.onPromptRequest && n.onPromptRequest.call(null, e.prompt, { ...e, isRetry: !0 }), p(); }, R = (e) => { e != null && e.responseContent && navigator.clipboard.writeText(e.responseContent), i(e.id), setTimeout(() => { i(""); }, 1e3); }, d = (e, a) => { n.onPromptRequest && n.onPromptRequest.call(null, e.prompt, { ...e, ratingType: a, isRetry: !1 }), p(); }, p = () => { r && r.current && r.current.scrollTo({ top: 0, behavior: "smooth" }); }; return /* @__PURE__ */ t.createElement(k, { name: _.name }, /* @__PURE__ */ t.createElement(v, { ref: r }, /* @__PURE__ */ t.createElement("div", { className: "k-card-list" }, l && l.length > 0 ? l.map((e, a) => /* @__PURE__ */ t.createElement(C, { key: `${e.id}_${a}` }, /* @__PURE__ */ t.createElement(w, null, m ? m(e) : /* @__PURE__ */ t.createElement(t.Fragment, null, e.title && /* @__PURE__ */ t.createElement(O, null, e.title), e.subTitle && /* @__PURE__ */ t.createElement(z, null, e.subTitle))), /* @__PURE__ */ t.createElement(f, null, c ? c(e) : e.responseContent), /* @__PURE__ */ t.createElement(x, null, s ? s(e) : /* @__PURE__ */ t.createElement(t.Fragment, null, /* @__PURE__ */ t.createElement( o, { size: "medium", themeColor: "primary", fillMode: "flat", rounded: "medium", title: "Copy", svgIcon: E === e.id ? q : M, "aria-hidden": "true", onClick: () => R(e) }, "Copy" ), /* @__PURE__ */ t.createElement( o, { size: "medium", themeColor: "base", fillMode: "flat", rounded: "medium", title: "Retry", svgIcon: F, "aria-hidden": "true", onClick: () => I(e) }, "Retry" ), y && /* @__PURE__ */ t.createElement(t.Fragment, null, /* @__PURE__ */ t.createElement("span", { className: "k-spacer" }), /* @__PURE__ */ t.createElement( o, { size: "medium", themeColor: e.ratingType === "positive" ? "primary" : "base", fillMode: "flat", rounded: "medium", title: "Rate up", svgIcon: N, "aria-hidden": "true", onClick: () => d(e, "positive") } ), /* @__PURE__ */ t.createElement( o, { size: "medium", themeColor: e.ratingType === "negative" ? "primary" : "base", fillMode: "flat", rounded: "medium", title: "Rate down", svgIcon: S, "aria-hidden": "true", onClick: () => d(e, "negative") } )))))) : /* @__PURE__ */ t.createElement(C, null, /* @__PURE__ */ t.createElement(f, null, h.toLanguageString(u, P[u])))))); }; export { K as AIPromptOutputView, _ as outputViewDefaults };