agentfs-sdk 0.1.2 → 0.2.0-pre.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/dist/index.d.ts +30 -2
- package/dist/index.js +36 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,23 @@ 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
|
+
* Unique identifier for the agent.
|
|
11
|
+
* - If provided without `path`: Creates storage at `.agentfs/{id}.db`
|
|
12
|
+
* - If provided with `path`: Uses the specified path
|
|
13
|
+
*/
|
|
14
|
+
id?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Explicit path to the database file.
|
|
17
|
+
* - If provided: Uses the specified path directly
|
|
18
|
+
* - Can be combined with `id`
|
|
19
|
+
*/
|
|
20
|
+
path?: string;
|
|
21
|
+
}
|
|
5
22
|
export declare class AgentFS {
|
|
6
23
|
private db;
|
|
7
24
|
readonly kv: KvStore;
|
|
@@ -13,10 +30,21 @@ export declare class AgentFS {
|
|
|
13
30
|
private constructor();
|
|
14
31
|
/**
|
|
15
32
|
* Open an agent filesystem
|
|
16
|
-
* @param
|
|
33
|
+
* @param options Configuration options (id and/or path required)
|
|
17
34
|
* @returns Fully initialized AgentFS instance
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* // Using id (creates .agentfs/my-agent.db)
|
|
38
|
+
* const agent = await AgentFS.open({ id: 'my-agent' });
|
|
39
|
+
*
|
|
40
|
+
* // Using id with custom path
|
|
41
|
+
* const agent = await AgentFS.open({ id: 'my-agent', path: './data/mydb.db' });
|
|
42
|
+
*
|
|
43
|
+
* // Using path only
|
|
44
|
+
* const agent = await AgentFS.open({ path: './data/mydb.db' });
|
|
45
|
+
* ```
|
|
18
46
|
*/
|
|
19
|
-
static open(
|
|
47
|
+
static open(options: AgentFSOptions): Promise<AgentFS>;
|
|
20
48
|
/**
|
|
21
49
|
* Get the underlying Database instance
|
|
22
50
|
*/
|
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,43 @@ class AgentFS {
|
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
20
|
* Open an agent filesystem
|
|
20
|
-
* @param
|
|
21
|
+
* @param options Configuration options (id and/or path required)
|
|
21
22
|
* @returns Fully initialized AgentFS instance
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* // Using id (creates .agentfs/my-agent.db)
|
|
26
|
+
* const agent = await AgentFS.open({ id: 'my-agent' });
|
|
27
|
+
*
|
|
28
|
+
* // Using id with custom path
|
|
29
|
+
* const agent = await AgentFS.open({ id: 'my-agent', path: './data/mydb.db' });
|
|
30
|
+
*
|
|
31
|
+
* // Using path only
|
|
32
|
+
* const agent = await AgentFS.open({ path: './data/mydb.db' });
|
|
33
|
+
* ```
|
|
22
34
|
*/
|
|
23
|
-
static async open(
|
|
35
|
+
static async open(options) {
|
|
36
|
+
const { id, path } = options;
|
|
37
|
+
// Require at least id or path
|
|
38
|
+
if (!id && !path) {
|
|
39
|
+
throw new Error("AgentFS.open() requires at least 'id' or 'path'.");
|
|
40
|
+
}
|
|
41
|
+
// Validate agent ID if provided
|
|
42
|
+
if (id && !/^[a-zA-Z0-9_-]+$/.test(id)) {
|
|
43
|
+
throw new Error('Agent ID must contain only alphanumeric characters, hyphens, and underscores');
|
|
44
|
+
}
|
|
45
|
+
// Determine database path: explicit path takes precedence, otherwise use id-based path
|
|
46
|
+
let dbPath;
|
|
47
|
+
if (path) {
|
|
48
|
+
dbPath = path;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
// id is guaranteed to be defined here (we checked !id && !path above)
|
|
52
|
+
const dir = '.agentfs';
|
|
53
|
+
if (!(0, fs_1.existsSync)(dir)) {
|
|
54
|
+
(0, fs_1.mkdirSync)(dir, { recursive: true });
|
|
55
|
+
}
|
|
56
|
+
dbPath = `${dir}/${id}.db`;
|
|
57
|
+
}
|
|
24
58
|
const db = new database_1.Database(dbPath);
|
|
25
59
|
// Connect to the database to ensure it's created
|
|
26
60
|
await db.connect();
|