feat:架构重构

This commit is contained in:
2026-10-01 23:08:06 -07:00
parent b82dc93404
commit 68588d1f92
74 changed files with 1131 additions and 3492 deletions
+7 -39
View File
@@ -1,6 +1,6 @@
"""前端组件目录及查询结果"""
from typing import Literal, Self
from typing import Self
from pydantic import BaseModel, ConfigDict, Field, model_validator
@@ -119,13 +119,17 @@ class ComponentCatalog(ExtensibleModel):
for group in component.field_groups
if isinstance(group, str) and group not in shared
]:
raise ValueError(f"物料 {component.key} 引用了不存在的共享分组: {missing}")
raise ValueError(
f"物料 {component.key} 引用了不存在的共享分组: {missing}"
)
if shadowed := [
group.key
for group in component.field_groups
if isinstance(group, FieldGroup) and group.key in shared
]:
raise ValueError(f"物料 {component.key} 的独有分组与共享分组重名: {shadowed}")
raise ValueError(
f"物料 {component.key} 的独有分组与共享分组重名: {shadowed}"
)
by_key = {group.key: group for group in self.field_groups}
fields = [
field
@@ -141,39 +145,3 @@ class ComponentCatalog(ExtensibleModel):
if problem:
raise ValueError(f"物料 {component.key} 字段 {field.path} {problem}")
return self
class ComponentQuery(ExtensibleModel):
key: NonBlankString | None = Field(default=None, description="精确匹配目录编号")
type: NonBlankString | None = Field(
default=None, description="精确匹配前端节点类型,可能对应多个预设"
)
keyword: NonBlankString | None = Field(
default=None, description="按名称、说明和标签查询,多个条件同时满足"
)
class ComponentResult(ExtensibleModel):
status: Literal["resolved", "not_found", "unsupported"]
components: list[ComponentDefinition] = Field(default_factory=list)
catalog_version: NonBlankString | None = None
message: NonBlankString
def to_planner_context(self) -> JsonObject:
# 显式提取摘要,避免默认数据、事件和扩展字段进入规划提示词
return {
"status": self.status,
"catalog_version": self.catalog_version,
"message": self.message,
"components": [
ComponentSummary(
key=component.key,
type=component.type,
name=component.name,
description=component.description,
default_width=component.schema_.layout.width,
default_height=component.schema_.layout.height,
).model_dump(mode="json")
for component in self.components
],
}