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.

3.9 KB
Raw Blame
/* Copyright 2026 Marimo. All rights reserved. */
import { toast } from "@/components/ui/use-toast";
import { Logger } from "@/utils/Logger";
import type { EditRequests, RunRequests } from "./types";

const STATIC_NOTEBOOK_TOAST_ID = "static-notebook";

function showStaticNotebookToast() {
  toast({
    id: STATIC_NOTEBOOK_TOAST_ID,
    once: true,
    title: "Static notebook",
    description:
      "This notebook is not connected to a kernel. Any interactive elements will not work.",
  });
}

export function createStaticRequests(): EditRequests & RunRequests {
  const throwNotInEditMode = () => {
    throw new Error("Unreachable. Expected to be in run mode");
  };

  return {
    sendComponentValues: async () => {
      showStaticNotebookToast();
      Logger.log("Updating UI elements is not supported in static mode");
      return null;
    },
    sendModelValue: async () => {
      Logger.log("Updating model values is not supported in static mode");
      return null;
    },
    sendInstantiate: async () => {
      Logger.log("Viewing as static notebook");
      return null;
    },
    sendFunctionRequest: async () => {
      showStaticNotebookToast();
      Logger.log("Function requests are not supported in static mode");
      return null;
    },
    sendRestart: throwNotInEditMode,
    sendRun: throwNotInEditMode,
    sendRunScratchpad: throwNotInEditMode,
    sendRename: throwNotInEditMode,
    saveLayout: throwNotInEditMode,
    sendCopy: throwNotInEditMode,
    sendInterrupt: throwNotInEditMode,
    sendShutdown: throwNotInEditMode,
    sendFormat: throwNotInEditMode,
    sendCodeCompletionRequest: throwNotInEditMode,
    saveUserConfig: throwNotInEditMode,
    saveAppConfig: throwNotInEditMode,
    sendStdin: throwNotInEditMode,
    readCode: throwNotInEditMode,
    readSnippets: throwNotInEditMode,
    previewDatasetColumn: throwNotInEditMode,
    previewSQLTable: throwNotInEditMode,
    previewSQLTableList: throwNotInEditMode,
    previewSQLSchemaList: throwNotInEditMode,
    previewDataSourceConnection: throwNotInEditMode,
    discoverDataSources: throwNotInEditMode,
    validateSQL: throwNotInEditMode,
    openFile: throwNotInEditMode,
    getUsageStats: throwNotInEditMode,
    getEnvironmentInfo: throwNotInEditMode,
    getFileRoots: throwNotInEditMode,
    sendListFiles: throwNotInEditMode,
    sendSearchFiles: throwNotInEditMode,
    sendPdb: throwNotInEditMode,
    sendSetBreakpoints: throwNotInEditMode,
    sendCreateFileOrFolder: throwNotInEditMode,
    sendDeleteFileOrFolder: throwNotInEditMode,
    sendCopyFileOrFolder: throwNotInEditMode,
    sendRenameFileOrFolder: throwNotInEditMode,
    sendUpdateFile: throwNotInEditMode,
    sendFileDetails: throwNotInEditMode,
    openTutorial: throwNotInEditMode,
    sendInstallMissingPackages: throwNotInEditMode,
    getRecentFiles: throwNotInEditMode,
    getWorkspaceFiles: throwNotInEditMode,
    getRunningNotebooks: throwNotInEditMode,
    shutdownSession: throwNotInEditMode,
    getExportAvailability: throwNotInEditMode,
    installExportRequirements: throwNotInEditMode,
    exportAsHTML: throwNotInEditMode,
    exportAsIPYNB: throwNotInEditMode,
    exportAsMarkdown: throwNotInEditMode,
    exportAsScript: throwNotInEditMode,
    exportAsPDF: throwNotInEditMode,
    autoExportAsHTML: throwNotInEditMode,
    autoExportAsMarkdown: throwNotInEditMode,
    autoExportAsIPYNB: throwNotInEditMode,
    updateCellOutputs: throwNotInEditMode,
    addPackage: throwNotInEditMode,
    removePackage: throwNotInEditMode,
    getPackageList: throwNotInEditMode,
    getSandbox: throwNotInEditMode,
    updateManifest: throwNotInEditMode,
    syncSandbox: throwNotInEditMode,
    getDependencyTree: throwNotInEditMode,
    listSecretKeys: throwNotInEditMode,
    writeSecret: throwNotInEditMode,
    invokeAiTool: throwNotInEditMode,
    clearCache: throwNotInEditMode,
    getCacheInfo: throwNotInEditMode,
    listStorageEntries: throwNotInEditMode,
    downloadStorage: throwNotInEditMode,
  };
}