script_engine/README.md

36 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# script_engine 脚本引擎模块W-06
脚本引擎:脚本表 CRUD + `execute_script` / `validate_script` 接口。独立模块,无业务依赖,可与 world / scene / entity 链路并行开发。
## 功能
- **script 表 CRUD**:新增 / 编辑 / 删除 / 详情 / 分页列表
- **execute_script**:按脚本 id 取库内脚本(或直传 content校验通过后执行
- **validate_script**:校验脚本内容(语法 + 受限语法 + 调用白名单),不落库不执行
- **编码字典**`script_type`0=Python / 1=JavaScript / 2=规则表达式)、`script_status`0=停用 / 1=启用)经 init/data.jsonFormat B appcodes幂等落库
## 数据表
- `script`id / script_name / script_type / content / description / status / created_at / updated_at
## 接口约定
- REST 统一前缀:`/api/*`(宿主自动路由 `/script_engine/api/xxx.dspy`
- 错误结构:`{code, message, field, detail}`code=0 成功400 参数错误404 不存在500 内部错误501 类型暂不支持)
- 分页:`{list, total}`
- 非法输入 100% 拦截,不落库、不执行
## 集成
1. `pip install .`
2. 宿主应用 `from script_engine.init import load_script_engine``init()` 内调用 `load_script_engine()`
3. `scripts/load_path.py` 登记 RBAC 路径;宿主 `load_path.py` 兜底
4. `build.sh` 生成 DDL / CRUD UI / 链接 wwwroot
## 接口清单wwwroot/api/
| 路径 | 说明 |
|---|---|
| `/script_engine/api/script_create.dspy` | 新增脚本 |
| `/script_engine/api/script_update.dspy` | 编辑脚本 |
| `/script_engine/api/script_delete.dspy` | 删除脚本 |
| `/script_engine/api/script_get.dspy` | 脚本详情 |
| `/script_engine/api/script_list.dspy` | 分页列表({list,total} |
| `/script_engine/api/script_execute.dspy` | 执行脚本 |
| `/script_engine/api/script_validate.dspy` | 校验脚本 |