@letta-ai/letta-agent-sdk 0.3.3 → 0.5.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 (55) hide show
  1. package/AGENTS.md +0 -3
  2. package/README.md +12 -0
  3. package/dist/app-server-management.d.ts +3 -48
  4. package/dist/app-server-management.d.ts.map +1 -1
  5. package/dist/app-server-session.d.ts +0 -6
  6. package/dist/app-server-session.d.ts.map +1 -1
  7. package/dist/client-base.d.ts +7 -15
  8. package/dist/client-base.d.ts.map +1 -1
  9. package/dist/client-entry.js +369 -468
  10. package/dist/client-entry.js.map +13 -12
  11. package/dist/client.d.ts +3 -3
  12. package/dist/client.d.ts.map +1 -1
  13. package/dist/cloud-session.d.ts.map +1 -1
  14. package/dist/cloud-status-transport.d.ts +53 -0
  15. package/dist/cloud-status-transport.d.ts.map +1 -0
  16. package/dist/index.d.ts +7 -16
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +896 -2019
  19. package/dist/index.js.map +18 -18
  20. package/dist/local-app-server-session.d.ts +1 -1
  21. package/dist/local-app-server-session.d.ts.map +1 -1
  22. package/dist/local-app-server.d.ts +11 -0
  23. package/dist/local-app-server.d.ts.map +1 -1
  24. package/dist/management.d.ts +0 -7
  25. package/dist/management.d.ts.map +1 -1
  26. package/dist/remote-session-protocol.d.ts +2 -0
  27. package/dist/remote-session-protocol.d.ts.map +1 -1
  28. package/dist/remote-turn-coordinator.d.ts.map +1 -1
  29. package/dist/types.d.ts +57 -66
  30. package/dist/types.d.ts.map +1 -1
  31. package/dist/validation.d.ts.map +1 -1
  32. package/package.json +2 -2
  33. package/src/app-server-management.ts +20 -256
  34. package/src/app-server-session.ts +0 -32
  35. package/src/client-base.ts +47 -73
  36. package/src/client.ts +31 -70
  37. package/src/cloud-session.ts +9 -267
  38. package/src/cloud-status-transport.ts +305 -0
  39. package/src/index.ts +11 -29
  40. package/src/local-app-server-session.ts +13 -3
  41. package/src/local-app-server.ts +97 -3
  42. package/src/management.ts +0 -7
  43. package/src/remote-session-protocol.ts +14 -0
  44. package/src/remote-turn-coordinator.ts +20 -2
  45. package/src/types.ts +64 -111
  46. package/src/validation.ts +21 -6
  47. package/dist/protocol.d.ts +0 -205
  48. package/dist/protocol.d.ts.map +0 -1
  49. package/dist/session.d.ts +0 -155
  50. package/dist/session.d.ts.map +0 -1
  51. package/dist/transport.d.ts +0 -53
  52. package/dist/transport.d.ts.map +0 -1
  53. package/src/protocol.ts +0 -249
  54. package/src/session.ts +0 -1638
  55. package/src/transport.ts +0 -484
package/src/index.ts CHANGED
@@ -11,9 +11,6 @@
11
11
  * const agentId = await client.createAgent();
12
12
  * const clientSession = client.resumeSession(agentId);
13
13
  *
14
- * // Start session with default agent + new conversation (like `letta`)
15
- * const session = createSession();
16
- *
17
14
  * // Create a new agent explicitly
18
15
  * const agentId = await createAgent();
19
16
  *
@@ -26,13 +23,11 @@
26
23
  * // Create new conversation on specific agent
27
24
  * const session = createSession(agentId);
28
25
  *
