@mastra/memory 1.0.1 → 1.1.0-alpha.1

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/dist/chunk-6TXUWFIU.js +3188 -0
  3. package/dist/chunk-6TXUWFIU.js.map +1 -0
  4. package/dist/chunk-FQJWVCDF.cjs +3205 -0
  5. package/dist/chunk-FQJWVCDF.cjs.map +1 -0
  6. package/dist/docs/README.md +1 -1
  7. package/dist/docs/SKILL.md +12 -1
  8. package/dist/docs/SOURCE_MAP.json +62 -2
  9. package/dist/docs/memory/02-storage.md +10 -0
  10. package/dist/index.cjs +108 -5
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.ts +62 -1
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +108 -5
  15. package/dist/index.js.map +1 -1
  16. package/dist/observational-memory-3Q42SITP.cjs +52 -0
  17. package/dist/observational-memory-3Q42SITP.cjs.map +1 -0
  18. package/dist/observational-memory-VXLHOSDZ.js +3 -0
  19. package/dist/observational-memory-VXLHOSDZ.js.map +1 -0
  20. package/dist/processors/index.cjs +52 -0
  21. package/dist/processors/index.cjs.map +1 -0
  22. package/dist/processors/index.d.ts +2 -0
  23. package/dist/processors/index.d.ts.map +1 -0
  24. package/dist/processors/index.js +3 -0
  25. package/dist/processors/index.js.map +1 -0
  26. package/dist/processors/observational-memory/index.d.ts +18 -0
  27. package/dist/processors/observational-memory/index.d.ts.map +1 -0
  28. package/dist/processors/observational-memory/observational-memory.d.ts +579 -0
  29. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -0
  30. package/dist/processors/observational-memory/observer-agent.d.ts +117 -0
  31. package/dist/processors/observational-memory/observer-agent.d.ts.map +1 -0
  32. package/dist/processors/observational-memory/reflector-agent.d.ts +46 -0
  33. package/dist/processors/observational-memory/reflector-agent.d.ts.map +1 -0
  34. package/dist/processors/observational-memory/token-counter.d.ts +30 -0
  35. package/dist/processors/observational-memory/token-counter.d.ts.map +1 -0
  36. package/dist/processors/observational-memory/types.d.ts +288 -0
  37. package/dist/processors/observational-memory/types.d.ts.map +1 -0
  38. package/package.json +15 -5
