Skip to content

Commit 3139b62

Browse files
perf: Assistant's basic application records are stored in the workspace of their respective data source
1 parent bcb192f commit 3139b62

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

backend/apps/system/api/assistant.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,15 @@ async def validator(session: SessionDep, id: int, virtual: Optional[int] = Query
6464
if not db_model:
6565
return AssistantValidator()
6666
db_model = AssistantModel.model_validate(db_model)
67+
assistant_oid = 1
68+
if(db_model.type == 0):
69+
configuration = db_model.configuration
70+
config_obj = json.loads(configuration) if configuration else {}
71+
assistant_oid = config_obj.get('oid', 1)
72+
6773
access_token_expires = timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
6874
assistantDict = {
69-
"id": virtual, "account": 'sqlbot-inner-assistant', "oid": 1, "assistant_id": id
75+
"id": virtual, "account": 'sqlbot-inner-assistant', "oid": assistant_oid, "assistant_id": id
7076
}
7177
access_token = create_access_token(
7278
assistantDict, expires_delta=access_token_expires

backend/apps/system/middleware/auth.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
import base64
3+
import json
34
from typing import Optional
45
from fastapi import Request
56
from fastapi.responses import JSONResponse
@@ -112,6 +113,16 @@ async def validateAssistant(self, assistantToken: Optional[str], trans: I18n) ->
112113
assistant_info = await get_assistant_info(session=session, assistant_id=payload['assistant_id'])
113114
assistant_info = AssistantModel.model_validate(assistant_info)
114115
assistant_info = AssistantHeader.model_validate(assistant_info.model_dump(exclude_unset=True))
116+
if assistant_info and assistant_info.type == 0:
117+
if payload['oid']:
118+
session_user.oid = payload['oid']
119+
else:
120+
assistant_oid = 1
121+
configuration = assistant_info.configuration
122+
config_obj = json.loads(configuration) if configuration else {}
123+
assistant_oid = config_obj.get('oid', 1)
124+
session_user.oid = assistant_oid
125+
115126
return True, session_user, assistant_info
116127
except Exception as e:
117128
SQLBotLogUtil.exception(f"Assistant validation error: {str(e)}")

0 commit comments

Comments
 (0)