The Open Framework for Building Agents
fix(eve): restore Slack auth public status (#116)
Allen Zhou0dca7949b07c
diff --git a/.changeset/slack-auth-public-status.md b/.changeset/slack-auth-public-status.mdnew file mode 100644index 000000000..5697bb761--- /dev/null+++ b/.changeset/slack-auth-public-status.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Restore Slack authorization status updates by posting a link-free public status while sending the sign-in challenge privately, then updating the public status when authorization completes.diff --git a/docs/channels/slack.mdx b/docs/channels/slack.mdxindex c9bf73da5..f385a1a9d 100644--- a/docs/channels/slack.mdx+++ b/docs/channels/slack.mdx@@ -105,7 +105,7 @@ export default slackChannel({HITL renders as Slack buttons and selects. When the user responds, the parked session (paused awaiting input) resumes.-Authorization prompts are private. A sign-in challenge (OAuth URL, device code) is a credential. Anyone who completes it binds their identity to the session's connection. The default `authorization.required` handler delivers the challenge ephemerally to the triggering user, device code included, and posts a public link-free status only when it has no user to target. The handler receives a private-delivery context with `postEphemeral`, `postDirectMessage` (needs the `im:write` scope), and `state`. There is, intentionally, no public `post` and no raw API access.+Authorization prompts split public status from private credentials. A sign-in challenge (OAuth URL, device code) is a credential. Anyone who completes it binds their identity to the session's connection. The default `authorization.required` handler posts a public, link-free status in the thread, delivers the actual challenge ephemerally to the triggering user, device code included, and then updates that public status when `authorization.completed` fires. The handler receives a private-delivery context with `postEphemeral`, `postDirectMessage` (needs the `im:write` scope), and `state`. There is, intentionally, no public `post` and no raw API access.```tsevents: {diff --git a/packages/eve/src/public/channels/slack/connections.ts b/packages/eve/src/public/channels/slack/connections.tsindex a9090d721..86fe16b74 100644--- a/packages/eve/src/public/channels/slack/connections.ts+++ b/packages/eve/src/public/channels/slack/connections.ts@@ -5,16 +5,16 @@* an OAuth-style authorization flow (e.g. signing in to Linear). The* challenge is a credential: anyone in a shared thread could complete a* posted sign-in link and bind their own identity to the session. The- * default handler therefore delivers the challenge as an ephemeral- * "Sign in with X" message visible only to the triggering user.+ * default handler therefore posts a link-free public status while+ * delivering the actual challenge as an ephemeral "Sign in with X"+ * message visible only to the triggering user.*- * Only when no user can be targeted (no triggering user id, no challenge- * URL, or the ephemeral delivery fails) does the handler fall back to a- * public status post, link-free by construction. The matching- * `authorization.completed` handler edits that fallback post in place to+ * When no user can be targeted (no triggering user id, no challenge+ * URL, or the ephemeral delivery fails), the public status still leaves+ * the shared thread with safe progress feedback. The matching+ * `authorization.completed` handler edits that status post in place to* surface the outcome (`authorized` / `declined` / `failed` /- * `timed-out`); on the normal ephemeral path there is nothing to edit- * and the outcome surfaces through the resumed turn itself.+ * `timed-out`).*/import type { ConnectionAuthorizationOutcome } from "#protocol/message.js";@@ -32,12 +32,11 @@ export function formatConnectionDisplayName(connectionName: string): string {}/**- * Public fallback status text for an authorization challenge that could- * not be delivered ephemerally. Deliberately link-free: it must stay safe- * to post in a shared thread. When the channel cannot identify a- * triggering user (rare — schedule-initiated sessions or events that lack- * actor metadata) the text drops the "Connect with" call-to-action since- * there's no one to act on it.+ * Public status text for an authorization challenge. Deliberately+ * link-free: it must stay safe to post in a shared thread. When the+ * channel cannot identify a triggering user (rare — schedule-initiated+ * sessions or events that lack actor metadata) the text drops the+ * "Connect with" call-to-action since there's no one to act on it.*/export function buildAuthRequiredPublicText(input: {readonly displayName: string;@@ -50,10 +49,9 @@ export function buildAuthRequiredPublicText(input: {}/**- * Final-state markdown for the public fallback status message. Edited in- * place by `authorization.completed` so the thread sees resolution- * without scrolling. Unused on the normal ephemeral path, which posts no- * status message.+ * Final-state markdown for the public status message. Edited in place by+ * `authorization.completed` so the thread sees resolution without+ * scrolling.*/export function buildAuthCompletedText(input: {readonly displayName: string;diff --git a/packages/eve/src/public/channels/slack/defaults.test.ts b/packages/eve/src/public/channels/slack/defaults.test.tsindex 64a8eb647..c96bffce5 100644--- a/packages/eve/src/public/channels/slack/defaults.test.ts+++ b/packages/eve/src/public/channels/slack/defaults.test.ts@@ -37,17 +37,20 @@ function authRequiredEvent(}describe("defaultEvents authorization.required", () => {- it("delivers the challenge ephemerally to the triggering user and posts nothing publicly", async () => {+ it("posts a public status and delivers the challenge ephemerally to the triggering user", async () => {const { channel, post, postEphemeral } = buildChannelStub({ triggeringUserId: "U777" });await defaultEvents["authorization.required"]!(authRequiredEvent(), channel, sessionCtx);+ expect(post).toHaveBeenCalledTimes(1);+ const publicText = post.mock.calls[0]?.[0] as string;+ expect(publicText).toBe("Connect with Notion to continue");+ expect(publicText).not.toContain("https://");expect(postEphemeral).toHaveBeenCalledTimes(1);expect(postEphemeral.mock.calls[0]?.[0]).toBe("U777");const message = postEphemeral.mock.calls[0]?.[1] as { text: string; blocks: unknown[] };expect(message.text).toContain("https://connect.example.com/a/sca_1");- expect(post).not.toHaveBeenCalled();- expect(channel.state.pendingAuthMessageTs).toBeUndefined();+ expect(channel.state.pendingAuthMessageTs).toEqual({ notion: "ts1" });});it("renders the device user code in the ephemeral blocks and fallback text", async () => {@@ -65,7 +68,7 @@ describe("defaultEvents authorization.required", () => {});it("renders the challenge displayName instead of the title-cased connection name", async () => {- const { channel, postEphemeral } = buildChannelStub({ triggeringUserId: "U777" });+ const { channel, post, postEphemeral } = buildChannelStub({ triggeringUserId: "U777" });await defaultEvents["authorization.required"]!(authRequiredEvent({ displayName: "Notion Workspace" }),@@ -73,11 +76,12 @@ describe("defaultEvents authorization.required", () => {sessionCtx,);+ expect(post.mock.calls[0]?.[0]).toBe("Connect with Notion Workspace to continue");const message = postEphemeral.mock.calls[0]?.[1] as { text: string };expect(message.text).toContain("Sign in with Notion Workspace");});- it("falls back to a link-free public status when there is no triggering user", async () => {+ it("posts a link-free public status when there is no triggering user", async () => {const { channel, post, postEphemeral } = buildChannelStub({ triggeringUserId: null });await defaultEvents["authorization.required"]!(authRequiredEvent(), channel, sessionCtx);@@ -90,7 +94,7 @@ describe("defaultEvents authorization.required", () => {expect(channel.state.pendingAuthMessageTs).toEqual({ notion: "ts1" });});- it("falls back to a link-free public status when the ephemeral delivery fails", async () => {+ it("keeps the link-free public status when the ephemeral delivery fails", async () => {const { channel, post, postEphemeral } = buildChannelStub({ triggeringUserId: "U777" });postEphemeral.mockRejectedValueOnce(new Error("ephemeral rejected"));@@ -102,10 +106,23 @@ describe("defaultEvents authorization.required", () => {expect(publicText).not.toContain("https://");expect(channel.state.pendingAuthMessageTs).toEqual({ notion: "ts1" });});++ it("reuses an existing public status when authorization is already pending", async () => {+ const { channel, post, postEphemeral } = buildChannelStub({+ triggeringUserId: "U777",+ pendingAuthMessageTs: { notion: "ts0" },+ });++ await defaultEvents["authorization.required"]!(authRequiredEvent(), channel, sessionCtx);++ expect(post).not.toHaveBeenCalled();+ expect(postEphemeral).toHaveBeenCalledTimes(1);+ expect(channel.state.pendingAuthMessageTs).toEqual({ notion: "ts0" });+ });});describe("defaultEvents authorization.completed", () => {- it("edits the public fallback status in place when one was posted", async () => {+ it("edits the public status in place when one was posted", async () => {const { channel, postEphemeral, request } = buildChannelStub({triggeringUserId: "U777",pendingAuthMessageTs: { notion: "ts1" },@@ -152,7 +169,7 @@ describe("defaultEvents authorization.completed", () => {});});- it("stays silent when no fallback status was posted", async () => {+ it("stays silent when no public status was recorded", async () => {const { channel, post, postEphemeral, request } = buildChannelStub({triggeringUserId: "U777",});diff --git a/packages/eve/src/public/channels/slack/defaults.ts b/packages/eve/src/public/channels/slack/defaults.tsindex 09c6f9fee..27439adfc 100644--- a/packages/eve/src/public/channels/slack/defaults.ts+++ b/packages/eve/src/public/channels/slack/defaults.ts@@ -109,7 +109,7 @@ export function defaultInputRequestedHandler(): NonNullable<SlackChannelEvents["* and the connection-authorization status flow. Each is overridable* per-event by passing the same key under `slackChannel({ events })`.* Typed as the internal full-context map because the default- * `authorization.required` handler owns the public link-free fallback,+ * `authorization.required` handler owns the public link-free status,* which user overrides cannot express.*/export const defaultEvents: SlackChannelInternalEvents = {@@ -196,6 +196,31 @@ export const defaultEvents: SlackChannelInternalEvents = {const triggeringUserId = channel.state.triggeringUserId ?? null;const challengeUrl = event.authorization?.url;+ // Post a public, link-free status so everyone in the thread can see+ // the session is blocked and later see it complete. The challenge+ // itself remains private.+ const pending = channel.state.pendingAuthMessageTs ?? {};+ if (pending[event.name] === undefined) {+ const publicText = buildAuthRequiredPublicText({+ displayName,+ hasUser: triggeringUserId !== null,+ });+ try {+ const sent = await channel.thread.post(publicText);+ if (sent.id) {+ channel.state.pendingAuthMessageTs = {+ ...pending,+ [event.name]: sent.id,+ };+ }+ } catch (error) {+ log.error("Slack auth public message delivery failed", {+ name: event.name,+ error,+ });+ }+ }+// The challenge is user-specific: the sign-in link (and device code)// must only ever be visible to the triggering user, never posted into// the shared thread.@@ -214,7 +239,6 @@ export const defaultEvents: SlackChannelInternalEvents = {? `Sign in with ${displayName}: ${challengeUrl} (code: ${userCode})`: `Sign in with ${displayName}: ${challengeUrl}`,});- return;} catch (error) {log.error("Slack auth ephemeral delivery failed", {name: event.name,@@ -222,28 +246,6 @@ export const defaultEvents: SlackChannelInternalEvents = {});}}-- // Fallback: no user to whisper to, or the ephemeral delivery failed.- // The public status is link-free by construction, so the thread learns- // the session is blocked without the challenge itself ever going public.- const publicText = buildAuthRequiredPublicText({- displayName,- hasUser: triggeringUserId !== null,- });- try {- const sent = await channel.thread.post(publicText);- if (sent.id) {- channel.state.pendingAuthMessageTs = {- ...channel.state.pendingAuthMessageTs,- [event.name]: sent.id,- };- }- } catch (error) {- log.error("Slack auth public message delivery failed", {- name: event.name,- error,- });- }},async "authorization.completed"(event, channel, _ctx) {diff --git a/packages/eve/src/public/channels/slack/slackChannel.ts b/packages/eve/src/public/channels/slack/slackChannel.tsindex ae8cf8eb8..97bb7d5ca 100644--- a/packages/eve/src/public/channels/slack/slackChannel.ts+++ b/packages/eve/src/public/channels/slack/slackChannel.ts@@ -179,11 +179,10 @@ export interface SlackChannelState {lastReasoningTypingStatus?: string | null;/*** Connection name to Slack message ts. Each entry is the public- * link-free fallback status post created by the default- * `authorization.required` handler when the challenge could not be- * delivered ephemerally; the matching `authorization.completed`- * handler edits it in place to surface the resolution outcome. The- * normal ephemeral path stores nothing here.+ * link-free status post created by the default+ * `authorization.required` handler; the matching+ * `authorization.completed` handler edits it in place to surface the+ * resolution outcome.*/pendingAuthMessageTs?: Record<string, string>;}@@ -347,8 +346,8 @@ export interface SlackChannelEvents {* Full-context variant of {@link SlackChannelEvents} consumed by the* channel internals. The framework's default `authorization.required`* handler keeps the full {@link SlackEventContext} because it owns the- * public link-free fallback for sessions with no user to target- * privately. The factory adapts user overrides into this shape with+ * public link-free status while user overrides remain private-only. The+ * factory adapts user overrides into this shape with* {@link constrainAuthorizationRequired}.*/export interface SlackChannelInternalEvents extends Omit<