Complete Documentation of Rule Template System

Complete Documentation of Rule Template System

I. Script Pipeline

All scripts are located in the scripts/ directory, arranged in execution order:

| Script | Purpose | Execution Timing |

|------|------|---------|

| import-aml-v2.js | Basic AML Import (ItemType/Method/Relationship/Permission/List/Lifecycle/Sequence/Workflow/Form) | Initial setup |

| extract-extended-aml.js | Extended Extraction (Identity/PermissionAccess/WorkflowActivities/LifecycleTransitions/Variables/Revisions/FormFields/ItemTypeBindings/MethodRules/RelationshipViews) | After basic import |

| generate-operation-rules.js | Rule Operation Classification + Relationship Rules + Method Trigger Rules + Operation Prompt Generation | After extended extraction |

1.1 import-aml-v2.js

# 全量重建(清空16张主表后重新导入)
node scripts/import-aml-v2.js --full

# 增量更新(只处理新文件)
node scripts/import-aml-v2.js

# 仅修补跨文件关联和模板回填
node scripts/import-aml-v2.js --patch

# 仅生成业务系统提示词
node scripts/import-aml-v2.js --generate-prompts

生成的表(23张):

  • sciot_item_types — Item type definitions
  • sciot_properties (including data_source/data_source_type/data_source_name/item_behavior columns) — Property definitions
  • sciot_methods — Method definitions
  • sciot_relationships (including create_related/is_dependent/rel_item_type_label/rel_properties) — Relationship types
  • sciot_permissions — Permission Definitions
  • sciot_lists + sciot_list_values — List Enumerations
  • sciot_lifecycle_maps + sciot_lifecycle_states — Lifecycle
  • sciot_sequences — Numbering Rules
  • sciot_workflow_maps — Workflow Mapping
  • sciot_forms — Form Definitions
  • sciot_rules — Auto-generated Validation Rules
  • sciot_templates (including lifecycle/lifecycle_start_state/generation_rules/relationship_types) — Object Creation Templates
  • sciot_meta_models + sciot_meta_model_properties + sciot_meta_model_events — Meta Models
  • sciot_business_systems + sciot_business_objects + sciot_business_prompts — Business Systems
  • sciot_creation_logs — Creation Logs

Rule Generation (generateEnhancedRules): For each ItemType with properties:

  • Required Field Rules (is_required=1 → severity='error')
  • Data Type Validation Rules (severity='warning')
  • Length constraint rules (stored_length>0 → severity='warning')
  • Pattern validation rules (pattern not empty → severity='info')
  • Lifecycle rules (one per lifecycle)
  • Relationship rules (one per relationship)

Template generation (backfillTemplates): Backfill sciot_templates for each ItemType:

  • Field classification (LLM-fillable fields/System-auto fields/Mandatory fields/Optional fields)
  • Lifecycle binding
  • Relationship type list
  • generation_rules JSON (including child_objects/nested_depth/sequence_name)

1.2 extract-extended-aml.js

# 全量重建(删除13张扩展表后重建)
node scripts/extract-extended-aml.js --full

# 仅处理特定类型
node scripts/extract-extended-aml.js --type identity

生成的表(13张):

| Table Name | Description |

|------|------|

| sciot_identities | User/Role/Group definitions |

| sciot_permission_access | Permission access rules (can_get/update/delete/discover/change_access) |

| sciot_workflow_activities | Workflow activity nodes |

| sciot_workflow_paths | Workflow paths |

| sciot_activity_assignments | Activity assignments |

| sciot_activity_transitions | Activity-triggered transitions |

| sciot_lifecycle_transitions | Lifecycle state transitions |

| sciot_variables | Global variables |

| sciot_revisions | Revision Rules |

| sciot_form_fields | Form Field Layout |

| sciot_itemtype_bindings | ItemType Bindings (Life Cycle/Workflow/Permission/Can Add/TOC Access/View) |

