feat: expose AI page recipes

This commit is contained in:
2026-06-17 12:38:26 +08:00
parent fcc5719bc6
commit 2b0b673ce9
8 changed files with 102 additions and 12 deletions

View File

@@ -62,6 +62,7 @@ import com.eip4.platform.metadata.schema.TypedPageSchemaIssue;
import com.eip4.platform.metadata.schema.TypedPageSchemaReport;
import com.eip4.platform.metadata.schema.TypedPageSchemaValidator;
import com.eip4.platform.metadata.schema.blueprint.PageBlueprint;
import com.eip4.platform.metadata.schema.blueprint.PageRecipeDefinition;
import com.eip4.platform.metadata.schema.blueprint.PageRecipeRegistry;
import com.eip4.platform.metadata.schema.blueprint.PageRecipeValidationReport;
import com.eip4.platform.metadata.schema.blueprint.PageRecipeValidator;
@@ -90,6 +91,7 @@ public class AiAgentService {
private final ObjectMapper objectMapper;
private final AiToolRegistry toolRegistry;
private final TypedPageSchemaValidator typedSchemaValidator;
private final PageRecipeRegistry pageRecipeRegistry;
private final PageRecipeValidator pageRecipeValidator;
private static volatile SchemaGate sharedSchemaGate;
@@ -127,7 +129,8 @@ public class AiAgentService {
this.typedSchemaValidator = typedSchemaValidator == null
? new TypedPageSchemaValidator(objectMapper, PageComponentRegistry.defaults())
: typedSchemaValidator;
this.pageRecipeValidator = new PageRecipeValidator(objectMapper, PageRecipeRegistry.defaults());
this.pageRecipeRegistry = PageRecipeRegistry.defaults();
this.pageRecipeValidator = new PageRecipeValidator(objectMapper, pageRecipeRegistry);
}
public AiTask createTask(String objective) {
@@ -760,6 +763,16 @@ public class AiAgentService {
return toolRegistry.employees();
}
public List<PageRecipeDefinition> listPageRecipes() {
return pageRecipeRegistry.definitions();
}
public PageRecipeDefinition getPageRecipe(String recipe) {
return pageRecipeRegistry.find(recipe)
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND,
"页面 recipe 不存在: " + (recipe == null ? "" : recipe)));
}
public AiToolAccessDecision checkToolAccess(AiToolAccessRequest request) {
return toolRegistry.check(request);
}

View File

