428 lines
16 KiB
Rust
428 lines
16 KiB
Rust
use super::*;
|
||
use crate::mapper::*;
|
||
use crate::module_bindings::delete_big_fish_work_procedure::delete_big_fish_work;
|
||
use crate::module_bindings::get_big_fish_run_procedure::get_big_fish_run;
|
||
use crate::module_bindings::record_big_fish_like_procedure::record_big_fish_like;
|
||
use crate::module_bindings::record_big_fish_play_procedure::record_big_fish_play;
|
||
use crate::module_bindings::remix_big_fish_work_procedure::remix_big_fish_work;
|
||
use crate::module_bindings::start_big_fish_run_procedure::start_big_fish_run;
|
||
use crate::module_bindings::submit_big_fish_input_procedure::submit_big_fish_input;
|
||
use module_big_fish::PUBLIC_BIG_FISH_GALLERY_OWNER_USER_ID;
|
||
|
||
impl SpacetimeClient {
|
||
pub async fn create_big_fish_session(
|
||
&self,
|
||
input: BigFishSessionCreateRecordInput,
|
||
) -> Result<BigFishSessionRecord, SpacetimeClientError> {
|
||
let procedure_input = BigFishSessionCreateInput {
|
||
session_id: input.session_id,
|
||
owner_user_id: input.owner_user_id,
|
||
seed_text: input.seed_text,
|
||
welcome_message_id: input.welcome_message_id,
|
||
welcome_message_text: input.welcome_message_text,
|
||
created_at_micros: input.created_at_micros,
|
||
};
|
||
|
||
self.call_after_connect("create_big_fish_session", move |connection, sender| {
|
||
connection.procedures().create_big_fish_session_then(
|
||
procedure_input,
|
||
move |_, result| {
|
||
let mapped = result
|
||
.map_err(SpacetimeClientError::from_sdk_error)
|
||
.and_then(map_big_fish_session_procedure_result);
|
||
send_once(&sender, mapped);
|
||
},
|
||
);
|
||
})
|
||
.await
|
||
}
|
||
|
||
pub async fn get_big_fish_session(
|
||
&self,
|
||
session_id: String,
|
||
owner_user_id: String,
|
||
) -> Result<BigFishSessionRecord, SpacetimeClientError> {
|
||
let procedure_input = BigFishSessionGetInput {
|
||
session_id,
|
||
owner_user_id,
|
||
};
|
||
|
||
self.call_after_connect("get_big_fish_session", move |connection, sender| {
|
||
connection
|
||
.procedures()
|
||
.get_big_fish_session_then(procedure_input, move |_, result| {
|
||
let mapped = result
|
||
.map_err(SpacetimeClientError::from_sdk_error)
|
||
.and_then(map_big_fish_session_procedure_result);
|
||
send_once(&sender, mapped);
|
||
});
|
||
})
|
||
.await
|
||
}
|
||
|
||
pub async fn list_big_fish_works(
|
||
&self,
|
||
owner_user_id: String,
|
||
) -> Result<Vec<BigFishWorkSummaryRecord>, SpacetimeClientError> {
|
||
let procedure_input = BigFishWorksListInput {
|
||
owner_user_id,
|
||
published_only: false,
|
||
};
|
||
|
||
self.list_big_fish_works_with_input(procedure_input).await
|
||
}
|
||
|
||
pub async fn list_big_fish_gallery(
|
||
&self,
|
||
) -> Result<Vec<BigFishWorkSummaryRecord>, SpacetimeClientError> {
|
||
self.list_big_fish_works_with_input(BigFishWorksListInput {
|
||
// 中文注释:公开广场读取只依赖 published_only,但旧部署模块会先校验 owner_user_id 非空。
|
||
owner_user_id: PUBLIC_BIG_FISH_GALLERY_OWNER_USER_ID.to_string(),
|
||
published_only: true,
|
||
})
|
||
.await
|
||
}
|
||
|
||
async fn list_big_fish_works_with_input(
|
||
&self,
|
||
procedure_input: BigFishWorksListInput,
|
||
) -> Result<Vec<BigFishWorkSummaryRecord>, SpacetimeClientError> {
|
||
self.call_after_connect("list_big_fish_works", move |connection, sender| {
|
||
let fallback_owner_user_id = if procedure_input.published_only {
|
||
None
|
||
} else {
|
||
Some(procedure_input.owner_user_id.clone())
|
||
};
|
||
connection
|
||
.procedures()
|
||
.list_big_fish_works_then(procedure_input, move |_, result| {
|
||
let mapped = result
|
||
.map_err(SpacetimeClientError::from_sdk_error)
|
||
.and_then(|result| {
|
||
map_big_fish_works_procedure_result(
|
||
result,
|
||
fallback_owner_user_id.as_deref(),
|
||
)
|
||
});
|
||
send_once(&sender, mapped);
|
||
});
|
||
})
|
||
.await
|
||
}
|
||
|
||
pub async fn delete_big_fish_work(
|
||
&self,
|
||
session_id: String,
|
||
owner_user_id: String,
|
||
) -> Result<Vec<BigFishWorkSummaryRecord>, SpacetimeClientError> {
|
||
let procedure_input = BigFishWorkDeleteInput {
|
||
session_id,
|
||
owner_user_id,
|
||
};
|
||
|
||
self.call_after_connect("delete_big_fish_work", move |connection, sender| {
|
||
let fallback_owner_user_id = Some(procedure_input.owner_user_id.clone());
|
||
connection
|
||
.procedures()
|
||
.delete_big_fish_work_then(procedure_input, move |_, result| {
|
||
let mapped = result
|
||
.map_err(SpacetimeClientError::from_sdk_error)
|
||
.and_then(|result| {
|
||
map_big_fish_works_procedure_result(
|
||
result,
|
||
fallback_owner_user_id.as_deref(),
|
||
)
|
||
});
|
||
send_once(&sender, mapped);
|
||
});
|
||
})
|
||
.await
|
||
}
|
||
|
||
pub async fn submit_big_fish_message(
|
||
&self,
|
||
input: BigFishMessageSubmitRecordInput,
|
||
) -> Result<BigFishSessionRecord, SpacetimeClientError> {
|
||
let procedure_input = BigFishMessageSubmitInput {
|
||
session_id: input.session_id,
|
||
owner_user_id: input.owner_user_id,
|
||
user_message_id: input.user_message_id,
|
||
user_message_text: input.user_message_text,
|
||
assistant_message_id: input.assistant_message_id,
|
||
submitted_at_micros: input.submitted_at_micros,
|
||
};
|
||
|
||
self.call_after_connect("submit_big_fish_message", move |connection, sender| {
|
||
connection.procedures().submit_big_fish_message_then(
|
||
procedure_input,
|
||
move |_, result| {
|
||
let mapped = result
|
||
.map_err(SpacetimeClientError::from_sdk_error)
|
||
.and_then(map_big_fish_session_procedure_result);
|
||
send_once(&sender, mapped);
|
||
},
|
||
);
|
||
})
|
||
.await
|
||
}
|
||
|
||
pub async fn finalize_big_fish_agent_message(
|
||
&self,
|
||
input: BigFishMessageFinalizeRecordInput,
|
||
) -> Result<BigFishSessionRecord, SpacetimeClientError> {
|
||
let procedure_input = BigFishMessageFinalizeInput {
|
||
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_big_fish_creation_stage(&input.stage)?,
|
||
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(
|
||
"finalize_big_fish_agent_message_turn",
|
||
move |connection, sender| {
|
||
connection
|
||
.procedures()
|
||
.finalize_big_fish_agent_message_turn_then(
|
||
procedure_input,
|
||
move |_, result| {
|
||
let mapped = result
|
||
.map_err(SpacetimeClientError::from_sdk_error)
|
||
.and_then(map_big_fish_session_procedure_result);
|
||
send_once(&sender, mapped);
|
||
},
|
||
);
|
||
},
|
||
)
|
||
.await
|
||
}
|
||
|
||
pub async fn compile_big_fish_draft(
|
||
&self,
|
||
input: BigFishDraftCompileRecordInput,
|
||
) -> Result<BigFishSessionRecord, SpacetimeClientError> {
|
||
let procedure_input = BigFishDraftCompileInput {
|
||
session_id: input.session_id,
|
||
owner_user_id: input.owner_user_id,
|
||
draft_json: input.draft_json,
|
||
compiled_at_micros: input.compiled_at_micros,
|
||
};
|
||
|
||
self.call_after_connect("compile_big_fish_draft", move |connection, sender| {
|
||
connection.procedures().compile_big_fish_draft_then(
|
||
procedure_input,
|
||
move |_, result| {
|
||
let mapped = result
|
||
.map_err(SpacetimeClientError::from_sdk_error)
|
||
.and_then(map_big_fish_session_procedure_result);
|
||
send_once(&sender, mapped);
|
||
},
|
||
);
|
||
})
|
||
.await
|
||
}
|
||
|
||
pub async fn generate_big_fish_asset(
|
||
&self,
|
||
input: BigFishAssetGenerateRecordInput,
|
||
) -> Result<BigFishSessionRecord, SpacetimeClientError> {
|
||
let procedure_input = BigFishAssetGenerateInput {
|
||
session_id: input.session_id,
|
||
owner_user_id: input.owner_user_id,
|
||
asset_kind: input.asset_kind.as_str().try_into()?,
|
||
level: input.level,
|
||
motion_key: input.motion_key,
|
||
asset_url: input.asset_url,
|
||
generated_at_micros: input.generated_at_micros,
|
||
};
|
||
|
||
self.call_after_connect("generate_big_fish_asset", move |connection, sender| {
|
||
connection.procedures().generate_big_fish_asset_then(
|
||
procedure_input,
|
||
move |_, result| {
|
||
let mapped = result
|
||
.map_err(SpacetimeClientError::from_sdk_error)
|
||
.and_then(map_big_fish_session_procedure_result);
|
||
send_once(&sender, mapped);
|
||
},
|
||
);
|
||
})
|
||
.await
|
||
}
|
||
|
||
pub async fn publish_big_fish_game(
|
||
&self,
|
||
session_id: String,
|
||
owner_user_id: String,
|
||
published_at_micros: i64,
|
||
) -> Result<BigFishSessionRecord, SpacetimeClientError> {
|
||
let procedure_input = BigFishPublishInput {
|
||
session_id,
|
||
owner_user_id,
|
||
published_at_micros,
|
||
};
|
||
|
||
self.call_after_connect("publish_big_fish_game", move |connection, sender| {
|
||
connection.procedures().publish_big_fish_game_then(
|
||
procedure_input,
|
||
move |_, result| {
|
||
let mapped = result
|
||
.map_err(SpacetimeClientError::from_sdk_error)
|
||
.and_then(map_big_fish_session_procedure_result);
|
||
send_once(&sender, mapped);
|
||
},
|
||
);
|
||
})
|
||
.await
|
||
}
|
||
|
||
pub async fn record_big_fish_play(
|
||
&self,
|
||
input: BigFishPlayReportRecordInput,
|
||
) -> Result<Vec<BigFishWorkSummaryRecord>, SpacetimeClientError> {
|
||
let procedure_input = BigFishPlayRecordInput {
|
||
session_id: input.session_id,
|
||
user_id: input.user_id,
|
||
elapsed_ms: input.elapsed_ms,
|
||
played_at_micros: input.reported_at_micros,
|
||
};
|
||
|
||
self.call_after_connect("record_big_fish_play", move |connection, sender| {
|
||
connection
|
||
.procedures()
|
||
.record_big_fish_play_then(procedure_input, move |_, result| {
|
||
let mapped = result
|
||
.map_err(SpacetimeClientError::from_sdk_error)
|
||
.and_then(|result| map_big_fish_works_procedure_result(result, None));
|
||
send_once(&sender, mapped);
|
||
});
|
||
})
|
||
.await
|
||
}
|
||
|
||
pub async fn start_big_fish_run(
|
||
&self,
|
||
input: BigFishRunStartRecordInput,
|
||
) -> Result<BigFishRuntimeRunRecord, SpacetimeClientError> {
|
||
let procedure_input = BigFishRunStartInput {
|
||
run_id: input.run_id,
|
||
session_id: input.session_id,
|
||
owner_user_id: input.owner_user_id,
|
||
started_at_micros: input.started_at_micros,
|
||
};
|
||
|
||
self.call_after_connect("start_big_fish_run", move |connection, sender| {
|
||
connection
|
||
.procedures()
|
||
.start_big_fish_run_then(procedure_input, move |_, result| {
|
||
let mapped = result
|
||
.map_err(SpacetimeClientError::from_sdk_error)
|
||
.and_then(map_big_fish_run_procedure_result);
|
||
send_once(&sender, mapped);
|
||
});
|
||
})
|
||
.await
|
||
}
|
||
|
||
pub async fn record_big_fish_like(
|
||
&self,
|
||
input: BigFishLikeReportRecordInput,
|
||
) -> Result<Vec<BigFishWorkSummaryRecord>, SpacetimeClientError> {
|
||
let procedure_input = BigFishWorkLikeRecordInput {
|
||
session_id: input.session_id,
|
||
user_id: input.user_id,
|
||
liked_at_micros: input.liked_at_micros,
|
||
};
|
||
|
||
self.call_after_connect("record_big_fish_like", move |connection, sender| {
|
||
connection
|
||
.procedures()
|
||
.record_big_fish_like_then(procedure_input, move |_, result| {
|
||
let mapped = result
|
||
.map_err(|error| SpacetimeClientError::Procedure(error.to_string()))
|
||
.and_then(|result| map_big_fish_works_procedure_result(result, None));
|
||
send_once(&sender, mapped);
|
||
});
|
||
})
|
||
.await
|
||
}
|
||
|
||
pub async fn get_big_fish_run(
|
||
&self,
|
||
run_id: String,
|
||
owner_user_id: String,
|
||
) -> Result<BigFishRuntimeRunRecord, SpacetimeClientError> {
|
||
let procedure_input = BigFishRunGetInput {
|
||
run_id,
|
||
owner_user_id,
|
||
};
|
||
|
||
self.call_after_connect("get_big_fish_run", move |connection, sender| {
|
||
connection
|
||
.procedures()
|
||
.get_big_fish_run_then(procedure_input, move |_, result| {
|
||
let mapped = result
|
||
.map_err(SpacetimeClientError::from_sdk_error)
|
||
.and_then(map_big_fish_run_procedure_result);
|
||
send_once(&sender, mapped);
|
||
});
|
||
})
|
||
.await
|
||
}
|
||
|
||
pub async fn remix_big_fish_work(
|
||
&self,
|
||
input: BigFishWorkRemixRecordInput,
|
||
) -> Result<BigFishSessionRecord, SpacetimeClientError> {
|
||
let procedure_input = BigFishWorkRemixInput {
|
||
source_session_id: input.source_session_id,
|
||
target_session_id: input.target_session_id,
|
||
target_owner_user_id: input.target_owner_user_id,
|
||
welcome_message_id: input.welcome_message_id,
|
||
remixed_at_micros: input.remixed_at_micros,
|
||
};
|
||
|
||
self.call_after_connect("remix_big_fish_work", move |connection, sender| {
|
||
connection
|
||
.procedures()
|
||
.remix_big_fish_work_then(procedure_input, move |_, result| {
|
||
let mapped = result
|
||
.map_err(|error| SpacetimeClientError::Procedure(error.to_string()))
|
||
.and_then(map_big_fish_session_procedure_result);
|
||
send_once(&sender, mapped);
|
||
});
|
||
})
|
||
.await
|
||
}
|
||
|
||
pub async fn submit_big_fish_input(
|
||
&self,
|
||
input: BigFishInputSubmitRecordInput,
|
||
) -> Result<BigFishRuntimeRunRecord, SpacetimeClientError> {
|
||
let procedure_input = BigFishInputSubmitInput {
|
||
run_id: input.run_id,
|
||
owner_user_id: input.owner_user_id,
|
||
x: input.x,
|
||
y: input.y,
|
||
submitted_at_micros: input.submitted_at_micros,
|
||
};
|
||
|
||
self.call_after_connect("submit_big_fish_input", move |connection, sender| {
|
||
connection.procedures().submit_big_fish_input_then(
|
||
procedure_input,
|
||
move |_, result| {
|
||
let mapped = result
|
||
.map_err(SpacetimeClientError::from_sdk_error)
|
||
.and_then(map_big_fish_run_procedure_result);
|
||
send_once(&sender, mapped);
|
||
},
|
||
);
|
||
})
|
||
.await
|
||
}
|
||
}
|