From 0b1f3d411f898c4c447ce3d9a5e4f0adc793fbca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=BD=AE?= Date: Fri, 26 Jun 2026 08:38:40 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E7=94=A8=E6=99=BA=E8=83=BD=E4=BD=93?= =?UTF-8?q?=E5=AD=90=E8=B4=A6=E5=8F=B7=E4=BD=BF=E7=94=A8=E4=B8=BB=E8=B4=A6?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/fastapi_utils.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/utils/fastapi_utils.py b/utils/fastapi_utils.py index ac4c5c3..5dd8709 100644 --- a/utils/fastapi_utils.py +++ b/utils/fastapi_utils.py @@ -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: async with pool.connection() as conn: async with conn.cursor() as cursor: + # Sub-accounts should fall back to the parent account's API token 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,) ) row = await cursor.fetchone() - if row and row[0]: - config["api_key"] = row[0] + if row: + config["api_key"] = row[1] or row[0] or "" logger.info( f"Fetched general agent config: model={config['model']}, " f"api_key={'*' + config['api_key'][-4:] if config.get('api_key') else 'N/A'}"