fix: sync rust api-server runtime and bindings
This commit is contained in:
@@ -155,7 +155,10 @@ use crate::module_bindings::{
|
||||
BigFishSessionGetInput as BindingBigFishSessionGetInput,
|
||||
BigFishSessionProcedureResult as BindingBigFishSessionProcedureResult,
|
||||
BigFishSessionSnapshot as BindingBigFishSessionSnapshot,
|
||||
BigFishVector2 as BindingBigFishVector2, CombatOutcome as BindingCombatOutcome,
|
||||
BigFishVector2 as BindingBigFishVector2,
|
||||
BigFishWorksListInput as BindingBigFishWorksListInput,
|
||||
BigFishWorksProcedureResult as BindingBigFishWorksProcedureResult,
|
||||
CombatOutcome as BindingCombatOutcome,
|
||||
CustomWorldAgentActionExecuteInput as BindingCustomWorldAgentActionExecuteInput,
|
||||
CustomWorldAgentActionExecuteResult as BindingCustomWorldAgentActionExecuteResult,
|
||||
CustomWorldAgentCardDetailGetInput as BindingCustomWorldAgentCardDetailGetInput,
|
||||
@@ -173,6 +176,7 @@ use crate::module_bindings::{
|
||||
CustomWorldDraftCardDetailSectionSnapshot as BindingCustomWorldDraftCardDetailSectionSnapshot,
|
||||
CustomWorldDraftCardDetailSnapshot as BindingCustomWorldDraftCardDetailSnapshot,
|
||||
CustomWorldDraftCardSnapshot as BindingCustomWorldDraftCardSnapshot,
|
||||
CustomWorldGalleryDetailByCodeInput as BindingCustomWorldGalleryDetailByCodeInput,
|
||||
CustomWorldGalleryDetailInput as BindingCustomWorldGalleryDetailInput,
|
||||
CustomWorldGalleryEntrySnapshot as BindingCustomWorldGalleryEntrySnapshot,
|
||||
CustomWorldGalleryListResult as BindingCustomWorldGalleryListResult,
|
||||
@@ -205,6 +209,7 @@ use crate::module_bindings::{
|
||||
NpcInteractionStatus as BindingNpcInteractionStatus,
|
||||
NpcRelationStance as BindingNpcRelationStance, NpcRelationState as BindingNpcRelationState,
|
||||
NpcStanceProfile as BindingNpcStanceProfile, NpcStateSnapshot as BindingNpcStateSnapshot,
|
||||
PuzzleAgentMessageFinalizeInput as BindingPuzzleAgentMessageFinalizeInput,
|
||||
PuzzleAgentMessageSubmitInput as BindingPuzzleAgentMessageSubmitInput,
|
||||
PuzzleAgentSessionCreateInput as BindingPuzzleAgentSessionCreateInput,
|
||||
PuzzleAgentSessionGetInput as BindingPuzzleAgentSessionGetInput,
|
||||
@@ -297,6 +302,7 @@ use crate::module_bindings::{
|
||||
execute_custom_world_agent_action_procedure::execute_custom_world_agent_action as _,
|
||||
fail_ai_task_and_return_procedure::fail_ai_task_and_return as _,
|
||||
finalize_custom_world_agent_message_turn_procedure::finalize_custom_world_agent_message_turn as _,
|
||||
finalize_puzzle_agent_message_turn_procedure::finalize_puzzle_agent_message_turn as _,
|
||||
generate_big_fish_asset_procedure::generate_big_fish_asset as _,
|
||||
get_battle_state_procedure::get_battle_state as _,
|
||||
get_big_fish_run_procedure::get_big_fish_run as _,
|
||||
@@ -304,6 +310,7 @@ use crate::module_bindings::{
|
||||
get_custom_world_agent_card_detail_procedure::get_custom_world_agent_card_detail as _,
|
||||
get_custom_world_agent_operation_procedure::get_custom_world_agent_operation as _,
|
||||
get_custom_world_agent_session_procedure::get_custom_world_agent_session as _,
|
||||
get_custom_world_gallery_detail_by_code_procedure::get_custom_world_gallery_detail_by_code as _,
|
||||
get_custom_world_gallery_detail_procedure::get_custom_world_gallery_detail as _,
|
||||
get_custom_world_library_detail_procedure::get_custom_world_library_detail as _,
|
||||
get_profile_dashboard_procedure::get_profile_dashboard as _,
|
||||
@@ -319,6 +326,7 @@ use crate::module_bindings::{
|
||||
list_custom_world_gallery_entries_procedure::list_custom_world_gallery_entries as _,
|
||||
list_custom_world_profiles_procedure::list_custom_world_profiles as _,
|
||||
list_custom_world_works_procedure::list_custom_world_works as _,
|
||||
list_big_fish_works_procedure::list_big_fish_works as _,
|
||||
list_platform_browse_history_procedure::list_platform_browse_history as _,
|
||||
list_profile_save_archives_procedure::list_profile_save_archives as _,
|
||||
list_profile_wallet_ledger_procedure::list_profile_wallet_ledger as _,
|
||||
@@ -739,12 +747,16 @@ impl SpacetimeClient {
|
||||
&self,
|
||||
profile_id: String,
|
||||
owner_user_id: String,
|
||||
public_work_code: Option<String>,
|
||||
author_public_user_code: String,
|
||||
author_display_name: String,
|
||||
published_at_micros: i64,
|
||||
) -> Result<CustomWorldLibraryMutationRecord, SpacetimeClientError> {
|
||||
let procedure_input = BindingCustomWorldProfilePublishInput {
|
||||
profile_id,
|
||||
owner_user_id,
|
||||
public_work_code,
|
||||
author_public_user_code,
|
||||
author_display_name,
|
||||
published_at_micros,
|
||||
};
|
||||
@@ -856,6 +868,25 @@ impl SpacetimeClient {
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_custom_world_gallery_detail_by_code(
|
||||
&self,
|
||||
public_work_code: String,
|
||||
) -> Result<CustomWorldLibraryMutationRecord, SpacetimeClientError> {
|
||||
let procedure_input = BindingCustomWorldGalleryDetailByCodeInput { public_work_code };
|
||||
|
||||
self.call_after_connect(move |connection, sender| {
|
||||
connection
|
||||
.procedures()
|
||||
.get_custom_world_gallery_detail_by_code_then(procedure_input, move |_, result| {
|
||||
let mapped = result
|
||||
.map_err(|error| SpacetimeClientError::Procedure(error.to_string()))
|
||||
.and_then(map_custom_world_library_mutation_result);
|
||||
send_once(&sender, mapped);
|
||||
});
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn publish_custom_world_world(
|
||||
&self,
|
||||
input: CustomWorldPublishWorldRecordInput,
|
||||
@@ -1086,6 +1117,35 @@ impl SpacetimeClient {
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn finalize_puzzle_agent_message(
|
||||
&self,
|
||||
input: PuzzleAgentMessageFinalizeRecordInput,
|
||||
) -> Result<PuzzleAgentSessionRecord, SpacetimeClientError> {
|
||||
let procedure_input = BindingPuzzleAgentMessageFinalizeInput {
|
||||
session_id: input.session_id,
|
||||
owner_user_id: input.owner_user_id,
|
||||
assistant_message_id: input.assistant_message_id,
|
||||
assistant_reply_text: input.assistant_reply_text,
|
||||
stage: parse_puzzle_agent_stage_record(input.stage.as_str())?,
|
||||
progress_percent: input.progress_percent,
|
||||
anchor_pack_json: input.anchor_pack_json,
|
||||
error_message: input.error_message,
|
||||
updated_at_micros: input.updated_at_micros,
|
||||
};
|
||||
|
||||
self.call_after_connect(move |connection, sender| {
|
||||
connection
|
||||
.procedures()
|
||||
.finalize_puzzle_agent_message_turn_then(procedure_input, move |_, result| {
|
||||
let mapped = result
|
||||
.map_err(|error| SpacetimeClientError::Procedure(error.to_string()))
|
||||
.and_then(map_puzzle_agent_session_procedure_result);
|
||||
send_once(&sender, mapped);
|
||||
});
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn compile_puzzle_agent_draft(
|
||||
&self,
|
||||
session_id: String,
|
||||
@@ -1467,6 +1527,26 @@ impl SpacetimeClient {
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn list_big_fish_works(
|
||||
&self,
|
||||
owner_user_id: String,
|
||||
) -> Result<Vec<BigFishWorkSummaryRecord>, SpacetimeClientError> {
|
||||
let procedure_input = BindingBigFishWorksListInput { owner_user_id };
|
||||
|
||||
self.call_after_connect(move |connection, sender| {
|
||||
connection.procedures().list_big_fish_works_then(
|
||||
procedure_input,
|
||||
move |_, result| {
|
||||
let mapped = result
|
||||
.map_err(|error| SpacetimeClientError::Procedure(error.to_string()))
|
||||
.and_then(map_big_fish_works_procedure_result);
|
||||
send_once(&sender, mapped);
|
||||
},
|
||||
);
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn submit_big_fish_message(
|
||||
&self,
|
||||
input: BigFishMessageSubmitRecordInput,
|
||||
@@ -1707,15 +1787,17 @@ impl SpacetimeClient {
|
||||
};
|
||||
|
||||
self.call_after_connect(move |connection, sender| {
|
||||
connection.procedures().finalize_custom_world_agent_message_turn_then(
|
||||
procedure_input,
|
||||
move |_, result| {
|
||||
let mapped = result
|
||||
.map_err(|error| SpacetimeClientError::Procedure(error.to_string()))
|
||||
.and_then(map_custom_world_agent_operation_procedure_result);
|
||||
send_once(&sender, mapped);
|
||||
},
|
||||
);
|
||||
connection
|
||||
.procedures()
|
||||
.finalize_custom_world_agent_message_turn_then(
|
||||
procedure_input,
|
||||
move |_, result| {
|
||||
let mapped = result
|
||||
.map_err(|error| SpacetimeClientError::Procedure(error.to_string()))
|
||||
.and_then(map_custom_world_agent_operation_procedure_result);
|
||||
send_once(&sender, mapped);
|
||||
},
|
||||
);
|
||||
})
|
||||
.await
|
||||
}
|
||||
@@ -2764,6 +2846,8 @@ fn map_custom_world_profile_upsert_input(
|
||||
BindingCustomWorldProfileUpsertInput {
|
||||
profile_id: input.profile_id,
|
||||
owner_user_id: input.owner_user_id,
|
||||
public_work_code: input.public_work_code,
|
||||
author_public_user_code: input.author_public_user_code,
|
||||
source_agent_session_id: input.source_agent_session_id,
|
||||
world_name: input.world_name,
|
||||
subtitle: input.subtitle,
|
||||
@@ -2785,6 +2869,8 @@ fn map_custom_world_publish_world_input(
|
||||
session_id: input.session_id,
|
||||
profile_id: input.profile_id,
|
||||
owner_user_id: input.owner_user_id,
|
||||
public_work_code: input.public_work_code,
|
||||
author_public_user_code: input.author_public_user_code,
|
||||
draft_profile_json: input.draft_profile_json,
|
||||
legacy_result_profile_json: input.legacy_result_profile_json,
|
||||
setting_text: input.setting_text,
|
||||
@@ -3480,6 +3566,26 @@ fn map_big_fish_session_procedure_result(
|
||||
Ok(map_big_fish_session_snapshot(session))
|
||||
}
|
||||
|
||||
fn map_big_fish_works_procedure_result(
|
||||
result: BindingBigFishWorksProcedureResult,
|
||||
) -> Result<Vec<BigFishWorkSummaryRecord>, SpacetimeClientError> {
|
||||
if !result.ok {
|
||||
return Err(SpacetimeClientError::Procedure(
|
||||
result
|
||||
.error_message
|
||||
.unwrap_or_else(|| "SpacetimeDB procedure 返回未知错误".to_string()),
|
||||
));
|
||||
}
|
||||
|
||||
let items_json = result.items_json.ok_or_else(|| {
|
||||
SpacetimeClientError::Procedure(
|
||||
"SpacetimeDB procedure 未返回 big fish works 快照".to_string(),
|
||||
)
|
||||
})?;
|
||||
serde_json::from_str::<Vec<BigFishWorkSummaryRecord>>(&items_json)
|
||||
.map_err(|error| SpacetimeClientError::Runtime(format!("big fish works items_json 非法: {error}")))
|
||||
}
|
||||
|
||||
fn map_big_fish_run_procedure_result(
|
||||
result: BindingBigFishRunProcedureResult,
|
||||
) -> Result<BigFishRuntimeRecord, SpacetimeClientError> {
|
||||
@@ -3817,6 +3923,8 @@ fn map_custom_world_library_entry_from_profile_snapshot(
|
||||
Ok(CustomWorldLibraryEntryRecord {
|
||||
owner_user_id: snapshot.owner_user_id,
|
||||
profile_id: snapshot.profile_id,
|
||||
public_work_code: snapshot.public_work_code,
|
||||
author_public_user_code: snapshot.author_public_user_code,
|
||||
profile,
|
||||
visibility: map_custom_world_publication_status(snapshot.publication_status).to_string(),
|
||||
published_at: snapshot.published_at_micros.map(format_timestamp_micros),
|
||||
@@ -3841,6 +3949,8 @@ fn map_custom_world_gallery_entry_snapshot(
|
||||
Ok(CustomWorldGalleryEntryRecord {
|
||||
owner_user_id: snapshot.owner_user_id,
|
||||
profile_id: snapshot.profile_id,
|
||||
public_work_code: snapshot.public_work_code,
|
||||
author_public_user_code: snapshot.author_public_user_code,
|
||||
visibility: "published".to_string(),
|
||||
published_at: Some(format_timestamp_micros(snapshot.published_at_micros)),
|
||||
updated_at: format_timestamp_micros(snapshot.updated_at_micros),
|
||||
@@ -3990,6 +4100,7 @@ fn map_custom_world_agent_session_snapshot(
|
||||
|
||||
Ok(CustomWorldAgentSessionRecord {
|
||||
session_id: snapshot.session_id,
|
||||
seed_text: snapshot.seed_text,
|
||||
current_turn: snapshot.current_turn,
|
||||
anchor_content,
|
||||
progress_percent: snapshot.progress_percent,
|
||||
@@ -5021,6 +5132,21 @@ fn map_rpg_agent_stage(value: crate::module_bindings::RpgAgentStage) -> String {
|
||||
.to_string()
|
||||
}
|
||||
|
||||
fn parse_puzzle_agent_stage_record(
|
||||
value: &str,
|
||||
) -> Result<crate::module_bindings::PuzzleAgentStage, SpacetimeClientError> {
|
||||
match value.trim() {
|
||||
"collecting_anchors" => Ok(crate::module_bindings::PuzzleAgentStage::CollectingAnchors),
|
||||
"draft_ready" => Ok(crate::module_bindings::PuzzleAgentStage::DraftReady),
|
||||
"image_refining" => Ok(crate::module_bindings::PuzzleAgentStage::ImageRefining),
|
||||
"ready_to_publish" => Ok(crate::module_bindings::PuzzleAgentStage::ReadyToPublish),
|
||||
"published" => Ok(crate::module_bindings::PuzzleAgentStage::Published),
|
||||
other => Err(SpacetimeClientError::Runtime(format!(
|
||||
"未知 puzzle agent stage: {other}"
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_rpg_agent_stage_record(
|
||||
value: &str,
|
||||
) -> Result<crate::module_bindings::RpgAgentStage, SpacetimeClientError> {
|
||||
@@ -5680,6 +5806,8 @@ pub struct ResolveCombatActionRecord {
|
||||
pub struct CustomWorldLibraryEntryRecord {
|
||||
pub owner_user_id: String,
|
||||
pub profile_id: String,
|
||||
pub public_work_code: Option<String>,
|
||||
pub author_public_user_code: Option<String>,
|
||||
pub profile: serde_json::Value,
|
||||
pub visibility: String,
|
||||
pub published_at: Option<String>,
|
||||
@@ -5698,6 +5826,8 @@ pub struct CustomWorldLibraryEntryRecord {
|
||||
pub struct CustomWorldGalleryEntryRecord {
|
||||
pub owner_user_id: String,
|
||||
pub profile_id: String,
|
||||
pub public_work_code: String,
|
||||
pub author_public_user_code: String,
|
||||
pub visibility: String,
|
||||
pub published_at: Option<String>,
|
||||
pub updated_at: String,
|
||||
@@ -5863,6 +5993,7 @@ pub struct CustomWorldDraftCardDetailRecord {
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct CustomWorldAgentSessionRecord {
|
||||
pub session_id: String,
|
||||
pub seed_text: String,
|
||||
pub current_turn: u32,
|
||||
pub anchor_content: serde_json::Value,
|
||||
pub progress_percent: u32,
|
||||
@@ -5892,6 +6023,8 @@ pub struct CustomWorldAgentSessionRecord {
|
||||
pub struct CustomWorldProfileUpsertRecordInput {
|
||||
pub profile_id: String,
|
||||
pub owner_user_id: String,
|
||||
pub public_work_code: Option<String>,
|
||||
pub author_public_user_code: Option<String>,
|
||||
pub source_agent_session_id: Option<String>,
|
||||
pub world_name: String,
|
||||
pub subtitle: String,
|
||||
@@ -5910,6 +6043,8 @@ pub struct CustomWorldPublishWorldRecordInput {
|
||||
pub session_id: String,
|
||||
pub profile_id: String,
|
||||
pub owner_user_id: String,
|
||||
pub public_work_code: Option<String>,
|
||||
pub author_public_user_code: String,
|
||||
pub draft_profile_json: String,
|
||||
pub legacy_result_profile_json: Option<String>,
|
||||
pub setting_text: String,
|
||||
@@ -6011,6 +6146,19 @@ pub struct PuzzleAgentMessageSubmitRecordInput {
|
||||
pub submitted_at_micros: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct PuzzleAgentMessageFinalizeRecordInput {
|
||||
pub session_id: String,
|
||||
pub owner_user_id: String,
|
||||
pub assistant_message_id: Option<String>,
|
||||
pub assistant_reply_text: Option<String>,
|
||||
pub stage: String,
|
||||
pub progress_percent: u32,
|
||||
pub anchor_pack_json: String,
|
||||
pub error_message: Option<String>,
|
||||
pub updated_at_micros: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct PuzzleGeneratedImagesSaveRecordInput {
|
||||
pub session_id: String,
|
||||
@@ -6438,6 +6586,23 @@ pub struct BigFishSessionRecord {
|
||||
pub updated_at: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct BigFishWorkSummaryRecord {
|
||||
pub work_id: String,
|
||||
pub source_session_id: String,
|
||||
pub title: String,
|
||||
pub subtitle: String,
|
||||
pub summary: String,
|
||||
pub cover_image_src: Option<String>,
|
||||
pub status: String,
|
||||
pub updated_at_micros: i64,
|
||||
pub publish_ready: bool,
|
||||
pub level_count: u32,
|
||||
pub level_main_image_ready_count: u32,
|
||||
pub level_motion_ready_count: u32,
|
||||
pub background_ready: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct BigFishVector2Record {
|
||||
pub x: f32,
|
||||
|
||||
Reference in New Issue
Block a user