update
This commit is contained in:
@@ -1,35 +1,69 @@
|
||||
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': {
|
||||
"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 '无法获取登录状态,请检查配置。';
|
||||
},
|
||||
},
|
||||
...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 '无法获取登录状态,请检查配置。';
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { app, appId } from '../app.ts';
|
||||
import './user/check.ts'
|
||||
import './repo/index.ts'
|
||||
import './workspace/index.ts'
|
||||
import { isEqual } from 'es-toolkit'
|
||||
/**
|
||||
* 验证上下文中的 App ID 是否与指定的 App ID 匹配
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { createSkill } from '@kevisual/router';
|
||||
import { app, cnb } from '../../app.ts';
|
||||
import { tool } from '@opencode-ai/plugin/tool';
|
||||
|
||||
|
||||
app.route({
|
||||
@@ -7,27 +9,36 @@ app.route({
|
||||
description: '检查用户登录状态,参数checkToken,default true; checkCookie, default false',
|
||||
middleware: ['auth'],
|
||||
metadata: {
|
||||
tags: ['opencode']
|
||||
tags: ['opencode'],
|
||||
...createSkill({
|
||||
skill: 'cnb-login-verify',
|
||||
title: 'CNB 登录验证信息',
|
||||
summary: '验证 CNB 登录信息是否有效',
|
||||
args: {
|
||||
checkToken: tool.schema.boolean().describe('是否检查 Token 的有效性').default(true),
|
||||
checkCookie: tool.schema.boolean().describe('是否检查 Cookie 的有效性').default(false),
|
||||
},
|
||||
})
|
||||
}
|
||||
}).define(async (ctx) => {
|
||||
const checkToken = ctx.query?.checkToken ?? true;
|
||||
const checkCookie = ctx.query?.checkCookie ?? false;
|
||||
let output = '';
|
||||
let content = '';
|
||||
if (checkToken) {
|
||||
const res = await cnb.user.getUser();
|
||||
if (res?.code !== 200) {
|
||||
output += `Token 无效,请检查 CNB_TOKEN 配置。\n`;
|
||||
content += `Token 无效,请检查 CNB_TOKEN 配置。\n`;
|
||||
} else {
|
||||
output += `Token 有效,Token用户昵称:${res.data?.nickname}\n`;
|
||||
content += `Token 有效,Token用户昵称:${res.data?.nickname}\n`;
|
||||
}
|
||||
}
|
||||
if (checkCookie) {
|
||||
const res = await cnb.user.getCurrentUser();
|
||||
if (res?.code !== 200) {
|
||||
output += `Cookie 无效,请检查 CNB_COOKIE 配置。\n`;
|
||||
content += `Cookie 无效,请检查 CNB_COOKIE 配置。\n`;
|
||||
} else {
|
||||
output += `Cookie 有效,当前Cookie用户:${res.data?.nickname}\n`;
|
||||
content += `Cookie 有效,当前Cookie用户:${res.data?.nickname}\n`;
|
||||
}
|
||||
}
|
||||
ctx.body = { output };
|
||||
ctx.body = { content };
|
||||
}).addTo(app);
|
||||
Reference in New Issue
Block a user