@carfiedli/runtime-guardrail 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.fe.md +256 -0
  2. package/README.hooks-security.md +1017 -0
  3. package/README.md +1316 -0
  4. package/dist/adapters/index.d.ts +1 -0
  5. package/dist/adapters/persistence/file-store.d.ts +18 -0
  6. package/dist/adapters/persistence/index.d.ts +4 -0
  7. package/dist/adapters/persistence/json-event-log.d.ts +31 -0
  8. package/dist/adapters/persistence/queue-store.d.ts +19 -0
  9. package/dist/adapters/persistence/snapshot-store.d.ts +14 -0
  10. package/dist/approval/approval-service.d.ts +27 -0
  11. package/dist/approval/approval-state-machine.d.ts +5 -0
  12. package/dist/approval/hitl/hitl-connector.d.ts +9 -0
  13. package/dist/approval/index.d.ts +4 -0
  14. package/dist/approval/run-hold-service.d.ts +16 -0
  15. package/dist/audit/audit-event-store.d.ts +12 -0
  16. package/dist/audit/audit-read-model-builder.d.ts +17 -0
  17. package/dist/audit/audit-service.d.ts +18 -0
  18. package/dist/audit/incident-query-service.d.ts +7 -0
  19. package/dist/audit/index.d.ts +5 -0
  20. package/dist/audit/metrics-projection.d.ts +10 -0
  21. package/dist/bootstrap/create-runtime-guardrail-plugin.d.ts +3 -0
  22. package/dist/bootstrap/dependency-container.d.ts +2 -0
  23. package/dist/bootstrap/index.d.ts +3 -0
  24. package/dist/bootstrap/runtime-facade.d.ts +31 -0
  25. package/dist/compat/index.d.ts +1 -0
  26. package/dist/compat/legacy-types.d.ts +29 -0
  27. package/dist/contracts/core.d.ts +277 -0
  28. package/dist/contracts/events.d.ts +35 -0
  29. package/dist/contracts/host.d.ts +239 -0
  30. package/dist/contracts/index.d.ts +6 -0
  31. package/dist/contracts/operator.d.ts +110 -0
  32. package/dist/execution/egress-mediator.d.ts +7 -0
  33. package/dist/execution/execution-broker.d.ts +13 -0
  34. package/dist/execution/execution-plan-builder.d.ts +12 -0
  35. package/dist/execution/index.d.ts +4 -0
  36. package/dist/execution/model-governance-service.d.ts +7 -0
  37. package/dist/index.d.ts +29 -0
  38. package/dist/index.js +23 -0
  39. package/dist/openclaw/hooks/egress-adapter.d.ts +9 -0
  40. package/dist/openclaw/hooks/hook-registry.d.ts +21 -0
  41. package/dist/openclaw/hooks/hook-result-mapper.d.ts +43 -0
  42. package/dist/openclaw/hooks/hook-types.d.ts +31 -0
  43. package/dist/openclaw/hooks/index.d.ts +8 -0
  44. package/dist/openclaw/hooks/ingress-adapter.d.ts +14 -0
  45. package/dist/openclaw/hooks/llm-request-adapter.d.ts +9 -0
  46. package/dist/openclaw/hooks/persist-adapter.d.ts +30 -0
  47. package/dist/openclaw/hooks/tool-call-adapter.d.ts +7 -0
  48. package/dist/openclaw/index.d.ts +4 -0
  49. package/dist/openclaw/plugin-runtime.d.ts +103 -0
  50. package/dist/openclaw/rpc-handlers.d.ts +20 -0
  51. package/dist/openclaw/skills-availability.d.ts +10 -0
  52. package/dist/openclaw/skills-upload.d.ts +17 -0
  53. package/dist/openclaw/testing/index.d.ts +1 -0
  54. package/dist/openclaw/testing/mock-openclaw-api.d.ts +74 -0
  55. package/dist/operator/cli/register-cli.d.ts +4 -0
  56. package/dist/operator/command-service.d.ts +15 -0
  57. package/dist/operator/index.d.ts +5 -0
  58. package/dist/operator/query-service.d.ts +21 -0
  59. package/dist/operator/reporting/report-service.d.ts +9 -0
  60. package/dist/operator/rpc/register-rpc.d.ts +5 -0
  61. package/dist/policy/detectors/detector-port.d.ts +23 -0
  62. package/dist/policy/finding-normalizer.d.ts +3 -0
  63. package/dist/policy/index.d.ts +4 -0
  64. package/dist/policy/policy-engine.d.ts +8 -0
  65. package/dist/policy/stage-resolver.d.ts +7 -0
  66. package/dist/runtime-core/device-id.d.ts +15 -0
  67. package/dist/runtime-core/evaluate-service.d.ts +91 -0
  68. package/dist/runtime-core/index.d.ts +10 -0
  69. package/dist/runtime-core/memory-audit-logger.d.ts +55 -0
  70. package/dist/runtime-core/memory-store.d.ts +141 -0
  71. package/dist/runtime-core/remote-guard-request-builder.d.ts +15 -0
  72. package/dist/runtime-core/remote-guard-transport.d.ts +79 -0
  73. package/dist/runtime-core/remote-guard-types.d.ts +183 -0
  74. package/dist/runtime-core/remote-policy-evaluator.d.ts +51 -0
  75. package/dist/runtime-core/skill-name-resolver.d.ts +31 -0
  76. package/dist/runtime-core/sync-remote-evaluate.d.ts +29 -0
  77. package/dist/runtime-core/sync-remote-worker.d.ts +14 -0
  78. package/dist/runtime-core/sync-remote-worker.js +2 -0
  79. package/dist/runtime-core/telemetry-service.d.ts +94 -0
  80. package/dist/runtime-core/telemetry-types.d.ts +181 -0
  81. package/dist/types.d.ts +224 -0
  82. package/dist/version.d.ts +1 -0
  83. package/openclaw.plugin.json +76 -0
  84. package/package.json +71 -0
  85. package/remote-guard-config.json +30 -0
  86. package/scripts/runtime-guardrailctl.mjs +864 -0
