Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(ui): keep chat bubble session links in-app (#1628)

Call White28966a1a4b00
diff --git a/ui/src/components/ui/markdown.tsx b/ui/src/components/ui/markdown.tsx
index 8450bd958..e15c079f4 100644
--- a/ui/src/components/ui/markdown.tsx
+++ b/ui/src/components/ui/markdown.tsx
@@ -3,12 +3,14 @@ import ReactMarkdown, { type Components, defaultUrlTransform } from 'react-markd
import remarkGfm from 'remark-gfm';
import remarkBreaks from 'remark-breaks';
import { useTranslation } from 'react-i18next';
+import { Link } from 'react-router-dom';
import { Check, Copy } from 'lucide-react';
import { Badge } from '@/components/ui/badge';
import { ChatImage, LinkedImageContent, LinkedImageProvider } from '@/components/ui/chat-image';
import { FileCard } from '@/components/ui/file-card';
import { SecretRequestCard } from '@/components/ui/secret-request-card';
+import { inAppChatPath } from '@/lib/applicationRoutes';
import { isProxyMediaUrl, readMediaDims } from '@/lib/mediaProxy';
import { isAbsoluteWindowsFileHref, resolveLocalFileLink, type LocalFileLinkTarget } from '@/lib/localFileLinks';
import {
@@ -283,6 +285,17 @@ export const Markdown: React.FC<{
);
}
if (!interactive) return <span>{children}</span>;
+ const chatPath = inAppChatPath(
+ url,
+ typeof window === 'undefined' ? null : window.location.href,
+ );
+ if (chatPath) {
+ return (
+ <Link to={chatPath}>
+ <LinkedImageProvider>{children}</LinkedImageProvider>
+ </Link>
+ );
+ }
// Wrap children so a nested ChatImage (``[![](media)](href)``) renders
// bare — without its own download anchor inside this one.
return (
diff --git a/ui/src/components/workbench/ChatArchivedReadOnly.test.tsx b/ui/src/components/workbench/ChatArchivedReadOnly.test.tsx
index 9fa79cc1a..3718646db 100644
--- a/ui/src/components/workbench/ChatArchivedReadOnly.test.tsx
+++ b/ui/src/components/workbench/ChatArchivedReadOnly.test.tsx
@@ -981,6 +981,22 @@ describe('agent-authored local file links', () => {
expect(routeMarkup).toContain('target="_blank"');
});
+ it('opens Workbench chat routes in the current document', () => {
+ const props = {
+ session: session({ workdir: '/workspace/project' }),
+ messageFontSize: 13,
+ onOpenLocalFile: () => undefined,
+ };
+ const chatMessage = {
+ ...linkedMessage('agent'),
+ text: '[open chat](/chat/session-456)',
+ } as WorkbenchMessage;
+ const markup = render(<MessageRow {...props} message={chatMessage} />);
+ expect(markup).toContain('href="/chat/session-456"');
+ expect(markup).not.toContain('target="_blank"');
+ expect(markup).not.toContain('data-local-file-link');
+ });
+
it('lets the outer local link own clicks for a linked local image', () => {
const linkedImageMessage = {
...linkedMessage('agent'),
diff --git a/ui/src/lib/applicationRoutes.test.ts b/ui/src/lib/applicationRoutes.test.ts
index 993ddf0f8..a700087d4 100644
--- a/ui/src/lib/applicationRoutes.test.ts
+++ b/ui/src/lib/applicationRoutes.test.ts
@@ -6,6 +6,7 @@ import { describe, expect, it } from 'vitest';
import {
APPLICATION_DYNAMIC_ROUTE_PATHS,
APPLICATION_ROUTE_PATHS,
+ inAppChatPath,
isApplicationRouteHref,
} from './applicationRoutes';
@@ -73,4 +74,21 @@ describe('AppShell route policy', () => {
expect(isApplicationRouteHref('/projects/report.md')).toBe(false);
expect(isApplicationRouteHref('/admin/settings/custom.json')).toBe(false);
});
+
+ it('keeps same-origin chat destinations on the SPA path', () => {
+ expect(APPLICATION_DYNAMIC_ROUTE_PATHS).toContain('/chat/:sessionId');
+ const current = 'https://alex-app.avibe.bot/chat/session-123';
+ expect(inAppChatPath('/chat/session-456?msg=latest#reply')).toBe(
+ '/chat/session-456?msg=latest#reply',
+ );
+ expect(inAppChatPath('/chat/session-456/')).toBe('/chat/session-456');
+ expect(inAppChatPath('https://alex-app.avibe.bot/chat/session-456', current)).toBe(
+ '/chat/session-456',
+ );
+ expect(inAppChatPath('https://github.com/avibe-bot/avibe/chat/session-456', current)).toBeNull();
+ expect(inAppChatPath('/apps/files')).toBeNull();
+ expect(inAppChatPath('/chat/session-456/notes.md')).toBeNull();
+ expect(inAppChatPath('./chat/session-456')).toBeNull();
+ expect(inAppChatPath('https://alex-app.avibe.bot/chat/session-456')).toBeNull();
+ });
});
diff --git a/ui/src/lib/applicationRoutes.ts b/ui/src/lib/applicationRoutes.ts
index d5ea53b11..d4506cc63 100644
--- a/ui/src/lib/applicationRoutes.ts
+++ b/ui/src/lib/applicationRoutes.ts
@@ -73,12 +73,49 @@ const APPLICATION_ROUTE_PATTERNS = APPLICATION_DYNAMIC_ROUTE_PATHS.map((path) =>
const pattern = path.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/:[^/]+/g, '[^/]+');
return new RegExp(`^${pattern}$`);
});
+const CHAT_ROUTE_PATTERN = APPLICATION_ROUTE_PATTERNS[
+ APPLICATION_DYNAMIC_ROUTE_PATHS.indexOf('/chat/:sessionId')
+];
-export function isApplicationRouteHref(href: string): boolean {
+function hrefPathname(href: string): string {
const rawPathname = href.split(/[?#]/, 1)[0];
- const pathname = rawPathname.replace(/\/+$/, '') || '/';
+ return rawPathname.replace(/\/+$/, '') || '/';
+}
+
+function isAbsoluteHref(href: string): boolean {
+ return /^[a-zA-Z][a-zA-Z+\-.]*:/.test(href) || href.startsWith('//');
+}
+
+export function isApplicationRouteHref(href: string): boolean {
+ const pathname = hrefPathname(href);
return (
APPLICATION_ROUTES.has(pathname) ||
APPLICATION_ROUTE_PATTERNS.some((pattern) => pattern.test(pathname))
);
}
+
+export function inAppChatPath(href: string, currentHref?: string | null): string | null {
+ try {
+ if (!href) return null;
+ if (isAbsoluteHref(href)) {
+ if (!currentHref) return null;
+ const current = new URL(currentHref);
+ const target = new URL(href, current);
+ if (target.origin !== current.origin || !['http:', 'https:'].includes(target.protocol)) {
+ return null;
+ }
+ return chatPath(target.pathname, target.search, target.hash);
+ }
+ if (!href.startsWith('/') || href.startsWith('//')) return null;
+ const target = new URL(href, 'https://avibe.invalid');
+ return chatPath(target.pathname, target.search, target.hash);
+ } catch {
+ return null;
+ }
+}
+
+function chatPath(pathname: string, search: string, hash: string): string | null {
+ const normalized = hrefPathname(pathname);
+ if (!CHAT_ROUTE_PATTERN?.test(normalized)) return null;
+ return `${normalized}${search}${hash}`;
+}