@mastra/memory 0.1.0-alpha.82 → 0.1.0-alpha.84
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 +16 -0
- package/dist/_tsup-dts-rollup.d.ts +63 -0
- package/dist/index.d.ts +1 -59
- package/dist/index.js +14 -13
- package/package.json +5 -7
- package/src/index.ts +10 -4
- package/tsconfig.json +1 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @mastra/memory
|
|
2
2
|
|
|
3
|
+
## 0.1.0-alpha.84
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [a9345f9]
|
|
8
|
+
- @mastra/core@0.2.0-alpha.102
|
|
9
|
+
|
|
10
|
+
## 0.1.0-alpha.83
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 4f1d1a1: Enforce types ann cleanup package.json
|
|
15
|
+
- Updated dependencies [66a03ec]
|
|
16
|
+
- Updated dependencies [4f1d1a1]
|
|
17
|
+
- @mastra/core@0.2.0-alpha.101
|
|
18
|
+
|
|
3
19
|
## 0.1.0-alpha.82
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { CoreMessage } from '@mastra/core';
|
|
2
|
+
import { MastraMemory } from '@mastra/core/memory';
|
|
3
|
+
import { MemoryConfig } from '@mastra/core/memory';
|
|
4
|
+
import { Message } from 'ai';
|
|
5
|
+
import { MessageType } from '@mastra/core/memory';
|
|
6
|
+
import { SharedMemoryConfig } from '@mastra/core/memory';
|
|
7
|
+
import { StorageGetMessagesArg } from '@mastra/core/storage';
|
|
8
|
+
import { StorageThreadType } from '@mastra/core/memory';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Concrete implementation of MastraMemory that adds support for thread configuration
|
|
12
|
+
* and message injection.
|
|
13
|
+
*/
|
|
14
|
+
export declare class Memory extends MastraMemory {
|
|
15
|
+
constructor(config: SharedMemoryConfig & {
|
|
16
|
+
embeddings?: any;
|
|
17
|
+
});
|
|
18
|
+
query({ threadId, selectBy, threadConfig, }: StorageGetMessagesArg): Promise<{
|
|
19
|
+
messages: CoreMessage[];
|
|
20
|
+
uiMessages: Message[];
|
|
21
|
+
}>;
|
|
22
|
+
rememberMessages({ threadId, vectorMessageSearch, config, }: {
|
|
23
|
+
threadId: string;
|
|
24
|
+
vectorMessageSearch?: string;
|
|
25
|
+
config?: MemoryConfig;
|
|
26
|
+
}): Promise<{
|
|
27
|
+
messages: CoreMessage[];
|
|
28
|
+
uiMessages: Message[];
|
|
29
|
+
}>;
|
|
30
|
+
getThreadById({ threadId }: {
|
|
31
|
+
threadId: string;
|
|
32
|
+
}): Promise<StorageThreadType | null>;
|
|
33
|
+
getThreadsByResourceId({ resourceId }: {
|
|
34
|
+
resourceId: string;
|
|
35
|
+
}): Promise<StorageThreadType[]>;
|
|
36
|
+
saveThread({ thread, memoryConfig, }: {
|
|
37
|
+
thread: StorageThreadType;
|
|
38
|
+
memoryConfig?: MemoryConfig;
|
|
39
|
+
}): Promise<StorageThreadType>;
|
|
40
|
+
updateThread({ id, title, metadata, }: {
|
|
41
|
+
id: string;
|
|
42
|
+
title: string;
|
|
43
|
+
metadata: Record<string, unknown>;
|
|
44
|
+
}): Promise<StorageThreadType>;
|
|
45
|
+
deleteThread(threadId: string): Promise<void>;
|
|
46
|
+
saveMessages({ messages }: {
|
|
47
|
+
messages: MessageType[];
|
|
48
|
+
}): Promise<MessageType[]>;
|
|
49
|
+
protected mutateMessagesToHideWorkingMemory(messages: MessageType[]): void;
|
|
50
|
+
protected parseWorkingMemory(text: string): string | null;
|
|
51
|
+
protected getWorkingMemory({ threadId }: {
|
|
52
|
+
threadId: string;
|
|
53
|
+
}): Promise<string | null>;
|
|
54
|
+
private saveWorkingMemory;
|
|
55
|
+
getSystemMessage({ threadId, memoryConfig, }: {
|
|
56
|
+
threadId: string;
|
|
57
|
+
memoryConfig?: MemoryConfig;
|
|
58
|
+
}): Promise<string | null>;
|
|
59
|
+
defaultWorkingMemoryTemplate: string;
|
|
60
|
+
private getWorkingMemoryWithInstruction;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { }
|
package/dist/index.d.ts
CHANGED
|
@@ -1,59 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { MastraMemory, SharedMemoryConfig, MemoryConfig, StorageThreadType, MessageType } from '@mastra/core/memory';
|
|
3
|
-
import { StorageGetMessagesArg } from '@mastra/core/storage';
|
|
4
|
-
import { Message } from 'ai';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Concrete implementation of MastraMemory that adds support for thread configuration
|
|
8
|
-
* and message injection.
|
|
9
|
-
*/
|
|
10
|
-
declare class Memory extends MastraMemory {
|
|
11
|
-
constructor(config: SharedMemoryConfig & {
|
|
12
|
-
embeddings?: any;
|
|
13
|
-
});
|
|
14
|
-
query({ threadId, selectBy, threadConfig, }: StorageGetMessagesArg): Promise<{
|
|
15
|
-
messages: CoreMessage[];
|
|
16
|
-
uiMessages: Message[];
|
|
17
|
-
}>;
|
|
18
|
-
rememberMessages({ threadId, vectorMessageSearch, config, }: {
|
|
19
|
-
threadId: string;
|
|
20
|
-
vectorMessageSearch?: string;
|
|
21
|
-
config?: MemoryConfig;
|
|
22
|
-
}): Promise<{
|
|
23
|
-
messages: CoreMessage[];
|
|
24
|
-
uiMessages: Message[];
|
|
25
|
-
}>;
|
|
26
|
-
getThreadById({ threadId }: {
|
|
27
|
-
threadId: string;
|
|
28
|
-
}): Promise<StorageThreadType | null>;
|
|
29
|
-
getThreadsByResourceId({ resourceId }: {
|
|
30
|
-
resourceId: string;
|
|
31
|
-
}): Promise<StorageThreadType[]>;
|
|
32
|
-
saveThread({ thread, memoryConfig, }: {
|
|
33
|
-
thread: StorageThreadType;
|
|
34
|
-
memoryConfig?: MemoryConfig;
|
|
35
|
-
}): Promise<StorageThreadType>;
|
|
36
|
-
updateThread({ id, title, metadata, }: {
|
|
37
|
-
id: string;
|
|
38
|
-
title: string;
|
|
39
|
-
metadata: Record<string, unknown>;
|
|
40
|
-
}): Promise<StorageThreadType>;
|
|
41
|
-
deleteThread(threadId: string): Promise<void>;
|
|
42
|
-
saveMessages({ messages }: {
|
|
43
|
-
messages: MessageType[];
|
|
44
|
-
}): Promise<MessageType[]>;
|
|
45
|
-
protected mutateMessagesToHideWorkingMemory(messages: MessageType[]): void;
|
|
46
|
-
protected parseWorkingMemory(text: string): string | null;
|
|
47
|
-
protected getWorkingMemory({ threadId }: {
|
|
48
|
-
threadId: string;
|
|
49
|
-
}): Promise<string | null>;
|
|
50
|
-
private saveWorkingMemory;
|
|
51
|
-
getSystemMessage({ threadId, memoryConfig, }: {
|
|
52
|
-
threadId: string;
|
|
53
|
-
memoryConfig?: MemoryConfig;
|
|
54
|
-
}): Promise<string | null>;
|
|
55
|
-
defaultWorkingMemoryTemplate: string;
|
|
56
|
-
private getWorkingMemoryWithInstruction;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export { Memory };
|
|
1
|
+
export { Memory } from './_tsup-dts-rollup.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { deepMerge } from '@mastra/core';
|
|
2
2
|
import { MastraMemory } from '@mastra/core/memory';
|
|
3
|
+
import '@mastra/core/storage';
|
|
3
4
|
import { embed } from 'ai';
|
|
4
5
|
|
|
5
6
|
// src/index.ts
|
|
@@ -30,19 +31,6 @@ ${embedderExample}`
|
|
|
30
31
|
);
|
|
31
32
|
}
|
|
32
33
|
super({ name: "Memory", ...config });
|
|
33
|
-
this.defaultWorkingMemoryTemplate = `
|
|
34
|
-
<user>
|
|
35
|
-
<first_name></first_name>
|
|
36
|
-
<last_name></last_name>
|
|
37
|
-
<location></location>
|
|
38
|
-
<occupation></occupation>
|
|
39
|
-
<interests></interests>
|
|
40
|
-
<goals></goals>
|
|
41
|
-
<events></events>
|
|
42
|
-
<facts></facts>
|
|
43
|
-
<projects></projects>
|
|
44
|
-
</user>
|
|
45
|
-
`;
|
|
46
34
|
const mergedConfig = this.getMergedThreadConfig({
|
|
47
35
|
workingMemory: config.options?.workingMemory || {
|
|
48
36
|
enabled: false,
|
|
@@ -253,6 +241,19 @@ ${embedderExample}`
|
|
|
253
241
|
}
|
|
254
242
|
return this.getWorkingMemoryWithInstruction(workingMemory);
|
|
255
243
|
}
|
|
244
|
+
defaultWorkingMemoryTemplate = `
|
|
245
|
+
<user>
|
|
246
|
+
<first_name></first_name>
|
|
247
|
+
<last_name></last_name>
|
|
248
|
+
<location></location>
|
|
249
|
+
<occupation></occupation>
|
|
250
|
+
<interests></interests>
|
|
251
|
+
<goals></goals>
|
|
252
|
+
<events></events>
|
|
253
|
+
<facts></facts>
|
|
254
|
+
<projects></projects>
|
|
255
|
+
</user>
|
|
256
|
+
`;
|
|
256
257
|
getWorkingMemoryWithInstruction(workingMemoryBlock) {
|
|
257
258
|
return `WORKING_MEMORY_SYSTEM_INSTRUCTION:
|
|
258
259
|
Store and update any conversation-relevant information by including "<working_memory>text</working_memory>" in your responses. Updates replace existing memory while maintaining this structure. If information might be referenced again - store it!
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/memory",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.84",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -36,20 +36,18 @@
|
|
|
36
36
|
"pg-pool": "^3.7.0",
|
|
37
37
|
"postgres": "^3.4.5",
|
|
38
38
|
"redis": "^4.7.0",
|
|
39
|
-
"@mastra/core": "^0.2.0-alpha.
|
|
39
|
+
"@mastra/core": "^0.2.0-alpha.102"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@
|
|
43
|
-
"@
|
|
44
|
-
"@tsconfig/recommended": "^1.0.7",
|
|
45
|
-
"@types/node": "^22.9.0",
|
|
42
|
+
"@microsoft/api-extractor": "^7.49.2",
|
|
43
|
+
"@types/node": "^22.13.1",
|
|
46
44
|
"@types/pg": "^8.11.10",
|
|
47
45
|
"tsup": "^8.0.1",
|
|
48
46
|
"vitest": "^3.0.4"
|
|
49
47
|
},
|
|
50
48
|
"scripts": {
|
|
51
49
|
"check": "tsc --noEmit",
|
|
52
|
-
"build": "pnpm run check && tsup src/index.ts --format esm --dts --clean --treeshake",
|
|
50
|
+
"build": "pnpm run check && tsup src/index.ts --format esm --experimental-dts --clean --treeshake",
|
|
53
51
|
"build:watch": "pnpm build --watch",
|
|
54
52
|
"test:integration": "cd integration-tests && pnpm run test",
|
|
55
53
|
"test": "pnpm test:integration"
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import { CoreMessage, deepMerge } from '@mastra/core';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { type CoreMessage, deepMerge } from '@mastra/core';
|
|
2
|
+
import {
|
|
3
|
+
MastraMemory,
|
|
4
|
+
type MessageType,
|
|
5
|
+
type MemoryConfig,
|
|
6
|
+
type SharedMemoryConfig,
|
|
7
|
+
type StorageThreadType,
|
|
8
|
+
} from '@mastra/core/memory';
|
|
9
|
+
import { type StorageGetMessagesArg } from '@mastra/core/storage';
|
|
10
|
+
import { embed, type Message as AiMessage } from 'ai';
|
|
5
11
|
|
|
6
12
|
/**
|
|
7
13
|
* Concrete implementation of MastraMemory that adds support for thread configuration
|
package/tsconfig.json
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"moduleResolution": "bundler",
|
|
5
|
-
"outDir": "./dist",
|
|
6
|
-
"rootDir": "./src",
|
|
7
|
-
"esModuleInterop": true
|
|
8
|
-
},
|
|
2
|
+
"extends": "../../tsconfig.node.json",
|
|
9
3
|
"include": ["src/**/*"],
|
|
10
4
|
"exclude": ["node_modules", "**/*.test.ts"]
|
|
11
5
|
}
|