@mastra/memory 1.20.0 → 1.20.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/_types/@internal_ai-sdk-v4/dist/index.d.ts +2 -160
  3. package/dist/{chunk-BCWFD5J7.js → chunk-KMJQDCCZ.js} +144 -15
  4. package/dist/chunk-KMJQDCCZ.js.map +1 -0
  5. package/dist/{chunk-SMKIROLC.cjs → chunk-P4BYW7GY.cjs} +143 -14
  6. package/dist/chunk-P4BYW7GY.cjs.map +1 -0
  7. package/dist/docs/SKILL.md +1 -1
  8. package/dist/docs/assets/SOURCE_MAP.json +39 -39
  9. package/dist/docs/references/docs-agents-agent-approval.md +14 -0
  10. package/dist/docs/references/docs-memory-observational-memory.md +19 -0
  11. package/dist/docs/references/docs-memory-semantic-recall.md +1 -1
  12. package/dist/docs/references/reference-memory-observational-memory.md +2 -0
  13. package/dist/docs/references/reference-vectors-pg.md +2 -0
  14. package/dist/index.cjs +199 -203
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +190 -194
  18. package/dist/index.js.map +1 -1
  19. package/dist/{observational-memory-LGCWMUEM.cjs → observational-memory-CDLGZL67.cjs} +26 -26
  20. package/dist/{observational-memory-LGCWMUEM.cjs.map → observational-memory-CDLGZL67.cjs.map} +1 -1
  21. package/dist/{observational-memory-E6F7NKJP.js → observational-memory-TJFOX3YN.js} +3 -3
  22. package/dist/{observational-memory-E6F7NKJP.js.map → observational-memory-TJFOX3YN.js.map} +1 -1
  23. package/dist/processors/index.cjs +24 -24
  24. package/dist/processors/index.js +1 -1
  25. package/dist/processors/observational-memory/observation-strategies/types.d.ts +4 -2
  26. package/dist/processors/observational-memory/observation-strategies/types.d.ts.map +1 -1
  27. package/dist/processors/observational-memory/observation-turn/turn.d.ts +5 -1
  28. package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -1
  29. package/dist/processors/observational-memory/observational-memory.d.ts +5 -1
  30. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
  31. package/dist/processors/observational-memory/processor.d.ts.map +1 -1
  32. package/dist/processors/observational-memory/temporal-markers.d.ts.map +1 -1
  33. package/dist/processors/observational-memory/token-counter.d.ts +1 -0
  34. package/dist/processors/observational-memory/token-counter.d.ts.map +1 -1
  35. package/dist/processors/observational-memory/types.d.ts +11 -0
  36. package/dist/processors/observational-memory/types.d.ts.map +1 -1
  37. package/dist/tools/working-memory.d.ts.map +1 -1
  38. package/package.json +8 -8
  39. package/dist/chunk-BCWFD5J7.js.map +0 -1
  40. package/dist/chunk-SMKIROLC.cjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @mastra/memory
2
2
 
