have payload.agent take precedence over inputs.defaultAgent
This commit is contained in:
@@ -7,6 +7,15 @@ inputs:
|
|||||||
description: "Prompt to send to Claude Code"
|
description: "Prompt to send to Claude Code"
|
||||||
required: true
|
required: true
|
||||||
default: "Hello from Claude Code!"
|
default: "Hello from Claude Code!"
|
||||||
|
defaultAgent:
|
||||||
|
description: "Default agent to use. Overridden by payload.agent if present."
|
||||||
|
required: false
|
||||||
|
type: choice
|
||||||
|
options:
|
||||||
|
- claude
|
||||||
|
- codex
|
||||||
|
- cursor
|
||||||
|
- gemini
|
||||||
anthropic_api_key:
|
anthropic_api_key:
|
||||||
description: "Anthropic API key for Claude Code authentication"
|
description: "Anthropic API key for Claude Code authentication"
|
||||||
required: false
|
required: false
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ async function run(): Promise<void> {
|
|||||||
try {
|
try {
|
||||||
const inputs: Required<Inputs> = {
|
const inputs: Required<Inputs> = {
|
||||||
prompt: core.getInput("prompt", { required: true }),
|
prompt: core.getInput("prompt", { required: true }),
|
||||||
agent: core.getInput("agent") ? AgentName.assert(core.getInput("agent")) : undefined,
|
defaultAgent: core.getInput("defaultAgent") ? AgentName.assert(core.getInput("defaultAgent")) : undefined,
|
||||||
...flatMorph(agents, (_, agent) =>
|
...flatMorph(agents, (_, agent) =>
|
||||||
agent.apiKeyNames.map((inputKey) => [inputKey, core.getInput(inputKey)])
|
agent.apiKeyNames.map((inputKey) => [inputKey, core.getInput(inputKey)])
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -123,6 +123,10 @@ export type PayloadEvent =
|
|||||||
url: string;
|
url: string;
|
||||||
};
|
};
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
trigger: "unknown";
|
||||||
|
[key: string]: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
// payload type for agent execution
|
// payload type for agent execution
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ const keyInputDefs = flatMorph(agents, (_, agent) =>
|
|||||||
export const Inputs = type({
|
export const Inputs = type({
|
||||||
prompt: "string",
|
prompt: "string",
|
||||||
...keyInputDefs,
|
...keyInputDefs,
|
||||||
"agent?": type.enumerated(...Object.values(agents).map((agent) => agent.name)).or("undefined"),
|
"defaultAgent?": type
|
||||||
|
.enumerated(...Object.values(agents).map((agent) => agent.name))
|
||||||
|
.or("undefined"),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type Inputs = typeof Inputs.infer;
|
export type Inputs = typeof Inputs.infer;
|
||||||
@@ -51,12 +53,13 @@ export async function main(inputs: Inputs): Promise<MainResult> {
|
|||||||
const ctx = partialCtx as MainContext;
|
const ctx = partialCtx as MainContext;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// parse payload early to extract agent for determineAgent
|
||||||
|
ctx.payload = parsePayload(inputs);
|
||||||
await determineAgent(ctx);
|
await determineAgent(ctx);
|
||||||
setupGitAuth(ctx.githubInstallationToken, ctx.repoContext);
|
setupGitAuth(ctx.githubInstallationToken, ctx.repoContext);
|
||||||
await setupTempDirectory(ctx);
|
await setupTempDirectory(ctx);
|
||||||
setupMcpLogPolling(ctx);
|
setupMcpLogPolling(ctx);
|
||||||
|
|
||||||
ctx.payload = parsePayload(inputs);
|
|
||||||
setupGitBranch(ctx.payload);
|
setupGitBranch(ctx.payload);
|
||||||
setupMcpServers(ctx);
|
setupMcpServers(ctx);
|
||||||
await installAgentCli(ctx);
|
await installAgentCli(ctx);
|
||||||
@@ -73,7 +76,10 @@ export async function main(inputs: Inputs): Promise<MainResult> {
|
|||||||
error: errorMessage,
|
error: errorMessage,
|
||||||
};
|
};
|
||||||
} finally {
|
} finally {
|
||||||
await cleanup(partialCtx);
|
await cleanup({
|
||||||
|
...partialCtx,
|
||||||
|
payload: ctx.payload,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,14 +173,16 @@ async function initializeContext(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function determineAgent(
|
async function determineAgent(
|
||||||
ctx: Omit<MainContext, "payload" | "mcpServers" | "cliPath" | "apiKey">
|
ctx: Omit<MainContext, "mcpServers" | "cliPath" | "apiKey">
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const repoSettings = await fetchRepoSettings({
|
const repoSettings = await fetchRepoSettings({
|
||||||
token: ctx.githubInstallationToken,
|
token: ctx.githubInstallationToken,
|
||||||
repoContext: ctx.repoContext,
|
repoContext: ctx.repoContext,
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx.agentName = ctx.inputs.agent || repoSettings.defaultAgent || "claude";
|
// precedence: payload.agent > inputs.defaultAgent > repoSettings.defaultAgent > "claude"
|
||||||
|
ctx.agentName =
|
||||||
|
ctx.payload.agent || ctx.inputs.defaultAgent || repoSettings.defaultAgent || "claude";
|
||||||
ctx.agent = agents[ctx.agentName];
|
ctx.agent = agents[ctx.agentName];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,11 +223,8 @@ function parsePayload(inputs: Inputs): Payload {
|
|||||||
agent: null,
|
agent: null,
|
||||||
prompt: inputs.prompt,
|
prompt: inputs.prompt,
|
||||||
event: {
|
event: {
|
||||||
trigger: "issues_opened",
|
trigger: "unknown",
|
||||||
issue_number: 0,
|
},
|
||||||
issue_title: "",
|
|
||||||
issue_body: null,
|
|
||||||
} as Payload["event"],
|
|
||||||
modes,
|
modes,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -283,9 +288,7 @@ async function handleAgentResult(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function cleanup(
|
async function cleanup(ctx: Omit<MainContext, "mcpServers" | "cliPath" | "apiKey">): Promise<void> {
|
||||||
ctx: Omit<MainContext, "payload" | "mcpServers" | "cliPath" | "apiKey">
|
|
||||||
): Promise<void> {
|
|
||||||
if (ctx.pollInterval) {
|
if (ctx.pollInterval) {
|
||||||
clearInterval(ctx.pollInterval);
|
clearInterval(ctx.pollInterval);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,9 +21,12 @@ export async function run(prompt: string): Promise<AgentResult> {
|
|||||||
const originalCwd = process.cwd();
|
const originalCwd = process.cwd();
|
||||||
process.chdir(tempDir);
|
process.chdir(tempDir);
|
||||||
|
|
||||||
|
// check if prompt is a pullfrog payload and extract agent
|
||||||
|
// note: agent from payload will be used by determineAgent with highest precedence
|
||||||
|
// we don't need to extract it here since main() will parse the payload
|
||||||
const inputs: Required<Inputs> = {
|
const inputs: Required<Inputs> = {
|
||||||
prompt,
|
prompt,
|
||||||
agent: "codex",
|
defaultAgent: undefined,
|
||||||
...flatMorph(agents, (_, agent) =>
|
...flatMorph(agents, (_, agent) =>
|
||||||
agent.apiKeyNames.map((inputKey) => [inputKey, process.env[inputKey.toUpperCase()]])
|
agent.apiKeyNames.map((inputKey) => [inputKey, process.env[inputKey.toUpperCase()]])
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user