56 lines
1.9 KiB
Rust
56 lines
1.9 KiB
Rust
//! 剧情会话领域模型。
|
|
//!
|
|
//! 这里仅保存 RPG story session 聚合内的稳定状态和值对象;LLM 生成、HTTP 回包和
|
|
//! SpacetimeDB 写回都留给外层 adapter,不在领域模型里直接发生副作用。
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
use shared_kernel::build_prefixed_seed_id;
|
|
#[cfg(feature = "spacetime-types")]
|
|
use spacetimedb::SpacetimeType;
|
|
|
|
/// 剧情会话 ID 的稳定前缀,统一放在领域层,避免 adapter 重复拼接。
|
|
pub const STORY_SESSION_ID_PREFIX: &str = "storysess_";
|
|
/// 新建剧情会话快照的初始版本号。
|
|
pub const INITIAL_STORY_SESSION_VERSION: u32 = 1;
|
|
|
|
/// 剧情会话状态,用于判断后续 story command 是否还能继续推进。
|
|
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub enum StorySessionStatus {
|
|
Active,
|
|
Completed,
|
|
Archived,
|
|
}
|
|
|
|
impl StorySessionStatus {
|
|
pub fn as_str(&self) -> &'static str {
|
|
match self {
|
|
Self::Active => "active",
|
|
Self::Completed => "completed",
|
|
Self::Archived => "archived",
|
|
}
|
|
}
|
|
}
|
|
|
|
/// story session 的领域快照,SpacetimeDB row 与 HTTP DTO 都从它映射。
|
|
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct StorySessionSnapshot {
|
|
pub story_session_id: String,
|
|
pub runtime_session_id: String,
|
|
pub actor_user_id: String,
|
|
pub world_profile_id: String,
|
|
pub initial_prompt: String,
|
|
pub opening_summary: Option<String>,
|
|
pub latest_narrative_text: String,
|
|
pub latest_choice_function_id: Option<String>,
|
|
pub status: StorySessionStatus,
|
|
pub version: u32,
|
|
pub created_at_micros: i64,
|
|
pub updated_at_micros: i64,
|
|
}
|
|
|
|
pub fn generate_story_session_id(seed_micros: i64) -> String {
|
|
build_prefixed_seed_id(STORY_SESSION_ID_PREFIX, seed_micros)
|
|
}
|