@agentclientprotocol/codex-acp 2.5.1-preview.6 → 2.5.1-preview.8
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 +159 -49
- 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
|
}
|
|
@@ -32770,13 +32829,13 @@ var AcpV2Connection = class {
|
|
|
32770
32829
|
let update;
|
|
32771
32830
|
switch (kind) {
|
|
32772
32831
|
case "user_message":
|
|
32773
|
-
update = { sessionUpdate: "user_message", messageId, content: [] };
|
|
32832
|
+
update = { sessionUpdate: "user_message", messageId, content: [], _meta: null };
|
|
32774
32833
|
break;
|
|
32775
32834
|
case "agent_message":
|
|
32776
|
-
update = { sessionUpdate: "agent_message", messageId, content: [] };
|
|
32835
|
+
update = { sessionUpdate: "agent_message", messageId, content: [], _meta: null };
|
|
32777
32836
|
break;
|
|
32778
32837
|
case "agent_thought":
|
|
32779
|
-
update = { sessionUpdate: "agent_thought", messageId, content: [] };
|
|
32838
|
+
update = { sessionUpdate: "agent_thought", messageId, content: [], _meta: null };
|
|
32780
32839
|
break;
|
|
32781
32840
|
}
|
|
32782
32841
|
await this.client.notify(methods2.client.session.update, {
|
|
@@ -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.8",
|
|
41002
41068
|
description: "",
|
|
41003
41069
|
main: "dist/index.js",
|
|
41004
41070
|
bin: {
|
|
@@ -42082,6 +42148,7 @@ var CodexAcpClient = class _CodexAcpClient {
|
|
|
42082
42148
|
// Codex sends no thread/settings/updated on a resume. The response holds the mode.
|
|
42083
42149
|
collaborationMode: response.collaborationMode ?? this.getCollaborationMode(response.thread.id),
|
|
42084
42150
|
threadStatus: response.thread.status,
|
|
42151
|
+
sessionTitle: normalizeSessionTitle(listedSessionTitle(response.thread)),
|
|
42085
42152
|
modelProvider: response.modelProvider,
|
|
42086
42153
|
currentServiceTier: response.serviceTier ?? null,
|
|
42087
42154
|
additionalDirectories,
|
|
@@ -49760,6 +49827,7 @@ var CodexAcpServer = class {
|
|
|
49760
49827
|
connection;
|
|
49761
49828
|
mcpServerSignIn;
|
|
49762
49829
|
clientDelivery;
|
|
49830
|
+
setupResponseOrdering = false;
|
|
49763
49831
|
/** ACP protocol version of the connection this agent serves, fixed by the protocol router. */
|
|
49764
49832
|
protocolVersion;
|
|
49765
49833
|
/** The v2 client handle; `null` on a v1 connection. */
|
|
@@ -49883,7 +49951,8 @@ var CodexAcpServer = class {
|
|
|
49883
49951
|
(operation) => this.runWithProcessCheck(operation),
|
|
49884
49952
|
this.mcpServerSignIn,
|
|
49885
49953
|
() => this.capabilities,
|
|
49886
|
-
(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)
|
|
49887
49956
|
);
|
|
49888
49957
|
this.defaultAuthRequest = defaultAuthRequest ?? null;
|
|
49889
49958
|
this.codexProcessState = codexProcessState ?? null;
|
|
@@ -49923,6 +49992,10 @@ var CodexAcpServer = class {
|
|
|
49923
49992
|
const state = this.sessions.get(sessionId);
|
|
49924
49993
|
return state ? this.subagentModels(state) : null;
|
|
49925
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;
|
|
49926
49999
|
const router = this.usesStandardSubagents() ? new StandardSubagentEventRouter(
|
|
49927
50000
|
sessionId,
|
|
49928
50001
|
session,
|
|
@@ -49930,7 +50003,7 @@ var CodexAcpServer = class {
|
|
|
49930
50003
|
release,
|
|
49931
50004
|
this.capabilities,
|
|
49932
50005
|
replay,
|
|
49933
|
-
|
|
50006
|
+
ready,
|
|
49934
50007
|
(id) => this.codexAcpClient.appServerClient.runningTurnId(id),
|
|
49935
50008
|
models,
|
|
49936
50009
|
{
|
|
@@ -49999,13 +50072,30 @@ var CodexAcpServer = class {
|
|
|
49999
50072
|
check2();
|
|
50000
50073
|
return check2;
|
|
50001
50074
|
}
|
|
50002
|
-
|
|
50003
|
-
|
|
50004
|
-
|
|
50005
|
-
|
|
50006
|
-
|
|
50007
|
-
|
|
50008
|
-
}
|
|
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
|
+
};
|
|
50009
50099
|
}
|
|
50010
50100
|
async interruptStandardChildren(session) {
|
|
50011
50101
|
if (!(session.subagents instanceof StandardSubagentEventRouter)) return;
|
|
@@ -50535,6 +50625,7 @@ You have been logged out. Please try again.`);
|
|
|
50535
50625
|
const sessionMcpServers = this.resolveSessionMcpServers(requestedMcpServers, operation === "resume");
|
|
50536
50626
|
const currentModel = this.findCurrentModel(models, currentModelId);
|
|
50537
50627
|
const currentModelSupportsFast = modelSupportsFast(currentModel);
|
|
50628
|
+
if (this.setupResponseOrdering && operation !== "resume") this.clientDelivery.beginSessionSetup(sessionId);
|
|
50538
50629
|
const sessionState = {
|
|
50539
50630
|
sessionId,
|
|
50540
50631
|
currentModelId,
|
|
@@ -50564,7 +50655,7 @@ You have been logged out. Please try again.`);
|
|
|
50564
50655
|
sessionMcpServers,
|
|
50565
50656
|
clientCapabilities: this.capabilities,
|
|
50566
50657
|
goalRevision: 0,
|
|
50567
|
-
sessionTitle: null,
|
|
50658
|
+
sessionTitle: sessionMetadata.sessionTitle ?? null,
|
|
50568
50659
|
sessionTitleSource: operation === "resume" ? "unknown" : "unset",
|
|
50569
50660
|
subagents: this.createSubagentRouter(sessionId),
|
|
50570
50661
|
asyncTasks: this.createAsyncTasks(sessionId),
|
|
@@ -51039,19 +51130,22 @@ You have been logged out. Please try again.`);
|
|
|
51039
51130
|
const request = { ...rest, systemPrompt: toV1SystemPrompt(systemPrompt) };
|
|
51040
51131
|
if (replayFrom == null) {
|
|
51041
51132
|
await this.resumeSession(request);
|
|
51042
|
-
|
|
51043
|
-
|
|
51044
|
-
|
|
51045
|
-
|
|
51046
|
-
|
|
51133
|
+
} else {
|
|
51134
|
+
if (replayFrom.type !== "start") {
|
|
51135
|
+
throw RequestError.invalidParams(void 0, `Unsupported replayFrom type: ${replayFrom.type}`);
|
|
51136
|
+
}
|
|
51137
|
+
await this.loadSessionAndReplayHistory(request);
|
|
51047
51138
|
}
|
|
51048
|
-
|
|
51049
|
-
|
|
51050
|
-
return this.createSessionSetupResponseV2(this.getSessionState(sessionId));
|
|
51139
|
+
await this.snapshotSessionStateV2(params.sessionId);
|
|
51140
|
+
return this.createSessionSetupResponseV2(this.getSessionState(params.sessionId));
|
|
51051
51141
|
}
|
|
51052
|
-
async
|
|
51142
|
+
async snapshotSessionStateV2(sessionId) {
|
|
51053
51143
|
await this.codexAcpClient.waitForSessionNotifications(sessionId);
|
|
51054
|
-
this.getSessionState(sessionId);
|
|
51144
|
+
const state = this.getSessionState(sessionId);
|
|
51145
|
+
await new ACPSessionConnection(this.connection, sessionId).update({
|
|
51146
|
+
sessionUpdate: "session_info_update",
|
|
51147
|
+
title: state.sessionTitle
|
|
51148
|
+
});
|
|
51055
51149
|
await AcpV2Connection.of(this.connection).snapshotForegroundState(sessionId);
|
|
51056
51150
|
}
|
|
51057
51151
|
async forkSession(params) {
|
|
@@ -52438,11 +52532,8 @@ You have been logged out. Please try again.`);
|
|
|
52438
52532
|
}
|
|
52439
52533
|
}
|
|
52440
52534
|
/**
|
|
52441
|
-
*
|
|
52442
|
-
*
|
|
52443
|
-
* already holds for it (`session-setup.mdx`). No-op for chunks with no messageId: those get
|
|
52444
|
-
* a fresh random id downstream instead (`toV2SessionUpdate`), so there is nothing to key on
|
|
52445
|
-
* ahead of time.
|
|
52535
|
+
* Start each v2 replayed message with empty content and metadata before its chunks.
|
|
52536
|
+
* Chunks without a messageId get a fresh id in toV2SessionUpdate and cannot be primed.
|
|
52446
52537
|
*/
|
|
52447
52538
|
async sendReplayMessageStart(session, update, started) {
|
|
52448
52539
|
const kind = replayMessageStartKind(update.sessionUpdate);
|
|
@@ -54448,7 +54539,7 @@ var AcpResponseDelivery = class {
|
|
|
54448
54539
|
if ("method" in message || message.id === null) return;
|
|
54449
54540
|
const callback = this.callbacks.get(message.id);
|
|
54450
54541
|
this.callbacks.delete(message.id);
|
|
54451
|
-
callback?.();
|
|
54542
|
+
callback?.("result" in message);
|
|
54452
54543
|
},
|
|
54453
54544
|
close: async () => {
|
|
54454
54545
|
const writer = stream.writable.getWriter();
|
|
@@ -54541,7 +54632,15 @@ function createRouter(createAgent, responses) {
|
|
|
54541
54632
|
const setups = /* @__PURE__ */ new Map();
|
|
54542
54633
|
const setup = (sessionId, requestId, operation, signal) => {
|
|
54543
54634
|
const agent3 = getAgent({ sessionId });
|
|
54544
|
-
if (!agent3.usesStandardSubagents())
|
|
54635
|
+
if (!agent3.usesStandardSubagents()) {
|
|
54636
|
+
return operation().then((result) => {
|
|
54637
|
+
const publish = agent3.captureSessionSetupPublication(sessionId);
|
|
54638
|
+
responses.afterWrite(requestId, (successful) => {
|
|
54639
|
+
if (successful) void publish();
|
|
54640
|
+
});
|
|
54641
|
+
return result;
|
|
54642
|
+
});
|
|
54643
|
+
}
|
|
54545
54644
|
const assertCurrent = agent3.captureSessionSetup(sessionId);
|
|
54546
54645
|
const state = setups.get(sessionId) ?? { tail: Promise.resolve(), publication: Promise.resolve(), epoch: 0, pending: 0 };
|
|
54547
54646
|
setups.set(sessionId, state);
|
|
@@ -54559,7 +54658,7 @@ function createRouter(createAgent, responses) {
|
|
|
54559
54658
|
state.tail = state.tail.catch(() => {
|
|
54560
54659
|
}).then(async () => {
|
|
54561
54660
|
let registered = false;
|
|
54562
|
-
let
|
|
54661
|
+
let publish = null;
|
|
54563
54662
|
try {
|
|
54564
54663
|
for (; ; ) {
|
|
54565
54664
|
const publication = state.publication;
|
|
@@ -54568,14 +54667,14 @@ function createRouter(createAgent, responses) {
|
|
|
54568
54667
|
}
|
|
54569
54668
|
if (signal.aborted) throw new RequestError(-32800, "Session setup was cancelled");
|
|
54570
54669
|
assertCurrent();
|
|
54571
|
-
responses.afterWrite(requestId, () => {
|
|
54572
|
-
if (epoch === state.epoch &&
|
|
54670
|
+
responses.afterWrite(requestId, (successful) => {
|
|
54671
|
+
if (successful && epoch === state.epoch && publish) state.publication = publish();
|
|
54573
54672
|
void state.publication.then(finish, finish);
|
|
54574
54673
|
});
|
|
54575
54674
|
registered = true;
|
|
54576
54675
|
const result = await operation();
|
|
54577
54676
|
if (signal.aborted) throw new RequestError(-32800, "Session setup was cancelled");
|
|
54578
|
-
|
|
54677
|
+
publish = agent3.captureSessionSetupPublication(sessionId);
|
|
54579
54678
|
resolve(result);
|
|
54580
54679
|
} catch (error62) {
|
|
54581
54680
|
reject(error62);
|
|
@@ -54584,18 +54683,29 @@ function createRouter(createAgent, responses) {
|
|
|
54584
54683
|
});
|
|
54585
54684
|
return response;
|
|
54586
54685
|
};
|
|
54686
|
+
const createdSetup = async (requestId, operation) => {
|
|
54687
|
+
const agent3 = getAgent();
|
|
54688
|
+
const result = await operation();
|
|
54689
|
+
const publish = agent3.captureSessionCreationPublication(result.sessionId);
|
|
54690
|
+
responses.afterWrite(requestId, (successful) => {
|
|
54691
|
+
if (successful) publish();
|
|
54692
|
+
});
|
|
54693
|
+
return result;
|
|
54694
|
+
};
|
|
54587
54695
|
const attachAgent = (agent3, signal) => {
|
|
54588
54696
|
codexAcpServer = agent3;
|
|
54697
|
+
const stopSetupPublication = agent3.observeSessionSetupResponses();
|
|
54589
54698
|
signal.addEventListener("abort", () => {
|
|
54590
54699
|
setups.clear();
|
|
54700
|
+
stopSetupPublication();
|
|
54591
54701
|
agent3.sessionIndex.dispose();
|
|
54592
54702
|
if (codexAcpServer === agent3) {
|
|
54593
54703
|
codexAcpServer = null;
|
|
54594
54704
|
}
|
|
54595
54705
|
});
|
|
54596
54706
|
};
|
|
54597
|
-
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));
|
|
54598
|
-
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));
|
|
54707
|
+
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));
|
|
54708
|
+
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));
|
|
54599
54709
|
return agentProtocolRouter().withV1(v1Agent).withV2(v2Agent);
|
|
54600
54710
|
}
|
|
54601
54711
|
|