zettcode-gateway 0.3.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zettcode/gateway/__init__.py +22 -0
- zettcode/gateway/app.py +454 -0
- zettcode/gateway/backend.py +368 -0
- zettcode/gateway/chat.py +142 -0
- zettcode/gateway/cli.py +495 -0
- zettcode/gateway/py.typed +0 -0
- zettcode/gateway/runfile.py +145 -0
- zettcode/gateway/service.py +1219 -0
- zettcode/gateway/settings.py +62 -0
- zettcode/gateway/static/app.css +1434 -0
- zettcode/gateway/static/app.js +3 -0
- zettcode/gateway/static/assets/KaTeX_AMS-Regular-U6PRYMIZ.woff2 +0 -0
- zettcode/gateway/static/assets/KaTeX_Caligraphic-Bold-5QL5CMTE.woff2 +0 -0
- zettcode/gateway/static/assets/KaTeX_Caligraphic-Regular-KX5MEWCF.woff2 +0 -0
- zettcode/gateway/static/assets/KaTeX_Fraktur-Bold-2QVFK6NQ.woff2 +0 -0
- zettcode/gateway/static/assets/KaTeX_Fraktur-Regular-2PEIFJSJ.woff2 +0 -0
- zettcode/gateway/static/assets/KaTeX_Main-Bold-YP5VVQRP.woff2 +0 -0
- zettcode/gateway/static/assets/KaTeX_Main-BoldItalic-N4V3DX7S.woff2 +0 -0
- zettcode/gateway/static/assets/KaTeX_Main-Italic-RELBIK7M.woff2 +0 -0
- zettcode/gateway/static/assets/KaTeX_Main-Regular-ARRPAO67.woff2 +0 -0
- zettcode/gateway/static/assets/KaTeX_Math-BoldItalic-K4WTGH3J.woff2 +0 -0
- zettcode/gateway/static/assets/KaTeX_Math-Italic-6KGCHLFN.woff2 +0 -0
- zettcode/gateway/static/assets/KaTeX_SansSerif-Bold-RRNVJFFW.woff2 +0 -0
- zettcode/gateway/static/assets/KaTeX_SansSerif-Italic-HMPFTM52.woff2 +0 -0
- zettcode/gateway/static/assets/KaTeX_SansSerif-Regular-XIQ62X4E.woff2 +0 -0
- zettcode/gateway/static/assets/KaTeX_Script-Regular-APUWIHLP.woff2 +0 -0
- zettcode/gateway/static/assets/KaTeX_Size1-Regular-5LRUTBFT.woff2 +0 -0
- zettcode/gateway/static/assets/KaTeX_Size2-Regular-LELKET5D.woff2 +0 -0
- zettcode/gateway/static/assets/KaTeX_Size3-Regular-WQRQ47UD.woff2 +0 -0
- zettcode/gateway/static/assets/KaTeX_Size4-Regular-CDMV7U5C.woff2 +0 -0
- zettcode/gateway/static/assets/KaTeX_Typewriter-Regular-VBYJ4NRC.woff2 +0 -0
- zettcode/gateway/static/chunks/chunk-Y6SLVHK3.js +1 -0
- zettcode/gateway/static/chunks/render-G6G3TSB3.js +341 -0
- zettcode/gateway/static/icon.png +0 -0
- zettcode/gateway/static/index.html +23 -0
- zettcode/gateway/static/logo.svg +205 -0
- zettcode/gateway/static/manifest.webmanifest +11 -0
- zettcode_gateway-0.3.4.dist-info/METADATA +21 -0
- zettcode_gateway-0.3.4.dist-info/RECORD +40 -0
- zettcode_gateway-0.3.4.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""What the gateway is told at start: where it listens, who may use it, and where it may start agents."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
#: The environment variables the command reads.
|
|
10
|
+
TOKEN_VARIABLE = "ZETTCODE_GATEWAY_TOKEN"
|
|
11
|
+
DIRECTORY_VARIABLE = "ZETTCODE_GATEWAY_DIR"
|
|
12
|
+
|
|
13
|
+
DEFAULT_HOST = "127.0.0.1"
|
|
14
|
+
DEFAULT_PORT = 8765
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def default_directory() -> Path:
|
|
18
|
+
"""Return the gateway's own folder: ``$ZETTCODE_GATEWAY_DIR``, or ``~/.zettcode/gateway``."""
|
|
19
|
+
override = os.environ.get(DIRECTORY_VARIABLE)
|
|
20
|
+
return Path(override).expanduser() if override else Path.home() / ".zettcode" / "gateway"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass(frozen=True, slots=True)
|
|
24
|
+
class Settings:
|
|
25
|
+
"""The gateway's configuration.
|
|
26
|
+
|
|
27
|
+
Attributes:
|
|
28
|
+
token: What a person types to sign in. Empty means no sign-in at all, which only a gateway listening on this
|
|
29
|
+
machine alone may have (see :attr:`open`).
|
|
30
|
+
host: The address to listen on. Anything but loopback puts the gateway on the network.
|
|
31
|
+
port: The port.
|
|
32
|
+
roots: The directories a daemon may be started in, or in any directory below one of them. Nothing else is
|
|
33
|
+
allowed: a page that could name any path could start an agent anywhere.
|
|
34
|
+
allow_full: Whether a daemon may be given the ``full`` shell level (no sandbox, no approval). Decided by the
|
|
35
|
+
command line (``--no-full`` turns it off), never from the page.
|
|
36
|
+
directory: The gateway's own folder: its workspace, the id of its session, and what the page remembers.
|
|
37
|
+
log_level: uvicorn's log level.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
token: str = ""
|
|
41
|
+
host: str = DEFAULT_HOST
|
|
42
|
+
port: int = DEFAULT_PORT
|
|
43
|
+
roots: tuple[Path, ...] = ()
|
|
44
|
+
allow_full: bool = False
|
|
45
|
+
directory: Path = field(default_factory=default_directory)
|
|
46
|
+
log_level: str = "info"
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
def open(self) -> bool:
|
|
50
|
+
"""Return whether anybody who can reach the gateway may use it, with no token."""
|
|
51
|
+
return not self.token
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def workspace(self) -> Path:
|
|
55
|
+
"""Return the directory the gateway's own session works in: it has nothing to edit, and its name is public."""
|
|
56
|
+
return self.directory / "gateway"
|
|
57
|
+
|
|
58
|
+
@property
|
|
59
|
+
def url(self) -> str:
|
|
60
|
+
"""Return the address the page is served at."""
|
|
61
|
+
host = f"[{self.host}]" if ":" in self.host else self.host
|
|
62
|
+
return f"http://{host}:{self.port}"
|