@@ -486,6 +486,15 @@ func (t *AutomationModuleAnalyzer) handleAnalyze(ctx context.Context, request mc
486
486
return nil , errors .New ("参数错误:requirement 必须是非空字符串" )
487
487
}
488
488
489
+ // 检测用户是否想要创建插件
490
+ suggestedType , isPlugin , confidence := t .detectPluginIntent (requirement )
491
+ pluginDetectionMsg := ""
492
+ if isPlugin {
493
+ pluginDetectionMsg = fmt .Sprintf ("\n \n 🔍 **插件检测结果**:检测到用户想要创建插件(置信度:%s)\n ⚠️ **重要提醒**:当用户提到插件时,packageType和template字段都必须设置为 \" plugin\" ,不能使用 \" package\" !" , confidence )
494
+ } else {
495
+ pluginDetectionMsg = fmt .Sprintf ("\n \n 🔍 **类型检测结果**:建议使用 %s 类型" , suggestedType )
496
+ }
497
+
489
498
// 从数据库获取所有自动化包信息
490
499
var packages []model.SysAutoCodePackage
491
500
if err := global .GVA_DB .Find (& packages ).Error ; err != nil {
@@ -554,7 +563,7 @@ func (t *AutomationModuleAnalyzer) handleAnalyze(ctx context.Context, request mc
554
563
555
564
%s
556
565
557
- 请AI根据用户需求:%s
566
+ 请AI根据用户需求:%s%s
558
567
559
568
分析现有的包、历史记录和预设计模块,然后构建ExecutionPlan结构体调用execute操作。
560
569
@@ -583,13 +592,13 @@ func (t *AutomationModuleAnalyzer) handleAnalyze(ctx context.Context, request mc
583
592
{
584
593
"packageName": "包名",
585
594
"moduleName": "模块名",
586
- "packageType": "package或plugin",
595
+ "packageType": "package或plugin", // 当用户提到插件时必须是"plugin"
587
596
"needCreatedPackage": true/false,
588
597
"needCreatedModules": true/false,
589
598
"packageInfo": {
590
599
"desc": "描述",
591
600
"label": "展示名",
592
- "template": "package或plugin",
601
+ "template": "package或plugin", // 必须与packageType保持一致!
593
602
"packageName": "包名"
594
603
},
595
604
"modulesInfo": {
@@ -643,25 +652,30 @@ func (t *AutomationModuleAnalyzer) handleAnalyze(ctx context.Context, request mc
643
652
644
653
**重要提醒**:ExecutionPlan必须严格按照以下格式和验证规则:
645
654
655
+ **插件类型检测规则(最重要)**:
656
+ 1. 当用户需求中包含"插件"、"plugin"等关键词时,packageType和template都必须设置为"plugin"
657
+ 2. packageType和template字段必须保持一致,不能一个是"package"另一个是"plugin"
658
+ 3. 如果检测到插件意图但设置错误,会导致创建失败
659
+
646
660
**字段完整性要求**:
647
- 1 . 所有字符串字段都不能为空(包括packageName、moduleName、structName、tableName、description等)
648
- 2 . 所有布尔字段必须明确设置true或false,不能使用默认值
661
+ 4 . 所有字符串字段都不能为空(包括packageName、moduleName、structName、tableName、description等)
662
+ 5 . 所有布尔字段必须明确设置true或false,不能使用默认值
649
663
650
664
**主键设置规则(关键)**:
651
- 3 . 当gvaModel=false时:fields数组中必须有且仅有一个字段的primaryKey=true
652
- 4 . 当gvaModel=true时:系统自动创建ID主键,fields中所有字段的primaryKey都应为false
653
- 5 . 主键设置错误会导致模板执行时PrimaryField为nil的严重错误!
665
+ 6 . 当gvaModel=false时:fields数组中必须有且仅有一个字段的primaryKey=true
666
+ 7 . 当gvaModel=true时:系统自动创建ID主键,fields中所有字段的primaryKey都应为false
667
+ 8 . 主键设置错误会导致模板执行时PrimaryField为nil的严重错误!
654
668
655
669
**包和模块创建逻辑**:
656
- 6 . 如果存在可用的package,needCreatedPackage应设为false
657
- 7 . 如果存在可用的modules,needCreatedModules应设为false
658
- 8 . 如果发现合适的预设计模块,可以考虑基于它进行扩展而不是从零创建
670
+ 9 . 如果存在可用的package,needCreatedPackage应设为false
671
+ 10 . 如果存在可用的modules,needCreatedModules应设为false
672
+ 11 . 如果发现合适的预设计模块,可以考虑基于它进行扩展而不是从零创建
659
673
660
674
**字典创建流程**:
661
- 9 . 如果字段需要字典类型,请先使用 generate_dictionary_options 工具创建字典
662
- 10 . 字典创建成功后,再执行模块创建操作
675
+ 12 . 如果字段需要字典类型,请先使用 generate_dictionary_options 工具创建字典
676
+ 13 . 字典创建成功后,再执行模块创建操作
663
677
664
- ` , string (resultJSON ), requirement ),
678
+ ` , string (resultJSON ), requirement , pluginDetectionMsg ),
665
679
},
666
680
},
667
681
}, nil
@@ -965,6 +979,13 @@ func (t *AutomationModuleAnalyzer) validateExecutionPlan(plan *ExecutionPlan) er
965
979
return errors .New ("packageType 必须是 'package' 或 'plugin'" )
966
980
}
967
981
982
+ // 验证packageType和template字段的一致性
983
+ if plan .NeedCreatedPackage && plan .PackageInfo != nil {
984
+ if plan .PackageType != plan .PackageInfo .Template {
985
+ return errors .New ("packageType 和 packageInfo.template 必须保持一致" )
986
+ }
987
+ }
988
+
968
989
// 验证包信息
969
990
if plan .NeedCreatedPackage {
970
991
if plan .PackageInfo == nil {
@@ -1249,3 +1270,48 @@ func (t *AutomationModuleAnalyzer) generateSmartDictionaryOptions(dictType, fiel
1249
1270
sort int
1250
1271
}{}
1251
1272
}
1273
+
1274
+ // detectPluginIntent 检测用户需求中是否包含插件相关的关键词
1275
+ func (t * AutomationModuleAnalyzer ) detectPluginIntent (requirement string ) (suggestedType string , isPlugin bool , confidence string ) {
1276
+ // 转换为小写进行匹配
1277
+ requirementLower := strings .ToLower (requirement )
1278
+
1279
+ // 插件相关关键词
1280
+ pluginKeywords := []string {
1281
+ "插件" , "plugin" , "扩展" , "extension" , "addon" , "模块插件" ,
1282
+ "功能插件" , "业务插件" , "第三方插件" , "自定义插件" ,
1283
+ }
1284
+
1285
+ // 包相关关键词(用于排除误判)
1286
+ packageKeywords := []string {
1287
+ "包" , "package" , "模块包" , "业务包" , "功能包" ,
1288
+ }
1289
+
1290
+ // 检测插件关键词
1291
+ pluginMatches := 0
1292
+ for _ , keyword := range pluginKeywords {
1293
+ if strings .Contains (requirementLower , keyword ) {
1294
+ pluginMatches ++
1295
+ }
1296
+ }
1297
+
1298
+ // 检测包关键词
1299
+ packageMatches := 0
1300
+ for _ , keyword := range packageKeywords {
1301
+ if strings .Contains (requirementLower , keyword ) {
1302
+ packageMatches ++
1303
+ }
1304
+ }
1305
+
1306
+ // 决策逻辑
1307
+ if pluginMatches > 0 {
1308
+ if packageMatches == 0 || pluginMatches > packageMatches {
1309
+ return "plugin" , true , "高"
1310
+ } else {
1311
+ return "plugin" , true , "中"
1312
+ }
1313
+ }
1314
+
1315
+ // 默认返回package
1316
+ return "package" , false , "低"
1317
+ }
0 commit comments