agentfs-sdk 0.1.1 → 0.2.0-pre.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/dist/index.d.ts +22 -2
- package/dist/index.js +37 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,17 @@ import { Database } from '@tursodatabase/database';
|
|
|
2
2
|
import { KvStore } from './kvstore';
|
|
3
3
|
import { Filesystem } from './filesystem';
|
|
4
4
|
import { ToolCalls } from './toolcalls';
|
|
5
|
+
/**
|
|
6
|
+
* Configuration options for opening an AgentFS instance
|
|
7
|
+
*/
|
|
8
|
+
export interface AgentFSOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Optional unique identifier for the agent.
|
|
11
|
+
* - If provided: Creates persistent storage at `.agentfs/{id}.db`
|
|
12
|
+
* - If omitted: Uses ephemeral in-memory database
|
|
13
|
+
*/
|
|
14
|
+
id?: string;
|
|
15
|
+
}
|
|
5
16
|
export declare class AgentFS {
|
|
6
17
|
private db;
|
|
7
18
|
readonly kv: KvStore;
|
|
@@ -13,10 +24,19 @@ export declare class AgentFS {
|
|
|
13
24
|
private constructor();
|
|
14
25
|
/**
|
|
15
26
|
* Open an agent filesystem
|
|
16
|
-
* @param
|
|
27
|
+
* @param options Configuration options (optional id for persistent storage)
|
|
17
28
|
* @returns Fully initialized AgentFS instance
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // Persistent storage
|
|
32
|
+
* const agent = await AgentFS.open({ id: 'my-agent' });
|
|
33
|
+
* // Creates: .agentfs/my-agent.db
|
|
34
|
+
*
|
|
35
|
+
* // Ephemeral in-memory database
|
|
36
|
+
* const agent = await AgentFS.open();
|
|
37
|
+
* ```
|
|
18
38
|
*/
|
|
19
|
-
static open(
|
|
39
|
+
static open(options?: AgentFSOptions): Promise<AgentFS>;
|
|
20
40
|
/**
|
|
21
41
|
* Get the underlying Database instance
|
|
22
42
|
*/
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ToolCalls = exports.Filesystem = exports.KvStore = exports.AgentFS = void 0;
|
|
4
4
|
const database_1 = require("@tursodatabase/database");
|
|
5
|
+
const fs_1 = require("fs");
|
|
5
6
|
const kvstore_1 = require("./kvstore");
|
|
6
7
|
const filesystem_1 = require("./filesystem");
|
|
7
8
|
const toolcalls_1 = require("./toolcalls");
|
|
@@ -17,10 +18,44 @@ class AgentFS {
|
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
20
|
* Open an agent filesystem
|
|
20
|
-
* @param
|
|
21
|
+
* @param options Configuration options (optional id for persistent storage)
|
|
21
22
|
* @returns Fully initialized AgentFS instance
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* // Persistent storage
|
|
26
|
+
* const agent = await AgentFS.open({ id: 'my-agent' });
|
|
27
|
+
* // Creates: .agentfs/my-agent.db
|
|
28
|
+
*
|
|
29
|
+
* // Ephemeral in-memory database
|
|
30
|
+
* const agent = await AgentFS.open();
|
|
31
|
+
* ```
|
|
22
32
|
*/
|
|
23
|
-
static async open(
|
|
33
|
+
static async open(options) {
|
|
34
|
+
// Error handling for old API usage
|
|
35
|
+
if (typeof options === 'string') {
|
|
36
|
+
throw new Error(`AgentFS.open() no longer accepts string paths. ` +
|
|
37
|
+
`Please use: AgentFS.open({ id: 'your-id' }) for persistent storage, ` +
|
|
38
|
+
`or AgentFS.open() for ephemeral in-memory database.`);
|
|
39
|
+
}
|
|
40
|
+
const { id } = options || {};
|
|
41
|
+
// Determine database path based on id
|
|
42
|
+
let dbPath;
|
|
43
|
+
if (!id) {
|
|
44
|
+
// No id = ephemeral in-memory database
|
|
45
|
+
dbPath = ':memory:';
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// Validate agent ID to prevent path traversal attacks
|
|
49
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(id)) {
|
|
50
|
+
throw new Error('Agent ID must contain only alphanumeric characters, hyphens, and underscores');
|
|
51
|
+
}
|
|
52
|
+
// Ensure .agentfs directory exists
|
|
53
|
+
const dir = '.agentfs';
|
|
54
|
+
if (!(0, fs_1.existsSync)(dir)) {
|
|
55
|
+
(0, fs_1.mkdirSync)(dir, { recursive: true });
|
|
56
|
+
}
|
|
57
|
+
dbPath = `${dir}/${id}.db`;
|
|
58
|
+
}
|
|
24
59
|
const db = new database_1.Database(dbPath);
|
|
25
60
|
// Connect to the database to ensure it's created
|
|
26
61
|
await db.connect();
|