@aigne/afs 1.1.2-beta → 1.1.2
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/CHANGELOG.md +9 -0
- package/README.md +335 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.1.2](https://github.com/AIGNE-io/aigne-framework/compare/afs-v1.1.2-beta...afs-v1.1.2) (2025-11-12)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Dependencies
|
|
7
|
+
|
|
8
|
+
* The following workspace dependencies were updated
|
|
9
|
+
* dependencies
|
|
10
|
+
* @aigne/sqlite bumped to 0.4.4
|
|
11
|
+
|
|
3
12
|
## [1.1.2-beta](https://github.com/AIGNE-io/aigne-framework/compare/afs-v1.1.1...afs-v1.1.2-beta) (2025-11-12)
|
|
4
13
|
|
|
5
14
|
|
package/README.md
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
# @aigne/afs
|
|
2
|
+
|
|
3
|
+
**@aigne/afs** is the core package of the AIGNE File System (AFS), providing a virtual file system abstraction layer that enables AI agents to access various storage backends through a unified, path-based API.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
AFS Core provides the foundational infrastructure for building virtual file systems that can integrate with different storage backends. It includes the base AFS implementation, storage layer abstraction, and the built-in history module for automatic conversation tracking.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Virtual File System**: Hierarchical path-based structure similar to Unix file systems
|
|
12
|
+
- **Module System**: Pluggable architecture for custom storage backends
|
|
13
|
+
- **Unified API**: Consistent interface for list, read, write, and search operations
|
|
14
|
+
- **Event System**: Event-driven architecture for module communication
|
|
15
|
+
- **SQLite Storage**: Built-in persistent storage using SQLite
|
|
16
|
+
- **History Tracking**: Automatic conversation history recording (AFSHistory module)
|
|
17
|
+
- **AI Agent Integration**: Seamless integration with AIGNE agents
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @aigne/afs
|
|
23
|
+
# or
|
|
24
|
+
yarn add @aigne/afs
|
|
25
|
+
# or
|
|
26
|
+
pnpm add @aigne/afs
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { AFS } from "@aigne/afs";
|
|
33
|
+
|
|
34
|
+
// Create AFS instance with SQLite storage
|
|
35
|
+
const afs = new AFS({
|
|
36
|
+
storage: { url: "file:./memory.sqlite3" }
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// List entries
|
|
40
|
+
const { list } = await afs.list('/');
|
|
41
|
+
|
|
42
|
+
// Read an entry
|
|
43
|
+
const { result } = await afs.read('/history/some-id');
|
|
44
|
+
|
|
45
|
+
// Write an entry
|
|
46
|
+
await afs.write('/my-data/notes.txt', {
|
|
47
|
+
content: 'My notes',
|
|
48
|
+
summary: 'Personal notes'
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Search for content
|
|
52
|
+
const { list: results } = await afs.search('/', 'search query');
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Core Concepts
|
|
56
|
+
|
|
57
|
+
### AFSEntry
|
|
58
|
+
|
|
59
|
+
All data in AFS is represented as `AFSEntry` objects:
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
interface AFSEntry {
|
|
63
|
+
id: string; // Unique identifier
|
|
64
|
+
path: string; // Full path in AFS
|
|
65
|
+
content?: any; // File/data content
|
|
66
|
+
summary?: string; // Optional summary
|
|
67
|
+
metadata?: Record<string, any>; // Custom metadata
|
|
68
|
+
createdAt?: Date; // Creation timestamp
|
|
69
|
+
updatedAt?: Date; // Last update timestamp
|
|
70
|
+
userId?: string; // Associated user
|
|
71
|
+
sessionId?: string; // Associated session
|
|
72
|
+
linkTo?: string; // Link to another entry
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Modules
|
|
77
|
+
|
|
78
|
+
Modules are pluggable components that implement storage backends:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
interface AFSModule {
|
|
82
|
+
moduleId: string; // Unique module identifier
|
|
83
|
+
path: string; // Mount path (e.g., '/history')
|
|
84
|
+
description?: string; // Description for AI agents
|
|
85
|
+
|
|
86
|
+
// Operations (all optional)
|
|
87
|
+
list?(path: string, options?: AFSListOptions): Promise<{ list: AFSEntry[] }>;
|
|
88
|
+
read?(path: string): Promise<{ result?: AFSEntry }>;
|
|
89
|
+
write?(path: string, entry: AFSWriteEntryPayload): Promise<{ result: AFSEntry }>;
|
|
90
|
+
search?(path: string, query: string, options?: AFSSearchOptions): Promise<{ list: AFSEntry[] }>;
|
|
91
|
+
|
|
92
|
+
// Lifecycle
|
|
93
|
+
onMount?(afs: AFSRoot): void;
|
|
94
|
+
onUnmount?(): void;
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## API Reference
|
|
99
|
+
|
|
100
|
+
### AFS Class
|
|
101
|
+
|
|
102
|
+
#### Constructor
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
new AFS(options: AFSOptions)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Options:
|
|
109
|
+
- `storage`: Storage configuration (e.g., `{ url: "file:./memory.sqlite3" }`)
|
|
110
|
+
- `historyEnabled`: Enable/disable automatic history tracking (default: `true`)
|
|
111
|
+
|
|
112
|
+
#### Methods
|
|
113
|
+
|
|
114
|
+
##### use(module: AFSModule)
|
|
115
|
+
|
|
116
|
+
Mount a module at its specified path:
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
afs.use(new CustomModule());
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
##### list(path: string, options?: AFSListOptions)
|
|
123
|
+
|
|
124
|
+
List entries in a directory:
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
const { list, message } = await afs.list('/history', {
|
|
128
|
+
maxDepth: 2,
|
|
129
|
+
recursive: true,
|
|
130
|
+
limit: 10,
|
|
131
|
+
orderBy: [['createdAt', 'desc']]
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Options:
|
|
136
|
+
- `maxDepth`: Maximum recursion depth
|
|
137
|
+
- `recursive`: Enable recursive listing
|
|
138
|
+
- `limit`: Maximum number of results
|
|
139
|
+
- `orderBy`: Sort order (array of `[field, direction]` tuples)
|
|
140
|
+
|
|
141
|
+
##### read(path: string)
|
|
142
|
+
|
|
143
|
+
Read a specific entry:
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
const { result, message } = await afs.read('/history/uuid-123');
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
##### write(path: string, content: AFSWriteEntryPayload)
|
|
150
|
+
|
|
151
|
+
Write or update an entry:
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
const { result, message } = await afs.write('/data/file.txt', {
|
|
155
|
+
content: 'Hello, world!',
|
|
156
|
+
summary: 'Greeting file',
|
|
157
|
+
metadata: { type: 'greeting' }
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
##### search(path: string, query: string, options?: AFSSearchOptions)
|
|
162
|
+
|
|
163
|
+
Search for content:
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
const { list, message } = await afs.search('/history', 'authentication', {
|
|
167
|
+
limit: 5
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Events
|
|
172
|
+
|
|
173
|
+
AFS uses an event system for module communication:
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
afs.on('historyCreated', ({ entry }) => {
|
|
177
|
+
console.log('New history entry:', entry);
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Available events:
|
|
182
|
+
- `historyCreated`: Emitted when a new history entry is created
|
|
183
|
+
|
|
184
|
+
## Built-in Modules
|
|
185
|
+
|
|
186
|
+
### AFSHistory
|
|
187
|
+
|
|
188
|
+
The history module automatically tracks conversation history.
|
|
189
|
+
|
|
190
|
+
**Features:**
|
|
191
|
+
- Automatically records agent interactions
|
|
192
|
+
- Stores input/output pairs with UUID paths
|
|
193
|
+
- Enables conversation history injection into agent prompts
|
|
194
|
+
- Supports semantic search
|
|
195
|
+
|
|
196
|
+
**Usage:**
|
|
197
|
+
|
|
198
|
+
History is enabled by default. To disable:
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
const afs = new AFS({
|
|
202
|
+
storage: { url: "file:./memory.sqlite3" },
|
|
203
|
+
historyEnabled: false
|
|
204
|
+
});
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**Integration with AI Agents:**
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
import { AIAgent, AIGNE } from "@aigne/core";
|
|
211
|
+
|
|
212
|
+
const agent = AIAgent.from({
|
|
213
|
+
name: "assistant",
|
|
214
|
+
afs: afs,
|
|
215
|
+
afsConfig: {
|
|
216
|
+
injectHistory: true, // Inject history into prompts
|
|
217
|
+
historyWindowSize: 10 // Number of recent entries
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Creating Custom Modules
|
|
223
|
+
|
|
224
|
+
Create a custom module by implementing the `AFSModule` interface:
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
import { AFSModule, AFSEntry, AFSStorage } from "@aigne/afs";
|
|
228
|
+
|
|
229
|
+
export class CustomModule implements AFSModule {
|
|
230
|
+
readonly moduleId = "custom-module";
|
|
231
|
+
readonly path = "/custom";
|
|
232
|
+
readonly description = "My custom storage";
|
|
233
|
+
|
|
234
|
+
constructor(private storage: AFSStorage) {}
|
|
235
|
+
|
|
236
|
+
async list(path: string, options?: AFSListOptions) {
|
|
237
|
+
const entries = await this.storage.list(options);
|
|
238
|
+
return { list: entries };
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
async read(path: string) {
|
|
242
|
+
const entry = await this.storage.read(path);
|
|
243
|
+
return { result: entry };
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
async write(path: string, content: AFSWriteEntryPayload) {
|
|
247
|
+
const entry = await this.storage.create({ ...content, path });
|
|
248
|
+
return { result: entry };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async search(path: string, query: string, options?: AFSSearchOptions) {
|
|
252
|
+
const results = await this.storage.list({
|
|
253
|
+
where: { content: { contains: query } }
|
|
254
|
+
});
|
|
255
|
+
return { list: results };
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
onMount(afs: AFSRoot) {
|
|
259
|
+
console.log(`${this.moduleId} mounted at ${this.path}`);
|
|
260
|
+
|
|
261
|
+
// Listen to events
|
|
262
|
+
afs.on('someEvent', (data) => {
|
|
263
|
+
// Handle event
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Use the module
|
|
269
|
+
afs.use(new CustomModule());
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## Storage Layer
|
|
273
|
+
|
|
274
|
+
AFS Core includes a SQLite-based storage layer that modules can use:
|
|
275
|
+
|
|
276
|
+
```typescript
|
|
277
|
+
// Get module-specific storage
|
|
278
|
+
const storage = afs.storage(myModule);
|
|
279
|
+
|
|
280
|
+
// Storage operations
|
|
281
|
+
await storage.create({ path: '/data', content: 'value' });
|
|
282
|
+
await storage.read('/data');
|
|
283
|
+
await storage.update('/data', { content: 'new value' });
|
|
284
|
+
await storage.delete('/data');
|
|
285
|
+
await storage.list({ where: { path: { startsWith: '/data' } } });
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Integration with AI Agents
|
|
289
|
+
|
|
290
|
+
When an agent has AFS configured, these tools are automatically registered:
|
|
291
|
+
|
|
292
|
+
- **afs_list**: Browse directory contents
|
|
293
|
+
- **afs_read**: Read file contents
|
|
294
|
+
- **afs_write**: Write/create files
|
|
295
|
+
- **afs_search**: Search for content
|
|
296
|
+
|
|
297
|
+
Example:
|
|
298
|
+
|
|
299
|
+
```typescript
|
|
300
|
+
import { AIAgent, AIGNE } from "@aigne/core";
|
|
301
|
+
import { AFS } from "@aigne/afs";
|
|
302
|
+
|
|
303
|
+
const afs = new AFS({ storage: { url: "file:./memory.sqlite3" } });
|
|
304
|
+
|
|
305
|
+
const agent = AIAgent.from({
|
|
306
|
+
name: "assistant",
|
|
307
|
+
afs: afs,
|
|
308
|
+
afsConfig: {
|
|
309
|
+
injectHistory: true,
|
|
310
|
+
historyWindowSize: 10
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
const context = aigne.newContext();
|
|
315
|
+
const result = await context.invoke(agent, {
|
|
316
|
+
message: "What's in my history?"
|
|
317
|
+
});
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## Related Packages
|
|
321
|
+
|
|
322
|
+
- [@aigne/afs-system-fs](../system-fs/README.md) - Local file system module
|
|
323
|
+
- [@aigne/afs-user-profile-memory](../user-profile-memory/README.md) - User profile memory module
|
|
324
|
+
|
|
325
|
+
## Examples
|
|
326
|
+
|
|
327
|
+
See the [AFS examples](../../examples/afs-system-fs) for complete usage examples.
|
|
328
|
+
|
|
329
|
+
## TypeScript Support
|
|
330
|
+
|
|
331
|
+
This package includes full TypeScript type definitions.
|
|
332
|
+
|
|
333
|
+
## License
|
|
334
|
+
|
|
335
|
+
[Elastic-2.0](../../LICENSE.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/afs",
|
|
3
|
-
"version": "1.1.2
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "AIGNE File System (AFS) is a virtual file system that supports various storage backends and provides a unified API for file operations.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@aigne/uuid": "^13.0.1",
|
|
51
51
|
"strict-event-emitter": "^0.5.1",
|
|
52
52
|
"ufo": "^1.6.1",
|
|
53
|
-
"@aigne/sqlite": "^0.4.4
|
|
53
|
+
"@aigne/sqlite": "^0.4.4"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/bun": "^1.2.22",
|