greenline-works-mcp-server 0.3.2 → 0.3.3
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/package.json +1 -1
- package/src/constants.js +1 -1
- package/src/markdown.js +134 -0
- package/src/tools/cards.js +1 -1
- package/src/tools/comments.js +1 -1
- package/src/tools/tasks.js +1 -1
- package/src/markdown-delta.js +0 -94
package/package.json
CHANGED
package/src/constants.js
CHANGED
package/src/markdown.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// Converts the markdown LLM clients naturally produce into the HTML the API accepts.
|
|
2
|
+
//
|
|
3
|
+
// The public API takes rich text as an HTML string — POST /comments, POST /tasks and the
|
|
4
|
+
// checklist tasks[] all validate `required|string` on it — so markdown must become HTML here
|
|
5
|
+
// rather than a delta. The server converts that HTML to its stored delta (utils/quill.js),
|
|
6
|
+
// which preserves inline <code> and multi-line <pre> as of 8.8.0.
|
|
7
|
+
//
|
|
8
|
+
// Input that already contains HTML is returned untouched, so a client following the documented
|
|
9
|
+
// format is never double-converted.
|
|
10
|
+
|
|
11
|
+
const SUPPORTED_TAG = /<(?:p|br|strong|em|u|s|a|ul|ol|li|h[1-3]|blockquote|pre|code)\b[^>]*>/i;
|
|
12
|
+
const containsHtml = text => SUPPORTED_TAG.test(text);
|
|
13
|
+
|
|
14
|
+
const escapeHtml = text => text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
15
|
+
|
|
16
|
+
const renderMarkers = text =>
|
|
17
|
+
text
|
|
18
|
+
.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
|
|
19
|
+
.replace(/__([^_]+)__/g, '<strong>$1</strong>')
|
|
20
|
+
.replace(/(^|[^*])\*([^*\s][^*]*)\*/g, '$1<em>$2</em>')
|
|
21
|
+
.replace(/(^|[^_])_([^_\s][^_]*)_/g, '$1<em>$2</em>')
|
|
22
|
+
.replace(/~~([^~]+)~~/g, '<s>$1</s>')
|
|
23
|
+
.replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g, '<a href="$2">$1</a>');
|
|
24
|
+
|
|
25
|
+
// Code spans are split out before the other markers so they cannot mangle their contents —
|
|
26
|
+
// `run_a_test` is a name, not italics.
|
|
27
|
+
const renderInline = text =>
|
|
28
|
+
escapeHtml(text)
|
|
29
|
+
.split(/(`[^`]+`)/)
|
|
30
|
+
.map(part =>
|
|
31
|
+
part.length > 2 && part.startsWith('`') && part.endsWith('`')
|
|
32
|
+
? `<code>${part.slice(1, -1)}</code>`
|
|
33
|
+
: renderMarkers(part)
|
|
34
|
+
)
|
|
35
|
+
.join('');
|
|
36
|
+
|
|
37
|
+
const UNORDERED = /^(\s*)[-*+]\s+(.*)$/;
|
|
38
|
+
const ORDERED = /^(\s*)\d+[.)]\s+(.*)$/;
|
|
39
|
+
const HEADING = /^(#{1,3})\s+(.*)$/;
|
|
40
|
+
const QUOTE = /^>\s?(.*)$/;
|
|
41
|
+
const FENCE = /^\s*```/;
|
|
42
|
+
|
|
43
|
+
const markdownToHtml = value => {
|
|
44
|
+
if (typeof value !== 'string' || !value.trim()) return value;
|
|
45
|
+
if (containsHtml(value)) return value;
|
|
46
|
+
|
|
47
|
+
const lines = value.replace(/\r\n/g, '\n').split('\n');
|
|
48
|
+
const out = [];
|
|
49
|
+
let list = null;
|
|
50
|
+
let paragraph = [];
|
|
51
|
+
let fenced = false;
|
|
52
|
+
let fence = [];
|
|
53
|
+
|
|
54
|
+
const closeList = () => {
|
|
55
|
+
if (list) {
|
|
56
|
+
out.push(`</${list}>`);
|
|
57
|
+
list = null;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const closeParagraph = () => {
|
|
61
|
+
if (paragraph.length) {
|
|
62
|
+
out.push(`<p>${renderInline(paragraph.join(' '))}</p>`);
|
|
63
|
+
paragraph = [];
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const closeFence = () => {
|
|
67
|
+
out.push(`<pre>${fence.map(escapeHtml).join('\n')}</pre>`);
|
|
68
|
+
fence = [];
|
|
69
|
+
};
|
|
70
|
+
const openList = kind => {
|
|
71
|
+
if (list !== kind) {
|
|
72
|
+
closeList();
|
|
73
|
+
out.push(`<${kind}>`);
|
|
74
|
+
list = kind;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
for (const line of lines) {
|
|
79
|
+
if (FENCE.test(line)) {
|
|
80
|
+
closeParagraph();
|
|
81
|
+
closeList();
|
|
82
|
+
if (fenced) closeFence();
|
|
83
|
+
fenced = !fenced;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (fenced) {
|
|
87
|
+
fence.push(line);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (!line.trim()) {
|
|
91
|
+
closeParagraph();
|
|
92
|
+
closeList();
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const heading = line.match(HEADING);
|
|
97
|
+
if (heading) {
|
|
98
|
+
closeParagraph();
|
|
99
|
+
closeList();
|
|
100
|
+
out.push(`<h${heading[1].length}>${renderInline(heading[2])}</h${heading[1].length}>`);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const quote = line.match(QUOTE);
|
|
105
|
+
if (quote) {
|
|
106
|
+
closeParagraph();
|
|
107
|
+
closeList();
|
|
108
|
+
out.push(`<blockquote>${renderInline(quote[1])}</blockquote>`);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const unordered = line.match(UNORDERED);
|
|
113
|
+
const ordered = unordered ? null : line.match(ORDERED);
|
|
114
|
+
if (unordered || ordered) {
|
|
115
|
+
closeParagraph();
|
|
116
|
+
openList(unordered ? 'ul' : 'ol');
|
|
117
|
+
out.push(`<li>${renderInline((unordered || ordered)[2])}</li>`);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
paragraph.push(line.trim());
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
closeParagraph();
|
|
125
|
+
closeList();
|
|
126
|
+
// An unterminated fence still carries its lines.
|
|
127
|
+
if (fenced && fence.length) closeFence();
|
|
128
|
+
return out.join('');
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// Every rich-text field on the API is an HTML string; markdown is converted, HTML passes through.
|
|
132
|
+
const richTextBody = (field, value) => ({ [field]: markdownToHtml(value) });
|
|
133
|
+
|
|
134
|
+
module.exports = { markdownToHtml, richTextBody, containsHtml };
|
package/src/tools/cards.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { z } = require('zod');
|
|
2
2
|
const { makeApiRequest, safeRun } = require('../client');
|
|
3
3
|
const { responseFormatField, ResponseFormat, toJsonString, truncateIfNeeded, RICH_TEXT_HELP } = require('../format');
|
|
4
|
-
const { richTextBody } = require('../markdown
|
|
4
|
+
const { richTextBody } = require('../markdown');
|
|
5
5
|
const { objectIdField, boardPublicIdField, pageField, countField, isoDateField } = require('../schemas');
|
|
6
6
|
|
|
7
7
|
const READ = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true };
|
package/src/tools/comments.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { z } = require('zod');
|
|
2
2
|
const { makeApiRequest, safeRun } = require('../client');
|
|
3
3
|
const { responseFormatField, ResponseFormat, toJsonString, truncateIfNeeded, RICH_TEXT_HELP } = require('../format');
|
|
4
|
-
const { richTextBody } = require('../markdown
|
|
4
|
+
const { richTextBody } = require('../markdown');
|
|
5
5
|
const { objectIdField } = require('../schemas');
|
|
6
6
|
|
|
7
7
|
const READ = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true };
|
package/src/tools/tasks.js
CHANGED
|
@@ -2,7 +2,7 @@ const { z } = require('zod');
|
|
|
2
2
|
const { makeApiRequest, safeRun } = require('../client');
|
|
3
3
|
const { isoDateField, objectIdField } = require('../schemas');
|
|
4
4
|
const { RICH_TEXT_HELP } = require('../format');
|
|
5
|
-
const { richTextBody } = require('../markdown
|
|
5
|
+
const { richTextBody } = require('../markdown');
|
|
6
6
|
|
|
7
7
|
const WRITE = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true };
|
|
8
8
|
const IDEMPOTENT_WRITE = { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true };
|
package/src/markdown-delta.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
// Converts the markdown LLM clients naturally produce into a Quill Delta, so the API receives the
|
|
2
|
-
// stored format directly. Inline: `code`, **bold**, __bold__, *em*, _em_, ~~strike~~, [text](url).
|
|
3
|
-
// Blocks: #-### headings, -/*/+ and 1. lists (2-space nesting -> indent), > quotes, ``` fences ->
|
|
4
|
-
// code-block lines, blank-line paragraph breaks. Input that already contains HTML is passed through
|
|
5
|
-
// in the plain field for the server to convert (richTextBody).
|
|
6
|
-
|
|
7
|
-
const SUPPORTED_TAG = /<(?:p|br|strong|em|u|s|a|ul|ol|li|h[1-3]|blockquote|pre|code)\b[^>]*>/i;
|
|
8
|
-
const containsHtml = text => SUPPORTED_TAG.test(text);
|
|
9
|
-
|
|
10
|
-
const INLINE_TOKEN =
|
|
11
|
-
/(`[^`]+`)|(\*\*[^*]+?\*\*)|(__[^_]+?__)|(~~[^~]+?~~)|(\[([^\]]+)\]\((https?:\/\/[^)\s]+)\))|((?<![\w*])\*[^*\s][^*]*?\*(?![\w*]))|((?<![\w_])_[^_\s][^_]*?_(?![\w_]))/;
|
|
12
|
-
|
|
13
|
-
const runsFromText = text => {
|
|
14
|
-
const runs = [];
|
|
15
|
-
let rest = text;
|
|
16
|
-
while (rest) {
|
|
17
|
-
const match = rest.match(INLINE_TOKEN);
|
|
18
|
-
if (!match) {
|
|
19
|
-
runs.push({ insert: rest });
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
if (match.index > 0) runs.push({ insert: rest.slice(0, match.index) });
|
|
23
|
-
const token = match[0];
|
|
24
|
-
if (match[1]) runs.push({ insert: token.slice(1, -1), attributes: { code: true } });
|
|
25
|
-
else if (match[2] || match[3]) runs.push({ insert: token.slice(2, -2), attributes: { bold: true } });
|
|
26
|
-
else if (match[4]) runs.push({ insert: token.slice(2, -2), attributes: { strike: true } });
|
|
27
|
-
else if (match[5]) runs.push({ insert: match[6], attributes: { link: match[7] } });
|
|
28
|
-
else runs.push({ insert: token.slice(1, -1), attributes: { italic: true } });
|
|
29
|
-
rest = rest.slice(match.index + token.length);
|
|
30
|
-
}
|
|
31
|
-
return runs;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const markdownToDelta = markdown => {
|
|
35
|
-
const ops = [];
|
|
36
|
-
const lines = String(markdown).replace(/\r\n/g, '\n').split('\n');
|
|
37
|
-
let paragraph = [];
|
|
38
|
-
let fenced = false;
|
|
39
|
-
|
|
40
|
-
const flushParagraph = () => {
|
|
41
|
-
if (!paragraph.length) return;
|
|
42
|
-
ops.push(...runsFromText(paragraph.join(' ')), { insert: '\n' });
|
|
43
|
-
paragraph = [];
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
for (const line of lines) {
|
|
47
|
-
if (/^\s*```/.test(line)) {
|
|
48
|
-
flushParagraph();
|
|
49
|
-
fenced = !fenced;
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
if (fenced) {
|
|
53
|
-
if (line) ops.push({ insert: line });
|
|
54
|
-
ops.push({ insert: '\n', attributes: { 'code-block': true } });
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
if (!line.trim()) {
|
|
58
|
-
flushParagraph();
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
const heading = line.match(/^(#{1,3})\s+(.*)$/);
|
|
62
|
-
if (heading) {
|
|
63
|
-
flushParagraph();
|
|
64
|
-
ops.push(...runsFromText(heading[2]), { insert: '\n', attributes: { header: heading[1].length } });
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
const quote = line.match(/^>\s?(.*)$/);
|
|
68
|
-
if (quote) {
|
|
69
|
-
flushParagraph();
|
|
70
|
-
ops.push(...runsFromText(quote[1]), { insert: '\n', attributes: { blockquote: true } });
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
const unordered = line.match(/^(\s*)[-*+]\s+(.*)$/);
|
|
74
|
-
const ordered = unordered ? null : line.match(/^(\s*)\d+[.)]\s+(.*)$/);
|
|
75
|
-
if (unordered || ordered) {
|
|
76
|
-
flushParagraph();
|
|
77
|
-
const [, lead, text] = unordered || ordered;
|
|
78
|
-
const attributes = { list: unordered ? 'bullet' : 'ordered' };
|
|
79
|
-
const indent = Math.min(Math.floor(lead.length / 2), 8);
|
|
80
|
-
if (indent) attributes.indent = indent;
|
|
81
|
-
ops.push(...runsFromText(text), { insert: '\n', attributes });
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
paragraph.push(line.trim());
|
|
85
|
-
}
|
|
86
|
-
flushParagraph();
|
|
87
|
-
return ops.length ? { ops } : { ops: [{ insert: '\n' }] };
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
// HTML goes through unchanged for the server to convert; anything else is markdown.
|
|
91
|
-
const richTextBody = (field, value) =>
|
|
92
|
-
containsHtml(value) ? { [field]: value } : { [`${field}Delta`]: markdownToDelta(value) };
|
|
93
|
-
|
|
94
|
-
module.exports = { markdownToDelta, richTextBody, containsHtml };
|