Files
cnb/agent/routes/repo/repo.ts
xiongxiao 50332fe2f4 feat: update package dependencies and add new routes for CNB environment management
- Updated package.json and pnpm-lock.yaml with new dependencies and versions.
- Removed outdated readme files from requirements.
- Enhanced CNB environment configuration in cnb-env.ts with new VS Code remote SSH settings.
- Modified KnowledgeBase class to return structured results.
- Updated Workspace class to return structured results.
- Implemented new routes for managing CNB cookies and VS Code proxy URIs.
- Added AI chat functionality for querying knowledge base.
- Created skills for cleaning up closed workspaces.
2026-01-27 04:02:34 +08:00

110 lines
3.1 KiB
TypeScript

import { app, cnb } from '../../app.ts';
import { createSkill, Skill } from '@kevisual/router'
import { tool } from "@opencode-ai/plugin/tool"
// 创建一个仓库 kevisual/test-repo
app.route({
path: 'cnb',
key: 'create-repo',
description: '创建代码仓库, 参数name, visibility, description',
middleware: ['auth'],
metadata: {
tags: ['opencode'],
...createSkill({
skill: 'create-repo',
title: '创建代码仓库',
args: {
name: tool.schema.string().describe('代码仓库名称, 如 my-user/my-repo'),
visibility: tool.schema.string().describe('代码仓库可见性, public 或 private').default('public'),
description: tool.schema.string().describe('代码仓库描述'),
},
summary: '创建一个新的代码仓库',
})
}
}).define(async (ctx) => {
const name = ctx.query?.name;
const visibility = ctx.query?.visibility ?? 'public';
const description = ctx.query?.description ?? '';
if (!name) {
ctx.throw(400, '缺少参数 name');
}
try {
const res = await cnb.repo.createRepo({
name,
visibility,
description,
});
ctx.forward(res);
} catch (error) {
ctx.code = 200
ctx.body = { content: 'JS仓库可能已存在' }
}
}).addTo(app);
app.route({
path: 'cnb',
key: 'create-repo-file',
description: '在代码仓库中创建文件, repoName, filePath, content, encoding',
middleware: ['auth'],
metadata: {
tags: ['opencode'],
...createSkill({
skill: 'create-repo-file',
title: '在代码仓库中创建文件',
summary: `在代码仓库中创建文件, encoding 可选,默认 raw`,
args: {
repoName: tool.schema.string().describe('代码仓库名称, 如 my-user/my-repo'),
filePath: tool.schema.string().describe('文件路径, 如 src/index.ts'),
content: tool.schema.string().describe('文本的字符串的内容'),
encoding: tool.schema.string().describe('编码方式,如 raw').optional(),
},
})
}
}).define(async (ctx) => {
const repoName = ctx.query?.repoName;
const filePath = ctx.query?.filePath;
const content = ctx.query?.content;
const encoding = ctx.query?.encoding ?? 'raw';
if (!repoName || !filePath || !content) {
ctx.throw(400, '缺少参数 repoName, filePath 或 content');
}
const res = await cnb.repo.createCommit(repoName, {
message: `添加文件 ${filePath} 通过 API `,
files: [
{ path: filePath, content, encoding },
],
});
ctx.forward(res);
}).addTo(app);
// 删除一个仓库 kevisual/test-repo
app.route({
path: 'cnb',
key: 'delete-repo',
description: '删除代码仓库, 参数name',
middleware: ['auth'],
metadata: {
tags: ['opencode'],
...createSkill({
skill: 'delete-repo',
title: '删除代码仓库',
args: {
name: tool.schema.string().describe('代码仓库名称'),
},
summary: '删除一个代码仓库',
})
}
}).define(async (ctx) => {
const name = ctx.query?.name;
if (!name) {
ctx.throw(400, '缺少参数 name');
}
const res = await cnb.repo.deleteRepo(name);
ctx.forward(res);
}).addTo(app);