| sciot_method_rules | Method Business Logic Parsing (12 Rule Patterns) |

| sciot_relationship_views | Relationship Views |

Rule Generation (generateRulesFromExtendedData): Generate rules from Permission/Lifecycle/Workflow/Method data and write them into sciot_rules.

1.3 generate-operation-rules.js

# 全量重建(清理旧分类和规则后重新生成)
node scripts/generate-operation-rules.js --full

# 仅分析不写入
node scripts/generate-operation-rules.js --dry-run

执行步骤:

  1. tagExistingRules() — Tag sciot_rules with operation_type (rule_type→add/edit/get mapping)
  2. generateRelationshipRules() — Generate relationship handling rules from sciot_relationships
  3. generateMethodTriggerRules() — Generate method trigger rules from sciot_method_rules
  4. generateOperationPrompts() — Generate predefined prompts for each ItemType × 3 operation types into prompt_tables
  5. tagExistingPrompts() — Update operation_type for existing prompt_templates

--full mode cleanup logic:

  • Delete rules in sciot_rules where category='relationship' and category='method'
  • Reset operation_type of sciot_rules to empty
  • Delete auto-generated prompts in prompt_templates where id starts with 'prompt-'

II. Database Table Structure

2.1 sciot_rules (Main Rules Table)

Column NameTypeDescription
idINTEGER PKAuto-increment primary key
rule_typeTEXTRule type: required/pattern/validation/range/length/lifecycle/relationship/inspect/auto_create_related/state_transition/permission_check/notification/data_calculation/copy_clone/file_attachment/query_search/relationship_operation
data_typeTEXTAssociated data type
property_nameTEXTAssociated property name
property_labelTEXTProperty label
rule_patternTEXTRegular Expression/Value List Pattern
descriptionTEXTRule Description (for frontend display)
llm_instructionTEXTLLM Instruction
item_type_nameTEXTAssociated Object Type
priorityINTEGERPriority
severityTEXTerror/warning/info
categoryTEXTdata/relationship/lifecycle/method/permission/workflow
is_activeINTEGER1=Enabled 0=Disabled
operation_typeTEXTComma-separated operation types: add/edit/get

2.2 prompt_templates (Prompt table, replacing the deprecated sciot_prompts)

Column NameTypeDescription
idTEXT PKFormat: 'prompt-{opType}-{typeName}'
nameTEXTPrompt Name
contentTEXTPrompt Content (corresponds to frontend user_prompt_template)
prompt_typeTEXTcreation/edit/get
item_type_nameTEXTAssociated Object Type
operation_typeTEXTadd/edit/get
versionINTEGERVersion number
statusTEXTactive/inactive

3. Backend API

3.1 Unified Schema API

GET /api/aml/unified/schema/:itemType

Returns:

{
  "itemType": "Project",
  "properties": { "name": { "type": "string", "isRequired": true, ... }, ... },
  "llmFields": ["name", "description", ...],
  "autoFields": ["id", "created_by_id", ...],
  "requiredFields": ["name"],
  "rules": [
    {
      "id": 1,
      "rule_type": "required",
      "property_name": "name",
      "rule_description": "名称不能为空",
      "description": "名称不能为空",
      "severity": "error",
      "pattern": null,
      "is_active": 1,
      "operation_type": "add,edit,get"
    }
  ],
  "template": { "generation_rules": {...}, ... }
}

3.2 提示词 API

GET /api/aml/sciot/prompts?operation_type=add&item_type=Project&page=1&limit=50

  • operation_type filter: Matches operation_type = 'add' or any value in a comma-separated list
  • Returns paginated data

POST /api/aml/sciot/prompts/update — Write to prompt_templates.content

{ "item_type_name": "Project", "user_prompt_template": "..." }

3.3 规则 CRUD API

GET /api/aml/sciot/rules?item_type=Project&operation_type=add&page=1&limit=50

POST /api/aml/sciot/rules/add — Add a new rule to sciot_rules

