diff --git a/openframe-frontend-core/src/components/chat/__tests__/chat-message-in-app-links.test.tsx b/openframe-frontend-core/src/components/chat/__tests__/chat-message-in-app-links.test.tsx index 666666b484..f7f3cd3624 100644 --- a/openframe-frontend-core/src/components/chat/__tests__/chat-message-in-app-links.test.tsx +++ b/openframe-frontend-core/src/components/chat/__tests__/chat-message-in-app-links.test.tsx @@ -99,6 +99,17 @@ describe('ChatMessageEnhanced — in-app screen links', () => { expect(windowOpen).not.toHaveBeenCalled(); }); + it("draws a link that stays in the app as the inline box, by the runtime's own new-tab rule", () => { + renderAnswer(ANSWER); + // The box is the anchor around the lib's InlineChip (`InlineAppLinkChip`), routed by the same host anchor. + for (const anchor of screen.getAllByRole('link')) expect(anchor).toHaveClass('no-underline'); + }); + + it('keeps a link the runtime sends to a new tab a plain link, not a box', () => { + renderAnswer(ANSWER.replace(/\]\(\//g, `](${ORIGIN}/`)); + expect(screen.getByRole('link', { name: 'Devices → Add Device' })).not.toHaveClass('no-underline'); + }); + it('opens the same link written absolute in a new tab, even on the page origin', () => { renderAnswer(ANSWER.replace(/\]\(\//g, `](${ORIGIN}/`)); const anchor = screen.getByRole('link', { name: 'Devices → Add Device' }); diff --git a/openframe-frontend-core/src/components/chat/__tests__/inline-app-link-chip.test.tsx b/openframe-frontend-core/src/components/chat/__tests__/inline-app-link-chip.test.tsx new file mode 100644 index 0000000000..1f64847bcf --- /dev/null +++ b/openframe-frontend-core/src/components/chat/__tests__/inline-app-link-chip.test.tsx @@ -0,0 +1,25 @@ +import { render, screen } from '@testing-library/react'; +import type React from 'react'; +import { describe, expect, it } from 'vitest'; +import { InlineAppLinkChip } from '../inline-app-link-chip'; + +function HostAnchor({ href, className, children }: { href: string; className?: string; children?: React.ReactNode }) { + return ( + + {children} + + ); +} + +describe('a link that stays in the app is an inline box', () => { + it('draws the label in the boxed chip, through the host anchor', () => { + render( + + Devices → Add Device + , + ); + const link = screen.getByRole('link', { name: /Devices → Add Device/ }); + expect(link).toHaveAttribute('href', '/devices/new'); + expect(link).toHaveAttribute('data-testid', 'host-anchor'); + }); +}); diff --git a/openframe-frontend-core/src/components/chat/chat-message-enhanced.tsx b/openframe-frontend-core/src/components/chat/chat-message-enhanced.tsx index 5b7ceba9af..b51402b3db 100644 --- a/openframe-frontend-core/src/components/chat/chat-message-enhanced.tsx +++ b/openframe-frontend-core/src/components/chat/chat-message-enhanced.tsx @@ -2,6 +2,7 @@ import React, { forwardRef, memo, type ReactNode, useEffect, useMemo, useRef } from 'react'; import { createCardMarkerScanner } from '../../chat-protocol/card-marker'; +import { useChatRuntime } from '../../contexts/chat-runtime-context'; import Link from '../../embed-shims/next-link'; import { cn } from '../../utils/cn'; import { isToday } from '../../utils/date-utils'; @@ -30,6 +31,7 @@ import { ContextCompactionDisplay } from './context-compaction-display'; import { BlockCard, type BlockCardProps } from './entity-cards/block-card'; import { ErrorMessageDisplay } from './error-message-display'; import { EscalationOfferMessage } from './escalation-offer-message'; +import { InlineAppLinkChip } from './inline-app-link-chip'; import { remarkCardLinks } from './remark-card-links'; import { remarkMentionChips } from './remark-mention-chips'; import { remarkStripCitations } from './remark-strip-citations'; @@ -41,6 +43,7 @@ import { TicketEventMessage } from './ticket-event-message'; import { ToolExecutionDisplay } from './tool-execution-display'; import type { AskSegment, MessageSegment, MessageContent, ChatMessageEnhancedProps } from './types'; import { CHAT_APPEARANCE } from './types/chat.types'; +import { computeIsNewTab } from './utils/nav-anchor-props'; /** Inline `@marker:id` mention token in the message body (sibling of the * `[card://]` grammar) — used to filter out items rendered inline from the @@ -406,6 +409,9 @@ const ChatMessageEnhanced = forwardRef const renderingPlanRef = useRef(renderingPlan); renderingPlanRef.current = renderingPlan; + // The runtime decides whether a link stays in this app (`computeIsNewTab`); null outside a chat runtime, where + // every link stays a plain link. + const chatRuntime = useChatRuntime(); const cardComponentOverrides = useMemo(() => { if (!hasMarkerSupport && !hasMentionSupport) return undefined; return { @@ -463,6 +469,23 @@ const ChatMessageEnhanced = forwardRef // flamingo hero-demo with mock content), fall back to a plain // ``. No cross-origin sniffing here — the OSS-lib does // not own routing decisions; the host does. + // A link that stays in this app is drawn as an inline box, the skin of the host's entity mentions, still + // routed through the host's `NavLinkAnchor`. Whether it stays is the runtime's ONE new-tab rule + // (`computeIsNewTab`, the decision the chat's cards and source chips make): a link it keeps in this window + // is a place in the app; one it sends to a new tab (another site, a hub page from an embedded chat, a + // `mailto:`) stays a plain link. + if ( + typeof href === 'string' && + !href.startsWith('#') && + chatRuntime && + !computeIsNewTab(chatRuntime, href, null) + ) { + return ( + + {children} + + ); + } if (typeof href === 'string' && NavLinkAnchor && !href.startsWith('#')) { return ( @@ -481,7 +504,7 @@ const ChatMessageEnhanced = forwardRef // streaming turn (booleans + host-stable fn/component identities, both // enforced by this file's `memo` comparator). The rendering plan is // read through a ref above precisely so it does NOT appear here. - }, [hasMarkerSupport, hasMentionSupport, renderMention, NavLinkAnchor]); + }, [hasMarkerSupport, hasMentionSupport, renderMention, NavLinkAnchor, chatRuntime]); /** * Body of a markdown-bearing segment (`text` / `guide`). diff --git a/openframe-frontend-core/src/components/chat/embeddable-chat.tsx b/openframe-frontend-core/src/components/chat/embeddable-chat.tsx index 53096b533d..bedd46a482 100644 --- a/openframe-frontend-core/src/components/chat/embeddable-chat.tsx +++ b/openframe-frontend-core/src/components/chat/embeddable-chat.tsx @@ -64,8 +64,10 @@ import { ActionsMenuDropdown, type ActionsMenuItem } from '../ui/actions-menu'; import { Button } from '../ui/button'; import { Drawer, DrawerContent } from '../ui/drawer'; import { HoverDropdown, type HoverDropdownItem } from '../ui/hover-dropdown'; +import { TextHold } from '../ui/layout-hold'; import { LoadingItems } from '../ui/loading-scope'; import { CollisionBoundaryContext, PortalContainerContext } from '../ui/portal-container'; +import { SKELETON_SURFACE_CLASS } from '../ui/skeleton-surface'; import { SquareAvatar } from '../ui/square-avatar'; import { ChatAppearanceContext } from './chat-appearance-context'; import { ChatArchivePage } from './chat-archive-page'; @@ -705,6 +707,29 @@ function dispatchSlashCommandAction( * 2. Ask: small `MessageSquare` icon-button on the right → fires * `onDiscuss(ref)` to drill into THIS row via `entityIdFilter`. */ +/** A no-break space: one line of the chip's text, so a bar that holds it is exactly one text line tall. */ +const ONE_TEXT_LINE = '\u00a0'; + +/** How many chips the strip's loading form draws: the count real answers' strips showed (measured). On a phone, + * where a strip holds one chip a row, it draws one. */ +const SOURCE_CHIP_SKELETON_COUNT = 2; + +/** + * A source chip's loading form, built like the chip (`wrapChip` around `chipBody`): the chip's frame, its icon, + * its title as a bar one text line tall (so the chip is the loaded chip's height), and the Ask slot beside it. + */ +function SourceChipSkeleton({ className }: { className?: string }) { + return ( + + + + {ONE_TEXT_LINE} + + + + ); +} + function SourceChip({ src, baseRoute, @@ -903,6 +928,7 @@ function SourceChips({ chipBasePlatform, onClose, onDiscuss, + loading, }: { cited: ChatSource[]; uncited: ChatSource[]; @@ -910,9 +936,29 @@ function SourceChips({ chipBasePlatform?: string; onClose: () => void; onDiscuss?: (ref: ChatRef) => void; + /** The answer is still being written: the strip's frame, heading and a row of chips in their loading form, so + * the strip does not appear under the answer when it finishes. */ + loading?: boolean; }) { const [expanded, setExpanded] = useState(false); + if (loading) { + return ( +
+ + Sources + + {/* One row at every width: a chip that does not fit is cut, never wrapped (a strip's chips fit one row in + the answers measured, and a wrapped skeleton shrinks when the answer ends). */} +
+ {Array.from({ length: SOURCE_CHIP_SKELETON_COUNT }, (_, i) => ( + 0 ? 'max-md:hidden' : undefined} /> + ))} +
+
+ ); + } + if (cited.length === 0) { const fallback = uncited.slice(0, FALLBACK_TOP_RETRIEVED); if (fallback.length === 0) return null; @@ -2062,7 +2108,21 @@ function EmbeddableChatInner({ // the THREAD, so testing it alone pulls the strips off every earlier // answer too — a reader scrolled up watches finished citations blink out // for the duration of an unrelated turn. - if (chatLoading && index === messages.length - 1) return null; + // Its strip is drawn in its loading form meanwhile, so the strip is already there when the answer ends. + if (chatLoading && index === messages.length - 1) { + return ( +
+ +
+ ); + } const { cited, uncited } = splitCitedSources(message.sources, flattenAssistantContent(message.content)); if (cited.length === 0 && uncited.length === 0) return null; return ( diff --git a/openframe-frontend-core/src/components/chat/entity-cards/__tests__/chat-card-disclosure.test.tsx b/openframe-frontend-core/src/components/chat/entity-cards/__tests__/chat-card-disclosure.test.tsx new file mode 100644 index 0000000000..f037fc0e79 --- /dev/null +++ b/openframe-frontend-core/src/components/chat/entity-cards/__tests__/chat-card-disclosure.test.tsx @@ -0,0 +1,45 @@ +import { render, screen } from '@testing-library/react'; +import { describe, expect, it } from 'vitest'; +import type { ChatRef } from '../../chat-ref.types'; +import { SourceActionButton } from '../../source-action-button'; +import { CHAT_CARD_DISCLOSURES, ChatCardDisclosureButton, useChatCardDisclosure } from '../chat-card-disclosure'; + +const WATCH_VIDEO_LABEL = CHAT_CARD_DISCLOSURES.VIDEO.label; + +const ref = { type: 'webinar', id: 'w1', title: 'A webinar' } as ChatRef; + +function Footer({ video, reserve }: { video: ChatRef | null; reserve?: boolean }) { + const { action } = useChatCardDisclosure('VIDEO', video, { reserve }); + return
{action}
; +} + +describe('the card footer keeps its actions in place while loading', () => { + it('draws "Watch video" in its loading form: the label held as a skeleton bar, not a reachable button', () => { + render(); + expect(screen.getByText(WATCH_VIDEO_LABEL)).toHaveAttribute('aria-hidden', 'true'); + expect(screen.queryByRole('button')).toBeNull(); + }); + + it('keeps the slot, unseen, for a record of a video type that has no video', () => { + render(