@letta-ai/letta-agent-sdk 0.3.2 → 0.3.3
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/AGENTS.md +47 -0
- package/README.md +17 -0
- package/dist/client-entry.js +800 -732
- package/dist/client-entry.js.map +8 -5
- package/dist/cloud-sandbox.d.ts +33 -0
- package/dist/cloud-sandbox.d.ts.map +1 -0
- package/dist/cloud-session.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +799 -732
- package/dist/index.js.map +9 -6
- package/dist/remote-client-session-core.d.ts +6 -93
- package/dist/remote-client-session-core.d.ts.map +1 -1
- package/dist/remote-session-protocol.d.ts +130 -0
- package/dist/remote-session-protocol.d.ts.map +1 -0
- package/dist/remote-turn-coordinator.d.ts +49 -0
- package/dist/remote-turn-coordinator.d.ts.map +1 -0
- package/dist/types.d.ts +2 -20
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -2
- package/src/app-server-management.ts +641 -0
- package/src/app-server-session.ts +948 -0
- package/src/cli-resolver.ts +46 -0
- package/src/client-base.ts +482 -0
- package/src/client-entry.ts +31 -0
- package/src/client.ts +138 -0
- package/src/cloud-management.ts +360 -0
- package/src/cloud-sandbox.ts +117 -0
- package/src/cloud-session.ts +1313 -0
- package/src/index.ts +440 -0
- package/src/interactiveToolPolicy.ts +62 -0
- package/src/local-app-server-session.ts +39 -0
- package/src/local-app-server.ts +137 -0
- package/src/management-types.ts +133 -0
- package/src/management.ts +206 -0
- package/src/protocol.ts +249 -0
- package/src/remote-client-session-core.ts +786 -0
- package/src/remote-session-protocol.ts +660 -0
- package/src/remote-turn-coordinator.ts +505 -0
- package/src/remote.ts +177 -0
- package/src/repositories.ts +340 -0
- package/src/request-ids.ts +33 -0
- package/src/session.ts +1638 -0
- package/src/stream-events.ts +88 -0
- package/src/tool-helpers.ts +147 -0
- package/src/transport.ts +484 -0
- package/src/types.ts +1328 -0
- package/src/validation.ts +223 -0
- package/src/websocket.ts +22 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,1328 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Types
|
|
3
|
+
*
|
|
4
|
+
* These are the public-facing types for SDK consumers.
|
|
5
|
+
* Protocol types are defined locally to avoid relying on broken package subpath exports.
|
|
6
|
+
*/
|
|
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
|
+
import type { PersonalityId } from "@letta-ai/letta-code/agent-presets";
|
|
30
|
+
import type { LettaCodeCloudSandboxOptions } from "./cloud-sandbox.js";
|
|
31
|
+
export type {
|
|
32
|
+
GitHubRepositoryRef,
|
|
33
|
+
LettaCodeCloudSandboxOptions,
|
|
34
|
+
} from "./cloud-sandbox.js";
|
|
35
|
+
|
|
36
|
+
/** Letta Code personality preset used to seed a new agent. */
|
|
37
|
+
export type LettaCodePersonalityId = PersonalityId;
|
|
38
|
+
|
|
39
|
+
export interface LettaCodeSocketLike {
|
|
40
|
+
readyState: number;
|
|
41
|
+
send(data: string): void;
|
|
42
|
+
close(): void;
|
|
43
|
+
addEventListener?(type: string, listener: (event: unknown) => void): void;
|
|
44
|
+
removeEventListener?(type: string, listener: (event: unknown) => void): void;
|
|
45
|
+
on?(type: string, listener: (event: unknown) => void): void;
|
|
46
|
+
off?(type: string, listener: (event: unknown) => void): void;
|
|
47
|
+
once?(type: string, listener: (event: unknown) => void): void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface LettaCodeSocketOptions {
|
|
51
|
+
headers?: Record<string, string>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type LettaCodeSocketConstructor = new (
|
|
55
|
+
url: string,
|
|
56
|
+
options?: LettaCodeSocketOptions,
|
|
57
|
+
) => LettaCodeSocketLike;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* React Native's WebSocket constructor accepts request headers as its third
|
|
61
|
+
* argument, unlike the Node-style constructor used by the SDK protocol layer.
|
|
62
|
+
*/
|
|
63
|
+
export type LettaCodeReactNativeSocketConstructor = new (
|
|
64
|
+
url: string,
|
|
65
|
+
protocols?: string | string[] | null,
|
|
66
|
+
options?: LettaCodeSocketOptions,
|
|
67
|
+
) => LettaCodeSocketLike;
|
|
68
|
+
|
|
69
|
+
// ═══════════════════════════════════════════════════════════════
|
|
70
|
+
// MESSAGE CONTENT TYPES (for multimodal support)
|
|
71
|
+
// ═══════════════════════════════════════════════════════════════
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Text content in a message
|
|
75
|
+
*/
|
|
76
|
+
export interface TextContent {
|
|
77
|
+
type: "text";
|
|
78
|
+
text: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface RunTurnOptions {
|
|
82
|
+
/**
|
|
83
|
+
* Max automatic approval-conflict recovery attempts for this turn.
|
|
84
|
+
* Overrides session-level maxApprovalRecoveryAttempts when provided.
|
|
85
|
+
*/
|
|
86
|
+
maxApprovalRecoveryAttempts?: number;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Timeout in milliseconds for each approval recovery request.
|
|
90
|
+
* Overrides session-level approvalRecoveryTimeoutMs when provided.
|
|
91
|
+
*/
|
|
92
|
+
recoveryTimeoutMs?: number;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface RecoverPendingApprovalsOptions {
|
|
96
|
+
/**
|
|
97
|
+
* Timeout in milliseconds for the recovery control request.
|
|
98
|
+
*/
|
|
99
|
+
timeoutMs?: number;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface RecoverPendingApprovalsResult {
|
|
103
|
+
recovered: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Whether a pending approval is known to remain after recovery.
|
|
106
|
+
* Undefined means the SDK could not determine the state (for example, timeout).
|
|
107
|
+
*/
|
|
108
|
+
pendingApproval?: boolean;
|
|
109
|
+
unsupported: boolean;
|
|
110
|
+
detail?: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Image content in a message (base64 encoded)
|
|
115
|
+
*/
|
|
116
|
+
export interface ImageContent {
|
|
117
|
+
type: "image";
|
|
118
|
+
source: {
|
|
119
|
+
type: "base64";
|
|
120
|
+
media_type: "image/png" | "image/jpeg" | "image/gif" | "image/webp";
|
|
121
|
+
data: string;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* A single content item (text or image)
|
|
127
|
+
*/
|
|
128
|
+
export type MessageContentItem = TextContent | ImageContent;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* What send() accepts - either a simple string or multimodal content array
|
|
132
|
+
*/
|
|
133
|
+
export type SendMessage = string | MessageContentItem[];
|
|
134
|
+
|
|
135
|
+
// ═══════════════════════════════════════════════════════════════
|
|
136
|
+
// SKILLS / REMINDER / DREAMING TYPES
|
|
137
|
+
// ═══════════════════════════════════════════════════════════════
|
|
138
|
+
|
|
139
|
+
export type SkillSource = "bundled" | "global" | "agent" | "project";
|
|
140
|
+
|
|
141
|
+
export type DreamingTrigger = "off" | "step-count" | "compaction-event";
|
|
142
|
+
|
|
143
|
+
export type DreamingBehavior = "reminder" | "auto-launch";
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Dreaming settings exposed through SDK options.
|
|
147
|
+
* Any omitted fields preserve server/CLI defaults.
|
|
148
|
+
*/
|
|
149
|
+
export interface DreamingOptions {
|
|
150
|
+
trigger?: DreamingTrigger;
|
|
151
|
+
behavior?: DreamingBehavior;
|
|
152
|
+
stepCount?: number;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Fully-resolved dreaming settings emitted by init messages.
|
|
157
|
+
*/
|
|
158
|
+
export interface EffectiveDreamingSettings {
|
|
159
|
+
trigger: DreamingTrigger;
|
|
160
|
+
behavior: DreamingBehavior;
|
|
161
|
+
stepCount: number;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// ═══════════════════════════════════════════════════════════════
|
|
165
|
+
// SYSTEM PROMPT TYPES
|
|
166
|
+
// ═══════════════════════════════════════════════════════════════
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Available system prompt presets.
|
|
170
|
+
*/
|
|
171
|
+
export type SystemPromptPreset =
|
|
172
|
+
| "default" // Alias for letta-claude
|
|
173
|
+
| "letta-claude" // Full Letta Code prompt (Claude-optimized)
|
|
174
|
+
| "letta-codex" // Full Letta Code prompt (Codex-optimized)
|
|
175
|
+
| "letta-gemini" // Full Letta Code prompt (Gemini-optimized)
|
|
176
|
+
| "claude" // Basic Claude (no skills/memory instructions)
|
|
177
|
+
| "codex" // Basic Codex
|
|
178
|
+
| "gemini"; // Basic Gemini
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* System prompt preset configuration.
|
|
182
|
+
*/
|
|
183
|
+
export interface SystemPromptPresetConfigSDK {
|
|
184
|
+
type: "preset";
|
|
185
|
+
preset: SystemPromptPreset;
|
|
186
|
+
append?: string;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* System prompt configuration - either a raw string or preset config.
|
|
191
|
+
*/
|
|
192
|
+
export type SystemPromptConfig = string | SystemPromptPresetConfigSDK;
|
|
193
|
+
|
|
194
|
+
// ═══════════════════════════════════════════════════════════════
|
|
195
|
+
// MEMORY TYPES
|
|
196
|
+
// ═══════════════════════════════════════════════════════════════
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Reference to an existing shared block by ID.
|
|
200
|
+
*/
|
|
201
|
+
export interface BlockReference {
|
|
202
|
+
blockId: string;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Memory item - can be a preset name, custom block, or block reference.
|
|
207
|
+
*/
|
|
208
|
+
export type MemoryItem =
|
|
209
|
+
| string // Preset name: "project", "persona", "human"
|
|
210
|
+
| CreateBlock // Custom block: { label, value, description? }
|
|
211
|
+
| BlockReference; // Shared block reference: { blockId }
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Default memory block preset names.
|
|
215
|
+
*/
|
|
216
|
+
export type MemoryPreset = "persona" | "human" | "skills" | "loaded_skills";
|
|
217
|
+
|
|
218
|
+
// ═══════════════════════════════════════════════════════════════
|
|
219
|
+
// TOOL TYPES (matches pi-agent-core)
|
|
220
|
+
// ═══════════════════════════════════════════════════════════════
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Tool result content block
|
|
224
|
+
*/
|
|
225
|
+
export interface AgentToolResultContent {
|
|
226
|
+
type: "text" | "image";
|
|
227
|
+
text?: string;
|
|
228
|
+
data?: string; // base64 for images
|
|
229
|
+
mimeType?: string;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Tool result (matches pi-agent-core)
|
|
234
|
+
*/
|
|
235
|
+
export interface AgentToolResult<T> {
|
|
236
|
+
content: AgentToolResultContent[];
|
|
237
|
+
details?: T;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Tool update callback (for streaming tool progress)
|
|
242
|
+
*/
|
|
243
|
+
export type AgentToolUpdateCallback<T> = (update: Partial<AgentToolResult<T>>) => void;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Agent tool definition (matches pi-agent-core)
|
|
247
|
+
*/
|
|
248
|
+
export interface AgentTool<TParams, TResult> {
|
|
249
|
+
/** Display label */
|
|
250
|
+
label: string;
|
|
251
|
+
|
|
252
|
+
/** Tool name (used in API calls) */
|
|
253
|
+
name: string;
|
|
254
|
+
|
|
255
|
+
/** Description shown to the model */
|
|
256
|
+
description: string;
|
|
257
|
+
|
|
258
|
+
/** JSON Schema for parameters (TypeBox or plain object) */
|
|
259
|
+
parameters: TParams;
|
|
260
|
+
|
|
261
|
+
/** Execution function */
|
|
262
|
+
execute: (
|
|
263
|
+
toolCallId: string,
|
|
264
|
+
args: unknown,
|
|
265
|
+
signal?: AbortSignal,
|
|
266
|
+
onUpdate?: AgentToolUpdateCallback<TResult>,
|
|
267
|
+
) => Promise<AgentToolResult<TResult>>;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Convenience type for tools with any params
|
|
272
|
+
*/
|
|
273
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
274
|
+
export type AnyAgentTool = AgentTool<any, unknown>;
|
|
275
|
+
|
|
276
|
+
// ═══════════════════════════════════════════════════════════════
|
|
277
|
+
// TOP-LEVEL CLIENT TYPES
|
|
278
|
+
// ═══════════════════════════════════════════════════════════════
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* How the SDK reaches or runs the Letta Code harness.
|
|
282
|
+
*
|
|
283
|
+
* - local: spawn/manage a local Letta Code app-server over loopback websockets.
|
|
284
|
+
* - remote: connect to a user-managed app-server over websockets.
|
|
285
|
+
* - cloud: use agents hosted on Letta Cloud, with an explicit remote
|
|
286
|
+
* environment or SDK-managed sandbox.
|
|
287
|
+
*/
|
|
288
|
+
export type LettaCodeBackend = "local" | "remote" | "cloud";
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Stable execution target for remote/cloud runtimes.
|
|
292
|
+
*
|
|
293
|
+
* Strings are treated as human-readable environment names. Object forms allow
|
|
294
|
+
* callers to avoid relying on names as unique identifiers.
|
|
295
|
+
*/
|
|
296
|
+
export type LettaCodeEnvironment =
|
|
297
|
+
| string
|
|
298
|
+
| { name: string }
|
|
299
|
+
| { id: string }
|
|
300
|
+
| { connectionId: string }
|
|
301
|
+
| { deviceId: string };
|
|
302
|
+
|
|
303
|
+
export interface LettaCodeLocalAppServerOptions {
|
|
304
|
+
/**
|
|
305
|
+
* Optional URL for tests or advanced users with a pre-started local app-server.
|
|
306
|
+
* Omit to let the SDK spawn and own a loopback app-server.
|
|
307
|
+
*/
|
|
308
|
+
url?: string;
|
|
309
|
+
/**
|
|
310
|
+
* Which Letta Code backend the spawned app-server runs against:
|
|
311
|
+
* - "local": the in-process experimental backend (agents stored on this
|
|
312
|
+
* machine, `agent-local-*` ids). The default.
|
|
313
|
+
* - "api": Letta Cloud (real `agent-*` ids, cloud-side models such as
|
|
314
|
+
* letta/auto-memory) with tools still executing on this machine. Requires
|
|
315
|
+
* the harness to be authenticated (login or LETTA_API_KEY).
|
|
316
|
+
*/
|
|
317
|
+
harnessBackend?: "api" | "local";
|
|
318
|
+
/** Optional WebSocket constructor for tests/non-standard runtimes. */
|
|
319
|
+
WebSocket?: LettaCodeSocketConstructor;
|
|
320
|
+
/** Timeout for websocket protocol request/turn correlation. */
|
|
321
|
+
requestTimeoutMs?: number;
|
|
322
|
+
/** Milliseconds an idle management connection may be reused before release. Defaults to 250. */
|
|
323
|
+
idleLingerMs?: number;
|
|
324
|
+
/** Whether agents created through this app-server are added to Letta Code's global pinned-agent list. */
|
|
325
|
+
pinGlobalAgent?: boolean;
|
|
326
|
+
/** Local app-server listen URL when the SDK spawns it. Defaults to ws://127.0.0.1:0. */
|
|
327
|
+
listen?: string;
|
|
328
|
+
/** Timeout waiting for the spawned app-server to print its listening URL. */
|
|
329
|
+
startupTimeoutMs?: number;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export interface LettaCodeLocalClientOptions {
|
|
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. */
|
|
337
|
+
appServer?: LettaCodeLocalAppServerOptions;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export interface LettaCodeRemoteClientOptions {
|
|
341
|
+
backend: "remote";
|
|
342
|
+
/** URL of the user-managed app-server / websocket endpoint. */
|
|
343
|
+
url: string;
|
|
344
|
+
/** Optional capability token sent as Authorization: Bearer <token> during websocket upgrade. */
|
|
345
|
+
authToken?: string;
|
|
346
|
+
/** Optional WebSocket constructor for non-browser runtimes and tests. */
|
|
347
|
+
WebSocket?: LettaCodeSocketConstructor;
|
|
348
|
+
/** Timeout for websocket protocol request/turn correlation. */
|
|
349
|
+
requestTimeoutMs?: number;
|
|
350
|
+
/** Milliseconds an idle management connection may be reused before release. Defaults to 250. */
|
|
351
|
+
idleLingerMs?: number;
|
|
352
|
+
/** Whether agents created through this app-server are added to Letta Code's global pinned-agent list. */
|
|
353
|
+
pinGlobalAgent?: boolean;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export interface LettaCodeCloudClientOptions {
|
|
357
|
+
backend: "cloud";
|
|
358
|
+
/** Optional API key override. Defaults to LETTA_API_KEY / existing auth. */
|
|
359
|
+
apiKey?: string;
|
|
360
|
+
/** Optional API base URL override. Defaults to the Letta API. */
|
|
361
|
+
apiBaseUrl?: string;
|
|
362
|
+
/** Optional extra HTTP headers for Cloud API requests. */
|
|
363
|
+
headers?: Record<string, string>;
|
|
364
|
+
/** Optional fetch implementation for tests/non-standard runtimes. */
|
|
365
|
+
fetch?: typeof fetch;
|
|
366
|
+
/** Optional WebSocket constructor for non-browser runtimes and tests. */
|
|
367
|
+
WebSocket?: LettaCodeSocketConstructor;
|
|
368
|
+
/** Timeout for websocket protocol request/turn correlation. */
|
|
369
|
+
requestTimeoutMs?: number;
|
|
370
|
+
/**
|
|
371
|
+
* WebSocket authentication style. Defaults to Authorization headers; set to
|
|
372
|
+
* query for browser-style clients that cannot send WebSocket headers.
|
|
373
|
+
*/
|
|
374
|
+
webSocketAuth?: "header" | "query";
|
|
375
|
+
/** Heartbeat interval for the Cloud status websocket. Defaults to 30s. */
|
|
376
|
+
pingIntervalMs?: number;
|
|
377
|
+
/**
|
|
378
|
+
* Execution target for Letta Cloud sessions. If omitted, the SDK creates
|
|
379
|
+
* and owns a sandbox for the session.
|
|
380
|
+
*/
|
|
381
|
+
environment?: LettaCodeEnvironment;
|
|
382
|
+
/** Options for SDK-managed sandboxes when environment is omitted. */
|
|
383
|
+
sandbox?: LettaCodeCloudSandboxOptions;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export type LettaCodeClientOptions =
|
|
387
|
+
| LettaCodeLocalClientOptions
|
|
388
|
+
| LettaCodeRemoteClientOptions
|
|
389
|
+
| LettaCodeCloudClientOptions;
|
|
390
|
+
|
|
391
|
+
export interface Repository {
|
|
392
|
+
id: string;
|
|
393
|
+
name: string;
|
|
394
|
+
createdAt: string;
|
|
395
|
+
updatedAt: string;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export interface CreateRepositoryParams {
|
|
399
|
+
name: string;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export interface ListRepositoriesParams {
|
|
403
|
+
limit?: number;
|
|
404
|
+
offset?: number;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export interface ListRepositoriesResult {
|
|
408
|
+
repositories: Repository[];
|
|
409
|
+
hasNextPage: boolean;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
export interface RepositoryResource {
|
|
413
|
+
type: "repository";
|
|
414
|
+
repositoryId: string;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
export interface RepositoryFileEntry {
|
|
418
|
+
path: string;
|
|
419
|
+
type: "file" | "directory";
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
export interface ListRepositoryFilesParams {
|
|
423
|
+
pathPrefix?: string;
|
|
424
|
+
depth?: number;
|
|
425
|
+
ref?: string;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
export interface ListRepositoryFilesResult {
|
|
429
|
+
files: RepositoryFileEntry[];
|
|
430
|
+
ref: string;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export interface CreateRepositoryFileParams {
|
|
434
|
+
path: string;
|
|
435
|
+
content: string;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export interface RepositoryFile {
|
|
439
|
+
path: string;
|
|
440
|
+
content: string;
|
|
441
|
+
contentSha256: string;
|
|
442
|
+
ref?: string;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
export interface UpdateRepositoryFileParams {
|
|
446
|
+
path: string;
|
|
447
|
+
content?: string;
|
|
448
|
+
newPath?: string;
|
|
449
|
+
precondition?: {
|
|
450
|
+
contentSha256: string;
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
export interface RepositoryFileMutationResult {
|
|
455
|
+
path: string;
|
|
456
|
+
contentSha256: string;
|
|
457
|
+
commitSha: string;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
export interface DeleteRepositoryFileParams {
|
|
461
|
+
path: string;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
export interface DeleteRepositoryFileResult {
|
|
465
|
+
success: boolean;
|
|
466
|
+
commitSha: string;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
export interface RepositoryVersion {
|
|
470
|
+
sha: string;
|
|
471
|
+
message: string;
|
|
472
|
+
timestamp: string;
|
|
473
|
+
author_name: string | null;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
export interface ListRepositoryVersionsParams {
|
|
477
|
+
path?: string;
|
|
478
|
+
limit?: number;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export interface GetRepositoryVersionParams {
|
|
482
|
+
path: string;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// ═══════════════════════════════════════════════════════════════
|
|
486
|
+
// SESSION OPTIONS
|
|
487
|
+
// ═══════════════════════════════════════════════════════════════
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* A suggested permission grant attached to a `can_use_tool` approval request.
|
|
491
|
+
* Approval UIs can render these as selectable chips and echo the chosen ids
|
|
492
|
+
* back via `CanUseToolResponseAllow.updatedPermissions`.
|
|
493
|
+
*/
|
|
494
|
+
export interface CanUseToolPermissionSuggestion {
|
|
495
|
+
id: string;
|
|
496
|
+
text: string;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Additional context for a `can_use_tool` approval request, passed as the
|
|
501
|
+
* optional third argument to {@link CanUseToolCallback}.
|
|
502
|
+
*
|
|
503
|
+
* All fields are optional: transports pass through whatever subset the wire
|
|
504
|
+
* protocol provides, leaving absent fields undefined.
|
|
505
|
+
*/
|
|
506
|
+
export interface CanUseToolContext {
|
|
507
|
+
/** Id of the control request carrying this approval (for logging/correlation). */
|
|
508
|
+
requestId?: string;
|
|
509
|
+
/** Tool call id — links the approval to its tool_call card in the message stream. */
|
|
510
|
+
toolCallId?: string;
|
|
511
|
+
/** Suggested permission grants the user can select. */
|
|
512
|
+
permissionSuggestions?: CanUseToolPermissionSuggestion[];
|
|
513
|
+
/** Path that triggered the permission check, when the tool was blocked on a path rule. */
|
|
514
|
+
blockedPath?: string | null;
|
|
515
|
+
/**
|
|
516
|
+
* Diff previews for file-editing tools, passed through verbatim.
|
|
517
|
+
* Shape matches letta-code's `DiffPreview` (mode: "advanced" | "fallback" | "unpreviewable").
|
|
518
|
+
*/
|
|
519
|
+
diffs?: unknown[];
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* Callback for custom permission handling.
|
|
524
|
+
*
|
|
525
|
+
* The optional third argument carries approval context (tool call id,
|
|
526
|
+
* permission suggestions, diff previews). Two-argument callbacks remain
|
|
527
|
+
* fully supported.
|
|
528
|
+
*/
|
|
529
|
+
export type CanUseToolCallback = (
|
|
530
|
+
toolName: string,
|
|
531
|
+
toolInput: Record<string, unknown>,
|
|
532
|
+
context?: CanUseToolContext,
|
|
533
|
+
) => Promise<CanUseToolResponse> | CanUseToolResponse;
|
|
534
|
+
|
|
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
|
+
export type PermissionMode =
|
|
599
|
+
| "standard"
|
|
600
|
+
| "acceptEdits"
|
|
601
|
+
| "unrestricted";
|
|
602
|
+
|
|
603
|
+
export type ReasoningEffort =
|
|
604
|
+
| "none"
|
|
605
|
+
| "minimal"
|
|
606
|
+
| "low"
|
|
607
|
+
| "medium"
|
|
608
|
+
| "high"
|
|
609
|
+
| "xhigh";
|
|
610
|
+
|
|
611
|
+
export type LettaCodeModelEntry = Record<string, unknown> & {
|
|
612
|
+
id: string;
|
|
613
|
+
handle: string;
|
|
614
|
+
label: string;
|
|
615
|
+
description: string;
|
|
616
|
+
isDefault?: boolean;
|
|
617
|
+
isFeatured?: boolean;
|
|
618
|
+
free?: boolean;
|
|
619
|
+
updateArgs?: Record<string, unknown>;
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
export interface ListModelsResult {
|
|
623
|
+
entries: LettaCodeModelEntry[];
|
|
624
|
+
/** Handles available to this user. null means availability lookup failed. */
|
|
625
|
+
availableHandles?: string[] | null;
|
|
626
|
+
/** BYOK provider name -> base provider name, e.g. lc-anthropic -> anthropic. */
|
|
627
|
+
byokProviderAliases?: Record<string, string>;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
export interface UpdateModelOptions {
|
|
631
|
+
/** Model id from listModels() or direct model handle. Model ids usually omit '/'. */
|
|
632
|
+
model?: string;
|
|
633
|
+
/** Explicit model id from listModels(). */
|
|
634
|
+
modelId?: string;
|
|
635
|
+
/** Explicit direct model handle, including BYOK handles. */
|
|
636
|
+
modelHandle?: string;
|
|
637
|
+
/** Select a reasoning tier for the target model handle. */
|
|
638
|
+
reasoningEffort?: ReasoningEffort;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
export interface UpdateModelResult {
|
|
642
|
+
appliedTo?: "agent" | "conversation";
|
|
643
|
+
modelId?: string;
|
|
644
|
+
modelHandle?: string;
|
|
645
|
+
modelSettings?: Record<string, unknown> | null;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
export type SDKProtocolMessage<TType extends string = string> = Record<string, unknown> & {
|
|
649
|
+
type: TType;
|
|
650
|
+
request_id?: string;
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
export type SDKProtocolCommand<TType extends string = string> = SDKProtocolMessage<TType>;
|
|
654
|
+
|
|
655
|
+
export interface SendCommandOptions<TResponseType extends string = string> {
|
|
656
|
+
/** Wait for a response with this protocol message type. Omit for fire-and-forget commands. */
|
|
657
|
+
responseType?: TResponseType;
|
|
658
|
+
/** Override the websocket protocol request timeout for this command. */
|
|
659
|
+
timeoutMs?: number;
|
|
660
|
+
/** Optional custom matcher for advanced protocol responses. */
|
|
661
|
+
predicate?: (message: SDKProtocolMessage) => boolean;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* Options for createSession() and resumeSession() - restricted to options that can be applied to existing agents (LRU/Memo).
|
|
666
|
+
* For creating new agents with custom memory/persona, use createAgent().
|
|
667
|
+
*/
|
|
668
|
+
export interface CreateSessionOptions {
|
|
669
|
+
/** Model to use (e.g., "claude-sonnet-4-20250514") - updates the agent's LLM config */
|
|
670
|
+
model?: string;
|
|
671
|
+
|
|
672
|
+
/** Reasoning effort tier to use with the selected/current model on websocket protocol sessions. */
|
|
673
|
+
reasoningEffort?: ReasoningEffort;
|
|
674
|
+
|
|
675
|
+
/** System prompt preset (only presets, no custom strings or append) - updates the agent */
|
|
676
|
+
systemPrompt?: SystemPromptPreset;
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* Exact client-side tool allowlist for the session, including custom SDK
|
|
680
|
+
* tools. When omitted, the harness default toolset and registered custom
|
|
681
|
+
* tools apply. Interactive user-input tools (AskUserQuestion) are always
|
|
682
|
+
* excluded for SDK sessions.
|
|
683
|
+
*/
|
|
684
|
+
allowedTools?: string[];
|
|
685
|
+
|
|
686
|
+
/** List of disallowed tool names */
|
|
687
|
+
disallowedTools?: string[];
|
|
688
|
+
|
|
689
|
+
/** Permission mode */
|
|
690
|
+
permissionMode?: PermissionMode;
|
|
691
|
+
|
|
692
|
+
/** Working directory for the CLI process */
|
|
693
|
+
cwd?: string;
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* Restrict available skills by source.
|
|
697
|
+
* Empty array disables all skills (`--no-skills`).
|
|
698
|
+
*/
|
|
699
|
+
skillSources?: SkillSource[];
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Toggle first-turn system info reminder (device/git/cwd context).
|
|
703
|
+
* false -> `--no-system-info-reminder`.
|
|
704
|
+
*/
|
|
705
|
+
systemInfoReminder?: boolean;
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* Configure dreaming settings.
|
|
709
|
+
*/
|
|
710
|
+
dreaming?: DreamingOptions;
|
|
711
|
+
|
|
712
|
+
/** Custom permission callback - called when tool needs approval */
|
|
713
|
+
canUseTool?: CanUseToolCallback;
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Custom tools that execute locally in the SDK process.
|
|
717
|
+
* These tools are registered with the CLI and executed when the LLM calls them.
|
|
718
|
+
*/
|
|
719
|
+
tools?: AnyAgentTool[];
|
|
720
|
+
|
|
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
|
+
/**
|
|
728
|
+
* Max automatic approval-conflict recovery attempts per runTurn() call.
|
|
729
|
+
* Set to 0 to disable automatic recovery.
|
|
730
|
+
*/
|
|
731
|
+
maxApprovalRecoveryAttempts?: number;
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* Timeout in milliseconds for a single approval recovery request.
|
|
735
|
+
*/
|
|
736
|
+
approvalRecoveryTimeoutMs?: number;
|
|
737
|
+
|
|
738
|
+
/** Cloud repository resources to attach for the lifetime of the SDK session. */
|
|
739
|
+
resources?: RepositoryResource[];
|
|
740
|
+
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
/**
|
|
744
|
+
* Session options accepted by LettaAgentClient methods.
|
|
745
|
+
*
|
|
746
|
+
* `environment` is a cloud execution-target override. It is deliberately
|
|
747
|
+
* session-scoped rather than part of createAgent() options.
|
|
748
|
+
*/
|
|
749
|
+
export interface LettaCodeClientSessionOptions extends CreateSessionOptions {
|
|
750
|
+
environment?: LettaCodeEnvironment;
|
|
751
|
+
/** Per-session SDK-managed sandbox options when environment is omitted. */
|
|
752
|
+
sandbox?: LettaCodeCloudSandboxOptions;
|
|
753
|
+
/**
|
|
754
|
+
* Extra environment variables for the session's harness process. Each
|
|
755
|
+
* SDK-owned local app-server session runs in its own process, so this
|
|
756
|
+
* scopes cleanly per session — e.g. MEMORY_DIR / LETTA_MEMORY_DIR to point
|
|
757
|
+
* the harness's memory scoping (and its guard) at a session-specific
|
|
758
|
+
* memory copy. Ignored on remote and cloud transports.
|
|
759
|
+
*/
|
|
760
|
+
env?: Record<string, string>;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
export interface LettaCodeSession extends AsyncDisposable {
|
|
764
|
+
send(message: SendMessage): Promise<void>;
|
|
765
|
+
stream(): AsyncGenerator<SDKMessage>;
|
|
766
|
+
abort(): Promise<void>;
|
|
767
|
+
sendCommand(command: SDKProtocolCommand): Promise<void>;
|
|
768
|
+
sendCommand<TResponse extends SDKProtocolMessage = SDKProtocolMessage>(
|
|
769
|
+
command: SDKProtocolCommand,
|
|
770
|
+
options: SendCommandOptions,
|
|
771
|
+
): Promise<TResponse>;
|
|
772
|
+
listMessages(options?: ListMessagesOptions): Promise<ListMessagesResult>;
|
|
773
|
+
listModels(): Promise<ListModelsResult>;
|
|
774
|
+
updateModel(update: string | UpdateModelOptions): Promise<UpdateModelResult>;
|
|
775
|
+
/**
|
|
776
|
+
* Fetch the initial conversation projection used to hydrate or reconcile a
|
|
777
|
+
* resumed session.
|
|
778
|
+
*/
|
|
779
|
+
bootstrapState(options?: BootstrapStateOptions): Promise<BootstrapStateResult>;
|
|
780
|
+
/**
|
|
781
|
+
* Ask the runtime to recover any approval that was pending across a
|
|
782
|
+
* disconnect.
|
|
783
|
+
*/
|
|
784
|
+
recoverPendingApprovals(
|
|
785
|
+
options?: RecoverPendingApprovalsOptions,
|
|
786
|
+
): Promise<RecoverPendingApprovalsResult>;
|
|
787
|
+
/**
|
|
788
|
+
* Update runtime controls for subsequent work in this conversation.
|
|
789
|
+
*
|
|
790
|
+
* The current app-server protocol does not acknowledge this command. The
|
|
791
|
+
* promise confirms that the command was accepted for transport, not that the
|
|
792
|
+
* runtime has applied it.
|
|
793
|
+
*/
|
|
794
|
+
changeDeviceState(updates: ChangeDeviceStateOptions): Promise<void>;
|
|
795
|
+
/**
|
|
796
|
+
* Remove one queued user message and wait for the runtime acknowledgement.
|
|
797
|
+
*/
|
|
798
|
+
removeQueuedMessage(itemId: string): Promise<RemoveQueuedMessageResult>;
|
|
799
|
+
/**
|
|
800
|
+
* Read the device execution context (online/processing flags, permission
|
|
801
|
+
* mode, working directory, pending approvals).
|
|
802
|
+
*
|
|
803
|
+
* Sends a lightweight, request-correlated `sync` and resolves only after the
|
|
804
|
+
* runtime acknowledges it and pushes a fresh `update_device_status`
|
|
805
|
+
* snapshot for this runtime scope.
|
|
806
|
+
*/
|
|
807
|
+
getDeviceStatus(options?: GetDeviceStatusOptions): Promise<SessionDeviceStatus>;
|
|
808
|
+
/**
|
|
809
|
+
* Subscribe to every incoming device-status update for this session's
|
|
810
|
+
* runtime scope. Returns an unsubscribe function.
|
|
811
|
+
*/
|
|
812
|
+
onDeviceStatus(listener: (status: SessionDeviceStatus) => void): () => void;
|
|
813
|
+
close(): void;
|
|
814
|
+
readonly agentId: string | null;
|
|
815
|
+
readonly sessionId: string | null;
|
|
816
|
+
readonly conversationId: string | null;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
export interface ChangeDeviceStateOptions {
|
|
820
|
+
cwd?: string;
|
|
821
|
+
permissionMode?: PermissionMode;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
export interface RemoveQueuedMessageResult {
|
|
825
|
+
/** Queue item identifier echoed by the runtime. */
|
|
826
|
+
itemId: string;
|
|
827
|
+
/** False when the item was no longer present in the authoritative queue. */
|
|
828
|
+
removed: boolean;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
export interface GetDeviceStatusOptions {
|
|
832
|
+
/**
|
|
833
|
+
* Timeout in milliseconds for the authoritative sync and status replay.
|
|
834
|
+
* Defaults to the session's request timeout.
|
|
835
|
+
*/
|
|
836
|
+
timeoutMs?: number;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
/** A suggested permission grant attached to a pending approval. */
|
|
840
|
+
export interface SessionPermissionSuggestion {
|
|
841
|
+
id: string;
|
|
842
|
+
text: string;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
export interface SessionDiffHunkLine {
|
|
846
|
+
type: "context" | "add" | "remove";
|
|
847
|
+
content: string;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
export interface SessionDiffHunk {
|
|
851
|
+
oldStart: number;
|
|
852
|
+
oldLines: number;
|
|
853
|
+
newStart: number;
|
|
854
|
+
newLines: number;
|
|
855
|
+
lines: SessionDiffHunkLine[];
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
/** Portable projection of a file-edit diff preview. */
|
|
859
|
+
export type SessionDiffPreview =
|
|
860
|
+
| {
|
|
861
|
+
mode: "advanced";
|
|
862
|
+
fileName: string;
|
|
863
|
+
hunks: SessionDiffHunk[];
|
|
864
|
+
}
|
|
865
|
+
| {
|
|
866
|
+
mode: "fallback" | "unpreviewable";
|
|
867
|
+
fileName: string;
|
|
868
|
+
reason: string;
|
|
869
|
+
};
|
|
870
|
+
|
|
871
|
+
/** One tool approval the device is still waiting on. */
|
|
872
|
+
export interface SessionPendingControlRequest {
|
|
873
|
+
/**
|
|
874
|
+
* Control request id for correlation only. Approval decisions must still
|
|
875
|
+
* resolve through `recoverPendingApprovals()` and `canUseTool`.
|
|
876
|
+
*/
|
|
877
|
+
requestId: string;
|
|
878
|
+
/** Tool awaiting approval. */
|
|
879
|
+
toolName: string;
|
|
880
|
+
/** Tool call id awaiting approval, when reported. */
|
|
881
|
+
toolCallId?: string;
|
|
882
|
+
/** Tool input awaiting approval, when reported. */
|
|
883
|
+
toolInput?: Record<string, unknown>;
|
|
884
|
+
/** Permission grants offered by the runtime. */
|
|
885
|
+
permissionSuggestions: SessionPermissionSuggestion[];
|
|
886
|
+
/** Path that triggered the permission check, when reported. */
|
|
887
|
+
blockedPath: string | null;
|
|
888
|
+
/** File-edit previews supplied with the approval, when reported. */
|
|
889
|
+
diffs?: SessionDiffPreview[];
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
* Typed projection of the wire `update_device_status` payload.
|
|
894
|
+
*
|
|
895
|
+
* `raw` carries the full wire `device_status` object for fields that are not
|
|
896
|
+
* projected (git context, toolsets, background processes, ...).
|
|
897
|
+
*/
|
|
898
|
+
export interface SessionDeviceStatus {
|
|
899
|
+
/** Whether the executing device is connected. */
|
|
900
|
+
isOnline: boolean;
|
|
901
|
+
/** Whether the device is currently processing a turn. */
|
|
902
|
+
isProcessing: boolean;
|
|
903
|
+
/** Permission mode currently applied to this runtime scope. */
|
|
904
|
+
permissionMode: PermissionMode;
|
|
905
|
+
/** Working directory currently applied to this runtime scope. */
|
|
906
|
+
workingDirectory: string | null;
|
|
907
|
+
/** Approvals the device is still waiting on (foreground-resume UI). */
|
|
908
|
+
pendingControlRequests: SessionPendingControlRequest[];
|
|
909
|
+
/** Full wire `device_status` payload as an escape hatch. */
|
|
910
|
+
raw: Record<string, unknown>;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
/**
|
|
914
|
+
* Options for createAgent() - full control over agent creation.
|
|
915
|
+
*/
|
|
916
|
+
export interface CreateAgentOptions {
|
|
917
|
+
/**
|
|
918
|
+
* Letta Code personality preset. Defaults to "memo". The creation payload
|
|
919
|
+
* is built by `@letta-ai/letta-code/agent-presets`, matching Chat/Desktop.
|
|
920
|
+
*/
|
|
921
|
+
personality?: LettaCodePersonalityId;
|
|
922
|
+
|
|
923
|
+
/** Model to use (e.g., "claude-sonnet-4-20250514") */
|
|
924
|
+
model?: string;
|
|
925
|
+
|
|
926
|
+
/** Embedding model to use (e.g., "text-embedding-ada-002") */
|
|
927
|
+
embedding?: string;
|
|
928
|
+
|
|
929
|
+
/**
|
|
930
|
+
* System prompt configuration.
|
|
931
|
+
* - string: Use as the complete system prompt
|
|
932
|
+
* - SystemPromptPreset: Use a preset
|
|
933
|
+
* - { type: 'preset', preset, append? }: Use a preset with optional appended text
|
|
934
|
+
*/
|
|
935
|
+
systemPrompt?: string | SystemPromptPreset | SystemPromptPresetConfigSDK;
|
|
936
|
+
|
|
937
|
+
/**
|
|
938
|
+
* Memory block configuration. Each item can be:
|
|
939
|
+
* - string: Preset block name ("persona", "human", "skills", "loaded_skills")
|
|
940
|
+
* - CreateBlock: Custom block definition (e.g., { label: "project", value: "..." })
|
|
941
|
+
* - { blockId: string }: Reference to existing shared block
|
|
942
|
+
*/
|
|
943
|
+
memory?: MemoryItem[];
|
|
944
|
+
|
|
945
|
+
/** Convenience: Set persona block value directly */
|
|
946
|
+
persona?: string;
|
|
947
|
+
|
|
948
|
+
/** Convenience: Set human block value directly */
|
|
949
|
+
human?: string;
|
|
950
|
+
|
|
951
|
+
/**
|
|
952
|
+
* Whether to enable the git-backed memory filesystem on the new agent
|
|
953
|
+
* (default true). Pass false for worker-style agents that should not carry
|
|
954
|
+
* their own memory repo — enabling memfs is a slow backend round trip, and
|
|
955
|
+
* concurrent sessions on a shared-memfs agent contend on its git state.
|
|
956
|
+
*/
|
|
957
|
+
memfs?: boolean;
|
|
958
|
+
|
|
959
|
+
/** Display name for the agent. */
|
|
960
|
+
name?: string;
|
|
961
|
+
|
|
962
|
+
/** Description of the agent's purpose. */
|
|
963
|
+
description?: string;
|
|
964
|
+
|
|
965
|
+
/** Hide the agent from default listings (worker/subagent semantics). */
|
|
966
|
+
hidden?: boolean;
|
|
967
|
+
|
|
968
|
+
/**
|
|
969
|
+
* Server-side tools to attach at creation. When omitted, the harness
|
|
970
|
+
* applies its created-agent defaults (web_search, fetch_webpage). Pass []
|
|
971
|
+
* for none or an explicit list to override. Client-side tools (Bash,
|
|
972
|
+
* Edit, …) are provided by the harness at runtime and are unaffected.
|
|
973
|
+
*/
|
|
974
|
+
baseTools?: string[];
|
|
975
|
+
|
|
976
|
+
/**
|
|
977
|
+
* Exact client-side tool allowlist for the session, including custom SDK
|
|
978
|
+
* tools. When omitted, the harness default toolset and registered custom
|
|
979
|
+
* tools apply. Interactive user-input tools (AskUserQuestion) are always
|
|
980
|
+
* excluded for SDK sessions.
|
|
981
|
+
*/
|
|
982
|
+
allowedTools?: string[];
|
|
983
|
+
|
|
984
|
+
/** List of disallowed tool names */
|
|
985
|
+
disallowedTools?: string[];
|
|
986
|
+
|
|
987
|
+
/** Permission mode */
|
|
988
|
+
permissionMode?: PermissionMode;
|
|
989
|
+
|
|
990
|
+
/** Working directory for the CLI process */
|
|
991
|
+
cwd?: string;
|
|
992
|
+
|
|
993
|
+
/** Custom permission callback - called when tool needs approval */
|
|
994
|
+
canUseTool?: CanUseToolCallback;
|
|
995
|
+
|
|
996
|
+
/**
|
|
997
|
+
* Custom tools that execute locally in the SDK process.
|
|
998
|
+
* These tools are registered with the CLI and executed when the LLM calls them.
|
|
999
|
+
*/
|
|
1000
|
+
tools?: AnyAgentTool[];
|
|
1001
|
+
|
|
1002
|
+
/** Tags to organize and categorize the agent. */
|
|
1003
|
+
tags?: string[];
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* Restrict available skills by source.
|
|
1007
|
+
* Empty array disables all skills (`--no-skills`).
|
|
1008
|
+
*/
|
|
1009
|
+
skillSources?: SkillSource[];
|
|
1010
|
+
|
|
1011
|
+
/**
|
|
1012
|
+
* Toggle first-turn system info reminder (device/git/cwd context).
|
|
1013
|
+
* false -> `--no-system-info-reminder`.
|
|
1014
|
+
*/
|
|
1015
|
+
systemInfoReminder?: boolean;
|
|
1016
|
+
|
|
1017
|
+
/**
|
|
1018
|
+
* Configure dreaming settings.
|
|
1019
|
+
*/
|
|
1020
|
+
dreaming?: DreamingOptions;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
// ═══════════════════════════════════════════════════════════════
|
|
1024
|
+
// SDK MESSAGE TYPES
|
|
1025
|
+
// ═══════════════════════════════════════════════════════════════
|
|
1026
|
+
|
|
1027
|
+
/**
|
|
1028
|
+
* SDK message types - clean wrappers around wire types
|
|
1029
|
+
*/
|
|
1030
|
+
export interface SDKInitMessage {
|
|
1031
|
+
type: "init";
|
|
1032
|
+
agentId: string;
|
|
1033
|
+
sessionId: string;
|
|
1034
|
+
conversationId: string;
|
|
1035
|
+
model: string;
|
|
1036
|
+
/** Backend-reported tool names, when the transport exposes an authoritative list. */
|
|
1037
|
+
tools?: string[];
|
|
1038
|
+
memfsEnabled?: boolean;
|
|
1039
|
+
skillSources?: SkillSource[];
|
|
1040
|
+
systemInfoReminderEnabled?: boolean;
|
|
1041
|
+
dreaming?: EffectiveDreamingSettings;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
export interface SDKAssistantMessage {
|
|
1045
|
+
type: "assistant";
|
|
1046
|
+
content: string;
|
|
1047
|
+
uuid: string;
|
|
1048
|
+
/** Run ID from the Letta API for this event (used for stale-run detection). */
|
|
1049
|
+
runId?: string;
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
export interface SDKToolCallMessage {
|
|
1053
|
+
type: "tool_call";
|
|
1054
|
+
toolCallId: string;
|
|
1055
|
+
toolName: string;
|
|
1056
|
+
toolInput: Record<string, unknown>;
|
|
1057
|
+
/** Raw unparsed arguments string from the wire for consumer-side accumulation. */
|
|
1058
|
+
rawArguments?: string;
|
|
1059
|
+
uuid: string;
|
|
1060
|
+
/** Run ID from the Letta API for this event (used for stale-run detection). */
|
|
1061
|
+
runId?: string;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
export interface SDKToolResultMessage {
|
|
1065
|
+
type: "tool_result";
|
|
1066
|
+
toolCallId: string;
|
|
1067
|
+
content: string;
|
|
1068
|
+
isError: boolean;
|
|
1069
|
+
uuid: string;
|
|
1070
|
+
/** Run ID from the Letta API for this event (used for stale-run detection). */
|
|
1071
|
+
runId?: string;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
export interface SDKReasoningMessage {
|
|
1075
|
+
type: "reasoning";
|
|
1076
|
+
content: string;
|
|
1077
|
+
uuid: string;
|
|
1078
|
+
/** Run ID from the Letta API for this event (used for stale-run detection). */
|
|
1079
|
+
runId?: string;
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
/** Canonical SDK error codes recognized by the SDK. */
|
|
1083
|
+
export type SDKErrorCode =
|
|
1084
|
+
| "approval_conflict"
|
|
1085
|
+
| "approval_conflict_terminal"
|
|
1086
|
+
| "protocol_error"
|
|
1087
|
+
| "error"
|
|
1088
|
+
| "llm_api_error"
|
|
1089
|
+
| "max_steps"
|
|
1090
|
+
| "interrupted"
|
|
1091
|
+
| "stream_closed";
|
|
1092
|
+
|
|
1093
|
+
export interface SDKResultMessage {
|
|
1094
|
+
type: "result";
|
|
1095
|
+
success: boolean;
|
|
1096
|
+
result?: string;
|
|
1097
|
+
/** Legacy error string (kept for compatibility). Prefer errorCode. */
|
|
1098
|
+
error?: string;
|
|
1099
|
+
/** Canonical typed error code for machine handling. */
|
|
1100
|
+
errorCode?: SDKErrorCode;
|
|
1101
|
+
/** True when the failure corresponds to an approval conflict/deadlock. */
|
|
1102
|
+
approvalConflict?: boolean;
|
|
1103
|
+
/** Whether another recovery attempt could still succeed. */
|
|
1104
|
+
recoverable?: boolean;
|
|
1105
|
+
/** Number of SDK-managed recovery attempts executed for this turn. */
|
|
1106
|
+
recoveryAttempts?: number;
|
|
1107
|
+
/** Best-effort human-readable approval-conflict detail (if available). */
|
|
1108
|
+
errorDetail?: string;
|
|
1109
|
+
stopReason?: string;
|
|
1110
|
+
durationMs: number;
|
|
1111
|
+
totalCostUsd?: number;
|
|
1112
|
+
conversationId: string | null;
|
|
1113
|
+
/** Run IDs associated with this turn (if provided by the CLI). */
|
|
1114
|
+
runIds?: string[];
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
export interface SDKStreamEventDeltaPayload {
|
|
1118
|
+
type: string;
|
|
1119
|
+
index?: number;
|
|
1120
|
+
delta?: { type?: string; text?: string; reasoning?: string };
|
|
1121
|
+
content_block?: { type?: string; text?: string };
|
|
1122
|
+
[key: string]: unknown;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
export interface SDKStreamEventMessagePayload {
|
|
1126
|
+
message_type: string;
|
|
1127
|
+
id?: string;
|
|
1128
|
+
otid?: string | null;
|
|
1129
|
+
content?: unknown;
|
|
1130
|
+
reasoning?: string;
|
|
1131
|
+
name?: string;
|
|
1132
|
+
tool_call?: unknown;
|
|
1133
|
+
tool_calls?: unknown;
|
|
1134
|
+
tool_call_id?: string;
|
|
1135
|
+
tool_return?: string;
|
|
1136
|
+
status?: string;
|
|
1137
|
+
[key: string]: unknown;
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
export interface SDKUnknownStreamEventPayload {
|
|
1141
|
+
type?: string;
|
|
1142
|
+
message_type?: string;
|
|
1143
|
+
[key: string]: unknown;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
export type SDKStreamEventPayload =
|
|
1147
|
+
| SDKStreamEventDeltaPayload
|
|
1148
|
+
| SDKStreamEventMessagePayload
|
|
1149
|
+
| SDKUnknownStreamEventPayload;
|
|
1150
|
+
|
|
1151
|
+
export interface SDKStreamEventMessage {
|
|
1152
|
+
type: "stream_event";
|
|
1153
|
+
event: SDKStreamEventPayload;
|
|
1154
|
+
uuid: string;
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
/**
|
|
1158
|
+
* Error message from the CLI — carries the actual error detail that
|
|
1159
|
+
* would otherwise be lost (the subsequent `type=result` only has
|
|
1160
|
+
* the opaque string "error" as its error field).
|
|
1161
|
+
*/
|
|
1162
|
+
export interface SDKErrorMessage {
|
|
1163
|
+
type: "error";
|
|
1164
|
+
/** Human-readable error description from the CLI */
|
|
1165
|
+
message: string;
|
|
1166
|
+
/** Canonical typed error code for machine handling. */
|
|
1167
|
+
errorCode?: SDKErrorCode;
|
|
1168
|
+
/** True when the error detail indicates an approval conflict/deadlock. */
|
|
1169
|
+
approvalConflict?: boolean;
|
|
1170
|
+
/** Whether another recovery attempt could still succeed. */
|
|
1171
|
+
recoverable?: boolean;
|
|
1172
|
+
/** Parsed API error detail string when present. */
|
|
1173
|
+
errorDetail?: string;
|
|
1174
|
+
/** Why the run stopped (e.g. "error", "llm_api_error", "max_steps") */
|
|
1175
|
+
stopReason: string;
|
|
1176
|
+
/** Run that produced the error, if available */
|
|
1177
|
+
runId?: string;
|
|
1178
|
+
/** Nested Letta API error when the error originated server-side */
|
|
1179
|
+
apiError?: Record<string, unknown>;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
/**
|
|
1183
|
+
* Retry message — the CLI is retrying after a transient failure.
|
|
1184
|
+
* Emitted before each retry attempt so consumers can log / display progress.
|
|
1185
|
+
*/
|
|
1186
|
+
export interface SDKRetryMessage {
|
|
1187
|
+
type: "retry";
|
|
1188
|
+
/** The stop reason that triggered the retry */
|
|
1189
|
+
reason: string;
|
|
1190
|
+
/** Current attempt number (1-based) */
|
|
1191
|
+
attempt: number;
|
|
1192
|
+
/** Maximum attempts before giving up */
|
|
1193
|
+
maxAttempts: number;
|
|
1194
|
+
/** Delay in ms before the next attempt */
|
|
1195
|
+
delayMs: number;
|
|
1196
|
+
/** Run that triggered the retry, if available */
|
|
1197
|
+
runId?: string;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
export interface SDKQueueItem {
|
|
1201
|
+
id: string;
|
|
1202
|
+
clientMessageId: string;
|
|
1203
|
+
kind: string;
|
|
1204
|
+
source: string;
|
|
1205
|
+
content: unknown;
|
|
1206
|
+
enqueuedAt: string;
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
export interface SDKQueueUpdateMessage {
|
|
1210
|
+
type: "queue_update";
|
|
1211
|
+
queue: SDKQueueItem[];
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
export interface SDKLoopStatusMessage {
|
|
1215
|
+
type: "loop_status";
|
|
1216
|
+
status: string;
|
|
1217
|
+
activeRunIds: string[];
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
/** Union of all SDK message types */
|
|
1221
|
+
export type SDKMessage =
|
|
1222
|
+
| SDKInitMessage
|
|
1223
|
+
| SDKAssistantMessage
|
|
1224
|
+
| SDKToolCallMessage
|
|
1225
|
+
| SDKToolResultMessage
|
|
1226
|
+
| SDKReasoningMessage
|
|
1227
|
+
| SDKResultMessage
|
|
1228
|
+
| SDKStreamEventMessage
|
|
1229
|
+
| SDKErrorMessage
|
|
1230
|
+
| SDKRetryMessage
|
|
1231
|
+
| SDKQueueUpdateMessage
|
|
1232
|
+
| SDKLoopStatusMessage;
|
|
1233
|
+
|
|
1234
|
+
// ═══════════════════════════════════════════════════════════════
|
|
1235
|
+
// LIST MESSAGES API
|
|
1236
|
+
// ═══════════════════════════════════════════════════════════════
|
|
1237
|
+
|
|
1238
|
+
/**
|
|
1239
|
+
* Options for session.listMessages().
|
|
1240
|
+
*/
|
|
1241
|
+
export interface ListMessagesOptions {
|
|
1242
|
+
/** Explicit conversation ID (e.g. "conv-123"). If omitted, uses agent default. */
|
|
1243
|
+
conversationId?: string;
|
|
1244
|
+
/** Return messages before this message ID (cursor for older pages). */
|
|
1245
|
+
before?: string;
|
|
1246
|
+
/** Return messages after this message ID (cursor for newer pages). */
|
|
1247
|
+
after?: string;
|
|
1248
|
+
/** Sort order. Defaults to "desc" (newest first). */
|
|
1249
|
+
order?: "asc" | "desc";
|
|
1250
|
+
/** Max messages per page. Defaults to 50. */
|
|
1251
|
+
limit?: number;
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
/**
|
|
1255
|
+
* Result from session.listMessages().
|
|
1256
|
+
* `messages` are raw Letta API message objects in the requested order. Cursor
|
|
1257
|
+
* metadata is backend-supplied and omitted when the backend does not expose an
|
|
1258
|
+
* authoritative pagination answer.
|
|
1259
|
+
*/
|
|
1260
|
+
export interface ListMessagesResult {
|
|
1261
|
+
messages: unknown[];
|
|
1262
|
+
/** ID of the oldest message in this page; use as `before` for the next page when present. */
|
|
1263
|
+
nextBefore?: string | null;
|
|
1264
|
+
/** Whether more pages exist in the requested direction, when known. */
|
|
1265
|
+
hasMore?: boolean;
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
// ═══════════════════════════════════════════════════════════════
|
|
1269
|
+
// BOOTSTRAP SESSION STATE API
|
|
1270
|
+
// ═══════════════════════════════════════════════════════════════
|
|
1271
|
+
|
|
1272
|
+
/**
|
|
1273
|
+
* Options for session.bootstrapState().
|
|
1274
|
+
*/
|
|
1275
|
+
export interface BootstrapStateOptions {
|
|
1276
|
+
/** Max messages to include in the initial history page. Defaults to 50. */
|
|
1277
|
+
limit?: number;
|
|
1278
|
+
/** Sort order for initial history page. Defaults to "desc" (newest first). */
|
|
1279
|
+
order?: "asc" | "desc";
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
/**
|
|
1283
|
+
* Result from session.bootstrapState().
|
|
1284
|
+
*
|
|
1285
|
+
* Contains best-effort data needed to render the initial conversation view
|
|
1286
|
+
* without additional round-trips. Backend-derived booleans/cursors are omitted
|
|
1287
|
+
* when the remote/app-server backend does not expose an authoritative value.
|
|
1288
|
+
*/
|
|
1289
|
+
export interface BootstrapStateResult {
|
|
1290
|
+
/** Resolved agent ID for this session. */
|
|
1291
|
+
agentId: string;
|
|
1292
|
+
/** Resolved conversation ID for this session. */
|
|
1293
|
+
conversationId: string;
|
|
1294
|
+
/** LLM model handle. */
|
|
1295
|
+
model: string | undefined;
|
|
1296
|
+
/** Backend-reported tool names, when the transport exposes an authoritative list. */
|
|
1297
|
+
tools?: string[];
|
|
1298
|
+
/** Whether memfs (git-backed memory) is enabled, when known. */
|
|
1299
|
+
memfsEnabled?: boolean;
|
|
1300
|
+
/** Initial history page (same shape as listMessages.messages). */
|
|
1301
|
+
messages: unknown[];
|
|
1302
|
+
/** Cursor to fetch older messages. Null when the backend knows there are no more pages. */
|
|
1303
|
+
nextBefore?: string | null;
|
|
1304
|
+
/** Whether more history pages exist, when known. */
|
|
1305
|
+
hasMore?: boolean;
|
|
1306
|
+
/** Whether there is a pending approval waiting for a response, when known. */
|
|
1307
|
+
hasPendingApproval?: boolean;
|
|
1308
|
+
/** Wall-clock timing breakdown in milliseconds (if provided by CLI). */
|
|
1309
|
+
timings?: {
|
|
1310
|
+
resolve_ms: number;
|
|
1311
|
+
list_messages_ms: number;
|
|
1312
|
+
total_ms: number;
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
// ═══════════════════════════════════════════════════════════════
|
|
1317
|
+
// EXTERNAL TOOL PROTOCOL TYPES
|
|
1318
|
+
// ═══════════════════════════════════════════════════════════════
|
|
1319
|
+
|
|
1320
|
+
/**
|
|
1321
|
+
* Request to execute an external tool (CLI → SDK)
|
|
1322
|
+
*/
|
|
1323
|
+
export interface ExecuteExternalToolRequest {
|
|
1324
|
+
subtype: "execute_external_tool";
|
|
1325
|
+
tool_call_id: string;
|
|
1326
|
+
tool_name: string;
|
|
1327
|
+
input: Record<string, unknown>;
|
|
1328
|
+
}
|