29
- * // One-shot prompt (uses default agent)
30
- * const result = await prompt('Hello');
31
- * const result = await prompt('Hello', agentId); // specific agent
26
+ * // One-shot prompt in a new conversation
27
+ * const result = await prompt('Hello', agentId);
32
28
  * ```
33
29
  */
34
30
 
35
- import { Session } from "./session.js";
36
31
  import { LettaAgentClient } from "./client.js";
37
32
  import type {
38
33
  CreateSessionOptions,
@@ -98,6 +93,7 @@ export type {
98
93
  SessionDiffPreview,
99
94
  SkillSource,
100
95
  DreamingOptions,
96
+ SessionDreamingOptions,
101
97
  DreamingTrigger,
102
98
  DreamingBehavior,
103
99
  EffectiveDreamingSettings,
@@ -164,7 +160,6 @@ export type {
164
160
  ConversationMessagesResult,
165
161
  } from "./management-types.js";
166
162
 
167
- export { Session } from "./session.js";
168
163
  export { RepositoriesClient } from "./repositories.js";
169
164
  export { LettaAgentClient } from "./client.js";
170
165
  export { CloudManagedSandboxExpiredError } from "./cloud-session.js";
@@ -210,29 +205,20 @@ export async function createAgent(options: CreateAgentOptions = {}): Promise<str
210
205
  /**
211
206
  * Create a new conversation (session).
212
207
  *
213
- * - Without agentId: uses default/LRU agent with new conversation (like `letta`)
214
- * - With agentId: creates new conversation on specified agent
208
+ * Creates a new conversation on the specified agent.
215
209
  *
216
210
  * @example
217
211
  * ```typescript
218
- * // New conversation on default agent (like `letta`)
219
- * await using session = createSession();
220
- *
221
212
  * // New conversation on specific agent
222
213
  * await using session = createSession(agentId);
223
214
  * ```
224
215
  */
225
216
  export function createSession(
226
- agentId?: string,
217
+ agentId: string,
227
218
  options: CreateSessionOptions = {},
228
219
  ): LettaCodeSession {
229
220
  validateCreateSessionOptions(options);
230
- if (agentId) {
231
- return new LettaAgentClient().createSession(agentId, options);
232
- }
233
- // The app-server runtime_start protocol requires an explicit agent id. Keep
234
- // the historical default/LRU-agent helper on the legacy stdio transport.
235
- return new LettaAgentClient({ backend: "local", transport: "stdio" }).createSession(options);
221
+ return new LettaAgentClient().createSession(agentId, options);
236
222
  }
237
223
 
238
224
  /**
@@ -264,13 +250,11 @@ export function resumeSession(
264
250
  /**
265
251
  * One-shot prompt convenience function.
266
252
  *
267
- * - Without agentId: uses default agent (like `letta -p`), new conversation
268
- * - With agentId: uses specific agent, new conversation
253
+ * Uses the specified agent in a new conversation.
269
254
  * - Uses a short-lived session and returns the final turn result.
270
255
  *
271
256
  * @example
272
257
  * ```typescript
273
- * const result = await prompt('What is 2+2?'); // default agent
274
258
  * const result = await prompt('What is the capital of France?', agentId); // specific agent
