更新渠道申请

This commit is contained in:
Ubuntu
2026-01-05 13:03:15 +00:00
parent 23c84ea23e
commit 3a8e12657b
8 changed files with 1014 additions and 656 deletions
+44 -4
View File
@@ -677,10 +677,50 @@ async def list_channels(
for alloc in allocations:
# 查询Agent的资源配置
agent_result = await db.execute(
select(Agent).where(Agent.id == alloc.resource_id)
)
agent = agent_result.scalar_one_or_none()
# resource_id 可能是 UUID 字符串或模板名称(如 'code-reviewer')
agent = None
# 首先尝试按 UUID 查询
try:
resource_uuid = uuid.UUID(alloc.resource_id)
agent_result = await db.execute(
select(Agent).where(Agent.id == resource_uuid)
)
agent = agent_result.scalar_one_or_none()
except (ValueError, TypeError):
# 如果不是有效的 UUID,按名称查询
pass
# 如果按 UUID 没找到,尝试按名称查询
if not agent:
agent_result = await db.execute(
select(Agent).where(Agent.name == alloc.resource_id)
)
agent = agent_result.scalar_one_or_none()
# 如果仍然没找到,检查是否是平台 Agent 模板
if not agent and alloc.resource_id in PLATFORM_AGENT_TEMPLATES:
template = PLATFORM_AGENT_TEMPLATES[alloc.resource_id]
# 使用模板的默认资源配置
quantity = alloc.quantity or 1
# 解析 CPU (如 "500m" -> 0.5 核)
cpu_limit = template.get("cpuLimit", "0")
if isinstance(cpu_limit, str) and cpu_limit.endswith("m"):
total_cpu += float(cpu_limit[:-1]) / 1000 * quantity
elif cpu_limit:
try:
total_cpu += float(cpu_limit) * quantity
except ValueError:
pass
# 解析内存 (如 "512Mi" -> 0.5 GB)
memory_limit = template.get("memoryLimit", "0")
if isinstance(memory_limit, str):
if memory_limit.endswith("Mi"):
total_memory += float(memory_limit[:-2]) / 1024 * quantity
elif memory_limit.endswith("Gi"):
total_memory += float(memory_limit[:-2]) * quantity
continue
if agent:
quantity = alloc.quantity or 1
total_cpu += float(agent.cpu or 0) * quantity