UNPKG

@assistant-ui/react

Version:

React components for AI chat.

68 lines (67 loc) 2.88 kB
"use strict"; "use client"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/primitive-hooks/message/useMessageIf.tsx var useMessageIf_exports = {}; __export(useMessageIf_exports, { useMessageIf: () => useMessageIf }); module.exports = __toCommonJS(useMessageIf_exports); var import_MessageContext = require("../../context/react/MessageContext.cjs"); var import_useCombinedStore = require("../../utils/combined/useCombinedStore.cjs"); var useMessageIf = (props) => { const messageRuntime = (0, import_MessageContext.useMessageRuntime)(); const messageUtilsStore = (0, import_MessageContext.useMessageUtilsStore)(); return (0, import_useCombinedStore.useCombinedStore)( [messageRuntime, messageUtilsStore], ({ role, attachments, content, branchCount, isLast, speech, submittedFeedback }, { isCopied, isHovering }) => { if (props.hasBranches === true && branchCount < 2) return false; if (props.user && role !== "user") return false; if (props.assistant && role !== "assistant") return false; if (props.system && role !== "system") return false; if (props.lastOrHover === true && !isHovering && !isLast) return false; if (props.copied === true && !isCopied) return false; if (props.copied === false && isCopied) return false; if (props.speaking === true && speech == null) return false; if (props.speaking === false && speech != null) return false; if (props.hasAttachments === true && (role !== "user" || !attachments.length)) return false; if (props.hasAttachments === false && role === "user" && !!attachments.length) return false; if (props.hasContent === true && content.length === 0) return false; if (props.hasContent === false && content.length > 0) return false; if (props.submittedFeedback !== void 0 && (submittedFeedback?.type ?? null) !== props.submittedFeedback) return false; return true; } ); }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { useMessageIf }); //# sourceMappingURL=useMessageIf.js.map