Skip to content

Commit 061a422

Browse files
committed
Advertise auth logout capability
Route logout through unstable ACP auth support while keeping the legacy authentication/logout extension method as a compatibility shim.
1 parent 596b824 commit 061a422

4 files changed

Lines changed: 29 additions & 6 deletions

File tree

src/CodexAcpClient.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import type {
3131
UserInput,
3232
} from "./app-server/v2";
3333
import packageJson from "../package.json";
34-
import type {AuthenticationLogoutResponse, AuthenticationStatusResponse} from "./AcpExtensions";
34+
import type {AuthenticationStatusResponse} from "./AcpExtensions";
3535

3636
/**
3737
* API for accessing the Codex App Server using ACP requests.
@@ -167,11 +167,10 @@ export class CodexAcpClient {
167167
return settingsModelProvider.config.model_provider;
168168
}
169169

170-
async logout(): Promise<AuthenticationLogoutResponse> {
170+
async logout(): Promise<void> {
171171
const accountUpdatedPromise = this.awaitNextAccountUpdated();
172172
await this.codexClient.accountLogout();
173173
await accountUpdatedPromise;
174-
return {};
175174
}
176175

177176
async authRequired(): Promise<Boolean> {

src/CodexAcpServer.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ export class CodexAcpServer implements acp.Agent {
9494
return {
9595
protocolVersion: acp.PROTOCOL_VERSION,
9696
agentCapabilities: {
97+
auth: {
98+
logout: {},
99+
},
97100
loadSession: true,
98101
promptCapabilities: {
99102
image: true
@@ -119,8 +122,10 @@ export class CodexAcpServer implements acp.Agent {
119122
switch (methodRequest.method) {
120123
case "authentication/status":
121124
return await this.runWithProcessCheck(() => this.codexAcpClient.getAuthenticationStatus());
122-
case "authentication/logout":
123-
return await this.runWithProcessCheck(() => this.codexAcpClient.logout());
125+
case "authentication/logout": {
126+
await this.unstable_logout({});
127+
return {};
128+
}
124129
}
125130
}
126131

@@ -265,6 +270,12 @@ export class CodexAcpServer implements acp.Agent {
265270
return { };
266271
}
267272

273+
async unstable_logout(_params: acp.LogoutRequest): Promise<void> {
274+
logger.log("Logout request received");
275+
await this.runWithProcessCheck(() => this.codexAcpClient.logout());
276+
logger.log("Logout request completed");
277+
}
278+
268279
async setSessionMode(
269280
_params: acp.SetSessionModeRequest,
270281
): Promise<acp.SetSessionModeResponse> {

src/__tests__/CodexACPAgent/CodexAcpClient.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe('ACP server test', { timeout: 40_000 }, () => {
103103
const authenticatedResponse = await keyFixture.getCodexAcpAgent().extMethod("authentication/status", {});
104104
expect(authenticatedResponse).toEqual({type: "api-key"});
105105

106-
await keyFixture.getCodexAcpAgent().extMethod("authentication/logout", {});
106+
await keyFixture.getCodexAcpAgent().unstable_logout({});
107107
const logoutResponse = await keyFixture.getCodexAcpAgent().extMethod("authentication/status", {});
108108
expect(logoutResponse).toEqual({type: "unauthenticated"});
109109
});
@@ -137,6 +137,16 @@ describe('ACP server test', { timeout: 40_000 }, () => {
137137
expect(newSessionResponse.sessionId).toBeDefined()
138138
})
139139

140+
it('supports legacy authentication/logout ext method', async () => {
141+
const mockFixture = createCodexMockTestFixture();
142+
const codexAcpAgent = mockFixture.getCodexAcpAgent();
143+
144+
const logoutSpy = vi.spyOn(codexAcpAgent, "unstable_logout").mockResolvedValue({});
145+
146+
await expect(codexAcpAgent.extMethod("authentication/logout", {})).resolves.toEqual({});
147+
expect(logoutSpy).toHaveBeenCalledWith({});
148+
});
149+
140150
it('prefetches session additional skill roots before thread start', async () => {
141151
const mockFixture = createCodexMockTestFixture();
142152
const codexAcpClient = mockFixture.getCodexAcpClient();

src/__tests__/CodexACPAgent/initialize.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ describe('CodexACPAgent - initialize', () => {
3232
expect(result).toEqual({
3333
protocolVersion: acp.PROTOCOL_VERSION,
3434
agentCapabilities: {
35+
auth: {
36+
logout: {},
37+
},
3538
loadSession: true,
3639
promptCapabilities: {
3740
image: true

0 commit comments

Comments
 (0)