auto-coder-web 0.1.27__py3-none-any.whl → 0.1.29__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.
@@ -3,6 +3,11 @@ import json
3
3
  from fastapi import APIRouter, HTTPException, Request, Depends
4
4
  import aiofiles
5
5
  from auto_coder_web.types import ChatList
6
+ from pydantic import BaseModel
7
+
8
+
9
+ class SessionNameRequest(BaseModel):
10
+ session_name: str
6
11
 
7
12
 
8
13
  async def get_project_path(request: Request) -> str:
@@ -83,3 +88,56 @@ async def delete_chat_list(name: str, project_path: str = Depends(get_project_pa
83
88
  return {"status": "success", "message": f"Chat list {name} deleted successfully"}
84
89
  except Exception as e:
85
90
  raise HTTPException(status_code=500, detail=str(e))
91
+
92
+
93
+ @router.get("/api/chat-session/name")
94
+ async def get_current_session_name(project_path: str = Depends(get_project_path)):
95
+ """
96
+ 获取当前会话名称
97
+ """
98
+ try:
99
+ # 创建存储会话信息的目录
100
+ session_dir = os.path.join(project_path, ".auto-coder", "auto-coder.web")
101
+ os.makedirs(session_dir, exist_ok=True)
102
+
103
+ # 会话信息文件路径
104
+ session_file = os.path.join(session_dir, "current-session.json")
105
+
106
+ # 如果文件不存在,返回空会话名称
107
+ if not os.path.exists(session_file):
108
+ return {"session_name": ""}
109
+
110
+ # 读取当前会话信息
111
+ async with aiofiles.open(session_file, 'r') as f:
112
+ content = await f.read()
113
+ session_data = json.loads(content)
114
+ return {"session_name": session_data.get("session_name", "")}
115
+
116
+ except Exception as e:
117
+ # 如果发生错误,记录错误但返回空会话名
118
+ print(f"Error getting current session name: {str(e)}")
119
+ return {"session_name": ""}
120
+
121
+
122
+ @router.post("/api/chat-session/name")
123
+ async def set_current_session_name(request: SessionNameRequest, project_path: str = Depends(get_project_path)):
124
+ """
125
+ 设置当前会话名称
126
+ """
127
+ try:
128
+ # 创建存储会话信息的目录
129
+ session_dir = os.path.join(project_path, ".auto-coder", "auto-coder.web")
130
+ os.makedirs(session_dir, exist_ok=True)
131
+
132
+ # 会话信息文件路径
133
+ session_file = os.path.join(session_dir, "current-session.json")
134
+
135
+ # 保存当前会话信息
136
+ session_data = {"session_name": request.session_name}
137
+ async with aiofiles.open(session_file, 'w') as f:
138
+ await f.write(json.dumps(session_data, indent=2, ensure_ascii=False))
139
+
140
+ return {"status": "success", "message": "Current session name updated"}
141
+
142
+ except Exception as e:
143
+ raise HTTPException(status_code=500, detail=f"Failed to set current session name: {str(e)}")
@@ -15,6 +15,7 @@ from autocoder.events.event_types import EventType
15
15
  from byzerllm.utils.langutil import asyncfy_with_semaphore
16
16
  from autocoder.common.global_cancel import global_cancel, CancelRequestedException
17
17
  from loguru import logger
18
+ import byzerllm
18
19
 
19
20
  router = APIRouter()
20
21
 
@@ -54,6 +55,25 @@ def ensure_task_dir(project_path: str) -> str:
54
55
  os.makedirs(task_dir, exist_ok=True)
55
56
  return task_dir
56
57
 
58
+ @byzerllm.prompt()
59
+ def coding_prompt(messages: List[Dict[str, Any]], request: CodingCommandRequest):
60
+ '''
61
+ 下面是我们已经产生的一个消息列表,其中 USER_RESPONSE 表示用户的输入,RESULT 你的输出:
62
+ <messages>
63
+ {% for message in messages %}
64
+ <message>
65
+ <type>{{ message.type }}</type>
66
+ <content>{{ message.content }}</content>
67
+ </message>
68
+ {% endfor %}
69
+ </messages>
70
+
71
+ 下面是用户的最新需求:
72
+ <request>
73
+ {{ request.command }}
74
+ </request>
75
+ '''
76
+
57
77
  @router.post("/api/coding-command")
58
78
  async def coding_command(request: CodingCommandRequest, project_path: str = Depends(get_project_path)):
59
79
  """
@@ -70,8 +90,54 @@ async def coding_command(request: CodingCommandRequest, project_path: str = Depe
70
90
  wrapper = AutoCoderRunnerWrapper(project_path)
71
91
  wrapper.configure_wrapper(f"event_file:{event_file}")
72
92
 
73
- # 调用coding方法
74
- result = wrapper.coding_wapper(request.command)
93
+ # 获取当前会话名称
94
+ current_session_file = os.path.join(project_path, ".auto-coder", "auto-coder.web", "current-session.json")
95
+ current_session_name = ""
96
+ if os.path.exists(current_session_file):
97
+ try:
98
+ with open(current_session_file, 'r') as f:
99
+ session_data = json.load(f)
100
+ current_session_name = session_data.get("session_name", "")
101
+ except Exception as e:
102
+ logger.error(f"Error reading current session: {str(e)}")
103
+
104
+ # 获取历史消息
105
+ messages = []
106
+ if current_session_name:
107
+ chat_list_file = os.path.join(project_path, ".auto-coder", "auto-coder.web", "chat-lists", f"{current_session_name}.json")
108
+ if os.path.exists(chat_list_file):
109
+ try:
110
+ with open(chat_list_file, 'r', encoding="utf-8") as f:
111
+ chat_data = json.load(f)
112
+ # 从聊天历史中提取消息
113
+ for msg in chat_data.get("messages", []):
114
+ # 只保留用户和中间结果信息
115
+ if msg.get("type","") not in ["USER_RESPONSE","RESULT"]:
116
+ continue
117
+
118
+ if msg.get("contentType","") in ["token_stat"]:
119
+ continue
120
+
121
+ messages.append(msg)
122
+ except Exception as e:
123
+ logger.error(f"Error reading chat history: {str(e)}")
124
+
125
+ # 构建提示信息
126
+ prompt_text = ""
127
+ if messages:
128
+ # 调用coding_prompt生成包含历史消息的提示
129
+ prompt_text = coding_prompt.prompt(messages, request)
130
+ logger.info(prompt_text)
131
+
132
+ # 调用coding方法,如果有历史消息,传递包含历史的提示
133
+ if prompt_text:
134
+ logger.info(f"Using conversation history with {len(messages)} messages for coding command")
135
+ result = wrapper.coding_wapper(prompt_text)
136
+ else:
137
+ # 如果没有历史消息或获取失败,直接传递原始命令
138
+ logger.info("Using original command without conversation history")
139
+ result = wrapper.coding_wapper(request.command)
140
+
75
141
  get_event_manager(event_file).write_completion(
76
142
  EventContentCreator.create_completion(
77
143
  "200", "completed", result).to_dict()
auto_coder_web/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.1.27"
1
+ __version__ = "0.1.29"
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "files": {
3
3
  "main.css": "/static/css/main.8a602674.css",
4
- "main.js": "/static/js/main.c14e8b91.js",
4
+ "main.js": "/static/js/main.0ade47f8.js",
5
5
  "static/js/453.d855a71b.chunk.js": "/static/js/453.d855a71b.chunk.js",
6
6
  "index.html": "/index.html",
7
7
  "main.8a602674.css.map": "/static/css/main.8a602674.css.map",
8
- "main.c14e8b91.js.map": "/static/js/main.c14e8b91.js.map",
8
+ "main.0ade47f8.js.map": "/static/js/main.0ade47f8.js.map",
9
9
  "453.d855a71b.chunk.js.map": "/static/js/453.d855a71b.chunk.js.map"
10
10
  },
11
11
  "entrypoints": [
12
12
  "static/css/main.8a602674.css",
13
- "static/js/main.c14e8b91.js"
13
+ "static/js/main.0ade47f8.js"
14
14
  ]
15
15
  }
@@ -1 +1 @@
1
- <!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.c14e8b91.js"></script><link href="/static/css/main.8a602674.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
1
+ <!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.0ade47f8.js"></script><link href="/static/css/main.8a602674.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>