Repository navigation
feat(frontend): open agent chat links in a new tab - #9426
Conversation
Links in a rendered agent chat message that resolve to an http or https address now get target="_blank" and rel="noopener noreferrer", and links with another scheme such as mailto are unchanged.
Automated Reviewer SuggestionsBased on the
|
bobbai00
left a comment
There was a problem hiding this comment.
🟢 0 must-fix · 0 advisory · 0 polish: no findings. The links get their new-tab marks on every render, and the specs run the real markdown pipeline.
Verification trace
Traced against ngx-markdown 21.2.0 and Angular 21.2: MarkdownComponent.render() writes the sanitized HTML and only then emits ready, on every entry point (data change, src, transclusion, reload), so each render is handled, streamed updates included. Angular's sanitizer keeps target and rel, so a raw rel="opener" reaches the handler and is replaced, which is what the replacement spec checks. isWebLink resolves against document.baseURI, the same base the browser uses for the click under <base href="/">.
What changes were proposed in this PR?
A link in an agent chat message opened in the workflow tab, so one click replaced the editor with the linked page. The chat renders each message with
<markdown>, and the rendered<a>had notarget.Links in a chat message now open in a new tab.
agent-chat.component.htmlbinds thereadyoutput of the message's<markdown>to a newopenLinksInNewTabhandler.readyfires after every render, so a message that is rendered again with new text is handled again.target="_blank"andrel="noopener noreferrer"on every link that resolves to an http or https address. That covers links to other sites, bare URLs that markdown turns into links, and also anchors, links without a protocol, absolute paths and full links to the app. A rendered link is not a router link and the app has<base href="/">, so each of those would load another page of the app in the editor's tab (#summaryresolves to the app root).mailto:, and links whose address cannot be parsed are left as they were.targetorrelthe link already carried is replaced, so a message cannot keeprel="opener".The change is local to chat messages. The other markdown views (the Form View instructions, the dataset file preview, the dataset, model and hub workflow descriptions, and the system prompt tab of the agent's info dialog) render links the same way and are not changed here. They are a possible follow-up.
Before (
main). The agent's answer holds a link to a documentation page. Clicking it loads the documentation in the same tab, so the editor and the conversation are gone.After (this PR). The same click on the same conversation opens the documentation in a second tab. The editor's tab stays as it was.
Any related issues, documentation, discussions?
Closes #9422.
How was this PR tested?
cd frontend && NODE_OPTIONS="--no-experimental-webstorage" npx ng test --watch=false --include src/app/workspace/component/agent/agent-panel/agent-chat/agent-chat.component.spec.ts: 67 passed (52 before this PR). The 15 new tests render real messages through<markdown>and read the resulting links.rel="noopener noreferrer".mailto:link, ajavascript:link (which Angular has already rewritten tounsafe:javascript:) and a link whose address cannot be parsed are untouched.targetandrelalready on a link are replaced.mailto:link loses the new-tab marks.Also
agent-panel.component.spec.ts(49 passed), which renders the chat inside the panel,npx prettier --checkandnpx eslinton the three touched files, andnpx tsc --noEmit -p src/tsconfig.app.json. Four mutants were each caught by a test: an unparsable address treated as a link, every scheme treated as a web link, a link with an empty address skipped, andrelextended instead of replaced.Live check on a local stack with the frontend served from this branch. One typed message held an anchor link, an absolute path, a
mailto:link and a barehttp://localhost:8080URL, and the agent's answer held a link to a documentation page. In the rendered chat every link except themailto:one hadtarget="_blank"andrel="noopener noreferrer". Clicking the anchor link left the workflow editor and the conversation in place, where before the same click loaded the app root in the editor's tab.Was this PR authored or co-authored using generative AI tooling?
Yes. Generated-by: Claude Code (claude-fable-5-2). Co-authored with Claude; the author reviewed the change before submission.