restore(air): inferComponentProps (00378f2 加回)
00378f2commit 同时 stub 化 repair/repairWorkflow (regression) 和加 inferComponentProps (新功能). revert00378f2把新功能也撤了, 现从00378f2提取 inferComponentProps 部分加回: - 接口: +inferComponentProps(fieldsJson, dictsJson, formsJson) 声明 (BS-新65) - impl: +inferComponentProps 实现 + INFER_COMPONENT_PROPS_PROMPT (BS-新65) - controller: +POST /api/ssw/ai/infer-component-props 端点 验证: - smartProps: AI 推理 4 字段 props (从 'AI 推理失败' 变成功) - 直接调 /infer-component-props 返回 200 + 正确 props (port min/max, status dict)
This commit is contained in:
1 parent
f8d21f82b4
commit
bc18222485
3 files changed
+144
No files matched your search
@@ -77,4 +77,32 @@ public interface AIRepairService {
|
||||
* @return {id, fullName} 最佳分类 (LLM 返回)
|
||||
*/
|
||||
Map<String, Object> inferCategory(String formName, String appCode, String categories);
|
||||
|
||||
/**
|
||||
* v0.16+ (2026-07-07 dos 26 P0 闭环, BS-新65): 组件属性 AI 推理
|
||||
*
|
||||
* 跟 inferCategory / inferFields 的区别:
|
||||
* - inferCategory: 表级别 (1 个 category)
|
||||
* - inferFields: 字段级 (JNPF 控件类型 fieldComponent)
|
||||
* - inferComponentProps: 字段级组件属性 (dictionaryType/min/max/modelId/regList)
|
||||
*
|
||||
* 解决 dacli form create --ai 路径的 BS-新61/62/63/64 4 类盲点.
|
||||
* 替代 dacli 关键词规则 (无底洞, 用户反馈 v0.15+ 已弃用).
|
||||
* 一次性 LLM 推理: 给 fields + dicts + forms 全上下文, 让 LLM 决策每个字段的组件属性.
|
||||
*
|
||||
* @param fieldsJson 字段列表 JSON (含 __vModel__, __config__.jnpfKey/label)
|
||||
* '[{"vModel":"port","jnpfKey":"inputNumber","label":"端口"},...]'
|
||||
* @param dictsJson 候选字典列表 (含 enCode + fullName + id)
|
||||
* '[{"id":"x","enCode":"s52.status","fullName":"状态"},...]'
|
||||
* @param formsJson 候选 form 列表 (含 enCode + fullName + id, 用于 relationForm)
|
||||
* '[{"id":"y","enCode":"dataset","fullName":"数据集"},...]'
|
||||
* @return Map {props: [{vModel, dictionaryType, min, max, modelId, regList, reason}]}
|
||||
* - dictionaryType: 字典 id (选填, 仅 select 字段)
|
||||
* - min/max: inputNumber 范围 (按业务常识自动推)
|
||||
* - modelId: 外键 form 的 enCode (input 字段命名像外键时填)
|
||||
* - regList: input 字段正则校验规则 (按字段名匹配)
|
||||
* - reason: 推理原因 (debug 用)
|
||||
* 失败时返回空 Map
|
||||
*/
|
||||
Map<String, Object> inferComponentProps(String fieldsJson, String dictsJson, String formsJson);
|
||||
}
|
||||
+74
@@ -473,4 +473,78 @@ public class AIRepairServiceImpl implements AIRepairService {
|
||||
}
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// v0.16+ (2026-07-07 dos 26 P0 闭环, BS-新65): 组件属性 AI 推理
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 一次性 LLM 推理, 给全上下文 (fields + dicts + forms), 替代 v0.15+ 关键词规则.
|
||||
*/
|
||||
private static final String INFER_COMPONENT_PROPS_PROMPT =
|
||||
"你是表单组件属性助手. 根据字段列表 + 候选字典 + 候选 form, 为每字段推荐组件属性.\n" +
|
||||
"\n" +
|
||||
"返回 JSON 格式: {props: [{vModel, dictionaryType, min, max, modelId, regList, reason}]}\n" +
|
||||
"(有些 LLM 会直接返回数组 [...], 两种格式都接受)\n" +
|
||||
"\n" +
|
||||
"推理规则:\n" +
|
||||
"1. select 字段: 从候选字典中匹配, 字段名含 status→状态字典, type→类型字典, visibility→可见性字典\n" +
|
||||
"2. input 字段命名像外键 (含 _id/_code/_identifier/_fk): 找最相关 form, modelId=form.enCode\n" +
|
||||
"3. inputNumber: 按字段名给业务常识范围\n" +
|
||||
" port/端口 → min=1, max=65535; age/年龄 → min=1, max=150\n" +
|
||||
" cpu_core → min=1, max=256; memory_gb/内存 → min=1, max=2048\n" +
|
||||
" disk_gb/磁盘 → min=1, max=65536; percentage/百分比 → min=0, max=100\n" +
|
||||
" duration/耗时/seconds → min=0; count/数量 → min=1\n" +
|
||||
"4. input: 按字段名配 regList\n" +
|
||||
" ip_address/ip → ^(\\d{1,3}\\.){3}\\d{1,3}$ (IPv4)\n" +
|
||||
" email → ^[\\w.+-]+@[\\w-]+\\.[\\w.-]+$\n" +
|
||||
" url/_url/link → ^https?://[^\\s]+$\n" +
|
||||
" cron/expression → ^[\\s\\d\\*\\/\\,\\-]+$\n" +
|
||||
" phone/手机/mobile → ^1[3-9]\\d{9}$\n" +
|
||||
"\n" +
|
||||
"reason 必填, 没把握字段不要填. 不要 markdown 包裹.";
|
||||
|
||||
@Override
|
||||
public Map<String, Object> inferComponentProps(String fieldsJson, String dictsJson, String formsJson) {
|
||||
log.info("[AIRepair-inferComponentProps] fields={} 字符, dicts={} 字符, forms={} 字符",
|
||||
fieldsJson.length(), dictsJson.length(), formsJson.length());
|
||||
|
||||
String userPrompt = String.format(
|
||||
"字段列表 (JSON):\n%s\n\n候选字典 (JSON):\n%s\n\n候选 form (JSON):\n%s\n\n请推理每个字段的组件属性, 返回 JSON.",
|
||||
fieldsJson, dictsJson, formsJson);
|
||||
|
||||
String raw = llmClient.chat(INFER_COMPONENT_PROPS_PROMPT, userPrompt);
|
||||
if (raw == null || raw.isEmpty()) {
|
||||
log.warn("[AIRepair-inferComponentProps] LLM 返回空");
|
||||
return new HashMap<>();
|
||||
}
|
||||
log.info("[AIRepair-inferComponentProps] LLM 返回 {} 字符", raw.length());
|
||||
|
||||
String cleaned = raw.trim()
|
||||
.replaceAll("```json\\s*", "").replaceAll("```\\s*", "")
|
||||
.trim();
|
||||
String repaired = JsonRepairUtil.repair(cleaned);
|
||||
log.info("[AIRepair-inferComponentProps] 修复后 {} 字符", repaired.length());
|
||||
|
||||
// v0.16+: 兼容 2 种格式 ({props:[...]} 或 裸 [...])
|
||||
try {
|
||||
Map<String, Object> result = JSON.parseObject(repaired, new TypeReference<Map<String, Object>>() {});
|
||||
if (result != null && result.containsKey("props")) {
|
||||
log.info("[AIRepair-inferComponentProps] 格式 1 (包装): {} 个字段", ((List<?>) result.get("props")).size());
|
||||
return result;
|
||||
}
|
||||
} catch (Exception ignored) { /* fallthrough */ }
|
||||
try {
|
||||
List<Map<String, Object>> arr = JSON.parseObject(repaired, new TypeReference<List<Map<String, Object>>>() {});
|
||||
if (arr != null && !arr.isEmpty()) {
|
||||
log.info("[AIRepair-inferComponentProps] 格式 2 (裸数组): {} 个字段", arr.size());
|
||||
Map<String, Object> wrapped = new HashMap<>();
|
||||
wrapped.put("props", arr);
|
||||
return wrapped;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("[AIRepair-inferComponentProps] JSON 解析失败: {}", e.getMessage());
|
||||
}
|
||||
return new HashMap<>();
|
||||
}
|
||||
}
|
||||
+42
@@ -148,4 +148,46 @@ public class SswAIRepairController {
|
||||
return ActionResult.fail("分类推理异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* v0.16+ (2026-07-07 dos 26 P0 闭环, BS-新65): 组件属性 AI 推理
|
||||
*
|
||||
* dacli form create --ai 路径的 4 类盲点 (BS-新61/62/63/64) 智能选配:
|
||||
* - select 字段字典选配 (BS-新61)
|
||||
* - input _id/_code → relationForm (BS-新62)
|
||||
* - inputNumber 范围 (BS-新63)
|
||||
* - input regList 格式校验 (BS-新64)
|
||||
*
|
||||
* 请求: {
|
||||
* fields: '[{vModel:"port",jnpfKey:"inputNumber",label:"端口"},...]',
|
||||
* dicts: '[{id:"x",enCode:"s52.status",fullName:"状态"},...]',
|
||||
* forms: '[{id:"y",enCode:"dataset",fullName:"数据集"},...]'
|
||||
* }
|
||||
* 响应: {props: [{vModel, dictionaryType, min, max, modelId, regList, reason}]}
|
||||
*
|
||||
* vs dacli 关键词规则 (v0.15+ 已弃用, 用户反馈"无穷无尽"):
|
||||
* 一次性 LLM 推理, 给全上下文 (fields + dicts + forms), 替代人工维护 SELECT_DICT_RULES 等
|
||||
*/
|
||||
@PostMapping("/infer-component-props")
|
||||
@Operation(summary = "组件属性 AI 推理 (BS-新65, dos 26 P0 闭环)",
|
||||
description = "dacli form create --ai 路径选配组件属性: 字典/min-max/relationForm/regList")
|
||||
public ActionResult<Map<String, Object>> inferComponentProps(@RequestBody Map<String, Object> body) {
|
||||
String fieldsJson = (String) body.get("fields");
|
||||
String dictsJson = (String) body.get("dicts");
|
||||
String formsJson = (String) body.get("forms");
|
||||
if (fieldsJson == null || dictsJson == null || formsJson == null) {
|
||||
return ActionResult.fail("fields / dicts / forms 必填");
|
||||
}
|
||||
try {
|
||||
Map<String, Object> result = aiRepairService.inferComponentProps(
|
||||
fieldsJson, dictsJson, formsJson);
|
||||
if (result.isEmpty() || !result.containsKey("props")) {
|
||||
return ActionResult.fail("组件属性推理失败, 返回空结果");
|
||||
}
|
||||
return ActionResult.success(result);
|
||||
} catch (Exception e) {
|
||||
log.error("SswAIRepairController.inferComponentProps 异常", e);
|
||||
return ActionResult.fail("组件属性推理异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user