nofax 0.2.34 → 0.2.36
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 +9 -1
- package/src/ntfy.mjs +8 -1
- package/src/protocol.mjs +21 -5
- package/src/requests.mjs +15 -1
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.36' },
|
|
78
78
|
{ instructions: SERVER_INSTRUCTIONS }
|
|
79
79
|
);
|
|
80
80
|
|
package/src/mcp-tools.mjs
CHANGED
|
@@ -93,9 +93,17 @@ function publicRequest(request) {
|
|
|
93
93
|
return result;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
function safeSliceEnd(text, end) {
|
|
97
|
+
const previous = text.charCodeAt(end - 1);
|
|
98
|
+
return previous >= 0xD800 && previous <= 0xDBFF ? end - 1 : end;
|
|
99
|
+
}
|
|
100
|
+
|
|
96
101
|
function validateText(value, name, max = 2200) {
|
|
97
102
|
if (typeof value !== 'string' || !value.trim()) throw new Error(`NOFAX_${name}_REQUIRED`);
|
|
98
|
-
|
|
103
|
+
const text = value.trim();
|
|
104
|
+
if (text.length <= max) return text;
|
|
105
|
+
const end = safeSliceEnd(text, max - 14);
|
|
106
|
+
return `${text.slice(0, end)}…[truncated]`;
|
|
99
107
|
}
|
|
100
108
|
|
|
101
109
|
function validateWaitSeconds(value) {
|
package/src/ntfy.mjs
CHANGED
|
@@ -4,10 +4,17 @@ const MAX_TITLE = 120;
|
|
|
4
4
|
const MAX_MESSAGE = 2200;
|
|
5
5
|
const DEFAULT_REFINE_SHORTCUT = 'Nofax Refine';
|
|
6
6
|
|
|
7
|
+
function safeSliceEnd(text, end) {
|
|
8
|
+
const previous = text.charCodeAt(end - 1);
|
|
9
|
+
return previous >= 0xD800 && previous <= 0xDBFF ? end - 1 : end;
|
|
10
|
+
}
|
|
11
|
+
|
|
7
12
|
function boundText(value, max, name) {
|
|
8
13
|
if (typeof value !== 'string' || value.trim().length === 0) throw new Error(`NOFAX_${name}_REQUIRED`);
|
|
9
14
|
const text = value.trim();
|
|
10
|
-
|
|
15
|
+
if (text.length <= max) return text;
|
|
16
|
+
const end = safeSliceEnd(text, max - 14);
|
|
17
|
+
return `${text.slice(0, end)}…[truncated]`;
|
|
11
18
|
}
|
|
12
19
|
|
|
13
20
|
function sleep(ms) {
|
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,17 @@ function randomBase64Url(bytes) {
|
|
|
175
176
|
return randomBytes(bytes).toString('base64url');
|
|
176
177
|
}
|
|
177
178
|
|
|
179
|
+
function safeSliceEnd(text, end) {
|
|
180
|
+
const previous = text.charCodeAt(end - 1);
|
|
181
|
+
return previous >= 0xD800 && previous <= 0xDBFF ? end - 1 : end;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function boundResponseText(value) {
|
|
185
|
+
if (value.length <= MAX_RESPONSE_TEXT) return value;
|
|
186
|
+
const end = safeSliceEnd(value, MAX_RESPONSE_TEXT - TRUNCATION_MARKER.length);
|
|
187
|
+
return `${value.slice(0, end)}${TRUNCATION_MARKER}`;
|
|
188
|
+
}
|
|
189
|
+
|
|
178
190
|
export function createRequestId() {
|
|
179
191
|
return `nfx_${randomBase64Url(18)}`;
|
|
180
192
|
}
|
|
@@ -189,8 +201,10 @@ export function createPhoneTopic() {
|
|
|
189
201
|
|
|
190
202
|
function boundString(value) {
|
|
191
203
|
const redacted = redactSecretText(value);
|
|
192
|
-
const bounded = redacted.length <= MAX_STRING
|
|
193
|
-
|
|
204
|
+
const bounded = redacted.length <= MAX_STRING
|
|
205
|
+
? redacted
|
|
206
|
+
: redacted.slice(0, safeSliceEnd(redacted, MAX_STRING));
|
|
207
|
+
return value.length <= MAX_STRING ? bounded : `${bounded}${TRUNCATION_MARKER}`;
|
|
194
208
|
}
|
|
195
209
|
|
|
196
210
|
export function redactAndBound(value, options = {}) {
|
|
@@ -248,7 +262,8 @@ function serializeBounded(value) {
|
|
|
248
262
|
serialized = '[unserializable]';
|
|
249
263
|
}
|
|
250
264
|
if (serialized.length <= 1400) return serialized;
|
|
251
|
-
|
|
265
|
+
const end = safeSliceEnd(serialized, 1400);
|
|
266
|
+
return `${serialized.slice(0, end)}\n${TRUNCATION_MARKER}`;
|
|
252
267
|
}
|
|
253
268
|
|
|
254
269
|
export function buildAgentSummary({ source, toolName, cwd, toolInput, message }) {
|
|
@@ -260,7 +275,8 @@ export function buildAgentSummary({ source, toolName, cwd, toolInput, message })
|
|
|
260
275
|
if (toolInput !== undefined) lines.push('', 'Request:', serializeBounded(toolInput));
|
|
261
276
|
const result = lines.join('\n').trim();
|
|
262
277
|
if (result.length <= MAX_SUMMARY) return result;
|
|
263
|
-
|
|
278
|
+
const end = safeSliceEnd(result, MAX_SUMMARY - 14);
|
|
279
|
+
return `${result.slice(0, end)}\n${TRUNCATION_MARKER}`;
|
|
264
280
|
}
|
|
265
281
|
|
|
266
282
|
export function parseResponseMessage(message, { requestId, allowed, kind }) {
|
|
@@ -282,7 +298,7 @@ export function parseResponseMessage(message, { requestId, allowed, kind }) {
|
|
|
282
298
|
if (typeof parsed.text !== 'string') return null;
|
|
283
299
|
const text = parsed.text.trim();
|
|
284
300
|
if (!text) return null;
|
|
285
|
-
return { decision: 'refine', text: text
|
|
301
|
+
return { decision: 'refine', text: boundResponseText(text) };
|
|
286
302
|
}
|
|
287
303
|
|
|
288
304
|
return { decision };
|
package/src/requests.mjs
CHANGED
|
@@ -6,12 +6,26 @@ 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 safeSliceEnd(text, end) {
|
|
18
|
+
const previous = text.charCodeAt(end - 1);
|
|
19
|
+
return previous >= 0xD800 && previous <= 0xDBFF ? end - 1 : end;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function boundResponseText(value) {
|
|
23
|
+
const text = value.trim();
|
|
24
|
+
if (text.length <= MAX_RESPONSE_TEXT) return text;
|
|
25
|
+
const end = safeSliceEnd(text, MAX_RESPONSE_TEXT - TRUNCATION_MARKER.length);
|
|
26
|
+
return `${text.slice(0, end)}${TRUNCATION_MARKER}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
15
29
|
function validateRequest(input) {
|
|
16
30
|
if (!input || input.version !== 1) throw new Error('NOFAX_REQUEST_VERSION');
|
|
17
31
|
const requestId = validateRequestId(input.requestId);
|
|
@@ -47,7 +61,7 @@ function validateRequest(input) {
|
|
|
47
61
|
base.decision = decision;
|
|
48
62
|
if (input.text !== undefined) {
|
|
49
63
|
if (typeof input.text !== 'string' || !input.text.trim()) throw new Error('NOFAX_REQUEST_TEXT_INVALID');
|
|
50
|
-
base.text = input.text
|
|
64
|
+
base.text = boundResponseText(input.text);
|
|
51
65
|
}
|
|
52
66
|
}
|
|
53
67
|
return base;
|