1
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
2026-04-28 20:52:08 +08:00
82 changed files with 3844 additions and 4125 deletions

View File

@@ -53,7 +53,7 @@ use crate::{
AiGenerationDraftContext, AiGenerationDraftSink, AiGenerationDraftWriter,
},
api_response::json_success_body,
asset_billing::{consume_asset_operation_points, refund_asset_operation_points},
asset_billing::execute_billable_asset_operation,
auth::AuthenticatedAccessToken,
character_visual_assets::generate_character_primary_visual_for_profile,
custom_world_agent_entities::generate_custom_world_agent_entities,
@@ -599,37 +599,31 @@ pub async fn publish_custom_world_library_profile(
));
}
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.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;
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),
));
}
};
let author_public_user_code =
resolve_author_public_user_code(&state, &authenticated, &request_context)?;
let author_display_name = resolve_author_display_name(&state, &authenticated);
let mutation = execute_billable_asset_operation(
&state,
&owner_user_id,
"custom_world_publish",
&profile_id,
async {
state
.spacetime_client()
.publish_custom_world_profile(
profile_id.clone(),
owner_user_id.clone(),
None,
author_public_user_code,
author_display_name,
current_utc_micros(),
)
.await
.map_err(map_custom_world_client_error)
},
)
.await
.map_err(|error| custom_world_error_response(&request_context, error))?;
Ok(json_success_body(
Some(&request_context),
@@ -1525,46 +1519,33 @@ pub async fn execute_custom_world_agent_action(
};
let should_bill_publish = action == "publish_world";
if should_bill_publish {
consume_asset_operation_points(
let operation_future = async {
state
.spacetime_client()
.execute_custom_world_agent_action(CustomWorldAgentActionExecuteRecordInput {
session_id: session_id.clone(),
owner_user_id: owner_user_id.clone(),
operation_id: build_prefixed_uuid_id("operation-"),
action: action.clone(),
payload_json: Some(payload_json),
submitted_at_micros,
})
.await
.map_err(map_custom_world_client_error)
};
let result = if should_bill_publish {
execute_billable_asset_operation(
&state,
&owner_user_id,
"custom_world_agent_publish",
&session_id,
operation_future,
)
.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(),
owner_user_id: owner_user_id.clone(),
operation_id: build_prefixed_uuid_id("operation-"),
action: action.clone(),
payload_json: Some(payload_json),
submitted_at_micros,
})
.await
{
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),
));
}
} else {
operation_future.await
};
let result = result.map_err(|error| custom_world_error_response(&request_context, error))?;
if matches!(
action.as_str(),