3
+ ## 1.20.1-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed observational memory replaying previously observed assistant responses during reprocessing, so past assistant messages no longer reappear in later turns. ([#17338](https://github.com/mastra-ai/mastra/pull/17338))
8
+
9
+ - Fixed a crash in Cloudflare Workers when using a Zod schema for working memory. Working-memory input is now validated directly by the provided schema validator, which avoids runtime restrictions in Cloudflare Workers. ([#17327](https://github.com/mastra-ai/mastra/pull/17327))
10
+
11
+ - Preserve system-reminder filtering for normalized reactive signal metadata. ([#17191](https://github.com/mastra-ai/mastra/pull/17191))
12
+
13
+ - Fixed `Memory.saveMessages` not populating `role`, `content`, and `created_at` in the vector store metadata. Calls to `GET /api/memory/search` now return matches with the full message shape regardless of whether messages were saved through `agent.generate`/`agent.stream` or written directly via `Memory.saveMessages` (for example through the `POST /api/memory/save-messages` HTTP route used by external agents). ([#16381](https://github.com/mastra-ai/mastra/pull/16381))
14
+
15
+ - Updated dependencies [[`00eca42`](https://github.com/mastra-ai/mastra/commit/00eca4252393aa114dc8c9a5e1da68df91fa06cf), [`8ace89d`](https://github.com/mastra-ai/mastra/commit/8ace89df77f762e622d3b9f7f65ad7524350d050), [`fa63872`](https://github.com/mastra-ai/mastra/commit/fa6387280954e6b667bec5714b55ba082bc627ff), [`f07b646`](https://github.com/mastra-ai/mastra/commit/f07b64604ab7d25391179790b7fd4823df9e2dff), [`d8838ae`](https://github.com/mastra-ai/mastra/commit/d8838ae80b69780361693d27098f7f6684af12fe), [`40f9297`](https://github.com/mastra-ai/mastra/commit/40f9297003b921c62373d3e8d3a4bda76c9f6de3), [`0f0d1ba`](https://github.com/mastra-ai/mastra/commit/0f0d1ba67bfcb2204e571401662f1eceefc03357), [`8c31bcd`](https://github.com/mastra-ai/mastra/commit/8c31bcdb00e597880d5939b1b7d7566fbe5dacae), [`95b14cd`](https://github.com/mastra-ai/mastra/commit/95b14cdd820e86d97ac05fe568424c513a252e31), [`aa36be2`](https://github.com/mastra-ai/mastra/commit/aa36be23aa513b7dc53cb8ca16b7fab8f20e43ad), [`212c635`](https://github.com/mastra-ai/mastra/commit/212c635203e61d036ab41db8ff86c3893dc795b3), [`d8838ae`](https://github.com/mastra-ai/mastra/commit/d8838ae80b69780361693d27098f7f6684af12fe), [`9aa5a73`](https://github.com/mastra-ai/mastra/commit/9aa5a73e7e110f6e9365eec69364a33d5f03bb56), [`f73c789`](https://github.com/mastra-ai/mastra/commit/f73c789e8ef21561580395d2c410119cab5848c8), [`8bd16da`](https://github.com/mastra-ai/mastra/commit/8bd16da73a4cb874d739373643dbd6a6e7f88684), [`c8630f8`](https://github.com/mastra-ai/mastra/commit/c8630f80d4f40cb5d22e60ab162b618b1907167a), [`47f71dc`](https://github.com/mastra-ai/mastra/commit/47f71dc6fbcbd12d71e21a979e676e20a02bd77d), [`50ceae2`](https://github.com/mastra-ai/mastra/commit/50ceae270878e2f8fb2b2c6c2faab09df0007c8a), [`8cdde58`](https://github.com/mastra-ai/mastra/commit/8cdde5875bbba6702d9df226f2b20232b8d75d6c), [`847ff1e`](https://github.com/mastra-ai/mastra/commit/847ff1e0d94368d94b2e173e4e0908e115568ef3), [`259d409`](https://github.com/mastra-ai/mastra/commit/259d409a514174299dbde1ff5e1121209b3ba850), [`9e16c68`](https://github.com/mastra-ai/mastra/commit/9e16c6818b6485ccb43df28aba6f3a2219d28662), [`cefca33`](https://github.com/mastra-ai/mastra/commit/cefca33ae666e69810c935fedf95a929c173d1d7), [`d00e8c5`](https://github.com/mastra-ai/mastra/commit/d00e8c50daebe5bce5bf2f48bde39c86fc3d2fe4), [`36fa7e2`](https://github.com/mastra-ai/mastra/commit/36fa7e24d14e58a1eb46147097b32f583e5b8775), [`87e9774`](https://github.com/mastra-ai/mastra/commit/87e97741c1e493cd6d62f478eb810b49bda4d57c), [`65a72e7`](https://github.com/mastra-ai/mastra/commit/65a72e70c25eedea8ff985a6624b96be2850236b), [`0f77241`](https://github.com/mastra-ai/mastra/commit/0f7724108806703799a8ba80ad0f09414afd5066), [`92ff509`](https://github.com/mastra-ai/mastra/commit/92ff5098ef8a990438ca038077021a5f7541ec1d), [`3fce5e7`](https://github.com/mastra-ai/mastra/commit/3fce5e70d011d289043e75003ef3336ed4aa43c3), [`a763592`](https://github.com/mastra-ai/mastra/commit/a763592c3db46963ef1011cfe16fe372816e775e), [`80c7737`](https://github.com/mastra-ai/mastra/commit/80c7737e32d7917b5f356957d67c169d01744fd3), [`3f1cf47`](https://github.com/mastra-ai/mastra/commit/3f1cf476f74c1e4cc2df908837e05853a5347e31), [`ff9d743`](https://github.com/mastra-ai/mastra/commit/ff9d743f71d7e072927725c0d700632aca0c1fee)]:
16
+ - @mastra/schema-compat@1.2.11-alpha.0
17
+ - @mastra/core@1.38.0-alpha.3
18
+
19
+ ## 1.20.1-alpha.0
20
+
21
+ ### Patch Changes
22
+
23
+ - Added `observation.bufferOnIdle` to opt idle turns into background observation buffering and carry the signal sender needed for background notifications. ([#17181](https://github.com/mastra-ai/mastra/pull/17181))
24
+
25
+ - Updated dependencies [[`d779de3`](https://github.com/mastra-ai/mastra/commit/d779de3cd9d2e7ed8110547190e2f15e786a0e41), [`1750c97`](https://github.com/mastra-ai/mastra/commit/1750c975d6179fbf6db2813b15229d4f8f23fc55), [`0e32507`](https://github.com/mastra-ai/mastra/commit/0e32507962cdfa5569b7bda5bc6fb3dd34e40b03), [`3a081c1`](https://github.com/mastra-ai/mastra/commit/3a081c1255c5ae8c99f6dad91cc612934ef6f2bd), [`fe9eacd`](https://github.com/mastra-ai/mastra/commit/fe9eacd9545a0a9d64aad31c9fa90294a425289e), [`db79c86`](https://github.com/mastra-ai/mastra/commit/db79c86c60723d57e02f9636ca2611bd4515f194)]:
26
+ - @mastra/core@1.38.0-alpha.2
27
+
3
28
  ## 1.20.0
4
29
 
5
30
  ### Minor Changes
@@ -1,3 +1,4 @@
1
+ import { JSONSchema7 } from 'json-schema';
1
2
  import { ServerResponse } from 'http';
2
3
  import { ServerResponse as ServerResponse_2 } from 'node:http';
3
4
  import { z } from 'zod';
@@ -3324,165 +3325,6 @@ export declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7, {
3324
3325
  };
3325
3326
  }): Schema<OBJECT>;
3326
3327
 
3327
- declare interface JSONSchema7 {
3328
- $id?: string | undefined;
3329
- $ref?: string | undefined;
3330
- $schema?: JSONSchema7Version | undefined;
3331
- $comment?: string | undefined;
3332
-
3333
- /**
3334
- * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
3335
- * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
3336
- */
3337
- $defs?: {
3338
- [key: string]: JSONSchema7Definition;
3339
- } | undefined;
3340
-
3341
- /**
3342
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
3343
- */
3344
- type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
3345
- enum?: JSONSchema7Type[] | undefined;
3346
- const?: JSONSchema7Type | undefined;
3347
-
3348
- /**
3349
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
3350
- */
3351
- multipleOf?: number | undefined;
3352
- maximum?: number | undefined;
3353
- exclusiveMaximum?: number | undefined;
3354
- minimum?: number | undefined;
3355
- exclusiveMinimum?: number | undefined;
3356
-
3357
- /**
3358
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
3359
- */
3360
- maxLength?: number | undefined;
3361
- minLength?: number | undefined;
3362
- pattern?: string | undefined;
3363
-
3364
- /**
3365
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
3366
- */
3367
- items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
3368
- additionalItems?: JSONSchema7Definition | undefined;
3369
- maxItems?: number | undefined;
3370
- minItems?: number | undefined;
3371
- uniqueItems?: boolean | undefined;
3372
- contains?: JSONSchema7Definition | undefined;
3373
-
3374
- /**
3375
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
3376
- */
3377
- maxProperties?: number | undefined;
3378
- minProperties?: number | undefined;
3379
- required?: string[] | undefined;
3380
- properties?: {
3381
- [key: string]: JSONSchema7Definition;
3382
- } | undefined;
3383
- patternProperties?: {
3384
- [key: string]: JSONSchema7Definition;
3385
- } | undefined;
3386
- additionalProperties?: JSONSchema7Definition | undefined;
3387
- dependencies?: {
3388
- [key: string]: JSONSchema7Definition | string[];
3389
- } | undefined;
3390
- propertyNames?: JSONSchema7Definition | undefined;
3391
-
3392
- /**
3393
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
3394
- */
3395
- if?: JSONSchema7Definition | undefined;
3396
- then?: JSONSchema7Definition | undefined;
3397
- else?: JSONSchema7Definition | undefined;
3398
-
3399
- /**
3400
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
3401
- */
3402
- allOf?: JSONSchema7Definition[] | undefined;
3403
- anyOf?: JSONSchema7Definition[] | undefined;
3404
- oneOf?: JSONSchema7Definition[] | undefined;
3405
- not?: JSONSchema7Definition | undefined;
3406
-
3407
- /**
3408
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
3409
- */
3410
- format?: string | undefined;
3411
-
3412
- /**
3413
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
3414
- */
3415
- contentMediaType?: string | undefined;
3416
- contentEncoding?: string | undefined;
3417
-
3418
- /**
3419
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
3420
- */
3421
- definitions?: {
3422
- [key: string]: JSONSchema7Definition;
3423
- } | undefined;
3424
-
3425
- /**
3426
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
3427
- */
3428
- title?: string | undefined;
3429
- description?: string | undefined;
3430
- default?: JSONSchema7Type | undefined;
3431
- readOnly?: boolean | undefined;
3432
- writeOnly?: boolean | undefined;
3433
- examples?: JSONSchema7Type | undefined;
3434
- }
3435
-
3436
- declare interface JSONSchema7Array extends Array<JSONSchema7Type> {}
3437
-
3438
- /**
3439
- * JSON Schema v7
3440
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
3441
- */
3442
- declare type JSONSchema7Definition = JSONSchema7 | boolean;
3443
-
3444
- declare interface JSONSchema7Object {
3445
- [key: string]: JSONSchema7Type;
3446
- }
3447
-
3448
- /**
3449
- * Primitive type
3450
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
3451
- */
3452
- declare type JSONSchema7Type =
3453
- | string //
3454
- | number
3455
- | boolean
3456
- | JSONSchema7Object
3457
- | JSONSchema7Array
3458
- | null;
3459
-
3460
- /**
3461
- * Primitive type
3462
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
3463
- */
3464
- declare type JSONSchema7TypeName =
3465
- | "string" //
3466
- | "number"
3467
- | "integer"
3468
- | "boolean"
3469
- | "object"
3470
- | "array"
3471
- | "null";
3472
-
3473
- /**
3474
- * Meta schema
3475
- *
3476
- * Recommended values:
3477
- * - 'http://json-schema.org/schema#'
3478
- * - 'http://json-schema.org/hyper-schema#'
3479
- * - 'http://json-schema.org/draft-07/schema#'
3480
- * - 'http://json-schema.org/draft-07/hyper-schema#'
3481
- *
3482
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
3483
- */
3484
- declare type JSONSchema7Version = string;
3485
-
3486
3328
  /**
3487
3329
  A JSON value can be a string, number, boolean, object, array, or null.
3488
3330
  JSON values can be serialized and deserialized by the JSON.stringify and JSON.parse methods.
@@ -7605,4 +7447,4 @@ export declare function zodSchema<OBJECT>(zodSchema: z.Schema<OBJECT, z.ZodTypeD
7605
7447
  }): Schema<OBJECT>;
7606
7448
 
7607
7449
  export { }
7608
- export { LanguageModelV1Message as LanguageModelV1Message, LanguageModelV1CallSettings as LanguageModelV1CallSettings, LanguageModelV1FunctionTool as LanguageModelV1FunctionTool, LanguageModelV1ProviderDefinedTool as LanguageModelV1ProviderDefinedTool, LanguageModelV1ToolChoice as LanguageModelV1ToolChoice, LanguageModelV1ObjectGenerationMode as LanguageModelV1ObjectGenerationMode, LanguageModelV1FunctionToolCall as LanguageModelV1FunctionToolCall, LanguageModelV1Source as LanguageModelV1Source, LanguageModelV1LogProbs as LanguageModelV1LogProbs, FetchFunction as FetchFunction, TextUIPart as TextUIPart, ReasoningUIPart as ReasoningUIPart, ToolInvocationUIPart as ToolInvocationUIPart, SourceUIPart as SourceUIPart, FileUIPart as FileUIPart, StepStartUIPart as StepStartUIPart, AssistantStreamPartType as AssistantStreamPartType, AssistantStreamPartValueType as AssistantStreamPartValueType, AssistantStreamString as AssistantStreamString, DataStreamPartType as DataStreamPartType, DataStreamPartValueType as DataStreamPartValueType, DeepPartialInternal as DeepPartialInternal, Validator as Validator, JSONSchema7 as JSONSchema7, LanguageModelV1FinishReason as LanguageModelV1FinishReason, LanguageModelV1CallWarning as LanguageModelV1CallWarning, JSONValue_2 as JSONValue_2, Source as Source, DataStreamString as DataStreamString, AttributeValue as AttributeValue, Tracer as Tracer, EmbeddingModelV1 as EmbeddingModelV1, EmbeddingModelV1Embedding as EmbeddingModelV1Embedding, ImageModelV1CallWarning as ImageModelV1CallWarning, TranscriptionModelV1CallWarning as TranscriptionModelV1CallWarning, SpeechModelV1CallWarning as SpeechModelV1CallWarning, ProviderOptions as ProviderOptions, ReasoningPart as ReasoningPart, RedactedReasoningPart as RedactedReasoningPart, ToolResultContent as ToolResultContent, inferParameters as inferParameters, ToolParameters as ToolParameters, JSONRPCRequestSchema as JSONRPCRequestSchema, JSONRPCResponseSchema as JSONRPCResponseSchema, JSONRPCErrorSchema as JSONRPCErrorSchema, JSONRPCNotificationSchema as JSONRPCNotificationSchema, JSONRPCMessageSchema as JSONRPCMessageSchema, MCPClientConfig as MCPClientConfig, MCPClient as MCPClient, ValueOf as ValueOf, ToToolResultObject as ToToolResultObject, ToToolsWithDefinedExecute as ToToolsWithDefinedExecute, ToToolsWithExecute as ToToolsWithExecute, ReasoningDetail as ReasoningDetail, ToolCallArray as ToolCallArray, ToolResultArray as ToolResultArray, ResponseMessage as ResponseMessage, Output_2 as Output_2, ConsumeStreamOptions as ConsumeStreamOptions, ImageModelV1 as ImageModelV1, CallSettings as CallSettings, Prompt as Prompt, StreamObjectOnErrorCallback as StreamObjectOnErrorCallback, AsyncIterableStream as AsyncIterableStream, SpeechModelV1 as SpeechModelV1, TranscriptionModelV1 as TranscriptionModelV1, LanguageModelV1ProviderMetadata as LanguageModelV1ProviderMetadata, ExtractModelId as ExtractModelId, ExtractLiteralUnion as ExtractLiteralUnion, ProviderV1 as ProviderV1, SingleRequestTextStreamPart as SingleRequestTextStreamPart, RetryErrorReason as RetryErrorReason, AssistantResponseSettings as AssistantResponseSettings, AssistantResponseCallback as AssistantResponseCallback };
7450
+ export { LanguageModelV1Message as LanguageModelV1Message, LanguageModelV1CallSettings as LanguageModelV1CallSettings, LanguageModelV1FunctionTool as LanguageModelV1FunctionTool, LanguageModelV1ProviderDefinedTool as LanguageModelV1ProviderDefinedTool, LanguageModelV1ToolChoice as LanguageModelV1ToolChoice, LanguageModelV1ObjectGenerationMode as LanguageModelV1ObjectGenerationMode, LanguageModelV1FunctionToolCall as LanguageModelV1FunctionToolCall, LanguageModelV1Source as LanguageModelV1Source, LanguageModelV1LogProbs as LanguageModelV1LogProbs, FetchFunction as FetchFunction, TextUIPart as TextUIPart, ReasoningUIPart as ReasoningUIPart, ToolInvocationUIPart as ToolInvocationUIPart, SourceUIPart as SourceUIPart, FileUIPart as FileUIPart, StepStartUIPart as StepStartUIPart, AssistantStreamPartType as AssistantStreamPartType, AssistantStreamPartValueType as AssistantStreamPartValueType, AssistantStreamString as AssistantStreamString, DataStreamPartType as DataStreamPartType, DataStreamPartValueType as DataStreamPartValueType, DeepPartialInternal as DeepPartialInternal, Validator as Validator, LanguageModelV1FinishReason as LanguageModelV1FinishReason, LanguageModelV1CallWarning as LanguageModelV1CallWarning, JSONValue_2 as JSONValue_2, Source as Source, DataStreamString as DataStreamString, AttributeValue as AttributeValue, Tracer as Tracer, EmbeddingModelV1 as EmbeddingModelV1, EmbeddingModelV1Embedding as EmbeddingModelV1Embedding, ImageModelV1CallWarning as ImageModelV1CallWarning, TranscriptionModelV1CallWarning as TranscriptionModelV1CallWarning, SpeechModelV1CallWarning as SpeechModelV1CallWarning, ProviderOptions as ProviderOptions, ReasoningPart as ReasoningPart, RedactedReasoningPart as RedactedReasoningPart, ToolResultContent as ToolResultContent, inferParameters as inferParameters, ToolParameters as ToolParameters, JSONRPCRequestSchema as JSONRPCRequestSchema, JSONRPCResponseSchema as JSONRPCResponseSchema, JSONRPCErrorSchema as JSONRPCErrorSchema, JSONRPCNotificationSchema as JSONRPCNotificationSchema, JSONRPCMessageSchema as JSONRPCMessageSchema, MCPClientConfig as MCPClientConfig, MCPClient as MCPClient, ValueOf as ValueOf, ToToolResultObject as ToToolResultObject, ToToolsWithDefinedExecute as ToToolsWithDefinedExecute, ToToolsWithExecute as ToToolsWithExecute, ReasoningDetail as ReasoningDetail, ToolCallArray as ToolCallArray, ToolResultArray as ToolResultArray, ResponseMessage as ResponseMessage, Output_2 as Output_2, ConsumeStreamOptions as ConsumeStreamOptions, ImageModelV1 as ImageModelV1, CallSettings as CallSettings, Prompt as Prompt, StreamObjectOnErrorCallback as StreamObjectOnErrorCallback, AsyncIterableStream as AsyncIterableStream, SpeechModelV1 as SpeechModelV1, TranscriptionModelV1 as TranscriptionModelV1, LanguageModelV1ProviderMetadata as LanguageModelV1ProviderMetadata, ExtractModelId as ExtractModelId, ExtractLiteralUnion as ExtractLiteralUnion, ProviderV1 as ProviderV1, SingleRequestTextStreamPart as SingleRequestTextStreamPart, RetryErrorReason as RetryErrorReason, AssistantResponseSettings as AssistantResponseSettings, AssistantResponseCallback as AssistantResponseCallback };
@@ -6,7 +6,7 @@ import { MessageHistory } from '@mastra/core/processors';
6
6
  import xxhash from 'xxhash-wasm';
7
7
  import { appendFileSync, writeFileSync, mkdirSync } from 'fs';
8
8
  import { join } from 'path';
9
- import { randomBytes, createHash, randomUUID } from 'crypto';
9
+ import { createHash, randomBytes, randomUUID } from 'crypto';
10
10
  import { estimateTokenCount } from 'tokenx';
11
11
  import { Agent } from '@mastra/core/agent';
12
12
  import { getOrCreateSpan, EntityType, SpanType, createObservabilityContext } from '@mastra/core/observability';
@@ -2404,6 +2404,8 @@ var ObservationTurn = class {
2404
2404
  requestContext;
2405
2405
  /** Optional observability context for nested OM spans. */
2406
2406
  observabilityContext;
2407
+ /** Optional signal sender for processor-originated notifications. */
2408
+ sendSignal;
2407
2409
  /** Current actor model for this step. Updated by the processor before prepare(). */
2408
2410
  actorModelContext;
2409
2411
  /** Processor-provided hooks for turn/step lifecycle integration. */
@@ -2413,6 +2415,8 @@ var ObservationTurn = class {
2413
2415
  this.threadId = opts.threadId;
2414
2416
  this.resourceId = opts.resourceId;
2415
2417
  this.messageList = opts.messageList;
2418
+ this.sendSignal = opts.sendSignal;
2419
+ this.requestContext = opts.requestContext;
2416
2420
  this.observabilityContext = opts.observabilityContext;
2417
2421
  this.hooks = opts.hooks ?? {};
2418
2422
  }
@@ -2502,7 +2506,9 @@ var ObservationTurn = class {
2502
2506
  if (unsavedMessages.length > 0) {
2503
2507
  await this.om.persistMessages(unsavedMessages, this.threadId, this.resourceId);
2504
2508
  }
2505
- if (this.om.buffering.isAsyncObservationEnabled()) {
2509
+ const asyncObservationEnabled = this.om.buffering.isAsyncObservationEnabled();
2510
+ const bufferOnIdle = this.om.getObservationConfig().bufferOnIdle;
2511
+ if (asyncObservationEnabled && bufferOnIdle) {
2506
2512
  const allMessages = this.messageList.get.all.db();
2507
2513
  const record = this._record;
2508
2514
  const unobservedMessages = this.om.getUnobservedMessages(allMessages, record);
@@ -2513,8 +2519,11 @@ var ObservationTurn = class {
2513
2519
  messages: unobservedMessages,
2514
2520
  record,
2515
2521
  writer: this.writer,
2522
+ sendSignal: this.sendSignal,
2516
2523
  requestContext: this.requestContext,
2517
- observabilityContext: this.observabilityContext
2524
+ currentModel: this.actorModelContext,
2525
+ observabilityContext: this.observabilityContext,
2526
+ skipMinimumTokenCheck: true
2518
2527
  }).catch((err) => {
2519
2528
  omDebug(`[OM:turn.end] idle buffer failed: ${err?.message}`);
2520
2529
  });
@@ -5746,7 +5755,7 @@ function ensureMessageMastraMetadata(message) {
5746
5755
  return typedMessage.metadata.mastra;
5747
5756
  }
5748
5757
  function buildEstimateKey(kind, text) {
5749
- const payloadHash = createHash("sha1").update(text).digest("hex");
5758
+ const payloadHash = createHash("sha256").update(text).digest("hex");
5750
5759
  return `${kind}:${payloadHash}`;
5751
5760
  }
5752
5761
  function resolveEstimatorId() {
@@ -6289,7 +6298,7 @@ function getAttachmentFingerprint(asset) {
6289
6298
  }
6290
6299
  const base64 = encodeAttachmentBase64(asset);
6291
6300
  if (base64) {
6292
- return { contentHash: createHash("sha1").update(base64).digest("hex") };
6301
+ return { contentHash: createHash("sha256").update(base64).digest("hex") };
6293
6302
  }
6294
6303
  return {};
6295
6304
  }
@@ -6568,6 +6577,116 @@ var TokenCounter = class _TokenCounter {
6568
6577
  resolveToolResultForTokenCounting(part, invocationResult) {
6569
6578
  return resolveToolResultValue(part, invocationResult);
6570
6579
  }
6580
+ countMultimodalToolResultContent(part, toolResult) {
6581
+ if (!toolResult || typeof toolResult !== "object") {
6582
+ return void 0;
6583
+ }
6584
+ const output = toolResult;
6585
+ const content = output.type === "content" && Array.isArray(output.value) ? output.value : output.content;
6586
+ if (!Array.isArray(content)) {
6587
+ return void 0;
6588
+ }
6589
+ let hasAttachment = false;
6590
+ let tokens = 0;
6591
+ const cacheParts = [];
6592
+ const countJsonContentPart = (contentPart) => {
6593
+ const formatted = formatToolResultForObserver(contentPart);
6594
+ tokens += this.countString(formatted);
6595
+ cacheParts.push({ type: "json", valueHash: createHash("sha256").update(formatted).digest("hex") });
6596
+ };
6597
+ for (const item of content) {
6598
+ if (!item || typeof item !== "object") {
6599
+ continue;
6600
+ }
6601
+ const contentPart = item;
6602
+ const partType = contentPart.type;
6603
+ if (partType === "text") {
6604
+ const text = typeof contentPart.text === "string" ? contentPart.text : String(contentPart.value ?? "");
6605
+ tokens += this.countString(text);
6606
+ cacheParts.push({ type: "text", textHash: createHash("sha256").update(text).digest("hex") });
6607
+ continue;
6608
+ }
6609
+ if (partType === "image" || partType === "image-data" || partType === "media" && String(contentPart.mediaType ?? "").startsWith("image/")) {
6610
+ if (typeof contentPart.data !== "string") {
6611
+ countJsonContentPart(contentPart);
6612
+ continue;
6613
+ }
6614
+ hasAttachment = true;
6615
+ const imagePart = {
6616
+ type: "image",
6617
+ image: contentPart.data,
6618
+ mimeType: contentPart.mediaType ?? contentPart.mimeType,
6619
+ providerOptions: contentPart.providerOptions,
6620
+ providerMetadata: contentPart.providerMetadata
6621
+ };
6622
+ const clientEstimate = getClientPartTokenEstimate(imagePart);
6623
+ if (clientEstimate) {
6624
+ tokens += clientEstimate.tokens;
6625
+ cacheParts.push({
6626
+ type: "image-data-client-estimate",
6627
+ key: clientEstimate.key,
6628
+ tokens: clientEstimate.tokens
6629
+ });
6630
+ continue;
6631
+ }
6632
+ const estimate = this.estimateImageTokens(imagePart);
6633
+ tokens += estimate.tokens;
6634
+ cacheParts.push({ type: "image-data", estimate: JSON.parse(estimate.cachePayload) });
6635
+ continue;
6636
+ }
6637
+ if (partType === "audio" || partType === "file-data" || partType === "media") {
6638
+ if (typeof contentPart.data !== "string") {
6639
+ countJsonContentPart(contentPart);
6640
+ continue;
6641
+ }
6642
+ hasAttachment = true;
6643
+ const filePart = {
6644
+ type: "file",
6645
+ data: contentPart.data,
6646
+ mimeType: contentPart.mediaType ?? contentPart.mimeType,
6647
+ filename: contentPart.filename,
6648
+ providerOptions: contentPart.providerOptions,
6649
+ providerMetadata: contentPart.providerMetadata
6650
+ };
6651
+ const clientEstimate = getClientPartTokenEstimate(filePart);
6652
+ if (clientEstimate) {
6653
+ tokens += clientEstimate.tokens;
6654
+ cacheParts.push({
6655
+ type: "file-data-client-estimate",
6656
+ key: clientEstimate.key,
6657
+ tokens: clientEstimate.tokens
6658
+ });
6659
+ continue;
6660
+ }
6661
+ if (isImageLikeFilePart(filePart)) {
6662
+ const estimate = this.estimateImageLikeFileTokens(filePart);
6663
+ tokens += estimate.tokens;
6664
+ cacheParts.push({ type: "image-like-file-data", estimate: JSON.parse(estimate.cachePayload) });
6665
+ continue;
6666
+ }
6667
+ const byteEstimate = estimateNonImageFileTokens(this.getModelContext(), filePart);
6668
+ if (byteEstimate) {
6669
+ tokens += byteEstimate.tokens;
6670
+ cacheParts.push({ type: "file-data", estimate: JSON.parse(byteEstimate.cachePayload) });
6671
+ continue;
6672
+ }
6673
+ const descriptor = serializeNonImageFilePartForTokenCounting(filePart);
6674
+ tokens += this.countString(descriptor);
6675
+ cacheParts.push({ type: "file-data-descriptor", descriptor });
6676
+ continue;
6677
+ }
6678
+ countJsonContentPart(contentPart);
6679
+ }
6680
+ if (!hasAttachment) {
6681
+ return void 0;
6682
+ }
6683
+ return this.readOrPersistFixedPartEstimate(
6684
+ part,
6685
+ "tool-result-multimodal-content",
6686
+ JSON.stringify({ type: "content", value: cacheParts }),
6687
+ tokens
6688
+ );
6689
+ }
6571
6690
  estimateImageAssetTokens(part, asset, kind) {
6572
6691
  const modelContext = this.getModelContext();
6573
6692
  const provider = resolveProviderId(modelContext);
@@ -6826,12 +6945,17 @@ var TokenCounter = class _TokenCounter {
6826
6945
  invocation.result
6827
6946
  );
6828
6947
  if (resultForCounting !== void 0) {
6829
- const formattedResult = formatToolResultForObserver(resultForCounting);
6830
- tokens += this.readOrPersistPartEstimate(
6831
- part,
6832
- usingStoredModelOutput ? "tool-result-model-output-json" : "tool-result-json",
6833
- formattedResult
6834
- );
6948
+ const contentTokens = this.countMultimodalToolResultContent(part, resultForCounting);
6949
+ if (contentTokens !== void 0) {
6950
+ tokens += contentTokens;
6951
+ } else {
6952
+ const formattedResult = formatToolResultForObserver(resultForCounting);
6953
+ tokens += this.readOrPersistPartEstimate(
6954
+ part,
6955
+ usingStoredModelOutput ? "tool-result-model-output-json" : "tool-result-json",
6956
+ formattedResult
6957
+ );
6958
+ }
6835
6959
  if (typeof resultForCounting !== "string") {
6836
6960
  overheadDelta -= 12;
6837
6961
  }
@@ -7186,6 +7310,7 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
7186
7310
  config.observation?.bufferTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.bufferTokens,
7187
7311
  config.observation?.messageTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.messageTokens
7188
7312
  ),
7313
+ bufferOnIdle: config.observation?.bufferOnIdle ?? false,
7189
7314
  bufferActivation: asyncBufferingDisabled ? void 0 : config.observation?.bufferActivation ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.bufferActivation,
7190
7315
  activateAfterIdle: parseActivationTTL(observationActivateAfterIdle, observationActivateAfterIdlePath),
7191
7316
  activateOnProviderChange: config.observation?.activateOnProviderChange ?? config.activateOnProviderChange ?? false,
@@ -8997,7 +9122,7 @@ ${grouped}` : grouped;
8997
9122
  const bufferTokens = this.observationConfig.bufferTokens ?? 5e3;
8998
9123
  const minNewTokens = bufferTokens / 2;
8999
9124
  const newTokens = await this.tokenCounter.countMessagesAsync(candidateMessages);
9000
- if (newTokens < minNewTokens || candidateMessages.length === 0) {
9125
+ if (candidateMessages.length === 0 || !opts.skipMinimumTokenCheck && newTokens < minNewTokens) {
9001
9126
  return { buffered: false, record };
9002
9127
  }
9003
9128
  if (opts.beforeBuffer) {
@@ -9030,7 +9155,9 @@ ${grouped}` : grouped;
9030
9155
  cycleId,
9031
9156
  startedAt,
9032
9157
  writer,
9158
+ sendSignal: opts.sendSignal,
9033
9159
  requestContext,
9160
+ currentModel: opts.currentModel,
9034
9161
  observabilityContext
9035
9162
  }).run();
9036
9163
  if (isOmReproCaptureEnabled()) {
@@ -9564,7 +9691,8 @@ async function insertTemporalGapMarkers({
9564
9691
  }
9565
9692
  await sendSignal?.({
9566
9693
  id: `__temporal_gap_${crypto.randomUUID()}`,
9567
- type: "system-reminder",
9694
+ type: "reactive",
9695
+ tagName: "system-reminder",
9568
9696
  contents: getTemporalGapReminderText(gapText, timestamp),
9569
9697
  createdAt: new Date(timestamp - 1),
9570
9698
  acceptedAt: new Date(timestamp),
@@ -9716,6 +9844,7 @@ var ObservationalMemoryProcessor = class {
9716
9844
  }
9717
9845
  });
9718
9846
  this.turn.writer = writer;
9847
+ this.turn.sendSignal = args.sendSignal;
9719
9848
  this.turn.requestContext = requestContext;
9720
9849
  await this.turn.start(this.memory);
9721
9850
  if (stepNumber === 0 && this.temporalMarkers) {
@@ -9851,5 +9980,5 @@ function getObservationsAsOf(activeObservations, asOf) {
9851
9980
  }
9852
9981
 
9853
9982
  export { ModelByInputTokens, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, ObservationalMemoryProcessor, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, combineObservationGroupRanges, deriveObservationGroupProvenance, extractCurrentTask, formatMessagesForObserver, formatToolResultForObserver, getObservationsAsOf, hasCurrentTaskSection, injectAnchorIds, optimizeObservationsForContext, parseAnchorId, parseObservationGroups, parseObserverOutput, reconcileObservationGroupsFromReflection, renderObservationGroupsForReflection, resolveToolResultValue, stripEphemeralAnchorIds, stripObservationGroups, truncateStringByTokens, wrapInObservationGroup };
9854
- //# sourceMappingURL=chunk-BCWFD5J7.js.map
9855
- //# sourceMappingURL=chunk-BCWFD5J7.js.map
9983
+ //# sourceMappingURL=chunk-KMJQDCCZ.js.map
9984
+ //# sourceMappingURL=chunk-KMJQDCCZ.js.map