Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions frontend/src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
},
{
"url": "https://opensecret.cloud/*"
},
{
"url": "https://*"
}
Comment thread
AnthonyRonning marked this conversation as resolved.
]
},
Expand Down
3 changes: 3 additions & 0 deletions frontend/src-tauri/capabilities/mobile-android.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
},
{
"url": "https://*.google.com/*"
},
{
"url": "https://*"
}
]
}
Expand Down
3 changes: 3 additions & 0 deletions frontend/src-tauri/capabilities/mobile-ios.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
},
{
"url": "https://opensecret.cloud/*"
},
{
"url": "https://*"
}
]
},
Expand Down
49 changes: 49 additions & 0 deletions frontend/src/components/ExternalUrlConfirmDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle
} from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";

interface ExternalUrlConfirmDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
onConfirm: () => void;
url: string;
}

export function ExternalUrlConfirmDialog({
open,
onOpenChange,
onConfirm,
url
}: ExternalUrlConfirmDialogProps) {
const handleConfirm = (e: React.MouseEvent) => {
e.preventDefault();
onConfirm();
onOpenChange(false);
};

return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent>
<DialogHeader>
<DialogTitle>Open External Link?</DialogTitle>
<DialogDescription>
You are about to open an external URL in your browser:
<div className="mt-2 p-2 bg-muted rounded-md break-all text-sm font-mono">{url}</div>
</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button variant="outline" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<Button onClick={handleConfirm}>Open</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
32 changes: 32 additions & 0 deletions frontend/src/components/ExternalUrlConfirmHandler.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useEffect, useState } from "react";
import { ExternalUrlConfirmDialog } from "@/components/ExternalUrlConfirmDialog";
import { setUrlConfirmationCallback, openExternalUrl } from "@/utils/openUrl";

