Files
cnb/agent/routes/workspace/build.ts

43 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { createSkill, tool } from '@kevisual/router';
import { app, cnbManager, notCNBCheck } from '../../app.ts';
// 启动工作空间
app.route({
path: 'cnb',
key: 'cloud-build',
description: '云端构建,参数 event, repo, branch, ref, config, env',
middleware: ['auth'],
metadata: {
tags: ['opencode'],
...createSkill({
skill: 'cloud-build',
title: '云端构建',
summary: '在云端构建代码仓库,参数包括 event, repo, branch, ref, config, env',
args: {
env: tool.schema.any().optional().describe('构建环境变量,格式为 { "KEY": "VALUE" }'),
event: tool.schema.string().optional().describe('触发事件类型,例如 api_trigger_event'),
branch: tool.schema.string().optional().describe('分支名称,默认主分支'),
config: tool.schema.string().describe('构建config文件内容例如 cloudbuild.yaml对应的yml的内容'),
repo: tool.schema.string().describe('代码仓库路径,例如 user/repo'),
},
})
}
}).define(async (ctx) => {
const cnb = await cnbManager.getContext(ctx);
const repo = ctx.query?.repo;
const branch = ctx.query?.branch || 'main';
const config = ctx.query?.config;
const event = ctx.query?.event || 'api_trigger_event';
const env = ctx.query?.env ?? {};
if (!repo) {
ctx.throw(400, '缺少参数 repo');
}
const res = await cnb.build.startBuild(repo, {
branch,
config,
event,
env,
});
ctx.forward(res);
}).addTo(app);