Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const require_chunk = require("../../chunk-CKQMccvm.cjs");
const require_LayoutContext = require("../../LayoutContext-qUdkWJWV.cjs");
const require_ArtifactOverlay = require("../../ArtifactOverlay-7Tt6OY58.cjs");
const require_BottomTray = require("../../BottomTray-D1uGQccU.cjs");
const require_components_IconButton_index = require("../IconButton/index.cjs");
const require_ThemeProvider = require("../../ThemeProvider-0ytg6ico.cjs");
const require_ToolCall = require("../../ToolCall-BXicKrtH.cjs");
const require_ToolResult = require("../../ToolResult-CeQt4t3K.cjs");
const require_components_Button_index = require("../Button/index.cjs");
const require_CopilotShell = require("../../CopilotShell-CinO8LKZ.cjs");
const require_components_Input_index = require("../Input/index.cjs");
const require_Shell = require("../../Shell-CXCVPlSX.cjs");
let clsx = require("clsx");
clsx = require_chunk.__toESM(clsx);
let lucide_react = require("lucide-react");
let react = require("react");
react = require_chunk.__toESM(react);
let react_jsx_runtime = require("react/jsx-runtime");
let _openuidev_react_headless = require("@openuidev/react-headless");
let _radix_ui_react_dialog = require("@radix-ui/react-dialog");
_radix_ui_react_dialog = require_chunk.__toESM(_radix_ui_react_dialog);
let _openuidev_react_lang = require("@openuidev/react-lang");
//#region src/components/OpenUIChat/CustomComposerAdapter.tsx
const CustomComposerAdapter = ({ composer: Composer }) => {
	const processMessage = (0, _openuidev_react_headless.useThread)((s) => s.processMessage);
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Composer, {
		onSend: (message) => {
			processMessage({
				role: "user",
				content: message
			});
		},
		onCancel: (0, _openuidev_react_headless.useThread)((s) => s.cancelMessage),
		isRunning: (0, _openuidev_react_headless.useThread)((s) => s.isRunning),
		isLoadingMessages: (0, _openuidev_react_headless.useThread)((s) => s.isLoadingMessages)
	});
};
//#endregion
//#region src/components/OpenUIChat/ShareThreadModal.tsx
const getErrorMessage = (error) => {
	if (error instanceof DOMException && error.name === "NotAllowedError") return "Clipboard access denied. Please allow clipboard access in your browser settings, or copy the link manually from the text area above.";
	else if (error instanceof DOMException && error.name === "NotSupportedError") return "Clipboard not supported. Please copy the link manually from the text area above.";
	else return "Failed to copy to clipboard. Please copy the link manually from the text area above.";
};
/**
* Modal dialog for generating and copying a shareable link.
*
* @category Components
*/
const ShareThreadModal = (0, react.forwardRef)(({ title, trigger, generateLink, themeClassName }, _ref) => {
	const { portalThemeClassName } = require_ThemeProvider.useTheme();
	const { layout } = require_LayoutContext.useLayoutContext() || {};
	const isMobile = layout === "mobile";
	const [isOpen, setIsOpen] = (0, react.useState)(false);
	const [isLoading, setIsLoading] = (0, react.useState)(false);
	const [generatedLink, setGeneratedLink] = (0, react.useState)(null);
	const [hasCopied, setHasCopied] = (0, react.useState)(false);
	const [clipboardError, setClipboardError] = (0, react.useState)(null);
	const handleGenerateLink = (0, react.useCallback)(async () => {
		setIsLoading(true);
		try {
			setGeneratedLink(await generateLink());
		} catch (_error) {
			console.error(_error);
		} finally {
			setIsLoading(false);
		}
	}, [generateLink]);
	const handleCopy = (0, react.useCallback)(async () => {
		if (!generatedLink) return;
		setClipboardError(null);
		if (!navigator.clipboard) {
			setClipboardError("Clipboard access not available. Please copy the link manually from the text area above.");
			return;
		}
		try {
			await navigator.clipboard.writeText(generatedLink);
			setHasCopied(true);
			setTimeout(() => setHasCopied(false), 2e3);
		} catch (error) {
			console.warn("Copy to clipboard failed:", error);
			setClipboardError(getErrorMessage(error));
		}
	}, [generatedLink]);
	const handleOnOpenChange = (0, react.useCallback)((open) => {
		setIsOpen(open);
		if (!open) setTimeout(() => {
			setIsLoading(false);
			setGeneratedLink(null);
			setHasCopied(false);
			setClipboardError(null);
		}, 300);
	}, []);
	const renderActionButton = () => {
		if (isLoading) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_components_Button_index.Button, {
			onClick: handleCopy,
			size: "medium",
			disabled: true,
			children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Loader2, { className: "openui-share-thread-modal__loading-icon" }), "Generating..."]
		});
		if (generatedLink) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_components_Button_index.Button, {
			onClick: handleCopy,
			size: "medium",
			children: [hasCopied ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Check, {}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Copy, {}), hasCopied ? "Copied!" : "Copy link"]
		});
		return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_components_Button_index.Button, {
			onClick: handleGenerateLink,
			size: "medium",
			children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Link, {}), "Generate link"]
		});
	};
	return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_radix_ui_react_dialog.Root, {
		open: isOpen,
		onOpenChange: handleOnOpenChange,
		children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dialog.Trigger, {
			asChild: true,
			children: trigger
		}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_radix_ui_react_dialog.Portal, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dialog.Overlay, { className: (0, clsx.default)("openui-share-thread-modal__overlay", themeClassName || portalThemeClassName) }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_radix_ui_react_dialog.Content, {
			className: (0, clsx.default)("openui-share-thread-modal__content", isMobile ? "openui-share-thread-modal__content--mobile" : "", themeClassName || portalThemeClassName),
			children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
				className: "openui-share-thread-modal__header",
				children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dialog.Title, {
					className: "openui-share-thread-modal__title",
					children: title ?? "Share chat"
				}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_IconButton_index.IconButton, {
					icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.X, {}),
					variant: "tertiary",
					size: "small",
					onClick: () => handleOnOpenChange(false),
					className: "openui-share-thread-modal__close-button"
				})]
			}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
				className: "openui-share-thread-modal__body",
				children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
					className: "openui-share-thread-modal__description",
					children: "This conversation may include personal information. Take a moment to check the content before sharing the link."
				}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
					className: "openui-share-thread-modal__input-section",
					children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
						className: "openui-share-thread-modal__input-wrapper",
						children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_Input_index.Input, {
							value: generatedLink || "",
							placeholder: generatedLink ? "" : "Click \"Generate link\" to create a shareable link",
							readOnly: true,
							className: "openui-share-thread-modal__input"
						}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
							className: "openui-share-thread-modal__button-container",
							children: renderActionButton()
						})]
					}), clipboardError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
						className: "openui-share-thread-modal__error-message",
						children: clipboardError
					})]
				})]
			})]
		})] })]
	});
});
ShareThreadModal.displayName = "ShareThreadModal";
//#endregion
//#region src/components/OpenUIChat/useShareThread.ts
/**
* Hook for sharing conversation threads by threadId.
* The consumer's backend looks up messages by threadId.
*
* @category Hooks
*/
const useShareThread = ({ generateShareLink }) => {
	const { isRunning, isLoadingMessages, messages } = (0, _openuidev_react_headless.useThread)();
	const { selectedThreadId } = (0, _openuidev_react_headless.useThreadList)();
	const getShareThreadLink = (0, react.useCallback)(async () => {
		if (!selectedThreadId) throw new Error("No thread selected");
		return generateShareLink(selectedThreadId);
	}, [generateShareLink, selectedThreadId]);
	return {
		shouldDisableShareButton: isRunning || isLoadingMessages || !selectedThreadId,
		hasMessages: messages.length > 0,
		getShareThreadLink
	};
};
//#endregion
//#region src/components/OpenUIChat/ShareThread.tsx
/**
* Share button that opens a modal for generating and copying a shareable link.
* Renders nothing when there are no messages to share.
*
* @category Components
*/
const ShareThread = ({ generateShareLink, modalTitle, customTrigger }) => {
	const { layout } = require_LayoutContext.useLayoutContext() || {};
	const isMobile = layout === "mobile";
	const { portalThemeClassName } = require_ThemeProvider.useTheme();
	const { hasMessages, getShareThreadLink, shouldDisableShareButton } = useShareThread({ generateShareLink });
	if (!hasMessages) return null;
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ShareThreadModal, {
		title: modalTitle,
		trigger: customTrigger ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefaultShareButton, {
			isMobile,
			shouldDisableShareButton
		}),
		generateLink: getShareThreadLink,
		themeClassName: portalThemeClassName
	});
};
ShareThread.displayName = "ShareThread";
const DefaultShareButton = react.default.forwardRef(({ isMobile, shouldDisableShareButton, ...props }, ref) => {
	return isMobile ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_IconButton_index.IconButton, {
		ref,
		size: "medium",
		icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Share2, { size: "1em" }),
		variant: "secondary",
		disabled: shouldDisableShareButton,
		...props
	}) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_components_Button_index.Button, {
		ref,
		variant: "secondary",
		disabled: shouldDisableShareButton,
		...props,
		children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Share2, {}), "Share"]
	});
});
DefaultShareButton.displayName = "DefaultShareButton";
//#endregion
//#region src/components/OpenUIChat/utils/index.ts
/**
* Type guard to check if a WelcomeMessageConfig is a custom React component.
*
* Use this to differentiate between a custom component and a props-based
* configuration when rendering the welcome message.
*
* @param config - The welcome message configuration to check
* @returns `true` if config is a React component, `false` if it's a props object
*
* @example
* if (isWelcomeComponent(welcomeMessage)) {
*   // welcomeMessage is a React.ComponentType
*   const CustomWelcome = welcomeMessage;
*   return <CustomWelcome />;
* } else {
*   // welcomeMessage is { title?, description?, image? }
*   return <WelcomeScreen {...welcomeMessage} />;
* }
*/
const isWelcomeComponent = (config) => {
	return typeof config === "function";
};
//#endregion
//#region src/components/OpenUIChat/GenUIAssistantMessage.tsx
const GenUIAssistantMessage = ({ message, library }) => {
	const messages = (0, _openuidev_react_headless.useThread)((s) => s.messages);
	const isRunning = (0, _openuidev_react_headless.useThread)((s) => s.isRunning);
	const processMessage = (0, _openuidev_react_headless.useThread)((s) => s.processMessage);
	const updateMessage = (0, _openuidev_react_headless.useThread)((s) => s.updateMessage);
	const isStreaming = (0, react.useMemo)(() => {
		if (!isRunning) return false;
		for (let i = messages.length - 1; i >= 0; i--) if (messages[i]?.role === "assistant") return messages[i]?.id === message.id;
		return false;
	}, [
		isRunning,
		messages,
		message.id
	]);
	const { content: openuiCode, contextString } = (0, react.useMemo)(() => {
		if (!message.content) return {
			content: null,
			contextString: null
		};
		return require_Shell.separateContentAndContext(message.content);
	}, [message.content]);
	const initialState = (0, react.useMemo)(() => {
		if (!contextString) return void 0;
		try {
			const parsed = JSON.parse(contextString);
			if (Array.isArray(parsed) && typeof parsed[0] === "object") return parsed[0];
			if (typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
			return;
		} catch {
			return;
		}
	}, [contextString]);
	const toolMessages = (0, react.useMemo)(() => {
		const result = [];
		const msgIndex = messages.findIndex((m) => m.id === message.id);
		if (msgIndex !== -1) for (let i = msgIndex + 1; i < messages.length; i++) {
			const m = messages[i];
			if (m && m.role === "tool") result.push(m);
			else break;
		}
		return result;
	}, [messages, message.id]);
	const getToolName = (toolCallId) => {
		return (message.toolCalls?.find((tc) => tc.id === toolCallId))?.function.name;
	};
	const handleStateUpdate = (0, react.useCallback)((state) => {
		const code = openuiCode ?? "";
		const contextJson = JSON.stringify([state]);
		const fullMessage = code + "\n" + require_Shell.wrapContext(contextJson);
		updateMessage({
			...message,
			content: fullMessage
		});
	}, [
		updateMessage,
		message,
		openuiCode
	]);
	const handleAction = (0, react.useCallback)((event) => {
		if (event.type === _openuidev_react_lang.BuiltinActionType.ContinueConversation) {
			const contentPart = event.humanFriendlyMessage ? require_Shell.wrapContent(event.humanFriendlyMessage) : "";
			const messageCtx = [`User clicked: ${event.humanFriendlyMessage}`];
			if (event.formState) messageCtx.push(event.formState);
			processMessage({
				role: "user",
				content: `${contentPart}${require_Shell.wrapContext(JSON.stringify(messageCtx))}`
			});
		} else if (event.type === _openuidev_react_lang.BuiltinActionType.OpenUrl) {
			const url = event.params?.["url"];
			if (typeof window !== "undefined" && url) window.open(url, "_blank");
		}
	}, [processMessage]);
	return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_Shell.AssistantMessageContainer, { children: [(message.toolCalls && message.toolCalls.length > 0 || toolMessages.length > 0) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_ToolCall.BehindTheScenes, {
		isStreaming,
		toolCallsComplete: !!message.content,
		children: [message.toolCalls?.map((toolCall, idx) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ToolCall.ToolCallComponent, {
			toolCall,
			isStreaming,
			toolsDone: !!message.content,
			isLast: idx === (message.toolCalls?.length ?? 0) - 1 && toolMessages.length === 0
		}, toolCall.id)), toolMessages.map((tm) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ToolResult.ToolResult, {
			message: tm,
			toolName: getToolName(tm.toolCallId)
		}, tm.id))]
	}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_openuidev_react_lang.Renderer, {
		response: openuiCode,
		library,
		isStreaming,
		onAction: handleAction,
		onStateUpdate: handleStateUpdate,
		initialState
	})] });
};
//#endregion
//#region src/components/OpenUIChat/GenUIUserMessage.tsx
/**
* Extracts the first plain object from a context string.
* The triggerAction context format is: ["action description string", { formState }]
*/
function parseContextForDisplay(contextString) {
	if (!contextString) return {};
	try {
		const parsed = JSON.parse(contextString);
		if (Array.isArray(parsed)) return parsed.find((item) => item !== null && typeof item === "object" && !Array.isArray(item)) ?? {};
		if (typeof parsed === "object" && parsed !== null) return parsed;
		return {};
	} catch {
		return {};
	}
}
function getEntries(state) {
	const isNested = Object.values(state).some((v) => v !== null && typeof v === "object" && !("value" in v) && Object.values(v).some((f) => f !== null && typeof f === "object" && "value" in f));
	const entries = [];
	if (isNested) for (const [, fields] of Object.entries(state)) {
		if (typeof fields !== "object" || fields === null) continue;
		for (const [fieldName, field] of Object.entries(fields)) if (field && typeof field === "object" && "value" in field) {
			const val = field.value;
			if (val !== void 0 && val !== null && val !== "") entries.push({
				label: fieldName,
				value: String(val)
			});
		}
	}
	else for (const [fieldName, field] of Object.entries(state)) if (field && typeof field === "object" && "value" in field) {
		const val = field.value;
		if (val !== void 0 && val !== null && val !== "") entries.push({
			label: fieldName,
			value: String(val)
		});
	}
	return entries;
}
function FormDataAccordion({ state }) {
	const [isExpanded, setIsExpanded] = (0, react.useState)(false);
	const entries = getEntries(state);
	if (entries.length === 0) return null;
	return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
		className: "openui-genui-user-message__form-state",
		children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
			className: "openui-genui-user-message__form-state-header",
			onClick: () => setIsExpanded((v) => !v),
			type: "button",
			children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
				className: "openui-genui-user-message__form-state-label",
				children: [
					"Form data (",
					entries.length,
					" ",
					entries.length === 1 ? "field" : "fields",
					")"
				]
			}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronDown, {
				size: 14,
				className: `openui-genui-user-message__form-state-chevron${isExpanded ? " openui-genui-user-message__form-state-chevron--expanded" : ""}`
			})]
		}), isExpanded && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
			className: "openui-genui-user-message__form-state-content",
			children: entries.map(({ label, value }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
				className: "openui-genui-user-message__form-field",
				children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
					className: "openui-genui-user-message__form-field-label",
					children: [label, ":"]
				}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
					className: "openui-genui-user-message__form-field-value",
					children: value
				})]
			}, label))
		})]
	});
}
/**
* Renders a user message, handling both plain text messages and
* XML-formatted messages from form submissions (which contain <content> and <context> tags).
*/
const GenUIUserMessage = ({ message }) => {
	const { content: humanText, contextString } = require_Shell.separateContentAndContext(typeof message.content === "string" ? message.content : "");
	const formState = parseContextForDisplay(contextString);
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
		className: "openui-shell-thread-message-user",
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
			className: "openui-genui-user-message",
			children: [Object.keys(formState).length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormDataAccordion, { state: formState }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
				className: "openui-shell-thread-message-user__content",
				children: humanText && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: humanText })
			})]
		})
	});
};
//#endregion
//#region src/components/OpenUIChat/withChatProvider.tsx
const DummyThemeProvider = ({ children }) => {
	return children;
};
const CHAT_PROVIDER_PROP_KEYS = new Set([
	"apiUrl",
	"processMessage",
	"threadApiUrl",
	"fetchThreadList",
	"createThread",
	"deleteThread",
	"updateThread",
	"loadThread",
	"streamProtocol",
	"messageFormat"
]);
function withChatProvider(WrappedComponent) {
	const WithChatProvider = (props) => {
		const innerProps = {};
		const chatProviderProps = {};
		let theme;
		let disableThemeProvider = false;
		for (const [key, value] of Object.entries(props)) if (key === "theme") theme = value;
		else if (key === "disableThemeProvider") disableThemeProvider = value;
		else if (CHAT_PROVIDER_PROP_KEYS.has(key)) chatProviderProps[key] = value;
		else innerProps[key] = value;
		const componentLibrary = innerProps["componentLibrary"];
		const customAssistantMessage = innerProps["assistantMessage"];
		const customUserMessage = innerProps["userMessage"];
		const genUIAssistantMessage = (0, react.useMemo)(() => {
			if (customAssistantMessage || !componentLibrary) return void 0;
			return ({ message }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GenUIAssistantMessage, {
				message,
				library: componentLibrary
			});
		}, [customAssistantMessage, componentLibrary]);
		const genUIUserMessage = (0, react.useMemo)(() => {
			if (customUserMessage || !componentLibrary) return void 0;
			return ({ message }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GenUIUserMessage, { message });
		}, [customUserMessage, componentLibrary]);
		if (genUIAssistantMessage && !customAssistantMessage) innerProps["assistantMessage"] = genUIAssistantMessage;
		if (genUIUserMessage && !customUserMessage) innerProps["userMessage"] = genUIUserMessage;
		return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(disableThemeProvider ? DummyThemeProvider : require_ThemeProvider.ThemeProvider, {
			...theme,
			children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_openuidev_react_headless.ChatProvider, {
				...chatProviderProps,
				children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WrappedComponent, { ...innerProps })
			})
		});
	};
	WithChatProvider.displayName = `withChatProvider(${WrappedComponent.displayName || WrappedComponent.name || "Component"})`;
	return WithChatProvider;
}
//#endregion
//#region src/components/OpenUIChat/ComposedBottomTray.tsx
const WelcomeMessageRenderer$2 = ({ welcomeMessage }) => {
	const messages = (0, _openuidev_react_headless.useThread)((s) => s.messages);
	const isLoadingMessages = (0, _openuidev_react_headless.useThread)((s) => s.isLoadingMessages);
	if (!welcomeMessage || !require_ArtifactOverlay.isChatEmpty({
		isLoadingMessages,
		messages
	})) return null;
	if (isWelcomeComponent(welcomeMessage)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_BottomTray.WelcomeScreen, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(welcomeMessage, {}) });
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_BottomTray.WelcomeScreen, {
		title: welcomeMessage.title,
		description: welcomeMessage.description,
		image: welcomeMessage.image
	});
};
const ConversationStartersRenderer$2 = ({ conversationStarters }) => {
	const messages = (0, _openuidev_react_headless.useThread)((s) => s.messages);
	const isLoadingMessages = (0, _openuidev_react_headless.useThread)((s) => s.isLoadingMessages);
	if (!conversationStarters || !require_ArtifactOverlay.isChatEmpty({
		isLoadingMessages,
		messages
	})) return null;
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_BottomTray.ConversationStarter, {
		variant: conversationStarters.variant,
		starters: conversationStarters.options
	});
};
const BottomTrayInner = ({ logoUrl = "https://www.openui.com/favicon.svg", agentName = "My Agent", messageLoading: MessageLoadingComponent = require_BottomTray.MessageLoading, scrollVariant = "user-message-anchor", isOpen: controlledIsOpen, onOpenChange, defaultOpen = false, welcomeMessage, conversationStarters, assistantMessage, userMessage, composer: ComposerComponent, headerActions, generateShareLink }) => {
	const [uncontrolledIsOpen, setUncontrolledIsOpen] = (0, react.useState)(defaultOpen);
	const isOpen = controlledIsOpen !== void 0 ? controlledIsOpen : uncontrolledIsOpen;
	const handleOpenChange = (newIsOpen) => {
		if (controlledIsOpen === void 0) setUncontrolledIsOpen(newIsOpen);
		onOpenChange?.(newIsOpen);
	};
	return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_BottomTray.Trigger, {
		onClick: () => handleOpenChange(!isOpen),
		isOpen,
		children: logoUrl ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
			src: logoUrl,
			alt: "Logo",
			className: "openui-bottom-tray-trigger-logo"
		}) : null
	}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_BottomTray.Container, {
		logoUrl,
		agentName,
		isOpen,
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_BottomTray.ThreadContainer, { children: [
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_BottomTray.Header, {
				onMinimize: () => handleOpenChange(false),
				rightChildren: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [generateShareLink ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ShareThread, { generateShareLink }) : null, headerActions] })
			}),
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)(WelcomeMessageRenderer$2, { welcomeMessage }),
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_BottomTray.ScrollArea, {
				scrollVariant,
				children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_BottomTray.Messages, {
					loader: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MessageLoadingComponent, {}),
					assistantMessage,
					userMessage
				})
			}),
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ConversationStartersRenderer$2, { conversationStarters }),
			ComposerComponent ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CustomComposerAdapter, { composer: ComposerComponent }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_BottomTray.Composer, {})
		] })
	})] });
};
const BottomTray = withChatProvider(BottomTrayInner);
//#endregion
//#region src/components/OpenUIChat/ComposedCopilot.tsx
const WelcomeMessageRenderer$1 = ({ welcomeMessage }) => {
	const messages = (0, _openuidev_react_headless.useThread)((s) => s.messages);
	const isLoadingMessages = (0, _openuidev_react_headless.useThread)((s) => s.isLoadingMessages);
	if (!welcomeMessage || !require_ArtifactOverlay.isChatEmpty({
		isLoadingMessages,
		messages
	})) return null;
	if (isWelcomeComponent(welcomeMessage)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_CopilotShell.WelcomeScreen, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(welcomeMessage, {}) });
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_CopilotShell.WelcomeScreen, {
		title: welcomeMessage.title,
		description: welcomeMessage.description,
		image: welcomeMessage.image
	});
};
const ConversationStartersRenderer$1 = ({ conversationStarters }) => {
	const messages = (0, _openuidev_react_headless.useThread)((s) => s.messages);
	const isLoadingMessages = (0, _openuidev_react_headless.useThread)((s) => s.isLoadingMessages);
	if (!conversationStarters || !require_ArtifactOverlay.isChatEmpty({
		isLoadingMessages,
		messages
	})) return null;
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_CopilotShell.ConversationStarter, {
		variant: conversationStarters.variant,
		starters: conversationStarters.options
	});
};
const CopilotInner = ({ logoUrl = "https://www.openui.com/favicon.svg", agentName = "My Agent", messageLoading: MessageLoadingComponent = require_CopilotShell.MessageLoading, scrollVariant = "user-message-anchor", welcomeMessage, conversationStarters, assistantMessage, userMessage, composer: ComposerComponent, headerActions, generateShareLink }) => {
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_CopilotShell.Container, {
		logoUrl,
		agentName,
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_CopilotShell.ThreadContainer, { children: [
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_CopilotShell.Header, { rightChildren: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [generateShareLink ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ShareThread, { generateShareLink }) : null, headerActions] }) }),
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)(WelcomeMessageRenderer$1, { welcomeMessage }),
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_CopilotShell.ScrollArea, {
				scrollVariant,
				children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_CopilotShell.Messages, {
					loader: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MessageLoadingComponent, {}),
					assistantMessage,
					userMessage
				})
			}),
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ConversationStartersRenderer$1, { conversationStarters }),
			ComposerComponent ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CustomComposerAdapter, { composer: ComposerComponent }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_CopilotShell.Composer, {})
		] })
	});
};
const Copilot = withChatProvider(CopilotInner);
//#endregion
//#region src/components/OpenUIChat/ComposedStandalone.tsx
const WelcomeMessageRenderer = ({ welcomeMessage, conversationStarters }) => {
	const messages = (0, _openuidev_react_headless.useThread)((s) => s.messages);
	const isLoadingMessages = (0, _openuidev_react_headless.useThread)((s) => s.isLoadingMessages);
	if (!welcomeMessage || !require_ArtifactOverlay.isChatEmpty({
		isLoadingMessages,
		messages
	})) return null;
	if (isWelcomeComponent(welcomeMessage)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Shell.WelcomeScreen, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(welcomeMessage, {}) });
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Shell.WelcomeScreen, {
		title: welcomeMessage.title,
		description: welcomeMessage.description,
		image: welcomeMessage.image,
		starters: conversationStarters?.options,
		starterVariant: conversationStarters?.variant
	});
};
const ConversationStartersRenderer = ({ conversationStarters }) => {
	const messages = (0, _openuidev_react_headless.useThread)((s) => s.messages);
	const isLoadingMessages = (0, _openuidev_react_headless.useThread)((s) => s.isLoadingMessages);
	if (!conversationStarters || !require_ArtifactOverlay.isChatEmpty({
		isLoadingMessages,
		messages
	})) return null;
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Shell.ConversationStarter, {
		variant: conversationStarters.variant,
		starters: conversationStarters.options
	});
};
const FullScreenInner = ({ logoUrl = "https://www.openui.com/favicon.svg", agentName = "My Agent", messageLoading: MessageLoadingComponent = require_Shell.MessageLoading, scrollVariant = "user-message-anchor", welcomeMessage, conversationStarters, assistantMessage, userMessage, composer: ComposerComponent, threadHeader, mobileHeaderActions, generateShareLink }) => {
	const shareButton = generateShareLink ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ShareThread, { generateShareLink }) : null;
	return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_Shell.Container, {
		logoUrl,
		agentName,
		children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_Shell.SidebarContainer, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Shell.SidebarHeader, {}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_Shell.SidebarContent, { children: [
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Shell.NewChatButton, {}),
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Shell.SidebarSeparator, {}),
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Shell.ThreadList, {})
		] })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_Shell.ThreadContainer, { children: [
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Shell.MobileHeader, { rightChildren: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [shareButton, mobileHeaderActions] }) }),
			(threadHeader || shareButton) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_Shell.ThreadHeader, { children: [threadHeader, shareButton] }),
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)(WelcomeMessageRenderer, {
				welcomeMessage,
				conversationStarters
			}),
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Shell.ScrollArea, {
				scrollVariant,
				children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Shell.Messages, {
					loader: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MessageLoadingComponent, {}),
					assistantMessage,
					userMessage
				})
			}),
			/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ConversationStartersRenderer, { conversationStarters }),
			ComposerComponent ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CustomComposerAdapter, { composer: ComposerComponent }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Shell.Composer, {})
		] })]
	});
};
const FullScreen = withChatProvider(FullScreenInner);
//#endregion
exports.BottomTray = BottomTray;
exports.Copilot = Copilot;
exports.FullScreen = FullScreen;
exports.GenUIUserMessage = GenUIUserMessage;
exports.ShareThread = ShareThread;
exports.ShareThreadModal = ShareThreadModal;
exports.isChatEmpty = require_ArtifactOverlay.isChatEmpty;
exports.isWelcomeComponent = isWelcomeComponent;

//# sourceMappingURL=index.cjs.map