@letta-ai/letta-agent-sdk 0.7.6 → 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.
@@ -13,6 +13,7 @@ export declare class LettaAgentClient extends LettaAgentClientBase {
13
13
  export { CloudManagedSandboxExpiredError } from "./cloud-session.js";
14
14
  export { ConversationForkHydrationError } from "./management-errors.js";
15
15
  export { RepositoriesClient } from "./repositories.js";
16
+ export type * from "./sandbox-files.js";
16
17
  export type { Computer, ComputerMetadata, ComputerSelector, ComputersClient, ListComputersOptions, ListComputersResult, ResolvedComputer, } from "./computers.js";
17
18
  export type * from "./management-types.js";
18
19
  export { extractStreamTextDelta } from "./stream-events.js";
@@ -1 +1 @@
1
- {"version":3,"file":"client-entry.d.ts","sourceRoot":"","sources":["../src/client-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EACV,2BAA2B,EAC3B,4BAA4B,EAC7B,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,+BAA+B,GACvC,4BAA4B,GAC5B,2BAA2B,CAAC;AAEhC;;;;;GAKG;AACH,qBAAa,gBAAiB,SAAQ,oBAAoB;gBAC5C,OAAO,EAAE,+BAA+B;CAMrD;AAED,OAAO,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,YAAY,EACV,QAAQ,EACR,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,mBAAmB,uBAAuB,CAAC;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,2BAA2B,EAAE,MAAM,6BAA6B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B,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,qCAAqC,EAAE,MAAM,gBAAgB,CAAC;AACvE,mBAAmB,YAAY,CAAC"}
@@ -10963,6 +10963,51 @@ function validateCloudSandboxOptions(options, name) {
10963
10963
  }
10964
10964
  }
10965
10965
 
10966
+ // src/sandbox-files.ts
10967
+ function isUploadedFile(value) {
10968
+ if (!value || typeof value !== "object" || Array.isArray(value))
10969
+ return false;
10970
+ const file = value;
10971
+ return typeof file.path === "string" && typeof file.name === "string" && typeof file.mimeType === "string" && typeof file.size === "number" && Number.isSafeInteger(file.size) && file.size >= 0;
10972
+ }
10973
+ function parseUploadResult(value) {
10974
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
10975
+ throw new Error("Cloud sandbox file upload returned an invalid response.");
10976
+ }
10977
+ const files = value.files;
10978
+ if (!Array.isArray(files) || !files.every(isUploadedFile)) {
10979
+ throw new Error("Cloud sandbox file upload returned invalid file metadata.");
10980
+ }
10981
+ return { files };
10982
+ }
10983
+ function uploadForm(files) {
10984
+ if (files.length === 0) {
10985
+ throw new Error("Cloud sandbox file upload requires at least one file.");
10986
+ }
10987
+ const form = new FormData;
10988
+ for (const [index, file] of files.entries()) {
10989
+ if (!file || typeof file.name !== "string" || file.name.trim() === "") {
10990
+ throw new Error(`Invalid Cloud sandbox upload file at index ${index}.`);
10991
+ }
10992
+ form.append("file", file.data, file.name);
10993
+ }
10994
+ return form;
10995
+ }
10996
+ async function uploadSandboxFiles(apiClient, sandboxId, files) {
10997
+ const response = await apiClient.post(`/v1/sandboxes/${encodeURIComponent(sandboxId)}/files`, { body: uploadForm(files) });
10998
+ return parseUploadResult(response);
10999
+ }
11000
+ async function downloadSandboxFile(apiClient, sandboxId, path2) {
11001
+ if (typeof path2 !== "string" || path2.trim() === "") {
11002
+ throw new Error("Cloud sandbox file download requires a non-empty path.");
11003
+ }
11004
+ const response = await apiClient.get(`/v1/sandboxes/${encodeURIComponent(sandboxId)}/files`, {
11005
+ query: { path: path2 },
11006
+ __binaryResponse: true
11007
+ });
11008
+ return new Uint8Array(await response.arrayBuffer());
11009
+ }
11010
+
10966
11011
  // src/cloud-session.ts
10967
11012
  var DEFAULT_TURN_TIMEOUT_MS = 120000;
10968
11013
  var DEFAULT_PING_INTERVAL_MS = 30000;
@@ -10971,6 +11016,7 @@ var DEFAULT_SANDBOX_READY_TIMEOUT_MS = 120000;
10971
11016
  var DEFAULT_SANDBOX_READY_POLL_INTERVAL_MS = 1000;
10972
11017
  var DEFAULT_REPOSITORY_ATTACH_TIMEOUT_MS = 1e4;
10973
11018
  var DEFAULT_REPOSITORY_ATTACH_POLL_INTERVAL_MS = 250;
11019
+ var INITIAL_CLOUD_TRANSPORT_ATTEMPTS = 2;
10974
11020
  var SDK_AGENT_ORIGIN = "@letta-ai/letta-agent-sdk";
10975
11021
 
