diff --git a/python_core/cli/commands/auth.py b/python_core/cli/commands/auth.py index 093512f..95b54a4 100644 --- a/python_core/cli/commands/auth.py +++ b/python_core/cli/commands/auth.py @@ -26,7 +26,7 @@ def register_user( password: Optional[str] = typer.Option(None, "--password", "-p", help="密码(不提供则交互式输入)") ): """注册新用户""" - response = create_response_handler(str(uuid4())) + response = create_response_handler() try: # 获取密码 if not password: @@ -52,7 +52,7 @@ def login_user( password: Optional[str] = typer.Option(None, "--password", "-p", help="密码(不提供则交互式输入)") ): """用户登录""" - response = create_response_handler(str(uuid4())) + response = create_response_handler() try: # 获取密码 if not password: @@ -75,7 +75,7 @@ def verify_token( token: str = typer.Argument(..., help="JWT token"), ): """验证JWT token""" - response = create_response_handler(str(uuid4())) + response = create_response_handler() try: # 验证token result = auth_api.verify_token({ @@ -92,7 +92,7 @@ def list_users( include_inactive: bool = typer.Option(False, "--include-inactive", "-i", help="包含非活跃用户"), ): """列出所有用户""" - response = create_response_handler(str(uuid4())) + response = create_response_handler() try: # 获取用户列表 users = user_table.get_all_users(include_inactive) @@ -105,7 +105,7 @@ def list_users( @auth_app.command("stats") def show_stats(): """显示用户统计信息""" - response = create_response_handler(str(uuid4())) + response = create_response_handler() try: # 获取统计信息 stats = user_table.get_user_count() diff --git a/python_core/cli/commands/template.py b/python_core/cli/commands/template.py index 9c72a48..1ce974c 100644 --- a/python_core/cli/commands/template.py +++ b/python_core/cli/commands/template.py @@ -22,7 +22,7 @@ def batch_import( json_output: bool = typer.Option(True, "--json", help="JSON格式输出") ): """批量导入模板""" - response = create_progress_reporter(str(uuid4())) + response = create_progress_reporter() try: # 验证源文件夹 source_path = Path(source_folder) @@ -69,7 +69,7 @@ def list_templates( json_output: bool = typer.Option(True, "--json", help="JSON格式输出") ): """列出所有模板""" - response = create_response_handler(str(uuid4())) + response = create_response_handler() try: # 创建模板管理器 manager = TemplateManagerCloud(user_id=user_id or "default") @@ -107,7 +107,7 @@ def get_template( json_output: bool = typer.Option(True, "--json", help="JSON格式输出") ): """获取模板详情""" - response = create_response_handler(str(uuid4())) + response = create_response_handler() try: # 创建模板管理器 manager = TemplateManagerCloud(user_id=user_id or "default") @@ -140,7 +140,7 @@ def delete_template( json_output: bool = typer.Option(True, "--json", help="JSON格式输出") ): """删除模板""" - response = create_response_handler(str(uuid4())) + response = create_response_handler() try: # 创建模板管理器 manager = TemplateManagerCloud(user_id=user_id or "default") @@ -177,7 +177,7 @@ def search_templates( json_output: bool = typer.Option(True, "--json", help="JSON格式输出") ): """搜索模板""" - response = create_response_handler(str(uuid4())) + response = create_response_handler() try: # 创建模板管理器 manager = TemplateManagerCloud(user_id=user_id or "default") @@ -211,7 +211,7 @@ def get_template_stats( json_output: bool = typer.Option(True, "--json", help="JSON格式输出") ): """获取模板统计信息""" - response = create_response_handler(str(uuid4())) + response = create_response_handler() try: # 创建模板管理器 manager = TemplateManagerCloud(user_id=user_id or "default") @@ -250,7 +250,7 @@ def get_popular_tags( json_output: bool = typer.Option(True, "--json", help="JSON格式输出") ): """获取热门标签""" - response = create_response_handler(str(uuid4())) + response = create_response_handler() try: # 创建模板管理器 manager = TemplateManagerCloud(user_id=user_id or "default") @@ -278,7 +278,7 @@ def get_templates_by_tag( json_output: bool = typer.Option(True, "--json", help="JSON格式输出") ): """根据标签获取模板""" - response = create_response_handler(str(uuid4())) + response = create_response_handler() try: # 创建模板管理器 manager = TemplateManagerCloud(user_id=user_id or "default") diff --git a/python_core/utils/jsonrpc_enhanced.py b/python_core/utils/jsonrpc_enhanced.py index 7344505..dd42e9d 100644 --- a/python_core/utils/jsonrpc_enhanced.py +++ b/python_core/utils/jsonrpc_enhanced.py @@ -96,8 +96,8 @@ class EnhancedJSONRPCResponse: class EnhancedProgressReporter: """增强版进度报告器""" - def __init__(self, total: int = 0): - self.response = EnhancedJSONRPCResponse() + def __init__(self, response_id: str, total: int = 0): + self.response = EnhancedJSONRPCResponse(response_id) self.step = 0 self.total = total @@ -131,6 +131,15 @@ class EnhancedProgressReporter: """调试消息""" self.response.progress("debug", -1, message, ProgressLevel.DEBUG, data) + def progress(self, current: int, total: int, message: str, data: Optional[Dict[str, Any]] = None) -> None: + """进度报告 - 兼容旧版本API""" + if total > 0: + progress_percentage = int((current / total) * 100) + else: + progress_percentage = -1 + + self.response.progress("progress", progress_percentage, message, ProgressLevel.INFO, data) + class JSONRPCMethodRegistry: """JSON-RPC 方法注册器""" @@ -225,14 +234,14 @@ method_registry = JSONRPCMethodRegistry() # 便捷函数 -def create_response_handler(request_id: Optional[Union[str, int]] = None) -> EnhancedJSONRPCResponse: +def create_response_handler() -> EnhancedJSONRPCResponse: """创建响应处理器""" - return EnhancedJSONRPCResponse(request_id) + return EnhancedJSONRPCResponse(uuid4()) - -def create_progress_reporter(total: int = 0) -> EnhancedProgressReporter: +from uuid import uuid4 +def create_progress_reporter(total: int = 100) -> EnhancedProgressReporter: """创建进度报告器""" - return EnhancedProgressReporter(total) + return EnhancedProgressReporter(uuid4(), total) def register_method(name: Optional[str] = None):