codexuse-cli 2.5.5 → 2.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -5386,21 +5386,6 @@ function isThreadNotFoundError(error) {
5386
5386
  const lower = message.toLowerCase();
5387
5387
  return lower.includes("thread not found") || lower.includes("rollout");
5388
5388
  }
5389
- function isMethodPayloadUnsupportedError(error) {
5390
- if (!error || typeof error !== "object") {
5391
- return false;
5392
- }
5393
- const code = error.code;
5394
- if (typeof code !== "number" || code !== -32600) {
5395
- return false;
5396
- }
5397
- const message = error.message;
5398
- if (typeof message !== "string") {
5399
- return false;
5400
- }
5401
- const normalized = message.toLowerCase();
5402
- return normalized.includes("invalid request") || normalized.includes("missing field") || normalized.includes("unknown field");
5403
- }
5404
5389
  function asString4(value) {
5405
5390
  return typeof value === "string" ? value : value != null ? String(value) : "";
5406
5391
  }
@@ -5442,58 +5427,6 @@ function normalizeSendUserMessageItem(value) {
5442
5427
  }
5443
5428
  return value;
5444
5429
  }
5445
- function buildSendUserMessageItemsFromLegacyParams(params) {
5446
- const items = [];
5447
- const text = asString4(params.text);
5448
- if (text.trim()) {
5449
- items.push({
5450
- type: "text",
5451
- data: { text }
5452
- });
5453
- }
5454
- if (Array.isArray(params.images)) {
5455
- for (const candidate of params.images) {
5456
- const image = asString4(candidate).trim();
5457
- if (!image) {
5458
- continue;
5459
- }
5460
- if (isInlineImageValue(image)) {
5461
- items.push({
5462
- type: "image",
5463
- data: { image_url: image }
5464
- });
5465
- continue;
5466
- }
5467
- items.push({
5468
- type: "localImage",
5469
- data: { path: image }
5470
- });
5471
- }
5472
- }
5473
- if (items.length === 0) {
5474
- return null;
5475
- }
5476
- return items;
5477
- }
5478
- function normalizeSendUserMessageParams(params) {
5479
- const normalized = { ...params };
5480
- const conversationId = asString4(
5481
- params.conversationId ?? params.conversation_id ?? params.threadId ?? params.thread_id ?? ""
5482
- ).trim();
5483
- if (conversationId && !asString4(params.conversationId).trim()) {
5484
- normalized.conversationId = conversationId;
5485
- }
5486
- const items = Array.isArray(params.items) ? params.items.map((item) => normalizeSendUserMessageItem(item)).filter((item) => item !== null) : null;
5487
- if (items && items.length > 0) {
5488
- normalized.items = items;
5489
- return normalized;
5490
- }
5491
- const legacyItems = buildSendUserMessageItemsFromLegacyParams(params);
5492
- if (legacyItems) {
5493
- normalized.items = legacyItems;
5494
- }
5495
- return normalized;
5496
- }
5497
5430
  function normalizeTurnInputParams(params) {
5498
5431
  const normalized = { ...params };
5499
5432
  const threadId = asString4(
@@ -5517,6 +5450,26 @@ function normalizeTurnInputParams(params) {
5517
5450
  normalized.input = providedInput;
5518
5451
  return normalized;
5519
5452
  }
5453
+ const providedItems = Array.isArray(params.items) ? params.items.map((item) => normalizeSendUserMessageItem(item)).filter((item) => item !== null) : [];
5454
+ if (providedItems.length > 0) {
5455
+ const input2 = providedItems.flatMap((item) => {
5456
+ const type = asString4(item.type).trim();
5457
+ const data = isRecord6(item.data) ? item.data : item;
5458
+ if (type === "text") {
5459
+ const text2 = asString4(data.text).trim();
5460
+ return text2 ? [{ type: "text", text: text2 }] : [];
5461
+ }
5462
+ if (type === "localImage") {
5463
+ const path17 = asString4(data.path).trim();
5464
+ return path17 ? [{ type: "localImage", path: path17 }] : [];
5465
+ }
5466
+ return [];
5467
+ });
5468
+ if (input2.length > 0) {
5469
+ normalized.input = input2;
5470
+ return normalized;
5471
+ }
5472
+ }
5520
5473
  const input = [];
5521
5474
  const text = asString4(params.text);
5522
5475
  if (text.trim()) {
@@ -5595,37 +5548,9 @@ function normalizeThreadLiveWorkspaceId(value) {
5595
5548
  const workspaceId = asString4(value).trim();
5596
5549
  return workspaceId || DEFAULT_THREAD_LIVE_WORKSPACE_ID;
5597
5550
  }
5598
- function resolveThreadLiveWorkspacePayloadId(workspaceId) {
5599
- return workspaceId === DEFAULT_THREAD_LIVE_WORKSPACE_ID ? null : workspaceId;
5600
- }
5601
5551
  function threadLiveKey(workspaceId, threadId) {
5602
5552
  return `${workspaceId}:${threadId}`;
5603
5553
  }
5604
- function buildThreadRealtimePayloads(threadId, workspaceId) {
5605
- const payloads = [];
5606
- const seen = /* @__PURE__ */ new Set();
5607
- const pushPayload = (payload) => {
5608
- const signature = JSON.stringify(payload);
5609
- if (seen.has(signature)) {
5610
- return;
5611
- }
5612
- seen.add(signature);
5613
- payloads.push(payload);
5614
- };
5615
- pushPayload({ threadId });
5616
- pushPayload({ conversationId: threadId });
5617
- pushPayload({ threadId, conversationId: threadId });
5618
- if (!workspaceId) {
5619
- return payloads;
5620
- }
5621
- pushPayload({ threadId, workspaceId });
5622
- pushPayload({ conversationId: threadId, workspaceId });
5623
- pushPayload({ threadId, conversationId: threadId, workspaceId });
5624
- pushPayload({ threadId, workspace_id: workspaceId });
5625
- pushPayload({ conversationId: threadId, workspace_id: workspaceId });
5626
- pushPayload({ threadId, conversationId: threadId, workspace_id: workspaceId });
5627
- return payloads;
5628
- }
5629
5554
  function escapeInvalidJsonStringChars(input) {
5630
5555
  let output = "";
5631
5556
  let inString = false;
@@ -5732,6 +5657,7 @@ var CodexAppServer = class extends import_node_events.EventEmitter {
5732
5657
  this.parseLineBuffer = null;
5733
5658
  this.threadLiveSubscriptionIdByKey = /* @__PURE__ */ new Map();
5734
5659
  this.threadLiveModeByKey = /* @__PURE__ */ new Map();
5660
+ this.addConversationListenerSupported = null;
5735
5661
  this.setMaxListeners(50);
5736
5662
  }
5737
5663
  async start() {
@@ -5763,6 +5689,7 @@ var CodexAppServer = class extends import_node_events.EventEmitter {
5763
5689
  this.parseLineBuffer = null;
5764
5690
  this.threadLiveSubscriptionIdByKey.clear();
5765
5691
  this.threadLiveModeByKey.clear();
5692
+ this.addConversationListenerSupported = null;
5766
5693
  this.clearPendingRequests(new Error("codex app-server stopped"));
5767
5694
  }
5768
5695
  isRunning() {
@@ -5824,6 +5751,9 @@ var CodexAppServer = class extends import_node_events.EventEmitter {
5824
5751
  return this.request("resumeConversation", merged);
5825
5752
  }
5826
5753
  async addConversationListenerWithResumeFallback(threadId, workspaceId = null) {
5754
+ if (this.addConversationListenerSupported === false) {
5755
+ return {};
5756
+ }
5827
5757
  const listenerParams = {
5828
5758
  conversationId: threadId
5829
5759
  };
@@ -5834,87 +5764,50 @@ var CodexAppServer = class extends import_node_events.EventEmitter {
5834
5764
  }
5835
5765
  try {
5836
5766
  const response = await this.request("addConversationListener", listenerParams);
5767
+ this.addConversationListenerSupported = true;
5837
5768
  return isRecord6(response) ? response : null;
5838
5769
  } catch (error) {
5770
+ if (isMethodUnavailableError(error, "addConversationListener")) {
5771
+ this.addConversationListenerSupported = false;
5772
+ return {};
5773
+ }
5839
5774
  if (!isThreadNotFoundError(error)) {
5840
5775
  throw error;
5841
5776
  }
5842
5777
  await this.threadResume(
5843
5778
  resolvedWorkspaceId ? { threadId, workspaceId: resolvedWorkspaceId, workspace_id: resolvedWorkspaceId } : { threadId }
5844
5779
  );
5845
- const response = await this.request("addConversationListener", listenerParams);
5846
- return isRecord6(response) ? response : null;
5847
- }
5848
- }
5849
- async removeConversationListenerBySubscriptionId(subscriptionId) {
5850
- if (!subscriptionId) {
5851
- return;
5852
- }
5853
- await this.request("removeConversationListener", { subscriptionId });
5854
- }
5855
- trackThreadLiveSubscriptionId(key, subscriptionId) {
5856
- if (!subscriptionId) {
5857
- return;
5858
- }
5859
- const previousSubscriptionId = this.threadLiveSubscriptionIdByKey.get(key) ?? null;
5860
- this.threadLiveSubscriptionIdByKey.set(key, subscriptionId);
5861
- if (previousSubscriptionId && previousSubscriptionId !== subscriptionId) {
5862
- void this.removeConversationListenerBySubscriptionId(
5863
- previousSubscriptionId
5864
- ).catch(() => {
5865
- });
5866
- }
5867
- }
5868
- async startThreadRealtime(threadId, workspaceId = null) {
5869
- const payloads = buildThreadRealtimePayloads(threadId, workspaceId);
5870
- let resumed = false;
5871
- for (let index = 0; index < payloads.length; index += 1) {
5872
- const payload = payloads[index];
5873
5780
  try {
5874
- const response = await this.request("thread/realtime/start", payload);
5875
- return isRecord6(response) ? response : {};
5876
- } catch (error) {
5877
- if (isMethodUnavailableError(error, "thread/realtime/start")) {
5878
- return null;
5781
+ const response = await this.request("addConversationListener", listenerParams);
5782
+ this.addConversationListenerSupported = true;
5783
+ return isRecord6(response) ? response : null;
5784
+ } catch (resumeError) {
5785
+ if (isMethodUnavailableError(resumeError, "addConversationListener")) {
5786
+ this.addConversationListenerSupported = false;
5787
+ return {};
5879
5788
  }
5880
- if (isMethodPayloadUnsupportedError(error)) {
5881
- continue;
5882
- }
5883
- if (!isThreadNotFoundError(error)) {
5884
- throw error;
5885
- }
5886
- if (resumed) {
5887
- continue;
5888
- }
5889
- resumed = true;
5890
- await this.threadResume({ threadId });
5891
- index = -1;
5789
+ throw resumeError;
5892
5790
  }
5893
5791
  }
5894
- return null;
5895
5792
  }
5896
- async stopThreadRealtime(threadId, workspaceId = null) {
5897
- const payloads = buildThreadRealtimePayloads(threadId, workspaceId);
5898
- for (const payload of payloads) {
5899
- try {
5900
- await this.request("thread/realtime/stop", payload);
5901
- return true;
5902
- } catch (error) {
5903
- if (isMethodUnavailableError(error, "thread/realtime/stop")) {
5904
- return false;
5905
- }
5906
- if (isMethodPayloadUnsupportedError(error)) {
5907
- continue;
5908
- }
5909
- if (isThreadNotFoundError(error)) {
5910
- return true;
5911
- }
5912
- throw error;
5793
+ async removeConversationListenerBySubscriptionId(subscriptionId) {
5794
+ if (!subscriptionId || this.addConversationListenerSupported === false) {
5795
+ return;
5796
+ }
5797
+ try {
5798
+ await this.request("removeConversationListener", { subscriptionId });
5799
+ } catch (error) {
5800
+ if (isMethodUnavailableError(error, "removeConversationListener")) {
5801
+ this.addConversationListenerSupported = false;
5802
+ return;
5913
5803
  }
5804
+ throw error;
5914
5805
  }
5915
- return false;
5916
5806
  }
5917
5807
  async addConversationListener(params) {
5808
+ if (this.addConversationListenerSupported === false) {
5809
+ return {};
5810
+ }
5918
5811
  const conversationId = asString4(
5919
5812
  params.conversationId ?? params.threadId ?? params.thread_id ?? ""
5920
5813
  ).trim();
@@ -5922,7 +5815,17 @@ var CodexAppServer = class extends import_node_events.EventEmitter {
5922
5815
  params.workspaceId ?? params.workspace_id ?? ""
5923
5816
  ).trim();
5924
5817
  if (!conversationId) {
5925
- return this.request("addConversationListener", params);
5818
+ try {
5819
+ const response = await this.request("addConversationListener", params);
5820
+ this.addConversationListenerSupported = true;
5821
+ return response;
5822
+ } catch (error) {
5823
+ if (isMethodUnavailableError(error, "addConversationListener")) {
5824
+ this.addConversationListenerSupported = false;
5825
+ return {};
5826
+ }
5827
+ throw error;
5828
+ }
5926
5829
  }
5927
5830
  return this.addConversationListenerWithResumeFallback(
5928
5831
  conversationId,
@@ -5930,13 +5833,23 @@ var CodexAppServer = class extends import_node_events.EventEmitter {
5930
5833
  );
5931
5834
  }
5932
5835
  async removeConversationListener(params) {
5933
- return this.request("removeConversationListener", params);
5836
+ if (this.addConversationListenerSupported === false) {
5837
+ return {};
5838
+ }
5839
+ try {
5840
+ return await this.request("removeConversationListener", params);
5841
+ } catch (error) {
5842
+ if (isMethodUnavailableError(error, "removeConversationListener")) {
5843
+ this.addConversationListenerSupported = false;
5844
+ return {};
5845
+ }
5846
+ throw error;
5847
+ }
5934
5848
  }
5935
5849
  async threadLiveSubscribe(params) {
5936
5850
  const workspaceId = normalizeThreadLiveWorkspaceId(
5937
5851
  params.workspaceId ?? params.workspace_id
5938
5852
  );
5939
- const workspaceIdForPayload = resolveThreadLiveWorkspacePayloadId(workspaceId);
5940
5853
  const threadId = asString4(
5941
5854
  params.threadId ?? params.thread_id ?? params.conversationId
5942
5855
  ).trim();
@@ -5944,38 +5857,14 @@ var CodexAppServer = class extends import_node_events.EventEmitter {
5944
5857
  return {};
5945
5858
  }
5946
5859
  const key = threadLiveKey(workspaceId, threadId);
5947
- const realtimeResponse = await this.startThreadRealtime(
5948
- threadId,
5949
- workspaceIdForPayload
5950
- );
5951
- if (realtimeResponse) {
5952
- const previousSubscriptionId = this.threadLiveSubscriptionIdByKey.get(key) ?? null;
5953
- this.threadLiveSubscriptionIdByKey.delete(key);
5954
- this.threadLiveModeByKey.set(key, "realtime");
5955
- if (previousSubscriptionId) {
5956
- void this.removeConversationListenerBySubscriptionId(
5957
- previousSubscriptionId
5958
- ).catch(() => {
5959
- });
5960
- }
5961
- return realtimeResponse;
5962
- }
5963
- const response = await this.addConversationListenerWithResumeFallback(
5964
- threadId,
5965
- workspaceIdForPayload
5966
- );
5967
5860
  this.threadLiveModeByKey.set(key, "listener");
5968
- this.trackThreadLiveSubscriptionId(
5969
- key,
5970
- asString4(response?.subscriptionId ?? "").trim() || null
5971
- );
5972
- return response ?? {};
5861
+ this.threadLiveSubscriptionIdByKey.delete(key);
5862
+ return {};
5973
5863
  }
5974
5864
  async threadLiveUnsubscribe(params) {
5975
5865
  const workspaceId = normalizeThreadLiveWorkspaceId(
5976
5866
  params.workspaceId ?? params.workspace_id
5977
5867
  );
5978
- const workspaceIdForPayload = resolveThreadLiveWorkspacePayloadId(workspaceId);
5979
5868
  const threadId = asString4(
5980
5869
  params.threadId ?? params.thread_id ?? params.conversationId
5981
5870
  ).trim();
@@ -5983,42 +5872,16 @@ var CodexAppServer = class extends import_node_events.EventEmitter {
5983
5872
  return {};
5984
5873
  }
5985
5874
  const key = threadLiveKey(workspaceId, threadId);
5986
- const mode = this.threadLiveModeByKey.get(key) ?? null;
5987
5875
  this.threadLiveModeByKey.delete(key);
5988
5876
  const subscriptionId = this.threadLiveSubscriptionIdByKey.get(key) ?? null;
5989
5877
  this.threadLiveSubscriptionIdByKey.delete(key);
5990
- if (mode === "realtime") {
5991
- const stoppedRealtime = await this.stopThreadRealtime(
5992
- threadId,
5993
- workspaceIdForPayload
5994
- );
5995
- if (stoppedRealtime) {
5996
- return {};
5997
- }
5998
- }
5999
5878
  if (subscriptionId) {
6000
5879
  await this.removeConversationListenerBySubscriptionId(subscriptionId);
6001
- return {};
6002
- }
6003
- if (mode !== "listener") {
6004
- const stoppedRealtime = await this.stopThreadRealtime(
6005
- threadId,
6006
- workspaceIdForPayload
6007
- );
6008
- if (stoppedRealtime) {
6009
- return {};
6010
- }
6011
5880
  }
6012
- return this.removeConversationListener(
6013
- workspaceIdForPayload ? {
6014
- conversationId: threadId,
6015
- workspaceId: workspaceIdForPayload,
6016
- workspace_id: workspaceIdForPayload
6017
- } : { conversationId: threadId }
6018
- );
5881
+ return {};
6019
5882
  }
6020
5883
  async sendUserMessage(params) {
6021
- return this.request("sendUserMessage", normalizeSendUserMessageParams(params));
5884
+ return this.request("turn/start", normalizeTurnInputParams(params));
6022
5885
  }
6023
5886
  async threadStart(params) {
6024
5887
  return this.request("thread/start", params);
@@ -6157,6 +6020,7 @@ var CodexAppServer = class extends import_node_events.EventEmitter {
6157
6020
  this.initializeResponse = null;
6158
6021
  this.initializePromise = null;
6159
6022
  this.parseLineBuffer = null;
6023
+ this.addConversationListenerSupported = null;
6160
6024
  child.on("exit", (code, signal) => {
6161
6025
  logWarn("[app-server] exited", { code, signal });
6162
6026
  this.child = null;
@@ -6164,6 +6028,7 @@ var CodexAppServer = class extends import_node_events.EventEmitter {
6164
6028
  this.initializePromise = null;
6165
6029
  this.threadLiveSubscriptionIdByKey.clear();
6166
6030
  this.threadLiveModeByKey.clear();
6031
+ this.addConversationListenerSupported = null;
6167
6032
  this.clearPendingRequests(new Error("codex app-server exited"));
6168
6033
  this.emit("codex:process-exited", {});
6169
6034
  });
@@ -6171,6 +6036,7 @@ var CodexAppServer = class extends import_node_events.EventEmitter {
6171
6036
  logError("[app-server] process error", error);
6172
6037
  this.threadLiveSubscriptionIdByKey.clear();
6173
6038
  this.threadLiveModeByKey.clear();
6039
+ this.addConversationListenerSupported = null;
6174
6040
  this.emit("codex:process-exited", {});
6175
6041
  });
6176
6042
  if (child.stderr) {
@@ -9113,7 +8979,7 @@ async function handleDaemonCommand(args, version) {
9113
8979
  }
9114
8980
 
9115
8981
  // src/index.ts
9116
- var VERSION = true ? "2.5.5" : "0.0.0";
8982
+ var VERSION = true ? "2.5.8" : "0.0.0";
9117
8983
  var cliStorageReadyPromise = null;
9118
8984
  async function ensureCliStorageReady() {
9119
8985
  if (cliStorageReadyPromise) {