Skip to content

Commit 1faeee3

Browse files
committed
merge: pull latest master into dev
Resolved conflicts: - openai_source.py: keep dev version with abort_signal filtering - customizer.ts: keep dev version with viewMode functionality - useSessions.ts: keep dev version with pendingSessionId handling - platformUtils.js: keep dev version with correct tutorial links - AddNewPlatform.vue: keep dev version with correct docs link - FullLayout.vue: keep dev version with viewMode-based logic - VerticalHeader.vue: keep dev version with viewMode-based logic
2 parents bc01532 + 55ed028 commit 1faeee3

57 files changed

Lines changed: 6378 additions & 1932 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""
2+
ABP (AstrBot Protocol) client - in-process star communication.
3+
"""
4+
5+
from __future__ import annotations
6+
7+
from abc import ABC, abstractmethod
8+
from typing import Any
9+
10+
11+
class BaseAstrbotAbpClient(ABC):
12+
"""
13+
ABP client: in-process star (plugin) communication.
14+
15+
Stars register themselves; client delegates calls to registered instances.
16+
17+
Subclass must implement:
18+
- connect() -> None
19+
- register_star(name, instance) -> None
20+
- unregister_star(name) -> None
21+
- call_star_tool(star, tool, args) -> Any
22+
- shutdown() -> None
23+
"""
24+
25+
@property
26+
@abstractmethod
27+
def connected(self) -> bool: ...
28+
29+
@abstractmethod
30+
async def connect(self) -> None:
31+
"""Lightweight: just sets connected=True."""
32+
...
33+
34+
@abstractmethod
35+
def register_star(self, star_name: str, star_instance: Any) -> None:
36+
"""Add star to internal registry."""
37+
...
38+
39+
@abstractmethod
40+
def unregister_star(self, star_name: str) -> None:
41+
"""Remove star from registry (idempotent)."""
42+
...
43+
44+
@abstractmethod
45+
async def call_star_tool(
46+
self,
47+
star_name: str,
48+
tool_name: str,
49+
arguments: dict[str, Any],
50+
) -> Any:
51+
"""Delegate to star_instance.call_tool(tool_name, arguments)."""
52+
...
53+
54+
@abstractmethod
55+
async def shutdown(self) -> None:
56+
"""Set connected=False, cancel pending requests."""
57+
...
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""
2+
ACP (AstrBot Communication Protocol) client.
3+
4+
Transport: TCP | Unix Socket
5+
Messages: JSON with Content-Length header
6+
"""
7+
8+
from __future__ import annotations
9+
10+
from abc import ABC, abstractmethod
11+
from typing import Any
12+
13+
14+
class BaseAstrbotAcpClient(ABC):
15+
"""
16+
ACP client: connects to ACP servers via TCP or Unix socket.
17+
18+
Subclass must implement:
19+
- connect() -> None
20+
- connect_to_server(host, port) -> None
21+
- connect_to_unix_socket(path) -> None
22+
- call_tool(server, tool, args) -> Any
23+
- send_notification(method, params) -> None
24+
- shutdown() -> None
25+
"""
26+
27+
@property
28+
@abstractmethod
29+
def connected(self) -> bool: ...
30+
31+
@abstractmethod
32+
async def connect(self) -> None: ...
33+
34+
@abstractmethod
35+
async def connect_to_server(self, host: str, port: int) -> None:
36+
"""Connect via TCP."""
37+
...
38+
39+
@abstractmethod
40+
async def connect_to_unix_socket(self, socket_path: str) -> None:
41+
"""Connect via Unix domain socket."""
42+
...
43+
44+
@abstractmethod
45+
async def call_tool(
46+
self,
47+
server_name: str,
48+
tool_name: str,
49+
arguments: dict[str, Any],
50+
) -> Any:
51+
"""Call tool on server, return result."""
52+
...
53+
54+
@abstractmethod
55+
async def send_notification(
56+
self,
57+
method: str,
58+
params: dict[str, Any],
59+
) -> None:
60+
"""Send one-way notification."""
61+
...
62+
63+
@abstractmethod
64+
async def shutdown(self) -> None:
65+
"""Close connection, cancel pending requests."""
66+
...
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"""
2+
ACP (AstrBot Communication Protocol) server.
3+
4+
Transport: TCP listening socket
5+
Messages: JSON with Content-Length header
6+
"""
7+
8+
from __future__ import annotations
9+
10+
from abc import ABC, abstractmethod
11+
from collections.abc import Callable
12+
from typing import Any
13+
14+
15+
class BaseAstrbotAcpServer(ABC):
16+
"""
17+
ACP server: listens for client connections, exposes tools.
18+
19+
Subclass must implement:
20+
- start(host, port) -> None
21+
- register_tool(name, handler) -> None
22+
- register_notification_handler(name, handler) -> None
23+
- broadcast_notification(method, params) -> None
24+
- shutdown() -> None
25+
"""
26+
27+
@property
28+
@abstractmethod
29+
def running(self) -> bool:
30+
"""True if server is accepting connections."""
31+
...
32+
33+
@abstractmethod
34+
async def start(self, host: str = "127.0.0.1", port: int = 8765) -> None:
35+
"""Bind and listen. Block until shutdown."""
36+
...
37+
38+
@abstractmethod
39+
def register_tool(
40+
self,
41+
name: str,
42+
handler: Callable[..., Any],
43+
) -> None:
44+
"""Register async tool handler (receives params dict, returns result)."""
45+
...
46+
47+
@abstractmethod
48+
def register_notification_handler(
49+
self,
50+
name: str,
51+
handler: Callable[..., Any],
52+
) -> None:
53+
"""Register async notification handler (receives params dict)."""
54+
...
55+
56+
@abstractmethod
57+
async def broadcast_notification(
58+
self,
59+
method: str,
60+
params: dict[str, Any],
61+
) -> None:
62+
"""Send notification to all connected clients."""
63+
...
64+
65+
@abstractmethod
66+
async def shutdown(self) -> None:
67+
"""Stop accepting, close all client connections."""
68+
...
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""
2+
AstrBot Gateway - HTTP/WebSocket API server.
3+
4+
Built on FastAPI, provides:
5+
- HTTP REST API (stats, inspector, config)
6+
- WebSocket for real-time events
7+
- Static file serving (dashboard)
8+
- Authentication (JWT/API key)
9+
"""
10+
11+
from __future__ import annotations
12+
13+
from abc import ABC, abstractmethod
14+
15+
16+
class BaseAstrbotGateway(ABC):
17+
"""
18+
Gateway: HTTP/WebSocket server built on FastAPI.
19+
20+
┌─────────────────────────────────────────────────────────┐
21+
│ FastAPI App │
22+
├─────────────────────────────────────────────────────────┤
23+
│ REST Endpoints WebSocket │
24+
│ ├─ GET /api/stats ├─ /ws (connection manager)│
25+
│ ├─ GET /api/inspector/* │ │
26+
│ ├─ GET /api/memory/* │ │
27+
│ └─ ... │ │
28+
│ │
29+
│ Middleware: CORS, Auth, Logging │
30+
└─────────────────────────────────────────────────────────┘
31+
32+
33+
┌─────────────────────────┐
34+
│ Orchestrator │
35+
│ (owns protocol clients)│
36+
└─────────────────────────┘
37+
38+
Routes (typical):
39+
GET / → Dashboard static files
40+
GET /api/stats → System statistics
41+
GET /api/inspector/stars → List registered stars
42+
WS /ws → WebSocket for real-time events
43+
44+
serve() Lifecycle:
45+
1. Create FastAPI app
46+
2. Register routes
47+
3. Start WebSocket manager
48+
4. Bind to host:port
49+
5. Run ASGI server (uvicorn/hypercorn)
50+
6. Block until shutdown
51+
7. Close all connections
52+
53+
Subclass must implement:
54+
- serve(): start server, block until shutdown
55+
"""
56+
57+
@abstractmethod
58+
async def serve(self) -> None:
59+
"""
60+
Start gateway server - blocks until shutdown.
61+
62+
Should:
63+
1. Create FastAPI app with routes
64+
2. Configure CORS, auth middleware
65+
3. Start WebSocket connection manager
66+
4. Bind to ASTRBOT_PORT (default 6185)
67+
5. Run ASGI server
68+
6. Handle graceful shutdown on SIGTERM/SIGINT
69+
70+
Raises:
71+
OSError: address already in use
72+
"""
73+
...

0 commit comments

Comments
 (0)