The Open Framework for Building Agents
[7/7] fix(eve): fix sign-in and budget prompt gaps in Discord, Slack, Teams, Twilio, TUI (#4265)
Ben Pankow52ebf7df2cdf
diff --git a/.changeset/sign-in-budget-channel-fixes.md b/.changeset/sign-in-budget-channel-fixes.mdnew file mode 100644index 000000000..8dab4af5f--- /dev/null+++ b/.changeset/sign-in-budget-channel-fixes.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Discord now posts session budget prompts instead of failing on a button ID over 100 characters. Slack sends its private sign-in prompt for sign-ins that only have instructions. Teams sign-in cards show the confirmation code and instructions, Twilio texts sign-ins and their outcome, and the dev TUI labels a sign-in with its display name. Discord buttons posted before this update stop working once it's deployed.diff --git a/packages/eve/src/cli/dev/tui/transcript.test.ts b/packages/eve/src/cli/dev/tui/transcript.test.tsindex 638adc31e..089951955 100644--- a/packages/eve/src/cli/dev/tui/transcript.test.ts+++ b/packages/eve/src/cli/dev/tui/transcript.test.ts@@ -727,7 +727,7 @@ describe("ConversationTranscript", () => {event(createAuthorizationRequiredEvent({attemptId,- authorization: { url: `https://idp.example.com/${attemptId}` },+ authorization: { displayName: "Linear", url: `https://idp.example.com/${attemptId}` },description: "Connect Linear",name: "linear",sequence: 1,@@ -752,8 +752,8 @@ describe("ConversationTranscript", () => {),]);expect(new ConversationTranscript().project(view(state, true), options)).toEqual([- expect.objectContaining({ title: "linear · authorization · authorized", live: false }),- expect.objectContaining({ title: "linear · authorization · required", live: true }),+ expect.objectContaining({ title: "Linear · authorization · authorized", live: false }),+ expect.objectContaining({ title: "Linear · authorization · required", live: true }),]);});diff --git a/packages/eve/src/cli/dev/tui/transcript.ts b/packages/eve/src/cli/dev/tui/transcript.tsindex a103e0d70..d6bfa849a 100644--- a/packages/eve/src/cli/dev/tui/transcript.ts+++ b/packages/eve/src/cli/dev/tui/transcript.ts@@ -552,7 +552,7 @@ export class ConversationTranscript {const terminalMessage = authorizationTerminalMessage(state);return {kind: "connection-auth",- title: `${stripTerminalControls(part.name)} · authorization · ${state}`,+ title: `${stripTerminalControls(part.displayName)} · authorization · ${state}`,body: formatAuthorization(part, terminalMessage),preformatted: true,live: terminalMessage === undefined,diff --git a/packages/eve/src/internal/testing/channel-conformance/MATRIX.md b/packages/eve/src/internal/testing/channel-conformance/MATRIX.mdindex 9f9ddcd10..1a1d1c3fb 100644--- a/packages/eve/src/internal/testing/channel-conformance/MATRIX.md+++ b/packages/eve/src/internal/testing/channel-conformance/MATRIX.md@@ -39,20 +39,20 @@ pnpm --filter eve exec vitest run --config vitest.unit.config.ts channel-conform| approving by text clears the approval's buttons | —<sup>[4](#note-4)</sup> | ✅ | ✅ | —<sup>[1](#note-1)</sup> | —<sup>[2](#note-2)</sup> | —<sup>[2](#note-2)</sup> | —<sup>[1](#note-1)</sup> | —<sup>[1](#note-1)</sup> | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | —<sup>[1](#note-1)</sup> | —<sup>[1](#note-1)</sup> | —<sup>[1](#note-1)</sup> || pressing Approve names who approved on the approval | —<sup>[6](#note-6)</sup> | ❌<sup>[7](#note-7)</sup> | | —<sup>[1](#note-1)</sup> | ❌<sup>[7](#note-7)</sup> | | —<sup>[1](#note-1)</sup> | | ✅ | | ✅ | | ❌<sup>[7](#note-7)</sup> | | —<sup>[1](#note-1)</sup> | —<sup>[1](#note-1)</sup> | —<sup>[1](#note-1)</sup> || approving by text names who approved on the approval | —<sup>[4](#note-4)</sup> | ❌<sup>[7](#note-7)</sup> | ❌<sup>[7](#note-7)</sup> | —<sup>[1](#note-1)</sup> | —<sup>[2](#note-2)</sup> | —<sup>[2](#note-2)</sup> | —<sup>[1](#note-1)</sup> | —<sup>[1](#note-1)</sup> | ❌<sup>[8](#note-8)</sup> | ❌<sup>[8](#note-8)</sup> | ❌<sup>[7](#note-7)</sup> | ❌<sup>[7](#note-7)</sup> | ❌<sup>[7](#note-7)</sup> | ❌<sup>[7](#note-7)</sup> | —<sup>[1](#note-1)</sup> | —<sup>[1](#note-1)</sup> | —<sup>[1](#note-1)</sup> |-| running out of budget opens budget prompt | ✅ | ✅ | | ✅ | ❌<sup>[9](#note-9)</sup> | | ✅ | | ✅ | | ✅ | | ✅ | | ✅ | ✅ | ✅ |-| pressing approve on budget prompt allows agent to continue | ✅ | ✅ | | —<sup>[1](#note-1)</sup> | ❌<sup>[9](#note-9)</sup> | | —<sup>[1](#note-1)</sup> | | ✅ | | ✅ | | ✅ | | —<sup>[1](#note-1)</sup> | —<sup>[1](#note-1)</sup> | —<sup>[1](#note-1)</sup> |+| running out of budget opens budget prompt | ✅ | ✅ | | ✅ | ✅ | | ✅ | | ✅ | | ✅ | | ✅ | | ✅ | ✅ | ✅ |+| pressing approve on budget prompt allows agent to continue | ✅ | ✅ | | —<sup>[1](#note-1)</sup> | ✅ | | —<sup>[1](#note-1)</sup> | | ✅ | | ✅ | | ✅ | | —<sup>[1](#note-1)</sup> | —<sup>[1](#note-1)</sup> | —<sup>[1](#note-1)</sup> || reply of approve on budget prompt allows agent to continue | ✅ | ✅ | ✅ | ✅ | —<sup>[2](#note-2)</sup> | —<sup>[2](#note-2)</sup> | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |-| pressing stop on budget prompt halts work, next message asks again | ❌<sup>[10](#note-10)</sup> | ✅ | ✅ | —<sup>[1](#note-1)</sup> | —<sup>[2](#note-2)</sup> | —<sup>[2](#note-2)</sup> | —<sup>[1](#note-1)</sup> | —<sup>[1](#note-1)</sup> | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | —<sup>[1](#note-1)</sup> | —<sup>[1](#note-1)</sup> | —<sup>[1](#note-1)</sup> |-| reply of stop on budget prompt halts work, next message asks again | ❌<sup>[10](#note-10)</sup> | ✅ | ✅ | ✅ | —<sup>[2](#note-2)</sup> | —<sup>[2](#note-2)</sup> | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |-| query sent during budget prompt answered after budget approval | ❌<sup>[11](#note-11)</sup> | ❌<sup>[11](#note-11)</sup> | ❌<sup>[11](#note-11)</sup> | ❌<sup>[11](#note-11)</sup> | —<sup>[2](#note-2)</sup> | —<sup>[2](#note-2)</sup> | ❌<sup>[11](#note-11)</sup> | ❌<sup>[11](#note-11)</sup> | ❌<sup>[11](#note-11)</sup> | ❌<sup>[11](#note-11)</sup> | ❌<sup>[11](#note-11)</sup> | ❌<sup>[11](#note-11)</sup> | ❌<sup>[11](#note-11)</sup> | ❌<sup>[11](#note-11)</sup> | ❌<sup>[11](#note-11)</sup> | ❌<sup>[11](#note-11)</sup> | ❌<sup>[11](#note-11)</sup> |-| a sign-in names the service and shows its sign-in link | ❌<sup>[12](#note-12)</sup> | ❌<sup>[13](#note-13)</sup> | ✅ | ✅ | ❌<sup>[14](#note-14)</sup> | ❌<sup>[14](#note-14)</sup> | ❌<sup>[13](#note-13)</sup> | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | —<sup>[15](#note-15)</sup> | ✅ | ❌<sup>[14](#note-14)</sup> |-| a sign-in shows its confirmation code | ✅ | ❌<sup>[13](#note-13)</sup> | ✅ | ✅ | ❌<sup>[14](#note-14)</sup> | ❌<sup>[14](#note-14)</sup> | ❌<sup>[13](#note-13)</sup> | ✅ | ✅ | ✅ | ❌<sup>[16](#note-16)</sup> | ❌<sup>[16](#note-16)</sup> | ✅ | ✅ | —<sup>[15](#note-15)</sup> | ✅ | ❌<sup>[14](#note-14)</sup> |-| only the person signing in sees the sign-in link and code | —<sup>[17](#note-17)</sup> | ✅ | —<sup>[17](#note-17)</sup> | —<sup>[17](#note-17)</sup> | ✅ | —<sup>[17](#note-17)</sup> | ✅ | —<sup>[17](#note-17)</sup> | ✅ | —<sup>[17](#note-17)</sup> | ❌<sup>[18](#note-18)</sup> | —<sup>[17](#note-17)</sup> | ✅ | —<sup>[17](#note-17)</sup> | ✅ | ❌<sup>[19](#note-19)</sup> | —<sup>[17](#note-17)</sup> |-| a sign-in without a link shows its instructions | ✅ | ❌<sup>[13](#note-13)</sup> | ✅ | ✅ | ❌<sup>[14](#note-14)</sup> | ❌<sup>[14](#note-14)</sup> | ❌<sup>[13](#note-13)</sup> | ✅ | ❌<sup>[20](#note-20)</sup> | ❌<sup>[20](#note-20)</sup> | ❌<sup>[21](#note-21)</sup> | ❌<sup>[21](#note-21)</sup> | ✅ | ✅ | ❌<sup>[14](#note-14)</sup> | ✅ | ❌<sup>[14](#note-14)</sup> |+| pressing stop on budget prompt halts work, next message asks again | ❌<sup>[9](#note-9)</sup> | ✅ | ✅ | —<sup>[1](#note-1)</sup> | —<sup>[2](#note-2)</sup> | —<sup>[2](#note-2)</sup> | —<sup>[1](#note-1)</sup> | —<sup>[1](#note-1)</sup> | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | —<sup>[1](#note-1)</sup> | —<sup>[1](#note-1)</sup> | —<sup>[1](#note-1)</sup> |+| reply of stop on budget prompt halts work, next message asks again | ❌<sup>[9](#note-9)</sup> | ✅ | ✅ | ✅ | —<sup>[2](#note-2)</sup> | —<sup>[2](#note-2)</sup> | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |+| query sent during budget prompt answered after budget approval | ❌<sup>[10](#note-10)</sup> | ❌<sup>[10](#note-10)</sup> | ❌<sup>[10](#note-10)</sup> | ❌<sup>[10](#note-10)</sup> | —<sup>[2](#note-2)</sup> | —<sup>[2](#note-2)</sup> | ❌<sup>[10](#note-10)</sup> | ❌<sup>[10](#note-10)</sup> | ❌<sup>[10](#note-10)</sup> | ❌<sup>[10](#note-10)</sup> | ❌<sup>[10](#note-10)</sup> | ❌<sup>[10](#note-10)</sup> | ❌<sup>[10](#note-10)</sup> | ❌<sup>[10](#note-10)</sup> | ❌<sup>[10](#note-10)</sup> | ❌<sup>[10](#note-10)</sup> | ❌<sup>[10](#note-10)</sup> |+| a sign-in names the service and shows its sign-in link | ✅ | ❌<sup>[11](#note-11)</sup> | ✅ | ✅ | ❌<sup>[12](#note-12)</sup> | ❌<sup>[12](#note-12)</sup> | ❌<sup>[11](#note-11)</sup> | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | —<sup>[13](#note-13)</sup> | ✅ | ✅ |+| a sign-in shows its confirmation code | ✅ | ❌<sup>[11](#note-11)</sup> | ✅ | ✅ | ❌<sup>[12](#note-12)</sup> | ❌<sup>[12](#note-12)</sup> | ❌<sup>[11](#note-11)</sup> | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | —<sup>[13](#note-13)</sup> | ✅ | ✅ |+| only the person signing in sees the sign-in link and code | —<sup>[14](#note-14)</sup> | ✅ | —<sup>[14](#note-14)</sup> | —<sup>[14](#note-14)</sup> | ✅ | —<sup>[14](#note-14)</sup> | ✅ | —<sup>[14](#note-14)</sup> | ✅ | —<sup>[14](#note-14)</sup> | ❌<sup>[15](#note-15)</sup> | —<sup>[14](#note-14)</sup> | ✅ | —<sup>[14](#note-14)</sup> | ✅ | ❌<sup>[16](#note-16)</sup> | —<sup>[14](#note-14)</sup> |+| a sign-in without a link shows its instructions | ✅ | ❌<sup>[11](#note-11)</sup> | ✅ | ✅ | ❌<sup>[12](#note-12)</sup> | ❌<sup>[12](#note-12)</sup> | ❌<sup>[11](#note-11)</sup> | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌<sup>[12](#note-12)</sup> | ✅ | ✅ || after signing in, the agent carries on with the request | ✅ | ✅ | | ✅ | ✅ | | ✅ | | ✅ | | ✅ | | ✅ | | ✅ | ✅ | ✅ |-| completing a sign-in tells the person it succeeded | ✅ | ✅ | ✅ | ✅ | ❌<sup>[14](#note-14)</sup> | ❌<sup>[14](#note-14)</sup> | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌<sup>[14](#note-14)</sup> | ✅ | ❌<sup>[14](#note-14)</sup> |+| completing a sign-in tells the person it succeeded | ✅ | ✅ | ✅ | ✅ | ❌<sup>[12](#note-12)</sup> | ❌<sup>[12](#note-12)</sup> | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌<sup>[12](#note-12)</sup> | ✅ | ✅ || message after ignored sign-in gets an answer, signing in late doesn't run | ✅ | ✅ | ✅ | ✅ | —<sup>[2](#note-2)</sup> | —<sup>[2](#note-2)</sup> | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |-| message after ignored sign-in tells user it was cancelled | ✅ | ✅ | ✅ | ✅ | —<sup>[2](#note-2)</sup> | —<sup>[2](#note-2)</sup> | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌<sup>[14](#note-14)</sup> | ✅ | ❌<sup>[14](#note-14)</sup> |+| message after ignored sign-in tells user it was cancelled | ✅ | ✅ | ✅ | ✅ | —<sup>[2](#note-2)</sup> | —<sup>[2](#note-2)</sup> | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌<sup>[12](#note-12)</sup> | ✅ | ✅ |## Notes@@ -64,16 +64,11 @@ pnpm --filter eve exec vitest run --config vitest.unit.config.ts channel-conform6. <a id="note-6"></a>one person answers at their own terminal; there's nobody else to tell7. <a id="note-7"></a>a resolved prompt doesn't say who answered; input.resolved carries no responder8. <a id="note-8"></a>the card loses its buttons after a typed approval but doesn't say who approved-9. <a id="note-9"></a>a budget prompt's request id overflows Discord's 100-character custom_id, so posting it throws-10. <a id="note-10"></a>a re-raised budget prompt keeps its request id, and eve/client ignores ids it has seen-11. <a id="note-11"></a>eve coalesces the queued reply with the later approve, which then matches no option-12. <a id="note-12"></a>the TUI labels a sign-in with the tool name, not the challenge's displayName-13. <a id="note-13"></a>outside a DM the bot says to continue in a direct message but never sends one-14. <a id="note-14"></a>the channel has no default sign-in renderer-15. <a id="note-15"></a>the rule applies only where the conversation is shared or private, and this one is public-16. <a id="note-16"></a>the Teams sign-in card omits the challenge's user code-17. <a id="note-17"></a>the rule applies only where the conversation is public or shared, and this one is private-18. <a id="note-18"></a>the sign-in prompt, link included, is posted to the whole thread-19. <a id="note-19"></a>the code is in the elicitation body the whole issue sees; who sees the auth signal's link is unverified-20. <a id="note-20"></a>Slack sends the private sign-in prompt only for a challenge with a URL-21. <a id="note-21"></a>the Teams sign-in card omits the challenge's instructions+9. <a id="note-9"></a>a re-raised budget prompt keeps its request id, and eve/client ignores ids it has seen+10. <a id="note-10"></a>eve coalesces the queued reply with the later approve, which then matches no option+11. <a id="note-11"></a>outside a DM the bot says to continue in a direct message but never sends one+12. <a id="note-12"></a>the channel has no default sign-in renderer+13. <a id="note-13"></a>the rule applies only where the conversation is shared or private, and this one is public+14. <a id="note-14"></a>the rule applies only where the conversation is public or shared, and this one is private+15. <a id="note-15"></a>the sign-in prompt, link included, is posted to the whole thread+16. <a id="note-16"></a>the code is in the elicitation body the whole issue sees; who sees the auth signal's link is unverifieddiff --git a/packages/eve/src/internal/testing/channel-conformance/conformance.ts b/packages/eve/src/internal/testing/channel-conformance/conformance.tsindex d8a633141..550cf2117 100644--- a/packages/eve/src/internal/testing/channel-conformance/conformance.ts+++ b/packages/eve/src/internal/testing/channel-conformance/conformance.ts@@ -159,11 +159,6 @@ const CHAT_SDK_BROKEN = {const DISCORD_BROKEN = {...unnamedAnsweredPrompts(UNNAMED_RESPONDER, ["approvalPress", "questionPress"]),- ...budgetPromptNotShown(- "a budget prompt's request id overflows Discord's 100-character custom_id, so posting it throws",- "running out of budget opens budget prompt",- "pressing approve on budget prompt allows agent to continue",- ),...noSignInRenderer("a sign-in names the service and shows its sign-in link","a sign-in shows its confirmation code",@@ -174,10 +169,6 @@ const DISCORD_BROKEN = {const SLACK_BROKEN = {...QUEUED_BUDGET_REPLY,- "a sign-in without a link shows its instructions": {- reason: "Slack sends the private sign-in prompt only for a challenge with a URL",- symptom: SIGN_IN_NOT_SHOWN,- },...staleAnsweredPrompts("only the button interaction handler edits a question; a typed answer leaves it",["questionText"],@@ -191,14 +182,6 @@ const SLACK_BROKEN = {const TEAMS_BROKEN = {...unnamedAnsweredPrompts(UNNAMED_RESPONDER, ["approvalText", "questionPress", "questionText"]),...QUEUED_BUDGET_REPLY,- "a sign-in shows its confirmation code": {- reason: "the Teams sign-in card omits the challenge's user code",- symptom: SIGN_IN_NOT_SHOWN,- },- "a sign-in without a link shows its instructions": {- reason: "the Teams sign-in card omits the challenge's instructions",- symptom: SIGN_IN_NOT_SHOWN,- },} satisfies Partial<Record<HitlRule, BrokenCell>>;/** The sign-in prompt, link included, goes to the whole thread. */@@ -282,10 +265,6 @@ const hitlConformance = {driver: tuiDriver,broken: {...QUEUED_BUDGET_REPLY,- "a sign-in names the service and shows its sign-in link": {- reason: "the TUI labels a sign-in with the tool name, not the challenge's displayName",- symptom: /Timed out waiting for the bot to show Calendar/u,- },...budgetPromptNotShown("a re-raised budget prompt keeps its request id, and eve/client ignores ids it has seen","pressing stop on budget prompt halts work, next message asks again",@@ -308,16 +287,7 @@ const hitlConformance = {twilio: [{driver: twilioDriver,- broken: {- ...QUEUED_BUDGET_REPLY,- ...noSignInRenderer(- "a sign-in names the service and shows its sign-in link",- "a sign-in shows its confirmation code",- "a sign-in without a link shows its instructions",- "completing a sign-in tells the person it succeeded",- "message after ignored sign-in tells user it was cancelled",- ),- },+ broken: QUEUED_BUDGET_REPLY,},],} satisfies Record<string, readonly ConformanceChannel[]>;diff --git a/packages/eve/src/public/channels/discord/hitl.ts b/packages/eve/src/public/channels/discord/hitl.tsindex 405a8d1b8..adc30f64d 100644--- a/packages/eve/src/public/channels/discord/hitl.ts+++ b/packages/eve/src/public/channels/discord/hitl.ts@@ -206,9 +206,14 @@ export function deriveModalInputResponses(return [parseInputResponse({ requestId: payload.requestId, text })];}+/**+ * Encodes the payload as a raw JSON array, which leaves room for long request+ * ids such as a session-limit prompt's `<sessionId>:limit:input:<tokens>`.+ */function encodeHitlCustomId(prefix: string, payload: HitlCustomIdPayload): string {- const encoded = Buffer.from(JSON.stringify(payload), "utf8").toString("base64url");- const customId = `${prefix}${encoded}`;+ const fields =+ payload.optionId === undefined ? [payload.requestId] : [payload.requestId, payload.optionId];+ const customId = `${prefix}${JSON.stringify(fields)}`;if (customId.length > DISCORD_CUSTOM_ID_MAX_LENGTH) {throw new Error("discordChannel: HITL custom_id exceeded Discord's 100-character limit.");}@@ -217,21 +222,17 @@ function encodeHitlCustomId(prefix: string, payload: HitlCustomIdPayload): strinfunction decodeHitlCustomId(customId: string, prefix: string): HitlCustomIdPayload | null {if (!customId.startsWith(prefix)) return null;+ let fields: unknown;try {- const decoded = Buffer.from(customId.slice(prefix.length), "base64url").toString("utf8");- const parsed = JSON.parse(decoded) as {- optionId?: unknown;- requestId?: unknown;- };- if (typeof parsed.requestId !== "string" || parsed.requestId.length === 0) return null;- const result: HitlCustomIdPayload = { requestId: parsed.requestId };- if (typeof parsed.optionId === "string") {- return { ...result, optionId: parsed.optionId };- }- return result;+ fields = JSON.parse(customId.slice(prefix.length));} catch {return null;}+ if (!Array.isArray(fields) || fields.length < 1 || fields.length > 2) return null;+ const [requestId, optionId] = fields as unknown[];+ if (typeof requestId !== "string" || requestId.length === 0) return null;+ if (optionId === undefined) return { requestId };+ return typeof optionId === "string" ? { optionId, requestId } : null;}function toDiscordButtonStyle(style: InputOption["style"]): number {diff --git a/packages/eve/src/public/channels/slack/connections.ts b/packages/eve/src/public/channels/slack/connections.tsindex 76ed462cf..9d7c23ded 100644--- a/packages/eve/src/public/channels/slack/connections.ts+++ b/packages/eve/src/public/channels/slack/connections.ts@@ -9,8 +9,8 @@* delivering the actual challenge as an ephemeral "Sign in"* message visible only to the Slack user behind the event's `principalId`.*- * When no user can be targeted (no Slack user for the principal, no challenge- * URL, or the ephemeral delivery fails), the public status still leaves+ * When no user can be targeted (no Slack user for the principal, no link or+ * instructions to show, 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` /@@ -68,53 +68,63 @@ export function buildAuthCompletedText(input: {return `:x: ${input.displayName} authorization ${input.outcome}${tail}`;}+/** The private sign-in prompt: a link to open, instructions to follow, or both. */+interface AuthEphemeralPrompt {+ readonly displayName: string;+ readonly instructions?: string;+ readonly url?: string;+ readonly userCode?: string;+}+/*** Block Kit blocks for the private sign-in prompt. It names the service and* why it is asking before the button, because the user may not remember which* request needed it. A device-code flow's `userCode` is a fallback the* provider shows only sometimes, so it is a quiet hint below the button.*/-export function buildAuthEphemeralBlocks(input: {- /** Lets the person cancel the held turn instead of connecting. */- readonly cancel?: SignInCancelTarget;- readonly displayName: string;- readonly url: string;- readonly userCode?: string;-}): unknown[] {+export function buildAuthEphemeralBlocks(+ input: AuthEphemeralPrompt & {+ /** Lets the person cancel the held turn instead of connecting. */+ readonly cancel?: SignInCancelTarget;+ },+): unknown[] {+ const intro =+ input.cancel === undefined+ ? `*Connect ${input.displayName}*\nTo continue, I need access to your ${input.displayName} account. Only you can see this message.`+ : `*Connect ${input.displayName}*\nI've paused until you connect your ${input.displayName} account or cancel. Only you can see this message.`;const blocks: unknown[] = [{type: "section",text: {type: "mrkdwn",- text:- input.cancel === undefined- ? `*Connect ${input.displayName}*\nTo continue, I need access to your ${input.displayName} account. Only you can see this message.`- : `*Connect ${input.displayName}*\nI've paused until you connect your ${input.displayName} account or cancel. Only you can see this message.`,+ text: hasText(input.instructions) ? `${intro}\n\n${input.instructions}` : intro,},},- {- type: "actions",- elements: [- {- type: "button",- text: { type: "plain_text", text: truncatePlainText(`Connect ${input.displayName}`) },- url: input.url,- style: "primary",- },- ...(input.cancel === undefined- ? []- : [- {- type: "button",- action_id: SIGN_IN_CANCEL_ACTION_ID,- text: { type: "plain_text", text: "Cancel" },- value: JSON.stringify(input.cancel),- },- ]),- ],- },];- if (input.userCode !== undefined && input.userCode.length > 0) {+ const buttons = [+ ...(!hasText(input.url)+ ? []+ : [+ {+ type: "button",+ text: { type: "plain_text", text: truncatePlainText(`Connect ${input.displayName}`) },+ url: input.url,+ style: "primary",+ },+ ]),+ ...(input.cancel === undefined+ ? []+ : [+ {+ type: "button",+ action_id: SIGN_IN_CANCEL_ACTION_ID,+ text: { type: "plain_text", text: "Cancel" },+ value: JSON.stringify(input.cancel),+ },+ ]),+ ];+ if (buttons.length > 0) blocks.push({ type: "actions", elements: buttons });+ if (hasText(input.userCode)) {blocks.push({type: "context",elements: [@@ -129,14 +139,18 @@ export function buildAuthEphemeralBlocks(input: {}/** Notification text for the private sign-in prompt, for clients that show no blocks. */-export function buildAuthEphemeralText(input: {- readonly displayName: string;- readonly url: string;- readonly userCode?: string;-}): string {- const code =- input.userCode !== undefined && input.userCode.length > 0- ? ` If asked for a confirmation code, enter ${input.userCode}.`- : "";- return `Connect your ${input.displayName} account to continue: ${input.url}${code}`;+export function buildAuthEphemeralText(input: AuthEphemeralPrompt): string {+ const parts = [+ !hasText(input.url)+ ? `Connect your ${input.displayName} account to continue.`+ : `Connect your ${input.displayName} account to continue: ${input.url}`,+ ];+ if (hasText(input.instructions)) parts.push(input.instructions);+ if (hasText(input.userCode))+ parts.push(`If asked for a confirmation code, enter ${input.userCode}.`);+ return parts.join(" ");+}++function hasText(value: string | undefined): value is string {+ return value !== undefined && value.length > 0;}diff --git a/packages/eve/src/public/channels/slack/defaults.ts b/packages/eve/src/public/channels/slack/defaults.tsindex 957aa7504..671f47711 100644--- a/packages/eve/src/public/channels/slack/defaults.ts+++ b/packages/eve/src/public/channels/slack/defaults.ts@@ -442,7 +442,8 @@ export const defaultEvents: SlackChannelInternalEvents = {// The challenge is user-specific: the sign-in link (and device code)// must only ever be visible to the person who started the sign-in, never posted into// the shared thread.- if (recipientUserId && challengeUrl) {+ const instructions = event.authorization?.instructions;+ if (recipientUserId && (challengeUrl || instructions)) {const { channelId, threadTs } = channel.state;// The turn's own sign-in holds it, so the prompt can cancel that turn.const cancel =@@ -452,6 +453,7 @@ export const defaultEvents: SlackChannelInternalEvents = {const prompt = {cancel,displayName,+ instructions,url: challengeUrl,userCode: event.authorization?.userCode,};diff --git a/packages/eve/src/public/channels/teams/defaults.ts b/packages/eve/src/public/channels/teams/defaults.tsindex d454de85b..4942f3ecc 100644--- a/packages/eve/src/public/channels/teams/defaults.ts+++ b/packages/eve/src/public/channels/teams/defaults.ts@@ -166,9 +166,20 @@ export const defaultEvents: TeamsChannelEvents = {async "authorization.required"(event, channel, _ctx) {const displayName = event.authorization?.displayName ?? formatConnectionDisplayName(event.name);const url = event.authorization?.url;- const text = url- ? `Authorization required for ${displayName}: ${url}`- : `Authorization required for ${displayName}.`;+ const instructions = event.authorization?.instructions;+ const userCode = event.authorization?.userCode;+ const codeHint = userCode+ ? `If ${displayName} asks for a confirmation code, enter ${userCode}.`+ : undefined;+ const text = [+ url+ ? `Authorization required for ${displayName}: ${url}`+ : `Authorization required for ${displayName}.`,+ instructions,+ codeHint,+ ]+ .filter(Boolean)+ .join(" ");const posted = await channel.thread.post({attachments: [{@@ -197,6 +208,9 @@ export const defaultEvents: TeamsChannelEvents = {type: "TextBlock",wrap: true,},+ ...[instructions, codeHint]+ .filter((line): line is string => Boolean(line))+ .map((line) => ({ text: line, type: "TextBlock", wrap: true })),],type: "AdaptiveCard",version: channel.adaptiveCardVersion,diff --git a/packages/eve/src/public/channels/twilio/defaults.ts b/packages/eve/src/public/channels/twilio/defaults.tsindex 0f3e604cf..3bcafbbe3 100644--- a/packages/eve/src/public/channels/twilio/defaults.ts+++ b/packages/eve/src/public/channels/twilio/defaults.ts@@ -13,6 +13,8 @@ import type {TwilioInboundResult,TwilioVoiceResult,} from "#public/channels/twilio/twilioChannel.js";+import type { ConnectionAuthorizationOutcome } from "#protocol/message.js";+import { displayProperName } from "#shared/display-name.js";import type { InputRequest } from "#shared/input.js";/** Default phone-number auth projection for Twilio webhook actors. */@@ -69,7 +71,7 @@ export function defaultOnVoiceTranscription(};}-/** Built-in Twilio event handlers for text delivery and terminal errors. */+/** Built-in Twilio event handlers for text delivery, sign-ins, and terminal errors. */export const defaultEvents: TwilioChannelEvents = {async "message.completed"(event, channel, _ctx) {if (event.finishReason === "tool-calls" || !event.message) return;@@ -81,6 +83,33 @@ export const defaultEvents: TwilioChannelEvents = {await channel.twilio.sendMessage(renderTwilioInputRequests(event.requests));},+ // An SMS thread is one person's, so the link and code can go in the message.+ async "authorization.required"(event, channel, _ctx) {+ if (event.candidateId !== undefined) return;+ const challenge = event.authorization;+ await channel.twilio.sendMessage(+ [+ `Sign in to ${challenge?.displayName ?? displayProperName(event.name)} to continue.`,+ challenge?.instructions,+ challenge?.userCode ? `Code: ${challenge.userCode}` : undefined,+ challenge?.url,+ ]+ .filter((part): part is string => part !== undefined && part.length > 0)+ .join("\n\n"),+ );+ },++ async "authorization.completed"(event, channel, _ctx) {+ if (event.candidateId !== undefined) return;+ await channel.twilio.sendMessage(+ renderAuthorizationOutcome({+ displayName: event.authorization?.displayName ?? displayProperName(event.name),+ outcome: event.outcome,+ reason: event.reason,+ }),+ );+ },+async "turn.failed"(event, channel, _ctx) {const hint = formatErrorHint(event);const errorId = extractErrorId(event.details);@@ -126,3 +155,15 @@ function renderTwilioInputRequests(requests: readonly InputRequest[]): string {}return sections.join("\n\n");}++function renderAuthorizationOutcome(input: {+ readonly displayName: string;+ readonly outcome: ConnectionAuthorizationOutcome;+ readonly reason?: string;+}): string {+ if (input.outcome === "authorized") return `${input.displayName} connected.`;+ if (input.outcome === "declined") return `${input.displayName} sign-in cancelled.`;+ const outcome = input.outcome === "timed-out" ? "timed out" : input.outcome;+ const reason = input.reason === undefined ? "" : ` (${input.reason})`;+ return `${input.displayName} sign-in ${outcome}${reason}.`;+}diff --git a/packages/eve/test/tui-client/tui-connection-auth-states.ts b/packages/eve/test/tui-client/tui-connection-auth-states.tsindex 01c760b0a..2ecfb04b0 100644--- a/packages/eve/test/tui-client/tui-connection-auth-states.ts+++ b/packages/eve/test/tui-client/tui-connection-auth-states.ts@@ -174,7 +174,7 @@ void (async () => {input.type("turn 1, drive stub-mcp through required → authorized");input.enter();- await screen.waitForText("● stub-mcp · authorization", 10_000);+ await screen.waitForText("● Stub-mcp · authorization", 10_000);console.log(theme.muted("[states] stub-mcp section header rendered"));await waitForCondition(@@ -232,7 +232,7 @@ void (async () => {input.type("turn 2, drive other-mcp through required → failed");input.enter();- await screen.waitForText("● other-mcp · authorization", 10_000);+ await screen.waitForText("● Other-mcp · authorization", 10_000);console.log(theme.muted("[states] other-mcp section header rendered"));server.emit(secondCallbackTurn);@@ -259,12 +259,13 @@ void (async () => {} catch (error) {input.ctrlC();input.ctrlC();- await runPromise.catch(() => undefined);+ // A runner stuck mid-turn may ignore Ctrl+C; don't let that mask the failure.+ await Promise.race([runPromise.catch(() => undefined), sleep(2_000)]);throw error;}})().catch((error: unknown) => {console.error(theme.danger("\n[tui] tui-connection-auth-states smoke test failed:"), error);- process.exitCode = 1;+ process.exit(1);});async function waitForCondition(