diff --git a/python_core/ai_video/video_generator.py b/python_core/ai_video/video_generator.py index e9579fe..9579338 100644 --- a/python_core/ai_video/video_generator.py +++ b/python_core/ai_video/video_generator.py @@ -206,6 +206,14 @@ class VideoGenerator: result['error_details'] = error_details logger.error(f"Video generation failed: {result['msg']}") logger.error(f"Traceback: {error_details['traceback']}") + progress.error(result['msg']) + rpc.error(JSONRPCError.GENERATION_FAILED, "Video generation failed", error_details) + + # Send final result via JSON-RPC + if result['status']: + rpc.success(result) + else: + rpc.error(JSONRPCError.GENERATION_FAILED, result.get('msg', 'Unknown error'), result) return result diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 406cdcc..f14ca84 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -135,17 +135,20 @@ async fn execute_python_command(app: tauri::AppHandle, args: &[String]) -> Resul progress_messages.push(json_value); println!("Progress: {}", json_str); } - } else if json_value.get("result").is_some() { - // This is a final result + } else if json_value.get("result").is_some() || json_value.get("error").is_some() { + // This is a final result or error response final_result = Some(json_str.to_string()); - println!("Final result: {}", json_str); + println!("Final JSON-RPC result: {}", json_str); } } } else if line.trim().starts_with('{') && line.trim().ends_with('}') { // Fallback: try to parse as direct JSON result - if let Ok(_) = serde_json::from_str::(line.trim()) { - final_result = Some(line.trim().to_string()); - println!("Direct JSON result: {}", line.trim()); + if let Ok(json_value) = serde_json::from_str::(line.trim()) { + // Check if this looks like a final result (has status field) + if json_value.get("status").is_some() { + final_result = Some(line.trim().to_string()); + println!("Direct JSON result: {}", line.trim()); + } } } } diff --git a/src/services/tauri.ts b/src/services/tauri.ts index e67decb..f34ab2d 100644 --- a/src/services/tauri.ts +++ b/src/services/tauri.ts @@ -389,6 +389,20 @@ export class AIVideoService { const parsedResult = JSON.parse(result as string) console.log('Parsed result:', parsedResult) + // Handle JSON-RPC response format + if (parsedResult.jsonrpc === "2.0") { + if (parsedResult.result) { + // Success response + console.log('JSON-RPC success result:', parsedResult.result) + return parsedResult.result + } else if (parsedResult.error) { + // Error response + console.error('JSON-RPC error:', parsedResult.error) + throw new Error(parsedResult.error.message || 'JSON-RPC error') + } + } + + // Fallback: direct result format return parsedResult } catch (error) { console.error('Failed to generate AI video:', error)