auto-coder-web 0.1.96__py3-none-any.whl → 0.1.97__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.
@@ -16,7 +16,7 @@ def _get_chat_list_file_path(project_path: str, name: str) -> str:
16
16
  chat_lists_dir = _get_chat_lists_dir(project_path)
17
17
  return os.path.join(chat_lists_dir, f"{name}.json")
18
18
 
19
- async def save_chat_list(project_path: str, name: str, messages: List[Dict[str, Any]]) -> None:
19
+ async def save_chat_list(project_path: str, name: str, messages: List[Dict[str, Any]], metadata: dict = None) -> None:
20
20
  """
21
21
  保存聊天列表到文件
22
22
 
@@ -24,14 +24,21 @@ async def save_chat_list(project_path: str, name: str, messages: List[Dict[str,
24
24
  project_path: 项目路径
25
25
  name: 聊天列表名称
26
26
  messages: 聊天消息列表
27
+ metadata: 聊天元数据
27
28
 
28
29
  Raises:
29
30
  Exception: 如果保存失败
30
31
  """
31
32
  file_path = _get_chat_list_file_path(project_path, name)
32
33
  try:
34
+ data = {
35
+ "name": name,
36
+ "messages": messages
37
+ }
38
+ if metadata is not None:
39
+ data["metadata"] = metadata
33
40
  async with aiofiles.open(file_path, 'w') as f:
34
- await f.write(json.dumps({"messages": messages}, indent=2, ensure_ascii=False))
41
+ await f.write(json.dumps(data, indent=2, ensure_ascii=False))
35
42
  except Exception as e:
36
43
  logger.error(f"Error saving chat list {name}: {str(e)}")
37
44
  raise e
@@ -73,18 +80,7 @@ async def get_chat_lists(project_path: str) -> List[str]:
73
80
 
74
81
  async def get_chat_list(project_path: str, name: str) -> Dict[str, Any]:
75
82
  """
76
- 获取特定聊天列表的内容
77
-
78
- Args:
79
- project_path: 项目路径
80
- name: 聊天列表名称
81
-
82
- Returns:
83
- 聊天列表内容
84
-
85
- Raises:
86
- FileNotFoundError: 如果聊天列表不存在
87
- Exception: 如果读取失败
83
+ 获取特定聊天列表的内容(兼容旧结构)
88
84
  """
89
85
  file_path = _get_chat_list_file_path(project_path, name)
90
86
  if not os.path.exists(file_path):
@@ -93,7 +89,13 @@ async def get_chat_list(project_path: str, name: str) -> Dict[str, Any]:
93
89
  try:
94
90
  async with aiofiles.open(file_path, 'r') as f:
95
91
  content = await f.read()
96
- return json.loads(content)
92
+ data = json.loads(content)
93
+ # 兼容旧数据结构(只有messages)
94
+ if "name" not in data:
95
+ data["name"] = name
96
+ if "metadata" not in data:
97
+ data["metadata"] = None
98
+ return data
97
99
  except json.JSONDecodeError as e:
98
100
  logger.error(f"Invalid JSON in chat list {name}: {str(e)}")
99
101
  raise Exception(f"Invalid JSON in chat list file: {str(e)}")
@@ -33,8 +33,8 @@ router = APIRouter()
33
33
  @router.post("/api/chat-lists/save")
34
34
  async def save_chat_list_endpoint(chat_list: ChatList, project_path: str = Depends(get_project_path)):
35
35
  try:
36
- # 调用管理模块保存聊天列表
37
- await save_chat_list(project_path, chat_list.name, chat_list.messages)
36
+ # 调用管理模块保存聊天列表,支持 metadata
37
+ await save_chat_list(project_path, chat_list.name, chat_list.messages, metadata=chat_list.metadata.dict() if chat_list.metadata else None)
38
38
  return {"status": "success", "message": f"Chat list {chat_list.name} saved successfully"}
39
39
  except Exception as e:
40
40
  raise HTTPException(status_code=500, detail=str(e))
auto_coder_web/types.py CHANGED
@@ -24,9 +24,15 @@ class CompletionResponse(BaseModel):
24
24
  completions: List[CompletionItem]
25
25
 
26
26
 
27
+ class ChatMetadata(BaseModel):
28
+ token_usage: Optional[int] = None # token 消耗
29
+ cost: Optional[float] = None # 费用
30
+ window_size: Optional[int] = None # 窗口大小
31
+
27
32
  class ChatList(BaseModel):
28
33
  name: str
29
34
  messages: List[Dict[str, Any]]
35
+ metadata: Optional[ChatMetadata] = None # 新增 metadata 字段
30
36
 
31
37
 
32
38
  class HistoryQuery(BaseModel):
auto_coder_web/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.1.96"
1
+ __version__ = "0.1.97"