@mastra/memory 1.15.1-alpha.0 → 1.15.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @mastra/memory
2
2
 
3
+ ## 1.15.1-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`4ba3bb1`](https://github.com/mastra-ai/mastra/commit/4ba3bb1e465ad2ddaba3bbf2bc47e0faec32985e), [`2a69802`](https://github.com/mastra-ai/mastra/commit/2a69802a0fc6d8a25a77fa6a42276e9d59a83914)]:
8
+ - @mastra/core@1.25.0-alpha.2
9
+ - @mastra/schema-compat@1.2.8-alpha.0
10
+
3
11
  ## 1.15.1-alpha.0
4
12
 
5
13
  ### Patch Changes
@@ -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.15.1-alpha.0"
6
+ version: "1.15.1-alpha.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.15.1-alpha.0",
2
+ "version": "1.15.1-alpha.1",
3
3
  "package": "@mastra/memory",
4
4
  "exports": {
5
5
  "ModelByInputTokens": {
@@ -307,8 +307,8 @@ Both scenarios are safe - guardrails prevent inappropriate content from being pe
307
307
 
308
308
  ## Related documentation
309
309
 
310
- - [Processors](https://mastra.ai/docs/agents/processors) - General processor concepts and custom processor creation
311
- - [Guardrails](https://mastra.ai/docs/agents/guardrails) - Security and validation processors
312
- - [Memory Overview](https://mastra.ai/docs/memory/overview) - Memory types and configuration
310
+ - [Processors](https://mastra.ai/docs/agents/processors): General processor concepts and custom processor creation
311
+ - [Guardrails](https://mastra.ai/docs/agents/guardrails): Security and validation processors
312
+ - [Memory Overview](https://mastra.ai/docs/memory/overview): Memory types and configuration
313
313
 
314
314
  When creating custom processors avoid mutating the input `messages` array or its objects directly.
@@ -100,8 +100,8 @@ await agent.stream('Hello', {
100
100
 
101
101
  You can use this history in two ways:
102
102
 
103
- - **Automatic inclusion** - Mastra automatically fetches and includes recent messages in the context window. By default, it includes the last 10 messages, keeping agents grounded in the conversation. You can adjust this number with `lastMessages`, but in most cases you don't need to think about it.
104
- - [**Manual querying**](#querying) - For more control, use the `recall()` function to query threads and messages directly. This lets you choose exactly which memories are included in the context window, or fetch messages to render conversation history in your UI.
103
+ - **Automatic inclusion**: Mastra automatically fetches and includes recent messages in the context window. By default, it includes the last 10 messages, keeping agents grounded in the conversation. You can adjust this number with `lastMessages`, but in most cases you don't need to think about it.
104
+ - [**Manual querying**](#querying): For more control, use the `recall()` function to query threads and messages directly. This lets you choose exactly which memories are included in the context window, or fetch messages to render conversation history in your UI.
105
105
 
106
106
  > **Tip:** When memory is enabled, [Studio](https://mastra.ai/docs/studio/overview) uses message history to display past conversations in the chat sidebar.
107
107
 
@@ -157,7 +157,7 @@ With retrieval mode enabled, OM:
157
157
  - Registers a `recall` tool the agent can call to:
158
158
 
159
159
  - Page through the raw messages behind any observation group range
160
- - Search by semantic similarity (`mode: "search"` with a `query` string) requires `vector: true`
160
+ - Search by semantic similarity (`mode: "search"` with a `query` string); requires `vector: true`
161
161
  - List all threads (`mode: "threads"`), browse other threads (`threadId`), and search across all threads (default `scope: 'resource'`)
162
162
  - When `scope: 'thread'`: restrict browsing and search to the current thread only
163
163
 
@@ -397,4 +397,4 @@ const response = await agent.generate('What do you know about me?', {
397
397
 
398
398
  - [Working memory with template](https://github.com/mastra-ai/mastra/tree/main/examples/memory-with-template)
399
399
  - [Working memory with schema](https://github.com/mastra-ai/mastra/tree/main/examples/memory-with-schema)
400
- - [Per-resource working memory](https://github.com/mastra-ai/mastra/tree/main/examples/memory-per-resource-example) - Complete example showing resource-scoped memory persistence
400
+ - [Per-resource working memory](https://github.com/mastra-ai/mastra/tree/main/examples/memory-per-resource-example): Complete example showing resource-scoped memory persistence
package/dist/index.cjs CHANGED
@@ -16453,6 +16453,25 @@ function deepMergeWorkingMemory(existing, update) {
16453
16453
  }
16454
16454
  return result;
16455
16455
  }
16456
+ function stripNullsFromOptional(value, schema) {
16457
+ if (Array.isArray(value)) {
16458
+ const itemSchema = schema.items ?? {};
16459
+ return value.map((item) => stripNullsFromOptional(item, itemSchema));
16460
+ }
16461
+ if (typeof value === "object" && value !== null) {
16462
+ const properties = schema.properties ?? {};
16463
+ const required = schema.required ?? [];
16464
+ const result = {};
16465
+ for (const [key, propertyValue] of Object.entries(value)) {
16466
+ if (propertyValue === null && !required.includes(key)) {
16467
+ continue;
16468
+ }
16469
+ result[key] = stripNullsFromOptional(propertyValue, properties[key] ?? {});
16470
+ }
16471
+ return result;
16472
+ }
16473
+ return value;
16474
+ }
16456
16475
  var updateWorkingMemoryTool = (memoryConfig) => {
16457
16476
  const schema$2 = memoryConfig?.workingMemory?.schema;
16458
16477
  let inputSchema = zod.z.object({
@@ -16462,7 +16481,7 @@ var updateWorkingMemoryTool = (memoryConfig) => {
16462
16481
  const standardSchema2 = schema$1.isStandardSchemaWithJSON(schema$2) ? schema$2 : schema$1.toStandardSchema(schema$2);
16463
16482
  const jsonSchema4 = schema.standardSchemaToJSONSchema(standardSchema2, { io: "input" });
16464
16483
  delete jsonSchema4.$schema;
16465
- inputSchema = schema$1.toStandardSchema({
16484
+ const wrappedSchema = schema$1.toStandardSchema({
16466
16485
  $schema: "http://json-schema.org/draft-07/schema#",
16467
16486
  type: "object",
16468
16487
  description: "The JSON formatted working memory content to store.",
@@ -16471,6 +16490,41 @@ var updateWorkingMemoryTool = (memoryConfig) => {
16471
16490
  },
16472
16491
  required: ["memory"]
16473
16492
  });
16493
+ inputSchema = {
16494
+ "~standard": {
16495
+ version: 1,
16496
+ vendor: "mastra",
16497
+ validate: (value) => {
16498
+ const wrappedResult = wrappedSchema["~standard"].validate(value);
16499
+ if (wrappedResult instanceof Promise) {
16500
+ return wrappedResult.then((result) => {
16501
+ if (!("issues" in result) || !result.issues) {
16502
+ return result;
16503
+ }
16504
+ if (!value || typeof value !== "object" || Array.isArray(value) || "memory" in value) {
16505
+ return result;
16506
+ }
16507
+ return wrappedSchema["~standard"].validate({
16508
+ memory: stripNullsFromOptional(value, jsonSchema4)
16509
+ });
16510
+ });
16511
+ }
16512
+ if (!("issues" in wrappedResult) || !wrappedResult.issues) {
16513
+ return wrappedResult;
16514
+ }
16515
+ if (!value || typeof value !== "object" || Array.isArray(value) || "memory" in value) {
16516
+ return wrappedResult;
16517
+ }
16518
+ return wrappedSchema["~standard"].validate({
16519
+ memory: stripNullsFromOptional(value, jsonSchema4)
16520
+ });
16521
+ },
16522
+ jsonSchema: {
16523
+ input: (props) => wrappedSchema["~standard"].jsonSchema.input(props),
16524
+ output: (props) => wrappedSchema["~standard"].jsonSchema.output(props)
16525
+ }
16526
+ }
16527
+ };
16474
16528
  }
16475
16529
  const usesMergeSemantics = Boolean(schema$2);
16476
16530
  const description = schema$2 ? `Update the working memory with new information. Data is merged with existing memory - only include fields you want to add or update. To preserve existing data, omit the field entirely. Arrays are replaced entirely when provided, so pass the complete array or omit it to keep the existing values.` : `Update the working memory with new information. Any data not included will be overwritten. Always pass data as string to the memory field. Never pass an object.`;