@nqminds/mcp-client 1.0.27 → 1.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/MCPChat.d.ts.map +1 -1
- package/dist/MCPChat.js +26 -1
- package/package.json +1 -1
package/dist/MCPChat.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MCPChat.d.ts","sourceRoot":"","sources":["../src/MCPChat.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAmD,MAAM,OAAO,CAAC;AAGxE,OAAO,KAAK,EAAyB,YAAY,EAAe,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"MCPChat.d.ts","sourceRoot":"","sources":["../src/MCPChat.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAmD,MAAM,OAAO,CAAC;AAGxE,OAAO,KAAK,EAAyB,YAAY,EAAe,MAAM,SAAS,CAAC;AA0MhF,wBAAgB,OAAO,CAAC,EACtB,aAAa,EACb,WAA6B,EAC7B,YAAiB,EACjB,SAAc,GACf,EAAE,YAAY,qBAshBd"}
|
package/dist/MCPChat.js
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
import React, { useState, useRef, useEffect, useCallback } from "react";
|
|
3
3
|
import ReactMarkdown from "react-markdown";
|
|
4
4
|
import remarkGfm from "remark-gfm";
|
|
5
|
+
/**
|
|
6
|
+
* Strips utm_source=openai (and any surrounding & or ?) from a URL.
|
|
7
|
+
*/
|
|
8
|
+
function stripUtmSource(url) {
|
|
9
|
+
return url
|
|
10
|
+
.replace(/[?&]utm_source=openai/gi, (match) => (match.startsWith("?") ? "?" : ""))
|
|
11
|
+
.replace(/\?$/, "");
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Post-processes AI response content to ensure all links open in a new tab
|
|
15
|
+
* and have tracking parameters removed.
|
|
16
|
+
* Converts HTML anchor tags (<a href="...">) into markdown links ([text](url))
|
|
17
|
+
* so they are handled by the ReactMarkdown custom 'a' component which adds
|
|
18
|
+
* target="_blank" rel="noopener noreferrer". This also prevents raw HTML
|
|
19
|
+
* anchor tags from breaking markdown tables.
|
|
20
|
+
*/
|
|
21
|
+
function preprocessLinks(content) {
|
|
22
|
+
// Convert HTML anchors to markdown links (stripping utm params)
|
|
23
|
+
const step1 = content.replace(/<a\s[^>]*?href="([^"]*)"[^>]*>([\s\S]*?)<\/a>/gi, (_, href, innerHtml) => {
|
|
24
|
+
const linkText = innerHtml.replace(/<[^>]+>/g, "").trim();
|
|
25
|
+
return `[${linkText || href}](${stripUtmSource(href)})`;
|
|
26
|
+
});
|
|
27
|
+
// Strip utm params from plain markdown links [text](url)
|
|
28
|
+
return step1.replace(/\[([^\]]*)\]\(([^)]*)\)/g, (_, text, url) => `[${text}](${stripUtmSource(url)})`);
|
|
29
|
+
}
|
|
5
30
|
const DEFAULT_ACTIONS = [
|
|
6
31
|
{
|
|
7
32
|
label: "Company overview",
|
|
@@ -466,7 +491,7 @@ export function MCPChat({ companyNumber, apiEndpoint = "/api/mcp/chat", customSt
|
|
|
466
491
|
msg.role === "assistant" ? (React.createElement("div", { className: "mcp-chat-message-content markdown-content" },
|
|
467
492
|
React.createElement(ReactMarkdown, { remarkPlugins: [remarkGfm], components: {
|
|
468
493
|
a: ({ href, children }) => (React.createElement("a", { href: href, target: "_blank", rel: "noopener noreferrer" }, children)),
|
|
469
|
-
} }, msg.content))) : (React.createElement("div", { className: "mcp-chat-message-content" }, msg.content)),
|
|
494
|
+
} }, preprocessLinks(msg.content)))) : (React.createElement("div", { className: "mcp-chat-message-content" }, msg.content)),
|
|
470
495
|
msg.role === "assistant" && !msg.isStreaming && (React.createElement("div", { className: "mcp-chat-message-timestamp" },
|
|
471
496
|
msg.timestamp.toLocaleTimeString(),
|
|
472
497
|
msg.tokenInfo && (React.createElement("span", { className: "mcp-chat-token-info" }, msg.tokenInfo)))))))),
|