Skip to content

Commit 50b94ff

Browse files
author
tangyicong
committed
docs: 更新 Git 克隆和模板创建文档,增加新选项和示例
1 parent 1ffe323 commit 50b94ff

File tree

64 files changed

+21467
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+21467
-0
lines changed

docs/TamDocs/业务开发/Midscene/server/ACTIONS_ARCHITECTURE.md

Lines changed: 601 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Action 配置快速参考
2+
3+
## 配置文件位置
4+
5+
`src/config/clientTypeActions.ts`
6+
7+
## 当前配置
8+
9+
### Web 端支持的 Actions
10+
11+
| Action | 名称 | 描述 | 类别 |
12+
|--------|------|------|------|
13+
| `CONNECT_TAB` | 连接标签页 | 连接浏览器标签页 | 系统 |
14+
| `AI` | AI 执行 | 执行 AI 自然语言指令 | 基础 |
15+
| `AI_SCRIPT` | AI 脚本 | 执行 AI YAML 脚本 | 高级 |
16+
| `DOWNLOAD_VIDEO` | 下载视频 | 下载视频资源 | 高级 |
17+
| `SITE_SCRIPT` | 站点脚本 | 在网页中执行 JavaScript | 高级 |
18+
| `COMMAND` | 服务命令 | 控制服务生命周期 | 系统 |
19+
20+
**总计:6 个操作**
21+
22+
### Windows 端支持的 Actions
23+
24+
| Action | 名称 | 描述 | 类别 |
25+
|--------|------|------|------|
26+
| `AI` | AI 执行 | 执行 Windows 桌面 AI 指令 | 基础 |
27+
| `AI_SCRIPT` | AI 脚本 | 执行 Windows AI YAML 脚本 | 高级 |
28+
| `COMMAND` | 服务命令 | 控制 Windows 服务 | 系统 |
29+
30+
**总计:3 个操作**
31+
32+
## 快速添加新 Action
33+
34+
### 1. 编辑配置文件
35+
36+
```typescript
37+
// src/config/clientTypeActions.ts
38+
39+
export const CLIENT_TYPE_ACTIONS = {
40+
web: [
41+
// ... 现有配置
42+
{
43+
action: WebSocketAction.YOUR_NEW_ACTION, // ← 添加这里
44+
name: '你的新功能',
45+
description: '详细描述',
46+
category: 'advanced', // basic | advanced | system
47+
},
48+
],
49+
};
50+
```
51+
52+
### 2. 重启服务器
53+
54+
```bash
55+
# 在 apps/server 目录
56+
pnpm dev
57+
```
58+
59+
### 3. 刷新 Web 页面
60+
61+
ActionSelector 会自动显示新 action!
62+
63+
## API 快速测试
64+
65+
```bash
66+
# 获取完整配置
67+
curl http://localhost:3000/api/client-type-actions
68+
69+
# 获取 Web 端配置
70+
curl http://localhost:3000/api/client-type-actions/web
71+
72+
# 获取 Windows 端配置
73+
curl http://localhost:3000/api/client-type-actions/windows
74+
75+
# 获取客户端类型列表
76+
curl http://localhost:3000/api/client-type-actions/types
77+
```
78+
79+
## 工具函数速查
80+
81+
### 服务端
82+
83+
```typescript
84+
import {
85+
getSupportedActions, // 获取 action 列表
86+
getActionConfigs, // 获取完整配置
87+
isActionSupported, // 检查是否支持
88+
validateMessageAction, // 验证消息
89+
} from '../config/clientTypeActions';
90+
91+
// 示例
92+
const actions = getSupportedActions('web');
93+
const supported = isActionSupported('windows', 'connectTab');
94+
const result = validateMessageAction('web', 'ai');
95+
```
96+
97+
### Web 端
98+
99+
```typescript
100+
import { useClientTypeActions } from '@/hooks/useClientTypeActions';
101+
102+
const {
103+
getActionsForClientType,
104+
isActionSupported,
105+
getActionsByCategory,
106+
} = useClientTypeActions();
107+
108+
// 示例
109+
const webActions = getActionsForClientType('web');
110+
const { basic, advanced, system } = getActionsByCategory('windows');
111+
```
112+
113+
## 分类说明
114+
115+
| 类别 | 用途 | 示例 |
116+
|------|------|------|
117+
| `basic` | 基础功能,常用操作 | AI 执行 |
118+
| `advanced` | 高级功能,复杂操作 | AI 脚本、视频下载 |
119+
| `system` | 系统功能,服务控制 | 连接标签页、服务命令 |
120+
121+
## 常见问题
122+
123+
**Q: 如何让 Web 和 Windows 都支持同一个 action?**
124+
125+
A: 在两个配置中都添加:
126+
127+
```typescript
128+
const aiActionConfig = {
129+
action: WebSocketAction.AI,
130+
name: 'AI 执行',
131+
category: 'basic',
132+
};
133+
134+
export const CLIENT_TYPE_ACTIONS = {
135+
web: [
136+
{ ...aiActionConfig, description: 'Web AI 指令' },
137+
// ...
138+
],
139+
windows: [
140+
{ ...aiActionConfig, description: 'Windows AI 指令' },
141+
// ...
142+
],
143+
};
144+
```
145+
146+
**Q: 如何禁用某个 action?**
147+
148+
A: 从配置中移除该 action,然后重启服务器。
149+
150+
**Q: Web 端多久同步一次配置?**
151+
152+
A: 页面加载时同步一次。如需重新同步,刷新页面即可。
153+
154+
**Q: 可以添加自定义分类吗?**
155+
156+
A: 可以,修改 `category` 类型定义并更新相关代码。
157+
158+
## 相关文档
159+
160+
- [CLIENT_TYPE_ACTION_VALIDATION.md](./CLIENT_TYPE_ACTION_VALIDATION.md) - 详细技术文档
161+
- [CLIENT_TYPE_FEATURE.md](./CLIENT_TYPE_FEATURE.md) - 客户端类型功能
162+
- [ACTIONS_ARCHITECTURE.md](./ACTIONS_ARCHITECTURE.md) - Actions 架构
163+
164+
---
165+
166+
**最后更新:** 2025-10-13
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# 构建方案对比
2+
3+
## 🔄 之前(tsc + 手动脚本)
4+
5+
```bash
6+
# 构建流程
7+
tsc → fix-imports.js → 准备部署文件
8+
9+
# Scripts 数量: 9+ 个
10+
# 文件:
11+
- tsconfig.json
12+
- scripts/fix-imports.js
13+
- scripts/create-*.js (7个)
14+
```
15+
16+
### 问题
17+
18+
❌ 构建步骤分散
19+
❌ 需要手动修复导入路径
20+
❌ 配置文件多
21+
❌ 维护成本高
22+
23+
---
24+
25+
## ✨ 现在(tsup)
26+
27+
```bash
28+
# 构建流程
29+
tsup (自动编译 + 自动修复导入) → 准备部署文件
30+
31+
# Scripts 数量: 8 个(减少1个)
32+
# 文件:
33+
- tsconfig.json
34+
- tsup.config.ts (新增,集成了修复逻辑)
35+
- scripts/create-*.js (7个,不变)
36+
```
37+
38+
### 优势
39+
40+
✅ 构建更快(基于 esbuild)
41+
✅ 自动修复导入路径(集成在配置中)
42+
✅ 配置集中管理
43+
✅ 代码更简洁
44+
✅ 更好的开发体验(watch mode, sourcemap)
45+
46+
---
47+
48+
## 📊 性能对比
49+
50+
| 指标 | 之前 (tsc) | 现在 (tsup) | 提升 |
51+
|------|-----------|------------|------|
52+
| 编译速度 | ~2-3s | ~70-300ms | **10x+** |
53+
| 构建步骤 | 3步 | 2步 | 简化 |
54+
| 脚本文件 | 9个 | 8个 | -1 |
55+
| 配置复杂度 | 分散 | 集中 | ⬇️ |
56+
57+
---
58+
59+
## 🎯 构建产物对比
60+
61+
### 相同点 ✅
62+
63+
- 63 个 .js 文件
64+
- 保持原始目录结构
65+
- 包含所有必要的配置文件
66+
- ESM 导入路径正确(带 .js 扩展名)
67+
- 支持同样的部署方式
68+
69+
### 改进点 ⭐
70+
71+
- 可选的 sourcemap(便于调试)
72+
- 更快的构建速度
73+
- 更好的错误提示
74+
- 支持 watch 模式
75+
76+
---
77+
78+
## 📦 使用对比
79+
80+
### 构建命令(完全相同)
81+
82+
```bash
83+
# Staging 环境
84+
npm run build:staging
85+
86+
# Production 环境
87+
npm run build:prod
88+
```
89+
90+
### 运行方式(完全相同)
91+
92+
```bash
93+
npm start
94+
#
95+
cd dist/server && node index.js
96+
```
97+
98+
---
99+
100+
## 🎉 结论
101+
102+
**迁移成功**: 打包效果一致或更好
103+
**向后兼容**: 使用方式完全相同
104+
**性能提升**: 构建速度显著提升
105+
**代码质量**: 更简洁、更易维护
106+
**开发体验**: 更现代的工具链
107+
108+
**推荐**: 继续使用 tsup 方案 ⭐⭐⭐⭐⭐

0 commit comments

Comments
 (0)