refactor: use pipeline_conversations + pipeline_agent_settings (shared tables)

This commit is contained in:
yumoqing 2026-08-02 00:00:21 +08:00
parent 97e2c6b2f4
commit bb09bd36a0

View File

@ -28,7 +28,7 @@ DEFAULT_SYSTEM_PROMPT = """你是一个专业的软件开发 Agent名为「
async def _load_agent_settings(sor, uid): async def _load_agent_settings(sor, uid):
"""Load user's agent settings, return defaults if not set.""" """Load user's agent settings, return defaults if not set."""
recs = await sor.sqlExe( 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} {"uid": uid}
) )
if recs: if recs:
@ -48,10 +48,9 @@ async def _load_agent_settings(sor, uid):
async def _load_context(sor, uid): async def _load_context(sor, uid):
"""Load session context: current project/iteration.""" """Load session context from pipeline_agent_settings."""
settings = await _load_agent_settings(sor, uid)
recs = await sor.sqlExe( 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} {"uid": uid}
) )
ctx = {'project_id': '', 'iteration_id': '', 'project_name': '', 'iteration_name': ''} 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): async def _save_context(sor, uid, project_id, iteration_id):
"""Save session context.""" """Save session context to pipeline_agent_settings."""
existing = await sor.sqlExe( 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: if existing:
await sor.sqlExe( 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} {"pid": project_id or '', "iid": iteration_id or '', "uid": uid}
) )
else: else:
await sor.C('sd_agent_settings', { await sor.C('pipeline_agent_settings', {
'id': getID(), 'user_id': uid, '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 '', '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 params["iid"] = iteration_id
if where: 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 params["max_msgs"] = max_msgs
history = await sor.sqlExe(sql, params) history = await sor.sqlExe(sql, params)
# Reverse to chronological order # Reverse to chronological order
@ -300,7 +299,7 @@ if action == 'send_message':
# 2. Classify intent # 2. Classify intent
history = await sor.sqlExe( 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', '')} {"iid": iteration_id or ctx.get('iteration_id', '')}
) )
history_msgs = [] history_msgs = []
@ -403,13 +402,13 @@ if action == 'send_message':
# 4. Save conversation # 4. Save conversation
msg_id = getID() 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', ''), 'id': msg_id, 'iteration_id': iteration_id or ctx.get('iteration_id', ''),
'task_id': '', 'step_name': '', 'role': 'user', 'content': message_text, 'task_id': '', 'step_name': '', 'role': 'user', 'content': message_text,
'attachments': file_paths_raw, 'msg_type': 'text', 'org_id': org_id, 'created_by': uid 'attachments': file_paths_raw, 'msg_type': 'text', 'org_id': org_id, 'created_by': uid
}) })
agent_msg_id = getID() 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', ''), 'id': agent_msg_id, 'iteration_id': iteration_id or ctx.get('iteration_id', ''),
'task_id': '', 'step_name': '', 'role': 'agent', 'content': agent_reply, 'task_id': '', 'step_name': '', 'role': 'agent', 'content': agent_reply,
'attachments': '[]', 'msg_type': 'text', 'org_id': org_id, 'created_by': 'system' 'attachments': '[]', 'msg_type': 'text', 'org_id': org_id, 'created_by': 'system'
@ -439,7 +438,7 @@ else:
where.append("iteration_id=${iid}$") where.append("iteration_id=${iid}$")
params["iid"] = iteration_id 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) msgs = await sor.sqlExe(sql, params)
msg_widgets = [] msg_widgets = []