@aigne/afs-user-profile-memory 1.3.0-beta.9 → 1.3.0

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
@@ -1,5 +1,229 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.3.0](https://github.com/AIGNE-io/aigne-framework/compare/afs-user-profile-memory-v1.3.0-beta.25...afs-user-profile-memory-v1.3.0) (2026-01-16)
4
+
5
+
6
+ ### Dependencies
7
+
8
+ * The following workspace dependencies were updated
9
+ * dependencies
10
+ * @aigne/afs bumped to 1.4.0
11
+ * @aigne/afs-history bumped to 1.2.0
12
+ * @aigne/core bumped to 1.72.0
13
+ * devDependencies
14
+ * @aigne/test-utils bumped to 0.5.69
15
+
16
+ ## [1.3.0-beta.25](https://github.com/AIGNE-io/aigne-framework/compare/afs-user-profile-memory-v1.3.0-beta.24...afs-user-profile-memory-v1.3.0-beta.25) (2026-01-16)
17
+
18
+
19
+ ### Features
20
+
21
+ * 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))
22
+ * **afs:** add basic AFS(AIGNE File System) support ([#505](https://github.com/AIGNE-io/aigne-framework/issues/505)) ([ac2a18a](https://github.com/AIGNE-io/aigne-framework/commit/ac2a18a82470a2f31c466f329386525eb1cdab6d))
23
+ * **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))
24
+ * **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))
25
+ * **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))
26
+ * 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))
27
+
28
+
29
+ ### Bug Fixes
30
+
31
+ * bump version ([696560f](https://github.com/AIGNE-io/aigne-framework/commit/696560fa2673eddcb4d00ac0523fbbbde7273cb3))
32
+ * bump version ([70d217c](https://github.com/AIGNE-io/aigne-framework/commit/70d217c8360dd0dda7f5f17011c4e92ec836e801))
33
+ * bump version ([af04b69](https://github.com/AIGNE-io/aigne-framework/commit/af04b6931951afa35d52065430acc7fef4b10087))
34
+ * bump version ([ba7ad18](https://github.com/AIGNE-io/aigne-framework/commit/ba7ad184fcf32b49bf0507a3cb638d20fb00690d))
35
+ * bump version ([93a1c10](https://github.com/AIGNE-io/aigne-framework/commit/93a1c10cf35f88eaafe91092481f5d087bd5b3a9))
36
+ * 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))
37
+
38
+
39
+ ### Dependencies
40
+
41
+ * The following workspace dependencies were updated
42
+ * dependencies
43
+ * @aigne/afs bumped to 1.4.0-beta.11
44
+ * @aigne/afs-history bumped to 1.2.0-beta.12
45
+ * @aigne/core bumped to 1.72.0-beta.25
46
+ * devDependencies
47
+ * @aigne/test-utils bumped to 0.5.69-beta.25
48
+
49
+ ## [1.3.0-beta.24](https://github.com/AIGNE-io/aigne-framework/compare/afs-user-profile-memory-v1.3.0-beta.23...afs-user-profile-memory-v1.3.0-beta.24) (2026-01-16)
50
+
51
+
52
+ ### Dependencies
53
+
54
+ * The following workspace dependencies were updated
55
+ * dependencies
56
+ * @aigne/afs bumped to 1.4.0-beta.10
57
+ * @aigne/afs-history bumped to 1.2.0-beta.11
58
+ * @aigne/core bumped to 1.72.0-beta.24
59
+ * devDependencies
60
+ * @aigne/test-utils bumped to 0.5.69-beta.24
61
+
62
+ ## [1.3.0-beta.23](https://github.com/AIGNE-io/aigne-framework/compare/afs-user-profile-memory-v1.3.0-beta.22...afs-user-profile-memory-v1.3.0-beta.23) (2026-01-15)
63
+
64
+
65
+ ### Dependencies
66
+
67
+ * The following workspace dependencies were updated
68
+ * dependencies
69
+ * @aigne/core bumped to 1.72.0-beta.23
70
+ * devDependencies
71
+ * @aigne/test-utils bumped to 0.5.69-beta.23
72
+
73
+ ## [1.3.0-beta.22](https://github.com/AIGNE-io/aigne-framework/compare/afs-user-profile-memory-v1.3.0-beta.21...afs-user-profile-memory-v1.3.0-beta.22) (2026-01-15)
74
+
75
+
76
+ ### Dependencies
77
+
78
+ * The following workspace dependencies were updated
79
+ * dependencies
80
+ * @aigne/core bumped to 1.72.0-beta.22
81
+ * devDependencies
82
+ * @aigne/test-utils bumped to 0.5.69-beta.22
83
+
84
+ ## [1.3.0-beta.21](https://github.com/AIGNE-io/aigne-framework/compare/afs-user-profile-memory-v1.3.0-beta.20...afs-user-profile-memory-v1.3.0-beta.21) (2026-01-15)
85
+
86
+
87
+ ### Dependencies
88
+
89
+ * The following workspace dependencies were updated
90
+ * dependencies
91
+ * @aigne/core bumped to 1.72.0-beta.21
92
+ * devDependencies
93
+ * @aigne/test-utils bumped to 0.5.69-beta.21
94
+
95
+ ## [1.3.0-beta.20](https://github.com/AIGNE-io/aigne-framework/compare/afs-user-profile-memory-v1.3.0-beta.19...afs-user-profile-memory-v1.3.0-beta.20) (2026-01-15)
96
+
97
+
98
+ ### Dependencies
99
+
100
+ * The following workspace dependencies were updated
101
+ * dependencies
102
+ * @aigne/core bumped to 1.72.0-beta.20
103
+ * devDependencies
104
+ * @aigne/test-utils bumped to 0.5.69-beta.20
105
+
106
+ ## [1.3.0-beta.19](https://github.com/AIGNE-io/aigne-framework/compare/afs-user-profile-memory-v1.3.0-beta.18...afs-user-profile-memory-v1.3.0-beta.19) (2026-01-14)
107
+
108
+
109
+ ### Features
110
+
111
+ * **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))
112
+
113
+
114
+ ### Bug Fixes
115
+
116
+ * 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))
117
+
118
+
119
+ ### Dependencies
120
+
121
+ * The following workspace dependencies were updated
122
+ * dependencies
123
+ * @aigne/afs bumped to 1.4.0-beta.9
124
+ * @aigne/afs-history bumped to 1.2.0-beta.10
125
+ * @aigne/core bumped to 1.72.0-beta.19
126
+ * devDependencies
127
+ * @aigne/test-utils bumped to 0.5.69-beta.19
128
+
129
+ ## [1.3.0-beta.18](https://github.com/AIGNE-io/aigne-framework/compare/afs-user-profile-memory-v1.3.0-beta.17...afs-user-profile-memory-v1.3.0-beta.18) (2026-01-13)
130
+
131
+
132
+ ### Dependencies
133
+
134
+ * The following workspace dependencies were updated
135
+ * dependencies
136
+ * @aigne/core bumped to 1.72.0-beta.18
137
+
138
+ ## [1.3.0-beta.17](https://github.com/AIGNE-io/aigne-framework/compare/afs-user-profile-memory-v1.3.0-beta.16...afs-user-profile-memory-v1.3.0-beta.17) (2026-01-12)
139
+
140
+
141
+ ### Dependencies
142
+
143
+ * The following workspace dependencies were updated
144
+ * dependencies
145
+ * @aigne/core bumped to 1.72.0-beta.17
146
+
147
+ ## [1.3.0-beta.16](https://github.com/AIGNE-io/aigne-framework/compare/afs-user-profile-memory-v1.3.0-beta.15...afs-user-profile-memory-v1.3.0-beta.16) (2026-01-12)
148
+
149
+
150
+ ### Dependencies
151
+
152
+ * The following workspace dependencies were updated
153
+ * dependencies
154
+ * @aigne/afs bumped to 1.4.0-beta.8
155
+ * @aigne/afs-history bumped to 1.2.0-beta.9
156
+ * @aigne/core bumped to 1.72.0-beta.16
157
+
158
+ ## [1.3.0-beta.15](https://github.com/AIGNE-io/aigne-framework/compare/afs-user-profile-memory-v1.3.0-beta.14...afs-user-profile-memory-v1.3.0-beta.15) (2026-01-10)
159
+
160
+
161
+ ### Dependencies
162
+
163
+ * The following workspace dependencies were updated
164
+ * dependencies
165
+ * @aigne/core bumped to 1.72.0-beta.15
166
+
167
+ ## [1.3.0-beta.14](https://github.com/AIGNE-io/aigne-framework/compare/afs-user-profile-memory-v1.3.0-beta.13...afs-user-profile-memory-v1.3.0-beta.14) (2026-01-09)
168
+
169
+
170
+ ### Dependencies
171
+
172
+ * The following workspace dependencies were updated
173
+ * dependencies
174
+ * @aigne/core bumped to 1.72.0-beta.14
175
+
176
+ ## [1.3.0-beta.13](https://github.com/AIGNE-io/aigne-framework/compare/afs-user-profile-memory-v1.3.0-beta.12...afs-user-profile-memory-v1.3.0-beta.13) (2026-01-08)
177
+
178
+
179
+ ### Bug Fixes
180
+
181
+ * bump version ([696560f](https://github.com/AIGNE-io/aigne-framework/commit/696560fa2673eddcb4d00ac0523fbbbde7273cb3))
182
+
183
+
184
+ ### Dependencies
185
+
186
+ * The following workspace dependencies were updated
187
+ * dependencies
188
+ * @aigne/afs bumped to 1.4.0-beta.7
189
+ * @aigne/afs-history bumped to 1.2.0-beta.8
190
+ * @aigne/core bumped to 1.72.0-beta.13
191
+
192
+ ## [1.3.0-beta.12](https://github.com/AIGNE-io/aigne-framework/compare/afs-user-profile-memory-v1.3.0-beta.11...afs-user-profile-memory-v1.3.0-beta.12) (2026-01-07)
193
+
194
+
195
+ ### Dependencies
196
+
197
+ * The following workspace dependencies were updated
198
+ * dependencies
199
+ * @aigne/core bumped to 1.72.0-beta.12
200
+
201
+ ## [1.3.0-beta.11](https://github.com/AIGNE-io/aigne-framework/compare/afs-user-profile-memory-v1.3.0-beta.10...afs-user-profile-memory-v1.3.0-beta.11) (2026-01-06)
202
+
203
+
204
+ ### Dependencies
205
+
206
+ * The following workspace dependencies were updated
207
+ * dependencies
208
+ * @aigne/afs bumped to 1.4.0-beta.6
209
+ * @aigne/afs-history bumped to 1.2.0-beta.7
210
+ * @aigne/core bumped to 1.72.0-beta.11
211
+
212
+ ## [1.3.0-beta.10](https://github.com/AIGNE-io/aigne-framework/compare/afs-user-profile-memory-v1.3.0-beta.9...afs-user-profile-memory-v1.3.0-beta.10) (2026-01-06)
213
+
214
+
215
+ ### Features
216
+
217
+ * **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))
218
+
219
+
220
+ ### Dependencies
221
+
222
+ * The following workspace dependencies were updated
223
+ * dependencies
224
+ * @aigne/afs-history bumped to 1.2.0-beta.6
225
+ * @aigne/core bumped to 1.72.0-beta.10
226
+
3
227
  ## [1.3.0-beta.9](https://github.com/AIGNE-io/aigne-framework/compare/afs-user-profile-memory-v1.3.0-beta.8...afs-user-profile-memory-v1.3.0-beta.9) (2026-01-02)
4
228
 
5
229
 
@@ -1,18 +1,34 @@
1
- import type { AFSEntry, AFSListOptions, AFSListResult, AFSModule, AFSReadResult, AFSRoot, AFSSearchOptions, AFSSearchResult, AFSWriteEntryPayload, AFSWriteResult } from "@aigne/afs";
1
+ import type { AFSAccessMode, AFSEntry, AFSListOptions, AFSListResult, AFSModule, AFSModuleLoadParams, AFSOperationOptions, AFSReadResult, AFSRoot, AFSSearchOptions, AFSSearchResult, AFSWriteEntryPayload, AFSWriteResult } from "@aigne/afs";
2
2
  import { SharedAFSStorage, type SharedAFSStorageOptions } from "@aigne/afs-history";
3
- import { AIAgent, type Context } from "@aigne/core";
4
- import type { z } from "zod";
3
+ import { AIAgent } from "@aigne/core";
4
+ import { z } from "zod";
5
5
  import { userProfileJsonPathSchema } from "./schema.js";
6
6
  export interface UserProfileMemoryOptions {
7
- context: Context;
8
7
  storage?: SharedAFSStorage | SharedAFSStorageOptions;
9
8
  description?: string;
9
+ /**
10
+ * Access mode for this module.
11
+ * @default "readwrite"
12
+ */
13
+ accessMode?: AFSAccessMode;
10
14
  }
11
15
  export declare class UserProfileMemory implements AFSModule {
12
16
  options: UserProfileMemoryOptions;
17
+ static schema(): z.ZodObject<{
18
+ description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
19
+ accessMode: z.ZodType<"readonly" | "readwrite" | undefined, z.ZodTypeDef, "readonly" | "readwrite" | undefined>;
20
+ }, "strip", z.ZodTypeAny, {
21
+ description?: string | undefined;
22
+ accessMode?: "readonly" | "readwrite" | undefined;
23
+ }, {
24
+ description?: string | undefined;
25
+ accessMode?: "readonly" | "readwrite" | undefined;
26
+ }>;
27
+ static load({ parsed }: AFSModuleLoadParams): Promise<UserProfileMemory>;
13
28
  constructor(options: UserProfileMemoryOptions);
14
29
  private storage;
15
30
  readonly name: string;
31
+ readonly accessMode: AFSAccessMode;
16
32
  description?: string | undefined;
17
33
  extractor: AIAgent<{
18
34
  schema: any;
@@ -20,7 +36,7 @@ export declare class UserProfileMemory implements AFSModule {
20
36
  entry: AFSEntry;
21
37
  }, z.infer<typeof userProfileJsonPathSchema>>;
22
38
  onMount(afs: AFSRoot): void;
23
- updateProfile(entry: AFSEntry): Promise<AFSWriteResult>;
39
+ updateProfile(entry: AFSEntry, options?: AFSOperationOptions): Promise<AFSWriteResult>;
24
40
  list(_path: string, _options?: AFSListOptions): Promise<AFSListResult>;
25
41
  read(path: string): Promise<AFSReadResult>;
26
42
  write(path: string, entry: AFSWriteEntryPayload): Promise<AFSWriteResult>;
package/lib/cjs/index.js CHANGED
@@ -3,12 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UserProfileMemory = void 0;
4
4
  const afs_history_1 = require("@aigne/afs-history");
5
5
  const core_1 = require("@aigne/core");
6
+ const schema_js_1 = require("@aigne/core/loader/schema.js");
6
7
  const logger_js_1 = require("@aigne/core/utils/logger.js");
7
8
  const uuid_1 = require("@aigne/uuid");
8
9
  const fast_json_patch_1 = require("fast-json-patch");
10
+ const zod_1 = require("zod");
9
11
  const zod_to_json_schema_1 = require("zod-to-json-schema");
10
12
  const prompt_js_1 = require("./prompt.js");
11
- const schema_js_1 = require("./schema.js");
13
+ const schema_js_2 = require("./schema.js");
12
14
  const DEFAULT_DESCRIPTION = `\
13
15
  User Profile Memory: This contains structured information about the user that has been \
14
16
  automatically extracted from previous conversations. It includes personal details such as name, \
@@ -16,8 +18,19 @@ location, interests, family members, projects, and other relevant information th
16
18
  Use this memory to personalize responses and maintain context about the user across conversations. \
17
19
  The profile is continuously updated as new information is learned.
18
20
  `;
21
+ const userProfileMemoryOptionsSchema = (0, schema_js_1.camelizeSchema)(zod_1.z.object({
22
+ description: (0, schema_js_1.optionalize)(zod_1.z.string().describe("Description of the user profile memory")),
23
+ accessMode: (0, schema_js_1.optionalize)(zod_1.z.enum(["readonly", "readwrite"]).describe("Access mode for this module")),
24
+ }));
19
25
  class UserProfileMemory {
20
26
  options;
27
+ static schema() {
28
+ return userProfileMemoryOptionsSchema;
29
+ }
30
+ static async load({ parsed }) {
31
+ const valid = await UserProfileMemory.schema().parseAsync(parsed);
32
+ return new UserProfileMemory(valid);
33
+ }
21
34
  constructor(options) {
22
35
  this.options = options;
23
36
  this.storage =
@@ -25,28 +38,35 @@ class UserProfileMemory {
25
38
  ? options.storage.withModule(this)
26
39
  : new afs_history_1.SharedAFSStorage(options?.storage).withModule(this);
27
40
  this.description = options.description || DEFAULT_DESCRIPTION;
41
+ this.accessMode = options.accessMode ?? "readwrite";
28
42
  }
29
43
  storage;
30
44
  name = "user-profile-memory";
45
+ accessMode;
31
46
  description;
32
47
  extractor = core_1.AIAgent.from({
33
48
  instructions: prompt_js_1.USER_PROFILE_MEMORY_EXTRACTOR_PROMPT,
34
- outputSchema: schema_js_1.userProfileJsonPathSchema,
49
+ outputSchema: schema_js_2.userProfileJsonPathSchema,
35
50
  });
36
51
  onMount(afs) {
37
- afs.on("historyCreated", async ({ entry }) => {
52
+ afs.on("historyCreated", async ({ entry }, options) => {
38
53
  try {
39
- await this.updateProfile(entry);
54
+ await this.updateProfile(entry, options);
40
55
  }
41
56
  catch (error) {
42
57
  logger_js_1.logger.error("Failed to update user profile memory", error);
43
58
  }
44
59
  });
45
60
  }
46
- async updateProfile(entry) {
61
+ async updateProfile(entry, options) {
47
62
  const { data: previous } = await this.read("/");
48
- const { ops } = await this.options.context.newContext({ reset: true }).invoke(this.extractor, {
49
- schema: (0, zod_to_json_schema_1.zodToJsonSchema)(schema_js_1.userProfileSchema),
63
+ if (typeof options?.context?.newContext !== "function") {
64
+ throw new Error("Context is not valid for user profile extraction");
65
+ }
66
+ const { ops } = await (options?.context)
67
+ .newContext({ reset: true })
68
+ .invoke(this.extractor, {
69
+ schema: (0, zod_to_json_schema_1.zodToJsonSchema)(schema_js_2.userProfileSchema),
50
70
  profile: previous?.content,
51
71
  entry,
52
72
  });
@@ -1,18 +1,34 @@
1
- import type { AFSEntry, AFSListOptions, AFSListResult, AFSModule, AFSReadResult, AFSRoot, AFSSearchOptions, AFSSearchResult, AFSWriteEntryPayload, AFSWriteResult } from "@aigne/afs";
1
+ import type { AFSAccessMode, AFSEntry, AFSListOptions, AFSListResult, AFSModule, AFSModuleLoadParams, AFSOperationOptions, AFSReadResult, AFSRoot, AFSSearchOptions, AFSSearchResult, AFSWriteEntryPayload, AFSWriteResult } from "@aigne/afs";
2
2
  import { SharedAFSStorage, type SharedAFSStorageOptions } from "@aigne/afs-history";
3
- import { AIAgent, type Context } from "@aigne/core";
4
- import type { z } from "zod";
3
+ import { AIAgent } from "@aigne/core";
4
+ import { z } from "zod";
5
5
  import { userProfileJsonPathSchema } from "./schema.js";
6
6
  export interface UserProfileMemoryOptions {
7
- context: Context;
8
7
  storage?: SharedAFSStorage | SharedAFSStorageOptions;
9
8
  description?: string;
9
+ /**
10
+ * Access mode for this module.
11
+ * @default "readwrite"
12
+ */
13
+ accessMode?: AFSAccessMode;
10
14
  }
11
15
  export declare class UserProfileMemory implements AFSModule {
12
16
  options: UserProfileMemoryOptions;
17
+ static schema(): z.ZodObject<{
18
+ description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
19
+ accessMode: z.ZodType<"readonly" | "readwrite" | undefined, z.ZodTypeDef, "readonly" | "readwrite" | undefined>;
20
+ }, "strip", z.ZodTypeAny, {
21
+ description?: string | undefined;
22
+ accessMode?: "readonly" | "readwrite" | undefined;
23
+ }, {
24
+ description?: string | undefined;
25
+ accessMode?: "readonly" | "readwrite" | undefined;
26
+ }>;
27
+ static load({ parsed }: AFSModuleLoadParams): Promise<UserProfileMemory>;
13
28
  constructor(options: UserProfileMemoryOptions);
14
29
  private storage;
15
30
  readonly name: string;
31
+ readonly accessMode: AFSAccessMode;
16
32
  description?: string | undefined;
17
33
  extractor: AIAgent<{
18
34
  schema: any;
@@ -20,7 +36,7 @@ export declare class UserProfileMemory implements AFSModule {
20
36
  entry: AFSEntry;
21
37
  }, z.infer<typeof userProfileJsonPathSchema>>;
22
38
  onMount(afs: AFSRoot): void;
23
- updateProfile(entry: AFSEntry): Promise<AFSWriteResult>;
39
+ updateProfile(entry: AFSEntry, options?: AFSOperationOptions): Promise<AFSWriteResult>;
24
40
  list(_path: string, _options?: AFSListOptions): Promise<AFSListResult>;
25
41
  read(path: string): Promise<AFSReadResult>;
26
42
  write(path: string, entry: AFSWriteEntryPayload): Promise<AFSWriteResult>;
@@ -1,18 +1,34 @@
1
- import type { AFSEntry, AFSListOptions, AFSListResult, AFSModule, AFSReadResult, AFSRoot, AFSSearchOptions, AFSSearchResult, AFSWriteEntryPayload, AFSWriteResult } from "@aigne/afs";
1
+ import type { AFSAccessMode, AFSEntry, AFSListOptions, AFSListResult, AFSModule, AFSModuleLoadParams, AFSOperationOptions, AFSReadResult, AFSRoot, AFSSearchOptions, AFSSearchResult, AFSWriteEntryPayload, AFSWriteResult } from "@aigne/afs";
2
2
  import { SharedAFSStorage, type SharedAFSStorageOptions } from "@aigne/afs-history";
3
- import { AIAgent, type Context } from "@aigne/core";
4
- import type { z } from "zod";
3
+ import { AIAgent } from "@aigne/core";
4
+ import { z } from "zod";
5
5
  import { userProfileJsonPathSchema } from "./schema.js";
6
6
  export interface UserProfileMemoryOptions {
7
- context: Context;
8
7
  storage?: SharedAFSStorage | SharedAFSStorageOptions;
9
8
  description?: string;
9
+ /**
10
+ * Access mode for this module.
11
+ * @default "readwrite"
12
+ */
13
+ accessMode?: AFSAccessMode;
10
14
  }
11
15
  export declare class UserProfileMemory implements AFSModule {
12
16
  options: UserProfileMemoryOptions;
17
+ static schema(): z.ZodObject<{
18
+ description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
19
+ accessMode: z.ZodType<"readonly" | "readwrite" | undefined, z.ZodTypeDef, "readonly" | "readwrite" | undefined>;
20
+ }, "strip", z.ZodTypeAny, {
21
+ description?: string | undefined;
22
+ accessMode?: "readonly" | "readwrite" | undefined;
23
+ }, {
24
+ description?: string | undefined;
25
+ accessMode?: "readonly" | "readwrite" | undefined;
26
+ }>;
27
+ static load({ parsed }: AFSModuleLoadParams): Promise<UserProfileMemory>;
13
28
  constructor(options: UserProfileMemoryOptions);
14
29
  private storage;
15
30
  readonly name: string;
31
+ readonly accessMode: AFSAccessMode;
16
32
  description?: string | undefined;
17
33
  extractor: AIAgent<{
18
34
  schema: any;
@@ -20,7 +36,7 @@ export declare class UserProfileMemory implements AFSModule {
20
36
  entry: AFSEntry;
21
37
  }, z.infer<typeof userProfileJsonPathSchema>>;
22
38
  onMount(afs: AFSRoot): void;
23
- updateProfile(entry: AFSEntry): Promise<AFSWriteResult>;
39
+ updateProfile(entry: AFSEntry, options?: AFSOperationOptions): Promise<AFSWriteResult>;
24
40
  list(_path: string, _options?: AFSListOptions): Promise<AFSListResult>;
25
41
  read(path: string): Promise<AFSReadResult>;
26
42
  write(path: string, entry: AFSWriteEntryPayload): Promise<AFSWriteResult>;
package/lib/esm/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import { SharedAFSStorage, } from "@aigne/afs-history";
2
2
  import { AIAgent } from "@aigne/core";
3
+ import { camelizeSchema, optionalize } from "@aigne/core/loader/schema.js";
3
4
  import { logger } from "@aigne/core/utils/logger.js";
4
5
  import { v7 } from "@aigne/uuid";
5
6
  import { applyPatch } from "fast-json-patch";
7
+ import { z } from "zod";
6
8
  import { zodToJsonSchema } from "zod-to-json-schema";
7
9
  import { USER_PROFILE_MEMORY_EXTRACTOR_PROMPT } from "./prompt.js";
8
10
  import { userProfileJsonPathSchema, userProfileSchema } from "./schema.js";
@@ -13,8 +15,19 @@ location, interests, family members, projects, and other relevant information th
13
15
  Use this memory to personalize responses and maintain context about the user across conversations. \
14
16
  The profile is continuously updated as new information is learned.
15
17
  `;
18
+ const userProfileMemoryOptionsSchema = camelizeSchema(z.object({
19
+ description: optionalize(z.string().describe("Description of the user profile memory")),
20
+ accessMode: optionalize(z.enum(["readonly", "readwrite"]).describe("Access mode for this module")),
21
+ }));
16
22
  export class UserProfileMemory {
17
23
  options;
24
+ static schema() {
25
+ return userProfileMemoryOptionsSchema;
26
+ }
27
+ static async load({ parsed }) {
28
+ const valid = await UserProfileMemory.schema().parseAsync(parsed);
29
+ return new UserProfileMemory(valid);
30
+ }
18
31
  constructor(options) {
19
32
  this.options = options;
20
33
  this.storage =
@@ -22,27 +35,34 @@ export class UserProfileMemory {
22
35
  ? options.storage.withModule(this)
23
36
  : new SharedAFSStorage(options?.storage).withModule(this);
24
37
  this.description = options.description || DEFAULT_DESCRIPTION;
38
+ this.accessMode = options.accessMode ?? "readwrite";
25
39
  }
26
40
  storage;
27
41
  name = "user-profile-memory";
42
+ accessMode;
28
43
  description;
29
44
  extractor = AIAgent.from({
30
45
  instructions: USER_PROFILE_MEMORY_EXTRACTOR_PROMPT,
31
46
  outputSchema: userProfileJsonPathSchema,
32
47
  });
33
48
  onMount(afs) {
34
- afs.on("historyCreated", async ({ entry }) => {
49
+ afs.on("historyCreated", async ({ entry }, options) => {
35
50
  try {
36
- await this.updateProfile(entry);
51
+ await this.updateProfile(entry, options);
37
52
  }
38
53
  catch (error) {
39
54
  logger.error("Failed to update user profile memory", error);
40
55
  }
41
56
  });
42
57
  }
43
- async updateProfile(entry) {
58
+ async updateProfile(entry, options) {
44
59
  const { data: previous } = await this.read("/");
45
- const { ops } = await this.options.context.newContext({ reset: true }).invoke(this.extractor, {
60
+ if (typeof options?.context?.newContext !== "function") {
61
+ throw new Error("Context is not valid for user profile extraction");
62
+ }
63
+ const { ops } = await (options?.context)
64
+ .newContext({ reset: true })
65
+ .invoke(this.extractor, {
46
66
  schema: zodToJsonSchema(userProfileSchema),
47
67
  profile: previous?.content,
48
68
  entry,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/afs-user-profile-memory",
3
- "version": "1.3.0-beta.9",
3
+ "version": "1.3.0",
4
4
  "description": "AIGNE AFS module for user profile memory",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -51,15 +51,16 @@
51
51
  "fast-json-patch": "^3.1.1",
52
52
  "zod": "^3.25.67",
53
53
  "zod-to-json-schema": "^3.24.6",
54
- "@aigne/afs": "^1.4.0-beta.5",
55
- "@aigne/afs-history": "^1.2.0-beta.5",
56
- "@aigne/core": "^1.72.0-beta.9"
54
+ "@aigne/afs": "^1.4.0",
55
+ "@aigne/afs-history": "^1.2.0",
56
+ "@aigne/core": "^1.72.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/bun": "^1.2.22",
60
60
  "npm-run-all": "^4.1.5",
61
61
  "rimraf": "^6.0.1",
62
- "typescript": "^5.9.2"
62
+ "typescript": "^5.9.2",
63
+ "@aigne/test-utils": "^0.5.69"
63
64
  },
64
65
  "scripts": {
65
66
  "lint": "tsc --noEmit",