fix: load/save_agent_config 用不存在的 project_id 列查 sd_org_settings
sd_org_settings 以 org_id 为键(无 project_id 列),导致每次 cockpit 请求抛 'Unknown column project_id'。 改为先由 sd_projects 解析 org_id 再查。save_agent_config 同步修正。
This commit is contained in:
parent
8d431721fa
commit
2ecf6e06f7
BIN
pipeline_core/__pycache__/agent_config.cpython-310.pyc
Normal file
BIN
pipeline_core/__pycache__/agent_config.cpython-310.pyc
Normal file
Binary file not shown.
@ -335,7 +335,7 @@ async def load_agent_config(pipeline_id: str = None, project_id: str = None) ->
|
|||||||
"""加载产线的 Agent 配置。
|
"""加载产线的 Agent 配置。
|
||||||
|
|
||||||
优先级:
|
优先级:
|
||||||
1. 项目级 sd_org_settings.agent_config
|
1. 项目级 sd_org_settings.agent_config(sd_org_settings 以 org_id 为键,由项目解析 org_id)
|
||||||
2. 产线级 pipelines.agent_config
|
2. 产线级 pipelines.agent_config
|
||||||
3. SDLC_DEFAULT_CONFIG
|
3. SDLC_DEFAULT_CONFIG
|
||||||
"""
|
"""
|
||||||
@ -344,21 +344,27 @@ async def load_agent_config(pipeline_id: str = None, project_id: str = None) ->
|
|||||||
|
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
async with db.sqlorContext("pipeline") as sor:
|
async with db.sqlorContext("pipeline") as sor:
|
||||||
# 项目级配置
|
# 项目级配置:sd_org_settings 无 project_id 列,需先由 sd_projects 解析 org_id 再查
|
||||||
if project_id:
|
if project_id:
|
||||||
recs = await sor.sqlExe(
|
org_id = ""
|
||||||
"SELECT agent_config FROM sd_org_settings WHERE project_id=${pid}$",
|
proj_recs = await sor.sqlExe(
|
||||||
{"pid": project_id},
|
"SELECT org_id FROM sd_projects WHERE id=${pid}$", {"pid": project_id})
|
||||||
)
|
if proj_recs:
|
||||||
if recs:
|
org_id = getattr(proj_recs[0], "org_id", "") or ""
|
||||||
raw = getattr(recs[0], "agent_config", "")
|
if org_id:
|
||||||
if raw:
|
recs = await sor.sqlExe(
|
||||||
try:
|
"SELECT agent_config FROM sd_org_settings WHERE org_id=${oid}$",
|
||||||
data = json.loads(raw) if isinstance(raw, str) else raw
|
{"oid": org_id},
|
||||||
data["tools"] = _merge_tools(data.get("tools", []), SDLC_DEFAULT_TOOLS)
|
)
|
||||||
return AgentConfig.from_dict(data)
|
if recs:
|
||||||
except (json.JSONDecodeError, TypeError):
|
raw = getattr(recs[0], "agent_config", "")
|
||||||
pass
|
if raw:
|
||||||
|
try:
|
||||||
|
data = json.loads(raw) if isinstance(raw, str) else raw
|
||||||
|
data["tools"] = _merge_tools(data.get("tools", []), SDLC_DEFAULT_TOOLS)
|
||||||
|
return AgentConfig.from_dict(data)
|
||||||
|
except (json.JSONDecodeError, TypeError):
|
||||||
|
pass
|
||||||
|
|
||||||
# 产线级配置 + 产线缺省模型
|
# 产线级配置 + 产线缺省模型
|
||||||
if pipeline_id:
|
if pipeline_id:
|
||||||
@ -400,27 +406,37 @@ def _merge_tools(custom_tools: list, default_tools: list) -> list:
|
|||||||
|
|
||||||
|
|
||||||
async def save_agent_config(project_id: str, config: AgentConfig):
|
async def save_agent_config(project_id: str, config: AgentConfig):
|
||||||
"""保存项目级 Agent 配置到 sd_org_settings"""
|
"""保存项目级 Agent 配置到 sd_org_settings(按 org_id 组织)"""
|
||||||
from sqlor.dbpools import DBPools
|
from sqlor.dbpools import DBPools
|
||||||
|
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
async with db.sqlorContext("pipeline") as sor:
|
async with db.sqlorContext("pipeline") as sor:
|
||||||
|
# sd_org_settings 以 org_id 为键,需先由项目解析 org_id
|
||||||
|
org_id = ""
|
||||||
|
ws = ""
|
||||||
|
proj_recs = await sor.sqlExe(
|
||||||
|
"SELECT org_id, workspace_dir FROM sd_projects WHERE id=${pid}$", {"pid": project_id})
|
||||||
|
if proj_recs:
|
||||||
|
org_id = getattr(proj_recs[0], "org_id", "") or ""
|
||||||
|
ws = getattr(proj_recs[0], "workspace_dir", "") or ""
|
||||||
|
if not org_id:
|
||||||
|
return
|
||||||
config_json = json.dumps(config.to_dict(), ensure_ascii=False)
|
config_json = json.dumps(config.to_dict(), ensure_ascii=False)
|
||||||
# UPDATE-first 防止竞态
|
# UPDATE-first 防止竞态
|
||||||
await sor.sqlExe(
|
await sor.sqlExe(
|
||||||
"UPDATE sd_org_settings SET agent_config=${cfg}$ WHERE project_id=${pid}$",
|
"UPDATE sd_org_settings SET agent_config=${cfg}$ WHERE org_id=${oid}$",
|
||||||
{"cfg": config_json, "pid": project_id},
|
{"cfg": config_json, "oid": org_id},
|
||||||
)
|
)
|
||||||
existing = await sor.sqlExe(
|
existing = await sor.sqlExe(
|
||||||
"SELECT id FROM sd_org_settings WHERE project_id=${pid}$",
|
"SELECT id FROM sd_org_settings WHERE org_id=${oid}$", {"oid": org_id},
|
||||||
{"pid": project_id},
|
|
||||||
)
|
)
|
||||||
if not existing:
|
if not existing:
|
||||||
from appPublic.uniqueID import getID
|
from appPublic.uniqueID import getID
|
||||||
|
|
||||||
await sor.C("sd_org_settings", {
|
await sor.C("sd_org_settings", {
|
||||||
"id": getID(),
|
"id": getID(),
|
||||||
"project_id": project_id,
|
"org_id": org_id,
|
||||||
|
"workspace_root": ws or "/tmp/ws",
|
||||||
"agent_config": config_json,
|
"agent_config": config_json,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user