The Open Framework for Building Agents
fix(eve): discord - restore environment credential fallback (#648)
Andrew Barba173fa5d806d9
diff --git a/.changeset/discord-environment-credentials.md b/.changeset/discord-environment-credentials.mdnew file mode 100644index 000000000..e194efadf--- /dev/null+++ b/.changeset/discord-environment-credentials.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Restore the `DISCORD_BOT_TOKEN` environment fallback for proactive Discord messages, typing indicators, and bot-authenticated requests when `discordChannel()` is configured without explicit credentials.diff --git a/packages/eve/src/public/channels/discord/discordChannel.test.ts b/packages/eve/src/public/channels/discord/discordChannel.test.tsindex 290e5d806..fb88340a7 100644--- a/packages/eve/src/public/channels/discord/discordChannel.test.ts+++ b/packages/eve/src/public/channels/discord/discordChannel.test.ts@@ -163,6 +163,7 @@ function commandBody(overrides?: Record<string, unknown>): string {}afterEach(() => {+ vi.unstubAllEnvs();vi.unstubAllGlobals();});@@ -414,6 +415,41 @@ describe("discordChannel() default event handlers", () => {).resolves.toEqual(makeEvent("turn.started", {}));});+ it("uses the environment bot token for proactive messages", async () => {+ const fetchMock = vi.fn().mockResolvedValue(+ new Response(JSON.stringify({ channel_id: "C01", id: "M01" }), {+ headers: { "content-type": "application/json" },+ }),+ );+ vi.stubGlobal("fetch", fetchMock);+ const adapter = withState(getAdapter(discordChannel()), {+ channelId: "C01",+ initialResponseSent: true,+ });+ const { accessor } = captureAccessor("discord:C01:");+ const ctx = buildAdapterContext(adapter, accessor);+ vi.stubEnv("DISCORD_BOT_TOKEN", "environment-token");++ await callEvent(+ adapter,+ makeEvent("message.completed", {+ finishReason: "stop",+ message: "Hello from the agent",+ sequence: 0,+ stepIndex: 0,+ turnId: "t1",+ }),+ ctx,+ );++ expect(fetchMock).toHaveBeenCalledTimes(1);+ const [url, init] = fetchMock.mock.calls[0]!;+ expect(String(url)).toBe("https://discord.com/api/v10/channels/C01/messages");+ expect(new Headers((init as RequestInit).headers).get("authorization")).toBe(+ "Bot environment-token",+ );+ });+it("edits the original response and rekeys the session on the first post", async () => {const fetchMock = vi.fn().mockResolvedValue(new Response(JSON.stringify({ channel_id: "C01", id: "M01" }), {diff --git a/packages/eve/src/public/channels/discord/discordChannel.ts b/packages/eve/src/public/channels/discord/discordChannel.tsindex e4c5925fc..637b730ad 100644--- a/packages/eve/src/public/channels/discord/discordChannel.ts+++ b/packages/eve/src/public/channels/discord/discordChannel.ts@@ -11,6 +11,7 @@ import {createDiscordFollowupMessage,discordContinuationToken,editDiscordOriginalResponse,+ resolveDiscordBotToken,sendDiscordChannelMessage,splitDiscordMessageContent,triggerDiscordTypingIndicator,@@ -674,7 +675,7 @@ function mergeCredentials(): DiscordChannelCredentials {const merged: DiscordChannelCredentials = {applicationId: state.applicationId ?? credentials?.applicationId,- botToken: credentials?.botToken,+ botToken: credentials?.botToken ?? (() => resolveDiscordBotToken()),publicKey: credentials?.publicKey,webhookVerifier: credentials?.webhookVerifier,};