docs: update README and CLAUDE.md to v2.2.0

- Added documentation for audit tracking (IP address, invocation method).
- Updated database model descriptions for enhanced WorkOrder and Conversation fields.
- Documented the new UnifiedConfig system.
- Reflected enhanced logging transparency for knowledge base parsing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
zhaojie
2026-02-11 00:08:09 +08:00
parent 2026007045
commit c3560b43fd
218 changed files with 3354 additions and 5096 deletions

View File

@@ -90,8 +90,21 @@ class WebSocketServer:
await self._send_error(websocket, "缺少必要参数", message_id)
return
# 获取客户端IP
ip_address = None
try:
# websockets 15.x 获取 remote_address 的方式
ip_address = websocket.remote_address[0] if websocket.remote_address else None
except Exception:
pass
# 处理消息
result = self.chat_manager.process_message(session_id, message)
result = self.chat_manager.process_message(
session_id,
message,
ip_address=ip_address,
invocation_method="websocket"
)
response = {
"type": "message_response",
@@ -210,21 +223,9 @@ class WebSocketServer:
await websocket.send(json.dumps(response, ensure_ascii=False))
async def handle_client(self, websocket: WebSocketServerProtocol, path: str):
"""处理客户端连接"""
# 检查连接头
headers = websocket.request_headers
connection = headers.get("Connection", "").lower()
# 处理不同的连接头格式
if "upgrade" not in connection and "keep-alive" in connection:
logger.warning(f"收到非标准连接头: {connection}")
# 对于keep-alive连接头我们仍然接受连接
elif "upgrade" not in connection:
logger.warning(f"连接头不包含upgrade: {connection}")
await websocket.close(code=1002, reason="Invalid connection header")
return
async def handle_client(self, websocket):
"""处理客户端连接(兼容 websockets 15.x"""
# websockets 15.x 版本中handler 只接收 websocket 参数,不再有 path 参数
await self.register_client(websocket)
try:
@@ -238,61 +239,17 @@ class WebSocketServer:
await self.unregister_client(websocket)
async def start_server(self):
"""启动WebSocket服务器"""
"""启动WebSocket服务器(兼容 websockets 15.x"""
logger.info(f"启动WebSocket服务器: ws://{self.host}:{self.port}")
# 添加CORS支持
async def handle_client_with_cors(websocket: WebSocketServerProtocol):
# 获取pathwebsockets在提供process_request时不会将path传递给handler
path = websocket.path
# 设置CORS头
if websocket.request_headers.get("Origin"):
# 允许跨域连接
pass
await self.handle_client(websocket, path)
# websockets 15.x 简化版本:直接传递处理函数
async with websockets.serve(
handle_client_with_cors,
self.handle_client,
self.host,
self.port,
# 添加额外的服务器选项
process_request=self._process_request
self.port
):
await asyncio.Future() # 保持服务器运行
def _process_request(self, path, request_headers):
"""处理HTTP请求支持CORS"""
# 检查是否是WebSocket升级请求
# request_headers 可能是 Headers 对象或 Request 对象
if hasattr(request_headers, 'get'):
upgrade_header = request_headers.get("Upgrade", "").lower()
elif hasattr(request_headers, 'headers'):
upgrade_header = request_headers.headers.get("Upgrade", "").lower()
else:
upgrade_header = ""
if upgrade_header == "websocket":
return None # 允许WebSocket连接
# 对于非WebSocket请求返回简单的HTML页面
return (
200,
[("Content-Type", "text/html; charset=utf-8")],
b"""
<!DOCTYPE html>
<html>
<head>
<title>WebSocket Server</title>
</head>
<body>
<h1>WebSocket Server is running</h1>
<p>This is a WebSocket server. Please use a WebSocket client to connect.</p>
<p>WebSocket URL: ws://localhost:8765</p>
</body>
</html>
"""
)
def run(self):
"""运行服务器"""
asyncio.run(self.start_server())