diff --git a/wwwroot/api/cockpit_chat.dspy b/wwwroot/api/cockpit_chat.dspy index b937b74..e628ab4 100644 --- a/wwwroot/api/cockpit_chat.dspy +++ b/wwwroot/api/cockpit_chat.dspy @@ -28,7 +28,7 @@ DEFAULT_SYSTEM_PROMPT = """你是一个专业的软件开发 Agent,名为「 async def _load_agent_settings(sor, uid): """Load user's agent settings, return defaults if not set.""" recs = await sor.sqlExe( - "SELECT default_llm_id, system_prompt, temperature, max_context_messages FROM sd_agent_settings WHERE user_id=${uid}$", + "SELECT default_llm_id, system_prompt, temperature, max_context_messages FROM pipeline_agent_settings WHERE user_id=${uid}$", {"uid": uid} ) if recs: @@ -48,10 +48,9 @@ async def _load_agent_settings(sor, uid): async def _load_context(sor, uid): - """Load session context: current project/iteration.""" - settings = await _load_agent_settings(sor, uid) + """Load session context from pipeline_agent_settings.""" recs = await sor.sqlExe( - "SELECT current_project_id, current_iteration_id FROM sd_agent_settings WHERE user_id=${uid}$", + "SELECT current_project_id, current_iteration_id FROM pipeline_agent_settings WHERE user_id=${uid}$", {"uid": uid} ) ctx = {'project_id': '', 'iteration_id': '', 'project_name': '', 'iteration_name': ''} @@ -75,19 +74,19 @@ async def _load_context(sor, uid): async def _save_context(sor, uid, project_id, iteration_id): - """Save session context.""" + """Save session context to pipeline_agent_settings.""" existing = await sor.sqlExe( - "SELECT id FROM sd_agent_settings WHERE user_id=${uid}$", {"uid": uid} + "SELECT id FROM pipeline_agent_settings WHERE user_id=${uid}$", {"uid": uid} ) if existing: await sor.sqlExe( - "UPDATE sd_agent_settings SET current_project_id=${pid}$, current_iteration_id=${iid}$ WHERE user_id=${uid}$", + "UPDATE pipeline_agent_settings SET current_project_id=${pid}$, current_iteration_id=${iid}$ WHERE user_id=${uid}$", {"pid": project_id or '', "iid": iteration_id or '', "uid": uid} ) else: - await sor.C('sd_agent_settings', { + await sor.C('pipeline_agent_settings', { 'id': getID(), 'user_id': uid, - 'current_project_id': project_id or '', + 'default_llm_id': '', 'current_project_id': project_id or '', 'current_iteration_id': iteration_id or '', }) @@ -172,7 +171,7 @@ async def _build_context(sor, iteration_id, task_id, max_msgs, system_prompt): params["iid"] = iteration_id if where: - sql = f"SELECT role, content FROM sd_conversations WHERE {' OR '.join(where)} ORDER BY created_at DESC LIMIT ${max_msgs}$" + sql = f"SELECT role, content FROM pipeline_conversations WHERE {' OR '.join(where)} ORDER BY created_at DESC LIMIT ${max_msgs}$" params["max_msgs"] = max_msgs history = await sor.sqlExe(sql, params) # Reverse to chronological order @@ -300,7 +299,7 @@ if action == 'send_message': # 2. Classify intent history = await sor.sqlExe( - "SELECT role, content FROM sd_conversations WHERE iteration_id=${iid}$ OR iteration_id='' ORDER BY created_at DESC LIMIT 4", + "SELECT role, content FROM pipeline_conversations WHERE iteration_id=${iid}$ OR iteration_id='' ORDER BY created_at DESC LIMIT 4", {"iid": iteration_id or ctx.get('iteration_id', '')} ) history_msgs = [] @@ -403,13 +402,13 @@ if action == 'send_message': # 4. Save conversation msg_id = getID() - await sor.C('sd_conversations', { + await sor.C('pipeline_conversations', { 'id': msg_id, 'iteration_id': iteration_id or ctx.get('iteration_id', ''), 'task_id': '', 'step_name': '', 'role': 'user', 'content': message_text, 'attachments': file_paths_raw, 'msg_type': 'text', 'org_id': org_id, 'created_by': uid }) agent_msg_id = getID() - await sor.C('sd_conversations', { + await sor.C('pipeline_conversations', { 'id': agent_msg_id, 'iteration_id': iteration_id or ctx.get('iteration_id', ''), 'task_id': '', 'step_name': '', 'role': 'agent', 'content': agent_reply, 'attachments': '[]', 'msg_type': 'text', 'org_id': org_id, 'created_by': 'system' @@ -439,7 +438,7 @@ else: where.append("iteration_id=${iid}$") params["iid"] = iteration_id - sql = f"SELECT role, content, msg_type, created_at FROM sd_conversations WHERE {' OR '.join(where)} ORDER BY created_at ASC LIMIT 50" + sql = f"SELECT role, content, msg_type, created_at FROM pipeline_conversations WHERE {' OR '.join(where)} ORDER BY created_at ASC LIMIT 50" msgs = await sor.sqlExe(sql, params) msg_widgets = []