94 lines
3.1 KiB
Rust
94 lines
3.1 KiB
Rust
use super::*;
|
|
|
|
impl SpacetimeClient {
|
|
pub async fn begin_story_session(
|
|
&self,
|
|
story_session_id: String,
|
|
runtime_session_id: String,
|
|
actor_user_id: String,
|
|
world_profile_id: String,
|
|
initial_prompt: String,
|
|
opening_summary: Option<String>,
|
|
created_at_micros: i64,
|
|
) -> Result<StorySessionResultRecord, SpacetimeClientError> {
|
|
let procedure_input = build_story_session_input(
|
|
story_session_id,
|
|
runtime_session_id,
|
|
actor_user_id,
|
|
world_profile_id,
|
|
initial_prompt,
|
|
opening_summary,
|
|
created_at_micros,
|
|
)
|
|
.map_err(SpacetimeClientError::validation_failed)?
|
|
.into();
|
|
|
|
self.call_after_connect(move |connection, sender| {
|
|
connection.procedures().begin_story_session_and_return_then(
|
|
procedure_input,
|
|
move |_, result| {
|
|
let mapped = result
|
|
.map_err(SpacetimeClientError::from_sdk_error)
|
|
.and_then(map_story_session_procedure_result);
|
|
send_once(&sender, mapped);
|
|
},
|
|
);
|
|
})
|
|
.await
|
|
}
|
|
|
|
pub async fn continue_story(
|
|
&self,
|
|
story_session_id: String,
|
|
event_id: String,
|
|
narrative_text: String,
|
|
choice_function_id: Option<String>,
|
|
updated_at_micros: i64,
|
|
) -> Result<StorySessionResultRecord, SpacetimeClientError> {
|
|
let procedure_input = build_story_continue_input(
|
|
story_session_id,
|
|
event_id,
|
|
narrative_text,
|
|
choice_function_id,
|
|
updated_at_micros,
|
|
)
|
|
.map_err(SpacetimeClientError::validation_failed)?
|
|
.into();
|
|
|
|
self.call_after_connect(move |connection, sender| {
|
|
connection.procedures().continue_story_and_return_then(
|
|
procedure_input,
|
|
move |_, result| {
|
|
let mapped = result
|
|
.map_err(SpacetimeClientError::from_sdk_error)
|
|
.and_then(map_story_session_procedure_result);
|
|
send_once(&sender, mapped);
|
|
},
|
|
);
|
|
})
|
|
.await
|
|
}
|
|
|
|
pub async fn get_story_session_state(
|
|
&self,
|
|
story_session_id: String,
|
|
) -> Result<StorySessionStateRecord, SpacetimeClientError> {
|
|
let procedure_input = build_story_session_state_input(story_session_id)
|
|
.map_err(SpacetimeClientError::validation_failed)?
|
|
.into();
|
|
|
|
self.call_after_connect(move |connection, sender| {
|
|
connection.procedures().get_story_session_state_then(
|
|
procedure_input,
|
|
move |_, result| {
|
|
let mapped = result
|
|
.map_err(SpacetimeClientError::from_sdk_error)
|
|
.and_then(map_story_session_state_procedure_result);
|
|
send_once(&sender, mapped);
|
|
},
|
|
);
|
|
})
|
|
.await
|
|
}
|
|
}
|