配置文件应位于项目根目录,与
your-project/
├── agent-cloudbase-functions.json ← 配置文件位置
├── package.json
└── src/
└── ...
{
"functionsRoot": "./src",
"functions": [
{
"name": "函数名称",
"directory": "./相对路径",
"source": "入口文件名",
"triggerPath": "/路由路径"
}
]
}
字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
functionsRoot | string | ✅ 是 | 函数代码的根目录,相对于配置文件所在目录。通常为 "./src" |
functions | FunctionConfig[] | ✅ 是 | 函数配置数组,至少需要配置一个函数 |
字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
name | string | ✅ 是 | 函数名称,必须与代码中导出的函数名一致 |
directory | string | ✅ 是 | 函数代码所在的目录,相对于 functionsRoot 。使用 "./" 表示根目录 |
source | string | ✅ 是 | 入口文件名,通常是 "index.js" |
triggerPath | string | ✅ 是 | HTTP 触发路径,必须以 / 开头。例如:"/" 、"/user/profile" |
注意:
triggerPath必须唯一,不能有重复的路由路径。
{
"functionsRoot": "./src",
"functions": [
{
"name": "main",
"directory": "./",
"source": "index.js",
"triggerPath": "/"
}
]
}
{
"functionsRoot": "./src",
"functions": [
{
"name": "userProfile",
"directory": "./user",
"source": "index.js",
"triggerPath": "/user/profile"
},
{
"name": "booksList",
"directory": "./books",
"source": "index.js",
"triggerPath": "/books/list"
}
]
}
在
{
"version": "1.0.0",
"description": "智能体模板",
"scripts": {
"dev": "rcb-ff"
},
"dependencies": {
"@vectorx/functions-framework": "latest"
}
}
字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
version | string | ❌ 否 | 项目版本号,遵循 semver 规范(如 "1.0.0" ) |
description | string | ❌ 否 | 项目描述信息 |
scripts | object | ❌ 否 | 脚本命令, "dev": "rcb-ff" 用于启动本地开发服务器 |
dependencies | object | ✅ 是 | 项目依赖,必须包含 @vectorx/functions-framework |
函数必须按照配置的
// src/index.js(对应 name: "main")
exports.main = async (req, res) => {
res.json({ message: "Hello World" });
};
// src/user/index.js(对应 name: "userProfile")
exports.userProfile = async (req, res) => {
res.json({ user: { name: "Alice" } });
};
示例: