agentfs-sdk 0.3.0-pre.8 → 0.3.0-pre.9
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/agentfs.d.ts +39 -0
- package/dist/agentfs.js +27 -0
- package/dist/filesystem.d.ts +3 -2
- package/dist/filesystem.js +12 -13
- package/dist/index_browser.d.ts +11 -0
- package/dist/index_browser.js +18 -0
- package/dist/index_node.d.ts +28 -0
- package/dist/index_node.js +63 -0
- package/dist/kvstore.d.ts +2 -2
- package/dist/kvstore.js +2 -5
- package/dist/toolcalls.d.ts +2 -2
- package/dist/toolcalls.js +2 -5
- package/package.json +18 -4
- package/dist/index.d.ts +0 -62
- package/dist/index.js +0 -90
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { DatabasePromise } from '@tursodatabase/database-common';
|
|
2
|
+
import { KvStore } from './kvstore.js';
|
|
3
|
+
import { Filesystem } from './filesystem.js';
|
|
4
|
+
import { ToolCalls } from './toolcalls.js';
|
|
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
|
+
}
|
|
22
|
+
export declare class AgentFSCore {
|
|
23
|
+
private db;
|
|
24
|
+
readonly kv: KvStore;
|
|
25
|
+
readonly fs: Filesystem;
|
|
26
|
+
readonly tools: ToolCalls;
|
|
27
|
+
/**
|
|
28
|
+
* Private constructor - use AgentFS.open() instead
|
|
29
|
+
*/
|
|
30
|
+
protected constructor(db: DatabasePromise, kv: KvStore, fs: Filesystem, tools: ToolCalls);
|
|
31
|
+
/**
|
|
32
|
+
* Get the underlying Database instance
|
|
33
|
+
*/
|
|
34
|
+
getDatabase(): DatabasePromise;
|
|
35
|
+
/**
|
|
36
|
+
* Close the database connection
|
|
37
|
+
*/
|
|
38
|
+
close(): Promise<void>;
|
|
39
|
+
}
|
package/dist/agentfs.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export class AgentFSCore {
|
|
2
|
+
db;
|
|
3
|
+
kv;
|
|
4
|
+
fs;
|
|
5
|
+
tools;
|
|
6
|
+
/**
|
|
7
|
+
* Private constructor - use AgentFS.open() instead
|
|
8
|
+
*/
|
|
9
|
+
constructor(db, kv, fs, tools) {
|
|
10
|
+
this.db = db;
|
|
11
|
+
this.kv = kv;
|
|
12
|
+
this.fs = fs;
|
|
13
|
+
this.tools = tools;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get the underlying Database instance
|
|
17
|
+
*/
|
|
18
|
+
getDatabase() {
|
|
19
|
+
return this.db;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Close the database connection
|
|
23
|
+
*/
|
|
24
|
+
async close() {
|
|
25
|
+
await this.db.close();
|
|
26
|
+
}
|
|
27
|
+
}
|
package/dist/filesystem.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { DatabasePromise } from '@tursodatabase/database-common';
|
|
2
2
|
export interface Stats {
|
|
3
3
|
ino: number;
|
|
4
4
|
mode: number;
|
|
@@ -15,13 +15,14 @@ export interface Stats {
|
|
|
15
15
|
}
|
|
16
16
|
export declare class Filesystem {
|
|
17
17
|
private db;
|
|
18
|
+
private bufferCtor;
|
|
18
19
|
private rootIno;
|
|
19
20
|
private chunkSize;
|
|
20
21
|
private constructor();
|
|
21
22
|
/**
|
|
22
23
|
* Create a Filesystem from an existing database connection
|
|
23
24
|
*/
|
|
24
|
-
static fromDatabase(db:
|
|
25
|
+
static fromDatabase(db: DatabasePromise, b?: BufferConstructor): Promise<Filesystem>;
|
|
25
26
|
/**
|
|
26
27
|
* Get the configured chunk size
|
|
27
28
|
*/
|
package/dist/filesystem.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Filesystem = void 0;
|
|
4
1
|
// File types for mode field
|
|
5
2
|
const S_IFMT = 0o170000; // File type mask
|
|
6
3
|
const S_IFREG = 0o100000; // Regular file
|
|
@@ -10,17 +7,20 @@ const S_IFLNK = 0o120000; // Symbolic link
|
|
|
10
7
|
const DEFAULT_FILE_MODE = S_IFREG | 0o644; // Regular file, rw-r--r--
|
|
11
8
|
const DEFAULT_DIR_MODE = S_IFDIR | 0o755; // Directory, rwxr-xr-x
|
|
12
9
|
const DEFAULT_CHUNK_SIZE = 4096;
|
|
13
|
-
class Filesystem {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
export class Filesystem {
|
|
11
|
+
db;
|
|
12
|
+
bufferCtor;
|
|
13
|
+
rootIno = 1;
|
|
14
|
+
chunkSize = DEFAULT_CHUNK_SIZE;
|
|
15
|
+
constructor(db, b) {
|
|
17
16
|
this.db = db;
|
|
17
|
+
this.bufferCtor = b;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Create a Filesystem from an existing database connection
|
|
21
21
|
*/
|
|
22
|
-
static async fromDatabase(db) {
|
|
23
|
-
const fs = new Filesystem(db);
|
|
22
|
+
static async fromDatabase(db, b) {
|
|
23
|
+
const fs = new Filesystem(db, b ?? Buffer);
|
|
24
24
|
await fs.initialize();
|
|
25
25
|
return fs;
|
|
26
26
|
}
|
|
@@ -259,7 +259,7 @@ class Filesystem {
|
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
async updateFileContent(ino, content) {
|
|
262
|
-
const buffer = typeof content === 'string' ?
|
|
262
|
+
const buffer = typeof content === 'string' ? this.bufferCtor.from(content, 'utf-8') : content;
|
|
263
263
|
const now = Math.floor(Date.now() / 1000);
|
|
264
264
|
// Delete existing data chunks
|
|
265
265
|
const deleteStmt = this.db.prepare('DELETE FROM fs_data WHERE ino = ?');
|
|
@@ -303,12 +303,12 @@ class Filesystem {
|
|
|
303
303
|
const rows = await stmt.all(ino);
|
|
304
304
|
let combined;
|
|
305
305
|
if (rows.length === 0) {
|
|
306
|
-
combined =
|
|
306
|
+
combined = this.bufferCtor.alloc(0);
|
|
307
307
|
}
|
|
308
308
|
else {
|
|
309
309
|
// Concatenate all chunks
|
|
310
310
|
const buffers = rows.map(row => row.data);
|
|
311
|
-
combined =
|
|
311
|
+
combined = this.bufferCtor.concat(buffers);
|
|
312
312
|
}
|
|
313
313
|
// Update atime
|
|
314
314
|
const now = Math.floor(Date.now() / 1000);
|
|
@@ -390,4 +390,3 @@ class Filesystem {
|
|
|
390
390
|
};
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
|
-
exports.Filesystem = Filesystem;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AgentFSCore } from "./agentfs.js";
|
|
2
|
+
import { DatabasePromise } from "@tursodatabase/database-common";
|
|
3
|
+
export declare class AgentFS extends AgentFSCore {
|
|
4
|
+
static openWith(db: DatabasePromise): Promise<AgentFSCore>;
|
|
5
|
+
}
|
|
6
|
+
export { AgentFSOptions } from './agentfs.js';
|
|
7
|
+
export { KvStore } from './kvstore.js';
|
|
8
|
+
export { Filesystem } from './filesystem.js';
|
|
9
|
+
export type { Stats } from './filesystem.js';
|
|
10
|
+
export { ToolCalls } from './toolcalls.js';
|
|
11
|
+
export type { ToolCall, ToolCallStats } from './toolcalls.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AgentFSCore } from "./agentfs.js";
|
|
2
|
+
import { KvStore } from "./kvstore.js";
|
|
3
|
+
import { Filesystem } from "./filesystem.js";
|
|
4
|
+
import { ToolCalls } from "./toolcalls.js";
|
|
5
|
+
import { Buffer } from "buffer";
|
|
6
|
+
export class AgentFS extends AgentFSCore {
|
|
7
|
+
static async openWith(db) {
|
|
8
|
+
const [kv, fs, tools] = await Promise.all([
|
|
9
|
+
KvStore.fromDatabase(db),
|
|
10
|
+
Filesystem.fromDatabase(db, Buffer),
|
|
11
|
+
ToolCalls.fromDatabase(db),
|
|
12
|
+
]);
|
|
13
|
+
return new AgentFS(db, kv, fs, tools);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export { KvStore } from './kvstore.js';
|
|
17
|
+
export { Filesystem } from './filesystem.js';
|
|
18
|
+
export { ToolCalls } from './toolcalls.js';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AgentFSCore, AgentFSOptions } from "./agentfs.js";
|
|
2
|
+
import { DatabasePromise } from "@tursodatabase/database-common";
|
|
3
|
+
export declare class AgentFS extends AgentFSCore {
|
|
4
|
+
/**
|
|
5
|
+
* Open an agent filesystem
|
|
6
|
+
* @param options Configuration options (id and/or path required)
|
|
7
|
+
* @returns Fully initialized AgentFS instance
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Using id (creates .agentfs/my-agent.db)
|
|
11
|
+
* const agent = await AgentFS.open({ id: 'my-agent' });
|
|
12
|
+
*
|
|
13
|
+
* // Using id with custom path
|
|
14
|
+
* const agent = await AgentFS.open({ id: 'my-agent', path: './data/mydb.db' });
|
|
15
|
+
*
|
|
16
|
+
* // Using path only
|
|
17
|
+
* const agent = await AgentFS.open({ path: './data/mydb.db' });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
static open(options: AgentFSOptions): Promise<AgentFS>;
|
|
21
|
+
static openWith(db: DatabasePromise): Promise<AgentFSCore>;
|
|
22
|
+
}
|
|
23
|
+
export { AgentFSOptions } from './agentfs.js';
|
|
24
|
+
export { KvStore } from './kvstore.js';
|
|
25
|
+
export { Filesystem } from './filesystem.js';
|
|
26
|
+
export type { Stats } from './filesystem.js';
|
|
27
|
+
export { ToolCalls } from './toolcalls.js';
|
|
28
|
+
export type { ToolCall, ToolCallStats } from './toolcalls.js';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Database } from "@tursodatabase/database";
|
|
2
|
+
import { existsSync, mkdirSync } from "fs";
|
|
3
|
+
import { AgentFSCore } from "./agentfs.js";
|
|
4
|
+
import { KvStore } from "./kvstore.js";
|
|
5
|
+
import { Filesystem } from "./filesystem.js";
|
|
6
|
+
import { ToolCalls } from "./toolcalls.js";
|
|
7
|
+
export class AgentFS extends AgentFSCore {
|
|
8
|
+
/**
|
|
9
|
+
* Open an agent filesystem
|
|
10
|
+
* @param options Configuration options (id and/or path required)
|
|
11
|
+
* @returns Fully initialized AgentFS instance
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Using id (creates .agentfs/my-agent.db)
|
|
15
|
+
* const agent = await AgentFS.open({ id: 'my-agent' });
|
|
16
|
+
*
|
|
17
|
+
* // Using id with custom path
|
|
18
|
+
* const agent = await AgentFS.open({ id: 'my-agent', path: './data/mydb.db' });
|
|
19
|
+
*
|
|
20
|
+
* // Using path only
|
|
21
|
+
* const agent = await AgentFS.open({ path: './data/mydb.db' });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
static async open(options) {
|
|
25
|
+
const { id, path } = options;
|
|
26
|
+
// Require at least id or path
|
|
27
|
+
if (!id && !path) {
|
|
28
|
+
throw new Error("AgentFS.open() requires at least 'id' or 'path'.");
|
|
29
|
+
}
|
|
30
|
+
// Validate agent ID if provided
|
|
31
|
+
if (id && !/^[a-zA-Z0-9_-]+$/.test(id)) {
|
|
32
|
+
throw new Error('Agent ID must contain only alphanumeric characters, hyphens, and underscores');
|
|
33
|
+
}
|
|
34
|
+
// Determine database path: explicit path takes precedence, otherwise use id-based path
|
|
35
|
+
let dbPath;
|
|
36
|
+
if (path) {
|
|
37
|
+
dbPath = path;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// id is guaranteed to be defined here (we checked !id && !path above)
|
|
41
|
+
const dir = '.agentfs';
|
|
42
|
+
if (!existsSync(dir)) {
|
|
43
|
+
mkdirSync(dir, { recursive: true });
|
|
44
|
+
}
|
|
45
|
+
dbPath = `${dir}/${id}.db`;
|
|
46
|
+
}
|
|
47
|
+
const db = new Database(dbPath);
|
|
48
|
+
// Connect to the database to ensure it's created
|
|
49
|
+
await db.connect();
|
|
50
|
+
return await this.openWith(db);
|
|
51
|
+
}
|
|
52
|
+
static async openWith(db) {
|
|
53
|
+
const [kv, fs, tools] = await Promise.all([
|
|
54
|
+
KvStore.fromDatabase(db),
|
|
55
|
+
Filesystem.fromDatabase(db),
|
|
56
|
+
ToolCalls.fromDatabase(db),
|
|
57
|
+
]);
|
|
58
|
+
return new AgentFS(db, kv, fs, tools);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export { KvStore } from './kvstore.js';
|
|
62
|
+
export { Filesystem } from './filesystem.js';
|
|
63
|
+
export { ToolCalls } from './toolcalls.js';
|
package/dist/kvstore.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { DatabasePromise } from '@tursodatabase/database-common';
|
|
2
2
|
export declare class KvStore {
|
|
3
3
|
private db;
|
|
4
4
|
private constructor();
|
|
5
5
|
/**
|
|
6
6
|
* Create a KvStore from an existing database connection
|
|
7
7
|
*/
|
|
8
|
-
static fromDatabase(db:
|
|
8
|
+
static fromDatabase(db: DatabasePromise): Promise<KvStore>;
|
|
9
9
|
private initialize;
|
|
10
10
|
set(key: string, value: any): Promise<void>;
|
|
11
11
|
get<T = any>(key: string): Promise<T | undefined>;
|
package/dist/kvstore.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.KvStore = void 0;
|
|
4
|
-
class KvStore {
|
|
1
|
+
export class KvStore {
|
|
2
|
+
db;
|
|
5
3
|
constructor(db) {
|
|
6
4
|
this.db = db;
|
|
7
5
|
}
|
|
@@ -62,4 +60,3 @@ class KvStore {
|
|
|
62
60
|
await stmt.run(key);
|
|
63
61
|
}
|
|
64
62
|
}
|
|
65
|
-
exports.KvStore = KvStore;
|
package/dist/toolcalls.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { DatabasePromise } from '@tursodatabase/database-common';
|
|
2
2
|
export interface ToolCall {
|
|
3
3
|
id: number;
|
|
4
4
|
name: string;
|
|
@@ -23,7 +23,7 @@ export declare class ToolCalls {
|
|
|
23
23
|
/**
|
|
24
24
|
* Create a ToolCalls from an existing database connection
|
|
25
25
|
*/
|
|
26
|
-
static fromDatabase(db:
|
|
26
|
+
static fromDatabase(db: DatabasePromise): Promise<ToolCalls>;
|
|
27
27
|
private initialize;
|
|
28
28
|
/**
|
|
29
29
|
* Start a new tool call and mark it as pending
|
package/dist/toolcalls.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ToolCalls = void 0;
|
|
4
|
-
class ToolCalls {
|
|
1
|
+
export class ToolCalls {
|
|
2
|
+
db;
|
|
5
3
|
constructor(db) {
|
|
6
4
|
this.db = db;
|
|
7
5
|
}
|
|
@@ -194,4 +192,3 @@ class ToolCalls {
|
|
|
194
192
|
};
|
|
195
193
|
}
|
|
196
194
|
}
|
|
197
|
-
exports.ToolCalls = ToolCalls;
|
package/package.json
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentfs-sdk",
|
|
3
|
-
"version": "0.3.0-pre.
|
|
3
|
+
"version": "0.3.0-pre.9",
|
|
4
4
|
"description": "AgentFS SDK",
|
|
5
|
-
"main": "dist/
|
|
6
|
-
"types": "dist/
|
|
5
|
+
"main": "dist/index_node.js",
|
|
6
|
+
"types": "dist/index_node.d.ts",
|
|
7
7
|
"packageManager": "npm@10.9.0",
|
|
8
|
+
"type": "module",
|
|
8
9
|
"scripts": {
|
|
9
10
|
"build": "tsc",
|
|
10
11
|
"watch": "tsc --watch",
|
|
11
12
|
"test": "vitest run",
|
|
13
|
+
"test:browser": "CI=1 vitest -c vitest.browser.config.ts --browser=chromium --run && CI=1 vitest -c vitest.browser.config.ts --browser=firefox --run",
|
|
12
14
|
"test:watch": "vitest watch",
|
|
13
15
|
"test:ui": "vitest --ui",
|
|
14
16
|
"test:coverage": "vitest run --coverage",
|
|
15
17
|
"prepublishOnly": "npm run build"
|
|
16
18
|
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"node": "./dist/index_node.js",
|
|
22
|
+
"browser": "./dist/index_browser.js",
|
|
23
|
+
"default": "./dist/index_node.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
17
26
|
"keywords": [
|
|
18
27
|
"ai",
|
|
19
28
|
"agent",
|
|
@@ -29,13 +38,18 @@
|
|
|
29
38
|
"url": "https://github.com/tursodatabase/agentfs"
|
|
30
39
|
},
|
|
31
40
|
"devDependencies": {
|
|
41
|
+
"@tursodatabase/database-wasm": "^0.4.0-pre.17",
|
|
32
42
|
"@types/node": "^20.0.0",
|
|
43
|
+
"@vitest/browser": "^4.0.16",
|
|
44
|
+
"@vitest/browser-playwright": "^4.0.16",
|
|
33
45
|
"@vitest/ui": "^4.0.1",
|
|
34
46
|
"typescript": "^5.3.0",
|
|
35
47
|
"vitest": "^4.0.1"
|
|
36
48
|
},
|
|
37
49
|
"dependencies": {
|
|
38
|
-
"@tursodatabase/database": "^0.4.0-pre.17"
|
|
50
|
+
"@tursodatabase/database": "^0.4.0-pre.17",
|
|
51
|
+
"@tursodatabase/database-common": "^0.4.0-pre.17",
|
|
52
|
+
"buffer": "^6.0.3"
|
|
39
53
|
},
|
|
40
54
|
"files": [
|
|
41
55
|
"dist"
|
package/dist/index.d.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { Database } from '@tursodatabase/database';
|
|
2
|
-
import { KvStore } from './kvstore';
|
|
3
|
-
import { Filesystem } from './filesystem';
|
|
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
|
-
}
|
|
22
|
-
export declare class AgentFS {
|
|
23
|
-
private db;
|
|
24
|
-
readonly kv: KvStore;
|
|
25
|
-
readonly fs: Filesystem;
|
|
26
|
-
readonly tools: ToolCalls;
|
|
27
|
-
/**
|
|
28
|
-
* Private constructor - use AgentFS.open() instead
|
|
29
|
-
*/
|
|
30
|
-
private constructor();
|
|
31
|
-
/**
|
|
32
|
-
* Open an agent filesystem
|
|
33
|
-
* @param options Configuration options (id and/or path required)
|
|
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
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
static open(options: AgentFSOptions): Promise<AgentFS>;
|
|
48
|
-
static openWith(db: Database): Promise<AgentFS>;
|
|
49
|
-
/**
|
|
50
|
-
* Get the underlying Database instance
|
|
51
|
-
*/
|
|
52
|
-
getDatabase(): Database;
|
|
53
|
-
/**
|
|
54
|
-
* Close the database connection
|
|
55
|
-
*/
|
|
56
|
-
close(): Promise<void>;
|
|
57
|
-
}
|
|
58
|
-
export { KvStore } from './kvstore';
|
|
59
|
-
export { Filesystem } from './filesystem';
|
|
60
|
-
export type { Stats } from './filesystem';
|
|
61
|
-
export { ToolCalls } from './toolcalls';
|
|
62
|
-
export type { ToolCall, ToolCallStats } from './toolcalls';
|
package/dist/index.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ToolCalls = exports.Filesystem = exports.KvStore = exports.AgentFS = void 0;
|
|
4
|
-
const database_1 = require("@tursodatabase/database");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const kvstore_1 = require("./kvstore");
|
|
7
|
-
const filesystem_1 = require("./filesystem");
|
|
8
|
-
const toolcalls_1 = require("./toolcalls");
|
|
9
|
-
class AgentFS {
|
|
10
|
-
/**
|
|
11
|
-
* Private constructor - use AgentFS.open() instead
|
|
12
|
-
*/
|
|
13
|
-
constructor(db, kv, fs, tools) {
|
|
14
|
-
this.db = db;
|
|
15
|
-
this.kv = kv;
|
|
16
|
-
this.fs = fs;
|
|
17
|
-
this.tools = tools;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Open an agent filesystem
|
|
21
|
-
* @param options Configuration options (id and/or path required)
|
|
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
|
-
* ```
|
|
34
|
-
*/
|
|
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
|
-
}
|
|
58
|
-
const db = new database_1.Database(dbPath);
|
|
59
|
-
// Connect to the database to ensure it's created
|
|
60
|
-
await db.connect();
|
|
61
|
-
return await AgentFS.openWith(db);
|
|
62
|
-
}
|
|
63
|
-
static async openWith(db) {
|
|
64
|
-
const [kv, fs, tools] = await Promise.all([
|
|
65
|
-
kvstore_1.KvStore.fromDatabase(db),
|
|
66
|
-
filesystem_1.Filesystem.fromDatabase(db),
|
|
67
|
-
toolcalls_1.ToolCalls.fromDatabase(db),
|
|
68
|
-
]);
|
|
69
|
-
return new AgentFS(db, kv, fs, tools);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Get the underlying Database instance
|
|
73
|
-
*/
|
|
74
|
-
getDatabase() {
|
|
75
|
-
return this.db;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Close the database connection
|
|
79
|
-
*/
|
|
80
|
-
async close() {
|
|
81
|
-
await this.db.close();
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
exports.AgentFS = AgentFS;
|
|
85
|
-
var kvstore_2 = require("./kvstore");
|
|
86
|
-
Object.defineProperty(exports, "KvStore", { enumerable: true, get: function () { return kvstore_2.KvStore; } });
|
|
87
|
-
var filesystem_2 = require("./filesystem");
|
|
88
|
-
Object.defineProperty(exports, "Filesystem", { enumerable: true, get: function () { return filesystem_2.Filesystem; } });
|
|
89
|
-
var toolcalls_2 = require("./toolcalls");
|
|
90
|
-
Object.defineProperty(exports, "ToolCalls", { enumerable: true, get: function () { return toolcalls_2.ToolCalls; } });
|