@mastra/memory 1.1.0-alpha.0 → 1.1.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 +95 -0
- package/dist/chunk-6TXUWFIU.js +3188 -0
- package/dist/chunk-6TXUWFIU.js.map +1 -0
- package/dist/chunk-FQJWVCDF.cjs +3205 -0
- package/dist/chunk-FQJWVCDF.cjs.map +1 -0
- package/dist/docs/README.md +1 -1
- package/dist/docs/SKILL.md +12 -1
- package/dist/docs/SOURCE_MAP.json +62 -2
- package/dist/docs/memory/02-storage.md +10 -0
- package/dist/index.cjs +96 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +53 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +96 -1
- package/dist/index.js.map +1 -1
- package/dist/observational-memory-3Q42SITP.cjs +52 -0
- package/dist/observational-memory-3Q42SITP.cjs.map +1 -0
- package/dist/observational-memory-VXLHOSDZ.js +3 -0
- package/dist/observational-memory-VXLHOSDZ.js.map +1 -0
- package/dist/processors/index.cjs +52 -0
- package/dist/processors/index.cjs.map +1 -0
- package/dist/processors/index.d.ts +2 -0
- package/dist/processors/index.d.ts.map +1 -0
- package/dist/processors/index.js +3 -0
- package/dist/processors/index.js.map +1 -0
- package/dist/processors/observational-memory/index.d.ts +18 -0
- package/dist/processors/observational-memory/index.d.ts.map +1 -0
- package/dist/processors/observational-memory/observational-memory.d.ts +579 -0
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -0
- package/dist/processors/observational-memory/observer-agent.d.ts +117 -0
- package/dist/processors/observational-memory/observer-agent.d.ts.map +1 -0
- package/dist/processors/observational-memory/reflector-agent.d.ts +46 -0
- package/dist/processors/observational-memory/reflector-agent.d.ts.map +1 -0
- package/dist/processors/observational-memory/token-counter.d.ts +30 -0
- package/dist/processors/observational-memory/token-counter.d.ts.map +1 -0
- package/dist/processors/observational-memory/types.d.ts +288 -0
- package/dist/processors/observational-memory/types.d.ts.map +1 -0
- package/package.json +18 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { embedMany } from './_types/@internal_ai-sdk-v4/dist/index.js';
|
|
2
2
|
import type { MastraDBMessage } from '@mastra/core/agent';
|
|
3
|
-
import type { MemoryConfig, SharedMemoryConfig, StorageThreadType, WorkingMemoryTemplate, MessageDeleteInput } from '@mastra/core/memory';
|
|
4
3
|
import { MastraMemory } from '@mastra/core/memory';
|
|
4
|
+
import type { MemoryConfig, SharedMemoryConfig, StorageThreadType, WorkingMemoryTemplate, MessageDeleteInput } from '@mastra/core/memory';
|
|
5
|
+
import type { InputProcessor, InputProcessorOrWorkflow, OutputProcessor, OutputProcessorOrWorkflow } from '@mastra/core/processors';
|
|
6
|
+
import type { RequestContext } from '@mastra/core/request-context';
|
|
5
7
|
import type { StorageListThreadsInput, StorageListThreadsOutput, StorageListMessagesInput, MemoryStorage, StorageCloneThreadInput, StorageCloneThreadOutput, ThreadCloneMetadata } from '@mastra/core/storage';
|
|
6
8
|
import type { ToolAction } from '@mastra/core/tools';
|
|
7
9
|
import { deepMergeWorkingMemory } from './tools/working-memory.js';
|
|
@@ -17,6 +19,35 @@ export declare class Memory extends MastraMemory {
|
|
|
17
19
|
* Gets the memory storage domain, throwing if not available.
|
|
18
20
|
*/
|
|
19
21
|
protected getMemoryStore(): Promise<MemoryStorage>;
|
|
22
|
+
listMessagesByResourceId(args: {
|
|
23
|
+
resourceId: string;
|
|
24
|
+
perPage?: number | false;
|
|
25
|
+
page?: number;
|
|
26
|
+
orderBy?: {
|
|
27
|
+
field?: 'createdAt';
|
|
28
|
+
direction?: 'ASC' | 'DESC';
|
|
29
|
+
};
|
|
30
|
+
filter?: {
|
|
31
|
+
dateRange?: {
|
|
32
|
+
start?: Date;
|
|
33
|
+
end?: Date;
|
|
34
|
+
startExclusive?: boolean;
|
|
35
|
+
endExclusive?: boolean;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
include?: Array<{
|
|
39
|
+
id: string;
|
|
40
|
+
threadId?: string;
|
|
41
|
+
withPreviousMessages?: number;
|
|
42
|
+
withNextMessages?: number;
|
|
43
|
+
}>;
|
|
44
|
+
}): Promise<{
|
|
45
|
+
messages: MastraDBMessage[];
|
|
46
|
+
total: number;
|
|
47
|
+
page: number;
|
|
48
|
+
perPage: number | false;
|
|
49
|
+
hasMore: boolean;
|
|
50
|
+
}>;
|
|
20
51
|
protected validateThreadIsOwnedByResource(threadId: string, resourceId: string, config: MemoryConfig): Promise<void>;
|
|
21
52
|
recall(args: StorageListMessagesInput & {
|
|
22
53
|
threadConfig?: MemoryConfig;
|
|
@@ -282,6 +313,27 @@ export declare class Memory extends MastraMemory {
|
|
|
282
313
|
* ```
|
|
283
314
|
*/
|
|
284
315
|
getCloneHistory(threadId: string): Promise<StorageThreadType[]>;
|
|
316
|
+
/**
|
|
317
|
+
* Get input processors for this memory instance.
|
|
318
|
+
* Extends the base implementation to add ObservationalMemory processor when configured.
|
|
319
|
+
*
|
|
320
|
+
* @param configuredProcessors - Processors already configured by the user (for deduplication)
|
|
321
|
+
* @param context - Request context for runtime configuration
|
|
322
|
+
* @returns Array of input processors configured for this memory instance
|
|
323
|
+
*/
|
|
324
|
+
getInputProcessors(configuredProcessors?: InputProcessorOrWorkflow[], context?: RequestContext): Promise<InputProcessor[]>;
|
|
325
|
+
/**
|
|
326
|
+
* Extends the base implementation to add ObservationalMemory as an output processor.
|
|
327
|
+
* OM needs processOutputResult to save messages at the end of the agent turn,
|
|
328
|
+
* even when the observation threshold was never reached during the loop.
|
|
329
|
+
*/
|
|
330
|
+
getOutputProcessors(configuredProcessors?: OutputProcessorOrWorkflow[], context?: RequestContext): Promise<OutputProcessor[]>;
|
|
331
|
+
/**
|
|
332
|
+
* Creates an ObservationalMemory processor instance if configured and not already present.
|
|
333
|
+
* A new instance is created per call — processorStates (e.g., sealedIds) are shared
|
|
334
|
+
* via the ProcessorRunner's state map keyed by processor ID, not by instance identity.
|
|
335
|
+
*/
|
|
336
|
+
private createOMProcessor;
|
|
285
337
|
}
|
|
286
338
|
export { SemanticRecall, WorkingMemory, MessageHistory } from '@mastra/core/processors';
|
|
287
339
|
export type { StorageCloneThreadInput, StorageCloneThreadOutput, ThreadCloneMetadata } from '@mastra/core/storage';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAKhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAKhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,EAAE,YAAY,EAAwD,MAAM,qBAAqB,CAAC;AACzG,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAEnB,MAAM,qBAAqB,CAAC;AAe7B,OAAO,KAAK,EACV,cAAc,EACd,wBAAwB,EACxB,eAAe,EACf,yBAAyB,EAC1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EACV,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,aAAa,EACb,uBAAuB,EACvB,wBAAwB,EACxB,mBAAmB,EACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAQrD,OAAO,EAGL,sBAAsB,EACvB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,sBAAsB,EAAE,CAAC;AAClC,OAAO,EAAE,wBAAw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CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,eAAe,EAAE,CAAC;IAW7B;;;;OAIG;YACW,iBAAiB;CAuEhC;AAGD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGxF,YAAY,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import * as z4 from 'zod/v4';
|
|
|
5
5
|
import { z as z$1 } from 'zod/v4';
|
|
6
6
|
import { ZodFirstPartyTypeKind } from 'zod/v3';
|
|
7
7
|
import { MessageList } from '@mastra/core/agent';
|
|
8
|
+
import { coreFeatures } from '@mastra/core/features';
|
|
8
9
|
import { MastraMemory, removeWorkingMemoryTags, extractWorkingMemoryContent } from '@mastra/core/memory';
|
|
9
10
|
export { extractWorkingMemoryContent, extractWorkingMemoryTags, removeWorkingMemoryTags } from '@mastra/core/memory';
|
|
10
11
|
import { generateEmptyFromSchema } from '@mastra/core/utils';
|
|
@@ -14576,6 +14577,12 @@ var __experimental_updateWorkingMemoryToolVNext = (config) => {
|
|
|
14576
14577
|
}
|
|
14577
14578
|
});
|
|
14578
14579
|
};
|
|
14580
|
+
function normalizeObservationalMemoryConfig(config) {
|
|
14581
|
+
if (config === true) return {};
|
|
14582
|
+
if (config === false || config === void 0) return void 0;
|
|
14583
|
+
if (typeof config === "object" && config.enabled === false) return void 0;
|
|
14584
|
+
return config;
|
|
14585
|
+
}
|
|
14579
14586
|
var CHARS_PER_TOKEN = 4;
|
|
14580
14587
|
var DEFAULT_MESSAGE_RANGE = { before: 1, after: 1 };
|
|
14581
14588
|
var DEFAULT_TOP_K = 4;
|
|
@@ -14590,7 +14597,8 @@ var Memory = class extends MastraMemory {
|
|
|
14590
14597
|
// and someone bumps @mastra/memory without bumping @mastra/core the defaults wouldn't exist yet
|
|
14591
14598
|
enabled: false,
|
|
14592
14599
|
template: this.defaultWorkingMemoryTemplate
|
|
14593
|
-
}
|
|
14600
|
+
},
|
|
14601
|
+
observationalMemory: config.options?.observationalMemory
|
|
14594
14602
|
});
|
|
14595
14603
|
this.threadConfig = mergedConfig;
|
|
14596
14604
|
}
|
|
@@ -14604,6 +14612,10 @@ var Memory = class extends MastraMemory {
|
|
|
14604
14612
|
}
|
|
14605
14613
|
return store;
|
|
14606
14614
|
}
|
|
14615
|
+
async listMessagesByResourceId(args) {
|
|
14616
|
+
const memoryStore = await this.getMemoryStore();
|
|
14617
|
+
return memoryStore.listMessagesByResourceId(args);
|
|
14618
|
+
}
|
|
14607
14619
|
async validateThreadIsOwnedByResource(threadId, resourceId, config) {
|
|
14608
14620
|
const resourceScope = typeof config?.semanticRecall === "object" && config?.semanticRecall?.scope !== `thread` || config.semanticRecall === true;
|
|
14609
14621
|
const thread = await this.getThreadById({ threadId });
|
|
@@ -15621,6 +15633,89 @@ Notes:
|
|
|
15621
15633
|
}
|
|
15622
15634
|
return history;
|
|
15623
15635
|
}
|
|
15636
|
+
/**
|
|
15637
|
+
* Get input processors for this memory instance.
|
|
15638
|
+
* Extends the base implementation to add ObservationalMemory processor when configured.
|
|
15639
|
+
*
|
|
15640
|
+
* @param configuredProcessors - Processors already configured by the user (for deduplication)
|
|
15641
|
+
* @param context - Request context for runtime configuration
|
|
15642
|
+
* @returns Array of input processors configured for this memory instance
|
|
15643
|
+
*/
|
|
15644
|
+
async getInputProcessors(configuredProcessors = [], context) {
|
|
15645
|
+
const processors = await super.getInputProcessors(configuredProcessors, context);
|
|
15646
|
+
const om = await this.createOMProcessor(configuredProcessors, context);
|
|
15647
|
+
if (om) {
|
|
15648
|
+
processors.push(om);
|
|
15649
|
+
}
|
|
15650
|
+
return processors;
|
|
15651
|
+
}
|
|
15652
|
+
/**
|
|
15653
|
+
* Extends the base implementation to add ObservationalMemory as an output processor.
|
|
15654
|
+
* OM needs processOutputResult to save messages at the end of the agent turn,
|
|
15655
|
+
* even when the observation threshold was never reached during the loop.
|
|
15656
|
+
*/
|
|
15657
|
+
async getOutputProcessors(configuredProcessors = [], context) {
|
|
15658
|
+
const processors = await super.getOutputProcessors(configuredProcessors, context);
|
|
15659
|
+
const om = await this.createOMProcessor(configuredProcessors, context);
|
|
15660
|
+
if (om) {
|
|
15661
|
+
processors.push(om);
|
|
15662
|
+
}
|
|
15663
|
+
return processors;
|
|
15664
|
+
}
|
|
15665
|
+
/**
|
|
15666
|
+
* Creates an ObservationalMemory processor instance if configured and not already present.
|
|
15667
|
+
* A new instance is created per call — processorStates (e.g., sealedIds) are shared
|
|
15668
|
+
* via the ProcessorRunner's state map keyed by processor ID, not by instance identity.
|
|
15669
|
+
*/
|
|
15670
|
+
async createOMProcessor(configuredProcessors = [], context) {
|
|
15671
|
+
const hasObservationalMemory = configuredProcessors.some(
|
|
15672
|
+
(p) => !("workflow" in p) && p.id === "observational-memory"
|
|
15673
|
+
);
|
|
15674
|
+
const memoryContext = context?.get("MastraMemory");
|
|
15675
|
+
const runtimeMemoryConfig = memoryContext?.memoryConfig;
|
|
15676
|
+
const effectiveConfig = runtimeMemoryConfig ? this.getMergedThreadConfig(runtimeMemoryConfig) : this.threadConfig;
|
|
15677
|
+
const omConfig = normalizeObservationalMemoryConfig(effectiveConfig.observationalMemory);
|
|
15678
|
+
if (!omConfig || hasObservationalMemory) {
|
|
15679
|
+
return null;
|
|
15680
|
+
}
|
|
15681
|
+
const coreSupportsOM = coreFeatures.has("observationalMemory");
|
|
15682
|
+
if (!coreSupportsOM) {
|
|
15683
|
+
throw new Error(
|
|
15684
|
+
"Observational memory is enabled but the installed version of @mastra/core does not support it. Please upgrade @mastra/core to a version that includes observational memory support."
|
|
15685
|
+
);
|
|
15686
|
+
}
|
|
15687
|
+
const memoryStore = await this.storage.getStore("memory");
|
|
15688
|
+
if (!memoryStore) {
|
|
15689
|
+
throw new Error(
|
|
15690
|
+
"Using Mastra Memory observational memory requires a storage adapter but no attached adapter was detected."
|
|
15691
|
+
);
|
|
15692
|
+
}
|
|
15693
|
+
if (!memoryStore.supportsObservationalMemory) {
|
|
15694
|
+
throw new Error(
|
|
15695
|
+
`Observational memory is enabled but the storage adapter (${memoryStore.constructor.name}) does not support it. If you're using @mastra/libsql, @mastra/pg, or @mastra/mongodb, upgrade to the latest version. Otherwise, use one of those adapters or disable observational memory.`
|
|
15696
|
+
);
|
|
15697
|
+
}
|
|
15698
|
+
const { ObservationalMemory } = await import('./observational-memory-VXLHOSDZ.js');
|
|
15699
|
+
return new ObservationalMemory({
|
|
15700
|
+
storage: memoryStore,
|
|
15701
|
+
scope: omConfig.scope,
|
|
15702
|
+
shareTokenBudget: omConfig.shareTokenBudget,
|
|
15703
|
+
model: omConfig.model,
|
|
15704
|
+
observation: omConfig.observation ? {
|
|
15705
|
+
model: omConfig.observation.model,
|
|
15706
|
+
messageTokens: omConfig.observation.messageTokens,
|
|
15707
|
+
modelSettings: omConfig.observation.modelSettings,
|
|
15708
|
+
maxTokensPerBatch: omConfig.observation.maxTokensPerBatch,
|
|
15709
|
+
providerOptions: omConfig.observation.providerOptions
|
|
15710
|
+
} : void 0,
|
|
15711
|
+
reflection: omConfig.reflection ? {
|
|
15712
|
+
model: omConfig.reflection.model,
|
|
15713
|
+
observationTokens: omConfig.reflection.observationTokens,
|
|
15714
|
+
modelSettings: omConfig.reflection.modelSettings,
|
|
15715
|
+
providerOptions: omConfig.reflection.providerOptions
|
|
15716
|
+
} : void 0
|
|
15717
|
+
});
|
|
15718
|
+
}
|
|
15624
15719
|
};
|
|
15625
15720
|
|
|
15626
15721
|
export { Memory, deepMergeWorkingMemory };
|