@letta-ai/letta-agent-sdk 0.7.5 → 0.7.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.
package/README.md CHANGED
@@ -32,6 +32,19 @@ for await (const message of session.stream()) {
32
32
  }
33
33
  ```
34
34
 
35
+ Latency-sensitive applications can initialize the runtime and transport before
36
+ the first user action without fetching transcript history or invoking the model:
37
+
38
+ ```typescript
39
+ const session = client.resumeSession(conversationId);
40
+ await session.ready();
41
+ await session.send(message);
42
+ ```
43
+
44
+ `ready()` is idempotent and safe to call concurrently. `SDKResultMessage.durationMs`
45
+ measures the tracked turn and excludes session initialization; measure `ready()`
46
+ separately when startup latency matters.
47
+
35
48
  Set `LETTA_API_KEY` for the cloud backend. See the [quickstart](https://docs.letta.com/agent-sdk/quickstart) for the local and self-hosted paths.
36
49
 
37
50
  ## Where your agents run
@@ -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,+B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BAAmB,oBAAoB,CAAC;AACxC,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,CAAC;AAC1E,YAAY,EACV,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,aAAa,EACb,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,qCAAqC,EAAE,MAAM,gBAAgB,CAAC;AACvE,mBAAmB,YAAY,CAAC"}
@@ -9337,6 +9337,22 @@ class RemoteClientSessionCore {
9337
9337
  this.initializePromise = memo;
9338
9338
  return memo;
9339
9339
  }
9340
+ async ready() {
9341
+ if (this.closed)
9342
+ throw new Error("Session is closed");
9343
+ if (!this.initialized)
9344
+ await this.initialize();
9345
+ await this.recoverIdleTransportIfNeeded();
9346
+ if (!this._agentId || !this._conversationId) {
9347
+ throw new Error("Session is not initialized");
9348
+ }
9349
+ return {
9350
+ agentId: this._agentId,
9351
+ conversationId: this._conversationId,
9352
+ model: this._model || undefined,
9353
+ ...this.toolNames !== undefined ? { tools: [...this.toolNames] } : {}
9354
+ };
9355
+ }
9340
9356
  async performInitialize() {
9341
9357
  const init = await this.initializeRuntimeController();
9342
9358
  this.controller = init.controller;
@@ -10947,6 +10963,51 @@ function validateCloudSandboxOptions(options, name) {
10947
10963
  }
10948
10964
  }
10949
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
+
10950
11011
  // src/cloud-session.ts
10951
11012
  var DEFAULT_TURN_TIMEOUT_MS = 120000;
10952
11013
  var DEFAULT_PING_INTERVAL_MS = 30000;
@@ -11086,6 +11147,7 @@ function assertCloudSessionOptionsSupported(action, options) {
11086
11147
  class CloudEnvironmentSession extends RemoteClientSessionCore {
11087
11148
  cloudOptions;
11088
11149
  apiClient;
11150
+ sandbox;
11089
11151
  connectionId = null;
11090
11152
  removeExternalToolHandler = null;
11091
11153
  removeControlRequestHandler = null;
@@ -11109,11 +11171,17 @@ class CloudEnvironmentSession extends RemoteClientSessionCore {
11109
11171
  this.apiClient = apiClient;
11110
11172
  this.cloudMode = mode;
11111
11173
  this.repositoryManagement = new CloudManagementTransport(apiClient);
11174
+ this.sandbox = this.effectiveEnvironment() === undefined ? {
11175
+ uploadFiles: (files) => this.uploadFilesToManagedSandbox(files),
11176
+ downloadFile: (path2) => this.downloadFileFromManagedSandbox(path2)
11177
+ } : undefined;
11112
11178
  const tools = mode.options.tools;
11113
11179
  this.externalTools = externalToolsByName(tools);
11114
11180
  }
11115
11181
  async initializeRuntimeController() {
11116
11182
  await this.mcpCleanup;
11183
+ if (!this.closed)
11184
+ this.sandboxLifecycleClosing = false;
11117
11185
  const resolved = await this.resolveRuntime();
11118
11186
  const connection = await this.resolveConnectionForRuntime(resolved.runtime).catch(async (error) => {
11119
11187
  await this.cleanupSessionRepositories(resolved.runtime.agent_id, resolved.runtime.conversation_id);
@@ -11272,6 +11340,26 @@ class CloudEnvironmentSession extends RemoteClientSessionCore {
11272
11340
  return;
11273
11341
  await this.refreshManagedSandbox(sandbox);
11274
11342
  }
11343
+ async uploadFilesToManagedSandbox(files) {
11344
+ const sandbox = await this.requireManagedSandboxForFileTransfer();
11345
+ return uploadSandboxFiles(this.apiClient, sandbox.sandboxId, files);
11346
+ }
11347
+ async downloadFileFromManagedSandbox(path2) {
11348
+ const sandbox = await this.requireManagedSandboxForFileTransfer();
11349
+ return downloadSandboxFile(this.apiClient, sandbox.sandboxId, path2);
11350
+ }
11351
+ async requireManagedSandboxForFileTransfer() {
11352
+ if (this.effectiveEnvironment() !== undefined) {
11353
+ throw new Error("Sandbox file transfer requires an SDK-managed Cloud sandbox.");
11354
+ }
11355
+ await this.ready();
11356
+ const sandbox = this.managedSandbox;
11357
+ if (!sandbox) {
11358
+ throw new Error("SDK-managed Cloud sandbox is unavailable.");
11359
+ }
11360
+ await this.refreshManagedSandbox(sandbox);
11361
+ return sandbox;
11362
+ }
11275
11363
  onCoreClose() {
11276
11364
  this.cleanupTransportHandlers();
11277
11365
  this.mcpCleanup = this.closeMcpBridge();
@@ -12770,4 +12858,4 @@ export {
12770
12858
  CloudManagedSandboxExpiredError
12771
12859
  };
12772
12860
 
12773
- //# debugId=4189F3F92EE00D0D64756E2164756E21
12861
+ //# debugId=4D2DEBF58B35A6BA64756E2164756E21