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.

1.2 KB
Raw Blame
/* Copyright 2026 Marimo. All rights reserved. */

import { atom } from "jotai";
import type { DocumentModel } from "../notebook/document";
import type { NotebookReplica } from "../notebook/replica";

/** The replica owned by the mounted notebook session. */
export const activeNotebookReplicaAtom = atom<NotebookReplica | null>(null);

/** The document model owned by the mounted notebook session. */
export const activeDocumentModelAtom = atom<DocumentModel | null>(null);

/** The backend of the connected notebook, or null while none is. */
export const activeNotebookBackendAtom = atom((get) => {
  const replica = get(activeNotebookReplicaAtom);
  return replica === null ? null : get(replica.backendAtom);
});

/**
 * The document the host last confirmed, or null while no notebook is
 * connected. Facts the host owns read this one, such as permission, the
 * app config, saved state and whether source is available. What the user
 * is editing reads the model's document, which adds this browser's drafts.
 */
export const confirmedDocumentAtom = atom((get) => {
  const replica = get(activeNotebookReplicaAtom);
  return replica === null ? null : get(replica.documentAtom);
});