refactor: 直接使用 TolerantJsonParser 而不是通过命令调用

- 移除对 parse_json_tolerant 命令的依赖,避免 Mutex 污染问题
- 直接创建和使用 TolerantJsonParser 实例
- 简化代码路径,提高性能和稳定性
- 移除不必要的 JsonParserState 参数
This commit is contained in:
imeepos 2025-08-15 18:59:42 +08:00
parent 8785cc6097
commit 9ba62d9e06
1 changed files with 13 additions and 21 deletions

View File

@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
use serde_json::Value;
use chrono;
use veo3_scene_writer::Veo3ActorDefine;
use crate::presentation::commands::tolerant_json_commands::{ParseJsonRequest, JsonParserState};
use crate::infrastructure::tolerant_json_parser::TolerantJsonParser;
/// VEO3 角色定义响应结构
#[derive(Debug, Serialize, Deserialize)]
@ -202,7 +202,6 @@ pub struct CreateActorFileResponse {
pub async fn veo3_actor_define_create_actor_file(
request: CreateActorFileRequest,
session_manager: State<'_, Veo3ActorDefineSessionManager>,
json_parser_state: State<'_, JsonParserState>,
) -> Result<CreateActorFileResponse, String> {
// 获取最近一次助手回复
let last_assistant_message = {
@ -233,16 +232,20 @@ pub async fn veo3_actor_define_create_actor_file(
};
// 使用容错JSON解析器提取JSON
let parse_request = ParseJsonRequest {
text: assistant_message,
config: None,
let mut parser = match TolerantJsonParser::new(None) {
Ok(p) => p,
Err(e) => {
return Ok(CreateActorFileResponse {
success: false,
file_path: None,
extracted_json: None,
error: Some(format!("创建JSON解析器失败: {}", e)),
});
}
};
let parse_response = match crate::presentation::commands::tolerant_json_commands::parse_json_tolerant(
parse_request,
json_parser_state,
).await {
Ok(response) => response,
let json_data = match parser.parse(&assistant_message) {
Ok((data, _statistics)) => data,
Err(e) => {
return Ok(CreateActorFileResponse {
success: false,
@ -253,17 +256,6 @@ pub async fn veo3_actor_define_create_actor_file(
}
};
if !parse_response.success || parse_response.data.is_none() {
return Ok(CreateActorFileResponse {
success: false,
file_path: None,
extracted_json: None,
error: Some(parse_response.error.unwrap_or_else(|| "JSON解析失败".to_string())),
});
}
let json_data = parse_response.data.unwrap();
// 生成文件名
let file_name = request.file_name.unwrap_or_else(|| {
let timestamp = chrono::Utc::now().format("%Y%m%d_%H%M%S");