@letta-ai/letta-agent-sdk 0.3.3 → 0.5.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.
Files changed (56) hide show
  1. package/AGENTS.md +0 -3
  2. package/README.md +8 -1
  3. package/dist/app-server-management.d.ts +3 -48
  4. package/dist/app-server-management.d.ts.map +1 -1
  5. package/dist/app-server-session.d.ts +0 -6
  6. package/dist/app-server-session.d.ts.map +1 -1
  7. package/dist/client-base.d.ts +7 -15
  8. package/dist/client-base.d.ts.map +1 -1
  9. package/dist/client-entry.js +428 -486
  10. package/dist/client-entry.js.map +13 -12
  11. package/dist/client.d.ts +3 -3
  12. package/dist/client.d.ts.map +1 -1
  13. package/dist/cloud-session.d.ts +2 -0
  14. package/dist/cloud-session.d.ts.map +1 -1
  15. package/dist/cloud-status-transport.d.ts +53 -0
  16. package/dist/cloud-status-transport.d.ts.map +1 -0
  17. package/dist/index.d.ts +7 -16
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +911 -1993
  20. package/dist/index.js.map +18 -18
  21. package/dist/local-app-server-session.d.ts +1 -1
  22. package/dist/local-app-server-session.d.ts.map +1 -1
  23. package/dist/local-app-server.d.ts +11 -0
  24. package/dist/local-app-server.d.ts.map +1 -1
  25. package/dist/management.d.ts +0 -7
  26. package/dist/management.d.ts.map +1 -1
  27. package/dist/remote-session-protocol.d.ts +2 -0
  28. package/dist/remote-session-protocol.d.ts.map +1 -1
  29. package/dist/remote-turn-coordinator.d.ts.map +1 -1
  30. package/dist/types.d.ts +65 -66
  31. package/dist/types.d.ts.map +1 -1
  32. package/dist/validation.d.ts.map +1 -1
  33. package/package.json +2 -2
  34. package/src/app-server-management.ts +20 -256
  35. package/src/app-server-session.ts +0 -32
  36. package/src/client-base.ts +47 -73
  37. package/src/client.ts +31 -70
  38. package/src/cloud-session.ts +113 -287
  39. package/src/cloud-status-transport.ts +305 -0
  40. package/src/index.ts +11 -29
  41. package/src/local-app-server-session.ts +13 -3
  42. package/src/local-app-server.ts +97 -3
  43. package/src/management.ts +0 -7
  44. package/src/remote-session-protocol.ts +18 -0
  45. package/src/remote-turn-coordinator.ts +20 -2
  46. package/src/types.ts +72 -111
  47. package/src/validation.ts +21 -6
  48. package/dist/protocol.d.ts +0 -205
  49. package/dist/protocol.d.ts.map +0 -1
  50. package/dist/session.d.ts +0 -155
  51. package/dist/session.d.ts.map +0 -1
  52. package/dist/transport.d.ts +0 -53
  53. package/dist/transport.d.ts.map +0 -1
  54. package/src/protocol.ts +0 -249
  55. package/src/session.ts +0 -1638
  56. package/src/transport.ts +0 -484
