@ztimson/ai-agents 0.1.1 → 0.1.2
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.
- package/package.json +1 -1
- package/src/refine.mjs +2 -1
- package/src/review.mjs +22 -2
package/package.json
CHANGED
package/src/refine.mjs
CHANGED
|
@@ -181,8 +181,9 @@ Output ONLY markdown. No explanations, labels, or extra formatting.`});
|
|
|
181
181
|
const hasDuplicates = (await ai.language.ask(`ID: ${issueData.id}\nTitle: ${title}\n\`\`\`markdown\n${body}\n\`\`\``, {
|
|
182
182
|
system: `Your job is to identify duplicates. Respond ONLY with the duplicate's ID number or "NONE" if no match exists\n\n${dupes}`
|
|
183
183
|
}))?.pop()?.content;
|
|
184
|
+
|
|
184
185
|
// Handle duplicates
|
|
185
|
-
if(hasDuplicates && hasDuplicates
|
|
186
|
+
if(hasDuplicates && !hasDuplicates.toUpperCase().includes('NONE') && (dupeId = dupeIds.find(id => id == hasDuplicates.trim())) != null && dupeId != issueData.id) {
|
|
186
187
|
await fetch(`${git}/api/v1/repos/${owner}/${repo}/issues/${ticket}/comments`, {
|
|
187
188
|
method: 'POST',
|
|
188
189
|
headers: {'Authorization': `token ${auth}`, 'Content-Type': 'application/json'},
|
package/src/review.mjs
CHANGED
|
@@ -19,12 +19,23 @@ dotenv.config({path: '.env.local', override: true, quiet: true, debug: false});
|
|
|
19
19
|
owner = process.env['GIT_OWNER'],
|
|
20
20
|
repo = process.env['GIT_REPO'],
|
|
21
21
|
auth = process.env['GIT_TOKEN'],
|
|
22
|
+
labelEnabled = process.env['LABEL_ENABLED'] || 'Review/AI',
|
|
22
23
|
pr = process.env['PULL_REQUEST'],
|
|
23
24
|
host = process.env['AI_HOST'],
|
|
24
25
|
model = process.env['AI_MODEL'],
|
|
25
26
|
token = process.env['AI_TOKEN'];
|
|
26
27
|
|
|
27
28
|
console.log(`Reviewing: ${root}\n`);
|
|
29
|
+
const info = await fetch(`${git}/api/v1/repos/${owner}/${repo}/pulls/${pr}`)
|
|
30
|
+
.then(async resp => {
|
|
31
|
+
if(resp.ok) return resp.json();
|
|
32
|
+
throw new Error(`${resp.status} ${await resp.text()}`);
|
|
33
|
+
});
|
|
34
|
+
if(!info.labels.some(l => l.name === labelEnabled)) {
|
|
35
|
+
console.log('Skipping');
|
|
36
|
+
return process.exit();
|
|
37
|
+
}
|
|
38
|
+
|
|
28
39
|
const branch = process.env['GIT_BRANCH'] || await $`cd ${root} && git symbolic-ref refs/remotes/origin/HEAD`;
|
|
29
40
|
const comments = [];
|
|
30
41
|
const commit = await $`cd ${root} && git log -1 --pretty=format:%H`;
|
|
@@ -53,7 +64,7 @@ dotenv.config({path: '.env.local', override: true, quiet: true, debug: false});
|
|
|
53
64
|
...options,
|
|
54
65
|
model: [host, model],
|
|
55
66
|
path: process.env['path'] || os.tmpdir(),
|
|
56
|
-
system: `You are a code reviewer. Analyze the git diff and use the \`recommend\` tool for EACH issue you find. You must call \`recommend\` exactly once for every bug or improvement opportunity directly related to changes. Ignore formatting recommendations. After making all recommendations, provide
|
|
67
|
+
system: `You are a code reviewer. Analyze the git diff and use the \`recommend\` tool for EACH issue you find. You must call \`recommend\` exactly once for every bug or improvement opportunity directly related to changes. Ignore formatting recommendations. After making all recommendations, provide a quick 75 words or less sitrep.${existingComments}`,
|
|
57
68
|
tools: [{
|
|
58
69
|
name: 'read_file',
|
|
59
70
|
description: 'Read contents of a file',
|
|
@@ -87,7 +98,16 @@ dotenv.config({path: '.env.local', override: true, quiet: true, debug: false});
|
|
|
87
98
|
}]
|
|
88
99
|
});
|
|
89
100
|
|
|
90
|
-
const messages = await ai.language.ask(
|
|
101
|
+
const messages = await ai.language.ask(`Title: ${info.title || 'None'}
|
|
102
|
+
Description:
|
|
103
|
+
\`\`\`md
|
|
104
|
+
${info.body || 'None'}
|
|
105
|
+
\`\`\`
|
|
106
|
+
|
|
107
|
+
Git Diff:
|
|
108
|
+
\`\`\`
|
|
109
|
+
${gitDiff}
|
|
110
|
+
\`\`\``);
|
|
91
111
|
const summary = messages.pop().content;
|
|
92
112
|
if(git) {
|
|
93
113
|
const res = await fetch(`${git}/api/v1/repos/${owner}/${repo}/pulls/${pr}/reviews`, {
|