style: 统一代码格式和 import 顺序

- 调整 Python 文件 import 顺序,遵循标准库→第三方库→项目模块顺序
- 统一字符串引号风格为双引号
- 优化 Vue 组件 console.log 格式
- 压缩 import 语句为单行
- 清理不必要的空行
This commit is contained in:
Wenjie Zhang 2026-02-13 22:29:20 +08:00
parent 44e41bbb5a
commit 1f5636520e
6 changed files with 47 additions and 45 deletions

View File

@ -1,8 +1,7 @@
from langchain.agents import create_agent
from langchain.agents.middleware import ModelRetryMiddleware
from deepagents.backends import StateBackend
from deepagents.middleware.filesystem import FilesystemMiddleware
from langchain.agents import create_agent
from langchain.agents.middleware import ModelRetryMiddleware
from src.agents.common import BaseAgent, load_chat_model
from src.agents.common.middlewares import (

View File

@ -31,9 +31,9 @@ def _make_attachment_path(file_name: str) -> str:
"""
# 提取不带扩展名的部分
base_name = file_name
for ext in ['.docx', '.txt', '.html', '.htm', '.pdf', '.md']:
for ext in [".docx", ".txt", ".html", ".htm", ".pdf", ".md"]:
if file_name.lower().endswith(ext):
base_name = file_name[:-len(ext)]
base_name = file_name[: -len(ext)]
break
# 替换路径分隔符

View File

@ -13,19 +13,18 @@ import asyncio
import contextlib
import os
import sys
import uuid
from pathlib import Path
import httpx
from dotenv import load_dotenv
# 添加项目根目录到 Python 路径
PROJECT_ROOT = Path(__file__).parent.parent.parent
sys.path.insert(0, str(PROJECT_ROOT))
# 加载 .env 文件
from dotenv import load_dotenv
load_dotenv(PROJECT_ROOT / ".env")
import httpx
import uuid
# API 配置
API_BASE_URL = os.getenv("API_BASE_URL", "http://localhost:5050")
@ -58,9 +57,9 @@ class APITester:
async def login(self) -> bool:
"""登录获取 token"""
print(f"\n{'='*60}")
print(f"\n{'=' * 60}")
print(f"1. 正在登录: {self.username}")
print(f"{'='*60}")
print(f"{'=' * 60}")
async with self._client() as client:
response = await client.post(
@ -82,9 +81,9 @@ class APITester:
async def create_thread(self, agent_id: str) -> str:
"""创建对话线程"""
print(f"\n{'='*60}")
print(f"\n{'=' * 60}")
print(f"2. 创建对话线程 (agent_id: {agent_id})")
print(f"{'='*60}")
print(f"{'=' * 60}")
async with self._client() as client:
response = await client.post(
@ -104,9 +103,9 @@ class APITester:
async def upload_attachment(self, thread_id: str, file_path: str) -> dict | None:
"""上传附件"""
print(f"\n{'='*60}")
print(f"\n{'=' * 60}")
print(f"3. 上传附件: {file_path}")
print(f"{'='*60}")
print(f"{'=' * 60}")
if not os.path.exists(file_path):
print(f" ✗ 文件不存在: {file_path}")
@ -123,7 +122,7 @@ class APITester:
if response.status_code == 200:
attachment = response.json()
print(f" ✓ 上传成功!")
print(" ✓ 上传成功!")
print(f" file_id: {attachment.get('file_id')}")
print(f" file_name: {attachment.get('file_name')}")
print(f" status: {attachment.get('status')}")
@ -134,9 +133,9 @@ class APITester:
async def list_attachments(self, thread_id: str) -> list[dict]:
"""列出附件"""
print(f"\n{'='*60}")
print(f"\n{'=' * 60}")
print(f"4. 列出附件 (thread_id: {thread_id})")
print(f"{'='*60}")
print(f"{'=' * 60}")
async with self._client() as client:
response = await client.get(
@ -157,9 +156,9 @@ class APITester:
async def get_agent_state(self, agent_id: str, thread_id: str) -> dict | None:
"""获取 agent state"""
print(f"\n{'='*60}")
print(f"\n{'=' * 60}")
print(f"5. 获取 Agent State (agent_id: {agent_id}, thread_id: {thread_id})")
print(f"{'='*60}")
print(f"{'=' * 60}")
async with self._client() as client:
response = await client.get(
@ -171,11 +170,11 @@ class APITester:
if response.status_code == 200:
state = response.json()
agent_state = state.get("agent_state", {})
print(f" ✓ 获取成功!")
print(" ✓ 获取成功!")
print(f" files: {len(agent_state.get('files', {}))}")
print(f" todos: {len(agent_state.get('todos', []))}")
if agent_state.get("files"):
print(f" 文件列表:")
print(" 文件列表:")
for path in agent_state["files"]:
file_info = agent_state["files"][path]
print(f" - {path}: {len(file_info.get('content', []))}")
@ -186,9 +185,9 @@ class APITester:
async def send_chat_message(self, agent_id: str, thread_id: str, query: str) -> bool:
"""发送聊天消息(流式)"""
print(f"\n{'='*60}")
print(f"6. 发送聊天消息")
print(f"{'='*60}")
print(f"\n{'=' * 60}")
print("6. 发送聊天消息")
print(f"{'=' * 60}")
print(f" Query: {query}")
print(f" Thread ID: {thread_id}")
@ -200,7 +199,7 @@ class APITester:
headers=self.headers,
) as response:
print(f"\n 响应状态: {response.status_code}")
print(f" 响应内容:")
print(" 响应内容:")
async for chunk in response.aiter_lines():
if chunk:
print(f" {chunk[:150]}...")
@ -264,11 +263,7 @@ def hello():
await tester.get_agent_state(agent_id, thread_id)
# 7. 发送聊天消息测试
await tester.send_chat_message(
agent_id,
thread_id,
"你好,请简单介绍一下你自己。"
)
await tester.send_chat_message(agent_id, thread_id, "你好,请简单介绍一下你自己。")
# 8. 再次获取 agent state (验证 todos 等状态)
await asyncio.sleep(1)
@ -279,9 +274,9 @@ def hello():
os.remove(test_file_path)
print(f"\n 测试文件已清理: {test_file_path}")
print(f"\n{'='*60}")
print(f"\n{'=' * 60}")
print(" 测试完成!")
print(f"{'='*60}\n")
print(f"{'=' * 60}\n")
if __name__ == "__main__":

View File

@ -671,7 +671,16 @@ const fetchAgentState = async (agentId, threadId) => {
// currentChatId state currentAgentState
// currentChatId null使 threadId
const targetChatId = currentChatId.value || threadId
console.log('[fetchAgentState] agentId:', agentId, 'threadId:', threadId, 'targetChatId:', targetChatId, 'agent_state:', JSON.stringify(res.agent_state || {})?.slice(0, 200))
console.log(
'[fetchAgentState] agentId:',
agentId,
'threadId:',
threadId,
'targetChatId:',
targetChatId,
'agent_state:',
JSON.stringify(res.agent_state || {})?.slice(0, 200)
)
const ts = getThreadState(targetChatId)
if (ts) {
ts.agentState = res.agent_state || null
@ -1088,7 +1097,14 @@ const handleAgentStateRefresh = async (threadId = null) => {
if (!currentAgentId.value) return
// 使 threadId使 currentChatId
let chatId = threadId || currentChatId.value
console.log('[handleAgentStateRefresh] input threadId:', threadId, 'currentChatId:', currentChatId.value, 'final chatId:', chatId)
console.log(
'[handleAgentStateRefresh] input threadId:',
threadId,
'currentChatId:',
currentChatId.value,
'final chatId:',
chatId
)
if (!chatId) return
await fetchAgentState(currentAgentId.value, chatId)
}

View File

@ -151,14 +151,7 @@
<script setup>
import { computed, ref, onMounted, onUpdated, nextTick } from 'vue'
import {
Download,
X,
FolderCode,
RefreshCw,
Folder,
FolderOpen
} from 'lucide-vue-next'
import { Download, X, FolderCode, RefreshCw, Folder, FolderOpen } from 'lucide-vue-next'
import {
CheckCircleOutlined,
SyncOutlined,

View File

@ -121,7 +121,6 @@ const loadCallStats = async () => {
await nextTick()
renderCallStatsChart()
} catch (error) {
console.error('加载调用统计数据失败:', error)
} finally {
callStatsLoading.value = false