34 lines
1.8 KiB
Markdown
34 lines
1.8 KiB
Markdown
---
|
||
name: script_engine
|
||
description: 逻辑编程(脚本/规则引擎)模块——脚本表 CRUD + execute_script/validate_script 接口,通过 load_script_engine() 挂载。脚本类型 0=Python / 1=JavaScript / 2=规则表达式。
|
||
---
|
||
|
||
# script_engine 模块
|
||
|
||
脚本/规则引擎:脚本表(`script`)CRUD + 执行/校验接口。独立模块,无业务依赖。
|
||
|
||
## 数据模型
|
||
- `script`:`id`(str32 PK)、`script_name`(str100 not null)、`script_type`(str32 default '0')、`content`(text not null)、`description`(str255)、`status`(str32 default '1')、`created_at`、`updated_at`
|
||
- 索引:`idx_script_name`、`idx_script_type`
|
||
- 编码:`script_type` → appcodes_kv parentid='script_type';`status` → appcodes_kv parentid='script_status'
|
||
|
||
## 关键接口(ServerEnv 注册函数,.dspy 直接调用)
|
||
- `create_script / update_script / delete_script / get_script / list_scripts`
|
||
- `execute_script`(id 或 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)
|
||
|
||
## 陷阱
|
||
- 取库名用 `ServerEnv().get_module_dbname('script_engine')`,禁止硬编码 DBNAME
|
||
- 非法输入(空名/超长/非法类型/语法错误/受限语法/危险调用)100% 拦截,不落库不执行
|
||
- Python 执行受限命名空间:仅内置白名单函数,禁 import/类/λ/async/await/对象方法调用
|
||
- .dspy 无 import/print/uuid/f-string,显式 return;helper 在 init.py
|
||
- init/data.json 为 Format B appcodes(parentid + items),幂等落库
|
||
|
||
## 依赖
|
||
- 无业务依赖;依赖基础包 sqlor / ahserver / appPublic
|