@assistant-ui/react
Version:
Typescript/React library for AI Chat
76 lines (75 loc) • 3.07 kB
JavaScript
"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/primitives/message/MessageIf.tsx
var MessageIf_exports = {};
__export(MessageIf_exports, {
MessagePrimitiveIf: () => MessagePrimitiveIf
});
module.exports = __toCommonJS(MessageIf_exports);
var import_MessageContext = require("../../context/react/MessageContext.js");
var import_useCombinedStore = require("../../utils/combined/useCombinedStore.js");
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;
}
);
};
var MessagePrimitiveIf = ({
children,
...query
}) => {
const result = useMessageIf(query);
return result ? children : null;
};
MessagePrimitiveIf.displayName = "MessagePrimitive.If";
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
MessagePrimitiveIf
});
//# sourceMappingURL=MessageIf.js.map
;