@mastra/memory 0.0.0-afterToolExecute-20250414225911

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/LICENSE.md ADDED
@@ -0,0 +1,46 @@
1
+ # Elastic License 2.0 (ELv2)
2
+
3
+ Copyright (c) 2025 Mastra AI, Inc.
4
+
5
+ **Acceptance**
6
+ By using the software, you agree to all of the terms and conditions below.
7
+
8
+ **Copyright License**
9
+ The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
10
+
11
+ **Limitations**
12
+ You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
13
+
14
+ You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
15
+
16
+ You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
17
+
18
+ **Patents**
19
+ The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
20
+
21
+ **Notices**
22
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
23
+
24
+ If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
25
+
26
+ **No Other Rights**
27
+ These terms do not imply any licenses other than those expressly granted in these terms.
28
+
29
+ **Termination**
30
+ If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
31
+
32
+ **No Liability**
33
+ As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
34
+
35
+ **Definitions**
36
+ The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
37
+
38
+ _you_ refers to the individual or entity agreeing to these terms.
39
+
40
+ _your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
41
+
42
+ _your licenses_ are all the licenses granted to you for the software under these terms.
43
+
44
+ _use_ means anything you do with the software requiring one of your licenses.
45
+
46
+ _trademark_ means trademarks, service marks, and similar rights.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # Mastra Memory
2
+
3
+ Memory management for Mastra agents. Visit [the docs](https://mastra.ai/docs/agents/agent-memory) for more information.
4
+
5
+ ## License
6
+
7
+ MIT
@@ -0,0 +1,132 @@
1
+ import type { AiMessageType } from '@mastra/core';
2
+ import type { CoreMessage } from '@mastra/core';
3
+ import type { CoreTool } from '@mastra/core';
4
+ import { MastraMemory } from '@mastra/core/memory';
5
+ import type { MemoryConfig } from '@mastra/core/memory';
6
+ import { MemoryProcessor } from '@mastra/core/memory';
7
+ import { MemoryProcessor as MemoryProcessor_2 } from '@mastra/core';
8
+ import type { MemoryProcessorOpts } from '@mastra/core';
9
+ import type { MessageType } from '@mastra/core/memory';
10
+ import type { SharedMemoryConfig } from '@mastra/core/memory';
11
+ import type { StorageGetMessagesArg } from '@mastra/core/storage';
12
+ import type { StorageThreadType } from '@mastra/core/memory';
13
+ import type { TiktokenBPE } from 'js-tiktoken/lite';
14
+
15
+ /**
16
+ * Concrete implementation of MastraMemory that adds support for thread configuration
17
+ * and message injection.
18
+ */
19
+ export declare class Memory extends MastraMemory {
20
+ constructor(config?: SharedMemoryConfig);
21
+ private validateThreadIsOwnedByResource;
22
+ query({ threadId, resourceId, selectBy, threadConfig, }: StorageGetMessagesArg & {
23
+ threadConfig?: MemoryConfig;
24
+ }): Promise<{
25
+ messages: CoreMessage[];
26
+ uiMessages: AiMessageType[];
27
+ }>;
28
+ rememberMessages({ threadId, resourceId, vectorMessageSearch, config, }: {
29
+ threadId: string;
30
+ resourceId?: string;
31
+ vectorMessageSearch?: string;
32
+ config?: MemoryConfig;
33
+ }): Promise<{
34
+ threadId: string;
35
+ messages: CoreMessage[];
36
+ uiMessages: AiMessageType[];
37
+ }>;
38
+ getThreadById({ threadId }: {
39
+ threadId: string;
40
+ }): Promise<StorageThreadType | null>;
41
+ getThreadsByResourceId({ resourceId }: {
42
+ resourceId: string;
43
+ }): Promise<StorageThreadType[]>;
44
+ saveThread({ thread, memoryConfig, }: {
45
+ thread: StorageThreadType;
46
+ memoryConfig?: MemoryConfig;
47
+ }): Promise<StorageThreadType>;
48
+ updateThread({ id, title, metadata, }: {
49
+ id: string;
50
+ title: string;
51
+ metadata: Record<string, unknown>;
52
+ }): Promise<StorageThreadType>;
53
+ deleteThread(threadId: string): Promise<void>;
54
+ private chunkText;
55
+ private hasher;
56
+ private embeddingCache;
57
+ private firstEmbed;
58
+ private embedMessageContent;
59
+ saveMessages({ messages, memoryConfig, }: {
60
+ messages: MessageType[];
61
+ memoryConfig?: MemoryConfig;
62
+ }): Promise<MessageType[]>;
63
+ protected mutateMessagesToHideWorkingMemory(messages: MessageType[]): void;
64
+ protected parseWorkingMemory(text: string): string | null;
65
+ getWorkingMemory({ threadId }: {
66
+ threadId: string;
67
+ }): Promise<string | null>;
68
+ private saveWorkingMemory;
69
+ getSystemMessage({ threadId, memoryConfig, }: {
70
+ threadId: string;
71
+ memoryConfig?: MemoryConfig;
72
+ }): Promise<string | null>;
73
+ defaultWorkingMemoryTemplate: string;
74
+ private getWorkingMemoryWithInstruction;
75
+ private getWorkingMemoryToolInstruction;
76
+ getTools(config?: MemoryConfig): Record<string, CoreTool>;
77
+ }
78
+
79
+ /**
80
+ * Limits the total number of tokens in the messages.
81
+ * Uses js-tiktoken with o200k_base encoding by default for accurate token counting with modern models.
82
+ */
83
+ declare class TokenLimiter extends MemoryProcessor {
84
+ private encoder;
85
+ private maxTokens;
86
+ TOKENS_PER_MESSAGE: number;
87
+ TOKENS_PER_TOOL: number;
88
+ TOKENS_PER_CONVERSATION: number;
89
+ /**
90
+ * Create a token limiter for messages.
91
+ * @param options Either a number (token limit) or a configuration object
92
+ */
93
+ constructor(options: number | TokenLimiterOptions);
94
+ process(messages: CoreMessage[], { systemMessage, memorySystemMessage, newMessages }?: MemoryProcessorOpts): CoreMessage[];
95
+ countTokens(message: string | CoreMessage): number;
96
+ }
97
+ export { TokenLimiter }
98
+ export { TokenLimiter as TokenLimiter_alias_1 }
99
+
100
+ /**
101
+ * Configuration options for TokenLimiter
102
+ */
103
+ declare interface TokenLimiterOptions {
104
+ /** Maximum number of tokens to allow */
105
+ limit: number;
106
+ /** Optional encoding to use (defaults to o200k_base which is used by gpt-4o) */
107
+ encoding?: TiktokenBPE;
108
+ }
109
+
110
+ /**
111
+ * Filters out tool calls and results from messages.
112
+ * By default (with no arguments), excludes all tool calls and their results.
113
+ * Can be configured to exclude only specific tools by name.
114
+ */
115
+ declare class ToolCallFilter extends MemoryProcessor_2 {
116
+ private exclude;
117
+ /**
118
+ * Create a filter for tool calls and results.
119
+ * @param options Configuration options
120
+ * @param options.exclude List of specific tool names to exclude. If not provided, all tool calls are excluded.
121
+ */
122
+ constructor(options?: {
123
+ exclude?: string[];
124
+ });
125
+ process(messages: CoreMessage[]): CoreMessage[];
126
+ }
127
+ export { ToolCallFilter }
128
+ export { ToolCallFilter as ToolCallFilter_alias_1 }
129
+
130
+ export declare const updateWorkingMemoryTool: CoreTool;
131
+
132
+ export { }
@@ -0,0 +1,132 @@
1
+ import type { AiMessageType } from '@mastra/core';
2
+ import type { CoreMessage } from '@mastra/core';
3
+ import type { CoreTool } from '@mastra/core';
4
+ import { MastraMemory } from '@mastra/core/memory';
5
+ import type { MemoryConfig } from '@mastra/core/memory';
6
+ import { MemoryProcessor } from '@mastra/core/memory';
7
+ import { MemoryProcessor as MemoryProcessor_2 } from '@mastra/core';
8
+ import type { MemoryProcessorOpts } from '@mastra/core';
9
+ import type { MessageType } from '@mastra/core/memory';
10
+ import type { SharedMemoryConfig } from '@mastra/core/memory';
11
+ import type { StorageGetMessagesArg } from '@mastra/core/storage';
12
+ import type { StorageThreadType } from '@mastra/core/memory';
13
+ import type { TiktokenBPE } from 'js-tiktoken/lite';
14
+
15
+ /**
16
+ * Concrete implementation of MastraMemory that adds support for thread configuration
17
+ * and message injection.
18
+ */
19
+ export declare class Memory extends MastraMemory {
20
+ constructor(config?: SharedMemoryConfig);
21
+ private validateThreadIsOwnedByResource;
22
+ query({ threadId, resourceId, selectBy, threadConfig, }: StorageGetMessagesArg & {
23
+ threadConfig?: MemoryConfig;
24
+ }): Promise<{
25
+ messages: CoreMessage[];
26
+ uiMessages: AiMessageType[];
27
+ }>;
28
+ rememberMessages({ threadId, resourceId, vectorMessageSearch, config, }: {
29
+ threadId: string;
30
+ resourceId?: string;
31
+ vectorMessageSearch?: string;
32
+ config?: MemoryConfig;
33
+ }): Promise<{
34
+ threadId: string;
35
+ messages: CoreMessage[];
36
+ uiMessages: AiMessageType[];
37
+ }>;
38
+ getThreadById({ threadId }: {
39
+ threadId: string;
40
+ }): Promise<StorageThreadType | null>;
41
+ getThreadsByResourceId({ resourceId }: {
42
+ resourceId: string;
43
+ }): Promise<StorageThreadType[]>;
44
+ saveThread({ thread, memoryConfig, }: {
45
+ thread: StorageThreadType;
46
+ memoryConfig?: MemoryConfig;
47
+ }): Promise<StorageThreadType>;
48
+ updateThread({ id, title, metadata, }: {
49
+ id: string;
50
+ title: string;
51
+ metadata: Record<string, unknown>;
52
+ }): Promise<StorageThreadType>;
53
+ deleteThread(threadId: string): Promise<void>;
54
+ private chunkText;
55
+ private hasher;
56
+ private embeddingCache;
57
+ private firstEmbed;
58
+ private embedMessageContent;
59
+ saveMessages({ messages, memoryConfig, }: {
60
+ messages: MessageType[];
61
+ memoryConfig?: MemoryConfig;
62
+ }): Promise<MessageType[]>;
63
+ protected mutateMessagesToHideWorkingMemory(messages: MessageType[]): void;
64
+ protected parseWorkingMemory(text: string): string | null;
65
+ getWorkingMemory({ threadId }: {
66
+ threadId: string;
67
+ }): Promise<string | null>;
68
+ private saveWorkingMemory;
69
+ getSystemMessage({ threadId, memoryConfig, }: {
70
+ threadId: string;
71
+ memoryConfig?: MemoryConfig;
72
+ }): Promise<string | null>;
73
+ defaultWorkingMemoryTemplate: string;
74
+ private getWorkingMemoryWithInstruction;
75
+ private getWorkingMemoryToolInstruction;
76
+ getTools(config?: MemoryConfig): Record<string, CoreTool>;
77
+ }
78
+
79
+ /**
80
+ * Limits the total number of tokens in the messages.
81
+ * Uses js-tiktoken with o200k_base encoding by default for accurate token counting with modern models.
82
+ */
83
+ declare class TokenLimiter extends MemoryProcessor {
84
+ private encoder;
85
+ private maxTokens;
86
+ TOKENS_PER_MESSAGE: number;
87
+ TOKENS_PER_TOOL: number;
88
+ TOKENS_PER_CONVERSATION: number;
89
+ /**
90
+ * Create a token limiter for messages.
91
+ * @param options Either a number (token limit) or a configuration object
92
+ */
93
+ constructor(options: number | TokenLimiterOptions);
94
+ process(messages: CoreMessage[], { systemMessage, memorySystemMessage, newMessages }?: MemoryProcessorOpts): CoreMessage[];
95
+ countTokens(message: string | CoreMessage): number;
96
+ }
97
+ export { TokenLimiter }
98
+ export { TokenLimiter as TokenLimiter_alias_1 }
99
+
100
+ /**
101
+ * Configuration options for TokenLimiter
102
+ */
103
+ declare interface TokenLimiterOptions {
104
+ /** Maximum number of tokens to allow */
105
+ limit: number;
106
+ /** Optional encoding to use (defaults to o200k_base which is used by gpt-4o) */
107
+ encoding?: TiktokenBPE;
108
+ }
109
+
110
+ /**
111
+ * Filters out tool calls and results from messages.
112
+ * By default (with no arguments), excludes all tool calls and their results.
113
+ * Can be configured to exclude only specific tools by name.
114
+ */
115
+ declare class ToolCallFilter extends MemoryProcessor_2 {
116
+ private exclude;
117
+ /**
118
+ * Create a filter for tool calls and results.
119
+ * @param options Configuration options
120
+ * @param options.exclude List of specific tool names to exclude. If not provided, all tool calls are excluded.
121
+ */
122
+ constructor(options?: {
123
+ exclude?: string[];
124
+ });
125
+ process(messages: CoreMessage[]): CoreMessage[];
126
+ }
127
+ export { ToolCallFilter }
128
+ export { ToolCallFilter as ToolCallFilter_alias_1 }
129
+
130
+ export declare const updateWorkingMemoryTool: CoreTool;
131
+
132
+ export { }