feat: Migrate to React Flow and add Fixed + Dynamic category mode

Frontend:
- Migrate MindmapDAG from D3.js to React Flow (@xyflow/react)
- Add custom node components (QueryNode, CategoryHeaderNode, AttributeNode)
- Add useDAGLayout hook for column-based layout
- Add "AI" badge for LLM-suggested categories
- Update CategorySelector with Fixed + Dynamic mode option
- Improve dark/light theme support

Backend:
- Add FIXED_PLUS_DYNAMIC category mode
- Filter duplicate category names in LLM suggestions
- Update prompts to exclude fixed categories when suggesting new ones
- Improve LLM service with better error handling and logging
- Auto-remove /no_think prefix for non-Qwen models
- Add smart JSON format detection for model compatibility
- Improve JSON extraction with multiple parsing strategies

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-03 01:22:57 +08:00
parent 91f7f41bc1
commit 1ed1dab78f
21 changed files with 1254 additions and 614 deletions

View File

@@ -73,6 +73,7 @@ class CategoryMode(str, Enum):
"""類別模式"""
FIXED_ONLY = "fixed_only"
FIXED_PLUS_CUSTOM = "fixed_plus_custom"
FIXED_PLUS_DYNAMIC = "fixed_plus_dynamic" # Fixed + LLM suggested
CUSTOM_ONLY = "custom_only"
DYNAMIC_AUTO = "dynamic_auto"
@@ -98,3 +99,35 @@ class DynamicStep1Result(BaseModel):
class DynamicCausalChain(BaseModel):
"""動態版本的因果鏈"""
chain: Dict[str, str] # {類別名: 選中屬性}
# ===== DAG (Directed Acyclic Graph) schemas =====
class DAGNode(BaseModel):
"""DAG 節點 - 每個屬性只出現一次"""
id: str # 唯一 ID: "{category}_{index}"
name: str # 顯示名稱
category: str # 所屬類別
order: int # 欄位內位置
class DAGEdge(BaseModel):
"""DAG 邊 - 節點之間的連接"""
source_id: str
target_id: str
class AttributeDAG(BaseModel):
"""完整 DAG 結構"""
query: str
categories: List[CategoryDefinition]
nodes: List[DAGNode]
edges: List[DAGEdge]
class DAGRelationship(BaseModel):
"""Step 2 輸出 - 單一關係"""
source_category: str
source: str # source attribute name
target_category: str
target: str # target attribute name