构建 API
本文档描述了 Trae 构建系统的 API 接口。
概述
构建 API 提供了管理项目构建过程的接口,包括编译、打包和部署功能。
端点
开始构建
http
POST /api/build/start请求参数
| 参数 | 类型 | 必需 | 描述 |
|---|---|---|---|
project_id | string | 是 | 项目 ID |
branch | string | 否 | 构建分支,默认为 main |
config | object | 否 | 构建配置 |
响应
json
{
"build_id": "build_123",
"status": "started",
"timestamp": "2024-01-01T00:00:00Z",
"estimated_duration": 300
}获取构建状态
http
GET /api/build/{build_id}/status响应
json
{
"build_id": "build_123",
"status": "running",
"progress": 45,
"logs": [
{
"timestamp": "2024-01-01T00:00:00Z",
"level": "info",
"message": "开始编译..."
}
]
}停止构建
http
POST /api/build/{build_id}/stop构建状态
pending- 等待中running- 运行中success- 成功failed- 失败cancelled- 已取消
示例
启动构建
javascript
const response = await fetch('/api/build/start', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
project_id: 'my-project',
branch: 'main',
config: {
environment: 'production',
minify: true
}
})
});
const build = await response.json();
console.log('构建已启动:', build.build_id);监控构建进度
javascript
const buildId = 'build_123';
const checkStatus = async () => {
const response = await fetch(`/api/build/${buildId}/status`);
const status = await response.json();
console.log(`构建进度: ${status.progress}%`);
if (status.status === 'running') {
setTimeout(checkStatus, 5000); // 5秒后再次检查
}
};
checkStatus();