@aigne/afs-history 1.2.0-beta.4 → 1.2.0-beta.5

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.
@@ -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
+ type?: 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;
@@ -1,22 +1,37 @@
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
5
  export interface AFSStorageListOptions {
6
6
  filter?: {
7
7
  agentId?: string;
8
8
  userId?: string;
9
9
  sessionId?: string;
10
+ before?: Date | string;
11
+ after?: Date | string;
10
12
  };
11
13
  limit?: number;
12
14
  orderBy?: [string, "asc" | "desc"][];
13
15
  }
16
+ export interface AFSStorageReadOptions {
17
+ filter?: {
18
+ agentId?: string;
19
+ userId?: string;
20
+ sessionId?: string;
21
+ };
22
+ }
23
+ export type CompactType = "session" | "user" | "agent";
14
24
  export interface AFSStorage {
15
25
  create(entry: AFSStorageCreatePayload): Promise<AFSEntry>;
16
26
  list(options?: AFSStorageListOptions): Promise<{
17
27
  data: AFSEntry[];
18
28
  }>;
19
- read(path: string): Promise<AFSEntry | undefined>;
29
+ read(id: string, options?: AFSStorageReadOptions): Promise<AFSEntry | undefined>;
30
+ createCompact(type: CompactType, entry: AFSStorageCreatePayload): Promise<AFSEntry>;
31
+ listCompact(type: CompactType, options?: AFSStorageListOptions): Promise<{
32
+ data: AFSEntry[];
33
+ }>;
34
+ readCompact(type: CompactType, id: string, options?: AFSStorageReadOptions): Promise<AFSEntry | undefined>;
20
35
  }
