@mastra/memory 1.37.1-alpha.0 → 1.37.1-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.
@@ -3,7 +3,7 @@ name: mastra-memory
3
3
  description: Documentation for @mastra/memory. Use when working with @mastra/memory APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/memory"
6
- version: "1.37.1-alpha.0"
6
+ version: "1.37.1-alpha.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.37.1-alpha.0",
2
+ "version": "1.37.1-alpha.1",
3
3
  "package": "@mastra/memory",
4
4
  "exports": {},
5
5
  "modules": {
@@ -158,7 +158,7 @@ const memory = new Memory({
158
158
  })
159
159
  ```
160
160
 
161
- OM requires a storage adapter that supports it: `@mastra/libsql`, `@mastra/pg`, `@mastra/mongodb`, or `@mastra/oracledb`.
161
+ OM requires a storage adapter that supports it: `@mastra/libsql`, `@mastra/pg`, `@mastra/mongodb`, `@mastra/mysql`, `@mastra/convex`, or `@mastra/oracledb`.
162
162
 
163
163
  > **Note:** If you switch the Observer to a less capable model and see facts attributed to a generic `User` instead of individual participants, use [`observation.instruction`](https://mastra.ai/reference/memory/observational-memory) to explain how to interpret the `<turn>` tag.
164
164
 
@@ -69,7 +69,7 @@ const result = await memory.listThreads({
69
69
 
70
70
  **page** (`number`): Page number (0-indexed) to retrieve
71
71
 
72
- **perPage** (`number | false`): Maximum number of threads to return per page, or false to fetch all
72
+ **perPage** (`number | false`): Maximum number of threads to return per page, or false to fetch all (Default: `100`)
73
73
 
74
74
  **orderBy** (`{ field: 'createdAt' | 'updatedAt', direction: 'ASC' | 'DESC' }`): Sort configuration with field and direction (defaults to { field: 'createdAt', direction: 'DESC' })
75
75
 
@@ -28,7 +28,7 @@ const processor = new TokenLimiterProcessor({
28
28
 
29
29
  **options.limit** (`number`): Maximum number of tokens to allow in the response
30
30
 
31
- **options.encoding** (`TiktokenBPE`): Optional encoding to use. Defaults to o200k\_base which is used by gpt-5.1
31
+ **options.encoding** (`unknown`): Deprecated. Accepted for backwards compatibility but ignored. Token counts are estimated with tokenx, so no encoder is needed.
32
32
 
33
33
  **options.strategy** (`'truncate' | 'abort'`): Strategy when token limit is reached: 'truncate' stops emitting chunks, 'abort' calls abort() to stop the stream
34
34
 
@@ -40,7 +40,7 @@ const processor = new TokenLimiterProcessor({
40
40
 
41
41
  **id** (`string`): Processor identifier set to 'token-limiter'
42
42
 
43
- **name** (`string`): Optional processor display name
43
+ **name** (`string`): Processor display name set to 'Token Limiter'
44
44
 
45
45
  **processInput** (`(args: { messages: MastraDBMessage[]; abort: (reason?: string) => never }) => Promise<MastraDBMessage[]>`): Trims stored history to fit within the token limit before the agentic loop starts in 'memory-only' trim mode, prioritizing recent messages while preserving system messages and the current turn
46
46
 
@@ -121,7 +121,7 @@ Searches for similar vectors with optional metadata filtering.
121
121
 
122
122
  **includeVector** (`boolean`): Whether to include vector data in results (Default: `false`)
123
123
 
124
- **minScore** (`number`): Minimum similarity score threshold (Default: `0`)
124
+ **minScore** (`number`): Minimum similarity score threshold (cosine similarity ranges from -1 to 1) (Default: `-1`)
125
125
 
126
126
  ### `describeIndex()`
127
127
 
@@ -352,6 +352,7 @@ interface QueryResult {
352
352
  score: number
353
353
  metadata: Record<string, any>
354
354
  vector?: number[] // Only included if includeVector is true
355
+ document?: string // Source text stored with the vector, when available
355
356
  }
356
357
  ```
357
358
 
@@ -429,7 +430,7 @@ const results = await store.query({
429
430
 
430
431
  **similarity** (`'cosine' | 'dotProduct' | 'euclidean'`): Vector similarity function. Defaults to MongoDB's own default when omitted.
431
432
 
432
- **numDimensions** (`256 | 512 | 1024 | 2048`): Length of the generated embeddings. (Default: `1024`)
433
+ **numDimensions** (`number`): Length of the generated embeddings. Common values are 256, 512, 1024, and 2048. (Default: `1024`)
433
434
 
434
435
  **quantization** (`'float' | 'scalar' | 'binary' | 'binaryNoRescore'`): Storage format for the generated vectors. (Default: `scalar`)
435
436
 
@@ -82,7 +82,9 @@ const vectorStore = new PgVector({
82
82
 
83
83
  **dimension** (`number`): Vector dimension (must match your embedding model)
84
84
 
85
- **metric** (`'cosine' | 'euclidean' | 'dotproduct'`): Distance metric for similarity search (Default: `cosine`)
85
+ **metric** (`'cosine' | 'euclidean' | 'dotproduct' | 'hamming' | 'jaccard'`): Distance metric for similarity search. 'hamming' and 'jaccard' are only valid with vectorType 'bit', and 'jaccard' requires an HNSW index. (Default: `'cosine' ('hamming' when vectorType is 'bit')`)
86
+
87
+ **vectorType** (`'vector' | 'halfvec' | 'bit' | 'sparsevec'`): pgvector storage type for the embeddings (Default: `vector`)
86
88
 
87
89
  **indexConfig** (`IndexConfig`): Index configuration (Default: `{ type: 'ivfflat' }`)
88
90
 
@@ -142,13 +144,11 @@ Higher M values or efConstruction values will increase memory requirements subst
142
144
 
143
145
  **includeVector** (`boolean`): Whether to include the vector in the result (Default: `false`)
144
146
 
145
- **minScore** (`number`): Minimum similarity score threshold (Default: `0`)
146
-
147
- **options** (`{ ef?: number; probes?: number }`): Additional options for HNSW and IVF indexes
147
+ **minScore** (`number`): Minimum similarity score threshold (Default: `-1`)
148
148
 
149
- **options.ef** (`number`): HNSW search parameter
149
+ **ef** (`number`): HNSW search parameter. Higher values improve accuracy at the cost of speed.
150
150
 
151
- **options.probes** (`number`): IVF search parameter
151
+ **probes** (`number`): IVFFlat search parameter. Number of lists to visit during search.
152
152
 
153
153
  ### `listIndexes()`
154
154
 
@@ -164,8 +164,9 @@ Returns:
164
164
  interface PGIndexStats {
165
165
  dimension: number
166
166
  count: number
167
- metric: 'cosine' | 'euclidean' | 'dotproduct'
167
+ metric: 'cosine' | 'euclidean' | 'dotproduct' | 'hamming' | 'jaccard'
168
168
  type: 'flat' | 'hnsw' | 'ivfflat'
169
+ vectorType: 'vector' | 'halfvec' | 'bit' | 'sparsevec'
169
170
  config: {
170
171
  m?: number
171
172
  efConstruction?: number
@@ -246,7 +247,7 @@ Closes the database connection pool. Should be called when done using the store.
246
247
 
247
248
  **indexName** (`string`): Name of the index to define
248
249
 
249
- **metric** (`'cosine' | 'euclidean' | 'dotproduct'`): Distance metric for similarity search (Default: `cosine`)
250
+ **metric** (`'cosine' | 'euclidean' | 'dotproduct' | 'hamming' | 'jaccard'`): Distance metric for similarity search (Default: `cosine`)
250
251
 
251
252
  **indexConfig** (`IndexConfig`): Configuration for the index type and parameters
252
253
 
@@ -291,17 +292,21 @@ interface QueryResult {
291
292
 
292
293
  ## Error handling
293
294
 
294
- The store throws typed errors that can be caught:
295
+ The store throws `MastraError` instances from `@mastra/core/error`:
295
296
 
296
297
  ```typescript
298
+ import { MastraError } from '@mastra/core/error'
299
+
297
300
  try {
298
301
  await store.query({
299
302
  indexName: 'index_name',
300
303
  queryVector: queryVector,
301
304
  })
302
305
  } catch (error) {
303
- if (error instanceof VectorStoreError) {
304
- console.log(error.code) // 'connection_failed' | 'invalid_dimension' | etc
306
+ if (error instanceof MastraError) {
307
+ console.log(error.id) // 'MASTRA_VECTOR_PG_QUERY_FAILED'
308
+ console.log(error.domain) // 'MASTRA_VECTOR'
309
+ console.log(error.category) // 'USER' | 'THIRD_PARTY'
305
310
  console.log(error.details) // Additional error context
306
311
  }
307
312
  }
@@ -8,6 +8,8 @@ The UpstashVector class provides vector search using [Upstash Vector](https://up
8
8
 
9
9
  ## Constructor options
10
10
 
11
+ **id** (`string`): Unique identifier for this vector store instance
12
+
11
13
  **url** (`string`): Upstash Vector database URL
12
14
 
13
15
  **token** (`string`): Upstash Vector API token
@@ -194,24 +196,28 @@ Query results are returned in this format:
194
196
  interface QueryResult {
195
197
  id: string
196
198
  score: number
197
- metadata: Record<string, any>
199
+ metadata?: Record<string, any>
198
200
  vector?: number[] // Only included if includeVector is true
199
201
  }
200
202
  ```
201
203
 
202
204
  ## Error handling
203
205
 
204
- The store throws typed errors that can be caught:
206
+ The store throws `MastraError` instances from `@mastra/core/error`:
205
207
 
206
208
  ```typescript
209
+ import { MastraError } from '@mastra/core/error'
210
+
207
211
  try {
208
212
  await store.query({
209
213
  indexName: 'index_name',
210
214
  queryVector: queryVector,
211
215
  })
212
216
  } catch (error) {
213
- if (error instanceof VectorStoreError) {
214
- console.log(error.code) // 'connection_failed' | 'invalid_dimension' | etc
217
+ if (error instanceof MastraError) {
218
+ console.log(error.id) // 'MASTRA_VECTOR_UPSTASH_QUERY_FAILED'
219
+ console.log(error.domain) // 'STORAGE'
220
+ console.log(error.category) // 'USER' | 'THIRD_PARTY'
215
221
  console.log(error.details) // Additional error context
216
222
  }
217
223
  }
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("./src-BpxX0T2g.cjs");
2
+ const require_src = require("./src-BcRCGtUY.cjs");
3
3
  let _mastra_core_processors = require("@mastra/core/processors");
4
4
  exports.AUTO_MODEL_BY_PROVIDER = require_src.AUTO_MODEL_BY_PROVIDER;
5
5
  exports.Extractor = require_src.Extractor;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { C as WorkingMemoryExtractor, E as summarizeConversation, G as Subconscious, K as KnowledgeSemanticIndexCoordinator, T as SUMMARIZE_THREAD_DEFAULTS, Y as ModelByInputTokens, a as extractWorkingMemoryContent, c as getObservationsAsOf, d as AUTO_MODEL_BY_PROVIDER, et as Extractor, f as resolveAutoModelId, h as WorkingMemoryStateProcessor, i as WorkingMemory, m as WORKING_MEMORY_STATE_PROCESSOR_ID, n as MessageHistory, o as extractWorkingMemoryTags, p as WORKING_MEMORY_STATE_ID, q as StaleKnowledgeSemanticIndexError, r as SemanticRecall, s as removeWorkingMemoryTags, t as Memory, w as deepMergeWorkingMemory } from "./src-ThciS3vu.js";
1
+ import { C as WorkingMemoryExtractor, E as summarizeConversation, G as Subconscious, K as KnowledgeSemanticIndexCoordinator, T as SUMMARIZE_THREAD_DEFAULTS, Y as ModelByInputTokens, a as extractWorkingMemoryContent, c as getObservationsAsOf, d as AUTO_MODEL_BY_PROVIDER, et as Extractor, f as resolveAutoModelId, h as WorkingMemoryStateProcessor, i as WorkingMemory, m as WORKING_MEMORY_STATE_PROCESSOR_ID, n as MessageHistory, o as extractWorkingMemoryTags, p as WORKING_MEMORY_STATE_ID, q as StaleKnowledgeSemanticIndexError, r as SemanticRecall, s as removeWorkingMemoryTags, t as Memory, w as deepMergeWorkingMemory } from "./src-DjDnBIS0.js";
2
2
  export { AUTO_MODEL_BY_PROVIDER, Extractor, KnowledgeSemanticIndexCoordinator, Memory, MessageHistory, ModelByInputTokens, SUMMARIZE_THREAD_DEFAULTS, SemanticRecall, StaleKnowledgeSemanticIndexError, Subconscious, WORKING_MEMORY_STATE_ID, WORKING_MEMORY_STATE_PROCESSOR_ID, WorkingMemory, WorkingMemoryExtractor, WorkingMemoryStateProcessor, deepMergeWorkingMemory, extractWorkingMemoryContent, extractWorkingMemoryTags, getObservationsAsOf, removeWorkingMemoryTags, resolveAutoModelId, summarizeConversation };
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("../src-BpxX0T2g.cjs");
2
+ const require_src = require("../src-BcRCGtUY.cjs");
3
3
  exports.AUTO_MODEL_BY_PROVIDER = require_src.AUTO_MODEL_BY_PROVIDER;
4
4
  exports.Extractor = require_src.Extractor;
5
5
  exports.KnowledgeSemanticIndexCoordinator = require_src.KnowledgeSemanticIndexCoordinator;
@@ -1,2 +1,2 @@
1
- import { $ as renderSubconsciousActivity, A as buildObserverSystemPrompt, B as OBSERVATION_CONTEXT_INSTRUCTIONS, C as WorkingMemoryExtractor, D as TokenCounter, E as summarizeConversation, F as parseObserverOutput, G as Subconscious, H as OBSERVATION_CONTEXT_PROMPT_THREAD, I as injectAnchorIds, J as SubconsciousRemindExtractor, K as KnowledgeSemanticIndexCoordinator, L as parseAnchorId, M as formatMessagesForObserver, N as hasCurrentTaskSection, O as OBSERVER_SYSTEM_PROMPT, P as optimizeObservationsForContext, Q as publishSubconsciousActivity, R as stripEphemeralAnchorIds, S as wrapInObservationGroup, U as OBSERVATION_CONTINUATION_HINT, V as OBSERVATION_CONTEXT_PROMPT, W as getObservationContextPrompt, X as SUBCONSCIOUS_ACTIVITY_STATE_ID, Y as ModelByInputTokens, Z as buildSubconsciousActivitySnapshot, _ as deriveObservationGroupProvenance, b as renderObservationGroupsForReflection, c as getObservationsAsOf, d as AUTO_MODEL_BY_PROVIDER, et as Extractor, f as resolveAutoModelId, g as combineObservationGroupRanges, j as extractCurrentTask, k as buildObserverPrompt, l as ObservationalMemoryProcessor, q as StaleKnowledgeSemanticIndexError, u as ObservationalMemory, v as parseObservationGroups, x as stripObservationGroups, y as reconcileObservationGroupsFromReflection, z as OBSERVATIONAL_MEMORY_DEFAULTS } from "../src-ThciS3vu.js";
1
+ import { $ as renderSubconsciousActivity, A as buildObserverSystemPrompt, B as OBSERVATION_CONTEXT_INSTRUCTIONS, C as WorkingMemoryExtractor, D as TokenCounter, E as summarizeConversation, F as parseObserverOutput, G as Subconscious, H as OBSERVATION_CONTEXT_PROMPT_THREAD, I as injectAnchorIds, J as SubconsciousRemindExtractor, K as KnowledgeSemanticIndexCoordinator, L as parseAnchorId, M as formatMessagesForObserver, N as hasCurrentTaskSection, O as OBSERVER_SYSTEM_PROMPT, P as optimizeObservationsForContext, Q as publishSubconsciousActivity, R as stripEphemeralAnchorIds, S as wrapInObservationGroup, U as OBSERVATION_CONTINUATION_HINT, V as OBSERVATION_CONTEXT_PROMPT, W as getObservationContextPrompt, X as SUBCONSCIOUS_ACTIVITY_STATE_ID, Y as ModelByInputTokens, Z as buildSubconsciousActivitySnapshot, _ as deriveObservationGroupProvenance, b as renderObservationGroupsForReflection, c as getObservationsAsOf, d as AUTO_MODEL_BY_PROVIDER, et as Extractor, f as resolveAutoModelId, g as combineObservationGroupRanges, j as extractCurrentTask, k as buildObserverPrompt, l as ObservationalMemoryProcessor, q as StaleKnowledgeSemanticIndexError, u as ObservationalMemory, v as parseObservationGroups, x as stripObservationGroups, y as reconcileObservationGroupsFromReflection, z as OBSERVATIONAL_MEMORY_DEFAULTS } from "../src-DjDnBIS0.js";
2
2
  export { AUTO_MODEL_BY_PROVIDER, Extractor, KnowledgeSemanticIndexCoordinator, ModelByInputTokens, OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTEXT_PROMPT_THREAD, OBSERVATION_CONTINUATION_HINT, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, ObservationalMemoryProcessor, SUBCONSCIOUS_ACTIVITY_STATE_ID, StaleKnowledgeSemanticIndexError, Subconscious, SubconsciousRemindExtractor, TokenCounter, WorkingMemoryExtractor, buildObserverPrompt, buildObserverSystemPrompt, buildSubconsciousActivitySnapshot, combineObservationGroupRanges, deriveObservationGroupProvenance, extractCurrentTask, formatMessagesForObserver, getObservationContextPrompt, getObservationsAsOf, hasCurrentTaskSection, injectAnchorIds, optimizeObservationsForContext, parseAnchorId, parseObservationGroups, parseObserverOutput, publishSubconsciousActivity, reconcileObservationGroupsFromReflection, renderObservationGroupsForReflection, renderSubconsciousActivity, resolveAutoModelId, stripEphemeralAnchorIds, stripObservationGroups, summarizeConversation, wrapInObservationGroup };
@@ -1 +1 @@
1
- {"version":3,"file":"extraction-runner.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/extraction-runner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEnE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAGnE,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAI9D,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAClD;AAiBD,wBAAsB,uBAAuB,CAAC,IAAI,EAAE;IAClD,KAAK,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IACjC,MAAM,EAAE,eAAe,CAAC;IACxB,UAAU,CAAC,EAAE,SAAS,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;IACvC,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/C,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B,GAAG,OAAO,CAAC,0BAA0B,CAAC,CA4HtC"}
1
+ {"version":3,"file":"extraction-runner.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/extraction-runner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEnE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAGnE,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAI9D,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAClD;AAwBD,wBAAsB,uBAAuB,CAAC,IAAI,EAAE;IAClD,KAAK,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IACjC,MAAM,EAAE,eAAe,CAAC;IACxB,UAAU,CAAC,EAAE,SAAS,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;IACvC,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/C,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAuItC"}
@@ -1 +1 @@
1
- {"version":3,"file":"working-memory-extractor.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/working-memory-extractor.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAgFxC,qBAAa,sBAAuB,SAAQ,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;;CAyC7F"}
1
+ {"version":3,"file":"working-memory-extractor.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/working-memory-extractor.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAoFxC,qBAAa,sBAAuB,SAAQ,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;;CA+C7F"}
@@ -19251,8 +19251,12 @@ function formatOmError(error) {
19251
19251
  function isAbortError(error, abortSignal) {
19252
19252
  return abortSignal?.aborted === true || hasAbortInChain(error);
19253
19253
  }
19254
+ function hasEmptyObjectValue(object, extractor) {
19255
+ const value = object[extractor.slug];
19256
+ return typeof value === "object" && value !== null && !Array.isArray(value) && Object.keys(value).length === 0;
19257
+ }
19254
19258
  function shouldRetryEmptyStructuredObject(object, extractors) {
19255
- return Object.keys(object).length === 0 && extractors.some((extractor) => extractor.retryStructuredExtractionOnEmptyObject);
19259
+ return extractors.some((extractor) => extractor.retryStructuredExtractionOnEmptyObject && (Object.keys(object).length === 0 || hasEmptyObjectValue(object, extractor)));
19256
19260
  }
19257
19261
  async function extractStructuredValues(opts) {
19258
19262
  const structuredExtractors = (opts.extractors ?? []).filter((extractor) => extractor.mode === "structured");
@@ -19326,17 +19330,28 @@ ${extractorInstructions}${priorLines.length > 0 ? `\n\n## Prior Extracted Values
19326
19330
  }
19327
19331
  }
19328
19332
  if (retryEmptyObject) try {
19329
- object = await streamWithStructuredOutput(_mastra_core_features.coreFeatures.has("json-prompt-injection:inline") ? "inline" : true);
19333
+ const fallbackJsonPromptInjection = _mastra_core_features.coreFeatures.has("json-prompt-injection:inline") ? "inline" : true;
19334
+ object = {
19335
+ ...object,
19336
+ ...await streamWithStructuredOutput(fallbackJsonPromptInjection)
19337
+ };
19330
19338
  } catch (fallbackError) {
19331
19339
  if (isAbortError(fallbackError, opts.abortSignal)) throw fallbackError;
19332
19340
  const message = fallbackError instanceof Error ? fallbackError.message : String(fallbackError);
19333
- return {
19341
+ if (Object.keys(object).length === 0) return {
19334
19342
  values,
19335
19343
  failures: structuredExtractors.map((extractor) => ({
19336
19344
  slug: extractor.slug,
19337
19345
  error: message
19338
19346
  }))
19339
19347
  };
19348
+ for (const extractor of structuredExtractors) if (extractor.retryStructuredExtractionOnEmptyObject && hasEmptyObjectValue(object, extractor)) {
19349
+ failures.push({
19350
+ slug: extractor.slug,
19351
+ error: message
19352
+ });
19353
+ delete object[extractor.slug];
19354
+ }
19340
19355
  }
19341
19356
  for (const extractor of structuredExtractors) {
19342
19357
  const value = object[extractor.slug];
@@ -24162,6 +24177,9 @@ async function validateAgainstConfiguredSchema(schema, value) {
24162
24177
  }).join("; ");
24163
24178
  throw new Error(`Working memory update does not match the configured schema, so it was not saved: ${details}`);
24164
24179
  }
24180
+ function isEmptyPlainObject(value) {
24181
+ return typeof value === "object" && value !== null && !Array.isArray(value) && Object.keys(value).length === 0;
24182
+ }
24165
24183
  async function getWorkingMemoryDetails(context) {
24166
24184
  const memory = context.memory;
24167
24185
  const memoryConfig = (0, _mastra_core_memory.parseMemoryRequestContext)(context.requestContext)?.memoryConfig;
@@ -24209,8 +24227,9 @@ var WorkingMemoryExtractor = class extends Extractor {
24209
24227
  const configuredSchema = memory.getMergedThreadConfig(memoryConfig ?? {}).workingMemory?.schema;
24210
24228
  let document = current;
24211
24229
  if (configuredSchema) {
24212
- if (current === null) return;
24230
+ if (current === null || isEmptyPlainObject(current)) return;
24213
24231
  document = await validateAgainstConfiguredSchema(configuredSchema, current);
24232
+ if (document === null || isEmptyPlainObject(document)) return;
24214
24233
  }
24215
24234
  const workingMemory = typeof document === "string" ? document : JSON.stringify(document) ?? "";
24216
24235
  if (!workingMemory.trim()) return;
@@ -36881,4 +36900,4 @@ Object.defineProperty(exports, "wrapInObservationGroup", {
36881
36900
  }
36882
36901
  });
36883
36902
 
36884
- //# sourceMappingURL=src-BpxX0T2g.cjs.map
36903
+ //# sourceMappingURL=src-BcRCGtUY.cjs.map