nofax 0.2.36 → 0.2.37
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 +11 -4
- package/src/ntfy.mjs +1 -0
- package/src/requests.mjs +12 -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.37' },
|
|
78
78
|
{ instructions: SERVER_INSTRUCTIONS }
|
|
79
79
|
);
|
|
80
80
|
|
package/src/mcp-tools.mjs
CHANGED
|
@@ -131,6 +131,9 @@ function validateChoiceOptions(options) {
|
|
|
131
131
|
if (new Set(normalized.map((option) => option.value)).size !== normalized.length) {
|
|
132
132
|
throw new Error('NOFAX_CHOICE_DUPLICATE');
|
|
133
133
|
}
|
|
134
|
+
if (new Set(normalized.map((option) => option.label)).size !== normalized.length) {
|
|
135
|
+
throw new Error('NOFAX_CHOICE_DUPLICATE');
|
|
136
|
+
}
|
|
134
137
|
return normalized;
|
|
135
138
|
}
|
|
136
139
|
|
|
@@ -155,13 +158,15 @@ export function createMcpToolHandlers(overrides = {}) {
|
|
|
155
158
|
return deps.loadConfigImpl({ home: deps.home, env: deps.env });
|
|
156
159
|
}
|
|
157
160
|
|
|
158
|
-
async function persistRemote({ kind, remote }) {
|
|
161
|
+
async function persistRemote({ kind, remote, requestConfig }) {
|
|
159
162
|
const request = {
|
|
160
163
|
version: 1,
|
|
161
164
|
requestId: remote.requestId,
|
|
162
165
|
kind,
|
|
163
166
|
responseTopic: remote.responseTopic,
|
|
164
167
|
allowed: remote.allowed,
|
|
168
|
+
server: requestConfig.server,
|
|
169
|
+
topic: requestConfig.topic,
|
|
165
170
|
status: 'pending',
|
|
166
171
|
createdAt: new Date(deps.nowImpl()).toISOString()
|
|
167
172
|
};
|
|
@@ -174,10 +179,10 @@ export function createMcpToolHandlers(overrides = {}) {
|
|
|
174
179
|
const remote = await deps.createRemoteRequestImpl({
|
|
175
180
|
...input,
|
|
176
181
|
beforePublish: async (prepared) => {
|
|
177
|
-
persisted = await persistRemote({ kind, remote: prepared });
|
|
182
|
+
persisted = await persistRemote({ kind, remote: prepared, requestConfig: input.config });
|
|
178
183
|
}
|
|
179
184
|
});
|
|
180
|
-
return persisted ?? persistRemote({ kind, remote });
|
|
185
|
+
return persisted ?? persistRemote({ kind, remote, requestConfig: input.config });
|
|
181
186
|
}
|
|
182
187
|
|
|
183
188
|
return {
|
|
@@ -233,7 +238,9 @@ export function createMcpToolHandlers(overrides = {}) {
|
|
|
233
238
|
let request = await deps.loadRequestImpl({ home: deps.home, env: deps.env, requestId });
|
|
234
239
|
if (request.status === 'resolved') return terminalResult(request);
|
|
235
240
|
|
|
236
|
-
const current =
|
|
241
|
+
const current = request.server && request.topic
|
|
242
|
+
? { server: request.server, topic: request.topic }
|
|
243
|
+
: await config();
|
|
237
244
|
const deadline = deps.nowImpl() + seconds * 1000;
|
|
238
245
|
while (deps.nowImpl() < deadline) {
|
|
239
246
|
const response = await deps.pollRemoteResponseImpl({
|
package/src/ntfy.mjs
CHANGED
|
@@ -97,6 +97,7 @@ function normalizeOptions(options) {
|
|
|
97
97
|
return { value, label: label.slice(0, 32) };
|
|
98
98
|
});
|
|
99
99
|
if (new Set(normalized.map((option) => option.value)).size !== normalized.length) throw new Error('NOFAX_CHOICE_DUPLICATE');
|
|
100
|
+
if (new Set(normalized.map((option) => option.label)).size !== normalized.length) throw new Error('NOFAX_CHOICE_DUPLICATE');
|
|
100
101
|
return normalized;
|
|
101
102
|
}
|
|
102
103
|
|
package/src/requests.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { chmod, link, mkdir, readFile, readdir, rename, unlink, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import { resolveNofaxHome } from './config.mjs';
|
|
3
|
+
import { normalizeServer, resolveNofaxHome } from './config.mjs';
|
|
4
4
|
|
|
5
5
|
const REQUEST_ID = /^nfx_[A-Za-z0-9_-]{20,80}$/;
|
|
6
6
|
const RESPONSE_TOPIC = /^nofax_r_[A-Za-z0-9_-]{20,120}$/;
|
|
7
|
+
const PHONE_TOPIC = /^[A-Za-z0-9_-]{24,128}$/;
|
|
7
8
|
const KINDS = new Set(['approval', 'choice', 'refinement']);
|
|
8
9
|
const STATUSES = new Set(['pending', 'resolved']);
|
|
9
10
|
const MAX_RESPONSE_TEXT = 2000;
|
|
@@ -40,6 +41,9 @@ function validateRequest(input) {
|
|
|
40
41
|
}
|
|
41
42
|
if (!STATUSES.has(input.status)) throw new Error('NOFAX_REQUEST_STATUS_INVALID');
|
|
42
43
|
if (typeof input.createdAt !== 'string' || Number.isNaN(Date.parse(input.createdAt))) throw new Error('NOFAX_REQUEST_CREATED_AT_INVALID');
|
|
44
|
+
const hasServer = input.server !== undefined;
|
|
45
|
+
const hasTopic = input.topic !== undefined;
|
|
46
|
+
if (hasServer !== hasTopic) throw new Error('NOFAX_REQUEST_TRANSPORT_INVALID');
|
|
43
47
|
const base = {
|
|
44
48
|
version: 1,
|
|
45
49
|
requestId,
|
|
@@ -49,6 +53,13 @@ function validateRequest(input) {
|
|
|
49
53
|
status: input.status,
|
|
50
54
|
createdAt: input.createdAt
|
|
51
55
|
};
|
|
56
|
+
if (hasServer) {
|
|
57
|
+
if (typeof input.server !== 'string' || typeof input.topic !== 'string' || !PHONE_TOPIC.test(input.topic)) {
|
|
58
|
+
throw new Error('NOFAX_REQUEST_TRANSPORT_INVALID');
|
|
59
|
+
}
|
|
60
|
+
base.server = normalizeServer(input.server);
|
|
61
|
+
base.topic = input.topic;
|
|
62
|
+
}
|
|
52
63
|
if (input.status === 'resolved') {
|
|
53
64
|
if (typeof input.resolvedAt !== 'string' || Number.isNaN(Date.parse(input.resolvedAt))) throw new Error('NOFAX_REQUEST_RESOLVED_AT_INVALID');
|
|
54
65
|
if (typeof input.decision !== 'string') throw new Error('NOFAX_REQUEST_DECISION_INVALID');
|