Fix undefined bug
This commit is contained in:
committed by
pullfrog[bot]
parent
e1b017f6e2
commit
f65cb4d2e3
+4
-9
@@ -28,7 +28,7 @@ export function resolveAgent(params: {
|
||||
`» determineAgent: agentOverride=${agentOverride}, payload.agent=${params.payload.agent}, repoSettings.defaultAgent=${params.repoSettings.defaultAgent}`
|
||||
);
|
||||
const configuredAgentName =
|
||||
agentOverride || params.payload.agent || params.repoSettings.defaultAgent || null;
|
||||
agentOverride || params.payload.agent || params.repoSettings.defaultAgent || undefined;
|
||||
|
||||
if (configuredAgentName) {
|
||||
const agent = agents[configuredAgentName];
|
||||
@@ -38,14 +38,9 @@ export function resolveAgent(params: {
|
||||
|
||||
// if explicitly configured (via override or payload), respect it even without matching keys
|
||||
// this allows users to force an agent selection (will fail later with clear error if no keys)
|
||||
const isExplicitOverride = agentOverride !== undefined || params.payload.agent !== null;
|
||||
if (isExplicitOverride) {
|
||||
log.info(`» selected configured agent: ${agent.name}`);
|
||||
return agent;
|
||||
}
|
||||
|
||||
// for repo-level defaults, check if agent has matching keys before selecting
|
||||
if (agentHasApiKeys(agent)) {
|
||||
// for repo-level defaults, only select if agent has matching API keys
|
||||
const isExplicitOverride = agentOverride !== undefined || params.payload.agent !== undefined;
|
||||
if (isExplicitOverride || agentHasApiKeys(agent)) {
|
||||
log.info(`» selected configured agent: ${agent.name}`);
|
||||
return agent;
|
||||
}
|
||||
|
||||
+16
-25
@@ -1,13 +1,7 @@
|
||||
import { isAbsolute, resolve } from "node:path";
|
||||
import * as core from "@actions/core";
|
||||
import { type } from "arktype";
|
||||
import {
|
||||
AgentName,
|
||||
type AgentName as AgentNameType,
|
||||
type AuthorPermission,
|
||||
Effort,
|
||||
type PayloadEvent,
|
||||
} from "../external.ts";
|
||||
import { AgentName, type AuthorPermission, Effort, type PayloadEvent } from "../external.ts";
|
||||
import type { RepoSettings } from "./repoSettings.ts";
|
||||
|
||||
// tool permission enum types for inputs
|
||||
@@ -19,11 +13,11 @@ const BashPermissionInput = type.enumerated("disabled", "restricted", "enabled")
|
||||
// permissions are derived from event.authorPermission instead
|
||||
const JsonPayload = type({
|
||||
"~pullfrog": "true",
|
||||
"agent?": AgentName.or("null"),
|
||||
"agent?": AgentName.or("undefined"),
|
||||
"prompt?": "string",
|
||||
"repoInstructions?": "string",
|
||||
"event?": "object",
|
||||
"effort?": Effort,
|
||||
"effort?": Effort.or("undefined"),
|
||||
});
|
||||
|
||||
// permission levels that indicate collaborator status (have push access)
|
||||
@@ -42,18 +36,18 @@ function isCollaborator(event: PayloadEvent): boolean {
|
||||
// if included, must match the type - so we need to explicitly allow undefined.
|
||||
export const Inputs = type({
|
||||
prompt: "string",
|
||||
"effort?": Effort,
|
||||
"agent?": AgentName.or("null"),
|
||||
"effort?": Effort.or("undefined"),
|
||||
"agent?": AgentName.or("undefined"),
|
||||
"web?": ToolPermissionInput.or("undefined"),
|
||||
"search?": ToolPermissionInput.or("undefined"),
|
||||
"write?": ToolPermissionInput.or("undefined"),
|
||||
"bash?": BashPermissionInput.or("undefined"),
|
||||
"cwd?": "string|null",
|
||||
"cwd?": type.string.or("undefined"),
|
||||
});
|
||||
|
||||
export type Inputs = typeof Inputs.infer;
|
||||
|
||||
function isAgentName(value: unknown): value is AgentNameType {
|
||||
function isAgentName(value: unknown): value is AgentName {
|
||||
return typeof value === "string" && AgentName(value) instanceof type.errors === false;
|
||||
}
|
||||
|
||||
@@ -61,9 +55,9 @@ function isPayloadEvent(value: unknown): value is PayloadEvent {
|
||||
return typeof value === "object" && value !== null && "trigger" in value;
|
||||
}
|
||||
|
||||
function resolveCwd(cwd: string | null | undefined): string | null {
|
||||
function resolveCwd(cwd: string | undefined): string | undefined {
|
||||
const workspace = process.env.GITHUB_WORKSPACE;
|
||||
if (!cwd) return workspace ?? null;
|
||||
if (!cwd) return workspace;
|
||||
if (isAbsolute(cwd)) return cwd;
|
||||
return workspace ? resolve(workspace, cwd) : cwd;
|
||||
}
|
||||
@@ -72,19 +66,17 @@ export function resolvePayload(repoSettings: RepoSettings) {
|
||||
const inputs = Inputs.assert({
|
||||
prompt: core.getInput("prompt", { required: true }),
|
||||
effort: core.getInput("effort") || undefined,
|
||||
agent: core.getInput("agent") || null,
|
||||
cwd: core.getInput("cwd") || null,
|
||||
agent: core.getInput("agent") || undefined,
|
||||
cwd: core.getInput("cwd") || undefined,
|
||||
web: core.getInput("web") || undefined,
|
||||
search: core.getInput("search") || undefined,
|
||||
write: core.getInput("write") || undefined,
|
||||
bash: core.getInput("bash") || undefined,
|
||||
});
|
||||
|
||||
// convert "null" string to null, validate agent name
|
||||
const agent: AgentNameType | null =
|
||||
inputs.agent !== undefined && inputs.agent !== "null" && isAgentName(inputs.agent)
|
||||
? inputs.agent
|
||||
: null;
|
||||
// validate agent name
|
||||
const agent: AgentName | undefined =
|
||||
inputs.agent !== undefined && isAgentName(inputs.agent) ? inputs.agent : undefined;
|
||||
|
||||
// try to parse prompt as JSON payload (internal invocation)
|
||||
let jsonPayload: typeof JsonPayload.infer | null = null;
|
||||
@@ -108,9 +100,8 @@ export function resolvePayload(repoSettings: RepoSettings) {
|
||||
|
||||
// resolve agent from jsonPayload with type guard
|
||||
const jsonAgent = jsonPayload?.agent;
|
||||
const resolvedAgent: AgentNameType | null =
|
||||
agent ??
|
||||
(jsonAgent !== undefined && jsonAgent !== "null" && isAgentName(jsonAgent) ? jsonAgent : null);
|
||||
const resolvedAgent: AgentName | undefined =
|
||||
agent ?? (jsonAgent !== undefined && isAgentName(jsonAgent) ? jsonAgent : undefined);
|
||||
|
||||
// determine if permissions should be restricted based on event author
|
||||
// non-collaborators (read, triage, none, or missing) get restricted bash access
|
||||
|
||||
Reference in New Issue
Block a user