@nathapp/nax-agent-acp 0.3.0
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 +63 -0
- package/LICENSE +21 -0
- package/README.md +227 -0
- package/dist/client/backend.d.ts +30 -0
- package/dist/client/backend.js +238 -0
- package/dist/client/capabilities.d.ts +42 -0
- package/dist/client/capabilities.js +60 -0
- package/dist/client/connection.d.ts +31 -0
- package/dist/client/connection.js +32 -0
- package/dist/client/elicitation.d.ts +34 -0
- package/dist/client/elicitation.js +184 -0
- package/dist/client/env.d.ts +8 -0
- package/dist/client/env.js +21 -0
- package/dist/client/errors.d.ts +36 -0
- package/dist/client/errors.js +92 -0
- package/dist/client/events.d.ts +33 -0
- package/dist/client/events.js +96 -0
- package/dist/client/inbound.d.ts +40 -0
- package/dist/client/inbound.js +100 -0
- package/dist/client/index.d.ts +14 -0
- package/dist/client/index.js +12 -0
- package/dist/client/launch.d.ts +47 -0
- package/dist/client/launch.js +145 -0
- package/dist/client/open.d.ts +35 -0
- package/dist/client/open.js +154 -0
- package/dist/client/options.d.ts +46 -0
- package/dist/client/options.js +91 -0
- package/dist/client/permissions.d.ts +36 -0
- package/dist/client/permissions.js +92 -0
- package/dist/client/pre-approval.d.ts +24 -0
- package/dist/client/pre-approval.js +22 -0
- package/dist/client/race.d.ts +22 -0
- package/dist/client/race.js +20 -0
- package/dist/client/registry.d.ts +35 -0
- package/dist/client/registry.js +43 -0
- package/dist/client/resume.d.ts +37 -0
- package/dist/client/resume.js +93 -0
- package/dist/client/stream-scrub.d.ts +7 -0
- package/dist/client/stream-scrub.js +37 -0
- package/dist/client/text.d.ts +29 -0
- package/dist/client/text.js +62 -0
- package/dist/client/tool-calls.d.ts +42 -0
- package/dist/client/tool-calls.js +147 -0
- package/dist/client/tool-display.d.ts +23 -0
- package/dist/client/tool-display.js +90 -0
- package/dist/client/tool-events.d.ts +35 -0
- package/dist/client/tool-events.js +177 -0
- package/dist/client/tool-host.d.ts +25 -0
- package/dist/client/tool-host.js +178 -0
- package/dist/client/turn.d.ts +19 -0
- package/dist/client/turn.js +52 -0
- package/dist/client/usage.d.ts +36 -0
- package/dist/client/usage.js +65 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MCP tool host (S4 spec §6.6): an HTTP server on 127.0.0.1, an ephemeral
|
|
3
|
+
* port, path /mcp, serving the session's embedder tools to the agent. Before a
|
|
4
|
+
* request reaches MCP it passes the gate (D4-e): path, method, Host (DNS
|
|
5
|
+
* rebinding), Origin, the bearer token (constant time) and the 1 MiB body cap.
|
|
6
|
+
* Each POST then gets a fresh stateless MCP server and transport (D4-d): the SDK
|
|
7
|
+
* refuses to reuse a stateless transport. The token exists before the host
|
|
8
|
+
* listens, so it joins the session's redaction set from the start (D4-i). stop()
|
|
9
|
+
* revokes the token, aborts calls, drops open connections and closes the port
|
|
10
|
+
* (D4-l).
|
|
11
|
+
*/
|
|
12
|
+
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
13
|
+
import { createServer } from "node:http";
|
|
14
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
15
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
16
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
17
|
+
import { NaxError } from "@nathapp/nax-agent";
|
|
18
|
+
import { TOOL_HOST_SERVER_NAME } from "#src/client/pre-approval";
|
|
19
|
+
import { race } from "#src/client/race";
|
|
20
|
+
export const TOOL_HOST_PATH = "/mcp";
|
|
21
|
+
export const MAX_BODY_BYTES = 1024 * 1024;
|
|
22
|
+
/** Past this many body bytes the 413 is sent at once and the connection closed. */
|
|
23
|
+
export const MAX_DRAIN_BYTES = 8 * MAX_BODY_BYTES;
|
|
24
|
+
/** stop() waits at most this long for the port to close. */
|
|
25
|
+
const CLOSE_WAIT_MS = 2_000;
|
|
26
|
+
const LOOPBACK = "127.0.0.1";
|
|
27
|
+
const BEARER = "Bearer ";
|
|
28
|
+
/** MCP-level server identity shown to the agent; not the package version. */
|
|
29
|
+
const SERVER_INFO = { name: TOOL_HOST_SERVER_NAME, version: "1.0.0" };
|
|
30
|
+
export function newToolHostToken() {
|
|
31
|
+
return randomBytes(32).toString("base64url");
|
|
32
|
+
}
|
|
33
|
+
const digest = (value) => createHash("sha256").update(value).digest();
|
|
34
|
+
/** Constant time: both sides are hashed to the same length first. */
|
|
35
|
+
function tokenMatches(header, token) {
|
|
36
|
+
const presented = header?.startsWith(BEARER) === true ? header.slice(BEARER.length) : "";
|
|
37
|
+
return timingSafeEqual(digest(presented), digest(token));
|
|
38
|
+
}
|
|
39
|
+
function pathOf(url) {
|
|
40
|
+
return (url ?? "").split("?")[0] ?? "";
|
|
41
|
+
}
|
|
42
|
+
/** Everything checked before the body is read, in order (D4-e). */
|
|
43
|
+
function refusalFor(state, req) {
|
|
44
|
+
if (pathOf(req.url) !== TOOL_HOST_PATH)
|
|
45
|
+
return { status: 404 };
|
|
46
|
+
if (req.method !== "POST")
|
|
47
|
+
return { status: 405, headers: { allow: "POST" } };
|
|
48
|
+
if (req.headers.host !== `${LOOPBACK}:${state.port}` || req.headers.origin !== undefined)
|
|
49
|
+
return { status: 403 };
|
|
50
|
+
if (state.stopped.signal.aborted || !tokenMatches(req.headers.authorization, state.token))
|
|
51
|
+
return { status: 401 };
|
|
52
|
+
if (Number(req.headers["content-length"] ?? 0) > MAX_BODY_BYTES) {
|
|
53
|
+
return { status: 413, headers: { connection: "close" } };
|
|
54
|
+
}
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
function reply(res, refusal) {
|
|
58
|
+
res.writeHead(refusal.status, { "content-type": "text/plain; charset=utf-8", ...refusal.headers });
|
|
59
|
+
res.end(`${refusal.status}\n`);
|
|
60
|
+
}
|
|
61
|
+
function parseJson(bytes) {
|
|
62
|
+
try {
|
|
63
|
+
return { kind: "json", value: JSON.parse(bytes.toString("utf8")) };
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return { kind: "invalid" };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* At most MAX_BODY_BYTES kept; past that the rest is drained and discarded, so the
|
|
71
|
+
* 413 is still delivered. Past MAX_DRAIN_BYTES the 413 is sent at once and the
|
|
72
|
+
* connection is closed after it: an endless body cannot hold the socket.
|
|
73
|
+
*/
|
|
74
|
+
function readBody(req) {
|
|
75
|
+
return new Promise((resolve) => {
|
|
76
|
+
const chunks = [];
|
|
77
|
+
let size = 0;
|
|
78
|
+
req.on("data", (chunk) => {
|
|
79
|
+
size += chunk.length;
|
|
80
|
+
if (size <= MAX_BODY_BYTES)
|
|
81
|
+
chunks.push(chunk);
|
|
82
|
+
else if (size > MAX_DRAIN_BYTES)
|
|
83
|
+
resolve({ kind: "too-large" });
|
|
84
|
+
});
|
|
85
|
+
req.on("end", () => resolve(size > MAX_BODY_BYTES ? { kind: "too-large" } : parseJson(Buffer.concat(chunks))));
|
|
86
|
+
req.on("error", () => resolve({ kind: "invalid" }));
|
|
87
|
+
req.on("close", () => resolve({ kind: "invalid" }));
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/** One stateless MCP server per request (D4-d). Its calls abort when the response closes or the host stops. */
|
|
91
|
+
async function serveMcp(state, req, res, body) {
|
|
92
|
+
const gone = new AbortController();
|
|
93
|
+
const signal = AbortSignal.any([gone.signal, state.stopped.signal]);
|
|
94
|
+
const server = new Server(SERVER_INFO, { capabilities: { tools: {} } });
|
|
95
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: state.calls.list() }));
|
|
96
|
+
server.setRequestHandler(CallToolRequestSchema, (request) => state.calls.call(request.params.name, request.params.arguments, signal));
|
|
97
|
+
const transport = new StreamableHTTPServerTransport({ enableJsonResponse: true });
|
|
98
|
+
res.on("close", () => {
|
|
99
|
+
gone.abort();
|
|
100
|
+
void transport.close().catch(() => undefined);
|
|
101
|
+
void server.close().catch(() => undefined);
|
|
102
|
+
});
|
|
103
|
+
await server.connect(transport);
|
|
104
|
+
await transport.handleRequest(req, res, body);
|
|
105
|
+
}
|
|
106
|
+
async function handle(state, req, res) {
|
|
107
|
+
const refusal = refusalFor(state, req);
|
|
108
|
+
if (refusal !== undefined)
|
|
109
|
+
return reply(res, refusal);
|
|
110
|
+
const body = await readBody(req);
|
|
111
|
+
if (body.kind === "too-large") {
|
|
112
|
+
res.once("finish", () => req.destroy());
|
|
113
|
+
return reply(res, { status: 413, headers: { connection: "close" } });
|
|
114
|
+
}
|
|
115
|
+
if (body.kind === "invalid")
|
|
116
|
+
return reply(res, { status: 400 });
|
|
117
|
+
await serveMcp(state, req, res, body.value);
|
|
118
|
+
}
|
|
119
|
+
function failed(res) {
|
|
120
|
+
if (res.headersSent) {
|
|
121
|
+
res.destroy();
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
reply(res, { status: 500 });
|
|
125
|
+
}
|
|
126
|
+
function listen(http) {
|
|
127
|
+
return new Promise((resolve, reject) => {
|
|
128
|
+
http.once("error", reject);
|
|
129
|
+
http.listen(0, LOOPBACK, () => {
|
|
130
|
+
http.off("error", reject);
|
|
131
|
+
const address = http.address();
|
|
132
|
+
resolve(typeof address === "object" && address !== null ? address.port : 0);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* closeAllConnections() first, then close(): on Bun 1.4 the reverse order never
|
|
138
|
+
* fires the close callback while a request is in flight (probed while planning;
|
|
139
|
+
* Node works either way). The wait is bounded all the same, so close() can never
|
|
140
|
+
* hang on a runtime quirk.
|
|
141
|
+
*/
|
|
142
|
+
async function close(http) {
|
|
143
|
+
if (!http.listening)
|
|
144
|
+
return;
|
|
145
|
+
const closed = new Promise((resolve) => {
|
|
146
|
+
http.closeAllConnections();
|
|
147
|
+
http.close(() => resolve());
|
|
148
|
+
});
|
|
149
|
+
await race(closed, { timeoutMs: CLOSE_WAIT_MS });
|
|
150
|
+
}
|
|
151
|
+
export function createToolHost(calls, token = newToolHostToken()) {
|
|
152
|
+
const state = { token, calls, stopped: new AbortController(), port: 0 };
|
|
153
|
+
const http = createServer((req, res) => {
|
|
154
|
+
void handle(state, req, res).catch(() => failed(res));
|
|
155
|
+
});
|
|
156
|
+
let stopping;
|
|
157
|
+
return {
|
|
158
|
+
token,
|
|
159
|
+
async start() {
|
|
160
|
+
if (state.stopped.signal.aborted) {
|
|
161
|
+
throw new NaxError("The MCP tool host was already stopped", "ACP_TOOL_HOST_STOPPED", { stage: "acp" });
|
|
162
|
+
}
|
|
163
|
+
state.port = await listen(http);
|
|
164
|
+
return {
|
|
165
|
+
type: "http",
|
|
166
|
+
name: TOOL_HOST_SERVER_NAME,
|
|
167
|
+
url: `http://${LOOPBACK}:${state.port}${TOOL_HOST_PATH}`,
|
|
168
|
+
headers: [{ name: "Authorization", value: `${BEARER}${token}` }],
|
|
169
|
+
};
|
|
170
|
+
},
|
|
171
|
+
drain: () => calls.drain(),
|
|
172
|
+
stop() {
|
|
173
|
+
state.stopped.abort();
|
|
174
|
+
stopping ??= close(http);
|
|
175
|
+
return stopping;
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type TurnResult } from "@nathapp/nax-agent";
|
|
2
|
+
import type { AcpLink } from "#src/client/connection";
|
|
3
|
+
import type { TurnCollector } from "#src/client/events";
|
|
4
|
+
import { type LaunchedAgent } from "#src/client/launch";
|
|
5
|
+
export interface TurnState {
|
|
6
|
+
readonly link: AcpLink;
|
|
7
|
+
readonly launched: LaunchedAgent;
|
|
8
|
+
readonly agentSessionId: string;
|
|
9
|
+
readonly cancelGraceMs: number;
|
|
10
|
+
readonly secrets: readonly string[];
|
|
11
|
+
/** Marks the session disconnected: its process is gone or was killed (D-f). */
|
|
12
|
+
disconnect(): void;
|
|
13
|
+
}
|
|
14
|
+
export interface TurnInput {
|
|
15
|
+
readonly text: string;
|
|
16
|
+
readonly signal: AbortSignal;
|
|
17
|
+
readonly collector: TurnCollector;
|
|
18
|
+
}
|
|
19
|
+
export declare function runPromptTurn(state: TurnState, input: TurnInput): Promise<TurnResult>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { NaxError } from "@nathapp/nax-agent";
|
|
2
|
+
import { promptRequestError, rpcErrorOf, stopReasonError } from "#src/client/errors";
|
|
3
|
+
import { agentGoneError } from "#src/client/launch";
|
|
4
|
+
import { race } from "#src/client/race";
|
|
5
|
+
export async function runPromptTurn(state, input) {
|
|
6
|
+
const pending = state.link.prompt({
|
|
7
|
+
sessionId: state.agentSessionId,
|
|
8
|
+
prompt: [{ type: "text", text: input.text }],
|
|
9
|
+
});
|
|
10
|
+
const outcome = await race(pending, { signal: input.signal });
|
|
11
|
+
switch (outcome.kind) {
|
|
12
|
+
case "ok":
|
|
13
|
+
return resultOf(outcome.value, input.collector);
|
|
14
|
+
case "failed":
|
|
15
|
+
throw await promptFailure(state, outcome.error);
|
|
16
|
+
default:
|
|
17
|
+
await cancelTurn(state, pending);
|
|
18
|
+
throw abortReason(input.signal);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function resultOf(response, collector) {
|
|
22
|
+
const spend = collector.settle(response);
|
|
23
|
+
if (response.stopReason !== "end_turn")
|
|
24
|
+
throw stopReasonError(String(response.stopReason));
|
|
25
|
+
return {
|
|
26
|
+
output: collector.output(),
|
|
27
|
+
tokenUsage: spend.tokenUsage,
|
|
28
|
+
estimatedCostUsd: spend.costUsd,
|
|
29
|
+
costSource: spend.costSource,
|
|
30
|
+
internalRoundTrips: 1,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
async function promptFailure(state, error) {
|
|
34
|
+
const rpc = rpcErrorOf(error);
|
|
35
|
+
if (rpc !== undefined)
|
|
36
|
+
return promptRequestError(rpc, state.secrets);
|
|
37
|
+
state.disconnect();
|
|
38
|
+
return agentGoneError("session/prompt", state.launched, state.secrets);
|
|
39
|
+
}
|
|
40
|
+
async function cancelTurn(state, pending) {
|
|
41
|
+
await state.link.cancel(state.agentSessionId).catch(() => undefined);
|
|
42
|
+
const settled = await race(pending, { timeoutMs: state.cancelGraceMs });
|
|
43
|
+
if (settled.kind === "timeout") {
|
|
44
|
+
state.launched.kill();
|
|
45
|
+
state.disconnect();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function abortReason(signal) {
|
|
49
|
+
return signal.reason instanceof Error
|
|
50
|
+
? signal.reason
|
|
51
|
+
: new NaxError("The turn was aborted", "AGENT_SESSION_TURN_FAILED", { stage: "acp" });
|
|
52
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A turn's usage (S4 spec §6.7 usage, S4-5 D5-a, D5-b, D5-h). Tokens come from
|
|
3
|
+
* PromptResponse.usage and are per turn as reported: Claude's adapter resets them
|
|
4
|
+
* when a turn starts (D5-a). Output tokens include thought tokens; cache fields stay
|
|
5
|
+
* absent when not reported. Cost comes from usage_update.cost, a cumulative USD
|
|
6
|
+
* reading: the session's meter remembers the reading at the end of the last priced
|
|
7
|
+
* turn, and a turn's cost is its latest reading minus that. A new session starts at
|
|
8
|
+
* 0; a resumed or reconnected one starts at the stored baseline, because the agent's
|
|
9
|
+
* running total survives a resume (S4-6 D6-a). A reading below the baseline means
|
|
10
|
+
* the agent's counter restarted, so the raw reading is the turn's cost. No reading:
|
|
11
|
+
* costUsd 0, "unpriced", baseline kept.
|
|
12
|
+
*/
|
|
13
|
+
import type { PromptResponse } from "@agentclientprotocol/sdk";
|
|
14
|
+
import type { TokenUsage, TurnEvent } from "@nathapp/nax-agent";
|
|
15
|
+
export interface TurnCost {
|
|
16
|
+
readonly costUsd: number;
|
|
17
|
+
readonly costSource: "reported" | "unpriced";
|
|
18
|
+
}
|
|
19
|
+
export interface TurnSpend extends TurnCost {
|
|
20
|
+
readonly tokenUsage: TokenUsage;
|
|
21
|
+
}
|
|
22
|
+
export interface CostMeter {
|
|
23
|
+
/** Starts a turn: forgets readings of a turn that never settled. */
|
|
24
|
+
beginTurn(): void;
|
|
25
|
+
/** A usage_update's `cost`: kept when it is a finite, non-negative USD amount. */
|
|
26
|
+
observe(cost: unknown): void;
|
|
27
|
+
/** The turn's cost; a priced turn moves the baseline to its latest reading. */
|
|
28
|
+
settle(): TurnCost;
|
|
29
|
+
/** The reading the next priced turn is measured from (D6-a). */
|
|
30
|
+
baseline(): number;
|
|
31
|
+
}
|
|
32
|
+
export declare function tokenUsageOf(usage: unknown): TokenUsage;
|
|
33
|
+
/** `initialBaseline`: the stored reading of a resumed session; anything but a finite, non-negative number is 0. */
|
|
34
|
+
export declare function createCostMeter(initialBaseline?: number): CostMeter;
|
|
35
|
+
export declare function turnSpend(response: PromptResponse, meter: CostMeter): TurnSpend;
|
|
36
|
+
export declare function usageEvent(spend: TurnSpend): TurnEvent;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { isRecord } from "#src/client/text";
|
|
2
|
+
const UNPRICED = Object.freeze({ costUsd: 0, costSource: "unpriced" });
|
|
3
|
+
function count(value) {
|
|
4
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : undefined;
|
|
5
|
+
}
|
|
6
|
+
function usdAmount(cost) {
|
|
7
|
+
if (!isRecord(cost) || typeof cost.amount !== "number" || typeof cost.currency !== "string")
|
|
8
|
+
return undefined;
|
|
9
|
+
if (cost.currency.trim().toUpperCase() !== "USD")
|
|
10
|
+
return undefined;
|
|
11
|
+
return Number.isFinite(cost.amount) && cost.amount >= 0 ? cost.amount : undefined;
|
|
12
|
+
}
|
|
13
|
+
export function tokenUsageOf(usage) {
|
|
14
|
+
if (!isRecord(usage))
|
|
15
|
+
return { inputTokens: 0, outputTokens: 0 };
|
|
16
|
+
const cacheRead = count(usage.cachedReadTokens);
|
|
17
|
+
const cacheWrite = count(usage.cachedWriteTokens);
|
|
18
|
+
return {
|
|
19
|
+
inputTokens: count(usage.inputTokens) ?? 0,
|
|
20
|
+
outputTokens: (count(usage.outputTokens) ?? 0) + (count(usage.thoughtTokens) ?? 0),
|
|
21
|
+
...(cacheRead === undefined ? {} : { cacheReadTokens: cacheRead }),
|
|
22
|
+
...(cacheWrite === undefined ? {} : { cacheWriteTokens: cacheWrite }),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** `initialBaseline`: the stored reading of a resumed session; anything but a finite, non-negative number is 0. */
|
|
26
|
+
export function createCostMeter(initialBaseline = 0) {
|
|
27
|
+
let baseline = Number.isFinite(initialBaseline) && initialBaseline >= 0 ? initialBaseline : 0;
|
|
28
|
+
let latest;
|
|
29
|
+
return {
|
|
30
|
+
beginTurn() {
|
|
31
|
+
latest = undefined;
|
|
32
|
+
},
|
|
33
|
+
observe(cost) {
|
|
34
|
+
const amount = usdAmount(cost);
|
|
35
|
+
if (amount !== undefined)
|
|
36
|
+
latest = amount;
|
|
37
|
+
},
|
|
38
|
+
settle() {
|
|
39
|
+
if (latest === undefined)
|
|
40
|
+
return UNPRICED;
|
|
41
|
+
const reading = latest;
|
|
42
|
+
const delta = reading - baseline;
|
|
43
|
+
baseline = reading;
|
|
44
|
+
latest = undefined;
|
|
45
|
+
return { costUsd: delta < 0 ? reading : delta, costSource: "reported" };
|
|
46
|
+
},
|
|
47
|
+
baseline: () => baseline,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export function turnSpend(response, meter) {
|
|
51
|
+
return { tokenUsage: tokenUsageOf(response.usage), ...meter.settle() };
|
|
52
|
+
}
|
|
53
|
+
export function usageEvent(spend) {
|
|
54
|
+
const { tokenUsage } = spend;
|
|
55
|
+
return {
|
|
56
|
+
type: "usage",
|
|
57
|
+
round: 0,
|
|
58
|
+
inputTokens: tokenUsage.inputTokens,
|
|
59
|
+
outputTokens: tokenUsage.outputTokens,
|
|
60
|
+
...(tokenUsage.cacheReadTokens === undefined ? {} : { cacheRead: tokenUsage.cacheReadTokens }),
|
|
61
|
+
...(tokenUsage.cacheWriteTokens === undefined ? {} : { cacheWrite: tokenUsage.cacheWriteTokens }),
|
|
62
|
+
costUsd: spend.costUsd,
|
|
63
|
+
costSource: spend.costSource,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nathapp/nax-agent-acp",
|
|
3
|
+
"version": "0.3.0",
|
|
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
|
+
"license": "MIT",
|
|
6
|
+
"author": "William Khoo",
|
|
7
|
+
"homepage": "https://github.com/nathapp-io/nax/tree/main/packages/nax-agent-acp",
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/nathapp-io/nax/issues"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"acp",
|
|
13
|
+
"agent-client-protocol",
|
|
14
|
+
"coding-agent",
|
|
15
|
+
"claude-code",
|
|
16
|
+
"nax"
|
|
17
|
+
],
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/nathapp-io/nax.git",
|
|
21
|
+
"directory": "packages/nax-agent-acp"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"exports": {
|
|
25
|
+
"./client": {
|
|
26
|
+
"types": "./dist/client/index.d.ts",
|
|
27
|
+
"import": "./dist/client/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./server": {
|
|
30
|
+
"types": "./dist/server/index.d.ts",
|
|
31
|
+
"import": "./dist/server/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"imports": {
|
|
35
|
+
"#src/*": {
|
|
36
|
+
"types": "./dist/*.d.ts",
|
|
37
|
+
"default": "./dist/*.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=22.19.0"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@agentclientprotocol/sdk": "~1.7.0",
|
|
45
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
46
|
+
"zod": "^4.3.6"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"@nathapp/nax-agent": "^0.3.0"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public",
|
|
53
|
+
"registry": "https://registry.npmjs.org/",
|
|
54
|
+
"provenance": false,
|
|
55
|
+
"tag": "latest"
|
|
56
|
+
}
|
|
57
|
+
}
|