@letta-ai/letta-agent-sdk 0.2.1
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/LICENSE +190 -0
- package/README.md +240 -0
- package/dist/app-server-session.d.ts +86 -0
- package/dist/app-server-session.d.ts.map +1 -0
- package/dist/cli-resolver.d.ts +9 -0
- package/dist/cli-resolver.d.ts.map +1 -0
- package/dist/client.d.ts +47 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/cloud-session.d.ts +45 -0
- package/dist/cloud-session.d.ts.map +1 -0
- package/dist/index.d.ts +167 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4994 -0
- package/dist/index.js.map +24 -0
- package/dist/interactiveToolPolicy.d.ts +4 -0
- package/dist/interactiveToolPolicy.d.ts.map +1 -0
- package/dist/local-app-server.d.ts +17 -0
- package/dist/local-app-server.d.ts.map +1 -0
- package/dist/protocol.d.ts +205 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/remote-client-session-core.d.ts +140 -0
- package/dist/remote-client-session-core.d.ts.map +1 -0
- package/dist/remote.d.ts +57 -0
- package/dist/remote.d.ts.map +1 -0
- package/dist/session.d.ts +142 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/stream-events.d.ts +15 -0
- package/dist/stream-events.d.ts.map +1 -0
- package/dist/tests/advanced-session.d.ts +10 -0
- package/dist/tests/advanced-session.d.ts.map +1 -0
- package/dist/tool-helpers.d.ts +47 -0
- package/dist/tool-helpers.d.ts.map +1 -0
- package/dist/transport.d.ts +53 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/types.d.ts +759 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/validation.d.ts +15 -0
- package/dist/validation.d.ts.map +1 -0
- package/package.json +45 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,759 @@
|
|
|
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
|
+
export type { WireMessage, SystemInitMessage, MessageWire, ResultMessage, ErrorMessage, StreamEvent, ControlRequest, ControlResponse, CanUseToolControlRequest, CanUseToolResponse, CanUseToolResponseAllow, CanUseToolResponseDeny, SystemPromptPresetConfig, CreateBlock, } from "./protocol.js";
|
|
8
|
+
import type { CreateBlock, CanUseToolResponse } from "./protocol.js";
|
|
9
|
+
export interface LettaCodeSocketLike {
|
|
10
|
+
readyState: number;
|
|
11
|
+
send(data: string): void;
|
|
12
|
+
close(): void;
|
|
13
|
+
addEventListener?(type: string, listener: (event: unknown) => void): void;
|
|
14
|
+
removeEventListener?(type: string, listener: (event: unknown) => void): void;
|
|
15
|
+
on?(type: string, listener: (event: unknown) => void): void;
|
|
16
|
+
off?(type: string, listener: (event: unknown) => void): void;
|
|
17
|
+
once?(type: string, listener: (event: unknown) => void): void;
|
|
18
|
+
}
|
|
19
|
+
export interface LettaCodeSocketOptions {
|
|
20
|
+
headers?: Record<string, string>;
|
|
21
|
+
}
|
|
22
|
+
export type LettaCodeSocketConstructor = new (url: string, options?: LettaCodeSocketOptions) => LettaCodeSocketLike;
|
|
23
|
+
/**
|
|
24
|
+
* Text content in a message
|
|
25
|
+
*/
|
|
26
|
+
export interface TextContent {
|
|
27
|
+
type: "text";
|
|
28
|
+
text: string;
|
|
29
|
+
}
|
|
30
|
+
export interface RunTurnOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Max automatic approval-conflict recovery attempts for this turn.
|
|
33
|
+
* Overrides session-level maxApprovalRecoveryAttempts when provided.
|
|
34
|
+
*/
|
|
35
|
+
maxApprovalRecoveryAttempts?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Timeout in milliseconds for each approval recovery request.
|
|
38
|
+
* Overrides session-level approvalRecoveryTimeoutMs when provided.
|
|
39
|
+
*/
|
|
40
|
+
recoveryTimeoutMs?: number;
|
|
41
|
+
}
|
|
42
|
+
export interface RecoverPendingApprovalsOptions {
|
|
43
|
+
/**
|
|
44
|
+
* Timeout in milliseconds for the recovery control request.
|
|
45
|
+
*/
|
|
46
|
+
timeoutMs?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface RecoverPendingApprovalsResult {
|
|
49
|
+
recovered: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Whether a pending approval is known to remain after recovery.
|
|
52
|
+
* Undefined means the SDK could not determine the state (for example, timeout).
|
|
53
|
+
*/
|
|
54
|
+
pendingApproval?: boolean;
|
|
55
|
+
unsupported: boolean;
|
|
56
|
+
detail?: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Image content in a message (base64 encoded)
|
|
60
|
+
*/
|
|
61
|
+
export interface ImageContent {
|
|
62
|
+
type: "image";
|
|
63
|
+
source: {
|
|
64
|
+
type: "base64";
|
|
65
|
+
media_type: "image/png" | "image/jpeg" | "image/gif" | "image/webp";
|
|
66
|
+
data: string;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A single content item (text or image)
|
|
71
|
+
*/
|
|
72
|
+
export type MessageContentItem = TextContent | ImageContent;
|
|
73
|
+
/**
|
|
74
|
+
* What send() accepts - either a simple string or multimodal content array
|
|
75
|
+
*/
|
|
76
|
+
export type SendMessage = string | MessageContentItem[];
|
|
77
|
+
export type SkillSource = "bundled" | "global" | "agent" | "project";
|
|
78
|
+
export type DreamingTrigger = "off" | "step-count" | "compaction-event";
|
|
79
|
+
export type DreamingBehavior = "reminder" | "auto-launch";
|
|
80
|
+
/**
|
|
81
|
+
* Dreaming settings exposed through SDK options.
|
|
82
|
+
* Any omitted fields preserve server/CLI defaults.
|
|
83
|
+
*/
|
|
84
|
+
export interface DreamingOptions {
|
|
85
|
+
trigger?: DreamingTrigger;
|
|
86
|
+
behavior?: DreamingBehavior;
|
|
87
|
+
stepCount?: number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Fully-resolved dreaming settings emitted by init messages.
|
|
91
|
+
*/
|
|
92
|
+
export interface EffectiveDreamingSettings {
|
|
93
|
+
trigger: DreamingTrigger;
|
|
94
|
+
behavior: DreamingBehavior;
|
|
95
|
+
stepCount: number;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Available system prompt presets.
|
|
99
|
+
*/
|
|
100
|
+
export type SystemPromptPreset = "default" | "letta-claude" | "letta-codex" | "letta-gemini" | "claude" | "codex" | "gemini";
|
|
101
|
+
/**
|
|
102
|
+
* System prompt preset configuration.
|
|
103
|
+
*/
|
|
104
|
+
export interface SystemPromptPresetConfigSDK {
|
|
105
|
+
type: "preset";
|
|
106
|
+
preset: SystemPromptPreset;
|
|
107
|
+
append?: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* System prompt configuration - either a raw string or preset config.
|
|
111
|
+
*/
|
|
112
|
+
export type SystemPromptConfig = string | SystemPromptPresetConfigSDK;
|
|
113
|
+
/**
|
|
114
|
+
* Reference to an existing shared block by ID.
|
|
115
|
+
*/
|
|
116
|
+
export interface BlockReference {
|
|
117
|
+
blockId: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Memory item - can be a preset name, custom block, or block reference.
|
|
121
|
+
*/
|
|
122
|
+
export type MemoryItem = string | CreateBlock | BlockReference;
|
|
123
|
+
/**
|
|
124
|
+
* Default memory block preset names.
|
|
125
|
+
*/
|
|
126
|
+
export type MemoryPreset = "persona" | "human" | "skills" | "loaded_skills";
|
|
127
|
+
/**
|
|
128
|
+
* Tool result content block
|
|
129
|
+
*/
|
|
130
|
+
export interface AgentToolResultContent {
|
|
131
|
+
type: "text" | "image";
|
|
132
|
+
text?: string;
|
|
133
|
+
data?: string;
|
|
134
|
+
mimeType?: string;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Tool result (matches pi-agent-core)
|
|
138
|
+
*/
|
|
139
|
+
export interface AgentToolResult<T> {
|
|
140
|
+
content: AgentToolResultContent[];
|
|
141
|
+
details?: T;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Tool update callback (for streaming tool progress)
|
|
145
|
+
*/
|
|
146
|
+
export type AgentToolUpdateCallback<T> = (update: Partial<AgentToolResult<T>>) => void;
|
|
147
|
+
/**
|
|
148
|
+
* Agent tool definition (matches pi-agent-core)
|
|
149
|
+
*/
|
|
150
|
+
export interface AgentTool<TParams, TResult> {
|
|
151
|
+
/** Display label */
|
|
152
|
+
label: string;
|
|
153
|
+
/** Tool name (used in API calls) */
|
|
154
|
+
name: string;
|
|
155
|
+
/** Description shown to the model */
|
|
156
|
+
description: string;
|
|
157
|
+
/** JSON Schema for parameters (TypeBox or plain object) */
|
|
158
|
+
parameters: TParams;
|
|
159
|
+
/** Execution function */
|
|
160
|
+
execute: (toolCallId: string, args: unknown, signal?: AbortSignal, onUpdate?: AgentToolUpdateCallback<TResult>) => Promise<AgentToolResult<TResult>>;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Convenience type for tools with any params
|
|
164
|
+
*/
|
|
165
|
+
export type AnyAgentTool = AgentTool<any, unknown>;
|
|
166
|
+
/**
|
|
167
|
+
* How the SDK reaches or runs the Letta Code harness.
|
|
168
|
+
*
|
|
169
|
+
* - local: spawn/manage a local Letta Code app-server over loopback websockets.
|
|
170
|
+
* - remote: connect to a user-managed app-server over websockets.
|
|
171
|
+
* - cloud: use agents hosted on Constellation, with an explicit remote
|
|
172
|
+
* environment or SDK-managed sandbox.
|
|
173
|
+
*/
|
|
174
|
+
export type LettaCodeBackend = "local" | "remote" | "cloud";
|
|
175
|
+
/**
|
|
176
|
+
* Stable execution target for remote/cloud runtimes.
|
|
177
|
+
*
|
|
178
|
+
* Strings are treated as human-readable environment names. Object forms allow
|
|
179
|
+
* callers to avoid relying on names as unique identifiers.
|
|
180
|
+
*/
|
|
181
|
+
export type LettaCodeEnvironment = string | {
|
|
182
|
+
name: string;
|
|
183
|
+
} | {
|
|
184
|
+
id: string;
|
|
185
|
+
} | {
|
|
186
|
+
connectionId: string;
|
|
187
|
+
} | {
|
|
188
|
+
deviceId: string;
|
|
189
|
+
};
|
|
190
|
+
export interface LettaCodeLocalAppServerOptions {
|
|
191
|
+
/**
|
|
192
|
+
* Optional URL for tests or advanced users with a pre-started local app-server.
|
|
193
|
+
* Omit to let the SDK spawn and own a loopback app-server.
|
|
194
|
+
*/
|
|
195
|
+
url?: string;
|
|
196
|
+
/** Optional WebSocket constructor for tests/non-standard runtimes. */
|
|
197
|
+
WebSocket?: LettaCodeSocketConstructor;
|
|
198
|
+
/** Timeout for websocket protocol request/turn correlation. */
|
|
199
|
+
requestTimeoutMs?: number;
|
|
200
|
+
/** Local app-server listen URL when the SDK spawns it. Defaults to ws://127.0.0.1:0. */
|
|
201
|
+
listen?: string;
|
|
202
|
+
/** Timeout waiting for the spawned app-server to print its listening URL. */
|
|
203
|
+
startupTimeoutMs?: number;
|
|
204
|
+
}
|
|
205
|
+
export interface LettaCodeLocalClientOptions {
|
|
206
|
+
backend?: "local";
|
|
207
|
+
/** Advanced local transport override. Defaults to app-server. */
|
|
208
|
+
transport?: "app-server" | "stdio";
|
|
209
|
+
/** Advanced app-server overrides for local transport. */
|
|
210
|
+
appServer?: LettaCodeLocalAppServerOptions;
|
|
211
|
+
}
|
|
212
|
+
export interface LettaCodeRemoteClientOptions {
|
|
213
|
+
backend: "remote";
|
|
214
|
+
/** URL of the user-managed app-server / websocket endpoint. */
|
|
215
|
+
url: string;
|
|
216
|
+
/** Optional capability token sent as Authorization: Bearer <token> during websocket upgrade. */
|
|
217
|
+
authToken?: string;
|
|
218
|
+
/** Optional WebSocket constructor for non-browser runtimes and tests. */
|
|
219
|
+
WebSocket?: LettaCodeSocketConstructor;
|
|
220
|
+
/** Timeout for websocket protocol request/turn correlation. */
|
|
221
|
+
requestTimeoutMs?: number;
|
|
222
|
+
}
|
|
223
|
+
export interface LettaCodeCloudSandboxOptions {
|
|
224
|
+
/**
|
|
225
|
+
* TTL to request when refreshing an SDK-managed sandbox. Defaults to 5
|
|
226
|
+
* minutes, matching the Cloud API default. Valid range: 1-60.
|
|
227
|
+
*/
|
|
228
|
+
ttlMinutes?: number;
|
|
229
|
+
/** Timeout waiting for a newly created sandbox environment to come online. */
|
|
230
|
+
readyTimeoutMs?: number;
|
|
231
|
+
/** Poll interval while waiting for a newly created sandbox environment. */
|
|
232
|
+
readyPollIntervalMs?: number;
|
|
233
|
+
/** Interval for proactive TTL refreshes while the session is open. */
|
|
234
|
+
refreshIntervalMs?: number;
|
|
235
|
+
/**
|
|
236
|
+
* Best-effort terminate the SDK-managed sandbox on session close. Defaults to
|
|
237
|
+
* true. Set false when multiple SDK sessions may race on the same agent.
|
|
238
|
+
*/
|
|
239
|
+
terminateOnClose?: boolean;
|
|
240
|
+
}
|
|
241
|
+
export interface LettaCodeCloudClientOptions {
|
|
242
|
+
backend: "cloud";
|
|
243
|
+
/** Optional API key override. Defaults to LETTA_API_KEY / existing auth. */
|
|
244
|
+
apiKey?: string;
|
|
245
|
+
/** Optional API base URL override. Defaults to the Letta API. */
|
|
246
|
+
apiBaseUrl?: string;
|
|
247
|
+
/** Optional extra HTTP headers for Cloud API requests. */
|
|
248
|
+
headers?: Record<string, string>;
|
|
249
|
+
/** Optional fetch implementation for tests/non-standard runtimes. */
|
|
250
|
+
fetch?: typeof fetch;
|
|
251
|
+
/** Optional WebSocket constructor for non-browser runtimes and tests. */
|
|
252
|
+
WebSocket?: LettaCodeSocketConstructor;
|
|
253
|
+
/** Timeout for websocket protocol request/turn correlation. */
|
|
254
|
+
requestTimeoutMs?: number;
|
|
255
|
+
/**
|
|
256
|
+
* WebSocket authentication style. Defaults to Authorization headers; set to
|
|
257
|
+
* query for browser-style clients that cannot send WebSocket headers.
|
|
258
|
+
*/
|
|
259
|
+
webSocketAuth?: "header" | "query";
|
|
260
|
+
/** Heartbeat interval for the Cloud status websocket. Defaults to 30s. */
|
|
261
|
+
pingIntervalMs?: number;
|
|
262
|
+
/**
|
|
263
|
+
* Advanced local app-server overrides used by cloud createAgent().
|
|
264
|
+
* Omit to let the SDK spawn a bundled local app-server authenticated to Cloud.
|
|
265
|
+
*/
|
|
266
|
+
appServer?: LettaCodeLocalAppServerOptions;
|
|
267
|
+
/**
|
|
268
|
+
* Execution target for Constellation sessions. If omitted, the SDK creates
|
|
269
|
+
* and owns a sandbox for the session.
|
|
270
|
+
*/
|
|
271
|
+
environment?: LettaCodeEnvironment;
|
|
272
|
+
/** Options for SDK-managed sandboxes when environment is omitted. */
|
|
273
|
+
sandbox?: LettaCodeCloudSandboxOptions;
|
|
274
|
+
}
|
|
275
|
+
export type LettaCodeClientOptions = LettaCodeLocalClientOptions | LettaCodeRemoteClientOptions | LettaCodeCloudClientOptions;
|
|
276
|
+
/**
|
|
277
|
+
* Callback for custom permission handling.
|
|
278
|
+
*/
|
|
279
|
+
export type CanUseToolCallback = (toolName: string, toolInput: Record<string, unknown>) => Promise<CanUseToolResponse> | CanUseToolResponse;
|
|
280
|
+
/**
|
|
281
|
+
* Internal session options used by Session/Transport classes.
|
|
282
|
+
* Not user-facing - use CreateSessionOptions or CreateAgentOptions instead.
|
|
283
|
+
* @internal
|
|
284
|
+
*/
|
|
285
|
+
export interface InternalSessionOptions {
|
|
286
|
+
agentId?: string;
|
|
287
|
+
conversationId?: string;
|
|
288
|
+
newConversation?: boolean;
|
|
289
|
+
defaultConversation?: boolean;
|
|
290
|
+
createOnly?: boolean;
|
|
291
|
+
model?: string;
|
|
292
|
+
reasoningEffort?: ReasoningEffort;
|
|
293
|
+
embedding?: string;
|
|
294
|
+
systemPrompt?: SystemPromptConfig;
|
|
295
|
+
memory?: MemoryItem[];
|
|
296
|
+
persona?: string;
|
|
297
|
+
human?: string;
|
|
298
|
+
tags?: string[];
|
|
299
|
+
skillSources?: SkillSource[];
|
|
300
|
+
systemInfoReminder?: boolean;
|
|
301
|
+
dreaming?: DreamingOptions;
|
|
302
|
+
allowedTools?: string[];
|
|
303
|
+
disallowedTools?: string[];
|
|
304
|
+
permissionMode?: PermissionMode;
|
|
305
|
+
canUseTool?: CanUseToolCallback;
|
|
306
|
+
tools?: AnyAgentTool[];
|
|
307
|
+
cwd?: string;
|
|
308
|
+
/** If true, pass --include-partial-messages to CLI for token-level stream_event chunks */
|
|
309
|
+
includePartialMessages?: boolean;
|
|
310
|
+
/**
|
|
311
|
+
* Max automatic approval-conflict recovery attempts per runTurn() call.
|
|
312
|
+
* Set to 0 to disable automatic recovery.
|
|
313
|
+
*/
|
|
314
|
+
maxApprovalRecoveryAttempts?: number;
|
|
315
|
+
/**
|
|
316
|
+
* Timeout in milliseconds for a single approval recovery request.
|
|
317
|
+
*/
|
|
318
|
+
approvalRecoveryTimeoutMs?: number;
|
|
319
|
+
}
|
|
320
|
+
export type PermissionMode = "default" | "acceptEdits" | "plan" | "bypassPermissions";
|
|
321
|
+
export type ReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
322
|
+
export interface LettaCodeModelEntry {
|
|
323
|
+
id: string;
|
|
324
|
+
handle: string;
|
|
325
|
+
label: string;
|
|
326
|
+
description: string;
|
|
327
|
+
isDefault?: boolean;
|
|
328
|
+
isFeatured?: boolean;
|
|
329
|
+
free?: boolean;
|
|
330
|
+
updateArgs?: Record<string, unknown>;
|
|
331
|
+
}
|
|
332
|
+
export interface ListModelsResult {
|
|
333
|
+
entries: LettaCodeModelEntry[];
|
|
334
|
+
/** Handles available to this user. null means availability lookup failed. */
|
|
335
|
+
availableHandles?: string[] | null;
|
|
336
|
+
/** BYOK provider name -> base provider name, e.g. lc-anthropic -> anthropic. */
|
|
337
|
+
byokProviderAliases?: Record<string, string>;
|
|
338
|
+
}
|
|
339
|
+
export interface UpdateModelOptions {
|
|
340
|
+
/** Model id from listModels() or direct model handle. Model ids usually omit '/'. */
|
|
341
|
+
model?: string;
|
|
342
|
+
/** Explicit model id from listModels(). */
|
|
343
|
+
modelId?: string;
|
|
344
|
+
/** Explicit direct model handle, including BYOK handles. */
|
|
345
|
+
modelHandle?: string;
|
|
346
|
+
/** Select a reasoning tier for the target model handle. */
|
|
347
|
+
reasoningEffort?: ReasoningEffort;
|
|
348
|
+
}
|
|
349
|
+
export interface UpdateModelResult {
|
|
350
|
+
appliedTo?: "agent" | "conversation";
|
|
351
|
+
modelId?: string;
|
|
352
|
+
modelHandle?: string;
|
|
353
|
+
modelSettings?: Record<string, unknown> | null;
|
|
354
|
+
}
|
|
355
|
+
export type SDKProtocolMessage<TType extends string = string> = Record<string, unknown> & {
|
|
356
|
+
type: TType;
|
|
357
|
+
request_id?: string;
|
|
358
|
+
};
|
|
359
|
+
export type SDKProtocolCommand<TType extends string = string> = SDKProtocolMessage<TType>;
|
|
360
|
+
export interface SendCommandOptions<TResponseType extends string = string> {
|
|
361
|
+
/** Wait for a response with this protocol message type. Omit for fire-and-forget commands. */
|
|
362
|
+
responseType?: TResponseType;
|
|
363
|
+
/** Override the websocket protocol request timeout for this command. */
|
|
364
|
+
timeoutMs?: number;
|
|
365
|
+
/** Optional custom matcher for advanced protocol responses. */
|
|
366
|
+
predicate?: (message: SDKProtocolMessage) => boolean;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Options for createSession() and resumeSession() - restricted to options that can be applied to existing agents (LRU/Memo).
|
|
370
|
+
* For creating new agents with custom memory/persona, use createAgent().
|
|
371
|
+
*/
|
|
372
|
+
export interface CreateSessionOptions {
|
|
373
|
+
/** Model to use (e.g., "claude-sonnet-4-20250514") - updates the agent's LLM config */
|
|
374
|
+
model?: string;
|
|
375
|
+
/** Reasoning effort tier to use with the selected/current model on websocket protocol sessions. */
|
|
376
|
+
reasoningEffort?: ReasoningEffort;
|
|
377
|
+
/** System prompt preset (only presets, no custom strings or append) - updates the agent */
|
|
378
|
+
systemPrompt?: SystemPromptPreset;
|
|
379
|
+
/** List of allowed tool names */
|
|
380
|
+
allowedTools?: string[];
|
|
381
|
+
/** List of disallowed tool names */
|
|
382
|
+
disallowedTools?: string[];
|
|
383
|
+
/** Permission mode */
|
|
384
|
+
permissionMode?: PermissionMode;
|
|
385
|
+
/** Working directory for the CLI process */
|
|
386
|
+
cwd?: string;
|
|
387
|
+
/**
|
|
388
|
+
* Restrict available skills by source.
|
|
389
|
+
* Empty array disables all skills (`--no-skills`).
|
|
390
|
+
*/
|
|
391
|
+
skillSources?: SkillSource[];
|
|
392
|
+
/**
|
|
393
|
+
* Toggle first-turn system info reminder (device/git/cwd context).
|
|
394
|
+
* false -> `--no-system-info-reminder`.
|
|
395
|
+
*/
|
|
396
|
+
systemInfoReminder?: boolean;
|
|
397
|
+
/**
|
|
398
|
+
* Configure dreaming settings.
|
|
399
|
+
*/
|
|
400
|
+
dreaming?: DreamingOptions;
|
|
401
|
+
/** Custom permission callback - called when tool needs approval */
|
|
402
|
+
canUseTool?: CanUseToolCallback;
|
|
403
|
+
/**
|
|
404
|
+
* Custom tools that execute locally in the SDK process.
|
|
405
|
+
* These tools are registered with the CLI and executed when the LLM calls them.
|
|
406
|
+
*/
|
|
407
|
+
tools?: AnyAgentTool[];
|
|
408
|
+
/**
|
|
409
|
+
* If true, pass --include-partial-messages to CLI to receive token-level
|
|
410
|
+
* stream_event chunks for incremental assistant/reasoning rendering.
|
|
411
|
+
*/
|
|
412
|
+
includePartialMessages?: boolean;
|
|
413
|
+
/**
|
|
414
|
+
* Max automatic approval-conflict recovery attempts per runTurn() call.
|
|
415
|
+
* Set to 0 to disable automatic recovery.
|
|
416
|
+
*/
|
|
417
|
+
maxApprovalRecoveryAttempts?: number;
|
|
418
|
+
/**
|
|
419
|
+
* Timeout in milliseconds for a single approval recovery request.
|
|
420
|
+
*/
|
|
421
|
+
approvalRecoveryTimeoutMs?: number;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Session options accepted by LettaCodeClient methods.
|
|
425
|
+
*
|
|
426
|
+
* `environment` is a cloud execution-target override. It is deliberately
|
|
427
|
+
* session-scoped rather than part of createAgent() options.
|
|
428
|
+
*/
|
|
429
|
+
export interface LettaCodeClientSessionOptions extends CreateSessionOptions {
|
|
430
|
+
environment?: LettaCodeEnvironment;
|
|
431
|
+
/** Per-session SDK-managed sandbox options when environment is omitted. */
|
|
432
|
+
sandbox?: LettaCodeCloudSandboxOptions;
|
|
433
|
+
}
|
|
434
|
+
export interface LettaCodeSession extends AsyncDisposable {
|
|
435
|
+
send(message: SendMessage): Promise<void>;
|
|
436
|
+
stream(): AsyncGenerator<SDKMessage>;
|
|
437
|
+
abort(): Promise<void>;
|
|
438
|
+
sendCommand(command: SDKProtocolCommand): Promise<void>;
|
|
439
|
+
sendCommand<TResponse extends SDKProtocolMessage = SDKProtocolMessage>(command: SDKProtocolCommand, options: SendCommandOptions): Promise<TResponse>;
|
|
440
|
+
listMessages(options?: ListMessagesOptions): Promise<ListMessagesResult>;
|
|
441
|
+
listModels(): Promise<ListModelsResult>;
|
|
442
|
+
updateModel(update: string | UpdateModelOptions): Promise<UpdateModelResult>;
|
|
443
|
+
close(): void;
|
|
444
|
+
readonly agentId: string | null;
|
|
445
|
+
readonly sessionId: string | null;
|
|
446
|
+
readonly conversationId: string | null;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Options for createAgent() - full control over agent creation.
|
|
450
|
+
*/
|
|
451
|
+
export interface CreateAgentOptions {
|
|
452
|
+
/** Model to use (e.g., "claude-sonnet-4-20250514") */
|
|
453
|
+
model?: string;
|
|
454
|
+
/** Embedding model to use (e.g., "text-embedding-ada-002") */
|
|
455
|
+
embedding?: string;
|
|
456
|
+
/**
|
|
457
|
+
* System prompt configuration.
|
|
458
|
+
* - string: Use as the complete system prompt
|
|
459
|
+
* - SystemPromptPreset: Use a preset
|
|
460
|
+
* - { type: 'preset', preset, append? }: Use a preset with optional appended text
|
|
461
|
+
*/
|
|
462
|
+
systemPrompt?: string | SystemPromptPreset | SystemPromptPresetConfigSDK;
|
|
463
|
+
/**
|
|
464
|
+
* Memory block configuration. Each item can be:
|
|
465
|
+
* - string: Preset block name ("persona", "human", "skills", "loaded_skills")
|
|
466
|
+
* - CreateBlock: Custom block definition (e.g., { label: "project", value: "..." })
|
|
467
|
+
* - { blockId: string }: Reference to existing shared block
|
|
468
|
+
*/
|
|
469
|
+
memory?: MemoryItem[];
|
|
470
|
+
/** Convenience: Set persona block value directly */
|
|
471
|
+
persona?: string;
|
|
472
|
+
/** Convenience: Set human block value directly */
|
|
473
|
+
human?: string;
|
|
474
|
+
/** List of allowed tool names */
|
|
475
|
+
allowedTools?: string[];
|
|
476
|
+
/** List of disallowed tool names */
|
|
477
|
+
disallowedTools?: string[];
|
|
478
|
+
/** Permission mode */
|
|
479
|
+
permissionMode?: PermissionMode;
|
|
480
|
+
/** Working directory for the CLI process */
|
|
481
|
+
cwd?: string;
|
|
482
|
+
/** Custom permission callback - called when tool needs approval */
|
|
483
|
+
canUseTool?: CanUseToolCallback;
|
|
484
|
+
/**
|
|
485
|
+
* Custom tools that execute locally in the SDK process.
|
|
486
|
+
* These tools are registered with the CLI and executed when the LLM calls them.
|
|
487
|
+
*/
|
|
488
|
+
tools?: AnyAgentTool[];
|
|
489
|
+
/** Tags to organize and categorize the agent. */
|
|
490
|
+
tags?: string[];
|
|
491
|
+
/**
|
|
492
|
+
* Restrict available skills by source.
|
|
493
|
+
* Empty array disables all skills (`--no-skills`).
|
|
494
|
+
*/
|
|
495
|
+
skillSources?: SkillSource[];
|
|
496
|
+
/**
|
|
497
|
+
* Toggle first-turn system info reminder (device/git/cwd context).
|
|
498
|
+
* false -> `--no-system-info-reminder`.
|
|
499
|
+
*/
|
|
500
|
+
systemInfoReminder?: boolean;
|
|
501
|
+
/**
|
|
502
|
+
* Configure dreaming settings.
|
|
503
|
+
*/
|
|
504
|
+
dreaming?: DreamingOptions;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* SDK message types - clean wrappers around wire types
|
|
508
|
+
*/
|
|
509
|
+
export interface SDKInitMessage {
|
|
510
|
+
type: "init";
|
|
511
|
+
agentId: string;
|
|
512
|
+
sessionId: string;
|
|
513
|
+
conversationId: string;
|
|
514
|
+
model: string;
|
|
515
|
+
/** Backend-reported tool names, when the transport exposes an authoritative list. */
|
|
516
|
+
tools?: string[];
|
|
517
|
+
memfsEnabled?: boolean;
|
|
518
|
+
skillSources?: SkillSource[];
|
|
519
|
+
systemInfoReminderEnabled?: boolean;
|
|
520
|
+
dreaming?: EffectiveDreamingSettings;
|
|
521
|
+
}
|
|
522
|
+
export interface SDKAssistantMessage {
|
|
523
|
+
type: "assistant";
|
|
524
|
+
content: string;
|
|
525
|
+
uuid: string;
|
|
526
|
+
/** Run ID from the Letta API for this event (used for stale-run detection). */
|
|
527
|
+
runId?: string;
|
|
528
|
+
}
|
|
529
|
+
export interface SDKToolCallMessage {
|
|
530
|
+
type: "tool_call";
|
|
531
|
+
toolCallId: string;
|
|
532
|
+
toolName: string;
|
|
533
|
+
toolInput: Record<string, unknown>;
|
|
534
|
+
/** Raw unparsed arguments string from the wire for consumer-side accumulation. */
|
|
535
|
+
rawArguments?: string;
|
|
536
|
+
uuid: string;
|
|
537
|
+
/** Run ID from the Letta API for this event (used for stale-run detection). */
|
|
538
|
+
runId?: string;
|
|
539
|
+
}
|
|
540
|
+
export interface SDKToolResultMessage {
|
|
541
|
+
type: "tool_result";
|
|
542
|
+
toolCallId: string;
|
|
543
|
+
content: string;
|
|
544
|
+
isError: boolean;
|
|
545
|
+
uuid: string;
|
|
546
|
+
/** Run ID from the Letta API for this event (used for stale-run detection). */
|
|
547
|
+
runId?: string;
|
|
548
|
+
}
|
|
549
|
+
export interface SDKReasoningMessage {
|
|
550
|
+
type: "reasoning";
|
|
551
|
+
content: string;
|
|
552
|
+
uuid: string;
|
|
553
|
+
/** Run ID from the Letta API for this event (used for stale-run detection). */
|
|
554
|
+
runId?: string;
|
|
555
|
+
}
|
|
556
|
+
/** Canonical SDK error codes recognized by the SDK. */
|
|
557
|
+
export type SDKErrorCode = "approval_conflict" | "approval_conflict_terminal" | "protocol_error" | "error" | "llm_api_error" | "max_steps" | "interrupted" | "stream_closed";
|
|
558
|
+
export interface SDKResultMessage {
|
|
559
|
+
type: "result";
|
|
560
|
+
success: boolean;
|
|
561
|
+
result?: string;
|
|
562
|
+
/** Legacy error string (kept for compatibility). Prefer errorCode. */
|
|
563
|
+
error?: string;
|
|
564
|
+
/** Canonical typed error code for machine handling. */
|
|
565
|
+
errorCode?: SDKErrorCode;
|
|
566
|
+
/** True when the failure corresponds to an approval conflict/deadlock. */
|
|
567
|
+
approvalConflict?: boolean;
|
|
568
|
+
/** Whether another recovery attempt could still succeed. */
|
|
569
|
+
recoverable?: boolean;
|
|
570
|
+
/** Number of SDK-managed recovery attempts executed for this turn. */
|
|
571
|
+
recoveryAttempts?: number;
|
|
572
|
+
/** Best-effort human-readable approval-conflict detail (if available). */
|
|
573
|
+
errorDetail?: string;
|
|
574
|
+
stopReason?: string;
|
|
575
|
+
durationMs: number;
|
|
576
|
+
totalCostUsd?: number;
|
|
577
|
+
conversationId: string | null;
|
|
578
|
+
/** Run IDs associated with this turn (if provided by the CLI). */
|
|
579
|
+
runIds?: string[];
|
|
580
|
+
}
|
|
581
|
+
export interface SDKStreamEventDeltaPayload {
|
|
582
|
+
type: string;
|
|
583
|
+
index?: number;
|
|
584
|
+
delta?: {
|
|
585
|
+
type?: string;
|
|
586
|
+
text?: string;
|
|
587
|
+
reasoning?: string;
|
|
588
|
+
};
|
|
589
|
+
content_block?: {
|
|
590
|
+
type?: string;
|
|
591
|
+
text?: string;
|
|
592
|
+
};
|
|
593
|
+
[key: string]: unknown;
|
|
594
|
+
}
|
|
595
|
+
export interface SDKStreamEventMessagePayload {
|
|
596
|
+
message_type: string;
|
|
597
|
+
id?: string;
|
|
598
|
+
otid?: string | null;
|
|
599
|
+
content?: unknown;
|
|
600
|
+
reasoning?: string;
|
|
601
|
+
name?: string;
|
|
602
|
+
tool_call?: unknown;
|
|
603
|
+
tool_calls?: unknown;
|
|
604
|
+
tool_call_id?: string;
|
|
605
|
+
tool_return?: string;
|
|
606
|
+
status?: string;
|
|
607
|
+
[key: string]: unknown;
|
|
608
|
+
}
|
|
609
|
+
export interface SDKUnknownStreamEventPayload {
|
|
610
|
+
type?: string;
|
|
611
|
+
message_type?: string;
|
|
612
|
+
[key: string]: unknown;
|
|
613
|
+
}
|
|
614
|
+
export type SDKStreamEventPayload = SDKStreamEventDeltaPayload | SDKStreamEventMessagePayload | SDKUnknownStreamEventPayload;
|
|
615
|
+
export interface SDKStreamEventMessage {
|
|
616
|
+
type: "stream_event";
|
|
617
|
+
event: SDKStreamEventPayload;
|
|
618
|
+
uuid: string;
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Error message from the CLI — carries the actual error detail that
|
|
622
|
+
* would otherwise be lost (the subsequent `type=result` only has
|
|
623
|
+
* the opaque string "error" as its error field).
|
|
624
|
+
*/
|
|
625
|
+
export interface SDKErrorMessage {
|
|
626
|
+
type: "error";
|
|
627
|
+
/** Human-readable error description from the CLI */
|
|
628
|
+
message: string;
|
|
629
|
+
/** Canonical typed error code for machine handling. */
|
|
630
|
+
errorCode?: SDKErrorCode;
|
|
631
|
+
/** True when the error detail indicates an approval conflict/deadlock. */
|
|
632
|
+
approvalConflict?: boolean;
|
|
633
|
+
/** Whether another recovery attempt could still succeed. */
|
|
634
|
+
recoverable?: boolean;
|
|
635
|
+
/** Parsed API error detail string when present. */
|
|
636
|
+
errorDetail?: string;
|
|
637
|
+
/** Why the run stopped (e.g. "error", "llm_api_error", "max_steps") */
|
|
638
|
+
stopReason: string;
|
|
639
|
+
/** Run that produced the error, if available */
|
|
640
|
+
runId?: string;
|
|
641
|
+
/** Nested Letta API error when the error originated server-side */
|
|
642
|
+
apiError?: Record<string, unknown>;
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Retry message — the CLI is retrying after a transient failure.
|
|
646
|
+
* Emitted before each retry attempt so consumers can log / display progress.
|
|
647
|
+
*/
|
|
648
|
+
export interface SDKRetryMessage {
|
|
649
|
+
type: "retry";
|
|
650
|
+
/** The stop reason that triggered the retry */
|
|
651
|
+
reason: string;
|
|
652
|
+
/** Current attempt number (1-based) */
|
|
653
|
+
attempt: number;
|
|
654
|
+
/** Maximum attempts before giving up */
|
|
655
|
+
maxAttempts: number;
|
|
656
|
+
/** Delay in ms before the next attempt */
|
|
657
|
+
delayMs: number;
|
|
658
|
+
/** Run that triggered the retry, if available */
|
|
659
|
+
runId?: string;
|
|
660
|
+
}
|
|
661
|
+
export interface SDKQueueItem {
|
|
662
|
+
id: string;
|
|
663
|
+
clientMessageId: string;
|
|
664
|
+
kind: string;
|
|
665
|
+
source: string;
|
|
666
|
+
content: unknown;
|
|
667
|
+
enqueuedAt: string;
|
|
668
|
+
}
|
|
669
|
+
export interface SDKQueueUpdateMessage {
|
|
670
|
+
type: "queue_update";
|
|
671
|
+
queue: SDKQueueItem[];
|
|
672
|
+
}
|
|
673
|
+
export interface SDKLoopStatusMessage {
|
|
674
|
+
type: "loop_status";
|
|
675
|
+
status: string;
|
|
676
|
+
activeRunIds: string[];
|
|
677
|
+
}
|
|
678
|
+
/** Union of all SDK message types */
|
|
679
|
+
export type SDKMessage = SDKInitMessage | SDKAssistantMessage | SDKToolCallMessage | SDKToolResultMessage | SDKReasoningMessage | SDKResultMessage | SDKStreamEventMessage | SDKErrorMessage | SDKRetryMessage | SDKQueueUpdateMessage | SDKLoopStatusMessage;
|
|
680
|
+
/**
|
|
681
|
+
* Options for session.listMessages().
|
|
682
|
+
*/
|
|
683
|
+
export interface ListMessagesOptions {
|
|
684
|
+
/** Explicit conversation ID (e.g. "conv-123"). If omitted, uses agent default. */
|
|
685
|
+
conversationId?: string;
|
|
686
|
+
/** Return messages before this message ID (cursor for older pages). */
|
|
687
|
+
before?: string;
|
|
688
|
+
/** Return messages after this message ID (cursor for newer pages). */
|
|
689
|
+
after?: string;
|
|
690
|
+
/** Sort order. Defaults to "desc" (newest first). */
|
|
691
|
+
order?: "asc" | "desc";
|
|
692
|
+
/** Max messages per page. Defaults to 50. */
|
|
693
|
+
limit?: number;
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Result from session.listMessages().
|
|
697
|
+
* `messages` are raw Letta API message objects in the requested order. Cursor
|
|
698
|
+
* metadata is backend-supplied and omitted when the backend does not expose an
|
|
699
|
+
* authoritative pagination answer.
|
|
700
|
+
*/
|
|
701
|
+
export interface ListMessagesResult {
|
|
702
|
+
messages: unknown[];
|
|
703
|
+
/** ID of the oldest message in this page; use as `before` for the next page when present. */
|
|
704
|
+
nextBefore?: string | null;
|
|
705
|
+
/** Whether more pages exist in the requested direction, when known. */
|
|
706
|
+
hasMore?: boolean;
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* Options for session.bootstrapState().
|
|
710
|
+
*/
|
|
711
|
+
export interface BootstrapStateOptions {
|
|
712
|
+
/** Max messages to include in the initial history page. Defaults to 50. */
|
|
713
|
+
limit?: number;
|
|
714
|
+
/** Sort order for initial history page. Defaults to "desc" (newest first). */
|
|
715
|
+
order?: "asc" | "desc";
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Result from session.bootstrapState().
|
|
719
|
+
*
|
|
720
|
+
* Contains best-effort data needed to render the initial conversation view
|
|
721
|
+
* without additional round-trips. Backend-derived booleans/cursors are omitted
|
|
722
|
+
* when the remote/app-server backend does not expose an authoritative value.
|
|
723
|
+
*/
|
|
724
|
+
export interface BootstrapStateResult {
|
|
725
|
+
/** Resolved agent ID for this session. */
|
|
726
|
+
agentId: string;
|
|
727
|
+
/** Resolved conversation ID for this session. */
|
|
728
|
+
conversationId: string;
|
|
729
|
+
/** LLM model handle. */
|
|
730
|
+
model: string | undefined;
|
|
731
|
+
/** Backend-reported tool names, when the transport exposes an authoritative list. */
|
|
732
|
+
tools?: string[];
|
|
733
|
+
/** Whether memfs (git-backed memory) is enabled, when known. */
|
|
734
|
+
memfsEnabled?: boolean;
|
|
735
|
+
/** Initial history page (same shape as listMessages.messages). */
|
|
736
|
+
messages: unknown[];
|
|
737
|
+
/** Cursor to fetch older messages. Null when the backend knows there are no more pages. */
|
|
738
|
+
nextBefore?: string | null;
|
|
739
|
+
/** Whether more history pages exist, when known. */
|
|
740
|
+
hasMore?: boolean;
|
|
741
|
+
/** Whether there is a pending approval waiting for a response, when known. */
|
|
742
|
+
hasPendingApproval?: boolean;
|
|
743
|
+
/** Wall-clock timing breakdown in milliseconds (if provided by CLI). */
|
|
744
|
+
timings?: {
|
|
745
|
+
resolve_ms: number;
|
|
746
|
+
list_messages_ms: number;
|
|
747
|
+
total_ms: number;
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Request to execute an external tool (CLI → SDK)
|
|
752
|
+
*/
|
|
753
|
+
export interface ExecuteExternalToolRequest {
|
|
754
|
+
subtype: "execute_external_tool";
|
|
755
|
+
tool_call_id: string;
|
|
756
|
+
tool_name: string;
|
|
757
|
+
input: Record<string, unknown>;
|
|
758
|
+
}
|
|
759
|
+
//# sourceMappingURL=types.d.ts.map
|