diff --git a/.cnb.yml b/.cnb.yml index 7390c5e..7e80fb8 100644 --- a/.cnb.yml +++ b/.cnb.yml @@ -8,7 +8,6 @@ include: TO_URL: git.xiongxiao.me imports: - https://cnb.cool/kevisual/env/-/blob/main/.env.development - - https://cnb.cool/kevisual/env/-/blob/main/.env.test $: vscode: diff --git a/.cnb/template.yml b/.cnb/template.yml index 503672a..92a5531 100644 --- a/.cnb/template.yml +++ b/.cnb/template.yml @@ -104,6 +104,7 @@ else echo "文件不存在" fi + printenv > ~/.env init_stages: - name: '安装依赖' script: | diff --git a/agent/opencode-plugin.ts b/agent/opencode-plugin.ts index 430a558..09dd2de 100644 --- a/agent/opencode-plugin.ts +++ b/agent/opencode-plugin.ts @@ -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) { + 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); +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 '无法获取登录状态,请检查配置。'; + }, + }, + } } \ No newline at end of file diff --git a/agent/routes/index.ts b/agent/routes/index.ts index 7b4614e..e48ed8e 100644 --- a/agent/routes/index.ts +++ b/agent/routes/index.ts @@ -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 匹配 diff --git a/agent/routes/user/check.ts b/agent/routes/user/check.ts index 7b0dc70..80f600d 100644 --- a/agent/routes/user/check.ts +++ b/agent/routes/user/check.ts @@ -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); \ No newline at end of file diff --git a/package.json b/package.json index 52131f7..f5050a8 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "@kevisual/types": "^0.0.11", "@opencode-ai/plugin": "^1.1.21", "@types/bun": "^1.3.6", - "@types/node": "^25.0.8", + "@types/node": "^25.0.9", "dotenv": "^17.2.3" }, "publishConfig": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b996fdb..33f5011 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -40,8 +40,8 @@ importers: specifier: ^1.3.6 version: 1.3.6 '@types/node': - specifier: ^25.0.8 - version: 25.0.8 + specifier: ^25.0.9 + version: 25.0.9 dotenv: specifier: ^17.2.3 version: 17.2.3 @@ -77,8 +77,8 @@ packages: '@types/bun@1.3.6': resolution: {integrity: sha512-uWCv6FO/8LcpREhenN1d1b6fcspAB+cefwD7uti8C8VffIv0Um08TKMn98FynpTiU38+y2dUO55T11NgDt8VAA==} - '@types/node@25.0.8': - resolution: {integrity: sha512-powIePYMmC3ibL0UJ2i2s0WIbq6cg6UyVFQxSCpaPxxzAaziRfimGivjdF943sSGV6RADVbk0Nvlm5P/FB44Zg==} + '@types/node@25.0.9': + resolution: {integrity: sha512-/rpCXHlCWeqClNBwUhDcusJxXYDjZTyE8v5oTO7WbL8eij2nKhUeU89/6xgjU7N4/Vh3He0BtyhJdQbDyhiXAw==} bun-types@1.3.6: resolution: {integrity: sha512-OlFwHcnNV99r//9v5IIOgQ9Uk37gZqrNMCcqEaExdkVq3Avwqok1bJFmvGMCkCE0FqzdY8VMOZpfpR3lwI+CsQ==} @@ -142,13 +142,13 @@ snapshots: dependencies: bun-types: 1.3.6 - '@types/node@25.0.8': + '@types/node@25.0.9': dependencies: undici-types: 7.16.0 bun-types@1.3.6: dependencies: - '@types/node': 25.0.8 + '@types/node': 25.0.9 dotenv@17.2.3: {}