Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): post GitHub input prompts by default (#1971)

vercel-gh-bot-5[bot]3eba8556dd15
diff --git a/.changeset/fuzzy-spiders-prompt.md b/.changeset/fuzzy-spiders-prompt.md
new file mode 100644
index 000000000..df1f55ed8
--- /dev/null
+++ b/.changeset/fuzzy-spiders-prompt.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Post GitHub human-in-the-loop prompts by default so users can see and answer pending input requests in the issue or pull request thread.
diff --git a/packages/eve/src/public/channels/github/defaults.ts b/packages/eve/src/public/channels/github/defaults.ts
index 76d4072da..35d472b49 100644
--- a/packages/eve/src/public/channels/github/defaults.ts
+++ b/packages/eve/src/public/channels/github/defaults.ts
@@ -16,6 +16,7 @@ import type {
} from "#public/channels/github/githubChannel.js";
import { splitGitHubCommentBody } from "#public/channels/github/limits.js";
import type { SessionContext } from "#public/definitions/callback-context.js";
+import type { InputRequest } from "#runtime/input/types.js";
const log = createLogger("github.defaults");
@@ -73,6 +74,7 @@ export function defaultOnComment(
/** Options used by built-in GitHub event handlers. */
export interface GitHubDefaultEventOptions {
readonly api?: GitHubApiOptions;
+ readonly botName?: string;
readonly credentials?: GitHubChannelCredentials;
readonly progress?: GitHubProgressConfig;
}
@@ -97,6 +99,14 @@ export function createDefaultEvents(options: GitHubDefaultEventOptions = {}): Gi
await postCommentChunks(channel, event.message);
},
+ async "input.requested"(event, channel, _ctx) {
+ if (event.requests.length === 0) return;
+ const sections = event.requests.map(renderInputRequest);
+ const replyInstruction = renderReplyInstruction(event.requests, options.botName);
+ if (replyInstruction !== undefined) sections.push(replyInstruction);
+ await postCommentChunks(channel, sections.join("\n\n"));
+ },
+
async "session.failed"(event, channel) {
const hint = formatErrorHint(event);
const errorId = extractErrorId(event.details);
@@ -123,6 +133,36 @@ export function createDefaultEvents(options: GitHubDefaultEventOptions = {}): Gi
};
}
+function renderInputRequest(request: InputRequest): string {
+ const lines = [request.prompt];
+ if (request.options !== undefined && request.options.length > 0) {
+ lines.push(
+ "",
+ ...request.options.map((option, index) => {
+ const description = option.description ? ` - ${option.description}` : "";
+ return `${index + 1}. ${option.label}${description}`;
+ }),
+ );
+ }
+ if (request.allowFreeform === true) {
+ lines.push("", "You can also reply with a custom answer.");
+ }
+ return lines.join("\n");
+}
+
+// The default onComment hook only dispatches comments that @mention the bot,
+// so a prompt without this instruction invites replies that are silently ignored.
+function renderReplyInstruction(
+ requests: readonly InputRequest[],
+ botName: string | undefined,
+): string | undefined {
+ const name = botName?.trim();
+ if (!name) return undefined;
+ const firstOption = requests.find((request) => (request.options?.length ?? 0) > 0)?.options?.[0];
+ const example = firstOption?.label ?? "<your answer>";
+ return `Answer by mentioning me in a reply, e.g. \`@${name} ${example}\`.`;
+}
+
async function checkoutRepositoryForTurn(
channel: Parameters<NonNullable<GitHubChannelEvents["turn.started"]>>[1],
ctx: SessionContext,
diff --git a/packages/eve/src/public/channels/github/githubChannel.test.ts b/packages/eve/src/public/channels/github/githubChannel.test.ts
index 2ad40c879..2be0bc52d 100644
--- a/packages/eve/src/public/channels/github/githubChannel.test.ts
+++ b/packages/eve/src/public/channels/github/githubChannel.test.ts
@@ -803,6 +803,135 @@ describe("githubChannel", () => {
);
});
+ it("posts input requests through the issue comments API", async () => {
+ const fetchMock = vi.fn().mockResolvedValue(new Response(JSON.stringify({ id: 77 })));
+ const adapter = withState(
+ getAdapter(
+ githubChannel({
+ api: { apiBaseUrl: "https://github.test", fetch: fetchMock },
+ botName: "testbot",
+ credentials: {
+ appId: "test-app",
+ webhookSecret: SECRET,
+ },
+ }),
+ ),
+ {
+ conversationKind: "issue",
+ installationId: 55,
+ issueNumber: 5,
+ owner: "vercel",
+ repo: "eve",
+ repositoryId: 123,
+ },
+ );
+ const ctx = buildAdapterContext(adapter, stubAccessor());
+
+ await callEvent(
+ adapter,
+ makeEvent("input.requested", {
+ requests: [
+ {
+ action: { callId: "call_1", input: {}, kind: "tool-call", toolName: "deploy" },
+ options: [
+ { id: "approve", label: "Yes" },
+ { id: "deny", label: "No" },
+ ],
+ prompt: "Approve this change?",
+ requestId: "call_1",
+ },
+ ],
+ sequence: 0,
+ stepIndex: 0,
+ turnId: "t1",
+ }),
+ ctx,
+ );
+
+ expect(fetchMock).toHaveBeenCalledTimes(1);
+ expect(JSON.parse(String((fetchMock.mock.calls[0]![1] as RequestInit).body))).toEqual({
+ body: "Approve this change?\n\n1. Yes\n2. No\n\nAnswer by mentioning me in a reply, e.g. `@testbot Yes`.",
+ });
+ });
+
+ it("omits the mention instruction when no bot name is configured", async () => {
+ const fetchMock = vi.fn().mockResolvedValue(new Response(JSON.stringify({ id: 78 })));
+ const adapter = withState(
+ getAdapter(
+ githubChannel({
+ api: { apiBaseUrl: "https://github.test", fetch: fetchMock },
+ credentials: { appId: "test-app", webhookSecret: SECRET },
+ }),
+ ),
+ {
+ conversationKind: "issue",
+ installationId: 55,
+ issueNumber: 5,
+ owner: "vercel",
+ repo: "eve",
+ repositoryId: 123,
+ },
+ );
+
+ await callEvent(
+ adapter,
+ makeEvent("input.requested", {
+ requests: [
+ {
+ action: { callId: "call_1", input: {}, kind: "tool-call", toolName: "deploy" },
+ options: [
+ { id: "approve", label: "Yes" },
+ { id: "deny", label: "No" },
+ ],
+ prompt: "Approve this change?",
+ requestId: "call_1",
+ },
+ ],
+ sequence: 0,
+ stepIndex: 0,
+ turnId: "t1",
+ }),
+ buildAdapterContext(adapter, stubAccessor()),
+ );
+
+ expect(JSON.parse(String((fetchMock.mock.calls[0]![1] as RequestInit).body))).toEqual({
+ body: "Approve this change?\n\n1. Yes\n2. No",
+ });
+ });
+
+ it("does not post an empty input request comment", async () => {
+ const fetchMock = vi.fn();
+ const adapter = withState(
+ getAdapter(
+ githubChannel({
+ api: { apiBaseUrl: "https://github.test", fetch: fetchMock },
+ credentials: { appId: "test-app", webhookSecret: SECRET },
+ }),
+ ),
+ {
+ conversationKind: "issue",
+ installationId: 55,
+ issueNumber: 5,
+ owner: "vercel",
+ repo: "eve",
+ repositoryId: 123,
+ },
+ );
+
+ await callEvent(
+ adapter,
+ makeEvent("input.requested", {
+ requests: [],
+ sequence: 0,
+ stepIndex: 0,
+ turnId: "t1",
+ }),
+ buildAdapterContext(adapter, stubAccessor()),
+ );
+
+ expect(fetchMock).not.toHaveBeenCalled();
+ });
+
it("turn.started adds an eyes reaction to the triggering comment", async () => {
const fetchMock = vi
.fn()
diff --git a/packages/eve/src/public/channels/github/githubChannel.ts b/packages/eve/src/public/channels/github/githubChannel.ts
index 9472f5dac..9c1b4b2e8 100644
--- a/packages/eve/src/public/channels/github/githubChannel.ts
+++ b/packages/eve/src/public/channels/github/githubChannel.ts
@@ -127,9 +127,9 @@ type GitHubSessionFailedHandler = (
/**
* Event handlers for `githubChannel({ events })`. The channel installs built-in
* handlers for `turn.started` (eyes reaction plus repo checkout),
- * `message.completed` (posts the reply), and `session.failed`/`turn.failed`
- * (posts an error comment). A handler supplied here replaces the built-in for
- * that key rather than running alongside it.
+ * `message.completed` (posts the reply), `input.requested` (posts the prompt),
+ * and `session.failed`/`turn.failed` (posts an error comment). A handler supplied
+ * here replaces the built-in for that key rather than running alongside it.
*/
export interface GitHubChannelEvents {
readonly "action.partial"?: GitHubEventHandler<"action.partial">;
@@ -225,6 +225,7 @@ export function githubChannel(config: GitHubChannelConfig = {}): GitHubChannel {
const mergedEvents: GitHubChannelEvents = {
...createDefaultEvents({
api: config.api,
+ botName,
credentials: config.credentials,
progress: config.progress,
}),