@marimo-team/frontend 0.25.2-dev96 → 0.25.2-dev97

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/assets/{JsonOutput-NVH7GWyC.js → JsonOutput-DCGUcLVV.js} +1 -1
  2. package/dist/assets/{MarimoErrorOutput-z5iFryzf.js → MarimoErrorOutput-BEsxXqp6.js} +1 -1
  3. package/dist/assets/{agent-panel-BcoO8S6Q.js → agent-panel-BPLrf7mA.js} +1 -1
  4. package/dist/assets/{cell-editor-CevZDS63.js → cell-editor-C3818WlB.js} +1 -1
  5. package/dist/assets/chat-panel-BZipGUZV.js +4 -0
  6. package/dist/assets/{column-preview-sL_Jo0hX.js → column-preview-fD3qW2B5.js} +1 -1
  7. package/dist/assets/{command-palette-DMQFuWz1.js → command-palette-BM9fUfEe.js} +1 -1
  8. package/dist/assets/{dependency-graph-panel-BwMayTyZ.js → dependency-graph-panel-CLrAZrHA.js} +1 -1
  9. package/dist/assets/{edit-page-DD1NFkiu.js → edit-page-Ctwp3mZE.js} +4 -4
  10. package/dist/assets/{error-panel-ByOEJuZN.js → error-panel-BgYJTJpA.js} +1 -1
  11. package/dist/assets/{file-explorer-panel-B92ugwxr.js → file-explorer-panel-HvVNt0Qs.js} +1 -1
  12. package/dist/assets/{hooks-DNPsQf79.js → hooks-Qxjt0Ypd.js} +1 -1
  13. package/dist/assets/{index-C6-WDESh.js → index-B5XWyg6n.js} +2 -2
  14. package/dist/assets/index-Xxay17E9.css +2 -0
  15. package/dist/assets/{layout-BaluekG6.js → layout-CSLw6wGo.js} +3 -3
  16. package/dist/assets/{panels-CO6Clgel.js → panels-BdsXFz1w.js} +1 -1
  17. package/dist/assets/{reveal-component-DeZTBbnn.js → reveal-component-B5GUiD5Q.js} +1 -1
  18. package/dist/assets/{run-page-BNEg-Ro9.js → run-page-CVWospEP.js} +1 -1
  19. package/dist/assets/{scratchpad-panel-lDJWcpVs.js → scratchpad-panel-B4qlmwP-.js} +1 -1
  20. package/dist/assets/{session-panel-BqutyoYd.js → session-panel-Ch5jQNj0.js} +1 -1
  21. package/dist/assets/state-BI0fn_YF.js +1 -0
  22. package/dist/assets/{useCellActionButton-DwAUf_Cn.js → useCellActionButton-BTsPn8Dv.js} +1 -1
  23. package/dist/assets/{useDependencyPanelTab-CbcGEmqM.js → useDependencyPanelTab-BTsnw2rN.js} +1 -1
  24. package/dist/assets/{useNotebookActions-pXzVjrlk.js → useNotebookActions-BzJtySGp.js} +1 -1
  25. package/dist/index.html +6 -6
  26. package/package.json +1 -1
  27. package/src/components/chat/__tests__/chat-history-popover.test.tsx +157 -0
  28. package/src/components/chat/chat-history-popover.tsx +98 -17
  29. package/src/components/chat/chat-panel.tsx +29 -0
  30. package/src/core/ai/__tests__/state.test.ts +120 -0
  31. package/src/core/ai/state.ts +36 -10
  32. package/dist/assets/chat-panel-DyaePe7B.js +0 -4
  33. package/dist/assets/index-B7ZZVUcj.css +0 -2
  34. package/dist/assets/state-B85OOscw.js +0 -1
@@ -1,9 +1,16 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
3
  import { useAtomValue } from "jotai";
4
- import { BotMessageSquareIcon, ClockIcon, SearchIcon } from "lucide-react";
5
- import { useMemo, useState } from "react";
4
+ import {
5
+ BotMessageSquareIcon,
6
+ ClockIcon,
7
+ SearchIcon,
8
+ Trash2Icon,
9
+ } from "lucide-react";
10
+ import { useMemo, useRef, useState } from "react";
6
11
  import { useLocale } from "react-aria";
12
+ import { useImperativeModal } from "@/components/modal/ImperativeModal";
13
+ import { AlertDialogDestructiveAction } from "@/components/ui/alert-dialog";
7
14
  import { Button } from "@/components/ui/button";
8
15
  import { Input } from "@/components/ui/input";