package/dist/session.d.ts DELETED
@@ -1,155 +0,0 @@
1
- /**
2
- * Session
3
- *
4
- * Represents a conversation session with a Letta agent.
5
- * Implements the V2 API pattern: send() / receive()
6
- */
7
- import type { InternalSessionOptions, SDKMessage, SDKInitMessage, SDKResultMessage, SendMessage, ListMessagesOptions, ListMessagesResult, ListModelsResult, BootstrapStateOptions, BootstrapStateResult, ChangeDeviceStateOptions, GetDeviceStatusOptions, SessionDeviceStatus, RunTurnOptions, RecoverPendingApprovalsOptions, RecoverPendingApprovalsResult, RemoveQueuedMessageResult, SDKProtocolCommand, SDKProtocolMessage, SendCommandOptions, UpdateModelOptions, UpdateModelResult } from "./types.js";
8
- export declare class Session implements AsyncDisposable {
9
- private options;
10
- private transport;
11
- private _agentId;
12
- private _sessionId;
13
- private _conversationId;
14
- private initialized;
15
- private closed;
16
- private initializePromise;
17
- private externalTools;
18
- private streamQueue;
19
- private streamResolvers;
20
- private pumpPromise;
21
- private pumpClosed;
22
- private droppedStreamMessages;
23
- private sendGeneration;
24
- private lastCompletedRunIds;
25
- private controlResponseWaiters;
26
- constructor(options?: InternalSessionOptions);
27
- /**
28
- * Initialize the session (called automatically on first send).
29
- *
30
- * Single-flight: concurrent callers (including lazily-initializing entry
31
- * points such as send()) share one in-flight initialization instead of
32
- * each connecting the transport. A failed stdio attempt closes the session
33
- * because its subprocess transport is no longer safe to reuse.
34
- */
35
- initialize(): Promise<SDKInitMessage>;
36
- private performInitialize;
37
- private cleanupFailedInitialize;
38
- /**
39
- * Send a message to the agent
40
- *
41
- * @param message - Text string or multimodal content array
42
- *
43
- * @example
44
- * // Simple text
45
- * await session.send("Hello!");
46
- *
47
- * @example
48
- * // With image
49
- * await session.send([
50
- * { type: "text", text: "What's in this image?" },
51
- * { type: "image", source: { type: "base64", mediaType: "image/png", data: "..." } }
52
- * ]);
53
- */
54
- send(message: SendMessage): Promise<void>;
55
- /**
56
- * Run a full turn (send + stream terminal result), with optional bounded
57
- * SDK-owned approval-conflict recovery.
58
- */
59
- runTurn(message: SendMessage, options?: RunTurnOptions): Promise<SDKResultMessage>;
60
- /**
61
- * Ask the CLI to recover pending approvals for the current
62
- * agent/conversation context.
63
- */
64
- recoverPendingApprovals(options?: RecoverPendingApprovalsOptions): Promise<RecoverPendingApprovalsResult>;
65
- private resolveMaxApprovalRecoveryAttempts;
66
- private resolveApprovalRecoveryTimeoutMs;
67
- private toTerminalApprovalConflictResult;
68
- private runSingleTurn;
69
- /**
70
- * Stream messages from the agent
71
- */
72
- stream(): AsyncGenerator<SDKMessage>;
73
- private startBackgroundPump;
74
- private runBackgroundPump;
75
- private handleControlRequest;
76
- private enqueueStreamMessage;
77
- private nextBufferedMessage;
78
- private resolveAllStreamWaiters;
79
- private getMessageRunId;
80
- private updateCompletedRunIds;
81
- /**
82
- * Register external tools with the CLI
83
- */
84
- private registerExternalTools;
85
- /**
86
- * Convert TypeBox schema to JSON Schema
87
- */
88
- private schemaToJsonSchema;
89
- /**
90
- * Handle execute_external_tool control request from CLI
91
- */
92
- private handleExecuteExternalTool;
93
- /**
94
- * Handle can_use_tool control request from CLI (Claude SDK compatible format)
95
- */
96
- private handleCanUseTool;
97
- /**
98
- * Abort the current operation (interrupt without closing the session)
99
- */
100
- abort(): Promise<void>;
101
- private requestControlResponse;
102
- /**
103
- * Fetch a page of conversation messages via the CLI control protocol.
104
- *
105
- * The session must be initialized before calling this method.
106
- * Safe to call concurrently with an active stream() — the pump routes
107
- * matching control_response messages to this waiter without touching the
108
- * stream queue.
109
- */
110
- listMessages(options?: ListMessagesOptions): Promise<ListMessagesResult>;
111
- listModels(): Promise<ListModelsResult>;
112
- sendCommand(command: SDKProtocolCommand): Promise<void>;
113
- sendCommand<TResponse extends SDKProtocolMessage = SDKProtocolMessage>(command: SDKProtocolCommand, options: SendCommandOptions): Promise<TResponse>;
114
- updateModel(_update: string | UpdateModelOptions): Promise<UpdateModelResult>;
115
- changeDeviceState(_updates: ChangeDeviceStateOptions): Promise<void>;
116
- removeQueuedMessage(_itemId: string): Promise<RemoveQueuedMessageResult>;
117
- getDeviceStatus(_options?: GetDeviceStatusOptions): Promise<SessionDeviceStatus>;
118
- onDeviceStatus(_listener: (status: SessionDeviceStatus) => void): () => void;
119
- /**
120
- * Fetch all data needed to render the initial conversation view in one round-trip.
121
- *
122
- * Returns resolved session metadata + initial history page + pending approval flag
123
- * + optional timing breakdown. This is faster than separate initialize() + listMessages()
124
- * calls because the CLI collects and returns everything in a single control response.
125
- *
126
- * The session must be initialized before calling this method.
127
- */
128
- bootstrapState(options?: BootstrapStateOptions): Promise<BootstrapStateResult>;
129
- updateToolset(_toolsetPreference: string): Promise<void>;
130
- /**
131
- * Close the session
132
- */
133
- close(): void;
134
- /**
135
- * Get the agent ID (available after initialization)
136
- */
137
- get agentId(): string | null;
138
- /**
139
- * Get the session ID (available after initialization)
140
- */
141
- get sessionId(): string | null;
142
- /**
143
- * Get the conversation ID (available after initialization)
144
- */
145
- get conversationId(): string | null;
146
- /**
147
- * AsyncDisposable implementation for `await using`
148
- */
149
- [Symbol.asyncDispose](): Promise<void>;
150
- /**
151
- * Transform wire message to SDK message
152
- */
153
- private transformMessage;
154
- }
155
- //# sourceMappingURL=session.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,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xE,eAAe,CAAC,QAAQ,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAMtF,cAAc,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,GAAG,MAAM,IAAI;IAM5E;;;;;;;;OAQG;IACG,cAAc,CAClB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,oBAAoB,CAAC;IAwD1B,aAAa,CAAC,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9D;;OAEG;IACH,KAAK,IAAI,IAAI;IASb;;OAEG;IACH,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAE3B;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,MAAM,GAAG,IAAI,CAE7B;IAED;;OAEG;IACH,IAAI,cAAc,IAAI,MAAM,GAAG,IAAI,CAElC;IAED;;OAEG;IACG,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5C;;OAEG;IACH,OAAO,CAAC,gBAAgB;CAoQzB"}
@@ -1,53 +0,0 @@
1
- /**
2
- * SubprocessTransport
3
- *
4
- * Spawns the Letta Code CLI and communicates via stdin/stdout JSON streams.
5
- */
6
- import type { InternalSessionOptions, WireMessage } from "./types.js";
7
- /**
8
- * Build the CLI argument array for a given set of session options.
9
- *
10
- * Exported as a pure function for testing — this IS the real production code
11
- * path. SubprocessTransport.buildArgs() delegates here.
12
- */
13
- export declare function buildCliArgs(options: InternalSessionOptions): string[];
14
- export declare class SubprocessTransport {
15
- private options;
16
- private process;
17
- private stdout;
18
- private messageQueue;
19
- private messageResolvers;
20
- private closed;
21
- private agentId?;
22
- private wireMessageCount;
23
- private lastMessageAt;
24
- private stderrLines;
25
- constructor(options?: InternalSessionOptions);
26
- /**
27
- * Start the CLI subprocess
28
- */
29
- connect(): Promise<void>;
30
- /**
31
- * Send a message to the CLI via stdin
32
- */
33
- write(data: object): Promise<void>;
34
- /**
35
- * Read the next message from the CLI
36
- */
37
- read(): Promise<WireMessage | null>;
38
- /**
39
- * Async iterator for messages
40
- */
41
- messages(): AsyncGenerator<WireMessage>;
42
- /**
43
- * Close the transport
44
- */
45
- close(): void;
46
- get isClosed(): boolean;
47
- /** Return buffered stderr output from the CLI subprocess. */
48
- getStderr(): string;
49
- private handleMessage;
50
- private buildArgs;
51
- private findCli;
52
- }
53
- //# sourceMappingURL=transport.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAgCtE;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,sBAAsB,GAAG,MAAM,EAAE,CA4KtE;AAED,qBAAa,mBAAmB;IAY5B,OAAO,CAAC,OAAO;IAXjB,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,gBAAgB,CAAgD;IACxE,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,gBAAgB,CAAK;IAC7B,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,WAAW,CAAgB;gBAGzB,OAAO,GAAE,sBAA2B;IAG9C;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA+E9B;;OAEG;IACG,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWxC;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAmBzC;;OAEG;IACI,QAAQ,IAAI,cAAc,CAAC,WAAW,CAAC;IAW9C;;OAEG;IACH,KAAK,IAAI,IAAI;IAgBb,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,6DAA6D;IAC7D,SAAS,IAAI,MAAM;IAInB,OAAO,CAAC,aAAa;IAqCrB,OAAO,CAAC,SAAS;YAMH,OAAO;CA4CtB"}
package/src/protocol.ts DELETED
@@ -1,249 +0,0 @@
1
- /**
2
- * Local protocol type surface consumed by the SDK.
3
- *
4
- * @letta-ai/letta-code@0.27.11 publishes these declarations under an internal
5
- * dist path while its package.json points the public `./protocol` export at a
6
- * missing file. Keep the SDK's public types self-contained so CI and consumers
7
- * do not depend on that broken subpath export.
8
- */
9
-
10
- export interface MessageEnvelope {
11
- type: string;
12
- session_id?: string;
13
- uuid?: string;
14
- timestamp?: string;
15
- event_seq?: number;
16
- agent_id?: string;
17
- conversation_id?: string;
18
- [key: string]: unknown;
19
- }
20
-
21
- /**
22
- * System prompt preset configuration used by the CLI protocol.
23
- */
24
- export interface SystemPromptPresetConfig {
25
- type: "preset";
26
- preset: string;
27
- append?: string;
28
- }
29
-
30
- /**
31
- * Custom memory block definition accepted when creating agents.
32
- */
33
- export interface CreateBlock {
34
- label: string;
35
- value: string;
36
- base_template_id?: string | null;
37
- deployment_id?: string | null;
38
- description?: string | null;
39
- entity_id?: string | null;
40
- hidden?: boolean | null;
41
- is_template?: boolean;
42
- limit?: number;
43
- metadata?: Record<string, unknown> | null;
44
- preserve_on_migration?: boolean | null;
45
- project_id?: string | null;
46
- read_only?: boolean;
47
- tags?: string[] | null;
48
- template_id?: string | null;
49
- template_name?: string | null;
50
- }
51
-
52
- export interface SystemInitMessage extends MessageEnvelope {
53
- type: "system";
54
- subtype: "init";
55
- agent_id: string;
56
- conversation_id: string;
57
- model: string;
58
- tools: string[];
59
- cwd: string;
60
- mcp_servers: Array<{
61
- name: string;
62
- status: string;
63
- }>;
64
- permission_mode: string;
65
- slash_commands: string[];
66
- memfs_enabled?: boolean;
67
- skill_sources?: Array<"bundled" | "global" | "agent" | "project">;
68
- system_info_reminder_enabled?: boolean;
69
- reflection_trigger?: "off" | "step-count" | "compaction-event";
70
- reflection_behavior?: "reminder" | "auto-launch";
71
- reflection_step_count?: number;
72
- }
73
-
74
- export interface MessageWire extends MessageEnvelope {
75
- type: "message";
76
- message_type?: string;
77
- run_id?: string;
78
- }
79
-
80
- export interface StreamEvent extends MessageEnvelope {
81
- type: "stream_event";
82
- event: unknown;
83
- }
84
-
85
- export type ResultSubtype = "success" | "interrupted" | "error" | string;
86
-
87
- export interface ResultMessage extends MessageEnvelope {
88
- type: "result";
89
- subtype: ResultSubtype;
90
- agent_id?: string;
91
- conversation_id: string;
92
- duration_ms: number;
93
- duration_api_ms?: number;
94
- num_turns?: number;
95
- result?: string | null;
96
- run_ids?: string[];
97
- usage?: unknown;
98
- stop_reason?: string;
99
- }
100
-
101
- export interface ErrorMessage extends MessageEnvelope {
102
- type: "error";
103
- message: string;
104
- stop_reason: string;
105
- run_id?: string;
106
- api_error?: Record<string, unknown>;
107
- }
108
-
109
- export interface CanUseToolControlRequest {
110
- subtype: "can_use_tool";
111
- tool_name: string;
112
- input: Record<string, unknown>;
113
- tool_call_id: string;
114
- permission_suggestions?: unknown[];
115
- blocked_path?: string | null;
116
- diffs?: unknown[];
117
- }
118
-
119
- export interface RegisterExternalToolsRequest {
120
- subtype: "register_external_tools";
121
- tools: Array<{
122
- name: string;
123
- label?: string;
124
- description: string;
125
- parameters: Record<string, unknown>;
126
- }>;
127
- }
128
-
129
- export interface BootstrapSessionStateRequest {
130
- subtype: "bootstrap_session_state";
131
- limit?: number;
132
- order?: "asc" | "desc";
133
- }
134
-
135
- export interface RecoverPendingApprovalsControlRequest {
136
- subtype: "recover_pending_approvals";
137
- agent_id?: string;
138
- conversation_id?: string;
139
- }
140
-
141
- export interface ListMessagesControlRequest {
142
- subtype: "list_messages";
143
- conversation_id?: string;
144
- agent_id?: string;
145
- before?: string;
146
- after?: string;
147
- order?: "asc" | "desc";
148
- limit?: number;
149
- }
150
-
151
- export interface InterruptControlRequest {
152
- subtype: "interrupt";
153
- }
154
-
155
- export interface InitializeControlRequest {
156
- subtype: "initialize";
157
- }
158
-
159
- export interface ExecuteExternalToolControlRequest {
160
- subtype: "execute_external_tool";
161
- tool_call_id: string;
162
- tool_name: string;
163
- input: Record<string, unknown>;
164
- }
165
-
166
- export type ControlRequestBody =
167
- | InitializeControlRequest
168
- | InterruptControlRequest
169
- | RegisterExternalToolsRequest
170
- | BootstrapSessionStateRequest
171
- | RecoverPendingApprovalsControlRequest
172
- | ListMessagesControlRequest
173
- | CanUseToolControlRequest
174
- | ExecuteExternalToolControlRequest
175
- | (Record<string, unknown> & { subtype: string });
176
-
177
- export interface ControlRequest extends MessageEnvelope {
178
- type: "control_request";
179
- request_id: string;
180
- request: ControlRequestBody;
181
- }
182
-
183
- export interface CanUseToolResponseAllow {
184
- behavior: "allow";
185
- message?: string;
186
- updatedInput?: Record<string, unknown> | null;
187
- updatedPermissions?: unknown[];
188
- }
189
-
190
- export interface CanUseToolResponseDeny {
191
- behavior: "deny";
192
- message: string;
193
- interrupt?: boolean;
194
- }
195
-
196
- export type CanUseToolResponse = CanUseToolResponseAllow | CanUseToolResponseDeny;
197
-
198
- export interface ExternalToolResultContent {
199
- type: "text" | "image";
200
- text?: string;
201
- data?: string;
202
- mimeType?: string;
203
- }
204
-
205
- export interface ExternalToolResultResponse {
206
- subtype: "external_tool_result";
207
- request_id: string;
208
- tool_call_id: string;
209
- content: ExternalToolResultContent[];
210
- is_error: boolean;
211
- }
212
-
213
- export type ControlResponseBody =
214
- | {
215
- subtype: "success";
216
- request_id: string;
217
- response?: CanUseToolResponse | Record<string, unknown>;
218
- }
219
- | {
220
- subtype: "error";
221
- request_id: string;
222
- error: string;
223
- }
224
- | ExternalToolResultResponse;
225
-
226
- export interface ControlResponse extends MessageEnvelope {
227
- type: "control_response";
228
- response: ControlResponseBody;
229
- }
230
-
231
- export interface RetryMessage extends MessageEnvelope {
232
- type: "retry";
233
- reason: string;
234
- attempt: number;
235
- max_attempts: number;
236
- delay_ms: number;
237
- run_id?: string;
238
- }
239
-
240
- export type WireMessage =
241
- | SystemInitMessage
242
- | MessageWire
243
- | StreamEvent
244
- | ResultMessage
245
- | ErrorMessage
246
- | RetryMessage
247
- | ControlRequest
248
- | ControlResponse
249
- | (MessageEnvelope & { type: string });