diff --git a/.cnb.yml b/.cnb.yml index 56fd294..d097b03 100644 --- a/.cnb.yml +++ b/.cnb.yml @@ -18,8 +18,8 @@ include: stages: - name: "task" script: | - bun install - bun run agent/npc.ts + npm i -g @kevisual/cnb --registry=https://npm.cnb.cool/kevisual/registry/-/packages/ + cloud-npc cnb npc $: vscode: - docker: diff --git a/agent/commander.ts b/agent/cli.ts similarity index 53% rename from agent/commander.ts rename to agent/cli.ts index d51294f..f515d42 100644 --- a/agent/commander.ts +++ b/agent/cli.ts @@ -1,4 +1,4 @@ import { app } from './index.ts'; import { parse } from '@kevisual/router/src/commander.ts'; -parse({ app: app as any, description: 'CNB控制台命令行工具', parse: true }) \ No newline at end of file +parse({ app: app, description: 'CNB控制台命令行工具', parse: true }) \ No newline at end of file diff --git a/agent/npc.ts b/agent/npc.ts index f598230..dc54029 100644 --- a/agent/npc.ts +++ b/agent/npc.ts @@ -1,7 +1,9 @@ import { app } from './index.ts'; +import { parse } from '@kevisual/router/src/commander.ts'; import { useIssueEnv, useCommentEnv, useRepoInfoEnv, IssueLabel } from '../src/index.ts' import { pick } from 'es-toolkit'; +import z from 'zod'; const writeToProcess = (message: string) => { if (process.send) { @@ -36,7 +38,7 @@ const getIssuesLabels = async () => { } -const main = async () => { +const main = async ({ exit }: { exit: (code: number) => void }) => { const repoInfoEnv = useRepoInfoEnv(); const commentEnv = useCommentEnv(); const issueEnv = useIssueEnv(); @@ -56,7 +58,7 @@ const main = async () => { envList.forEach(item => writeToProcess(item)); if (!isComment && !issueLabelsNames.includes('Run')) { writeToProcess('当前 Issue 不包含 Run 标签,跳过执行'); - process.exit(0); + return exit(0); } const messages = [ { @@ -84,11 +86,30 @@ const main = async () => { let _message = result.data.message || [] writeToProcess('执行完成') writeToProcess(JSON.stringify(_message, null, 2)) - process.exit(0) + exit(0); } else { writeToProcess(result.message || '执行错误') - process.exit(1) + exit(1); } } -main(); \ No newline at end of file +app.route({ + path: 'cnb', + key: 'npc', + description: 'CNB智能助手,提供智能建议和帮助, 程序入口', + metadata: { + tags: ['notInNpcAgent'], + args: { + needExit: z.boolean().optional().describe('是否需要在执行完成后退出进程') + } + } +}).define(async (ctx) => { + const exit = (code: number) => { + if (ctx.args.needExit) { + process.exit(code); + } + } + await main({ exit }); +}).addTo(app) + +parse({ app: app, description: 'CNB控制台命令行工具', parse: true }) diff --git a/agent/routes/chat/chat.ts b/agent/routes/chat/chat.ts index 4ad3d8c..2edd357 100644 --- a/agent/routes/chat/chat.ts +++ b/agent/routes/chat/chat.ts @@ -30,9 +30,17 @@ app.route({ role: 'user', content: ctx.args.question }] + const routes = app.routes.filter(route => { + const tags = route.metadata?.tags || []; + if (tags.includes('notInNpcAgent')) { + return false; + } + return true + }); const result = await runAgent({ app, messages: messages, + routes, languageModel: cnbAi(model), token: '', // token: ctx.query.token as string, diff --git a/bin/npc.js b/bin/npc.js new file mode 100644 index 0000000..338724e --- /dev/null +++ b/bin/npc.js @@ -0,0 +1,2 @@ +#!/usr/bin/env bun +import '../dist/npc.js'; \ No newline at end of file diff --git a/bun.config.ts b/bun.config.ts index 1a60b60..4635d65 100644 --- a/bun.config.ts +++ b/bun.config.ts @@ -3,4 +3,5 @@ await buildWithBun({ naming: 'opencode', entry: 'agent/opencode.ts', dts: true } await buildWithBun({ naming: 'keep', entry: 'src/keep.ts', dts: true, target: 'node' }); await buildWithBun({ naming: 'routes', entry: 'agent/index.ts', dts: true }); +await buildWithBun({ naming: 'npc', entry: 'agent/npc.ts', dts: true }); await buildWithBun({ naming: 'cli', entry: 'agent/commander.ts', dts: true, target: 'node' }); \ No newline at end of file diff --git a/package.json b/package.json index 9f08a64..828c350 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/cnb", - "version": "0.0.46", + "version": "0.0.47", "description": "", "main": "index.js", "basename": "/root/cnb", @@ -18,7 +18,8 @@ "keywords": [], "bin": { "cnb": "bin/index.js", - "cloud": "bin/index.js" + "cloud": "bin/index.js", + "cloud-npc": "bin/npc.js" }, "files": [ "dist", @@ -38,7 +39,7 @@ "@kevisual/dts": "^0.0.4", "@kevisual/remote-app": "^0.0.7", "@kevisual/types": "^0.0.12", - "@opencode-ai/plugin": "^1.2.25", + "@opencode-ai/plugin": "^1.2.27", "@types/bun": "^1.3.10", "@types/node": "^25.5.0", "@types/ws": "^8.18.1", @@ -55,11 +56,11 @@ }, "dependencies": { "@kevisual/query": "^0.0.53", - "@kevisual/router": "^0.1.1", + "@kevisual/router": "^0.1.2", "@kevisual/use-config": "^1.0.30", - "@opencode-ai/sdk": "^1.2.25", + "@opencode-ai/sdk": "^1.2.27", "es-toolkit": "^1.45.1", - "nanoid": "^5.1.6", + "nanoid": "^5.1.7", "unstorage": "^1.17.4", "ws": "npm:@kevisual/ws", "zod": "^4.3.6" @@ -74,4 +75,4 @@ "./src/*": "./src/*", "./agent/*": "./agent/*" } -} +} \ No newline at end of file