nofax 0.2.33 → 0.2.35
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/mcp-server.mjs +1 -1
- package/src/mcp-tools.mjs +7 -2
- package/src/protocol.mjs +11 -4
- package/src/requests.mjs +10 -2
package/package.json
CHANGED
package/src/mcp-server.mjs
CHANGED
|
@@ -74,7 +74,7 @@ const LIST_PENDING_OUTPUT_SCHEMA = z.object({
|
|
|
74
74
|
|
|
75
75
|
export function buildMcpServer({ handlers = createMcpToolHandlers() } = {}) {
|
|
76
76
|
const server = new McpServer(
|
|
77
|
-
{ name: 'nofax', version: '0.2.
|
|
77
|
+
{ name: 'nofax', version: '0.2.35' },
|
|
78
78
|
{ instructions: SERVER_INSTRUCTIONS }
|
|
79
79
|
);
|
|
80
80
|
|
package/src/mcp-tools.mjs
CHANGED
|
@@ -95,7 +95,8 @@ function publicRequest(request) {
|
|
|
95
95
|
|
|
96
96
|
function validateText(value, name, max = 2200) {
|
|
97
97
|
if (typeof value !== 'string' || !value.trim()) throw new Error(`NOFAX_${name}_REQUIRED`);
|
|
98
|
-
|
|
98
|
+
const text = value.trim();
|
|
99
|
+
return text.length <= max ? text : `${text.slice(0, max - 14)}…[truncated]`;
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
function validateWaitSeconds(value) {
|
|
@@ -108,7 +109,7 @@ function validateWaitSeconds(value) {
|
|
|
108
109
|
|
|
109
110
|
function validateChoiceOptions(options) {
|
|
110
111
|
if (!Array.isArray(options) || options.length < 1 || options.length > 3) throw new Error('NOFAX_CHOICE_LIMIT');
|
|
111
|
-
|
|
112
|
+
const normalized = options.map((option) => {
|
|
112
113
|
if (typeof option === 'string') {
|
|
113
114
|
const value = option.trim();
|
|
114
115
|
if (!value || value.length > 80) throw new Error('NOFAX_CHOICE_INVALID');
|
|
@@ -120,6 +121,10 @@ function validateChoiceOptions(options) {
|
|
|
120
121
|
if (!value || !label || value.length > 80) throw new Error('NOFAX_CHOICE_INVALID');
|
|
121
122
|
return { value, label: label.slice(0, 32) };
|
|
122
123
|
});
|
|
124
|
+
if (new Set(normalized.map((option) => option.value)).size !== normalized.length) {
|
|
125
|
+
throw new Error('NOFAX_CHOICE_DUPLICATE');
|
|
126
|
+
}
|
|
127
|
+
return normalized;
|
|
123
128
|
}
|
|
124
129
|
|
|
125
130
|
export function createMcpToolHandlers(overrides = {}) {
|
package/src/protocol.mjs
CHANGED
|
@@ -7,6 +7,7 @@ const MAX_ARRAY = 20;
|
|
|
7
7
|
const MAX_OBJECT_KEYS = 30;
|
|
8
8
|
const MAX_SUMMARY = 2200;
|
|
9
9
|
const MAX_RESPONSE_TEXT = 2000;
|
|
10
|
+
const TRUNCATION_MARKER = '…[truncated]';
|
|
10
11
|
|
|
11
12
|
function normalizeSecretKeyName(key) {
|
|
12
13
|
let normalized = '';
|
|
@@ -175,6 +176,11 @@ function randomBase64Url(bytes) {
|
|
|
175
176
|
return randomBytes(bytes).toString('base64url');
|
|
176
177
|
}
|
|
177
178
|
|
|
179
|
+
function boundResponseText(value) {
|
|
180
|
+
if (value.length <= MAX_RESPONSE_TEXT) return value;
|
|
181
|
+
return `${value.slice(0, MAX_RESPONSE_TEXT - TRUNCATION_MARKER.length)}${TRUNCATION_MARKER}`;
|
|
182
|
+
}
|
|
183
|
+
|
|
178
184
|
export function createRequestId() {
|
|
179
185
|
return `nfx_${randomBase64Url(18)}`;
|
|
180
186
|
}
|
|
@@ -274,17 +280,18 @@ export function parseResponseMessage(message, { requestId, allowed, kind }) {
|
|
|
274
280
|
if (!parsed || parsed.v !== 1 || parsed.requestId !== requestId || typeof parsed.decision !== 'string') {
|
|
275
281
|
return null;
|
|
276
282
|
}
|
|
277
|
-
|
|
283
|
+
const decision = parsed.decision.trim();
|
|
284
|
+
if (!decision || !allowed.includes(decision)) return null;
|
|
278
285
|
|
|
279
|
-
if (
|
|
286
|
+
if (decision === 'refine') {
|
|
280
287
|
if (kind === 'choice') return { decision: 'refine' };
|
|
281
288
|
if (typeof parsed.text !== 'string') return null;
|
|
282
289
|
const text = parsed.text.trim();
|
|
283
290
|
if (!text) return null;
|
|
284
|
-
return { decision: 'refine', text: text
|
|
291
|
+
return { decision: 'refine', text: boundResponseText(text) };
|
|
285
292
|
}
|
|
286
293
|
|
|
287
|
-
return { decision
|
|
294
|
+
return { decision };
|
|
288
295
|
}
|
|
289
296
|
|
|
290
297
|
export function parseDecisionMessage(message, { requestId, allowed, kind }) {
|
package/src/requests.mjs
CHANGED
|
@@ -6,12 +6,20 @@ const REQUEST_ID = /^nfx_[A-Za-z0-9_-]{20,80}$/;
|
|
|
6
6
|
const RESPONSE_TOPIC = /^nofax_r_[A-Za-z0-9_-]{20,120}$/;
|
|
7
7
|
const KINDS = new Set(['approval', 'choice', 'refinement']);
|
|
8
8
|
const STATUSES = new Set(['pending', 'resolved']);
|
|
9
|
+
const MAX_RESPONSE_TEXT = 2000;
|
|
10
|
+
const TRUNCATION_MARKER = '…[truncated]';
|
|
9
11
|
|
|
10
12
|
function validateRequestId(value) {
|
|
11
13
|
if (typeof value !== 'string' || !REQUEST_ID.test(value)) throw new Error('NOFAX_REQUEST_ID_INVALID');
|
|
12
14
|
return value;
|
|
13
15
|
}
|
|
14
16
|
|
|
17
|
+
function boundResponseText(value) {
|
|
18
|
+
const text = value.trim();
|
|
19
|
+
if (text.length <= MAX_RESPONSE_TEXT) return text;
|
|
20
|
+
return `${text.slice(0, MAX_RESPONSE_TEXT - TRUNCATION_MARKER.length)}${TRUNCATION_MARKER}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
15
23
|
function validateRequest(input) {
|
|
16
24
|
if (!input || input.version !== 1) throw new Error('NOFAX_REQUEST_VERSION');
|
|
17
25
|
const requestId = validateRequestId(input.requestId);
|
|
@@ -21,7 +29,7 @@ function validateRequest(input) {
|
|
|
21
29
|
throw new Error('NOFAX_REQUEST_ALLOWED_INVALID');
|
|
22
30
|
}
|
|
23
31
|
const allowed = input.allowed.map((value) => value.trim());
|
|
24
|
-
if (allowed.some((value) => !value || value.length > 80)) {
|
|
32
|
+
if (allowed.some((value) => !value || value.length > 80) || new Set(allowed).size !== allowed.length) {
|
|
25
33
|
throw new Error('NOFAX_REQUEST_ALLOWED_INVALID');
|
|
26
34
|
}
|
|
27
35
|
if (!STATUSES.has(input.status)) throw new Error('NOFAX_REQUEST_STATUS_INVALID');
|
|
@@ -47,7 +55,7 @@ function validateRequest(input) {
|
|
|
47
55
|
base.decision = decision;
|
|
48
56
|
if (input.text !== undefined) {
|
|
49
57
|
if (typeof input.text !== 'string' || !input.text.trim()) throw new Error('NOFAX_REQUEST_TEXT_INVALID');
|
|
50
|
-
base.text = input.text
|
|
58
|
+
base.text = boundResponseText(input.text);
|
|
51
59
|
}
|
|
52
60
|
}
|
|
53
61
|
return base;
|