default agent to null
This commit is contained in:
@@ -48,16 +48,37 @@ export interface MainResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function main(inputs: Inputs): Promise<MainResult> {
|
export async function main(inputs: Inputs): Promise<MainResult> {
|
||||||
const partialCtx = await initializeContext(inputs);
|
let githubInstallationToken: string | undefined;
|
||||||
const ctx = partialCtx as MainContext;
|
let pollInterval: NodeJS.Timeout | null = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// parse payload early to extract agent for determineAgent
|
// parse payload early to extract agent
|
||||||
ctx.payload = parsePayload(inputs);
|
const payload = parsePayload(inputs);
|
||||||
await determineAgent(ctx);
|
|
||||||
|
// resolve agent before initializing context
|
||||||
|
githubInstallationToken = await setupGitHubInstallationToken();
|
||||||
|
const repoContext = parseRepoContext();
|
||||||
|
const { agentName, agent } = await resolveAgent(
|
||||||
|
inputs,
|
||||||
|
payload,
|
||||||
|
githubInstallationToken,
|
||||||
|
repoContext
|
||||||
|
);
|
||||||
|
|
||||||
|
const partialCtx = await initializeContext(
|
||||||
|
inputs,
|
||||||
|
agentName,
|
||||||
|
agent,
|
||||||
|
githubInstallationToken,
|
||||||
|
repoContext
|
||||||
|
);
|
||||||
|
const ctx = partialCtx as MainContext;
|
||||||
|
ctx.payload = payload;
|
||||||
|
|
||||||
setupGitAuth(ctx.githubInstallationToken, ctx.repoContext);
|
setupGitAuth(ctx.githubInstallationToken, ctx.repoContext);
|
||||||
await setupTempDirectory(ctx);
|
await setupTempDirectory(ctx);
|
||||||
setupMcpLogPolling(ctx);
|
setupMcpLogPolling(ctx);
|
||||||
|
pollInterval = ctx.pollInterval;
|
||||||
|
|
||||||
setupGitBranch(ctx.payload);
|
setupGitBranch(ctx.payload);
|
||||||
setupMcpServers(ctx);
|
setupMcpServers(ctx);
|
||||||
@@ -75,10 +96,12 @@ export async function main(inputs: Inputs): Promise<MainResult> {
|
|||||||
error: errorMessage,
|
error: errorMessage,
|
||||||
};
|
};
|
||||||
} finally {
|
} finally {
|
||||||
await cleanup({
|
if (pollInterval) {
|
||||||
...partialCtx,
|
clearInterval(pollInterval);
|
||||||
payload: ctx.payload,
|
}
|
||||||
});
|
if (githubInstallationToken) {
|
||||||
|
await revokeInstallationToken(githubInstallationToken);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,49 +185,53 @@ interface MainContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function initializeContext(
|
async function initializeContext(
|
||||||
inputs: Inputs
|
inputs: Inputs,
|
||||||
|
agentName: AgentNameType,
|
||||||
|
agent: (typeof agents)[AgentNameType],
|
||||||
|
githubInstallationToken: string,
|
||||||
|
repoContext: RepoContext
|
||||||
): Promise<Omit<MainContext, "payload" | "mcpServers" | "cliPath" | "apiKey">> {
|
): Promise<Omit<MainContext, "payload" | "mcpServers" | "cliPath" | "apiKey">> {
|
||||||
log.info(`🐸 Running pullfrog/action@${packageJson.version}...`);
|
log.info(`🐸 Running pullfrog/action@${packageJson.version}...`);
|
||||||
Inputs.assert(inputs);
|
Inputs.assert(inputs);
|
||||||
setupGitConfig();
|
setupGitConfig();
|
||||||
|
|
||||||
const githubInstallationToken = await setupGitHubInstallationToken();
|
|
||||||
const repoContext = parseRepoContext();
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
inputs,
|
inputs,
|
||||||
githubInstallationToken,
|
githubInstallationToken,
|
||||||
repoContext,
|
repoContext,
|
||||||
agentName: "claude",
|
agentName,
|
||||||
agent: agents.claude,
|
agent,
|
||||||
sharedTempDir: "",
|
sharedTempDir: "",
|
||||||
mcpLogPath: "",
|
mcpLogPath: "",
|
||||||
pollInterval: null,
|
pollInterval: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function determineAgent(
|
async function resolveAgent(
|
||||||
ctx: Omit<MainContext, "mcpServers" | "cliPath" | "apiKey">
|
inputs: Inputs,
|
||||||
): Promise<void> {
|
payload: Payload,
|
||||||
|
githubInstallationToken: string,
|
||||||
|
repoContext: RepoContext
|
||||||
|
): Promise<{ agentName: AgentNameType; agent: (typeof agents)[AgentNameType] }> {
|
||||||
const repoSettings = await fetchRepoSettings({
|
const repoSettings = await fetchRepoSettings({
|
||||||
token: ctx.githubInstallationToken,
|
token: githubInstallationToken,
|
||||||
repoContext: ctx.repoContext,
|
repoContext,
|
||||||
});
|
});
|
||||||
|
|
||||||
const configuredAgentName =
|
const configuredAgentName =
|
||||||
(process.env.NODE_ENV === "development" && AGENT_OVERRIDE) ||
|
(process.env.NODE_ENV === "development" && AGENT_OVERRIDE) ||
|
||||||
ctx.payload.agent ||
|
payload.agent ||
|
||||||
repoSettings.defaultAgent ||
|
repoSettings.defaultAgent ||
|
||||||
null;
|
null;
|
||||||
|
|
||||||
if (configuredAgentName) {
|
if (configuredAgentName) {
|
||||||
ctx.agentName = configuredAgentName;
|
const agentName = configuredAgentName;
|
||||||
ctx.agent = agents[ctx.agentName];
|
const agent = agents[agentName];
|
||||||
log.info(`Selected configured agent: ${ctx.agentName}`);
|
log.info(`Selected configured agent: ${agentName}`);
|
||||||
return;
|
return { agentName, agent };
|
||||||
}
|
}
|
||||||
|
|
||||||
const availableAgents = getAvailableAgents(ctx.inputs);
|
const availableAgents = getAvailableAgents(inputs);
|
||||||
const availableAgentNames = availableAgents.map((agent) => agent.name).join(", ");
|
const availableAgentNames = availableAgents.map((agent) => agent.name).join(", ");
|
||||||
log.debug(`Available agents: ${availableAgentNames || "none"}`);
|
log.debug(`Available agents: ${availableAgentNames || "none"}`);
|
||||||
|
|
||||||
@@ -212,13 +239,14 @@ async function determineAgent(
|
|||||||
throwMissingApiKeyError({
|
throwMissingApiKeyError({
|
||||||
agentName: configuredAgentName,
|
agentName: configuredAgentName,
|
||||||
inputKeys: getAllPossibleKeyNames(),
|
inputKeys: getAllPossibleKeyNames(),
|
||||||
repoContext: ctx.repoContext,
|
repoContext,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.agentName = availableAgents[0].name;
|
const agentName = availableAgents[0].name;
|
||||||
ctx.agent = availableAgents[0];
|
const agent = availableAgents[0];
|
||||||
log.info(`No agent configured, defaulting to first available agent: ${ctx.agentName}`);
|
log.info(`No agent configured, defaulting to first available agent: ${agentName}`);
|
||||||
|
return { agentName, agent };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setupTempDirectory(
|
async function setupTempDirectory(
|
||||||
@@ -317,10 +345,3 @@ async function handleAgentResult(result: AgentResult): Promise<MainResult> {
|
|||||||
output: result.output || "",
|
output: result.output || "",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function cleanup(ctx: Omit<MainContext, "mcpServers" | "cliPath" | "apiKey">): Promise<void> {
|
|
||||||
if (ctx.pollInterval) {
|
|
||||||
clearInterval(ctx.pollInterval);
|
|
||||||
}
|
|
||||||
await revokeInstallationToken(ctx.githubInstallationToken);
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user