接入资产生成发布叙世币消耗
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
2026-04-27 23:32:34 +08:00
parent 1348b2e940
commit abe44948ee
11 changed files with 548 additions and 130 deletions

View File

@@ -51,6 +51,7 @@ use crate::{
AiGenerationDraftContext, AiGenerationDraftSink, AiGenerationDraftWriter,
},
api_response::json_success_body,
asset_billing::{consume_asset_operation_points, refund_asset_operation_points},
auth::AuthenticatedAccessToken,
character_visual_assets::generate_character_primary_visual_for_profile,
custom_world_agent_entities::generate_custom_world_agent_entities,
@@ -350,20 +351,37 @@ pub async fn publish_custom_world_library_profile(
));
}
let mutation = state
consume_asset_operation_points(&state, &owner_user_id, "custom_world_publish", &profile_id)
.await
.map_err(|error| custom_world_error_response(&request_context, error))?;
let mutation_result = state
.spacetime_client()
.publish_custom_world_profile(
profile_id,
owner_user_id,
profile_id.clone(),
owner_user_id.clone(),
None,
resolve_author_public_user_code(&state, &authenticated, &request_context)?,
resolve_author_display_name(&state, &authenticated),
current_utc_micros(),
)
.await
.map_err(|error| {
custom_world_error_response(&request_context, map_custom_world_client_error(error))
})?;
.await;
let mutation = match mutation_result {
Ok(mutation) => mutation,
Err(error) => {
refund_asset_operation_points(
&state,
&owner_user_id,
"custom_world_publish",
&profile_id,
)
.await;
return Err(custom_world_error_response(
&request_context,
map_custom_world_client_error(error),
));
}
};
Ok(json_success_body(
Some(&request_context),
@@ -1227,7 +1245,19 @@ pub async fn execute_custom_world_agent_action(
})?
};
let result = state
let should_bill_publish = action == "publish_world";
if should_bill_publish {
consume_asset_operation_points(
&state,
&owner_user_id,
"custom_world_agent_publish",
&session_id,
)
.await
.map_err(|error| custom_world_error_response(&request_context, error))?;
}
let result = match state
.spacetime_client()
.execute_custom_world_agent_action(CustomWorldAgentActionExecuteRecordInput {
session_id: session_id.clone(),
@@ -1238,9 +1268,24 @@ pub async fn execute_custom_world_agent_action(
submitted_at_micros,
})
.await
.map_err(|error| {
custom_world_error_response(&request_context, map_custom_world_client_error(error))
})?;
{
Ok(result) => result,
Err(error) => {
if should_bill_publish {
refund_asset_operation_points(
&state,
&owner_user_id,
"custom_world_agent_publish",
&session_id,
)
.await;
}
return Err(custom_world_error_response(
&request_context,
map_custom_world_client_error(error),
));
}
};
if matches!(
action.as_str(),