@noetic-tools/acp 2.0.0-next.1 → 2.0.0-next.3
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/dist/agents.d.ts +5 -0
- package/dist/agents.js +13 -1
- package/dist/bin.js +19 -2
- package/dist/client-adapters.d.ts +2 -2
- package/dist/client.d.ts +9 -2
- package/dist/client.js +40 -1
- package/dist/connection.d.ts +25 -2
- package/dist/connection.js +455 -36
- package/dist/define.d.ts +13 -0
- package/dist/define.js +122 -4
- package/dist/index.d.ts +1 -1
- package/dist/items.d.ts +1 -1
- package/dist/keeper/client.d.ts +93 -0
- package/dist/keeper/client.js +468 -0
- package/dist/keeper/main.d.ts +6 -0
- package/dist/keeper/main.js +31 -0
- package/dist/keeper/process.d.ts +24 -0
- package/dist/keeper/process.js +425 -0
- package/dist/keeper/protocol.d.ts +74 -0
- package/dist/keeper/protocol.js +108 -0
- package/dist/keeper/relay.d.ts +88 -0
- package/dist/keeper/relay.js +420 -0
- package/dist/mcp/node.d.ts +6 -1
- package/dist/mcp/node.js +4 -4
- package/dist/permission-channel.d.ts +5 -0
- package/dist/permission-channel.js +16 -1
- package/dist/runner/host.js +74 -16
- package/dist/runner/options.d.ts +2 -0
- package/dist/runner/options.js +2 -0
- package/dist/runner/protocol.d.ts +12 -0
- package/dist/runner/protocol.js +24 -0
- package/dist/runner/serve.d.ts +5 -0
- package/dist/runner/serve.js +93 -3
- package/dist/serve-events.d.ts +2 -0
- package/dist/serve-events.js +1 -0
- package/dist/serve-questions.d.ts +26 -0
- package/dist/serve-questions.js +105 -0
- package/dist/serve-types.d.ts +1 -1
- package/dist/serve.d.ts +2 -2
- package/dist/serve.js +10 -1
- package/dist/server.js +1 -1
- package/dist/stdio-process.d.ts +38 -0
- package/dist/stdio-process.js +214 -0
- package/dist/stdio.d.ts +50 -7
- package/dist/stdio.js +192 -52
- package/dist/tool-bridge.d.ts +9 -0
- package/dist/tool-bridge.js +5 -1
- package/dist/transport-loopback.d.ts +2 -2
- package/dist/transport-loopback.js +1 -1
- package/dist/turn.d.ts +3 -2
- package/dist/turn.js +22 -2
- package/dist/update-filter.d.ts +38 -0
- package/dist/update-filter.js +193 -0
- package/package.json +3 -3
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session updates newer than the protocol library.
|
|
3
|
+
*
|
|
4
|
+
* The SDK validates every `session/update` notification against the variants
|
|
5
|
+
* it knows and answers any other with `-32602 Invalid params`, dropping it. An
|
|
6
|
+
* agent built on a newer protocol revision would then lose data and log an
|
|
7
|
+
* error for normal traffic. This filter sits on the agent's byte stream before
|
|
8
|
+
* the SDK: a `session/update` whose variant the SDK does not know is handed to
|
|
9
|
+
* the host as it is and kept from the SDK. Every other line passes through
|
|
10
|
+
* byte-identical.
|
|
11
|
+
*/
|
|
12
|
+
import { frameworkCast } from '@noetic-tools/types';
|
|
13
|
+
/**
|
|
14
|
+
* Every variant the pinned SDK parses. A `Record` over the union, so a library
|
|
15
|
+
* bump that adds one fails to compile until it is listed here.
|
|
16
|
+
*/
|
|
17
|
+
const KNOWN = {
|
|
18
|
+
user_message_chunk: true,
|
|
19
|
+
agent_message_chunk: true,
|
|
20
|
+
agent_thought_chunk: true,
|
|
21
|
+
tool_call: true,
|
|
22
|
+
tool_call_update: true,
|
|
23
|
+
plan: true,
|
|
24
|
+
plan_update: true,
|
|
25
|
+
plan_removed: true,
|
|
26
|
+
available_commands_update: true,
|
|
27
|
+
current_mode_update: true,
|
|
28
|
+
config_option_update: true,
|
|
29
|
+
session_info_update: true,
|
|
30
|
+
usage_update: true,
|
|
31
|
+
notice: true,
|
|
32
|
+
compaction_update: true,
|
|
33
|
+
compaction_summary_chunk: true,
|
|
34
|
+
subagent_update: true,
|
|
35
|
+
session_message: true,
|
|
36
|
+
session_message_chunk: true,
|
|
37
|
+
};
|
|
38
|
+
function isKnown(kind) {
|
|
39
|
+
return Object.hasOwn(KNOWN, kind);
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region Helpers
|
|
43
|
+
function isRecord(value) {
|
|
44
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The notification when `line` is a `session/update` with a variant the SDK
|
|
48
|
+
* does not know; otherwise undefined.
|
|
49
|
+
*/
|
|
50
|
+
export function newerSessionUpdate(line) {
|
|
51
|
+
if (!line.includes('"session/update"')) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
let message;
|
|
55
|
+
try {
|
|
56
|
+
message = JSON.parse(line);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
if (!isRecord(message) || message.method !== 'session/update' || 'id' in message) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
const params = message.params;
|
|
65
|
+
if (!isRecord(params) || typeof params.sessionId !== 'string' || !isRecord(params.update)) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
const kind = params.update.sessionUpdate;
|
|
69
|
+
if (typeof kind !== 'string' || isKnown(kind)) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
// A variant from a newer protocol revision: the host's handlers treat an
|
|
73
|
+
// unknown `sessionUpdate` as opaque (the event bridge's `acp.<name>` event).
|
|
74
|
+
return frameworkCast(params);
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
/** Where an `elicitation/create`'s JSON-RPC id rides in its params, for the client. */
|
|
78
|
+
const REQUEST_ID_META = 'noetic.tools/requestId';
|
|
79
|
+
/**
|
|
80
|
+
* An agent's `elicitation/create` line with its JSON-RPC id copied into the
|
|
81
|
+
* params' `_meta`, or undefined for any other line. The SDK hands the client a
|
|
82
|
+
* request's params only; the id is what identifies the request across hosts,
|
|
83
|
+
* since a keeper asks a reattached host again with the agent's own id. Riding
|
|
84
|
+
* in the request itself, it cannot drift onto another request.
|
|
85
|
+
*/
|
|
86
|
+
export function tagElicitationRequest(line) {
|
|
87
|
+
if (!line.includes('"elicitation/create"')) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
let message;
|
|
91
|
+
try {
|
|
92
|
+
message = JSON.parse(line);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
if (!isRecord(message) || message.method !== 'elicitation/create' || !isRecord(message.params)) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
const id = message.id;
|
|
101
|
+
if (typeof id !== 'string' && typeof id !== 'number') {
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
const meta = isRecord(message.params._meta) ? message.params._meta : {};
|
|
105
|
+
return JSON.stringify({
|
|
106
|
+
...message,
|
|
107
|
+
params: {
|
|
108
|
+
...message.params,
|
|
109
|
+
_meta: {
|
|
110
|
+
...meta,
|
|
111
|
+
[REQUEST_ID_META]: id,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/** A request's params as the agent sent them, and the JSON-RPC id the stream tagged them with. */
|
|
117
|
+
export function untagElicitation(params) {
|
|
118
|
+
const meta = params._meta;
|
|
119
|
+
if (!meta || !Object.hasOwn(meta, REQUEST_ID_META)) {
|
|
120
|
+
return {
|
|
121
|
+
request: params,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const { [REQUEST_ID_META]: tagged, ...rest } = meta;
|
|
125
|
+
const requestId = typeof tagged === 'string' || typeof tagged === 'number' ? tagged : undefined;
|
|
126
|
+
const request = {
|
|
127
|
+
...params,
|
|
128
|
+
_meta: Object.keys(rest).length > 0 ? rest : undefined,
|
|
129
|
+
};
|
|
130
|
+
return {
|
|
131
|
+
request,
|
|
132
|
+
...(requestId === undefined
|
|
133
|
+
? {}
|
|
134
|
+
: {
|
|
135
|
+
requestId,
|
|
136
|
+
}),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region Public API
|
|
141
|
+
/**
|
|
142
|
+
* Pass the agent's stream through, handing `deliver` each `session/update`
|
|
143
|
+
* the SDK would reject for its variant instead of passing it on, and tagging
|
|
144
|
+
* each `elicitation/create` with its JSON-RPC id.
|
|
145
|
+
*/
|
|
146
|
+
export function divertNewerUpdates(readable, deliver) {
|
|
147
|
+
const decoder = new TextDecoder();
|
|
148
|
+
const encoder = new TextEncoder();
|
|
149
|
+
let carry = '';
|
|
150
|
+
const pass = (line, controller) => {
|
|
151
|
+
const tagged = tagElicitationRequest(line);
|
|
152
|
+
if (tagged !== undefined) {
|
|
153
|
+
controller.enqueue(encoder.encode(`${tagged}\n`));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const newer = newerSessionUpdate(line);
|
|
157
|
+
if (newer) {
|
|
158
|
+
deliver(newer);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
controller.enqueue(encoder.encode(`${line}\n`));
|
|
162
|
+
};
|
|
163
|
+
return readable.pipeThrough(new TransformStream({
|
|
164
|
+
transform(chunk, controller) {
|
|
165
|
+
carry += decoder.decode(chunk, {
|
|
166
|
+
stream: true,
|
|
167
|
+
});
|
|
168
|
+
let newline = carry.indexOf('\n');
|
|
169
|
+
while (newline >= 0) {
|
|
170
|
+
pass(carry.slice(0, newline), controller);
|
|
171
|
+
carry = carry.slice(newline + 1);
|
|
172
|
+
newline = carry.indexOf('\n');
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
flush(controller) {
|
|
176
|
+
const tail = carry + decoder.decode();
|
|
177
|
+
if (tail.length > 0) {
|
|
178
|
+
const tagged = tagElicitationRequest(tail);
|
|
179
|
+
if (tagged !== undefined) {
|
|
180
|
+
controller.enqueue(encoder.encode(tagged));
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const newer = newerSessionUpdate(tail);
|
|
184
|
+
if (newer) {
|
|
185
|
+
deliver(newer);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
controller.enqueue(encoder.encode(tail));
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
}));
|
|
192
|
+
}
|
|
193
|
+
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noetic-tools/acp",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Both directions of the Agent Client Protocol for Noetic. Drives any ACP-speaking coding agent (Claude Code, Codex, Gemini CLI, …) as a step, and serves a Noetic harness as an ACP agent for editors like Zed (toAcpAgent / serveAcp).",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@modelcontextprotocol/node": "2.1.2",
|
|
66
66
|
"@modelcontextprotocol/server": "2.4.0",
|
|
67
|
-
"@noetic-tools/types": "^3.19.0-next.
|
|
68
|
-
"@
|
|
67
|
+
"@noetic-tools/types": "^3.19.0-next.6",
|
|
68
|
+
"@agentclientprotocol/sdk": "1.9.0",
|
|
69
69
|
"ws": "8.22.1",
|
|
70
70
|
"zod": "^4.0.0"
|
|
71
71
|
},
|