-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauggie.ts
More file actions
100 lines (84 loc) · 2.86 KB
/
auggie.ts
File metadata and controls
100 lines (84 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import * as core from "@actions/core";
import { Auggie } from "@augmentcode/auggie-sdk";
import type { GithubPullRequest } from "./types";
import { AGENT_SYSTEM_PROMPT, generateContextPrompt } from "./utils/prompt";
/**
* Options for running Auggie agent
*/
export type RunAuggieOptions = {
userPrompt: string;
apiKey?: string;
apiUrl?: string;
workspaceRoot?: string;
context?: GithubPullRequest;
/** The body of the comment that triggered this action, if triggered by a comment */
commentBody?: string;
/** The ID of the comment that triggered this action, if triggered by a comment */
commentId?: number;
};
/**
* Run Auggie agent with the given prompt and return the response
*/
export async function runAuggie(options: RunAuggieOptions): Promise<string> {
const {
userPrompt,
apiKey,
apiUrl,
workspaceRoot,
context,
commentBody,
commentId,
} = options;
const workspace = workspaceRoot || process.cwd();
core.info("🤖 Initializing Auggie agent...");
core.info(`📁 Workspace root: ${workspace}`);
let client: Auggie | null = null;
try {
// Set GITHUB_API_TOKEN environment variable from GITHUB_TOKEN if available
const githubToken = process.env.GITHUB_TOKEN;
if (githubToken) {
process.env.GITHUB_API_TOKEN = githubToken;
core.info("✅ GITHUB_API_TOKEN environment variable set from GITHUB_TOKEN");
}
// Create Auggie client
client = await Auggie.create({
model: "sonnet4.5",
apiKey,
apiUrl,
workspaceRoot: workspace,
allowIndexing: true,
});
core.info("📝 Running Auggie agent ...");
// Build the full prompt by combining system prompt, context, and user prompt
let fullPrompt = AGENT_SYSTEM_PROMPT;
// Add context information if provided
if (context) {
const contextPrompt = generateContextPrompt(context);
fullPrompt = `${fullPrompt}\n\n## PR Context:\n${contextPrompt}`;
}
// Add user comment request if triggered by a comment
if (commentBody) {
fullPrompt = `${fullPrompt}\n\n## User Specific Request:\n${commentBody}`;
core.info("📨 User comment included in prompt");
}
// Add triggering comment ID if available
if (commentId) {
fullPrompt = `${fullPrompt}\n\n## Triggering Comment ID:\n${commentId}`;
core.info(`📍 Triggering comment ID: ${commentId}`);
}
// Add user prompt
fullPrompt = `${fullPrompt}\n\n${userPrompt}`;
const response = await client.prompt(fullPrompt, { isAnswerOnly: true });
core.info("✅ Auggie agent completed successfully");
return response;
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
core.error(`Failed to run Auggie agent: ${errorMessage}`);
throw error;
} finally {
// Always close the client
if (client) {
await client.close();
}
}
}