formagent-sdk 0.1.2 → 0.2.0
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/README.md +58 -8
- package/dist/cli/index.js +1062 -52
- package/dist/index.js +1289 -56
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ A powerful AI Agent framework for building intelligent assistants with streaming
|
|
|
8
8
|
## Features
|
|
9
9
|
|
|
10
10
|
- **Session-Based API**: Multi-turn conversations with state management
|
|
11
|
+
- **Persistent Sessions**: File-based storage for session persistence across restarts
|
|
11
12
|
- **Streaming Support**: Real-time streaming of LLM responses with event-based notifications
|
|
12
13
|
- **Built-in Tools**: File operations, bash execution, web fetch, and task management
|
|
13
14
|
- **Tool System**: Flexible tool registration with Zod schema support
|
|
@@ -227,20 +228,68 @@ for await (const event of session.receive()) {
|
|
|
227
228
|
|
|
228
229
|
## Session Management
|
|
229
230
|
|
|
230
|
-
|
|
231
|
+
### Persistent Sessions
|
|
232
|
+
|
|
233
|
+
Enable session persistence with `FileSessionStorage`:
|
|
231
234
|
|
|
232
235
|
```typescript
|
|
233
|
-
import { createSession,
|
|
236
|
+
import { createSession, FileSessionStorage, builtinTools } from "formagent-sdk"
|
|
237
|
+
|
|
238
|
+
// Create persistent storage
|
|
239
|
+
const storage = new FileSessionStorage("./sessions")
|
|
240
|
+
|
|
241
|
+
// Create session with persistence
|
|
242
|
+
const session = await createSession({
|
|
243
|
+
model: "claude-sonnet-4-20250514",
|
|
244
|
+
tools: builtinTools,
|
|
245
|
+
sessionStorage: storage,
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
console.log(`Session ID: ${session.id}`) // Save this for later
|
|
249
|
+
await session.close()
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Resume Sessions
|
|
253
|
+
|
|
254
|
+
Resume a previous session with full conversation context:
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
import { createSession, FileSessionStorage } from "formagent-sdk"
|
|
258
|
+
|
|
259
|
+
const storage = new FileSessionStorage("./sessions")
|
|
234
260
|
|
|
235
|
-
//
|
|
261
|
+
// Resume from saved session ID
|
|
262
|
+
const session = await createSession({
|
|
263
|
+
sessionStorage: storage,
|
|
264
|
+
resume: "previous-session-id",
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
await session.send("Continue where we left off")
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Global Storage Configuration
|
|
271
|
+
|
|
272
|
+
Set a default storage for all sessions:
|
|
273
|
+
|
|
274
|
+
```typescript
|
|
275
|
+
import { setDefaultStorage, FileSessionStorage, createSession } from "formagent-sdk"
|
|
276
|
+
|
|
277
|
+
// Set once at startup
|
|
278
|
+
setDefaultStorage(new FileSessionStorage("./sessions"))
|
|
279
|
+
|
|
280
|
+
// All sessions now persist automatically
|
|
236
281
|
const session = await createSession({ model: "claude-sonnet-4-20250514" })
|
|
237
|
-
|
|
282
|
+
```
|
|
238
283
|
|
|
239
|
-
|
|
240
|
-
|
|
284
|
+
### Fork Sessions
|
|
285
|
+
|
|
286
|
+
Create a branch from an existing session:
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
import { forkSession } from "formagent-sdk"
|
|
241
290
|
|
|
242
|
-
//
|
|
243
|
-
const forked = await forkSession(
|
|
291
|
+
// Fork creates a new session with copied conversation history
|
|
292
|
+
const forked = await forkSession("original-session-id")
|
|
244
293
|
```
|
|
245
294
|
|
|
246
295
|
## Event Types
|
|
@@ -272,6 +321,7 @@ See the [examples](./examples) directory for complete examples:
|
|
|
272
321
|
|
|
273
322
|
- [Getting Started](./docs/getting-started.md)
|
|
274
323
|
- [API Reference](./docs/api-reference.md)
|
|
324
|
+
- [Session Storage](./docs/session-storage.md)
|
|
275
325
|
- [Built-in Tools](./docs/tools.md)
|
|
276
326
|
- [MCP Servers](./docs/mcp-servers.md)
|
|
277
327
|
|