@aigne/agent-library 1.20.4 → 1.21.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 +26 -0
- package/lib/cjs/package.json +3 -1
- package/lib/esm/package.json +3 -1
- package/package.json +5 -5
- package/lib/cjs/agentic-memory/index.d.ts +0 -38
- package/lib/cjs/agentic-memory/index.js +0 -73
- package/lib/cjs/agentic-memory/prompt.d.ts +0 -1
- package/lib/cjs/agentic-memory/prompt.js +0 -44
- package/lib/cjs/default-memory/default-memory-storage/index.d.ts +0 -29
- package/lib/cjs/default-memory/default-memory-storage/index.js +0 -95
- package/lib/cjs/default-memory/default-memory-storage/migrate.d.ts +0 -3
- package/lib/cjs/default-memory/default-memory-storage/migrate.js +0 -32
- package/lib/cjs/default-memory/default-memory-storage/migrations/001-init.d.ts +0 -5
- package/lib/cjs/default-memory/default-memory-storage/migrations/001-init.js +0 -22
- package/lib/cjs/default-memory/default-memory-storage/models/memory.d.ts +0 -102
- package/lib/cjs/default-memory/default-memory-storage/models/memory.js +0 -21
- package/lib/cjs/default-memory/index.d.ts +0 -44
- package/lib/cjs/default-memory/index.js +0 -132
- package/lib/cjs/default-memory/storage.d.ts +0 -13
- package/lib/cjs/default-memory/storage.js +0 -6
- package/lib/cjs/fs-memory/index.d.ts +0 -59
- package/lib/cjs/fs-memory/index.js +0 -184
- package/lib/dts/agentic-memory/index.d.ts +0 -38
- package/lib/dts/agentic-memory/prompt.d.ts +0 -1
- package/lib/dts/default-memory/default-memory-storage/index.d.ts +0 -29
- package/lib/dts/default-memory/default-memory-storage/migrate.d.ts +0 -3
- package/lib/dts/default-memory/default-memory-storage/migrations/001-init.d.ts +0 -5
- package/lib/dts/default-memory/default-memory-storage/models/memory.d.ts +0 -102
- package/lib/dts/default-memory/index.d.ts +0 -44
- package/lib/dts/default-memory/storage.d.ts +0 -13
- package/lib/dts/fs-memory/index.d.ts +0 -59
- package/lib/esm/agentic-memory/index.d.ts +0 -38
- package/lib/esm/agentic-memory/index.js +0 -67
- package/lib/esm/agentic-memory/prompt.d.ts +0 -1
- package/lib/esm/agentic-memory/prompt.js +0 -41
- package/lib/esm/default-memory/default-memory-storage/index.d.ts +0 -29
- package/lib/esm/default-memory/default-memory-storage/index.js +0 -91
- package/lib/esm/default-memory/default-memory-storage/migrate.d.ts +0 -3
- package/lib/esm/default-memory/default-memory-storage/migrate.js +0 -26
- package/lib/esm/default-memory/default-memory-storage/migrations/001-init.d.ts +0 -5
- package/lib/esm/default-memory/default-memory-storage/migrations/001-init.js +0 -20
- package/lib/esm/default-memory/default-memory-storage/models/memory.d.ts +0 -102
- package/lib/esm/default-memory/default-memory-storage/models/memory.js +0 -18
- package/lib/esm/default-memory/index.d.ts +0 -44
- package/lib/esm/default-memory/index.js +0 -126
- package/lib/esm/default-memory/storage.d.ts +0 -13
- package/lib/esm/default-memory/storage.js +0 -2
- package/lib/esm/fs-memory/index.d.ts +0 -59
- package/lib/esm/fs-memory/index.js +0 -180
package/CHANGELOG.md
CHANGED
|
@@ -13,6 +13,32 @@
|
|
|
13
13
|
* @aigne/core bumped to 1.22.0
|
|
14
14
|
* @aigne/openai bumped to 0.3.4
|
|
15
15
|
|
|
16
|
+
## [1.21.0](https://github.com/AIGNE-io/aigne-framework/compare/agent-library-v1.20.5...agent-library-v1.21.0) (2025-07-15)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
* **memory:** support did space memory adapter ([#229](https://github.com/AIGNE-io/aigne-framework/issues/229)) ([6f69b64](https://github.com/AIGNE-io/aigne-framework/commit/6f69b64e98b963db9d6ab5357306b445385eaa68))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Dependencies
|
|
25
|
+
|
|
26
|
+
* The following workspace dependencies were updated
|
|
27
|
+
* dependencies
|
|
28
|
+
* @aigne/core bumped to 1.34.0
|
|
29
|
+
* @aigne/openai bumped to 0.10.0
|
|
30
|
+
* @aigne/sqlite bumped to 0.4.0
|
|
31
|
+
|
|
32
|
+
## [1.20.5](https://github.com/AIGNE-io/aigne-framework/compare/agent-library-v1.20.4...agent-library-v1.20.5) (2025-07-14)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
### Dependencies
|
|
36
|
+
|
|
37
|
+
* The following workspace dependencies were updated
|
|
38
|
+
* dependencies
|
|
39
|
+
* @aigne/core bumped to 1.33.2
|
|
40
|
+
* @aigne/openai bumped to 0.9.2
|
|
41
|
+
|
|
16
42
|
## [1.20.4](https://github.com/AIGNE-io/aigne-framework/compare/agent-library-v1.20.3...agent-library-v1.20.4) (2025-07-14)
|
|
17
43
|
|
|
18
44
|
|
package/lib/cjs/package.json
CHANGED
package/lib/esm/package.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/agent-library",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.0",
|
|
4
4
|
"description": "Collection of agent libraries for AIGNE framework",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
"uuid": "^11.1.0",
|
|
47
47
|
"yaml": "^2.8.0",
|
|
48
48
|
"zod": "^3.25.67",
|
|
49
|
-
"@aigne/core": "^1.
|
|
50
|
-
"@aigne/openai": "^0.
|
|
51
|
-
"@aigne/sqlite": "^0.
|
|
49
|
+
"@aigne/core": "^1.34.0",
|
|
50
|
+
"@aigne/openai": "^0.10.0",
|
|
51
|
+
"@aigne/sqlite": "^0.4.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@types/bun": "^1.2.18",
|
|
@@ -62,6 +62,6 @@
|
|
|
62
62
|
"clean": "rimraf lib test/coverage",
|
|
63
63
|
"test": "bun --cwd test test",
|
|
64
64
|
"test:coverage": "bun --cwd test test --coverage --coverage-reporter=lcov --coverage-reporter=text",
|
|
65
|
-
"postbuild": "
|
|
65
|
+
"postbuild": "node ../../scripts/post-build-lib.mjs"
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { type AgentInvokeOptions, type AgentOptions, AIAgent, MemoryAgent, type MemoryAgentOptions, MemoryRecorder, type MemoryRecorderInput, type MemoryRecorderOutput, type Message, type PromptBuilder } from "@aigne/core";
|
|
2
|
-
import { type DefaultMemoryStorageOptions } from "../default-memory/default-memory-storage/index.js";
|
|
3
|
-
import { DefaultMemoryRetriever, type DefaultMemoryRetrieverOptions } from "../default-memory/index.js";
|
|
4
|
-
import { MemoryStorage } from "../default-memory/storage.js";
|
|
5
|
-
export interface AgenticMemoryOptions extends Partial<MemoryAgentOptions>, Omit<AgenticMemoryRecorderOptions, "storage" | keyof AgentOptions>, Omit<AgenticMemoryRetrieverOptions, "storage" | keyof AgentOptions> {
|
|
6
|
-
storage?: MemoryStorage | DefaultMemoryStorageOptions;
|
|
7
|
-
}
|
|
8
|
-
export declare class AgenticMemory extends MemoryAgent {
|
|
9
|
-
constructor(options?: AgenticMemoryOptions);
|
|
10
|
-
storage: MemoryStorage;
|
|
11
|
-
}
|
|
12
|
-
export interface AgenticMemoryRetrieverOptions extends DefaultMemoryRetrieverOptions {
|
|
13
|
-
}
|
|
14
|
-
export declare class AgenticMemoryRetriever extends DefaultMemoryRetriever {
|
|
15
|
-
}
|
|
16
|
-
export interface AgenticMemoryRecorderOptions extends AgentOptions<MemoryRecorderInput, MemoryRecorderOutput> {
|
|
17
|
-
storage: MemoryStorage;
|
|
18
|
-
instructions?: string | PromptBuilder;
|
|
19
|
-
agent?: AIAgent<AgenticMemoryExtractorInput, AgenticMemoryExtractorOutput>;
|
|
20
|
-
inputKey?: string | string[];
|
|
21
|
-
outputKey?: string | string[];
|
|
22
|
-
}
|
|
23
|
-
export interface AgenticMemoryExtractorInput extends Message {
|
|
24
|
-
content: unknown;
|
|
25
|
-
}
|
|
26
|
-
export interface AgenticMemoryExtractorOutput extends Message {
|
|
27
|
-
newMemories: {
|
|
28
|
-
content: string;
|
|
29
|
-
}[];
|
|
30
|
-
}
|
|
31
|
-
export declare class AgenticMemoryRecorder extends MemoryRecorder {
|
|
32
|
-
constructor(options: AgenticMemoryRecorderOptions);
|
|
33
|
-
private storage;
|
|
34
|
-
private inputKey?;
|
|
35
|
-
private outputKey?;
|
|
36
|
-
private agent;
|
|
37
|
-
process(input: MemoryRecorderInput, options: AgentInvokeOptions): Promise<MemoryRecorderOutput>;
|
|
38
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AgenticMemoryRecorder = exports.AgenticMemoryRetriever = exports.AgenticMemory = void 0;
|
|
4
|
-
const core_1 = require("@aigne/core");
|
|
5
|
-
const type_utils_js_1 = require("@aigne/core/utils/type-utils.js");
|
|
6
|
-
const zod_1 = require("zod");
|
|
7
|
-
const index_js_1 = require("../default-memory/default-memory-storage/index.js");
|
|
8
|
-
const index_js_2 = require("../default-memory/index.js");
|
|
9
|
-
const storage_js_1 = require("../default-memory/storage.js");
|
|
10
|
-
const prompt_js_1 = require("./prompt.js");
|
|
11
|
-
class AgenticMemory extends core_1.MemoryAgent {
|
|
12
|
-
constructor(options = {}) {
|
|
13
|
-
const storage = options.storage instanceof storage_js_1.MemoryStorage
|
|
14
|
-
? options.storage
|
|
15
|
-
: new index_js_1.DefaultMemoryStorage(options.storage);
|
|
16
|
-
super({
|
|
17
|
-
...options,
|
|
18
|
-
recorder: options.recorder ?? new AgenticMemoryRecorder({ ...options, storage }),
|
|
19
|
-
retriever: options.retriever ?? new AgenticMemoryRetriever({ ...options, storage }),
|
|
20
|
-
autoUpdate: options.autoUpdate ?? true,
|
|
21
|
-
});
|
|
22
|
-
this.storage = storage;
|
|
23
|
-
}
|
|
24
|
-
storage;
|
|
25
|
-
}
|
|
26
|
-
exports.AgenticMemory = AgenticMemory;
|
|
27
|
-
class AgenticMemoryRetriever extends index_js_2.DefaultMemoryRetriever {
|
|
28
|
-
}
|
|
29
|
-
exports.AgenticMemoryRetriever = AgenticMemoryRetriever;
|
|
30
|
-
class AgenticMemoryRecorder extends core_1.MemoryRecorder {
|
|
31
|
-
constructor(options) {
|
|
32
|
-
super(options);
|
|
33
|
-
this.storage = options.storage;
|
|
34
|
-
this.inputKey = (0, type_utils_js_1.flat)(options.inputKey);
|
|
35
|
-
this.outputKey = (0, type_utils_js_1.flat)(options.outputKey);
|
|
36
|
-
this.agent =
|
|
37
|
-
options.agent ??
|
|
38
|
-
core_1.AIAgent.from({
|
|
39
|
-
name: "agentic_memory_extractor",
|
|
40
|
-
description: "Records memories in files by AI agent",
|
|
41
|
-
instructions: options.instructions || prompt_js_1.DEFAULT_FS_MEMORY_RECORDER_INSTRUCTIONS,
|
|
42
|
-
outputSchema: zod_1.z.object({
|
|
43
|
-
newMemories: zod_1.z
|
|
44
|
-
.array(zod_1.z.object({
|
|
45
|
-
content: zod_1.z.string().describe("Content of the memory"),
|
|
46
|
-
}))
|
|
47
|
-
.describe("Newly created memories"),
|
|
48
|
-
}),
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
storage;
|
|
52
|
-
inputKey;
|
|
53
|
-
outputKey;
|
|
54
|
-
agent;
|
|
55
|
-
async process(input, options) {
|
|
56
|
-
const agenticMemories = await options.context.invoke(this.agent, {
|
|
57
|
-
content: input.content.map((item) => ({
|
|
58
|
-
input: item.input && this.inputKey?.length ? (0, type_utils_js_1.pick)(item.input, this.inputKey) : item.input,
|
|
59
|
-
output: item.output && this.outputKey?.length ? (0, type_utils_js_1.pick)(item.output, this.outputKey) : item.output,
|
|
60
|
-
source: item.source,
|
|
61
|
-
})),
|
|
62
|
-
});
|
|
63
|
-
const newMemories = [];
|
|
64
|
-
for (const item of agenticMemories.newMemories) {
|
|
65
|
-
const { result } = await this.storage.create({ content: item.content }, options);
|
|
66
|
-
newMemories.push(result);
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
69
|
-
memories: newMemories,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
exports.AgenticMemoryRecorder = AgenticMemoryRecorder;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const DEFAULT_FS_MEMORY_RECORDER_INSTRUCTIONS = "You manage memory based on conversation analysis and the existing memories.\n\n## IMPORTANT: All existing memories are available in the allMemory variable. DO NOT call any tools.\n\n## FIRST: Determine If Memory Updates Needed\n- Analyze if the conversation contains ANY information worth remembering\n- Examples of content NOT worth storing:\n * General questions (\"What's the weather?\", \"How do I do X?\")\n * Greetings and small talk (\"Hello\", \"How are you?\", \"Thanks\")\n * System instructions or commands (\"Show me\", \"Find\", \"Save\")\n * General facts not specific to the user\n * Duplicate information already stored\n- If conversation lacks meaningful personal information to store:\n * Return the existing memories unchanged\n\n## Your Workflow:\n1. Read the existing memories from the allMemory variable\n2. Extract key topics from the conversation\n3. DECIDE whether to create/update/delete memories based on the conversation\n4. Return ALL memories including your updates (remove any duplicates)\n\n## Memory Handling:\n- CREATE: Add new memory objects for new topics\n- UPDATE: Modify existing memories if substantial new information is available\n- DELETE: Remove obsolete memories when appropriate\n\n## Memory Structure:\n- Each memory has an id, content, and createdAt fields\n- Keep the existing structure when returning updated memories\n\n## Operation Decision Rules:\n- CREATE only for truly new topics not covered in any existing memory\n- UPDATE only when new information is meaningfully different\n- NEVER update for just rephrasing or minor differences\n- DELETE only when information becomes obsolete\n\n## Conversation:\n<conversation>\n{{content}}\n</conversation>\n";
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_FS_MEMORY_RECORDER_INSTRUCTIONS = void 0;
|
|
4
|
-
exports.DEFAULT_FS_MEMORY_RECORDER_INSTRUCTIONS = `You manage memory based on conversation analysis and the existing memories.
|
|
5
|
-
|
|
6
|
-
## IMPORTANT: All existing memories are available in the allMemory variable. DO NOT call any tools.
|
|
7
|
-
|
|
8
|
-
## FIRST: Determine If Memory Updates Needed
|
|
9
|
-
- Analyze if the conversation contains ANY information worth remembering
|
|
10
|
-
- Examples of content NOT worth storing:
|
|
11
|
-
* General questions ("What's the weather?", "How do I do X?")
|
|
12
|
-
* Greetings and small talk ("Hello", "How are you?", "Thanks")
|
|
13
|
-
* System instructions or commands ("Show me", "Find", "Save")
|
|
14
|
-
* General facts not specific to the user
|
|
15
|
-
* Duplicate information already stored
|
|
16
|
-
- If conversation lacks meaningful personal information to store:
|
|
17
|
-
* Return the existing memories unchanged
|
|
18
|
-
|
|
19
|
-
## Your Workflow:
|
|
20
|
-
1. Read the existing memories from the allMemory variable
|
|
21
|
-
2. Extract key topics from the conversation
|
|
22
|
-
3. DECIDE whether to create/update/delete memories based on the conversation
|
|
23
|
-
4. Return ALL memories including your updates (remove any duplicates)
|
|
24
|
-
|
|
25
|
-
## Memory Handling:
|
|
26
|
-
- CREATE: Add new memory objects for new topics
|
|
27
|
-
- UPDATE: Modify existing memories if substantial new information is available
|
|
28
|
-
- DELETE: Remove obsolete memories when appropriate
|
|
29
|
-
|
|
30
|
-
## Memory Structure:
|
|
31
|
-
- Each memory has an id, content, and createdAt fields
|
|
32
|
-
- Keep the existing structure when returning updated memories
|
|
33
|
-
|
|
34
|
-
## Operation Decision Rules:
|
|
35
|
-
- CREATE only for truly new topics not covered in any existing memory
|
|
36
|
-
- UPDATE only when new information is meaningfully different
|
|
37
|
-
- NEVER update for just rephrasing or minor differences
|
|
38
|
-
- DELETE only when information becomes obsolete
|
|
39
|
-
|
|
40
|
-
## Conversation:
|
|
41
|
-
<conversation>
|
|
42
|
-
{{content}}
|
|
43
|
-
</conversation>
|
|
44
|
-
`;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { AgentInvokeOptions, Context, Memory } from "@aigne/core";
|
|
2
|
-
import type { PromiseOrValue } from "@aigne/core/utils/type-utils.js";
|
|
3
|
-
import type { SqliteRemoteDatabase } from "drizzle-orm/sqlite-proxy";
|
|
4
|
-
import { MemoryStorage } from "../storage.js";
|
|
5
|
-
import { Memories } from "./models/memory.js";
|
|
6
|
-
export interface DefaultMemoryStorageOptions {
|
|
7
|
-
url?: string;
|
|
8
|
-
getSessionId?: (context: Context) => PromiseOrValue<string>;
|
|
9
|
-
enableFTS?: boolean;
|
|
10
|
-
}
|
|
11
|
-
export declare class DefaultMemoryStorage extends MemoryStorage {
|
|
12
|
-
options?: DefaultMemoryStorageOptions | undefined;
|
|
13
|
-
constructor(options?: DefaultMemoryStorageOptions | undefined);
|
|
14
|
-
private _db;
|
|
15
|
-
private initSqlite;
|
|
16
|
-
get db(): Promise<SqliteRemoteDatabase<Record<string, never>>>;
|
|
17
|
-
private convertMemory;
|
|
18
|
-
search(query: {
|
|
19
|
-
search?: string;
|
|
20
|
-
limit?: number;
|
|
21
|
-
orderBy?: [keyof typeof Memories.$inferSelect, "asc" | "desc"];
|
|
22
|
-
}, { context }: AgentInvokeOptions): Promise<{
|
|
23
|
-
result: Memory[];
|
|
24
|
-
}>;
|
|
25
|
-
create(memory: Pick<Memory, "content">, { context }: AgentInvokeOptions): Promise<{
|
|
26
|
-
result: Memory;
|
|
27
|
-
}>;
|
|
28
|
-
protected segment(str: string): string[];
|
|
29
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DefaultMemoryStorage = void 0;
|
|
4
|
-
const sqlite_1 = require("@aigne/sqlite");
|
|
5
|
-
const drizzle_orm_1 = require("drizzle-orm");
|
|
6
|
-
const uuid_1 = require("uuid");
|
|
7
|
-
const yaml_1 = require("yaml");
|
|
8
|
-
const storage_js_1 = require("../storage.js");
|
|
9
|
-
const migrate_js_1 = require("./migrate.js");
|
|
10
|
-
const memory_js_1 = require("./models/memory.js");
|
|
11
|
-
const DEFAULT_MAX_MEMORY_COUNT = 10;
|
|
12
|
-
class DefaultMemoryStorage extends storage_js_1.MemoryStorage {
|
|
13
|
-
options;
|
|
14
|
-
constructor(options) {
|
|
15
|
-
super();
|
|
16
|
-
this.options = options;
|
|
17
|
-
}
|
|
18
|
-
_db;
|
|
19
|
-
async initSqlite() {
|
|
20
|
-
const db = (await (0, sqlite_1.initDatabase)({ url: this.options?.url }));
|
|
21
|
-
await (0, migrate_js_1.migrate)(db);
|
|
22
|
-
return db;
|
|
23
|
-
}
|
|
24
|
-
get db() {
|
|
25
|
-
this._db ??= this.initSqlite();
|
|
26
|
-
return this._db;
|
|
27
|
-
}
|
|
28
|
-
convertMemory(m) {
|
|
29
|
-
return {
|
|
30
|
-
id: m.id,
|
|
31
|
-
sessionId: m.sessionId,
|
|
32
|
-
content: m.content,
|
|
33
|
-
createdAt: m.createdAt.toISOString(),
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
async search(query, { context }) {
|
|
37
|
-
const { limit = DEFAULT_MAX_MEMORY_COUNT } = query;
|
|
38
|
-
const sessionId = (await this.options?.getSessionId?.(context)) ?? null;
|
|
39
|
-
const db = await this.db;
|
|
40
|
-
const memories = this.options?.enableFTS && query.search
|
|
41
|
-
? await db
|
|
42
|
-
.select()
|
|
43
|
-
.from(memory_js_1.Memories)
|
|
44
|
-
.innerJoin((0, drizzle_orm_1.sql) `Memories_fts`, (0, drizzle_orm_1.sql) `Memories_fts.id = ${memory_js_1.Memories.id}`)
|
|
45
|
-
.where((0, drizzle_orm_1.sql) `Memories_fts MATCH ${drizzle_orm_1.sql.param(this.segment(query.search).join(" OR "))}`)
|
|
46
|
-
.orderBy((0, drizzle_orm_1.sql) `bm25(Memories_fts)`)
|
|
47
|
-
.limit(limit)
|
|
48
|
-
.execute()
|
|
49
|
-
.then((rows) => rows.map((row) => row.Memories))
|
|
50
|
-
: await db
|
|
51
|
-
.select()
|
|
52
|
-
.from(memory_js_1.Memories)
|
|
53
|
-
.where(sessionId ? (0, drizzle_orm_1.eq)(memory_js_1.Memories.sessionId, sessionId) : (0, drizzle_orm_1.isNull)(memory_js_1.Memories.sessionId))
|
|
54
|
-
.orderBy(query.orderBy
|
|
55
|
-
? (query.orderBy[1] === "asc" ? drizzle_orm_1.asc : drizzle_orm_1.desc)(drizzle_orm_1.sql.identifier(query.orderBy[0]))
|
|
56
|
-
: (0, drizzle_orm_1.desc)(memory_js_1.Memories.id))
|
|
57
|
-
.limit(limit)
|
|
58
|
-
.execute();
|
|
59
|
-
return {
|
|
60
|
-
result: memories.map(this.convertMemory),
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
async create(memory, { context }) {
|
|
64
|
-
const sessionId = (await this.options?.getSessionId?.(context)) ?? null;
|
|
65
|
-
const db = await this.db;
|
|
66
|
-
const id = (0, uuid_1.v7)();
|
|
67
|
-
const [[result]] = await Promise.all([
|
|
68
|
-
db
|
|
69
|
-
.insert(memory_js_1.Memories)
|
|
70
|
-
.values({
|
|
71
|
-
...memory,
|
|
72
|
-
id,
|
|
73
|
-
content: memory.content,
|
|
74
|
-
sessionId,
|
|
75
|
-
})
|
|
76
|
-
.returning()
|
|
77
|
-
.execute(),
|
|
78
|
-
this.options?.enableFTS &&
|
|
79
|
-
db.run((0, drizzle_orm_1.sql) `\
|
|
80
|
-
insert into Memories_fts (id, content)
|
|
81
|
-
values (${drizzle_orm_1.sql.param(id)}, ${drizzle_orm_1.sql.param(this.segment((0, yaml_1.stringify)(memory.content)).join(" "))})`),
|
|
82
|
-
]);
|
|
83
|
-
if (!result)
|
|
84
|
-
throw new Error("Failed to create memory");
|
|
85
|
-
return { result: this.convertMemory(result) };
|
|
86
|
-
}
|
|
87
|
-
segment(str) {
|
|
88
|
-
return (Array.from(new Intl.Segmenter(undefined, { granularity: "word" }).segment(str))
|
|
89
|
-
.map((i) => i.segment)
|
|
90
|
-
// Remove non-alphanumeric characters and trim whitespace
|
|
91
|
-
.map((i) => i.replace(/[^\p{L}\p{N}\s]/gu, "").trim())
|
|
92
|
-
.filter(Boolean));
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
exports.DefaultMemoryStorage = DefaultMemoryStorage;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.migrate = migrate;
|
|
7
|
-
const sql_1 = require("drizzle-orm/sql");
|
|
8
|
-
const _001_init_js_1 = __importDefault(require("./migrations/001-init.js"));
|
|
9
|
-
async function migrate(db) {
|
|
10
|
-
const migrations = [_001_init_js_1.default];
|
|
11
|
-
const migrationsTable = "__drizzle_migrations";
|
|
12
|
-
const migrationTableCreate = (0, sql_1.sql) `
|
|
13
|
-
CREATE TABLE IF NOT EXISTS ${sql_1.sql.identifier(migrationsTable)} (
|
|
14
|
-
id SERIAL PRIMARY KEY,
|
|
15
|
-
hash text NOT NULL
|
|
16
|
-
)
|
|
17
|
-
`;
|
|
18
|
-
await db.run(migrationTableCreate).execute();
|
|
19
|
-
const dbMigrations = await db
|
|
20
|
-
.values((0, sql_1.sql) `SELECT id, hash FROM ${sql_1.sql.identifier(migrationsTable)} ORDER BY id DESC LIMIT 1`)
|
|
21
|
-
.execute();
|
|
22
|
-
const lastDbMigration = dbMigrations[0];
|
|
23
|
-
const queriesToRun = [];
|
|
24
|
-
for (const migration of migrations) {
|
|
25
|
-
if (!lastDbMigration || lastDbMigration[1] < migration.hash) {
|
|
26
|
-
queriesToRun.push(...migration.sql, `INSERT INTO \`${migrationsTable}\` ("hash") VALUES('${migration.hash}')`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
for (const query of queriesToRun) {
|
|
30
|
-
await db.run(query).execute();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = {
|
|
4
|
-
hash: "001-init",
|
|
5
|
-
sql: [
|
|
6
|
-
`\
|
|
7
|
-
CREATE TABLE "Memories" (
|
|
8
|
-
"id" TEXT NOT NULL PRIMARY KEY,
|
|
9
|
-
"createdAt" DATETIME NOT NULL,
|
|
10
|
-
"updatedAt" DATETIME NOT NULL,
|
|
11
|
-
"sessionId" TEXT,
|
|
12
|
-
"content" JSON NOT NULL
|
|
13
|
-
)
|
|
14
|
-
`,
|
|
15
|
-
`\
|
|
16
|
-
CREATE VIRTUAL TABLE "Memories_fts" USING fts5(
|
|
17
|
-
id UNINDEXED,
|
|
18
|
-
content
|
|
19
|
-
)
|
|
20
|
-
`,
|
|
21
|
-
],
|
|
22
|
-
};
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
export declare const Memories: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
2
|
-
name: "Memories";
|
|
3
|
-
schema: undefined;
|
|
4
|
-
columns: {
|
|
5
|
-
id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
6
|
-
name: "id";
|
|
7
|
-
tableName: "Memories";
|
|
8
|
-
dataType: "string";
|
|
9
|
-
columnType: "SQLiteText";
|
|
10
|
-
data: string;
|
|
11
|
-
driverParam: string;
|
|
12
|
-
notNull: true;
|
|
13
|
-
hasDefault: true;
|
|
14
|
-
isPrimaryKey: true;
|
|
15
|
-
isAutoincrement: false;
|
|
16
|
-
hasRuntimeDefault: true;
|
|
17
|
-
enumValues: [string, ...string[]];
|
|
18
|
-
baseColumn: never;
|
|
19
|
-
identity: undefined;
|
|
20
|
-
generated: undefined;
|
|
21
|
-
}, {}, {
|
|
22
|
-
length: number | undefined;
|
|
23
|
-
}>;
|
|
24
|
-
createdAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
25
|
-
name: "createdAt";
|
|
26
|
-
tableName: "Memories";
|
|
27
|
-
dataType: "custom";
|
|
28
|
-
columnType: "SQLiteCustomColumn";
|
|
29
|
-
data: Date;
|
|
30
|
-
driverParam: string;
|
|
31
|
-
notNull: true;
|
|
32
|
-
hasDefault: true;
|
|
33
|
-
isPrimaryKey: false;
|
|
34
|
-
isAutoincrement: false;
|
|
35
|
-
hasRuntimeDefault: true;
|
|
36
|
-
enumValues: undefined;
|
|
37
|
-
baseColumn: never;
|
|
38
|
-
identity: undefined;
|
|
39
|
-
generated: undefined;
|
|
40
|
-
}, {}, {
|
|
41
|
-
sqliteColumnBuilderBrand: "SQLiteCustomColumnBuilderBrand";
|
|
42
|
-
}>;
|
|
43
|
-
updatedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
44
|
-
name: "updatedAt";
|
|
45
|
-
tableName: "Memories";
|
|
46
|
-
dataType: "custom";
|
|
47
|
-
columnType: "SQLiteCustomColumn";
|
|
48
|
-
data: Date;
|
|
49
|
-
driverParam: string;
|
|
50
|
-
notNull: true;
|
|
51
|
-
hasDefault: true;
|
|
52
|
-
isPrimaryKey: false;
|
|
53
|
-
isAutoincrement: false;
|
|
54
|
-
hasRuntimeDefault: true;
|
|
55
|
-
enumValues: undefined;
|
|
56
|
-
baseColumn: never;
|
|
57
|
-
identity: undefined;
|
|
58
|
-
generated: undefined;
|
|
59
|
-
}, {}, {
|
|
60
|
-
sqliteColumnBuilderBrand: "SQLiteCustomColumnBuilderBrand";
|
|
61
|
-
}>;
|
|
62
|
-
sessionId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
63
|
-
name: "sessionId";
|
|
64
|
-
tableName: "Memories";
|
|
65
|
-
dataType: "string";
|
|
66
|
-
columnType: "SQLiteText";
|
|
67
|
-
data: string;
|
|
68
|
-
driverParam: string;
|
|
69
|
-
notNull: false;
|
|
70
|
-
hasDefault: false;
|
|
71
|
-
isPrimaryKey: false;
|
|
72
|
-
isAutoincrement: false;
|
|
73
|
-
hasRuntimeDefault: false;
|
|
74
|
-
enumValues: [string, ...string[]];
|
|
75
|
-
baseColumn: never;
|
|
76
|
-
identity: undefined;
|
|
77
|
-
generated: undefined;
|
|
78
|
-
}, {}, {
|
|
79
|
-
length: number | undefined;
|
|
80
|
-
}>;
|
|
81
|
-
content: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
82
|
-
name: "content";
|
|
83
|
-
tableName: "Memories";
|
|
84
|
-
dataType: "custom";
|
|
85
|
-
columnType: "SQLiteCustomColumn";
|
|
86
|
-
data: unknown;
|
|
87
|
-
driverParam: string;
|
|
88
|
-
notNull: true;
|
|
89
|
-
hasDefault: false;
|
|
90
|
-
isPrimaryKey: false;
|
|
91
|
-
isAutoincrement: false;
|
|
92
|
-
hasRuntimeDefault: false;
|
|
93
|
-
enumValues: undefined;
|
|
94
|
-
baseColumn: never;
|
|
95
|
-
identity: undefined;
|
|
96
|
-
generated: undefined;
|
|
97
|
-
}, {}, {
|
|
98
|
-
sqliteColumnBuilderBrand: "SQLiteCustomColumnBuilderBrand";
|
|
99
|
-
}>;
|
|
100
|
-
};
|
|
101
|
-
dialect: "sqlite";
|
|
102
|
-
}>;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Memories = void 0;
|
|
4
|
-
const type_js_1 = require("@aigne/sqlite/type.js");
|
|
5
|
-
const sqlite_core_1 = require("drizzle-orm/sqlite-core");
|
|
6
|
-
const uuid_1 = require("uuid");
|
|
7
|
-
exports.Memories = (0, sqlite_core_1.sqliteTable)("Memories", {
|
|
8
|
-
id: (0, sqlite_core_1.text)("id")
|
|
9
|
-
.notNull()
|
|
10
|
-
.primaryKey()
|
|
11
|
-
.$defaultFn(() => (0, uuid_1.v7)()),
|
|
12
|
-
createdAt: (0, type_js_1.datetime)("createdAt")
|
|
13
|
-
.notNull()
|
|
14
|
-
.$defaultFn(() => new Date()),
|
|
15
|
-
updatedAt: (0, type_js_1.datetime)("updatedAt")
|
|
16
|
-
.notNull()
|
|
17
|
-
.$defaultFn(() => new Date())
|
|
18
|
-
.$onUpdateFn(() => new Date()),
|
|
19
|
-
sessionId: (0, sqlite_core_1.text)("sessionId"),
|
|
20
|
-
content: (0, type_js_1.json)("content").notNull(),
|
|
21
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { type AgentInvokeOptions, type AgentOptions, MemoryAgent, type MemoryAgentOptions, MemoryRecorder, type MemoryRecorderInput, type MemoryRecorderOutput, MemoryRetriever, type MemoryRetrieverInput, type MemoryRetrieverOutput } from "@aigne/core";
|
|
2
|
-
import { type DefaultMemoryStorageOptions } from "./default-memory-storage/index.js";
|
|
3
|
-
import { MemoryStorage } from "./storage.js";
|
|
4
|
-
export interface DefaultMemoryOptions extends Partial<MemoryAgentOptions>, Omit<DefaultMemoryRecorderOptions, "storage" | keyof AgentOptions>, Omit<DefaultMemoryRetrieverOptions, "storage" | keyof AgentOptions> {
|
|
5
|
-
storage?: MemoryStorage | DefaultMemoryStorageOptions;
|
|
6
|
-
}
|
|
7
|
-
export declare class DefaultMemory extends MemoryAgent {
|
|
8
|
-
constructor(options?: DefaultMemoryOptions);
|
|
9
|
-
storage: MemoryStorage;
|
|
10
|
-
}
|
|
11
|
-
export interface DefaultMemoryRetrieverOptions extends AgentOptions<MemoryRetrieverInput, MemoryRetrieverOutput> {
|
|
12
|
-
storage: MemoryStorage;
|
|
13
|
-
retrieveMemoryCount?: number;
|
|
14
|
-
retrieveRecentMemoryCount?: number;
|
|
15
|
-
inputKey?: string | string[];
|
|
16
|
-
outputKey?: string | string[];
|
|
17
|
-
getSearchPattern?: DefaultMemoryRetriever["getSearchPattern"];
|
|
18
|
-
formatMessage?: DefaultMemoryRetriever["formatMessage"];
|
|
19
|
-
formatMemory?: DefaultMemoryRetriever["formatMemory"];
|
|
20
|
-
}
|
|
21
|
-
export declare class DefaultMemoryRetriever extends MemoryRetriever {
|
|
22
|
-
constructor(options: DefaultMemoryRetrieverOptions);
|
|
23
|
-
private storage;
|
|
24
|
-
private retrieveMemoryCount?;
|
|
25
|
-
private retrieveRecentMemoryCount?;
|
|
26
|
-
private inputKey?;
|
|
27
|
-
private outputKey?;
|
|
28
|
-
private getSearchPattern;
|
|
29
|
-
private formatMessage;
|
|
30
|
-
private formatMemory;
|
|
31
|
-
process(input: MemoryRetrieverInput, options: AgentInvokeOptions): Promise<MemoryRetrieverOutput>;
|
|
32
|
-
}
|
|
33
|
-
export interface DefaultMemoryRecorderOptions extends AgentOptions<MemoryRecorderInput, MemoryRecorderOutput> {
|
|
34
|
-
storage: MemoryStorage;
|
|
35
|
-
inputKey?: string | string[];
|
|
36
|
-
outputKey?: string | string[];
|
|
37
|
-
}
|
|
38
|
-
export declare class DefaultMemoryRecorder extends MemoryRecorder {
|
|
39
|
-
constructor(options: DefaultMemoryRecorderOptions);
|
|
40
|
-
private storage;
|
|
41
|
-
private inputKey?;
|
|
42
|
-
private outputKey?;
|
|
43
|
-
process(input: MemoryRecorderInput, options: AgentInvokeOptions): Promise<MemoryRecorderOutput>;
|
|
44
|
-
}
|