Repository navigation
feat(chat): chat videos open from their card instead of growing the answer CU-17tkuw61kfy #2870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a3519f1
feat(chat): CU-17tkuw61kfy chat videos open from their card instead o…
michaelassraf b6cc660
feat(chat): CU-17tkuw61kfy card footers and source strips keep their …
michaelassraf facc207
fix(chat): CU-17tkuw61kfy the sources strip's skeleton is one row, on…
michaelassraf c56da62
feat(chat): CU-17tkuw61kfy a link to a screen of the app is an inline…
michaelassraf eb0d984
refactor(chat): CU-17tkuw61kfy one inline box component, InlineChip
michaelassraf 556d341
refactor(chat): CU-17tkuw61kfy one card disclosure, an explicit app-s…
michaelassraf 120f283
refactor(chat): CU-17tkuw61kfy in-app links by the runtime's rule, di…
michaelassraf 09cc3c9
Merge branch 'main' into feat/mcp-in-app-links
michaelassraf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
openframe-frontend-core/src/chat-protocol/app-screen-link.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /** | ||
| * The link an answer makes to a screen of the app the chat runs in: a markdown link whose TITLE says so, | ||
| * `[Devices → Add Device](/devices/new "app-screen")`. One definition for both sides of the seam: the hub tells the | ||
| * model to write exactly this (`appScreenLinkMarkdown` in its instruction), and the chat draws exactly this as an | ||
| * inline box (`isAppScreenLink`). Nothing is inferred from the path: a link without the title is a plain link. | ||
| * | ||
| * A title, not a new URL scheme, so an answer read by a chat that predates this still shows a working link. | ||
| */ | ||
|
|
||
| /** The markdown link title that marks a link to a screen of the app. */ | ||
| export const APP_SCREEN_LINK_TITLE = 'app-screen'; | ||
|
|
||
| /** The markdown for a link to a screen of the app: the label as the reader sees the screen, the screen's path. */ | ||
| export function appScreenLinkMarkdown(label: string, path: string): string { | ||
| return `[${label}](${path} "${APP_SCREEN_LINK_TITLE}")`; | ||
| } | ||
|
|
||
| /** | ||
| * True for a link the answer marked as a screen of the app. The path must also be a path of this app (root-relative, | ||
| * never `//host`): the title states the intent, the path is still checked before the app routes to it. | ||
| */ | ||
| export function isAppScreenLink(href: string | undefined, title: string | undefined): boolean { | ||
| return title === APP_SCREEN_LINK_TITLE && typeof href === 'string' && href.startsWith('/') && !href.startsWith('//'); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
openframe-frontend-core/src/components/chat/__tests__/inline-app-link-chip.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import type React from 'react'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { appScreenLinkMarkdown, isAppScreenLink } from '../../../chat-protocol/app-screen-link'; | ||
| import { InlineAppLinkChip } from '../inline-app-link-chip'; | ||
|
|
||
| function HostAnchor({ href, className, children }: { href: string; className?: string; children?: React.ReactNode }) { | ||
| return ( | ||
| <a href={href} className={className} data-testid="host-anchor"> | ||
| {children} | ||
| </a> | ||
| ); | ||
| } | ||
|
|
||
| describe('a link to a screen of the app is an inline box', () => { | ||
| it('counts only links the answer marked as a screen of the app, never a guess from the path', () => { | ||
| expect(isAppScreenLink('/devices/new', 'app-screen')).toBe(true); | ||
| expect(isAppScreenLink('/devices/new', undefined)).toBe(false); | ||
| expect(isAppScreenLink('/devices/new', 'Devices')).toBe(false); | ||
| expect(isAppScreenLink('//evil.example/x', 'app-screen')).toBe(false); | ||
| expect(isAppScreenLink('https://openframe.ai/devices', 'app-screen')).toBe(false); | ||
| expect(isAppScreenLink(undefined, 'app-screen')).toBe(false); | ||
| }); | ||
|
|
||
| it('writes the marked link the hub tells the model to write', () => { | ||
| expect(appScreenLinkMarkdown('Devices → Add Device', '/devices/new')).toBe( | ||
| '[Devices → Add Device](/devices/new "app-screen")', | ||
| ); | ||
| }); | ||
|
|
||
| it('draws the label in the boxed chip, through the host anchor', () => { | ||
| render( | ||
| <InlineAppLinkChip href="/devices/new" anchor={HostAnchor}> | ||
| Devices → Add Device | ||
| </InlineAppLinkChip>, | ||
| ); | ||
| const link = screen.getByRole('link', { name: /Devices → Add Device/ }); | ||
| expect(link).toHaveAttribute('href', '/devices/new'); | ||
| expect(link).toHaveAttribute('data-testid', 'host-anchor'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...me-frontend-core/src/components/chat/entity-cards/__tests__/chat-card-disclosure.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <div data-testid="row">{action}</div>; | ||
| } | ||
|
|
||
| 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(<ChatCardDisclosureButton variant="video" loading />); | ||
| 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(<Footer video={null} reserve />); | ||
| // The action is laid out (its space is kept) but cannot be reached or read. | ||
| expect(screen.getByText(WATCH_VIDEO_LABEL)).toBeTruthy(); | ||
| expect(screen.queryByRole('button')).toBeNull(); | ||
| }); | ||
|
|
||
| it('draws nothing for a type that cannot carry a video', () => { | ||
| render(<Footer video={null} />); | ||
| expect(screen.getByTestId('row')).toBeEmptyDOMElement(); | ||
| }); | ||
|
|
||
| it('draws the live action when the record has a video', () => { | ||
| render(<Footer video={ref} reserve />); | ||
| expect(screen.getByRole('button', { name: `${WATCH_VIDEO_LABEL}: A webinar` })).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('draws Ask in its loading form with the same label width', () => { | ||
| render(<SourceActionButton chatRef={ref} onDiscuss={() => undefined} density="card" loading />); | ||
| expect(screen.queryByRole('button')).toBeNull(); | ||
| expect(screen.getByText('Ask')).toHaveAttribute('aria-hidden', 'true'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.