export function ExternalUrlConfirmHandler() {
const [pendingUrl, setPendingUrl] = useState<string | null>(null);

useEffect(() => {
const register = (url: string) => {
// Only set if no pending URL (ignore rapid clicks while dialog is open)
setPendingUrl((current) => (current !== null ? current : url));
};
setUrlConfirmationCallback(register);
return () => setUrlConfirmationCallback(null);
}, []);

const handleConfirm = () => {
if (pendingUrl) {
openExternalUrl(pendingUrl);
setPendingUrl(null);
}
};

return (
<ExternalUrlConfirmDialog
open={pendingUrl !== null}
onOpenChange={(open) => !open && setPendingUrl(null)}
onConfirm={handleConfirm}
url={pendingUrl || ""}
/>
);
}
16 changes: 8 additions & 8 deletions frontend/src/components/UnifiedChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ function ToolCallRenderer({
{query ? `Searched: "${query}"` : "Web Search"}
</span>
</div>
{/* Search result - indented to align with text */}
<div className="pl-6 text-foreground/80 whitespace-pre-wrap break-words">
{isExpanded ? output : preview}
{/* Search result - indented to align with text, render as markdown for links */}
<div className="pl-6 text-foreground/80">
<Markdown content={isExpanded ? output : preview} fontSize={14} />
Comment on lines +249 to +250
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Check that removing whitespace-pre-wrap break-words doesn't affect plain text formatting in tool outputs. The Markdown component handles this via RemarkBreaks plugin and CSS, but verify with outputs containing multiple spaces or special formatting.

Prompt To Fix With AI
This is a comment left during a code review.
Path: frontend/src/components/UnifiedChat.tsx
Line: 249:250

Comment:
**style:** Check that removing `whitespace-pre-wrap break-words` doesn't affect plain text formatting in tool outputs. The Markdown component handles this via `RemarkBreaks` plugin and CSS, but verify with outputs containing multiple spaces or special formatting.

How can I resolve this? If you propose a fix, please make it concise.

{hasMore && (
<button
onClick={() => setIsExpanded(!isExpanded)}
Expand Down Expand Up @@ -275,9 +275,9 @@ function ToolCallRenderer({
<Check className="h-4 w-4 text-green-600 dark:text-green-400 flex-shrink-0" />
<span className="font-medium text-foreground">{statusText}</span>
</div>
{/* Tool output - indented */}
<div className="pl-6 text-foreground/80 whitespace-pre-wrap break-words">
{isExpanded ? output : preview}
{/* Tool output - indented, render as markdown for links */}
<div className="pl-6 text-foreground/80">
<Markdown content={isExpanded ? output : preview} fontSize={14} />
{hasMore && (
<button
onClick={() => setIsExpanded(!isExpanded)}
Expand Down Expand Up @@ -328,8 +328,8 @@ function ToolCallRenderer({
<Check className="h-4 w-4 text-green-600 dark:text-green-400 flex-shrink-0" />
<span className="font-medium text-foreground">Tool Result</span>
</div>
<div className="pl-6 text-foreground/80 whitespace-pre-wrap break-words">
{isExpanded ? output : preview}
<div className="pl-6 text-foreground/80">
<Markdown content={isExpanded ? output : preview} fontSize={14} />
{hasMore && (
<button
onClick={() => setIsExpanded(!isExpanded)}
Expand Down
17 changes: 17 additions & 0 deletions frontend/src/components/markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import React from "react";
import { Button } from "./ui/button";
import { Check, Copy, ChevronDown, ChevronRight, Brain, FileText } from "lucide-react";
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "./ui/dialog";
import { openExternalUrlWithConfirmation } from "@/utils/openUrl";

async function copyToClipboard(text: string) {
try {
Expand Down Expand Up @@ -374,6 +375,22 @@ function MarkDownContentToMemo(props: { content: string }) {
const href = aProps.href || "";
const isInternal = /^\/#/i.test(href);
const target = isInternal ? "_self" : (aProps.target ?? "_blank");
Comment thread
AnthonyRonning marked this conversation as resolved.

// For external links, show confirmation before opening
if (!isInternal && href) {
return (
<a
{...aProps}
target={target}
onClick={(e) => {
e.preventDefault();
openExternalUrlWithConfirmation(href);
}}
style={{ cursor: "pointer" }}
/>
);
}

return <a {...aProps} target={target} />;
}
}}
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/routes/__root.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useOpenSecret } from "@opensecret/react";
import { OpenSecretContextType } from "@opensecret/react";
import { createRootRouteWithContext, Outlet } from "@tanstack/react-router";
import { ExternalUrlConfirmHandler } from "@/components/ExternalUrlConfirmHandler";

interface RootRouterContext {
os: OpenSecretContextType;
Expand Down Expand Up @@ -35,5 +36,10 @@ function Root() {
return <></>;
}

return <Outlet />;
return (
<>
<Outlet />
<ExternalUrlConfirmHandler />
</>
);
}
103 changes: 103 additions & 0 deletions frontend/src/utils/openUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* Utility for opening external URLs
*
* This module provides a unified way to open external URLs that works
* correctly in both web browsers and Tauri environments.
*
* In Tauri apps, regular <a> tags with target="_blank" don't work properly.
* We need to use the Tauri opener plugin to open URLs in the system browser.
*/

import { isTauri } from "@/utils/platform";

// State management for confirmation dialog
let urlConfirmationCallback: ((url: string) => void) | null = null;

export function setUrlConfirmationCallback(callback: ((url: string) => void) | null) {
urlConfirmationCallback = callback;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

/**
* Opens an external URL in the appropriate way for the current environment
*
* - In web browsers: uses window.open()
* - In Tauri apps: uses the opener plugin to open in system browser
*
* @param url - The URL to open
* @returns Promise that resolves when the URL is opened (or rejects on error)
*
* @example
* ```typescript
* // In a component
* import { openExternalUrl } from '@/utils/openUrl';
*
* <a
* href={url}
* onClick={(e) => {
* e.preventDefault();
* openExternalUrl(url);
* }}
* >
* Click me
* </a>
* ```
*/
export async function openExternalUrl(url: string): Promise<void> {
try {
if (isTauri()) {
// In Tauri, use the opener plugin
const { openUrl } = await import("@tauri-apps/plugin-opener");
await openUrl(url);
Comment thread
AnthonyRonning marked this conversation as resolved.
} else {
// In web browsers, use window.open
const popup = window.open(url, "_blank", "noopener,noreferrer");
if (!popup) {
throw new Error("Failed to open URL - popup may be blocked");
}
}
} catch (error) {
console.error("Failed to open URL:", url, error);
// Fallback: try window.open anyway
try {
const popup = window.open(url, "_blank", "noopener,noreferrer");
if (!popup) {
console.error("Fallback window.open was also blocked");
}
} catch (fallbackError) {
console.error("Fallback also failed:", fallbackError);
}
}
}

/**
* Opens an external URL with user confirmation
*
* Shows a confirmation dialog to the user before opening the URL.
* Requires ExternalUrlConfirmHandler to be mounted in the app.
*
* @param url - The URL to open
*
* @example
* ```typescript
* // In a component
* import { openExternalUrlWithConfirmation } from '@/utils/openUrl';
*
* <a
* href={url}
* onClick={(e) => {
* e.preventDefault();
* openExternalUrlWithConfirmation(url);
* }}
* >
* Click me
* </a>
* ```
*/
export function openExternalUrlWithConfirmation(url: string): void {
if (urlConfirmationCallback) {
urlConfirmationCallback(url);
} else {
console.warn("URL confirmation callback not set, opening directly");
openExternalUrl(url);
}
}
Loading