package/README.fe.md ADDED
@@ -0,0 +1,256 @@
1
+ # AI Guardrails 前端开发指南
2
+
3
+ > 本文档面向参与 `frontend/` 目录开发的工程师,涵盖环境搭建、项目架构、开发规范、新增页面流程与部署说明。
4
+
5
+ ---
6
+
7
+ ## 目录
8
+
9
+ - [1. 项目概述](#1-项目概述)
10
+ - [2. 技术栈](#2-技术栈)
11
+ - [3. 开发流程](#3-开发流程)
12
+ - [4. 项目结构](#4-项目结构)
13
+ - [5. 架构设计](#5-架构设计)
14
+ - [6. 常见问题](#13-常见问题)
15
+
16
+ ---
17
+
18
+ ## 1. 项目概述
19
+
20
+ **AI Guardrails Console** 是 AI 安全护栏管理控制台的前端项目,基于腾讯 **Tea 框架** 构建。提供安全态势总览、防护策略配置、日志审计等功能模块的管理界面。
21
+
22
+ | 属性 | 值 |
23
+ |------|-----|
24
+ | 包名 | `@tencent/tea-app-runtime-guardrails` |
25
+ | 框架 | Tea App(基于 React 16 + react-router-dom v5) |
26
+ | UI 库 | `@tencent/tea-component ^2.8.5` |
27
+ | 状态管理 | `zustand ^4.5.7` |
28
+ | 构建工具 | `@tencent/tea-scripts ^2.1.27` |
29
+
30
+ ---
31
+
32
+ ## 2. 技术栈
33
+
34
+ | 技术 | 版本 | 说明 |
35
+ |------|------|------|
36
+ | React | ^16.11.0 | UI 框架 |
37
+ | TypeScript | ^3.8.2 | 类型系统 |
38
+ | react-router-dom | ^5.2.0 | 客户端路由 |
39
+ | @tencent/tea-component | ^2.8.5 | Tea UI 组件库 |
40
+ | zustand | ^4.5.7 | 轻量级状态管理 |
41
+ | history | ^4.9.0 | 浏览器历史管理 |
42
+ | moment | ^2.24.0 | 日期时间处理 |
43
+ | Less | — | CSS 预处理器 |
44
+
45
+ ---
46
+
47
+ ## 3. 开发流程
48
+
49
+ ### 3.1 前置条件
50
+
51
+ - **Node.js**: 建议 v16+
52
+ - **tea-cli**: Tea 框架命令行工具
53
+
54
+ ### 3.2 安装 tea-cli
55
+
56
+ ```bash
57
+ npm i @tencent/tea-cli -g --registry=https://mirrors.tencent.com/npm/
58
+ ```
59
+ 使用 Tea 命令行工具前需要进行注册
60
+ [<token> 请点此获取](https://tea.tencent.com/developer)
61
+ 获取后,执行: tea login Token 登录成功后,才能使用tea cli工具执行前端开发
62
+
63
+ ### 3.3 安装依赖
64
+
65
+ ```bash
66
+ cd frontend
67
+ npm install
68
+ ```
69
+
70
+ > 项目配置了 `.npmrc`,npm 源指向 `https://mirrors.tencent.com/npm/`。
71
+
72
+ ### 3.4 启动开发服务器
73
+
74
+ ```bash
75
+ # 在frontend/ 目录执行:
76
+ npm run dev
77
+
78
+ # 或在项目根目录执行
79
+ npm run fe
80
+ ```
81
+
82
+ ### 3.5 使用whistle代理线上静态文件
83
+
84
+ 代理规则:
85
+
86
+ ```bash
87
+ /\/(runtime-guardrails)\.(\w{10})?\.(js|css)/ http://127.0.0.1:8322/$1.$3
88
+ ```
89
+ 此时,访问 https://ai-guard.woa.com/base/ 就能看到代理后的页面渲染效果
90
+
91
+
92
+ ### 3.6. 线上部署
93
+
94
+ 流水线地址: https://zhiyan.woa.com/qci/7038/pipeline/#/pipeline/detail/11655977/build/current
95
+
96
+
97
+ ## 4. 项目结构
98
+
99
+ ```
100
+ frontend/
101
+ ├── tea.config.js # Tea 构建配置(webpack 自定义)
102
+ ├── tsconfig.json # TypeScript 配置
103
+ ├── package.json # 依赖管理与脚本
104
+ ├── public/
105
+ │ └── index.html # HTML 模板
106
+
107
+ ├── app/ # 📦 框架层(别名 @tea/app)
108
+ │ ├── app.tsx # 核心 App 组件,路由渲染入口
109
+ │ ├── index.ts # 框架层导出入口
110
+ │ ├── history-context.ts # History Context + useHistory hook
111
+ │ ├── types.ts # 菜单/路由类型定义
112
+ │ ├── components/
113
+ │ │ ├── Layout.tsx # 全局布局(Header + Sider + Body)
114
+ │ │ ├── Menu.tsx # 左侧导航菜单
115
+ │ │ ├── UserMenu.tsx # 顶部右侧用户菜单
116
+ │ │ └── VersionBubble.tsx # 右下角版本切换浮动气泡
117
+ │ ├── hooks/
118
+ │ │ └── useUserInfo.ts # 用户信息消费 hook
119
+ │ └── stores/
120
+ │ └── useUserStore.ts # 用户状态 Zustand store
121
+
122
+ ├── src/ # 📦 业务层(别名 @src/*)
123
+ │ ├── app.ts # 业务入口(路由注册 + 样式导入)
124
+ │ ├── app.less # 全局样式
125
+ │ ├── configs/
126
+ │ │ └── menu.ts # 左侧导航菜单配置
127
+ │ ├── utils/
128
+ │ │ ├── request.ts # 通用请求方法 clawRequest
129
+ │ │ └── utils.ts # 工具函数(uuid)
130
+ │ ├── components/ # 公共业务组件
131
+ │ │ ├── ServiceContext/ # 全局 Service 选择上下文
132
+ │ │ ├── BatchOperation/ # 批量操作组件 + Hook
133
+ │ │ └── Skeleton/ # 骨架屏组件
134
+ │ ├── routes/ # 业务路由/页面模块
135
+ │ │ ├── dashboard/ # 安全态势总览
136
+ │ │ ├── deploy-nodes/ # 部署节点管理
137
+ │ │ ├── api-keys/ # API Keys 管理
138
+ │ │ ├── installation/ # 安装方式
139
+ │ │ ├── manual-review/ # 人工审核队列
140
+ │ │ ├── llm-protection/ # LLM 推理防护
141
+ │ │ ├── toolcall-protection/ # Tool Call 防护
142
+ │ │ ├── skills-protection/ # Skills 防护
143
+ │ │ ├── dlp-rules/ # DLP 规则
144
+ │ │ ├── log-analysis/ # 日志分析
145
+ │ │ ├── audit-logs/ # 审计日志
146
+ │ │ └── system-settings/ # 系统设置
147
+ │ ├── static/icons/ # SVG/PNG 图标资源
148
+ │ └── types/
149
+ │ └── assets.d.ts # 静态资源类型声明
150
+
151
+ └── vanilla/ # 原型版 HTML(通过 sync.sh 同步)
152
+ ```
153
+
154
+ ### 路径别名
155
+
156
+ 在 `tsconfig.json` 中配置了以下别名,import 时可直接使用:
157
+
158
+ | 别名 | 对应路径 | 用途 |
159
+ |------|---------|------|
160
+ | `@tea/app` | `app/` | 框架层模块 |
161
+ | `@tea/app/*` | `app/*` | 框架层子模块 |
162
+ | `@src/*` | `src/*` | 业务层模块 |
163
+
164
+ ---
165
+
166
+ ## 5. 架构设计
167
+
168
+ ### 5.1 分层架构
169
+
170
+ 项目采用**双层架构**设计:
171
+
172
+ ```
173
+ ┌─────────────────────────────────────────────┐
174
+ │ app/ — 框架层(Shell) │
175
+ │ • 路由系统、布局、History、用户状态管理 │
176
+ │ • 不含业务逻辑,仅提供基础设施 │
177
+ ├─────────────────────────────────────────────┤
178
+ │ src/ — 业务层 │
179
+ │ • 页面模块、业务组件、API 调用、样式 │
180
+ │ • 调用 app.routes() 注册路由到框架层 │
181
+ └─────────────────────────────────────────────┘
182
+ ```
183
+
184
+ **数据流**:
185
+ 1. `src/app.ts` 导入所有路由组件和菜单配置
186
+ 2. 调用 `app.routes(routes, menu)` 注册到框架层
187
+ 3. 框架层 `app/app.tsx` 创建 Router、Layout 并渲染
188
+
189
+ ### 5.2 路由系统
190
+
191
+ 路由采用**扁平一级路由**设计,在 `src/app.ts` 中集中注册:
192
+
193
+ ```typescript
194
+ // src/app.ts
195
+ const routes = {
196
+ "/": Dashboard,
197
+ "/deploy-nodes": DeployNodes,
198
+ "/api-keys": ApiKeys,
199
+ // ...
200
+ };
201
+ app.routes(routes, menu);
202
+ ```
203
+
204
+ **注意**:框架层强制只允许一级路由(有校验逻辑),不支持 `/a/b` 形式。如需模块内二级路由,请在页面组件内部使用 `react-router-dom` 的 `Switch/Route`。
205
+
206
+ ### 5.3 状态管理
207
+
208
+ | 状态类型 | 方案 | 使用方式 |
209
+ |---------|------|---------|
210
+ | 全局用户信息 | Zustand store | `useUserStore()` / `useUserInfo()` |
211
+ | Service 选择上下文 | React Context | `useServiceContext()` / `<ServiceSelector />` |
212
+ | 页面局部状态 | React useState | 组件内自行管理 |
213
+
214
+ ### 5.4 ServiceContext 机制
215
+
216
+ 部分页面需要关联特定 Service(如防护策略配置类页面),通过 `withServiceContext` HOC 实现:
217
+
218
+ ```
219
+ withServiceContext(MyPage)
220
+ └─> ServiceProvider # 自动加载 service 列表
221
+ └─> ServiceGate # loading → 骨架屏,error → 错误提示
222
+ └─> MyPage # 正常渲染,通过 useServiceContext() 获取 serviceId
223
+ ```
224
+
225
+ 使用此模式的页面:`llm-protection`、`toolcall-protection`、`skills-protection`、`dlp-rules`、`system-settings`。
226
+
227
+ ---
228
+
229
+
230
+ ## 6. 常见问题
231
+
232
+ ### Q: 页面白屏,控制台无报错?
233
+
234
+ 检查路由是否在 `src/app.ts` 中注册,以及组件是否正确导出。框架层默认将未匹配路由重定向到 `/`。
235
+
236
+ ### Q: useServiceContext 报错 "must be used within a ServiceProvider"?
237
+
238
+ 确保页面通过 `withServiceContext` HOC 包装导出,否则无法使用 `useServiceContext()`。
239
+
240
+ ### Q: 如何调试 API 请求?
241
+
242
+ `clawRequest` 默认发送 POST 请求,可在浏览器 Network 面板中查看。请求体中包含 `Action` 和 `RequestId` 字段。
243
+
244
+ ### Q: 本地开发时路由访问 404?
245
+
246
+ 开发环境的 basename 为 `/base`,请确保访问 `http://localhost:3000/base/...` 而非 `http://localhost:3000/...`。
247
+
248
+ ### Q: 新增的图标不显示?
249
+
250
+ 1. 确认 SVG/PNG 文件放在 `src/static/icons/` 目录下
251
+ 2. 确认 `src/types/assets.d.ts` 已声明对应的模块类型
252
+ 3. 使用 `import icon from "@src/static/icons/my-icon.svg"` 导入
253
+
254
+ ### Q: tea dev 报错 "Cannot read property 'endsWith' of undefined"?
255
+
256
+ `tea.config.js` 中的 `TEA_PUBLIC_PATH` 环境变量未设置。请使用 `npm run dev`(已通过 `cross-env` 注入),或手动添加默认值。