@letta-ai/letta-agent-sdk 0.6.2 → 0.7.0

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.
Files changed (44) hide show
  1. package/AGENTS.md +42 -0
  2. package/README.md +101 -1
  3. package/dist/app-server-session.d.ts.map +1 -1
  4. package/dist/client-base.d.ts +7 -0
  5. package/dist/client-base.d.ts.map +1 -1
  6. package/dist/client-entry.d.ts +3 -0
  7. package/dist/client-entry.d.ts.map +1 -1
  8. package/dist/client-entry.js +816 -138
  9. package/dist/client-entry.js.map +16 -14
  10. package/dist/cloud-session.d.ts +8 -1
  11. package/dist/cloud-session.d.ts.map +1 -1
  12. package/dist/computers.d.ts +67 -0
  13. package/dist/computers.d.ts.map +1 -0
  14. package/dist/index.d.ts +4 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +817 -139
  17. package/dist/index.js.map +17 -15
  18. package/dist/remote-client-session-core.d.ts +13 -16
  19. package/dist/remote-client-session-core.d.ts.map +1 -1
  20. package/dist/remote-session-protocol.d.ts +11 -0
  21. package/dist/remote-session-protocol.d.ts.map +1 -1
  22. package/dist/remote-turn-coordinator.d.ts +6 -1
  23. package/dist/remote-turn-coordinator.d.ts.map +1 -1
  24. package/dist/remote.d.ts +6 -1
  25. package/dist/remote.d.ts.map +1 -1
  26. package/dist/transcript-accumulator.d.ts +133 -0
  27. package/dist/transcript-accumulator.d.ts.map +1 -0
  28. package/dist/types.d.ts +41 -21
  29. package/dist/types.d.ts.map +1 -1
  30. package/dist/validation.d.ts.map +1 -1
  31. package/package.json +2 -2
  32. package/src/app-server-session.ts +9 -0
  33. package/src/client-base.ts +66 -19
  34. package/src/client-entry.ts +23 -0
  35. package/src/cloud-session.ts +112 -45
  36. package/src/computers.ts +132 -0
  37. package/src/index.ts +24 -0
  38. package/src/remote-client-session-core.ts +103 -27
  39. package/src/remote-session-protocol.ts +24 -0
  40. package/src/remote-turn-coordinator.ts +11 -2
  41. package/src/remote.ts +41 -12
  42. package/src/transcript-accumulator.ts +823 -0
  43. package/src/types.ts +43 -18
  44. package/src/validation.ts +16 -0
