nofax 0.2.18 → 0.2.20
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 +19 -13
- package/src/protocol.mjs +7 -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.20' },
|
|
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';
|
|
@@ -177,9 +179,9 @@ export async function sendResponseConfirmation({ config, response, title = 'Nofa
|
|
|
177
179
|
await sendNotification({
|
|
178
180
|
config,
|
|
179
181
|
title: `${confirmationTitle} - ${title}`,
|
|
180
|
-
message: response.decision === 'refine'
|
|
181
|
-
|
|
182
|
-
|
|
182
|
+
message: kind !== 'choice' && response.decision === 'refine'
|
|
183
|
+
? 'Your refinement was sent back to the agent.'
|
|
184
|
+
: `Nofax recorded: ${response.decision}`,
|
|
183
185
|
priority: 2,
|
|
184
186
|
tags: [tag],
|
|
185
187
|
fetchImpl
|
|
@@ -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
|
@@ -185,7 +185,9 @@ export function redactAndBound(value, options = {}) {
|
|
|
185
185
|
? value.name
|
|
186
186
|
: typeof value.key === 'string'
|
|
187
187
|
? value.key
|
|
188
|
-
:
|
|
188
|
+
: typeof value.header === 'string'
|
|
189
|
+
? value.header
|
|
190
|
+
: null;
|
|
189
191
|
const redactEntryValue = entryName !== null && isSecretKey(entryName);
|
|
190
192
|
|
|
191
193
|
const out = {};
|
|
@@ -220,7 +222,7 @@ export function buildAgentSummary({ source, toolName, cwd, toolInput, message })
|
|
|
220
222
|
return `${result.slice(0, MAX_SUMMARY - 14)}\n…[truncated]`;
|
|
221
223
|
}
|
|
222
224
|
|
|
223
|
-
export function parseResponseMessage(message, { requestId, allowed }) {
|
|
225
|
+
export function parseResponseMessage(message, { requestId, allowed, kind }) {
|
|
224
226
|
if (typeof message !== 'string') return null;
|
|
225
227
|
let parsed;
|
|
226
228
|
try {
|
|
@@ -234,6 +236,7 @@ export function parseResponseMessage(message, { requestId, allowed }) {
|
|
|
234
236
|
if (!allowed.includes(parsed.decision)) return null;
|
|
235
237
|
|
|
236
238
|
if (parsed.decision === 'refine') {
|
|
239
|
+
if (kind === 'choice') return { decision: 'refine' };
|
|
237
240
|
if (typeof parsed.text !== 'string') return null;
|
|
238
241
|
const text = parsed.text.trim();
|
|
239
242
|
if (!text) return null;
|
|
@@ -243,6 +246,6 @@ export function parseResponseMessage(message, { requestId, allowed }) {
|
|
|
243
246
|
return { decision: parsed.decision };
|
|
244
247
|
}
|
|
245
248
|
|
|
246
|
-
export function parseDecisionMessage(message, { requestId, allowed }) {
|
|
247
|
-
return parseResponseMessage(message, { requestId, allowed })?.decision ?? null;
|
|
249
|
+
export function parseDecisionMessage(message, { requestId, allowed, kind }) {
|
|
250
|
+
return parseResponseMessage(message, { requestId, allowed, kind })?.decision ?? null;
|
|
248
251
|
}
|