更新 .cnb.yml 中的命令行参数,修改 agent/npc.ts 以支持用户名称,更新 package.json 版本,完善 readme.md 环境变量说明
This commit is contained in:
2
.cnb.yml
2
.cnb.yml
@@ -19,7 +19,7 @@ include:
|
|||||||
- name: "task"
|
- name: "task"
|
||||||
script: |
|
script: |
|
||||||
git clone https://cnb.cool/kevisual/cnb cnb
|
git clone https://cnb.cool/kevisual/cnb cnb
|
||||||
cd cnb && bun run agent/npc.ts cnb npc
|
cd cnb && bun run agent/npc.ts cnb npc --args owner="小熊猫呜呜呜"
|
||||||
$:
|
$:
|
||||||
vscode:
|
vscode:
|
||||||
- docker:
|
- docker:
|
||||||
|
|||||||
17
agent/npc.ts
17
agent/npc.ts
@@ -4,6 +4,7 @@ import { parse } from '@kevisual/router/src/commander.ts';
|
|||||||
import { useIssueEnv, useCommentEnv, useRepoInfoEnv, IssueLabel } from '../src/index.ts'
|
import { useIssueEnv, useCommentEnv, useRepoInfoEnv, IssueLabel } from '../src/index.ts'
|
||||||
import { pick } from 'es-toolkit';
|
import { pick } from 'es-toolkit';
|
||||||
import z from 'zod';
|
import z from 'zod';
|
||||||
|
import { useKey } from '@kevisual/context';
|
||||||
|
|
||||||
const writeToProcess = (message: string) => {
|
const writeToProcess = (message: string) => {
|
||||||
if (process.send) {
|
if (process.send) {
|
||||||
@@ -38,7 +39,7 @@ const getIssuesLabels = async () => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const main = async ({ exit }: { exit: (code: number) => void }) => {
|
const main = async ({ exit, question }: { exit: (code: number) => void, question?: string }) => {
|
||||||
const repoInfoEnv = useRepoInfoEnv();
|
const repoInfoEnv = useRepoInfoEnv();
|
||||||
const commentEnv = useCommentEnv();
|
const commentEnv = useCommentEnv();
|
||||||
const issueEnv = useIssueEnv();
|
const issueEnv = useIssueEnv();
|
||||||
@@ -70,7 +71,7 @@ const main = async ({ exit }: { exit: (code: number) => void }) => {
|
|||||||
content: `相关变量:${JSON.stringify({ ...pickCommentEnv, ...pickIssueEnv, ...pickRepoInfoEnv })}`
|
content: `相关变量:${JSON.stringify({ ...pickCommentEnv, ...pickIssueEnv, ...pickRepoInfoEnv })}`
|
||||||
}, {
|
}, {
|
||||||
role: 'user',
|
role: 'user',
|
||||||
content: commentEnv.commentBody || pickIssueEnv.issueDescription || '无'
|
content: question || commentEnv.commentBody || pickIssueEnv.issueDescription || '无'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
writeToProcess('输入消息:');
|
writeToProcess('输入消息:');
|
||||||
@@ -100,17 +101,25 @@ app.route({
|
|||||||
metadata: {
|
metadata: {
|
||||||
tags: ['notInNpcAgent'],
|
tags: ['notInNpcAgent'],
|
||||||
args: {
|
args: {
|
||||||
needExit: z.boolean().optional().describe('是否需要在执行完成后退出进程')
|
needExit: z.boolean().optional().describe('是否需要在执行完成后退出进程'),
|
||||||
|
owner: z.string().optional().describe('用户名称')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).define(async (ctx) => {
|
}).define(async (ctx) => {
|
||||||
const needExit = ctx.args.needExit ?? true;
|
const needExit = ctx.args.needExit ?? true;
|
||||||
|
const owner = ctx.args.owner || '';
|
||||||
const exit = (code: number) => {
|
const exit = (code: number) => {
|
||||||
if (needExit) {
|
if (needExit) {
|
||||||
process.exit(code);
|
process.exit(code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await main({ exit });
|
const buildUserNickName = useKey('CNB_BUILD_USER_NICKNAME')
|
||||||
|
let admins = owner.split(',').map(item => item.trim());
|
||||||
|
if (owner && admins.includes(buildUserNickName)) {
|
||||||
|
await main({ exit });
|
||||||
|
} else {
|
||||||
|
await main({ exit, question: `你是${owner}的专属助手,请生成一条评论,说明你不具备其他用户能访问的能力。同时你需要提示说明,fork当前仓库后,即可成为你的专属助手` });
|
||||||
|
}
|
||||||
}).addTo(app)
|
}).addTo(app)
|
||||||
|
|
||||||
parse({ app: app, description: 'CNB控制台命令行工具', parse: true })
|
parse({ app: app, description: 'CNB控制台命令行工具', parse: true })
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@kevisual/cnb",
|
"name": "@kevisual/cnb",
|
||||||
"version": "0.0.48",
|
"version": "0.0.50",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"basename": "/root/cnb",
|
"basename": "/root/cnb",
|
||||||
|
|||||||
Reference in New Issue
Block a user