package/src/types.ts CHANGED
@@ -17,6 +17,7 @@ import type {
17
17
  import type { Message as LettaMessage } from "@letta-ai/letta-client/resources/agents/messages";
18
18
  import type { CreateBlock } from "@letta-ai/letta-client/resources/blocks/blocks";
19
19
  import type { LettaCodeCloudSandboxOptions } from "./cloud-sandbox.js";
20
+ import type { ComputerSelector } from "./computers.js";
20
21
  export type { CreateBlock } from "@letta-ai/letta-client/resources/blocks/blocks";
21
22
  export type {
22
23
  GitHubRepositoryRef,
@@ -108,6 +109,25 @@ export type MessageContentItem = TextContent | ImageContent;
108
109
  */
109
110
  export type SendMessage = string | MessageContentItem[];
110
111
 
112
+ /**
113
+ * Per-turn options accepted by `send()`.
114
+ */
115
+ export interface SendOptions {
116
+ /**
117
+ * Caller-supplied offline threading id (OTID) for this user message.
118
+ *
119
+ * The OTID is the canonical optimistic-input-matching key: stamp the row you
120
+ * render optimistically with the same value and you can correlate it with the
121
+ * persisted user message that comes back from the stream or from
122
+ * `listMessages()`. It is also used as the turn's `clientMessageId`, so it
123
+ * shows up on `SDKQueueItem.clientMessageId` while the message is queued.
124
+ *
125
+ * When omitted the SDK generates one. Must be a non-empty string; reuse the
126
+ * same value when retrying a send so the runtime can deduplicate it.
127
+ */
128
+ otid?: string;
129
+ }
130
+
111
131
  // ═══════════════════════════════════════════════════════════════
112
132
  // SKILLS / REMINDER / DREAMING TYPES
113
133
  // ═══════════════════════════════════════════════════════════════
@@ -301,18 +321,8 @@ export type McpServers = Record<string, McpServerConfig>;
301
321
  */
302
322
  export type LettaCodeBackend = "local" | "remote" | "cloud";
303
323
 
304
- /**
305
- * Stable execution target for remote/cloud runtimes.
306
- *
307
- * Strings are treated as human-readable environment names. Object forms allow
308
- * callers to avoid relying on names as unique identifiers.
309
- */
310
- export type LettaCodeEnvironment =
311
- | string
312
- | { name: string }
313
- | { id: string }
314
- | { connectionId: string }
315
- | { deviceId: string };
324
+ /** @deprecated Use `ComputerSelector` from the package root. */
325
+ export type LettaCodeEnvironment = ComputerSelector;
316
326
 
317
327
  export interface LettaCodeLocalAppServerOptions {
318
328
  /**
@@ -383,11 +393,13 @@ export interface LettaCodeCloudClientOptions {
383
393
  /** Heartbeat interval for the Cloud status websocket. Defaults to 30s. */
384
394
  pingIntervalMs?: number;
385
395
  /**
386
- * Execution target for Letta Cloud sessions. If omitted, the SDK creates
387
- * and owns a sandbox for the session.
396
+ * Computer where Letta Cloud sessions run. If omitted, the SDK creates and
397
+ * owns a managed sandbox for the session.
388
398
  */
399
+ computer?: ComputerSelector;
400
+ /** @deprecated Use `computer`. */
389
401
  environment?: LettaCodeEnvironment;
390
- /** Options for SDK-managed sandboxes when environment is omitted. */
402
+ /** Options for SDK-managed sandboxes when no computer is selected. */
391
403
  sandbox?: LettaCodeCloudSandboxOptions;
392
404
  }
393
405
 
@@ -670,6 +682,13 @@ export interface CreateSessionOptions {
670
682
  /** Working directory for the CLI process */
671
683
  cwd?: string;
672
684
 
685
+ /**
686
+ * Run without loading or changing the agent's MemFS. The agent and
687
+ * conversation remain persistent; this only changes the session's local
688
+ * memory, agent-skill, agent-mod, transcript, and reflection behavior.
689
+ */
690
+ stateless?: boolean;
691
+
673
692
  /**
674
693
  * Restrict available skills by source.
675
694
  * Empty array disables all skills (`--no-skills`).
@@ -709,12 +728,14 @@ export interface CreateSessionOptions {
709
728
  /**
710
729
  * Session options accepted by LettaAgentClient methods.
711
730
  *
712
- * `environment` is a cloud execution-target override. It is deliberately
731
+ * `computer` is a Cloud execution-target override. It is deliberately
713
732
  * session-scoped rather than part of createAgent() options.
714
733
  */
715
734
  export interface LettaCodeClientSessionOptions extends CreateSessionOptions {
735
+ computer?: ComputerSelector;
736
+ /** @deprecated Use `computer`. */
716
737
  environment?: LettaCodeEnvironment;
717
- /** Per-session SDK-managed sandbox options when environment is omitted. */
738
+ /** Per-session SDK-managed sandbox options when no computer is selected. */
718
739
  sandbox?: LettaCodeCloudSandboxOptions;
719
740
  /**
720
741
  * Extra environment variables for the session's harness process. Each
@@ -735,7 +756,11 @@ export interface LettaCodeClientSessionOptions extends CreateSessionOptions {
735
756
  }
736
757
 
737
758
  export interface LettaCodeSession extends AsyncDisposable {
738
- send(message: SendMessage): Promise<void>;
759
+ /**
760
+ * Send a user message. Pass `{ otid }` to supply your own correlation id for
761
+ * optimistic reconciliation; the SDK generates one when omitted.
762
+ */
763
+ send(message: SendMessage, options?: SendOptions): Promise<void>;
739
764
  stream(): AsyncGenerator<SDKMessage>;
740
765
  abort(): Promise<void>;
741
766
  sendCommand(command: SDKProtocolCommand): Promise<void>;
package/src/validation.ts CHANGED
@@ -223,6 +223,22 @@ function validateMcpServers(servers: McpServers | undefined): void {
223
223
  * Validate CreateSessionOptions (used by createSession and resumeSession).
224
224
  */
225
225
  export function validateCreateSessionOptions(options: CreateSessionOptions): void {
226
+ if (options.stateless !== undefined && typeof options.stateless !== "boolean") {
227
+ throw new Error("Invalid stateless. Expected a boolean.");
228
+ }
229
+ if (options.stateless) {
230
+ const persistedOption = [
231
+ ["model", options.model],
232
+ ["reasoningEffort", options.reasoningEffort],
233
+ ["dreaming", options.dreaming],
234
+ ["resources", options.resources],
235
+ ].find(([, value]) => value !== undefined);
236
+ if (persistedOption) {
237
+ throw new Error(
238
+ `stateless sessions cannot set ${persistedOption[0]} because it changes persisted agent configuration.`,
239
+ );
240
+ }
241
+ }
226
242
  validateClientToolset(options.toolset);
227
243
  validateSkillSources(options.skillSources);
228
244
  validateMcpServers(options.mcpServers);