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.0 KB
Raw Blame
/* Copyright 2026 Marimo. All rights reserved. */

export const ConnectionState = {
  NOT_STARTED: "NOT_STARTED",
  CONNECTING: "CONNECTING",
  OPEN: "OPEN",
  CLOSING: "CLOSING",
  CLOSED: "CLOSED",
} as const;

export type ConnectionState =
  (typeof ConnectionState)[keyof typeof ConnectionState];

export const ConnectionClosedReason = {
  KERNEL_DISCONNECTED: "KERNEL_DISCONNECTED",
  KERNEL_STARTUP_ERROR: "KERNEL_STARTUP_ERROR",
} as const;

export type ConnectionClosedReason =
  (typeof ConnectionClosedReason)[keyof typeof ConnectionClosedReason];

export type ConnectionStatus =
  | {
      state: typeof ConnectionState.CLOSED;
      code: ConnectionClosedReason;
      reason: string;
    }
  | {
      state: typeof ConnectionState.CONNECTING;
    }
  | {
      state:
        | typeof ConnectionState.OPEN
        | typeof ConnectionState.CLOSING
        | typeof ConnectionState.NOT_STARTED;
    };

/** The recovery policy for a closed connection. */
export interface CloseDecision {
  kind: "terminal" | "retry";
  status: ConnectionStatus;
}