nofax 0.2.17 → 0.2.19
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 +20 -1
- package/src/ntfy.mjs +16 -10
- package/src/protocol.mjs +11 -4
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.19' },
|
|
78
78
|
{ instructions: SERVER_INSTRUCTIONS }
|
|
79
79
|
);
|
|
80
80
|
|
package/src/mcp-tools.mjs
CHANGED
|
@@ -28,6 +28,23 @@ function pendingResult(requestId) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
function terminalResult(request) {
|
|
31
|
+
if (request.kind === 'choice') {
|
|
32
|
+
return {
|
|
33
|
+
status: 'resolved',
|
|
34
|
+
requestId: request.requestId,
|
|
35
|
+
decision: request.decision,
|
|
36
|
+
instruction: 'Human choice received. Apply only that explicit choice within the caller\'s existing authority.'
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (request.kind === 'refinement') {
|
|
40
|
+
return {
|
|
41
|
+
status: 'resolved',
|
|
42
|
+
requestId: request.requestId,
|
|
43
|
+
decision: request.decision,
|
|
44
|
+
...(request.text === undefined ? {} : { text: request.text }),
|
|
45
|
+
instruction: 'Apply the human refinement. If the resulting action still requires approval, create a new approval request and wait for that new terminal response before acting.'
|
|
46
|
+
};
|
|
47
|
+
}
|
|
31
48
|
if (request.decision === 'allow') {
|
|
32
49
|
return {
|
|
33
50
|
status: 'resolved',
|
|
@@ -211,7 +228,8 @@ export function createMcpToolHandlers(overrides = {}) {
|
|
|
211
228
|
config: current,
|
|
212
229
|
responseTopic: request.responseTopic,
|
|
213
230
|
requestId: request.requestId,
|
|
214
|
-
allowed: request.allowed
|
|
231
|
+
allowed: request.allowed,
|
|
232
|
+
kind: request.kind
|
|
215
233
|
});
|
|
216
234
|
if (response !== null) {
|
|
217
235
|
const resolution = await deps.resolveRequestWithClaimImpl({
|
|
@@ -229,6 +247,7 @@ export function createMcpToolHandlers(overrides = {}) {
|
|
|
229
247
|
await deps.sendResponseConfirmationImpl({
|
|
230
248
|
config: current,
|
|
231
249
|
response,
|
|
250
|
+
kind: request.kind,
|
|
232
251
|
title: request.kind === 'approval' ? 'Approval' : request.kind === 'refinement' ? 'Refinement' : 'Choice'
|
|
233
252
|
});
|
|
234
253
|
}
|
package/src/ntfy.mjs
CHANGED
|
@@ -133,7 +133,7 @@ export async function createRemoteRequest({
|
|
|
133
133
|
return remote;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
function parseNtfyPoll(text, requestId, allowed) {
|
|
136
|
+
function parseNtfyPoll(text, requestId, allowed, kind) {
|
|
137
137
|
for (const line of text.split(/\r?\n/)) {
|
|
138
138
|
if (!line.trim()) continue;
|
|
139
139
|
let event;
|
|
@@ -143,13 +143,13 @@ function parseNtfyPoll(text, requestId, allowed) {
|
|
|
143
143
|
continue;
|
|
144
144
|
}
|
|
145
145
|
if (event?.event !== 'message') continue;
|
|
146
|
-
const response = parseResponseMessage(event.message, { requestId, allowed });
|
|
146
|
+
const response = parseResponseMessage(event.message, { requestId, allowed, kind });
|
|
147
147
|
if (response !== null) return response;
|
|
148
148
|
}
|
|
149
149
|
return null;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
export async function pollRemoteResponse({ config, responseTopic, requestId, allowed, fetchImpl = fetch }) {
|
|
152
|
+
export async function pollRemoteResponse({ config, responseTopic, requestId, allowed, kind, fetchImpl = fetch }) {
|
|
153
153
|
let response;
|
|
154
154
|
try {
|
|
155
155
|
response = await fetchImpl(`${config.server}/${responseTopic}/json?poll=1&since=all`, {
|
|
@@ -160,13 +160,15 @@ export async function pollRemoteResponse({ config, responseTopic, requestId, all
|
|
|
160
160
|
throw new Error(`NOFAX_NTFY_POLL_NETWORK: ${error?.message ?? String(error)}`);
|
|
161
161
|
}
|
|
162
162
|
await ensureOk(response, 'NOFAX_NTFY_POLL');
|
|
163
|
-
return parseNtfyPoll(await response.text(), requestId, allowed);
|
|
163
|
+
return parseNtfyPoll(await response.text(), requestId, allowed, kind);
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
export async function sendResponseConfirmation({ config, response, title = 'Nofax', fetchImpl = fetch }) {
|
|
166
|
+
export async function sendResponseConfirmation({ config, response, kind, title = 'Nofax', fetchImpl = fetch }) {
|
|
167
167
|
let confirmationTitle = 'Response received';
|
|
168
168
|
let tag = 'white_check_mark';
|
|
169
|
-
if (
|
|
169
|
+
if (kind === 'choice') confirmationTitle = 'Choice received';
|
|
170
|
+
else if (kind === 'refinement') confirmationTitle = 'Refinement received';
|
|
171
|
+
else if (response.decision === 'allow') confirmationTitle = 'Approved';
|
|
170
172
|
else if (response.decision === 'deny') {
|
|
171
173
|
confirmationTitle = 'Denied';
|
|
172
174
|
tag = 'no_entry';
|
|
@@ -195,6 +197,7 @@ export async function waitRemoteResponse({
|
|
|
195
197
|
responseTopic,
|
|
196
198
|
requestId,
|
|
197
199
|
allowed,
|
|
200
|
+
kind,
|
|
198
201
|
timeoutMs,
|
|
199
202
|
pollIntervalMs = 1000,
|
|
200
203
|
fetchImpl = fetch,
|
|
@@ -203,7 +206,7 @@ export async function waitRemoteResponse({
|
|
|
203
206
|
}) {
|
|
204
207
|
const deadline = nowImpl() + timeoutMs;
|
|
205
208
|
while (nowImpl() < deadline) {
|
|
206
|
-
const response = await pollRemoteResponse({ config, responseTopic, requestId, allowed, fetchImpl });
|
|
209
|
+
const response = await pollRemoteResponse({ config, responseTopic, requestId, allowed, kind, fetchImpl });
|
|
207
210
|
if (response !== null) return response;
|
|
208
211
|
const remaining = deadline - nowImpl();
|
|
209
212
|
if (remaining <= 0) break;
|
|
@@ -217,6 +220,7 @@ async function requestDecision({
|
|
|
217
220
|
title,
|
|
218
221
|
message,
|
|
219
222
|
options,
|
|
223
|
+
kind,
|
|
220
224
|
includeRefine = false,
|
|
221
225
|
fetchImpl = fetch,
|
|
222
226
|
timeoutMs = config.timeoutSeconds * 1000,
|
|
@@ -228,6 +232,7 @@ async function requestDecision({
|
|
|
228
232
|
const response = await waitRemoteResponse({
|
|
229
233
|
config,
|
|
230
234
|
...remote,
|
|
235
|
+
kind,
|
|
231
236
|
timeoutMs,
|
|
232
237
|
pollIntervalMs,
|
|
233
238
|
fetchImpl,
|
|
@@ -237,13 +242,14 @@ async function requestDecision({
|
|
|
237
242
|
if (response === null) {
|
|
238
243
|
return { decision: 'timeout', requestId: remote.requestId, responseTopic: remote.responseTopic };
|
|
239
244
|
}
|
|
240
|
-
await sendResponseConfirmation({ config, response, title, fetchImpl });
|
|
245
|
+
await sendResponseConfirmation({ config, response, kind, title, fetchImpl });
|
|
241
246
|
return { ...response, requestId: remote.requestId, responseTopic: remote.responseTopic };
|
|
242
247
|
}
|
|
243
248
|
|
|
244
249
|
export async function requestApproval(options) {
|
|
245
250
|
return requestDecision({
|
|
246
251
|
...options,
|
|
252
|
+
kind: 'approval',
|
|
247
253
|
options: [
|
|
248
254
|
{ value: 'allow', label: 'Allow' },
|
|
249
255
|
{ value: 'deny', label: 'Deny' }
|
|
@@ -252,11 +258,11 @@ export async function requestApproval(options) {
|
|
|
252
258
|
}
|
|
253
259
|
|
|
254
260
|
export async function requestRefinement(options) {
|
|
255
|
-
return requestDecision({ ...options, options: [], includeRefine: true });
|
|
261
|
+
return requestDecision({ ...options, kind: 'refinement', options: [], includeRefine: true });
|
|
256
262
|
}
|
|
257
263
|
|
|
258
264
|
export async function requestChoice({ options, ...rest }) {
|
|
259
265
|
const normalized = normalizeOptions(options);
|
|
260
266
|
if (normalized.length < 1 || normalized.length > 3) throw new Error('NOFAX_CHOICE_LIMIT');
|
|
261
|
-
return requestDecision({ ...rest, options: normalized });
|
|
267
|
+
return requestDecision({ ...rest, kind: 'choice', options: normalized });
|
|
262
268
|
}
|
package/src/protocol.mjs
CHANGED
|
@@ -46,7 +46,13 @@ function normalizeSecretKeyName(key) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
function isSecretKey(key) {
|
|
49
|
-
|
|
49
|
+
const normalized = normalizeSecretKeyName(key);
|
|
50
|
+
const lower = normalized.toLowerCase();
|
|
51
|
+
const isPassphrase = lower === 'passphrase'
|
|
52
|
+
|| lower === 'pass_phrase'
|
|
53
|
+
|| lower.endsWith('_passphrase')
|
|
54
|
+
|| lower.endsWith('_pass_phrase');
|
|
55
|
+
return lower === 'auth' || isPassphrase || SECRET_KEY.test(normalized);
|
|
50
56
|
}
|
|
51
57
|
|
|
52
58
|
function redactSecretText(value) {
|
|
@@ -214,7 +220,7 @@ export function buildAgentSummary({ source, toolName, cwd, toolInput, message })
|
|
|
214
220
|
return `${result.slice(0, MAX_SUMMARY - 14)}\n…[truncated]`;
|
|
215
221
|
}
|
|
216
222
|
|
|
217
|
-
export function parseResponseMessage(message, { requestId, allowed }) {
|
|
223
|
+
export function parseResponseMessage(message, { requestId, allowed, kind }) {
|
|
218
224
|
if (typeof message !== 'string') return null;
|
|
219
225
|
let parsed;
|
|
220
226
|
try {
|
|
@@ -228,6 +234,7 @@ export function parseResponseMessage(message, { requestId, allowed }) {
|
|
|
228
234
|
if (!allowed.includes(parsed.decision)) return null;
|
|
229
235
|
|
|
230
236
|
if (parsed.decision === 'refine') {
|
|
237
|
+
if (kind === 'choice') return { decision: 'refine' };
|
|
231
238
|
if (typeof parsed.text !== 'string') return null;
|
|
232
239
|
const text = parsed.text.trim();
|
|
233
240
|
if (!text) return null;
|
|
@@ -237,6 +244,6 @@ export function parseResponseMessage(message, { requestId, allowed }) {
|
|
|
237
244
|
return { decision: parsed.decision };
|
|
238
245
|
}
|
|
239
246
|
|
|
240
|
-
export function parseDecisionMessage(message, { requestId, allowed }) {
|
|
241
|
-
return parseResponseMessage(message, { requestId, allowed })?.decision ?? null;
|
|
247
|
+
export function parseDecisionMessage(message, { requestId, allowed, kind }) {
|
|
248
|
+
return parseResponseMessage(message, { requestId, allowed, kind })?.decision ?? null;
|
|
242
249
|
}
|