188 lines
5.8 KiB
Rust
188 lines
5.8 KiB
Rust
//! 创意互动 Agent 领域模型。
|
||
//!
|
||
//! 本 crate 只描述会话、阶段、消息和目标绑定的纯领域事实;LLM、SSE、
|
||
//! 图片生成和 SpacetimeDB 写表均留在外层 adapter。
|
||
|
||
use serde::{Deserialize, Serialize};
|
||
#[cfg(feature = "spacetime-types")]
|
||
use spacetimedb::SpacetimeType;
|
||
|
||
pub const CREATIVE_AGENT_SESSION_ID_PREFIX: &str = "creative-session-";
|
||
pub const CREATIVE_AGENT_MESSAGE_ID_PREFIX: &str = "creative-message-";
|
||
pub const CREATIVE_AGENT_BINDING_ID_PREFIX: &str = "creative-binding-";
|
||
|
||
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||
pub enum CreativeAgentStage {
|
||
Idle,
|
||
Perceiving,
|
||
Thinking,
|
||
Remembering,
|
||
SelectingPuzzleTemplate,
|
||
WaitingTemplateConfirmation,
|
||
PlanningPuzzleLevels,
|
||
Acting,
|
||
Reflecting,
|
||
Collaborating,
|
||
TargetReady,
|
||
WaitingUser,
|
||
Failed,
|
||
}
|
||
|
||
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||
pub enum CreativeAgentMessageRole {
|
||
User,
|
||
Assistant,
|
||
System,
|
||
}
|
||
|
||
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||
pub enum CreativeAgentMessageKind {
|
||
Chat,
|
||
Stage,
|
||
ActionResult,
|
||
Warning,
|
||
}
|
||
|
||
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||
pub enum CreativeTargetPlayType {
|
||
Puzzle,
|
||
}
|
||
|
||
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||
pub enum CreativeTargetStage {
|
||
PuzzleAgentWorkspace,
|
||
PuzzleResult,
|
||
PuzzleRuntime,
|
||
}
|
||
|
||
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||
pub struct CreativeInputImageSnapshot {
|
||
pub asset_id: Option<String>,
|
||
pub read_url: Option<String>,
|
||
pub thumbnail_url: Option<String>,
|
||
pub width: Option<u32>,
|
||
pub height: Option<u32>,
|
||
pub summary: Option<String>,
|
||
}
|
||
|
||
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||
pub struct CreativeInputSummarySnapshot {
|
||
pub text: Option<String>,
|
||
pub entry_context: String,
|
||
pub images: Vec<CreativeInputImageSnapshot>,
|
||
pub material_summary: Option<String>,
|
||
pub unsupported_capabilities_json: String,
|
||
}
|
||
|
||
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||
pub struct CreativeAgentMessageSnapshot {
|
||
pub message_id: String,
|
||
pub session_id: String,
|
||
pub role: CreativeAgentMessageRole,
|
||
pub kind: CreativeAgentMessageKind,
|
||
pub text: String,
|
||
pub created_at_micros: i64,
|
||
}
|
||
|
||
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||
pub struct CreativeAgentTargetBindingSnapshot {
|
||
pub binding_id: String,
|
||
pub session_id: String,
|
||
pub play_type: CreativeTargetPlayType,
|
||
pub target_session_id: String,
|
||
pub target_stage: CreativeTargetStage,
|
||
pub result_profile_id: Option<String>,
|
||
pub created_at_micros: i64,
|
||
}
|
||
|
||
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||
pub struct CreativeAgentSessionSnapshot {
|
||
pub session_id: String,
|
||
pub owner_user_id: String,
|
||
pub stage: CreativeAgentStage,
|
||
pub input_summary: CreativeInputSummarySnapshot,
|
||
pub messages: Vec<CreativeAgentMessageSnapshot>,
|
||
pub puzzle_template_selection_json: Option<String>,
|
||
pub puzzle_image_generation_plan_json: Option<String>,
|
||
pub target_binding: Option<CreativeAgentTargetBindingSnapshot>,
|
||
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 CreativeAgentSessionProcedureResult {
|
||
pub ok: bool,
|
||
pub session_json: Option<String>,
|
||
pub error_message: Option<String>,
|
||
}
|
||
|
||
impl CreativeAgentStage {
|
||
pub fn as_str(self) -> &'static str {
|
||
match self {
|
||
Self::Idle => "idle",
|
||
Self::Perceiving => "perceiving",
|
||
Self::Thinking => "thinking",
|
||
Self::Remembering => "remembering",
|
||
Self::SelectingPuzzleTemplate => "selecting_puzzle_template",
|
||
Self::WaitingTemplateConfirmation => "waiting_template_confirmation",
|
||
Self::PlanningPuzzleLevels => "planning_puzzle_levels",
|
||
Self::Acting => "acting",
|
||
Self::Reflecting => "reflecting",
|
||
Self::Collaborating => "collaborating",
|
||
Self::TargetReady => "target_ready",
|
||
Self::WaitingUser => "waiting_user",
|
||
Self::Failed => "failed",
|
||
}
|
||
}
|
||
}
|
||
|
||
impl CreativeAgentMessageRole {
|
||
pub fn as_str(self) -> &'static str {
|
||
match self {
|
||
Self::User => "user",
|
||
Self::Assistant => "assistant",
|
||
Self::System => "system",
|
||
}
|
||
}
|
||
}
|
||
|
||
impl CreativeAgentMessageKind {
|
||
pub fn as_str(self) -> &'static str {
|
||
match self {
|
||
Self::Chat => "chat",
|
||
Self::Stage => "stage",
|
||
Self::ActionResult => "action_result",
|
||
Self::Warning => "warning",
|
||
}
|
||
}
|
||
}
|
||
|
||
impl CreativeTargetPlayType {
|
||
pub fn as_str(self) -> &'static str {
|
||
match self {
|
||
Self::Puzzle => "puzzle",
|
||
}
|
||
}
|
||
}
|
||
|
||
impl CreativeTargetStage {
|
||
pub fn as_str(self) -> &'static str {
|
||
match self {
|
||
Self::PuzzleAgentWorkspace => "puzzle-agent-workspace",
|
||
Self::PuzzleResult => "puzzle-result",
|
||
Self::PuzzleRuntime => "puzzle-runtime",
|
||
}
|
||
}
|
||
}
|