fix: Application debugging will add new users (#3630)

This commit is contained in:
shaohuzhang1 2025-07-16 16:47:32 +08:00 committed by GitHub
parent f385bb3aec
commit 69f004359b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 8 deletions

View File

@ -65,7 +65,7 @@ def event_content(response,
message_list: List[BaseMessage],
problem_text: str,
padding_problem_text: str = None,
client_id=None, client_type=None,
chat_user_id=None, chat_user_type=None,
is_ai_chat: bool = None,
model_setting=None):
if model_setting is None:
@ -134,14 +134,16 @@ def event_content(response,
request_token, response_token,
{'node_is_end': True, 'view_type': 'many_view',
'node_type': 'ai-chat-node'})
add_access_num(client_id, client_type, manage.context.get('application_id'))
if not manage.debug:
add_access_num(chat_user_id, chat_user_type, manage.context.get('application_id'))
except Exception as e:
maxkb_logger.error(f'{str(e)}:{traceback.format_exc()}')
all_text = 'Exception:' + str(e)
write_context(step, manage, 0, 0, all_text)
post_response_handler.handler(chat_id, chat_record_id, paragraph_list, problem_text,
all_text, manage, step, padding_problem_text, reasoning_content='')
add_access_num(client_id, client_type, manage.context.get('application_id'))
if not manage.debug:
add_access_num(chat_user_id, chat_user_type, manage.context.get('application_id'))
yield manage.get_base_to_response().to_stream_chunk_response(chat_id, str(chat_record_id), 'ai-chat-node',
[], all_text,
False,
@ -281,7 +283,7 @@ class BaseChatStep(IChatStep):
paragraph_list=None,
manage: PipelineManage = None,
padding_problem_text: str = None,
client_id=None, client_type=None, no_references_setting=None,
chat_user_id=None, chat_user_type=None, no_references_setting=None,
model_setting=None):
reasoning_content_enable = model_setting.get('reasoning_content_enable', False)
reasoning_content_start = model_setting.get('reasoning_content_start', '<think>')
@ -311,7 +313,8 @@ class BaseChatStep(IChatStep):
post_response_handler.handler(chat_id, chat_record_id, paragraph_list, problem_text,
content, manage, self, padding_problem_text,
reasoning_content=reasoning_content)
add_access_num(client_id, client_type, manage.context.get('application_id'))
if not manage.debug:
add_access_num(chat_user_id, chat_user_type, manage.context.get('application_id'))
return manage.get_base_to_response().to_block_response(str(chat_id), str(chat_record_id),
content, True,
request_token, response_token,
@ -326,6 +329,7 @@ class BaseChatStep(IChatStep):
write_context(self, manage, 0, 0, all_text)
post_response_handler.handler(chat_id, chat_record_id, paragraph_list, problem_text,
all_text, manage, self, padding_problem_text, reasoning_content='')
add_access_num(client_id, client_type, manage.context.get('application_id'))
if not manage.debug:
add_access_num(chat_user_id, chat_user_type, manage.context.get('application_id'))
return manage.get_base_to_response().to_block_response(str(chat_id), str(chat_record_id), all_text, True, 0,
0, _status=status.HTTP_500_INTERNAL_SERVER_ERROR)

View File

@ -83,7 +83,8 @@ class WorkFlowPostHandler:
self.chat_info.append_chat_record(chat_record)
self.chat_info.set_cache()
if [ChatUserType.ANONYMOUS_USER.value, ChatUserType.CHAT_USER.value].__contains__(
if not self.chat_info.debug and [ChatUserType.ANONYMOUS_USER.value, ChatUserType.CHAT_USER.value].__contains__(
workflow_body.get('chat_user_type')):
application_public_access_client = (QuerySet(ApplicationChatUserStats)
.filter(chat_user_id=workflow_body.get('chat_user_id'),

View File

@ -533,7 +533,7 @@ class ApplicationSerializer(serializers.Serializer):
UserResourcePermissionSerializer(data={
'workspace_id': self.data.get('workspace_id'),
'user_id': self.data.get('user_id'),
'auth_target_type': AuthTargetType.APPLICATION.value
'auth_target_type': AuthTargetType.TOOL.value
}).auth_resource_batch([t.id for t in tool_model_list])
return True