feat: 更新依赖项,添加 OpenCode 支持,重构代理和路由逻辑,新增 AGENTS 文档
This commit is contained in:
33
assistant/agent/call.ts
Normal file
33
assistant/agent/call.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { createSkill } from '@kevisual/router'
|
||||
import { app } from './index.ts'
|
||||
import { tool } from '@opencode-ai/plugin/tool'
|
||||
|
||||
// "调用 path: router key: list"
|
||||
app.route({
|
||||
path: 'call',
|
||||
key: '',
|
||||
description: '调用',
|
||||
middleware: ['auth'],
|
||||
metadata: {
|
||||
tags: ['opencode'],
|
||||
...createSkill({
|
||||
skill: 'call-app',
|
||||
title: '调用app应用',
|
||||
summary: '调用router的应用, 参数path, key, payload',
|
||||
args: {
|
||||
path: tool.schema.string().describe('应用路径,例如 cnb'),
|
||||
key: tool.schema.string().optional().describe('应用key,例如 list-repos'),
|
||||
payload: tool.schema.object({}).optional().describe('调用参数'),
|
||||
}
|
||||
})
|
||||
},
|
||||
}).define(async (ctx) => {
|
||||
const { path, key = '' } = ctx.query;
|
||||
if (!path) {
|
||||
ctx.throw('路径path不能为空');
|
||||
}
|
||||
const res = await ctx.run({ path, key, payload: ctx.query.payload || {} }, {
|
||||
...ctx
|
||||
});
|
||||
ctx.forward(res);
|
||||
}).addTo(app)
|
||||
3
assistant/agent/index.ts
Normal file
3
assistant/agent/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { app } from '../src/main.ts'
|
||||
|
||||
export { app }
|
||||
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']
|
||||
}
|
||||
}
|
||||
}
|
||||
27
assistant/agent/step.ts
Normal file
27
assistant/agent/step.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { createSkill } from '@kevisual/router'
|
||||
import { app } from './index.ts'
|
||||
import { tool } from '@opencode-ai/plugin/tool'
|
||||
|
||||
// "调用 path: test key: step"
|
||||
app.route({
|
||||
path: 'test',
|
||||
key: 'step',
|
||||
description: '测试步骤调用',
|
||||
metadata: {
|
||||
tags: ['opencode'],
|
||||
...createSkill({
|
||||
skill: 'test-step',
|
||||
title: '获取系统信息',
|
||||
summary: '根据步骤获取系统信息',
|
||||
args: {
|
||||
}
|
||||
})
|
||||
},
|
||||
}).define(async (ctx) => {
|
||||
ctx.body = {
|
||||
context: `执行步骤
|
||||
1. 调用 path: client key: system 获取系统信息
|
||||
2. 调用 path: client key: time 获取当前时间
|
||||
3. 返回结果`,
|
||||
};
|
||||
}).addTo(app)
|
||||
Reference in New Issue
Block a user