@agen-ai/provider-acp 0.4.0 → 0.4.2
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/README.md +515 -12
- package/dist/capabilities.d.ts +3 -1
- package/dist/capabilities.js +5 -4
- package/dist/configuration/catalog.js +0 -2
- package/dist/configuration/errors.js +0 -1
- package/dist/connection/contracts.d.ts +24 -1
- package/dist/connection/errors.js +0 -1
- package/dist/connection/initialize.d.ts +7 -3
- package/dist/connection/initialize.js +64 -19
- package/dist/connection/negotiation.d.ts +3 -1
- package/dist/connection/negotiation.js +22 -1
- package/dist/contracts.d.ts +3 -0
- package/dist/driver.d.ts +1 -1
- package/dist/driver.js +6 -39
- package/dist/driverFactory.d.ts +8 -0
- package/dist/driverFactory.js +48 -0
- package/dist/host/interactions.d.ts +6 -1
- package/dist/host/interactions.js +42 -17
- package/dist/host/leases.js +0 -1
- package/dist/host/router.d.ts +3 -2
- package/dist/host/router.js +23 -21
- package/dist/host/terminals.js +0 -2
- package/dist/index.d.ts +1 -0
- package/dist/instance.d.ts +7 -2
- package/dist/instance.js +113 -28
- package/dist/node/contracts.d.ts +6 -0
- package/dist/node/execution/errors.d.ts +11 -0
- package/dist/node/execution/errors.js +17 -0
- package/dist/node/execution/owner.d.ts +34 -0
- package/dist/node/execution/owner.js +162 -0
- package/dist/node/execution/types.d.ts +20 -0
- package/dist/node/execution/types.js +0 -0
- package/dist/node/index.d.ts +3 -1
- package/dist/node/index.js +16 -6
- package/dist/node/launch.d.ts +5 -8
- package/dist/node/launch.js +13 -1
- package/dist/permissions/contracts.d.ts +22 -0
- package/dist/permissions/contracts.js +0 -0
- package/dist/permissions/mapping.d.ts +13 -0
- package/dist/permissions/mapping.js +99 -0
- package/dist/permissions/selection.d.ts +5 -0
- package/dist/permissions/selection.js +96 -0
- package/dist/session/continuation.d.ts +33 -0
- package/dist/session/continuation.js +185 -0
- package/dist/session/create.d.ts +7 -1
- package/dist/session/create.js +3 -1
- package/dist/session/descendants.d.ts +29 -0
- package/dist/session/descendants.js +97 -0
- package/dist/session/errors.js +0 -1
- package/dist/session/mapping.d.ts +6 -0
- package/dist/session/mapping.js +5 -26
- package/dist/session/native.d.ts +1 -0
- package/dist/session/native.js +8 -0
- package/dist/session/opening.d.ts +1 -0
- package/dist/session/opening.js +3 -1
- package/dist/session/queue.js +0 -1
- package/dist/session/requests/elicitation.d.ts +1 -1
- package/dist/session/requests/elicitation.js +1 -1
- package/dist/session/requests/forms.js +0 -2
- package/dist/session/requests/grokWithdrawals.d.ts +28 -0
- package/dist/session/requests/grokWithdrawals.js +135 -0
- package/dist/session/requests/pending.d.ts +17 -4
- package/dist/session/requests/pending.js +63 -8
- package/dist/session/requests/resolution.js +4 -2
- package/dist/session/resources.js +5 -3
- package/dist/session/session.d.ts +12 -1
- package/dist/session/session.js +197 -47
- package/dist/session/turn.d.ts +6 -1
- package/dist/sessionInteractions/broker.d.ts +50 -0
- package/dist/sessionInteractions/broker.js +193 -0
- package/dist/sessionInteractions/contracts.d.ts +3 -0
- package/dist/sessionInteractions/contracts.js +0 -0
- package/dist/sessionInteractions/extensions.d.ts +4 -0
- package/dist/sessionInteractions/extensions.js +37 -0
- package/dist/sessionInteractions/grokFolderTrust.d.ts +42 -0
- package/dist/sessionInteractions/grokFolderTrust.js +106 -0
- package/dist/sessionInteractions/grokPlanReview.d.ts +16 -0
- package/dist/sessionInteractions/grokPlanReview.js +63 -0
- package/dist/sessionInteractions/request.d.ts +46 -0
- package/dist/sessionInteractions/request.js +173 -0
- package/package.json +4 -4
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { AcpRequestError } from "@agen-ai/acp-transport";
|
|
2
|
+
import {
|
|
3
|
+
parseAgentSessionDecisionResponseFor,
|
|
4
|
+
parseAgentSessionPlanReviewResponseFor
|
|
5
|
+
} from "@agen-ai/agent-protocol";
|
|
6
|
+
import {
|
|
7
|
+
throwIfAgentOperationAborted
|
|
8
|
+
} from "@agen-ai/agent-runtime";
|
|
9
|
+
import { AcpProviderSessionError } from "../session/errors.js";
|
|
10
|
+
import { deferred } from "../session/queue.js";
|
|
11
|
+
import { nativePlanReviewReply } from "./grokPlanReview.js";
|
|
12
|
+
function sessionDecisionError(code, message) {
|
|
13
|
+
return Object.freeze({ category: "invalid_request", code, message, recovery: Object.freeze({ kind: "none" }) });
|
|
14
|
+
}
|
|
15
|
+
class NativeSessionDecision {
|
|
16
|
+
constructor(input) {
|
|
17
|
+
this.input = input;
|
|
18
|
+
const base = {
|
|
19
|
+
request: input.request,
|
|
20
|
+
signal: this.presentation.signal,
|
|
21
|
+
terminal: this.terminal.promise
|
|
22
|
+
};
|
|
23
|
+
this.handle = input.request.kind === "plan_review" ? Object.freeze({
|
|
24
|
+
...base,
|
|
25
|
+
kind: "prepared",
|
|
26
|
+
request: input.request,
|
|
27
|
+
prepareResponse: (response) => this.prepareResponse(response)
|
|
28
|
+
}) : Object.freeze({ ...base, kind: "direct", respond: (response) => this.respond(response) });
|
|
29
|
+
this.nativeReply = this.answer.promise;
|
|
30
|
+
void input.nativeContext.settled.then(() => {
|
|
31
|
+
this.nativeSettled = true;
|
|
32
|
+
this.maybeRetire();
|
|
33
|
+
});
|
|
34
|
+
void this.nativeReply.catch(() => {
|
|
35
|
+
});
|
|
36
|
+
if (input.hostDeadlineAt !== void 0) this.timer = setTimeout(() => this.expire(), Math.max(0, input.hostDeadlineAt - Date.now()));
|
|
37
|
+
input.nativeContext.signal.addEventListener("abort", this.onNativeAbort, { once: true });
|
|
38
|
+
}
|
|
39
|
+
handle;
|
|
40
|
+
nativeReply;
|
|
41
|
+
answer = deferred();
|
|
42
|
+
terminal = deferred();
|
|
43
|
+
presentation = new AbortController();
|
|
44
|
+
state = { kind: "pending" };
|
|
45
|
+
callback;
|
|
46
|
+
callbackSettled = true;
|
|
47
|
+
nativeSettled = false;
|
|
48
|
+
presented = false;
|
|
49
|
+
retired = false;
|
|
50
|
+
timer;
|
|
51
|
+
onNativeAbort = () => this.nativeAborted();
|
|
52
|
+
observeNativeSignal() {
|
|
53
|
+
if (this.input.nativeContext.signal.aborted) this.nativeAborted();
|
|
54
|
+
}
|
|
55
|
+
present(handler) {
|
|
56
|
+
if (this.presented || this.state.kind !== "pending") return;
|
|
57
|
+
this.observeNativeSignal();
|
|
58
|
+
if (this.state.kind !== "pending" || !this.input.accepting()) return;
|
|
59
|
+
if (this.input.hostDeadlineAt !== void 0 && Date.now() >= this.input.hostDeadlineAt) {
|
|
60
|
+
this.expire();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
this.presented = true;
|
|
64
|
+
this.callbackSettled = false;
|
|
65
|
+
let synchronousFailure;
|
|
66
|
+
try {
|
|
67
|
+
this.callback = Promise.resolve(handler(this.handle));
|
|
68
|
+
} catch (cause) {
|
|
69
|
+
synchronousFailure = { cause };
|
|
70
|
+
this.callback = Promise.reject(cause);
|
|
71
|
+
}
|
|
72
|
+
void this.callback.then(() => {
|
|
73
|
+
this.callbackSettled = true;
|
|
74
|
+
this.maybeRetire();
|
|
75
|
+
}, (cause) => {
|
|
76
|
+
this.callbackSettled = true;
|
|
77
|
+
this.input.fail(callbackError(cause));
|
|
78
|
+
this.maybeRetire();
|
|
79
|
+
});
|
|
80
|
+
if (synchronousFailure) this.input.fail(callbackError(synchronousFailure.cause));
|
|
81
|
+
}
|
|
82
|
+
stop(terminal, cause) {
|
|
83
|
+
if (this.state.kind === "terminal") return;
|
|
84
|
+
this.finalize(terminal);
|
|
85
|
+
this.answer.reject(cause);
|
|
86
|
+
}
|
|
87
|
+
finalize(terminal) {
|
|
88
|
+
if (this.state.kind === "terminal") return;
|
|
89
|
+
this.state = { kind: "terminal", terminal: Object.freeze(terminal) };
|
|
90
|
+
clearTimeout(this.timer);
|
|
91
|
+
this.input.nativeContext.signal.removeEventListener("abort", this.onNativeAbort);
|
|
92
|
+
this.terminal.resolve(this.state.terminal);
|
|
93
|
+
this.presentation.abort(new DOMException("The session decision is no longer answerable.", "AbortError"));
|
|
94
|
+
this.maybeRetire();
|
|
95
|
+
}
|
|
96
|
+
expire() {
|
|
97
|
+
if (this.state.kind === "terminal") return;
|
|
98
|
+
const cause = new AcpProviderSessionError("acp_session_interaction_expired", "The session decision expired before acceptance.");
|
|
99
|
+
this.stop(Object.freeze({ kind: "expired", source: "host_policy" }), cause);
|
|
100
|
+
this.input.fail(cause);
|
|
101
|
+
}
|
|
102
|
+
nativeAborted() {
|
|
103
|
+
if (this.state.kind === "terminal") return;
|
|
104
|
+
const reason = this.input.nativeContext.signal.reason;
|
|
105
|
+
if (reason instanceof AcpRequestError && reason.reasonCode === "acp_reverse_request_canceled" && reason.requestId === this.input.nativeContext.id) {
|
|
106
|
+
this.stop(Object.freeze({ kind: "withdrawn" }), reason);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
this.input.fail(reason instanceof Error ? reason : new AcpProviderSessionError(
|
|
110
|
+
"acp_session_interaction_native_failed",
|
|
111
|
+
"The native session decision producer stopped."
|
|
112
|
+
));
|
|
113
|
+
}
|
|
114
|
+
async respond(input) {
|
|
115
|
+
throwIfAgentOperationAborted(input.signal);
|
|
116
|
+
if (this.input.request.kind !== "decision") throw new TypeError("Plan review requires prepared response ownership.");
|
|
117
|
+
const response = parseAgentSessionDecisionResponseFor(this.input.request, { kind: input.kind, choiceId: input.choiceId });
|
|
118
|
+
this.observeNativeSignal();
|
|
119
|
+
if (this.input.hostDeadlineAt !== void 0 && Date.now() >= this.input.hostDeadlineAt) this.expire();
|
|
120
|
+
if (!this.input.accepting() || this.state.kind === "terminal") {
|
|
121
|
+
return Object.freeze({ status: "rejected", requestState: "unavailable", error: sessionDecisionError(
|
|
122
|
+
"session_interaction_unavailable",
|
|
123
|
+
"The session decision is no longer available."
|
|
124
|
+
) });
|
|
125
|
+
}
|
|
126
|
+
this.answer.resolve(Object.freeze({ outcome: response.choiceId === "grant" ? "trust" : "reject" }));
|
|
127
|
+
this.finalize(Object.freeze({ kind: "answered", response }));
|
|
128
|
+
return Object.freeze({ status: "delivered" });
|
|
129
|
+
}
|
|
130
|
+
prepareResponse(input) {
|
|
131
|
+
throwIfAgentOperationAborted(input.signal);
|
|
132
|
+
if (this.input.request.kind !== "plan_review" || !this.input.prepareContinuation) throw new TypeError("This request has no continuation mapping.");
|
|
133
|
+
const response = parseAgentSessionPlanReviewResponseFor(this.input.request, input.response);
|
|
134
|
+
return this.input.prepareContinuation({ response, signal: input.signal, nativeSettled: this.input.nativeContext.settled, dispatch: async () => {
|
|
135
|
+
throwIfAgentOperationAborted(input.signal);
|
|
136
|
+
this.observeNativeSignal();
|
|
137
|
+
if (this.input.hostDeadlineAt !== void 0 && Date.now() >= this.input.hostDeadlineAt) this.expire();
|
|
138
|
+
if (!this.input.accepting() || this.state.kind === "terminal") return Object.freeze({
|
|
139
|
+
status: "rejected",
|
|
140
|
+
requestState: "unavailable",
|
|
141
|
+
error: sessionDecisionError("session_interaction_unavailable", "The plan review is no longer available.")
|
|
142
|
+
});
|
|
143
|
+
this.answer.resolve(nativePlanReviewReply(response));
|
|
144
|
+
this.finalize(Object.freeze({ kind: "answered", response: Object.freeze({
|
|
145
|
+
kind: "plan_review",
|
|
146
|
+
action: response.action,
|
|
147
|
+
choiceId: response.choiceId,
|
|
148
|
+
planId: response.planId,
|
|
149
|
+
revision: response.revision
|
|
150
|
+
}) }));
|
|
151
|
+
return Object.freeze({ status: "delivered" });
|
|
152
|
+
} });
|
|
153
|
+
}
|
|
154
|
+
maybeRetire() {
|
|
155
|
+
if (this.retired || this.state.kind !== "terminal" || !this.nativeSettled || !this.callbackSettled) return;
|
|
156
|
+
this.retired = true;
|
|
157
|
+
this.input.retire();
|
|
158
|
+
}
|
|
159
|
+
async join() {
|
|
160
|
+
await Promise.allSettled([this.input.nativeContext.settled, ...this.callback ? [this.callback] : []]);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function callbackError(cause) {
|
|
164
|
+
return cause instanceof Error ? cause : new AcpProviderSessionError(
|
|
165
|
+
"acp_session_interaction_handler_failed",
|
|
166
|
+
"The session decision handler failed.",
|
|
167
|
+
{ cause }
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
export {
|
|
171
|
+
NativeSessionDecision,
|
|
172
|
+
sessionDecisionError
|
|
173
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agen-ai/provider-acp",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Optional Agent Client Protocol provider for the AgenAI coding-agent runtime.",
|
|
6
6
|
"type": "module",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"./package.json": "./package.json"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@agen-ai/acp-transport": "^0.4.
|
|
31
|
-
"@agen-ai/agent-
|
|
32
|
-
"@agen-ai/agent-
|
|
30
|
+
"@agen-ai/acp-transport": "^0.4.2",
|
|
31
|
+
"@agen-ai/agent-runtime": "^0.4.2",
|
|
32
|
+
"@agen-ai/agent-protocol": "^0.4.2"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"tsup": "^8.5.0"
|