From 772477607f719961163fd0b5cadcd32cedd5c967 Mon Sep 17 00:00:00 2001 From: ViperEkura <3081035982@qq.com> Date: Mon, 13 Apr 2026 15:33:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=9F=E4=B8=80=E5=89=8D=E5=90=8E?= =?UTF-8?q?=E7=AB=AF=E8=BF=94=E5=9B=9E=E7=BB=93=E6=9E=9C=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dashboard/src/components/ProcessBlock.vue | 22 ++++-- luxx/tools/builtin/code.py | 34 +++------ luxx/tools/builtin/crawler.py | 14 ++-- luxx/tools/builtin/data.py | 86 ++++++----------------- luxx/tools/services.py | 5 +- 5 files changed, 60 insertions(+), 101 deletions(-) diff --git a/dashboard/src/components/ProcessBlock.vue b/dashboard/src/components/ProcessBlock.vue index 8c9e317..75ab6ba 100644 --- a/dashboard/src/components/ProcessBlock.vue +++ b/dashboard/src/components/ProcessBlock.vue @@ -99,10 +99,24 @@ const allItems = computed(() => { const toolId = step.id_ref || step.id const match = items.findLast(it => it.type === 'tool_call' && it.id === toolId) if (match) { - const resultContent = step.content || '' - match.resultSummary = resultContent.slice(0, 200) - match.fullResult = resultContent - match.displayResult = resultContent.length > 1024 ? resultContent.slice(0, 1024) + '...' : resultContent + let resultContent = step.content || '' + let displayContent = resultContent + + // 尝试解析 JSON 并格式化显示 + try { + const parsed = JSON.parse(resultContent) + if (parsed.error) { + displayContent = `错误: ${parsed.error}` + } else { + displayContent = JSON.stringify(parsed, null, 2) + } + } catch (e) { + // 不是 JSON,保持原样 + } + + match.resultSummary = displayContent.slice(0, 200) + match.fullResult = displayContent + match.displayResult = displayContent.length > 2048 ? displayContent.slice(0, 2048) + '...' : displayContent match.isSuccess = step.success !== false match.loading = false } else { diff --git a/luxx/tools/builtin/code.py b/luxx/tools/builtin/code.py index 799e2bf..d883581 100644 --- a/luxx/tools/builtin/code.py +++ b/luxx/tools/builtin/code.py @@ -37,7 +37,7 @@ def python_execute(arguments: Dict[str, Any]) -> Dict[str, Any]: timeout = arguments.get("timeout", 30) if not code: - return {"success": False, "error": "Code is required"} + return {"error": "Code is required"} # Create execution environment namespace = { @@ -64,23 +64,13 @@ def python_execute(arguments: Dict[str, Any]) -> Dict[str, Any]: if not k.startswith("_") and k != "__builtins__"} return { - "success": True, - "data": { - "output": result, - "variables": {k: repr(v) for k, v in result_vars.items()}, - "error": None - } + "output": result, + "variables": {k: repr(v) for k, v in result_vars.items()} } except SyntaxError as e: - return { - "success": False, - "error": f"Syntax error: {e}" - } + return {"error": f"Syntax error: {e}"} except Exception as e: - return { - "success": False, - "error": f"Runtime error: {type(e).__name__}: {str(e)}" - } + return {"error": f"Runtime error: {type(e).__name__}: {str(e)}"} @tool( @@ -103,19 +93,13 @@ def python_eval(arguments: Dict[str, Any]) -> Dict[str, Any]: expression = arguments.get("expression", "") if not expression: - return {"success": False, "error": "Expression is required"} + return {"error": "Expression is required"} try: result = eval(expression) return { - "success": True, - "data": { - "result": repr(result), - "type": type(result).__name__ - } + "result": repr(result), + "type": type(result).__name__ } except Exception as e: - return { - "success": False, - "error": f"Evaluation error: {str(e)}" - } + return {"error": f"Evaluation error: {str(e)}"} diff --git a/luxx/tools/builtin/crawler.py b/luxx/tools/builtin/crawler.py index 856386d..bc12b7f 100644 --- a/luxx/tools/builtin/crawler.py +++ b/luxx/tools/builtin/crawler.py @@ -13,7 +13,7 @@ from luxx.tools.services import SearchService, FetchService }, category="crawler") def web_search(arguments: dict) -> dict: results = SearchService().search(arguments["query"], arguments.get("max_results", 5)) - return {"success": True, "data": {"query": arguments["query"], "results": results or []}} + return {"results": results or []} @tool(name="web_fetch", description="Fetch content from a webpage.", parameters={ @@ -26,9 +26,11 @@ def web_search(arguments: dict) -> dict: }, category="crawler") def web_fetch(arguments: dict) -> dict: if not arguments.get("url"): - return {"success": False, "error": "URL is required"} + return {"error": "URL is required"} result = FetchService().fetch(arguments["url"], arguments.get("extract_type", "text")) - return {"success": "error" not in result, "data": result, "error": result.get("error")} + if "error" in result: + return {"error": result["error"]} + return result @tool(name="batch_fetch", description="Batch fetch multiple webpages.", parameters={ @@ -42,8 +44,8 @@ def web_fetch(arguments: dict) -> dict: def batch_fetch(arguments: dict) -> dict: urls = arguments.get("urls", []) if not urls: - return {"success": False, "error": "URLs list is required"} + return {"error": "URLs list is required"} if len(urls) > 10: - return {"success": False, "error": "Maximum 10 pages allowed"} + return {"error": "Maximum 10 pages allowed"} results = FetchService().fetch_batch(urls, arguments.get("extract_type", "text")) - return {"success": True, "data": {"results": results, "total": len(results)}} + return {"results": results, "total": len(results)} diff --git a/luxx/tools/builtin/data.py b/luxx/tools/builtin/data.py index 4ea99a8..540ea4d 100644 --- a/luxx/tools/builtin/data.py +++ b/luxx/tools/builtin/data.py @@ -28,7 +28,7 @@ def calculate(arguments: Dict[str, Any]) -> Dict[str, Any]: expression = arguments.get("expression", "") if not expression: - return {"success": False, "error": "Expression is required"} + return {"error": "Expression is required"} try: # Safe replacement for math functions @@ -52,19 +52,9 @@ def calculate(arguments: Dict[str, Any]) -> Dict[str, Any]: result = eval(safe_expr, {"__builtins__": {}, **safe_dict}) - return { - "success": True, - "data": { - "expression": expression, - "result": result, - "formatted": f"{result}" - } - } + return {"result": result} except Exception as e: - return { - "success": False, - "error": f"Calculation error: {str(e)}" - } + return {"error": f"Calculation error: {str(e)}"} @tool( @@ -93,7 +83,7 @@ def text_process(arguments: Dict[str, Any]) -> Dict[str, Any]: operation = arguments.get("operation", "") if not text: - return {"success": False, "error": "Text is required"} + return {"error": "Text is required"} operations = { "uppercase": text.upper(), @@ -108,16 +98,9 @@ def text_process(arguments: Dict[str, Any]) -> Dict[str, Any]: result = operations.get(operation) if result is None: - return {"success": False, "error": f"Unknown operation: {operation}"} + return {"error": f"Unknown operation: {operation}"} - return { - "success": True, - "data": { - "original": text, - "operation": operation, - "result": result - } - } + return {"result": result} @tool( @@ -146,7 +129,7 @@ def json_process(arguments: Dict[str, Any]) -> Dict[str, Any]: operation = arguments.get("operation", "") if not data: - return {"success": False, "error": "Data is required"} + return {"error": "Data is required"} try: parsed = json.loads(data) @@ -158,17 +141,11 @@ def json_process(arguments: Dict[str, Any]) -> Dict[str, Any]: elif operation == "validate": result = "Valid JSON" else: - return {"success": False, "error": f"Unknown operation: {operation}"} + return {"error": f"Unknown operation: {operation}"} - return { - "success": True, - "data": { - "result": result, - "operation": operation - } - } + return {"result": result} except json.JSONDecodeError as e: - return {"success": False, "error": f"Invalid JSON: {str(e)}"} + return {"error": f"Invalid JSON: {str(e)}"} @tool( @@ -199,23 +176,16 @@ def hash_text(arguments: Dict[str, Any]) -> Dict[str, Any]: algorithm = arguments.get("algorithm", "sha256") if not text: - return {"success": False, "error": "Text is required"} + return {"error": "Text is required"} try: hash_obj = hashlib.new(algorithm) hash_obj.update(text.encode('utf-8')) hash_value = hash_obj.hexdigest() - return { - "success": True, - "data": { - "text": text, - "algorithm": algorithm, - "hash": hash_value - } - } + return {"hash": hash_value} except Exception as e: - return {"success": False, "error": f"Hash error: {str(e)}"} + return {"error": f"Hash error: {str(e)}"} @tool( @@ -244,7 +214,7 @@ def url_encode_decode(arguments: Dict[str, Any]) -> Dict[str, Any]: operation = arguments.get("operation", "") if not text: - return {"success": False, "error": "Text is required"} + return {"error": "Text is required"} try: if operation == "encode": @@ -252,18 +222,11 @@ def url_encode_decode(arguments: Dict[str, Any]) -> Dict[str, Any]: elif operation == "decode": result = unquote(text) else: - return {"success": False, "error": f"Unknown operation: {operation}"} + return {"error": f"Unknown operation: {operation}"} - return { - "success": True, - "data": { - "original": text, - "operation": operation, - "result": result - } - } + return {"result": result} except Exception as e: - return {"success": False, "error": f"URL error: {str(e)}"} + return {"error": f"URL error: {str(e)}"} @tool( @@ -292,7 +255,7 @@ def base64_encode_decode(arguments: Dict[str, Any]) -> Dict[str, Any]: operation = arguments.get("operation", "") if not text: - return {"success": False, "error": "Text is required"} + return {"error": "Text is required"} try: if operation == "encode": @@ -300,15 +263,8 @@ def base64_encode_decode(arguments: Dict[str, Any]) -> Dict[str, Any]: elif operation == "decode": result = base64.b64decode(text.encode()).decode() else: - return {"success": False, "error": f"Unknown operation: {operation}"} + return {"error": f"Unknown operation: {operation}"} - return { - "success": True, - "data": { - "original": text, - "operation": operation, - "result": result - } - } + return {"result": result} except Exception as e: - return {"success": False, "error": f"Base64 error: {str(e)}"} + return {"error": f"Base64 error: {str(e)}"} diff --git a/luxx/tools/services.py b/luxx/tools/services.py index b9f87f1..42b49f2 100644 --- a/luxx/tools/services.py +++ b/luxx/tools/services.py @@ -72,6 +72,9 @@ class FetchService: with ThreadPoolExecutor(max_workers=max_concurrent) as pool: futures = {pool.submit(self.fetch, url, extract_type): i for i, url in enumerate(urls)} for future in as_completed(futures): - results[futures[future]] = future.result() + try: + results[futures[future]] = future.result() + except Exception as e: + results[futures[future]] = {"error": str(e)} return results