Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a3519f1
feat(chat): CU-17tkuw61kfy chat videos open from their card instead o…
michaelassraf Oct 28, 2026
b6cc660
feat(chat): CU-17tkuw61kfy card footers and source strips keep their …
michaelassraf Oct 29, 2026
facc207
fix(chat): CU-17tkuw61kfy the sources strip's skeleton is one row, on…
michaelassraf Oct 29, 2026
c56da62
feat(chat): CU-17tkuw61kfy a link to a screen of the app is an inline…
michaelassraf Oct 29, 2026
eb0d984
refactor(chat): CU-17tkuw61kfy one inline box component, InlineChip
michaelassraf Oct 29, 2026
556d341
refactor(chat): CU-17tkuw61kfy one card disclosure, an explicit app-s…
michaelassraf Oct 29, 2026
120f283
refactor(chat): CU-17tkuw61kfy in-app links by the runtime's rule, di…
michaelassraf Oct 29, 2026
ee333ac
Merge remote-tracking branch 'origin/main' into feat/mcp-in-app-links
michaelassraf Oct 29, 2026
bb8745a
fix(chat): CU-17tkuw61kfy the in-app link box is drawn inside the rou…
michaelassraf Oct 29, 2026
98be922
refactor(chat): CU-17tkuw61kfy markdown links read the navigation SSOT
michaelassraf Oct 29, 2026
81cf49d
refactor(chat): CU-17tkuw61kfy one navigation decision for every link…
michaelassraf Oct 29, 2026
8c78f9b
Merge branch 'main' into feat/mcp-in-app-links
michaelassraf Oct 29, 2026
5356117
refactor(chat): CU-17tkuw61kfy navigation goes through the host, with…
michaelassraf Oct 29, 2026
f636338
Merge remote-tracking branch 'origin/feat/mcp-in-app-links' into feat…
michaelassraf Oct 29, 2026
28f0873
feat(lint): CU-17tkuw61kfy flamingo/no-navigation-fallback blocks a s…
michaelassraf Oct 29, 2026
d85c25b
feat(chat): CU-17tkuw61kfy the navigation hooks a host's own links use
michaelassraf Oct 29, 2026
b17ce36
fix(chat): CU-17tkuw61kfy a link keeps the hub's old behavior exactly
michaelassraf Oct 29, 2026
eeea97f
Merge remote-tracking branch 'origin/main' into feat/mcp-in-app-links
michaelassraf Oct 29, 2026
5f148ed
fix(chat): CU-17tkuw61kfy one navigation path across the lib, from re…
michaelassraf Oct 29, 2026
5ffc671
fix(chat): CU-17tkuw61kfy review findings on the one navigation path
michaelassraf Oct 29, 2026
3b525ca
feat(chat): CU-17tkuw61kfy the host sets how many source skeletons an…
michaelassraf Oct 29, 2026
558e959
Merge branch 'main' into feat/mcp-in-app-links
michaelassraf Oct 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions openframe-frontend-core/eslint-config/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { boxedPrimitivesPlugin } from './boxed-primitives.js';
import { ignores } from './ignores.js';
import { imageSizesPlugin } from './image-sizes.js';
import { layoutVariantsPlugin } from './layout-variants.js';
import { navigationPlugin } from './navigation.js';
import { popupPortalPlugin } from './popup-portal.js';
import { reExportsPlugin } from './re-exports.js';
import { webviewPerformancePlugin } from './webview-performance.js';
Expand All @@ -19,6 +20,7 @@ export const flamingoPlugin = {
rules: {
...webviewPerformancePlugin.rules,
...layoutVariantsPlugin.rules,
...navigationPlugin.rules,
...imageSizesPlugin.rules,
...boxedPrimitivesPlugin.rules,
...popupPortalPlugin.rules,
Expand Down Expand Up @@ -333,6 +335,15 @@ export const base = [
rules: { 'flamingo/no-mixed-layout-variants': 'error' },
},

// A link is followed through the lib's navigation executor only — see ./navigation.js.
{
name: 'flamingo/base/navigation',
files: ['**/*.{js,mjs,jsx,ts,mts,tsx}'],
ignores: ['**/*.{test,spec}.{js,mjs,jsx,ts,mts,tsx}', '**/__tests__/**'],
plugins: { flamingo: flamingoPlugin },
rules: { 'flamingo/no-navigation-fallback': 'error' },
},

// A picture's `sizes` and quality come from the lib's image-size table — see ./image-sizes.js. Tests and stories
// draw no picture a reader waits on.
{
Expand Down
142 changes: 142 additions & 0 deletions openframe-frontend-core/eslint-config/navigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/**
* A link is followed in ONE way: the lib's navigation executor (`executeNavigation`, `executeNavigationImperative`,
* `executeNewTabNavigation`, the hooks built on it), which hands a same-tab link to the host's `runtime.navigation.navigate` and lets the browser
* open what the host does not take. Nothing beside it navigates: no fallback option handed to it, and no router push or
* `location` write in the same function as a call to it. A second path is how a host's routing gets skipped quietly
* (CU-17tkuw61kfy: every caller passed `fallbackNavigate: router.push`). If a host does not navigate, wire its
* `navigate`; never route around it.
*/

/** The executor and the hooks that call it. */
const EXECUTORS = new Set([
'executeNavigation',
'executeNavigationImperative',
'executeNewTabNavigation',
'useNavLinkViaRuntime',
'useNavigateViaRuntime',
]);

/** `router.push(...)`, `router.replace(...)`: a router call on anything named like a router. */
const ROUTER_METHOD = new Set(['push', 'replace']);
const LOCATION_METHOD = new Set(['assign', 'replace']);

function calleeName(callee) {
if (callee.type === 'Identifier') return callee.name;
if (callee.type === 'MemberExpression' && !callee.computed && callee.property.type === 'Identifier') {
return callee.property.name;
}
return null;
}

function objectName(node) {
if (node.type === 'Identifier') return node.name;
if (node.type === 'MemberExpression' && !node.computed && node.property.type === 'Identifier') {
return node.property.name;
}
if (node.type === 'CallExpression') return calleeName(node.callee);
return null;
}

/** A direct navigation: `router.push(x)`, `location.assign(x)`, `window.open(x)`, or a `location.href =` write. */
function directNavigation(node) {
if (node.type === 'CallExpression' && node.callee.type === 'MemberExpression' && !node.callee.computed) {
const method = node.callee.property.name;
const owner = objectName(node.callee.object);
if (!owner) return null;
if (ROUTER_METHOD.has(method) && /router$/i.test(owner)) return `${owner}.${method}()`;
if (LOCATION_METHOD.has(method) && owner === 'location') return `location.${method}()`;
if (method === 'open' && owner === 'window') return 'window.open()';
}
if (
node.type === 'AssignmentExpression' &&
node.left.type === 'MemberExpression' &&
!node.left.computed &&
node.left.property.name === 'href' &&
objectName(node.left.object) === 'location'
) {
return 'location.href =';
}
return null;
}

const FUNCTION_TYPES = new Set(['FunctionDeclaration', 'FunctionExpression', 'ArrowFunctionExpression']);

/** @type {import('eslint').Rule.RuleModule} */
const noNavigationFallback = {
meta: {
type: 'problem',
docs: { description: 'Disallow a second way to navigate beside the lib navigation executor' },
schema: [],
messages: {
option:
"`{{key}}` hands {{executor}} a second way to navigate. Links go through the host's " +
'`runtime.navigation.navigate`; a host that does not navigate wires `navigate`, never a fallback.',
beside:
'{{call}} navigates beside {{executor}} in the same function. Follow a link through the executor only; a ' +
'host that does not navigate wires `runtime.navigation.navigate`.',
},
},
create(context) {
// The module that DEFINES the executor is where navigating is implemented; the rule guards its callers.
const definesExecutor = context.sourceCode.ast.body.some(statement => {
const declaration = statement.type === 'ExportNamedDeclaration' ? statement.declaration : statement;
return declaration?.type === 'FunctionDeclaration' && EXECUTORS.has(declaration.id?.name);
});
if (definesExecutor) return {};
/** Per enclosing function: the executor calls and the direct navigations anywhere inside it (nested handlers
* included). The file itself is a frame too, but only for its top-level code: two components in one file are
* two functions. */
const frames = [];
const reported = new Set();
const enter = () => frames.push({ executors: [], direct: [] });
const exit = () => {
const frame = frames.pop();
if (!frame || frame.executors.length === 0) return;
for (const { node, call } of frame.direct) {
if (reported.has(node)) continue;
reported.add(node);
context.report({ node, messageId: 'beside', data: { call, executor: frame.executors[0] } });
}
};
/** The frames a fact belongs to: every enclosing function, or the file when at the top level. */
const owners = () => (frames.length > 1 ? frames.slice(1) : frames);
const noteDirect = node => {
const call = directNavigation(node);
if (call) for (const frame of owners()) frame.direct.push({ node, call });
};

return {
Program: enter,
'Program:exit': exit,
...Object.fromEntries(
[...FUNCTION_TYPES].flatMap(t => [
[t, enter],
[`${t}:exit`, exit],
]),
),
CallExpression(node) {
const name = calleeName(node.callee);
if (name && EXECUTORS.has(name)) {
for (const frame of owners()) frame.executors.push(name);
for (const arg of node.arguments) {
if (arg.type !== 'ObjectExpression') continue;
for (const prop of arg.properties) {
const key = prop.type === 'Property' && !prop.computed ? (prop.key.name ?? prop.key.value) : null;
if (typeof key === 'string' && /^fallback/i.test(key)) {
context.report({ node: prop, messageId: 'option', data: { key, executor: name } });
}
}
}
return;
}
noteDirect(node);
},
AssignmentExpression: noteDirect,
};
},
};

export const navigationPlugin = {
meta: { name: 'flamingo-navigation' },
rules: { 'no-navigation-fallback': noNavigationFallback },
};
55 changes: 55 additions & 0 deletions openframe-frontend-core/src/__tests__/eslint-navigation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { RuleTester } from 'eslint';
import { navigationPlugin } from '../../eslint-config/navigation.js';

new RuleTester().run('no-navigation-fallback', navigationPlugin.rules['no-navigation-fallback'], {
valid: [
// The executor alone.
'function onClick(e) { executeNavigation({ event: e, runtime, href, path, targetPlatform, hostRoute }); }',
'function open() { executeNewTabNavigation({ runtime, href, targetPlatform: null }); }',
// A router call with no executor in the function: a query-string write, not a link.
'function setPage(p) { router.replace(`${pathname}?page=${p}`); }',
// Two components in one file: one follows links, the other writes the URL.
'function Row() { const go = e => executeNavigation({ event: e, runtime, href }); }\n' +
'function List() { router.replace(`${pathname}?q=1`); }',
// The module that defines the executor implements navigating.
'export function executeNavigation(args) { window.location.assign(args.href); }',
],
invalid: [
{
// CU-17tkuw61kfy: every caller handed the executor `router.push`.
code: 'function onClick(e) { executeNavigation({ event: e, runtime, href, fallbackNavigate: router.push }); }',
errors: [{ messageId: 'option' }],
},
{
code: 'function go() { executeNavigationImperative({ runtime, href, fallback: href => location.assign(href) }); }',
errors: [{ messageId: 'option' }, { messageId: 'beside' }],
},
{
// A second path after the executor.
code: 'function onClick(e) { if (!executeNavigation({ event: e, runtime, href })) router.push(href); }',
errors: [{ messageId: 'beside' }],
},
{
// A new tab opened by hand beside the executor.
code:
'function onSelect(row, wantsNewTab) {\n' +
" if (wantsNewTab) { window.open(row.href, '_blank'); return; }\n" +
' executeNavigationImperative({ runtime, href: row.href });\n' +
'}',
errors: [{ messageId: 'beside' }],
},
{
code: 'function onClick(e) { executeNavigation({ event: e, runtime, href }) || (window.location.href = href); }',
errors: [{ messageId: 'beside' }],
},
{
// A handler nested in a component: the component follows links, so it navigates only through the executor.
code:
'function Card() {\n' +
' const onClick = e => executeNavigation({ event: e, runtime, href });\n' +
' const onKey = () => router.push(href);\n' +
'}',
errors: [{ messageId: 'beside' }],
},
],
});
14 changes: 8 additions & 6 deletions openframe-frontend-core/src/components/announcement-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { X } from 'lucide-react';
import { useEffect, useMemo, useState, useSyncExternalStore } from 'react';
import { useChatRuntime } from '../contexts/chat-runtime-context';
import { useEndpointsRuntime } from '../contexts/endpoints-runtime-context';
import { usePathname } from '../embed-shims/next-navigation';
import { useSelfFetch } from '../hooks/use-self-fetch';
Expand All @@ -16,6 +17,7 @@
import { getAppType } from '../utils/app-config';
import { pickReadableTextColor } from '../utils/color-analysis';
import { pathMatchesAny } from '../utils/path-pattern';
import { executeNavigationImperative, executeNewTabNavigation } from './chat/utils/execute-navigation';
import { EntityIcon } from './icon-display';
import { AnnouncementBarView } from './ui/announcement-bar-view';
import { Button } from './ui/button';
Expand Down Expand Up @@ -89,6 +91,8 @@
// `usePathname` on a Next host, the embedder's registered router elsewhere).
// Read HERE so every host gets `excluded_paths` with no wiring of its own.
const pathname = usePathname();
// The CTA is followed through the lib's navigation executor, with the host's runtime when there is one.
const runtime = useChatRuntime();

// Optional endpoint runtime: no provider → no URL → fetching disabled.
const endpoints = useEndpointsRuntime();
Expand Down Expand Up @@ -200,7 +204,7 @@
if (previewMode || !announcement?.cta_url) return;
// Scheme guard: cta_url is admin-entered data — only http(s) (absolute or
// relative) may navigate. A `javascript:` value would otherwise execute
// via location.href / window.open (stored XSS).
// via a navigation (stored XSS).
let safeUrl: string;
try {
// Resolve against the CURRENT page (not the origin) so path-relative and
Expand All @@ -211,11 +215,9 @@
} catch {
return;
}
if (announcement.cta_target === '_blank') {
window.open(safeUrl, '_blank', 'noopener,noreferrer');
} else {
window.location.href = safeUrl;
}
// The admin chose the tab (`cta_target`).
if (announcement.cta_target === '_blank') executeNewTabNavigation({ runtime, href: safeUrl });
else executeNavigationImperative({ runtime, href: safeUrl, openIn: 'same-tab' });

Check warning on line 220 in openframe-frontend-core/src/components/announcement-bar.tsx

View check run for this annotation

Flamingo / Flamingo Code Review / tests and mutation

Components moved onto the navigation executor have no tests

The announcement bar CTA, the ticket alerts button (ticket-alerts-button.tsx:63), the contact form redirect (use-contact-submission.ts:113), the vendor button, the service card, the devices table and ticket attachments now navigate through executeNewTabNavigation / executeNavigationImperative instead of window.open / location / router.push, and none of them has a test of the click. The announcement CTA's same-tab path is now the host's soft navigation, not a full page load. Risk: A wrong argument (a missing runtime, openIn, or targetPlatform) would send a CTA or a ticket alert to the wrong tab or not navigate at all, unnoticed until someone clicks it. Fix: Add one click test per component with a stub runtime: the announcement CTA calls navigate for a same-tab target and openExternal for cta_target '_blank'; the ticket alerts button calls navigate with the newest-unread ticket href; the contact redirect calls navigate after success.
Comment thread
michaelassraf marked this conversation as resolved.
Resolved
};

// Never had anything to show: render nothing. Dismissal AND deactivation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface EmbeddableChatProps {
```

### Key Runtime Dependencies
- **`useRequiredChatRuntime()`** — provides `user`, `source`, and navigation context (replaces hub's `useAuth`, `currentPlatform`, `useNavLink`)
- **`useRequiredChatRuntime()`** — provides `user`, `source`, and navigation context (replaces hub's `useAuth`, `currentPlatform`, `useNavLinkViaRuntime`)
- **`useUnifiedChat()`** — orchestrates Guide/Mingo mode switching and transport adapters
- **`useSseChatAdapter()`** — SSE transport for Guide mode (replaces `useDocChat`)
- **`NavLinkAnchorViaRuntime`** — runtime-aware link rendering (replaces hub's `NavLinkAnchor`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Primary export. Resolves the final href and new-tab decision at runtime, then de
- **`resolveHrefForRuntime`** — adapts the raw `href` for the active runtime context
- **`computeIsNewTab`** — applies embed-mode short-circuit → `runtime.navigation.decideNewTab` → lib fallback chain
- **`newTabAnchorAttrs`** — produces correct `target` / `rel` attributes
- **`handleChatNavClick`** — unified click handler shared with source chips and inline cards
- **`executeNavigation`** — unified click handler shared with source chips and inline cards
- **`useChatPanel`** — closes the chat panel on same-tab navigation; leaves it open for new-tab clicks

> **Chat-only contract:** Uses `useRequiredChatRuntime`, which **throws** if mounted outside a `<ChatRuntimeContext.Provider>`. This is intentional — silent fallback when the runtime is absent is never acceptable.
Expand All @@ -44,7 +44,7 @@ function ChatMarkdownLink({ href, children }) {
}
```

> For links **outside** the chat tree (header chrome, marketing pages), use the hub's own `useNavLink`-based anchor instead — this component will throw in those contexts by design.
> A host mounts the runtime app-wide, so its header, footer and pages use this component (or `useNavLinkViaRuntime` / `useNavigateViaRuntime`) for their own links too.

## Source

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* is the lib rule with no target platform).
*/

import { fireEvent, render, screen } from '@testing-library/react';
import { fireEvent, render, screen, within } from '@testing-library/react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { type ChatRuntime, ChatRuntimeContext } from '../../../contexts/chat-runtime-context';
import { ChatMessageEnhanced } from '../chat-message-enhanced';
Expand Down Expand Up @@ -101,13 +101,14 @@ describe('ChatMessageEnhanced — in-app screen links', () => {

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');
// The same routed anchor as every link (see the routing case above); only its content is the lib's InlineChip.
for (const anchor of screen.getAllByRole('link')) expect(within(anchor).getByTestId('inline-chip')).toBeTruthy();
});

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');
const anchor = screen.getByRole('link', { name: 'Devices → Add Device' });
expect(within(anchor).queryByTestId('inline-chip')).toBeNull();
});

it('opens the same link written absolute in a new tab, even on the page origin', () => {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { render, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { InlineChip } from '../inline-chip';

describe('InlineChip', () => {
it('draws its label in the inline box', () => {
render(<InlineChip label="Devices → Add Device" />);
expect(screen.getByTestId('inline-chip')).toHaveTextContent('Devices → Add Device');
});
});
Loading
Loading