@aigne/afs-user-profile-memory 1.4.0-beta → 1.74.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/dist/index.cjs ADDED
@@ -0,0 +1,102 @@
1
+ const require_prompt = require('./prompt.cjs');
2
+ const require_schema = require('./schema.cjs');
3
+ let _aigne_afs_utils_zod = require("@aigne/afs/utils/zod");
4
+ let _aigne_afs_history = require("@aigne/afs-history");
5
+ let _aigne_core = require("@aigne/core");
6
+ let _aigne_core_utils_logger = require("@aigne/core/utils/logger");
7
+ let _aigne_uuid = require("@aigne/uuid");
8
+ let fast_json_patch = require("fast-json-patch");
9
+ let zod = require("zod");
10
+ let zod_to_json_schema = require("zod-to-json-schema");
11
+
12
+ //#region src/index.ts
13
+ const DEFAULT_DESCRIPTION = `\
14
+ User Profile Memory: This contains structured information about the user that has been \
15
+ automatically extracted from previous conversations. It includes personal details such as name, \
16
+ location, interests, family members, projects, and other relevant information the user has shared. \
17
+ Use this memory to personalize responses and maintain context about the user across conversations. \
18
+ The profile is continuously updated as new information is learned.
19
+ `;
20
+ const userProfileMemoryOptionsSchema = (0, _aigne_afs_utils_zod.camelize)(zod.z.object({
21
+ description: (0, _aigne_afs_utils_zod.optionalize)(zod.z.string().describe("Description of the user profile memory")),
22
+ accessMode: (0, _aigne_afs_utils_zod.optionalize)(zod.z.enum(["readonly", "readwrite"]).describe("Access mode for this module"))
23
+ }));
24
+ var UserProfileMemory = class UserProfileMemory {
25
+ static schema() {
26
+ return userProfileMemoryOptionsSchema;
27
+ }
28
+ static async load({ parsed }) {
29
+ return new UserProfileMemory(await UserProfileMemory.schema().parseAsync(parsed));
30
+ }
31
+ constructor(options) {
32
+ this.options = options;
33
+ this.storage = (0, _aigne_afs_history.isAFSStorage)(options?.storage) ? options.storage : new _aigne_afs_history.AFSStorageSQLite(this, options?.storage);
34
+ this.description = options.description || DEFAULT_DESCRIPTION;
35
+ this.accessMode = options.accessMode ?? "readwrite";
36
+ }
37
+ storage;
38
+ name = "user-profile-memory";
39
+ accessMode;
40
+ description;
41
+ extractor = _aigne_core.AIAgent.from({
42
+ instructions: require_prompt.USER_PROFILE_MEMORY_EXTRACTOR_PROMPT,
43
+ outputSchema: require_schema.userProfileJsonPathSchema
44
+ });
45
+ onMount(afs) {
46
+ afs.on("historyCreated", async ({ entry }, options) => {
47
+ try {
48
+ await this.updateProfile(entry, options);
49
+ } catch (error) {
50
+ _aigne_core_utils_logger.logger.error("Failed to update user profile memory", error);
51
+ }
52
+ });
53
+ }
54
+ async updateProfile(entry, options) {
55
+ const { data: previous } = await this.read("/");
56
+ if (typeof (options?.context)?.newContext !== "function") throw new Error("Context is not valid for user profile extraction");
57
+ const { ops } = await (options?.context).newContext({ reset: true }).invoke(this.extractor, {
58
+ schema: (0, zod_to_json_schema.zodToJsonSchema)(require_schema.userProfileSchema),
59
+ profile: previous?.content,
60
+ entry
61
+ });
62
+ const profile = (0, fast_json_patch.applyPatch)(previous?.content || {}, ops.map((op) => {
63
+ const value = typeof op.value === "string" && op.value ? JSON.parse(op.value) : op.value;
64
+ return {
65
+ ...op,
66
+ value
67
+ };
68
+ })).newDocument;
69
+ return await this.write("/", { content: profile });
70
+ }
71
+ async list(_path, _options) {
72
+ const { data: profile } = await this.read("/");
73
+ return { data: profile ? [profile] : [] };
74
+ }
75
+ async read(path) {
76
+ if (path !== "/") return {};
77
+ const data = (await this.storage.list({
78
+ orderBy: [["createdAt", "desc"]],
79
+ limit: 1
80
+ })).data.at(0);
81
+ if (data) data.description = this.description;
82
+ return { data };
83
+ }
84
+ async write(path, entry) {
85
+ const { data: previous } = await this.read("/");
86
+ const data = await this.storage.create({
87
+ ...previous,
88
+ ...entry,
89
+ id: previous?.id || (0, _aigne_uuid.v7)(),
90
+ path
91
+ });
92
+ if (data) data.description = this.description;
93
+ return { data };
94
+ }
95
+ async search(_path, _query, _options) {
96
+ const { data: profile } = await this.read("/");
97
+ return { data: profile ? [profile] : [] };
98
+ }
99
+ };
100
+
101
+ //#endregion
102
+ exports.UserProfileMemory = UserProfileMemory;
@@ -0,0 +1,54 @@
1
+ import { userProfileJsonPathSchema } from "./schema.cjs";
2
+ import { AFSAccessMode, AFSEntry, AFSListOptions, AFSListResult, AFSModule, AFSModuleLoadParams, AFSOperationOptions, AFSReadResult, AFSRoot, AFSSearchOptions, AFSSearchResult, AFSWriteEntryPayload, AFSWriteResult } from "@aigne/afs";
3
+ import { AFSStorage, AFSStorageSQLiteOptions } from "@aigne/afs-history";
4
+ import { AIAgent } from "@aigne/core";
5
+ import { z } from "zod";
6
+
7
+ //#region src/index.d.ts
8
+ interface UserProfileMemoryOptions {
9
+ storage?: AFSStorage | AFSStorageSQLiteOptions;
10
+ description?: string;
11
+ /**
12
+ * Access mode for this module.
13
+ * @default "readwrite"
14
+ */
15
+ accessMode?: AFSAccessMode;
16
+ }
17
+ declare class UserProfileMemory implements AFSModule {
18
+ options: UserProfileMemoryOptions;
19
+ static schema(): z.ZodEffects<z.ZodObject<{
20
+ description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
21
+ accessMode: z.ZodType<"readonly" | "readwrite" | undefined, z.ZodTypeDef, "readonly" | "readwrite" | undefined>;
22
+ }, "strip", z.ZodTypeAny, {
23
+ description?: string | undefined;
24
+ accessMode?: "readonly" | "readwrite" | undefined;
25
+ }, {
26
+ description?: string | undefined;
27
+ accessMode?: "readonly" | "readwrite" | undefined;
28
+ }>, {
29
+ description?: string | undefined;
30
+ accessMode?: "readonly" | "readwrite" | undefined;
31
+ }, any>;
32
+ static load({
33
+ parsed
34
+ }: AFSModuleLoadParams): Promise<UserProfileMemory>;
35
+ constructor(options: UserProfileMemoryOptions);
36
+ private storage;
37
+ readonly name: string;
38
+ readonly accessMode: AFSAccessMode;
39
+ description?: string | undefined;
40
+ extractor: AIAgent<{
41
+ schema: any;
42
+ profile?: any;
43
+ entry: AFSEntry;
44
+ }, z.infer<typeof userProfileJsonPathSchema>>;
45
+ onMount(afs: AFSRoot): void;
46
+ updateProfile(entry: AFSEntry, options?: AFSOperationOptions): Promise<AFSWriteResult>;
47
+ list(_path: string, _options?: AFSListOptions): Promise<AFSListResult>;
48
+ read(path: string): Promise<AFSReadResult>;
49
+ write(path: string, entry: AFSWriteEntryPayload): Promise<AFSWriteResult>;
50
+ search(_path: string, _query: string, _options?: AFSSearchOptions): Promise<AFSSearchResult>;
51
+ }
52
+ //#endregion
53
+ export { UserProfileMemory, UserProfileMemoryOptions };
54
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;UA+BiB,wBAAA;EAAA,OAAA,GACL,UAAA,GAAa,uBAAA;EAAA,WAAA;EAAA;;;AA0BzB;EA1ByB,UAAA,GAMV,aAAA;AAAA;AAAA,cAoBF,iBAAA,YAA6B,SAAA;EAAA,OAAA,EAUZ,wBAAA;EAAA,OAAA,OAAA,GATf,CAAA,CAAA,UAAA,CAAA,CAAA,CAAA,SAAA;IAAA,WAAA;;;;;;;;;;;;;;KAIiB,mBAAA,GAAmB,OAAA,CAAA,iBAAA;EAAA,YAAA,OAAA,EAKrB,wBAAA;EAAA,QAAA,OAAA;EAAA,SAAA,IAAA;EAAA,SAAA,UAAA,EAaP,aAAA;EAAA,WAAA;EAAA,SAAA,EAIV,OAAA;IAAA,MAAA;IAAA,OAAA;IAAA,KAAA,EAC4B,QAAA;EAAA,GACrC,CAAA,CAAE,KAAA,QAAa,yBAAA;EAAA,QAAA,GAAA,EAMJ,OAAA;EAAA,cAAA,KAAA,EAUc,QAAA,EAAA,OAAA,GAAoB,mBAAA,GAAmB,OAAA,CAAA,cAAA;EAAA,KAAA,KAAA,UAAA,QAAA,GA0B7B,cAAA,GAAiB,OAAA,CAAQ,aAAA;EAAA,KAAA,IAAA,WAKpC,OAAA,CAAQ,aAAA;EAAA,MAAA,IAAA,UAAA,KAAA,EAaD,oBAAA,GAAuB,OAAA,CAAQ,cAAA;EAAA,OAAA,KAAA,UAAA,MAAA,UAAA,QAAA,GAenD,gBAAA,GACV,OAAA,CAAQ,eAAA;AAAA"}
@@ -0,0 +1,54 @@
1
+ import { userProfileJsonPathSchema } from "./schema.mjs";
2
+ import { AFSStorage, AFSStorageSQLiteOptions } from "@aigne/afs-history";
3
+ import { AIAgent } from "@aigne/core";
4
+ import { z } from "zod";
5
+ import { AFSAccessMode, AFSEntry, AFSListOptions, AFSListResult, AFSModule, AFSModuleLoadParams, AFSOperationOptions, AFSReadResult, AFSRoot, AFSSearchOptions, AFSSearchResult, AFSWriteEntryPayload, AFSWriteResult } from "@aigne/afs";
6
+
7
+ //#region src/index.d.ts
8
+ interface UserProfileMemoryOptions {
9
+ storage?: AFSStorage | AFSStorageSQLiteOptions;
10
+ description?: string;
11
+ /**
12
+ * Access mode for this module.
13
+ * @default "readwrite"
14
+ */
15
+ accessMode?: AFSAccessMode;
16
+ }
17
+ declare class UserProfileMemory implements AFSModule {
18
+ options: UserProfileMemoryOptions;
19
+ static schema(): z.ZodEffects<z.ZodObject<{
20
+ description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
21
+ accessMode: z.ZodType<"readonly" | "readwrite" | undefined, z.ZodTypeDef, "readonly" | "readwrite" | undefined>;
22
+ }, "strip", z.ZodTypeAny, {
23
+ description?: string | undefined;
24
+ accessMode?: "readonly" | "readwrite" | undefined;
25
+ }, {
26
+ description?: string | undefined;
27
+ accessMode?: "readonly" | "readwrite" | undefined;
28
+ }>, {
29
+ description?: string | undefined;
30
+ accessMode?: "readonly" | "readwrite" | undefined;
31
+ }, any>;
32
+ static load({
33
+ parsed
34
+ }: AFSModuleLoadParams): Promise<UserProfileMemory>;
35
+ constructor(options: UserProfileMemoryOptions);
36
+ private storage;
37
+ readonly name: string;
38
+ readonly accessMode: AFSAccessMode;
39
+ description?: string | undefined;
40
+ extractor: AIAgent<{
41
+ schema: any;
42
+ profile?: any;
43
+ entry: AFSEntry;
44
+ }, z.infer<typeof userProfileJsonPathSchema>>;
45
+ onMount(afs: AFSRoot): void;
46
+ updateProfile(entry: AFSEntry, options?: AFSOperationOptions): Promise<AFSWriteResult>;
47
+ list(_path: string, _options?: AFSListOptions): Promise<AFSListResult>;
48
+ read(path: string): Promise<AFSReadResult>;
49
+ write(path: string, entry: AFSWriteEntryPayload): Promise<AFSWriteResult>;
50
+ search(_path: string, _query: string, _options?: AFSSearchOptions): Promise<AFSSearchResult>;
51
+ }
52
+ //#endregion
53
+ export { UserProfileMemory, UserProfileMemoryOptions };
54
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;UA+BiB,wBAAA;EAAA,OAAA,GACL,UAAA,GAAa,uBAAA;EAAA,WAAA;EAAA;;;AA0BzB;EA1ByB,UAAA,GAMV,aAAA;AAAA;AAAA,cAoBF,iBAAA,YAA6B,SAAA;EAAA,OAAA,EAUZ,wBAAA;EAAA,OAAA,OAAA,GATf,CAAA,CAAA,UAAA,CAAA,CAAA,CAAA,SAAA;IAAA,WAAA;;;;;;;;;;;;;;KAIiB,mBAAA,GAAmB,OAAA,CAAA,iBAAA;EAAA,YAAA,OAAA,EAKrB,wBAAA;EAAA,QAAA,OAAA;EAAA,SAAA,IAAA;EAAA,SAAA,UAAA,EAaP,aAAA;EAAA,WAAA;EAAA,SAAA,EAIV,OAAA;IAAA,MAAA;IAAA,OAAA;IAAA,KAAA,EAC4B,QAAA;EAAA,GACrC,CAAA,CAAE,KAAA,QAAa,yBAAA;EAAA,QAAA,GAAA,EAMJ,OAAA;EAAA,cAAA,KAAA,EAUc,QAAA,EAAA,OAAA,GAAoB,mBAAA,GAAmB,OAAA,CAAA,cAAA;EAAA,KAAA,KAAA,UAAA,QAAA,GA0B7B,cAAA,GAAiB,OAAA,CAAQ,aAAA;EAAA,KAAA,IAAA,WAKpC,OAAA,CAAQ,aAAA;EAAA,MAAA,IAAA,UAAA,KAAA,EAaD,oBAAA,GAAuB,OAAA,CAAQ,cAAA;EAAA,OAAA,KAAA,UAAA,MAAA,UAAA,QAAA,GAenD,gBAAA,GACV,OAAA,CAAQ,eAAA;AAAA"}
package/dist/index.mjs ADDED
@@ -0,0 +1,103 @@
1
+ import { USER_PROFILE_MEMORY_EXTRACTOR_PROMPT } from "./prompt.mjs";
2
+ import { userProfileJsonPathSchema, userProfileSchema } from "./schema.mjs";
3
+ import { camelize, optionalize } from "@aigne/afs/utils/zod";
4
+ import { AFSStorageSQLite, isAFSStorage } from "@aigne/afs-history";
5
+ import { AIAgent } from "@aigne/core";
6
+ import { logger } from "@aigne/core/utils/logger";
7
+ import { v7 } from "@aigne/uuid";
8
+ import { applyPatch } from "fast-json-patch";
9
+ import { z } from "zod";
10
+ import { zodToJsonSchema } from "zod-to-json-schema";
11
+
12
+ //#region src/index.ts
13
+ const DEFAULT_DESCRIPTION = `\
14
+ User Profile Memory: This contains structured information about the user that has been \
15
+ automatically extracted from previous conversations. It includes personal details such as name, \
16
+ location, interests, family members, projects, and other relevant information the user has shared. \
17
+ Use this memory to personalize responses and maintain context about the user across conversations. \
18
+ The profile is continuously updated as new information is learned.
19
+ `;
20
+ const userProfileMemoryOptionsSchema = camelize(z.object({
21
+ description: optionalize(z.string().describe("Description of the user profile memory")),
22
+ accessMode: optionalize(z.enum(["readonly", "readwrite"]).describe("Access mode for this module"))
23
+ }));
24
+ var UserProfileMemory = class UserProfileMemory {
25
+ static schema() {
26
+ return userProfileMemoryOptionsSchema;
27
+ }
28
+ static async load({ parsed }) {
29
+ return new UserProfileMemory(await UserProfileMemory.schema().parseAsync(parsed));
30
+ }
31
+ constructor(options) {
32
+ this.options = options;
33
+ this.storage = isAFSStorage(options?.storage) ? options.storage : new AFSStorageSQLite(this, options?.storage);
34
+ this.description = options.description || DEFAULT_DESCRIPTION;
35
+ this.accessMode = options.accessMode ?? "readwrite";
36
+ }
37
+ storage;
38
+ name = "user-profile-memory";
39
+ accessMode;
40
+ description;
41
+ extractor = AIAgent.from({
42
+ instructions: USER_PROFILE_MEMORY_EXTRACTOR_PROMPT,
43
+ outputSchema: userProfileJsonPathSchema
44
+ });
45
+ onMount(afs) {
46
+ afs.on("historyCreated", async ({ entry }, options) => {
47
+ try {
48
+ await this.updateProfile(entry, options);
49
+ } catch (error) {
50
+ logger.error("Failed to update user profile memory", error);
51
+ }
52
+ });
53
+ }
54
+ async updateProfile(entry, options) {
55
+ const { data: previous } = await this.read("/");
56
+ if (typeof (options?.context)?.newContext !== "function") throw new Error("Context is not valid for user profile extraction");
57
+ const { ops } = await (options?.context).newContext({ reset: true }).invoke(this.extractor, {
58
+ schema: zodToJsonSchema(userProfileSchema),
59
+ profile: previous?.content,
60
+ entry
61
+ });
62
+ const profile = applyPatch(previous?.content || {}, ops.map((op) => {
63
+ const value = typeof op.value === "string" && op.value ? JSON.parse(op.value) : op.value;
64
+ return {
65
+ ...op,
66
+ value
67
+ };
68
+ })).newDocument;
69
+ return await this.write("/", { content: profile });
70
+ }
71
+ async list(_path, _options) {
72
+ const { data: profile } = await this.read("/");
73
+ return { data: profile ? [profile] : [] };
74
+ }
75
+ async read(path) {
76
+ if (path !== "/") return {};
77
+ const data = (await this.storage.list({
78
+ orderBy: [["createdAt", "desc"]],
79
+ limit: 1
80
+ })).data.at(0);
81
+ if (data) data.description = this.description;
82
+ return { data };
83
+ }
84
+ async write(path, entry) {
85
+ const { data: previous } = await this.read("/");
86
+ const data = await this.storage.create({
87
+ ...previous,
88
+ ...entry,
89
+ id: previous?.id || v7(),
90
+ path
91
+ });
92
+ if (data) data.description = this.description;
93
+ return { data };
94
+ }
95
+ async search(_path, _query, _options) {
96
+ const { data: profile } = await this.read("/");
97
+ return { data: profile ? [profile] : [] };
98
+ }
99
+ };
100
+
101
+ //#endregion
102
+ export { UserProfileMemory };
103
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type {\n AFSAccessMode,\n AFSEntry,\n AFSListOptions,\n AFSListResult,\n AFSModule,\n AFSModuleLoadParams,\n AFSOperationOptions,\n AFSReadResult,\n AFSRoot,\n AFSSearchOptions,\n AFSSearchResult,\n AFSWriteEntryPayload,\n AFSWriteResult,\n} from \"@aigne/afs\";\nimport { camelize, optionalize } from \"@aigne/afs/utils/zod\";\nimport {\n type AFSStorage,\n AFSStorageSQLite,\n type AFSStorageSQLiteOptions,\n isAFSStorage,\n} from \"@aigne/afs-history\";\nimport { AIAgent, type Context } from \"@aigne/core\";\nimport { logger } from \"@aigne/core/utils/logger\";\nimport { v7 } from \"@aigne/uuid\";\nimport { applyPatch, type Operation } from \"fast-json-patch\";\nimport { z } from \"zod\";\nimport { zodToJsonSchema } from \"zod-to-json-schema\";\nimport { USER_PROFILE_MEMORY_EXTRACTOR_PROMPT } from \"./prompt.js\";\nimport { userProfileJsonPathSchema, userProfileSchema } from \"./schema.js\";\n\nexport interface UserProfileMemoryOptions {\n storage?: AFSStorage | AFSStorageSQLiteOptions;\n description?: string;\n /**\n * Access mode for this module.\n * @default \"readwrite\"\n */\n accessMode?: AFSAccessMode;\n}\n\nconst DEFAULT_DESCRIPTION = `\\\nUser Profile Memory: This contains structured information about the user that has been \\\nautomatically extracted from previous conversations. It includes personal details such as name, \\\nlocation, interests, family members, projects, and other relevant information the user has shared. \\\nUse this memory to personalize responses and maintain context about the user across conversations. \\\nThe profile is continuously updated as new information is learned.\n`;\n\nconst userProfileMemoryOptionsSchema = camelize(\n z.object({\n description: optionalize(z.string().describe(\"Description of the user profile memory\")),\n accessMode: optionalize(\n z.enum([\"readonly\", \"readwrite\"]).describe(\"Access mode for this module\"),\n ),\n }),\n);\n\nexport class UserProfileMemory implements AFSModule {\n static schema() {\n return userProfileMemoryOptionsSchema;\n }\n\n static async load({ parsed }: AFSModuleLoadParams) {\n const valid = await UserProfileMemory.schema().parseAsync(parsed);\n return new UserProfileMemory(valid);\n }\n\n constructor(public options: UserProfileMemoryOptions) {\n this.storage = isAFSStorage(options?.storage)\n ? options.storage\n : new AFSStorageSQLite(this, options?.storage);\n\n this.description = options.description || DEFAULT_DESCRIPTION;\n this.accessMode = options.accessMode ?? \"readwrite\";\n }\n\n private storage: AFSStorage;\n\n readonly name: string = \"user-profile-memory\";\n\n readonly accessMode: AFSAccessMode;\n\n description?: string | undefined;\n\n extractor: AIAgent<\n { schema: any; profile?: any; entry: AFSEntry },\n z.infer<typeof userProfileJsonPathSchema>\n > = AIAgent.from({\n instructions: USER_PROFILE_MEMORY_EXTRACTOR_PROMPT,\n outputSchema: userProfileJsonPathSchema,\n });\n\n onMount(afs: AFSRoot): void {\n afs.on(\"historyCreated\", async ({ entry }, options) => {\n try {\n await this.updateProfile(entry, options);\n } catch (error) {\n logger.error(\"Failed to update user profile memory\", error);\n }\n });\n }\n\n async updateProfile(entry: AFSEntry, options?: AFSOperationOptions) {\n const { data: previous } = await this.read(\"/\");\n\n if (typeof (options?.context as Context)?.newContext !== \"function\") {\n throw new Error(\"Context is not valid for user profile extraction\");\n }\n\n const { ops } = await (options?.context as Context)\n .newContext({ reset: true })\n .invoke(this.extractor, {\n schema: zodToJsonSchema(userProfileSchema),\n profile: previous?.content,\n entry,\n });\n\n const profile = applyPatch(\n previous?.content || {},\n ops.map((op) => {\n const value = typeof op.value === \"string\" && op.value ? JSON.parse(op.value) : op.value;\n return { ...op, value } as Operation;\n }),\n ).newDocument;\n\n return await this.write(\"/\", { content: profile });\n }\n\n async list(_path: string, _options?: AFSListOptions): Promise<AFSListResult> {\n const { data: profile } = await this.read(\"/\");\n return { data: profile ? [profile] : [] };\n }\n\n async read(path: string): Promise<AFSReadResult> {\n if (path !== \"/\") return {};\n\n const data = (\n await this.storage.list({\n orderBy: [[\"createdAt\", \"desc\"]],\n limit: 1,\n })\n ).data.at(0);\n if (data) data.description = this.description;\n return { data };\n }\n\n async write(path: string, entry: AFSWriteEntryPayload): Promise<AFSWriteResult> {\n const { data: previous } = await this.read(\"/\");\n const data = await this.storage.create({\n ...previous,\n ...entry,\n id: previous?.id || v7(),\n path,\n });\n if (data) data.description = this.description;\n return { data };\n }\n\n async search(\n _path: string,\n _query: string,\n _options?: AFSSearchOptions,\n ): Promise<AFSSearchResult> {\n const { data: profile } = await this.read(\"/\");\n return { data: profile ? [profile] : [] };\n }\n}\n"],"mappings":";;;;;;;;;;;;AAyCA,MAAM,sBAAsB;;;;;;;AAQ5B,MAAM,iCAAiC,SACrC,EAAE,OAAO;CACP,aAAa,YAAY,EAAE,QAAQ,CAAC,SAAS,yCAAyC,CAAC;CACvF,YAAY,YACV,EAAE,KAAK,CAAC,YAAY,YAAY,CAAC,CAAC,SAAS,8BAA8B,CAC1E;CACF,CAAC,CACH;AAED,IAAa,oBAAb,MAAa,kBAAuC;CAClD,OAAO,SAAS;AACd,SAAO;;CAGT,aAAa,KAAK,EAAE,UAA+B;AAEjD,SAAO,IAAI,kBADG,MAAM,kBAAkB,QAAQ,CAAC,WAAW,OAAO,CAC9B;;CAGrC,YAAY,AAAO,SAAmC;EAAnC;AACjB,OAAK,UAAU,aAAa,SAAS,QAAQ,GACzC,QAAQ,UACR,IAAI,iBAAiB,MAAM,SAAS,QAAQ;AAEhD,OAAK,cAAc,QAAQ,eAAe;AAC1C,OAAK,aAAa,QAAQ,cAAc;;CAG1C,AAAQ;CAER,AAAS,OAAe;CAExB,AAAS;CAET;CAEA,YAGI,QAAQ,KAAK;EACf,cAAc;EACd,cAAc;EACf,CAAC;CAEF,QAAQ,KAAoB;AAC1B,MAAI,GAAG,kBAAkB,OAAO,EAAE,SAAS,YAAY;AACrD,OAAI;AACF,UAAM,KAAK,cAAc,OAAO,QAAQ;YACjC,OAAO;AACd,WAAO,MAAM,wCAAwC,MAAM;;IAE7D;;CAGJ,MAAM,cAAc,OAAiB,SAA+B;EAClE,MAAM,EAAE,MAAM,aAAa,MAAM,KAAK,KAAK,IAAI;AAE/C,MAAI,QAAQ,SAAS,UAAqB,eAAe,WACvD,OAAM,IAAI,MAAM,mDAAmD;EAGrE,MAAM,EAAE,QAAQ,OAAO,SAAS,SAC7B,WAAW,EAAE,OAAO,MAAM,CAAC,CAC3B,OAAO,KAAK,WAAW;GACtB,QAAQ,gBAAgB,kBAAkB;GAC1C,SAAS,UAAU;GACnB;GACD,CAAC;EAEJ,MAAM,UAAU,WACd,UAAU,WAAW,EAAE,EACvB,IAAI,KAAK,OAAO;GACd,MAAM,QAAQ,OAAO,GAAG,UAAU,YAAY,GAAG,QAAQ,KAAK,MAAM,GAAG,MAAM,GAAG,GAAG;AACnF,UAAO;IAAE,GAAG;IAAI;IAAO;IACvB,CACH,CAAC;AAEF,SAAO,MAAM,KAAK,MAAM,KAAK,EAAE,SAAS,SAAS,CAAC;;CAGpD,MAAM,KAAK,OAAe,UAAmD;EAC3E,MAAM,EAAE,MAAM,YAAY,MAAM,KAAK,KAAK,IAAI;AAC9C,SAAO,EAAE,MAAM,UAAU,CAAC,QAAQ,GAAG,EAAE,EAAE;;CAG3C,MAAM,KAAK,MAAsC;AAC/C,MAAI,SAAS,IAAK,QAAO,EAAE;EAE3B,MAAM,QACJ,MAAM,KAAK,QAAQ,KAAK;GACtB,SAAS,CAAC,CAAC,aAAa,OAAO,CAAC;GAChC,OAAO;GACR,CAAC,EACF,KAAK,GAAG,EAAE;AACZ,MAAI,KAAM,MAAK,cAAc,KAAK;AAClC,SAAO,EAAE,MAAM;;CAGjB,MAAM,MAAM,MAAc,OAAsD;EAC9E,MAAM,EAAE,MAAM,aAAa,MAAM,KAAK,KAAK,IAAI;EAC/C,MAAM,OAAO,MAAM,KAAK,QAAQ,OAAO;GACrC,GAAG;GACH,GAAG;GACH,IAAI,UAAU,MAAM,IAAI;GACxB;GACD,CAAC;AACF,MAAI,KAAM,MAAK,cAAc,KAAK;AAClC,SAAO,EAAE,MAAM;;CAGjB,MAAM,OACJ,OACA,QACA,UAC0B;EAC1B,MAAM,EAAE,MAAM,YAAY,MAAM,KAAK,KAAK,IAAI;AAC9C,SAAO,EAAE,MAAM,UAAU,CAAC,QAAQ,GAAG,EAAE,EAAE"}
@@ -1,7 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.USER_PROFILE_MEMORY_EXTRACTOR_PROMPT = void 0;
4
- exports.USER_PROFILE_MEMORY_EXTRACTOR_PROMPT = `\
1
+
2
+ //#region src/prompt.ts
3
+ const USER_PROFILE_MEMORY_EXTRACTOR_PROMPT = `\
5
4
  <role>