10976
11022
  class CloudManagedSandboxOwnershipError extends Error {
@@ -11102,6 +11148,7 @@ function assertCloudSessionOptionsSupported(action, options) {
11102
11148
  class CloudEnvironmentSession extends RemoteClientSessionCore {
11103
11149
  cloudOptions;
11104
11150
  apiClient;
11151
+ sandbox;
11105
11152
  connectionId = null;
11106
11153
  removeExternalToolHandler = null;
11107
11154
  removeControlRequestHandler = null;
@@ -11125,6 +11172,10 @@ class CloudEnvironmentSession extends RemoteClientSessionCore {
11125
11172
  this.apiClient = apiClient;
11126
11173
  this.cloudMode = mode;
11127
11174
  this.repositoryManagement = new CloudManagementTransport(apiClient);
11175
+ this.sandbox = this.effectiveEnvironment() === undefined ? {
11176
+ uploadFiles: (files) => this.uploadFilesToManagedSandbox(files),
11177
+ downloadFile: (path2) => this.downloadFileFromManagedSandbox(path2)
11178
+ } : undefined;
11128
11179
  const tools = mode.options.tools;
11129
11180
  this.externalTools = externalToolsByName(tools);
11130
11181
  }
@@ -11156,30 +11207,9 @@ class CloudEnvironmentSession extends RemoteClientSessionCore {
11156
11207
  }
11157
11208
  }
11158
11209
  async openCloudTransport(runtime, connectionId) {
11159
- const apiKey = getCloudApiKey(this.cloudOptions);
11160
- const url = buildCloudStatusWebSocketUrl({
11161
- apiBaseUrl: this.cloudOptions.apiBaseUrl,
11162
- connectionId,
11163
- agentId: runtime.agent_id,
11164
- conversationId: runtime.conversation_id,
11165
- apiKey,
11166
- authMode: this.cloudOptions.webSocketAuth ?? "header"
11167
- });
11168
- const client = applyUniqueRequestIds(createAppServerClient({
11169
- url,
11170
- WebSocket: createCloudStatusTransportConstructor({
11171
- url,
11172
- WebSocket: getWebSocketConstructor(this.cloudOptions.WebSocket),
11173
- ...(this.cloudOptions.webSocketAuth ?? "header") === "header" ? { headers: cloudWebSocketHeaders(this.cloudOptions) } : {},
11174
- pingIntervalMs: this.cloudOptions.pingIntervalMs ?? DEFAULT_PING_INTERVAL_MS,
11175
- runtime
11176
- }),
11177
- requestTimeoutMs: this.cloudOptions.requestTimeoutMs ?? DEFAULT_TURN_TIMEOUT_MS
11178
- }));
11210
+ const client = await this.connectCloudTransport(runtime, connectionId);
11179
11211
  const options = this.currentOptions();
11180
- this.installTransportHandlers(client);
11181
11212
  try {
11182
- await client.connect();
11183
11213
  const response = await this.startCloudRuntime(client, runtime);
11184
11214
  if (!response.success || !response.runtime) {
11185
11215
  throw new Error(response.error ?? "Failed to start Cloud status runtime");
@@ -11207,6 +11237,62 @@ class CloudEnvironmentSession extends RemoteClientSessionCore {
11207
11237
  throw error;
11208
11238
  }
11209
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
+ }
11210
11296
  installTransportHandlers(client) {
11211
11297
  this.cleanupTransportHandlers();
11212
11298
  this.removeControlRequestHandler = registerAppServerControlRequestHandler({
@@ -11290,6 +11376,26 @@ class CloudEnvironmentSession extends RemoteClientSessionCore {
11290
11376
  return;
11291
11377
  await this.refreshManagedSandbox(sandbox);
11292
11378
  }
11379
+ async uploadFilesToManagedSandbox(files) {
11380
+ const sandbox = await this.requireManagedSandboxForFileTransfer();
11381
+ return uploadSandboxFiles(this.apiClient, sandbox.sandboxId, files);
11382
+ }
11383
+ async downloadFileFromManagedSandbox(path2) {
11384
+ const sandbox = await this.requireManagedSandboxForFileTransfer();
11385
+ return downloadSandboxFile(this.apiClient, sandbox.sandboxId, path2);
11386
+ }
11387
+ async requireManagedSandboxForFileTransfer() {
11388
+ if (this.effectiveEnvironment() !== undefined) {
11389
+ throw new Error("Sandbox file transfer requires an SDK-managed Cloud sandbox.");
11390
+ }
11391
+ await this.ready();
11392
+ const sandbox = this.managedSandbox;
11393
+ if (!sandbox) {
11394
+ throw new Error("SDK-managed Cloud sandbox is unavailable.");
11395
+ }
11396
+ await this.refreshManagedSandbox(sandbox);
11397
+ return sandbox;
11398
+ }
11293
11399
  onCoreClose() {
11294
11400
  this.cleanupTransportHandlers();
11295
11401
  this.mcpCleanup = this.closeMcpBridge();
@@ -12788,4 +12894,4 @@ export {
12788
12894
  CloudManagedSandboxExpiredError
12789
12895
  };
12790
12896
 
12791
- //# debugId=7375838F6D261D8064756E2164756E21
12897
+ //# debugId=02750F72F2B016D564756E2164756E21