nofax 0.2.32 → 0.2.33
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/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.33' },
|
|
78
78
|
{ instructions: SERVER_INSTRUCTIONS }
|
|
79
79
|
);
|
|
80
80
|
|
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)) {
|
|
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 });
|