This commit is contained in:
root
2025-07-12 21:17:36 +08:00
parent cc33875d16
commit 3927c4ffb7
3 changed files with 29 additions and 20 deletions

View File

@@ -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):