@agentclientprotocol/codex-acp 2.5.1-preview.14 → 2.5.1-preview.16
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 +194 -116
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -41315,6 +41315,7 @@ var AgentMode = class _AgentMode {
|
|
|
41315
41315
|
|
|
41316
41316
|
// src/CodexAcpClient.ts
|
|
41317
41317
|
import path10 from "node:path";
|
|
41318
|
+
import { isDeepStrictEqual } from "node:util";
|
|
41318
41319
|
|
|
41319
41320
|
// package.json
|
|
41320
41321
|
var package_default = {
|
|
@@ -41322,7 +41323,7 @@ var package_default = {
|
|
|
41322
41323
|
publishConfig: {
|
|
41323
41324
|
access: "public"
|
|
41324
41325
|
},
|
|
41325
|
-
version: "2.5.1-preview.
|
|
41326
|
+
version: "2.5.1-preview.16",
|
|
41326
41327
|
description: "",
|
|
41327
41328
|
main: "dist/index.js",
|
|
41328
41329
|
bin: {
|
|
@@ -41703,6 +41704,83 @@ function isUnknownRecord(value) {
|
|
|
41703
41704
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
41704
41705
|
}
|
|
41705
41706
|
|
|
41707
|
+
// src/RequestCancellation.ts
|
|
41708
|
+
function throwIfRequestCancelled(signal) {
|
|
41709
|
+
if (signal?.aborted) throw RequestError.requestCancelled();
|
|
41710
|
+
}
|
|
41711
|
+
function withRequestCancellation(operation, signal) {
|
|
41712
|
+
if (!signal) return operation;
|
|
41713
|
+
return new Promise((resolve, reject) => {
|
|
41714
|
+
const cancelled = () => {
|
|
41715
|
+
signal.removeEventListener("abort", cancelled);
|
|
41716
|
+
reject(RequestError.requestCancelled());
|
|
41717
|
+
};
|
|
41718
|
+
if (signal.aborted) cancelled();
|
|
41719
|
+
else signal.addEventListener("abort", cancelled, { once: true });
|
|
41720
|
+
void operation.then((value) => {
|
|
41721
|
+
signal.removeEventListener("abort", cancelled);
|
|
41722
|
+
if (signal.aborted) cancelled();
|
|
41723
|
+
else resolve(value);
|
|
41724
|
+
}, (error62) => {
|
|
41725
|
+
signal.removeEventListener("abort", cancelled);
|
|
41726
|
+
reject(error62);
|
|
41727
|
+
});
|
|
41728
|
+
});
|
|
41729
|
+
}
|
|
41730
|
+
|
|
41731
|
+
// src/CodexAccountLogin.ts
|
|
41732
|
+
async function runAccountLogin(client, params, show, signal) {
|
|
41733
|
+
throwIfRequestCancelled(signal);
|
|
41734
|
+
let expectedId;
|
|
41735
|
+
const buffered = [];
|
|
41736
|
+
let complete;
|
|
41737
|
+
let endWait;
|
|
41738
|
+
const notified = new Promise((resolve, reject) => {
|
|
41739
|
+
complete = resolve;
|
|
41740
|
+
endWait = reject;
|
|
41741
|
+
});
|
|
41742
|
+
const accept = (event) => {
|
|
41743
|
+
if (expectedId === void 0) buffered.push(event);
|
|
41744
|
+
else if ((event.loginId ?? null) === expectedId) complete(event);
|
|
41745
|
+
};
|
|
41746
|
+
const listener = client.connection.onNotification("account/login/completed", accept);
|
|
41747
|
+
const completed = client.waitWhileConnected("account/login/completed", notified);
|
|
41748
|
+
void completed.catch(() => {
|
|
41749
|
+
});
|
|
41750
|
+
let response = null;
|
|
41751
|
+
let finished2 = false;
|
|
41752
|
+
try {
|
|
41753
|
+
response = await client.accountLogin(params);
|
|
41754
|
+
expectedId = "loginId" in response ? response.loginId : null;
|
|
41755
|
+
for (const event of buffered) accept(event);
|
|
41756
|
+
buffered.length = 0;
|
|
41757
|
+
throwIfRequestCancelled(signal);
|
|
41758
|
+
const first = await withRequestCancellation(Promise.race([
|
|
41759
|
+
completed.then((result2) => ({ type: "completed", result: result2 })),
|
|
41760
|
+
show(response).then((accepted) => ({ type: "shown", accepted }))
|
|
41761
|
+
]), signal);
|
|
41762
|
+
if (first.type === "completed") {
|
|
41763
|
+
finished2 = true;
|
|
41764
|
+
return first.result.success;
|
|
41765
|
+
}
|
|
41766
|
+
if (!first.accepted) return false;
|
|
41767
|
+
const result = await withRequestCancellation(completed, signal);
|
|
41768
|
+
finished2 = true;
|
|
41769
|
+
return result.success;
|
|
41770
|
+
} finally {
|
|
41771
|
+
if (!finished2 && response && "loginId" in response) {
|
|
41772
|
+
await client.accountLoginCancel({ loginId: response.loginId }).catch((error62) => {
|
|
41773
|
+
logger.error("Failed to cancel Codex account login", error62);
|
|
41774
|
+
});
|
|
41775
|
+
} else if (signal?.aborted && response && expectedId === null) {
|
|
41776
|
+
await completed.catch(() => {
|
|
41777
|
+
});
|
|
41778
|
+
}
|
|
41779
|
+
endWait(new Error("Account login has ended"));
|
|
41780
|
+
listener.dispose();
|
|
41781
|
+
}
|
|
41782
|
+
}
|
|
41783
|
+
|
|
41706
41784
|
// src/ClientSystemPrompt.ts
|
|
41707
41785
|
function clientSystemPromptText(value) {
|
|
41708
41786
|
if (value == null) return void 0;
|
|
@@ -41858,7 +41936,7 @@ var CodexAcpClient = class _CodexAcpClient {
|
|
|
41858
41936
|
* routing). `authStatus` reports only the agent-owned one.
|
|
41859
41937
|
*/
|
|
41860
41938
|
gatewayConfigSource;
|
|
41861
|
-
|
|
41939
|
+
authenticationTail = Promise.resolve();
|
|
41862
41940
|
pendingAccountUpdated = null;
|
|
41863
41941
|
sessionNotificationQueues = /* @__PURE__ */ new Map();
|
|
41864
41942
|
subagents;
|
|
@@ -41918,48 +41996,46 @@ var CodexAcpClient = class _CodexAcpClient {
|
|
|
41918
41996
|
getHomePath() {
|
|
41919
41997
|
return this.configPath;
|
|
41920
41998
|
}
|
|
41921
|
-
|
|
41999
|
+
authenticate(authRequest, urlElicitationRequester, signal) {
|
|
41922
42000
|
if (!isCodexAuthRequest(authRequest)) {
|
|
41923
|
-
|
|
42001
|
+
return Promise.reject(RequestError.invalidParams());
|
|
41924
42002
|
}
|
|
42003
|
+
const run = this.authenticationTail.then(() => this.authenticateOnce(authRequest, urlElicitationRequester, signal));
|
|
42004
|
+
this.authenticationTail = run.then(() => {
|
|
42005
|
+
}, () => {
|
|
42006
|
+
});
|
|
42007
|
+
return withRequestCancellation(run, signal);
|
|
42008
|
+
}
|
|
42009
|
+
async authenticateOnce(authRequest, urlElicitationRequester, signal) {
|
|
42010
|
+
throwIfRequestCancelled(signal);
|
|
41925
42011
|
this.gatewayConfig = null;
|
|
41926
42012
|
this.gatewayConfigSource = null;
|
|
41927
42013
|
switch (authRequest.methodId) {
|
|
41928
42014
|
case "api-key":
|
|
41929
|
-
return await this.authenticateWithApiKey(authRequest);
|
|
42015
|
+
return await this.authenticateWithApiKey(authRequest, signal);
|
|
41930
42016
|
case "chat-gpt":
|
|
41931
|
-
return await this.authenticateWithChatGpt();
|
|
42017
|
+
return await this.authenticateWithChatGpt(signal);
|
|
41932
42018
|
case "chat-gpt-device-code":
|
|
41933
|
-
return await this.authenticateWithChatGptDeviceCode(urlElicitationRequester);
|
|
42019
|
+
return await this.authenticateWithChatGptDeviceCode(urlElicitationRequester, signal);
|
|
41934
42020
|
case "gateway":
|
|
41935
42021
|
return this.authenticateWithGateway(authRequest);
|
|
41936
42022
|
}
|
|
41937
42023
|
}
|
|
41938
|
-
async authenticateWithApiKey(authRequest) {
|
|
42024
|
+
async authenticateWithApiKey(authRequest, signal) {
|
|
41939
42025
|
const apiKey = authRequest._meta?.["api-key"]?.apiKey ?? this.readApiKeyFromEnv();
|
|
41940
|
-
|
|
41941
|
-
loginCompletedPromise.catch(() => {
|
|
41942
|
-
});
|
|
41943
|
-
await this.codexClient.accountLogin({
|
|
41944
|
-
type: "apiKey",
|
|
41945
|
-
apiKey
|
|
41946
|
-
});
|
|
41947
|
-
const result = await loginCompletedPromise;
|
|
41948
|
-
return result.success;
|
|
42026
|
+
return runAccountLogin(this.codexClient, { type: "apiKey", apiKey }, async () => true, signal);
|
|
41949
42027
|
}
|
|
41950
|
-
async authenticateWithChatGpt() {
|
|
42028
|
+
async authenticateWithChatGpt(signal) {
|
|
41951
42029
|
if (await this.hasWorkingChatGptLogin()) {
|
|
42030
|
+
throwIfRequestCancelled(signal);
|
|
41952
42031
|
return true;
|
|
41953
42032
|
}
|
|
41954
|
-
|
|
41955
|
-
|
|
41956
|
-
|
|
41957
|
-
|
|
41958
|
-
|
|
41959
|
-
|
|
41960
|
-
}
|
|
41961
|
-
const result = await loginCompletedPromise;
|
|
41962
|
-
return result.success;
|
|
42033
|
+
return runAccountLogin(this.codexClient, { type: "chatgpt" }, async (response) => {
|
|
42034
|
+
if (response.type !== "chatgpt") return false;
|
|
42035
|
+
throwIfRequestCancelled(signal);
|
|
42036
|
+
await open_default(response.authUrl);
|
|
42037
|
+
return true;
|
|
42038
|
+
}, signal);
|
|
41963
42039
|
}
|
|
41964
42040
|
/**
|
|
41965
42041
|
* Reads with a token refresh whether the agent has a ChatGPT login that a new login does not need to replace.
|
|
@@ -41985,56 +42061,27 @@ var CodexAcpClient = class _CodexAcpClient {
|
|
|
41985
42061
|
throw error62;
|
|
41986
42062
|
}
|
|
41987
42063
|
}
|
|
41988
|
-
async authenticateWithChatGptDeviceCode(urlElicitationRequester) {
|
|
42064
|
+
async authenticateWithChatGptDeviceCode(urlElicitationRequester, signal) {
|
|
41989
42065
|
if (await this.hasWorkingChatGptLogin()) {
|
|
42066
|
+
throwIfRequestCancelled(signal);
|
|
41990
42067
|
return true;
|
|
41991
42068
|
}
|
|
41992
42069
|
if (!urlElicitationRequester) {
|
|
41993
42070
|
throw RequestError.invalidRequest(void 0, "Device code authentication requires URL elicitation support");
|
|
41994
42071
|
}
|
|
41995
|
-
const loginCompletedPromise = this.awaitNextLoginCompleted();
|
|
41996
|
-
loginCompletedPromise.catch(() => {
|
|
41997
|
-
});
|
|
41998
|
-
const loginResponse = await this.codexClient.accountLogin({ type: "chatgptDeviceCode" });
|
|
41999
|
-
if (loginResponse.type !== "chatgptDeviceCode") {
|
|
42000
|
-
return false;
|
|
42001
|
-
}
|
|
42002
|
-
const elicitationResponsePromise = Promise.resolve(urlElicitationRequester.elicitUrl({
|
|
42003
|
-
url: loginResponse.verificationUrl,
|
|
42004
|
-
message: `Sign in to ChatGPT and enter this code: ${loginResponse.userCode}`,
|
|
42005
|
-
elicitationId: loginResponse.loginId
|
|
42006
|
-
}));
|
|
42007
42072
|
try {
|
|
42008
|
-
|
|
42009
|
-
|
|
42010
|
-
|
|
42011
|
-
|
|
42012
|
-
|
|
42013
|
-
|
|
42014
|
-
type: "elicitationResponse",
|
|
42015
|
-
response
|
|
42016
|
-
}))
|
|
42017
|
-
]);
|
|
42018
|
-
if (first.type === "loginCompleted") {
|
|
42019
|
-
await urlElicitationRequester.completeElicitation();
|
|
42020
|
-
return first.result.success;
|
|
42021
|
-
}
|
|
42022
|
-
if (!CreateElicitationResponse.isAccept(first.response)) {
|
|
42023
|
-
await this.codexClient.accountLoginCancel({ loginId: loginResponse.loginId });
|
|
42024
|
-
throw RequestError.requestCancelled(
|
|
42025
|
-
{ methodId: "chat-gpt-device-code", action: first.response.action },
|
|
42026
|
-
"ChatGPT device code sign-in was cancelled"
|
|
42027
|
-
);
|
|
42028
|
-
}
|
|
42029
|
-
const result = await loginCompletedPromise;
|
|
42030
|
-
await urlElicitationRequester.completeElicitation();
|
|
42031
|
-
return result.success;
|
|
42032
|
-
} catch (error62) {
|
|
42033
|
-
if (this.codexClient.connectionLoss.lost) {
|
|
42034
|
-
await Promise.resolve(urlElicitationRequester.completeElicitation()).catch(() => {
|
|
42073
|
+
return await runAccountLogin(this.codexClient, { type: "chatgptDeviceCode" }, async (response) => {
|
|
42074
|
+
if (response.type !== "chatgptDeviceCode") return false;
|
|
42075
|
+
const answer = await urlElicitationRequester.elicitUrl({
|
|
42076
|
+
url: response.verificationUrl,
|
|
42077
|
+
message: `Sign in to ChatGPT and enter this code: ${response.userCode}`,
|
|
42078
|
+
elicitationId: response.loginId
|
|
42035
42079
|
});
|
|
42036
|
-
|
|
42037
|
-
|
|
42080
|
+
return CreateElicitationResponse.isAccept(answer);
|
|
42081
|
+
}, signal);
|
|
42082
|
+
} finally {
|
|
42083
|
+
await urlElicitationRequester.completeElicitation().catch(() => {
|
|
42084
|
+
});
|
|
42038
42085
|
}
|
|
42039
42086
|
}
|
|
42040
42087
|
authenticateWithGateway(authRequest) {
|
|
@@ -42158,9 +42205,9 @@ var CodexAcpClient = class _CodexAcpClient {
|
|
|
42158
42205
|
if (!URL.canParse(request.baseUrl) || !["http:", "https:"].includes(new URL(request.baseUrl).protocol)) {
|
|
42159
42206
|
throw RequestError.invalidParams({ baseUrl: request.baseUrl }, "baseUrl must be an http(s) URL");
|
|
42160
42207
|
}
|
|
42161
|
-
const
|
|
42208
|
+
const previousListing = this.hasProviderRouting(gatewayConfig) ? this.gatewayConfig?.listedModels ?? null : null;
|
|
42162
42209
|
try {
|
|
42163
|
-
gatewayConfig.listedModels =
|
|
42210
|
+
gatewayConfig.listedModels = previousListing ?? await listGatewayModels(gatewayConfig.config.base_url, gatewayConfig.config.http_headers);
|
|
42164
42211
|
} catch (error62) {
|
|
42165
42212
|
if (error62 instanceof GatewayListingError) {
|
|
42166
42213
|
throw RequestError.internalError(
|
|
@@ -42172,6 +42219,10 @@ var CodexAcpClient = class _CodexAcpClient {
|
|
|
42172
42219
|
}
|
|
42173
42220
|
return gatewayConfig;
|
|
42174
42221
|
}
|
|
42222
|
+
/** Whether `providers/set` already applied the provider config of `gatewayConfig`. */
|
|
42223
|
+
hasProviderRouting(gatewayConfig) {
|
|
42224
|
+
return this.gatewayConfigSource === "acpProviders" && this.gatewayConfig !== null && sameProviderConfig(this.gatewayConfig, gatewayConfig);
|
|
42225
|
+
}
|
|
42175
42226
|
/** `providers/set`: replaces the routing with a configuration from {@link prepareProvider}. */
|
|
42176
42227
|
setProvider(gatewayConfig) {
|
|
42177
42228
|
this.gatewayConfigSource = "acpProviders";
|
|
@@ -42887,20 +42938,6 @@ var CodexAcpClient = class _CodexAcpClient {
|
|
|
42887
42938
|
async listSkills(params) {
|
|
42888
42939
|
return withoutUnsupportedSkills(await this.codexClient.listSkills(params ?? {}));
|
|
42889
42940
|
}
|
|
42890
|
-
async awaitNextLoginCompleted() {
|
|
42891
|
-
if (this.pendingLoginCompleted !== null) {
|
|
42892
|
-
return await this.pendingLoginCompleted;
|
|
42893
|
-
}
|
|
42894
|
-
this.pendingLoginCompleted = this.awaitSingleNotification(
|
|
42895
|
-
"account/login/completed",
|
|
42896
|
-
(event) => event
|
|
42897
|
-
);
|
|
42898
|
-
try {
|
|
42899
|
-
return await this.pendingLoginCompleted;
|
|
42900
|
-
} finally {
|
|
42901
|
-
this.pendingLoginCompleted = null;
|
|
42902
|
-
}
|
|
42903
|
-
}
|
|
42904
42941
|
async awaitNextAccountUpdated() {
|
|
42905
42942
|
if (this.pendingAccountUpdated !== null) {
|
|
42906
42943
|
return await this.pendingAccountUpdated;
|
|
@@ -43112,10 +43149,8 @@ function buildGatewayConfig(params) {
|
|
|
43112
43149
|
listedModels: null
|
|
43113
43150
|
};
|
|
43114
43151
|
}
|
|
43115
|
-
function
|
|
43116
|
-
|
|
43117
|
-
const rightHeaders = right.config.http_headers;
|
|
43118
|
-
return left.config.base_url === right.config.base_url && left.config.wire_api === right.config.wire_api && leftHeaders.length === Object.keys(rightHeaders).length && leftHeaders.every(([name, value]) => rightHeaders[name] === value);
|
|
43152
|
+
function sameProviderConfig(left, right) {
|
|
43153
|
+
return left.modelProvider === right.modelProvider && isDeepStrictEqual(left.config, right.config);
|
|
43119
43154
|
}
|
|
43120
43155
|
function readMetaAdditionalRoots(meta3) {
|
|
43121
43156
|
const rawRoots = meta3?.["additionalRoots"];
|
|
@@ -50033,6 +50068,7 @@ var CodexAcpServer = class {
|
|
|
50033
50068
|
mcpServerSignIn;
|
|
50034
50069
|
clientDelivery;
|
|
50035
50070
|
setupResponseOrdering = false;
|
|
50071
|
+
initializeResponseDelivery = "direct";
|
|
50036
50072
|
/** ACP protocol version of the connection this agent serves, fixed by the protocol router. */
|
|
50037
50073
|
protocolVersion;
|
|
50038
50074
|
/** The v2 client handle; `null` on a v1 connection. */
|
|
@@ -50096,6 +50132,8 @@ var CodexAcpServer = class {
|
|
|
50096
50132
|
recovery;
|
|
50097
50133
|
initializeRequest = null;
|
|
50098
50134
|
providerUpdate = null;
|
|
50135
|
+
/** The last provider update failed, so the app-server may not run the routing of the agent. */
|
|
50136
|
+
providerUpdateFailed = false;
|
|
50099
50137
|
/**
|
|
50100
50138
|
* Numbers `providers/set` and `providers/disable` requests in arrival order. A listing finishing after a newer
|
|
50101
50139
|
* request was applied is dropped; a newer request that failed drops nothing.
|
|
@@ -51550,41 +51588,53 @@ You have been logged out. Please try again.`);
|
|
|
51550
51588
|
...this.createSessionSetupResponseV2(this.getSessionState(sessionId))
|
|
51551
51589
|
};
|
|
51552
51590
|
}
|
|
51553
|
-
async authenticate(_params, requestId) {
|
|
51591
|
+
async authenticate(_params, requestId, signal) {
|
|
51554
51592
|
logger.log("Authenticate request received");
|
|
51593
|
+
throwIfRequestCancelled(signal);
|
|
51555
51594
|
const appServer = this.ensureAppServer();
|
|
51556
|
-
if (appServer) await appServer;
|
|
51557
|
-
const elicitationRequester = this.createUrlElicitationRequester(requestId);
|
|
51558
|
-
|
|
51559
|
-
|
|
51560
|
-
|
|
51561
|
-
|
|
51562
|
-
|
|
51563
|
-
|
|
51564
|
-
|
|
51565
|
-
|
|
51595
|
+
if (appServer) await withRequestCancellation(appServer, signal);
|
|
51596
|
+
const elicitationRequester = this.createUrlElicitationRequester(requestId, signal);
|
|
51597
|
+
try {
|
|
51598
|
+
const isAuthenticated = await this.runWithProcessCheck(() => this.codexAcpClient.authenticate(_params, elicitationRequester, signal));
|
|
51599
|
+
throwIfRequestCancelled(signal);
|
|
51600
|
+
if (!isAuthenticated) {
|
|
51601
|
+
logger.log("Authenticate request failed");
|
|
51602
|
+
throw RequestError.authRequired({ methodId: _params.methodId }, "Sign-in did not complete");
|
|
51603
|
+
}
|
|
51604
|
+
await withRequestCancellation(this.refreshAuthState(this.getAuthProviderForAuthenticateRequest(_params)), signal);
|
|
51605
|
+
logger.log("Authenticate request completed");
|
|
51606
|
+
return {};
|
|
51607
|
+
} finally {
|
|
51608
|
+
await elicitationRequester?.completeElicitation().catch(() => {
|
|
51609
|
+
});
|
|
51610
|
+
}
|
|
51566
51611
|
}
|
|
51567
|
-
createUrlElicitationRequester(requestId) {
|
|
51612
|
+
createUrlElicitationRequester(requestId, signal) {
|
|
51568
51613
|
if (requestId == null || !clientSupportsUrlElicitation(this.clientCapabilities)) {
|
|
51569
51614
|
return void 0;
|
|
51570
51615
|
}
|
|
51616
|
+
const lifetime = new AbortController();
|
|
51617
|
+
const cancellationSignal = signal ? AbortSignal.any([signal, lifetime.signal]) : lifetime.signal;
|
|
51571
51618
|
let elicitationId = null;
|
|
51572
51619
|
return {
|
|
51573
|
-
elicitUrl: (request) => {
|
|
51620
|
+
elicitUrl: async (request) => {
|
|
51574
51621
|
elicitationId = request.elicitationId;
|
|
51575
|
-
|
|
51622
|
+
const response = await this.connection.request(methods.client.elicitation.create, {
|
|
51576
51623
|
mode: "url",
|
|
51577
51624
|
requestId,
|
|
51578
51625
|
...request
|
|
51579
|
-
});
|
|
51626
|
+
}, { cancellationSignal });
|
|
51627
|
+
if (!CreateElicitationResponse.isAccept(response)) elicitationId = null;
|
|
51628
|
+
return response;
|
|
51580
51629
|
},
|
|
51581
51630
|
completeElicitation: async () => {
|
|
51582
51631
|
if (elicitationId === null) {
|
|
51583
51632
|
return;
|
|
51584
51633
|
}
|
|
51585
|
-
|
|
51586
|
-
|
|
51587
|
-
|
|
51634
|
+
const completedId = elicitationId;
|
|
51635
|
+
elicitationId = null;
|
|
51636
|
+
lifetime.abort();
|
|
51637
|
+
await this.connection.notify(methods.client.elicitation.complete, { elicitationId: completedId });
|
|
51588
51638
|
}
|
|
51589
51639
|
};
|
|
51590
51640
|
}
|
|
@@ -51597,11 +51647,11 @@ You have been logged out. Please try again.`);
|
|
|
51597
51647
|
logger.log("Logout request completed");
|
|
51598
51648
|
}
|
|
51599
51649
|
/** v2 `auth/login`: same params as v1 `authenticate`, only the method name changed. */
|
|
51600
|
-
async authenticateV2(params, requestId) {
|
|
51650
|
+
async authenticateV2(params, requestId, signal) {
|
|
51601
51651
|
if (!getCodexAuthMethodsV2(this.clientCapabilities).some((method) => method.methodId === params.methodId)) {
|
|
51602
51652
|
throw RequestError.invalidParams(void 0, `Unsupported authentication method: ${params.methodId}`);
|
|
51603
51653
|
}
|
|
51604
|
-
return await this.authenticate(params, requestId);
|
|
51654
|
+
return await this.authenticate(params, requestId, signal);
|
|
51605
51655
|
}
|
|
51606
51656
|
/** v2 `auth/logout`: same params as v1 `logout`, only the method name changed. */
|
|
51607
51657
|
async logoutV2(params) {
|
|
@@ -51619,6 +51669,11 @@ You have been logged out. Please try again.`);
|
|
|
51619
51669
|
return {};
|
|
51620
51670
|
}
|
|
51621
51671
|
this.appliedProviderRequest = request;
|
|
51672
|
+
if (this.codexAcpClient.hasProviderRouting(gatewayConfig) && !this.providerUpdateFailed) {
|
|
51673
|
+
logger.log("providers/set unchanged: the app-server is not restarted");
|
|
51674
|
+
await this.waitForProviderUpdate();
|
|
51675
|
+
return {};
|
|
51676
|
+
}
|
|
51622
51677
|
this.codexAcpClient.setProvider(gatewayConfig);
|
|
51623
51678
|
await this.enqueueProviderUpdate((client) => client.setProvider(gatewayConfig));
|
|
51624
51679
|
return {};
|
|
@@ -51716,6 +51771,11 @@ You have been logged out. Please try again.`);
|
|
|
51716
51771
|
}
|
|
51717
51772
|
});
|
|
51718
51773
|
this.providerUpdate = update;
|
|
51774
|
+
update.then(() => {
|
|
51775
|
+
this.providerUpdateFailed = false;
|
|
51776
|
+
}, () => {
|
|
51777
|
+
this.providerUpdateFailed = true;
|
|
51778
|
+
});
|
|
51719
51779
|
this.recovery?.settleReplacement(update);
|
|
51720
51780
|
try {
|
|
51721
51781
|
await update;
|
|
@@ -51864,16 +51924,23 @@ You have been logged out. Please try again.`);
|
|
|
51864
51924
|
* Schedules the connection's first `_auth/status_update`: one account read,
|
|
51865
51925
|
* pushed whatever it says, including `none`.
|
|
51866
51926
|
*
|
|
51867
|
-
*
|
|
51868
|
-
*
|
|
51869
|
-
* the read starts from a check-phase callback, which always runs after it.
|
|
51870
|
-
* `initialize` itself never waits for the read.
|
|
51927
|
+
* Routed connections publish at the response-write boundary. Direct callers
|
|
51928
|
+
* have no transport boundary, so they retain the asynchronous fallback.
|
|
51871
51929
|
*
|
|
51872
51930
|
* "Unconditional" costs nothing extra here: nothing has been pushed yet on
|
|
51873
51931
|
* this connection, so {@link setAuthStatus} cannot suppress this one.
|
|
51874
51932
|
*/
|
|
51875
51933
|
publishFirstAuthStatusAfterResponse() {
|
|
51876
|
-
|
|
51934
|
+
if (this.initializeResponseDelivery === "direct") {
|
|
51935
|
+
setImmediate(() => void this.publishAuthStatusRead());
|
|
51936
|
+
}
|
|
51937
|
+
}
|
|
51938
|
+
observeInitializeResponse() {
|
|
51939
|
+
this.initializeResponseDelivery = "pending";
|
|
51940
|
+
}
|
|
51941
|
+
afterInitializeResponse() {
|
|
51942
|
+
this.initializeResponseDelivery = "written";
|
|
51943
|
+
void this.publishAuthStatusRead();
|
|
51877
51944
|
}
|
|
51878
51945
|
/**
|
|
51879
51946
|
* Reads the agent-owned identity and pushes it.
|
|
@@ -51957,6 +52024,7 @@ You have been logged out. Please try again.`);
|
|
|
51957
52024
|
*/
|
|
51958
52025
|
async applyAccountUpdated(notification) {
|
|
51959
52026
|
this.lastReadAccount = accountFromUpdated(notification, this.lastReadAccount);
|
|
52027
|
+
if (this.initializeResponseDelivery === "pending") return;
|
|
51960
52028
|
try {
|
|
51961
52029
|
if (this.codexAcpClient.getAuthGatewayProviderName() !== null) {
|
|
51962
52030
|
return;
|
|
@@ -51987,6 +52055,7 @@ You have been logged out. Please try again.`);
|
|
|
51987
52055
|
*/
|
|
51988
52056
|
async setAuthStatus(next) {
|
|
51989
52057
|
this.authStatusVersion += 1;
|
|
52058
|
+
if (this.initializeResponseDelivery === "pending") return;
|
|
51990
52059
|
if (sameAuthStatus(this.currentAuthStatus, next)) {
|
|
51991
52060
|
return;
|
|
51992
52061
|
}
|
|
@@ -54881,6 +54950,7 @@ function createRouter(createAgent, responses) {
|
|
|
54881
54950
|
};
|
|
54882
54951
|
const attachAgent = (agent3, signal) => {
|
|
54883
54952
|
codexAcpServer = agent3;
|
|
54953
|
+
agent3.observeInitializeResponse();
|
|
54884
54954
|
const stopSetupPublication = agent3.observeSessionSetupResponses();
|
|
54885
54955
|
signal.addEventListener("abort", () => {
|
|
54886
54956
|
setups.clear();
|
|
@@ -54891,8 +54961,16 @@ function createRouter(createAgent, responses) {
|
|
|
54891
54961
|
}
|
|
54892
54962
|
});
|
|
54893
54963
|
};
|
|
54894
|
-
const
|
|
54895
|
-
|
|
54964
|
+
const initialize = async (requestId, operation) => {
|
|
54965
|
+
const agent3 = getAgent();
|
|
54966
|
+
const result = await operation();
|
|
54967
|
+
responses.afterWrite(requestId, (successful) => {
|
|
54968
|
+
if (successful) agent3.afterInitializeResponse();
|
|
54969
|
+
});
|
|
54970
|
+
return result;
|
|
54971
|
+
};
|
|
54972
|
+
const v1Agent = agent({ name: package_default.name }).onConnect((connection) => attachAgent(createAgent(connection.client), connection.signal)).onRequest(methods.agent.initialize, (ctx) => initialize(ctx.requestId, () => 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, ctx.signal)).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));
|
|
54973
|
+
const v2Agent = agent2({ name: package_default.name }).onConnect((connection) => attachAgent(createAgent(new AcpV2Connection(connection.client)), connection.signal)).onRequest(methods2.agent.initialize, (ctx) => initialize(ctx.requestId, () => 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, ctx.signal)).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));
|
|
54896
54974
|
return agentProtocolRouter().withV1(v1Agent).withV2(v2Agent);
|
|
54897
54975
|
}
|
|
54898
54976
|
|