UNPKG

mongodb-chatbot-ui

Version:

UI React components for the MongoDB Chatbot Framework

148 lines (146 loc) 4.21 kB
import { j as e } from "./jsx-runtime.js"; import { c as L } from "./Transition.js"; import { F as N, a as z, M as B, x as O } from "./MessageContent2.js"; import { P, h } from "./index14.js"; import { useContext as T, lazy as b, useState as d, Fragment as W, Suspense as v } from "react"; import { a as H, g as I } from "./messageLinks.js"; import { useChatbotContext as q } from "./useChatbotContext.js"; import { u as G } from "./useLinkData.js"; import "./index2.js"; import "react-dom"; import "./index4.js"; import "./OpenNewTab.js"; import "./index5.js"; import "./index18.js"; import "./X.js"; import "./index8.js"; import "./index9.js"; import "./index10.js"; import "./Warning.js"; import "./ChevronDown.js"; import "./index16.js"; import "./index7.js"; import "./index11.js"; import "./index19.js"; import "./index12.js"; import "./index15.js"; import "./utils.js"; import "./ChatbotProvider.js"; import "./LinkDataProvider.js"; function J() { return T(H); } const K = b(async () => ({ default: (await import("./MessageRating.js")).MessageRatingWithFeedbackComment })), Q = b(async () => ({ default: (await import("./MessagePrompts.js")).MessagePrompts })), X = () => /* @__PURE__ */ e.jsx( O, { className: L` width: 100%; min-width: 120px; & > div { width: 100%; } ` } ); function Y(t, i) { return { isSender: t.role === "user", senderName: t.role === "user" ? i == null ? void 0 : i.name : "Mongo", avatarVariant: t.role === "user" ? h.User : h.Mongo }; } const Rt = ({ messageData: t, suggestedPrompts: i = [], showSuggestedPrompts: x = !0, canSubmitSuggestedPrompt: M = () => !0, onReferenceClick: C, onSuggestedPromptClick: n, isLoading: u, showRating: k, conversation: p, bottomContent: w }) => { var g; const { maxCommentCharacters: j } = q(), R = J(), o = Y(t, R), [c, l] = d("none"), [y, s] = d(), [f, S] = d(void 0); async function F(r) { if (r) try { await p.commentMessage(t.id, r), l("submitted"), S(t.rating ? "liked" : "disliked"), s(void 0); } catch { s( "Oops, there was an issue submitting the response to the server. Please try again." ); } } function E() { l("abandoned"); } const a = (g = t.metadata) == null ? void 0 : g.verifiedAnswer, U = a ? { verifier: "MongoDB Staff", verifiedAt: new Date(a.updated ?? a.created) } : void 0, { tck: V } = G(), A = I(t, { tck: V, onReferenceClick: C }); return /* @__PURE__ */ e.jsxs(W, { children: [ /* @__PURE__ */ e.jsxs( N, { baseFontSize: 16, isSender: o.isSender, avatar: /* @__PURE__ */ e.jsx(P, { variant: o.avatarVariant, name: o.senderName }), sourceType: u ? void 0 : z.Markdown, messageBody: t.content, verified: U, links: A, componentOverrides: { MessageContent: B }, children: [ u ? /* @__PURE__ */ e.jsx(X, {}) : null, /* @__PURE__ */ e.jsx(v, { fallback: null, children: k ? /* @__PURE__ */ e.jsx( K, { submit: F, abandon: E, status: c, errorMessage: y, clearErrorMessage: () => s(void 0), maxCommentCharacterCount: j, messageRatingProps: { value: t.rating === void 0 ? void 0 : t.rating ? "liked" : "disliked", description: "How was the response?", hideThumbsUp: f === "disliked", hideThumbsDown: f === "liked", onChange: async (r) => { const m = r.target.value; m && c !== "submitted" && await p.rateMessage( t.id, m === "liked" ); } } } ) : null }), w ?? null ] } ), /* @__PURE__ */ e.jsx(v, { fallback: null, children: x && /* @__PURE__ */ e.jsx( Q, { prompts: i, onPromptClick: (r) => { n == null || n(r); }, canSubmit: M } ) }) ] }, t.id); }; export { Rt as Message };