Files
cnb/agent/npc.ts
xiongxiao ef38fc0596 update
2026-03-11 16:15:48 +08:00

44 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { app } from './index.ts';
import { useIssueEnv, useCommentEnv, useRepoInfoEnv } from '../src/index.ts'
import { pick } from 'es-toolkit';
const main = async () => {
const repoInfoEnv = useRepoInfoEnv();
const commentEnv = useCommentEnv();
const issueEnv = useIssueEnv();
const pickCommentEnv = pick(commentEnv, ['commentId', 'commentIdLabel']);
const pickIssueEnv = pick(issueEnv, ['issueId', 'issueIdLabel', 'issueIid', 'issueIidLabel', 'issueTitle', 'issueTitleLabel', 'issueDescription', 'issueDescriptionLabel']);
const pickRepoInfoEnv = pick(repoInfoEnv, ['repoId', 'repoIdLabel', 'repoName', 'repoNameLabel', 'repoSlug', 'repoSlugLabel']);
const messages = [
{
role: 'system',
content: `你是一个智能的代码助手, 根据用户提供的上下文信息,提供有用的建议和帮助, 如果用户的要求和执行工具不一致请说出你不能这么做。并把最后的结果提交一个评论到对应的issue中。用户提供的上下文信息如下`
},
{
role: 'system',
content: `相关变量:${JSON.stringify({ ...pickCommentEnv, ...pickIssueEnv, ...pickRepoInfoEnv })}`
}, {
role: 'user',
content: commentEnv.commentBody || pickIssueEnv.issueDescription || '无'
}
]
console.log('messages', messages)
const result = await app.run({
path: 'cnb',
key: 'chat',
payload: {
messages
}
}, { appId: app.appId })
if (result.code === 200) {
let _message = result.data.message || []
console.log('执行完成', JSON.stringify(_message, null, 2))
process.exit(0)
} else {
console.log(result.message || '执行错误')
process.exit(1)
}
}
main();