feat: 更新依赖项,添加 OpenCode 支持,重构代理和路由逻辑,新增 AGENTS 文档
This commit is contained in:
64
assistant/agent/plugin.ts
Normal file
64
assistant/agent/plugin.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { tool } from "@opencode-ai/plugin/tool"
|
||||
import { type Plugin } from "@opencode-ai/plugin"
|
||||
import { app } from './index.ts';
|
||||
import { Skill } from "@kevisual/router";
|
||||
|
||||
import './call.ts';
|
||||
import './step.ts';
|
||||
|
||||
const routes = app.router.routes.filter(r => {
|
||||
const metadata = r.metadata as Skill
|
||||
if (metadata && metadata.tags && metadata.tags.includes('opencode')) {
|
||||
return !!metadata.skill
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
// opencode run "查看系统信息"
|
||||
export const AgentPlugin: Plugin = async ({ project, client, $, directory, worktree }) => {
|
||||
return {
|
||||
'tool': {
|
||||
...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
|
||||
},
|
||||
// @ts-ignore
|
||||
{ appId: app.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);
|
||||
// delete toolSkills['cnb-login-verify']
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user