@mastra/memory 1.20.1-alpha.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.
- package/CHANGELOG.md +16 -0
- package/dist/_types/@internal_ai-sdk-v4/dist/index.d.ts +2 -160
- package/dist/{chunk-LXU26UVM.js → chunk-KMJQDCCZ.js} +128 -12
- package/dist/{chunk-LXU26UVM.js.map → chunk-KMJQDCCZ.js.map} +1 -1
- package/dist/{chunk-R2H7SJS2.cjs → chunk-P4BYW7GY.cjs} +127 -11
- package/dist/chunk-P4BYW7GY.cjs.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +28 -28
- package/dist/docs/references/docs-agents-agent-approval.md +14 -0
- package/dist/docs/references/docs-memory-semantic-recall.md +1 -1
- package/dist/docs/references/reference-vectors-pg.md +2 -0
- package/dist/index.cjs +198 -203
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +189 -194
- package/dist/index.js.map +1 -1
- package/dist/{observational-memory-L32TPJ5J.cjs → observational-memory-CDLGZL67.cjs} +26 -26
- package/dist/{observational-memory-L32TPJ5J.cjs.map → observational-memory-CDLGZL67.cjs.map} +1 -1
- package/dist/{observational-memory-GE5MP6W7.js → observational-memory-TJFOX3YN.js} +3 -3
- package/dist/{observational-memory-GE5MP6W7.js.map → observational-memory-TJFOX3YN.js.map} +1 -1
- package/dist/processors/index.cjs +24 -24
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/temporal-markers.d.ts.map +1 -1
- package/dist/processors/observational-memory/token-counter.d.ts +1 -0
- package/dist/processors/observational-memory/token-counter.d.ts.map +1 -1
- package/dist/tools/working-memory.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/chunk-R2H7SJS2.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
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
|
+
|
|
3
19
|
## 1.20.1-alpha.0
|
|
4
20
|
|
|
5
21
|
### Patch 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,
|
|
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 {
|
|
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';
|
|
@@ -5755,7 +5755,7 @@ function ensureMessageMastraMetadata(message) {
|
|
|
5755
5755
|
return typedMessage.metadata.mastra;
|
|
5756
5756
|
}
|
|
5757
5757
|
function buildEstimateKey(kind, text) {
|
|
5758
|
-
const payloadHash = createHash("
|
|
5758
|
+
const payloadHash = createHash("sha256").update(text).digest("hex");
|
|
5759
5759
|
return `${kind}:${payloadHash}`;
|
|
5760
5760
|
}
|
|
5761
5761
|
function resolveEstimatorId() {
|
|
@@ -6298,7 +6298,7 @@ function getAttachmentFingerprint(asset) {
|
|
|
6298
6298
|
}
|
|
6299
6299
|
const base64 = encodeAttachmentBase64(asset);
|
|
6300
6300
|
if (base64) {
|
|
6301
|
-
return { contentHash: createHash("
|
|
6301
|
+
return { contentHash: createHash("sha256").update(base64).digest("hex") };
|
|
6302
6302
|
}
|
|
6303
6303
|
return {};
|
|
6304
6304
|
}
|
|
@@ -6577,6 +6577,116 @@ var TokenCounter = class _TokenCounter {
|
|
|
6577
6577
|
resolveToolResultForTokenCounting(part, invocationResult) {
|
|
6578
6578
|
return resolveToolResultValue(part, invocationResult);
|
|
6579
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
|
+
}
|
|
6580
6690
|
estimateImageAssetTokens(part, asset, kind) {
|
|
6581
6691
|
const modelContext = this.getModelContext();
|
|
6582
6692
|
const provider = resolveProviderId(modelContext);
|
|
@@ -6835,12 +6945,17 @@ var TokenCounter = class _TokenCounter {
|
|
|
6835
6945
|
invocation.result
|
|
6836
6946
|
);
|
|
6837
6947
|
if (resultForCounting !== void 0) {
|
|
6838
|
-
const
|
|
6839
|
-
|
|
6840
|
-
|
|
6841
|
-
|
|
6842
|
-
formattedResult
|
|
6843
|
-
|
|
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
|
+
}
|
|
6844
6959
|
if (typeof resultForCounting !== "string") {
|
|
6845
6960
|
overheadDelta -= 12;
|
|
6846
6961
|
}
|
|
@@ -9576,7 +9691,8 @@ async function insertTemporalGapMarkers({
|
|
|
9576
9691
|
}
|
|
9577
9692
|
await sendSignal?.({
|
|
9578
9693
|
id: `__temporal_gap_${crypto.randomUUID()}`,
|
|
9579
|
-
type: "
|
|
9694
|
+
type: "reactive",
|
|
9695
|
+
tagName: "system-reminder",
|
|
9580
9696
|
contents: getTemporalGapReminderText(gapText, timestamp),
|
|
9581
9697
|
createdAt: new Date(timestamp - 1),
|
|
9582
9698
|
acceptedAt: new Date(timestamp),
|
|
@@ -9864,5 +9980,5 @@ function getObservationsAsOf(activeObservations, asOf) {
|
|
|
9864
9980
|
}
|
|
9865
9981
|
|
|
9866
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 };
|
|
9867
|
-
//# sourceMappingURL=chunk-
|
|
9868
|
-
//# sourceMappingURL=chunk-
|
|
9983
|
+
//# sourceMappingURL=chunk-KMJQDCCZ.js.map
|
|
9984
|
+
//# sourceMappingURL=chunk-KMJQDCCZ.js.map
|