@cadraos/sdk 0.3.6 → 0.3.7

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.
@@ -3675,6 +3675,15 @@ var ExecutionStreamControllerImpl = class {
3675
3675
  sseClient = null;
3676
3676
  status = "connecting";
3677
3677
  reconnectAttempts = 0;
3678
+ // CAD-39 / webchat dual-plane create-connect race. `hasConnected` flips true on
3679
+ // the first successful SSE open; `notFoundRetries` bounds retries of a 404
3680
+ // encountered BEFORE we ever connect (the run row is persisted slightly AFTER
3681
+ // the client opens the stream — the norm on the webchat path where msg-api owns
3682
+ // the executionId and cadra persists the agent_executions row via an async
3683
+ // worker callback). See handleConnectionError.
3684
+ hasConnected = false;
3685
+ notFoundRetries = 0;
3686
+ maxConnectRaceRetries = 3;
3678
3687
  seenEventIds = /* @__PURE__ */ new Set();
3679
3688
  _lastEventId = null;
3680
3689
  activityTimeoutId = null;
@@ -3814,6 +3823,8 @@ var ExecutionStreamControllerImpl = class {
3814
3823
  if (connected) {
3815
3824
  this.status = "connected";
3816
3825
  this.reconnectAttempts = 0;
3826
+ this.hasConnected = true;
3827
+ this.notFoundRetries = 0;
3817
3828
  this.resetActivityTimeout();
3818
3829
  }
3819
3830
  this.emit("connectionChange", { connected, usingFallback: false });
@@ -4103,6 +4114,38 @@ var ExecutionStreamControllerImpl = class {
4103
4114
  return;
4104
4115
  }
4105
4116
  const msg = error instanceof Error ? error.message : String(error);
4117
+ const isNotFound = /\b404\b/.test(msg);
4118
+ const isAuthFailure = /\b40[13]\b/.test(msg) || /INVALID_API_KEY|INVALID_REQUEST/.test(msg);
4119
+ if (isNotFound && !isAuthFailure && !this.hasConnected) {
4120
+ if (this.notFoundRetries < this.maxConnectRaceRetries) {
4121
+ this.notFoundRetries++;
4122
+ this.status = "reconnecting";
4123
+ const delay = Math.min(
4124
+ this.config.reconnectBaseDelayMs * this.notFoundRetries,
4125
+ this.config.reconnectMaxDelayMs
4126
+ );
4127
+ await new Promise((resolve) => setTimeout(resolve, delay));
4128
+ if (this.status === "closed") {
4129
+ return;
4130
+ }
4131
+ try {
4132
+ await this.connectSSE();
4133
+ } catch (retryError) {
4134
+ await this.handleConnectionError(retryError);
4135
+ }
4136
+ return;
4137
+ }
4138
+ if (this.pollingEnabled) {
4139
+ if (this.sseClient) {
4140
+ this.sseClient.disconnect();
4141
+ this.sseClient = null;
4142
+ }
4143
+ this.status = "fallback_polling";
4144
+ this.emit("connectionChange", { connected: false, usingFallback: true });
4145
+ this.startPolling();
4146
+ return;
4147
+ }
4148
+ }
4106
4149
  if (/\b4\d\d\b/.test(msg) || /INVALID_API_KEY|INVALID_REQUEST/.test(msg)) {
4107
4150
  if (this.sseClient) {
4108
4151
  this.sseClient.disconnect();
@@ -4352,7 +4395,6 @@ var AgentsAPI = class extends BaseResourceAPI {
4352
4395
  super(http, "/api/v1/agents");
4353
4396
  this.getStreamConfig = getStreamConfig;
4354
4397
  }
4355
- getStreamConfig;
4356
4398
  // ===== LIST Operations =====
4357
4399
  /**
4358
4400
  * List all agents in the organization
@@ -5258,7 +5300,6 @@ var SessionsAPI = class extends BaseResourceAPI {
5258
5300
  super(http, "/api/v1/sessions");
5259
5301
  this.getStreamConfig = getStreamConfig;
5260
5302
  }
5261
- getStreamConfig;
5262
5303
  // ===== LIST Operations =====
5263
5304
  /**
5264
5305
  * List all sessions in the organization
@@ -5578,7 +5619,6 @@ var KanbanAPI = class extends BaseResourceAPI {
5578
5619
  super(http, "/api/v1/kanban");
5579
5620
  this.getStreamConfig = getStreamConfig;
5580
5621
  }
5581
- getStreamConfig;
5582
5622
  // ===== BOARD =====
5583
5623
  /**
5584
5624
  * Get the current org's board (lanes in declared order). Auto-provisions
@@ -5780,7 +5820,6 @@ var RemoteAgentsAPI = class extends BaseResourceAPI {
5780
5820
  super(http, "/api/v1/remote-agents");
5781
5821
  this.getStreamConfig = getStreamConfig;
5782
5822
  }
5783
- getStreamConfig;
5784
5823
  /**
5785
5824
  * List all remote agents in the organization
5786
5825
  *