Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Fix #6702: keep the pinned sign-in card out of the transcript's way

Huyvux12fd7a062ff82c
diff --git a/src/components/AskCard.test.ts b/src/components/AskCard.test.ts
index 478d8ab79f..6442ac0864 100644
--- a/src/components/AskCard.test.ts
+++ b/src/components/AskCard.test.ts
@@ -33,6 +33,13 @@ describe("AskCard", () => {
expect(renderToStaticMarkup(createElement(AskCard, { ...base, onDismiss: () => {} }))).not.toContain("<button");
expect(renderToStaticMarkup(createElement(AskCard, { ...base, onDismiss: () => {}, dismissLabel: "Not now" }))).toContain('aria-label="Not now"');
});
+
+ it("stays in view below the header, however tall the header grows", () => {
+ const html = renderToStaticMarkup(createElement(AskCard, { ariaLabel: "Key", title: "API key", stays: true }));
+ const card = classesOf(html, /^<div[^>]*class="([^"]*)"/);
+ expect(card).toEqual(expect.arrayContaining(["sticky", "z-10", "top-[var(--glass-top,60px)]"]));
+ expect(card).not.toContain("top-[60px]");
+ });
});
describe("AskChoices", () => {
diff --git a/src/components/AskCard.tsx b/src/components/AskCard.tsx
index 3fcf536946..f678f0a2a9 100644
--- a/src/components/AskCard.tsx
+++ b/src/components/AskCard.tsx
@@ -65,7 +65,7 @@ export function AskCard({
data-tour={tour}
data-ask-card="pending" data-look="ask-card"
onKeyDown={onKeyDown}
- className={cn("w-full max-w-[560px] rounded-[18px] px-4 pb-3.5 pt-3 text-start", stays ? `sticky top-[60px] bottom-[72px] z-10 ${ELEVATED_FLOAT}` : ELEVATED_CARD)}
+ className={cn("w-full max-w-[560px] rounded-[18px] px-4 pb-3.5 pt-3 text-start", stays ? `sticky top-[var(--glass-top,60px)] bottom-[72px] z-10 ${ELEVATED_FLOAT}` : ELEVATED_CARD)}
>
{header && <div className="mb-1.5 pe-6">{header}</div>}
<div className="flex min-w-0 items-start gap-2">
diff --git a/src/components/ChatRows.tsx b/src/components/ChatRows.tsx
new file mode 100644
index 0000000000..8b62397592
--- /dev/null
+++ b/src/components/ChatRows.tsx
@@ -0,0 +1,51 @@
+import { createContext, memo, use, useContext, type Dispatch } from "react";
+import { LiveToolsContext } from "@/hooks/use-live-tool-ids";
+import { t } from "@/lib/i18n";
+import type { MentionPeer } from "@/lib/mentions";
+import { toolPlace, type EffectivePlace } from "@/lib/place";
+import { userBubbleStyle } from "@/lib/user-bubble-tone";
+import type { Action, AppState, Bot, ConfigStatus, Message } from "@/state/store";
+import { useStoreRef } from "@/state/store-ref";
+import { openRoomThread } from "@/state/thread-navigation";
+import { CheckBackLine } from "./CheckBackLine";
+import { HandoffChip } from "./HandoffReply";
+import { TeammateChip } from "./TeammateChip";
+import { ThreadChip } from "./ThreadChip";
+import { ToolActivity } from "./ToolActivity";
+
+export interface ChatRows {
+ botId: string; threadId: string; botName: string; botColor: Bot["color"]; voiceId?: string;
+ tts: ConfigStatus["tts"]; localVoice: boolean;
+ hasMore: boolean; bots: readonly Bot[];
+ mentionPeers: readonly MentionPeer[]; mentionPerson: { profileName?: string };
+ speakerViewer?: string | null;
+ focus: AppState["focusMessage"];
+ showToolCalls: boolean;
+ locale: string;
+ bubbleStyle?: ReturnType<typeof userBubbleStyle>;
+ dispatch: Dispatch<Action>;
+ onBranch: (messageId: string) => boolean;
+ conversational: boolean; simple?: boolean; canReact: boolean;
+ openedAt: number;
+ phone: boolean;
+}
+
+export const ChatRowsContext = createContext<ChatRows | null>(null);
+
+export function useChatRows(): ChatRows {
+ const rows = useContext(ChatRowsContext);
+ if (!rows) throw new Error("a chat row outside ChatView");
+ return rows;
+}
+
+export const ActivityChip = memo(function ActivityChip({ message, place = "auto" }: { message: Message; place?: EffectivePlace }) {
+ const { bots, dispatch, threadId } = useChatRows(), liveTools = use(LiveToolsContext);
+ const tool = message.tool;
+ if (!tool) return null;
+ if (message.threadRef) return <ThreadChip message={message} threadId={threadId} />; if (message.relay) return <TeammateChip message={message} />; if (message.checkBack) return <CheckBackLine line={message.checkBack} />;
+ const comm = message.comm;
+ if (comm) return <RoomHandoffChip message={message} comm={comm} bots={bots} dispatch={dispatch} threadId={threadId} />;
+ return <ToolActivity tool={tool} live={liveTools.has(message.id)} place={toolPlace(tool.name, place)} source={{ threadId, messageId: message.id }} />;
+});
+
+const RoomHandoffChip = ({ message, comm, bots, dispatch, threadId }: { message: Message; comm: NonNullable<Message["comm"]>; bots: readonly Bot[]; dispatch: Dispatch<Action>; threadId: string }) => { const store = useStoreRef(); return <HandoffChip message={message} bots={bots} threadId={threadId} title={t("chat.openConversationWith", { name: comm.withName })} onClick={() => openRoomThread(dispatch, comm, store.state().groups)} />; };
diff --git a/src/components/ChatView.tsx b/src/components/ChatView.tsx
index 830b634ff1..b651e2d869 100644
--- a/src/components/ChatView.tsx
+++ b/src/components/ChatView.tsx
@@ -1,4 +1,4 @@
-import { createContext, memo, use, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type Dispatch, type ReactNode } from "react";
+import { memo, use, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from "react";
import { useAdvancedMode } from "@/lib/interface-mode";
import { PHONE_LAYOUT, useMediaQuery } from "@/lib/use-media-query";
import { ThreadLinkContext } from "@/components/ThreadLinkMenu";
@@ -19,15 +19,11 @@ import {
api,
currentTaskBot,
formatTime,
- openRoomThread,
openThread,
visibleMessages,
- type Action,
type Bot,
- type ConfigStatus,
type InstanceInfo,
type Message,
- type AppState,
awayFromMainThread,
openBot,
} from "@/state/store";
@@ -63,15 +59,13 @@ import { ChatMarkdown } from "./ChatMarkdown";
import { LiveToolsContext, useLiveToolIds } from "@/hooks/use-live-tool-ids";
import { VoiceNoteBubble, type VoiceNoteAttachment } from "./VoiceNoteBubble";
import { RawMarkdownView, RawToggleAction } from "./RawMarkdownToggle";
-import { ThreadChip } from "./ThreadChip"; import { CheckBackLine } from "./CheckBackLine";
-import { HandoffChip } from "./HandoffReply"; import { TeammateChip } from "./TeammateChip"; import { useTeammates } from "@/state/team-people"; import type { MentionPeer } from "@/lib/mentions";
+import { useTeammates } from "@/state/team-people";
import { NewConversationInstead } from "./NewConversationInstead";
import { VerifyCard } from "./VerifyCard";
import { askText, runSkill, runSteps, runSummary, showRun, skillPrompt } from "@/lib/verify-steps";
import { useShowRunCard } from "@/lib/run-card-preferences";
import { useColorUserBubbles } from "@/lib/user-bubble-preference";
import { userBubbleStyle } from "@/lib/user-bubble-tone";
-import { ToolActivity } from "./ToolActivity";
import { DataResultChip } from "./DataResultChip"; import { PublishedPageCard } from "./PublishedPageCard"; import { TemplateChatCard } from "./TemplateCard"; import { PublishedSiteCards } from "./published-apps/PublishedSiteCards";
import { ThreadRefText } from "./ThreadRefs"; import { WatchScreenButton } from "./WatchScreenButton";
import { optionsCardRow } from "./OptionsCardRow";
@@ -86,6 +80,8 @@ import { ReplyQuote } from "./ReplyQuote";
import { ConnectorCard } from "./ConnectorCard";
import { SecretRequestCard } from "./SecretRequestCard";
import { SignInRequestCard } from "./SignInRequestCard";
+import { isPinnedSignIn, NO_PINNED_SIGN_INS, PinnedSignInSlot } from "./PinnedSignInSlot";
+import { ActivityChip, ChatRowsContext, useChatRows, type ChatRows } from "./ChatRows";
import { AutomationCaption, RoutineRunRow } from "./RoutineRunCard"; import { InboxAnswers, InboxCaption, RelayLabel } from "./InboxLine"; import { InboxCardSlot } from "./inbox/InboxCard";
import { CallRecordRow } from "./CallRecordRow";
import { AttachmentGallery, collectMessageFiles, replyAttachmentGroup, splitMessageAttachments } from "./AttachmentGallery";
@@ -102,7 +98,7 @@ import { SpeakButton, speakReady } from "./SpeakButton";
import { CallOverlay } from "./CallView";
import { LiveCallBar } from "./LiveCallBar";
import { LiveCallChip } from "./LiveCallPill";
-import { effectivePlace, toolPlace, type EffectivePlace } from "@/lib/place";
+import { effectivePlace, type EffectivePlace } from "@/lib/place";
import { cn } from "@/lib/cn";
import { activeLocale, intlLocale, t } from "@/lib/i18n";
import { COMPACT_BUBBLE } from "@/lib/compact-chip";
@@ -140,31 +136,6 @@ import { BOT_BUBBLE_FINISH, isBotTextRow, joinedCorners, needsStamp, quietRow, s
const USER_COLLAPSE_CHARS = 600;
const USER_COLLAPSE_LINES = 8;
-interface ChatRows {
- botId: string; threadId: string; botName: string; botColor: Bot["color"]; voiceId?: string;
- tts: ConfigStatus["tts"]; localVoice: boolean;
- hasMore: boolean; bots: readonly Bot[];
- mentionPeers: readonly MentionPeer[]; mentionPerson: { profileName?: string };
- speakerViewer?: string | null;
- focus: AppState["focusMessage"];
- showToolCalls: boolean;
- locale: string;
- bubbleStyle?: ReturnType<typeof userBubbleStyle>;
- dispatch: Dispatch<Action>;
- onBranch: (messageId: string) => boolean;
- conversational: boolean; simple?: boolean; canReact: boolean;
- openedAt: number;
- phone: boolean;
-}
-
-const ChatRowsContext = createContext<ChatRows | null>(null);
-
-function useChatRows(): ChatRows {
- const rows = useContext(ChatRowsContext);
- if (!rows) throw new Error("a chat row outside ChatView");
- return rows;
-}
-
export function ErrorRow({
message,
headline: plainHeadline,
@@ -595,20 +566,10 @@ const Bubble = memo(function Bubble({
);
});
-const ActivityChip = memo(function ActivityChip({ message, place = "auto" }: { message: Message; place?: EffectivePlace }) {
- const { bots, dispatch, threadId } = useChatRows(), liveTools = use(LiveToolsContext);
- const tool = message.tool;
- if (!tool) return null;
- if (message.threadRef) return <ThreadChip message={message} threadId={threadId} />; if (message.relay) return <TeammateChip message={message} />; if (message.checkBack) return <CheckBackLine line={message.checkBack} />;
- const comm = message.comm;
- if (comm) return <RoomHandoffChip message={message} comm={comm} bots={bots} dispatch={dispatch} threadId={threadId} />;
- return <ToolActivity tool={tool} live={liveTools.has(message.id)} place={toolPlace(tool.name, place)} source={{ threadId, messageId: message.id }} />;
-});
-
-const RoomHandoffChip = ({ message, comm, bots, dispatch, threadId }: { message: Message; comm: NonNullable<Message["comm"]>; bots: readonly Bot[]; dispatch: Dispatch<Action>; threadId: string }) => { const store = useStoreRef(); return <HandoffChip message={message} bots={bots} threadId={threadId} title={t("chat.openConversationWith", { name: comm.withName })} onClick={() => openRoomThread(dispatch, comm, store.state().groups)} />; };
const MessagesList = memo(function MessagesList({
messages: saved, drawFrom,
transcript,
+ pinnedSignInIds = NO_PINNED_SIGN_INS,
lookups,
place,
pinnedMessageId,
@@ -630,6 +591,7 @@ const MessagesList = memo(function MessagesList({
/** The oldest row this commit draws; the rows above it keep their places for the next. */
drawFrom?: string;
transcript: Message[];
+ pinnedSignInIds?: ReadonlySet<string>;
lookups: TranscriptLookups;
place: EffectivePlace;
pinnedMessageId?: string;
@@ -703,7 +665,7 @@ const MessagesList = memo(function MessagesList({
case "secret":
return m.secret ? <SecretRequestCard botId={botId} botName={botName} color={botColor} threadId={threadId} message={m} /> : null;
case "signin":
- return m.signIn ? <SignInRequestCard botId={botId} botName={botName} color={botColor} threadId={threadId} message={m} /> : null;
+ return m.signIn && !pinnedSignInIds.has(m.id) ? <SignInRequestCard botId={botId} botName={botName} color={botColor} threadId={threadId} message={m} /> : null;
case "connector":
return m.connector ? <ConnectorCard botId={botId} color={botColor} threadId={threadId} message={m} /> : null;
case "options":
@@ -811,6 +773,8 @@ export const ChatView = memo(function ChatView({ bot: profile, inForkPanel = fal
const { messages: allMessages, activeLeafId } = bot;
const messages = useMemo(() => visibleMessages({ messages: allMessages, activeLeafId }), [allMessages, activeLeafId]), chatMessages = useMemo(() => chatActivityMessages(messages, advanced, activity, bot.pinnedMessageId), [advanced, activity, messages, bot.pinnedMessageId]);
+ const pinnedSignIns = useMemo(() => messages.filter(isPinnedSignIn).map((m) => ({ message: m, botId: bot.id, botName: bot.name, color: bot.color, threadId: bot.threadId })), [messages, bot.id, bot.name, bot.color, bot.threadId]);
+ const pinnedSignInIds = useMemo(() => new Set(pinnedSignIns.map((card) => card.message.id)), [pinnedSignIns]);
const lookups = useMemo(() => transcriptLookups(allMessages, messages), [allMessages, messages]);
const liveTools = useLiveToolIds(messages, bot);
const recordedRun = useMemo(() => runSteps(messages, liveTools), [messages, liveTools]);
@@ -1109,6 +1073,7 @@ export const ChatView = memo(function ChatView({ bot: profile, inForkPanel = fal
<ChatErrorBanner message={state.error} onDismiss={() => dispatch({ type: "error", message: null })} />
<ChatNotice notice={state.notice} />
<UnreadContextOverlay messages={chatMessages} windowedMessages={windowedMessages} unreadMessageId={unreadDivider.messageId} scrollRef={scrollRef} visitKey={`${bot.id}:${bot.threadId}:${openedAt}`} onJump={(messageId) => dispatch({ type: "focusMessage", threadId: bot.threadId, messageId })} />
+ <PinnedSignInSlot cards={pinnedSignIns} />
</GlassBar>
@@ -1144,6 +1109,7 @@ export const ChatView = memo(function ChatView({ bot: profile, inForkPanel = fal
<MessagesList
messages={windowedMessages} drawFrom={drawFrom}
transcript={messages}
+ pinnedSignInIds={pinnedSignInIds}
lookups={lookups}
place={place}
pinnedMessageId={bot.pinnedMessageId}
diff --git a/src/components/GroupView.tsx b/src/components/GroupView.tsx
index 31dc747657..d8b8691016 100644
--- a/src/components/GroupView.tsx
+++ b/src/components/GroupView.tsx
@@ -47,6 +47,7 @@ import { isPureLeakedSystemHarnessMessage } from "../../shared/system-message-gu
import { ConnectorCard } from "./ConnectorCard";
import { SecretRequestCard } from "./SecretRequestCard";
import { SignInRequestCard } from "./SignInRequestCard";
+import { isPinnedSignIn, NO_PINNED_SIGN_INS, PinnedSignInSlot } from "./PinnedSignInSlot";
import { hasRoutineExecutionTask, RoutineRunCard } from "./RoutineRunCard";
import { GoalRunCard } from "./GoalRunCard";
import { OptionCard } from "./OptionCard";
@@ -126,6 +127,7 @@ export const Transcript = memo(function Transcript({
locale, localVoice = false,
messages: saved,
transcript,
+ pinnedSignInIds = NO_PINNED_SIGN_INS,
emergingId,
unreadDividerId = null,
unreadDividerFading = false,
@@ -136,6 +138,7 @@ export const Transcript = memo(function Transcript({
locale: string; localVoice?: boolean;
messages: Message[];
transcript: Message[];
+ pinnedSignInIds?: ReadonlySet<string>;
emergingId?: string | null;
unreadDividerId?: string | null;
unreadDividerFading?: boolean;
@@ -241,7 +244,7 @@ export const Transcript = memo(function Transcript({
) :
m.kind === "secret" && m.secret && m.from?.botId ? (
<SecretRequestCard botId={m.from.botId} color={m.from.color} threadId={group.threadId} message={m} />
- ) : m.kind === "signin" && m.signIn && m.from?.botId ? (
+ ) : m.kind === "signin" && m.signIn && m.from?.botId && !pinnedSignInIds.has(m.id) ? (
<SignInRequestCard botId={m.from.botId} botName={m.from.name} color={m.from.color} threadId={group.threadId} message={m} />
) : m.kind === "connector" && m.connector && m.from?.botId ? (
<ConnectorCard botId={m.from.botId} color={m.from.color} threadId={group.threadId} message={m} />
@@ -678,6 +681,11 @@ export function GroupView({ group, inForkPanel = false }: { group: Group; inFork
const remoteClient = window.ogb?.remoteClient?.active === true;
const composerDockRef = useRef<HTMLDivElement>(null);
const composerDock = useComposerDockPad(composerDockRef);
+ const pinnedSignIns = useMemo(() => group.messages.flatMap((m) => {
+ const from = m.from;
+ return isPinnedSignIn(m) && from?.botId ? [{ message: m, botId: from.botId, botName: from.name, color: from.color, threadId: group.threadId }] : [];
+ }), [group.messages, group.threadId]);
+ const pinnedSignInIds = useMemo(() => new Set(pinnedSignIns.map((card) => card.message.id)), [pinnedSignIns]);
const [folderOpen, setFolderOpen] = useState(false);
const [membersOpen, setMembersOpen] = useState(false);
const [findOpen, setFindOpen] = useState(false);
@@ -839,6 +847,7 @@ export function GroupView({ group, inForkPanel = false }: { group: Group; inFork
</div>
</div>
)}
+ <PinnedSignInSlot cards={pinnedSignIns} />
</GlassBar>
@@ -895,6 +904,7 @@ export function GroupView({ group, inForkPanel = false }: { group: Group; inFork
locale={activeLocale()} localVoice={localSystemVoiceActive()}
messages={windowedMessages}
transcript={group.messages}
+ pinnedSignInIds={pinnedSignInIds}
emergingId={popping?.id}
unreadDividerId={unreadDivider.messageId}
unreadDividerFading={unreadDivider.fading}
diff --git a/src/components/PinnedSignInSlot.tsx b/src/components/PinnedSignInSlot.tsx
new file mode 100644
index 0000000000..2b04d4df8a
--- /dev/null
+++ b/src/components/PinnedSignInSlot.tsx
@@ -0,0 +1,30 @@
+import { signInCardWaits } from "../../shared/sign-in-request";
+import type { Bot, Message } from "@/state/store";
+import { SignInRequestCard } from "./SignInRequestCard";
+
+export function isPinnedSignIn(message: Message): boolean {
+ return message.kind === "signin" && message.signIn !== undefined && signInCardWaits(message.signIn);
+}
+
+export const NO_PINNED_SIGN_INS: ReadonlySet<string> = new Set();
+
+export type PinnedSignInCard = {
+ message: Message;
+ botId: string;
+ botName: string;
+ color?: Bot["color"];
+ threadId: string;
+};
+
+export function PinnedSignInSlot({ cards }: { cards: readonly PinnedSignInCard[] }) {
+ if (cards.length === 0) return null;
+ return (
+ <div data-pinned-sign-in-slot className="px-4 pb-3">
+ <div className="chat-column flex flex-col gap-3">
+ {cards.map((card) => (
+ <SignInRequestCard key={card.message.id} botId={card.botId} botName={card.botName} color={card.color} threadId={card.threadId} message={card.message} stays={false} />
+ ))}
+ </div>
+ </div>
+ );
+}
diff --git a/src/components/SignInRequestCard.test.ts b/src/components/SignInRequestCard.test.ts
index 3a0acc4516..32c76e0e4b 100644
--- a/src/components/SignInRequestCard.test.ts
+++ b/src/components/SignInRequestCard.test.ts
@@ -29,19 +29,25 @@ vi.mock("@/lib/logins", () => ({
}));
import { LoginForm } from "./LoginForm";
+import { isPinnedSignIn, PinnedSignInSlot } from "./PinnedSignInSlot";
import { SignInBanner, SignInRequestCard } from "./SignInRequestCard";
import { VaultChoices } from "./VaultChoices";
-const card = (signIn: Record<string, unknown> = {}): Message => ({
- id: "card-1",
+const card = (signIn: Record<string, unknown> = {}, id = "card-1"): Message => ({
+ id,
role: "bot",
kind: "signin",
at: 1,
text: "Pepper needs you to sign in to example.com.",
signIn: { url: "https://example.com/login", site: "example.com", place: "browser", reason: "The report is behind a login.", ...signIn } as Message["signIn"],
});
-const props = (signIn?: Record<string, unknown>) => ({ botId: "pepper", botName: "Pepper", threadId: "thread-1", message: card(signIn) });
-const view = (signIn?: Record<string, unknown>) => renderToStaticMarkup(createElement(SignInRequestCard, props(signIn)));
+const props = (signIn?: Record<string, unknown>, extra?: Record<string, unknown>) => ({ ...extra, botId: "pepper", botName: "Pepper", threadId: "thread-1", message: card(signIn) });
+const view = (signIn?: Record<string, unknown>, extra?: Record<string, unknown>) => renderToStaticMarkup(createElement(SignInRequestCard, props(signIn, extra)));
+const pendingCardClasses = (html: string): string[] => {
+ const match = /data-ask-card="pending"[^>]*class="([^"]*)"/u.exec(html);
+ expect(match).not.toBeNull();
+ return match![1]!.split(/\s+/u);
+};
type Node = ReactElement<{ children?: ReactNode; onClick?: () => void }>;
const elements = (node: ReactNode): Node[] => {
@@ -80,6 +86,22 @@ describe("SignInRequestCard while it waits", () => {
expect(html).not.toContain("<input");
});
+ it("stays pinned in view while it waits, like the password and connect cards", () => {
+ const classes = pendingCardClasses(view());
+ expect(classes).toContain("sticky");
+ expect(classes).toContain("z-10");
+ expect(classes).toContain("bg-composer");
+ });
+
+ it("renders in the chat flow, without painting over anything, when its host pins it in a reserved slot", () => {
+ const html = view(undefined, { stays: false });
+ const classes = pendingCardClasses(html);
+ expect(classes).not.toContain("sticky");
+ expect(classes).not.toContain("z-10");
+ expect(classes).toContain("bg-composer");
+ for (const label of ["Open", "Done", "Cancel"]) expect(html).toContain(label);
+ });
+
it.each([
["vm", "the private desktop Pepper works on"],
["cloud", "the cloud desktop Pepper works on"],
@@ -246,3 +268,40 @@ describe("SignInRequestCard saved logins", () => {
expect(offered()).toBe(false);
});
});
+
+describe("PinnedSignInSlot", () => {
+ const slotHtml = (messages: Message[]) => renderToStaticMarkup(createElement(PinnedSignInSlot, {
+ cards: messages.filter(isPinnedSignIn).map((message) => ({ message, botId: "pepper", botName: "Pepper", threadId: "thread-1" })),
+ }));
+
+ it("takes only the sign-in cards that still wait", () => {
+ expect(isPinnedSignIn(card())).toBe(true);
+ for (const state of [{ done: true }, { cancelled: true }, { superseded: true }, { answeredInChat: true }, { stopped: true }]) {
+ expect(isPinnedSignIn(card(state))).toBe(false);
+ }
+ expect(isPinnedSignIn({ ...card(), kind: "text", signIn: undefined })).toBe(false);
+ expect(isPinnedSignIn({ ...card(), signIn: undefined })).toBe(false);
+ });
+
+ it("renders a waiting card in the reserved slot, in-flow and still answering", () => {
+ const html = slotHtml([card()]);
+ expect(html).toContain("data-pinned-sign-in-slot");
+ expect(html).toContain("Sign in needed");
+ expect(html).toContain("example.com");
+ const classes = pendingCardClasses(html);
+ expect(classes).not.toContain("sticky");
+ expect(classes).not.toContain("z-10");
+ expect(classes).toContain("bg-composer");
+ for (const label of ["Open", "Done", "Cancel"]) expect(html).toContain(label);
+ });
+
+ it("renders nothing when no sign-in card waits", () => {
+ expect(slotHtml([card({ done: true })])).toBe("");
+ expect(slotHtml([])).toBe("");
+ });
+
+ it("stacks two waiting cards", () => {
+ const html = slotHtml([card({}, "card-1"), card({}, "card-2")]);
+ expect(html.match(/data-ask-card="pending"/gu)?.length).toBe(2);
+ });
+});
diff --git a/src/components/SignInRequestCard.tsx b/src/components/SignInRequestCard.tsx
index 37297ab4f0..c6379c3649 100644
--- a/src/components/SignInRequestCard.tsx
+++ b/src/components/SignInRequestCard.tsx
@@ -30,12 +30,15 @@ export function SignInRequestCard({
color,
threadId,
message,
+ stays = true,
}: {
botId: string;
botName: string;
color?: Bot["color"];
threadId: string;
message: Message;
+ /** False when the host already pins the card in a reserved slot outside the scrollport. */
+ stays?: boolean;
}) {
const { state, dispatch } = useStore();
const card = message.signIn!;
@@ -128,10 +131,10 @@ export function SignInRequestCard({
try { pageHost = new URL(card.url).hostname; } catch {}
return (
<AskCard
+ stays={stays}
ariaLabel={t("signIn.cardLabel", { name: botName, site: card.site })}
icon={<LogIn size={15} />}
title={t("signIn.title")}
- stays
footer={saving ? undefined : <>
<button type="button" onClick={() => void answer("cancel")} disabled={pending !== null} className={cn(ASK_CHIP, ASK_CHIP_IDLE)}>
{pending === "cancel" ? <Loader2 size={14} className="animate-spin" /> : <X size={14} />}