@letta-ai/letta-agent-sdk 0.7.7 → 0.7.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.
@@ -11016,6 +11016,7 @@ var DEFAULT_SANDBOX_READY_TIMEOUT_MS = 120000;
11016
11016
  var DEFAULT_SANDBOX_READY_POLL_INTERVAL_MS = 1000;
11017
11017
  var DEFAULT_REPOSITORY_ATTACH_TIMEOUT_MS = 1e4;
11018
11018
  var DEFAULT_REPOSITORY_ATTACH_POLL_INTERVAL_MS = 250;
11019
+ var INITIAL_CLOUD_TRANSPORT_ATTEMPTS = 2;
11019
11020
  var SDK_AGENT_ORIGIN = "@letta-ai/letta-agent-sdk";
11020
11021
 
11021
11022
  class CloudManagedSandboxOwnershipError extends Error {
@@ -11206,30 +11207,9 @@ class CloudEnvironmentSession extends RemoteClientSessionCore {
11206
11207
  }
11207
11208
  }
11208
11209
  async openCloudTransport(runtime, connectionId) {
11209
- const apiKey = getCloudApiKey(this.cloudOptions);
11210
- const url = buildCloudStatusWebSocketUrl({
11211
- apiBaseUrl: this.cloudOptions.apiBaseUrl,
11212
- connectionId,
11213
- agentId: runtime.agent_id,
11214
- conversationId: runtime.conversation_id,
11215
- apiKey,
11216
- authMode: this.cloudOptions.webSocketAuth ?? "header"
11217
- });
11218
- const client = applyUniqueRequestIds(createAppServerClient({
11219
- url,
11220
- WebSocket: createCloudStatusTransportConstructor({
11221
- url,
11222
- WebSocket: getWebSocketConstructor(this.cloudOptions.WebSocket),
11223
- ...(this.cloudOptions.webSocketAuth ?? "header") === "header" ? { headers: cloudWebSocketHeaders(this.cloudOptions) } : {},
11224
- pingIntervalMs: this.cloudOptions.pingIntervalMs ?? DEFAULT_PING_INTERVAL_MS,
11225
- runtime
11226
- }),
11227
- requestTimeoutMs: this.cloudOptions.requestTimeoutMs ?? DEFAULT_TURN_TIMEOUT_MS
11228
- }));
11210
+ const client = await this.connectCloudTransport(runtime, connectionId);
11229
11211
  const options = this.currentOptions();
11230
- this.installTransportHandlers(client);
11231
11212
  try {
11232
- await client.connect();
11233
11213
  const response = await this.startCloudRuntime(client, runtime);
11234
11214
  if (!response.success || !response.runtime) {
11235
11215
  throw new Error(response.error ?? "Failed to start Cloud status runtime");
@@ -11257,6 +11237,62 @@ class CloudEnvironmentSession extends RemoteClientSessionCore {
11257
11237
  throw error;
11258
11238
  }
11259
11239
  }
11240
+ createCloudTransportClient(runtime, connectionId) {
11241
+ const apiKey = getCloudApiKey(this.cloudOptions);
11242
+ const url = buildCloudStatusWebSocketUrl({
11243
+ apiBaseUrl: this.cloudOptions.apiBaseUrl,
11244
+ connectionId,
11245
+ agentId: runtime.agent_id,
11246
+ conversationId: runtime.conversation_id,
11247
+ apiKey,
11248
+ authMode: this.cloudOptions.webSocketAuth ?? "header"
11249
+ });
11250
+ return applyUniqueRequestIds(createAppServerClient({
11251
+ url,
11252
+ WebSocket: createCloudStatusTransportConstructor({
11253
+ url,
11254
+ WebSocket: getWebSocketConstructor(this.cloudOptions.WebSocket),
11255
+ ...(this.cloudOptions.webSocketAuth ?? "header") === "header" ? { headers: cloudWebSocketHeaders(this.cloudOptions) } : {},
11256
+ pingIntervalMs: this.cloudOptions.pingIntervalMs ?? DEFAULT_PING_INTERVAL_MS,
11257
+ runtime
11258
+ }),
11259
+ requestTimeoutMs: this.cloudOptions.requestTimeoutMs ?? DEFAULT_TURN_TIMEOUT_MS
11260
+ }));
11261
+ }
11262
+ async connectCloudTransport(runtime, initialConnectionId) {
11263
+ let connectionId = initialConnectionId;
11264
+ let lastError;
11265
+ for (let attempt = 0;attempt < INITIAL_CLOUD_TRANSPORT_ATTEMPTS; attempt++) {
11266
+ const client = this.createCloudTransportClient(runtime, connectionId);
11267
+ this.installTransportHandlers(client);
11268
+ try {
11269
+ await client.connect();
11270
+ this.connectionId = connectionId;
11271
+ return client;
11272
+ } catch (error) {
11273
+ lastError = error;
11274
+ console.warn(JSON.stringify({
11275
+ event: "cloud_status_transport_connection_failed",
11276
+ attempt: attempt + 1,
11277
+ max_attempts: INITIAL_CLOUD_TRANSPORT_ATTEMPTS,
11278
+ will_retry: attempt + 1 < INITIAL_CLOUD_TRANSPORT_ATTEMPTS,
11279
+ connection_id: connectionId,
11280
+ agent_id: runtime.agent_id,
11281
+ conversation_id: runtime.conversation_id,
11282
+ error_name: error instanceof Error ? error.name : null,
11283
+ error_message: error instanceof Error ? error.message : String(error)
11284
+ }));
11285
+ this.cleanupTransportHandlers();
11286
+ client.close();
11287
+ }
11288
+ if (attempt + 1 < INITIAL_CLOUD_TRANSPORT_ATTEMPTS) {
11289
+ const resolved = await this.resolveRecoveryConnection(runtime);
11290
+ connectionId = resolved.connectionId;
11291
+ }
11292
+ }
11293
+ const detail = lastError instanceof Error ? lastError.message : String(lastError);
11294
+ throw new Error(`Cloud status WebSocket failed to open for connection ${connectionId}: ${detail}`, { cause: lastError });
11295
+ }
11260
11296
  installTransportHandlers(client) {
11261
11297
  this.cleanupTransportHandlers();
11262
11298
  this.removeControlRequestHandler = registerAppServerControlRequestHandler({
@@ -12858,4 +12894,4 @@ export {
12858
12894
  CloudManagedSandboxExpiredError
12859
12895
  };
12860
12896
 
12861
- //# debugId=4D2DEBF58B35A6BA64756E2164756E21
12897
+ //# debugId=02750F72F2B016D564756E2164756E21