@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 v } 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 M } from "./AIPromptViewRender.mjs";
import { AIPromptExpander as W } from "../AIPromptExpander.mjs";
import { useAIPromptContext as _ } 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: a
} = h, [r, s] = e.useState(S || ""), [n] = _(), [A, c] = d(P), [E, p] = d(x), I = () => {
n.onPromptRequest && n.onPromptRequest.call(null, r), s("");
}, T = (t) => {
s(t);
}, C = (t) => {
s(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: m, alternatives: g } = t;
if (m && g.length > 0) {
const b = g[0].transcript, k = (() => {
const l = r, B = l && !l.endsWith(" ") && !l.endsWith(`
`);
return l + (B ? " " : "") + b;
})();
s(k);
}
};
let i;
return o && (typeof o == "object" ? i = {
...o,
onResult: o.onResult || f
} : i = {
onResult: f
}), /* @__PURE__ */ e.createElement(M, { name: D.name }, /* @__PURE__ */ e.createElement(v, { streaming: n.streaming, onCancel: n.onCancel }, /* @__PURE__ */ e.createElement(
E,
{
value: r,
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", ...i }))) : void 0,
onChange: C,
...R
}
), a && a.length > 0 && /* @__PURE__ */ e.createElement(W, { title: "Prompt Suggestions" }, /* @__PURE__ */ e.createElement(
$,
{
suggestionsView: n.suggestionsView,
suggestions: a.map((t, m) => ({
id: m,
text: t,
description: t
})),
onSuggestionClick: (t) => {
T(t.text);
}
}
))), /* @__PURE__ */ e.createElement(y, null, /* @__PURE__ */ e.createElement(
A,
{
themeColor: "primary",
fillMode: "solid",
rounded: "full",
size: "medium",
onClick: I,
disabled: !r.trim(),
...u
},
u.children
)));
};
export {
oe as AIPromptView
};