@aigne/afs-history 1.2.0-beta.4 → 1.2.0-beta.6
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/CHANGELOG.md +21 -0
- package/lib/cjs/index.d.ts +9 -3
- package/lib/cjs/index.js +217 -22
- package/lib/cjs/storage/index.d.ts +10 -6
- package/lib/cjs/storage/index.js +67 -21
- package/lib/cjs/storage/migrate.d.ts +1 -1
- package/lib/cjs/storage/migrate.js +14 -5
- package/lib/cjs/storage/migrations/003-add-compact-table.d.ts +2 -0
- package/lib/cjs/storage/migrations/003-add-compact-table.js +23 -0
- package/lib/cjs/storage/migrations/004-add-memory-table.d.ts +2 -0
- package/lib/cjs/storage/migrations/004-add-memory-table.js +23 -0
- package/lib/cjs/storage/migrations/005-add-indexes.d.ts +2 -0
- package/lib/cjs/storage/migrations/005-add-indexes.js +31 -0
- package/lib/cjs/storage/models/compact.d.ts +183 -0
- package/lib/cjs/storage/models/compact.js +27 -0
- package/lib/cjs/storage/models/memory.d.ts +182 -0
- package/lib/cjs/storage/models/memory.js +27 -0
- package/lib/cjs/storage/type.d.ts +31 -4
- package/lib/dts/index.d.ts +9 -3
- package/lib/dts/storage/index.d.ts +10 -6
- package/lib/dts/storage/migrate.d.ts +1 -1
- package/lib/dts/storage/migrations/003-add-compact-table.d.ts +2 -0
- package/lib/dts/storage/migrations/004-add-memory-table.d.ts +2 -0
- package/lib/dts/storage/migrations/005-add-indexes.d.ts +2 -0
- package/lib/dts/storage/models/compact.d.ts +183 -0
- package/lib/dts/storage/models/memory.d.ts +182 -0
- package/lib/dts/storage/type.d.ts +31 -4
- package/lib/esm/index.d.ts +9 -3
- package/lib/esm/index.js +217 -22
- package/lib/esm/storage/index.d.ts +10 -6
- package/lib/esm/storage/index.js +68 -22
- package/lib/esm/storage/migrate.d.ts +1 -1
- package/lib/esm/storage/migrate.js +14 -5
- package/lib/esm/storage/migrations/003-add-compact-table.d.ts +2 -0
- package/lib/esm/storage/migrations/003-add-compact-table.js +20 -0
- package/lib/esm/storage/migrations/004-add-memory-table.d.ts +2 -0
- package/lib/esm/storage/migrations/004-add-memory-table.js +20 -0
- package/lib/esm/storage/migrations/005-add-indexes.d.ts +2 -0
- package/lib/esm/storage/migrations/005-add-indexes.js +28 -0
- package/lib/esm/storage/models/compact.d.ts +183 -0
- package/lib/esm/storage/models/compact.js +22 -0
- package/lib/esm/storage/models/memory.d.ts +182 -0
- package/lib/esm/storage/models/memory.js +22 -0
- package/lib/esm/storage/type.d.ts +31 -4
- package/package.json +3 -2
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { AFSEntry, AFSModule } from "@aigne/afs";
|
|
2
2
|
import { initDatabase } from "@aigne/sqlite";
|
|
3
|
-
import {
|
|
4
|
-
import type { AFSStorage, AFSStorageCreatePayload, AFSStorageListOptions } from "./type.js";
|
|
3
|
+
import type { AFSStorage, AFSStorageCreateOptions, AFSStorageCreatePayload, AFSStorageDeleteOptions, AFSStorageListOptions, AFSStorageReadOptions } from "./type.js";
|
|
5
4
|
export * from "./type.js";
|
|
6
5
|
export interface SharedAFSStorageOptions {
|
|
7
6
|
url?: string;
|
|
@@ -17,11 +16,16 @@ export declare class SharedAFSStorage {
|
|
|
17
16
|
}
|
|
18
17
|
export declare class AFSStorageWithModule implements AFSStorage {
|
|
19
18
|
private db;
|
|
20
|
-
private
|
|
21
|
-
constructor(db: ReturnType<typeof initDatabase>,
|
|
19
|
+
private module;
|
|
20
|
+
constructor(db: ReturnType<typeof initDatabase>, module: AFSModule);
|
|
21
|
+
private _tables?;
|
|
22
|
+
private get tables();
|
|
22
23
|
list(options?: AFSStorageListOptions): Promise<{
|
|
23
24
|
data: AFSEntry[];
|
|
24
25
|
}>;
|
|
25
|
-
read(
|
|
26
|
-
create(entry: AFSStorageCreatePayload): Promise<AFSEntry>;
|
|
26
|
+
read(id: string, options?: AFSStorageReadOptions): Promise<AFSEntry | undefined>;
|
|
27
|
+
create(entry: AFSStorageCreatePayload, options?: AFSStorageCreateOptions): Promise<AFSEntry>;
|
|
28
|
+
delete(id: string, options?: AFSStorageDeleteOptions): Promise<{
|
|
29
|
+
deletedCount: number;
|
|
30
|
+
}>;
|
|
27
31
|
}
|
package/lib/esm/storage/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { and, asc, desc, eq, initDatabase, sql } from "@aigne/sqlite";
|
|
1
|
+
import { and, asc, desc, eq, gt, initDatabase, lt, sql } from "@aigne/sqlite";
|
|
2
2
|
import { migrate } from "./migrate.js";
|
|
3
|
+
import { compactTable } from "./models/compact.js";
|
|
3
4
|
import { entriesTable } from "./models/entries.js";
|
|
5
|
+
import { memoryTable } from "./models/memory.js";
|
|
4
6
|
export * from "./type.js";
|
|
5
7
|
const DEFAULT_AFS_STORAGE_LIST_LIMIT = 10;
|
|
6
8
|
export class SharedAFSStorage {
|
|
@@ -14,55 +16,99 @@ export class SharedAFSStorage {
|
|
|
14
16
|
return this._db;
|
|
15
17
|
}
|
|
16
18
|
withModule(module) {
|
|
17
|
-
return new AFSStorageWithModule(this.db,
|
|
19
|
+
return new AFSStorageWithModule(this.db, module);
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
export class AFSStorageWithModule {
|
|
21
23
|
db;
|
|
22
|
-
|
|
23
|
-
constructor(db,
|
|
24
|
+
module;
|
|
25
|
+
constructor(db, module) {
|
|
24
26
|
this.db = db;
|
|
25
|
-
this.
|
|
27
|
+
this.module = module;
|
|
28
|
+
}
|
|
29
|
+
_tables;
|
|
30
|
+
get tables() {
|
|
31
|
+
if (!this._tables) {
|
|
32
|
+
this._tables = this.db.then((db) => migrate(db, this.module).then(() => ({
|
|
33
|
+
db,
|
|
34
|
+
entries: entriesTable(this.module),
|
|
35
|
+
compact: compactTable(this.module),
|
|
36
|
+
memory: memoryTable(this.module),
|
|
37
|
+
})));
|
|
38
|
+
}
|
|
39
|
+
return this._tables;
|
|
26
40
|
}
|
|
27
41
|
async list(options = {}) {
|
|
28
|
-
const { filter, limit = DEFAULT_AFS_STORAGE_LIST_LIMIT } = options;
|
|
29
|
-
const db = await this.
|
|
30
|
-
|
|
42
|
+
const { type = "history", scope, filter, limit = DEFAULT_AFS_STORAGE_LIST_LIMIT } = options;
|
|
43
|
+
const { db, entries, compact, memory } = await this.tables;
|
|
44
|
+
// Select table based on type
|
|
45
|
+
const table = type === "compact" ? compact : type === "memory" ? memory : entries;
|
|
31
46
|
const data = await db
|
|
32
47
|
.select()
|
|
33
48
|
.from(table)
|
|
34
|
-
.where(and(
|
|
35
|
-
|
|
49
|
+
.where(and(
|
|
50
|
+
// Add scope filter for compact/memory tables
|
|
51
|
+
scope && type !== "history"
|
|
52
|
+
? eq(sql `json_extract(${table.metadata}, '$.scope')`, scope)
|
|
53
|
+
: undefined, filter?.agentId ? eq(table.agentId, filter.agentId) : undefined, filter?.userId ? eq(table.userId, filter.userId) : undefined, filter?.sessionId ? eq(table.sessionId, filter.sessionId) : undefined, filter?.before ? lt(table.createdAt, new Date(filter.before)) : undefined, filter?.after ? gt(table.createdAt, new Date(filter.after)) : undefined))
|
|
54
|
+
.orderBy(...(options.orderBy ?? [["createdAt", "desc"]]).map((item) => (item[1] === "asc" ? asc : desc)(sql.identifier(item[0]))))
|
|
36
55
|
.limit(limit)
|
|
37
56
|
.execute();
|
|
38
57
|
return { data };
|
|
39
58
|
}
|
|
40
|
-
async read(
|
|
41
|
-
const
|
|
42
|
-
const
|
|
59
|
+
async read(id, options) {
|
|
60
|
+
const { type = "history", scope, filter } = options ?? {};
|
|
61
|
+
const { db, entries, compact, memory } = await this.tables;
|
|
62
|
+
// Select table based on type
|
|
63
|
+
const table = type === "compact" ? compact : type === "memory" ? memory : entries;
|
|
43
64
|
return db
|
|
44
65
|
.select()
|
|
45
66
|
.from(table)
|
|
46
|
-
.where(eq(table.
|
|
67
|
+
.where(and(eq(table.id, id),
|
|
68
|
+
// Add scope filter for compact/memory tables
|
|
69
|
+
scope && type !== "history"
|
|
70
|
+
? eq(sql `json_extract(${table.metadata}, '$.scope')`, scope)
|
|
71
|
+
: undefined, filter?.agentId ? eq(table.agentId, filter.agentId) : undefined, filter?.userId ? eq(table.userId, filter.userId) : undefined, filter?.sessionId ? eq(table.sessionId, filter.sessionId) : undefined))
|
|
47
72
|
.limit(1)
|
|
48
73
|
.execute()
|
|
49
|
-
.then((
|
|
74
|
+
.then((rows) => rows.at(0));
|
|
50
75
|
}
|
|
51
|
-
async create(entry) {
|
|
52
|
-
const
|
|
53
|
-
const
|
|
76
|
+
async create(entry, options) {
|
|
77
|
+
const { type = "history", scope } = options ?? {};
|
|
78
|
+
const { db, entries, compact, memory } = await this.tables;
|
|
79
|
+
// Select table based on type
|
|
80
|
+
const table = type === "compact" ? compact : type === "memory" ? memory : entries;
|
|
81
|
+
// Prepare entry data - only add scope to metadata for compact/memory types
|
|
82
|
+
const entryData = { ...entry, metadata: { ...entry.metadata, scope } };
|
|
83
|
+
// Try update first, then insert if not found (upsert)
|
|
54
84
|
let result = await db
|
|
55
85
|
.update(table)
|
|
56
|
-
.set(
|
|
57
|
-
.where(eq(table.
|
|
86
|
+
.set(entryData)
|
|
87
|
+
.where(eq(table.id, entry.id))
|
|
58
88
|
.returning()
|
|
59
89
|
.execute();
|
|
60
90
|
if (!result.length) {
|
|
61
|
-
result = await db.insert(table).values(
|
|
91
|
+
result = await db.insert(table).values(entryData).returning().execute();
|
|
62
92
|
}
|
|
63
93
|
const [res] = result;
|
|
64
94
|
if (!res)
|
|
65
|
-
throw new Error(
|
|
95
|
+
throw new Error(`Failed to create ${type} entry, no result`);
|
|
66
96
|
return res;
|
|
67
97
|
}
|
|
98
|
+
async delete(id, options) {
|
|
99
|
+
const { type = "history", scope, filter } = options ?? {};
|
|
100
|
+
const { db, entries, compact, memory } = await this.tables;
|
|
101
|
+
// Select table based on type
|
|
102
|
+
const table = type === "compact" ? compact : type === "memory" ? memory : entries;
|
|
103
|
+
const result = await db
|
|
104
|
+
.delete(table)
|
|
105
|
+
.where(and(eq(table.id, id),
|
|
106
|
+
// Add scope filter for compact/memory tables
|
|
107
|
+
scope && type !== "history"
|
|
108
|
+
? eq(sql `json_extract(${table.metadata}, '$.scope')`, scope)
|
|
109
|
+
: undefined, filter?.agentId ? eq(table.agentId, filter.agentId) : undefined, filter?.userId ? eq(table.userId, filter.userId) : undefined, filter?.sessionId ? eq(table.sessionId, filter.sessionId) : undefined))
|
|
110
|
+
.returning()
|
|
111
|
+
.execute();
|
|
112
|
+
return { deletedCount: result.length };
|
|
113
|
+
}
|
|
68
114
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { AFSModule } from "@aigne/afs";
|
|
2
2
|
import { type initDatabase } from "@aigne/sqlite";
|
|
3
|
-
export declare function migrate(db: ReturnType<typeof initDatabase
|
|
3
|
+
export declare function migrate(db: Awaited<ReturnType<typeof initDatabase>>, module: AFSModule): Promise<void>;
|
|
@@ -2,8 +2,17 @@ import { sql } from "@aigne/sqlite";
|
|
|
2
2
|
import { v7 } from "@aigne/uuid";
|
|
3
3
|
import { init } from "./migrations/001-init.js";
|
|
4
4
|
import { addAgentId } from "./migrations/002-add-agent-id.js";
|
|
5
|
+
import { addCompactTable } from "./migrations/003-add-compact-table.js";
|
|
6
|
+
import { addMemoryTable } from "./migrations/004-add-memory-table.js";
|
|
7
|
+
import { addIndexes } from "./migrations/005-add-indexes.js";
|
|
5
8
|
export async function migrate(db, module) {
|
|
6
|
-
const migrations = [
|
|
9
|
+
const migrations = [
|
|
10
|
+
init,
|
|
11
|
+
addAgentId,
|
|
12
|
+
addCompactTable,
|
|
13
|
+
addMemoryTable,
|
|
14
|
+
addIndexes,
|
|
15
|
+
];
|
|
7
16
|
const migrationsTable = "__drizzle_migrations";
|
|
8
17
|
const migrationTableCreate = sql `
|
|
9
18
|
CREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (
|
|
@@ -12,18 +21,18 @@ export async function migrate(db, module) {
|
|
|
12
21
|
"hash" TEXT NOT NULL
|
|
13
22
|
)
|
|
14
23
|
`;
|
|
15
|
-
await
|
|
16
|
-
const dbMigrations = await
|
|
24
|
+
await db.run(migrationTableCreate).execute();
|
|
25
|
+
const dbMigrations = await db
|
|
17
26
|
.values(sql `SELECT "id", "moduleId", "hash" FROM ${sql.identifier(migrationsTable)} WHERE "moduleId" = ${sql.param(module.name)} ORDER BY id DESC LIMIT 1`)
|
|
18
27
|
.execute();
|
|
19
28
|
const lastDbMigration = dbMigrations[0];
|
|
20
29
|
const queriesToRun = [];
|
|
21
30
|
for (const migration of migrations) {
|
|
22
|
-
if (!lastDbMigration || lastDbMigration[
|
|
31
|
+
if (!lastDbMigration || lastDbMigration[2] < migration.hash) {
|
|
23
32
|
queriesToRun.push(...migration.sql(module), sql `INSERT INTO ${sql.identifier(migrationsTable)} ("id", "moduleId", "hash") VALUES(${sql.param(v7())}, ${sql.param(module.name)}, ${sql.param(migration.hash)})`);
|
|
24
33
|
}
|
|
25
34
|
}
|
|
26
35
|
for (const query of queriesToRun) {
|
|
27
|
-
await
|
|
36
|
+
await db.run(query).execute();
|
|
28
37
|
}
|
|
29
38
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { sql } from "@aigne/sqlite";
|
|
2
|
+
import { compactTableName } from "../models/compact.js";
|
|
3
|
+
export const addCompactTable = {
|
|
4
|
+
hash: "003-add-compact-table",
|
|
5
|
+
sql: (module) => [
|
|
6
|
+
sql `\
|
|
7
|
+
CREATE TABLE IF NOT EXISTS ${sql.identifier(compactTableName(module))} (
|
|
8
|
+
"id" TEXT NOT NULL PRIMARY KEY,
|
|
9
|
+
"createdAt" DATETIME NOT NULL,
|
|
10
|
+
"updatedAt" DATETIME NOT NULL,
|
|
11
|
+
"path" TEXT NOT NULL,
|
|
12
|
+
"sessionId" TEXT,
|
|
13
|
+
"userId" TEXT,
|
|
14
|
+
"agentId" TEXT,
|
|
15
|
+
"metadata" JSON,
|
|
16
|
+
"content" JSON
|
|
17
|
+
)
|
|
18
|
+
`,
|
|
19
|
+
],
|
|
20
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { sql } from "@aigne/sqlite";
|
|
2
|
+
import { memoryTableName } from "../models/memory.js";
|
|
3
|
+
export const addMemoryTable = {
|
|
4
|
+
hash: "004-add-memory-table",
|
|
5
|
+
sql: (module) => [
|
|
6
|
+
sql `\
|
|
7
|
+
CREATE TABLE IF NOT EXISTS ${sql.identifier(memoryTableName(module))} (
|
|
8
|
+
"id" TEXT NOT NULL PRIMARY KEY,
|
|
9
|
+
"createdAt" DATETIME NOT NULL,
|
|
10
|
+
"updatedAt" DATETIME NOT NULL,
|
|
11
|
+
"path" TEXT NOT NULL,
|
|
12
|
+
"sessionId" TEXT,
|
|
13
|
+
"userId" TEXT,
|
|
14
|
+
"agentId" TEXT,
|
|
15
|
+
"metadata" JSON,
|
|
16
|
+
"content" JSON
|
|
17
|
+
)
|
|
18
|
+
`,
|
|
19
|
+
],
|
|
20
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { sql } from "@aigne/sqlite";
|
|
2
|
+
import { compactTableName } from "../models/compact.js";
|
|
3
|
+
import { entriesTableName } from "../models/entries.js";
|
|
4
|
+
import { memoryTableName } from "../models/memory.js";
|
|
5
|
+
export const addIndexes = {
|
|
6
|
+
hash: "005-add-indexes",
|
|
7
|
+
sql: (module) => {
|
|
8
|
+
const entriesTable = entriesTableName(module);
|
|
9
|
+
const memoryTable = memoryTableName(module);
|
|
10
|
+
const compactTable = compactTableName(module);
|
|
11
|
+
return [
|
|
12
|
+
// Entries table indexes
|
|
13
|
+
sql `CREATE INDEX IF NOT EXISTS "idx_entries_session_created" ON ${sql.identifier(entriesTable)} ("sessionId", "createdAt" DESC)`,
|
|
14
|
+
sql `CREATE INDEX IF NOT EXISTS "idx_entries_user_created" ON ${sql.identifier(entriesTable)} ("userId", "createdAt" DESC)`,
|
|
15
|
+
sql `CREATE INDEX IF NOT EXISTS "idx_entries_agent_created" ON ${sql.identifier(entriesTable)} ("agentId", "createdAt" DESC)`,
|
|
16
|
+
// Memory table indexes
|
|
17
|
+
sql `CREATE INDEX IF NOT EXISTS "idx_memory_session_created" ON ${sql.identifier(memoryTable)} ("sessionId", "createdAt" DESC)`,
|
|
18
|
+
sql `CREATE INDEX IF NOT EXISTS "idx_memory_user_created" ON ${sql.identifier(memoryTable)} ("userId", "createdAt" DESC)`,
|
|
19
|
+
sql `CREATE INDEX IF NOT EXISTS "idx_memory_agent_created" ON ${sql.identifier(memoryTable)} ("agentId", "createdAt" DESC)`,
|
|
20
|
+
sql `CREATE INDEX IF NOT EXISTS "idx_memory_scope" ON ${sql.identifier(memoryTable)} (json_extract("metadata", '$.scope'))`,
|
|
21
|
+
// Compact table indexes
|
|
22
|
+
sql `CREATE INDEX IF NOT EXISTS "idx_compact_session_created" ON ${sql.identifier(compactTable)} ("sessionId", "createdAt" DESC)`,
|
|
23
|
+
sql `CREATE INDEX IF NOT EXISTS "idx_compact_user_created" ON ${sql.identifier(compactTable)} ("userId", "createdAt" DESC)`,
|
|
24
|
+
sql `CREATE INDEX IF NOT EXISTS "idx_compact_agent_created" ON ${sql.identifier(compactTable)} ("agentId", "createdAt" DESC)`,
|
|
25
|
+
sql `CREATE INDEX IF NOT EXISTS "idx_compact_scope" ON ${sql.identifier(compactTable)} (json_extract("metadata", '$.scope'))`,
|
|
26
|
+
];
|
|
27
|
+
},
|
|
28
|
+
};
|
|
@@ -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,22 @@
|
|
|
1
|
+
import { datetime, json, sqliteTable, text } from "@aigne/sqlite";
|
|
2
|
+
import { v7 } from "@aigne/uuid";
|
|
3
|
+
export const compactTableName = (module) => `Entries_${module.name}_compact`;
|
|
4
|
+
export const compactTable = (module) => sqliteTable(compactTableName(module), {
|
|
5
|
+
id: text("id")
|
|
6
|
+
.notNull()
|
|
7
|
+
.primaryKey()
|
|
8
|
+
.$defaultFn(() => v7()),
|
|
9
|
+
createdAt: datetime("createdAt")
|
|
10
|
+
.notNull()
|
|
11
|
+
.$defaultFn(() => new Date()),
|
|
12
|
+
updatedAt: datetime("updatedAt")
|
|
13
|
+
.notNull()
|
|
14
|
+
.$defaultFn(() => new Date())
|
|
15
|
+
.$onUpdateFn(() => new Date()),
|
|
16
|
+
path: text("path").notNull(),
|
|
17
|
+
userId: text("userId"),
|
|
18
|
+
sessionId: text("sessionId"),
|
|
19
|
+
agentId: text("agentId"),
|
|
20
|
+
metadata: json("metadata"),
|
|
21
|
+
content: json("content"),
|
|
22
|
+
});
|