POST /api/aml/sciot/rules/update — Update a rule

DELETE /api/aml/sciot/rules?id=X — Delete a rule

3.4 Rule Statistics

GET /api/aml/sciot/rules/stats

Returns total/active/by_type/by_severity/by_category


4. Frontend Usage

4.1 Creation Process (StaffCapabilities.vue → runCreate())

1. fetch Schema → /api/aml/unified/schema/:itemType
2. fetch TypeTemplate → 属性/关系类型
3. fetch Prompts → /api/aml/sciot/prompts(仅一次)
4. 组装 Prompt → 发给 LLM
5. sanitizeProperties → 修正字段值(list/integer/date 等)
6. validateProperties → 规则验证
7. Generate AML
8. 创建关系(仅 create_related=1 的关系)

4.2 规则验证(rule-validator.js → validateProperties)

支持的 rule_type:

| Type | Behavior | Example |

|------|------|------|

| required | Reports error when value is missing | Name is required |

| pattern | Warning when value does not match pattern | Incorrect format |

| validation | Output rule_description as warning | Custom validation logic |

| range | Warning when value exists | Value range constraint |

| length | Warning when character limit exceeded | Length cannot exceed N |

| inspect | Warning when value exists | Requires manual inspection |

| lifecycle | Output rule_description | Lifecycle rules |

| state_transition | Output rule_description | State transition rules |

| permission_check | Output rule_description | Permission check rules |

4.3 create_related Filtering

In creation process Step 8, only relationships with create_related=1 are automatically created. The relationships output by the LLM must match the createRelated field defined in relTypes (obtained from the typeTemplate API).


5. Data Flow

SCIOT/ 目录 AML 文件
    ↓
import-aml-v2.js(基础导入:23张表 + 规则 + 模板)
    ↓
extract-extended-aml.js(扩展提取:13张表 + 额外规则)
    ↓
generate-operation-rules.js(operation_typeCategory + 关系规则 + 方法规则 + 提示词生成)
    ↓
前端使用(StaffCapabilities.vue)
    ├─ /api/aml/unified/schema/:type → properties + rules + template
    ├─ /api/aml/sciot/prompts?operation_type=add → 提示词
    ├─ sanitizeProperties → 字段修正
    └─ validateProperties → 规则验证(required/pattern/validation/range/length/inspect...)

六、快速参考

6.1 全量重建

node scripts/import-aml-v2.js --full
node scripts/extract-extended-aml.js --full
node scripts/generate-operation-rules.js --full

6.2 常用 SQL

-- 某类型所有规则(按操作类型分组)
SELECT operation_type, rule_type, COUNT(*)
FROM sciot_rules WHERE item_type_name = 'Project' AND is_active = 1
GROUP BY operation_type, rule_type;

-- 某类型的关系规则
SELECT * FROM sciot_rules
WHERE item_type_name = 'Project' AND category = 'relationship';

-- 某类型的提示词
SELECT operation_type, name, LENGTH(content) as len
FROM prompt_templates
WHERE item_type_name = 'Project' AND status = 'active';

-- 某类型可自动创建的关系
SELECT * FROM sciot_relationships
WHERE (name = 'Project' OR related_item_type = 'Project')
  AND create_related = 1;

6.3 新增操作类型

如需支持新的操作类型(如 delete):

  1. Modify the ruleToOp mapping in scripts/generate-operation-rules.js
  2. Add prompt templates for new operation types in generateOperationPrompts()
  3. node scripts/generate-operation-rules.js --full
← 返回案例列表

Try 左帮右臂 Industrial Agent — your digital workforce

Available as a WeChat mini program, web app (ylxt.chat) and desktop client. Start from whichever fits your workflow.

🌐 Web App 💻 Desktop Download 📞 Call 189-8606-6876
WeChat mini program QR
Scan for the WeChat mini program
Share:
🤖 Try Now →
🤖
🎁