@noetic-tools/acp 1.1.0 → 1.2.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/dist/permission-channel.d.ts +3 -3
- package/dist/serve-events.js +140 -115
- package/package.json +2 -2
|
@@ -44,10 +44,10 @@ export declare const AcpPermissionPromptSchema: z.ZodObject<{
|
|
|
44
44
|
optionId: z.ZodString;
|
|
45
45
|
name: z.ZodString;
|
|
46
46
|
kind: z.ZodEnum<{
|
|
47
|
-
allow_always: "allow_always";
|
|
48
47
|
allow_once: "allow_once";
|
|
49
|
-
|
|
48
|
+
allow_always: "allow_always";
|
|
50
49
|
reject_once: "reject_once";
|
|
50
|
+
reject_always: "reject_always";
|
|
51
51
|
}>;
|
|
52
52
|
}, z.core.$strip>>;
|
|
53
53
|
}, z.core.$strip>;
|
|
@@ -58,8 +58,8 @@ export declare const AcpPermissionReplySchema: z.ZodObject<{
|
|
|
58
58
|
requestId: z.ZodString;
|
|
59
59
|
decision: z.ZodEnum<{
|
|
60
60
|
allow: "allow";
|
|
61
|
-
cancel: "cancel";
|
|
62
61
|
deny: "deny";
|
|
62
|
+
cancel: "cancel";
|
|
63
63
|
}>;
|
|
64
64
|
optionId: z.ZodOptional<z.ZodString>;
|
|
65
65
|
reason: z.ZodOptional<z.ZodString>;
|
package/dist/serve-events.js
CHANGED
|
@@ -124,133 +124,31 @@ function readNestedUpdate(event) {
|
|
|
124
124
|
* `session/update` notifications, and return how the turn ended.
|
|
125
125
|
*/
|
|
126
126
|
export async function pumpTurnEvents(params) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const flushOpenCalls = async (status) => {
|
|
134
|
-
for (const toolCallId of openCalls) {
|
|
135
|
-
await notifyIfPrimary(params, primary, {
|
|
136
|
-
sessionUpdate: 'tool_call_update',
|
|
137
|
-
toolCallId,
|
|
138
|
-
status,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
openCalls.clear();
|
|
127
|
+
const state = {
|
|
128
|
+
params,
|
|
129
|
+
primary: false,
|
|
130
|
+
turnId: null,
|
|
131
|
+
argsByCallId: new Map(),
|
|
132
|
+
openCalls: new Set(),
|
|
142
133
|
};
|
|
134
|
+
let claimed = false;
|
|
143
135
|
for await (const event of params.events) {
|
|
144
136
|
if (!claimed) {
|
|
145
137
|
const claim = matchClaim(event, params.messageId);
|
|
146
138
|
if (claim.kind === 'ours') {
|
|
147
139
|
claimed = true;
|
|
148
|
-
primary = claim.primary;
|
|
149
|
-
turnId = claim.turnId;
|
|
140
|
+
state.primary = claim.primary;
|
|
141
|
+
state.turnId = claim.turnId;
|
|
150
142
|
}
|
|
151
143
|
continue;
|
|
152
144
|
}
|
|
153
145
|
if (event.source === 'sdk') {
|
|
154
|
-
|
|
155
|
-
await notifyIfPrimary(params, primary, textChunk('agent_message_chunk', event.data.delta));
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
if (event.type === 'response.reasoning.delta' && typeof event.data.delta === 'string') {
|
|
159
|
-
await notifyIfPrimary(params, primary, textChunk('agent_thought_chunk', event.data.delta));
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
const fc = readFunctionCallArgs(event);
|
|
163
|
-
if (fc) {
|
|
164
|
-
argsByCallId.set(fc.callId, fc.args);
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
const nested = readNestedUpdate(event);
|
|
168
|
-
if (nested) {
|
|
169
|
-
await notifyIfPrimary(params, primary, nested);
|
|
170
|
-
}
|
|
146
|
+
await handleSdkEvent(state, event);
|
|
171
147
|
continue;
|
|
172
148
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
openCalls.add(call.callId);
|
|
177
|
-
const presentation = params.present(call.name, call.callId, argsByCallId.get(call.callId));
|
|
178
|
-
await notifyIfPrimary(params, primary, {
|
|
179
|
-
sessionUpdate: 'tool_call',
|
|
180
|
-
toolCallId: call.callId,
|
|
181
|
-
title: presentation.title,
|
|
182
|
-
kind: presentation.kind,
|
|
183
|
-
status: presentation.status,
|
|
184
|
-
locations: presentation.locations,
|
|
185
|
-
rawInput: asRecord(argsByCallId.get(call.callId)),
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
continue;
|
|
189
|
-
}
|
|
190
|
-
if (hasEventName(event, 'tool_call_completed')) {
|
|
191
|
-
const call = readToolCall(event);
|
|
192
|
-
if (call) {
|
|
193
|
-
openCalls.delete(call.callId);
|
|
194
|
-
const output = typeof event.data.output === 'string' ? event.data.output : undefined;
|
|
195
|
-
await notifyIfPrimary(params, primary, {
|
|
196
|
-
sessionUpdate: 'tool_call_update',
|
|
197
|
-
toolCallId: call.callId,
|
|
198
|
-
status: event.data.error === true ? 'failed' : 'completed',
|
|
199
|
-
// The tool's output (or failure text) as renderable content — the
|
|
200
|
-
// spec's "completed with the output as content, failed carrying the
|
|
201
|
-
// error".
|
|
202
|
-
content: output !== undefined
|
|
203
|
-
? [
|
|
204
|
-
{
|
|
205
|
-
type: 'content',
|
|
206
|
-
content: {
|
|
207
|
-
type: 'text',
|
|
208
|
-
text: output,
|
|
209
|
-
},
|
|
210
|
-
},
|
|
211
|
-
]
|
|
212
|
-
: undefined,
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
217
|
-
if (hasEventName(event, 'turn_completed') && matchesTurn(event, turnId)) {
|
|
218
|
-
await flushOpenCalls('completed');
|
|
219
|
-
return {
|
|
220
|
-
kind: 'stop',
|
|
221
|
-
stopReason: 'end_turn',
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
if (hasEventName(event, 'turn_aborted') && matchesTurn(event, turnId)) {
|
|
225
|
-
await flushOpenCalls('failed');
|
|
226
|
-
// The typed error kind (spec 31 gate contract) classifies the abort;
|
|
227
|
-
// the session-level cancel flag covers aborts that carry no kind (a
|
|
228
|
-
// host-initiated harness.abort has only a reason string).
|
|
229
|
-
const errorKind = typeof event.data.errorKind === 'string' ? event.data.errorKind : undefined;
|
|
230
|
-
if (errorKind === 'cancelled' || params.cancelRequested()) {
|
|
231
|
-
return {
|
|
232
|
-
kind: 'stop',
|
|
233
|
-
stopReason: 'cancelled',
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
if (errorKind === 'model_refused') {
|
|
237
|
-
return {
|
|
238
|
-
kind: 'stop',
|
|
239
|
-
stopReason: 'refusal',
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
if (errorKind === 'budget_exceeded') {
|
|
243
|
-
// The closest wire vocabulary for a spent token budget — an editor
|
|
244
|
-
// renders it as a native budget stop instead of a generic error.
|
|
245
|
-
return {
|
|
246
|
-
kind: 'stop',
|
|
247
|
-
stopReason: 'max_tokens',
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
return {
|
|
251
|
-
kind: 'error',
|
|
252
|
-
message: typeof event.data.reason === 'string' ? event.data.reason : 'turn aborted',
|
|
253
|
-
};
|
|
149
|
+
const outcome = await handleFrameworkEvent(state, event);
|
|
150
|
+
if (outcome) {
|
|
151
|
+
return outcome;
|
|
254
152
|
}
|
|
255
153
|
}
|
|
256
154
|
// The stream ended without a boundary — the harness (or connection) is
|
|
@@ -261,6 +159,133 @@ export async function pumpTurnEvents(params) {
|
|
|
261
159
|
stopReason: 'cancelled',
|
|
262
160
|
};
|
|
263
161
|
}
|
|
162
|
+
async function flushOpenCalls(state, status) {
|
|
163
|
+
for (const toolCallId of state.openCalls) {
|
|
164
|
+
await notifyIfPrimary(state.params, state.primary, {
|
|
165
|
+
sessionUpdate: 'tool_call_update',
|
|
166
|
+
toolCallId,
|
|
167
|
+
status,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
state.openCalls.clear();
|
|
171
|
+
}
|
|
172
|
+
async function handleSdkEvent(state, event) {
|
|
173
|
+
const { params, primary } = state;
|
|
174
|
+
if (event.type === 'response.output_text.delta' && typeof event.data.delta === 'string') {
|
|
175
|
+
await notifyIfPrimary(params, primary, textChunk('agent_message_chunk', event.data.delta));
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (event.type === 'response.reasoning.delta' && typeof event.data.delta === 'string') {
|
|
179
|
+
await notifyIfPrimary(params, primary, textChunk('agent_thought_chunk', event.data.delta));
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const fc = readFunctionCallArgs(event);
|
|
183
|
+
if (fc) {
|
|
184
|
+
state.argsByCallId.set(fc.callId, fc.args);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const nested = readNestedUpdate(event);
|
|
188
|
+
if (nested) {
|
|
189
|
+
await notifyIfPrimary(params, primary, nested);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
async function handleToolCallStarted(state, event) {
|
|
193
|
+
const call = readToolCall(event);
|
|
194
|
+
if (!call) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
state.openCalls.add(call.callId);
|
|
198
|
+
const args = state.argsByCallId.get(call.callId);
|
|
199
|
+
const presentation = state.params.present(call.name, call.callId, args);
|
|
200
|
+
await notifyIfPrimary(state.params, state.primary, {
|
|
201
|
+
sessionUpdate: 'tool_call',
|
|
202
|
+
toolCallId: call.callId,
|
|
203
|
+
title: presentation.title,
|
|
204
|
+
kind: presentation.kind,
|
|
205
|
+
status: presentation.status,
|
|
206
|
+
locations: presentation.locations,
|
|
207
|
+
rawInput: asRecord(args),
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
async function handleToolCallCompleted(state, event) {
|
|
211
|
+
const call = readToolCall(event);
|
|
212
|
+
if (!call) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
state.openCalls.delete(call.callId);
|
|
216
|
+
const output = typeof event.data.output === 'string' ? event.data.output : undefined;
|
|
217
|
+
await notifyIfPrimary(state.params, state.primary, {
|
|
218
|
+
sessionUpdate: 'tool_call_update',
|
|
219
|
+
toolCallId: call.callId,
|
|
220
|
+
status: event.data.error === true ? 'failed' : 'completed',
|
|
221
|
+
// The tool's output (or failure text) as renderable content — the spec's
|
|
222
|
+
// "completed with the output as content, failed carrying the error".
|
|
223
|
+
content: output !== undefined
|
|
224
|
+
? [
|
|
225
|
+
{
|
|
226
|
+
type: 'content',
|
|
227
|
+
content: {
|
|
228
|
+
type: 'text',
|
|
229
|
+
text: output,
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
]
|
|
233
|
+
: undefined,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
async function handleTurnAborted(state, event) {
|
|
237
|
+
await flushOpenCalls(state, 'failed');
|
|
238
|
+
// The typed error kind (spec 31 gate contract) classifies the abort; the
|
|
239
|
+
// session-level cancel flag covers aborts that carry no kind (a
|
|
240
|
+
// host-initiated harness.abort has only a reason string).
|
|
241
|
+
const errorKind = typeof event.data.errorKind === 'string' ? event.data.errorKind : undefined;
|
|
242
|
+
if (errorKind === 'cancelled' || state.params.cancelRequested()) {
|
|
243
|
+
return {
|
|
244
|
+
kind: 'stop',
|
|
245
|
+
stopReason: 'cancelled',
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
if (errorKind === 'model_refused') {
|
|
249
|
+
return {
|
|
250
|
+
kind: 'stop',
|
|
251
|
+
stopReason: 'refusal',
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
if (errorKind === 'budget_exceeded') {
|
|
255
|
+
// The closest wire vocabulary for a spent token budget — an editor
|
|
256
|
+
// renders it as a native budget stop instead of a generic error.
|
|
257
|
+
return {
|
|
258
|
+
kind: 'stop',
|
|
259
|
+
stopReason: 'max_tokens',
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
kind: 'error',
|
|
264
|
+
message: typeof event.data.reason === 'string' ? event.data.reason : 'turn aborted',
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
/** Returns an outcome when the event is this turn's boundary; null otherwise. */
|
|
268
|
+
async function handleFrameworkEvent(state, event) {
|
|
269
|
+
if (hasEventName(event, 'tool_call_started')) {
|
|
270
|
+
await handleToolCallStarted(state, event);
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
if (hasEventName(event, 'tool_call_completed')) {
|
|
274
|
+
await handleToolCallCompleted(state, event);
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
if (hasEventName(event, 'turn_completed') && matchesTurn(event, state.turnId)) {
|
|
278
|
+
await flushOpenCalls(state, 'completed');
|
|
279
|
+
return {
|
|
280
|
+
kind: 'stop',
|
|
281
|
+
stopReason: 'end_turn',
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
if (hasEventName(event, 'turn_aborted') && matchesTurn(event, state.turnId)) {
|
|
285
|
+
return handleTurnAborted(state, event);
|
|
286
|
+
}
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
264
289
|
async function notifyIfPrimary(params, primary, update) {
|
|
265
290
|
if (!primary) {
|
|
266
291
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noetic-tools/acp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"zod": "^4.0.0"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@noetic-tools/types": "^3.
|
|
59
|
+
"@noetic-tools/types": "^3.6.0",
|
|
60
60
|
"@zed-industries/agent-client-protocol": "^0.4.5",
|
|
61
61
|
"zod": "^4.0.0"
|
|
62
62
|
},
|