275
259
  * ```
276
260
  */
@@ -283,13 +267,11 @@ type InitializableSession = LettaCodeSession & {
283
267
  };
284
268
 
285
269
  export async function prompt(
286
- message: string,
287
- agentId?: string
270
+ message: SendMessage,
271
+ agentId: string,
272
+ options: CreateSessionOptions = {},
288
273
  ): Promise<SDKResultMessage> {
289
- // Use default agent behavior (like letta -p) when no agentId specified
290
- const session = agentId
291
- ? createSession(agentId)
292
- : createSession();
274
+ const session = createSession(agentId, options);
293
275
 
294
276
  try {
295
277
  return await (session as TurnSession).runTurn(message);
@@ -4,12 +4,14 @@ import {
4
4
  type AppServerSessionOptions,
5
5
  } from "./app-server-session.js";
6
6
  import { startLocalAppServer } from "./local-app-server.js";
7
- import type { LettaCodeLocalAppServerOptions } from "./types.js";
7
+ import type {
8
+ LettaCodeClientSessionOptions,
9
+ LettaCodeLocalAppServerOptions,
10
+ } from "./types.js";
8
11
 
9
12
  export function createLocalAppServerSession(
10
13
  options: LettaCodeLocalAppServerOptions | undefined,
11
14
  mode: AppServerSessionMode,
12
- beforeConnect?: () => Promise<void>,
13
15
  ): AppServerSession {
14
16
  const appServer = options ?? {};
15
17
  const sessionOptions: AppServerSessionOptions = {
@@ -22,6 +24,15 @@ export function createLocalAppServerSession(
22
24
  backend: appServer.harnessBackend ?? "local",
23
25
  startupTimeoutMs: appServer.startupTimeoutMs,
24
26
  env: sessionEnv,
27
+ filesystemConfinement:
28
+ mode.kind === "session"
29
+ ? (mode.options as LettaCodeClientSessionOptions)
30
+ .filesystemConfinement
31
+ : undefined,
32
+ agentId:
33
+ mode.kind === "session" && "agentId" in mode
34
+ ? mode.agentId
35
+ : undefined,
25
36
  }),
26
37
  }),
27
38
  ...(appServer.WebSocket !== undefined
@@ -33,7 +44,6 @@ export function createLocalAppServerSession(
33
44
  ...(appServer.pinGlobalAgent !== undefined
34
45
  ? { pinGlobalAgent: appServer.pinGlobalAgent }
35
46
  : {}),
36
- ...(beforeConnect ? { beforeConnect } : {}),
37
47
  };
38
48
  return new AppServerSession(sessionOptions, mode);
39
49
  }
@@ -1,4 +1,11 @@
1
1
  import { spawn, type ChildProcess } from "node:child_process";
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
+ import {
5
+ createMemoryConfinementLauncher,
6
+ type MemoryConfinementLauncherInput,
7
+ type MemoryConfinementLauncherResult,
8
+ } from "@letta-ai/letta-code/memory-confinement";
2
9
  import { findLettaCli } from "./cli-resolver.js";
3
10
 
4
11
  export interface LocalAppServerHandle {
@@ -12,12 +19,70 @@ export interface StartLocalAppServerOptions {
12
19
  startupTimeoutMs?: number;
13
20
  cliPath?: string;
14
21
  env?: Record<string, string | undefined>;
22
+ filesystemConfinement?: "memory";
23
+ agentId?: string;
15
24
  }
16
25
 
26
+ interface LocalAppServerProcess {
27
+ command: string;
28
+ args: string[];
29
+ env: NodeJS.ProcessEnv;
30
+ }
31
+
32
+ type MemoryConfinementLauncher = (
33
+ input: MemoryConfinementLauncherInput,
34
+ ) => MemoryConfinementLauncherResult;
35
+
17
36
  const DEFAULT_LISTEN_URL = "ws://127.0.0.1:0";
18
37
  const DEFAULT_STARTUP_TIMEOUT_MS = 30_000;
19
38
  const LISTENING_RE = /^Listening on\s+(ws:\/\/\S+)\s*$/m;
20
39
 
40
+ function targetHomeDirectory(env: NodeJS.ProcessEnv): string {
41
+ if (process.platform === "win32") {
42
+ const profile = env.USERPROFILE?.trim();
43
+ if (profile) return profile;
44
+ const drive = env.HOMEDRIVE?.trim();
45
+ const path = env.HOMEPATH?.trim();
46
+ if (drive && path) return `${drive}${path}`;
47
+ return homedir();
48
+ }
49
+ return env.HOME?.trim() || homedir();
50
+ }
51
+
52
+ function withDefaultMemoryDirectory(
53
+ env: NodeJS.ProcessEnv,
54
+ options: StartLocalAppServerOptions,
55
+ ): NodeJS.ProcessEnv {
56
+ const explicitMemoryDir = options.env?.MEMORY_DIR?.trim();
57
+ const explicitLettaMemoryDir = options.env?.LETTA_MEMORY_DIR?.trim();
58
+ const scopedEnv = { ...env };
59
+ if (explicitMemoryDir || explicitLettaMemoryDir) {
60
+ if (!explicitMemoryDir) delete scopedEnv.MEMORY_DIR;
61
+ if (!explicitLettaMemoryDir) delete scopedEnv.LETTA_MEMORY_DIR;
62
+ return scopedEnv;
63
+ }
64
+
65
+ // Never inherit the SDK process's agent scope into a different session.
66
+ delete scopedEnv.MEMORY_DIR;
67
+ delete scopedEnv.LETTA_MEMORY_DIR;
68
+ if (!options.agentId) return scopedEnv;
69
+
70
+ const homeDir = targetHomeDirectory(env);
71
+ // Mirrors Letta Code's getScopedMemoryFilesystemRoot contract. The SDK pins
72
+ // an exact Letta Code version so the launch policy and layout move together.
73
+ const memoryDir =
74
+ options.backend === "api"
75
+ ? join(homeDir, ".letta", "agents", options.agentId, "memory")
76
+ : join(
77
+ env.LETTA_LOCAL_BACKEND_DIR?.trim() ||
78
+ join(homeDir, ".letta", "lc-local-backend"),
79
+ "memfs",
80
+ options.agentId,
81
+ "memory",
82
+ );
83
+ return { ...scopedEnv, MEMORY_DIR: memoryDir };
84
+ }
85
+
21
86
  function appendLine(buffer: string, chunk: unknown): string {
22
87
  return buffer + String(chunk);
23
88
  }
@@ -40,6 +105,35 @@ export function buildLocalAppServerArgs(
40
105
  ];
41
106
  }
42
107
 
108
+ export function buildLocalAppServerProcess(
109
+ cliPath: string,
110
+ options: StartLocalAppServerOptions = {},
111
+ confineMemory: MemoryConfinementLauncher = createMemoryConfinementLauncher,
112
+ ): LocalAppServerProcess {
113
+ const env = { ...process.env, ...(options.env ?? {}) };
114
+ const launcher = [
115
+ process.execPath,
116
+ ...buildLocalAppServerArgs(cliPath, options),
117
+ ];
118
+ if (options.filesystemConfinement !== "memory") {
119
+ return {
120
+ command: launcher[0] as string,
121
+ args: launcher.slice(1),
122
+ env,
123
+ };
124
+ }
125
+
126
+ const confined = confineMemory({
127
+ launcher,
128
+ env: withDefaultMemoryDirectory(env, options),
129
+ });
130
+ return {
131
+ command: confined.launcher[0] as string,
132
+ args: confined.launcher.slice(1),
133
+ env: confined.env,
134
+ };
135
+ }
136
+
43
137
  function terminateProcess(child: ChildProcess): void {
44
138
  if (child.exitCode !== null || child.signalCode !== null) return;
45
139
  child.kill("SIGTERM");
@@ -57,13 +151,13 @@ export function startLocalAppServer(
57
151
  options: StartLocalAppServerOptions = {},
58
152
  ): Promise<LocalAppServerHandle> {
59
153
  const cliPath = options.cliPath ?? findLettaCli();
60
- const args = buildLocalAppServerArgs(cliPath, options);
154
+ const processSpec = buildLocalAppServerProcess(cliPath, options);
61
155
  const startupTimeoutMs = options.startupTimeoutMs ?? DEFAULT_STARTUP_TIMEOUT_MS;
62
156
 
63
157
  return new Promise((resolve, reject) => {
64
- const child = spawn(process.execPath, args, {
158
+ const child = spawn(processSpec.command, processSpec.args, {
65
159
  stdio: ["ignore", "pipe", "pipe"],
66
- env: { ...process.env, ...(options.env ?? {}) },
160
+ env: processSpec.env,
67
161
  });
68
162
 
69
163
  let settled = false;
package/src/management.ts CHANGED
@@ -45,13 +45,6 @@ export interface ManagementTransport {
45
45
  conversationId: string,
46
46
  query: ManagementQuery,
47
47
  ): Promise<ConversationMessagesResult>;
48
- /**
49
- * Release the pooled connection, waiting for in-flight work when necessary,
50
- * so other clients of the same backend (for example sessions, which compete
51
- * for the app-server's single control-client slot) can connect. Optional;
52
- * transports whose backend has no such contention (Cloud REST) omit it.
53
- */
54
- releaseIdleConnection?(): Promise<void> | void;
55
48
  }
56
49
 
57
50
  type TransportProvider = () => ManagementTransport;
@@ -450,6 +450,20 @@ export function streamDeltaRunId(delta: Record<string, unknown>): string | undef
450
450
  return typeof delta.run_id === "string" ? delta.run_id : undefined;
451
451
  }
452
452
 
453
+ export function streamDeltaOtid(
454
+ delta: Record<string, unknown>,
455
+ ): string | null | undefined {
456
+ return typeof delta.otid === "string" || delta.otid === null
457
+ ? delta.otid
458
+ : undefined;
459
+ }
460
+
461
+ export function streamDeltaSeqId(
462
+ delta: Record<string, unknown>,
463
+ ): number | undefined {
464
+ return typeof delta.seq_id === "number" ? delta.seq_id : undefined;
465
+ }
466
+
453
467
  export function streamDeltaStopReason(delta: Record<string, unknown>): string | null | undefined {
454
468
  return typeof delta.stop_reason === "string" ? delta.stop_reason : undefined;
455
469
  }
@@ -18,8 +18,10 @@ import {
18
18
  queueItems,
19
19
  sameRuntime,
20
20
  streamDeltaMessageType,
21
+ streamDeltaOtid,
21
22
  streamDeltaRecord,
22
23
  streamDeltaRunId,
24
+ streamDeltaSeqId,
23
25
  streamDeltaStopReason,
24
26
  toSdkErrorCode,
25
27
  toSessionDeviceStatus,
@@ -303,6 +305,8 @@ export class RemoteTurnCoordinator {
303
305
  const messageType =
304
306
  typeof delta.message_type === "string" ? delta.message_type : undefined;
305
307
  const runId = typeof delta.run_id === "string" ? delta.run_id : undefined;
308
+ const otid = streamDeltaOtid(delta);
309
+ const seqId = streamDeltaSeqId(delta);
306
310
  const uuid =
307
311
  typeof delta.id === "string"
308
312
  ? delta.id
@@ -312,7 +316,14 @@ export class RemoteTurnCoordinator {
312
316
  const content = extractTextFromContent(delta.content);
313
317
  if (!content) return null;
314
318
  if (this.activeTurn) this.activeTurn.assistantText += content;
315
- return { type: "assistant", content, uuid, runId };
319
+ return {
320
+ type: "assistant",
321
+ content,
322
+ uuid,
323
+ ...(otid !== undefined ? { otid } : {}),
324
+ ...(seqId !== undefined ? { seqId } : {}),
325
+ runId,
326
+ };
316
327
  }
317
328
 
318
329
  if (messageType === "reasoning_message") {
@@ -321,7 +332,14 @@ export class RemoteTurnCoordinator {
321
332
  ? delta.reasoning
322
333
  : extractTextFromContent(delta.content);
323
334
  if (!content) return null;
324
- return { type: "reasoning", content, uuid, runId };
335
+ return {
336
+ type: "reasoning",
337
+ content,
338
+ uuid,
339
+ ...(otid !== undefined ? { otid } : {}),
340
+ ...(seqId !== undefined ? { seqId } : {}),
341
+ runId,
342
+ };
325
343
  }
326
344
 
327
345
  if (
package/src/types.ts CHANGED
@@ -5,27 +5,6 @@
5
5
  * Protocol types are defined locally to avoid relying on broken package subpath exports.
6
6
  */
7
7
 
8
- // Re-export protocol types for internal use
9
- export type {
10
- WireMessage,
11
- SystemInitMessage,
12
- MessageWire,
13
- ResultMessage,
14
- ErrorMessage,
15
- StreamEvent,
16
- ControlRequest,
17
- ControlResponse,
18
- CanUseToolControlRequest,
19
- CanUseToolResponse,
20
- CanUseToolResponseAllow,
21
- CanUseToolResponseDeny,
22
- // Configuration types
23
- SystemPromptPresetConfig,
24
- CreateBlock,
25
- } from "./protocol.js";
26
-
27
- // Import types for use in this file
28
- import type { CreateBlock, CanUseToolResponse } from "./protocol.js";
29
8
  import type { PersonalityId } from "@letta-ai/letta-code/agent-presets";
30
9
  import type { LettaCodeCloudSandboxOptions } from "./cloud-sandbox.js";
31
10
  export type {
@@ -36,6 +15,26 @@ export type {
36
15
  /** Letta Code personality preset used to seed a new agent. */
37
16
  export type LettaCodePersonalityId = PersonalityId;
38
17
 
18
+ /** Custom memory block definition accepted when creating agents. */
19
+ export interface CreateBlock {
20
+ label: string;
21
+ value: string;
22
+ base_template_id?: string | null;
23
+ deployment_id?: string | null;
24
+ description?: string | null;
25
+ entity_id?: string | null;
26
+ hidden?: boolean | null;
27
+ is_template?: boolean;
28
+ limit?: number;
29
+ metadata?: Record<string, unknown> | null;
30
+ preserve_on_migration?: boolean | null;
31
+ project_id?: string | null;
32
+ read_only?: boolean;
33
+ tags?: string[] | null;
34
+ template_id?: string | null;
35
+ template_name?: string | null;
36
+ }
37
+
39
38
  export interface LettaCodeSocketLike {
40
39
  readyState: number;
41
40
  send(data: string): void;
@@ -152,6 +151,9 @@ export interface DreamingOptions {
152
151
  stepCount?: number;
153
152
  }
154
153
 
154
+ /** Dreaming settings that can be changed when opening an existing agent session. */
155
+ export type SessionDreamingOptions = Omit<DreamingOptions, "behavior">;
156
+
155
157
  /**
156
158
  * Fully-resolved dreaming settings emitted by init messages.
157
159
  */
@@ -319,8 +321,6 @@ export interface LettaCodeLocalAppServerOptions {
319
321
  WebSocket?: LettaCodeSocketConstructor;
320
322
  /** Timeout for websocket protocol request/turn correlation. */
321
323
  requestTimeoutMs?: number;
322
- /** Milliseconds an idle management connection may be reused before release. Defaults to 250. */
323
- idleLingerMs?: number;
324
324
  /** Whether agents created through this app-server are added to Letta Code's global pinned-agent list. */
325
325
  pinGlobalAgent?: boolean;
326
326
  /** Local app-server listen URL when the SDK spawns it. Defaults to ws://127.0.0.1:0. */
@@ -331,9 +331,7 @@ export interface LettaCodeLocalAppServerOptions {
331
331
 
332
332
  export interface LettaCodeLocalClientOptions {
333
333
  backend?: "local";
334
- /** Advanced local transport override. Defaults to app-server. */
335
- transport?: "app-server" | "stdio";
336
- /** Advanced app-server overrides for local transport. */
334
+ /** Advanced app-server overrides for local execution. */
337
335
  appServer?: LettaCodeLocalAppServerOptions;
338
336
  }
339
337
 
@@ -347,8 +345,6 @@ export interface LettaCodeRemoteClientOptions {
347
345
  WebSocket?: LettaCodeSocketConstructor;
348
346
  /** Timeout for websocket protocol request/turn correlation. */
349
347
  requestTimeoutMs?: number;
350
- /** Milliseconds an idle management connection may be reused before release. Defaults to 250. */
351
- idleLingerMs?: number;
352
348
  /** Whether agents created through this app-server are added to Letta Code's global pinned-agent list. */
353
349
  pinGlobalAgent?: boolean;
354
350
  }
@@ -496,6 +492,23 @@ export interface CanUseToolPermissionSuggestion {
496
492
  text: string;
497
493
  }
498
494
 
495
+ export interface CanUseToolResponseAllow {
496
+ behavior: "allow";
497
+ message?: string;
498
+ updatedInput?: Record<string, unknown> | null;
499
+ updatedPermissions?: unknown[];
500
+ }
501
+
502
+ export interface CanUseToolResponseDeny {
503
+ behavior: "deny";
504
+ message: string;
505
+ interrupt?: boolean;
506
+ }
507
+
508
+ export type CanUseToolResponse =
509
+ | CanUseToolResponseAllow
510
+ | CanUseToolResponseDeny;
511
+
499
512
  /**
500
513
  * Additional context for a `can_use_tool` approval request, passed as the
501
514
  * optional third argument to {@link CanUseToolCallback}.
@@ -532,69 +545,6 @@ export type CanUseToolCallback = (
532
545
  context?: CanUseToolContext,
533
546
  ) => Promise<CanUseToolResponse> | CanUseToolResponse;
534
547
 
535
- /**
536
- * Internal session options used by Session/Transport classes.
537
- * Not user-facing - use CreateSessionOptions or CreateAgentOptions instead.
538
- * @internal
539
- */
540
- export interface InternalSessionOptions {
541
- // Agent/conversation routing
542
- agentId?: string;
543
- conversationId?: string;
544
- newConversation?: boolean;
545
- defaultConversation?: boolean;
546
- createOnly?: boolean;
547
-
548
- // Agent configuration
549
- model?: string;
550
- reasoningEffort?: ReasoningEffort;
551
- embedding?: string;
552
- systemPrompt?: SystemPromptConfig;
553
-
554
- // Memory blocks (only for new agents)
555
- memory?: MemoryItem[];
556
- persona?: string; // Convenience for persona block
557
- human?: string; // Convenience for human block
558
-
559
- // Tags (only for new agents)
560
- tags?: string[];
561
-
562
- // Skills/reminders
563
- skillSources?: SkillSource[];
564
- systemInfoReminder?: boolean;
565
- dreaming?: DreamingOptions;
566
-
567
- // Permissions
568
- allowedTools?: string[];
569
- disallowedTools?: string[];
570
- permissionMode?: PermissionMode;
571
- canUseTool?: CanUseToolCallback;
572
-
573
- // Server-side tools (only for new agents); omitted -> harness defaults.
574
- baseTools?: string[];
575
-
576
- // Custom tools
577
- tools?: AnyAgentTool[];
578
-
579
- // Process settings
580
- cwd?: string;
581
-
582
- /** If true, pass --include-partial-messages to CLI for token-level stream_event chunks */
583
- includePartialMessages?: boolean;
584
-
585
- /**
586
- * Max automatic approval-conflict recovery attempts per runTurn() call.
587
- * Set to 0 to disable automatic recovery.
588
- */
589
- maxApprovalRecoveryAttempts?: number;
590
-
591
- /**
592
- * Timeout in milliseconds for a single approval recovery request.
593
- */
594
- approvalRecoveryTimeoutMs?: number;
595
-
596
- }
597
-
598
548
  export type PermissionMode =
599
549
  | "standard"
600
550
  | "acceptEdits"
@@ -662,7 +612,8 @@ export interface SendCommandOptions<TResponseType extends string = string> {
662
612
  }
663
613
 
664
614
  /**
665
- * Options for createSession() and resumeSession() - restricted to options that can be applied to existing agents (LRU/Memo).
615
+ * Options for createSession() and resumeSession() restricted to settings that
616
+ * can be applied to existing agents.
666
617
  * For creating new agents with custom memory/persona, use createAgent().
667
618
  */
668
619
  export interface CreateSessionOptions {
@@ -672,9 +623,6 @@ export interface CreateSessionOptions {
672
623
  /** Reasoning effort tier to use with the selected/current model on websocket protocol sessions. */
673
624
  reasoningEffort?: ReasoningEffort;
674
625
 
675
- /** System prompt preset (only presets, no custom strings or append) - updates the agent */
676
- systemPrompt?: SystemPromptPreset;
677
-
678
626
  /**
679
627
  * Exact client-side tool allowlist for the session, including custom SDK
680
628
  * tools. When omitted, the harness default toolset and registered custom
@@ -683,9 +631,6 @@ export interface CreateSessionOptions {
683
631
  */
684
632
  allowedTools?: string[];
685
633
 
686
- /** List of disallowed tool names */
687
- disallowedTools?: string[];
688
-
689
634
  /** Permission mode */
690
635
  permissionMode?: PermissionMode;
691
636
 
@@ -698,16 +643,10 @@ export interface CreateSessionOptions {
698
643
  */
699
644
  skillSources?: SkillSource[];
700
645
 
701
- /**
702
- * Toggle first-turn system info reminder (device/git/cwd context).
703
- * false -> `--no-system-info-reminder`.
704
- */
705
- systemInfoReminder?: boolean;
706
-
707
646
  /**
708
647
  * Configure dreaming settings.
709
648
  */
710
- dreaming?: DreamingOptions;
649
+ dreaming?: SessionDreamingOptions;
711
650
 
712
651
  /** Custom permission callback - called when tool needs approval */
713
652
  canUseTool?: CanUseToolCallback;
@@ -718,12 +657,6 @@ export interface CreateSessionOptions {
718
657
  */
719
658
  tools?: AnyAgentTool[];
720
659
 
721
- /**
722
- * If true, pass --include-partial-messages to CLI to receive token-level
723
- * stream_event chunks for incremental assistant/reasoning rendering.
724
- */
725
- includePartialMessages?: boolean;
726
-
727
660
  /**
728
661
  * Max automatic approval-conflict recovery attempts per runTurn() call.
729
662
  * Set to 0 to disable automatic recovery.
@@ -758,6 +691,14 @@ export interface LettaCodeClientSessionOptions extends CreateSessionOptions {
758
691
  * memory copy. Ignored on remote and cloud transports.
759
692
  */
760
693
  env?: Record<string, string>;
694
+ /**
695
+ * Constrain an SDK-owned local session harness to memory-worker filesystem
696
+ * access. Agent-ID sessions derive the standard root; set `MEMORY_DIR` or
697
+ * `LETTA_MEMORY_DIR` for overrides and conversation-ID resumes. Fails closed
698
+ * without a root or supported kernel sandbox. Excludes agent creation,
699
+ * management calls, and remote/Cloud runtimes.
700
+ */
701
+ filesystemConfinement?: "memory";
761
702
  }
762
703
 
763
704
  export interface LettaCodeSession extends AsyncDisposable {
@@ -1044,7 +985,12 @@ export interface SDKInitMessage {
1044
985
  export interface SDKAssistantMessage {
1045
986
  type: "assistant";
1046
987
  content: string;
988
+ /** Legacy transport identifier. Prefer `otid` for message lineage. */
1047
989
  uuid: string;
990
+ /** Stable lineage key for this typed message slice, when provided. */
991
+ otid?: string | null;
992
+ /** Per-run replay cursor. Compare only within the same `runId`. */
993
+ seqId?: number;
1048
994
  /** Run ID from the Letta API for this event (used for stale-run detection). */
1049
995
  runId?: string;
1050
996
  }
@@ -1074,7 +1020,12 @@ export interface SDKToolResultMessage {
1074
1020
  export interface SDKReasoningMessage {
1075
1021
  type: "reasoning";
1076
1022
  content: string;
1023
+ /** Legacy transport identifier. Prefer `otid` for message lineage. */
1077
1024
  uuid: string;
1025
+ /** Stable lineage key for this typed message slice, when provided. */
1026
+ otid?: string | null;
1027
+ /** Per-run replay cursor. Compare only within the same `runId`. */
1028
+ seqId?: number;
1078
1029
  /** Run ID from the Letta API for this event (used for stale-run detection). */
1079
1030
  runId?: string;
1080
1031
  }
@@ -1126,6 +1077,8 @@ export interface SDKStreamEventMessagePayload {
1126
1077
  message_type: string;
1127
1078
  id?: string;
1128
1079
  otid?: string | null;
1080
+ seq_id?: number;
1081
+ run_id?: string;
1129
1082
  content?: unknown;
1130
1083
  reasoning?: string;
1131
1084
  name?: string;