通用智能体子账号使用主账号

This commit is contained in:
朱潮 2026-06-26 08:38:40 +08:00
parent 462ba14074
commit 0b1f3d411f

View File

@ -615,13 +615,19 @@ async def fetch_bot_config_from_db(bot_user_id: str, user_identifier: Optional[s
if not config.get("api_key") and user_identifier: if not config.get("api_key") and user_identifier:
async with pool.connection() as conn: async with pool.connection() as conn:
async with conn.cursor() as cursor: async with conn.cursor() as cursor:
# Sub-accounts should fall back to the parent account's API token
await cursor.execute( await cursor.execute(
"SELECT new_api_token FROM agent_user WHERE username = %s", """
SELECT u.new_api_token, parent.new_api_token
FROM agent_user u
LEFT JOIN agent_user parent ON u.parent_id = parent.id
WHERE u.username = %s
""",
(user_identifier,) (user_identifier,)
) )
row = await cursor.fetchone() row = await cursor.fetchone()
if row and row[0]: if row:
config["api_key"] = row[0] config["api_key"] = row[1] or row[0] or ""
logger.info( logger.info(
f"Fetched general agent config: model={config['model']}, " f"Fetched general agent config: model={config['model']}, "
f"api_key={'*' + config['api_key'][-4:] if config.get('api_key') else 'N/A'}" f"api_key={'*' + config['api_key'][-4:] if config.get('api_key') else 'N/A'}"