@@ -0,0 +1,117 @@
1
+ import type { MastraDBMessage } from '@mastra/core/agent';
2
+ /**
3
+ * Select which extraction instructions to use based on environment variable.
4
+ * Set OM_USE_LEGACY_PROMPT=1 to use the smaller Jan 7 prompt for A/B testing.
5
+ * Set OM_USE_CONDENSED_PROMPT=1 to use the new condensed V3 prompt.
6
+ */
7
+ export declare const OBSERVER_EXTRACTION_INSTRUCTIONS: string;
8
+ /**
9
+ * Base output format for Observer (without patterns section)
10
+ */
11
+ export declare const OBSERVER_OUTPUT_FORMAT_BASE = "Use priority levels:\n- \uD83D\uDD34 High: explicit user facts, preferences, goals achieved, critical context\n- \uD83D\uDFE1 Medium: project details, learned information, tool results\n- \uD83D\uDFE2 Low: minor details, uncertain observations\n\nGroup related observations (like tool sequences) by indenting:\n* \uD83D\uDFE1 (14:33) Agent debugging auth issue\n * -> ran git status, found 3 modified files\n * -> viewed auth.ts:45-60, found missing null check\n * -> applied fix, tests now pass\n\nGroup observations by date, then list each with 24-hour time.\n\n<observations>\nDate: Dec 4, 2025\n* \uD83D\uDD34 (14:30) User prefers direct answers\n* \uD83D\uDFE1 (14:31) Working on feature X\n* \uD83D\uDFE2 (14:32) User might prefer dark mode\n\nDate: Dec 5, 2025\n* \uD83D\uDFE1 (09:15) Continued work on feature X\n</observations>\n\n<current-task>\nState the current task(s) explicitly. Can be single or multiple:\n- Primary: What the agent is currently working on\n- Secondary: Other pending tasks (mark as \"waiting for user\" if appropriate)\n\nIf the agent started doing something without user approval, note that it's off-task.\n</current-task>\n\n<suggested-response>\nHint for the agent's immediate next message. Examples:\n- \"I've updated the navigation model. Let me walk you through the changes...\"\n- \"The assistant should wait for the user to respond before continuing.\"\n- Call the view tool on src/example.ts to continue debugging.\n</suggested-response>";
12
+ /**
13
+ * The guidelines for the Observer.
14
+ * This is exported so the Reflector can reference them.
15
+ */
16
+ export declare const OBSERVER_GUIDELINES: string;
17
+ /**
18
+ * Build the complete observer system prompt.
19
+ * @param multiThread - Whether this is for multi-thread batched observation (default: false)
20
+ */
21
+ export declare function buildObserverSystemPrompt(multiThread?: boolean): string;
22
+ /**
23
+ * Observer Agent System Prompt (default - for backwards compatibility)
24
+ *
25
+ * This prompt instructs the Observer to extract observations from message history.
26
+ * The observations become the agent's "subconscious memory" - the ONLY information
27
+ * the main agent will have about past interactions.
28
+ */
29
+ export declare const OBSERVER_SYSTEM_PROMPT: string;
30
+ /**
31
+ * Result from the Observer agent
32
+ */
33
+ export interface ObserverResult {
34
+ /** The extracted observations in markdown format */
35
+ observations: string;
36
+ /** The current task extracted from observations (for thread metadata) */
37
+ currentTask?: string;
38
+ /** Suggested continuation message for the Actor */
39
+ suggestedContinuation?: string;
40
+ /** Raw output from the model (for debugging) */
41
+ rawOutput?: string;
42
+ }
43
+ /**
44
+ * Format messages for the Observer's input.
45
+ * Includes timestamps for temporal context.
46
+ */
47
+ export declare function formatMessagesForObserver(messages: MastraDBMessage[], options?: {
48
+ maxPartLength?: number;
49
+ }): string;
50
+ /**
51
+ * Format messages from multiple threads for batched observation.
52
+ * Each thread's messages are wrapped in a <thread id="..."> block.
53
+ */
54
+ export declare function formatMultiThreadMessagesForObserver(messagesByThread: Map<string, MastraDBMessage[]>, threadOrder: string[]): string;
55
+ /**
56
+ * Build the prompt for multi-thread batched observation.
57
+ */
58
+ export declare function buildMultiThreadObserverPrompt(existingObservations: string | undefined, messagesByThread: Map<string, MastraDBMessage[]>, threadOrder: string[]): string;
59
+ /**
60
+ * Result from parsing multi-thread Observer output
61
+ */
62
+ export interface MultiThreadObserverResult {
63
+ /** Results per thread */
64
+ threads: Map<string, ObserverResult>;
65
+ /** Raw output from the model (for debugging) */
66
+ rawOutput: string;
67
+ }
68
+ /**
69
+ * Parse multi-thread Observer output to extract per-thread results.
70
+ */
71
+ export declare function parseMultiThreadObserverOutput(output: string): MultiThreadObserverResult;
72
+ /**
73
+ * Build the full prompt for the Observer agent.
74
+ * Includes emphasis on the most recent user message for priority handling.
75
+ */
76
+ export declare function buildObserverPrompt(existingObservations: string | undefined, messagesToObserve: MastraDBMessage[]): string;
77
+ /**
78
+ * Parse the Observer's output to extract observations, current task, and suggested response.
79
+ * Uses XML tag parsing for structured extraction.
80
+ */
81
+ export declare function parseObserverOutput(output: string): ObserverResult;
82
+ /**
83
+ * Parsed result from XML memory section
84
+ */
85
+ interface ParsedMemorySection {
86
+ observations: string;
87
+ currentTask: string;
88
+ suggestedResponse: string;
89
+ }
90
+ /**
91
+ * Parse XML tags from observer/reflector output.
92
+ * Extracts content from <observations>, <current-task>, and <suggested-response> tags.
93
+ */
94
+ export declare function parseMemorySectionXml(content: string): ParsedMemorySection;
95
+ /**
96
+ * Check if observations contain a Current Task section.
97
+ * Supports both XML format and legacy markdown format.
98
+ */
99
+ export declare function hasCurrentTaskSection(observations: string): boolean;
100
+ /**
101
+ * Extract the Current Task content from observations.
102
+ */
103
+ export declare function extractCurrentTask(observations: string): string | null;
104
+ /**
105
+ * Optimize observations for token efficiency before presenting to the Actor.
106
+ *
107
+ * This removes:
108
+ * - Non-critical emojis (🟡 and 🟢, keeping only 🔴)
109
+ * - Semantic tags [label, label]
110
+ * - Arrow indicators (->)
111
+ * - Extra whitespace
112
+ *
113
+ * The full format is preserved in storage for analysis.
114
+ */
115
+ export declare function optimizeObservationsForContext(observations: string): string;
116
+ export {};
117
+ //# sourceMappingURL=observer-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observer-agent.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/observer-agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AA0T1D;;;;GAIG;AACH,eAAO,MAAM,gCAAgC,QAIC,CAAC;AAqD/C;;GAEG;AACH,eAAO,MAAM,2BAA2B,+8CA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,GAAG,SAAS,EACxC,iBAAiB,EAAE,eAAe,EAAE,GACnC,MAAM,CAiBR;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,CAalE;AAED;;GAEG;AACH,UAAU,mBAAmB;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,mBAAmB,CAsC1E;AAqBD;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAenE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAUtE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAoB3E"}
@@ -0,0 +1,46 @@
1
+ import type { ReflectorResult as BaseReflectorResult } from './types.js';
2
+ /**
3
+ * Result from parsing Reflector output, extending the base type with
4
+ * token count used for compression validation.
5
+ */
6
+ export interface ReflectorResult extends BaseReflectorResult {
7
+ /** Token count of output (for compression validation) */
8
+ tokenCount?: number;
9
+ }
10
+ /**
11
+ * Build the Reflector's system prompt.
12
+ *
13
+ * The Reflector handles meta-observation - when observations grow too large,
14
+ * it reorganizes them into something more manageable by:
15
+ * - Re-organizing and streamlining observations
16
+ * - Drawing connections and conclusions between observations
17
+ * - Identifying if the agent got off track and how to get back on track
18
+ * - Preserving ALL important information (reflections become the ENTIRE memory)
19
+ */
20
+ export declare function buildReflectorSystemPrompt(): string;
21
+ /**
22
+ * The Reflector's system prompt (default - for backwards compatibility)
23
+ */
24
+ export declare const REFLECTOR_SYSTEM_PROMPT: string;
25
+ /**
26
+ * Compression retry prompt - used when reflection doesn't reduce size
27
+ */
28
+ export declare const COMPRESSION_RETRY_PROMPT = "\n## COMPRESSION REQUIRED\n\nYour previous reflection was the same size or larger than the original observations.\n\nPlease re-process with slightly more compression:\n- Towards the beginning, condense more observations into higher-level reflections\n- Closer to the end, retain more fine details (recent context matters more)\n- Memory is getting long - use a more condensed style throughout\n- Combine related items more aggressively but do not lose important specific details of names, places, events, and people\n- For example if there is a long nested observation list about repeated tool calls, you can combine those into a single line and observe that the tool was called multiple times for x reason, and finally y outcome happened.\n\nYour current detail level was a 10/10, lets aim for a 8/10 detail level.\n";
29
+ /**
30
+ * Build the prompt for the Reflector agent
31
+ */
32
+ export declare function buildReflectorPrompt(observations: string, manualPrompt?: string, compressionRetry?: boolean): string;
33
+ /**
34
+ * Parse the Reflector's output to extract observations, current task, and suggested response.
35
+ * Uses XML tag parsing for structured extraction.
36
+ */
37
+ export declare function parseReflectorOutput(output: string): ReflectorResult;
38
+ /**
39
+ * Validate that reflection actually compressed the observations below the target threshold
40
+ *
41
+ * @param reflectedTokens - Token count of reflected observations
42
+ * @param targetThreshold - Target token count to compress below (the reflection threshold)
43
+ * @returns true if compression was successful (reflected tokens are below target)
44
+ */
45
+ export declare function validateCompression(reflectedTokens: number, targetThreshold: number): boolean;
46
+ //# sourceMappingURL=reflector-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reflector-agent.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/reflector-agent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,IAAI,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEtE;;;GAGG;AACH,MAAM,WAAW,eAAgB,SAAQ,mBAAmB;IAC1D,yDAAyD;IACzD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,IAAI,MAAM,CA8FnD;AAED;;GAEG;AACH,eAAO,MAAM,uBAAuB,QAA+B,CAAC;AAEpE;;GAEG;AACH,eAAO,MAAM,wBAAwB,szBAapC,CAAC;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,gBAAgB,CAAC,EAAE,OAAO,GAAG,MAAM,CAwBpH;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe,CAYpE;AAsED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,eAAe,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAG7F"}
@@ -0,0 +1,30 @@
1
+ import type { MastraDBMessage } from '@mastra/core/agent';
2
+ import type { TiktokenBPE } from 'js-tiktoken/lite';
3
+ /**
4
+ * Token counting utility using tiktoken.
5
+ * For POC we use o200k_base (GPT-4o encoding) as a reasonable default.
6
+ * Production will add provider-aware counting.
7
+ */
8
+ export declare class TokenCounter {
9
+ private encoder;
10
+ private static readonly TOKENS_PER_MESSAGE;
11
+ private static readonly TOKENS_PER_CONVERSATION;
12
+ constructor(encoding?: TiktokenBPE);
13
+ /**
14
+ * Count tokens in a plain string
15
+ */
16
+ countString(text: string): number;
17
+ /**
18
+ * Count tokens in a single message
19
+ */
20
+ countMessage(message: MastraDBMessage): number;
21
+ /**
22
+ * Count tokens in an array of messages
23
+ */
24
+ countMessages(messages: MastraDBMessage[]): number;
25
+ /**
26
+ * Count tokens in observations string
27
+ */
28
+ countObservations(observations: string): number;
29
+ }
30
+ //# sourceMappingURL=token-counter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-counter.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/token-counter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpD;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAAW;IAK1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAO;IAEjD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,uBAAuB,CAAM;gBAEzC,QAAQ,CAAC,EAAE,WAAW;IAIlC;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAMjC;;OAEG;IACH,YAAY,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM;IA6D9C;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,MAAM;IAUlD;;OAEG;IACH,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;CAGhD"}
@@ -0,0 +1,288 @@
1
+ import type { AgentConfig } from '@mastra/core/agent';
2
+ import type { ObservationalMemoryModelSettings } from '@mastra/core/memory';
3
+ /**
4
+ * Threshold can be a simple number or a dynamic range.
5
+ *
6
+ * Simple form:
7
+ * ```ts
8
+ * messageTokens: 10_000
9
+ * ```
10
+ *
11
+ * Range form (dynamic threshold based on observation space):
12
+ * ```ts
13
+ * messageTokens: { min: 8_000, max: 15_000 }
14
+ * ```
15
+ */
16
+ export type ThresholdRange = {
17
+ /** Minimum threshold (used when observations are full) */
18
+ min: number;
19
+ /** Maximum threshold (used when observations have room) */
20
+ max: number;
21
+ };
22
+ /**
23
+ * Model settings for Observer/Reflector agents.
24
+ * Re-exported from @mastra/core/memory for convenience.
25
+ */
26
+ export type ModelSettings = ObservationalMemoryModelSettings;
27
+ /**
28
+ * Google-specific provider options
29
+ */
30
+ export interface GoogleProviderOptions {
31
+ thinkingConfig?: {
32
+ thinkingBudget?: number;
33
+ includeThoughts?: boolean;
34
+ };
35
+ [key: string]: any;
36
+ }
37
+ /**
38
+ * Provider-specific options for model configuration.
39
+ * Compatible with core's ProviderOptions type.
40
+ */
41
+ export interface ProviderOptions {
42
+ google?: GoogleProviderOptions;
43
+ [key: string]: Record<string, any> | undefined;
44
+ }
45
+ /**
46
+ * Configuration for the observation step (Observer agent).
47
+ */
48
+ export interface ObservationConfig {
49
+ /**
50
+ * Model for the Observer agent.
51
+ * Can be a model ID string (e.g., 'openai/gpt-4o'), a LanguageModel instance,
52
+ * a function that returns either (for dynamic model selection),
53
+ * or an array of ModelWithRetries for fallback support.
54
+ *
55
+ * Cannot be set if a top-level `model` is also provided on ObservationalMemoryConfig.
56
+ *
57
+ * @default 'google/gemini-2.5-flash'
58
+ */
59
+ model?: AgentConfig['model'];
60
+ /**
61
+ * Token count of unobserved messages that triggers observation.
62
+ * When unobserved message tokens exceed this, the Observer is called.
63
+ *
64
+ * @default 30000
65
+ */
66
+ messageTokens?: number;
67
+ /**
68
+ * Model settings for the Observer agent.
69
+ * @default { temperature: 0.3, maxOutputTokens: 100_000 }
70
+ */
71
+ modelSettings?: ModelSettings;
72
+ /**
73
+ * Provider-specific options.
74
+ * @default { google: { thinkingConfig: { thinkingBudget: 215 } } }
75
+ */
76
+ providerOptions?: ProviderOptions;
77
+ /**
78
+ * Maximum tokens per batch when observing multiple threads.
79
+ * Threads are chunked into batches of this size and processed in parallel.
80
+ * Lower values = more parallelism but more API calls.
81
+ * Higher values = fewer API calls but less parallelism.
82
+ *
83
+ * @default 10000
84
+ */
85
+ maxTokensPerBatch?: number;
86
+ }
87
+ /**
88
+ * Configuration for the reflection step (Reflector agent).
89
+ */
90
+ export interface ReflectionConfig {
91
+ /**
92
+ * Model for the Reflector agent.
93
+ * Can be a model ID string (e.g., 'openai/gpt-4o'), a LanguageModel instance,
94
+ * a function that returns either (for dynamic model selection),
95
+ * or an array of ModelWithRetries for fallback support.
96
+ *
97
+ * Cannot be set if a top-level `model` is also provided on ObservationalMemoryConfig.
98
+ *
99
+ * @default 'google/gemini-2.5-flash'
100
+ */
101
+ model?: AgentConfig['model'];
102
+ /**
103
+ * Token count of observations that triggers reflection.
104
+ * When observation tokens exceed this, the Reflector is called to condense them.
105
+ *
106
+ * @default 40000
107
+ */
108
+ observationTokens?: number;
109
+ /**
110
+ * Model settings for the Reflector agent.
111
+ * @default { temperature: 0, maxOutputTokens: 100_000 }
112
+ */
113
+ modelSettings?: ModelSettings;
114
+ /**
115
+ * Provider-specific options.
116
+ * @default { google: { thinkingConfig: { thinkingBudget: 1024 } } }
117
+ */
118
+ providerOptions?: ProviderOptions;
119
+ }
120
+ /**
121
+ * Result from Observer agent
122
+ */
123
+ export interface ObserverResult {
124
+ /** The extracted observations */
125
+ observations: string;
126
+ /** Suggested continuation for the Actor */
127
+ suggestedContinuation?: string;
128
+ }
129
+ /**
130
+ * Result from Reflector agent
131
+ */
132
+ export interface ReflectorResult {
133
+ /** The condensed observations */
134
+ observations: string;
135
+ /** Suggested continuation for the Actor */
136
+ suggestedContinuation?: string;
137
+ }
138
+ /**
139
+ * Config snapshot included in observation markers for debugging.
140
+ */
141
+ export interface ObservationMarkerConfig {
142
+ messageTokens: number;
143
+ observationTokens: number;
144
+ scope: 'thread' | 'resource';
145
+ }
146
+ /**
147
+ * Start marker inserted when observation begins.
148
+ * Everything BEFORE this marker will be observed.
149
+ *
150
+ * If this marker exists without a corresponding `end` or `failed` marker,
151
+ * observation is in progress.
152
+ */
153
+ /** Type of OM operation - observation or reflection */
154
+ export type OmOperationType = 'observation' | 'reflection';
155
+ export interface DataOmObservationStartPart {
156
+ type: 'data-om-observation-start';
157
+ data: {
158
+ /** Unique ID for this observation cycle - shared between start/end/failed markers */
159
+ cycleId: string;
160
+ /** Type of operation: 'observation' or 'reflection' */
161
+ operationType: OmOperationType;
162
+ /** When observation started */
163
+ startedAt: string;
164
+ /** Tokens being observed in this batch */
165
+ tokensToObserve: number;
166
+ /** The OM record ID this observation belongs to */
167
+ recordId: string;
168
+ /** This thread's ID */
169
+ threadId: string;
170
+ /** All thread IDs being observed in this batch (for resource-scoped) */
171
+ threadIds: string[];
172
+ /** Snapshot of config at observation time */
173
+ config: ObservationMarkerConfig;
174
+ };
175
+ }
176
+ /**
177
+ * End marker inserted when observation completes successfully.
178
+ * Parts BEFORE the corresponding `start` marker have been observed.
179
+ */
180
+ export interface DataOmObservationEndPart {
181
+ type: 'data-om-observation-end';
182
+ data: {
183
+ /** Unique ID for this observation cycle - shared between start/end/failed markers */
184
+ cycleId: string;
185
+ /** Type of operation: 'observation' or 'reflection' */
186
+ operationType: OmOperationType;
187
+ /** When observation completed */
188
+ completedAt: string;
189
+ /** Duration in milliseconds */
190
+ durationMs: number;
191
+ /** Total tokens that were observed */
192
+ tokensObserved: number;
193
+ /** Resulting observation tokens after compression */
194
+ observationTokens: number;
195
+ /** The actual observations generated in this cycle */
196
+ observations?: string;
197
+ /** Current task extracted by the Observer */
198
+ currentTask?: string;
199
+ /** Suggested response extracted by the Observer */
200
+ suggestedResponse?: string;
201
+ /** The OM record ID */
202
+ recordId: string;
203
+ /** This thread's ID */
204
+ threadId: string;
205
+ };
206
+ }
207
+ /**
208
+ * Failed marker inserted when observation fails.
209
+ * Allows for retry logic and debugging.
210
+ */
211
+ export interface DataOmObservationFailedPart {
212
+ type: 'data-om-observation-failed';
213
+ data: {
214
+ /** Unique ID for this observation cycle - shared between start/end/failed markers */
215
+ cycleId: string;
216
+ /** Type of operation: 'observation' or 'reflection' */
217
+ operationType: OmOperationType;
218
+ /** When observation failed */
219
+ failedAt: string;
220
+ /** Duration until failure in milliseconds */
221
+ durationMs: number;
222
+ /** Tokens that were attempted to observe */
223
+ tokensAttempted: number;
224
+ /** Error message */
225
+ error: string;
226
+ /** The OM record ID */
227
+ recordId: string;
228
+ /** This thread's ID */
229
+ threadId: string;
230
+ };
231
+ }
232
+ /**
233
+ * Progress marker streamed during agent execution to provide real-time
234
+ * token progress updates for UI feedback.
235
+ */
236
+ export interface DataOmProgressPart {
237
+ type: 'data-om-progress';
238
+ data: {
239
+ /** Current pending tokens (unobserved message tokens) */
240
+ pendingTokens: number;
241
+ /** Current message token threshold that triggers observation */
242
+ messageTokens: number;
243
+ /** Percentage of message token threshold reached */
244
+ messageTokensPercent: number;
245
+ /** Current observation tokens (for reflection progress) */
246
+ observationTokens: number;
247
+ /** Observation token threshold that triggers reflection */
248
+ observationTokensThreshold: number;
249
+ /** Percentage of observation token threshold reached */
250
+ observationTokensPercent: number;
251
+ /** Whether observation will trigger */
252
+ willObserve: boolean;
253
+ /** The OM record ID */
254
+ recordId: string;
255
+ /** Thread ID */
256
+ threadId: string;
257
+ /** Step number in the agent loop */
258
+ stepNumber: number;
259
+ };
260
+ }
261
+ /**
262
+ * Union of all observation marker types.
263
+ */
264
+ export type DataOmObservationPart = DataOmObservationStartPart | DataOmObservationEndPart | DataOmObservationFailedPart | DataOmProgressPart;
265
+ /**
266
+ * @deprecated Use DataOmObservationStartPart and DataOmObservationEndPart instead.
267
+ * Kept for backwards compatibility during migration.
268
+ */
269
+ export interface DataOmObservedPart {
270
+ type: 'data-om-observed';
271
+ data: {
272
+ /** When this observation occurred */
273
+ observedAt: string;
274
+ /** Total tokens observed across all threads in this batch */
275
+ tokensObserved: number;
276
+ /** Resulting observation tokens after compression */
277
+ observationTokens: number;
278
+ /** The OM record ID this observation belongs to */
279
+ recordId: string;
280
+ /** This thread's ID */
281
+ threadId: string;
282
+ /** All thread IDs that were observed in this batch (for resource-scoped) */
283
+ threadIds: string[];
284
+ /** Snapshot of config at observation time (for debugging) */
285
+ config?: ObservationMarkerConfig;
286
+ };
287
+ }
288
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;AAE5E;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,0DAA0D;IAC1D,GAAG,EAAE,MAAM,CAAC;IACZ,2DAA2D;IAC3D,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,gCAAgC,CAAC;AAE7D;;GAEG;AACH,MAAM,W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xB,2BAA2B,GAC3B,kBAAkB,CAAC;AAEvB;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,kBAAkB,CAAC;IACzB,IAAI,EAAE;QACJ,qCAAqC;QACrC,UAAU,EAAE,MAAM,CAAC;QAEnB,6DAA6D;QAC7D,cAAc,EAAE,MAAM,CAAC;QAEvB,qDAAqD;QACrD,iBAAiB,EAAE,MAAM,CAAC;QAE1B,mDAAmD;QACnD,QAAQ,EAAE,MAAM,CAAC;QAEjB,uBAAuB;QACvB,QAAQ,EAAE,MAAM,CAAC;QAEjB,4EAA4E;QAC5E,SAAS,EAAE,MAAM,EAAE,CAAC;QAEpB,6DAA6D;QAC7D,MAAM,CAAC,EAAE,uBAAuB,CAAC;KAClC,CAAC;CACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/memory",
3
- "version": "1.0.1",
3
+ "version": "1.1.0-alpha.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -20,6 +20,16 @@
20
20
  "default": "./dist/index.cjs"
