agentfs-sdk 0.2.0-pre.1 → 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 CHANGED
@@ -7,11 +7,17 @@ import { ToolCalls } from './toolcalls';
7
7
  */
8
8
  export interface AgentFSOptions {
9
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
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
13
  */
14
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;
15
21
  }
16
22
  export declare class AgentFS {
17
23
  private db;
@@ -24,19 +30,21 @@ export declare class AgentFS {
24
30
  private constructor();
25
31
  /**
26
32
  * Open an agent filesystem
27
- * @param options Configuration options (optional id for persistent storage)
33
+ * @param options Configuration options (id and/or path required)
28
34
  * @returns Fully initialized AgentFS instance
29
35
  * @example
30
36
  * ```typescript
31
- * // Persistent storage
37
+ * // Using id (creates .agentfs/my-agent.db)
32
38
  * const agent = await AgentFS.open({ id: 'my-agent' });
33
- * // Creates: .agentfs/my-agent.db
34
39
  *
35
- * // Ephemeral in-memory database
36
- * const agent = await AgentFS.open();
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' });
37
45
  * ```
38
46
  */
39
- static open(options?: AgentFSOptions): Promise<AgentFS>;
47
+ static open(options: AgentFSOptions): Promise<AgentFS>;
40
48
  /**
41
49
  * Get the underlying Database instance
42
50
  */
package/dist/index.js CHANGED
@@ -18,38 +18,37 @@ class AgentFS {
18
18
  }
19
19
  /**
20
20
  * Open an agent filesystem
21
- * @param options Configuration options (optional id for persistent storage)
21
+ * @param options Configuration options (id and/or path required)
22
22
  * @returns Fully initialized AgentFS instance
23
23
  * @example
24
24
  * ```typescript
25
- * // Persistent storage
25
+ * // Using id (creates .agentfs/my-agent.db)
26
26
  * const agent = await AgentFS.open({ id: 'my-agent' });
27
- * // Creates: .agentfs/my-agent.db
28
27
  *
29
- * // Ephemeral in-memory database
30
- * const agent = await AgentFS.open();
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' });
31
33
  * ```
32
34
  */
33
35
  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.`);
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');
39
44
  }
40
- const { id } = options || {};
41
- // Determine database path based on id
45
+ // Determine database path: explicit path takes precedence, otherwise use id-based path
42
46
  let dbPath;
43
- if (!id) {
44
- // No id = ephemeral in-memory database
45
- dbPath = ':memory:';
47
+ if (path) {
48
+ dbPath = path;
46
49
  }
47
50
  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
51
+ // id is guaranteed to be defined here (we checked !id && !path above)
53
52
  const dir = '.agentfs';
54
53
  if (!(0, fs_1.existsSync)(dir)) {
55
54
  (0, fs_1.mkdirSync)(dir, { recursive: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentfs-sdk",
3
- "version": "0.2.0-pre.1",
3
+ "version": "0.2.0-pre.2",
4
4
  "description": "AgentFS SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",