//! 自定义世界领域模型。 //! //! 只保留 profile、Agent 会话、草稿卡、发布门禁和画廊投影的纯领域结构;LLM 推理、SSE 和 OSS 均留在外层 adapter。 use serde::{Deserialize, Serialize}; #[cfg(feature = "spacetime-types")] use spacetimedb::SpacetimeType; pub const MAX_PROGRESS_PERCENT: u32 = 100; #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum CustomWorldPublicationStatus { Draft, Published, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum CustomWorldThemeMode { Martial, Arcane, Machina, Tide, Rift, Mythic, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum CustomWorldGenerationMode { Fast, Full, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum CustomWorldSessionStatus { Clarifying, ReadyToGenerate, Generating, Completed, GenerationError, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum RpgAgentStage { CollectingIntent, Clarifying, FoundationReview, ObjectRefining, VisualRefining, LongTailReview, ReadyToPublish, Published, Error, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum RpgAgentMessageRole { User, Assistant, System, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum RpgAgentMessageKind { Chat, Clarification, Summary, Checkpoint, Warning, ActionResult, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum RpgAgentOperationType { ProcessMessage, DraftFoundation, UpdateDraftCard, SyncResultProfile, GenerateCharacters, GenerateLandmarks, DeleteCharacters, DeleteLandmarks, GenerateRoleAssets, SyncRoleAssets, GenerateSceneAssets, SyncSceneAssets, ExpandLongTail, PublishWorld, RevertCheckpoint, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum RpgAgentOperationStatus { Queued, Running, Completed, Failed, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum RpgAgentDraftCardKind { World, Camp, Faction, Character, Landmark, Thread, Chapter, SceneChapter, Carrier, SidequestSeed, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum RpgAgentDraftCardStatus { Suggested, Confirmed, Locked, Warning, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum CustomWorldRoleAssetStatus { Missing, VisualReady, AnimationsReady, Complete, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CustomWorldProfileSnapshot { pub profile_id: String, pub owner_user_id: String, pub public_work_code: Option, pub author_public_user_code: Option, pub source_agent_session_id: Option, pub publication_status: CustomWorldPublicationStatus, pub world_name: String, pub subtitle: String, pub summary_text: String, pub theme_mode: CustomWorldThemeMode, pub cover_image_src: Option, pub profile_payload_json: String, pub playable_npc_count: u32, pub landmark_count: u32, pub play_count: u32, pub remix_count: u32, pub like_count: u32, pub author_display_name: String, pub published_at_micros: Option, pub deleted_at_micros: Option, pub created_at_micros: i64, pub updated_at_micros: i64, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CustomWorldGalleryEntrySnapshot { pub profile_id: String, pub owner_user_id: String, pub public_work_code: String, pub author_public_user_code: String, pub author_display_name: String, pub world_name: String, pub subtitle: String, pub summary_text: String, pub cover_image_src: Option, pub theme_mode: CustomWorldThemeMode, pub playable_npc_count: u32, pub landmark_count: u32, pub play_count: u32, pub remix_count: u32, pub like_count: u32, pub recent_play_count_7d: u32, pub published_at_micros: i64, pub updated_at_micros: i64, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CustomWorldLibraryMutationResult { pub ok: bool, pub entry: Option, pub gallery_entry: Option, pub error_message: Option, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CustomWorldProfileListResult { pub ok: bool, pub entries: Vec, pub error_message: Option, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CustomWorldGalleryListResult { pub ok: bool, pub entries: Vec, pub error_message: Option, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CustomWorldPublishBlockerSnapshot { pub blocker_id: String, pub code: String, pub message: String, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CustomWorldPublishGateSnapshot { pub profile_id: String, pub blockers: Vec, pub blocker_count: u32, pub publish_ready: bool, pub can_enter_world: bool, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CustomWorldWorkSummarySnapshot { pub work_id: String, pub source_type: String, pub status: String, pub title: String, pub subtitle: String, pub summary: String, pub cover_image_src: Option, pub cover_render_mode: Option, pub cover_character_image_srcs_json: String, pub updated_at_micros: i64, pub published_at_micros: Option, pub stage: Option, pub stage_label: Option, pub playable_npc_count: u32, pub landmark_count: u32, pub role_visual_ready_count: Option, pub role_animation_ready_count: Option, pub role_asset_summary_label: Option, pub session_id: Option, pub profile_id: Option, pub can_resume: bool, pub can_enter_world: bool, pub blocker_count: u32, pub publish_ready: bool, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CustomWorldWorksListResult { pub ok: bool, pub items: Vec, pub error_message: Option, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CustomWorldAgentMessageSnapshot { pub message_id: String, pub session_id: String, pub role: RpgAgentMessageRole, pub kind: RpgAgentMessageKind, pub text: String, pub related_operation_id: Option, pub created_at_micros: i64, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CustomWorldAgentOperationSnapshot { pub operation_id: String, pub session_id: String, pub operation_type: RpgAgentOperationType, pub status: RpgAgentOperationStatus, pub phase_label: String, pub phase_detail: String, pub progress: u32, pub error_message: Option, pub created_at_micros: i64, pub updated_at_micros: i64, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CustomWorldDraftCardSnapshot { pub card_id: String, pub session_id: String, pub kind: RpgAgentDraftCardKind, pub status: RpgAgentDraftCardStatus, pub title: String, pub subtitle: String, pub summary: String, pub linked_ids_json: String, pub warning_count: u32, pub asset_status: Option, pub asset_status_label: Option, pub detail_payload_json: Option, pub created_at_micros: i64, pub updated_at_micros: i64, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CustomWorldDraftCardDetailSectionSnapshot { pub section_id: String, pub label: String, pub value: String, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CustomWorldDraftCardDetailSnapshot { pub card_id: String, pub kind: RpgAgentDraftCardKind, pub title: String, pub sections: Vec, pub linked_ids_json: String, pub locked: bool, pub editable: bool, pub editable_section_ids_json: String, pub warning_messages_json: String, pub asset_status: Option, pub asset_status_label: Option, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CustomWorldDraftCardDetailResult { pub ok: bool, pub card: Option, pub error_message: Option, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CustomWorldAgentSessionSnapshot { pub session_id: String, pub owner_user_id: String, pub seed_text: String, pub current_turn: u32, pub progress_percent: u32, pub stage: RpgAgentStage, pub focus_card_id: Option, pub anchor_content_json: String, pub creator_intent_json: Option, pub creator_intent_readiness_json: String, pub anchor_pack_json: Option, pub lock_state_json: Option, pub draft_profile_json: Option, pub last_assistant_reply: Option, pub publish_gate_json: Option, pub result_preview_json: Option, pub pending_clarifications_json: String, pub quality_findings_json: String, pub suggested_actions_json: String, pub recommended_replies_json: String, pub asset_coverage_json: String, pub checkpoints_json: String, pub supported_actions_json: String, pub messages: Vec, pub draft_cards: Vec, pub operations: Vec, pub created_at_micros: i64, pub updated_at_micros: i64, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CustomWorldAgentSessionProcedureResult { pub ok: bool, pub session: Option, pub error_message: Option, } impl CustomWorldPublicationStatus { pub fn as_str(&self) -> &'static str { match self { Self::Draft => "draft", Self::Published => "published", } } } impl CustomWorldThemeMode { pub fn as_str(&self) -> &'static str { match self { Self::Martial => "martial", Self::Arcane => "arcane", Self::Machina => "machina", Self::Tide => "tide", Self::Rift => "rift", Self::Mythic => "mythic", } } pub fn from_client_str(value: &str) -> Option { match value.trim().to_ascii_lowercase().as_str() { "martial" => Some(Self::Martial), "arcane" => Some(Self::Arcane), "machina" => Some(Self::Machina), "tide" => Some(Self::Tide), "rift" => Some(Self::Rift), "mythic" => Some(Self::Mythic), _ => None, } } } impl CustomWorldGenerationMode { pub fn as_str(&self) -> &'static str { match self { Self::Fast => "fast", Self::Full => "full", } } } impl CustomWorldSessionStatus { pub fn as_str(&self) -> &'static str { match self { Self::Clarifying => "clarifying", Self::ReadyToGenerate => "ready_to_generate", Self::Generating => "generating", Self::Completed => "completed", Self::GenerationError => "generation_error", } } } impl RpgAgentStage { pub fn as_str(&self) -> &'static str { match self { Self::CollectingIntent => "collecting_intent", Self::Clarifying => "clarifying", Self::FoundationReview => "foundation_review", Self::ObjectRefining => "object_refining", Self::VisualRefining => "visual_refining", Self::LongTailReview => "long_tail_review", Self::ReadyToPublish => "ready_to_publish", Self::Published => "published", Self::Error => "error", } } } impl RpgAgentMessageRole { pub fn as_str(&self) -> &'static str { match self { Self::User => "user", Self::Assistant => "assistant", Self::System => "system", } } } impl RpgAgentMessageKind { pub fn as_str(&self) -> &'static str { match self { Self::Chat => "chat", Self::Clarification => "clarification", Self::Summary => "summary", Self::Checkpoint => "checkpoint", Self::Warning => "warning", Self::ActionResult => "action_result", } } } impl RpgAgentOperationType { pub fn as_str(&self) -> &'static str { match self { Self::ProcessMessage => "process_message", Self::DraftFoundation => "draft_foundation", Self::UpdateDraftCard => "update_draft_card", Self::SyncResultProfile => "sync_result_profile", Self::GenerateCharacters => "generate_characters", Self::GenerateLandmarks => "generate_landmarks", Self::DeleteCharacters => "delete_characters", Self::DeleteLandmarks => "delete_landmarks", Self::GenerateRoleAssets => "generate_role_assets", Self::SyncRoleAssets => "sync_role_assets", Self::GenerateSceneAssets => "generate_scene_assets", Self::SyncSceneAssets => "sync_scene_assets", Self::ExpandLongTail => "expand_long_tail", Self::PublishWorld => "publish_world", Self::RevertCheckpoint => "revert_checkpoint", } } } impl RpgAgentOperationStatus { pub fn as_str(&self) -> &'static str { match self { Self::Queued => "queued", Self::Running => "running", Self::Completed => "completed", Self::Failed => "failed", } } } impl RpgAgentDraftCardKind { pub fn as_str(&self) -> &'static str { match self { Self::World => "world", Self::Camp => "camp", Self::Faction => "faction", Self::Character => "character", Self::Landmark => "landmark", Self::Thread => "thread", Self::Chapter => "chapter", Self::SceneChapter => "scene_chapter", Self::Carrier => "carrier", Self::SidequestSeed => "sidequest_seed", } } } impl RpgAgentDraftCardStatus { pub fn as_str(&self) -> &'static str { match self { Self::Suggested => "suggested", Self::Confirmed => "confirmed", Self::Locked => "locked", Self::Warning => "warning", } } } impl CustomWorldRoleAssetStatus { pub fn as_str(&self) -> &'static str { match self { Self::Missing => "missing", Self::VisualReady => "visual_ready", Self::AnimationsReady => "animations_ready", Self::Complete => "complete", } } }