feat: add puzzle and big fish draft generation progress
This commit is contained in:
@@ -435,14 +435,17 @@ pub async fn execute_puzzle_agent_action(
|
||||
|
||||
let (operation_type, phase_label, phase_detail, session) = match payload.action.trim() {
|
||||
"compile_puzzle_draft" => {
|
||||
let session = state
|
||||
.spacetime_client()
|
||||
.compile_puzzle_agent_draft(session_id, owner_user_id, now)
|
||||
.await;
|
||||
let session = compile_puzzle_draft_with_initial_cover(
|
||||
&state,
|
||||
session_id.clone(),
|
||||
owner_user_id.clone(),
|
||||
now,
|
||||
)
|
||||
.await;
|
||||
(
|
||||
"compile_puzzle_draft",
|
||||
"结果页草稿",
|
||||
"已根据当前锚点编译结果页草稿。",
|
||||
"完整拼图草稿",
|
||||
"已编译草稿、生成候选图并应用正式图片。",
|
||||
session,
|
||||
)
|
||||
}
|
||||
@@ -572,6 +575,18 @@ pub async fn execute_puzzle_agent_action(
|
||||
)
|
||||
})?;
|
||||
|
||||
let session = state
|
||||
.spacetime_client()
|
||||
.get_puzzle_agent_session(session_id.clone(), owner_user_id.clone())
|
||||
.await
|
||||
.map_err(|error| {
|
||||
puzzle_error_response(
|
||||
&request_context,
|
||||
PUZZLE_AGENT_API_BASE_PROVIDER,
|
||||
map_puzzle_client_error(error),
|
||||
)
|
||||
})?;
|
||||
|
||||
return Ok(json_success_body(
|
||||
Some(&request_context),
|
||||
PuzzleAgentActionResponse {
|
||||
@@ -584,6 +599,7 @@ pub async fn execute_puzzle_agent_action(
|
||||
progress: 100,
|
||||
error: None,
|
||||
},
|
||||
session: map_puzzle_agent_session_response(session),
|
||||
},
|
||||
));
|
||||
}
|
||||
@@ -616,6 +632,7 @@ pub async fn execute_puzzle_agent_action(
|
||||
progress: 100,
|
||||
error: None,
|
||||
},
|
||||
session: map_puzzle_agent_session_response(session),
|
||||
},
|
||||
))
|
||||
}
|
||||
@@ -1336,6 +1353,64 @@ fn build_stable_puzzle_work_ids(session_id: &str) -> (String, String) {
|
||||
)
|
||||
}
|
||||
|
||||
async fn compile_puzzle_draft_with_initial_cover(
|
||||
state: &AppState,
|
||||
session_id: String,
|
||||
owner_user_id: String,
|
||||
now: i64,
|
||||
) -> Result<PuzzleAgentSessionRecord, SpacetimeClientError> {
|
||||
let compiled_session = state
|
||||
.spacetime_client()
|
||||
.compile_puzzle_agent_draft(session_id.clone(), owner_user_id.clone(), now)
|
||||
.await?;
|
||||
let draft = compiled_session
|
||||
.draft
|
||||
.clone()
|
||||
.ok_or_else(|| SpacetimeClientError::Runtime("拼图结果页草稿尚未生成".to_string()))?;
|
||||
// 点击生成草稿时一次性完成首图生成与正式图选定,前端只展示进度,不再承担业务编排。
|
||||
let candidates = generate_puzzle_image_candidates(
|
||||
state,
|
||||
owner_user_id.as_str(),
|
||||
&compiled_session.session_id,
|
||||
&draft.level_name,
|
||||
&draft.summary,
|
||||
2,
|
||||
)
|
||||
.await
|
||||
.map_err(SpacetimeClientError::Runtime)?;
|
||||
let selected_candidate_id = candidates
|
||||
.iter()
|
||||
.find(|candidate| candidate.selected)
|
||||
.or_else(|| candidates.first())
|
||||
.map(|candidate| candidate.candidate_id.clone())
|
||||
.ok_or_else(|| SpacetimeClientError::Runtime("拼图候选图生成结果为空".to_string()))?;
|
||||
let candidates_json = serde_json::to_string(
|
||||
&candidates
|
||||
.iter()
|
||||
.map(to_puzzle_generated_image_candidate)
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
.map_err(|error| SpacetimeClientError::Runtime(format!("拼图候选图序列化失败:{error}")))?;
|
||||
state
|
||||
.spacetime_client()
|
||||
.save_puzzle_generated_images(PuzzleGeneratedImagesSaveRecordInput {
|
||||
session_id: compiled_session.session_id.clone(),
|
||||
owner_user_id: owner_user_id.clone(),
|
||||
candidates_json,
|
||||
saved_at_micros: current_utc_micros(),
|
||||
})
|
||||
.await?;
|
||||
state
|
||||
.spacetime_client()
|
||||
.select_puzzle_cover_image(PuzzleSelectCoverImageRecordInput {
|
||||
session_id,
|
||||
owner_user_id,
|
||||
candidate_id: selected_candidate_id,
|
||||
selected_at_micros: current_utc_micros(),
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
fn ensure_non_empty(
|
||||
request_context: &RequestContext,
|
||||
provider: &str,
|
||||
|
||||
Reference in New Issue
Block a user