{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://static.cloudbase.net/cli/cloudbaserc.schema.json",
  "title": "CloudBase CLI 配置文件",
  "description": "cloudbaserc.json 配置文件的 JSON Schema 定义，用于腾讯云 CloudBase CLI (tcb) 的项目配置。支持 cloudbaserc.json、cloudbaserc.js、cloudbaserc.yaml 等多种格式。",
  "type": "object",
  "required": [],
  "properties": {
    "$schema": {
      "type": "string",
      "description": "JSON Schema 引用地址",
      "examples": ["https://static.cloudbase.net/cli/cloudbaserc.schema.json"]
    },
    "version": {
      "type": "string",
      "description": "配置文件版本",
      "enum": ["2.0"],
      "default": "2.0"
    },
    "envId": {
      "type": "string",
      "description": "云开发环境 ID，支持模板变量 {{env.ENV_ID}}",
      "examples": ["your-env-id", "{{env.ENV_ID}}"]
    },
    "region": {
      "type": "string",
      "description": "环境所在地域",
      "enum": ["ap-shanghai", "ap-guangzhou"],
      "default": "ap-shanghai"
    },
    "functionRoot": {
      "type": "string",
      "description": "云函数代码根目录（相对于项目根目录）",
      "default": "./functions"
    },
    "functionDefaultConfig": {
      "$ref": "#/definitions/CloudFunction",
      "description": "云函数默认配置，会通过 lodash.merge 合并到每个函数配置中。函数自身的同名配置优先级更高。"
    },
    "functions": {
      "type": "array",
      "description": "云函数配置列表",
      "items": {
        "$ref": "#/definitions/CloudFunction"
      }
    },
    "servers": {
      "type": "array",
      "description": "服务器配置列表（Node.js 服务）",
      "items": {
        "$ref": "#/definitions/ServerConfig"
      }
    },
    "app": {
      "$ref": "#/definitions/CloudAppConfig",
      "description": "云应用配置（静态托管部署）"
    },
    "ai": {
      "$ref": "#/definitions/AIConfig",
      "description": "AI 编码助手配置（tcb ai 命令使用）"
    },
    "privateSettings": {
      "$ref": "#/definitions/PrivateSettings",
      "description": "私有化部署配置。设置此字段表示当前为私有化环境。"
    },
    "lowcodeCustomComponents": {
      "type": "object",
      "description": "微搭低代码自定义组件配置",
      "additionalProperties": true
    }
  },
  "additionalProperties": true,
  "definitions": {
    "CloudFunction": {
      "type": "object",
      "description": "云函数配置",
      "required": ["name"],
      "properties": {
        "name": {
          "type": "string",
          "description": "函数名称",
          "pattern": "^[a-zA-Z][a-zA-Z0-9_-]*$"
        },
        "description": {
          "type": "string",
          "description": "函数描述信息"
        },
        "type": {
          "type": "string",
          "description": "函数类型：Event（事件函数）或 HTTP（Web 云函数）",
          "enum": ["Event", "HTTP"],
          "default": "Event"
        },
        "runtime": {
          "type": "string",
          "description": "运行时环境",
          "enum": [
            "Nodejs24.11",
            "Nodejs22.21",
            "Nodejs20.19",
            "Nodejs18.15",
            "Nodejs16.13",
            "Python3.11",
            "Python3.10",
            "Python3.9",
            "Python3.7",
            "Php8.0",
            "Php7.4",
            "Java11",
            "Java8",
            "Go1"
          ],
          "default": "Nodejs18.15"
        },
        "handler": {
          "type": "string",
          "description": "函数入口方法。格式为 文件名.方法名（Node.js/Python/PHP）或 包名.类名::方法名（Java）或 可执行文件名（Go）",
          "default": "index.main",
          "examples": ["index.main", "example.Hello::mainHandler", "main"]
        },
        "timeout": {
          "type": "integer",
          "description": "函数执行超时时间（秒），范围 1-900",
          "minimum": 1,
          "maximum": 900,
          "default": 15
        },
        "memorySize": {
          "type": "integer",
          "description": "函数运行内存（MB）。可选 64MB，或 128-3072MB 且必须是 128 的倍数",
          "examples": [64, 128, 256, 512, 1024, 2048, 3072]
        },
        "dir": {
          "type": "string",
          "description": "函数代码目录路径（相对于项目根目录）。如不指定则默认为 functionRoot/name"
        },
        "envVariables": {
          "type": "object",
          "description": "环境变量，键值对形式",
          "additionalProperties": {
            "oneOf": [
              { "type": "string" },
              { "type": "number" },
              { "type": "boolean" }
            ]
          }
        },
        "vpc": {
          "$ref": "#/definitions/FunctionVPC",
          "description": "VPC 网络配置"
        },
        "installDependency": {
          "type": "boolean",
          "description": "是否在云端自动安装依赖（仅 Node.js 运行时有效）",
          "default": true
        },
        "isWaitInstall": {
          "type": "boolean",
          "description": "是否等待依赖安装完成后再返回"
        },
        "l5": {
          "type": "boolean",
          "description": "是否开启 L5 （内部服务发现）"
        },
        "ignore": {
          "description": "部署时忽略的文件/目录 glob 模式",
          "oneOf": [
            {
              "type": "string"
            },
            {
              "type": "array",
              "items": { "type": "string" }
            }
          ],
          "default": ["node_modules", "node_modules/**/*", ".git"]
        },
        "params": {
          "type": "object",
          "description": "函数参数（键值对）",
          "additionalProperties": {
            "type": "string"
          }
        },
        "config": {
          "$ref": "#/definitions/CloudFunctionConfig",
          "description": "函数运行配置（嵌套形式，也可直接写在函数顶层）"
        },
        "triggers": {
          "type": "array",
          "description": "触发器列表",
          "items": {
            "$ref": "#/definitions/CloudFunctionTrigger"
          }
        },
        "protocolType": {
          "type": "string",
          "description": "协议类型。设置为 'WS' 表示支持 WebSocket，不设置则为普通 HTTP。仅在 type 为 HTTP 时有效。注意：协议类型仅支持在创建函数时设置，后续不可变更。",
          "enum": ["WS"]
        },
        "protocolParams": {
          "type": "object",
          "description": "协议参数，仅 WebSocket 协议生效",
          "properties": {
            "wsParams": {
              "type": "object",
              "description": "WebSocket 参数",
              "properties": {
                "idleTimeOut": {
                  "type": "integer",
                  "description": "空闲超时时间（秒），范围 10-7200",
                  "minimum": 10,
                  "maximum": 7200,
                  "default": 15
                }
              },
              "additionalProperties": false
            }
          },
          "additionalProperties": false
        },
        "instanceConcurrencyConfig": {
          "type": "object",
          "description": "多并发配置，仅 HTTP 函数生效",
          "properties": {
            "dynamicEnabled": {
              "type": "string",
              "description": "是否开启智能动态并发。'TRUE' 表示开启，'FALSE' 表示静态并发。",
              "enum": ["TRUE", "FALSE"]
            },
            "maxConcurrency": {
              "type": "integer",
              "description": "单实例并发数最大值，范围 1-100",
              "minimum": 1,
              "maximum": 100
            }
          },
          "additionalProperties": false
        },
        "imageConfig": {
          "$ref": "#/definitions/FunctionImageConfig",
          "description": "镜像配置（仅当部署方式为 image 时使用）"
        }
      },
      "additionalProperties": false
    },
    "CloudFunctionConfig": {
      "type": "object",
      "description": "函数运行配置（嵌套在 config 字段中的形式）",
      "properties": {
        "timeout": {
          "type": "integer",
          "description": "函数执行超时时间（秒），范围 1-900",
          "minimum": 1,
          "maximum": 900
        },
        "envVariables": {
          "type": "object",
          "description": "环境变量",
          "additionalProperties": {
            "oneOf": [
              { "type": "string" },
              { "type": "number" },
              { "type": "boolean" }
            ]
          }
        },
        "runtime": {
          "type": "string",
          "description": "运行时环境",
          "enum": [
            "Nodejs24.11",
            "Nodejs22.21",
            "Nodejs20.19",
            "Nodejs18.15",
            "Nodejs16.13",
            "Python3.11",
            "Python3.10",
            "Python3.9",
            "Python3.7",
            "Php8.0",
            "Php7.4",
            "Java11",
            "Java8",
            "Go1"
          ]
        },
        "vpc": {
          "$ref": "#/definitions/FunctionVPC"
        },
        "installDependency": {
          "type": "boolean",
          "description": "是否在云端自动安装依赖"
        },
        "l5": {
          "type": "boolean",
          "description": "是否开启 L5"
        }
      },
      "additionalProperties": false
    },
    "CloudFunctionTrigger": {
      "type": "object",
      "description": "云函数触发器配置",
      "required": ["name", "type", "config"],
      "properties": {
        "name": {
          "type": "string",
          "description": "触发器名称"
        },
        "type": {
          "type": "string",
          "description": "触发器类型",
          "enum": ["timer"],
          "examples": ["timer"]
        },
        "config": {
          "type": "string",
          "description": "触发器配置（cron 表达式）",
          "examples": ["0 0 2 1 * * *", "0 */5 * * * * *"]
        }
      },
      "additionalProperties": false
    },
    "FunctionVPC": {
      "type": "object",
      "description": "VPC 网络配置",
      "required": ["vpcId", "subnetId"],
      "properties": {
        "vpcId": {
          "type": "string",
          "description": "VPC ID"
        },
        "subnetId": {
          "type": "string",
          "description": "子网 ID"
        }
      },
      "additionalProperties": false
    },
    "FunctionImageConfig": {
      "type": "object",
      "description": "镜像部署配置",
      "required": ["imageType", "imageUri"],
      "properties": {
        "imageType": {
          "type": "string",
          "description": "镜像类型",
          "enum": ["enterprise", "personal"]
        },
        "imageUri": {
          "type": "string",
          "description": "镜像地址"
        },
        "registryId": {
          "type": "string",
          "description": "镜像仓库 ID（企业版镜像必填）"
        },
        "entryPoint": {
          "type": "string",
          "description": "容器启动命令"
        },
        "command": {
          "type": "string",
          "description": "容器启动参数（已废弃，建议使用 argsList）",
          "deprecated": true
        },
        "args": {
          "type": "string",
          "description": "启动参数（已废弃，建议使用 argsList）",
          "deprecated": true
        },
        "containerImageAccelerate": {
          "type": "boolean",
          "description": "是否开启镜像加速"
        },
        "imagePort": {
          "type": "integer",
          "description": "镜像监听端口",
          "default": 9000
        },
        "commandList": {
          "type": "array",
          "description": "启动命令列表",
          "items": { "type": "string" }
        },
        "argsList": {
          "type": "array",
          "description": "启动参数列表",
          "items": { "type": "string" }
        }
      },
      "additionalProperties": false
    },
    "ServerConfig": {
      "type": "object",
      "description": "服务器配置",
      "required": ["type", "name", "path"],
      "properties": {
        "type": {
          "type": "string",
          "description": "服务器类型",
          "enum": ["node"]
        },
        "name": {
          "type": "string",
          "description": "服务名称"
        },
        "path": {
          "type": "string",
          "description": "服务代码路径"
        }
      },
      "additionalProperties": false
    },
    "CloudAppConfig": {
      "type": "object",
      "description": "云应用配置（静态托管部署）",
      "required": [],
      "properties": {
        "root": {
          "type": "string",
          "description": "应用项目根目录（相对于 cloudbaserc.json 所在目录）。用于 monorepo 场景指定子项目路径。默认为当前目录。",
          "examples": [".", "./packages/web", "./apps/frontend"]
        },
        "serviceName": {
          "type": "string",
          "description": "服务名称"
        },
        "framework": {
          "type": "string",
          "description": "前端框架类型",
          "examples": ["react", "vue", "vite", "next", "nuxt", "angular", "static", "custom"]
        },
        "installCommand": {
          "type": "string",
          "description": "安装命令",
          "default": "npm install",
          "examples": ["npm install", "yarn install", "pnpm install", "bun install"]
        },
        "buildCommand": {
          "type": "string",
          "description": "构建命令",
          "examples": ["npm run build", "yarn build", "pnpm run build"]
        },
        "outputDir": {
          "type": "string",
          "description": "构建产物目录",
          "examples": ["dist", "build", ".next", ".output"]
        },
        "deployPath": {
          "type": "string",
          "description": "部署路径，默认为 /。若部署在非根目录下，请确认项目公共路径配置已设置为相对路径，以确保静态资源能够被正确加载。",
          "default": "/",
          "examples": ["/", "/blog", "/docs"]
        },
        "envVariables": {
          "type": "object",
          "description": "环境变量（非敏感），键值对形式。会在云端构建时注入。敏感信息请通过控制台设置。",
          "additionalProperties": {
            "oneOf": [
              { "type": "string" },
              { "type": "number" },
              { "type": "boolean" }
            ]
          },
          "examples": [{ "NODE_ENV": "production", "VITE_API_BASE": "/api" }]
        },
        "ignore": {
          "description": "打包上传时忽略的文件/目录 glob 模式。默认已排除 node_modules 和 .git，此处配置会追加到默认规则中。",
          "oneOf": [
            {
              "type": "string"
            },
            {
              "type": "array",
              "items": { "type": "string" }
            }
          ],
          "default": ["node_modules", "node_modules/**/*", ".git", ".git/**/*"],
          "examples": [["dist", "test", ".env.local", "*.log"]]
        }
      },
      "additionalProperties": false
    },
    "AIConfig": {
      "type": "object",
      "description": "AI 编码助手配置",
      "required": ["defaultAgent"],
      "properties": {
        "defaultAgent": {
          "type": "string",
          "description": "默认使用的 AI Agent，支持模板变量 {{env.AI_DEFAULT_AGENT}}",
          "oneOf": [
            { "enum": ["claude", "qwen", "codex", "aider", "cursor", "codebuddy"] },
            { "pattern": "^\\{\\{env\\..+\\}\\}$" }
          ],
          "examples": ["claude", "{{env.AI_DEFAULT_AGENT}}"]
        },
        "agents": {
          "type": "object",
          "description": "各 AI Agent 的配置",
          "properties": {
            "claude": {
              "$ref": "#/definitions/ClaudeAgentConfig"
            },
            "qwen": {
              "$ref": "#/definitions/StandardAgentConfig"
            },
            "codex": {
              "$ref": "#/definitions/StandardAgentConfig"
            },
            "aider": {
              "$ref": "#/definitions/AiderAgentConfig"
            },
            "cursor": {
              "$ref": "#/definitions/CursorAgentConfig"
            },
            "codebuddy": {
              "$ref": "#/definitions/CodebuddyAgentConfig"
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "ClaudeAgentConfig": {
      "description": "Claude Code Agent 配置",
      "oneOf": [
        {
          "type": "object",
          "required": ["type"],
          "properties": {
            "type": { "type": "string", "enum": ["none"] }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["type", "baseUrl", "apiKey", "model"],
          "properties": {
            "type": { "type": "string", "enum": ["custom"] },
            "baseUrl": { "type": "string", "description": "API 基础 URL" },
            "apiKey": { "type": "string", "description": "API Key，支持模板变量 {{env.AI_CLAUDE_API_KEY}}" },
            "model": { "type": "string", "description": "模型名称" }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["type", "provider", "model"],
          "properties": {
            "type": { "type": "string", "enum": ["cloudbase"] },
            "provider": { "type": "string", "description": "CloudBase AI Provider（如 kimi-exp, deepseek, longcat）" },
            "model": { "type": "string", "description": "模型名称" },
            "transformer": { "type": "string", "description": "协议转换器（如 deepseek）" }
          },
          "additionalProperties": false
        }
      ]
    },
    "StandardAgentConfig": {
      "description": "标准 Agent 配置（Qwen / Codex 通用）",
      "oneOf": [
        {
          "type": "object",
          "required": ["type"],
          "properties": {
            "type": { "type": "string", "enum": ["none"] }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["type", "baseUrl", "apiKey", "model"],
          "properties": {
            "type": { "type": "string", "enum": ["custom"] },
            "baseUrl": { "type": "string", "description": "API 基础 URL" },
            "apiKey": { "type": "string", "description": "API Key" },
            "model": { "type": "string", "description": "模型名称" }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["type", "provider", "model"],
          "properties": {
            "type": { "type": "string", "enum": ["cloudbase"] },
            "provider": { "type": "string", "description": "CloudBase AI Provider" },
            "model": { "type": "string", "description": "模型名称" }
          },
          "additionalProperties": false
        }
      ]
    },
    "AiderAgentConfig": {
      "description": "Aider Agent 配置（不支持 none 类型）",
      "oneOf": [
        {
          "type": "object",
          "required": ["type", "baseUrl", "apiKey", "model"],
          "properties": {
            "type": { "type": "string", "enum": ["custom"] },
            "baseUrl": { "type": "string", "description": "API 基础 URL" },
            "apiKey": { "type": "string", "description": "API Key" },
            "model": { "type": "string", "description": "模型名称" }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["type", "provider", "model"],
          "properties": {
            "type": { "type": "string", "enum": ["cloudbase"] },
            "provider": { "type": "string", "description": "CloudBase AI Provider" },
            "model": { "type": "string", "description": "模型名称" }
          },
          "additionalProperties": false
        }
      ]
    },
    "CursorAgentConfig": {
      "description": "Cursor CLI Agent 配置（仅支持 none 类型）",
      "type": "object",
      "required": ["type"],
      "properties": {
        "type": { "type": "string", "enum": ["none"] }
      },
      "additionalProperties": false
    },
    "CodebuddyAgentConfig": {
      "description": "CodeBuddy Agent 配置",
      "oneOf": [
        {
          "type": "object",
          "required": ["type"],
          "properties": {
            "type": { "type": "string", "enum": ["none"] }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["type"],
          "properties": {
            "type": { "type": "string", "enum": ["custom"] },
            "apiKey": { "type": "string", "description": "API Key（可选）" }
          },
          "additionalProperties": false
        }
      ]
    },
    "PrivateSettings": {
      "type": "object",
      "description": "私有化部署配置",
      "required": ["credential", "endpoints", "privateUin"],
      "properties": {
        "credential": {
          "$ref": "#/definitions/Credential",
          "description": "私有化环境的认证凭证"
        },
        "endpoints": {
          "type": "object",
          "description": "私有化服务端点",
          "required": ["editor", "cliApi"],
          "properties": {
            "editor": {
              "type": "string",
              "description": "编辑器服务地址",
              "pattern": "^https?://"
            },
            "cliApi": {
              "type": "string",
              "description": "CLI API 服务地址",
              "pattern": "^https?://"
            }
          },
          "additionalProperties": false
        },
        "privateUin": {
          "type": "string",
          "description": "私有化环境 UIN"
        }
      },
      "additionalProperties": false
    },
    "Credential": {
      "type": "object",
      "description": "认证凭证（支持永久密钥和临时密钥）",
      "properties": {
        "secretId": {
          "type": "string",
          "description": "永久密钥 SecretId"
        },
        "secretKey": {
          "type": "string",
          "description": "永久密钥 SecretKey"
        },
        "tmpSecretId": {
          "type": "string",
          "description": "临时密钥 SecretId"
        },
        "tmpSecretKey": {
          "type": "string",
          "description": "临时密钥 SecretKey"
        },
        "tmpToken": {
          "type": "string",
          "description": "临时密钥 Token"
        },
        "tmpExpired": {
          "type": "string",
          "description": "临时密钥过期时间"
        },
        "expired": {
          "type": "string",
          "description": "过期时间"
        },
        "authTime": {
          "type": "string",
          "description": "认证时间"
        },
        "refreshToken": {
          "type": "string",
          "description": "刷新 Token"
        },
        "uin": {
          "type": "string",
          "description": "用户 UIN"
        },
        "hash": {
          "type": "string",
          "description": "凭证哈希"
        }
      },
      "additionalProperties": false
    }
  }
}
