@aigne/afs-history 1.2.0-beta.9 → 1.3.0-beta

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 CHANGED
@@ -6,6 +6,94 @@
6
6
  * dependencies
7
7
  * @aigne/afs bumped to 1.2.0
8
8
 
9
+ ## [1.3.0-beta](https://github.com/AIGNE-io/aigne-framework/compare/afs-history-v1.2.0...afs-history-v1.3.0-beta) (2026-01-20)
10
+
11
+
12
+ ### Features
13
+
14
+ * **afs:** add @aigne/afs-utils package ([#927](https://github.com/AIGNE-io/aigne-framework/issues/927)) ([3922635](https://github.com/AIGNE-io/aigne-framework/commit/3922635981aab4578607c5bf1fb882c8e45725ce))
15
+
16
+
17
+ ### Dependencies
18
+
19
+ * The following workspace dependencies were updated
20
+ * dependencies
21
+ * @aigne/afs-utils bumped to 1.0.0
22
+
23
+ ## [1.2.0](https://github.com/AIGNE-io/aigne-framework/compare/afs-history-v1.2.0-beta.12...afs-history-v1.2.0) (2026-01-16)
24
+
25
+
26
+ ### Dependencies
27
+
28
+ * The following workspace dependencies were updated
29
+ * dependencies
30
+ * @aigne/afs bumped to 1.4.0
31
+ * @aigne/sqlite bumped to 0.4.9
32
+
33
+ ## [1.2.0-beta.12](https://github.com/AIGNE-io/aigne-framework/compare/afs-history-v1.2.0-beta.11...afs-history-v1.2.0-beta.12) (2026-01-16)
34
+
35
+
36
+ ### Features
37
+
38
+ * add session compact support for AIAgent ([#863](https://github.com/AIGNE-io/aigne-framework/issues/863)) ([9010918](https://github.com/AIGNE-io/aigne-framework/commit/9010918cd3f18b02b5c60ddc9ed5c34b568d0b28))
39
+ * **afs:** add module access control and schema validation support ([#904](https://github.com/AIGNE-io/aigne-framework/issues/904)) ([d0b279a](https://github.com/AIGNE-io/aigne-framework/commit/d0b279aac07ebe2bcc1fd4148498fc3f6bbcd561))
40
+ * **afs:** support expand context into prompt template by call `$afs.xxx` ([#830](https://github.com/AIGNE-io/aigne-framework/issues/830)) ([5616acd](https://github.com/AIGNE-io/aigne-framework/commit/5616acd6ea257c91aa0b766608f45c5ce17f0345))
41
+ * **core:** add cross session user memory support ([#873](https://github.com/AIGNE-io/aigne-framework/issues/873)) ([f377aa1](https://github.com/AIGNE-io/aigne-framework/commit/f377aa17f2cf8004fd3225ade4a37fd90af1292f))
42
+ * **core:** add session history support ([#858](https://github.com/AIGNE-io/aigne-framework/issues/858)) ([28a070e](https://github.com/AIGNE-io/aigne-framework/commit/28a070ed33b821d1fd344b899706d817ca992b9f))
43
+ * support mount mcp agent into AFS ([#740](https://github.com/AIGNE-io/aigne-framework/issues/740)) ([6d474fc](https://github.com/AIGNE-io/aigne-framework/commit/6d474fc05845a15e2c3e8fa97727b409bdd70945))
44
+
45
+
46
+ ### Bug Fixes
47
+
48
+ * **afs:** support read binary file as base64 string ([3480f9f](https://github.com/AIGNE-io/aigne-framework/commit/3480f9fe90647eba3bf2ff37e22c334599b72e35))
49
+ * bump version ([696560f](https://github.com/AIGNE-io/aigne-framework/commit/696560fa2673eddcb4d00ac0523fbbbde7273cb3))
50
+ * bump version ([70d217c](https://github.com/AIGNE-io/aigne-framework/commit/70d217c8360dd0dda7f5f17011c4e92ec836e801))
51
+ * bump version ([af04b69](https://github.com/AIGNE-io/aigne-framework/commit/af04b6931951afa35d52065430acc7fef4b10087))
52
+ * bump version ([ba7ad18](https://github.com/AIGNE-io/aigne-framework/commit/ba7ad184fcf32b49bf0507a3cb638d20fb00690d))
53
+ * bump version ([93a1c10](https://github.com/AIGNE-io/aigne-framework/commit/93a1c10cf35f88eaafe91092481f5d087bd5b3a9))
54
+ * improve test coverage tracking and reporting ([#903](https://github.com/AIGNE-io/aigne-framework/issues/903)) ([031144e](https://github.com/AIGNE-io/aigne-framework/commit/031144e74f29e882cffe52ffda8f7a18c76ace7f))
55
+
56
+
57
+ ### Dependencies
58
+
59
+ * The following workspace dependencies were updated
60
+ * dependencies
61
+ * @aigne/afs bumped to 1.4.0-beta.11
62
+
63
+ ## [1.2.0-beta.11](https://github.com/AIGNE-io/aigne-framework/compare/afs-history-v1.2.0-beta.10...afs-history-v1.2.0-beta.11) (2026-01-16)
64
+
65
+
66
+ ### Bug Fixes
67
+
68
+ * **afs:** support read binary file as base64 string ([3480f9f](https://github.com/AIGNE-io/aigne-framework/commit/3480f9fe90647eba3bf2ff37e22c334599b72e35))
69
+
70
+
71
+ ### Dependencies
72
+
73
+ * The following workspace dependencies were updated
74
+ * dependencies
75
+ * @aigne/afs bumped to 1.4.0-beta.10
76
+
77
+ ## [1.2.0-beta.10](https://github.com/AIGNE-io/aigne-framework/compare/afs-history-v1.2.0-beta.9...afs-history-v1.2.0-beta.10) (2026-01-14)
78
+
79
+
80
+ ### Features
81
+
82
+ * **afs:** add module access control and schema validation support ([#904](https://github.com/AIGNE-io/aigne-framework/issues/904)) ([d0b279a](https://github.com/AIGNE-io/aigne-framework/commit/d0b279aac07ebe2bcc1fd4148498fc3f6bbcd561))
83
+
84
+
85
+ ### Bug Fixes
86
+
87
+ * improve test coverage tracking and reporting ([#903](https://github.com/AIGNE-io/aigne-framework/issues/903)) ([031144e](https://github.com/AIGNE-io/aigne-framework/commit/031144e74f29e882cffe52ffda8f7a18c76ace7f))
88
+
89
+
90
+ ### Dependencies
91
+
92
+ * The following workspace dependencies were updated
93
+ * dependencies
94
+ * @aigne/afs bumped to 1.4.0-beta.9
95
+ * @aigne/sqlite bumped to 0.4.9-beta.2
96
+
9
97
  ## [1.2.0-beta.9](https://github.com/AIGNE-io/aigne-framework/compare/afs-history-v1.2.0-beta.8...afs-history-v1.2.0-beta.9) (2026-01-12)
10
98
 
11
99
 
@@ -1,12 +1,33 @@
1
- import type { AFSDeleteOptions, AFSDeleteResult, AFSListOptions, AFSListResult, AFSModule, AFSReadOptions, AFSReadResult, AFSRoot, AFSWriteEntryPayload, AFSWriteResult } from "@aigne/afs";
2
- import { SharedAFSStorage, type SharedAFSStorageOptions } from "./storage/index.js";
1
+ import { type AFSAccessMode, type AFSDeleteOptions, type AFSDeleteResult, type AFSListOptions, type AFSListResult, type AFSModule, type AFSModuleLoadParams, type AFSReadOptions, type AFSReadResult, type AFSRoot, type AFSWriteEntryPayload, type AFSWriteOptions, type AFSWriteResult } from "@aigne/afs";
2
+ import { z } from "zod";
3
+ import { type AFSStorage, type AFSStorageSQLiteOptions } from "./storage/index.js";
3
4
  export * from "./storage/index.js";
4
5
  export interface AFSHistoryOptions {
5
- storage?: SharedAFSStorage | SharedAFSStorageOptions;
6
+ storage?: AFSStorage | AFSStorageSQLiteOptions;
7
+ /**
8
+ * Access mode for this module.
9
+ * @default "readwrite"
10
+ */
11
+ accessMode?: AFSAccessMode;
6
12
  }
7
13
  export declare class AFSHistory implements AFSModule {
14
+ static schema(): z.ZodEffects<z.ZodObject<{
15
+ storage: z.ZodType<any, z.ZodTypeDef, any>;
16
+ accessMode: z.ZodOptional<z.ZodEnum<["readonly", "readwrite"]>>;
17
+ }, "strip", z.ZodTypeAny, {
18
+ storage?: any;
19
+ accessMode?: "readonly" | "readwrite" | undefined;
20
+ }, {
21
+ storage?: any;
22
+ accessMode?: "readonly" | "readwrite" | undefined;
23
+ }>, {
24
+ storage?: any;
25
+ accessMode?: "readonly" | "readwrite" | undefined;
26
+ }, any>;
27
+ static load({ parsed }: AFSModuleLoadParams): Promise<AFSHistory>;
8
28
  constructor(options?: AFSHistoryOptions);
9
29
  readonly name: string;
30
+ readonly accessMode: AFSAccessMode;
10
31
  private storage;
11
32
  private afs?;
12
33
  private router;
@@ -14,7 +35,7 @@ export declare class AFSHistory implements AFSModule {
14
35
  onMount(afs: AFSRoot): void;
15
36
  list(path: string, options?: AFSListOptions): Promise<AFSListResult>;
16
37
  read(path: string, options?: AFSReadOptions): Promise<AFSReadResult>;
17
- write(path: string, content: AFSWriteEntryPayload): Promise<AFSWriteResult>;
38
+ write(path: string, content: AFSWriteEntryPayload, options: AFSWriteOptions): Promise<AFSWriteResult>;
18
39
  delete(path: string, _options?: AFSDeleteOptions): Promise<AFSDeleteResult>;
19
40
  private normalizePath;
20
41
  }
package/lib/cjs/index.js CHANGED
@@ -15,19 +15,38 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.AFSHistory = void 0;
18
+ const afs_1 = require("@aigne/afs");
19
+ const index_js_1 = require("@aigne/afs-utils/zod/index.js");
18
20
  const uuid_1 = require("@aigne/uuid");
19
21
  const radix3_1 = require("radix3");
20
22
  const ufo_1 = require("ufo");
21
- const index_js_1 = require("./storage/index.js");
23
+ const zod_1 = require("zod");
24
+ const index_js_2 = require("./storage/index.js");
22
25
  __exportStar(require("./storage/index.js"), exports);
26
+ const afsStorageOptionsSchema = (0, index_js_1.camelize)(zod_1.z.object({
27
+ url: (0, index_js_1.optionalize)(zod_1.z.string().describe("Database URL for storage")),
28
+ }));
29
+ const afsHistoryOptionsSchema = (0, index_js_1.camelize)(zod_1.z.object({
30
+ storage: (0, index_js_1.optionalize)(zod_1.z.union([zod_1.z.custom((v) => (0, index_js_2.isAFSStorage)(v)), afsStorageOptionsSchema])),
31
+ accessMode: afs_1.accessModeSchema,
32
+ }));
23
33
  class AFSHistory {
34
+ static schema() {
35
+ return afsHistoryOptionsSchema;
36
+ }
37
+ static async load({ parsed }) {
38
+ const valid = await AFSHistory.schema().parseAsync(parsed);
39
+ return new AFSHistory(valid);
40
+ }
24
41
  constructor(options) {
25
- this.storage =
26
- options?.storage instanceof index_js_1.SharedAFSStorage
27
- ? options.storage.withModule(this)
28
- : new index_js_1.SharedAFSStorage(options?.storage).withModule(this);
42
+ (0, index_js_1.zodParse)((0, index_js_1.optionalize)(afsHistoryOptionsSchema), options);
43
+ this.storage = (0, index_js_2.isAFSStorage)(options?.storage)
44
+ ? options.storage
45
+ : new index_js_2.AFSStorageSQLite(this, options?.storage);
46
+ this.accessMode = options?.accessMode ?? "readwrite";
29
47
  }
30
48
  name = "history";
49
+ accessMode;
31
50
  storage;
32
51
  afs;
33
52
  router = (0, radix3_1.createRouter)({
@@ -176,7 +195,7 @@ class AFSHistory {
176
195
  },
177
196
  };
178
197
  }
179
- async write(path, content) {
198
+ async write(path, content, options) {
180
199
  const id = (0, uuid_1.v7)();
181
200
  const match = this.router.lookup(path);
182
201
  if (!match || match.action !== "create") {
@@ -197,7 +216,7 @@ class AFSHistory {
197
216
  }, { type, scope });
198
217
  // Emit event for history entries
199
218
  if (type === "history") {
200
- this.afs?.emit("historyCreated", { entry });
219
+ this.afs?.emit("historyCreated", { entry }, options);
201
220
  }
202
221
  return {
203
222
  data: {
@@ -252,3 +271,4 @@ class AFSHistory {
252
271
  }
253
272
  }
254
273
  exports.AFSHistory = AFSHistory;
274
+ const _typeCheck = AFSHistory;
@@ -1,21 +1,13 @@
1
1
  import type { AFSEntry, AFSModule } from "@aigne/afs";
2
- import { initDatabase } from "@aigne/sqlite";
3
2
  import type { AFSStorage, AFSStorageCreateOptions, AFSStorageCreatePayload, AFSStorageDeleteOptions, AFSStorageListOptions, AFSStorageReadOptions } from "./type.js";
4
3
  export * from "./type.js";
5
- export interface SharedAFSStorageOptions {
4
+ export interface AFSStorageSQLiteOptions {
6
5
  url?: string;
7
6
  }
8
- export declare class SharedAFSStorage {
9
- options?: SharedAFSStorageOptions | undefined;
10
- constructor(options?: SharedAFSStorageOptions | undefined);
11
- private _db;
12
- get db(): Promise<import("drizzle-orm/sqlite-proxy/driver.js").SqliteRemoteDatabase<Record<string, never>>>;
13
- withModule(module: AFSModule): AFSStorage;
14
- }
15
- export declare class AFSStorageWithModule implements AFSStorage {
16
- private db;
17
- private module;
18
- constructor(db: ReturnType<typeof initDatabase>, module: AFSModule);
7
+ export declare class AFSStorageSQLite implements AFSStorage {
8
+ module: AFSModule;
9
+ options?: AFSStorageSQLiteOptions | undefined;
10
+ constructor(module: AFSModule, options?: AFSStorageSQLiteOptions | undefined);
19
11
  private _tables?;
20
12
  private get tables();
21
13
  list(options?: AFSStorageListOptions): Promise<{
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.AFSStorageWithModule = exports.SharedAFSStorage = void 0;
17
+ exports.AFSStorageSQLite = void 0;
18
18
  const sqlite_1 = require("@aigne/sqlite");
19
19
  const migrate_js_1 = require("./migrate.js");
20
20
  const compact_js_1 = require("./models/compact.js");
@@ -22,32 +22,17 @@ const entries_js_1 = require("./models/entries.js");
22
22
  const memory_js_1 = require("./models/memory.js");
23
23
  __exportStar(require("./type.js"), exports);
24
24
  const DEFAULT_AFS_STORAGE_LIST_LIMIT = 10;
25
- class SharedAFSStorage {
26
- options;
27
- constructor(options) {
28
- this.options = options;
29
- }
30
- _db;
31
- get db() {
32
- this._db ??= (0, sqlite_1.initDatabase)({ url: this.options?.url });
33
- return this._db;
34
- }
35
- withModule(module) {
36
- return new AFSStorageWithModule(this.db, module);
37
- }
38
- }
39
- exports.SharedAFSStorage = SharedAFSStorage;
40
- class AFSStorageWithModule {
41
- db;
25
+ class AFSStorageSQLite {
42
26
  module;
43
- constructor(db, module) {
44
- this.db = db;
27
+ options;
28
+ constructor(module, options) {
45
29
  this.module = module;
30
+ this.options = options;
46
31
  }
47
32
  _tables;
48
33
  get tables() {
49
34
  if (!this._tables) {
50
- this._tables = this.db.then((db) => (0, migrate_js_1.migrate)(db, this.module).then(() => ({
35
+ this._tables = (0, sqlite_1.initDatabase)({ url: this.options?.url }).then((db) => (0, migrate_js_1.migrate)(db, this.module).then(() => ({
51
36
  db,
52
37
  entries: (0, entries_js_1.entriesTable)(this.module),
53
38
  compact: (0, compact_js_1.compactTable)(this.module),
@@ -130,4 +115,4 @@ class AFSStorageWithModule {
130
115
  return { deletedCount: result.length };
131
116
  }
132
117
  }
133
- exports.AFSStorageWithModule = AFSStorageWithModule;
118
+ exports.AFSStorageSQLite = AFSStorageSQLite;
@@ -45,6 +45,7 @@ export interface AFSStorage {
45
45
  deletedCount: number;
46
46
  }>;
47
47
  }
48
+ export declare function isAFSStorage(value: any): value is AFSStorage;
48
49
  export type AFSStorageMigrations = {
49
50
  hash: string;
50
51
  sql: (module: AFSModule) => SQL[];
@@ -1,2 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAFSStorage = isAFSStorage;
4
+ function isAFSStorage(value) {
5
+ return (!!value &&
6
+ typeof value === "object" &&
7
+ typeof value.create === "function" &&
8
+ typeof value.list === "function" &&
9
+ typeof value.read === "function" &&
10
+ typeof value.delete === "function");
11
+ }
@@ -1,12 +1,33 @@
1
- import type { AFSDeleteOptions, AFSDeleteResult, AFSListOptions, AFSListResult, AFSModule, AFSReadOptions, AFSReadResult, AFSRoot, AFSWriteEntryPayload, AFSWriteResult } from "@aigne/afs";
2
- import { SharedAFSStorage, type SharedAFSStorageOptions } from "./storage/index.js";
1
+ import { type AFSAccessMode, type AFSDeleteOptions, type AFSDeleteResult, type AFSListOptions, type AFSListResult, type AFSModule, type AFSModuleLoadParams, type AFSReadOptions, type AFSReadResult, type AFSRoot, type AFSWriteEntryPayload, type AFSWriteOptions, type AFSWriteResult } from "@aigne/afs";
2
+ import { z } from "zod";
3
+ import { type AFSStorage, type AFSStorageSQLiteOptions } from "./storage/index.js";
3
4
  export * from "./storage/index.js";
4
5
  export interface AFSHistoryOptions {
5
- storage?: SharedAFSStorage | SharedAFSStorageOptions;
6
+ storage?: AFSStorage | AFSStorageSQLiteOptions;
7
+ /**
8
+ * Access mode for this module.
9
+ * @default "readwrite"
10
+ */
11
+ accessMode?: AFSAccessMode;
6
12
  }
7
13
  export declare class AFSHistory implements AFSModule {
14
+ static schema(): z.ZodEffects<z.ZodObject<{
15
+ storage: z.ZodType<any, z.ZodTypeDef, any>;
16
+ accessMode: z.ZodOptional<z.ZodEnum<["readonly", "readwrite"]>>;
17
+ }, "strip", z.ZodTypeAny, {
18
+ storage?: any;
19
+ accessMode?: "readonly" | "readwrite" | undefined;
20
+ }, {
21
+ storage?: any;
22
+ accessMode?: "readonly" | "readwrite" | undefined;
23
+ }>, {
24
+ storage?: any;
25
+ accessMode?: "readonly" | "readwrite" | undefined;
26
+ }, any>;
27
+ static load({ parsed }: AFSModuleLoadParams): Promise<AFSHistory>;
8
28
  constructor(options?: AFSHistoryOptions);
9
29
  readonly name: string;
30
+ readonly accessMode: AFSAccessMode;
10
31
  private storage;
11
32
  private afs?;
12
33
  private router;
@@ -14,7 +35,7 @@ export declare class AFSHistory implements AFSModule {
14
35
  onMount(afs: AFSRoot): void;
15
36
  list(path: string, options?: AFSListOptions): Promise<AFSListResult>;
16
37
  read(path: string, options?: AFSReadOptions): Promise<AFSReadResult>;
17
- write(path: string, content: AFSWriteEntryPayload): Promise<AFSWriteResult>;
38
+ write(path: string, content: AFSWriteEntryPayload, options: AFSWriteOptions): Promise<AFSWriteResult>;
18
39
  delete(path: string, _options?: AFSDeleteOptions): Promise<AFSDeleteResult>;
19
40
  private normalizePath;
20
41
  }
@@ -1,23 +1,13 @@
1
1
  import type { AFSEntry, AFSModule } from "@aigne/afs";
2
- import { initDatabase } from "@aigne/sqlite";
3
2
  import type { AFSStorage, AFSStorageCreateOptions, AFSStorageCreatePayload, AFSStorageDeleteOptions, AFSStorageListOptions, AFSStorageReadOptions } from "./type.js";
4
3
  export * from "./type.js";
5
- export interface SharedAFSStorageOptions {
4
+ export interface AFSStorageSQLiteOptions {
6
5
  url?: string;
7
6
  }
8
- export declare class SharedAFSStorage {
9
- options?: SharedAFSStorageOptions | undefined;
10
- constructor(options?: SharedAFSStorageOptions | undefined);
11
- private _db;
12
- get db(): Promise<import("drizzle-orm/libsql").LibSQLDatabase<Record<string, never>> & {
13
- vacuum?: () => Promise<void>;
14
- }>;
15
- withModule(module: AFSModule): AFSStorage;
16
- }
17
- export declare class AFSStorageWithModule implements AFSStorage {
18
- private db;
19
- private module;
20
- constructor(db: ReturnType<typeof initDatabase>, module: AFSModule);
7
+ export declare class AFSStorageSQLite implements AFSStorage {
8
+ module: AFSModule;
9
+ options?: AFSStorageSQLiteOptions | undefined;
10
+ constructor(module: AFSModule, options?: AFSStorageSQLiteOptions | undefined);
21
11
  private _tables?;
22
12
  private get tables();
23
13
  list(options?: AFSStorageListOptions): Promise<{
@@ -45,6 +45,7 @@ export interface AFSStorage {
45
45
  deletedCount: number;
46
46
  }>;
47
47
  }
48
+ export declare function isAFSStorage(value: any): value is AFSStorage;
48
49
  export type AFSStorageMigrations = {
49
50
  hash: string;
50
51
  sql: (module: AFSModule) => SQL[];
@@ -1,12 +1,33 @@
1
- import type { AFSDeleteOptions, AFSDeleteResult, AFSListOptions, AFSListResult, AFSModule, AFSReadOptions, AFSReadResult, AFSRoot, AFSWriteEntryPayload, AFSWriteResult } from "@aigne/afs";
2
- import { SharedAFSStorage, type SharedAFSStorageOptions } from "./storage/index.js";
1
+ import { type AFSAccessMode, type AFSDeleteOptions, type AFSDeleteResult, type AFSListOptions, type AFSListResult, type AFSModule, type AFSModuleLoadParams, type AFSReadOptions, type AFSReadResult, type AFSRoot, type AFSWriteEntryPayload, type AFSWriteOptions, type AFSWriteResult } from "@aigne/afs";
2
+ import { z } from "zod";
3
+ import { type AFSStorage, type AFSStorageSQLiteOptions } from "./storage/index.js";
3
4
  export * from "./storage/index.js";
4
5
  export interface AFSHistoryOptions {
5
- storage?: SharedAFSStorage | SharedAFSStorageOptions;
6
+ storage?: AFSStorage | AFSStorageSQLiteOptions;
7
+ /**
8
+ * Access mode for this module.
9
+ * @default "readwrite"
10
+ */
11
+ accessMode?: AFSAccessMode;
6
12
  }
7
13
  export declare class AFSHistory implements AFSModule {
14
+ static schema(): z.ZodEffects<z.ZodObject<{
15
+ storage: z.ZodType<any, z.ZodTypeDef, any>;
16
+ accessMode: z.ZodOptional<z.ZodEnum<["readonly", "readwrite"]>>;
17
+ }, "strip", z.ZodTypeAny, {
18
+ storage?: any;
19
+ accessMode?: "readonly" | "readwrite" | undefined;
20
+ }, {
21
+ storage?: any;
22
+ accessMode?: "readonly" | "readwrite" | undefined;
23
+ }>, {
24
+ storage?: any;
25
+ accessMode?: "readonly" | "readwrite" | undefined;
26
+ }, any>;
27
+ static load({ parsed }: AFSModuleLoadParams): Promise<AFSHistory>;
8
28
  constructor(options?: AFSHistoryOptions);
9
29
  readonly name: string;
30
+ readonly accessMode: AFSAccessMode;
10
31
  private storage;
11
32
  private afs?;
12
33
  private router;
@@ -14,7 +35,7 @@ export declare class AFSHistory implements AFSModule {
14
35
  onMount(afs: AFSRoot): void;
15
36
  list(path: string, options?: AFSListOptions): Promise<AFSListResult>;
16
37
  read(path: string, options?: AFSReadOptions): Promise<AFSReadResult>;
17
- write(path: string, content: AFSWriteEntryPayload): Promise<AFSWriteResult>;
38
+ write(path: string, content: AFSWriteEntryPayload, options: AFSWriteOptions): Promise<AFSWriteResult>;
18
39
  delete(path: string, _options?: AFSDeleteOptions): Promise<AFSDeleteResult>;
19
40
  private normalizePath;
20
41
  }
package/lib/esm/index.js CHANGED
@@ -1,16 +1,35 @@
1
+ import { accessModeSchema, } from "@aigne/afs";
2
+ import { camelize, optionalize, zodParse } from "@aigne/afs-utils/zod/index.js";
1
3
  import { v7 } from "@aigne/uuid";
2
4
  import { createRouter } from "radix3";
3
5
  import { joinURL } from "ufo";
4
- import { SharedAFSStorage, } from "./storage/index.js";
6
+ import { z } from "zod";
7
+ import { AFSStorageSQLite, isAFSStorage, } from "./storage/index.js";
5
8
  export * from "./storage/index.js";
9
+ const afsStorageOptionsSchema = camelize(z.object({
10
+ url: optionalize(z.string().describe("Database URL for storage")),
11
+ }));
12
+ const afsHistoryOptionsSchema = camelize(z.object({
13
+ storage: optionalize(z.union([z.custom((v) => isAFSStorage(v)), afsStorageOptionsSchema])),
14
+ accessMode: accessModeSchema,
15
+ }));
6
16
  export class AFSHistory {
17
+ static schema() {
18
+ return afsHistoryOptionsSchema;
19
+ }
20
+ static async load({ parsed }) {
21
+ const valid = await AFSHistory.schema().parseAsync(parsed);
22
+ return new AFSHistory(valid);
23
+ }
7
24
  constructor(options) {
8
- this.storage =
9
- options?.storage instanceof SharedAFSStorage
10
- ? options.storage.withModule(this)
11
- : new SharedAFSStorage(options?.storage).withModule(this);
25
+ zodParse(optionalize(afsHistoryOptionsSchema), options);
26
+ this.storage = isAFSStorage(options?.storage)
27
+ ? options.storage
28
+ : new AFSStorageSQLite(this, options?.storage);
29
+ this.accessMode = options?.accessMode ?? "readwrite";
12
30
  }
13
31
  name = "history";
32
+ accessMode;
14
33
  storage;
15
34
  afs;
16
35
  router = createRouter({
@@ -159,7 +178,7 @@ export class AFSHistory {
159
178
  },
160
179
  };
161
180
  }
162
- async write(path, content) {
181
+ async write(path, content, options) {
163
182
  const id = v7();
164
183
  const match = this.router.lookup(path);
165
184
  if (!match || match.action !== "create") {
@@ -180,7 +199,7 @@ export class AFSHistory {
180
199
  }, { type, scope });
181
200
  // Emit event for history entries
182
201
  if (type === "history") {
183
- this.afs?.emit("historyCreated", { entry });
202
+ this.afs?.emit("historyCreated", { entry }, options);
184
203
  }
185
204
  return {
186
205
  data: {
@@ -234,3 +253,4 @@ export class AFSHistory {
234
253
  return joinURL("/", prefix, scopeId, entry.id);
235
254
  }
236
255
  }
256
+ const _typeCheck = AFSHistory;
@@ -1,23 +1,13 @@
1
1
  import type { AFSEntry, AFSModule } from "@aigne/afs";
2
- import { initDatabase } from "@aigne/sqlite";
3
2
  import type { AFSStorage, AFSStorageCreateOptions, AFSStorageCreatePayload, AFSStorageDeleteOptions, AFSStorageListOptions, AFSStorageReadOptions } from "./type.js";
4
3
  export * from "./type.js";
5
- export interface SharedAFSStorageOptions {
4
+ export interface AFSStorageSQLiteOptions {
6
5
  url?: string;
7
6
  }
8
- export declare class SharedAFSStorage {
9
- options?: SharedAFSStorageOptions | undefined;
10
- constructor(options?: SharedAFSStorageOptions | undefined);
11
- private _db;
12
- get db(): Promise<import("drizzle-orm/libsql").LibSQLDatabase<Record<string, never>> & {
13
- vacuum?: () => Promise<void>;
14
- }>;
15
- withModule(module: AFSModule): AFSStorage;
16
- }
17
- export declare class AFSStorageWithModule implements AFSStorage {
18
- private db;
19
- private module;
20
- constructor(db: ReturnType<typeof initDatabase>, module: AFSModule);
7
+ export declare class AFSStorageSQLite implements AFSStorage {
8
+ module: AFSModule;
9
+ options?: AFSStorageSQLiteOptions | undefined;
10
+ constructor(module: AFSModule, options?: AFSStorageSQLiteOptions | undefined);
21
11
  private _tables?;
22
12
  private get tables();
23
13
  list(options?: AFSStorageListOptions): Promise<{
@@ -5,31 +5,17 @@ import { entriesTable } from "./models/entries.js";
5
5
  import { memoryTable } from "./models/memory.js";
6
6
  export * from "./type.js";
7
7
  const DEFAULT_AFS_STORAGE_LIST_LIMIT = 10;
8
- export class SharedAFSStorage {
9
- options;
10
- constructor(options) {
11
- this.options = options;
12
- }
13
- _db;
14
- get db() {
15
- this._db ??= initDatabase({ url: this.options?.url });
16
- return this._db;
17
- }
18
- withModule(module) {
19
- return new AFSStorageWithModule(this.db, module);
20
- }
21
- }
22
- export class AFSStorageWithModule {
23
- db;
8
+ export class AFSStorageSQLite {
24
9
  module;
25
- constructor(db, module) {
26
- this.db = db;
10
+ options;
11
+ constructor(module, options) {
27
12
  this.module = module;
13
+ this.options = options;
28
14
  }
29
15
  _tables;
30
16
  get tables() {
31
17
  if (!this._tables) {
32
- this._tables = this.db.then((db) => migrate(db, this.module).then(() => ({
18
+ this._tables = initDatabase({ url: this.options?.url }).then((db) => migrate(db, this.module).then(() => ({
33
19
  db,
34
20
  entries: entriesTable(this.module),
35
21
  compact: compactTable(this.module),
@@ -45,6 +45,7 @@ export interface AFSStorage {
45
45
  deletedCount: number;
46
46
  }>;
47
47
  }
48
+ export declare function isAFSStorage(value: any): value is AFSStorage;
48
49
  export type AFSStorageMigrations = {
49
50
  hash: string;
50
51
  sql: (module: AFSModule) => SQL[];
@@ -1 +1,8 @@
1
- export {};
1
+ export function isAFSStorage(value) {
2
+ return (!!value &&
3
+ typeof value === "object" &&
4
+ typeof value.create === "function" &&
5
+ typeof value.list === "function" &&
6
+ typeof value.read === "function" &&
7
+ typeof value.delete === "function");
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/afs-history",
3
- "version": "1.2.0-beta.9",
3
+ "version": "1.3.0-beta",
4
4
  "description": "AIGNE AFS module for managing chat history",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -50,8 +50,10 @@
50
50
  "@aigne/uuid": "^13.0.1",
51
51
  "radix3": "^1.1.2",
52
52
  "ufo": "^1.6.1",
53
- "@aigne/afs": "^1.4.0-beta.8",
54
- "@aigne/sqlite": "^0.4.9-beta.1"
53
+ "zod": "^3.25.67",
54
+ "@aigne/sqlite": "^0.4.9",
55
+ "@aigne/afs-utils": "^1.0.0",
56
+ "@aigne/afs": "^1.4.0"
55
57
  },
56
58
  "devDependencies": {
57
59
  "@types/bun": "^1.2.22",