nofax 0.2.32 → 0.2.34
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 +5 -1
- package/src/protocol.mjs +4 -3
- package/src/requests.mjs +15 -7
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.34' },
|
|
78
78
|
{ instructions: SERVER_INSTRUCTIONS }
|
|
79
79
|
);
|
|
80
80
|
|
package/src/mcp-tools.mjs
CHANGED
|
@@ -108,7 +108,7 @@ function validateWaitSeconds(value) {
|
|
|
108
108
|
|
|
109
109
|
function validateChoiceOptions(options) {
|
|
110
110
|
if (!Array.isArray(options) || options.length < 1 || options.length > 3) throw new Error('NOFAX_CHOICE_LIMIT');
|
|
111
|
-
|
|
111
|
+
const normalized = options.map((option) => {
|
|
112
112
|
if (typeof option === 'string') {
|
|
113
113
|
const value = option.trim();
|
|
114
114
|
if (!value || value.length > 80) throw new Error('NOFAX_CHOICE_INVALID');
|
|
@@ -120,6 +120,10 @@ function validateChoiceOptions(options) {
|
|
|
120
120
|
if (!value || !label || value.length > 80) throw new Error('NOFAX_CHOICE_INVALID');
|
|
121
121
|
return { value, label: label.slice(0, 32) };
|
|
122
122
|
});
|
|
123
|
+
if (new Set(normalized.map((option) => option.value)).size !== normalized.length) {
|
|
124
|
+
throw new Error('NOFAX_CHOICE_DUPLICATE');
|
|
125
|
+
}
|
|
126
|
+
return normalized;
|
|
123
127
|
}
|
|
124
128
|
|
|
125
129
|
export function createMcpToolHandlers(overrides = {}) {
|
package/src/protocol.mjs
CHANGED
|
@@ -274,9 +274,10 @@ export function parseResponseMessage(message, { requestId, allowed, kind }) {
|
|
|
274
274
|
if (!parsed || parsed.v !== 1 || parsed.requestId !== requestId || typeof parsed.decision !== 'string') {
|
|
275
275
|
return null;
|
|
276
276
|
}
|
|
277
|
-
|
|
277
|
+
const decision = parsed.decision.trim();
|
|
278
|
+
if (!decision || !allowed.includes(decision)) return null;
|
|
278
279
|
|
|
279
|
-
if (
|
|
280
|
+
if (decision === 'refine') {
|
|
280
281
|
if (kind === 'choice') return { decision: 'refine' };
|
|
281
282
|
if (typeof parsed.text !== 'string') return null;
|
|
282
283
|
const text = parsed.text.trim();
|
|
@@ -284,7 +285,7 @@ export function parseResponseMessage(message, { requestId, allowed, kind }) {
|
|
|
284
285
|
return { decision: 'refine', text: text.slice(0, MAX_RESPONSE_TEXT) };
|
|
285
286
|
}
|
|
286
287
|
|
|
287
|
-
return { decision
|
|
288
|
+
return { decision };
|
|
288
289
|
}
|
|
289
290
|
|
|
290
291
|
export function parseDecisionMessage(message, { requestId, allowed, kind }) {
|
package/src/requests.mjs
CHANGED
|
@@ -17,7 +17,11 @@ function validateRequest(input) {
|
|
|
17
17
|
const requestId = validateRequestId(input.requestId);
|
|
18
18
|
if (!KINDS.has(input.kind)) throw new Error('NOFAX_REQUEST_KIND_INVALID');
|
|
19
19
|
if (typeof input.responseTopic !== 'string' || !RESPONSE_TOPIC.test(input.responseTopic)) throw new Error('NOFAX_RESPONSE_TOPIC_INVALID');
|
|
20
|
-
if (!Array.isArray(input.allowed) || input.allowed.length < 1 || input.allowed.length > 3 || input.allowed.some((value) => typeof value !== 'string'
|
|
20
|
+
if (!Array.isArray(input.allowed) || input.allowed.length < 1 || input.allowed.length > 3 || input.allowed.some((value) => typeof value !== 'string')) {
|
|
21
|
+
throw new Error('NOFAX_REQUEST_ALLOWED_INVALID');
|
|
22
|
+
}
|
|
23
|
+
const allowed = input.allowed.map((value) => value.trim());
|
|
24
|
+
if (allowed.some((value) => !value || value.length > 80) || new Set(allowed).size !== allowed.length) {
|
|
21
25
|
throw new Error('NOFAX_REQUEST_ALLOWED_INVALID');
|
|
22
26
|
}
|
|
23
27
|
if (!STATUSES.has(input.status)) throw new Error('NOFAX_REQUEST_STATUS_INVALID');
|
|
@@ -27,18 +31,20 @@ function validateRequest(input) {
|
|
|
27
31
|
requestId,
|
|
28
32
|
kind: input.kind,
|
|
29
33
|
responseTopic: input.responseTopic,
|
|
30
|
-
allowed
|
|
34
|
+
allowed,
|
|
31
35
|
status: input.status,
|
|
32
36
|
createdAt: input.createdAt
|
|
33
37
|
};
|
|
34
38
|
if (input.status === 'resolved') {
|
|
35
39
|
if (typeof input.resolvedAt !== 'string' || Number.isNaN(Date.parse(input.resolvedAt))) throw new Error('NOFAX_REQUEST_RESOLVED_AT_INVALID');
|
|
36
|
-
if (typeof input.decision !== 'string'
|
|
37
|
-
|
|
40
|
+
if (typeof input.decision !== 'string') throw new Error('NOFAX_REQUEST_DECISION_INVALID');
|
|
41
|
+
const decision = input.decision.trim();
|
|
42
|
+
if (!allowed.includes(decision)) throw new Error('NOFAX_REQUEST_DECISION_INVALID');
|
|
43
|
+
if (decision === 'refine' && input.kind !== 'choice' && (typeof input.text !== 'string' || !input.text.trim())) {
|
|
38
44
|
throw new Error('NOFAX_REQUEST_TEXT_INVALID');
|
|
39
45
|
}
|
|
40
46
|
base.resolvedAt = input.resolvedAt;
|
|
41
|
-
base.decision =
|
|
47
|
+
base.decision = decision;
|
|
42
48
|
if (input.text !== undefined) {
|
|
43
49
|
if (typeof input.text !== 'string' || !input.text.trim()) throw new Error('NOFAX_REQUEST_TEXT_INVALID');
|
|
44
50
|
base.text = input.text.trim().slice(0, 2000);
|
|
@@ -120,12 +126,14 @@ export async function loadRequest({ home, env, requestId }) {
|
|
|
120
126
|
export async function resolveRequestWithClaim({ home, env, requestId, response, resolvedAt = new Date().toISOString() }) {
|
|
121
127
|
const current = await loadRequest({ home, env, requestId });
|
|
122
128
|
if (current.status === 'resolved') return { request: current, claimed: false };
|
|
123
|
-
if (!response || typeof response.decision !== 'string'
|
|
129
|
+
if (!response || typeof response.decision !== 'string') throw new Error('NOFAX_REQUEST_DECISION_INVALID');
|
|
130
|
+
const decision = response.decision.trim();
|
|
131
|
+
if (!current.allowed.includes(decision)) throw new Error('NOFAX_REQUEST_DECISION_INVALID');
|
|
124
132
|
const resolved = validateRequest({
|
|
125
133
|
...current,
|
|
126
134
|
status: 'resolved',
|
|
127
135
|
resolvedAt,
|
|
128
|
-
decision
|
|
136
|
+
decision,
|
|
129
137
|
...(response.text === undefined ? {} : { text: response.text })
|
|
130
138
|
});
|
|
131
139
|
const { terminal } = paths({ home, env, requestId });
|