@kevisual/cnb 0.0.46 → 0.0.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
1
  import { app } from './index.ts';
2
2
  import { parse } from '@kevisual/router/src/commander.ts';
3
3
 
4
- parse({ app: app as any, description: 'CNB控制台命令行工具', parse: true })
4
+ parse({ app: app, description: 'CNB控制台命令行工具', parse: true })
package/agent/npc.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { app } from './index.ts';
2
+ import { parse } from '@kevisual/router/src/commander.ts';
2
3
 
3
4
  import { useIssueEnv, useCommentEnv, useRepoInfoEnv, IssueLabel } from '../src/index.ts'
4
5
  import { pick } from 'es-toolkit';
6
+ import z from 'zod';
5
7
 
6
8
  const writeToProcess = (message: string) => {
7
9
  if (process.send) {
@@ -36,7 +38,7 @@ const getIssuesLabels = async () => {
36
38
 
37
39
  }
38
40
 
39
- const main = async () => {
41
+ const main = async ({ exit }: { exit: (code: number) => void }) => {
40
42
  const repoInfoEnv = useRepoInfoEnv();
41
43
  const commentEnv = useCommentEnv();
42
44
  const issueEnv = useIssueEnv();
@@ -56,7 +58,7 @@ const main = async () => {
56
58
  envList.forEach(item => writeToProcess(item));
57
59
  if (!isComment && !issueLabelsNames.includes('Run')) {
58
60
  writeToProcess('当前 Issue 不包含 Run 标签,跳过执行');
59
- process.exit(0);
61
+ return exit(0);
60
62
  }
61
63
  const messages = [
62
64
  {
@@ -84,11 +86,30 @@ const main = async () => {
84
86
  let _message = result.data.message || []
85
87
  writeToProcess('执行完成')
86
88
  writeToProcess(JSON.stringify(_message, null, 2))
87
- process.exit(0)
89
+ exit(0);
88
90
  } else {
89
91
  writeToProcess(result.message || '执行错误')
90
- process.exit(1)
92
+ exit(1);
91
93
  }
92
94
  }
93
95
 
94
- main();
96
+ app.route({
97
+ path: 'cnb',
98
+ key: 'npc',
99
+ description: 'CNB智能助手,提供智能建议和帮助, 程序入口',
100
+ metadata: {
101
+ tags: ['notInNpcAgent'],
102
+ args: {
103
+ needExit: z.boolean().optional().describe('是否需要在执行完成后退出进程')
104
+ }
105
+ }
106
+ }).define(async (ctx) => {
107
+ const exit = (code: number) => {
108
+ if (ctx.args.needExit) {
109
+ process.exit(code);
110
+ }
111
+ }
112
+ await main({ exit });
113
+ }).addTo(app)
114
+
115
+ parse({ app: app, description: 'CNB控制台命令行工具', parse: true })
@@ -30,9 +30,17 @@ app.route({
30
30
  role: 'user',
31
31
  content: ctx.args.question
32
32
  }]
33
+ const routes = app.routes.filter(route => {
34
+ const tags = route.metadata?.tags || [];
35
+ if (tags.includes('notInNpcAgent')) {
36
+ return false;
37
+ }
38
+ return true
39
+ });
33
40
  const result = await runAgent({
34
41
  app,
35
42
  messages: messages,
43
+ routes,
36
44
  languageModel: cnbAi(model),
37
45
  token: '',
38
46
  // token: ctx.query.token as string,
package/bin/npc.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env bun
2
+ import '../dist/npc.js';