69 lines
2.1 KiB
TypeScript
69 lines
2.1 KiB
TypeScript
import { tool } from "@opencode-ai/plugin/tool"
|
|
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')) {
|
|
return !!metadata.skill
|
|
}
|
|
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
|
|
},
|
|
'tool.execute.before': async (opts) => {
|
|
// console.log('CnbPlugin: tool.execute.before', opts.tool);
|
|
// delete toolSkills['cnb-login-verify']
|
|
}
|
|
}
|
|
}
|
|
|
|
const demo = {
|
|
'tool': {
|
|
"cnb-login-verify": {
|
|
name: "CNB 登录验证信息",
|
|
description: "验证 CNB 登录信息是否有效",
|
|
args: {
|
|
checkToken: tool.schema.boolean().describe("是否检查 Token 的有效性").default(true),
|
|
checkCookie: tool.schema.boolean().describe("是否检查 Cookie 的有效性").default(false),
|
|
},
|
|
async execute(args) {
|
|
const res = await app.run({
|
|
path: 'cnb',
|
|
key: 'user-check',
|
|
payload: {
|
|
...args
|
|
}
|
|
}, { appId });
|
|
if (res.code === 200) {
|
|
return res.data?.output;
|
|
}
|
|
return '无法获取登录状态,请检查配置。';
|
|
},
|
|
},
|
|
}
|
|
} |