@agentclientprotocol/codex-acp 2.5.1-preview.7 → 2.5.1-preview.9
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/index.js +193 -76
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -32522,6 +32522,7 @@ var AcpClientDelivery = class {
|
|
|
32522
32522
|
sessionRequests = /* @__PURE__ */ new Map();
|
|
32523
32523
|
closedSessions = /* @__PURE__ */ new Set();
|
|
32524
32524
|
urlElicitations = /* @__PURE__ */ new Map();
|
|
32525
|
+
sessionSetups = /* @__PURE__ */ new Map();
|
|
32525
32526
|
sendElicitationCompletion;
|
|
32526
32527
|
/** v2's direct send path shares URL scope tracking without routing back through its v1 view. */
|
|
32527
32528
|
setElicitationCompletionTransport(send) {
|
|
@@ -32534,9 +32535,56 @@ var AcpClientDelivery = class {
|
|
|
32534
32535
|
openSession(sessionId) {
|
|
32535
32536
|
this.closedSessions.delete(sessionId);
|
|
32536
32537
|
}
|
|
32538
|
+
/** A new session cannot open client UI until its setup response has been written. */
|
|
32539
|
+
beginSessionSetup(sessionId) {
|
|
32540
|
+
if (this.sessionSetups.has(sessionId)) return;
|
|
32541
|
+
let release;
|
|
32542
|
+
const ready = new Promise((resolve) => {
|
|
32543
|
+
release = resolve;
|
|
32544
|
+
});
|
|
32545
|
+
this.sessionSetups.set(sessionId, { ready, release });
|
|
32546
|
+
}
|
|
32547
|
+
sessionSetupReady(sessionId) {
|
|
32548
|
+
return this.sessionSetups.get(sessionId)?.ready ?? null;
|
|
32549
|
+
}
|
|
32550
|
+
captureSessionSetupRelease(sessionId) {
|
|
32551
|
+
const setup = this.sessionSetups.get(sessionId);
|
|
32552
|
+
return () => {
|
|
32553
|
+
if (setup && this.sessionSetups.get(sessionId) === setup) this.finishSessionSetup(sessionId);
|
|
32554
|
+
};
|
|
32555
|
+
}
|
|
32556
|
+
finishSessionSetup(sessionId) {
|
|
32557
|
+
const setup = this.sessionSetups.get(sessionId);
|
|
32558
|
+
this.sessionSetups.delete(sessionId);
|
|
32559
|
+
setup?.release();
|
|
32560
|
+
}
|
|
32561
|
+
waitForSessionSetup(sessionId, signal) {
|
|
32562
|
+
const ready = this.sessionSetupReady(sessionId);
|
|
32563
|
+
if (!ready) return null;
|
|
32564
|
+
return new Promise((resolve, reject) => {
|
|
32565
|
+
const cancelled = () => reject(RequestError.requestCancelled(void 0, `Session ${sessionId} setup was cancelled`));
|
|
32566
|
+
if (signal?.aborted) {
|
|
32567
|
+
cancelled();
|
|
32568
|
+
return;
|
|
32569
|
+
}
|
|
32570
|
+
signal?.addEventListener("abort", cancelled, { once: true });
|
|
32571
|
+
void ready.then(() => {
|
|
32572
|
+
signal?.removeEventListener("abort", cancelled);
|
|
32573
|
+
if (signal?.aborted || !this.canRequestSession(sessionId)) cancelled();
|
|
32574
|
+
else resolve();
|
|
32575
|
+
});
|
|
32576
|
+
});
|
|
32577
|
+
}
|
|
32578
|
+
disposeSessionSetups() {
|
|
32579
|
+
for (const sessionId of this.sessionSetups.keys()) {
|
|
32580
|
+
this.closedSessions.add(sessionId);
|
|
32581
|
+
this.cancelSessionRequests(sessionId);
|
|
32582
|
+
}
|
|
32583
|
+
}
|
|
32537
32584
|
/** Final teardown updates have been sent. Nothing else may publish for this session lifetime. */
|
|
32538
32585
|
closeSession(sessionId) {
|
|
32539
32586
|
this.closedSessions.add(sessionId);
|
|
32587
|
+
this.finishSessionSetup(sessionId);
|
|
32540
32588
|
for (const [id, scope] of this.urlElicitations) {
|
|
32541
32589
|
if (scope.sessionId === sessionId) this.urlElicitations.delete(id);
|
|
32542
32590
|
}
|
|
@@ -32590,10 +32638,11 @@ var AcpClientDelivery = class {
|
|
|
32590
32638
|
for (const controller of this.sessionRequests.get(sessionId) ?? []) {
|
|
32591
32639
|
controller.abort(RequestError.requestCancelled(void 0, `Session ${sessionId} is closing`));
|
|
32592
32640
|
}
|
|
32641
|
+
this.finishSessionSetup(sessionId);
|
|
32593
32642
|
}
|
|
32594
32643
|
sendRequest(method, params, options) {
|
|
32595
32644
|
const sessionId = clientRequestSessionId(method, params);
|
|
32596
|
-
return this.withElicitationRequest(method, params, () =>
|
|
32645
|
+
return sessionId === null ? this.withElicitationRequest(method, params, () => this.client.request(method, params, options)) : this.sendSessionRequest(sessionId, method, params, options);
|
|
32597
32646
|
}
|
|
32598
32647
|
/** Direct v2 requests and the shared v1-shaped path keep the same URL scope. */
|
|
32599
32648
|
withElicitationRequest(method, params, send) {
|
|
@@ -32623,7 +32672,13 @@ var AcpClientDelivery = class {
|
|
|
32623
32672
|
requests.add(controller);
|
|
32624
32673
|
const cancellationSignal = options?.cancellationSignal ? AbortSignal.any([options.cancellationSignal, controller.signal]) : controller.signal;
|
|
32625
32674
|
try {
|
|
32626
|
-
|
|
32675
|
+
const setup = this.waitForSessionSetup(sessionId, cancellationSignal);
|
|
32676
|
+
if (setup) await setup;
|
|
32677
|
+
return await this.withElicitationRequest(
|
|
32678
|
+
method,
|
|
32679
|
+
params,
|
|
32680
|
+
() => this.client.request(method, params, { ...options, cancellationSignal })
|
|
32681
|
+
);
|
|
32627
32682
|
} finally {
|
|
32628
32683
|
requests.delete(controller);
|
|
32629
32684
|
if (requests.size === 0) this.sessionRequests.delete(sessionId);
|
|
@@ -32679,8 +32734,12 @@ var AcpV2Connection = class {
|
|
|
32679
32734
|
if (sessionId !== null && this.sessionDelivery && !this.sessionDelivery.canRequestSession(sessionId)) {
|
|
32680
32735
|
return Promise.reject(RequestError.requestCancelled(void 0, `Session ${sessionId} is closing or closed`));
|
|
32681
32736
|
}
|
|
32682
|
-
const send = () =>
|
|
32683
|
-
|
|
32737
|
+
const send = () => {
|
|
32738
|
+
const request = () => client.request(method, params, options);
|
|
32739
|
+
return this.sessionDelivery?.withElicitationRequest(method, params, request) ?? request();
|
|
32740
|
+
};
|
|
32741
|
+
const setup = sessionId === null ? null : this.sessionDelivery?.waitForSessionSetup(sessionId, options?.cancellationSignal);
|
|
32742
|
+
return setup ? setup.then(send) : send();
|
|
32684
32743
|
}
|
|
32685
32744
|
};
|
|
32686
32745
|
}
|
|
@@ -40012,6 +40071,16 @@ function failure2(serverName, message) {
|
|
|
40012
40071
|
|
|
40013
40072
|
// src/mcp/McpSessionStartup.ts
|
|
40014
40073
|
var McpSessionStartup = class {
|
|
40074
|
+
constructor(connection, codexAcpClient, runWithProcessCheck, signIn, capabilities, isSessionOpen, waitForSessionSetup = () => null) {
|
|
40075
|
+
this.waitForSessionSetup = waitForSessionSetup;
|
|
40076
|
+
this.connection = connection;
|
|
40077
|
+
this.codexAcpClient = codexAcpClient;
|
|
40078
|
+
this.runWithProcessCheck = runWithProcessCheck;
|
|
40079
|
+
this.signIn = signIn;
|
|
40080
|
+
this.capabilities = capabilities;
|
|
40081
|
+
this.isSessionOpen = isSessionOpen;
|
|
40082
|
+
}
|
|
40083
|
+
waitForSessionSetup;
|
|
40015
40084
|
connection;
|
|
40016
40085
|
codexAcpClient;
|
|
40017
40086
|
runWithProcessCheck;
|
|
@@ -40020,14 +40089,6 @@ var McpSessionStartup = class {
|
|
|
40020
40089
|
/** True when the session is open and does not close. */
|
|
40021
40090
|
isSessionOpen;
|
|
40022
40091
|
pendingSessions = /* @__PURE__ */ new Map();
|
|
40023
|
-
constructor(connection, codexAcpClient, runWithProcessCheck, signIn, capabilities, isSessionOpen) {
|
|
40024
|
-
this.connection = connection;
|
|
40025
|
-
this.codexAcpClient = codexAcpClient;
|
|
40026
|
-
this.runWithProcessCheck = runWithProcessCheck;
|
|
40027
|
-
this.signIn = signIn;
|
|
40028
|
-
this.capabilities = capabilities;
|
|
40029
|
-
this.isSessionOpen = isSessionOpen;
|
|
40030
|
-
}
|
|
40031
40092
|
/**
|
|
40032
40093
|
* Starts the startup wait of the session and publishes the report when the startup ends.
|
|
40033
40094
|
* It returns a promise only when it waits for the startup, and returns null otherwise.
|
|
@@ -40055,6 +40116,9 @@ var McpSessionStartup = class {
|
|
|
40055
40116
|
this.pendingSessions.get(sessionId)?.abort.abort();
|
|
40056
40117
|
this.pendingSessions.delete(sessionId);
|
|
40057
40118
|
}
|
|
40119
|
+
dispose() {
|
|
40120
|
+
for (const sessionId of this.pendingSessions.keys()) this.close(sessionId);
|
|
40121
|
+
}
|
|
40058
40122
|
isPending(sessionId) {
|
|
40059
40123
|
return this.pendingSessions.has(sessionId);
|
|
40060
40124
|
}
|
|
@@ -40092,6 +40156,8 @@ var McpSessionStartup = class {
|
|
|
40092
40156
|
}
|
|
40093
40157
|
try {
|
|
40094
40158
|
const mcpStartup = await pendingStartup.startup;
|
|
40159
|
+
const setup = this.waitForSessionSetup(sessionId, pendingStartup.abort.signal);
|
|
40160
|
+
if (setup) await setup;
|
|
40095
40161
|
if (!this.isSessionOpen(sessionId) || this.pendingSessions.get(sessionId) !== pendingStartup) {
|
|
40096
40162
|
return;
|
|
40097
40163
|
}
|
|
@@ -40998,7 +41064,7 @@ var package_default = {
|
|
|
40998
41064
|
publishConfig: {
|
|
40999
41065
|
access: "public"
|
|
41000
41066
|
},
|
|
41001
|
-
version: "2.5.1-preview.
|
|
41067
|
+
version: "2.5.1-preview.9",
|
|
41002
41068
|
description: "",
|
|
41003
41069
|
main: "dist/index.js",
|
|
41004
41070
|
bin: {
|
|
@@ -49761,6 +49827,7 @@ var CodexAcpServer = class {
|
|
|
49761
49827
|
connection;
|
|
49762
49828
|
mcpServerSignIn;
|
|
49763
49829
|
clientDelivery;
|
|
49830
|
+
setupResponseOrdering = false;
|
|
49764
49831
|
/** ACP protocol version of the connection this agent serves, fixed by the protocol router. */
|
|
49765
49832
|
protocolVersion;
|
|
49766
49833
|
/** The v2 client handle; `null` on a v1 connection. */
|
|
@@ -49884,7 +49951,8 @@ var CodexAcpServer = class {
|
|
|
49884
49951
|
(operation) => this.runWithProcessCheck(operation),
|
|
49885
49952
|
this.mcpServerSignIn,
|
|
49886
49953
|
() => this.capabilities,
|
|
49887
|
-
(sessionId) => this.sessions.has(sessionId) && !this.sessionIsClosing(sessionId)
|
|
49954
|
+
(sessionId) => this.sessions.has(sessionId) && !this.sessionIsClosing(sessionId),
|
|
49955
|
+
(sessionId, signal) => this.clientDelivery.waitForSessionSetup(sessionId, signal)
|
|
49888
49956
|
);
|
|
49889
49957
|
this.defaultAuthRequest = defaultAuthRequest ?? null;
|
|
49890
49958
|
this.codexProcessState = codexProcessState ?? null;
|
|
@@ -49924,6 +49992,10 @@ var CodexAcpServer = class {
|
|
|
49924
49992
|
const state = this.sessions.get(sessionId);
|
|
49925
49993
|
return state ? this.subagentModels(state) : null;
|
|
49926
49994
|
};
|
|
49995
|
+
const setupReady = this.clientDelivery.sessionSetupReady(sessionId);
|
|
49996
|
+
const transition = this.sessions.get(sessionId)?.subagentTransition;
|
|
49997
|
+
const ready = setupReady ? Promise.all([setupReady, transition]).then(() => {
|
|
49998
|
+
}) : transition;
|
|
49927
49999
|
const router = this.usesStandardSubagents() ? new StandardSubagentEventRouter(
|
|
49928
50000
|
sessionId,
|
|
49929
50001
|
session,
|
|
@@ -49931,7 +50003,7 @@ var CodexAcpServer = class {
|
|
|
49931
50003
|
release,
|
|
49932
50004
|
this.capabilities,
|
|
49933
50005
|
replay,
|
|
49934
|
-
|
|
50006
|
+
ready,
|
|
49935
50007
|
(id) => this.codexAcpClient.appServerClient.runningTurnId(id),
|
|
49936
50008
|
models,
|
|
49937
50009
|
{
|
|
@@ -50000,13 +50072,30 @@ var CodexAcpServer = class {
|
|
|
50000
50072
|
check2();
|
|
50001
50073
|
return check2;
|
|
50002
50074
|
}
|
|
50003
|
-
|
|
50004
|
-
|
|
50005
|
-
|
|
50006
|
-
|
|
50007
|
-
|
|
50008
|
-
|
|
50009
|
-
}
|
|
50075
|
+
/** Direct method callers have no transport response-write boundary. */
|
|
50076
|
+
observeSessionSetupResponses() {
|
|
50077
|
+
this.setupResponseOrdering = true;
|
|
50078
|
+
return () => {
|
|
50079
|
+
this.mcpSessionStartup.dispose();
|
|
50080
|
+
this.clientDelivery.disposeSessionSetups();
|
|
50081
|
+
};
|
|
50082
|
+
}
|
|
50083
|
+
captureSessionCreationPublication(sessionId) {
|
|
50084
|
+
return this.clientDelivery.captureSessionSetupRelease(sessionId);
|
|
50085
|
+
}
|
|
50086
|
+
captureSessionSetupPublication(sessionId) {
|
|
50087
|
+
const session = this.sessions.get(sessionId);
|
|
50088
|
+
const release = this.clientDelivery.captureSessionSetupRelease(sessionId);
|
|
50089
|
+
return async () => {
|
|
50090
|
+
release();
|
|
50091
|
+
if (!session || this.sessions.get(sessionId) !== session || this.sessionIsClosing(sessionId)) return;
|
|
50092
|
+
const router = session.subagents;
|
|
50093
|
+
if (!(router instanceof StandardSubagentEventRouter)) return;
|
|
50094
|
+
this.codexAcpClient.redispatchSessionNotifications(sessionId, router.releaseReplay(), () => router.publishReplaySnapshots());
|
|
50095
|
+
await this.codexAcpClient.waitForSessionNotifications(sessionId).catch((error62) => {
|
|
50096
|
+
logger.error("Failed to release child traffic after session setup", error62);
|
|
50097
|
+
});
|
|
50098
|
+
};
|
|
50010
50099
|
}
|
|
50011
50100
|
async interruptStandardChildren(session) {
|
|
50012
50101
|
if (!(session.subagents instanceof StandardSubagentEventRouter)) return;
|
|
@@ -50536,6 +50625,7 @@ You have been logged out. Please try again.`);
|
|
|
50536
50625
|
const sessionMcpServers = this.resolveSessionMcpServers(requestedMcpServers, operation === "resume");
|
|
50537
50626
|
const currentModel = this.findCurrentModel(models, currentModelId);
|
|
50538
50627
|
const currentModelSupportsFast = modelSupportsFast(currentModel);
|
|
50628
|
+
if (this.setupResponseOrdering && operation !== "resume") this.clientDelivery.beginSessionSetup(sessionId);
|
|
50539
50629
|
const sessionState = {
|
|
50540
50630
|
sessionId,
|
|
50541
50631
|
currentModelId,
|
|
@@ -51698,7 +51788,11 @@ You have been logged out. Please try again.`);
|
|
|
51698
51788
|
modeId: _params.modeId
|
|
51699
51789
|
});
|
|
51700
51790
|
const sessionState = this.getSessionState(_params.sessionId);
|
|
51701
|
-
this.
|
|
51791
|
+
await this.applySessionConfigOption(sessionState, {
|
|
51792
|
+
sessionId: _params.sessionId,
|
|
51793
|
+
configId: MODE_CONFIG_ID,
|
|
51794
|
+
value: _params.modeId
|
|
51795
|
+
});
|
|
51702
51796
|
return {};
|
|
51703
51797
|
}
|
|
51704
51798
|
async setSessionConfigOption(params) {
|
|
@@ -51710,7 +51804,7 @@ You have been logged out. Please try again.`);
|
|
|
51710
51804
|
const sessionState = this.getSessionState(params.sessionId);
|
|
51711
51805
|
await this.applySessionConfigOption(sessionState, params);
|
|
51712
51806
|
return {
|
|
51713
|
-
configOptions: this.createSessionConfigOptions(
|
|
51807
|
+
configOptions: this.createSessionConfigOptions(this.getSessionState(params.sessionId))
|
|
51714
51808
|
};
|
|
51715
51809
|
}
|
|
51716
51810
|
async setSessionConfigOptionV2(params) {
|
|
@@ -51722,24 +51816,37 @@ You have been logged out. Please try again.`);
|
|
|
51722
51816
|
return { configOptions: toV2ConfigOptions(response.configOptions) };
|
|
51723
51817
|
}
|
|
51724
51818
|
async applySessionConfigOption(sessionState, params) {
|
|
51725
|
-
|
|
51726
|
-
|
|
51727
|
-
|
|
51728
|
-
|
|
51729
|
-
|
|
51730
|
-
|
|
51731
|
-
|
|
51732
|
-
|
|
51733
|
-
|
|
51734
|
-
|
|
51735
|
-
|
|
51736
|
-
|
|
51737
|
-
|
|
51738
|
-
|
|
51739
|
-
|
|
51740
|
-
|
|
51741
|
-
|
|
51742
|
-
|
|
51819
|
+
await this.updateSessionConfig(sessionState, async () => {
|
|
51820
|
+
switch (params.configId) {
|
|
51821
|
+
case FAST_MODE_CONFIG_ID:
|
|
51822
|
+
this.applyFastModeChange(sessionState, params);
|
|
51823
|
+
break;
|
|
51824
|
+
case MODE_CONFIG_ID:
|
|
51825
|
+
this.applyModeChange(sessionState, this.stringConfigValue(params));
|
|
51826
|
+
break;
|
|
51827
|
+
case COLLABORATION_MODE_CONFIG_ID:
|
|
51828
|
+
await this.applyCollaborationModeChange(sessionState, this.stringConfigValue(params));
|
|
51829
|
+
break;
|
|
51830
|
+
case MODEL_CONFIG_ID:
|
|
51831
|
+
this.applyModelChange(sessionState, this.stringConfigValue(params));
|
|
51832
|
+
break;
|
|
51833
|
+
case REASONING_EFFORT_CONFIG_ID:
|
|
51834
|
+
this.applyReasoningEffortChange(sessionState, this.stringConfigValue(params));
|
|
51835
|
+
break;
|
|
51836
|
+
default:
|
|
51837
|
+
throw RequestError.invalidParams();
|
|
51838
|
+
}
|
|
51839
|
+
});
|
|
51840
|
+
}
|
|
51841
|
+
async updateSessionConfig(sessionState, change) {
|
|
51842
|
+
const previous = JSON.stringify(this.createSessionConfigOptions(sessionState));
|
|
51843
|
+
await change();
|
|
51844
|
+
const configOptions = this.createSessionConfigOptions(sessionState);
|
|
51845
|
+
if (this.isSessionConfigEnabled() && this.sessions.get(sessionState.sessionId) === sessionState && JSON.stringify(configOptions) !== previous) {
|
|
51846
|
+
await new ACPSessionConnection(this.connection, sessionState.sessionId).update({
|
|
51847
|
+
sessionUpdate: "config_option_update",
|
|
51848
|
+
configOptions
|
|
51849
|
+
});
|
|
51743
51850
|
}
|
|
51744
51851
|
}
|
|
51745
51852
|
applyFastModeChange(sessionState, params) {
|
|
@@ -51804,20 +51911,15 @@ You have been logged out. Please try again.`);
|
|
|
51804
51911
|
* The session keeps its model when it can, the way a resumed thread keeps its own; see `createModelId`.
|
|
51805
51912
|
*/
|
|
51806
51913
|
async applyResumedModels(sessionState, client, resumed) {
|
|
51807
|
-
|
|
51808
|
-
|
|
51809
|
-
|
|
51810
|
-
|
|
51811
|
-
|
|
51812
|
-
|
|
51813
|
-
|
|
51814
|
-
|
|
51815
|
-
|
|
51816
|
-
await new ACPSessionConnection(this.connection, sessionState.sessionId).update({
|
|
51817
|
-
sessionUpdate: "config_option_update",
|
|
51818
|
-
configOptions: this.createSessionConfigOptions(sessionState)
|
|
51819
|
-
});
|
|
51820
|
-
}
|
|
51914
|
+
await this.updateSessionConfig(sessionState, () => {
|
|
51915
|
+
const { model, effort } = ModelId.fromString(sessionState.currentModelId);
|
|
51916
|
+
sessionState.availableModels = resumed.models;
|
|
51917
|
+
sessionState.currentModelId = client.createModelId(resumed.models, model, effort).toString();
|
|
51918
|
+
const currentModel = this.findCurrentModel(resumed.models, sessionState.currentModelId);
|
|
51919
|
+
sessionState.supportedReasoningEfforts = currentModel?.supportedReasoningEfforts ?? [];
|
|
51920
|
+
sessionState.supportedInputModalities = currentModel?.inputModalities ?? ["text", "image"];
|
|
51921
|
+
sessionState.currentModelSupportsFast = modelSupportsFast(currentModel);
|
|
51922
|
+
});
|
|
51821
51923
|
}
|
|
51822
51924
|
applyModelAndEffort(sessionState, model, effort) {
|
|
51823
51925
|
sessionState.currentModelId = ModelId.fromComponents(model, effort).toString();
|
|
@@ -51848,8 +51950,10 @@ You have been logged out. Please try again.`);
|
|
|
51848
51950
|
} else {
|
|
51849
51951
|
reasoningEffort = model.defaultReasoningEffort;
|
|
51850
51952
|
}
|
|
51851
|
-
sessionState
|
|
51852
|
-
|
|
51953
|
+
await this.updateSessionConfig(sessionState, () => {
|
|
51954
|
+
sessionState.availableModels = models;
|
|
51955
|
+
this.applyModelAndEffort(sessionState, model, reasoningEffort);
|
|
51956
|
+
});
|
|
51853
51957
|
return {};
|
|
51854
51958
|
}
|
|
51855
51959
|
parseLegacySetSessionModelParams(params) {
|
|
@@ -53632,11 +53736,6 @@ You have been logged out. Please try again.`);
|
|
|
53632
53736
|
configId,
|
|
53633
53737
|
value
|
|
53634
53738
|
});
|
|
53635
|
-
const session = new ACPSessionConnection(this.connection, sessionState.sessionId);
|
|
53636
|
-
await session.update({
|
|
53637
|
-
sessionUpdate: "config_option_update",
|
|
53638
|
-
configOptions: this.createSessionConfigOptions(sessionState)
|
|
53639
|
-
});
|
|
53640
53739
|
}
|
|
53641
53740
|
});
|
|
53642
53741
|
void commandPromise.catch((err) => {
|
|
@@ -53805,11 +53904,10 @@ You have been logged out. Please try again.`);
|
|
|
53805
53904
|
return cancelledPromptResponse();
|
|
53806
53905
|
}
|
|
53807
53906
|
if (approved && !this.promptShouldStop(params.sessionId, activePrompt)) {
|
|
53808
|
-
await this.
|
|
53809
|
-
|
|
53810
|
-
|
|
53811
|
-
|
|
53812
|
-
configOptions: this.createSessionConfigOptions(sessionState)
|
|
53907
|
+
await this.applySessionConfigOption(sessionState, {
|
|
53908
|
+
sessionId: sessionState.sessionId,
|
|
53909
|
+
configId: COLLABORATION_MODE_CONFIG_ID,
|
|
53910
|
+
value: DEFAULT_COLLABORATION_MODE
|
|
53813
53911
|
});
|
|
53814
53912
|
const implementationRequest = {
|
|
53815
53913
|
sessionId: params.sessionId,
|
|
@@ -54449,7 +54547,7 @@ var AcpResponseDelivery = class {
|
|
|
54449
54547
|
if ("method" in message || message.id === null) return;
|
|
54450
54548
|
const callback = this.callbacks.get(message.id);
|
|
54451
54549
|
this.callbacks.delete(message.id);
|
|
54452
|
-
callback?.();
|
|
54550
|
+
callback?.("result" in message);
|
|
54453
54551
|
},
|
|
54454
54552
|
close: async () => {
|
|
54455
54553
|
const writer = stream.writable.getWriter();
|
|
@@ -54542,7 +54640,15 @@ function createRouter(createAgent, responses) {
|
|
|
54542
54640
|
const setups = /* @__PURE__ */ new Map();
|
|
54543
54641
|
const setup = (sessionId, requestId, operation, signal) => {
|
|
54544
54642
|
const agent3 = getAgent({ sessionId });
|
|
54545
|
-
if (!agent3.usesStandardSubagents())
|
|
54643
|
+
if (!agent3.usesStandardSubagents()) {
|
|
54644
|
+
return operation().then((result) => {
|
|
54645
|
+
const publish = agent3.captureSessionSetupPublication(sessionId);
|
|
54646
|
+
responses.afterWrite(requestId, (successful) => {
|
|
54647
|
+
if (successful) void publish();
|
|
54648
|
+
});
|
|
54649
|
+
return result;
|
|
54650
|
+
});
|
|
54651
|
+
}
|
|
54546
54652
|
const assertCurrent = agent3.captureSessionSetup(sessionId);
|
|
54547
54653
|
const state = setups.get(sessionId) ?? { tail: Promise.resolve(), publication: Promise.resolve(), epoch: 0, pending: 0 };
|
|
54548
54654
|
setups.set(sessionId, state);
|
|
@@ -54560,7 +54666,7 @@ function createRouter(createAgent, responses) {
|
|
|
54560
54666
|
state.tail = state.tail.catch(() => {
|
|
54561
54667
|
}).then(async () => {
|
|
54562
54668
|
let registered = false;
|
|
54563
|
-
let
|
|
54669
|
+
let publish = null;
|
|
54564
54670
|
try {
|
|
54565
54671
|
for (; ; ) {
|
|
54566
54672
|
const publication = state.publication;
|
|
@@ -54569,14 +54675,14 @@ function createRouter(createAgent, responses) {
|
|
|
54569
54675
|
}
|
|
54570
54676
|
if (signal.aborted) throw new RequestError(-32800, "Session setup was cancelled");
|
|
54571
54677
|
assertCurrent();
|
|
54572
|
-
responses.afterWrite(requestId, () => {
|
|
54573
|
-
if (epoch === state.epoch &&
|
|
54678
|
+
responses.afterWrite(requestId, (successful) => {
|
|
54679
|
+
if (successful && epoch === state.epoch && publish) state.publication = publish();
|
|
54574
54680
|
void state.publication.then(finish, finish);
|
|
54575
54681
|
});
|
|
54576
54682
|
registered = true;
|
|
54577
54683
|
const result = await operation();
|
|
54578
54684
|
if (signal.aborted) throw new RequestError(-32800, "Session setup was cancelled");
|
|
54579
|
-
|
|
54685
|
+
publish = agent3.captureSessionSetupPublication(sessionId);
|
|
54580
54686
|
resolve(result);
|
|
54581
54687
|
} catch (error62) {
|
|
54582
54688
|
reject(error62);
|
|
@@ -54585,18 +54691,29 @@ function createRouter(createAgent, responses) {
|
|
|
54585
54691
|
});
|
|
54586
54692
|
return response;
|
|
54587
54693
|
};
|
|
54694
|
+
const createdSetup = async (requestId, operation) => {
|
|
54695
|
+
const agent3 = getAgent();
|
|
54696
|
+
const result = await operation();
|
|
54697
|
+
const publish = agent3.captureSessionCreationPublication(result.sessionId);
|
|
54698
|
+
responses.afterWrite(requestId, (successful) => {
|
|
54699
|
+
if (successful) publish();
|
|
54700
|
+
});
|
|
54701
|
+
return result;
|
|
54702
|
+
};
|
|
54588
54703
|
const attachAgent = (agent3, signal) => {
|
|
54589
54704
|
codexAcpServer = agent3;
|
|
54705
|
+
const stopSetupPublication = agent3.observeSessionSetupResponses();
|
|
54590
54706
|
signal.addEventListener("abort", () => {
|
|
54591
54707
|
setups.clear();
|
|
54708
|
+
stopSetupPublication();
|
|
54592
54709
|
agent3.sessionIndex.dispose();
|
|
54593
54710
|
if (codexAcpServer === agent3) {
|
|
54594
54711
|
codexAcpServer = null;
|
|
54595
54712
|
}
|
|
54596
54713
|
});
|
|
54597
54714
|
};
|
|
54598
|
-
const v1Agent = agent({ name: package_default.name }).onConnect((connection) => attachAgent(createAgent(connection.client), connection.signal)).onRequest(methods.agent.initialize, (ctx) => getAgent().initialize(ctx.params)).onRequest(methods.agent.session.new, (ctx) => getAgentForPaths(ctx.params).newSession(ctx.params)).onRequest(methods.agent.session.load, (ctx) => setup(ctx.params.sessionId, ctx.requestId, () => getAgentForPaths(ctx.params).loadSession(ctx.params), ctx.signal)).onRequest(methods.agent.session.fork, (ctx) => getAgentForPaths(ctx.params).forkSession(ctx.params)).onRequest(methods.agent.session.list, (ctx) => getAgentForPaths({ cwd: ctx.params.cwd ?? null }).listSessions(ctx.params)).onRequest(methods.agent.session.delete, (ctx) => getAgent(ctx.params).deleteSession(ctx.params)).onRequest(methods.agent.session.resume, (ctx) => setup(ctx.params.sessionId, ctx.requestId, () => getAgentForPaths(ctx.params).resumeSession(ctx.params), ctx.signal)).onRequest(methods.agent.session.close, (ctx) => getAgent(ctx.params).closeSession(ctx.params)).onRequest(methods.agent.session.setMode, (ctx) => getAgent(ctx.params).setSessionMode(ctx.params)).onRequest(methods.agent.session.setConfigOption, (ctx) => getAgent(ctx.params).setSessionConfigOption(ctx.params)).onRequest(methods.agent.authenticate, (ctx) => getAgent().authenticate(ctx.params, ctx.requestId)).onRequest(methods.agent.logout, (ctx) => getAgent().logout(ctx.params)).onRequest(methods.agent.providers.list, (ctx) => getAgent().listProviders(ctx.params)).onRequest(methods.agent.providers.set, (ctx) => getAgent().setProvider(ctx.params)).onRequest(methods.agent.providers.disable, (ctx) => getAgent().disableProvider(ctx.params)).onRequest(methods.agent.session.prompt, (ctx) => getAgent(ctx.params).prompt(ctx.params, ctx.signal)).onNotification(methods.agent.session.cancel, (ctx) => getAgent().cancel(ctx.params)).onRequest("authentication/status", emptyExtensionParamsParser, (ctx) => getAgent().extMethod("authentication/status", ctx.params)).onRequest("authentication/logout", emptyExtensionParamsParser, (ctx) => getAgent().extMethod("authentication/logout", ctx.params)).onRequest(LEGACY_SET_SESSION_MODEL_METHOD, legacySetSessionModelParamsParser, (ctx) => getAgent(ctx.params).extMethod(LEGACY_SET_SESSION_MODEL_METHOD, ctx.params)).onRequest(SESSION_STEERING_METHOD, sessionSteerParamsParser, (ctx) => getAgent(ctx.params).extMethod(SESSION_STEERING_METHOD, ctx.params)).onRequest(ASYNC_TASK_STOP_METHOD, asyncTaskStopParamsParser, (ctx) => getAgent(ctx.params).extMethod(ASYNC_TASK_STOP_METHOD, ctx.params)).onRequest(CODEX_HOOKS_LIST_METHOD, hooksListParamsParser, (ctx) => getAgent().listHooks(ctx.params.cwd)).onRequest(CODEX_HOOKS_TRUST_METHOD, hooksTrustParamsParser, (ctx) => getAgent().trustHooks(ctx.params.cwd, ctx.params.hooks)).onRequest(GOAL_CONTROL_METHOD, goalControlParamsParser, (ctx) => getAgent(ctx.params).extMethod(GOAL_CONTROL_METHOD, ctx.params)).onRequest(SESSION_RENAME_METHOD, sessionRenameParamsParser, (ctx) => getAgent(ctx.params).sessionIndex.rename(ctx.params)).onRequest(SESSION_BATCH_GET_METHOD, sessionBatchGetParamsParser, (ctx) => getAgent().sessionIndex.batchGet(ctx.params)).onRequest(SESSION_ARCHIVE_METHOD, sessionArchiveParamsParser, (ctx) => getAgent(ctx.params).sessionIndex.setArchived(ctx.params, true)).onRequest(SESSION_UNARCHIVE_METHOD, sessionArchiveParamsParser, (ctx) => getAgent(ctx.params).sessionIndex.setArchived(ctx.params, false)).onRequest(SESSION_LIST_SUBSCRIBE_METHOD, sessionListSubscriptionParamsParser, (ctx) => getAgent().sessionIndex.subscribeList(ctx.params)).onRequest(SESSION_LIST_UNSUBSCRIBE_METHOD, sessionListSubscriptionParamsParser, (ctx) => getAgent().sessionIndex.unsubscribeList(ctx.params));
|
|
54599
|
-
const v2Agent = agent2({ name: package_default.name }).onConnect((connection) => attachAgent(createAgent(new AcpV2Connection(connection.client)), connection.signal)).onRequest(methods2.agent.initialize, (ctx) => getAgent().initializeV2(ctx.params)).onRequest(methods2.agent.session.new, (ctx) => getAgentForPaths(ctx.params).newSessionV2(ctx.params)).onRequest(methods2.agent.session.list, (ctx) => getAgentForPaths({ cwd: ctx.params.cwd ?? null }).listSessions(ctx.params)).onRequest(methods2.agent.session.delete, (ctx) => getAgent(ctx.params).deleteSession(ctx.params)).onRequest(methods2.agent.session.resume, (ctx) => setup(ctx.params.sessionId, ctx.requestId, () => getAgentForPaths(ctx.params).resumeSessionV2(ctx.params), ctx.signal)).onRequest(methods2.agent.session.fork, (ctx) => getAgentForPaths(ctx.params).forkSessionV2(ctx.params)).onRequest(methods2.agent.session.close, (ctx) => getAgent(ctx.params).closeSession(ctx.params)).onRequest(methods2.agent.session.setConfigOption, (ctx) => getAgent(ctx.params).setSessionConfigOptionV2(ctx.params)).onRequest(methods2.agent.auth.login, (ctx) => getAgent().authenticateV2(ctx.params, ctx.requestId)).onRequest(methods2.agent.auth.logout, (ctx) => getAgent().logoutV2(ctx.params)).onRequest(methods2.agent.session.prompt, (ctx) => getAgent(ctx.params).promptV2(ctx.params, ctx.signal)).onNotification(methods2.agent.session.cancel, (ctx) => getAgent().cancel(ctx.params)).onRequest(methods2.agent.providers.list, (ctx) => getAgent().listProviders(ctx.params)).onRequest(methods2.agent.providers.set, (ctx) => getAgent().setProvider(ctx.params)).onRequest(methods2.agent.providers.disable, (ctx) => getAgent().disableProvider(ctx.params)).onRequest(SESSION_STEERING_METHOD, sessionSteerParamsParser, (ctx) => getAgent(ctx.params).extMethod(SESSION_STEERING_METHOD, ctx.params)).onRequest(GOAL_CONTROL_METHOD, goalControlParamsParser, (ctx) => getAgent(ctx.params).extMethod(GOAL_CONTROL_METHOD, ctx.params)).onRequest(ASYNC_TASK_STOP_METHOD, asyncTaskStopParamsParser, (ctx) => getAgent(ctx.params).extMethod(ASYNC_TASK_STOP_METHOD, ctx.params)).onRequest(SESSION_RENAME_METHOD, sessionRenameParamsParser, (ctx) => getAgent(ctx.params).sessionIndex.rename(ctx.params)).onRequest(SESSION_BATCH_GET_METHOD, sessionBatchGetParamsParser, (ctx) => getAgent().sessionIndex.batchGet(ctx.params)).onRequest(SESSION_ARCHIVE_METHOD, sessionArchiveParamsParser, (ctx) => getAgent(ctx.params).sessionIndex.setArchived(ctx.params, true)).onRequest(SESSION_UNARCHIVE_METHOD, sessionArchiveParamsParser, (ctx) => getAgent(ctx.params).sessionIndex.setArchived(ctx.params, false)).onRequest(SESSION_LIST_SUBSCRIBE_METHOD, sessionListSubscriptionParamsParser, (ctx) => getAgent().sessionIndex.subscribeList(ctx.params)).onRequest(SESSION_LIST_UNSUBSCRIBE_METHOD, sessionListSubscriptionParamsParser, (ctx) => getAgent().sessionIndex.unsubscribeList(ctx.params));
|
|
54715
|
+
const v1Agent = agent({ name: package_default.name }).onConnect((connection) => attachAgent(createAgent(connection.client), connection.signal)).onRequest(methods.agent.initialize, (ctx) => getAgent().initialize(ctx.params)).onRequest(methods.agent.session.new, (ctx) => createdSetup(ctx.requestId, () => getAgentForPaths(ctx.params).newSession(ctx.params))).onRequest(methods.agent.session.load, (ctx) => setup(ctx.params.sessionId, ctx.requestId, () => getAgentForPaths(ctx.params).loadSession(ctx.params), ctx.signal)).onRequest(methods.agent.session.fork, (ctx) => createdSetup(ctx.requestId, () => getAgentForPaths(ctx.params).forkSession(ctx.params))).onRequest(methods.agent.session.list, (ctx) => getAgentForPaths({ cwd: ctx.params.cwd ?? null }).listSessions(ctx.params)).onRequest(methods.agent.session.delete, (ctx) => getAgent(ctx.params).deleteSession(ctx.params)).onRequest(methods.agent.session.resume, (ctx) => setup(ctx.params.sessionId, ctx.requestId, () => getAgentForPaths(ctx.params).resumeSession(ctx.params), ctx.signal)).onRequest(methods.agent.session.close, (ctx) => getAgent(ctx.params).closeSession(ctx.params)).onRequest(methods.agent.session.setMode, (ctx) => getAgent(ctx.params).setSessionMode(ctx.params)).onRequest(methods.agent.session.setConfigOption, (ctx) => getAgent(ctx.params).setSessionConfigOption(ctx.params)).onRequest(methods.agent.authenticate, (ctx) => getAgent().authenticate(ctx.params, ctx.requestId)).onRequest(methods.agent.logout, (ctx) => getAgent().logout(ctx.params)).onRequest(methods.agent.providers.list, (ctx) => getAgent().listProviders(ctx.params)).onRequest(methods.agent.providers.set, (ctx) => getAgent().setProvider(ctx.params)).onRequest(methods.agent.providers.disable, (ctx) => getAgent().disableProvider(ctx.params)).onRequest(methods.agent.session.prompt, (ctx) => getAgent(ctx.params).prompt(ctx.params, ctx.signal)).onNotification(methods.agent.session.cancel, (ctx) => getAgent().cancel(ctx.params)).onRequest("authentication/status", emptyExtensionParamsParser, (ctx) => getAgent().extMethod("authentication/status", ctx.params)).onRequest("authentication/logout", emptyExtensionParamsParser, (ctx) => getAgent().extMethod("authentication/logout", ctx.params)).onRequest(LEGACY_SET_SESSION_MODEL_METHOD, legacySetSessionModelParamsParser, (ctx) => getAgent(ctx.params).extMethod(LEGACY_SET_SESSION_MODEL_METHOD, ctx.params)).onRequest(SESSION_STEERING_METHOD, sessionSteerParamsParser, (ctx) => getAgent(ctx.params).extMethod(SESSION_STEERING_METHOD, ctx.params)).onRequest(ASYNC_TASK_STOP_METHOD, asyncTaskStopParamsParser, (ctx) => getAgent(ctx.params).extMethod(ASYNC_TASK_STOP_METHOD, ctx.params)).onRequest(CODEX_HOOKS_LIST_METHOD, hooksListParamsParser, (ctx) => getAgent().listHooks(ctx.params.cwd)).onRequest(CODEX_HOOKS_TRUST_METHOD, hooksTrustParamsParser, (ctx) => getAgent().trustHooks(ctx.params.cwd, ctx.params.hooks)).onRequest(GOAL_CONTROL_METHOD, goalControlParamsParser, (ctx) => getAgent(ctx.params).extMethod(GOAL_CONTROL_METHOD, ctx.params)).onRequest(SESSION_RENAME_METHOD, sessionRenameParamsParser, (ctx) => getAgent(ctx.params).sessionIndex.rename(ctx.params)).onRequest(SESSION_BATCH_GET_METHOD, sessionBatchGetParamsParser, (ctx) => getAgent().sessionIndex.batchGet(ctx.params)).onRequest(SESSION_ARCHIVE_METHOD, sessionArchiveParamsParser, (ctx) => getAgent(ctx.params).sessionIndex.setArchived(ctx.params, true)).onRequest(SESSION_UNARCHIVE_METHOD, sessionArchiveParamsParser, (ctx) => getAgent(ctx.params).sessionIndex.setArchived(ctx.params, false)).onRequest(SESSION_LIST_SUBSCRIBE_METHOD, sessionListSubscriptionParamsParser, (ctx) => getAgent().sessionIndex.subscribeList(ctx.params)).onRequest(SESSION_LIST_UNSUBSCRIBE_METHOD, sessionListSubscriptionParamsParser, (ctx) => getAgent().sessionIndex.unsubscribeList(ctx.params));
|
|
54716
|
+
const v2Agent = agent2({ name: package_default.name }).onConnect((connection) => attachAgent(createAgent(new AcpV2Connection(connection.client)), connection.signal)).onRequest(methods2.agent.initialize, (ctx) => getAgent().initializeV2(ctx.params)).onRequest(methods2.agent.session.new, (ctx) => createdSetup(ctx.requestId, () => getAgentForPaths(ctx.params).newSessionV2(ctx.params))).onRequest(methods2.agent.session.list, (ctx) => getAgentForPaths({ cwd: ctx.params.cwd ?? null }).listSessions(ctx.params)).onRequest(methods2.agent.session.delete, (ctx) => getAgent(ctx.params).deleteSession(ctx.params)).onRequest(methods2.agent.session.resume, (ctx) => setup(ctx.params.sessionId, ctx.requestId, () => getAgentForPaths(ctx.params).resumeSessionV2(ctx.params), ctx.signal)).onRequest(methods2.agent.session.fork, (ctx) => createdSetup(ctx.requestId, () => getAgentForPaths(ctx.params).forkSessionV2(ctx.params))).onRequest(methods2.agent.session.close, (ctx) => getAgent(ctx.params).closeSession(ctx.params)).onRequest(methods2.agent.session.setConfigOption, (ctx) => getAgent(ctx.params).setSessionConfigOptionV2(ctx.params)).onRequest(methods2.agent.auth.login, (ctx) => getAgent().authenticateV2(ctx.params, ctx.requestId)).onRequest(methods2.agent.auth.logout, (ctx) => getAgent().logoutV2(ctx.params)).onRequest(methods2.agent.session.prompt, (ctx) => getAgent(ctx.params).promptV2(ctx.params, ctx.signal)).onNotification(methods2.agent.session.cancel, (ctx) => getAgent().cancel(ctx.params)).onRequest(methods2.agent.providers.list, (ctx) => getAgent().listProviders(ctx.params)).onRequest(methods2.agent.providers.set, (ctx) => getAgent().setProvider(ctx.params)).onRequest(methods2.agent.providers.disable, (ctx) => getAgent().disableProvider(ctx.params)).onRequest(SESSION_STEERING_METHOD, sessionSteerParamsParser, (ctx) => getAgent(ctx.params).extMethod(SESSION_STEERING_METHOD, ctx.params)).onRequest(GOAL_CONTROL_METHOD, goalControlParamsParser, (ctx) => getAgent(ctx.params).extMethod(GOAL_CONTROL_METHOD, ctx.params)).onRequest(ASYNC_TASK_STOP_METHOD, asyncTaskStopParamsParser, (ctx) => getAgent(ctx.params).extMethod(ASYNC_TASK_STOP_METHOD, ctx.params)).onRequest(SESSION_RENAME_METHOD, sessionRenameParamsParser, (ctx) => getAgent(ctx.params).sessionIndex.rename(ctx.params)).onRequest(SESSION_BATCH_GET_METHOD, sessionBatchGetParamsParser, (ctx) => getAgent().sessionIndex.batchGet(ctx.params)).onRequest(SESSION_ARCHIVE_METHOD, sessionArchiveParamsParser, (ctx) => getAgent(ctx.params).sessionIndex.setArchived(ctx.params, true)).onRequest(SESSION_UNARCHIVE_METHOD, sessionArchiveParamsParser, (ctx) => getAgent(ctx.params).sessionIndex.setArchived(ctx.params, false)).onRequest(SESSION_LIST_SUBSCRIBE_METHOD, sessionListSubscriptionParamsParser, (ctx) => getAgent().sessionIndex.subscribeList(ctx.params)).onRequest(SESSION_LIST_UNSUBSCRIBE_METHOD, sessionListSubscriptionParamsParser, (ctx) => getAgent().sessionIndex.unsubscribeList(ctx.params));
|
|
54600
54717
|
return agentProtocolRouter().withV1(v1Agent).withV2(v2Agent);
|
|
54601
54718
|
}
|
|
54602
54719
|
|