@nqminds/mcp-client 1.0.30 → 1.0.31
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 +74 -57
- 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;AAIxE,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;AAIxE,OAAO,KAAK,EAAyB,YAAY,EAAe,MAAM,SAAS,CAAC;AAgchF,wBAAgB,OAAO,CAAC,EACtB,aAAa,EACb,WAA6B,EAC7B,YAAiB,EACjB,SAAc,GACf,EAAE,YAAY,qBA6hBd"}
|
package/dist/MCPChat.js
CHANGED
|
@@ -12,80 +12,97 @@ function stripUtmSource(url) {
|
|
|
12
12
|
.replace(/\?$/, "");
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
* Fixes broken markdown tables
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* Fixes broken markdown tables produced by streaming LLM output.
|
|
16
|
+
*
|
|
17
|
+
* The LLM often emits an entire table (title + header + separator + data rows)
|
|
18
|
+
* as a single line, e.g.:
|
|
19
|
+
* "My title | Col A | Col B | |---|---| | val1 | val2 | | val3 | val4 |"
|
|
20
|
+
*
|
|
21
|
+
* Strategy:
|
|
22
|
+
* 1. Split content into lines.
|
|
23
|
+
* 2. For each line, detect whether a markdown separator pattern
|
|
24
|
+
* (|---|---| etc.) appears *somewhere* but the line is NOT already a
|
|
25
|
+
* standalone separator or a normal single table row.
|
|
26
|
+
* 3. If so, extract any leading title text, then split the remainder into
|
|
27
|
+
* individual pipe-delimited rows by counting pipes.
|
|
28
|
+
* 4. Emit blank + title (if any) + one row per line + blank.
|
|
29
|
+
*
|
|
30
|
+
* Deliberately avoids touching `preprocessLinks` output (markdown links
|
|
31
|
+
* have the form `[text](url)` which contains no `|`, so they are safe).
|
|
18
32
|
*/
|
|
19
33
|
function fixBrokenTables(content) {
|
|
20
|
-
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
const joined = p1 + p2;
|
|
24
|
-
if (/^\|[ :]*-{2,}[ :]*(\|[ :]*-{2,}[ :]*)+\|$/.test(joined.trim()))
|
|
25
|
-
return joined;
|
|
26
|
-
return full;
|
|
27
|
-
});
|
|
28
|
-
// 2) Scan line-by-line for inline separator patterns (= broken table)
|
|
29
|
-
const SEP_RE = /\|[ :]*-{2,}[ :]*(?:\|[ :]*-{2,}[ :]*)+\|/;
|
|
34
|
+
const SEP_CELL = /^[ \t]*:?-{2,}:?[ \t]*$/;
|
|
35
|
+
// Matches a run of pipe-delimited separator cells: |---|---:|:---|
|
|
36
|
+
const SEP_RE = /\|[ \t]*:?-{2,}:?[ \t]*(?:\|[ \t]*:?-{2,}:?[ \t]*)+\|/;
|
|
30
37
|
const lines = content.split("\n");
|
|
31
38
|
const out = [];
|
|
32
|
-
let i = 0;
|
|
33
|
-
while (i < lines.length) {
|
|
39
|
+
for (let i = 0; i < lines.length; i++) {
|
|
34
40
|
const line = lines[i];
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (!sepMatch
|
|
41
|
+
// Find a separator sub-string in this line
|
|
42
|
+
const sepMatch = SEP_RE.exec(line);
|
|
43
|
+
if (!sepMatch) {
|
|
38
44
|
out.push(line);
|
|
39
|
-
i++;
|
|
40
45
|
continue;
|
|
41
46
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const cols =
|
|
45
|
-
if (cols <
|
|
47
|
+
const sepStr = sepMatch[0];
|
|
48
|
+
// Count columns from the separator
|
|
49
|
+
const cols = sepStr.split("|").filter((s) => SEP_CELL.test(s)).length;
|
|
50
|
+
if (cols < 1) {
|
|
46
51
|
out.push(line);
|
|
47
|
-
i++;
|
|
48
52
|
continue;
|
|
49
53
|
}
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (!next || !next.startsWith("|"))
|
|
56
|
-
break;
|
|
57
|
-
raw += " " + next;
|
|
58
|
-
i++;
|
|
54
|
+
// If the line is ONLY the separator (possibly with surrounding whitespace)
|
|
55
|
+
// it's already correct — leave it alone.
|
|
56
|
+
if (line.trim() === sepStr.trim()) {
|
|
57
|
+
out.push(line);
|
|
58
|
+
continue;
|
|
59
59
|
}
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
// There may be a title/description before the first pipe.
|
|
61
|
+
// Everything before the very first "|" in the line is the title.
|
|
62
|
+
const firstPipeIdx = line.indexOf("|");
|
|
63
|
+
const title = firstPipeIdx > 0 ? line.substring(0, firstPipeIdx).trim() : "";
|
|
64
|
+
// Table content is everything from the first "|" onwards.
|
|
65
|
+
const tableText = firstPipeIdx >= 0 ? line.substring(firstPipeIdx) : line;
|
|
66
|
+
// Split into individual cells by pipe, preserving the "|" delimiters.
|
|
67
|
+
// We walk character-by-character and emit a new row every time we have
|
|
68
|
+
// accumulated exactly (cols + 1) pipe characters.
|
|
69
|
+
const rows = [];
|
|
70
|
+
let currentRow = "";
|
|
71
|
+
let pipeCount = 0;
|
|
72
|
+
const perRow = cols + 1; // a N-column row has N+1 pipes
|
|
73
|
+
for (let k = 0; k < tableText.length; k++) {
|
|
74
|
+
const ch = tableText[k];
|
|
75
|
+
currentRow += ch;
|
|
76
|
+
if (ch === "|") {
|
|
77
|
+
pipeCount++;
|
|
78
|
+
if (pipeCount === perRow) {
|
|
79
|
+
rows.push(currentRow.trim());
|
|
80
|
+
currentRow = "";
|
|
81
|
+
pipeCount = 0;
|
|
82
|
+
// Skip any whitespace between rows
|
|
83
|
+
while (k + 1 < tableText.length && tableText[k + 1] === " ")
|
|
84
|
+
k++;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
66
87
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
88
|
+
// Any leftover (incomplete row — happens during streaming)
|
|
89
|
+
if (currentRow.trim())
|
|
90
|
+
rows.push(currentRow.trim());
|
|
91
|
+
// Need at least header + separator to bother reconstructing
|
|
92
|
+
if (rows.length < 2) {
|
|
93
|
+
out.push(line);
|
|
71
94
|
continue;
|
|
72
|
-
} // can't reconstruct
|
|
73
|
-
// Text that precedes the first pipe (e.g. a heading label)
|
|
74
|
-
const prefix = flat.substring(0, pipes[0]).trim();
|
|
75
|
-
if (prefix) {
|
|
76
|
-
out.push(prefix);
|
|
77
|
-
out.push("");
|
|
78
95
|
}
|
|
79
|
-
// Emit each
|
|
80
|
-
|
|
81
|
-
out.push(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const trailing = flat.substring(pipes[fullRows * perRow - 1] + 1).trim();
|
|
85
|
-
if (trailing) {
|
|
96
|
+
// Emit: blank line, optional title, then each row on its own line, blank line
|
|
97
|
+
if (out.length > 0 && out[out.length - 1] !== "")
|
|
98
|
+
out.push("");
|
|
99
|
+
if (title) {
|
|
100
|
+
out.push(title);
|
|
86
101
|
out.push("");
|
|
87
|
-
out.push(trailing);
|
|
88
102
|
}
|
|
103
|
+
for (const row of rows)
|
|
104
|
+
out.push(row);
|
|
105
|
+
out.push("");
|
|
89
106
|
}
|
|
90
107
|
return out.join("\n");
|
|
91
108
|
}
|