Skip to content

Agent Zero AI framework

enhance README link handling in plugin installer

Alessandroe59cca3008ec
diff --git a/plugins/_plugin_installer/webui/pluginInstallStore.js b/plugins/_plugin_installer/webui/pluginInstallStore.js
index 2929b11c3..cbe9249e7 100644
--- a/plugins/_plugin_installer/webui/pluginInstallStore.js
+++ b/plugins/_plugin_installer/webui/pluginInstallStore.js
@@ -1,5 +1,6 @@
import { createStore } from "/js/AlpineStore.js";
import * as api from "/js/api.js";
+import { addBlankTargetsToLinks } from "/js/messages.js";
import { openModal } from "/js/modals.js";
import { marked } from "/vendor/marked/marked.esm.js";
import { toastFrontendSuccess, toastFrontendError } from "/components/notifications/notification-store.js";
@@ -78,6 +79,52 @@ const model = {
return url.replace("https://github.com/", "https://raw.githubusercontent.com/");
},
+ _rebaseReadmeLinks(html, githubUrl, branch) {
+ if (!html || typeof html !== "string" || !githubUrl || !branch) return html;
+
+ let repoUrl;
+ try {
+ repoUrl = new URL(githubUrl.trim().replace(/\.git$/i, ""));
+ } catch {
+ return html;
+ }
+
+ if (repoUrl.hostname !== "github.com") return html;
+
+ const [owner, repo] = repoUrl.pathname
+ .replace(/^\/+|\/+$/g, "")
+ .split("/");
+ if (!owner || !repo) return html;
+
+ const repoBlobBase = `https://github.com/${owner}/${repo}/blob/${branch}`;
+ const doc = new DOMParser().parseFromString(html, "text/html");
+
+ doc.querySelectorAll("a[href]").forEach((anchor) => {
+ const href = (anchor.getAttribute("href") || "").trim();
+ if (
+ !href ||
+ href.startsWith("#") ||
+ href.startsWith("//") ||
+ /^[a-zA-Z][a-zA-Z\d+.-]*:/.test(href)
+ ) {
+ return;
+ }
+
+ try {
+ const resolved = new URL(href, "https://repo-root.invalid/");
+ const repoPath = resolved.pathname.replace(/^\/+/, "");
+ anchor.setAttribute(
+ "href",
+ `${repoBlobBase}/${repoPath}${resolved.search}${resolved.hash}`,
+ );
+ } catch {
+ // Leave malformed links unchanged.
+ }
+ });
+
+ return doc.body.innerHTML;
+ },
+
_pluginPrimaryTag(plugin) {
const tags = Array.isArray(plugin?.tags) ? plugin.tags.filter(Boolean) : [];
return tags[0] || "";
@@ -474,7 +521,9 @@ const model = {
if (!response.ok) continue;
const readme = await response.text();
- this.readmeContent = marked.parse(readme, { breaks: true });
+ let html = marked.parse(readme, { breaks: true });
+ html = this._rebaseReadmeLinks(html, plugin?.github, branch);
+ this.readmeContent = addBlankTargetsToLinks(html);
return;
} catch (error) {
lastError = error;