@nathapp/nax-agent-acp 0.92.5 → 0.92.7
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/CHANGELOG.md +8 -0
- package/dist/client/backend.js +2 -1
- package/dist/client/events.d.ts +2 -1
- package/dist/client/events.js +6 -0
- package/dist/client/inbound.js +2 -1
- package/dist/client/tool-calls.js +6 -5
- package/dist/client/tool-host.js +3 -2
- package/dist/client/turn-end-abort.d.ts +31 -0
- package/dist/client/turn-end-abort.js +40 -0
- package/dist/server/translate/events.js +6 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to `@nathapp/nax-agent-acp` are recorded here. Versions move in
|
|
4
4
|
step with `@nathapp/nax-agent`.
|
|
5
5
|
|
|
6
|
+
## [0.92.7] - 2026-11-17
|
|
7
|
+
|
|
8
|
+
- No changes in this package. Released in lockstep with the other nax packages.
|
|
9
|
+
|
|
10
|
+
## [0.92.6] - 2026-11-16
|
|
11
|
+
|
|
12
|
+
- No changes in this package. Released in lockstep with the other nax packages.
|
|
13
|
+
|
|
6
14
|
## [0.92.5] - 2026-11-15
|
|
7
15
|
|
|
8
16
|
- No changes in this package. Released in lockstep with the other nax packages.
|
package/dist/client/backend.js
CHANGED
|
@@ -37,6 +37,7 @@ import { shellSandboxPlan } from "#src/client/shell-sandbox";
|
|
|
37
37
|
import { createToolCalls } from "#src/client/tool-calls";
|
|
38
38
|
import { createToolHost, newToolHostServerName, newToolHostToken } from "#src/client/tool-host";
|
|
39
39
|
import { runPromptTurn } from "#src/client/turn";
|
|
40
|
+
import { TurnEndAbort } from "#src/client/turn-end-abort";
|
|
40
41
|
import { createCostMeter } from "#src/client/usage";
|
|
41
42
|
/** Test seam: the process launcher, the tool host factory and its server name. Production always uses launchAgent, createToolHost and newToolHostServerName. */
|
|
42
43
|
export const _acpBackendDeps = {
|
|
@@ -140,7 +141,7 @@ async function connect(base, ctx, restore, retiredTokens, serverName) {
|
|
|
140
141
|
const status = { disconnected: false };
|
|
141
142
|
void acp.launched.exited.then(() => {
|
|
142
143
|
status.disconnected = true;
|
|
143
|
-
gone.abort();
|
|
144
|
+
gone.abort(new TurnEndAbort("the agent process exited"));
|
|
144
145
|
});
|
|
145
146
|
const state = {
|
|
146
147
|
link: acp.link,
|
package/dist/client/events.d.ts
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* values, holding back only the tail that could start a secret (D5-g); a delta of
|
|
5
5
|
* one stream, and any tool event, first flushes what the other stream holds, so the
|
|
6
6
|
* order is kept. Tool calls and results come from tool-events.ts (D5-c to D5-f);
|
|
7
|
-
* usage_update costs feed the session's cost meter (D5-b)
|
|
7
|
+
* usage_update costs feed the session's cost meter (D5-b); used/size emit separate
|
|
8
|
+
* context_usage snapshots, never billing totals. User chunks, plans, mode,
|
|
8
9
|
* config and command updates, and anything unknown are dropped. finish() flushes
|
|
9
10
|
* held text and answers unanswered tool calls; settle(response) does that and then
|
|
10
11
|
* emits the turn's one usage event (D5-h). onReceipt fires once, on the first
|
package/dist/client/events.js
CHANGED
|
@@ -108,6 +108,12 @@ export function createTurnCollector(emit, options = {}) {
|
|
|
108
108
|
return;
|
|
109
109
|
case "usage_update":
|
|
110
110
|
meter.observe(update.cost);
|
|
111
|
+
if (Number.isSafeInteger(update.used) &&
|
|
112
|
+
update.used >= 0 &&
|
|
113
|
+
Number.isSafeInteger(update.size) &&
|
|
114
|
+
update.size > 0) {
|
|
115
|
+
send({ type: "context_usage", used: update.used, size: update.size });
|
|
116
|
+
}
|
|
111
117
|
return;
|
|
112
118
|
default:
|
|
113
119
|
return;
|
package/dist/client/inbound.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getLogger } from "@nathapp/nax-agent";
|
|
2
2
|
import { isDenial, rejectLocally } from "#src/client/permissions";
|
|
3
3
|
import { isRecord } from "#src/client/text";
|
|
4
|
+
import { TurnEndAbort } from "#src/client/turn-end-abort";
|
|
4
5
|
/** Concurrent permission requests and elicitations one turn may hold; further ones are answered locally. */
|
|
5
6
|
export const MAX_PENDING_DECISIONS = 16;
|
|
6
7
|
const LOG_MESSAGES = {
|
|
@@ -105,7 +106,7 @@ export function createInboundRouter(decide, elicit = cancelElicitation, ownTools
|
|
|
105
106
|
return async () => {
|
|
106
107
|
if (active === binding)
|
|
107
108
|
active = undefined;
|
|
108
|
-
scope.abort();
|
|
109
|
+
scope.abort(new TurnEndAbort("the ACP prompt turn ended"));
|
|
109
110
|
await Promise.allSettled([...binding.pending]);
|
|
110
111
|
};
|
|
111
112
|
},
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ASK_CANCELLED_REASON, ASK_DENIED_REASON, ASK_NO_CHANNEL_REASON, ASK_PROFILE_REASON, ASK_TIMEOUT_REASON, ASK_UNSHOWABLE_REASON, capStrings, redactSecrets, } from "@nathapp/nax-agent";
|
|
2
2
|
import { capBytes, scrubSecrets, stripControl, stripInvisible } from "#src/client/text";
|
|
3
|
+
import { abandonedText } from "#src/client/turn-end-abort";
|
|
3
4
|
export const MAX_CONCURRENT_TOOL_CALLS = 8;
|
|
4
5
|
/** Byte cap of an approval summary (native: EMBEDDER_SUMMARY_BYTES). */
|
|
5
6
|
export const TOOL_SUMMARY_BYTES = 1024;
|
|
@@ -53,8 +54,8 @@ export function toolSummary(tool, input, secrets) {
|
|
|
53
54
|
const visible = scrubSecrets(stripInvisible(stripControl(describeInput(tool, input))), secrets);
|
|
54
55
|
return capBytes(visible.replace(/[\n\t]+/g, " ").trim(), TOOL_SUMMARY_BYTES);
|
|
55
56
|
}
|
|
56
|
-
function abandoned(name) {
|
|
57
|
-
return textResult(
|
|
57
|
+
function abandoned(name, signal) {
|
|
58
|
+
return textResult(abandonedText(name, signal), true);
|
|
58
59
|
}
|
|
59
60
|
function runSafely(tool, input, ctx) {
|
|
60
61
|
return Promise.resolve()
|
|
@@ -66,10 +67,10 @@ function runSafely(tool, input, ctx) {
|
|
|
66
67
|
/** Answers at once when the signal aborts: a run that ignores its signal is abandoned and its late result ignored. */
|
|
67
68
|
async function invoke(tool, input, ctx) {
|
|
68
69
|
if (ctx.signal.aborted)
|
|
69
|
-
return abandoned(tool.name);
|
|
70
|
+
return abandoned(tool.name, ctx.signal);
|
|
70
71
|
let onAbort = () => { };
|
|
71
72
|
const aborted = new Promise((resolve) => {
|
|
72
|
-
onAbort = () => resolve(abandoned(tool.name));
|
|
73
|
+
onAbort = () => resolve(abandoned(tool.name, ctx.signal));
|
|
73
74
|
ctx.signal.addEventListener("abort", onAbort, { once: true });
|
|
74
75
|
});
|
|
75
76
|
try {
|
|
@@ -107,7 +108,7 @@ export function createToolCalls(deps) {
|
|
|
107
108
|
const input = args ?? {};
|
|
108
109
|
const ctx = { sessionId: deps.sessionId, toolCallId: `mcp-${accepted}`, signal };
|
|
109
110
|
if (signal.aborted)
|
|
110
|
-
return abandoned(tool.name);
|
|
111
|
+
return abandoned(tool.name, signal);
|
|
111
112
|
const denied = await approve(deps, tool, input, ctx);
|
|
112
113
|
return denied ?? invoke(tool, input, ctx);
|
|
113
114
|
};
|
package/dist/client/tool-host.js
CHANGED
|
@@ -18,6 +18,7 @@ import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprot
|
|
|
18
18
|
import { NaxError } from "@nathapp/nax-agent";
|
|
19
19
|
import { TOOL_HOST_SERVER_NAME } from "#src/client/pre-approval";
|
|
20
20
|
import { race } from "#src/client/race";
|
|
21
|
+
import { TurnEndAbort } from "#src/client/turn-end-abort";
|
|
21
22
|
export const TOOL_HOST_PATH = "/mcp";
|
|
22
23
|
export const MAX_BODY_BYTES = 1024 * 1024;
|
|
23
24
|
/** Past this many body bytes the 413 is sent at once and the connection closed. */
|
|
@@ -104,7 +105,7 @@ async function serveMcp(state, req, res, body) {
|
|
|
104
105
|
server.setRequestHandler(CallToolRequestSchema, (request) => state.calls.call(request.params.name, request.params.arguments, signal));
|
|
105
106
|
const transport = new StreamableHTTPServerTransport({ enableJsonResponse: true });
|
|
106
107
|
res.on("close", () => {
|
|
107
|
-
gone.abort();
|
|
108
|
+
gone.abort(new TurnEndAbort("the agent closed the tool request"));
|
|
108
109
|
void transport.close().catch(() => undefined);
|
|
109
110
|
void server.close().catch(() => undefined);
|
|
110
111
|
});
|
|
@@ -190,7 +191,7 @@ export function createToolHost(calls, token = newToolHostToken(), opts = {}) {
|
|
|
190
191
|
},
|
|
191
192
|
drain: () => calls.drain(),
|
|
192
193
|
stop() {
|
|
193
|
-
state.stopped.abort();
|
|
194
|
+
state.stopped.abort(new TurnEndAbort("the tool host stopped"));
|
|
194
195
|
stopping ??= close(http);
|
|
195
196
|
return stopping;
|
|
196
197
|
},
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* US-004: the reasons this package gives for its own turn ends, and the
|
|
3
|
+
* abandoned-tool text they produce.
|
|
4
|
+
*
|
|
5
|
+
* nax-agent keeps the same pair (`session/turn-end-abort.ts`,
|
|
6
|
+
* `abandonedToolMessage`), but neither is exported from its public entry, so
|
|
7
|
+
* this package carries its own copies. `TurnEndAbort` keeps the AbortError
|
|
8
|
+
* contract (a NAME, as nax-agent's does): a bare `abort()` already produces a
|
|
9
|
+
* runtime `DOMException` with that name, so a distinguishable reason cannot be
|
|
10
|
+
* a different name — it is a nax-owned class whose name keeps the contract and
|
|
11
|
+
* whose message says WHY the turn ended.
|
|
12
|
+
*/
|
|
13
|
+
/** A turn end this package caused: name kept, message names the reason. */
|
|
14
|
+
export declare class TurnEndAbort extends Error {
|
|
15
|
+
readonly name = "AbortError";
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The text the agent receives for an abandoned embedder tool call.
|
|
19
|
+
*
|
|
20
|
+
* The reason is only observable once the signal has aborted, so this is
|
|
21
|
+
* evaluated at abandonment time, never before the race. `AbortSignal.any` keeps
|
|
22
|
+
* the reason of the source that aborted first, so a caller's own cancel or
|
|
23
|
+
* timeout reason wins over this package's turn-end reason when it fires first.
|
|
24
|
+
*
|
|
25
|
+
* - a `NaxError` reason names its code and message (a session cancel, the turn
|
|
26
|
+
* deadline, a stalled consumer);
|
|
27
|
+
* - this package's `TurnEndAbort` names its message alone (no error code);
|
|
28
|
+
* - anything else — a bare `abort()`, a runtime `DOMException`, an unrelated
|
|
29
|
+
* error — keeps the text that says only that the turn ended.
|
|
30
|
+
*/
|
|
31
|
+
export declare function abandonedText(name: string, signal: AbortSignal): string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* US-004: the reasons this package gives for its own turn ends, and the
|
|
3
|
+
* abandoned-tool text they produce.
|
|
4
|
+
*
|
|
5
|
+
* nax-agent keeps the same pair (`session/turn-end-abort.ts`,
|
|
6
|
+
* `abandonedToolMessage`), but neither is exported from its public entry, so
|
|
7
|
+
* this package carries its own copies. `TurnEndAbort` keeps the AbortError
|
|
8
|
+
* contract (a NAME, as nax-agent's does): a bare `abort()` already produces a
|
|
9
|
+
* runtime `DOMException` with that name, so a distinguishable reason cannot be
|
|
10
|
+
* a different name — it is a nax-owned class whose name keeps the contract and
|
|
11
|
+
* whose message says WHY the turn ended.
|
|
12
|
+
*/
|
|
13
|
+
import { NaxError } from "@nathapp/nax-agent";
|
|
14
|
+
/** A turn end this package caused: name kept, message names the reason. */
|
|
15
|
+
export class TurnEndAbort extends Error {
|
|
16
|
+
name = "AbortError";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The text the agent receives for an abandoned embedder tool call.
|
|
20
|
+
*
|
|
21
|
+
* The reason is only observable once the signal has aborted, so this is
|
|
22
|
+
* evaluated at abandonment time, never before the race. `AbortSignal.any` keeps
|
|
23
|
+
* the reason of the source that aborted first, so a caller's own cancel or
|
|
24
|
+
* timeout reason wins over this package's turn-end reason when it fires first.
|
|
25
|
+
*
|
|
26
|
+
* - a `NaxError` reason names its code and message (a session cancel, the turn
|
|
27
|
+
* deadline, a stalled consumer);
|
|
28
|
+
* - this package's `TurnEndAbort` names its message alone (no error code);
|
|
29
|
+
* - anything else — a bare `abort()`, a runtime `DOMException`, an unrelated
|
|
30
|
+
* error — keeps the text that says only that the turn ended.
|
|
31
|
+
*/
|
|
32
|
+
export function abandonedText(name, signal) {
|
|
33
|
+
const base = `Tool "${name}" was abandoned: the turn ended`;
|
|
34
|
+
const reason = signal.reason;
|
|
35
|
+
if (reason instanceof NaxError)
|
|
36
|
+
return `${base} (${reason.code}: ${reason.message}).`;
|
|
37
|
+
if (reason instanceof TurnEndAbort)
|
|
38
|
+
return `${base} (${reason.message}).`;
|
|
39
|
+
return `${base}.`;
|
|
40
|
+
}
|
|
@@ -45,6 +45,7 @@ function streamResetUpdate(event, notices) {
|
|
|
45
45
|
export function createEventTranslator(deps) {
|
|
46
46
|
const calls = new Map();
|
|
47
47
|
const approvals = new Map();
|
|
48
|
+
let context;
|
|
48
49
|
let compactions = 0;
|
|
49
50
|
let sessionCostUsd = deps.priorCostUsd ?? 0;
|
|
50
51
|
const describeCall = (toolCallId, call) => {
|
|
@@ -67,7 +68,8 @@ export function createEventTranslator(deps) {
|
|
|
67
68
|
function usage(event) {
|
|
68
69
|
if (event.costSource !== "unpriced")
|
|
69
70
|
sessionCostUsd += event.costUsd;
|
|
70
|
-
|
|
71
|
+
const updates = usageUpdate(event, context?.size ?? deps.contextWindow, sessionCostUsd);
|
|
72
|
+
return context === undefined ? updates : updates.map((update) => ({ ...update, ...context }));
|
|
71
73
|
}
|
|
72
74
|
function compaction(event) {
|
|
73
75
|
if (!deps.clientUpdates.compaction)
|
|
@@ -113,6 +115,9 @@ export function createEventTranslator(deps) {
|
|
|
113
115
|
return [];
|
|
114
116
|
case "approval_resolved":
|
|
115
117
|
return resolved(event);
|
|
118
|
+
case "context_usage":
|
|
119
|
+
context = { used: event.used, size: event.size };
|
|
120
|
+
return [{ sessionUpdate: "usage_update", used: event.used, size: event.size }];
|
|
116
121
|
case "turn_start":
|
|
117
122
|
case "question":
|
|
118
123
|
case "turn_end":
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nathapp/nax-agent-acp",
|
|
3
|
-
"version": "0.92.
|
|
3
|
+
"version": "0.92.7",
|
|
4
4
|
"description": "ACP (Agent Client Protocol) backend for @nathapp/nax-agent sessions: drive Claude Code and other ACP agents through the nax-agent session API.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "William Khoo",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"zod": "^4.6.6"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@nathapp/nax-agent": "^0.92.
|
|
52
|
+
"@nathapp/nax-agent": "^0.92.7"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public",
|