6
5
  You are an AI assistant responsible for maintaining a structured user profile memory.
7
6
  You must output JSON Patch operations to update the profile.
@@ -41,3 +40,6 @@ All values must be JSON serialized strings.
41
40
  Return only the JSON object with ops array, no explanations, no extra text.
42
41
  </instructions>
43
42
  `;
43
+
44
+ //#endregion
45
+ exports.USER_PROFILE_MEMORY_EXTRACTOR_PROMPT = USER_PROFILE_MEMORY_EXTRACTOR_PROMPT;
@@ -1,4 +1,5 @@
1
- export const USER_PROFILE_MEMORY_EXTRACTOR_PROMPT = `\
1
+ //#region src/prompt.ts
2
+ const USER_PROFILE_MEMORY_EXTRACTOR_PROMPT = `\
2
3
  <role>
3
4
  You are an AI assistant responsible for maintaining a structured user profile memory.
4
5
  You must output JSON Patch operations to update the profile.
@@ -38,3 +39,7 @@ All values must be JSON serialized strings.
38
39
  Return only the JSON object with ops array, no explanations, no extra text.
39
40
  </instructions>
40
41
  `;
42
+
43
+ //#endregion
44
+ export { USER_PROFILE_MEMORY_EXTRACTOR_PROMPT };
45
+ //# sourceMappingURL=prompt.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.mjs","names":[],"sources":["../src/prompt.ts"],"sourcesContent":["export const USER_PROFILE_MEMORY_EXTRACTOR_PROMPT = `\\\n<role>\nYou are an AI assistant responsible for maintaining a structured user profile memory.\nYou must output JSON Patch operations to update the profile.\n</role>\n\n<principles>\n- Be concise: keep the profile simple and clear, avoid redundancy.\n- Single placement: each piece of information belongs to exactly one most relevant field, never duplicate across multiple fields.\n- Preserve history: keep all existing data unless there is explicit correction or new reliable information.\n- Minimal change: if no new information is extracted, return empty ops array.\n- Use arrays only when multiple distinct values exist (e.g., multiple names, multiple locations).\n</principles>\n\n<tasks>\n1. Start from the given profile (may be empty).\n2. Read the latest conversation input and output.\n3. If the conversation contains new user-related facts, generate JSON Patch operations to update the profile.\n4. If the conversation does not provide any new reliable user-related information, return empty ops array.\n5. Do not invent information.\n</tasks>\n\n<current-profile>\n{{profile}}\n</current-profile>\n\n<latest-conversation>\n{{entry.content}}\n</latest-conversation>\n\n<profile-memory-schema>\n{{schema}}\n</profile-memory-schema>\n\n<instructions>\nGenerate JSON Patch operations to update the profile, or return empty ops array if no update is needed.\nAll values must be JSON serialized strings.\nReturn only the JSON object with ops array, no explanations, no extra text.\n</instructions>\n`;\n"],"mappings":";AAAA,MAAa,uCAAuC"}
@@ -0,0 +1,47 @@
1
+ let zod = require("zod");
2
+
3
+ //#region src/schema.ts
4
+ const userProfileJsonPathSchema = zod.z.object({ ops: zod.z.array(zod.z.object({
5
+ op: zod.z.enum([
6
+ "add",
7
+ "remove",
8
+ "replace"
9
+ ]),
10
+ path: zod.z.string(),
11
+ value: zod.z.string().optional().describe("JSON serialized value for add/replace operations")
12
+ })).describe("List of operations to update the user profile") });
13
+ const userProfileSchema = zod.z.object({
14
+ name: zod.z.array(zod.z.object({
15
+ name: zod.z.string(),
16
+ remark: zod.z.string().optional()
17
+ })).optional(),
18
+ gender: zod.z.string().optional(),
19
+ birthday: zod.z.string().optional(),
20
+ languages: zod.z.array(zod.z.object({
21
+ language: zod.z.string(),
22
+ remark: zod.z.string().optional()
23
+ })).optional(),
24
+ location: zod.z.array(zod.z.object({
25
+ country: zod.z.string().optional(),
26
+ city: zod.z.string().optional(),
27
+ address: zod.z.string().optional(),
28
+ remark: zod.z.string().optional()
29
+ })).optional(),
30
+ interests: zod.z.array(zod.z.object({
31
+ content: zod.z.string(),
32
+ remark: zod.z.string().optional()
33
+ })).optional(),
34
+ family: zod.z.array(zod.z.object({
35
+ member: zod.z.string(),
36
+ relation: zod.z.string().optional(),
37
+ remark: zod.z.string().optional()
38
+ })).optional(),
39
+ projects: zod.z.array(zod.z.object({
40
+ name: zod.z.string(),
41
+ remark: zod.z.string().optional()
42
+ })).optional()
43
+ });
44
+
45
+ //#endregion
46
+ exports.userProfileJsonPathSchema = userProfileJsonPathSchema;
47
+ exports.userProfileSchema = userProfileSchema;
@@ -0,0 +1,33 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/schema.d.ts
4
+ declare const userProfileJsonPathSchema: z.ZodObject<{
5
+ ops: z.ZodArray<z.ZodObject<{
6
+ op: z.ZodEnum<["add", "remove", "replace"]>;
7
+ path: z.ZodString;
8
+ value: z.ZodOptional<z.ZodString>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ path: string;
11
+ op: "add" | "remove" | "replace";
12
+ value?: string | undefined;
13
+ }, {
14
+ path: string;
15
+ op: "add" | "remove" | "replace";
16
+ value?: string | undefined;
17
+ }>, "many">;
18
+ }, "strip", z.ZodTypeAny, {
19
+ ops: {
20
+ path: string;
21
+ op: "add" | "remove" | "replace";
22
+ value?: string | undefined;
23
+ }[];
24
+ }, {
25
+ ops: {
26
+ path: string;
27
+ op: "add" | "remove" | "replace";
28
+ value?: string | undefined;
29
+ }[];
30
+ }>;
31
+ //#endregion
32
+ export { userProfileJsonPathSchema };
33
+ //# sourceMappingURL=schema.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.cts","names":[],"sources":["../src/schema.ts"],"mappings":";;;cAEa,yBAAA,EAAyB,CAAA,CAAA,SAAA;EAAA,GAAA"}
@@ -0,0 +1,33 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/schema.d.ts
4
+ declare const userProfileJsonPathSchema: z.ZodObject<{
5
+ ops: z.ZodArray<z.ZodObject<{
6
+ op: z.ZodEnum<["add", "remove", "replace"]>;
7
+ path: z.ZodString;
8
+ value: z.ZodOptional<z.ZodString>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ path: string;
11
+ op: "add" | "remove" | "replace";
12
+ value?: string | undefined;
13
+ }, {
14
+ path: string;
15
+ op: "add" | "remove" | "replace";
16
+ value?: string | undefined;
17
+ }>, "many">;
18
+ }, "strip", z.ZodTypeAny, {
19
+ ops: {
20
+ path: string;
21
+ op: "add" | "remove" | "replace";
22
+ value?: string | undefined;
23
+ }[];
24
+ }, {
25
+ ops: {
26
+ path: string;
27
+ op: "add" | "remove" | "replace";
28
+ value?: string | undefined;
29
+ }[];
30
+ }>;
31
+ //#endregion
32
+ export { userProfileJsonPathSchema };
33
+ //# sourceMappingURL=schema.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.mts","names":[],"sources":["../src/schema.ts"],"mappings":";;;cAEa,yBAAA,EAAyB,CAAA,CAAA,SAAA;EAAA,GAAA"}
@@ -0,0 +1,47 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/schema.ts
4
+ const userProfileJsonPathSchema = z.object({ ops: z.array(z.object({
5
+ op: z.enum([
6
+ "add",
7
+ "remove",
8
+ "replace"
9
+ ]),
10
+ path: z.string(),
11
+ value: z.string().optional().describe("JSON serialized value for add/replace operations")
12
+ })).describe("List of operations to update the user profile") });
13
+ const userProfileSchema = z.object({
14
+ name: z.array(z.object({
15
+ name: z.string(),
16
+ remark: z.string().optional()
17
+ })).optional(),
18
+ gender: z.string().optional(),
19
+ birthday: z.string().optional(),
20
+ languages: z.array(z.object({
21
+ language: z.string(),
22
+ remark: z.string().optional()
23
+ })).optional(),
24
+ location: z.array(z.object({
25
+ country: z.string().optional(),
26
+ city: z.string().optional(),
27
+ address: z.string().optional(),
28
+ remark: z.string().optional()
29
+ })).optional(),
30
+ interests: z.array(z.object({
31
+ content: z.string(),
32
+ remark: z.string().optional()
33
+ })).optional(),
34
+ family: z.array(z.object({
35
+ member: z.string(),
36
+ relation: z.string().optional(),
37
+ remark: z.string().optional()
38
+ })).optional(),
39
+ projects: z.array(z.object({
40
+ name: z.string(),
41
+ remark: z.string().optional()
42
+ })).optional()
43
+ });
44
+
45
+ //#endregion
46
+ export { userProfileJsonPathSchema, userProfileSchema };
47
+ //# sourceMappingURL=schema.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.mjs","names":[],"sources":["../src/schema.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const userProfileJsonPathSchema = z.object({\n ops: z\n .array(\n z.object({\n op: z.enum([\"add\", \"remove\", \"replace\"]),\n path: z.string(),\n value: z.string().optional().describe(\"JSON serialized value for add/replace operations\"),\n }),\n )\n .describe(\"List of operations to update the user profile\"),\n});\n\nexport const userProfileSchema = z.object({\n name: z\n .array(\n z.object({\n name: z.string(),\n remark: z.string().optional(),\n }),\n )\n .optional(),\n gender: z.string().optional(),\n birthday: z.string().optional(),\n languages: z\n .array(\n z.object({\n language: z.string(),\n remark: z.string().optional(),\n }),\n )\n .optional(),\n location: z\n .array(\n z.object({\n country: z.string().optional(),\n city: z.string().optional(),\n address: z.string().optional(),\n remark: z.string().optional(),\n }),\n )\n .optional(),\n interests: z\n .array(\n z.object({\n content: z.string(),\n remark: z.string().optional(),\n }),\n )\n .optional(),\n family: z\n .array(\n z.object({\n member: z.string(),\n relation: z.string().optional(),\n remark: z.string().optional(),\n }),\n )\n .optional(),\n projects: z\n .array(\n z.object({\n name: z.string(),\n remark: z.string().optional(),\n }),\n )\n .optional(),\n});\n"],"mappings":";;;AAEA,MAAa,4BAA4B,EAAE,OAAO,EAChD,KAAK,EACF,MACC,EAAE,OAAO;CACP,IAAI,EAAE,KAAK;EAAC;EAAO;EAAU;EAAU,CAAC;CACxC,MAAM,EAAE,QAAQ;CAChB,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,SAAS,mDAAmD;CAC1F,CAAC,CACH,CACA,SAAS,gDAAgD,EAC7D,CAAC;AAEF,MAAa,oBAAoB,EAAE,OAAO;CACxC,MAAM,EACH,MACC,EAAE,OAAO;EACP,MAAM,EAAE,QAAQ;EAChB,QAAQ,EAAE,QAAQ,CAAC,UAAU;EAC9B,CAAC,CACH,CACA,UAAU;CACb,QAAQ,EAAE,QAAQ,CAAC,UAAU;CAC7B,UAAU,EAAE,QAAQ,CAAC,UAAU;CAC/B,WAAW,EACR,MACC,EAAE,OAAO;EACP,UAAU,EAAE,QAAQ;EACpB,QAAQ,EAAE,QAAQ,CAAC,UAAU;EAC9B,CAAC,CACH,CACA,UAAU;CACb,UAAU,EACP,MACC,EAAE,OAAO;EACP,SAAS,EAAE,QAAQ,CAAC,UAAU;EAC9B,MAAM,EAAE,QAAQ,CAAC,UAAU;EAC3B,SAAS,EAAE,QAAQ,CAAC,UAAU;EAC9B,QAAQ,EAAE,QAAQ,CAAC,UAAU;EAC9B,CAAC,CACH,CACA,UAAU;CACb,WAAW,EACR,MACC,EAAE,OAAO;EACP,SAAS,EAAE,QAAQ;EACnB,QAAQ,EAAE,QAAQ,CAAC,UAAU;EAC9B,CAAC,CACH,CACA,UAAU;CACb,QAAQ,EACL,MACC,EAAE,OAAO;EACP,QAAQ,EAAE,QAAQ;EAClB,UAAU,EAAE,QAAQ,CAAC,UAAU;EAC/B,QAAQ,EAAE,QAAQ,CAAC,UAAU;EAC9B,CAAC,CACH,CACA,UAAU;CACb,UAAU,EACP,MACC,EAAE,OAAO;EACP,MAAM,EAAE,QAAQ;EAChB,QAAQ,EAAE,QAAQ,CAAC,UAAU;EAC9B,CAAC,CACH,CACA,UAAU;CACd,CAAC"}