diff --git a/components/chat/messages.tsx b/components/chat/messages.tsx index c01d11b..5d0ef72 100644 --- a/components/chat/messages.tsx +++ b/components/chat/messages.tsx @@ -7,6 +7,7 @@ import { Avatar, Button, Tooltip } from '@nextui-org/react'; import type { CallFrame } from '@gptscript-ai/gptscript'; import Calls from './messages/calls'; import { GoIssueReopened } from 'react-icons/go'; +import { defaultUrlTransform } from 'react-markdown'; export enum MessageType { Alert, @@ -30,6 +31,14 @@ const abbreviate = (name: string) => { return firstLetters.slice(0, 2).join('').toUpperCase(); }; +// Allow links for file references in messages if it starts with file://, otherwise this will cause an empty href and cause app to reload when clicking on it +const urlTransformAllowFiles = (u: string) => { + if (u.startsWith('file://')) { + return u; + } + return defaultUrlTransform(u); +}; + const Message = React.memo( ({ message, @@ -88,6 +97,7 @@ const Message = React.memo( rehypePlugins={[ [rehypeExternalLinks, { target: '_blank' }], ]} + urlTransform={urlTransformAllowFiles} > {message.message} @@ -156,6 +166,7 @@ const Message = React.memo( rehypePlugins={[ [rehypeExternalLinks, { target: '_blank' }], ]} + urlTransform={urlTransformAllowFiles} > {message.message} diff --git a/electron/main.mjs b/electron/main.mjs index 66b2917..ce94ae6 100644 --- a/electron/main.mjs +++ b/electron/main.mjs @@ -96,6 +96,13 @@ function createWindow(url) { // Allow navigation for internal URLs return { action: 'allow' }; }); + + win.webContents.on('will-navigate', (event, url) => { + if (url.startsWith('file://')) { + event.preventDefault(); + shell.openExternal(url); + } + }); } function ensureDirExists(dir) {