@letta-ai/letta-code-sdk 0.0.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.
@@ -0,0 +1,63 @@
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 { SessionOptions, SDKMessage, SDKInitMessage } 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
+ constructor(options?: SessionOptions & {
16
+ agentId?: string;
17
+ });
18
+ /**
19
+ * Initialize the session (called automatically on first send)
20
+ */
21
+ initialize(): Promise<SDKInitMessage>;
22
+ /**
23
+ * Send a message to the agent
24
+ */
25
+ send(message: string): Promise<void>;
26
+ /**
27
+ * Stream messages from the agent
28
+ */
29
+ stream(): AsyncGenerator<SDKMessage>;
30
+ /**
31
+ * Handle can_use_tool control request from CLI (Claude SDK compatible format)
32
+ */
33
+ private handleCanUseTool;
34
+ /**
35
+ * Abort the current operation (interrupt without closing the session)
36
+ */
37
+ abort(): Promise<void>;
38
+ /**
39
+ * Close the session
40
+ */
41
+ close(): void;
42
+ /**
43
+ * Get the agent ID (available after initialization)
44
+ */
45
+ get agentId(): string | null;
46
+ /**
47
+ * Get the session ID (available after initialization)
48
+ */
49
+ get sessionId(): string | null;
50
+ /**
51
+ * Get the conversation ID (available after initialization)
52
+ */
53
+ get conversationId(): string | null;
54
+ /**
55
+ * AsyncDisposable implementation for `await using`
56
+ */
57
+ [Symbol.asyncDispose](): Promise<void>;
58
+ /**
59
+ * Transform wire message to SDK message
60
+ */
61
+ private transformMessage;
62
+ }
63
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EACV,cAAc,EACd,UAAU,EACV,cAAc,EASf,MAAM,YAAY,CAAC;AAGpB,qBAAa,OAAQ,YAAW,eAAe;IAQ3C,OAAO,CAAC,OAAO;IAPjB,OAAO,CAAC,SAAS,CAAsB;IACvC,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,WAAW,CAAS;gBAGlB,OAAO,GAAE,cAAc,GAAG;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAO;IAO7D;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,cAAc,CAAC;IA2C3C;;OAEG;IACG,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW1C;;OAEG;IACI,MAAM,IAAI,cAAc,CAAC,UAAU,CAAC;IA0B3C;;OAEG;YACW,gBAAgB;IAiD9B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ5B;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;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;CAiIzB"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * SubprocessTransport
3
+ *
4
+ * Spawns the Letta Code CLI and communicates via stdin/stdout JSON streams.
5
+ */
6
+ import type { SessionOptions, WireMessage } from "./types.js";
7
+ export declare class SubprocessTransport {
8
+ private options;
9
+ private process;
10
+ private stdout;
11
+ private messageQueue;
12
+ private messageResolvers;
13
+ private closed;
14
+ private agentId?;
15
+ constructor(options?: SessionOptions & {
16
+ agentId?: string;
17
+ });
18
+ /**
19
+ * Start the CLI subprocess
20
+ */
21
+ connect(): Promise<void>;
22
+ /**
23
+ * Send a message to the CLI via stdin
24
+ */
25
+ write(data: object): Promise<void>;
26
+ /**
27
+ * Read the next message from the CLI
28
+ */
29
+ read(): Promise<WireMessage | null>;
30
+ /**
31
+ * Async iterator for messages
32
+ */
33
+ messages(): AsyncGenerator<WireMessage>;
34
+ /**
35
+ * Close the transport
36
+ */
37
+ close(): void;
38
+ get isClosed(): boolean;
39
+ private handleMessage;
40
+ private buildArgs;
41
+ private findCli;
42
+ }
43
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9D,qBAAa,mBAAmB;IAS5B,OAAO,CAAC,OAAO;IARjB,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,gBAAgB,CAAyC;IACjE,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAC,CAAS;gBAGf,OAAO,GAAE,cAAc,GAAG;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAO;IAG7D;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA2C9B;;OAEG;IACG,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOxC;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAiBzC;;OAEG;IACI,QAAQ,IAAI,cAAc,CAAC,WAAW,CAAC;IAQ9C;;OAEG;IACH,KAAK,IAAI,IAAI;IAeb,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,OAAO,CAAC,aAAa;IAgBrB,OAAO,CAAC,SAAS;YAwJH,OAAO;CA0CtB"}
@@ -0,0 +1,172 @@
1
+ /**
2
+ * SDK Types
3
+ *
4
+ * These are the public-facing types for SDK consumers.
5
+ * Protocol types are imported from @letta-ai/letta-code/protocol.
6
+ */
7
+ export type { WireMessage, SystemInitMessage, MessageWire, ResultMessage, ErrorMessage, StreamEvent, ControlRequest, ControlResponse, CanUseToolControlRequest, CanUseToolResponse, CanUseToolResponseAllow, CanUseToolResponseDeny, SystemPromptPresetConfig, CreateBlock, } from "@letta-ai/letta-code/protocol";
8
+ import type { CreateBlock } from "@letta-ai/letta-code/protocol";
9
+ /**
10
+ * Available system prompt presets.
11
+ */
12
+ export type SystemPromptPreset = "default" | "letta-claude" | "letta-codex" | "letta-gemini" | "claude" | "codex" | "gemini";
13
+ /**
14
+ * System prompt preset configuration.
15
+ */
16
+ export interface SystemPromptPresetConfigSDK {
17
+ type: "preset";
18
+ preset: SystemPromptPreset;
19
+ append?: string;
20
+ }
21
+ /**
22
+ * System prompt configuration - either a raw string or preset config.
23
+ */
24
+ export type SystemPromptConfig = string | SystemPromptPresetConfigSDK;
25
+ /**
26
+ * Reference to an existing shared block by ID.
27
+ */
28
+ export interface BlockReference {
29
+ blockId: string;
30
+ }
31
+ /**
32
+ * Memory item - can be a preset name, custom block, or block reference.
33
+ */
34
+ export type MemoryItem = string | CreateBlock | BlockReference;
35
+ /**
36
+ * Default memory block preset names.
37
+ */
38
+ export type MemoryPreset = "persona" | "human" | "project";
39
+ /**
40
+ * Result of a canUseTool callback
41
+ */
42
+ export interface PermissionResult {
43
+ allow: boolean;
44
+ reason?: string;
45
+ }
46
+ /**
47
+ * Callback for custom permission handling
48
+ */
49
+ export type CanUseToolCallback = (toolName: string, toolInput: Record<string, unknown>) => Promise<PermissionResult> | PermissionResult;
50
+ /**
51
+ * Options for creating a session
52
+ */
53
+ export interface SessionOptions {
54
+ /** Model to use (e.g., "claude-sonnet-4-20250514") */
55
+ model?: string;
56
+ /** Resume a specific conversation by ID (derives agent automatically) */
57
+ conversationId?: string;
58
+ /** Create a new conversation for concurrent sessions (requires agentId) */
59
+ newConversation?: boolean;
60
+ /** Resume the last session (agent + conversation from previous run) */
61
+ continue?: boolean;
62
+ /** Use agent's default conversation (requires agentId) */
63
+ defaultConversation?: boolean;
64
+ /**
65
+ * System prompt configuration.
66
+ * - string: Use as the complete system prompt
67
+ * - { type: 'preset', preset, append? }: Use a preset with optional appended text
68
+ *
69
+ * Available presets: 'default', 'letta-claude', 'letta-codex', 'letta-gemini',
70
+ * 'claude', 'codex', 'gemini'
71
+ */
72
+ systemPrompt?: SystemPromptConfig;
73
+ /**
74
+ * Memory block configuration. Each item can be:
75
+ * - string: Preset block name ("project", "persona", "human")
76
+ * - CreateBlock: Custom block definition
77
+ * - { blockId: string }: Reference to existing shared block
78
+ *
79
+ * If not specified, defaults to ["persona", "human", "project"].
80
+ * Core blocks (skills, loaded_skills) are always included automatically.
81
+ */
82
+ memory?: MemoryItem[];
83
+ /**
84
+ * Convenience: Set persona block value directly.
85
+ * Uses default block description/limit, just overrides the value.
86
+ * Error if persona not included in memory config.
87
+ */
88
+ persona?: string;
89
+ /**
90
+ * Convenience: Set human block value directly.
91
+ */
92
+ human?: string;
93
+ /**
94
+ * Convenience: Set project block value directly.
95
+ */
96
+ project?: string;
97
+ /** List of allowed tool names */
98
+ allowedTools?: string[];
99
+ /** Permission mode */
100
+ permissionMode?: PermissionMode;
101
+ /** Working directory */
102
+ cwd?: string;
103
+ /** Maximum conversation turns */
104
+ maxTurns?: number;
105
+ /** Custom permission callback - called when tool needs approval */
106
+ canUseTool?: CanUseToolCallback;
107
+ }
108
+ export type PermissionMode = "default" | "acceptEdits" | "bypassPermissions";
109
+ /**
110
+ * SDK message types - clean wrappers around wire types
111
+ */
112
+ export interface SDKInitMessage {
113
+ type: "init";
114
+ agentId: string;
115
+ sessionId: string;
116
+ conversationId: string;
117
+ model: string;
118
+ tools: string[];
119
+ }
120
+ export interface SDKAssistantMessage {
121
+ type: "assistant";
122
+ content: string;
123
+ uuid: string;
124
+ }
125
+ export interface SDKToolCallMessage {
126
+ type: "tool_call";
127
+ toolCallId: string;
128
+ toolName: string;
129
+ toolInput: Record<string, unknown>;
130
+ uuid: string;
131
+ }
132
+ export interface SDKToolResultMessage {
133
+ type: "tool_result";
134
+ toolCallId: string;
135
+ content: string;
136
+ isError: boolean;
137
+ uuid: string;
138
+ }
139
+ export interface SDKReasoningMessage {
140
+ type: "reasoning";
141
+ content: string;
142
+ uuid: string;
143
+ }
144
+ export interface SDKResultMessage {
145
+ type: "result";
146
+ success: boolean;
147
+ result?: string;
148
+ error?: string;
149
+ durationMs: number;
150
+ totalCostUsd?: number;
151
+ conversationId: string | null;
152
+ }
153
+ export interface SDKStreamEventMessage {
154
+ type: "stream_event";
155
+ event: {
156
+ type: string;
157
+ index?: number;
158
+ delta?: {
159
+ type?: string;
160
+ text?: string;
161
+ reasoning?: string;
162
+ };
163
+ content_block?: {
164
+ type?: string;
165
+ text?: string;
166
+ };
167
+ };
168
+ uuid: string;
169
+ }
170
+ /** Union of all SDK message types */
171
+ export type SDKMessage = SDKInitMessage | SDKAssistantMessage | SDKToolCallMessage | SDKToolResultMessage | SDKReasoningMessage | SDKResultMessage | SDKStreamEventMessage;
172
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,YAAY,EACV,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,YAAY,EACZ,WAAW,EACX,cAAc,EACd,eAAe,EACf,wBAAwB,EACxB,kBAAkB,EAClB,uBAAuB,EACvB,sBAAsB,EAEtB,wBAAwB,EACxB,WAAW,GACZ,MAAM,+BAA+B,CAAC;AAGvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAMjE;;GAEG;AACH,MAAM,MAAM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,CAAC;CACd;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE;YAAE,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,SAAS,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QAC7D,aAAa,CAAC,EAAE;YAAE,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;KAClD,CAAC;IACF,IAAI,EAAE,MAAM,CAAC;CACd;AAED,qCAAqC;AACrC,MAAM,MAAM,UAAU,GAClB,cAAc,GACd,mBAAmB,GACnB,kBAAkB,GAClB,oBAAoB,GACpB,mBAAmB,GACnB,gBAAgB,GAChB,qBAAqB,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * SDK Validation
3
+ *
4
+ * Validates SessionOptions before spawning the CLI.
5
+ */
6
+ import type { SessionOptions } from "./types.js";
7
+ /**
8
+ * Validate SessionOptions before spawning CLI.
9
+ * Throws an error if validation fails.
10
+ */
11
+ export declare function validateSessionOptions(options: SessionOptions): void;
12
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,YAAY,CAAC;AAe1E;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAsFpE"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@letta-ai/letta-code-sdk",
3
+ "version": "0.0.1",
4
+ "description": "SDK for programmatic control of Letta Code CLI",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md"
17
+ ],
18
+ "scripts": {
19
+ "build": "bun run build.ts",
20
+ "dev": "bun run build.ts --watch",
21
+ "check": "tsc --noEmit",
22
+ "test": "bun test"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/letta-ai/letta-code-sdk"
27
+ },
28
+ "dependencies": {
29
+ "@letta-ai/letta-code": "latest"
30
+ },
31
+ "devDependencies": {
32
+ "@types/bun": "latest",
33
+ "@types/node": "^22.0.0",
34
+ "typescript": "^5.7.0"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "license": "Apache-2.0"
40
+ }