UNPKG

@copilotkit/react-ui

Version:

<div align="center"> <a href="https://copilotkit.ai" target="_blank"> <img src="https://github.com/copilotkit/copilotkit/raw/main/assets/banner.png" alt="CopilotKit Logo"> </a>

1,268 lines (1,247 loc) 101 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __defProps = Object.defineProperties; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropDescs = Object.getOwnPropertyDescriptors; var __getOwnPropNames = Object.getOwnPropertyNames; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); var __objRest = (source, exclude) => { var target = {}; for (var prop in source) if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0) target[prop] = source[prop]; if (source != null && __getOwnPropSymbols) for (var prop of __getOwnPropSymbols(source)) { if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop)) target[prop] = source[prop]; } return target; }; 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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { step(generator.next(value)); } catch (e) { reject(e); } }; var rejected = (value) => { try { step(generator.throw(value)); } catch (e) { reject(e); } }; var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); step((generator = generator.apply(__this, __arguments)).next()); }); }; // src/components/index.ts var components_exports = {}; __export(components_exports, { AssistantMessage: () => AssistantMessage, CopilotChat: () => CopilotChat, CopilotDevConsole: () => CopilotDevConsole, CopilotPopup: () => CopilotPopup, CopilotSidebar: () => CopilotSidebar, Markdown: () => Markdown, UserMessage: () => UserMessage, shouldShowDevConsole: () => shouldShowDevConsole, useChatContext: () => useChatContext }); module.exports = __toCommonJS(components_exports); // src/components/chat/Modal.tsx var import_react14 = __toESM(require("react")); // src/components/chat/ChatContext.tsx var import_react = __toESM(require("react")); // src/components/chat/Icons.tsx var import_jsx_runtime = require("react/jsx-runtime"); var OpenIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", width: "24", height: "24", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("g", { transform: "translate(24, 0) scale(-1, 1)", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "path", { fillRule: "evenodd", d: "M5.337 21.718a6.707 6.707 0 01-.533-.074.75.75 0 01-.44-1.223 3.73 3.73 0 00.814-1.686c.023-.115-.022-.317-.254-.543C3.274 16.587 2.25 14.41 2.25 12c0-5.03 4.428-9 9.75-9s9.75 3.97 9.75 9c0 5.03-4.428 9-9.75 9-.833 0-1.643-.097-2.417-.279a6.721 6.721 0 01-4.246.997z", clipRule: "evenodd" } ) }) } ); var CloseIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: "1.5", stroke: "currentColor", width: "24", height: "24", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19.5 8.25l-7.5 7.5-7.5-7.5" }) } ); var HeaderCloseIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: "1.5", stroke: "currentColor", width: "24", height: "24", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18L18 6M6 6l12 12" }) } ); var SendIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: "1.5", stroke: "currentColor", width: "24", height: "24", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M12 19V5m0 0l-7 7m7-7l7 7" }) } ); var MicrophoneIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: "1.5", stroke: "currentColor", width: "24", height: "24", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M12 18.75a6 6 0 006-6v-1.5m-6 7.5a6 6 0 01-6-6v-1.5m6 7.5v3.75m-3.75 0h7.5M12 15.75a3 3 0 01-3-3V4.5a3 3 0 116 0v8.25a3 3 0 01-3 3z" } ) } ); var StopIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: "1.5", stroke: "currentColor", width: "24", height: "24", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M5.25 7.5A2.25 2.25 0 017.5 5.25h9a2.25 2.25 0 012.25 2.25v9a2.25 2.25 0 01-2.25 2.25h-9a2.25 2.25 0 01-2.25-2.25v-9z" } ) } ); var RegenerateIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: "2", stroke: "currentColor", width: "16", height: "16", style: { minWidth: "16px", minHeight: "16px" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0l3.181 3.183a8.25 8.25 0 0013.803-3.7M4.031 9.865a8.25 8.25 0 0113.803-3.7l3.181 3.182m0-4.991v4.99" } ) } ); var CopyIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: "2", stroke: "currentColor", width: "16", height: "16", style: { minWidth: "16px", minHeight: "16px" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M15.75 17.25v3.375c0 .621-.504 1.125-1.125 1.125h-9.75a1.125 1.125 0 01-1.125-1.125V7.875c0-.621.504-1.125 1.125-1.125H6.75a9.06 9.06 0 011.5.124m7.5 10.376h3.375c.621 0 1.125-.504 1.125-1.125V11.25c0-4.46-3.243-8.161-7.5-8.876a9.06 9.06 0 00-1.5-.124H9.375c-.621 0-1.125.504-1.125 1.125v3.5m7.5 10.375H9.375a1.125 1.125 0 01-1.125-1.125v-9.25m12 6.625v-1.875a3.375 3.375 0 00-3.375-3.375h-1.5a1.125 1.125 0 01-1.125-1.125v-1.5a3.375 3.375 0 00-3.375-3.375H9.75" } ) } ); var SmallSpinnerIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "copilotKitSpinner", style: { width: "13px", height: "13px" } }); var SpinnerIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "copilotKitSpinner", style: { width: "24px", height: "24px" } }); var ActivityIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "4px" }, children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "copilotKitActivityDot", style: { animationDelay: "0s" } }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "copilotKitActivityDot", style: { animationDelay: "0.2s" } }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "copilotKitActivityDot", style: { animationDelay: "0.4s" } }) ] }); var ThumbsUpIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: "2", stroke: "currentColor", width: "16", height: "16", style: { minWidth: "16px", minHeight: "16px" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6.633 10.5c.806 0 1.533-.446 2.031-1.08a9.041 9.041 0 012.861-2.4c.723-.384 1.35-.956 1.653-1.715a4.498 4.498 0 00.322-1.672V3a.75.75 0 01.75-.75A2.25 2.25 0 0116.5 4.5c0 1.152-.26 2.243-.723 3.218-.266.558.107 1.282.725 1.282h3.126c1.026 0 1.945.694 2.054 1.715.045.422.068.85.068 1.285a11.95 11.95 0 01-2.649 7.521c-.388.482-.987.729-1.605.729H13.48c-.483 0-.964-.078-1.423-.23l-3.114-1.04a4.501 4.501 0 00-1.423-.23H5.904M14.25 9h2.25M5.904 18.75c.083.205.173.405.27.602.197.4-.078.898-.523.898h-.908c-.889 0-1.713-.518-1.972-1.368a12 12 0 01-.521-3.507c0-1.553.295-3.036.831-4.398C3.387 10.203 4.167 9.75 5 9.75h1.053c.472 0 .745.556.5.96a8.958 8.958 0 00-1.302 4.665c0 1.194.232 2.333.654 3.375z" } ) } ); var ThumbsDownIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: "2", stroke: "currentColor", width: "16", height: "16", style: { minWidth: "16px", minHeight: "16px" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M7.5 15h2.25m8.024-9.75c.011.05.028.1.052.148.591 1.2.924 2.55.924 3.977a8.96 8.96 0 01-.999 4.125m.023-8.25c-.076-.365.183-.75.575-.75h.908c.889 0 1.713.518 1.972 1.368.339 1.11.521 2.287.521 3.507 0 1.553-.295 3.036-.831 4.398C20.613 14.547 19.833 15 19 15h-1.053c-.472 0-.745-.556-.5-.96a8.95 8.95 0 00.303-.54m.023-8.25H16.48a4.5 4.5 0 01-1.423-.23l-3.114-1.04a4.5 4.5 0 00-1.423-.23H6.504c-.618 0-1.217.247-1.605.729A11.95 11.95 0 002.25 12c0 .434.023.863.068 1.285C2.427 14.306 3.346 15 4.372 15h3.126c.618 0 .991.724.725 1.282A7.471 7.471 0 007.5 19.5a2.25 2.25 0 002.25 2.25.75.75 0 00.75-.75v-.633c0-.573.11-1.14.322-1.672.304-.76.93-1.33 1.653-1.715a9.04 9.04 0 002.86-2.4c.498-.634 1.226-1.08 2.032-1.08h.384" } ) } ); var DownloadIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: "2", stroke: "currentColor", width: "16", height: "16", style: { minWidth: "16px", minHeight: "16px" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5M16.5 12L12 16.5m0 0L7.5 12m4.5 4.5V3" } ) } ); var CheckIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: "2", stroke: "currentColor", width: "16", height: "16", style: { minWidth: "16px", minHeight: "16px" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M4.5 12.75l6 6 9-13.5" }) } ); // src/components/chat/ChatContext.tsx var import_jsx_runtime2 = require("react/jsx-runtime"); var ChatContext = import_react.default.createContext(void 0); function useChatContext() { const context = import_react.default.useContext(ChatContext); if (context === void 0) { throw new Error( "Context not found. Did you forget to wrap your app in a <ChatContextProvider> component?" ); } return context; } var ChatContextProvider = ({ // temperature, // instructions, // maxFeedback, labels, icons, children, open, setOpen }) => { const memoizedLabels = (0, import_react.useMemo)( () => __spreadValues(__spreadValues({}, { initial: "", title: "CopilotKit", placeholder: "Type a message...", error: "\u274C An error occurred. Please try again.", stopGenerating: "Stop generating", regenerateResponse: "Regenerate response", copyToClipboard: "Copy to clipboard", thumbsUp: "Thumbs up", thumbsDown: "Thumbs down", copied: "Copied!" }), labels), [labels] ); const memoizedIcons = (0, import_react.useMemo)( () => __spreadValues(__spreadValues({}, { openIcon: OpenIcon, closeIcon: CloseIcon, headerCloseIcon: HeaderCloseIcon, sendIcon: SendIcon, activityIcon: ActivityIcon, spinnerIcon: SpinnerIcon, stopIcon: StopIcon, regenerateIcon: RegenerateIcon, pushToTalkIcon: MicrophoneIcon, copyIcon: CopyIcon, thumbsUpIcon: ThumbsUpIcon, thumbsDownIcon: ThumbsDownIcon }), icons), [icons] ); const context = (0, import_react.useMemo)( () => ({ labels: memoizedLabels, icons: memoizedIcons, open, setOpen }), [memoizedLabels, memoizedIcons, open, setOpen] ); return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChatContext.Provider, { value: context, children }); }; // src/components/chat/Window.tsx var import_react2 = __toESM(require("react")); var import_react_core = require("@copilotkit/react-core"); // src/hooks/use-dark-mode.ts var useDarkMode = () => { if (typeof window === "undefined") return false; return document.documentElement.classList.contains("dark") || document.body.classList.contains("dark") || document.documentElement.getAttribute("data-theme") === "dark" || document.body.getAttribute("data-theme") === "dark" || window.matchMedia("(prefers-color-scheme: dark)").matches; }; // src/components/chat/Window.tsx var import_jsx_runtime3 = require("react/jsx-runtime"); var Window = ({ children, clickOutsideToClose, shortcut, hitEscapeToClose }) => { var _a; const windowRef = import_react2.default.useRef(null); const context = (0, import_react_core.useCopilotContext)(); const { open, setOpen } = useChatContext(); const handleClickOutside = (0, import_react2.useCallback)( (event) => { var _a2; if (!clickOutsideToClose) { return; } const parentElement = (_a2 = windowRef.current) == null ? void 0 : _a2.parentElement; let className = ""; if (event.target instanceof HTMLElement) { className = event.target.className; } if (open && parentElement && !parentElement.contains(event.target) && // prevent closing the window when clicking on the debug menu !className.includes("copilotKitDebugMenu")) { setOpen(false); } }, [clickOutsideToClose, open, setOpen] ); const handleKeyDown = (0, import_react2.useCallback)( (event) => { var _a2; const target = event.target; const isInput = target.tagName === "INPUT" || target.tagName === "SELECT" || target.tagName === "TEXTAREA" || target.isContentEditable; const isDescendantOfWrapper = (_a2 = windowRef.current) == null ? void 0 : _a2.contains(target); if (open && event.key === "Escape" && (!isInput || isDescendantOfWrapper) && hitEscapeToClose) { setOpen(false); } else if (event.key === shortcut && (isMacOS() && event.metaKey || !isMacOS() && event.ctrlKey) && (!isInput || isDescendantOfWrapper)) { setOpen(!open); } }, [hitEscapeToClose, shortcut, open, setOpen] ); const adjustForMobile = (0, import_react2.useCallback)(() => { const copilotKitWindow = windowRef.current; const vv = window.visualViewport; if (!copilotKitWindow || !vv) { return; } if (window.innerWidth < 640 && open) { copilotKitWindow.style.height = `${vv.height}px`; copilotKitWindow.style.left = `${vv.offsetLeft}px`; copilotKitWindow.style.top = `${vv.offsetTop}px`; document.body.style.position = "fixed"; document.body.style.width = "100%"; document.body.style.height = `${window.innerHeight}px`; document.body.style.overflow = "hidden"; document.body.style.touchAction = "none"; document.body.addEventListener("touchmove", preventScroll, { passive: false }); } else { copilotKitWindow.style.height = ""; copilotKitWindow.style.left = ""; copilotKitWindow.style.top = ""; document.body.style.position = ""; document.body.style.height = ""; document.body.style.width = ""; document.body.style.overflow = ""; document.body.style.top = ""; document.body.style.touchAction = ""; document.body.removeEventListener("touchmove", preventScroll); } }, [open]); (0, import_react2.useEffect)(() => { document.addEventListener("mousedown", handleClickOutside); document.addEventListener("keydown", handleKeyDown); if (window.visualViewport) { window.visualViewport.addEventListener("resize", adjustForMobile); adjustForMobile(); } return () => { document.removeEventListener("mousedown", handleClickOutside); document.removeEventListener("keydown", handleKeyDown); if (window.visualViewport) { window.visualViewport.removeEventListener("resize", adjustForMobile); } }; }, [adjustForMobile, handleClickOutside, handleKeyDown]); const isDark = useDarkMode(); const showPoweredBy = !((_a = context.copilotApiConfig) == null ? void 0 : _a.publicApiKey); const poweredByStyle = { visibility: "visible", display: "block", position: "static", textAlign: "center", fontSize: "12px", padding: "3px 0", color: isDark ? "rgb(69, 69, 69)" : "rgb(214, 214, 214)" }; return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)( "div", { className: `copilotKitWindow ${showPoweredBy ? " poweredByContainer" : ""} ${open ? " open" : ""}`, ref: windowRef, children: [ children, showPoweredBy && // @ts-expect-error -- expecting position not to be a string, but it can be. /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "poweredBy", style: poweredByStyle, children: "Powered by CopilotKit" }) ] } ); }; var preventScroll = (event) => { let targetElement = event.target; const hasParentWithClass = (element, className) => { while (element && element !== document.body) { if (element.classList.contains(className)) { return true; } element = element.parentElement; } return false; }; if (!hasParentWithClass(targetElement, "copilotKitMessages")) { event.preventDefault(); } }; function isMacOS() { return /Mac|iMac|Macintosh/i.test(navigator.userAgent); } // src/components/chat/Button.tsx var import_jsx_runtime4 = require("react/jsx-runtime"); var Button = ({}) => { const { open, setOpen, icons } = useChatContext(); return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { onClick: () => setOpen(!open), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)( "button", { className: `copilotKitButton ${open ? "open" : ""}`, "aria-label": open ? "Close Chat" : "Open Chat", children: [ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "copilotKitButtonIcon copilotKitButtonIconOpen", children: icons.openIcon }), /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "copilotKitButtonIcon copilotKitButtonIconClose", children: icons.closeIcon }) ] } ) }); }; // src/components/dev-console/utils.ts var import_react_core2 = require("@copilotkit/react-core"); function shouldShowDevConsole(showDevConsole) { if (typeof showDevConsole === "boolean") { return showDevConsole; } return getHostname() === "localhost" || getHostname() === "127.0.0.1" || getHostname() === "0.0.0.0" || getHostname() === "::1"; } function getHostname() { if (typeof window !== "undefined" && window.location) { return window.location.hostname; } return ""; } function getPublishedCopilotKitVersion(current, forceCheck = false) { return __async(this, null, function* () { const LOCAL_STORAGE_KEY = "__copilotkit_version_check__"; const serializedVersion = localStorage.getItem(LOCAL_STORAGE_KEY); if (serializedVersion && !forceCheck) { try { const parsedVersion = JSON.parse(serializedVersion); const oneHour = 60 * 60 * 1e3; const now = (/* @__PURE__ */ new Date()).getTime(); if (parsedVersion.current === current && now - new Date(parsedVersion.lastChecked).getTime() < oneHour) { return parsedVersion; } } catch (error) { console.error("Failed to parse CopilotKitVersion from localStorage", error); } } try { const response = yield fetch("https://api.cloud.copilotkit.ai/check-for-updates", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ packages: [ { packageName: "@copilotkit/shared", packageVersion: current } ] }) }); const data = yield response.json(); const version = { current, lastChecked: (/* @__PURE__ */ new Date()).getTime(), latest: data.packages[0].latestVersion, severity: data.packages[0].severity, advisory: data.packages[0].advisory || null }; localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(version)); return version; } catch (error) { console.error("Failed to check for updates", error); throw error; } }); } function logReadables(context) { console.log("%cCurrent Readables:", "font-size: 16px; font-weight: bold;"); const readables = context.getContextString([], import_react_core2.defaultCopilotContextCategories).trim(); if (readables.length === 0) { console.log("No readables found"); return; } console.log(readables); } function logActions(context) { console.log("%cCurrent Actions:", "font-size: 16px; font-weight: bold;"); if (Object.values(context.actions).length === 0) { console.log("No actions found"); return; } for (const action of Object.values(context.actions)) { console.group(action.name); console.log("name", action.name); console.log("description", action.description); console.log("parameters", action.parameters); console.groupEnd(); } } function logMessages(context) { console.log("%cCurrent Messages:", "font-size: 16px; font-weight: bold;"); if (context.messages.length === 0) { console.log("No messages found"); return; } const tableData = context.messages.map((message) => { if (message.isTextMessage()) { return { id: message.id, type: "TextMessage", role: message.role, name: void 0, scope: void 0, content: message.content }; } else if (message.isActionExecutionMessage()) { return { id: message.id, type: "ActionExecutionMessage", role: void 0, name: message.name, scope: message.parentMessageId, content: message.arguments }; } else if (message.isResultMessage()) { return { id: message.id, type: "ResultMessage", role: void 0, name: message.actionName, scope: message.actionExecutionId, content: message.result }; } else if (message.isAgentStateMessage()) { return { id: message.id, type: `AgentStateMessage (running: ${message.running})`, role: message.role, name: void 0, scope: message.threadId, content: message.state }; } }); console.table(tableData); } // src/components/dev-console/console.tsx var import_react_core3 = require("@copilotkit/react-core"); var import_react4 = require("react"); // src/components/dev-console/icons.tsx var import_jsx_runtime5 = require("react/jsx-runtime"); var ExclamationMarkTriangleIcon = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)( "svg", { width: "13.3967723px", height: "12px", viewBox: "0 0 13.3967723 12", version: "1.1", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("g", { id: "Page-1", stroke: "none", strokeWidth: "1", fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("g", { id: "exclamation-triangle", fill: "#CD2121", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)( "path", { d: "M5.39935802,0.75 C5.97670802,-0.25 7.42007802,-0.25 7.99742802,0.75 L13.193588,9.75 C13.770888,10.75 13.049288,12 11.894588,12 L1.50223802,12 C0.34753802,12 -0.37414898,10.75 0.20319802,9.75 L5.39935802,0.75 Z M6.69838802,2.5 C7.11260802,2.5 7.44838802,2.83579 7.44838802,3.25 L7.44838802,6.25 C7.44838802,6.66421 7.11260802,7 6.69838802,7 C6.28417802,7 5.94838802,6.66421 5.94838802,6.25 L5.94838802,3.25 C5.94838802,2.83579 6.28417802,2.5 6.69838802,2.5 Z M6.69838802,10.5 C7.25067802,10.5 7.69838802,10.0523 7.69838802,9.5 C7.69838802,8.9477 7.25067802,8.5 6.69838802,8.5 C6.14610802,8.5 5.69838802,8.9477 5.69838802,9.5 C5.69838802,10.0523 6.14610802,10.5 6.69838802,10.5 Z", id: "Shape" } ) }) }) } ); var ExclamationMarkIcon = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)( "svg", { width: "14px", height: "14px", viewBox: "0 0 14 14", version: "1.1", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("g", { id: "Page-1", stroke: "none", strokeWidth: "1", fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("g", { id: "exclamation-circle", fill: "#EC662C", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)( "path", { d: "M7,14 C10.866,14 14,10.866 14,7 C14,3.13401 10.866,0 7,0 C3.13401,0 0,3.13401 0,7 C0,10.866 3.13401,14 7,14 Z M7,3 C7.41421,3 7.75,3.33579 7.75,3.75 L7.75,6.75 C7.75,7.16421 7.41421,7.5 7,7.5 C6.58579,7.5 6.25,7.16421 6.25,6.75 L6.25,3.75 C6.25,3.33579 6.58579,3 7,3 Z M7,11 C7.55228,11 8,10.5523 8,10 C8,9.4477 7.55228,9 7,9 C6.44772,9 6,9.4477 6,10 C6,10.5523 6.44772,11 7,11 Z", id: "Shape" } ) }) }) } ); var ChevronDownIcon = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)( "svg", { width: "7px", height: "4px", viewBox: "0 0 7 4", version: "1.1", xmlns: "http://www.w3.org/2000/svg", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("g", { id: "Page-1", stroke: "none", strokeWidth: "1", fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("g", { id: "Group", fill: "currentColor", fillRule: "nonzero", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)( "path", { d: "M3.71690723,3.90271086 C3.59268176,4.03242971 3.39143629,4.03242971 3.26721082,3.90271086 L0.0853966595,0.57605615 C-0.0314221035,0.444981627 -0.0279751448,0.240725043 0.0931934622,0.114040675 C0.214362069,-0.0126436935 0.409725445,-0.0162475626 0.535093061,0.105888951 L3.49205902,3.19746006 L6.44902499,0.105888951 C6.52834574,0.0168884389 6.64780588,-0.0197473458 6.7605411,0.0103538404 C6.87327633,0.0404550266 6.96130636,0.132492308 6.99009696,0.250359396 C7.01888756,0.368226483 6.98384687,0.493124608 6.89872139,0.57605615 L3.71690723,3.90271086 Z", id: "Path" } ) }) }) } ); var CheckIcon2 = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)( "svg", { width: "14px", height: "14px", viewBox: "0 0 14 14", version: "1.1", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("g", { id: "Page-1", stroke: "none", strokeWidth: "1", fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("g", { id: "Group-2", transform: "translate(-118, 0)", fill: "#1BC030", fillRule: "nonzero", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("g", { id: "Group", transform: "translate(118, 0)", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)( "path", { d: "M0,7 C0,3.13384615 3.13384615,0 7,0 C10.8661538,0 14,3.13384615 14,7 C14,10.8661538 10.8661538,14 7,14 C3.13384615,14 0,10.8661538 0,7 Z M9.59179487,5.69764103 C9.70905818,5.54139023 9.73249341,5.33388318 9.65303227,5.15541491 C9.57357113,4.97694665 9.40367989,4.85551619 9.20909814,4.83811118 C9.01451638,4.82070616 8.82577109,4.91005717 8.71589744,5.07158974 L6.39261538,8.32389744 L5.22666667,7.15794872 C5.01450582,6.96025518 4.68389046,6.9660885 4.47883563,7.17114332 C4.27378081,7.37619815 4.26794748,7.70681351 4.46564103,7.91897436 L6.08102564,9.53435897 C6.19289944,9.64614839 6.3482622,9.70310251 6.50588106,9.69010587 C6.66349993,9.67710922 6.80743532,9.59547613 6.89948718,9.46687179 L9.59179487,5.69764103 L9.59179487,5.69764103 Z", id: "Shape" } ) }) }) }) } ); // src/components/dev-console/console.tsx var import_react5 = require("@headlessui/react"); var import_shared = require("@copilotkit/shared"); // src/components/help-modal/modal.tsx var import_react3 = require("react"); // src/components/help-modal/icons.tsx var import_jsx_runtime6 = require("react/jsx-runtime"); var CloseIcon2 = () => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)( "svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: "1.5", stroke: "currentColor", width: "20", height: "20", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18L18 6M6 6l12 12" }) } ); // src/components/help-modal/modal.tsx var import_jsx_runtime7 = require("react/jsx-runtime"); function CopilotKitHelpModal() { const [showHelpModal, setShowHelpModal] = (0, import_react3.useState)(false); const buttonRef = (0, import_react3.useRef)(null); const popoverRef = (0, import_react3.useRef)(null); (0, import_react3.useEffect)(() => { const handleClickOutside = (event) => { if (popoverRef.current && !popoverRef.current.contains(event.target) && buttonRef.current && !buttonRef.current.contains(event.target)) { setShowHelpModal(false); } }; if (showHelpModal) { document.addEventListener("mousedown", handleClickOutside); } return () => { document.removeEventListener("mousedown", handleClickOutside); }; }, [showHelpModal]); const HelpButton = () => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)( "button", { ref: buttonRef, onClick: () => setShowHelpModal(!showHelpModal), className: "copilotKitDebugMenuTriggerButton relative", "aria-label": "Open Help", children: "Help" } ); return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "relative", children: [ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HelpButton, {}), showHelpModal && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)( "div", { ref: popoverRef, className: "absolute mt-2 z-50", style: { top: "100%", right: "-120px", width: "380px" }, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "copilotKitHelpModal rounded-lg shadow-xl w-full p-4 flex-col relative", children: [ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)( "button", { className: "copilotKitHelpModalCloseButton absolute text-gray-400 hover:text-gray-600 focus:outline-none", style: { top: "10px", right: "10px" }, onClick: () => setShowHelpModal(false), "aria-label": "Close", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CloseIcon2, {}) } ), /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "w-full flex mb-6 justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("h2", { className: "text-2xl font-bold", children: "Help Options" }) }), /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "space-y-4 mb-4", children: [ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "copilotKitHelpItemButton", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)( "a", { href: "https://docs.copilotkit.ai/coagents/troubleshooting/common-issues", target: "_blank", rel: "noopener noreferrer", children: "Visit the Troubleshooting and FAQ section in the docs" } ) }), /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "copilotKitHelpItemButton", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)( "a", { href: "https://go.copilotkit.ai/dev-console-support-discord", target: "_blank", rel: "noopener noreferrer", children: "Go to Discord Support Channel (Community Support)" } ) }), /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "copilotKitHelpItemButton", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)( "a", { href: "https://go.copilotkit.ai/dev-console-support-slack", target: "_blank", rel: "noopener noreferrer", children: "Apply for Priority Direct Slack Support" } ) }) ] }) ] }) } ) ] }); } // src/components/dev-console/console.tsx var import_jsx_runtime8 = require("react/jsx-runtime"); function CopilotDevConsole() { const currentVersion = import_shared.COPILOTKIT_VERSION; const context = (0, import_react_core3.useCopilotContext)(); const [showDevConsole, setShowDevConsole] = (0, import_react4.useState)(false); (0, import_react4.useEffect)(() => { setShowDevConsole(shouldShowDevConsole(context.showDevConsole)); }, [context.showDevConsole]); const dontRunTwiceInDevMode = (0, import_react4.useRef)(false); const [versionStatus, setVersionStatus] = (0, import_react4.useState)("unknown"); const [latestVersion, setLatestVersion] = (0, import_react4.useState)(""); const consoleRef = (0, import_react4.useRef)(null); const [debugButtonMode, setDebugButtonMode] = (0, import_react4.useState)("full"); const checkForUpdates = (force = false) => { setVersionStatus("checking"); getPublishedCopilotKitVersion(currentVersion, force).then((v) => { setLatestVersion(v.latest); let versionOk = false; if (v.current === v.latest) { versionOk = true; } else if (/[a-zA-Z]/.test(v.current)) { versionOk = true; } if (versionOk) { setVersionStatus("latest"); } else if (v.severity !== "low") { setVersionStatus("outdated"); } else { setVersionStatus("update-available"); } }).catch((e) => { console.error(e); setVersionStatus("unknown"); }); }; (0, import_react4.useEffect)(() => { if (dontRunTwiceInDevMode.current === true) { return; } dontRunTwiceInDevMode.current = true; checkForUpdates(); }, []); if (!showDevConsole) { return null; } return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)( "div", { ref: consoleRef, className: "copilotKitDevConsole " + (versionStatus === "update-available" ? "copilotKitDevConsoleUpgrade" : "") + (versionStatus === "outdated" ? "copilotKitDevConsoleWarnOutdated" : ""), children: [ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)( VersionInfo, { showDevConsole: context.showDevConsole, versionStatus, currentVersion, latestVersion } ), /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CopilotKitHelpModal, {}), /* @__PURE__ */ (0, import_jsx_runtime8.jsx)( DebugMenuButton, { setShowDevConsole, checkForUpdates, mode: debugButtonMode } ) ] } ); } function VersionInfo({ showDevConsole, versionStatus, currentVersion, latestVersion }) { const [copyStatus, setCopyStatus] = (0, import_react4.useState)(""); let versionLabel = ""; let versionIcon = ""; let currentVersionLabel = currentVersion; if (versionStatus === "latest") { versionLabel = "latest"; versionIcon = CheckIcon2; } else if (versionStatus === "checking") { versionLabel = "checking"; versionIcon = SmallSpinnerIcon; } else if (versionStatus === "update-available") { versionLabel = "update available"; versionIcon = ExclamationMarkIcon; currentVersionLabel = `${currentVersion} \u2192 ${latestVersion}`; } else if (versionStatus === "outdated") { versionLabel = "outdated"; versionIcon = ExclamationMarkTriangleIcon; currentVersionLabel = `${currentVersion} \u2192 ${latestVersion}`; } let asideLabel = ""; if (showDevConsole === "auto") { asideLabel = "(localhost only)"; } else if (showDevConsole === true) { asideLabel = "(always on)"; } const installCommand = [ `npm install`, `@copilotkit/react-core@${latestVersion}`, `@copilotkit/react-ui@${latestVersion}`, `@copilotkit/react-textarea@${latestVersion}`, `&& npm install @copilotkit/runtime@${latestVersion}` ].join(" "); const handleCopyClick = () => { navigator.clipboard.writeText(installCommand.trim()).then(() => { setCopyStatus("Command copied to clipboard!"); setTimeout(() => setCopyStatus(""), 1e3); }); }; if (versionStatus === "update-available" || versionStatus === "outdated") { return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "copilotKitVersionInfo", children: [ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("p", { children: [ currentVersionLabel, " ", versionIcon ] }), /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { onClick: handleCopyClick, children: copyStatus || installCommand }) ] }); } return null; } function DebugMenuButton({ setShowDevConsole, checkForUpdates, mode }) { const context = (0, import_react_core3.useCopilotContext)(); const messagesContext = (0, import_react_core3.useCopilotMessagesContext)(); return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_react5.Menu, { children: [ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)( import_react5.MenuButton, { className: `copilotKitDebugMenuTriggerButton ${mode === "compact" ? "compact" : ""}`, children: mode == "compact" ? "Debug" : /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [ "Debug ", ChevronDownIcon ] }) } ), /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)( import_react5.MenuItems, { transition: true, anchor: "bottom end", className: "copilotKitDebugMenu", style: { zIndex: 40 }, children: [ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react5.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { className: "copilotKitDebugMenuItem", onClick: () => logReadables(context), children: "Log Readables" }) }), /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react5.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { className: "copilotKitDebugMenuItem", onClick: () => logActions(context), children: "Log Actions" }) }), /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react5.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)( "button", { className: "copilotKitDebugMenuItem", onClick: () => logMessages(messagesContext), children: "Log Messages" } ) }), /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react5.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { className: "copilotKitDebugMenuItem", onClick: () => checkForUpdates(true), children: "Check for Updates" }) }), /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("hr", {}), /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react5.MenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { className: "copilotKitDebugMenuItem", onClick: () => setShowDevConsole(false), children: "Hide Dev Console" }) }) ] } ) ] }) }); } // src/components/chat/Header.tsx var import_jsx_runtime9 = require("react/jsx-runtime"); var Header = ({}) => { const { setOpen, icons, labels } = useChatContext(); return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "copilotKitHeader", children: [ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { children: labels.title }), /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "copilotKitHeaderControls", children: [ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(CopilotDevConsole, {}), /* @__PURE__ */ (0, import_jsx_runtime9.jsx)( "button", { onClick: () => setOpen(false), "aria-label": "Close", className: "copilotKitHeaderCloseButton", children: icons.headerCloseIcon } ) ] }) ] }); }; // src/components/chat/Messages.tsx var import_react6 = require("react"); var import_runtime_client_gql = require("@copilotkit/runtime-client-gql"); var import_react_core4 = require("@copilotkit/react-core"); var import_jsx_runtime10 = require("react/jsx-runtime"); var Messages = ({ messages, inProgress, children, RenderTextMessage: RenderTextMessage2, RenderActionExecutionMessage: RenderActionExecutionMessage2, RenderAgentStateMessage: RenderAgentStateMessage2, RenderResultMessage: RenderResultMessage2, AssistantMessage: AssistantMessage2, UserMessage: UserMessage2, onRegenerate, onCopy, onThumbsUp, onThumbsDown }) => { const context = useChatContext(); const initialMessages = (0, import_react6.useMemo)( () => makeInitialMessages(context.labels.initial), [context.labels.initial] ); messages = [...initialMessages, ...messages]; const actionResults = {}; for (let i = 0; i < messages.length; i++) { if (messages[i].isActionExecutionMessage()) { const id = messages[i].id; const resultMessage = messages.find( (message) => message.isResultMessage() && message.actionExecutionId === id ); if (resultMessage) { actionResults[id] = import_runtime_client_gql.ResultMessage.decodeResult(resultMessage.result || ""); } } } const { messagesEndRef, messagesContainerRef } = useScrollToBottom(messages); const interrupt = (0, import_react_core4.useLangGraphInterruptRender)(); return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "copilotKitMessages", ref: messagesContainerRef, children: [ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "copilotKitMessagesContainer", children: [ messages.map((message, index) => { const isCurrentMessage = index === messages.length - 1; if (message.isTextMessage()) { return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)( RenderTextMessage2, { message, inProgress, index, isCurrentMessage, AssistantMessage: AssistantMessage2, UserMessage: UserMessage2, onRegenerate, onCopy, onThumbsUp, onThumbsDown }, index ); } else if (message.isActionExecutionMessage()) { return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)( RenderActionExecutionMessage2, { message, inProgress, index, isCurrentMessage, actionResult: actionResults[message.id], AssistantMessage: AssistantMessage2, UserMessage: UserMessage2 }, index ); } else if (message.isAgentStateMessage()) { return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)( RenderAgentStateMessage2, { message, inProgress, index, isCurrentMessage, AssistantMessage: AssistantMessage2, UserMessage: UserMessage2 }, index ); } else if (message.isResultMessage()) { return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)( RenderResultMessage2, { message, inProgress, index, isCurrentMessage, AssistantMessage: AssistantMessage2, UserMessage: UserMessage2 }, index ); } }), interrupt ] }), /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("footer", { className: "copilotKitMessagesFooter", ref: messagesEndRef, children }) ] }); }; function makeInitialMessages(initial) { let initialArray = []; if (initial) { if (Array.isArray(initial)) { initialArray.push(...initial); } else { initialArray.push(initial); } } return initialArray.map( (message) => new import_runtime_client_gql.TextMessage({ role: import_runtime_client_gql.Role.Assistant, content: message }) ); } function useScrollToBottom(messages) { const messagesEndRef = (0, import_react6.useRef)(null); const messagesContainerRef = (0, import_react6.useRef)(null); const isProgrammaticScrollRef = (0, import_react6.useRef)(false); const isUserScrollUpRef = (0, import_react6.useRef)(false); const scrollToBottom = () => { if (messagesEndRef.current) { isProgrammaticScrollRef.current = true; messagesEndRef.current.scrollIntoView({ behavior: "auto" }); } }; const handleScroll = () => { if (isProgrammaticScrollRef.current) { isProgrammaticScrollRef.current = false; return; } if (messagesContainerRef.current) { const { scrollTop, scrollHeight, clientHeight } = messagesContainerRef.current; isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight; } }; (0, import_react6.useEffect)(() => { const container = messagesContainerRef.current; if (container) { container.addEventListener("scroll", handleScroll); } return () => { if (container) { container.removeEventListener("scroll", handleScroll); } }; }, []); (0, import_react6.useEffect)(() => { const container = messagesContainerRef.current; if (!container) { return; } const mutationObserver = new MutationObserver(() => { if (!isUserScrollUpRef.current) { scrollToBottom(); } }); mutationObserver.observe(container, { childList: true, subtree: true, characterData: true }); return () => { mutationObserver.disconnect(); }; }, []); (0, import_react6.useEffect)(() => { isUserScrollUpRef.current = false; scrollToBottom(); }, [messages.filter((m) => m.isTextMessage() && m.role === import_runtime_client_gql.Role.User).length]); return { messagesEndRef, messagesContainerRef }; } // src/components/chat/Input.tsx var import_react9 = require("react"); // src/components/chat/Textarea.tsx var import_react7 = require("react"); var import_jsx_runtime11 = require("react/jsx-runtime"); var AutoResizingTextarea = (0, import_react7.forwardRef)( ({ maxRows = 1, placeholder, value, onChange, onKeyDown, autoFocus }, ref) => { const internalTextareaRef = (0, import_react7.useRef)(null); const [maxHeight, setMaxHeight] = (0, import_react7.useState)(0); (0, import_react7.useImperativeHandle)(ref, () => internalTextareaRef.current); (0, import_react7.useEffect)(() => { const calculateMaxHeight = () => { const textarea = internalTextareaRef.current; if (textarea) { textarea.style.height = "auto"; const singleRowHeight = textarea.sc