|
| 1 | +# Copyright 2026 Marimo. All rights reserved. |
| 2 | +# AUTO-GENERATED FILE — DO NOT EDIT. |
| 3 | +# Regenerate with `make host-protocol-codegen`. |
| 4 | +# ruff: noqa: TC003 - msgspec resolves annotations at runtime |
| 5 | +"""Python bindings for the `marimo.breakpoints` notebook extension. |
| 6 | +
|
| 7 | +Each operation defines a `Call` type for its decoded request and a |
| 8 | +`Result` type for its handler's response. The host uses `event` |
| 9 | +to publish the extension's record and `handle` to dispatch a call to |
| 10 | +the handlers for one notebook. |
| 11 | +""" |
| 12 | + |
| 13 | +from __future__ import annotations |
| 14 | + |
| 15 | +from datetime import datetime |
| 16 | +from typing import Annotated, Final, Protocol, TypeAlias, assert_never |
| 17 | + |
| 18 | +import msgspec |
| 19 | +from msgspec import UNSET, Meta, Struct, UnsetType |
| 20 | + |
| 21 | +from marimo._core import protocol, result |
| 22 | +from marimo._core.protocol import RuntimeId, Timestamp |
| 23 | +from marimo._core.protocol.api import MutationProblem |
| 24 | +from marimo._core.stream import ExtensionEvent |
| 25 | + |
| 26 | +BreakpointLine: TypeAlias = Annotated[int, Meta(ge=1)] |
| 27 | + |
| 28 | + |
| 29 | +class Breakpoints(Struct, frozen=True): |
| 30 | + cells: Annotated[ |
| 31 | + dict[str, tuple[BreakpointLine, ...]], |
| 32 | + Meta(description="One-based breakpoint lines by cell id."), |
| 33 | + ] |
| 34 | + runtime_id: RuntimeId |
| 35 | + |
| 36 | + |
| 37 | +class MarimoBreakpointsMessage(Struct, frozen=True): |
| 38 | + marimo_breakpoints: Breakpoints = msgspec.field(name="marimo.breakpoints") |
| 39 | + request_id: ( |
| 40 | + Annotated[ |
| 41 | + str, |
| 42 | + Meta( |
| 43 | + description="The `Idempotency-Key` of the request that caused this event. Omitted when no request did, and on snapshots unless that request's work is still in progress." |
| 44 | + ), |
| 45 | + ] |
| 46 | + | UnsetType |
| 47 | + ) = UNSET |
| 48 | + time: ( |
| 49 | + Annotated[ |
| 50 | + Timestamp, |
| 51 | + Meta( |
| 52 | + description="When the host published this event. Present on live and replayed events; omitted on snapshots." |
| 53 | + ), |
| 54 | + ] |
| 55 | + | UnsetType |
| 56 | + ) = UNSET |
| 57 | + |
| 58 | + |
| 59 | +class ReplaceBreakpointsRequest( |
| 60 | + Struct, frozen=True, forbid_unknown_fields=True |
| 61 | +): |
| 62 | + cells: Annotated[ |
| 63 | + dict[str, tuple[BreakpointLine, ...]], |
| 64 | + Meta(description="One-based breakpoint lines by cell id."), |
| 65 | + ] |
| 66 | + |
| 67 | + |
| 68 | +class MarimoBreakpointsEvent( |
| 69 | + ExtensionEvent, frozen=True, tag="marimo.breakpoints" |
| 70 | +): |
| 71 | + data: MarimoBreakpointsMessage |
| 72 | + |
| 73 | + |
| 74 | +def event( |
| 75 | + record: Breakpoints, |
| 76 | + *, |
| 77 | + request_id: str | UnsetType = UNSET, |
| 78 | + time: datetime | UnsetType = UNSET, |
| 79 | +) -> MarimoBreakpointsEvent: |
| 80 | + return MarimoBreakpointsEvent( |
| 81 | + MarimoBreakpointsMessage( |
| 82 | + marimo_breakpoints=record, request_id=request_id, time=time |
| 83 | + ) |
| 84 | + ) |
| 85 | + |
| 86 | + |
| 87 | +class Replace: |
| 88 | + """Replace the current runtime's debugger breakpoints.""" |
| 89 | + |
| 90 | + ID: Final = "notebook.extensions.breakpoints.replace" |
| 91 | + METHOD: Final = "PUT" |
| 92 | + PATH: Final = "/extensions/marimo.breakpoints/notebooks/{notebook_id}" |
| 93 | + |
| 94 | + class Params(msgspec.Struct, frozen=True): |
| 95 | + notebook_id: protocol.NotebookId |
| 96 | + |
| 97 | + class Headers(msgspec.Struct, frozen=True): |
| 98 | + idempotency_key: str = msgspec.field(name="idempotency-key") |
| 99 | + |
| 100 | + class Call( |
| 101 | + msgspec.Struct, |
| 102 | + frozen=True, |
| 103 | + tag_field="operation", |
| 104 | + tag="notebook.extensions.breakpoints.replace", |
| 105 | + ): |
| 106 | + params: Replace.Params |
| 107 | + headers: Replace.Headers |
| 108 | + body: ReplaceBreakpointsRequest |
| 109 | + |
| 110 | + Result: TypeAlias = result.Result[ |
| 111 | + Breakpoints, MutationProblem | protocol.NoRuntimeProblem |
| 112 | + ] |
| 113 | + |
| 114 | + |
| 115 | +class Handlers(Protocol): |
| 116 | + """Operations an implementation of `marimo.breakpoints` must provide.""" |
| 117 | + |
| 118 | + async def replace(self, call: Replace.Call, /) -> Replace.Result: ... |
| 119 | + |
| 120 | + |
| 121 | +OPERATIONS = (Replace,) |
| 122 | +Call: TypeAlias = Replace.Call |
| 123 | + |
| 124 | + |
| 125 | +async def handle( |
| 126 | + handlers: Handlers, call: Call |
| 127 | +) -> result.Result[ |
| 128 | + tuple[int, msgspec.Struct | None], |
| 129 | + MutationProblem | protocol.NoRuntimeProblem, |
| 130 | +]: |
| 131 | + match call: |
| 132 | + case Replace.Call(): |
| 133 | + outcome_replace = await handlers.replace(call) |
| 134 | + if outcome_replace.ok: |
| 135 | + return result.Ok((200, outcome_replace.value)) |
| 136 | + return outcome_replace |
| 137 | + assert_never(call) |
0 commit comments