- Python FastAPI 引擎:世界状态模拟、全局能量条、世界事件系统 - Node.js WebSocket 服务器:实时通信、事件队列批处理 - 前端仪表盘:世界状态可视化、行动日志、事件展示 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
83 lines
1.7 KiB
Python
83 lines
1.7 KiB
Python
from __future__ import annotations
|
|
from pydantic import BaseModel, Field
|
|
from typing import List, Dict, Optional
|
|
from enum import Enum
|
|
|
|
|
|
class Emotion(str, Enum):
|
|
CALM = "calm"
|
|
HAPPY = "happy"
|
|
ANXIOUS = "anxious"
|
|
|
|
|
|
class Weather(str, Enum):
|
|
SUNNY = "sunny"
|
|
RAINY = "rainy"
|
|
|
|
|
|
class GlobalMeter(BaseModel):
|
|
"""全体能量条"""
|
|
value: int = 0
|
|
threshold: int = 100
|
|
cooldown: int = 0
|
|
|
|
|
|
class WorldEffect(BaseModel):
|
|
"""持续影响效果"""
|
|
type: str
|
|
name: str
|
|
intensity: int = 1
|
|
remaining_ticks: int = 5
|
|
mood_modifier: int = 0
|
|
|
|
|
|
class AgentState(BaseModel):
|
|
emotion: Emotion = Emotion.CALM
|
|
goal: str = ""
|
|
memory: List[str] = Field(default_factory=list)
|
|
|
|
|
|
class WorldState(BaseModel):
|
|
tick: int = 0
|
|
weather: Weather = Weather.SUNNY
|
|
town_mood: int = Field(default=0, ge=-10, le=10)
|
|
agents: Dict[str, AgentState] = Field(default_factory=dict)
|
|
events: List[str] = Field(default_factory=list)
|
|
global_meter: GlobalMeter = Field(default_factory=GlobalMeter)
|
|
world_effects: List[WorldEffect] = Field(default_factory=list)
|
|
|
|
|
|
class Event(BaseModel):
|
|
type: str
|
|
text: str
|
|
user: str
|
|
ts: float
|
|
|
|
|
|
class StepRequest(BaseModel):
|
|
events: List[Event] = Field(default_factory=list)
|
|
|
|
|
|
class Action(BaseModel):
|
|
agent_id: str
|
|
say: str
|
|
do: str
|
|
|
|
|
|
class GlobalEventInfo(BaseModel):
|
|
"""世界级事件信息"""
|
|
name: str
|
|
description: str
|
|
|
|
|
|
class GlobalEventResult(BaseModel):
|
|
"""世界级事件触发结果"""
|
|
triggered: bool = False
|
|
event: Optional[GlobalEventInfo] = None
|
|
|
|
|
|
class StepResponse(BaseModel):
|
|
world_state: WorldState
|
|
actions: List[Action]
|
|
global_event: GlobalEventResult = Field(default_factory=GlobalEventResult)
|