This commit is contained in:
2026-04-24 12:21:33 +08:00
parent 3528980645
commit 70b5a7cf73
515 changed files with 14971 additions and 6831 deletions

View File

@@ -42,6 +42,7 @@ use std::convert::Infallible;
use crate::{
api_response::json_success_body,
auth::AuthenticatedAccessToken,
custom_world_agent_entities::generate_custom_world_agent_entities,
custom_world_agent_turn::{
CustomWorldAgentTurnRequest, build_failed_finalize_record_input,
build_finalize_record_input, run_custom_world_agent_turn,
@@ -916,7 +917,10 @@ pub async fn execute_custom_world_agent_action(
let owner_user_id = authenticated.claims().user_id().to_string();
let submitted_at_micros = current_utc_micros();
let payload_json = if action == "draft_foundation" {
let payload_json = if matches!(
action.as_str(),
"draft_foundation" | "generate_characters" | "generate_landmarks"
) {
let session = state
.spacetime_client()
.get_custom_world_agent_session(session_id.clone(), owner_user_id.clone())
@@ -924,15 +928,6 @@ pub async fn execute_custom_world_agent_action(
.map_err(|error| {
custom_world_error_response(&request_context, map_custom_world_client_error(error))
})?;
if session.progress_percent < 100 {
return Err(custom_world_error_response(
&request_context,
AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({
"provider": "custom-world-agent",
"message": "draft_foundation requires progressPercent >= 100",
})),
));
}
let llm_client = state.llm_client().ok_or_else(|| {
custom_world_error_response(
&request_context,
@@ -942,19 +937,29 @@ pub async fn execute_custom_world_agent_action(
})),
)
})?;
let draft_result = generate_custom_world_foundation_draft(llm_client, &session)
.await
.map_err(|message| {
custom_world_error_response(
if action == "draft_foundation" {
if session.progress_percent < 100 {
return Err(custom_world_error_response(
&request_context,
AppError::from_status(StatusCode::BAD_GATEWAY).with_details(json!({
AppError::from_status(StatusCode::BAD_REQUEST).with_details(json!({
"provider": "custom-world-agent",
"message": message,
"message": "draft_foundation requires progressPercent >= 100",
})),
)
})?;
build_draft_foundation_action_payload_json(&payload, &draft_result.draft_profile_json)
.map_err(|error| {
));
}
let draft_result = generate_custom_world_foundation_draft(llm_client, &session)
.await
.map_err(|message| {
custom_world_error_response(
&request_context,
AppError::from_status(StatusCode::BAD_GATEWAY).with_details(json!({
"provider": "custom-world-agent",
"message": message,
})),
)
})?;
build_draft_foundation_action_payload_json(&payload, &draft_result.draft_profile_json)
.map_err(|error| {
let (status, message) = match error {
DraftFoundationPayloadError::SerializePayload(message) => {
(StatusCode::BAD_REQUEST, message)
@@ -975,6 +980,21 @@ pub async fn execute_custom_world_agent_action(
})),
)
})?
} else {
let generation_result =
generate_custom_world_agent_entities(llm_client, &session, &payload)
.await
.map_err(|message| {
custom_world_error_response(
&request_context,
AppError::from_status(StatusCode::BAD_GATEWAY).with_details(json!({
"provider": "custom-world-agent",
"message": message,
})),
)
})?;
generation_result.payload_json
}
} else {
serde_json::to_string(&payload).map_err(|error| {
custom_world_error_response(