21
21
  }
22
22
  },
23
+ "./processors": {
24
+ "import": {
25
+ "types": "./dist/processors/index.d.ts",
26
+ "default": "./dist/processors/index.js"
27
+ },
28
+ "require": {
29
+ "types": "./dist/processors/index.d.ts",
30
+ "default": "./dist/processors/index.cjs"
31
+ }
32
+ },
23
33
  "./package.json": "./package.json"
24
34
  },
25
35
  "keywords": [],
@@ -31,7 +41,7 @@
31
41
  "json-schema": "^0.4.0",
32
42
  "lru-cache": "^11.2.2",
33
43
  "xxhash-wasm": "^1.1.0",
34
- "@mastra/schema-compat": "1.0.0"
44
+ "@mastra/schema-compat": "1.1.0-alpha.0"
35
45
  },
36
46
  "devDependencies": {
37
47
  "@ai-sdk/openai": "^1.3.24",
@@ -46,12 +56,12 @@
46
56
  "typescript": "^5.9.3",
47
57
  "typescript-eslint": "^8.51.0",
48
58
  "vitest": "4.0.16",
49
- "@internal/ai-sdk-v4": "0.0.3",
50
- "@internal/ai-sdk-v5": "0.0.3",
51
59
  "@internal/ai-v6": "0.0.3",
60
+ "@internal/ai-sdk-v5": "0.0.3",
52
61
  "@internal/lint": "0.0.56",
53
62
  "@internal/types-builder": "0.0.31",
54
- "@mastra/core": "1.1.0"
63
+ "@mastra/core": "1.2.0-alpha.1",
64
+ "@internal/ai-sdk-v4": "0.0.3"
55
65
  },
56
66
  "peerDependencies": {
57
67
  "@mastra/core": ">=1.0.0-0 <2.0.0-0",