更新代码仓库相关功能,修改 API 参数,添加删除仓库功能,更新文档和测试用例

This commit is contained in:
xiongxiao
2026-01-16 03:46:14 +08:00
parent d85f42d38b
commit f10f588ea5
10 changed files with 208 additions and 45 deletions

View File

@@ -3,6 +3,7 @@ import { type Plugin } from "@opencode-ai/plugin"
import { app, cnb, appId } from './index.ts';
import { } from 'es-toolkit'
import { Skill } from "@kevisual/router";
const routes = app.routes.filter(r => {
const metadata = r.metadata as Skill
if (metadata && metadata.tags && metadata.tags.includes('opencode')) {
@@ -10,30 +11,46 @@ const routes = app.routes.filter(r => {
}
return false
})
const toolSkills = routes.reduce((acc, route) => {
const metadata = route.metadata as Skill
acc[metadata.skill!] = {
name: metadata.title || metadata.skill,
description: metadata.summary || '',
args: metadata.args || {},
async execute(args: Record<string, any>) {
const res = await app.run({
path: route.path,
key: route.key,
payload: args
}, { appId });
return res.data?.content || res.data || res;
}
}
return acc;
}, {} as Record<string, any>);
console.log('CnbPlugin loaded skills:', Object.keys(toolSkills));
// opencode run "请使用 cnb-login-verify 工具验证登录信信息,检查cookie"
export const CnbPlugin: Plugin = async ({ project, client, $, directory, worktree }) => {
return {
'tool': {
...toolSkills
...routes.reduce((acc, route) => {
const metadata = route.metadata as Skill
acc[metadata.skill!] = {
name: metadata.title || metadata.skill,
description: metadata.summary || '',
args: metadata.args || {},
async execute(args: Record<string, any>) {
console.log(`Executing skill ${metadata.skill} with args:`, args);
await client.app.log({
body: {
service: 'cnb',
level: 'info',
message: `Executing skill ${metadata.skill} with args: ${JSON.stringify(args)}`
}
});
const res = await app.run({
path: route.path,
key: route.key,
payload: args
}, { appId });
if (res.code === 200) {
if (res.data?.content) {
return res.data.content;
}
const str = JSON.stringify(res.data || res, null, 2);
if (str.length > 5000) {
return str.slice(0, 5000) + '... (truncated)';
}
return str;
}
return `Error: ${res?.message || '无法获取结果'}`;
}
}
return acc;
}, {} as Record<string, any>)
},
'tool.execute.before': async (opts) => {
// console.log('CnbPlugin: tool.execute.before', opts.tool);