@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.
- package/LICENSE +190 -0
- package/README.md +328 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +548 -0
- package/dist/index.js.map +13 -0
- package/dist/session.d.ts +63 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/transport.d.ts +43 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/types.d.ts +172 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/validation.d.ts +12 -0
- package/dist/validation.d.ts.map +1 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2025, Letta authors
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
# Letta Code SDK
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@letta-ai/letta-code-sdk)
|
|
4
|
+
|
|
5
|
+
The SDK interface to [Letta Code](https://github.com/letta-ai/letta-code). Build agents with persistent memory that learn over time.
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { prompt } from '@letta-ai/letta-code-sdk';
|
|
9
|
+
|
|
10
|
+
const result = await prompt('Find and fix the bug in auth.py', {
|
|
11
|
+
allowedTools: ['Read', 'Edit', 'Bash'],
|
|
12
|
+
permissionMode: 'bypassPermissions'
|
|
13
|
+
});
|
|
14
|
+
console.log(result.result);
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @letta-ai/letta-code-sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
### One-shot prompt
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { prompt } from '@letta-ai/letta-code-sdk';
|
|
29
|
+
|
|
30
|
+
const result = await prompt('Run: echo hello', {
|
|
31
|
+
allowedTools: ['Bash'],
|
|
32
|
+
permissionMode: 'bypassPermissions'
|
|
33
|
+
});
|
|
34
|
+
console.log(result.result); // "hello"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Multi-turn session
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { createSession } from '@letta-ai/letta-code-sdk';
|
|
41
|
+
|
|
42
|
+
await using session = createSession();
|
|
43
|
+
|
|
44
|
+
await session.send('What is 5 + 3?');
|
|
45
|
+
for await (const msg of session.stream()) {
|
|
46
|
+
if (msg.type === 'assistant') console.log(msg.content);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
await session.send('Multiply that by 2');
|
|
50
|
+
for await (const msg of session.stream()) {
|
|
51
|
+
if (msg.type === 'assistant') console.log(msg.content);
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Persistent memory
|
|
56
|
+
|
|
57
|
+
Agents persist across sessions and remember context:
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { createSession, resumeSession } from '@letta-ai/letta-code-sdk';
|
|
61
|
+
|
|
62
|
+
// First session
|
|
63
|
+
const session1 = createSession();
|
|
64
|
+
await session1.send('Remember: the secret word is "banana"');
|
|
65
|
+
for await (const msg of session1.stream()) { /* ... */ }
|
|
66
|
+
const agentId = session1.agentId;
|
|
67
|
+
session1.close();
|
|
68
|
+
|
|
69
|
+
// Later...
|
|
70
|
+
await using session2 = resumeSession(agentId);
|
|
71
|
+
await session2.send('What is the secret word?');
|
|
72
|
+
for await (const msg of session2.stream()) {
|
|
73
|
+
if (msg.type === 'assistant') console.log(msg.content); // "banana"
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Multi-threaded Conversations
|
|
78
|
+
|
|
79
|
+
Run multiple concurrent conversations with the same agent. Each conversation has its own message history while sharing the agent's persistent memory.
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { createSession, resumeSession, resumeConversation } from '@letta-ai/letta-code-sdk';
|
|
83
|
+
|
|
84
|
+
// Create an agent
|
|
85
|
+
const session = createSession();
|
|
86
|
+
await session.send('Hello!');
|
|
87
|
+
for await (const msg of session.stream()) { /* ... */ }
|
|
88
|
+
const agentId = session.agentId;
|
|
89
|
+
const conversationId = session.conversationId; // Save this!
|
|
90
|
+
session.close();
|
|
91
|
+
|
|
92
|
+
// Resume a specific conversation
|
|
93
|
+
await using session2 = resumeConversation(conversationId);
|
|
94
|
+
await session2.send('Continue our discussion...');
|
|
95
|
+
for await (const msg of session2.stream()) { /* ... */ }
|
|
96
|
+
|
|
97
|
+
// Create a NEW conversation on the same agent
|
|
98
|
+
await using session3 = resumeSession(agentId, { newConversation: true });
|
|
99
|
+
await session3.send('Start a fresh thread...');
|
|
100
|
+
// session3.conversationId is different from conversationId
|
|
101
|
+
|
|
102
|
+
// Resume with agent's default conversation
|
|
103
|
+
await using session4 = resumeSession(agentId, { defaultConversation: true });
|
|
104
|
+
|
|
105
|
+
// Resume last used session (agent + conversation)
|
|
106
|
+
await using session5 = createSession({ continue: true });
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Key concepts:**
|
|
110
|
+
- **Agent** (`agentId`): Persistent entity with memory that survives across sessions
|
|
111
|
+
- **Conversation** (`conversationId`): A message thread within an agent
|
|
112
|
+
- **Session** (`sessionId`): A single execution/connection
|
|
113
|
+
|
|
114
|
+
Agents remember across conversations (via memory blocks), but each conversation has its own message history.
|
|
115
|
+
|
|
116
|
+
## Agent Configuration
|
|
117
|
+
|
|
118
|
+
### System Prompt
|
|
119
|
+
|
|
120
|
+
Choose from built-in presets or provide a custom prompt:
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
// Use a preset
|
|
124
|
+
createSession({
|
|
125
|
+
systemPrompt: { type: 'preset', preset: 'letta-claude' }
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Use a preset with additional instructions
|
|
129
|
+
createSession({
|
|
130
|
+
systemPrompt: {
|
|
131
|
+
type: 'preset',
|
|
132
|
+
preset: 'letta-claude',
|
|
133
|
+
append: 'Always respond in Spanish.'
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Use a completely custom prompt
|
|
138
|
+
createSession({
|
|
139
|
+
systemPrompt: 'You are a helpful Python expert.'
|
|
140
|
+
});
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**Available presets:**
|
|
144
|
+
- `default` / `letta-claude` - Full Letta Code prompt (Claude-optimized)
|
|
145
|
+
- `letta-codex` - Full Letta Code prompt (Codex-optimized)
|
|
146
|
+
- `letta-gemini` - Full Letta Code prompt (Gemini-optimized)
|
|
147
|
+
- `claude` - Basic Claude (no skills/memory instructions)
|
|
148
|
+
- `codex` - Basic Codex
|
|
149
|
+
- `gemini` - Basic Gemini
|
|
150
|
+
|
|
151
|
+
### Memory Blocks
|
|
152
|
+
|
|
153
|
+
Configure which memory blocks the agent uses:
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
// Use default blocks (persona, human, project)
|
|
157
|
+
createSession({});
|
|
158
|
+
|
|
159
|
+
// Use specific preset blocks
|
|
160
|
+
createSession({
|
|
161
|
+
memory: ['project', 'persona'] // Only these blocks
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// Use custom blocks
|
|
165
|
+
createSession({
|
|
166
|
+
memory: [
|
|
167
|
+
{ label: 'context', value: 'API documentation for Acme Corp...' },
|
|
168
|
+
{ label: 'rules', value: 'Always use TypeScript. Prefer functional patterns.' }
|
|
169
|
+
]
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// Mix presets and custom blocks
|
|
173
|
+
createSession({
|
|
174
|
+
memory: [
|
|
175
|
+
'project', // Use default project block
|
|
176
|
+
{ label: 'custom', value: 'Additional context...' }
|
|
177
|
+
]
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// No optional blocks (only core skills blocks)
|
|
181
|
+
createSession({
|
|
182
|
+
memory: []
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Convenience Props
|
|
187
|
+
|
|
188
|
+
Quickly customize common memory blocks:
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
createSession({
|
|
192
|
+
persona: 'You are a senior Python developer who writes clean, tested code.',
|
|
193
|
+
human: 'Name: Alice. Prefers concise responses.',
|
|
194
|
+
project: 'FastAPI backend for a todo app using PostgreSQL.'
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// Combine with memory config
|
|
198
|
+
createSession({
|
|
199
|
+
memory: ['persona', 'project'], // Only include these blocks
|
|
200
|
+
persona: 'You are a Go expert.',
|
|
201
|
+
project: 'CLI tool for managing Docker containers.'
|
|
202
|
+
});
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Tool Execution
|
|
206
|
+
|
|
207
|
+
Execute tools with automatic permission handling:
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
import { prompt } from '@letta-ai/letta-code-sdk';
|
|
211
|
+
|
|
212
|
+
// Run shell commands
|
|
213
|
+
const result = await prompt('List all TypeScript files', {
|
|
214
|
+
allowedTools: ['Glob', 'Bash'],
|
|
215
|
+
permissionMode: 'bypassPermissions',
|
|
216
|
+
cwd: '/path/to/project'
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// Read and analyze code
|
|
220
|
+
const analysis = await prompt('Explain what auth.ts does', {
|
|
221
|
+
allowedTools: ['Read', 'Grep'],
|
|
222
|
+
permissionMode: 'bypassPermissions'
|
|
223
|
+
});
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## API Reference
|
|
227
|
+
|
|
228
|
+
### Functions
|
|
229
|
+
|
|
230
|
+
| Function | Description |
|
|
231
|
+
|----------|-------------|
|
|
232
|
+
| `prompt(message, options?)` | One-shot query, returns result directly |
|
|
233
|
+
| `createSession(options?)` | Create new agent session |
|
|
234
|
+
| `resumeSession(agentId, options?)` | Resume existing agent by ID |
|
|
235
|
+
| `resumeConversation(conversationId, options?)` | Resume specific conversation (derives agent automatically) |
|
|
236
|
+
|
|
237
|
+
### Session
|
|
238
|
+
|
|
239
|
+
| Property/Method | Description |
|
|
240
|
+
|-----------------|-------------|
|
|
241
|
+
| `send(message)` | Send user message |
|
|
242
|
+
| `stream()` | AsyncGenerator yielding messages |
|
|
243
|
+
| `close()` | Close the session |
|
|
244
|
+
| `agentId` | Agent ID (for resuming later) |
|
|
245
|
+
| `sessionId` | Current session ID |
|
|
246
|
+
| `conversationId` | Conversation ID (for resuming specific thread) |
|
|
247
|
+
|
|
248
|
+
### Options
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
interface SessionOptions {
|
|
252
|
+
// Model selection
|
|
253
|
+
model?: string;
|
|
254
|
+
|
|
255
|
+
// Conversation options
|
|
256
|
+
conversationId?: string; // Resume specific conversation
|
|
257
|
+
newConversation?: boolean; // Create new conversation on agent
|
|
258
|
+
continue?: boolean; // Resume last session (agent + conversation)
|
|
259
|
+
defaultConversation?: boolean; // Use agent's default conversation
|
|
260
|
+
|
|
261
|
+
// System prompt: string or preset config
|
|
262
|
+
systemPrompt?: string | {
|
|
263
|
+
type: 'preset';
|
|
264
|
+
preset: 'default' | 'letta-claude' | 'letta-codex' | 'letta-gemini' | 'claude' | 'codex' | 'gemini';
|
|
265
|
+
append?: string;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
// Memory blocks: preset names, custom blocks, or mixed
|
|
269
|
+
memory?: Array<string | CreateBlock | { blockId: string }>;
|
|
270
|
+
|
|
271
|
+
// Convenience: set block values directly
|
|
272
|
+
persona?: string;
|
|
273
|
+
human?: string;
|
|
274
|
+
project?: string;
|
|
275
|
+
|
|
276
|
+
// Tool configuration
|
|
277
|
+
allowedTools?: string[];
|
|
278
|
+
permissionMode?: 'default' | 'acceptEdits' | 'bypassPermissions';
|
|
279
|
+
|
|
280
|
+
// Working directory
|
|
281
|
+
cwd?: string;
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Message Types
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
// Streamed during receive()
|
|
289
|
+
interface SDKAssistantMessage {
|
|
290
|
+
type: 'assistant';
|
|
291
|
+
content: string;
|
|
292
|
+
uuid: string;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Final message
|
|
296
|
+
interface SDKResultMessage {
|
|
297
|
+
type: 'result';
|
|
298
|
+
success: boolean;
|
|
299
|
+
result?: string;
|
|
300
|
+
error?: string;
|
|
301
|
+
durationMs: number;
|
|
302
|
+
conversationId: string;
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
## Examples
|
|
307
|
+
|
|
308
|
+
See [`examples/`](./examples/) for comprehensive examples including:
|
|
309
|
+
|
|
310
|
+
- Basic session usage
|
|
311
|
+
- Multi-turn conversations
|
|
312
|
+
- Session resume with persistent memory
|
|
313
|
+
- **Multi-threaded conversations** (resumeConversation, newConversation)
|
|
314
|
+
- System prompt configuration
|
|
315
|
+
- Memory block customization
|
|
316
|
+
- Tool execution (Bash, Glob, Read, etc.)
|
|
317
|
+
|
|
318
|
+
Run examples:
|
|
319
|
+
```bash
|
|
320
|
+
bun examples/v2-examples.ts all
|
|
321
|
+
|
|
322
|
+
# Run just conversation tests
|
|
323
|
+
bun examples/v2-examples.ts conversations
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
## License
|
|
327
|
+
|
|
328
|
+
Apache-2.0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Letta Code SDK
|
|
3
|
+
*
|
|
4
|
+
* Programmatic control of Letta Code CLI with persistent agent memory.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { createSession, prompt } from '@letta-ai/letta-code-sdk';
|
|
9
|
+
*
|
|
10
|
+
* // One-shot
|
|
11
|
+
* const result = await prompt('What is 2+2?', { model: 'claude-sonnet-4-20250514' });
|
|
12
|
+
*
|
|
13
|
+
* // Multi-turn session
|
|
14
|
+
* await using session = createSession({ model: 'claude-sonnet-4-20250514' });
|
|
15
|
+
* await session.send('Hello!');
|
|
16
|
+
* for await (const msg of session.stream()) {
|
|
17
|
+
* if (msg.type === 'assistant') console.log(msg.content);
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* // Resume with persistent memory
|
|
21
|
+
* await using resumed = resumeSession(agentId, { model: 'claude-sonnet-4-20250514' });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
import { Session } from "./session.js";
|
|
25
|
+
import type { SessionOptions, SDKResultMessage } from "./types.js";
|
|
26
|
+
export type { SessionOptions, SDKMessage, SDKInitMessage, SDKAssistantMessage, SDKToolCallMessage, SDKToolResultMessage, SDKReasoningMessage, SDKResultMessage, SDKStreamEventMessage, PermissionMode, PermissionResult, CanUseToolCallback, } from "./types.js";
|
|
27
|
+
export { Session } from "./session.js";
|
|
28
|
+
/**
|
|
29
|
+
* Create a new session with a fresh Letta agent.
|
|
30
|
+
*
|
|
31
|
+
* The agent will have persistent memory that survives across sessions.
|
|
32
|
+
* Use `resumeSession` to continue a conversation with an existing agent.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* await using session = createSession({ model: 'claude-sonnet-4-20250514' });
|
|
37
|
+
* await session.send('My name is Alice');
|
|
38
|
+
* for await (const msg of session.stream()) {
|
|
39
|
+
* console.log(msg);
|
|
40
|
+
* }
|
|
41
|
+
* console.log(`Agent ID: ${session.agentId}`); // Save this to resume later
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function createSession(options?: SessionOptions): Session;
|
|
45
|
+
/**
|
|
46
|
+
* Resume an existing session with a Letta agent.
|
|
47
|
+
*
|
|
48
|
+
* Unlike Claude Agent SDK (ephemeral sessions), Letta agents have persistent
|
|
49
|
+
* memory. You can resume a conversation days later and the agent will remember.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* // Days later...
|
|
54
|
+
* await using session = resumeSession(agentId, { model: 'claude-sonnet-4-20250514' });
|
|
55
|
+
* await session.send('What is my name?');
|
|
56
|
+
* for await (const msg of session.stream()) {
|
|
57
|
+
* // Agent remembers: "Your name is Alice"
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function resumeSession(agentId: string, options?: SessionOptions): Session;
|
|
62
|
+
/**
|
|
63
|
+
* Resume an existing conversation.
|
|
64
|
+
*
|
|
65
|
+
* Conversations are threads within an agent. The agent is derived automatically
|
|
66
|
+
* from the conversation ID. Use this to continue a specific conversation thread.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // Resume a specific conversation
|
|
71
|
+
* await using session = resumeConversation(conversationId);
|
|
72
|
+
* await session.send('Continue our discussion...');
|
|
73
|
+
* for await (const msg of session.stream()) {
|
|
74
|
+
* console.log(msg);
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function resumeConversation(conversationId: string, options?: SessionOptions): Session;
|
|
79
|
+
/**
|
|
80
|
+
* One-shot prompt convenience function.
|
|
81
|
+
*
|
|
82
|
+
* Creates a session, sends the prompt, collects the response, and closes.
|
|
83
|
+
* Returns the final result message.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const result = await prompt('What is the capital of France?', {
|
|
88
|
+
* model: 'claude-sonnet-4-20250514'
|
|
89
|
+
* });
|
|
90
|
+
* if (result.success) {
|
|
91
|
+
* console.log(result.result);
|
|
92
|
+
* }
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function prompt(message: string, options?: SessionOptions): Promise<SDKResultMessage>;
|
|
96
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,EAAE,cAAc,EAAc,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG/E,YAAY,EACV,cAAc,EACd,UAAU,EACV,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAEnE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAET;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAChC,cAAc,EAAE,MAAM,EACtB,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAET;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,MAAM,CAC1B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,gBAAgB,CAAC,CA4B3B"}
|