From 69f004359b6aff65dac4a8d7d3dc15b3e642f125 Mon Sep 17 00:00:00 2001 From: shaohuzhang1 <80892890+shaohuzhang1@users.noreply.github.com> Date: Wed, 16 Jul 2025 16:47:32 +0800 Subject: [PATCH] fix: Application debugging will add new users (#3630) --- .../step/chat_step/impl/base_chat_step.py | 16 ++++++++++------ apps/application/flow/i_step_node.py | 3 ++- apps/application/serializers/application.py | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/apps/application/chat_pipeline/step/chat_step/impl/base_chat_step.py b/apps/application/chat_pipeline/step/chat_step/impl/base_chat_step.py index 295680713..8e4c410f0 100644 --- a/apps/application/chat_pipeline/step/chat_step/impl/base_chat_step.py +++ b/apps/application/chat_pipeline/step/chat_step/impl/base_chat_step.py @@ -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', '') @@ -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) diff --git a/apps/application/flow/i_step_node.py b/apps/application/flow/i_step_node.py index 02e7470d5..4e35fac2b 100644 --- a/apps/application/flow/i_step_node.py +++ b/apps/application/flow/i_step_node.py @@ -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'), diff --git a/apps/application/serializers/application.py b/apps/application/serializers/application.py index c96cecb3b..d5f247e55 100644 --- a/apps/application/serializers/application.py +++ b/apps/application/serializers/application.py @@ -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