Skip to content

构建 API

本文档描述了 Trae 构建系统的 API 接口。

概述

构建 API 提供了管理项目构建过程的接口,包括编译、打包和部署功能。

端点

开始构建

http
POST /api/build/start

请求参数

参数类型必需描述
project_idstring项目 ID
branchstring构建分支,默认为 main
configobject构建配置

响应

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();

您的终极 AI 驱动 IDE 学习指南