@aigne/afs-history 1.1.3 → 1.2.0-beta.10

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +135 -0
  2. package/lib/cjs/index.d.ts +38 -13
  3. package/lib/cjs/index.js +244 -23
  4. package/lib/cjs/storage/index.d.ts +11 -7
  5. package/lib/cjs/storage/index.js +69 -23
  6. package/lib/cjs/storage/migrate.d.ts +1 -1
  7. package/lib/cjs/storage/migrate.js +15 -5
  8. package/lib/cjs/storage/migrations/002-add-agent-id.d.ts +2 -0
  9. package/lib/cjs/storage/migrations/002-add-agent-id.js +13 -0
  10. package/lib/cjs/storage/migrations/003-add-compact-table.d.ts +2 -0
  11. package/lib/cjs/storage/migrations/003-add-compact-table.js +23 -0
  12. package/lib/cjs/storage/migrations/004-add-memory-table.d.ts +2 -0
  13. package/lib/cjs/storage/migrations/004-add-memory-table.js +23 -0
  14. package/lib/cjs/storage/migrations/005-add-indexes.d.ts +2 -0
  15. package/lib/cjs/storage/migrations/005-add-indexes.js +31 -0
  16. package/lib/cjs/storage/models/compact.d.ts +183 -0
  17. package/lib/cjs/storage/models/compact.js +27 -0
  18. package/lib/cjs/storage/models/entries.d.ts +19 -0
  19. package/lib/cjs/storage/models/entries.js +1 -0
  20. package/lib/cjs/storage/models/memory.d.ts +182 -0
  21. package/lib/cjs/storage/models/memory.js +27 -0
  22. package/lib/cjs/storage/type.d.ts +33 -5
  23. package/lib/dts/index.d.ts +38 -13
  24. package/lib/dts/storage/index.d.ts +11 -7
  25. package/lib/dts/storage/migrate.d.ts +1 -1
  26. package/lib/dts/storage/migrations/002-add-agent-id.d.ts +2 -0
  27. package/lib/dts/storage/migrations/003-add-compact-table.d.ts +2 -0
  28. package/lib/dts/storage/migrations/004-add-memory-table.d.ts +2 -0
  29. package/lib/dts/storage/migrations/005-add-indexes.d.ts +2 -0
  30. package/lib/dts/storage/models/compact.d.ts +183 -0
  31. package/lib/dts/storage/models/entries.d.ts +19 -0
  32. package/lib/dts/storage/models/memory.d.ts +182 -0
  33. package/lib/dts/storage/type.d.ts +33 -5
  34. package/lib/esm/index.d.ts +38 -13
  35. package/lib/esm/index.js +244 -23
  36. package/lib/esm/storage/index.d.ts +11 -7
  37. package/lib/esm/storage/index.js +70 -24
  38. package/lib/esm/storage/migrate.d.ts +1 -1
  39. package/lib/esm/storage/migrate.js +15 -5
  40. package/lib/esm/storage/migrations/002-add-agent-id.d.ts +2 -0
  41. package/lib/esm/storage/migrations/002-add-agent-id.js +10 -0
  42. package/lib/esm/storage/migrations/003-add-compact-table.d.ts +2 -0
  43. package/lib/esm/storage/migrations/003-add-compact-table.js +20 -0
  44. package/lib/esm/storage/migrations/004-add-memory-table.d.ts +2 -0
  45. package/lib/esm/storage/migrations/004-add-memory-table.js +20 -0
  46. package/lib/esm/storage/migrations/005-add-indexes.d.ts +2 -0
  47. package/lib/esm/storage/migrations/005-add-indexes.js +28 -0
  48. package/lib/esm/storage/models/compact.d.ts +183 -0
  49. package/lib/esm/storage/models/compact.js +22 -0
  50. package/lib/esm/storage/models/entries.d.ts +19 -0
  51. package/lib/esm/storage/models/entries.js +1 -0
  52. package/lib/esm/storage/models/memory.d.ts +182 -0
  53. package/lib/esm/storage/models/memory.js +22 -0
  54. package/lib/esm/storage/type.d.ts +33 -5
  55. package/package.json +5 -3
@@ -4,8 +4,18 @@ exports.migrate = migrate;
4
4
  const sqlite_1 = require("@aigne/sqlite");
