@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
96 lines (95 loc) • 3.42 kB
JavaScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
import e from "react";
import { AIPromptContent as B } from "../AIPromptContent.mjs";
import { AIPromptFooter as y } from "../AIPromptFooter.mjs";
import { SpeechToTextButton as j, Button as q } from "@progress/kendo-react-buttons";
import { InputSeparator as z, InputSuffix as F, TextArea as G } from "@progress/kendo-react-inputs";
import { sparklesIcon as O } from "@progress/kendo-svg-icons";
import { useCustomComponent as d } from "@progress/kendo-react-common";
import { AIPromptViewRender as _ } from "./AIPromptViewRender.mjs";
import { AIPromptExpander as M } from "../AIPromptExpander.mjs";
import { useAIPromptContext as W } from "../AIPromptContext.mjs";
import { SuggestionGroup as $ } from "../../chat/components/SuggestionsGroup.mjs";
import { promptViewDefaults as D } from "./constants.mjs";
const oe = (h) => {
const {
promptInput: x = G,
generateButton: P = q,
enableSpeechToText: o = !1,
promptValue: S,
promptSuggestions: i
} = h, [s, l] = e.useState(S || ""), [n] = W(), [A, c] = d(P), [E, p] = d(x), I = () => {
n.onPromptRequest && n.onPromptRequest.call(null, s), l("");
}, T = (t) => {
l(t);
}, C = (t) => {
l(t.target.value);
}, V = {
title: "Generate",
children: "Generate",
svgIcon: O
}, w = {
placeholder: "Ask or generate content with AI ...",
rows: 2
}, u = Object.keys(c).length > 0 ? c : V, R = Object.keys(p).length > 0 ? p : w, f = (t) => {
const { isFinal: r, alternatives: g } = t;
if (r && g.length > 0) {
const b = g[0].transcript, k = (() => {
const a = s, v = a && !a.endsWith(" ") && !a.endsWith(`
`);
return a + (v ? " " : "") + b;
})();
l(k);
}
};
let m;
return o && (typeof o == "object" ? m = {
...o,
onResult: o.onResult || f
} : m = {
onResult: f
}), /* @__PURE__ */ e.createElement(_, { name: D.name }, /* @__PURE__ */ e.createElement(B, { streaming: n.streaming, onCancel: n.onCancel }, /* @__PURE__ */ e.createElement(
E,
{
value: s,
className: "!k-flex-col",
suffix: o ? /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(z, { orientation: "horizontal" }), /* @__PURE__ */ e.createElement(F, { orientation: "horizontal" }, /* @__PURE__ */ e.createElement(j, { fillMode: "flat", ...m }))) : void 0,
onChange: C,
...R
}
), i && i.length > 0 && /* @__PURE__ */ e.createElement(M, { title: "Prompt Suggestions" }, /* @__PURE__ */ e.createElement(
$,
{
suggestionsView: n.suggestionsView,
suggestions: i.map((t, r) => ({
id: r,
text: t,
description: t
})),
onSuggestionClick: (t, r) => {
T(r.text);
}
}
))), /* @__PURE__ */ e.createElement(y, null, /* @__PURE__ */ e.createElement(
A,
{
themeColor: "primary",
fillMode: "solid",
rounded: "full",
size: "medium",
onClick: I,
disabled: !s.trim(),
...u
},
u.children
)));
};
export {
oe as AIPromptView
};