clabe.server ¶
Serve a run over HTTP: a snapshot, a resumable Server-Sent Events stream, answers and commands, described by
OpenAPI (/openapi.json); plus a thin Python client.
RunClient ¶
RunClient(
base_url: str,
*,
token: str | None = None,
name: str = "remote",
timeout: float = 10.0,
)
Talks to a served run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
The server's root URL, e.g. |
required |
token
|
str | None
|
The shared token, when the server requires one. |
None
|
name
|
str
|
Recorded as the client in answers and commands. |
'remote'
|
timeout
|
float
|
Seconds to wait for a non-streaming request. |
10.0
|
Source code in src/clabe/server/_client.py
answer ¶
answer(prompt_id: str, value: Any) -> CommandResult
back ¶
back(step: str | None = None) -> CommandResult
Goes back to step; to the previous step (the state's back_target) when omitted.
Source code in src/clabe/server/_client.py
retry ¶
retry(step: str) -> CommandResult
skip ¶
skip(step: str) -> CommandResult
forward ¶
forward() -> CommandResult
close ¶
close() -> CommandResult
options ¶
The options of an open autocomplete prompt for the text typed so far.
Source code in src/clabe/server/_client.py
report ¶
report(comment: str = '') -> ReportInfo
Files an issue report with comment; returns what was saved.
Source code in src/clabe/server/_client.py
abort ¶
abort(reason: str = 'Aborted by user.') -> CommandResult
list_dir ¶
list_dir(
path: str | None = None,
*,
kind: str = "any",
extensions: list[str] | None = None,
) -> DirListing
Lists a directory of the machine running the run.
Source code in src/clabe/server/_client.py
events ¶
Follows the run's events from after; reconnects (resuming) when the stream drops, until the run ends.
Source code in src/clabe/server/_client.py
AbortBody ¶
Bases: BaseModel
Aborts the run.
AnswerBody ¶
Bases: BaseModel
An answer to an open prompt.
ClientBody ¶
Bases: BaseModel
Identifies who sends a command.
CommandResult ¶
Bases: BaseModel
Outcome of an answer or a command: accepted, or rejected with a reason to show the user.
DirEntry ¶
Bases: BaseModel
One entry of a listed directory.
DirListing ¶
Bases: BaseModel
A listed directory.
ListDirBody ¶
Bases: BaseModel
Lists a directory of the machine running the run (the remote path picker).
ServerInfo ¶
Bases: BaseModel
Identity of the server and the run it serves.
SessionInfo ¶
Bases: BaseModel
What a run is about, as far as known so far: the hub lists it as a session.
RunServer ¶
Serves a run over HTTP (API + web UI) on a background thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run
|
Run
|
The run to serve. |
required |
host
|
str
|
Interface to bind; |
'127.0.0.1'
|
port
|
int
|
Preferred port; the next free one is used when it is taken. |
8090
|
token
|
str | None
|
When set, every API request must carry it. |
None
|
Source code in src/clabe/server/_server.py
url
property
¶
url: str
Where the run is served (with the token, when one is set).
Open to the LAN (0.0.0.0 or ::), it names this computer, so the address also works from other PCs.
start ¶
Starts serving (on the next free port if needed) and returns the URL.
Raises:
| Type | Description |
|---|---|
ImportError
|
The web server (the |
Source code in src/clabe/server/_server.py
create_app ¶
create_app(
run: Run,
*,
token: str | None = None,
static_dir: Path | None = STATIC_DIR,
logs: LogBuffer | None = None,
) -> FastAPI
Builds the API serving run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run
|
Run
|
The run to serve. |
required |
token
|
str | None
|
When set, every API request must carry it ( |
None
|
static_dir
|
Path | None
|
Directory of the web UI to serve at |
STATIC_DIR
|
logs
|
LogBuffer | None
|
The process' log records to serve at |
None
|
Source code in src/clabe/server/_app.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
free_port ¶
The first port from start on which host can listen.