mirror of
https://github.com/aaif-goose/goose.git
synced 2026-07-03 14:10:03 +02:00
[app] Limit link detection - show all parts of messages which contain toolInvocations and text content
This commit is contained in:
@@ -13,23 +13,20 @@ interface GooseMessageProps {
|
||||
}
|
||||
|
||||
export default function GooseMessage({ message, metadata, messages, append }: GooseMessageProps) {
|
||||
// Find the preceding user message
|
||||
// Extract URLs under a few conditions
|
||||
// 1. The message is purely text
|
||||
// 2. The link wasn't also present in the previous message
|
||||
// 3. The message contains the explicit http:// or https:// protocol at the beginning
|
||||
const messageIndex = messages?.findIndex(msg => msg.id === message.id);
|
||||
const previousMessage = messageIndex > 0 ? messages[messageIndex - 1] : null;
|
||||
|
||||
// Get URLs from previous user message (if it exists)
|
||||
const previousUrls = previousMessage
|
||||
? extractUrls(previousMessage.content)
|
||||
: [];
|
||||
|
||||
// Extract URLs from current message, excluding those from the previous user message
|
||||
const urls = extractUrls(message.content, previousUrls);
|
||||
const previousUrls = previousMessage ? extractUrls(previousMessage.content) : [];
|
||||
const urls = !message.toolInvocations ? extractUrls(message.content, previousUrls) : [];
|
||||
|
||||
return (
|
||||
<div className="flex mb-[16px]">
|
||||
<div className="flex">
|
||||
<div className="flex flex-col">
|
||||
<div className="bg-goose-bubble text-white rounded-2xl p-4">
|
||||
{message.toolInvocations ? (
|
||||
{message.toolInvocations && (
|
||||
<div className="bg-goose-bubble text-white rounded-2xl p-4 mb-[16px]">
|
||||
<div className="space-y-4">
|
||||
{message.toolInvocations.map((toolInvocation) => (
|
||||
<ToolInvocation
|
||||
@@ -38,18 +35,14 @@ export default function GooseMessage({ message, metadata, messages, append }: Go
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
metadata ? (
|
||||
<GooseResponseForm
|
||||
message={message.content}
|
||||
metadata={metadata}
|
||||
append={append}
|
||||
/>
|
||||
) : (
|
||||
<ReactMarkdown className="prose">{message.content}</ReactMarkdown>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{message.content && (
|
||||
<div className="bg-goose-bubble text-white rounded-2xl p-4 mb-[16px]">
|
||||
<ReactMarkdown className="prose">{message.content}</ReactMarkdown>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{urls.length > 0 && (
|
||||
<div className="mt-2">
|
||||
@@ -58,6 +51,16 @@ export default function GooseMessage({ message, metadata, messages, append }: Go
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{false && metadata && (
|
||||
<div className="bg-goose-bubble text-white rounded-2xl p-4 mb-[16px]">
|
||||
<GooseResponseForm
|
||||
message={message.content}
|
||||
metadata={metadata}
|
||||
append={append}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -4,9 +4,8 @@ import LinkPreview from './LinkPreview'
|
||||
import { extractUrls } from '../utils/urlUtils'
|
||||
|
||||
export default function UserMessage({ message }) {
|
||||
// Extract URLs from current message
|
||||
const urls = extractUrls(message.content, []); // No previous URLs to check against
|
||||
console.log('User message URLs:', urls);
|
||||
// Extract URLs which explicitly contain the http:// or https:// protocol
|
||||
const urls = extractUrls(message.content, []);
|
||||
|
||||
return (
|
||||
<div className="flex justify-end mb-[16px]">
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import * as linkify from 'linkifyjs';
|
||||
|
||||
// Helper to normalize URLs for comparison
|
||||
function normalizeUrl(url: string): string {
|
||||
try {
|
||||
@@ -13,21 +11,18 @@ function normalizeUrl(url: string): string {
|
||||
}
|
||||
|
||||
export function extractUrls(content: string, previousUrls: string[] = []): string[] {
|
||||
// First extract markdown-style links using regex
|
||||
const markdownLinkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
|
||||
// Modified regex to only match markdown links with http:// or https://
|
||||
const markdownLinkRegex = /\[([^\]]+)\]\((https?:\/\/[^)]+)\)/g;
|
||||
const markdownMatches = Array.from(content.matchAll(markdownLinkRegex));
|
||||
const markdownUrls = markdownMatches.map(match => match[2]);
|
||||
|
||||
// Then use linkifyjs to find regular URLs
|
||||
const links = linkify.find(content);
|
||||
// Modified regex for standalone URLs with http:// or https://
|
||||
const urlRegex = /(https?:\/\/[^\s<>"']+)/g;
|
||||
const urlMatches = Array.from(content.matchAll(urlRegex));
|
||||
const standardUrls = urlMatches.map(match => match[1]);
|
||||
|
||||
// Get URLs from current content
|
||||
const linkifyUrls = links
|
||||
.filter(link => link.type === 'url')
|
||||
.map(link => link.href);
|
||||
|
||||
// Combine markdown URLs with linkify URLs
|
||||
const currentUrls = [...new Set([...markdownUrls, ...linkifyUrls])];
|
||||
// Combine markdown URLs with standard URLs
|
||||
const currentUrls = [...new Set([...markdownUrls, ...standardUrls])];
|
||||
|
||||
// Normalize all URLs for comparison
|
||||
const normalizedPreviousUrls = previousUrls.map(normalizeUrl);
|
||||
|
||||
Reference in New Issue
Block a user