Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

feat: add ai chat persistence between sessions (#5141)

Joaquin Corominab31b27580615
diff --git a/frontend/src/core/ai/state.ts b/frontend/src/core/ai/state.ts
index 6c51e0231f..413e102c02 100644
--- a/frontend/src/core/ai/state.ts
+++ b/frontend/src/core/ai/state.ts
@@ -1,7 +1,10 @@
/* Copyright 2024 Marimo. All rights reserved. */
import { atom } from "jotai";
+import { atomWithStorage } from "jotai/utils";
import type { CellId } from "../cells/ids";
+const KEY = "marimo:ai:chatState:v1";
+
export const aiCompletionCellAtom = atom<{
cellId: CellId;
initialPrompt?: string;
@@ -27,7 +30,7 @@ export interface ChatState {
activeChatId: string | null;
}
-export const chatStateAtom = atom<ChatState>({
+export const chatStateAtom = atomWithStorage<ChatState>(KEY, {
chats: [],
activeChatId: null,
});