Skip to content

Commit d7cc5ee

Browse files
committed
fix(tarko-agent-ui): use react components instead of html strings for url links
1 parent d92283e commit d7cc5ee

File tree

1 file changed

+41
-28
lines changed

1 file changed

+41
-28
lines changed

multimodal/tarko/agent-ui/src/standalone/workspace/renderers/TerminalRenderer.tsx

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,37 +58,50 @@ function formatArguments(args: Record<string, any>): string {
5858
* Custom CodeHighlight wrapper that makes URLs clickable in JSON
5959
*/
6060
function CodeHighlightWithLinks({ code, language }: { code: string; language: string }) {
61-
const [processedCode, setProcessedCode] = React.useState<string>(code);
62-
63-
React.useEffect(() => {
64-
if (language === 'json') {
65-
// Replace URLs in JSON strings with clickable links
66-
const urlRegex = /"(https?:\/\/[^"\s]+)"/g;
67-
const linkedCode = code.replace(urlRegex, (match, url) => {
68-
return `"<span class='json-url-link text-blue-400 hover:text-blue-300 underline cursor-pointer' data-url='${url}'>${url}</span>"`;
69-
});
70-
setProcessedCode(linkedCode);
71-
} else {
72-
setProcessedCode(code);
73-
}
74-
}, [code, language]);
75-
76-
const handleClick = React.useCallback((e: React.MouseEvent) => {
77-
const target = e.target as HTMLElement;
78-
if (target.classList.contains('json-url-link')) {
79-
e.preventDefault();
80-
e.stopPropagation();
81-
const url = target.getAttribute('data-url');
82-
if (url) {
83-
window.open(url, '_blank', 'noopener,noreferrer');
61+
if (language !== 'json') {
62+
return <CodeHighlight code={code} language={language} />;
63+
}
64+
65+
// For JSON, render with clickable URLs
66+
const renderJsonWithLinks = (jsonString: string) => {
67+
const urlRegex = /"(https?:\/\/[^"\s]+)"/g;
68+
const parts = jsonString.split(urlRegex);
69+
70+
return parts.map((part, index) => {
71+
// Check if this part is a URL (every odd index after split)
72+
if (index > 0 && index % 2 === 1 && /^https?:\/\//.test(part)) {
73+
return (
74+
<React.Fragment key={index}>
75+
<span className="text-green-400">"</span>
76+
<a
77+
href={part}
78+
target="_blank"
79+
rel="noopener noreferrer"
80+
className="text-blue-400 hover:text-blue-300 underline cursor-pointer"
81+
onClick={(e) => e.stopPropagation()}
82+
>
83+
{part}
84+
</a>
85+
<span className="text-green-400">"</span>
86+
</React.Fragment>
87+
);
8488
}
85-
}
86-
}, []);
89+
return <span key={index}>{part}</span>;
90+
});
91+
};
92+
93+
// Check if the code contains URLs in JSON strings
94+
const hasUrls = /"https?:\/\/[^"\s]+"/.test(code);
8795

96+
if (!hasUrls) {
97+
return <CodeHighlight code={code} language={language} />;
98+
}
99+
100+
// Render with custom URL handling
88101
return (
89-
<div onClick={handleClick}>
90-
<CodeHighlight code={processedCode} language={language} />
91-
</div>
102+
<pre className="text-sm bg-transparent text-gray-300 whitespace-pre-wrap break-words font-mono">
103+
<code>{renderJsonWithLinks(code)}</code>
104+
</pre>
92105
);
93106
}
94107

0 commit comments

Comments
 (0)