@agentclientprotocol/codex-acp 0.0.43 → 0.0.45

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.
Files changed (2) hide show
  1. package/dist/index.js +484 -169
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -14441,6 +14441,7 @@ var AGENT_METHODS = {
14441
14441
  document_did_save: "document/didSave",
14442
14442
  initialize: "initialize",
14443
14443
  logout: "logout",
14444
+ mcp_message: "mcp/message",
14444
14445
  nes_accept: "nes/accept",
14445
14446
  nes_close: "nes/close",
14446
14447
  nes_reject: "nes/reject",
@@ -14451,6 +14452,7 @@ var AGENT_METHODS = {
14451
14452
  providers_set: "providers/set",
14452
14453
  session_cancel: "session/cancel",
14453
14454
  session_close: "session/close",
14455
+ session_delete: "session/delete",
14454
14456
  session_fork: "session/fork",
14455
14457
  session_list: "session/list",
14456
14458
  session_load: "session/load",
@@ -14466,6 +14468,9 @@ var CLIENT_METHODS = {
14466
14468
  elicitation_create: "elicitation/create",
14467
14469
  fs_read_text_file: "fs/read_text_file",
14468
14470
  fs_write_text_file: "fs/write_text_file",
14471
+ mcp_connect: "mcp/connect",
14472
+ mcp_disconnect: "mcp/disconnect",
14473
+ mcp_message: "mcp/message",
14469
14474
  session_request_permission: "session/request_permission",
14470
14475
  session_update: "session/update",
14471
14476
  terminal_create: "terminal/create",
@@ -14551,6 +14556,9 @@ var zCreateTerminalResponse = external_exports.object({
14551
14556
  _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish(),
14552
14557
  terminalId: external_exports.string()
14553
14558
  });
14559
+ var zDeleteSessionResponse = external_exports.object({
14560
+ _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish()
14561
+ });
14554
14562
  var zDiff = external_exports.object({
14555
14563
  _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish(),
14556
14564
  newText: external_exports.string(),
@@ -14564,6 +14572,9 @@ var zDisableProvidersRequest = external_exports.object({
14564
14572
  var zDisableProvidersResponse = external_exports.object({
14565
14573
  _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish()
14566
14574
  });
14575
+ var zDisconnectMcpResponse = external_exports.object({
14576
+ _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish()
14577
+ });
14567
14578
  var zElicitationContentValue = external_exports.union([
14568
14579
  external_exports.string(),
14569
14580
  external_exports.number(),
@@ -14669,7 +14680,6 @@ var zListProvidersRequest = external_exports.object({
14669
14680
  });
14670
14681
  var zListSessionsRequest = external_exports.object({
14671
14682
  _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish(),
14672
- additionalDirectories: external_exports.array(external_exports.string()).optional(),
14673
14683
  cursor: external_exports.string().nullish(),
14674
14684
  cwd: external_exports.string().nullish()
14675
14685
  });
@@ -14696,9 +14706,29 @@ var zLogoutResponse = external_exports.object({
14696
14706
  });
14697
14707
  var zMcpCapabilities = external_exports.object({
14698
14708
  _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish(),
14709
+ acp: external_exports.boolean().optional().default(false),
14699
14710
  http: external_exports.boolean().optional().default(false),
14700
14711
  sse: external_exports.boolean().optional().default(false)
14701
14712
  });
14713
+ var zMcpConnectionId = external_exports.string();
14714
+ var zConnectMcpResponse = external_exports.object({
14715
+ _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish(),
14716
+ connectionId: zMcpConnectionId
14717
+ });
14718
+ var zDisconnectMcpRequest = external_exports.object({
14719
+ _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish(),
14720
+ connectionId: zMcpConnectionId
14721
+ });
14722
+ var zMcpServerAcpId = external_exports.string();
14723
+ var zConnectMcpRequest = external_exports.object({
14724
+ _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish(),
14725
+ acpId: zMcpServerAcpId
14726
+ });
14727
+ var zMcpServerAcp = external_exports.object({
14728
+ _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish(),
14729
+ id: zMcpServerAcpId,
14730
+ name: external_exports.string()
14731
+ });
14702
14732
  var zMcpServerHttp = external_exports.object({
14703
14733
  _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish(),
14704
14734
  headers: external_exports.array(zHttpHeader),
@@ -14725,8 +14755,24 @@ var zMcpServer = external_exports.union([
14725
14755
  zMcpServerSse.and(external_exports.object({
14726
14756
  type: external_exports.literal("sse")
14727
14757
  })),
14758
+ zMcpServerAcp.and(external_exports.object({
14759
+ type: external_exports.literal("acp")
14760
+ })),
14728
14761
  zMcpServerStdio
14729
14762
  ]);
14763
+ var zMessageMcpNotification = external_exports.object({
14764
+ _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish(),
14765
+ connectionId: zMcpConnectionId,
14766
+ method: external_exports.string(),
14767
+ params: external_exports.record(external_exports.string(), external_exports.unknown()).nullish()
14768
+ });
14769
+ var zMessageMcpRequest = external_exports.object({
14770
+ _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish(),
14771
+ connectionId: zMcpConnectionId,
14772
+ method: external_exports.string(),
14773
+ params: external_exports.record(external_exports.string(), external_exports.unknown()).nullish()
14774
+ });
14775
+ var zMessageMcpResponse = external_exports.unknown();
14730
14776
  var zModelId = external_exports.string();
14731
14777
  var zModelInfo = external_exports.object({
14732
14778
  _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish(),
@@ -15134,6 +15180,9 @@ var zConfigOptionUpdate = external_exports.object({
15134
15180
  _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish(),
15135
15181
  configOptions: external_exports.array(zSessionConfigOption)
15136
15182
  });
15183
+ var zSessionDeleteCapabilities = external_exports.object({
15184
+ _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish()
15185
+ });
15137
15186
  var zSessionForkCapabilities = external_exports.object({
15138
15187
  _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish()
15139
15188
  });
@@ -15164,6 +15213,10 @@ var zCreateTerminalRequest = external_exports.object({
15164
15213
  outputByteLimit: external_exports.number().nullish(),
15165
15214
  sessionId: zSessionId
15166
15215
  });
15216
+ var zDeleteSessionRequest = external_exports.object({
15217
+ _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish(),
15218
+ sessionId: zSessionId
15219
+ });
15167
15220
  var zDidCloseDocumentNotification = external_exports.object({
15168
15221
  _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish(),
15169
15222
  sessionId: zSessionId,
@@ -15313,6 +15366,7 @@ var zSessionCapabilities = external_exports.object({
15313
15366
  _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish(),
15314
15367
  additionalDirectories: zSessionAdditionalDirectoriesCapabilities.nullish(),
15315
15368
  close: zSessionCloseCapabilities.nullish(),
15369
+ delete: zSessionDeleteCapabilities.nullish(),
15316
15370
  fork: zSessionForkCapabilities.nullish(),
15317
15371
  list: zSessionListCapabilities.nullish(),
15318
15372
  resume: zSessionResumeCapabilities.nullish()
@@ -15455,6 +15509,7 @@ var zClientNotification = external_exports.object({
15455
15509
  zDidFocusDocumentNotification,
15456
15510
  zAcceptNesNotification,
15457
15511
  zRejectNesNotification,
15512
+ zMessageMcpNotification,
15458
15513
  zExtNotification
15459
15514
  ]).nullish()
15460
15515
  });
@@ -15487,7 +15542,11 @@ var zAgentCapabilities = external_exports.object({
15487
15542
  _meta: external_exports.record(external_exports.string(), external_exports.unknown()).nullish(),
15488
15543
  auth: zAgentAuthCapabilities.optional().default({}),
15489
15544
  loadSession: external_exports.boolean().optional().default(false),
15490
- mcpCapabilities: zMcpCapabilities.optional().default({ http: false, sse: false }),
15545
+ mcpCapabilities: zMcpCapabilities.optional().default({
15546
+ acp: false,
15547
+ http: false,
15548
+ sse: false
15549
+ }),
15491
15550
  nes: zNesCapabilities.nullish(),
15492
15551
  positionEncoding: zPositionEncodingKind.nullish(),
15493
15552
  promptCapabilities: zPromptCapabilities.optional().default({
@@ -15503,7 +15562,11 @@ var zInitializeResponse = external_exports.object({
15503
15562
  agentCapabilities: zAgentCapabilities.optional().default({
15504
15563
  auth: {},
15505
15564
  loadSession: false,
15506
- mcpCapabilities: { http: false, sse: false },
15565
+ mcpCapabilities: {
15566
+ acp: false,
15567
+ http: false,
15568
+ sse: false
15569
+ },
15507
15570
  promptCapabilities: {
15508
15571
  audio: false,
15509
15572
  embeddedContext: false,
@@ -15734,6 +15797,7 @@ var zAgentResponse = external_exports.union([
15734
15797
  zNewSessionResponse,
15735
15798
  zLoadSessionResponse,
15736
15799
  zListSessionsResponse,
15800
+ zDeleteSessionResponse,
15737
15801
  zForkSessionResponse,
15738
15802
  zResumeSessionResponse,
15739
15803
  zCloseSessionResponse,
@@ -15744,7 +15808,8 @@ var zAgentResponse = external_exports.union([
15744
15808
  zStartNesResponse,
15745
15809
  zSuggestNesResponse,
15746
15810
  zCloseNesResponse,
15747
- zExtResponse
15811
+ zExtResponse,
15812
+ zMessageMcpResponse
15748
15813
  ])
15749
15814
  }),
15750
15815
  external_exports.object({
@@ -15803,6 +15868,7 @@ var zAgentNotification = external_exports.object({
15803
15868
  params: external_exports.union([
15804
15869
  zSessionNotification,
15805
15870
  zCompleteElicitationNotification,
15871
+ zMessageMcpNotification,
15806
15872
  zExtNotification
15807
15873
  ]).nullish()
15808
15874
  });
@@ -15841,6 +15907,7 @@ var zClientRequest = external_exports.object({
15841
15907
  zNewSessionRequest,
15842
15908
  zLoadSessionRequest,
15843
15909
  zListSessionsRequest,
15910
+ zDeleteSessionRequest,
15844
15911
  zForkSessionRequest,
15845
15912
  zResumeSessionRequest,
15846
15913
  zCloseSessionRequest,
@@ -15851,6 +15918,7 @@ var zClientRequest = external_exports.object({
15851
15918
  zStartNesRequest,
15852
15919
  zSuggestNesRequest,
15853
15920
  zCloseNesRequest,
15921
+ zMessageMcpRequest,
15854
15922
  zExtRequest
15855
15923
  ]).nullish()
15856
15924
  });
@@ -15873,6 +15941,9 @@ var zAgentRequest = external_exports.object({
15873
15941
  zWaitForTerminalExitRequest,
15874
15942
  zKillTerminalRequest,
15875
15943
  zCreateElicitationRequest,
15944
+ zConnectMcpRequest,
15945
+ zMessageMcpRequest,
15946
+ zDisconnectMcpRequest,
15876
15947
  zExtRequest
15877
15948
  ]).nullish()
15878
15949
  });
@@ -15892,7 +15963,10 @@ var zClientResponse = external_exports.union([
15892
15963
  zWaitForTerminalExitResponse,
15893
15964
  zKillTerminalResponse,
15894
15965
  zCreateElicitationResponse,
15895
- zExtResponse
15966
+ zConnectMcpResponse,
15967
+ zDisconnectMcpResponse,
15968
+ zExtResponse,
15969
+ zMessageMcpResponse
15896
15970
  ])
15897
15971
  }),
15898
15972
  external_exports.object({
@@ -15967,6 +16041,15 @@ function ndJsonStream(output, input) {
15967
16041
  }
15968
16042
 
15969
16043
  // node_modules/@agentclientprotocol/sdk/dist/acp.js
16044
+ function emptyObjectResponse(response) {
16045
+ return response ?? {};
16046
+ }
16047
+ function rejectedPromise(error40) {
16048
+ const promise2 = Promise.reject(error40);
16049
+ promise2.catch(() => {
16050
+ });
16051
+ return promise2;
16052
+ }
15970
16053
  var AgentSideConnection = class {
15971
16054
  connection;
15972
16055
  /**
@@ -16007,6 +16090,14 @@ var AgentSideConnection = class {
16007
16090
  const validatedParams = zListSessionsRequest.parse(params);
16008
16091
  return agent.listSessions(validatedParams);
16009
16092
  }
16093
+ case AGENT_METHODS.session_delete: {
16094
+ if (!agent.unstable_deleteSession) {
16095
+ throw RequestError.methodNotFound(method);
16096
+ }
16097
+ const validatedParams = zDeleteSessionRequest.parse(params);
16098
+ const result = await agent.unstable_deleteSession(validatedParams);
16099
+ return result ?? {};
16100
+ }
16010
16101
  case AGENT_METHODS.session_fork: {
16011
16102
  if (!agent.unstable_forkSession) {
16012
16103
  throw RequestError.methodNotFound(method);
@@ -16191,8 +16282,8 @@ var AgentSideConnection = class {
16191
16282
  *
16192
16283
  * See protocol docs: [Agent Reports Output](https://agentclientprotocol.com/protocol/prompt-turn#3-agent-reports-output)
16193
16284
  */
16194
- async sessionUpdate(params) {
16195
- return await this.connection.sendNotification(CLIENT_METHODS.session_update, params);
16285
+ sessionUpdate(params) {
16286
+ return this.connection.sendNotification(CLIENT_METHODS.session_update, params);
16196
16287
  }
16197
16288
  /**
16198
16289
  * Requests permission from the user for a tool call operation.
@@ -16206,8 +16297,8 @@ var AgentSideConnection = class {
16206
16297
  *
16207
16298
  * See protocol docs: [Requesting Permission](https://agentclientprotocol.com/protocol/tool-calls#requesting-permission)
16208
16299
  */
16209
- async requestPermission(params) {
16210
- return await this.connection.sendRequest(CLIENT_METHODS.session_request_permission, params);
16300
+ requestPermission(params) {
16301
+ return this.connection.sendRequest(CLIENT_METHODS.session_request_permission, params);
16211
16302
  }
16212
16303
  /**
16213
16304
  * Reads content from a text file in the client's file system.
@@ -16217,8 +16308,8 @@ var AgentSideConnection = class {
16217
16308
  *
16218
16309
  * See protocol docs: [Client](https://agentclientprotocol.com/protocol/overview#client)
16219
16310
  */
16220
- async readTextFile(params) {
16221
- return await this.connection.sendRequest(CLIENT_METHODS.fs_read_text_file, params);
16311
+ readTextFile(params) {
16312
+ return this.connection.sendRequest(CLIENT_METHODS.fs_read_text_file, params);
16222
16313
  }
16223
16314
  /**
16224
16315
  * Writes content to a text file in the client's file system.
@@ -16228,8 +16319,8 @@ var AgentSideConnection = class {
16228
16319
  *
16229
16320
  * See protocol docs: [Client](https://agentclientprotocol.com/protocol/overview#client)
16230
16321
  */
16231
- async writeTextFile(params) {
16232
- return await this.connection.sendRequest(CLIENT_METHODS.fs_write_text_file, params) ?? {};
16322
+ writeTextFile(params) {
16323
+ return this.connection.sendRequest(CLIENT_METHODS.fs_write_text_file, params, emptyObjectResponse);
16233
16324
  }
16234
16325
  /**
16235
16326
  * Executes a command in a new terminal.
@@ -16243,9 +16334,8 @@ var AgentSideConnection = class {
16243
16334
  * @param params - The terminal creation parameters
16244
16335
  * @returns A handle to control and monitor the terminal
16245
16336
  */
16246
- async createTerminal(params) {
16247
- const response = await this.connection.sendRequest(CLIENT_METHODS.terminal_create, params);
16248
- return new TerminalHandle(response.terminalId, params.sessionId, this.connection);
16337
+ createTerminal(params) {
16338
+ return this.connection.sendRequest(CLIENT_METHODS.terminal_create, params, (response) => new TerminalHandle(response.terminalId, params.sessionId, this.connection));
16249
16339
  }
16250
16340
  /**
16251
16341
  * **UNSTABLE**
@@ -16256,8 +16346,8 @@ var AgentSideConnection = class {
16256
16346
  *
16257
16347
  * @experimental
16258
16348
  */
16259
- async unstable_createElicitation(params) {
16260
- return await this.connection.sendRequest(CLIENT_METHODS.elicitation_create, params);
16349
+ unstable_createElicitation(params) {
16350
+ return this.connection.sendRequest(CLIENT_METHODS.elicitation_create, params);
16261
16351
  }
16262
16352
  /**
16263
16353
  * **UNSTABLE**
@@ -16268,24 +16358,24 @@ var AgentSideConnection = class {
16268
16358
  *
16269
16359
  * @experimental
16270
16360
  */
16271
- async unstable_completeElicitation(params) {
16272
- return await this.connection.sendNotification(CLIENT_METHODS.elicitation_complete, params);
16361
+ unstable_completeElicitation(params) {
16362
+ return this.connection.sendNotification(CLIENT_METHODS.elicitation_complete, params);
16273
16363
  }
16274
16364
  /**
16275
16365
  * Extension method
16276
16366
  *
16277
16367
  * Allows the Agent to send an arbitrary request that is not part of the ACP spec.
16278
16368
  */
16279
- async extMethod(method, params) {
16280
- return await this.connection.sendRequest(method, params);
16369
+ extMethod(method, params) {
16370
+ return this.connection.sendRequest(method, params);
16281
16371
  }
16282
16372
  /**
16283
16373
  * Extension notification
16284
16374
  *
16285
16375
  * Allows the Agent to send an arbitrary notification that is not part of the ACP spec.
16286
16376
  */
16287
- async extNotification(method, params) {
16288
- return await this.connection.sendNotification(method, params);
16377
+ extNotification(method, params) {
16378
+ return this.connection.sendNotification(method, params);
16289
16379
  }
16290
16380
  /**
16291
16381
  * AbortSignal that aborts when the connection closes.
@@ -16349,8 +16439,8 @@ var TerminalHandle = class {
16349
16439
  /**
16350
16440
  * Gets the current terminal output without waiting for the command to exit.
16351
16441
  */
16352
- async currentOutput() {
16353
- return await this.connection.sendRequest(CLIENT_METHODS.terminal_output, {
16442
+ currentOutput() {
16443
+ return this.connection.sendRequest(CLIENT_METHODS.terminal_output, {
16354
16444
  sessionId: this.sessionId,
16355
16445
  terminalId: this.id
16356
16446
  });
@@ -16358,8 +16448,8 @@ var TerminalHandle = class {
16358
16448
  /**
16359
16449
  * Waits for the terminal command to complete and returns its exit status.
16360
16450
  */
16361
- async waitForExit() {
16362
- return await this.connection.sendRequest(CLIENT_METHODS.terminal_wait_for_exit, {
16451
+ waitForExit() {
16452
+ return this.connection.sendRequest(CLIENT_METHODS.terminal_wait_for_exit, {
16363
16453
  sessionId: this.sessionId,
16364
16454
  terminalId: this.id
16365
16455
  });
@@ -16374,11 +16464,11 @@ var TerminalHandle = class {
16374
16464
  *
16375
16465
  * Useful for implementing timeouts or cancellation.
16376
16466
  */
16377
- async kill() {
16378
- return await this.connection.sendRequest(CLIENT_METHODS.terminal_kill, {
16467
+ kill() {
16468
+ return this.connection.sendRequest(CLIENT_METHODS.terminal_kill, {
16379
16469
  sessionId: this.sessionId,
16380
16470
  terminalId: this.id
16381
- }) ?? {};
16471
+ }, emptyObjectResponse);
16382
16472
  }
16383
16473
  /**
16384
16474
  * Releases the terminal and frees all associated resources.
@@ -16392,11 +16482,11 @@ var TerminalHandle = class {
16392
16482
  *
16393
16483
  * **Important:** Always call this method when done with the terminal.
16394
16484
  */
16395
- async release() {
16396
- return await this.connection.sendRequest(CLIENT_METHODS.terminal_release, {
16485
+ release() {
16486
+ return this.connection.sendRequest(CLIENT_METHODS.terminal_release, {
16397
16487
  sessionId: this.sessionId,
16398
16488
  terminalId: this.id
16399
- }) ?? {};
16489
+ }, emptyObjectResponse);
16400
16490
  }
16401
16491
  async [Symbol.asyncDispose]() {
16402
16492
  await this.release();
@@ -16581,25 +16671,36 @@ var Connection = class {
16581
16671
  console.error("Got response to unknown request", response.id);
16582
16672
  }
16583
16673
  }
16584
- sendRequest(method, params) {
16585
- this.throwIfClosed();
16674
+ sendRequest(method, params, mapResponse) {
16675
+ if (this.abortController.signal.aborted) {
16676
+ return rejectedPromise(this.closedReason());
16677
+ }
16586
16678
  const id = this.nextRequestId++;
16587
16679
  const responsePromise = new Promise((resolve, reject) => {
16588
- this.pendingResponses.set(id, { resolve, reject });
16680
+ this.pendingResponses.set(id, {
16681
+ resolve: (response) => {
16682
+ try {
16683
+ resolve(mapResponse ? mapResponse(response) : response);
16684
+ } catch (error40) {
16685
+ reject(error40);
16686
+ }
16687
+ },
16688
+ reject
16689
+ });
16589
16690
  });
16590
16691
  responsePromise.catch(() => {
16591
16692
  });
16592
16693
  void this.sendMessage({ jsonrpc: "2.0", id, method, params });
16593
16694
  return responsePromise;
16594
16695
  }
16595
- async sendNotification(method, params) {
16596
- this.throwIfClosed();
16597
- await this.sendMessage({ jsonrpc: "2.0", method, params });
16598
- }
16599
- throwIfClosed() {
16696
+ sendNotification(method, params) {
16600
16697
  if (this.abortController.signal.aborted) {
16601
- throw this.abortController.signal.reason ?? new Error("ACP connection closed");
16698
+ return rejectedPromise(this.closedReason());
16602
16699
  }
16700
+ return this.sendMessage({ jsonrpc: "2.0", method, params });
16701
+ }
16702
+ closedReason() {
16703
+ return this.abortController.signal.reason ?? new Error("ACP connection closed");
16603
16704
  }
16604
16705
  async sendMessage(message) {
16605
16706
  this.writeQueue = this.writeQueue.then(async () => {
@@ -17369,7 +17470,7 @@ function createCommandActionEvent(id, status, cwd, commandAction) {
17369
17470
  toolCallId: id,
17370
17471
  status: acpStatus,
17371
17472
  kind: "read",
17372
- title: "Read file",
17473
+ title: `Read file '${commandAction.path}'`,
17373
17474
  locations: [{ path: commandAction.path }]
17374
17475
  };
17375
17476
  } else if (commandAction.type === "search") {
@@ -17536,6 +17637,27 @@ var CodexEventHandler = class {
17536
17637
  return null;
17537
17638
  case "thread/tokenUsage/updated":
17538
17639
  return this.createUsageUpdate(notification.params);
17640
+ case "thread/name/updated":
17641
+ return {
17642
+ sessionUpdate: "session_info_update",
17643
+ title: notification.params.threadName ?? null
17644
+ };
17645
+ case "thread/status/changed":
17646
+ return this.createCodexSessionInfoUpdate({
17647
+ threadStatus: notification.params.status
17648
+ });
17649
+ case "thread/archived":
17650
+ return this.createCodexSessionInfoUpdate({
17651
+ archived: true
17652
+ });
17653
+ case "thread/unarchived":
17654
+ return this.createCodexSessionInfoUpdate({
17655
+ archived: false
17656
+ });
17657
+ case "thread/closed":
17658
+ return this.createCodexSessionInfoUpdate({
17659
+ closed: true
17660
+ });
17539
17661
  case "item/commandExecution/outputDelta":
17540
17662
  return this.createCommandOutputDeltaEvent(notification.params);
17541
17663
  case "item/mcpToolCall/progress":
@@ -17582,10 +17704,6 @@ var CodexEventHandler = class {
17582
17704
  case "serverRequest/resolved":
17583
17705
  case "model/verification":
17584
17706
  case "windows/worldWritableWarning":
17585
- case "thread/status/changed":
17586
- case "thread/archived":
17587
- case "thread/unarchived":
17588
- case "thread/closed":
17589
17707
  case "thread/realtime/started":
17590
17708
  case "thread/realtime/itemAdded":
17591
17709
  case "thread/realtime/transcript/delta":
@@ -17602,7 +17720,6 @@ var CodexEventHandler = class {
17602
17720
  case "externalAgentConfig/import/completed":
17603
17721
  case "rawResponseItem/completed":
17604
17722
  case "thread/started":
17605
- case "thread/name/updated":
17606
17723
  case "item/plan/delta":
17607
17724
  case "thread/goal/updated":
17608
17725
  case "thread/goal/cleared":
@@ -17611,6 +17728,14 @@ var CodexEventHandler = class {
17611
17728
  return null;
17612
17729
  }
17613
17730
  }
17731
+ createCodexSessionInfoUpdate(codexMetadata) {
17732
+ return {
17733
+ sessionUpdate: "session_info_update",
17734
+ _meta: {
17735
+ codex: codexMetadata
17736
+ }
17737
+ };
17738
+ }
17614
17739
  async createTextEvent(event) {
17615
17740
  return {
17616
17741
  sessionUpdate: "agent_message_chunk",
@@ -18000,12 +18125,19 @@ var CodexApprovalHandler = class {
18000
18125
  }
18001
18126
  };
18002
18127
 
18128
+ // src/McpApprovalOptionId.ts
18129
+ var McpApprovalOptionId = {
18130
+ AllowOnce: "allow_once",
18131
+ AllowSession: "allow_session",
18132
+ AllowAlways: "allow_always",
18133
+ Decline: "decline"
18134
+ };
18135
+
18003
18136
  // src/CodexElicitationHandler.ts
18004
18137
  var ELICITATION_OPTIONS = [
18005
18138
  { optionId: "accept", name: "Accept", kind: "allow_once" },
18006
18139
  { optionId: "decline", name: "Decline", kind: "reject_once" }
18007
18140
  ];
18008
- var OPTION_ALLOW_SESSION = "allow_session";
18009
18141
  function parsePersistOptions(meta) {
18010
18142
  const result = /* @__PURE__ */ new Set();
18011
18143
  if (!meta || typeof meta !== "object") return result;
@@ -18025,15 +18157,15 @@ function isMcpToolCallApproval(meta) {
18025
18157
  }
18026
18158
  function buildToolApprovalOptions(persistOptions) {
18027
18159
  const options = [
18028
- { optionId: ApprovalOptionId.AllowOnce, name: "Allow", kind: "allow_once" }
18160
+ { optionId: McpApprovalOptionId.AllowOnce, name: "Allow", kind: "allow_once" }
18029
18161
  ];
18030
18162
  if (persistOptions.has("session")) {
18031
- options.push({ optionId: OPTION_ALLOW_SESSION, name: "Allow for This Session", kind: "allow_always" });
18163
+ options.push({ optionId: McpApprovalOptionId.AllowSession, name: "Allow for This Session", kind: "allow_always" });
18032
18164
  }
18033
18165
  if (persistOptions.has("always")) {
18034
- options.push({ optionId: ApprovalOptionId.AllowAlways, name: "Allow and Don't Ask Again", kind: "allow_always" });
18166
+ options.push({ optionId: McpApprovalOptionId.AllowAlways, name: "Allow and Don't Ask Again", kind: "allow_always" });
18035
18167
  }
18036
- options.push({ optionId: "decline", name: "Decline", kind: "reject_once" });
18168
+ options.push({ optionId: McpApprovalOptionId.Decline, name: "Decline", kind: "reject_once" });
18037
18169
  return options;
18038
18170
  }
18039
18171
  var CodexElicitationHandler = class {
@@ -18080,7 +18212,7 @@ var CodexElicitationHandler = class {
18080
18212
  const response = await this.connection.requestPermission(request);
18081
18213
  if (correlatedCallId !== void 0 && response.outcome.outcome !== "cancelled") {
18082
18214
  const optionId = response.outcome.optionId;
18083
- if (optionId !== "decline") {
18215
+ if (optionId !== McpApprovalOptionId.Decline) {
18084
18216
  await this.connection.sessionUpdate({
18085
18217
  sessionId: this.sessionState.sessionId,
18086
18218
  update: { sessionUpdate: "tool_call_update", toolCallId: correlatedCallId, status: "in_progress" }
@@ -18158,13 +18290,13 @@ var CodexElicitationHandler = class {
18158
18290
  return { action: "cancel", content: null, _meta: null };
18159
18291
  }
18160
18292
  const optionId = response.outcome.optionId;
18161
- if (optionId === OPTION_ALLOW_SESSION) {
18293
+ if (optionId === McpApprovalOptionId.AllowSession) {
18162
18294
  return { action: "accept", content: null, _meta: { persist: "session" } };
18163
18295
  }
18164
- if (optionId === ApprovalOptionId.AllowAlways) {
18296
+ if (optionId === McpApprovalOptionId.AllowAlways) {
18165
18297
  return { action: "accept", content: null, _meta: { persist: "always" } };
18166
18298
  }
18167
- if (optionId === ApprovalOptionId.AllowOnce || optionId === "accept") {
18299
+ if (optionId === McpApprovalOptionId.AllowOnce || optionId === "accept") {
18168
18300
  return { action: "accept", content: null, _meta: null };
18169
18301
  }
18170
18302
  return { action: "decline", content: null, _meta: null };
@@ -18958,7 +19090,7 @@ var package_default = {
18958
19090
  publishConfig: {
18959
19091
  access: "public"
18960
19092
  },
18961
- version: "0.0.43",
19093
+ version: "0.0.45",
18962
19094
  description: "",
18963
19095
  main: "dist/index.js",
18964
19096
  bin: {
@@ -19016,7 +19148,7 @@ var package_default = {
19016
19148
  vitest: "^4.0.10"
19017
19149
  },
19018
19150
  dependencies: {
19019
- "@agentclientprotocol/sdk": "^0.21.0",
19151
+ "@agentclientprotocol/sdk": "^0.22.1",
19020
19152
  "@openai/codex": "^0.128.0",
19021
19153
  diff: "^8.0.3",
19022
19154
  open: "^11.0.0",
@@ -19160,15 +19292,9 @@ var CodexAcpClient = class {
19160
19292
  async resumeSession(request) {
19161
19293
  await this.refreshSkills(request.cwd, request._meta);
19162
19294
  const response = await this.codexClient.threadResume({
19163
- approvalPolicy: null,
19164
- sandbox: null,
19165
- baseInstructions: null,
19166
- config: this.createSessionConfig(request.cwd, request.mcpServers ?? []),
19295
+ config: await this.createSessionConfig(request.cwd, request.mcpServers ?? []),
19167
19296
  cwd: request.cwd,
19168
- developerInstructions: null,
19169
- model: null,
19170
19297
  modelProvider: this.getResumeModelProvider(),
19171
- personality: null,
19172
19298
  threadId: request.sessionId
19173
19299
  });
19174
19300
  const codexModels = await this.fetchAvailableModels();
@@ -19176,20 +19302,15 @@ var CodexAcpClient = class {
19176
19302
  return {
19177
19303
  sessionId: request.sessionId,
19178
19304
  currentModelId,
19179
- models: codexModels
19305
+ models: codexModels,
19306
+ currentServiceTier: response.serviceTier ?? null
19180
19307
  };
19181
19308
  }
19182
19309
  async loadSession(request) {
19183
19310
  const response = await this.codexClient.threadResume({
19184
- approvalPolicy: null,
19185
- sandbox: null,
19186
- baseInstructions: null,
19187
- config: this.createSessionConfig(request.cwd, request.mcpServers ?? []),
19311
+ config: await this.createSessionConfig(request.cwd, request.mcpServers ?? []),
19188
19312
  cwd: request.cwd,
19189
- developerInstructions: null,
19190
- model: null,
19191
19313
  modelProvider: this.getResumeModelProvider(),
19192
- personality: null,
19193
19314
  threadId: request.sessionId
19194
19315
  });
19195
19316
  const codexModels = await this.fetchAvailableModels();
@@ -19198,22 +19319,16 @@ var CodexAcpClient = class {
19198
19319
  sessionId: request.sessionId,
19199
19320
  currentModelId,
19200
19321
  models: codexModels,
19322
+ currentServiceTier: response.serviceTier ?? null,
19201
19323
  thread: response.thread
19202
19324
  };
19203
19325
  }
19204
19326
  async newSession(request) {
19205
19327
  await this.refreshSkills(request.cwd, request._meta);
19206
19328
  const response = await this.codexClient.threadStart({
19207
- config: this.createSessionConfig(request.cwd, request.mcpServers),
19329
+ config: await this.createSessionConfig(request.cwd, request.mcpServers),
19208
19330
  modelProvider: this.getModelProvider(),
19209
- model: null,
19210
- cwd: request.cwd,
19211
- approvalPolicy: null,
19212
- sandbox: null,
19213
- baseInstructions: null,
19214
- developerInstructions: null,
19215
- personality: null,
19216
- ephemeral: null
19331
+ cwd: request.cwd
19217
19332
  });
19218
19333
  const codexModels = await this.fetchAvailableModels();
19219
19334
  if (codexModels.length === 0) {
@@ -19223,7 +19338,8 @@ var CodexAcpClient = class {
19223
19338
  return {
19224
19339
  sessionId: response.thread.id,
19225
19340
  currentModelId,
19226
- models: codexModels
19341
+ models: codexModels,
19342
+ currentServiceTier: response.serviceTier ?? null
19227
19343
  };
19228
19344
  }
19229
19345
  async awaitMcpServerStartup(serverNames, afterVersion) {
@@ -19232,7 +19348,7 @@ var CodexAcpClient = class {
19232
19348
  getMcpServerStartupVersion() {
19233
19349
  return this.codexClient.getMcpServerStartupVersion();
19234
19350
  }
19235
- createSessionConfig(projectPath, mcpServers) {
19351
+ async createSessionConfig(projectPath, mcpServers) {
19236
19352
  const mergedConfig = {
19237
19353
  ...mergeGatewayConfig(this.config, this.gatewayConfig),
19238
19354
  projects: {
@@ -19244,11 +19360,24 @@ var CodexAcpClient = class {
19244
19360
  if (mcpServers.length === 0) {
19245
19361
  return mergedConfig;
19246
19362
  }
19363
+ const existingNames = await this.getConfigMcpServerNames(projectPath);
19364
+ const uniqueServers = mcpServers.filter((mcp) => !existingNames.has(mcp.name));
19365
+ if (uniqueServers.length === 0) {
19366
+ return mergedConfig;
19367
+ }
19247
19368
  return {
19248
19369
  ...mergedConfig,
19249
- "mcp_servers": Object.fromEntries(mcpServers.map((mcp) => [mcp.name, this.createMcpSeverConfig(mcp)]))
19370
+ "mcp_servers": Object.fromEntries(uniqueServers.map((mcp) => [mcp.name, this.createMcpSeverConfig(mcp)]))
19250
19371
  };
19251
19372
  }
19373
+ async getConfigMcpServerNames(projectPath) {
19374
+ const response = await this.codexClient.configRead({ includeLayers: true, cwd: projectPath });
19375
+ const mcpServers = response?.config?.["mcp_servers"];
19376
+ if (!mcpServers || typeof mcpServers !== "object" || Array.isArray(mcpServers)) {
19377
+ return /* @__PURE__ */ new Set();
19378
+ }
19379
+ return new Set(Object.keys(mcpServers));
19380
+ }
19252
19381
  getModelProvider() {
19253
19382
  return this.gatewayConfig?.modelProvider ?? this.modelProvider;
19254
19383
  }
@@ -19274,13 +19403,17 @@ var CodexAcpClient = class {
19274
19403
  */
19275
19404
  createMcpSeverConfig(mcpServer) {
19276
19405
  if ("type" in mcpServer) {
19277
- if (mcpServer.type == "sse") {
19278
- throw RequestError.invalidRequest("Codex doesn't support MCP SSE transport protocol");
19406
+ switch (mcpServer.type) {
19407
+ case "acp":
19408
+ throw RequestError.invalidRequest("Codex doesn't support MCP ACP transport protocol");
19409
+ case "sse":
19410
+ throw RequestError.invalidRequest("Codex doesn't support MCP SSE transport protocol");
19411
+ case "http":
19412
+ return {
19413
+ "url": mcpServer.url,
19414
+ "http_headers": Object.fromEntries(mcpServer.headers.map((h) => [h.name, h.value]))
19415
+ };
19279
19416
  }
19280
- return {
19281
- "url": mcpServer.url,
19282
- "http_headers": Object.fromEntries(mcpServer.headers.map((h) => [h.name, h.value]))
19283
- };
19284
19417
  }
19285
19418
  return {
19286
19419
  "command": mcpServer.command,
@@ -19304,23 +19437,20 @@ var CodexAcpClient = class {
19304
19437
  this.codexClient.onApprovalRequest(sessionId, approvalHandler);
19305
19438
  this.codexClient.onElicitationRequest(sessionId, elicitationHandler);
19306
19439
  }
19307
- async sendPrompt(request, agentMode, modelId, disableSummary, cwd) {
19440
+ async sendPrompt(request, agentMode, modelId, serviceTier, disableSummary, cwd) {
19308
19441
  const input = buildPromptItems(request.prompt);
19309
19442
  const effort = modelId.effort;
19310
19443
  await this.refreshSkills(cwd, request._meta);
19311
- await this.codexClient.turnStart({
19312
- outputSchema: null,
19444
+ return await this.codexClient.runTurn({
19313
19445
  threadId: request.sessionId,
19314
19446
  input,
19315
19447
  approvalPolicy: agentMode.approvalPolicy,
19316
19448
  sandboxPolicy: agentMode.sandboxPolicy,
19317
19449
  summary: disableSummary ? "none" : null,
19318
- personality: null,
19319
- cwd: null,
19320
19450
  effort,
19321
- model: modelId.model
19451
+ model: modelId.model,
19452
+ serviceTier
19322
19453
  });
19323
- return await this.codexClient.awaitTurnCompleted();
19324
19454
  }
19325
19455
  async listSkills(params) {
19326
19456
  return this.codexClient.listSkills(params ?? {});
@@ -19362,8 +19492,8 @@ var CodexAcpClient = class {
19362
19492
  });
19363
19493
  });
19364
19494
  }
19365
- async listMcpServers(params = { cursor: null, limit: null }) {
19366
- return this.codexClient.listMcpServerStatus(params);
19495
+ async listMcpServers() {
19496
+ return this.codexClient.listMcpServerStatus({});
19367
19497
  }
19368
19498
  async listSessions(request) {
19369
19499
  const sourceKinds = [
@@ -19391,11 +19521,8 @@ var CodexAcpClient = class {
19391
19521
  const modelProviders = preferredProvider ? [preferredProvider] : [];
19392
19522
  const listResponse = await this.codexClient.threadList({
19393
19523
  cursor: request.cursor ?? null,
19394
- limit: null,
19395
- sortKey: null,
19396
19524
  modelProviders,
19397
- sourceKinds,
19398
- archived: null
19525
+ sourceKinds
19399
19526
  });
19400
19527
  if (listResponse.data.length === 0) {
19401
19528
  const diagnostics = await this.runSessionListDiagnostics();
@@ -19404,14 +19531,14 @@ var CodexAcpClient = class {
19404
19531
  let sessions = listResponse.data.map((thread) => ({
19405
19532
  sessionId: thread.id,
19406
19533
  cwd: thread.cwd,
19407
- title: thread.preview || null,
19534
+ title: (thread.name ?? thread.preview) || null,
19408
19535
  updatedAt: new Date(thread.updatedAt * 1e3).toISOString()
19409
19536
  }));
19410
19537
  if (requestedCwd) {
19411
19538
  const filtered = listResponse.data.filter(filterByCwd).map((thread) => ({
19412
19539
  sessionId: thread.id,
19413
19540
  cwd: thread.cwd,
19414
- title: thread.preview || null,
19541
+ title: (thread.name ?? thread.preview) || null,
19415
19542
  updatedAt: new Date(thread.updatedAt * 1e3).toISOString()
19416
19543
  }));
19417
19544
  if (filtered.length > 0 || path4.isAbsolute(requestedCwd)) {
@@ -19443,30 +19570,9 @@ var CodexAcpClient = class {
19443
19570
  }
19444
19571
  async runSessionListDiagnostics() {
19445
19572
  const [allProviders, archivedAllProviders, customGateway] = await Promise.all([
19446
- this.codexClient.threadList({
19447
- cursor: null,
19448
- limit: null,
19449
- sortKey: null,
19450
- modelProviders: [],
19451
- sourceKinds: null,
19452
- archived: null
19453
- }),
19454
- this.codexClient.threadList({
19455
- cursor: null,
19456
- limit: null,
19457
- sortKey: null,
19458
- modelProviders: [],
19459
- sourceKinds: null,
19460
- archived: true
19461
- }),
19462
- this.codexClient.threadList({
19463
- cursor: null,
19464
- limit: null,
19465
- sortKey: null,
19466
- modelProviders: ["custom-gateway"],
19467
- sourceKinds: null,
19468
- archived: null
19469
- })
19573
+ this.codexClient.threadList({}),
19574
+ this.codexClient.threadList({ archived: true }),
19575
+ this.codexClient.threadList({ modelProviders: ["custom-gateway"] })
19470
19576
  ]);
19471
19577
  return {
19472
19578
  allProviders: {
@@ -19571,13 +19677,6 @@ var CodexCommands = class {
19571
19677
  logger.error(`Failed to publish available commands for session ${sessionId}`, err);
19572
19678
  }
19573
19679
  }
19574
- async tryHandle(prompt, sessionState) {
19575
- const command = this.parseCommand(prompt);
19576
- if (command) {
19577
- return this.handleCommand(command, sessionState);
19578
- }
19579
- return false;
19580
- }
19581
19680
  buildAvailableCommands(skillsEntries) {
19582
19681
  const commands = /* @__PURE__ */ new Map();
19583
19682
  for (const builtin of this.getBuiltinCommands()) {
@@ -19624,25 +19723,21 @@ var CodexCommands = class {
19624
19723
  }
19625
19724
  ];
19626
19725
  }
19627
- parseCommand(prompt) {
19628
- if (prompt.length !== 1) return null;
19629
- const [single] = prompt;
19630
- if (!single) return null;
19631
- if (single.type !== "text") return null;
19632
- const trimmed = single.text.trim();
19633
- if (!trimmed.startsWith("/")) return null;
19634
- const commandText = trimmed.slice(1).trim();
19726
+ getCommandName(prompt) {
19727
+ const firstBlock = prompt[0];
19728
+ if (!firstBlock || firstBlock.type != "text") return null;
19729
+ const text = firstBlock.text.trim();
19730
+ if (!text.startsWith("/")) return null;
19731
+ const commandText = text.slice(1).trim();
19635
19732
  if (commandText.length === 0) return null;
19636
- const [name, ...rest] = commandText.split(/\s+/);
19637
- const input = rest.join(" ").trim();
19638
- return {
19639
- name: name.toLowerCase(),
19640
- input: input.length > 0 ? input : null
19641
- };
19733
+ const [name] = commandText.split(/\s+/);
19734
+ return name?.toLowerCase() ?? null;
19642
19735
  }
19643
- async handleCommand(command, sessionState) {
19736
+ async tryHandleCommand(prompt, sessionState) {
19737
+ const commandName = this.getCommandName(prompt);
19738
+ if (commandName === null) return false;
19644
19739
  const sessionId = sessionState.sessionId;
19645
- switch (command.name) {
19740
+ switch (commandName) {
19646
19741
  case "status": {
19647
19742
  const session = new ACPSessionConnection(this.connection, sessionId);
19648
19743
  const message = this.buildStatusMessage(sessionState);
@@ -19694,7 +19789,7 @@ var CodexCommands = class {
19694
19789
  return true;
19695
19790
  }
19696
19791
  default:
19697
- await this.sendUnknownCommandMessage(command.name, sessionId);
19792
+ await this.sendUnknownCommandMessage(commandName, sessionId);
19698
19793
  return true;
19699
19794
  }
19700
19795
  }
@@ -19851,8 +19946,47 @@ function isExtMethodRequest(request) {
19851
19946
  return request.method === "authentication/status" || request.method === "authentication/logout";
19852
19947
  }
19853
19948
 
19949
+ // src/FastModeConfig.ts
19950
+ var FAST_MODE_CONFIG_ID = "fast-mode";
19951
+ var FAST_MODE_ON = "on";
19952
+ var FAST_MODE_OFF = "off";
19953
+ var FAST_MODE_DESCRIPTION = "1.5x speed, increased usage";
19954
+ function modelSupportsFast(model) {
19955
+ return model?.additionalSpeedTiers?.includes("fast") ?? false;
19956
+ }
19957
+ function resolveFastServiceTier(fastModeEnabled, currentModelSupportsFast) {
19958
+ return fastModeEnabled && currentModelSupportsFast ? "fast" : null;
19959
+ }
19960
+ function createFastModeConfigOption(fastModeEnabled) {
19961
+ return {
19962
+ id: FAST_MODE_CONFIG_ID,
19963
+ name: "Fast mode",
19964
+ description: FAST_MODE_DESCRIPTION,
19965
+ category: FAST_MODE_CONFIG_ID,
19966
+ type: "select",
19967
+ currentValue: fastModeEnabled ? FAST_MODE_ON : FAST_MODE_OFF,
19968
+ options: [
19969
+ {
19970
+ value: FAST_MODE_OFF,
19971
+ name: "Off",
19972
+ description: "Default speed, normal usage"
19973
+ },
19974
+ {
19975
+ value: FAST_MODE_ON,
19976
+ name: "On",
19977
+ description: FAST_MODE_DESCRIPTION
19978
+ }
19979
+ ]
19980
+ };
19981
+ }
19982
+
19854
19983
  // src/CodexAcpServer.ts
19855
- var CodexAcpServer = class {
19984
+ var CodexAcpServer = class _CodexAcpServer {
19985
+ static MODEL_NAME_TOKEN_OVERRIDES = {
19986
+ gpt: "GPT",
19987
+ mini: "Mini",
19988
+ codex: "Codex"
19989
+ };
19856
19990
  codexAcpClient;
19857
19991
  connection;
19858
19992
  defaultAuthRequest;
@@ -19878,12 +20012,18 @@ var CodexAcpServer = class {
19878
20012
  await this.runWithProcessCheck(() => this.codexAcpClient.initialize(_params));
19879
20013
  return {
19880
20014
  protocolVersion: PROTOCOL_VERSION,
20015
+ agentInfo: {
20016
+ name: package_default.name,
20017
+ title: "Codex",
20018
+ version: package_default.version
20019
+ },
19881
20020
  agentCapabilities: {
19882
20021
  auth: {
19883
20022
  logout: {}
19884
20023
  },
19885
20024
  loadSession: true,
19886
20025
  promptCapabilities: {
20026
+ embeddedContext: true,
19887
20027
  image: true
19888
20028
  },
19889
20029
  sessionCapabilities: {
@@ -19891,6 +20031,7 @@ var CodexAcpServer = class {
19891
20031
  list: {}
19892
20032
  },
19893
20033
  mcpCapabilities: {
20034
+ acp: false,
19894
20035
  http: true,
19895
20036
  sse: false
19896
20037
  }
@@ -19929,6 +20070,23 @@ var CodexAcpServer = class {
19929
20070
  }
19930
20071
  }
19931
20072
  async getOrCreateSession(request) {
20073
+ try {
20074
+ return await this.tryCreateSession(request);
20075
+ } catch (e) {
20076
+ const error40 = e instanceof Error ? e : new Error(String(e));
20077
+ await this.handleError(error40);
20078
+ throw e;
20079
+ }
20080
+ }
20081
+ async handleError(e) {
20082
+ if (e.message.includes("log out")) {
20083
+ await this.runWithProcessCheck(() => this.codexAcpClient.logout());
20084
+ throw RequestError.internalError(`${e.message}
20085
+
20086
+ You have been logged out. Please try again.`);
20087
+ }
20088
+ }
20089
+ async tryCreateSession(request) {
19932
20090
  await this.checkAuthorization();
19933
20091
  const requestedMcpServers = request.mcpServers ?? [];
19934
20092
  const mcpServerStartupVersion = requestedMcpServers.length > 0 ? this.codexAcpClient.getMcpServerStartupVersion() : null;
@@ -19944,6 +20102,7 @@ var CodexAcpServer = class {
19944
20102
  const { sessionId, currentModelId, models } = sessionMetadata;
19945
20103
  const sessionMcpServers = this.resolveSessionMcpServers(requestedMcpServers, "sessionId" in request);
19946
20104
  const currentModel = this.findCurrentModel(models, currentModelId);
20105
+ const currentModelSupportsFast = modelSupportsFast(currentModel);
19947
20106
  const sessionState = {
19948
20107
  sessionId,
19949
20108
  currentModelId,
@@ -19957,6 +20116,8 @@ var CodexAcpServer = class {
19957
20116
  rateLimits: null,
19958
20117
  account,
19959
20118
  cwd: request.cwd,
20119
+ fastModeEnabled: sessionMetadata.currentServiceTier === "fast",
20120
+ currentModelSupportsFast,
19960
20121
  sessionMcpServers
19961
20122
  };
19962
20123
  this.sessions.set(sessionId, sessionState);
@@ -19995,7 +20156,8 @@ var CodexAcpServer = class {
19995
20156
  });
19996
20157
  return {
19997
20158
  models: modelState,
19998
- modes: modeState
20159
+ modes: modeState,
20160
+ configOptions: this.createSessionConfigOptions(this.getSessionState(sessionId))
19999
20161
  };
20000
20162
  }
20001
20163
  async resumeSession(params) {
@@ -20008,7 +20170,8 @@ var CodexAcpServer = class {
20008
20170
  });
20009
20171
  return {
20010
20172
  models: modelState,
20011
- modes: modeState
20173
+ modes: modeState,
20174
+ configOptions: this.createSessionConfigOptions(this.getSessionState(sessionId))
20012
20175
  };
20013
20176
  }
20014
20177
  async listSessions(params) {
@@ -20027,7 +20190,8 @@ var CodexAcpServer = class {
20027
20190
  return {
20028
20191
  sessionId,
20029
20192
  models: modelState,
20030
- modes: modeState
20193
+ modes: modeState,
20194
+ configOptions: this.createSessionConfigOptions(this.getSessionState(sessionId))
20031
20195
  };
20032
20196
  }
20033
20197
  async authenticate(_params) {
@@ -20059,6 +20223,24 @@ var CodexAcpServer = class {
20059
20223
  sessionState.agentMode = newMode;
20060
20224
  return {};
20061
20225
  }
20226
+ async setSessionConfigOption(params) {
20227
+ logger.log("Set session config option requested", {
20228
+ sessionId: params.sessionId,
20229
+ configId: params.configId
20230
+ });
20231
+ const sessionState = this.sessions.get(params.sessionId);
20232
+ if (!sessionState) throw new Error(`Session ${params.sessionId} not found`);
20233
+ if (params.configId !== FAST_MODE_CONFIG_ID || "type" in params && params.type === "boolean") {
20234
+ throw RequestError.invalidParams();
20235
+ }
20236
+ if (params.value !== FAST_MODE_ON && params.value !== FAST_MODE_OFF) {
20237
+ throw RequestError.invalidParams();
20238
+ }
20239
+ sessionState.fastModeEnabled = params.value === FAST_MODE_ON;
20240
+ return {
20241
+ configOptions: this.createSessionConfigOptions(sessionState)
20242
+ };
20243
+ }
20062
20244
  async unstable_setSessionModel(params) {
20063
20245
  logger.log("Set session model requested", {
20064
20246
  sessionId: params.sessionId,
@@ -20088,8 +20270,14 @@ var CodexAcpServer = class {
20088
20270
  sessionState.currentModelId = ModelId.fromComponents(model, reasoningEffort).toString();
20089
20271
  sessionState.supportedReasoningEfforts = model.supportedReasoningEfforts;
20090
20272
  sessionState.supportedInputModalities = model.inputModalities;
20273
+ sessionState.currentModelSupportsFast = modelSupportsFast(model);
20091
20274
  return {};
20092
20275
  }
20276
+ createSessionConfigOptions(sessionState) {
20277
+ return [
20278
+ createFastModeConfigOption(sessionState.fastModeEnabled)
20279
+ ];
20280
+ }
20093
20281
  publishAvailableCommandsAsync(sessionId) {
20094
20282
  void this.availableCommands.publish(sessionId);
20095
20283
  }
@@ -20097,11 +20285,14 @@ var CodexAcpServer = class {
20097
20285
  const modelId = ModelId.fromString(currentModelId);
20098
20286
  return models.find((m) => m.id === modelId.model);
20099
20287
  }
20288
+ normalizeModelDisplayName(displayName) {
20289
+ return displayName.split("-").map((token) => _CodexAcpServer.MODEL_NAME_TOKEN_OVERRIDES[token.toLowerCase()] ?? token).join("-");
20290
+ }
20100
20291
  createModelState(availableModels, selectedModelId) {
20101
20292
  const allowedModels = availableModels.flatMap(
20102
20293
  (model) => model.supportedReasoningEfforts.map((effort) => ({
20103
20294
  modelId: ModelId.fromComponents(model, effort.reasoningEffort).toString(),
20104
- name: `${model.displayName} (${effort.reasoningEffort})`,
20295
+ name: `${this.normalizeModelDisplayName(model.displayName)} (${effort.reasoningEffort})`,
20105
20296
  description: `${model.description} ${effort.description}`
20106
20297
  }))
20107
20298
  );
@@ -20122,6 +20313,7 @@ var CodexAcpServer = class {
20122
20313
  const { sessionId, currentModelId, models, thread } = sessionMetadata;
20123
20314
  const sessionMcpServers = this.resolveSessionMcpServers(requestedMcpServers, true);
20124
20315
  const currentModel = this.findCurrentModel(models, currentModelId);
20316
+ const currentModelSupportsFast = modelSupportsFast(currentModel);
20125
20317
  const sessionState = {
20126
20318
  sessionId,
20127
20319
  currentModelId,
@@ -20135,6 +20327,8 @@ var CodexAcpServer = class {
20135
20327
  rateLimits: null,
20136
20328
  account,
20137
20329
  cwd: request.cwd,
20330
+ fastModeEnabled: sessionMetadata.currentServiceTier === "fast",
20331
+ currentModelSupportsFast,
20138
20332
  sessionMcpServers
20139
20333
  };
20140
20334
  this.sessions.set(sessionId, sessionState);
@@ -20427,7 +20621,7 @@ ${item.text}`
20427
20621
  approvalHandler,
20428
20622
  elicitationHandler
20429
20623
  );
20430
- if (await this.availableCommands.tryHandle(params.prompt, sessionState)) {
20624
+ if (await this.availableCommands.tryHandleCommand(params.prompt, sessionState)) {
20431
20625
  logger.log("Prompt handled by a command");
20432
20626
  return {
20433
20627
  stopReason: "end_turn",
@@ -20448,8 +20642,12 @@ ${item.text}`
20448
20642
  throw RequestError.invalidRequest("The current model does not support image input");
20449
20643
  }
20450
20644
  const agentMode = sessionState.agentMode;
20645
+ const serviceTier = resolveFastServiceTier(
20646
+ sessionState.fastModeEnabled,
20647
+ sessionState.currentModelSupportsFast
20648
+ );
20451
20649
  const turnCompleted = await this.runWithProcessCheck(
20452
- () => this.codexAcpClient.sendPrompt(params, agentMode, modelId, disableSummary, sessionState.cwd)
20650
+ () => this.codexAcpClient.sendPrompt(params, agentMode, modelId, serviceTier, disableSummary, sessionState.cwd)
20453
20651
  );
20454
20652
  if (turnCompleted.turn.status === "interrupted") {
20455
20653
  await this.connection.sessionUpdate({
@@ -20561,6 +20759,8 @@ var CodexAppServerClient = class {
20561
20759
  mcpServerStartupVersion = 0;
20562
20760
  mcpServerStartupStates = /* @__PURE__ */ new Map();
20563
20761
  mcpServerStartupResolvers = [];
20762
+ pendingTurnCompletionResolvers = /* @__PURE__ */ new Map();
20763
+ turnCompletionCaptures = /* @__PURE__ */ new Map();
20564
20764
  constructor(connection) {
20565
20765
  this.connection = connection;
20566
20766
  this.connection.onUnhandledNotification((data) => {
@@ -20574,6 +20774,9 @@ var CodexAppServerClient = class {
20574
20774
  });
20575
20775
  this.resolveMcpServerStartupResolvers();
20576
20776
  }
20777
+ if (isTurnCompletedNotification(serverNotification)) {
20778
+ this.recordTurnCompleted(serverNotification.params);
20779
+ }
20577
20780
  this.notify(serverNotification);
20578
20781
  for (const callback of this.codexEventHandlers) {
20579
20782
  callback({ eventType: "notification", ...serverNotification });
@@ -20613,6 +20816,23 @@ var CodexAppServerClient = class {
20613
20816
  async turnStart(params) {
20614
20817
  return await this.sendRequest({ method: "turn/start", params });
20615
20818
  }
20819
+ async runTurn(params) {
20820
+ const capturedCompletions = [];
20821
+ const releaseCapture = this.captureTurnCompletions(params.threadId, (event) => {
20822
+ capturedCompletions.push(event);
20823
+ });
20824
+ try {
20825
+ const turnStarted = await this.turnStart(params);
20826
+ const earlyCompletion = capturedCompletions.find((event) => event.turn.id === turnStarted.turn.id);
20827
+ releaseCapture();
20828
+ if (earlyCompletion) {
20829
+ return earlyCompletion;
20830
+ }
20831
+ return await this.awaitTurnCompleted(params.threadId, turnStarted.turn.id);
20832
+ } finally {
20833
+ releaseCapture();
20834
+ }
20835
+ }
20616
20836
  async turnInterrupt(params) {
20617
20837
  return await this.sendRequest({ method: "turn/interrupt", params });
20618
20838
  }
@@ -20667,17 +20887,16 @@ var CodexAppServerClient = class {
20667
20887
  return await this.sendRequest({ method: "account/read", params });
20668
20888
  }
20669
20889
  //TODO create type-safe helper
20670
- async awaitTurnCompleted() {
20890
+ async awaitTurnCompleted(threadId, turnId) {
20671
20891
  return await new Promise((resolve) => {
20672
- this.connection.onNotification("turn/completed", (event) => {
20673
- resolve(event);
20674
- });
20892
+ const threadResolvers = this.getOrCreatePendingTurnCompletionResolvers(threadId);
20893
+ threadResolvers.set(turnId, resolve);
20675
20894
  });
20676
20895
  }
20677
- async listModels(params = { cursor: null, limit: null }) {
20896
+ async listModels(params) {
20678
20897
  return await this.sendRequest({ method: "model/list", params });
20679
20898
  }
20680
- async listSkills(params = {}) {
20899
+ async listSkills(params) {
20681
20900
  return await this.sendRequest({ method: "skills/list", params });
20682
20901
  }
20683
20902
  /**
@@ -20693,10 +20912,62 @@ var CodexAppServerClient = class {
20693
20912
  }
20694
20913
  notificationHandlers = /* @__PURE__ */ new Map();
20695
20914
  notify(notification) {
20915
+ const threadId = extractThreadId(notification);
20916
+ if (threadId !== null) {
20917
+ const handler = this.notificationHandlers.get(threadId);
20918
+ if (handler) {
20919
+ handler(notification);
20920
+ }
20921
+ return;
20922
+ }
20696
20923
  for (const notificationHandler of this.notificationHandlers.values()) {
20697
20924
  notificationHandler(notification);
20698
20925
  }
20699
20926
  }
20927
+ recordTurnCompleted(event) {
20928
+ const threadResolvers = this.pendingTurnCompletionResolvers.get(event.threadId);
20929
+ const resolve = threadResolvers?.get(event.turn.id);
20930
+ if (resolve) {
20931
+ threadResolvers.delete(event.turn.id);
20932
+ if (threadResolvers.size === 0) {
20933
+ this.pendingTurnCompletionResolvers.delete(event.threadId);
20934
+ }
20935
+ resolve(event);
20936
+ return;
20937
+ }
20938
+ const captures = this.turnCompletionCaptures.get(event.threadId);
20939
+ if (!captures) {
20940
+ return;
20941
+ }
20942
+ for (const capture of captures) {
20943
+ capture(event);
20944
+ }
20945
+ }
20946
+ getOrCreatePendingTurnCompletionResolvers(threadId) {
20947
+ const existing = this.pendingTurnCompletionResolvers.get(threadId);
20948
+ if (existing) {
20949
+ return existing;
20950
+ }
20951
+ const created = /* @__PURE__ */ new Map();
20952
+ this.pendingTurnCompletionResolvers.set(threadId, created);
20953
+ return created;
20954
+ }
20955
+ captureTurnCompletions(threadId, capture) {
20956
+ const captures = this.turnCompletionCaptures.get(threadId) ?? /* @__PURE__ */ new Set();
20957
+ captures.add(capture);
20958
+ this.turnCompletionCaptures.set(threadId, captures);
20959
+ let released = false;
20960
+ return () => {
20961
+ if (released) {
20962
+ return;
20963
+ }
20964
+ released = true;
20965
+ captures.delete(capture);
20966
+ if (captures.size === 0) {
20967
+ this.turnCompletionCaptures.delete(threadId);
20968
+ }
20969
+ };
20970
+ }
20700
20971
  resolveMcpServerStartupResolvers() {
20701
20972
  const pendingResolvers = [];
20702
20973
  for (const resolver of this.mcpServerStartupResolvers) {
@@ -20756,6 +21027,16 @@ var CodexAppServerClient = class {
20756
21027
  function isMcpServerStatusUpdatedNotification(notification) {
20757
21028
  return notification.method === "mcpServer/startupStatus/updated";
20758
21029
  }
21030
+ function isTurnCompletedNotification(notification) {
21031
+ return notification.method === "turn/completed";
21032
+ }
21033
+ function extractThreadId(notification) {
21034
+ const params = notification.params;
21035
+ if (params && typeof params.threadId === "string") {
21036
+ return params.threadId;
21037
+ }
21038
+ return null;
21039
+ }
20759
21040
 
20760
21041
  // src/login.ts
20761
21042
  function parseArgs(args) {
@@ -20860,6 +21141,34 @@ async function runLoginCommand(args) {
20860
21141
  return login(options);
20861
21142
  }
20862
21143
 
21144
+ // src/CodexCli.ts
21145
+ import { spawn as spawn2 } from "node:child_process";
21146
+ import { createRequire as createRequire2 } from "node:module";
21147
+ function runCodexCli(codexPath, args) {
21148
+ const child = spawnCodexCli(codexPath, args);
21149
+ return new Promise((resolve, reject) => {
21150
+ child.on("error", reject);
21151
+ child.on("exit", (code, signal) => {
21152
+ if (signal) {
21153
+ process.kill(process.pid, signal);
21154
+ return;
21155
+ }
21156
+ resolve(code ?? 1);
21157
+ });
21158
+ });
21159
+ }
21160
+ function spawnCodexCli(codexPath, args) {
21161
+ const options = {
21162
+ env: process.env,
21163
+ stdio: "inherit"
21164
+ };
21165
+ if (codexPath) {
21166
+ return spawn2(codexPath, args, { ...options, shell: process.platform === "win32" });
21167
+ }
21168
+ const bundledCodexPath = createRequire2(import.meta.url).resolve("@openai/codex/bin/codex.js");
21169
+ return spawn2(process.execPath, [bundledCodexPath, ...args], options);
21170
+ }
21171
+
20863
21172
  // src/index.ts
20864
21173
  if (process.argv.includes("--version")) {
20865
21174
  console.log(`${package_default.name} ${package_default.version}`);
@@ -20871,6 +21180,12 @@ if (process.argv[2] === "login") {
20871
21180
  console.error("Login error:", error40.message);
20872
21181
  process.exit(1);
20873
21182
  });
21183
+ } else if (process.argv[2] === "cli") {
21184
+ const args = process.argv.slice(3);
21185
+ runCodexCli(process.env["CODEX_PATH"], args).then((exitCode) => process.exit(exitCode)).catch((error40) => {
21186
+ console.error("Codex CLI error:", error40.message);
21187
+ process.exit(1);
21188
+ });
20874
21189
  } else {
20875
21190
  startAcpServer();
20876
21191
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.0.43",
6
+ "version": "0.0.45",
7
7
  "description": "",
8
8
  "main": "dist/index.js",
9
9
  "bin": {
@@ -61,7 +61,7 @@
61
61
  "vitest": "^4.0.10"
62
62
  },
63
63
  "dependencies": {
64
- "@agentclientprotocol/sdk": "^0.21.0",
64
+ "@agentclientprotocol/sdk": "^0.22.1",
65
65
  "@openai/codex": "^0.128.0",
66
66
  "diff": "^8.0.3",
67
67
  "open": "^11.0.0",