forked from xiaohei/taiji-AI-PAD
更新渠道申请
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user