script_engine/skill/SKILL.md

2.3 KiB
Raw Blame History

name description
script_engine 逻辑编程(脚本/规则引擎)模块——脚本表 CRUD + execute_script/validate_script 接口,通过 load_script_engine() 挂载。脚本类型 0=Python / 1=SQL。

script_engine 模块

脚本/规则引擎:脚本表(script_engineCRUD + 执行/校验接口。独立模块,无业务依赖。

数据模型

  • script_engineid(str32 PK)、script_name(str100 not null)、script_type(str32 default '0')、content(text not null)、description(str255)、status(str32 default '1')、created_atupdated_at
  • 索引:idx_script_nameidx_script_type
  • 编码:script_type → appcodes_kv parentid='script_type'0=Python1=SQLstatus → appcodes_kv parentid='script_status'0=停用1=启用)

关键接口ServerEnv 注册函数,.dspy 直接调用)

  • create_script / update_script / delete_script / get_script / list_scripts
  • execute_scriptid 或 content+script_type校验后执行
  • validate_script_api(仅校验,不落库不执行)
  • 复数别名 create_scripts/update_scripts/delete_scripts 与单数同实现CRUD 框架约定)

错误结构与分页

  • 统一 {code, message, field, detail}code=0 成功
  • 分页 {list, total}list_scripts 返回 data.list / data.total

REST 接口wwwroot/api/*.dspy

  • script_create.dspy / script_update.dspy / script_delete.dspy / script_get.dspy / script_list.dspy
  • script_execute.dspy / execute_script.dspy / script_validate.dspy / validate_script.dspy
  • get_search_script_type.dspy / get_search_status.dspy下拉 [{value,text}]

陷阱

  • 取库名用 ServerEnv().get_module_dbname('script_engine'),禁止硬编码 DBNAME
  • 非法输入(空名/超长/非法类型/语法错误/受限语法/危险调用100% 拦截,不落库不执行
  • Python 执行受限命名空间:仅内置白名单函数,禁 import/类/λ/async/await/对象方法调用engine.py ast 校验 + 白名单 builtins
  • SQL 仅允许只读单语句SELECT/SHOW/DESCRIBE/EXPLAIN禁写语句/多语句/危险关键字
  • .dspy 无 import/print/uuid/f-string显式 returnhelper 在 init.py
  • init/data.json 为 Format B appcodesparentid + items幂等落库

依赖

  • 无业务依赖;依赖基础包 sqlor / ahserver / appPublic