@agentclientprotocol/codex-acp 2.5.1-preview.14 → 2.5.1-preview.15

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 +173 -110
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -41322,7 +41322,7 @@ var package_default = {
41322
41322
  publishConfig: {
41323
41323
  access: "public"
41324
41324
  },
41325
- version: "2.5.1-preview.14",
41325
+ version: "2.5.1-preview.15",
41326
41326
  description: "",
41327
41327
  main: "dist/index.js",
41328
41328
  bin: {
@@ -41703,6 +41703,83 @@ function isUnknownRecord(value) {
41703
41703
  return typeof value === "object" && value !== null && !Array.isArray(value);
41704
41704
  }
41705
41705
 
41706
+ // src/RequestCancellation.ts
41707
+ function throwIfRequestCancelled(signal) {
41708
+ if (signal?.aborted) throw RequestError.requestCancelled();
41709
+ }
41710
+ function withRequestCancellation(operation, signal) {
41711
+ if (!signal) return operation;
41712
+ return new Promise((resolve, reject) => {
41713
+ const cancelled = () => {
41714
+ signal.removeEventListener("abort", cancelled);
41715
+ reject(RequestError.requestCancelled());
41716
+ };
41717
+ if (signal.aborted) cancelled();
41718
+ else signal.addEventListener("abort", cancelled, { once: true });
41719
+ void operation.then((value) => {
41720
+ signal.removeEventListener("abort", cancelled);
41721
+ if (signal.aborted) cancelled();
41722
+ else resolve(value);
41723
+ }, (error62) => {
41724
+ signal.removeEventListener("abort", cancelled);
41725
+ reject(error62);
41726
+ });
41727
+ });
41728
+ }
41729
+
41730
+ // src/CodexAccountLogin.ts
41731
+ async function runAccountLogin(client, params, show, signal) {
41732
+ throwIfRequestCancelled(signal);
41733
+ let expectedId;
41734
+ const buffered = [];
41735
+ let complete;
41736
+ let endWait;
41737
+ const notified = new Promise((resolve, reject) => {
41738
+ complete = resolve;
41739
+ endWait = reject;
41740
+ });
41741
+ const accept = (event) => {
41742
+ if (expectedId === void 0) buffered.push(event);
41743
+ else if ((event.loginId ?? null) === expectedId) complete(event);
41744
+ };
41745
+ const listener = client.connection.onNotification("account/login/completed", accept);
41746
+ const completed = client.waitWhileConnected("account/login/completed", notified);
41747
+ void completed.catch(() => {
41748
+ });
41749
+ let response = null;
41750
+ let finished2 = false;
41751
+ try {
41752
+ response = await client.accountLogin(params);
41753
+ expectedId = "loginId" in response ? response.loginId : null;
41754
+ for (const event of buffered) accept(event);
41755
+ buffered.length = 0;
41756
+ throwIfRequestCancelled(signal);
41757
+ const first = await withRequestCancellation(Promise.race([
41758
+ completed.then((result2) => ({ type: "completed", result: result2 })),
41759
+ show(response).then((accepted) => ({ type: "shown", accepted }))
41760
+ ]), signal);
41761
+ if (first.type === "completed") {
41762
+ finished2 = true;
41763
+ return first.result.success;
41764
+ }
41765
+ if (!first.accepted) return false;
41766
+ const result = await withRequestCancellation(completed, signal);
41767
+ finished2 = true;
41768
+ return result.success;
41769
+ } finally {
41770
+ if (!finished2 && response && "loginId" in response) {
41771
+ await client.accountLoginCancel({ loginId: response.loginId }).catch((error62) => {
41772
+ logger.error("Failed to cancel Codex account login", error62);
41773
+ });
41774
+ } else if (signal?.aborted && response && expectedId === null) {
41775
+ await completed.catch(() => {
41776
+ });
41777
+ }
41778
+ endWait(new Error("Account login has ended"));
41779
+ listener.dispose();
41780
+ }
41781
+ }
41782
+
41706
41783
  // src/ClientSystemPrompt.ts
41707
41784
  function clientSystemPromptText(value) {
41708
41785
  if (value == null) return void 0;
@@ -41858,7 +41935,7 @@ var CodexAcpClient = class _CodexAcpClient {
41858
41935
  * routing). `authStatus` reports only the agent-owned one.
41859
41936
  */
41860
41937
  gatewayConfigSource;
41861
- pendingLoginCompleted = null;
41938
+ authenticationTail = Promise.resolve();
41862
41939
  pendingAccountUpdated = null;
41863
41940
  sessionNotificationQueues = /* @__PURE__ */ new Map();
41864
41941
  subagents;
@@ -41918,48 +41995,46 @@ var CodexAcpClient = class _CodexAcpClient {
41918
41995
  getHomePath() {
41919
41996
  return this.configPath;
41920
41997
  }
41921
- async authenticate(authRequest, urlElicitationRequester) {
41998
+ authenticate(authRequest, urlElicitationRequester, signal) {
41922
41999
  if (!isCodexAuthRequest(authRequest)) {
41923
- throw RequestError.invalidParams();
42000
+ return Promise.reject(RequestError.invalidParams());
41924
42001
  }
42002
+ const run = this.authenticationTail.then(() => this.authenticateOnce(authRequest, urlElicitationRequester, signal));
42003
+ this.authenticationTail = run.then(() => {
42004
+ }, () => {
42005
+ });
42006
+ return withRequestCancellation(run, signal);
42007
+ }
42008
+ async authenticateOnce(authRequest, urlElicitationRequester, signal) {
42009
+ throwIfRequestCancelled(signal);
41925
42010
  this.gatewayConfig = null;
41926
42011
  this.gatewayConfigSource = null;
41927
42012
  switch (authRequest.methodId) {
41928
42013
  case "api-key":
41929
- return await this.authenticateWithApiKey(authRequest);
42014
+ return await this.authenticateWithApiKey(authRequest, signal);
41930
42015
  case "chat-gpt":
41931
- return await this.authenticateWithChatGpt();
42016
+ return await this.authenticateWithChatGpt(signal);
41932
42017
  case "chat-gpt-device-code":
41933
- return await this.authenticateWithChatGptDeviceCode(urlElicitationRequester);
42018
+ return await this.authenticateWithChatGptDeviceCode(urlElicitationRequester, signal);
41934
42019
  case "gateway":
41935
42020
  return this.authenticateWithGateway(authRequest);
41936
42021
  }
41937
42022
  }
41938
- async authenticateWithApiKey(authRequest) {
42023
+ async authenticateWithApiKey(authRequest, signal) {
41939
42024
  const apiKey = authRequest._meta?.["api-key"]?.apiKey ?? this.readApiKeyFromEnv();
41940
- const loginCompletedPromise = this.awaitNextLoginCompleted();
41941
- loginCompletedPromise.catch(() => {
41942
- });
41943
- await this.codexClient.accountLogin({
41944
- type: "apiKey",
41945
- apiKey
41946
- });
41947
- const result = await loginCompletedPromise;
41948
- return result.success;
42025
+ return runAccountLogin(this.codexClient, { type: "apiKey", apiKey }, async () => true, signal);
41949
42026
  }
41950
- async authenticateWithChatGpt() {
42027
+ async authenticateWithChatGpt(signal) {
41951
42028
  if (await this.hasWorkingChatGptLogin()) {
42029
+ throwIfRequestCancelled(signal);
41952
42030
  return true;
41953
42031
  }
41954
- const loginCompletedPromise = this.awaitNextLoginCompleted();
41955
- loginCompletedPromise.catch(() => {
41956
- });
41957
- const loginResponse = await this.codexClient.accountLogin({ type: "chatgpt" });
41958
- if (loginResponse.type == "chatgpt") {
41959
- await open_default(loginResponse.authUrl);
41960
- }
41961
- const result = await loginCompletedPromise;
41962
- return result.success;
42032
+ return runAccountLogin(this.codexClient, { type: "chatgpt" }, async (response) => {
42033
+ if (response.type !== "chatgpt") return false;
42034
+ throwIfRequestCancelled(signal);
42035
+ await open_default(response.authUrl);
42036
+ return true;
42037
+ }, signal);
41963
42038
  }
41964
42039
  /**
41965
42040
  * Reads with a token refresh whether the agent has a ChatGPT login that a new login does not need to replace.
@@ -41985,56 +42060,27 @@ var CodexAcpClient = class _CodexAcpClient {
41985
42060
  throw error62;
41986
42061
  }
41987
42062
  }
41988
- async authenticateWithChatGptDeviceCode(urlElicitationRequester) {
42063
+ async authenticateWithChatGptDeviceCode(urlElicitationRequester, signal) {
41989
42064
  if (await this.hasWorkingChatGptLogin()) {
42065
+ throwIfRequestCancelled(signal);
41990
42066
  return true;
41991
42067
  }
41992
42068
  if (!urlElicitationRequester) {
41993
42069
  throw RequestError.invalidRequest(void 0, "Device code authentication requires URL elicitation support");
41994
42070
  }
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
42071
  try {
42008
- const first = await Promise.race([
42009
- loginCompletedPromise.then((result2) => ({
42010
- type: "loginCompleted",
42011
- result: result2
42012
- })),
42013
- elicitationResponsePromise.then((response) => ({
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(() => {
42072
+ return await runAccountLogin(this.codexClient, { type: "chatgptDeviceCode" }, async (response) => {
42073
+ if (response.type !== "chatgptDeviceCode") return false;
42074
+ const answer = await urlElicitationRequester.elicitUrl({
42075
+ url: response.verificationUrl,
42076
+ message: `Sign in to ChatGPT and enter this code: ${response.userCode}`,
42077
+ elicitationId: response.loginId
42035
42078
  });
42036
- }
42037
- throw error62;
42079
+ return CreateElicitationResponse.isAccept(answer);
42080
+ }, signal);
42081
+ } finally {
42082
+ await urlElicitationRequester.completeElicitation().catch(() => {
42083
+ });
42038
42084
  }
42039
42085
  }
42040
42086
  authenticateWithGateway(authRequest) {
@@ -42887,20 +42933,6 @@ var CodexAcpClient = class _CodexAcpClient {
42887
42933
  async listSkills(params) {
42888
42934
  return withoutUnsupportedSkills(await this.codexClient.listSkills(params ?? {}));
42889
42935
  }
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
42936
  async awaitNextAccountUpdated() {
42905
42937
  if (this.pendingAccountUpdated !== null) {
42906
42938
  return await this.pendingAccountUpdated;
@@ -50033,6 +50065,7 @@ var CodexAcpServer = class {
50033
50065
  mcpServerSignIn;
50034
50066
  clientDelivery;
50035
50067
  setupResponseOrdering = false;
50068
+ initializeResponseDelivery = "direct";
50036
50069
  /** ACP protocol version of the connection this agent serves, fixed by the protocol router. */
50037
50070
  protocolVersion;
50038
50071
  /** The v2 client handle; `null` on a v1 connection. */
@@ -51550,41 +51583,53 @@ You have been logged out. Please try again.`);
51550
51583
  ...this.createSessionSetupResponseV2(this.getSessionState(sessionId))
51551
51584
  };
51552
51585
  }
51553
- async authenticate(_params, requestId) {
51586
+ async authenticate(_params, requestId, signal) {
51554
51587
  logger.log("Authenticate request received");
51588
+ throwIfRequestCancelled(signal);
51555
51589
  const appServer = this.ensureAppServer();
51556
- if (appServer) await appServer;
51557
- const elicitationRequester = this.createUrlElicitationRequester(requestId);
51558
- const isAuthenticated = await this.runWithProcessCheck(() => this.codexAcpClient.authenticate(_params, elicitationRequester));
51559
- if (!isAuthenticated) {
51560
- logger.log("Authenticate request failed");
51561
- throw RequestError.authRequired({ methodId: _params.methodId }, "Sign-in did not complete");
51562
- }
51563
- await this.refreshAuthState(this.getAuthProviderForAuthenticateRequest(_params));
51564
- logger.log("Authenticate request completed");
51565
- return {};
51590
+ if (appServer) await withRequestCancellation(appServer, signal);
51591
+ const elicitationRequester = this.createUrlElicitationRequester(requestId, signal);
51592
+ try {
51593
+ const isAuthenticated = await this.runWithProcessCheck(() => this.codexAcpClient.authenticate(_params, elicitationRequester, signal));
51594
+ throwIfRequestCancelled(signal);
51595
+ if (!isAuthenticated) {
51596
+ logger.log("Authenticate request failed");
51597
+ throw RequestError.authRequired({ methodId: _params.methodId }, "Sign-in did not complete");
51598
+ }
51599
+ await withRequestCancellation(this.refreshAuthState(this.getAuthProviderForAuthenticateRequest(_params)), signal);
51600
+ logger.log("Authenticate request completed");
51601
+ return {};
51602
+ } finally {
51603
+ await elicitationRequester?.completeElicitation().catch(() => {
51604
+ });
51605
+ }
51566
51606
  }
51567
- createUrlElicitationRequester(requestId) {
51607
+ createUrlElicitationRequester(requestId, signal) {
51568
51608
  if (requestId == null || !clientSupportsUrlElicitation(this.clientCapabilities)) {
51569
51609
  return void 0;
51570
51610
  }
51611
+ const lifetime = new AbortController();
51612
+ const cancellationSignal = signal ? AbortSignal.any([signal, lifetime.signal]) : lifetime.signal;
51571
51613
  let elicitationId = null;
51572
51614
  return {
51573
- elicitUrl: (request) => {
51615
+ elicitUrl: async (request) => {
51574
51616
  elicitationId = request.elicitationId;
51575
- return this.connection.request(methods.client.elicitation.create, {
51617
+ const response = await this.connection.request(methods.client.elicitation.create, {
51576
51618
  mode: "url",
51577
51619
  requestId,
51578
51620
  ...request
51579
- });
51621
+ }, { cancellationSignal });
51622
+ if (!CreateElicitationResponse.isAccept(response)) elicitationId = null;
51623
+ return response;
51580
51624
  },
51581
51625
  completeElicitation: async () => {
51582
51626
  if (elicitationId === null) {
51583
51627
  return;
51584
51628
  }
51585
- await this.connection.notify(methods.client.elicitation.complete, {
51586
- elicitationId
51587
- });
51629
+ const completedId = elicitationId;
51630
+ elicitationId = null;
51631
+ lifetime.abort();
51632
+ await this.connection.notify(methods.client.elicitation.complete, { elicitationId: completedId });
51588
51633
  }
51589
51634
  };
51590
51635
  }
@@ -51597,11 +51642,11 @@ You have been logged out. Please try again.`);
51597
51642
  logger.log("Logout request completed");
51598
51643
  }
51599
51644
  /** v2 `auth/login`: same params as v1 `authenticate`, only the method name changed. */
51600
- async authenticateV2(params, requestId) {
51645
+ async authenticateV2(params, requestId, signal) {
51601
51646
  if (!getCodexAuthMethodsV2(this.clientCapabilities).some((method) => method.methodId === params.methodId)) {
51602
51647
  throw RequestError.invalidParams(void 0, `Unsupported authentication method: ${params.methodId}`);
51603
51648
  }
51604
- return await this.authenticate(params, requestId);
51649
+ return await this.authenticate(params, requestId, signal);
51605
51650
  }
51606
51651
  /** v2 `auth/logout`: same params as v1 `logout`, only the method name changed. */
51607
51652
  async logoutV2(params) {
@@ -51864,16 +51909,23 @@ You have been logged out. Please try again.`);
51864
51909
  * Schedules the connection's first `_auth/status_update`: one account read,
51865
51910
  * pushed whatever it says, including `none`.
51866
51911
  *
51867
- * The push must not overtake the `initialize` response. The JSON-RPC layer
51868
- * writes that response in the microtask that resolves {@link initialize}, so
51869
- * the read starts from a check-phase callback, which always runs after it.
51870
- * `initialize` itself never waits for the read.
51912
+ * Routed connections publish at the response-write boundary. Direct callers
51913
+ * have no transport boundary, so they retain the asynchronous fallback.
51871
51914
  *
51872
51915
  * "Unconditional" costs nothing extra here: nothing has been pushed yet on
51873
51916
  * this connection, so {@link setAuthStatus} cannot suppress this one.
51874
51917
  */
51875
51918
  publishFirstAuthStatusAfterResponse() {
51876
- setImmediate(() => void this.publishAuthStatusRead());
51919
+ if (this.initializeResponseDelivery === "direct") {
51920
+ setImmediate(() => void this.publishAuthStatusRead());
51921
+ }
51922
+ }
51923
+ observeInitializeResponse() {
51924
+ this.initializeResponseDelivery = "pending";
51925
+ }
51926
+ afterInitializeResponse() {
51927
+ this.initializeResponseDelivery = "written";
51928
+ void this.publishAuthStatusRead();
51877
51929
  }
51878
51930
  /**
51879
51931
  * Reads the agent-owned identity and pushes it.
@@ -51957,6 +52009,7 @@ You have been logged out. Please try again.`);
51957
52009
  */
51958
52010
  async applyAccountUpdated(notification) {
51959
52011
  this.lastReadAccount = accountFromUpdated(notification, this.lastReadAccount);
52012
+ if (this.initializeResponseDelivery === "pending") return;
51960
52013
  try {
51961
52014
  if (this.codexAcpClient.getAuthGatewayProviderName() !== null) {
51962
52015
  return;
@@ -51987,6 +52040,7 @@ You have been logged out. Please try again.`);
51987
52040
  */
51988
52041
  async setAuthStatus(next) {
51989
52042
  this.authStatusVersion += 1;
52043
+ if (this.initializeResponseDelivery === "pending") return;
51990
52044
  if (sameAuthStatus(this.currentAuthStatus, next)) {
51991
52045
  return;
51992
52046
  }
@@ -54881,6 +54935,7 @@ function createRouter(createAgent, responses) {
54881
54935
  };
54882
54936
  const attachAgent = (agent3, signal) => {
54883
54937
  codexAcpServer = agent3;
54938
+ agent3.observeInitializeResponse();
54884
54939
  const stopSetupPublication = agent3.observeSessionSetupResponses();
54885
54940
  signal.addEventListener("abort", () => {
54886
54941
  setups.clear();
@@ -54891,8 +54946,16 @@ function createRouter(createAgent, responses) {
54891
54946
  }
54892
54947
  });
54893
54948
  };
54894
- const v1Agent = agent({ name: package_default.name }).onConnect((connection) => attachAgent(createAgent(connection.client), connection.signal)).onRequest(methods.agent.initialize, (ctx) => getAgent().initialize(ctx.params)).onRequest(methods.agent.session.new, (ctx) => createdSetup(ctx.requestId, () => getAgentForPaths(ctx.params).newSession(ctx.params))).onRequest(methods.agent.session.load, (ctx) => setup(ctx.params.sessionId, ctx.requestId, () => getAgentForPaths(ctx.params).loadSession(ctx.params), ctx.signal)).onRequest(methods.agent.session.fork, (ctx) => createdSetup(ctx.requestId, () => getAgentForPaths(ctx.params).forkSession(ctx.params))).onRequest(methods.agent.session.list, (ctx) => getAgentForPaths({ cwd: ctx.params.cwd ?? null }).listSessions(ctx.params)).onRequest(methods.agent.session.delete, (ctx) => getAgent(ctx.params).deleteSession(ctx.params)).onRequest(methods.agent.session.resume, (ctx) => setup(ctx.params.sessionId, ctx.requestId, () => getAgentForPaths(ctx.params).resumeSession(ctx.params), ctx.signal)).onRequest(methods.agent.session.close, (ctx) => getAgent(ctx.params).closeSession(ctx.params)).onRequest(methods.agent.session.setMode, (ctx) => getAgent(ctx.params).setSessionMode(ctx.params)).onRequest(methods.agent.session.setConfigOption, (ctx) => getAgent(ctx.params).setSessionConfigOption(ctx.params)).onRequest(methods.agent.authenticate, (ctx) => getAgent().authenticate(ctx.params, ctx.requestId)).onRequest(methods.agent.logout, (ctx) => getAgent().logout(ctx.params)).onRequest(methods.agent.providers.list, (ctx) => getAgent().listProviders(ctx.params)).onRequest(methods.agent.providers.set, (ctx) => getAgent().setProvider(ctx.params)).onRequest(methods.agent.providers.disable, (ctx) => getAgent().disableProvider(ctx.params)).onRequest(methods.agent.session.prompt, (ctx) => getAgent(ctx.params).prompt(ctx.params, ctx.signal)).onNotification(methods.agent.session.cancel, (ctx) => getAgent().cancel(ctx.params)).onRequest("authentication/status", emptyExtensionParamsParser, (ctx) => getAgent().extMethod("authentication/status", ctx.params)).onRequest("authentication/logout", emptyExtensionParamsParser, (ctx) => getAgent().extMethod("authentication/logout", ctx.params)).onRequest(LEGACY_SET_SESSION_MODEL_METHOD, legacySetSessionModelParamsParser, (ctx) => getAgent(ctx.params).extMethod(LEGACY_SET_SESSION_MODEL_METHOD, ctx.params)).onRequest(SESSION_STEERING_METHOD, sessionSteerParamsParser, (ctx) => getAgent(ctx.params).extMethod(SESSION_STEERING_METHOD, ctx.params)).onRequest(ASYNC_TASK_STOP_METHOD, asyncTaskStopParamsParser, (ctx) => getAgent(ctx.params).extMethod(ASYNC_TASK_STOP_METHOD, ctx.params)).onRequest(CODEX_HOOKS_LIST_METHOD, hooksListParamsParser, (ctx) => getAgent().listHooks(ctx.params.cwd)).onRequest(CODEX_HOOKS_TRUST_METHOD, hooksTrustParamsParser, (ctx) => getAgent().trustHooks(ctx.params.cwd, ctx.params.hooks)).onRequest(GOAL_CONTROL_METHOD, goalControlParamsParser, (ctx) => getAgent(ctx.params).extMethod(GOAL_CONTROL_METHOD, ctx.params)).onRequest(SESSION_RENAME_METHOD, sessionRenameParamsParser, (ctx) => getAgent(ctx.params).sessionIndex.rename(ctx.params)).onRequest(SESSION_BATCH_GET_METHOD, sessionBatchGetParamsParser, (ctx) => getAgent().sessionIndex.batchGet(ctx.params)).onRequest(SESSION_ARCHIVE_METHOD, sessionArchiveParamsParser, (ctx) => getAgent(ctx.params).sessionIndex.setArchived(ctx.params, true)).onRequest(SESSION_UNARCHIVE_METHOD, sessionArchiveParamsParser, (ctx) => getAgent(ctx.params).sessionIndex.setArchived(ctx.params, false)).onRequest(SESSION_LIST_SUBSCRIBE_METHOD, sessionListSubscriptionParamsParser, (ctx) => getAgent().sessionIndex.subscribeList(ctx.params)).onRequest(SESSION_LIST_UNSUBSCRIBE_METHOD, sessionListSubscriptionParamsParser, (ctx) => getAgent().sessionIndex.unsubscribeList(ctx.params));
54895
- const v2Agent = agent2({ name: package_default.name }).onConnect((connection) => attachAgent(createAgent(new AcpV2Connection(connection.client)), connection.signal)).onRequest(methods2.agent.initialize, (ctx) => getAgent().initializeV2(ctx.params)).onRequest(methods2.agent.session.new, (ctx) => createdSetup(ctx.requestId, () => getAgentForPaths(ctx.params).newSessionV2(ctx.params))).onRequest(methods2.agent.session.list, (ctx) => getAgentForPaths({ cwd: ctx.params.cwd ?? null }).listSessions(ctx.params)).onRequest(methods2.agent.session.delete, (ctx) => getAgent(ctx.params).deleteSession(ctx.params)).onRequest(methods2.agent.session.resume, (ctx) => setup(ctx.params.sessionId, ctx.requestId, () => getAgentForPaths(ctx.params).resumeSessionV2(ctx.params), ctx.signal)).onRequest(methods2.agent.session.fork, (ctx) => createdSetup(ctx.requestId, () => getAgentForPaths(ctx.params).forkSessionV2(ctx.params))).onRequest(methods2.agent.session.close, (ctx) => getAgent(ctx.params).closeSession(ctx.params)).onRequest(methods2.agent.session.setConfigOption, (ctx) => getAgent(ctx.params).setSessionConfigOptionV2(ctx.params)).onRequest(methods2.agent.auth.login, (ctx) => getAgent().authenticateV2(ctx.params, ctx.requestId)).onRequest(methods2.agent.auth.logout, (ctx) => getAgent().logoutV2(ctx.params)).onRequest(methods2.agent.session.prompt, (ctx) => getAgent(ctx.params).promptV2(ctx.params, ctx.signal)).onNotification(methods2.agent.session.cancel, (ctx) => getAgent().cancel(ctx.params)).onRequest(methods2.agent.providers.list, (ctx) => getAgent().listProviders(ctx.params)).onRequest(methods2.agent.providers.set, (ctx) => getAgent().setProvider(ctx.params)).onRequest(methods2.agent.providers.disable, (ctx) => getAgent().disableProvider(ctx.params)).onRequest(SESSION_STEERING_METHOD, sessionSteerParamsParser, (ctx) => getAgent(ctx.params).extMethod(SESSION_STEERING_METHOD, ctx.params)).onRequest(GOAL_CONTROL_METHOD, goalControlParamsParser, (ctx) => getAgent(ctx.params).extMethod(GOAL_CONTROL_METHOD, ctx.params)).onRequest(ASYNC_TASK_STOP_METHOD, asyncTaskStopParamsParser, (ctx) => getAgent(ctx.params).extMethod(ASYNC_TASK_STOP_METHOD, ctx.params)).onRequest(SESSION_RENAME_METHOD, sessionRenameParamsParser, (ctx) => getAgent(ctx.params).sessionIndex.rename(ctx.params)).onRequest(SESSION_BATCH_GET_METHOD, sessionBatchGetParamsParser, (ctx) => getAgent().sessionIndex.batchGet(ctx.params)).onRequest(SESSION_ARCHIVE_METHOD, sessionArchiveParamsParser, (ctx) => getAgent(ctx.params).sessionIndex.setArchived(ctx.params, true)).onRequest(SESSION_UNARCHIVE_METHOD, sessionArchiveParamsParser, (ctx) => getAgent(ctx.params).sessionIndex.setArchived(ctx.params, false)).onRequest(SESSION_LIST_SUBSCRIBE_METHOD, sessionListSubscriptionParamsParser, (ctx) => getAgent().sessionIndex.subscribeList(ctx.params)).onRequest(SESSION_LIST_UNSUBSCRIBE_METHOD, sessionListSubscriptionParamsParser, (ctx) => getAgent().sessionIndex.unsubscribeList(ctx.params));
54949
+ const initialize = async (requestId, operation) => {
54950
+ const agent3 = getAgent();
54951
+ const result = await operation();
54952
+ responses.afterWrite(requestId, (successful) => {
54953
+ if (successful) agent3.afterInitializeResponse();
54954
+ });
54955
+ return result;
54956
+ };
54957
+ 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));
54958
+ 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
54959
  return agentProtocolRouter().withV1(v1Agent).withV2(v2Agent);
54897
54960
  }
54898
54961
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "2.5.1-preview.14",
6
+ "version": "2.5.1-preview.15",
7
7
  "description": "",
8
8
  "main": "dist/index.js",
9
9
  "bin": {