9
16
  import {
@@ -19,18 +26,48 @@ import { timeAgo } from "@/utils/dates";
19
26
  import { PanelEmptyState } from "../editor/chrome/panels/empty-state";
20
27
  import { groupChatsByDate } from "./chat-history-utils";
21
28
 
29
+ const CHAT_HISTORY_WARNING_THRESHOLD = 50;
30
+
22
31
  interface ChatHistoryPopoverProps {
23
32
  activeChatId: ChatId | undefined;
24
33
  setActiveChat: (id: ChatId | null) => void;
34
+ onDeleteChats: (id: ChatId | null) => void;
35
+ isLoading: boolean;
25
36
  }
26
37
 
27
38
  export const ChatHistoryPopover: React.FC<ChatHistoryPopoverProps> = ({
28
39
  activeChatId,
29
40
  setActiveChat,
41
+ onDeleteChats,
42
+ isLoading,
30
43
  }) => {
31
44
  const chatState = useAtomValue(chatStateAtom);
32
45
  const { locale } = useLocale();
33
46
  const [searchQuery, setSearchQuery] = useState("");
47
+ const searchInputRef = useRef<HTMLInputElement>(null);
48
+ const [open, setOpen] = useState(false);
49
+ const { openConfirm, closeModal } = useImperativeModal();
50
+
51
+ const confirmDeleteAllChats = () => {
52
+ // Close the popover before opening a modal so focus moves to the dialog.
53
+ setOpen(false);
54
+ openConfirm({
55
+ title: "Delete all chats?",
56
+ description:
57
+ "This will permanently delete all chat history for all notebooks on this site in this browser. This cannot be undone.",
58
+ variant: "destructive",
59
+ confirmAction: (
60
+ <AlertDialogDestructiveAction
61
+ onClick={() => {
62
+ onDeleteChats(null);
63
+ closeModal();
64
+ }}
65
+ >
66
+ Delete all chats
67
+ </AlertDialogDestructiveAction>
68
+ ),
69
+ });
70
+ };
34
71
 
35
72
  const chats = useMemo(() => {
36
73
  return [...chatState.chats.values()].toSorted(
@@ -52,10 +89,10 @@ export const ChatHistoryPopover: React.FC<ChatHistoryPopoverProps> = ({
52
89
  }, [filteredChats]);
53
90
 
54
91
  return (
55
- <Popover>
92
+ <Popover open={open} onOpenChange={setOpen}>
56
93
  <Tooltip content="Previous chats">
57
94
  <PopoverTrigger asChild={true}>
58
- <Button variant="text" size="icon">
95
+ <Button variant="text" size="icon" aria-label="Previous chats">
59
96
  <ClockIcon className="h-4 w-4" />
60
97
  </Button>
61
98
  </PopoverTrigger>
@@ -63,6 +100,7 @@ export const ChatHistoryPopover: React.FC<ChatHistoryPopoverProps> = ({
63
100
  <PopoverContent className="w-[480px] p-0" align="start" side="right">
64
101
  <div className="pt-3 px-3 w-full">
65
102
  <Input
103
+ ref={searchInputRef}
66
104
  placeholder="Search chat history..."
67
105
  value={searchQuery}
68
106
  onChange={(e) => setSearchQuery(e.target.value)}
@@ -92,25 +130,46 @@ export const ChatHistoryPopover: React.FC<ChatHistoryPopoverProps> = ({
92
130
  </div>
93
131
  <div>
94
132
  {group.chats.map((chat) => (
95
- <button
133
+ <div
96
134
  key={chat.id}
97
135
  className={cn(
98
- "w-full p-1 rounded-md cursor-pointer text-left flex items-center justify-between",
136
+ "w-full rounded-md flex items-center justify-between",
99
137
  chat.id === activeChatId && "bg-accent",
100
138
  chat.id !== activeChatId && "hover:bg-muted/20",
101
139
  )}
102
- onClick={() => {
103
- setActiveChat(chat.id);
104
- }}
105
- type="button"
106
140
  >
107
- <div className="flex-1 min-w-0">
108
- <div className="text-sm truncate">{chat.title}</div>
109
- </div>
110
- <div className="text-xs text-muted-foreground/60 ml-2 shrink-0">
111
- {timeAgo(chat.updatedAt, locale)}
112
- </div>
113
- </button>
141
+ <button
142
+ className="flex flex-1 min-w-0 items-center justify-between p-1 text-left cursor-pointer"
143
+ onClick={() => setActiveChat(chat.id)}
144
+ type="button"
145
+ >
146
+ <span className="text-sm truncate">{chat.title}</span>
147
+ <span className="text-xs text-muted-foreground/60 ml-2 shrink-0">
148
+ {timeAgo(chat.updatedAt, locale)}
149
+ </span>
150
+ </button>
151
+ <Tooltip
152
+ content={
153
+ isLoading && chat.id === activeChatId
154
+ ? "Stop the response before deleting this chat"
155
+ : "Delete chat"
156
+ }
157
+ >
158
+ <Button
159
+ variant="text"
160
+ size="icon"
161
+ className="text-muted-foreground/90 hover:text-destructive transition-colors ml-px"
162
+ aria-label={`Delete chat: ${chat.title}`}
163
+ disabled={isLoading && chat.id === activeChatId}
164
+ onClick={() => {
165
+ searchInputRef.current?.focus();
166
+ onDeleteChats(chat.id);
167
+ }}
168
+ >
169
+ <Trash2Icon className="h-3.5 w-3.5" />
170
+ </Button>
171
+ </Tooltip>
172
+ </div>
114
173
  ))}
115
174
  </div>
116
175
  {/* If last group, don't show a divider */}
@@ -119,6 +178,28 @@ export const ChatHistoryPopover: React.FC<ChatHistoryPopoverProps> = ({
119
178
  ))}
120
179
  </div>
121
180
  </ScrollArea>
181
+ {chats.length > 0 && (
182
+ <div className="border-t p-2 flex items-center justify-between gap-2">
183
+ {chats.length > CHAT_HISTORY_WARNING_THRESHOLD ? (
184
+ <p className="text-xs text-muted-foreground">
185
+ You have over <b>{CHAT_HISTORY_WARNING_THRESHOLD}</b> chats.
186
+ Delete old chats to free up browser storage.
187
+ </p>
188
+ ) : (
189
+ <p className="text-xs text-muted-foreground">
190
+ Chats are shared across notebooks.
191
+ </p>
192
+ )}
193
+ <Button
194
+ variant="linkDestructive"
195
+ size="xs"
196
+ disabled={isLoading}
197
+ onClick={confirmDeleteAllChats}
198
+ >
199
+ Delete all chats
200
+ </Button>
201
+ </div>
202
+ )}
122
203
  </PopoverContent>
123
204
  </Popover>
124
205
  );
@@ -150,12 +150,16 @@ interface ChatHeaderProps {
150
150
  onNewChat: () => void;
151
151
  activeChatId: ChatId | undefined;
152
152
  setActiveChat: (id: ChatId | null) => void;
153
+ onDeleteChats: (id: ChatId | null) => void;
154
+ isLoading: boolean;
153
155
  }
154
156
 
155
157
  const ChatHeader: React.FC<ChatHeaderProps> = ({
156
158
  onNewChat,
157
159
  activeChatId,
158
160
  setActiveChat,
161
+ onDeleteChats,
162
+ isLoading,
159
163
  }) => {
160
164
  const { handleClick } = useOpenSettingsToTab();
161
165
 
@@ -184,6 +188,8 @@ const ChatHeader: React.FC<ChatHeaderProps> = ({
184
188
  <ChatHistoryPopover
185
189
  activeChatId={activeChatId}
186
190
  setActiveChat={setActiveChat}
191
+ onDeleteChats={onDeleteChats}
192
+ isLoading={isLoading}
187
193
  />
188
194
  </div>
189
195
  </div>
@@ -838,6 +844,27 @@ const ChatPanelBody = () => {
838
844
  clearFiles();
839
845
  });
840
846
 
847
+ const handleDeleteChats = useEvent((id: ChatId | null) => {
848
+ if (id === null || id === activeChatId) {
849
+ handleNewChat();
850
+ }
851
+ setChatState((prev) => {
852
+ const chats = new Map(prev.chats);
853
+ if (id === null) {
854
+ chats.clear();
855
+ } else {
856
+ chats.delete(id);
857
+ }
858
+ return {
859
+ chats,
860
+ activeChatId:
861
+ prev.activeChatId && chats.has(prev.activeChatId)
862
+ ? prev.activeChatId
863
+ : null,
864
+ };
865
+ });
866
+ });
867
+
841
868
  const handlePairWithAgent = useEvent(() => {
842
869
  openModal(<PairWithAgentModal onClose={closeModal} />);
843
870
  });
@@ -997,6 +1024,8 @@ const ChatPanelBody = () => {
997
1024
  onNewChat={handleNewChat}
998
1025
  activeChatId={activeChat?.id}
999
1026
  setActiveChat={setActiveChat}
1027
+ onDeleteChats={handleDeleteChats}
1028
+ isLoading={isLoading}
1000
1029
  />
1001
1030
  </TooltipProvider>
1002
1031
 
@@ -0,0 +1,120 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { createStore } from "jotai";
4
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
5
+ import { toast } from "@/components/ui/use-toast";
6
+ import { type Chat, type ChatId, chatStateAtom } from "../state";
7
+
8
+ vi.mock("@/components/ui/use-toast", () => ({ toast: vi.fn() }));
9
+
10
+ const KEY = "marimo:ai:chatState:v5";
11
+ const chatId = "saved-chat" as ChatId;
12
+ const chat: Chat = {
13
+ id: chatId,
14
+ title: "Saved conversation",
15
+ messages: [
16
+ { id: "message", role: "user", parts: [{ type: "text", text: "Hello" }] },
17
+ ],
18
+ createdAt: 1,
19
+ updatedAt: 1,
20
+ };
21
+
22
+ const unsubscribers: (() => void)[] = [];
23
+
24
+ function loadStore() {
25
+ const store = createStore();
26
+ unsubscribers.push(store.sub(chatStateAtom, vi.fn()));
27
+ return store;
28
+ }
29
+
30
+ function fillStorage() {
31
+ vi.spyOn(Storage.prototype, "setItem").mockImplementation(() => {
32
+ throw new DOMException("Storage is full", "QuotaExceededError");
33
+ });
34
+ }
35
+
36
+ describe("chat history storage", () => {
37
+ beforeEach(() => {
38
+ window.localStorage.clear();
39
+ window.localStorage.setItem(
40
+ KEY,
41
+ JSON.stringify({
42
+ chats: [[chatId, chat]],
43
+ activeChatId: chatId,
44
+ }),
45
+ );
46
+ });
47
+
48
+ afterEach(() => {
49
+ for (const unsubscribe of unsubscribers.splice(0)) {
50
+ unsubscribe();
51
+ }
52
+ vi.restoreAllMocks();
53
+ });
54
+
55
+ it("loads saved history when storage is full", () => {
56
+ fillStorage();
57
+ expect(loadStore().get(chatStateAtom)).toEqual({
58
+ chats: new Map([[chatId, chat]]),
59
+ activeChatId: chatId,
60
+ });
61
+ });
62
+
63
+ it("warns on save failure without interrupting in-memory updates", () => {
64
+ const store = loadStore();
65
+ const savedHistory = window.localStorage.getItem(KEY);
66
+ fillStorage();
67
+ const updatedChat = { ...chat, title: "Unsaved conversation" };
68
+ expect(() =>
69
+ store.set(chatStateAtom, {
70
+ chats: new Map([[chatId, updatedChat]]),
71
+ activeChatId: chatId,
72
+ }),
73
+ ).not.toThrow();
74
+
75
+ expect(store.get(chatStateAtom).chats.get(chatId)).toEqual(updatedChat);
76
+ expect(window.localStorage.getItem(KEY)).toBe(savedHistory);
77
+ expect(toast).toHaveBeenCalledWith(
78
+ expect.objectContaining({
79
+ id: "chat-storage-error",
80
+ once: true,
81
+ title: "Chat history couldn't be saved",
82
+ }),
83
+ );
84
+ });
85
+
86
+ it("frees storage when history is cleared even if further writes fail", () => {
87
+ window.localStorage.setItem("unrelated-setting", "keep");
88
+ const store = loadStore();
89
+ fillStorage();
90
+ store.set(chatStateAtom, { chats: new Map(), activeChatId: null });
91
+
92
+ expect(window.localStorage.getItem(KEY)).toBeNull();
93
+ expect(window.localStorage.getItem("unrelated-setting")).toBe("keep");
94
+ expect(loadStore().get(chatStateAtom)).toEqual({
95
+ chats: new Map(),
96
+ activeChatId: null,
97
+ });
98
+ expect(toast).not.toHaveBeenCalled();
99
+ });
100
+
101
+ it("removes saved history when only an empty chat remains and writes fail", () => {
102
+ const store = loadStore();
103
+ const emptyChat = { ...chat, messages: [] };
104
+ const state = {
105
+ chats: new Map([[chatId, emptyChat]]),
106
+ activeChatId: chatId,
107
+ };
108
+ fillStorage();
109
+
110
+ store.set(chatStateAtom, state);
111
+
112
+ expect(window.localStorage.getItem(KEY)).toBeNull();
113
+ expect(store.get(chatStateAtom)).toEqual(state);
114
+ expect(loadStore().get(chatStateAtom)).toEqual({
115
+ chats: new Map(),
116
+ activeChatId: null,
117
+ });
118
+ expect(toast).not.toHaveBeenCalled();
119
+ });
120
+ });
@@ -4,7 +4,9 @@ import type { UIMessage } from "@ai-sdk/react";
4
4
  import type { FileUIPart } from "ai";
5
5
  import { atom } from "jotai";
6
6
  import { atomWithStorage } from "jotai/utils";
7
+ import { toast } from "@/components/ui/use-toast";
7
8
  import { uniqueBy } from "@/utils/arrays";
9
+ import { Logger } from "@/utils/Logger";
8
10
  import { adaptForLocalStorage, jotaiJsonStorage } from "@/utils/storage/jotai";
9
11
  import type { TypedString } from "@/utils/typed";
10
12
  import type { CellId } from "../cells/ids";
@@ -85,22 +87,46 @@ function removeEmptyChats(chatState: Map<ChatId, Chat>): Map<ChatId, Chat> {
85
87
  return result;
86
88
  }
87
89
 
90
+ const chatStorage = adaptForLocalStorage({
91
+ toSerializable: (value: ChatState) => ({
92
+ chats: [...removeEmptyChats(value.chats).entries()],
93
+ activeChatId: value.activeChatId,
94
+ }),
95
+ fromSerializable: (value) => ({
96
+ chats: new Map(value.chats),
97
+ activeChatId: value.activeChatId,
98
+ }),
99
+ });
100
+
88
101
  export const chatStateAtom = atomWithStorage<ChatState>(
89
102
  KEY,
90
103
  {
91
104
  chats: new Map(),
92
105
  activeChatId: null,
93
106
  },
94
- adaptForLocalStorage({
95
- toSerializable: (value: ChatState) => ({
96
- chats: [...removeEmptyChats(value.chats).entries()],
97
- activeChatId: value.activeChatId,
98
- }),
99
- fromSerializable: (value) => ({
100
- chats: new Map(value.chats),
101
- activeChatId: value.activeChatId,
102
- }),
103
- }),
107
+ {
108
+ ...chatStorage,
109
+ setItem: (key, value) => {
110
+ try {
111
+ // Removing the key frees space even when no further writes can fit.
112
+ if (removeEmptyChats(value.chats).size === 0) {
113
+ chatStorage.removeItem(key);
114
+ } else {
115
+ chatStorage.setItem(key, value);
116
+ }
117
+ } catch (error) {
118
+ Logger.warn("Could not save chat history", error);
119
+ toast({
120
+ id: "chat-storage-error",
121
+ once: true,
122
+ title: "Chat history couldn't be saved",
123
+ description:
124
+ "Try deleting old chats. New messages may be lost when you reload.",
125
+ variant: "danger",
126
+ });
127
+ }
128
+ },
129
+ },
104
130
  );
105
131
 
106
132
  export const activeChatAtom = atom(
@@ -1,4 +0,0 @@
1
- import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{c as t,d as n,l as r,t as i,u as a}from"./useEvent-Dc9HkKI2.js";import{t as o}from"./react-CUdNIagt.js";import{D as s,Zn as c,ao as l,br as u,cn as d,dn as f,qa as p,un as m}from"./cells-CxY8RSp7.js";import{t as h}from"./compiler-runtime-BQ9S8nyo.js";import{i as g,t as _}from"./config-Cyum2gRs.js";import{M as v,c as y,h as b,m as x,p as S,r as C,t as w}from"./ai-model-dropdown-CvJsRj9y.js";import{g as T,o as E}from"./useEventListener-IRzG-0mH.js";import{M as D,o as O}from"./config-D_c_6ce1.js";import{t as k}from"./cn-ldLVeaqm.js";import{t as A}from"./jsx-runtime-B74pBk57.js";import{C as j,S as M,T as N,b as P,v as F,w as I}from"./fullscreen-DEBblJKh.js";import{u as L}from"./menu-items-DAaNKHJF.js";import{t as ee}from"./config-CR2d-XsP.js";import{a as R,i as z,m as te,n as ne,r as re,s as ie,t as ae}from"./select-BwRFbZty.js";import{t as oe}from"./switch-C-83e2fG.js";import{i as se,t as B}from"./tooltip-B5pI8o2n.js";import{t as V}from"./button-M49xxKoi.js";import{t as H}from"./createLucideIcon-rHn2EdoM.js";import{t as ce}from"./arrow-right-xoNT7eIQ.js";import{t as le}from"./bot-message-square-BfGaNy9r.js";import{i as ue,n as de,r as fe,t as pe}from"./chat-display-YETh6yXV.js";import{B as me,C as he,D as ge,E as _e,N as ve,R as ye,S as be,U as xe,_ as Se,b as Ce,c as U,d as we,f as Te,g as Ee,h as De,k as Oe,l as W,m as ke,n as Ae,u as G,v as je,w as Me,x as Ne,y as Pe,z as Fe}from"./add-cell-with-ai-Wyt6GBhk.js";import{t as Ie}from"./code-DW4kNwKG.js";import{t as Le}from"./hat-glasses-DVgK5i5l.js";import{b as Re,p as ze}from"./write-secret-modal-BcosCmZy.js";import{n as Be}from"./spinner-CGdRKCnw.js";import{t as Ve}from"./message-circle-OTHnVlxO.js";import{t as K}from"./plus-gbN72xHe.js";import{r as He,rn as Ue}from"./input-DPd57MDP.js";import{t as We}from"./settings-DlKTeV_0.js";import{t as Ge}from"./copy-icon-wfSGfX8v.js";import{r as Ke}from"./requests-yTHMxhVa.js";import{t as qe}from"./uuid-k9DpjH68.js";import{t as Je}from"./I18nProvider-BFOBKCJB.js";import{s as Ye}from"./dates-BgcKUsHb.js";import{i as Xe,o as Ze,r as Qe,t as $e}from"./state-B85OOscw.js";import{n as et}from"./error-banner-D1_bPN9u.js";import{t as tt}from"./empty-state-CzxjZqGW.js";import{t as nt}from"./scroll-to-bottom-button-Dmrd5bjQ.js";var q=e(o(),1),J=A(),rt=Object.defineProperty,Y=(e,t)=>rt(e,`name`,{value:t,configurable:!0});function it(e,t){return q.useReducer((e,n)=>t[e][n]??e,e)}Y(it,`useStateMachine`);var at=`ScrollArea`,[ot,st]=I(at),[ct,X]=ot(at),lt=q.forwardRef(Y(function(e,t){let{__scopeScrollArea:n,type:r=`hover`,dir:i,scrollHideDelay:a=600,...o}=e,[s,c]=q.useState(null),[l,u]=q.useState(null),[d,f]=q.useState(null),[p,m]=q.useState(null),[h,g]=q.useState(null),[_,v]=q.useState(0),[y,b]=q.useState(0),[x,S]=q.useState(!1),[C,w]=q.useState(!1),T=E(t,c),D=L(i);return(0,J.jsx)(ct,{scope:n,type:r,dir:D,scrollHideDelay:a,scrollArea:s,viewport:l,onViewportChange:u,content:d,onContentChange:f,scrollbarX:p,onScrollbarXChange:m,scrollbarXEnabled:x,onScrollbarXEnabledChange:S,scrollbarY:h,onScrollbarYChange:g,scrollbarYEnabled:C,onScrollbarYEnabledChange:w,onCornerWidthChange:v,onCornerHeightChange:b,children:(0,J.jsx)(N.div,{dir:D,...o,ref:T,style:{position:`relative`,"--radix-scroll-area-corner-width":_+`px`,"--radix-scroll-area-corner-height":y+`px`,...e.style}})})},`ScrollArea`)),ut=`ScrollAreaViewport`,dt=q.forwardRef(Y(function(e,t){let{__scopeScrollArea:n,children:r,nonce:i,...a}=e,o=X(ut,n),s=q.useRef(null),c=E(t,s,o.onViewportChange);return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(ft,{nonce:i}),(0,J.jsx)(N.div,{"data-radix-scroll-area-viewport":``,...a,ref:c,style:{overflowX:o.scrollbarXEnabled?`scroll`:`hidden`,overflowY:o.scrollbarYEnabled?`scroll`:`hidden`,...e.style},children:(0,J.jsx)(`div`,{ref:o.onContentChange,style:{minWidth:`100%`,display:`table`},children:r})})]})},`ScrollAreaViewport`)),ft=q.memo(Y(function({nonce:e}){return(0,J.jsx)(`style`,{dangerouslySetInnerHTML:{__html:`[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}`},nonce:e})},`ScrollAreaViewportStyle`),(e,t)=>e.nonce===t.nonce),Z=`ScrollAreaScrollbar`,pt=q.forwardRef(Y(function(e,t){let{forceMount:n,...r}=e,i=X(Z,e.__scopeScrollArea),{onScrollbarXEnabledChange:a,onScrollbarYEnabledChange:o}=i,s=e.orientation===`horizontal`;return q.useEffect(()=>(s?a(!0):o(!0),()=>{s?a(!1):o(!1)}),[s,a,o]),i.type===`hover`?(0,J.jsx)(mt,{...r,ref:t,forceMount:n}):i.type===`scroll`?(0,J.jsx)(ht,{...r,ref:t,forceMount:n}):i.type===`auto`?(0,J.jsx)(gt,{...r,ref:t,forceMount:n}):i.type===`always`?(0,J.jsx)(_t,{...r,ref:t,"data-state":`visible`}):null},`ScrollAreaScrollbar`)),mt=q.forwardRef(Y(function(e,t){let{forceMount:n,...r}=e,i=X(Z,e.__scopeScrollArea),[a,o]=q.useState(!1);return q.useEffect(()=>{let e=i.scrollArea,t=0;if(e){let n=Y(()=>{window.clearTimeout(t),o(!0)},`handlePointerEnter`),r=Y(()=>{t=window.setTimeout(()=>o(!1),i.scrollHideDelay)},`handlePointerLeave`);return e.addEventListener(`pointerenter`,n),e.addEventListener(`pointerleave`,r),()=>{window.clearTimeout(t),e.removeEventListener(`pointerenter`,n),e.removeEventListener(`pointerleave`,r)}}},[i.scrollArea,i.scrollHideDelay]),(0,J.jsx)(P,{present:n||a,children:(0,J.jsx)(gt,{"data-state":a?`visible`:`hidden`,...r,ref:t})})},`ScrollAreaScrollbarHover`)),ht=q.forwardRef(Y(function(e,t){let{forceMount:n,...r}=e,i=X(Z,e.__scopeScrollArea),a=e.orientation===`horizontal`,o=Lt(()=>c(`SCROLL_END`),100),[s,c]=it(`hidden`,{hidden:{SCROLL:`scrolling`},scrolling:{SCROLL_END:`idle`,POINTER_ENTER:`interacting`},interacting:{SCROLL:`interacting`,POINTER_LEAVE:`idle`},idle:{HIDE:`hidden`,SCROLL:`scrolling`,POINTER_ENTER:`interacting`}});return q.useEffect(()=>{if(s===`idle`){let e=window.setTimeout(()=>c(`HIDE`),i.scrollHideDelay);return()=>window.clearTimeout(e)}},[s,i.scrollHideDelay,c]),q.useEffect(()=>{let e=i.viewport,t=a?`scrollLeft`:`scrollTop`;if(e){let n=e[t],r=Y(()=>{let r=e[t];n!==r&&(c(`SCROLL`),o()),n=r},`handleScroll`);return e.addEventListener(`scroll`,r),()=>e.removeEventListener(`scroll`,r)}},[i.viewport,a,c,o]),(0,J.jsx)(P,{present:n||s!==`hidden`,children:(0,J.jsx)(_t,{"data-state":s===`hidden`?`hidden`:`visible`,...r,ref:t,onPointerEnter:j(e.onPointerEnter,()=>c(`POINTER_ENTER`)),onPointerLeave:j(e.onPointerLeave,()=>c(`POINTER_LEAVE`))})})},`ScrollAreaScrollbarScroll`)),gt=q.forwardRef(Y(function(e,t){let n=X(Z,e.__scopeScrollArea),{forceMount:r,...i}=e,[a,o]=q.useState(!1),s=e.orientation===`horizontal`,c=Lt(()=>{if(n.viewport){let e=n.viewport.offsetWidth<n.viewport.scrollWidth,t=n.viewport.offsetHeight<n.viewport.scrollHeight;o(s?e:t)}},10);return Q(n.viewport,c),Q(n.content,c),(0,J.jsx)(P,{present:r||a,children:(0,J.jsx)(_t,{"data-state":a?`visible`:`hidden`,...i,ref:t})})},`ScrollAreaScrollbarAuto`)),_t=q.forwardRef(Y(function(e,t){let{orientation:n=`vertical`,...r}=e,i=X(Z,e.__scopeScrollArea),a=q.useRef(null),o=q.useRef(0),[s,c]=q.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),l=At(s.viewport,s.content),u={...r,sizes:s,onSizesChange:c,hasThumb:l>0&&l<1,onThumbChange:Y(e=>a.current=e,`onThumbChange`),onThumbPointerUp:Y(()=>o.current=0,`onThumbPointerUp`),onThumbPointerDown:Y(e=>o.current=e,`onThumbPointerDown`)};function d(e,t){return Mt(e,o.current,s,t)}return Y(d,`getScrollPosition`),n===`horizontal`?(0,J.jsx)(vt,{...u,ref:t,onThumbPositionChange:()=>{if(i.viewport&&a.current){let e=i.viewport.scrollLeft,t=Nt(e,s,i.dir);a.current.style.transform=`translate3d(${t}px, 0, 0)`}},onWheelScroll:e=>{i.viewport&&(i.viewport.scrollLeft=e)},onDragScroll:e=>{i.viewport&&(i.viewport.scrollLeft=d(e,i.dir))}}):n===`vertical`?(0,J.jsx)(yt,{...u,ref:t,onThumbPositionChange:()=>{if(i.viewport&&a.current){let e=i.viewport.scrollTop,t=Nt(e,s);a.current.style.transform=`translate3d(0, ${t}px, 0)`}},onWheelScroll:e=>{i.viewport&&(i.viewport.scrollTop=e)},onDragScroll:e=>{i.viewport&&(i.viewport.scrollTop=d(e))}}):null},`ScrollAreaScrollbarVisible`)),vt=q.forwardRef(Y(function(e,t){let{sizes:n,onSizesChange:r,...i}=e,a=X(Z,e.__scopeScrollArea),[o,s]=q.useState(),c=q.useRef(null),l=E(t,c,a.onScrollbarXChange);return q.useEffect(()=>{c.current&&s(getComputedStyle(c.current))},[c]),(0,J.jsx)(St,{"data-orientation":`horizontal`,...i,ref:l,sizes:n,style:{bottom:0,left:a.dir===`rtl`?`var(--radix-scroll-area-corner-width)`:0,right:a.dir===`ltr`?`var(--radix-scroll-area-corner-width)`:0,"--radix-scroll-area-thumb-width":jt(n)+`px`,...e.style},onThumbPointerDown:t=>e.onThumbPointerDown(t.x),onDragScroll:t=>e.onDragScroll(t.x),onWheelScroll:(t,n)=>{if(a.viewport){let r=a.viewport.scrollLeft+t.deltaX;e.onWheelScroll(r),Ft(r,n)&&t.preventDefault()}},onResize:()=>{c.current&&a.viewport&&o&&r({content:a.viewport.scrollWidth,viewport:a.viewport.offsetWidth,scrollbar:{size:c.current.clientWidth,paddingStart:kt(o.paddingLeft),paddingEnd:kt(o.paddingRight)}})}})},`ScrollAreaScrollbarX`)),yt=q.forwardRef(Y(function(e,t){let{sizes:n,onSizesChange:r,...i}=e,a=X(Z,e.__scopeScrollArea),[o,s]=q.useState(),c=q.useRef(null),l=E(t,c,a.onScrollbarYChange);return q.useEffect(()=>{c.current&&s(getComputedStyle(c.current))},[c]),(0,J.jsx)(St,{"data-orientation":`vertical`,...i,ref:l,sizes:n,style:{top:0,right:a.dir===`ltr`?0:void 0,left:a.dir===`rtl`?0:void 0,bottom:`var(--radix-scroll-area-corner-height)`,"--radix-scroll-area-thumb-height":jt(n)+`px`,...e.style},onThumbPointerDown:t=>e.onThumbPointerDown(t.y),onDragScroll:t=>e.onDragScroll(t.y),onWheelScroll:(t,n)=>{if(a.viewport){let r=a.viewport.scrollTop+t.deltaY;e.onWheelScroll(r),Ft(r,n)&&t.preventDefault()}},onResize:()=>{c.current&&a.viewport&&o&&r({content:a.viewport.scrollHeight,viewport:a.viewport.offsetHeight,scrollbar:{size:c.current.clientHeight,paddingStart:kt(o.paddingTop),paddingEnd:kt(o.paddingBottom)}})}})},`ScrollAreaScrollbarY`)),[bt,xt]=ot(Z),St=q.forwardRef(Y(function(e,t){let{__scopeScrollArea:n,sizes:r,hasThumb:i,onThumbChange:a,onThumbPointerUp:o,onThumbPointerDown:s,onThumbPositionChange:c,onDragScroll:l,onWheelScroll:u,onResize:d,...f}=e,p=X(Z,n),[m,h]=q.useState(null),g=E(t,h),_=q.useRef(null),v=q.useRef(``),y=p.viewport,b=r.content-r.viewport,x=F(u),S=F(c),C=Lt(d,10);function w(e){if(_.current){let t=e.clientX-_.current.left,n=e.clientY-_.current.top;l({x:t,y:n})}}return Y(w,`handleDragScroll`),q.useEffect(()=>{let e=Y(e=>{let t=e.target;m?.contains(t)&&x(e,b)},`handleWheel`);return document.addEventListener(`wheel`,e,{passive:!1}),()=>document.removeEventListener(`wheel`,e,{passive:!1})},[y,m,b,x]),q.useEffect(S,[r,S]),Q(m,C),Q(p.content,C),(0,J.jsx)(bt,{scope:n,scrollbar:m,hasThumb:i,onThumbChange:F(a),onThumbPointerUp:F(o),onThumbPositionChange:S,onThumbPointerDown:F(s),children:(0,J.jsx)(N.div,{...f,ref:g,style:{position:`absolute`,...f.style},onPointerDown:j(e.onPointerDown,e=>{e.button===0&&(e.target.setPointerCapture(e.pointerId),_.current=m.getBoundingClientRect(),v.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect=`none`,p.viewport&&(p.viewport.style.scrollBehavior=`auto`),w(e))}),onPointerMove:j(e.onPointerMove,w),onPointerUp:j(e.onPointerUp,e=>{let t=e.target;t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId),document.body.style.webkitUserSelect=v.current,p.viewport&&(p.viewport.style.scrollBehavior=``),_.current=null})})})},`ScrollAreaScrollbarImpl`)),Ct=`ScrollAreaThumb`,wt=q.forwardRef(Y(function(e,t){let{forceMount:n,...r}=e,i=xt(Ct,e.__scopeScrollArea);return(0,J.jsx)(P,{present:n||i.hasThumb,children:(0,J.jsx)(Tt,{ref:t,...r})})},`ScrollAreaThumb`)),Tt=q.forwardRef(Y(function(e,t){let{__scopeScrollArea:n,style:r,...i}=e,a=X(Ct,n),o=xt(Ct,n),{onThumbPositionChange:s}=o,c=E(t,o.onThumbChange),l=q.useRef(void 0),u=Lt(()=>{l.current&&=(l.current(),void 0)},100);return q.useEffect(()=>{let e=a.viewport;if(e){let t=Y(()=>{if(u(),!l.current){let t=It(e,s);l.current=t,s()}},`handleScroll`);return s(),e.addEventListener(`scroll`,t),()=>e.removeEventListener(`scroll`,t)}},[a.viewport,u,s]),(0,J.jsx)(N.div,{"data-state":o.hasThumb?`visible`:`hidden`,...i,ref:c,style:{width:`var(--radix-scroll-area-thumb-width)`,height:`var(--radix-scroll-area-thumb-height)`,...r},onPointerDownCapture:j(e.onPointerDownCapture,e=>{let t=e.target.getBoundingClientRect(),n=e.clientX-t.left,r=e.clientY-t.top;o.onThumbPointerDown({x:n,y:r})}),onPointerUp:j(e.onPointerUp,o.onThumbPointerUp)})},`ScrollAreaThumbImpl`)),Et=`ScrollAreaCorner`,Dt=q.forwardRef(Y(function(e,t){let n=X(Et,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!==`scroll`&&r?(0,J.jsx)(Ot,{...e,ref:t}):null},`ScrollAreaCorner`)),Ot=q.forwardRef(Y(function(e,t){let{__scopeScrollArea:n,...r}=e,i=X(Et,n),[a,o]=q.useState(0),[s,c]=q.useState(0),l=!!(a&&s),{onCornerWidthChange:u,onCornerHeightChange:d}=i;return Q(i.scrollbarX,()=>{let e=i.scrollbarX?.offsetHeight||0;i.onCornerHeightChange(e),c(e)}),Q(i.scrollbarY,()=>{let e=i.scrollbarY?.offsetWidth||0;i.onCornerWidthChange(e),o(e)}),q.useEffect(()=>()=>{u(0),d(0)},[u,d]),l?(0,J.jsx)(N.div,{...r,ref:t,style:{width:a,height:s,position:`absolute`,right:i.dir===`ltr`?0:void 0,left:i.dir===`rtl`?0:void 0,bottom:0,...e.style}}):null},`ScrollAreaCornerImpl`));function kt(e){return e?parseInt(e,10):0}Y(kt,`toInt`);function At(e,t){let n=e/t;return isNaN(n)?0:n}Y(At,`getThumbRatio`);function jt(e){let t=At(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}Y(jt,`getThumbSize`);function Mt(e,t,n,r=`ltr`){let i=jt(n),a=i/2,o=t||a,s=i-o,c=n.scrollbar.paddingStart+o,l=n.scrollbar.size-n.scrollbar.paddingEnd-s,u=n.content-n.viewport,d=r===`ltr`?[0,u]:[u*-1,0];return Pt([c,l],d)(e)}Y(Mt,`getScrollPositionFromPointer`);function Nt(e,t,n=`ltr`){let r=jt(t),i=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,a=t.scrollbar.size-i,o=t.content-t.viewport,s=a-r,c=n===`ltr`?[0,o]:[o*-1,0],l=te(e,c);return Pt([0,o],[0,s])(l)}Y(Nt,`getThumbOffsetFromScroll`);function Pt(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];let r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}Y(Pt,`linearScale`);function Ft(e,t){return e>0&&e<t}Y(Ft,`isScrollingWithinScrollbarBounds`);var It=Y((e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return Y((function i(){let a={left:e.scrollLeft,top:e.scrollTop},o=n.left!==a.left,s=n.top!==a.top;(o||s)&&t(),n=a,r=window.requestAnimationFrame(i)}),`loop`)(),()=>window.cancelAnimationFrame(r)},`addUnlinkedScrollListener`);function Lt(e,t){let n=F(e),r=q.useRef(0);return q.useEffect(()=>()=>window.clearTimeout(r.current),[]),q.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}Y(Lt,`useDebounceCallback`);function Q(e,t){let n=F(t);M(()=>{let t=0;if(e){let r=new ResizeObserver(()=>{cancelAnimationFrame(t),t=window.requestAnimationFrame(n)});return r.observe(e),()=>{window.cancelAnimationFrame(t),r.unobserve(e)}}},[e,n])}Y(Q,`useResizeObserver`);var Rt=lt,zt=dt,Bt=Dt,Vt=H(`notebook-text`,[[`path`,{d:`M2 6h4`,key:`aawbzj`}],[`path`,{d:`M2 10h4`,key:`l0bgd4`}],[`path`,{d:`M2 14h4`,key:`1gsvsf`}],[`path`,{d:`M2 18h4`,key:`1bu2t1`}],[`rect`,{width:`16`,height:`20`,x:`4`,y:`2`,rx:`2`,key:`1nb95v`}],[`path`,{d:`M9.5 8h5`,key:`11mslq`}],[`path`,{d:`M9.5 12H16`,key:`ktog6x`}],[`path`,{d:`M9.5 16H14`,key:`p1seyn`}]]),Ht=H(`sliders-horizontal`,[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]),$=h(),Ut=({chatState:e,chatId:t,messages:n})=>{if(!t)return T.warn(`No active chat`),e;let r=e.chats.get(t);if(!r)return T.warn(`No active chat`),e;let i=new Map(e.chats),a=Date.now();return i.set(r.id,{...r,messages:n,updatedAt:a}),{...e,chats:i}},Wt=class extends me{onChunkReceived;constructor(e,t){super(e),this.onChunkReceived=t}processResponseStream(e){let t=this.onChunkReceived;return super.processResponseStream(e).pipeThrough(new TransformStream({async transform(e,n){t(e),n.enqueue(e)}}))}},Gt=q.forwardRef((e,t)=>{let n=(0,$.c)(15),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:i,children:r,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;n[4]===i?o=n[5]:(o=k(`relative overflow-hidden`,i),n[4]=i,n[5]=o);let s;n[6]===r?s=n[7]:(s=(0,J.jsx)(zt,{className:`h-full w-full rounded-[inherit]`,children:r}),n[6]=r,n[7]=s);let c,l;n[8]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,J.jsx)(Kt,{}),l=(0,J.jsx)(Bt,{}),n[8]=c,n[9]=l):(c=n[8],l=n[9]);let u;return n[10]!==a||n[11]!==t||n[12]!==o||n[13]!==s?(u=(0,J.jsxs)(Rt,{ref:t,className:o,...a,children:[s,c,l]}),n[10]=a,n[11]=t,n[12]=o,n[13]=s,n[14]=u):u=n[14],u});Gt.displayName=Rt.displayName;var Kt=q.forwardRef((e,t)=>{let n=(0,$.c)(14),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,orientation:a,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=a===void 0?`vertical`:a,s=o===`vertical`&&`h-full w-2.5 border-l border-l-transparent p-px`,c=o===`horizontal`&&`h-2.5 flex-col border-t border-t-transparent p-px`,l;n[4]!==r||n[5]!==s||n[6]!==c?(l=k(`flex touch-none select-none transition-colors`,s,c,r),n[4]=r,n[5]=s,n[6]=c,n[7]=l):l=n[7];let u;n[8]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,J.jsx)(wt,{className:`relative flex-1 rounded-full bg-border`}),n[8]=u):u=n[8];let d;return n[9]!==o||n[10]!==i||n[11]!==t||n[12]!==l?(d=(0,J.jsx)(pt,{ref:t,orientation:o,className:l,...i,children:u}),n[9]=o,n[10]=i,n[11]=t,n[12]=l,n[13]=d):d=n[13],d});Kt.displayName=pt.displayName;var qt=[{label:`Today`,days:0},{label:`Yesterday`,days:1},{label:`2d ago`,days:2},{label:`3d ago`,days:3},{label:`This week`,days:7},{label:`This month`,days:30}],Jt=e=>{let t=Date.now(),n=qt.map(e=>({...e,chats:[]})),r={label:`Older`,days:1/0,chats:[]},i=e=>{switch(e){case 0:return n[0];case 1:return n[1];case 2:return n[2];case 3:return n[3];default:return e>=4&&e<=7?n[4]:e>=8&&e<=30?n[5]:r}};for(let n of e)i(Math.floor((t-n.updatedAt)/864e5)).chats.push(n);return[...n,r].filter(e=>e.chats.length>0)},Yt=e=>{let t=(0,$.c)(36),{activeChatId:n,setActiveChat:i}=e,a=r(Xe),{locale:o}=Je(),[s,c]=(0,q.useState)(``),u;t[0]===a.chats?u=t[1]:(u=[...a.chats.values()].toSorted(Xt),t[0]=a.chats,t[1]=u);let p=u,h;bb0:{if(!s.trim()){h=p;break bb0}let e;if(t[2]!==p||t[3]!==s){let n;t[5]===s?n=t[6]:(n=e=>e.title.toLowerCase().includes(s.toLowerCase()),t[5]=s,t[6]=n),e=p.filter(n),t[2]=p,t[3]=s,t[4]=e}else e=t[4];h=e}let g=h,_;t[7]===g?_=t[8]:(_=Jt(g),t[7]=g,t[8]=_);let v=_,y;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,J.jsx)(B,{content:`Previous chats`,children:(0,J.jsx)(f,{asChild:!0,children:(0,J.jsx)(V,{variant:`text`,size:`icon`,children:(0,J.jsx)(l,{className:`h-4 w-4`})})})}),t[9]=y):y=t[9];let b;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(b=e=>c(e.target.value),t[10]=b):b=t[10];let x;t[11]===s?x=t[12]:(x=(0,J.jsx)(`div`,{className:`pt-3 px-3 w-full`,children:(0,J.jsx)(He,{placeholder:`Search chat history...`,value:s,onChange:b,className:`text-xs`})}),t[11]=s,t[12]=x);let S;t[13]===p.length?S=t[14]:(S=p.length===0&&(0,J.jsx)(tt,{title:`No chats yet`,description:`Start a new chat to get started`,icon:(0,J.jsx)(le,{})}),t[13]=p.length,t[14]=S);let C;t[15]!==p.length||t[16]!==g.length||t[17]!==s?(C=g.length===0&&s&&p.length>0&&(0,J.jsx)(tt,{title:`No chats found`,description:`No chats match "${s}"`,icon:(0,J.jsx)(Ue,{})}),t[15]=p.length,t[16]=g.length,t[17]=s,t[18]=C):C=t[18];let w;if(t[19]!==n||t[20]!==v||t[21]!==o||t[22]!==i){let e;t[24]!==n||t[25]!==v.length||t[26]!==o||t[27]!==i?(e=(e,t)=>(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(`div`,{className:`text-xs px-1 text-muted-foreground/60`,children:e.label}),(0,J.jsx)(`div`,{children:e.chats.map(e=>(0,J.jsxs)(`button`,{className:k(`w-full p-1 rounded-md cursor-pointer text-left flex items-center justify-between`,e.id===n&&`bg-accent`,e.id!==n&&`hover:bg-muted/20`),onClick:()=>{i(e.id)},type:`button`,children:[(0,J.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,J.jsx)(`div`,{className:`text-sm truncate`,children:e.title})}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground/60 ml-2 shrink-0`,children:Ye(e.updatedAt,o)})]},e.id))}),t!==v.length-1&&(0,J.jsx)(`hr`,{})]},e.label),t[24]=n,t[25]=v.length,t[26]=o,t[27]=i,t[28]=e):e=t[28],w=v.map(e),t[19]=n,t[20]=v,t[21]=o,t[22]=i,t[23]=w}else w=t[23];let T;t[29]!==S||t[30]!==C||t[31]!==w?(T=(0,J.jsx)(Gt,{className:`h-[450px] p-2`,children:(0,J.jsxs)(`div`,{className:`space-y-3`,children:[S,C,w]})}),t[29]=S,t[30]=C,t[31]=w,t[32]=T):T=t[32];let E;return t[33]!==T||t[34]!==x?(E=(0,J.jsxs)(d,{children:[y,(0,J.jsxs)(m,{className:`w-[480px] p-0`,align:`start`,side:`right`,children:[x,T]})]}),t[33]=T,t[34]=x,t[35]=E):E=t[35],E};function Xt(e,t){return t.updatedAt-e.updatedAt}var Zt=()=>{let e=(0,$.c)(17),[n,r]=t(Qe),i=n.webSearch,a=i?`Capabilities (web search enabled)`:`Capabilities`,o=i||void 0,s=i&&`bg-primary/15 text-primary ring-1 ring-primary/30 opacity-100 hover:bg-primary/20`,c;e[0]===s?c=e[1]:(c=k(`h-6 w-6 shrink-0 bg-muted hover:bg-muted/30`,s),e[0]=s,e[1]=c);let l;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,J.jsx)(Ht,{className:`h-3.5 w-3.5`}),e[2]=l):l=e[2];let u;e[3]!==a||e[4]!==o||e[5]!==c?(u=(0,J.jsx)(f,{asChild:!0,children:(0,J.jsx)(V,{"aria-label":`Capabilities`,title:a,"data-active":o,variant:`text`,size:`icon`,className:c,children:l})}),e[3]=a,e[4]=o,e[5]=c,e[6]=u):u=e[6];let p;e[7]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,J.jsx)(`span`,{className:`text-sm font-semibold`,children:`Web search`}),e[7]=p):p=e[7];let h;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,J.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[p,(0,J.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Search the web when the model supports it.`,` `,(0,J.jsx)(ze,{href:`https://docs.marimo.io/guides/editor_features/tools#web-search-and-fetch`,children:`Learn more`})]})]}),e[8]=h):h=e[8];let g;e[9]===r?g=e[10]:(g=e=>r(t=>({...t,webSearch:e})),e[9]=r,e[10]=g);let _;e[11]!==g||e[12]!==i?(_=(0,J.jsx)(m,{className:`w-76 p-3`,align:`start`,side:`top`,children:(0,J.jsxs)(`label`,{htmlFor:`web-search-toggle`,className:`flex items-start justify-between gap-3 cursor-pointer`,children:[h,(0,J.jsx)(oe,{id:`web-search-toggle`,"aria-label":`Web search`,size:`sm`,checked:i,onCheckedChange:g})]})}),e[11]=g,e[12]=i,e[13]=_):_=e[13];let v;return e[14]!==u||e[15]!==_?(v=(0,J.jsxs)(d,{children:[u,_]}),e[14]=u,e[15]=_,e[16]=v):v=e[16],v};function Qt(){return qe()}function $t(e){let t=(0,$.c)(4),[n,r]=(0,q.useState)(Qt),a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=()=>r(Qt()),t[0]=a):a=t[0];let o=i(a),s=e??n,c;return t[1]!==o||t[2]!==s?(c={chatControllerId:s,renewDraftChatId:o},t[1]=o,t[2]=s,t[3]=c):c=t[3],c}var en=`manual`,tn=(0,q.memo)(e=>{let t=(0,$.c)(18),{message:n}=e,r;t[0]===n.parts?r=t[1]:(r=n.parts.filter(un).map(dn).join(`
2
- `),t[0]=n.parts,t[1]=r);let i=r,a,o,s;if(t[2]!==n.parts){let e=n.parts.filter(fn);s=`flex justify-end`,a=`w-[95%] bg-background border border-dashed p-2 rounded-sm opacity-70`,o=e.map(pn),t[2]=n.parts,t[3]=a,t[4]=o,t[5]=s}else a=t[3],o=t[4],s=t[5];let c;t[6]===i?c=t[7]:(c=(0,J.jsx)(`span`,{className:`wrap-break-word`,children:i}),t[6]=i,t[7]=c);let l;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,J.jsx)(Be,{className:`h-3.5 w-3.5 shrink-0 animate-spin`}),t[8]=l):l=t[8];let u;t[9]===c?u=t[10]:(u=(0,J.jsxs)(`div`,{className:`flex items-center justify-end gap-2 text-sm text-muted-foreground`,children:[c,l]}),t[9]=c,t[10]=u);let d;t[11]!==a||t[12]!==o||t[13]!==u?(d=(0,J.jsxs)(`div`,{className:a,children:[o,u]}),t[11]=a,t[12]=o,t[13]=u,t[14]=d):d=t[14];let f;return t[15]!==s||t[16]!==d?(f=(0,J.jsx)(`div`,{className:s,children:d}),t[15]=s,t[16]=d,t[17]=f):f=t[17],f});tn.displayName=`QueuedMessageDisplay`;var nn=e=>{let t=(0,$.c)(19),{onNewChat:n,activeChatId:r,setActiveChat:i}=e,{handleClick:a}=C(),o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,J.jsx)(K,{className:`h-4 w-4`}),t[0]=o):o=t[0];let s;t[1]===n?s=t[2]:(s=(0,J.jsx)(B,{content:`New chat`,children:(0,J.jsx)(V,{variant:`text`,size:`icon`,onClick:n,children:o})}),t[1]=n,t[2]=s);let c,l;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,J.jsx)(B,{content:`Connect your agent`,children:(0,J.jsx)(x,{className:`mr-1`,label:`Connect`})}),l=(0,J.jsx)(y,{}),t[3]=c,t[4]=l):(c=t[3],l=t[4]);let u;t[5]===a?u=t[6]:(u=()=>a(`ai`),t[5]=a,t[6]=u);let d;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,J.jsx)(We,{className:`h-4 w-4`}),t[7]=d):d=t[7];let f;t[8]===u?f=t[9]:(f=(0,J.jsx)(B,{content:`AI Settings`,children:(0,J.jsx)(V,{variant:`text`,size:`xs`,className:`hover:bg-foreground/10 py-2`,onClick:u,children:d})}),t[8]=u,t[9]=f);let p;t[10]!==r||t[11]!==i?(p=(0,J.jsx)(Yt,{activeChatId:r,setActiveChat:i}),t[10]=r,t[11]=i,t[12]=p):p=t[12];let m;t[13]!==f||t[14]!==p?(m=(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[c,l,f,p]}),t[13]=f,t[14]=p,t[15]=m):m=t[15];let h;return t[16]!==s||t[17]!==m?(h=(0,J.jsxs)(`div`,{className:`flex border-b px-2 py-1 justify-between shrink-0 items-center`,children:[s,m]}),t[16]=s,t[17]=m,t[18]=h):h=t[18],h},rn=(0,q.memo)(e=>{let t=(0,$.c)(17),{message:n,index:r,onEdit:i,isStreamingReasoning:a,isLast:o,isActive:s,addToolApprovalResponse:c}=e,l;t[0]!==r||t[1]!==i?(l=e=>{let t=(e.parts?.filter(mn))?.map(hn).join(`
3
- `),n=e.parts?.filter(gn);return(0,J.jsxs)(`div`,{className:`w-[95%] bg-background border p-1 rounded-sm`,children:[n?.map(_n),(0,J.jsx)(Ae,{value:t,placeholder:`Type your message...`,onChange:vn,onSubmit:(e,t)=>{t.trim()&&i(r,t)},onClose:yn},e.id)]})},t[0]=r,t[1]=i,t[2]=l):l=t[2];let u=l,d;t[3]!==c||t[4]!==s||t[5]!==o||t[6]!==a?(d=e=>{let t=e.parts.filter(bn).map(xn).join(`
4
- `);return(0,J.jsxs)(`div`,{className:`w-[95%] wrap-break-word`,children:[(0,J.jsx)(`div`,{className:`absolute right-1 top-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,J.jsx)(Ge,{className:`h-3 w-3`,value:t||``})}),pe({message:e,isStreamingReasoning:a,isLast:o,isActive:s,addToolApprovalResponse:c})]})},t[3]=c,t[4]=s,t[5]=o,t[6]=a,t[7]=d):d=t[7];let f=d,p=n.role===`user`?`justify-end`:`justify-start`,m;t[8]===p?m=t[9]:(m=k(`flex group relative`,p),t[8]=p,t[9]=m);let h;t[10]!==n||t[11]!==f||t[12]!==u?(h=n.role===`user`?u(n):f(n),t[10]=n,t[11]=f,t[12]=u,t[13]=h):h=t[13];let g;return t[14]!==m||t[15]!==h?(g=(0,J.jsx)(`div`,{className:m,children:h}),t[14]=m,t[15]=h,t[16]=g):g=t[16],g});rn.displayName=`ChatMessage`;var an=(0,q.memo)(e=>{let t=(0,$.c)(43),{isEmpty:n,onSendClick:i,isLoading:a,onStop:o,fileInputRef:s,onAddFiles:c,onAddContext:l}=e,u=r(_),d=u?.mode||en,f=u?.models?.chat_model||`openai/gpt-4o`,p=v.parse(f).providerId,{saveModeChange:m}=ee(),h;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(h=[{value:`manual`,label:`Manual`,subtitle:`Pure chat, no tool usage`,Icon:Ve},{value:`ask`,label:`Ask`,subtitle:`AI with access to read-only tools like documentation search`,Icon:Vt},{value:`agent`,label:`Agent`,subtitle:`AI with access to read and write tools`,Icon:Le},{value:`code_mode`,label:`Code Mode (beta)`,subtitle:`AI with access to the notebook's kernel. Potentially destructive.`,Icon:Ie}],t[0]=h):h=t[0];let g=h,y=ke.has(p),b;t[1]!==d||t[2]!==g?(b=g.find(e=>e.value===d),t[1]=d,t[2]=g,t[3]=b):b=t[3];let x=b,S=x?.Icon,C=x?.label,T;t[4]===S?T=t[5]:(T=S&&(0,J.jsx)(S,{className:`h-3 w-3`}),t[4]=S,t[5]=T);let E;t[6]===C?E=t[7]:(E=(0,J.jsx)(`span`,{className:`text-nowrap`,children:C}),t[6]=C,t[7]=E);let D;t[8]!==T||t[9]!==E?(D=(0,J.jsxs)(ie,{className:`h-6 text-xs border-border shadow-none! ring-0! bg-muted hover:bg-muted/30 py-0 px-2 gap-1.5 shrink-0`,children:[T,E]}),t[8]=T,t[9]=E,t[10]=D):D=t[10];let O;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,J.jsx)(R,{className:`text-xs uppercase tracking-wider text-muted-foreground/70 font-medium`,children:`AI Mode`}),t[11]=O):O=t[11];let k;t[12]===g?k=t[13]:(k=(0,J.jsx)(ne,{children:(0,J.jsxs)(re,{children:[O,g.map(Sn)]})}),t[12]=g,t[13]=k);let A;t[14]!==d||t[15]!==m||t[16]!==D||t[17]!==k?(A=(0,J.jsxs)(ae,{value:d,onValueChange:m,children:[D,k]}),t[14]=d,t[15]=m,t[16]=D,t[17]=k,t[18]=A):A=t[18];let j,M;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,J.jsx)(w,{placeholder:`Model`,triggerClassName:`h-6 text-xs shadow-none! ring-0! bg-muted hover:bg-muted/30 rounded-sm max-w-[200px]`,iconSize:`small`,showAddCustomModelDocs:!0,forRole:`chat`}),j=(0,J.jsx)(Zt,{}),t[19]=j,t[20]=M):(j=t[19],M=t[20]);let N;t[21]===A?N=t[22]:(N=(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[A,M,j]}),t[21]=A,t[22]=N);let P;t[23]!==a||t[24]!==l?(P=(0,J.jsx)(U,{handleAddContext:l,isLoading:a}),t[23]=a,t[24]=l,t[25]=P):P=t[25];let F;t[26]!==s||t[27]!==y||t[28]!==a||t[29]!==c?(F=y&&(0,J.jsx)(W,{fileInputRef:s,isLoading:a,onAddFiles:c}),t[26]=s,t[27]=y,t[28]=a,t[29]=c,t[30]=F):F=t[30];let I;t[31]!==n||t[32]!==a||t[33]!==i||t[34]!==o?(I=(0,J.jsx)(Te,{isLoading:a,onStop:o,onSendClick:i,isEmpty:n}),t[31]=n,t[32]=a,t[33]=i,t[34]=o,t[35]=I):I=t[35];let L;t[36]!==P||t[37]!==F||t[38]!==I?(L=(0,J.jsxs)(`div`,{className:`flex flex-row ml-auto`,children:[P,F,I]}),t[36]=P,t[37]=F,t[38]=I,t[39]=L):L=t[39];let z;return t[40]!==N||t[41]!==L?(z=(0,J.jsx)(se,{children:(0,J.jsxs)(`div`,{className:`px-3 py-2 border-t border-border/20 flex flex-wrap items-center gap-1`,children:[N,L]})}),t[40]=N,t[41]=L,t[42]=z):z=t[42],z});an.displayName=`ChatInputFooter`;var on=(0,q.memo)(e=>{let t=(0,$.c)(31),{placeholder:n,input:r,inputClassName:a,setInput:o,onSubmit:s,inputRef:c,isLoading:l,onStop:u,fileInputRef:d,onAddFiles:f,onClose:p}=e,m;t[0]!==r||t[1]!==s?(m=()=>{r.trim()&&s(void 0,r)},t[0]=r,t[1]=s,t[2]=m):m=t[2];let h=i(m),g;t[3]===a?g=t[4]:(g=k(`px-2 py-1.5`,a),t[3]=a,t[4]=g);let _=n||`Type your message...`,v;t[5]!==r||t[6]!==c||t[7]!==f||t[8]!==p||t[9]!==s||t[10]!==o||t[11]!==_?(v=(0,J.jsx)(Ae,{className:`max-h-[400px]`,inputRef:c,value:r,onChange:o,onSubmit:s,onClose:p,onAddFiles:f,placeholder:_}),t[5]=r,t[6]=c,t[7]=f,t[8]=p,t[9]=s,t[10]=o,t[11]=_,t[12]=v):v=t[12];let y;t[13]!==g||t[14]!==v?(y=(0,J.jsx)(`div`,{className:g,children:v}),t[13]=g,t[14]=v,t[15]=y):y=t[15];let b;t[16]===r?b=t[17]:(b=r.trim(),t[16]=r,t[17]=b);let x=!b,S;t[18]===c?S=t[19]:(S=()=>Me(c),t[18]=c,t[19]=S);let C;t[20]!==d||t[21]!==h||t[22]!==l||t[23]!==f||t[24]!==u||t[25]!==x||t[26]!==S?(C=(0,J.jsx)(an,{isEmpty:x,onAddContext:S,onSendClick:h,isLoading:l,onStop:u,fileInputRef:d,onAddFiles:f}),t[20]=d,t[21]=h,t[22]=l,t[23]=f,t[24]=u,t[25]=x,t[26]=S,t[27]=C):C=t[27];let w;return t[28]!==y||t[29]!==C?(w=(0,J.jsxs)(`div`,{className:`relative shrink-0 flex flex-col border-t`,children:[y,C]}),t[28]=y,t[29]=C,t[30]=w):w=t[30],w});on.displayName=`ChatInput`;var sn=e=>{let t=(0,$.c)(5),{onPairWithAgent:n}=e;if(D())return null;let r,i,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,J.jsx)(p,{className:`h-3.5 w-3.5 shrink-0`}),i=(0,J.jsx)(`span`,{children:`Connect your own agent to this notebook`}),a=(0,J.jsx)(ce,{className:`h-3 w-3 shrink-0`}),t[0]=r,t[1]=i,t[2]=a):(r=t[0],i=t[1],a=t[2]);let o;return t[3]===n?o=t[4]:(o=(0,J.jsxs)(V,{variant:`text`,className:`gap-1.5 text-sm text-link hover:underline`,onClick:n,children:[r,i,a]}),t[3]=n,t[4]=o),o},cn=()=>{let e=(0,$.c)(9),t=r(g),{handleClick:n}=C();if(!t){let t;e[0]===n?t=e[1]:(t=(0,J.jsx)(V,{variant:`outline`,size:`sm`,className:`self-start`,onClick:()=>n(`ai`,`ai-providers`),children:`Edit AI settings`}),e[0]=n,e[1]=t);let r;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,J.jsx)(S,{}),e[2]=r):r=e[2];let i;e[3]===t?i=e[4]:(i=(0,J.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[t,r]}),e[3]=t,e[4]=i);let a;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,J.jsx)(le,{}),e[5]=a):a=e[5];let o;return e[6]===i?o=e[7]:(o=(0,J.jsx)(tt,{title:`Chat with AI`,description:`No AI provider configured or Chat model not selected`,action:i,icon:a}),e[6]=i,e[7]=o),o}let i;return e[8]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,J.jsx)(ln,{}),e[8]=i):i=e[8],i},ln=()=>{let e=a(Xe),[r,o]=t($e),[l,d]=t(Ze),[f,p]=(0,q.useState)(``),[m,h]=(0,q.useState)(``),[g,v]=(0,q.useState)(!0),{files:y,addFiles:x,clearFiles:S,removeFile:C}=be(),{messages:w,enqueue:E,flushNext:D,clear:A,hasQueuedRef:j}=he(),M=(0,q.useRef)(null),N=(0,q.useRef)(null),P=(0,q.useRef)(null),F=(0,q.useRef)(null),I=(0,q.useRef)(null),[L,ee]=(0,q.useState)(null),R=i(()=>{I.current=null,ee(null)}),z=O(),{invokeAiTool:te,sendRun:ne}=Ke(),{openModal:re,closeModal:ie}=Re(),ae=r?.id,{chatControllerId:oe,renewDraftChatId:B}=$t(ae),H=n(),{addStagedCell:ce}=ve(),{createNewCell:le,prepareForRun:pe}=s(),me={addStagedCell:ce,createNewCell:le,prepareForRun:pe,sendRun:ne,store:H},{messages:U,sendMessage:Te,error:W,status:ke,regenerate:Ae,stop:G,addToolOutput:Me,addToolApprovalResponse:Ie,id:Le}=Fe({id:oe,throttle:100,sendAutomaticallyWhen:({messages:e})=>je(e),messages:r?.messages||[],transport:new Wt({api:z.getAiURL(`chat`).toString(),headers:()=>z.headers(),prepareSendMessagesRequest:async e=>{let t=await xe({messages:e.messages});t.success||T.debug(`Outgoing chat messages failed AI SDK schema validation`,t.error);let n={uiMessages:e.messages,includeOtherCode:c(``),options:H.get(Qe)},r=H.get(_)?.mode||en,i=Oe.getToolSchemas(r);return{api:z.getAiURL(`chat`).toString(),body:{tools:i,...e,...n}}}},e=>{let t=fe(e);t!==void 0&&(I.current=t)}),onFinish:({messages:t,isError:n,isAbort:r,finishReason:i})=>{if(e(e=>Ut({chatState:e,chatId:e.activeChatId,messages:t})),r){let e=ue({isAbort:!0,streamReason:I.current});if(R(),e!=null){let t=de(e);T.debug(`Chat stream aborted`,{reason:e,finishReason:i}),ee(t)}}else R();Ve(t,{isError:n,isAbort:r})},onToolCall:async({toolCall:e})=>{await Se({invokeAiTool:te,addToolOutput:Me,toolCall:{toolName:e.toolName,toolCallId:e.toolCallId,input:e.input},toolContext:me})},onError:e=>{T.error(`An error occurred:`,e)}}),ze=i(e=>{R(),Te({role:`user`,parts:e})}),Ve=i((e,t)=>{j.current&&Ne({isError:t.isError,isAbort:t.isAbort,hasPendingToolCalls:je(e),hasUnresolvedToolCalls:Pe(e)})&&D(ze)}),K=ke===`submitted`||ke===`streaming`,He=(0,q.useRef)(K);He.current=K;let Ue=i(e=>{He.current||j.current?E(e):ze(e)}),We=i(()=>{let e=P.current;if(!e)return;let{scrollTop:t,scrollHeight:n,clientHeight:r}=e,i=n>r?Math.abs(n-r-t)<5:!0;v(i)}),Ge=i((e=!1)=>{let t=P.current;t&&t.scrollTo({top:t.scrollHeight,behavior:e?`smooth`:`auto`})}),qe=K&&U.length>0&&Ce(U);(0,q.useEffect)(()=>{v(!0),A(),R()},[ae,A,R]),(0,q.useEffect)(()=>{if(!g)return;let e=requestAnimationFrame(()=>{Ge()});return()=>cancelAnimationFrame(e)},[U,w,K,g,Ge]),(0,q.useEffect)(()=>{K||Ve(U,{isError:W!=null,isAbort:!1})},[U,K,W,Ve]);let Je=i(t=>{let n=Date.now(),r={id:Le,title:Ee(t),messages:[],createdAt:n,updatedAt:n};e(e=>{let t=new Map(e.chats);return t.set(r.id,r),{...e,chats:t,activeChatId:r.id}})}),Ye=i(async(e,t)=>{Je(e);let n=t&&t.length>0?await De(t):void 0,{contextPart:r,attachments:i}=await ge(e);Te({role:`user`,parts:[{type:`text`,text:e},...r?[r]:[],...n??[],...i]}),S(),p(``)}),tt=i(()=>{B(),o(null),p(``),h(``),A(),S()}),rt=i(()=>{re((0,J.jsx)(b,{onClose:ie}))}),Y=i(async(e,t)=>{let n=U[e],r=n.parts?.filter(e=>e.type===`file`&&!_e(e))??[],{contextPart:i,attachments:a}=await ge(t),o=n.id;Te({messageId:o,role:`user`,parts:[{type:`text`,text:t},...i?[i]:[],...r,...a]})}),it=i(async(e,t)=>{if(!t.trim())return;N.current?.view&&ye(N.current.view);let n=y?await De(y):void 0,{contextPart:r,attachments:i}=await ge(t);e?.preventDefault(),Ue([{type:`text`,text:t},...r?[r]:[],...n??[],...i]),p(``),S()}),at=()=>{R(),Ae()},ot=i(()=>{m.trim()&&(M.current?.view&&ye(M.current.view),Ye(m.trim(),y))}),st=()=>M.current?.editor?.blur(),ct=i(async e=>{ae??(Je(e),p(m));let{contextPart:t,attachments:n}=await ge(e);Ue([{type:`text`,text:e},...t?[t]:[],...n])}),X=U.length===0;(0,q.useEffect)(()=>{if(!l)return;d(null);let{prompt:e,submit:t}=l;t?ct(e):X?(h(e),u(M)):(p(e),u(N))},[l,d,X,ct]);let lt=X?(0,J.jsx)(on,{placeholder:`Ask anything, @ to include context about tables or dataframes`,input:m,inputRef:M,inputClassName:`px-1 py-0`,setInput:h,onSubmit:ot,isLoading:K,onStop:G,fileInputRef:F,onAddFiles:x,onClose:st},`new-thread-input`):(0,J.jsx)(on,{input:f,setInput:p,onSubmit:it,inputRef:N,isLoading:K,onStop:G,onClose:()=>N.current?.editor?.blur(),fileInputRef:F,onAddFiles:x}),ut=y&&y.length>0&&(0,J.jsx)(`div`,{className:k(`flex flex-row gap-1 flex-wrap p-1`,X&&`py-2 px-1`),children:y?.map(e=>(0,J.jsx)(we,{file:e,onRemove:()=>C(e)},e.name))});return(0,J.jsxs)(`div`,{className:`flex flex-col h-[calc(100%-53px)]`,children:[(0,J.jsx)(se,{children:(0,J.jsx)(nn,{onNewChat:tt,activeChatId:r?.id,setActiveChat:o})}),(0,J.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden relative min-h-0`,children:[(0,J.jsxs)(`div`,{className:`flex-1 px-3 bg-(--slate-1) gap-4 py-3 flex flex-col overflow-y-auto`,ref:P,onScroll:We,children:[X&&(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,J.jsxs)(`div`,{className:`rounded-md border bg-background`,children:[ut,lt]}),(0,J.jsx)(sn,{onPairWithAgent:rt})]}),U.map((e,t)=>(0,J.jsx)(rn,{message:e,index:t,onEdit:Y,isStreamingReasoning:qe,isLast:t===U.length-1,isActive:K,addToolApprovalResponse:Ie},e.id)),w.map(e=>(0,J.jsx)(tn,{message:e},e.id)),K&&(0,J.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,J.jsx)(Be,{className:`h-4 w-4 animate-spin`})}),W&&(0,J.jsxs)(`div`,{className:`flex items-center justify-center space-x-2 mb-4`,children:[(0,J.jsx)(et,{error:W||Error(`Unknown error`)}),(0,J.jsx)(V,{variant:`outline`,size:`sm`,onClick:at,children:`Retry`})]}),L&&!K&&!W&&(0,J.jsx)(`div`,{className:`flex justify-center py-2`,children:(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:L})})]}),(0,J.jsx)(nt,{isVisible:!g&&(U.length>0||w.length>0),onScrollToBottom:()=>Ge(!0)})]}),K&&(0,J.jsx)(`div`,{className:`w-full flex justify-center items-center z-20 border-t`,children:(0,J.jsx)(V,{variant:`linkDestructive`,size:`sm`,onClick:G,children:`Stop`})}),!X&&(0,J.jsxs)(J.Fragment,{children:[ut,lt]})]})};function un(e){return e.type===`text`}function dn(e){return e.text}function fn(e){return e.type===`file`}function pn(e,t){return(0,J.jsx)(G,{attachment:e},t)}function mn(e){return e.type===`text`}function hn(e){return e.text}function gn(e){return e.type===`file`}function _n(e,t){return(0,J.jsx)(G,{attachment:e},t)}function vn(){}function yn(){}function bn(e){return e.type===`text`}function xn(e){return e.text}function Sn(e){return(0,J.jsx)(z,{value:e.value,className:`text-xs py-1`,children:(0,J.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,J.jsx)(`span`,{className:`mt-1 text-muted-foreground`,children:(0,J.jsx)(e.Icon,{className:`h-3 w-3`})}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,J.jsx)(`span`,{className:`font-semibold`,children:e.label}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:e.subtitle})]})]})},e.value)}export{cn as default};