5
5
  const uuid_1 = require("@aigne/uuid");
6
6
  const _001_init_js_1 = require("./migrations/001-init.js");
7
+ const _002_add_agent_id_js_1 = require("./migrations/002-add-agent-id.js");
8
+ const _003_add_compact_table_js_1 = require("./migrations/003-add-compact-table.js");
9
+ const _004_add_memory_table_js_1 = require("./migrations/004-add-memory-table.js");
10
+ const _005_add_indexes_js_1 = require("./migrations/005-add-indexes.js");
7
11
  async function migrate(db, module) {
8
- const migrations = [_001_init_js_1.init];
12
+ const migrations = [
13
+ _001_init_js_1.init,
14
+ _002_add_agent_id_js_1.addAgentId,
15
+ _003_add_compact_table_js_1.addCompactTable,
16
+ _004_add_memory_table_js_1.addMemoryTable,
17
+ _005_add_indexes_js_1.addIndexes,
18
+ ];
9
19
  const migrationsTable = "__drizzle_migrations";
10
20
  const migrationTableCreate = (0, sqlite_1.sql) `
11
21
  CREATE TABLE IF NOT EXISTS ${sqlite_1.sql.identifier(migrationsTable)} (
@@ -14,18 +24,18 @@ async function migrate(db, module) {
14
24
  "hash" TEXT NOT NULL
15
25
  )
16
26
  `;
17
- await (await db).run(migrationTableCreate).execute();
18
- const dbMigrations = await (await db)
27
+ await db.run(migrationTableCreate).execute();
28
+ const dbMigrations = await db
19
29
  .values((0, sqlite_1.sql) `SELECT "id", "moduleId", "hash" FROM ${sqlite_1.sql.identifier(migrationsTable)} WHERE "moduleId" = ${sqlite_1.sql.param(module.name)} ORDER BY id DESC LIMIT 1`)
20
30
  .execute();
21
31
  const lastDbMigration = dbMigrations[0];
22
32
  const queriesToRun = [];
23
33
  for (const migration of migrations) {
24
- if (!lastDbMigration || lastDbMigration[1] < migration.hash) {
34
+ if (!lastDbMigration || lastDbMigration[2] < migration.hash) {
25
35
  queriesToRun.push(...migration.sql(module), (0, sqlite_1.sql) `INSERT INTO ${sqlite_1.sql.identifier(migrationsTable)} ("id", "moduleId", "hash") VALUES(${sqlite_1.sql.param((0, uuid_1.v7)())}, ${sqlite_1.sql.param(module.name)}, ${sqlite_1.sql.param(migration.hash)})`);
26
36
  }
27
37
  }
28
38
  for (const query of queriesToRun) {
29
- await (await db).run(query).execute();
39
+ await db.run(query).execute();
30
40
  }
31
41
  }
@@ -0,0 +1,2 @@
1
+ import type { AFSStorageMigrations } from "../type.js";
2
+ export declare const addAgentId: AFSStorageMigrations;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addAgentId = void 0;
4
+ const sqlite_1 = require("@aigne/sqlite");
5
+ const entries_js_1 = require("../models/entries.js");
6
+ exports.addAgentId = {
7
+ hash: "002-add-agent-id",
8
+ sql: (module) => [
9
+ (0, sqlite_1.sql) `\
10
+ ALTER TABLE ${sqlite_1.sql.identifier((0, entries_js_1.entriesTableName)(module))} ADD COLUMN "agentId" TEXT;
11
+ `,
12
+ ],
13
+ };
@@ -0,0 +1,2 @@
1
+ import type { AFSStorageMigrations } from "../type.js";
2
+ export declare const addCompactTable: AFSStorageMigrations;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addCompactTable = void 0;
4
+ const sqlite_1 = require("@aigne/sqlite");
5
+ const compact_js_1 = require("../models/compact.js");
6
+ exports.addCompactTable = {
7
+ hash: "003-add-compact-table",
8
+ sql: (module) => [
9
+ (0, sqlite_1.sql) `\
10
+ CREATE TABLE IF NOT EXISTS ${sqlite_1.sql.identifier((0, compact_js_1.compactTableName)(module))} (
11
+ "id" TEXT NOT NULL PRIMARY KEY,
12
+ "createdAt" DATETIME NOT NULL,
13
+ "updatedAt" DATETIME NOT NULL,
14
+ "path" TEXT NOT NULL,
15
+ "sessionId" TEXT,
16
+ "userId" TEXT,
17
+ "agentId" TEXT,
18
+ "metadata" JSON,
19
+ "content" JSON
20
+ )
21
+ `,
22
+ ],
23
+ };
@@ -0,0 +1,2 @@
1
+ import type { AFSStorageMigrations } from "../type.js";
2
+ export declare const addMemoryTable: AFSStorageMigrations;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addMemoryTable = void 0;
4
+ const sqlite_1 = require("@aigne/sqlite");
5
+ const memory_js_1 = require("../models/memory.js");
6
+ exports.addMemoryTable = {
7
+ hash: "004-add-memory-table",
8
+ sql: (module) => [
9
+ (0, sqlite_1.sql) `\
10
+ CREATE TABLE IF NOT EXISTS ${sqlite_1.sql.identifier((0, memory_js_1.memoryTableName)(module))} (
11
+ "id" TEXT NOT NULL PRIMARY KEY,
12
+ "createdAt" DATETIME NOT NULL,
13
+ "updatedAt" DATETIME NOT NULL,
14
+ "path" TEXT NOT NULL,
15
+ "sessionId" TEXT,
16
+ "userId" TEXT,
17
+ "agentId" TEXT,
18
+ "metadata" JSON,
19
+ "content" JSON
20
+ )
21
+ `,
22
+ ],
23
+ };
@@ -0,0 +1,2 @@
1
+ import type { AFSStorageMigrations } from "../type.js";
2
+ export declare const addIndexes: AFSStorageMigrations;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addIndexes = void 0;
4
+ const sqlite_1 = require("@aigne/sqlite");
5
+ const compact_js_1 = require("../models/compact.js");
6
+ const entries_js_1 = require("../models/entries.js");
7
+ const memory_js_1 = require("../models/memory.js");
8
+ exports.addIndexes = {
9
+ hash: "005-add-indexes",
10
+ sql: (module) => {
11
+ const entriesTable = (0, entries_js_1.entriesTableName)(module);
12
+ const memoryTable = (0, memory_js_1.memoryTableName)(module);
13
+ const compactTable = (0, compact_js_1.compactTableName)(module);
14
+ return [
15
+ // Entries table indexes
16
+ (0, sqlite_1.sql) `CREATE INDEX IF NOT EXISTS "idx_entries_session_created" ON ${sqlite_1.sql.identifier(entriesTable)} ("sessionId", "createdAt" DESC)`,
17
+ (0, sqlite_1.sql) `CREATE INDEX IF NOT EXISTS "idx_entries_user_created" ON ${sqlite_1.sql.identifier(entriesTable)} ("userId", "createdAt" DESC)`,
18
+ (0, sqlite_1.sql) `CREATE INDEX IF NOT EXISTS "idx_entries_agent_created" ON ${sqlite_1.sql.identifier(entriesTable)} ("agentId", "createdAt" DESC)`,
19
+ // Memory table indexes
20
+ (0, sqlite_1.sql) `CREATE INDEX IF NOT EXISTS "idx_memory_session_created" ON ${sqlite_1.sql.identifier(memoryTable)} ("sessionId", "createdAt" DESC)`,
21
+ (0, sqlite_1.sql) `CREATE INDEX IF NOT EXISTS "idx_memory_user_created" ON ${sqlite_1.sql.identifier(memoryTable)} ("userId", "createdAt" DESC)`,
22
+ (0, sqlite_1.sql) `CREATE INDEX IF NOT EXISTS "idx_memory_agent_created" ON ${sqlite_1.sql.identifier(memoryTable)} ("agentId", "createdAt" DESC)`,
23
+ (0, sqlite_1.sql) `CREATE INDEX IF NOT EXISTS "idx_memory_scope" ON ${sqlite_1.sql.identifier(memoryTable)} (json_extract("metadata", '$.scope'))`,
24
+ // Compact table indexes
25
+ (0, sqlite_1.sql) `CREATE INDEX IF NOT EXISTS "idx_compact_session_created" ON ${sqlite_1.sql.identifier(compactTable)} ("sessionId", "createdAt" DESC)`,
26
+ (0, sqlite_1.sql) `CREATE INDEX IF NOT EXISTS "idx_compact_user_created" ON ${sqlite_1.sql.identifier(compactTable)} ("userId", "createdAt" DESC)`,
27
+ (0, sqlite_1.sql) `CREATE INDEX IF NOT EXISTS "idx_compact_agent_created" ON ${sqlite_1.sql.identifier(compactTable)} ("agentId", "createdAt" DESC)`,
28
+ (0, sqlite_1.sql) `CREATE INDEX IF NOT EXISTS "idx_compact_scope" ON ${sqlite_1.sql.identifier(compactTable)} (json_extract("metadata", '$.scope'))`,
29
+ ];
30
+ },
31
+ };
@@ -0,0 +1,183 @@
1
+ import type { AFSModule } from "@aigne/afs";
2
+ export declare const compactTableName: (module: AFSModule) => string;
3
+ export declare const compactTable: (module: AFSModule) => import("@aigne/sqlite").SQLiteTableWithColumns<{
4
+ name: string;
5
+ schema: undefined;
6
+ columns: {
7
+ id: import("@aigne/sqlite").SQLiteColumn<{
8
+ name: "id";
9
+ tableName: string;
10
+ dataType: "string";
11
+ columnType: "SQLiteText";
12
+ data: string;
13
+ driverParam: string;
14
+ notNull: true;
15
+ hasDefault: true;
16
+ isPrimaryKey: true;
17
+ isAutoincrement: false;
18
+ hasRuntimeDefault: true;
19
+ enumValues: [string, ...string[]];
20
+ baseColumn: never;
21
+ identity: undefined;
22
+ generated: undefined;
23
+ }, {}, {
24
+ length: number | undefined;
25
+ }>;
26
+ createdAt: import("@aigne/sqlite").SQLiteColumn<{
27
+ name: "createdAt";
28
+ tableName: string;
29
+ dataType: "custom";
30
+ columnType: "SQLiteCustomColumn";
31
+ data: Date;
32
+ driverParam: string;
33
+ notNull: true;
34
+ hasDefault: true;
35
+ isPrimaryKey: false;
36
+ isAutoincrement: false;
37
+ hasRuntimeDefault: true;
38
+ enumValues: undefined;
39
+ baseColumn: never;
40
+ identity: undefined;
41
+ generated: undefined;
42
+ }, {}, {
43
+ sqliteColumnBuilderBrand: "SQLiteCustomColumnBuilderBrand";
44
+ }>;
45
+ updatedAt: import("@aigne/sqlite").SQLiteColumn<{
46
+ name: "updatedAt";
47
+ tableName: string;
48
+ dataType: "custom";
49
+ columnType: "SQLiteCustomColumn";
50
+ data: Date;
51
+ driverParam: string;
52
+ notNull: true;
53
+ hasDefault: true;
54
+ isPrimaryKey: false;
55
+ isAutoincrement: false;
56
+ hasRuntimeDefault: true;
57
+ enumValues: undefined;
58
+ baseColumn: never;
59
+ identity: undefined;
60
+ generated: undefined;
61
+ }, {}, {
62
+ sqliteColumnBuilderBrand: "SQLiteCustomColumnBuilderBrand";
63
+ }>;
64
+ path: import("@aigne/sqlite").SQLiteColumn<{
65
+ name: "path";
66
+ tableName: string;
67
+ dataType: "string";
68
+ columnType: "SQLiteText";
69
+ data: string;
70
+ driverParam: string;
71
+ notNull: true;
72
+ hasDefault: false;
73
+ isPrimaryKey: false;
74
+ isAutoincrement: false;
75
+ hasRuntimeDefault: false;
76
+ enumValues: [string, ...string[]];
77
+ baseColumn: never;
78
+ identity: undefined;
79
+ generated: undefined;
80
+ }, {}, {
81
+ length: number | undefined;
82
+ }>;
83
+ userId: import("@aigne/sqlite").SQLiteColumn<{
84
+ name: "userId";
85
+ tableName: string;
86
+ dataType: "string";
87
+ columnType: "SQLiteText";
88
+ data: string;
89
+ driverParam: string;
90
+ notNull: false;
91
+ hasDefault: false;
92
+ isPrimaryKey: false;
93
+ isAutoincrement: false;
94
+ hasRuntimeDefault: false;
95
+ enumValues: [string, ...string[]];
96
+ baseColumn: never;
97
+ identity: undefined;
98
+ generated: undefined;
99
+ }, {}, {
100
+ length: number | undefined;
101
+ }>;
102
+ sessionId: import("@aigne/sqlite").SQLiteColumn<{
103
+ name: "sessionId";
104
+ tableName: string;
105
+ dataType: "string";
106
+ columnType: "SQLiteText";
107
+ data: string;
108
+ driverParam: string;
109
+ notNull: false;
110
+ hasDefault: false;
111
+ isPrimaryKey: false;
112
+ isAutoincrement: false;
113
+ hasRuntimeDefault: false;
114
+ enumValues: [string, ...string[]];
115
+ baseColumn: never;
116
+ identity: undefined;
117
+ generated: undefined;
118
+ }, {}, {
119
+ length: number | undefined;
120
+ }>;
121
+ agentId: import("@aigne/sqlite").SQLiteColumn<{
122
+ name: "agentId";
123
+ tableName: string;
124
+ dataType: "string";
125
+ columnType: "SQLiteText";
126
+ data: string;
127
+ driverParam: string;
128
+ notNull: false;
129
+ hasDefault: false;
130
+ isPrimaryKey: false;
131
+ isAutoincrement: false;
132
+ hasRuntimeDefault: false;
133
+ enumValues: [string, ...string[]];
134
+ baseColumn: never;
135
+ identity: undefined;
136
+ generated: undefined;
137
+ }, {}, {
138
+ length: number | undefined;
139
+ }>;
140
+ metadata: import("@aigne/sqlite").SQLiteColumn<{
141
+ name: string;
142
+ tableName: string;
143
+ dataType: "custom";
144
+ columnType: "SQLiteCustomColumn";
145
+ data: {
146
+ scope?: string;
147
+ latestEntryId?: string;
148
+ } & Record<string, unknown>;
149
+ driverParam: string;
150
+ notNull: false;
151
+ hasDefault: false;
152
+ isPrimaryKey: false;
153
+ isAutoincrement: false;
154
+ hasRuntimeDefault: false;
155
+ enumValues: undefined;
156
+ baseColumn: never;
157
+ identity: undefined;
158
+ generated: undefined;
159
+ }, {}, {
160
+ sqliteColumnBuilderBrand: "SQLiteCustomColumnBuilderBrand";
161
+ }>;
162
+ content: import("@aigne/sqlite").SQLiteColumn<{
163
+ name: string;
164
+ tableName: string;
165
+ dataType: "custom";
166
+ columnType: "SQLiteCustomColumn";
167
+ data: unknown;
168
+ driverParam: string;
169
+ notNull: false;
170
+ hasDefault: false;
171
+ isPrimaryKey: false;
172
+ isAutoincrement: false;
173
+ hasRuntimeDefault: false;
174
+ enumValues: undefined;
175
+ baseColumn: never;
176
+ identity: undefined;
177
+ generated: undefined;
178
+ }, {}, {
179
+ sqliteColumnBuilderBrand: "SQLiteCustomColumnBuilderBrand";
180
+ }>;
181
+ };
182
+ dialect: "sqlite";
183
+ }>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compactTable = exports.compactTableName = void 0;
4
+ const sqlite_1 = require("@aigne/sqlite");
5
+ const uuid_1 = require("@aigne/uuid");
6
+ const compactTableName = (module) => `Entries_${module.name}_compact`;
7
+ exports.compactTableName = compactTableName;
8
+ const compactTable = (module) => (0, sqlite_1.sqliteTable)((0, exports.compactTableName)(module), {
9
+ id: (0, sqlite_1.text)("id")
10
+ .notNull()
11
+ .primaryKey()
12
+ .$defaultFn(() => (0, uuid_1.v7)()),
13
+ createdAt: (0, sqlite_1.datetime)("createdAt")
14
+ .notNull()
15
+ .$defaultFn(() => new Date()),
16
+ updatedAt: (0, sqlite_1.datetime)("updatedAt")
17
+ .notNull()
18
+ .$defaultFn(() => new Date())
19
+ .$onUpdateFn(() => new Date()),
20
+ path: (0, sqlite_1.text)("path").notNull(),
21
+ userId: (0, sqlite_1.text)("userId"),
22
+ sessionId: (0, sqlite_1.text)("sessionId"),
23
+ agentId: (0, sqlite_1.text)("agentId"),
24
+ metadata: (0, sqlite_1.json)("metadata"),
25
+ content: (0, sqlite_1.json)("content"),
26
+ });
27
+ exports.compactTable = compactTable;
@@ -80,6 +80,25 @@ export declare const entriesTable: (module: AFSModule) => import("@aigne/sqlite"
80
80
  }, {}, {
81
81
  length: number | undefined;
82
82
  }>;
83
+ agentId: import("@aigne/sqlite").SQLiteColumn<{
84
+ name: "agentId";
85
+ tableName: string;
86
+ dataType: "string";
87
+ columnType: "SQLiteText";
88
+ data: string;
89
+ driverParam: string;
90
+ notNull: false;
91
+ hasDefault: false;
92
+ isPrimaryKey: false;
93
+ isAutoincrement: false;
94
+ hasRuntimeDefault: false;
95
+ enumValues: [string, ...string[]];
96
+ baseColumn: never;
97
+ identity: undefined;
98
+ generated: undefined;
99
+ }, {}, {
100
+ length: number | undefined;
101
+ }>;
83
102
  userId: import("@aigne/sqlite").SQLiteColumn<{
84
103
  name: "userId";
85
104
  tableName: string;
@@ -18,6 +18,7 @@ const entriesTable = (module) => (0, sqlite_1.sqliteTable)((0, exports.entriesTa
18
18
  .$defaultFn(() => new Date())
19
19
  .$onUpdateFn(() => new Date()),
20
20
  path: (0, sqlite_1.text)("path").notNull(),
21
+ agentId: (0, sqlite_1.text)("agentId"),
21
22
  userId: (0, sqlite_1.text)("userId"),
22
23
  sessionId: (0, sqlite_1.text)("sessionId"),
23
24
  summary: (0, sqlite_1.text)("summary"),
@@ -0,0 +1,182 @@
1
+ import type { AFSModule } from "@aigne/afs";
2
+ export declare const memoryTableName: (module: AFSModule) => string;
3
+ export declare const memoryTable: (module: AFSModule) => import("@aigne/sqlite").SQLiteTableWithColumns<{
4
+ name: string;
5
+ schema: undefined;
6
+ columns: {
7
+ id: import("@aigne/sqlite").SQLiteColumn<{
8
+ name: "id";
9
+ tableName: string;
10
+ dataType: "string";
11
+ columnType: "SQLiteText";
12
+ data: string;
13
+ driverParam: string;
14
+ notNull: true;
15
+ hasDefault: true;
16
+ isPrimaryKey: true;
17
+ isAutoincrement: false;
18
+ hasRuntimeDefault: true;
19
+ enumValues: [string, ...string[]];
20
+ baseColumn: never;
21
+ identity: undefined;
22
+ generated: undefined;
23
+ }, {}, {
24
+ length: number | undefined;
25
+ }>;
26
+ createdAt: import("@aigne/sqlite").SQLiteColumn<{
27
+ name: "createdAt";
28
+ tableName: string;
29
+ dataType: "custom";
30
+ columnType: "SQLiteCustomColumn";
31
+ data: Date;
32
+ driverParam: string;
33
+ notNull: true;
34
+ hasDefault: true;
35
+ isPrimaryKey: false;
36
+ isAutoincrement: false;
37
+ hasRuntimeDefault: true;
38
+ enumValues: undefined;
39
+ baseColumn: never;
40
+ identity: undefined;
41
+ generated: undefined;
42
+ }, {}, {
43
+ sqliteColumnBuilderBrand: "SQLiteCustomColumnBuilderBrand";
44
+ }>;
45
+ updatedAt: import("@aigne/sqlite").SQLiteColumn<{
46
+ name: "updatedAt";
47
+ tableName: string;
48
+ dataType: "custom";
49
+ columnType: "SQLiteCustomColumn";
50
+ data: Date;
51
+ driverParam: string;
52
+ notNull: true;
53
+ hasDefault: true;
54
+ isPrimaryKey: false;
55
+ isAutoincrement: false;
56
+ hasRuntimeDefault: true;
57
+ enumValues: undefined;
58
+ baseColumn: never;
59
+ identity: undefined;
60
+ generated: undefined;
61
+ }, {}, {
62
+ sqliteColumnBuilderBrand: "SQLiteCustomColumnBuilderBrand";
63
+ }>;
64
+ path: import("@aigne/sqlite").SQLiteColumn<{
65
+ name: "path";
66
+ tableName: string;
67
+ dataType: "string";
68
+ columnType: "SQLiteText";
69
+ data: string;
70
+ driverParam: string;
71
+ notNull: true;
72
+ hasDefault: false;
73
+ isPrimaryKey: false;
74
+ isAutoincrement: false;
75
+ hasRuntimeDefault: false;
76
+ enumValues: [string, ...string[]];
77
+ baseColumn: never;
78
+ identity: undefined;
79
+ generated: undefined;
80
+ }, {}, {
81
+ length: number | undefined;
82
+ }>;
83
+ userId: import("@aigne/sqlite").SQLiteColumn<{
84
+ name: "userId";
85
+ tableName: string;
86
+ dataType: "string";
87
+ columnType: "SQLiteText";
88
+ data: string;
89
+ driverParam: string;
90
+ notNull: false;
91
+ hasDefault: false;
92
+ isPrimaryKey: false;
93
+ isAutoincrement: false;
94
+ hasRuntimeDefault: false;
95
+ enumValues: [string, ...string[]];
96
+ baseColumn: never;
97
+ identity: undefined;
98
+ generated: undefined;
99
+ }, {}, {
100
+ length: number | undefined;
101
+ }>;
102
+ sessionId: import("@aigne/sqlite").SQLiteColumn<{
103
+ name: "sessionId";
104
+ tableName: string;
105
+ dataType: "string";
106
+ columnType: "SQLiteText";
107
+ data: string;
108
+ driverParam: string;
109
+ notNull: false;
110
+ hasDefault: false;
111
+ isPrimaryKey: false;
112
+ isAutoincrement: false;
113
+ hasRuntimeDefault: false;
114
+ enumValues: [string, ...string[]];
115
+ baseColumn: never;
116
+ identity: undefined;
117
+ generated: undefined;
118
+ }, {}, {
119
+ length: number | undefined;
120
+ }>;
121
+ agentId: import("@aigne/sqlite").SQLiteColumn<{
122
+ name: "agentId";
123
+ tableName: string;
124
+ dataType: "string";
125
+ columnType: "SQLiteText";
126
+ data: string;
127
+ driverParam: string;
128
+ notNull: false;
129
+ hasDefault: false;
130
+ isPrimaryKey: false;
131
+ isAutoincrement: false;
132
+ hasRuntimeDefault: false;
133
+ enumValues: [string, ...string[]];
134
+ baseColumn: never;
135
+ identity: undefined;
136
+ generated: undefined;
137
+ }, {}, {
138
+ length: number | undefined;
139
+ }>;
140
+ metadata: import("@aigne/sqlite").SQLiteColumn<{
141
+ name: string;
142
+ tableName: string;
143
+ dataType: "custom";
144
+ columnType: "SQLiteCustomColumn";
145
+ data: {
146
+ scope?: string;
147
+ } & Record<string, unknown>;
148
+ driverParam: string;
149
+ notNull: false;
150
+ hasDefault: false;
151
+ isPrimaryKey: false;
152
+ isAutoincrement: false;
153
+ hasRuntimeDefault: false;
154
+ enumValues: undefined;
155
+ baseColumn: never;
156
+ identity: undefined;
157
+ generated: undefined;
158
+ }, {}, {
159
+ sqliteColumnBuilderBrand: "SQLiteCustomColumnBuilderBrand";
160
+ }>;
161
+ content: import("@aigne/sqlite").SQLiteColumn<{
162
+ name: string;
163
+ tableName: string;
164
+ dataType: "custom";
165
+ columnType: "SQLiteCustomColumn";
166
+ data: unknown;
167
+ driverParam: string;
168
+ notNull: false;
169
+ hasDefault: false;
170
+ isPrimaryKey: false;
171
+ isAutoincrement: false;
172
+ hasRuntimeDefault: false;
173
+ enumValues: undefined;
174
+ baseColumn: never;
175
+ identity: undefined;
176
+ generated: undefined;
177
+ }, {}, {
178
+ sqliteColumnBuilderBrand: "SQLiteCustomColumnBuilderBrand";
179
+ }>;
180
+ };
181
+ dialect: "sqlite";
182
+ }>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.memoryTable = exports.memoryTableName = void 0;
4
+ const sqlite_1 = require("@aigne/sqlite");
5
+ const uuid_1 = require("@aigne/uuid");
6
+ const memoryTableName = (module) => `Entries_${module.name}_memory`;
7
+ exports.memoryTableName = memoryTableName;
8
+ const memoryTable = (module) => (0, sqlite_1.sqliteTable)((0, exports.memoryTableName)(module), {
9
+ id: (0, sqlite_1.text)("id")
10
+ .notNull()
11
+ .primaryKey()
12
+ .$defaultFn(() => (0, uuid_1.v7)()),
13
+ createdAt: (0, sqlite_1.datetime)("createdAt")
14
+ .notNull()
15
+ .$defaultFn(() => new Date()),
16
+ updatedAt: (0, sqlite_1.datetime)("updatedAt")
17
+ .notNull()
18
+ .$defaultFn(() => new Date())
19
+ .$onUpdateFn(() => new Date()),
20
+ path: (0, sqlite_1.text)("path").notNull(),
21
+ userId: (0, sqlite_1.text)("userId"),
22
+ sessionId: (0, sqlite_1.text)("sessionId"),
23
+ agentId: (0, sqlite_1.text)("agentId"),
24
+ metadata: (0, sqlite_1.json)("metadata"),
25
+ content: (0, sqlite_1.json)("content"),
26
+ });
27
+ exports.memoryTable = memoryTable;
@@ -1,21 +1,49 @@
1
1
  import type { AFSEntry, AFSModule } from "@aigne/afs";
2
2
  import type { SQL } from "@aigne/sqlite";
3
- export interface AFSStorageCreatePayload extends Omit<AFSEntry, "id"> {
3
+ export interface AFSStorageCreatePayload extends AFSEntry {
4
4
  }
5
- export interface AFSStorageListOptions {
5
+ export interface AFSStorageTypeOptions {
6
+ type?: EntryType;
7
+ scope?: Scope;
8
+ }
9
+ export interface AFSStorageListOptions extends AFSStorageTypeOptions {
6
10
  filter?: {
11
+ agentId?: string;
7
12
  userId?: string;
8
13
  sessionId?: string;
14
+ before?: Date | string;
15
+ after?: Date | string;
9
16
  };
10
17
  limit?: number;
11
18
  orderBy?: [string, "asc" | "desc"][];
12
19
  }
20
+ export interface AFSStorageReadOptions extends AFSStorageTypeOptions {
21
+ filter?: {
22
+ agentId?: string;
23
+ userId?: string;
24
+ sessionId?: string;
25
+ };
26
+ }
27
+ export interface AFSStorageDeleteOptions extends AFSStorageTypeOptions {
28
+ filter?: {
29
+ agentId?: string;
30
+ userId?: string;
31
+ sessionId?: string;
32
+ };
33
+ }
34
+ export type EntryType = "history" | "compact" | "memory";
35
+ export type Scope = "session" | "user" | "agent";
36
+ export interface AFSStorageCreateOptions extends AFSStorageTypeOptions {
37
+ }
13
38
  export interface AFSStorage {
14
- create(entry: AFSStorageCreatePayload): Promise<AFSEntry>;
39
+ create(entry: AFSStorageCreatePayload, options?: AFSStorageCreateOptions): Promise<AFSEntry>;
15
40
  list(options?: AFSStorageListOptions): Promise<{
16
- list: AFSEntry[];
41
+ data: AFSEntry[];
42
+ }>;
43
+ read(id: string, options?: AFSStorageReadOptions): Promise<AFSEntry | undefined>;
44
+ delete(id: string, options?: AFSStorageDeleteOptions): Promise<{
45
+ deletedCount: number;
17
46
  }>;
18
- read(path: string): Promise<AFSEntry | undefined>;
19
47
  }
20
48
  export type AFSStorageMigrations = {
21
49
  hash: string;