21
36
  export type AFSStorageMigrations = {
22
37
  hash: string;
@@ -1,4 +1,4 @@
1
- import type { AFSListOptions, AFSListResult, AFSModule, AFSReadResult, AFSRoot } from "@aigne/afs";
1
+ import type { AFSListOptions, AFSListResult, AFSModule, AFSReadOptions, AFSReadResult, AFSRoot, AFSWriteEntryPayload, AFSWriteResult } from "@aigne/afs";
2
2
  import { SharedAFSStorage, type SharedAFSStorageOptions } from "./storage/index.js";
3
3
  export * from "./storage/index.js";
4
4
  export interface AFSHistoryOptions {
@@ -6,9 +6,15 @@ export interface AFSHistoryOptions {
6
6
  }
7
7
  export declare class AFSHistory implements AFSModule {
8
8
  constructor(options?: AFSHistoryOptions);
9
- private storage;
10
9
  readonly name: string;
10
+ private storage;
11
+ private afs?;
12
+ private router;
13
+ private rootEntries;
11
14
  onMount(afs: AFSRoot): void;
12
15
  list(path: string, options?: AFSListOptions): Promise<AFSListResult>;
13
- read(path: string): Promise<AFSReadResult>;
16
+ read(path: string, options?: AFSReadOptions): Promise<AFSReadResult>;
17
+ write(path: string, content: AFSWriteEntryPayload): Promise<AFSWriteResult>;
18
+ private getCompactType;
19
+ private normalizePath;
14
20
  }
@@ -1,7 +1,6 @@
1
1
  import type { AFSEntry, AFSModule } from "@aigne/afs";
2
2
  import { initDatabase } from "@aigne/sqlite";
3
- import { entriesTable } from "./models/entries.js";
4
- import type { AFSStorage, AFSStorageCreatePayload, AFSStorageListOptions } from "./type.js";
3
+ import type { AFSStorage, AFSStorageCreatePayload, AFSStorageListOptions, AFSStorageReadOptions, CompactType } from "./type.js";
5
4
  export * from "./type.js";
6
5
  export interface SharedAFSStorageOptions {
7
6
  url?: string;
@@ -17,11 +16,18 @@ export declare class SharedAFSStorage {
17
16
  }
18
17
  export declare class AFSStorageWithModule implements AFSStorage {
19
18
  private db;
20
- private table;
21
- constructor(db: ReturnType<typeof initDatabase>, table: Promise<ReturnType<typeof entriesTable>>);
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(path: string): Promise<AFSEntry | undefined>;
26
+ read(id: string, options?: AFSStorageReadOptions): Promise<AFSEntry | undefined>;
26
27
  create(entry: AFSStorageCreatePayload): Promise<AFSEntry>;
28
+ createCompact(type: CompactType, entry: AFSStorageCreatePayload): Promise<AFSEntry>;
29
+ listCompact(type: CompactType, options?: AFSStorageListOptions): Promise<{
30
+ data: AFSEntry[];
31
+ }>;
32
+ readCompact(type: CompactType, id: string, options?: AFSStorageReadOptions): Promise<AFSEntry | undefined>;
27
33
  }
@@ -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>, module: AFSModule): Promise<void>;
3
+ export declare function migrate(db: Awaited<ReturnType<typeof initDatabase>>, module: AFSModule): Promise<void>;
@@ -0,0 +1,2 @@
1
+ import type { AFSStorageMigrations } from "../type.js";
2
+ export declare const addCompactTable: AFSStorageMigrations;
@@ -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
+ type?: 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
+ }>;
@@ -1,22 +1,37 @@
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
5
  export interface AFSStorageListOptions {
6
6
  filter?: {
7
7
  agentId?: string;
8
8
  userId?: string;
9
9
  sessionId?: string;
10
+ before?: Date | string;
11
+ after?: Date | string;
10
12
  };
11
13
  limit?: number;
12
14
  orderBy?: [string, "asc" | "desc"][];
13
15
  }
16
+ export interface AFSStorageReadOptions {
17
+ filter?: {
18
+ agentId?: string;
19
+ userId?: string;
20
+ sessionId?: string;
21
+ };
22
+ }
23
+ export type CompactType = "session" | "user" | "agent";
14
24
  export interface AFSStorage {
15
25
  create(entry: AFSStorageCreatePayload): Promise<AFSEntry>;
16
26
  list(options?: AFSStorageListOptions): Promise<{
17
27
  data: AFSEntry[];
18
28
  }>;
19
- read(path: string): Promise<AFSEntry | undefined>;
29
+ read(id: string, options?: AFSStorageReadOptions): Promise<AFSEntry | undefined>;
30
+ createCompact(type: CompactType, entry: AFSStorageCreatePayload): Promise<AFSEntry>;
31
+ listCompact(type: CompactType, options?: AFSStorageListOptions): Promise<{
32
+ data: AFSEntry[];
33
+ }>;
34
+ readCompact(type: CompactType, id: string, options?: AFSStorageReadOptions): Promise<AFSEntry | undefined>;
20
35
  }
21
36
  export type AFSStorageMigrations = {
22
37
  hash: string;
@@ -1,4 +1,4 @@
1
- import type { AFSListOptions, AFSListResult, AFSModule, AFSReadResult, AFSRoot } from "@aigne/afs";
1
+ import type { AFSListOptions, AFSListResult, AFSModule, AFSReadOptions, AFSReadResult, AFSRoot, AFSWriteEntryPayload, AFSWriteResult } from "@aigne/afs";
2
2
  import { SharedAFSStorage, type SharedAFSStorageOptions } from "./storage/index.js";
3
3
  export * from "./storage/index.js";
4
4
  export interface AFSHistoryOptions {
@@ -6,9 +6,15 @@ export interface AFSHistoryOptions {
6
6
  }
7
7
  export declare class AFSHistory implements AFSModule {
8
8
  constructor(options?: AFSHistoryOptions);
9
- private storage;
10
9
  readonly name: string;
10
+ private storage;
11
+ private afs?;
12
+ private router;
13
+ private rootEntries;
11
14
  onMount(afs: AFSRoot): void;
12
15
  list(path: string, options?: AFSListOptions): Promise<AFSListResult>;
13
- read(path: string): Promise<AFSReadResult>;
16
+ read(path: string, options?: AFSReadOptions): Promise<AFSReadResult>;
17
+ write(path: string, content: AFSWriteEntryPayload): Promise<AFSWriteResult>;
18
+ private getCompactType;
19
+ private normalizePath;
14
20
  }