@@ -34,6 +34,10 @@ public final class AiToolRegistry {
"Validate AMIS and typed page schema before saving or packaging.",
List.of("POST /api/ai/tools/validate-schema", "POST /api/page/schema/validate"),
List.of("ai:schema:validate"), false, false);
registerTool(tools, "page-recipe.read", "design-contract",
"Read EIP4 page recipes and UI/UE constraints before generating page blueprints.",
List.of("GET /api/ai/page-recipes", "GET /api/ai/page-recipes/{recipe}"),
List.of("ai:page-recipe:read"), false, false);
registerTool(tools, "local.apply", "local-gate",
"Apply a change set to a local EIP4 environment only.",
List.of("POST /api/ai/tasks/{taskId}/change-sets/{changeSetId}/local-apply"),
@@ -56,9 +60,9 @@ public final class AiToolRegistry {
Map<String, AiEmployeeDefinition> employees = new LinkedHashMap<>();
registerEmployee(employees, "agent-developer", "Agent Developer",
"Develops EIP4 feature packages in local environments.",
List.of("feature.draft.generate", "schema.validate", "local.apply", "smoke.run",
List.of("feature.draft.generate", "schema.validate", "page-recipe.read", "local.apply", "smoke.run",
"feature.package", "release.prepare"),
List.of("ai:feature:draft", "ai:schema:validate", "ai:local:apply", "ai:smoke:run",
List.of("ai:feature:draft", "ai:schema:validate", "ai:page-recipe:read", "ai:local:apply", "ai:smoke:run",
"ai:package:create", "ai:release:prepare"),
List.of("Local apply only", "Production deployment requires human operator"));
registerEmployee(employees, "release-auditor", "Release Auditor",

View File

@@ -33,6 +33,7 @@ import com.eip4.platform.ai.model.AiToolAccessRequest;
import com.eip4.platform.ai.model.AiToolDefinition;
import com.eip4.platform.ai.model.AiEmployeeDefinition;
import com.eip4.platform.ai.service.AiAgentService;
import com.eip4.platform.metadata.schema.blueprint.PageRecipeDefinition;
import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.v3.oas.annotations.Operation;
@@ -207,6 +208,18 @@ public class AiAgentController {
return service.listEmployees();
}
@Operation(summary = "列出 AI 页面 recipe", description = "返回 Agent 生成页面前必须读取的 EIP4 UI/UE recipe 定义")
@GetMapping("/page-recipes")
public List<PageRecipeDefinition> pageRecipes() {
return service.listPageRecipes();
}
@Operation(summary = "查看 AI 页面 recipe", description = "按 recipe id 返回字段映射、门禁和版本信息")
@GetMapping("/page-recipes/{recipe}")
public PageRecipeDefinition pageRecipe(@PathVariable String recipe) {
return service.getPageRecipe(recipe);
}
@Operation(summary = "检查 AI 工具访问权限", description = "只做权限判定,不执行工具;生产写默认阻断")
@PostMapping("/tools/access-check")
public AiToolAccessDecision checkToolAccess(@RequestBody(required = false) AiToolAccessRequest request) {

View File

@@ -26,6 +26,19 @@ class AiToolRegistryTest {
assertTrue(decision.blockers().isEmpty());
}
@Test
void agentDeveloperCanReadPageRecipes() {
var decision = registry.check(new AiToolAccessRequest(
"agent-developer",
"page-recipe.read",
List.of("ai:page-recipe:read"),
"local",
false));
assertTrue(decision.allowed());
assertTrue(decision.blockers().isEmpty());
}
@Test
void localOnlyToolIsBlockedForProductionTarget() {
var decision = registry.check(new AiToolAccessRequest(

View File

@@ -50,6 +50,7 @@ import com.eip4.platform.ai.model.AiToolAccessRequest;
import com.eip4.platform.ai.model.AiToolDefinition;
import com.eip4.platform.ai.model.AiEmployeeDefinition;
import com.eip4.platform.ai.service.AiAgentService;
import com.eip4.platform.metadata.schema.blueprint.PageRecipeDefinition;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -183,6 +184,37 @@ class AiAgentControllerTest {
verify(service).listEmployees();
}
@Test
void 页面Recipe列表接口返回规范定义() throws Exception {
when(service.listPageRecipes()).thenReturn(List.of(new PageRecipeDefinition(
"maintenance-crud-v1", 1, "EIP4 maintenance CRUD page",
Map.of("string", "input-text"),
List.of("page-recipe", "typed-page-schema"))));
mvc.perform(get("/api/ai/page-recipes"))
.andExpect(status().isOk())
.andExpect(jsonPath("$[0].recipe").value("maintenance-crud-v1"))
.andExpect(jsonPath("$[0].fieldMappings.string").value("input-text"))
.andExpect(jsonPath("$[0].gates[0]").value("page-recipe"));
verify(service).listPageRecipes();
}
@Test
void 页面Recipe详情接口按名称查询() throws Exception {
when(service.getPageRecipe(eq("maintenance-crud-v1"))).thenReturn(new PageRecipeDefinition(
"maintenance-crud-v1", 1, "EIP4 maintenance CRUD page",
Map.of("boolean", "switch"),
List.of("page-recipe")));
mvc.perform(get("/api/ai/page-recipes/maintenance-crud-v1"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.recipe").value("maintenance-crud-v1"))
.andExpect(jsonPath("$.fieldMappings.boolean").value("switch"));
verify(service).getPageRecipe("maintenance-crud-v1");
}
@Test
void 工具访问检查接口不执行工具只返回判定() throws Exception {
var request = new AiToolAccessRequest("agent-developer", "local.apply",