@mastra/memory 1.6.3-alpha.0 → 1.7.0
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 +28 -0
- package/dist/{chunk-3CM4XQJO.js → chunk-M7RAJAZ6.js} +11 -28
- package/dist/chunk-M7RAJAZ6.js.map +1 -0
- package/dist/{chunk-5W5463NI.cjs → chunk-SHID74TI.cjs} +11 -29
- package/dist/chunk-SHID74TI.cjs.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +25 -25
- package/dist/docs/references/docs-memory-observational-memory.md +2 -2
- package/dist/docs/references/reference-memory-observational-memory.md +4 -2
- package/dist/docs/references/reference-processors-token-limiter-processor.md +30 -4
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{observational-memory-C5LO7RBR.cjs → observational-memory-AU6MIH4Q.cjs} +17 -17
- package/dist/{observational-memory-C5LO7RBR.cjs.map → observational-memory-AU6MIH4Q.cjs.map} +1 -1
- package/dist/{observational-memory-OYK4MEUD.js → observational-memory-YRWU6CY3.js} +3 -3
- package/dist/{observational-memory-OYK4MEUD.js.map → observational-memory-YRWU6CY3.js.map} +1 -1
- package/dist/processors/index.cjs +15 -15
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/token-counter.d.ts +2 -5
- package/dist/processors/observational-memory/token-counter.d.ts.map +1 -1
- package/package.json +9 -9
- package/dist/chunk-3CM4XQJO.js.map +0 -1
- package/dist/chunk-5W5463NI.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @mastra/memory
|
|
2
2
|
|
|
3
|
+
## 1.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Observational Memory now performs local threshold checks with lower CPU and memory overhead. ([#14178](https://github.com/mastra-ai/mastra/pull/14178))
|
|
8
|
+
|
|
9
|
+
This update keeps the same multimodal thresholding behavior for image-aware inputs, so existing Observational Memory configurations continue to work without changes.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`709362d`](https://github.com/mastra-ai/mastra/commit/709362d67b80d8832729bbf9e449cad27640a5d2), [`cddf895`](https://github.com/mastra-ai/mastra/commit/cddf895532b8ee7f9fa814136ec672f53d37a9ba), [`9cede11`](https://github.com/mastra-ai/mastra/commit/9cede110abac9d93072e0521bb3c8bcafb9fdadf), [`a59f126`](https://github.com/mastra-ai/mastra/commit/a59f1269104f54726699c5cdb98c72c93606d2df), [`ed8fd75`](https://github.com/mastra-ai/mastra/commit/ed8fd75cbff03bb5e19971ddb30ab7040fc60447), [`c510833`](https://github.com/mastra-ai/mastra/commit/c5108333e8cbc19dafee5f8bfefbcb5ee935335c), [`c4c7dad`](https://github.com/mastra-ai/mastra/commit/c4c7dadfe2e4584f079f6c24bfabdb8c4981827f), [`787f3ac`](https://github.com/mastra-ai/mastra/commit/787f3ac08b3bb77413645a7ab5c447fa851708fd), [`45c3112`](https://github.com/mastra-ai/mastra/commit/45c31122666a0cc56b94727099fcb1871ed1b3f6), [`7296fcc`](https://github.com/mastra-ai/mastra/commit/7296fcc599c876a68699a71c7054a16d5aaf2337), [`00c27f9`](https://github.com/mastra-ai/mastra/commit/00c27f9080731433230a61be69c44e39a7a7b4c7), [`5e7c287`](https://github.com/mastra-ai/mastra/commit/5e7c28701f2bce795dd5c811e4c3060bf2ea2242), [`7e17d3f`](https://github.com/mastra-ai/mastra/commit/7e17d3f656fdda2aad47c4beb8c491636d70820c), [`ee19c9b`](https://github.com/mastra-ai/mastra/commit/ee19c9ba3ec3ed91feb214ad539bdc766c53bb01)]:
|
|
14
|
+
- @mastra/schema-compat@1.2.1
|
|
15
|
+
- @mastra/core@1.12.0
|
|
16
|
+
|
|
17
|
+
## 1.7.0-alpha.1
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- Observational Memory now performs local threshold checks with lower CPU and memory overhead. ([#14178](https://github.com/mastra-ai/mastra/pull/14178))
|
|
22
|
+
|
|
23
|
+
This update keeps the same multimodal thresholding behavior for image-aware inputs, so existing Observational Memory configurations continue to work without changes.
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [[`709362d`](https://github.com/mastra-ai/mastra/commit/709362d67b80d8832729bbf9e449cad27640a5d2), [`9cede11`](https://github.com/mastra-ai/mastra/commit/9cede110abac9d93072e0521bb3c8bcafb9fdadf), [`a59f126`](https://github.com/mastra-ai/mastra/commit/a59f1269104f54726699c5cdb98c72c93606d2df), [`c510833`](https://github.com/mastra-ai/mastra/commit/c5108333e8cbc19dafee5f8bfefbcb5ee935335c), [`7296fcc`](https://github.com/mastra-ai/mastra/commit/7296fcc599c876a68699a71c7054a16d5aaf2337), [`00c27f9`](https://github.com/mastra-ai/mastra/commit/00c27f9080731433230a61be69c44e39a7a7b4c7), [`ee19c9b`](https://github.com/mastra-ai/mastra/commit/ee19c9ba3ec3ed91feb214ad539bdc766c53bb01)]:
|
|
28
|
+
- @mastra/schema-compat@1.2.1-alpha.1
|
|
29
|
+
- @mastra/core@1.12.0-alpha.1
|
|
30
|
+
|
|
3
31
|
## 1.6.3-alpha.0
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
|
@@ -9,8 +9,7 @@ import xxhash from 'xxhash-wasm';
|
|
|
9
9
|
import { createHash, randomUUID } from 'crypto';
|
|
10
10
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
11
11
|
import imageSize from 'image-size';
|
|
12
|
-
import {
|
|
13
|
-
import o200k_base from 'js-tiktoken/ranks/o200k_base';
|
|
12
|
+
import { estimateTokenCount } from 'tokenx';
|
|
14
13
|
|
|
15
14
|
// src/processors/observational-memory/observational-memory.ts
|
|
16
15
|
|
|
@@ -1590,14 +1589,6 @@ function calculateProjectedMessageRemoval(chunks, bufferActivation, messageToken
|
|
|
1590
1589
|
}
|
|
1591
1590
|
return bestBoundaryMessageTokens;
|
|
1592
1591
|
}
|
|
1593
|
-
var GLOBAL_TIKTOKEN_KEY = "__mastraTiktoken";
|
|
1594
|
-
function getDefaultEncoder() {
|
|
1595
|
-
const cached = globalThis[GLOBAL_TIKTOKEN_KEY];
|
|
1596
|
-
if (cached) return cached;
|
|
1597
|
-
const encoder = new Tiktoken(o200k_base);
|
|
1598
|
-
globalThis[GLOBAL_TIKTOKEN_KEY] = encoder;
|
|
1599
|
-
return encoder;
|
|
1600
|
-
}
|
|
1601
1592
|
var IMAGE_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
1602
1593
|
"png",
|
|
1603
1594
|
"jpg",
|
|
@@ -1611,7 +1602,7 @@ var IMAGE_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
1611
1602
|
"heif",
|
|
1612
1603
|
"avif"
|
|
1613
1604
|
]);
|
|
1614
|
-
var TOKEN_ESTIMATE_CACHE_VERSION =
|
|
1605
|
+
var TOKEN_ESTIMATE_CACHE_VERSION = 6;
|
|
1615
1606
|
var DEFAULT_IMAGE_ESTIMATOR = {
|
|
1616
1607
|
baseTokens: 85,
|
|
1617
1608
|
tileTokens: 170,
|
|
@@ -1678,13 +1669,8 @@ function buildEstimateKey(kind, text) {
|
|
|
1678
1669
|
const payloadHash = createHash("sha1").update(text).digest("hex");
|
|
1679
1670
|
return `${kind}:${payloadHash}`;
|
|
1680
1671
|
}
|
|
1681
|
-
function
|
|
1682
|
-
|
|
1683
|
-
try {
|
|
1684
|
-
return `custom:${createHash("sha1").update(JSON.stringify(encoding)).digest("hex")}`;
|
|
1685
|
-
} catch {
|
|
1686
|
-
return "custom:unknown";
|
|
1687
|
-
}
|
|
1672
|
+
function resolveEstimatorId() {
|
|
1673
|
+
return "tokenx";
|
|
1688
1674
|
}
|
|
1689
1675
|
function isTokenEstimateEntry(value) {
|
|
1690
1676
|
if (!value || typeof value !== "object") return false;
|
|
@@ -2383,20 +2369,17 @@ async function fetchGoogleAttachmentTokenEstimate(modelId, part) {
|
|
|
2383
2369
|
}
|
|
2384
2370
|
}
|
|
2385
2371
|
var TokenCounter = class _TokenCounter {
|
|
2386
|
-
encoder;
|
|
2387
2372
|
cacheSource;
|
|
2388
2373
|
defaultModelContext;
|
|
2389
2374
|
modelContextStorage = new AsyncLocalStorage();
|
|
2390
2375
|
inFlightAttachmentCounts = /* @__PURE__ */ new Map();
|
|
2391
2376
|
// Per-message overhead: accounts for role tokens, message framing, and separators.
|
|
2392
|
-
//
|
|
2393
|
-
// fractional overhead from name/role encoding). 3.8 is a practical average across models.
|
|
2377
|
+
// 3.8 remains a practical average across providers for OM thresholding.
|
|
2394
2378
|
static TOKENS_PER_MESSAGE = 3.8;
|
|
2395
2379
|
// Conversation-level overhead: system prompt framing, reply priming tokens, etc.
|
|
2396
2380
|
static TOKENS_PER_CONVERSATION = 24;
|
|
2397
|
-
constructor(
|
|
2398
|
-
this.
|
|
2399
|
-
this.cacheSource = `v${TOKEN_ESTIMATE_CACHE_VERSION}:${resolveEncodingId(encoding)}`;
|
|
2381
|
+
constructor(options) {
|
|
2382
|
+
this.cacheSource = `v${TOKEN_ESTIMATE_CACHE_VERSION}:${resolveEstimatorId()}`;
|
|
2400
2383
|
this.defaultModelContext = parseModelContext(options?.model);
|
|
2401
2384
|
}
|
|
2402
2385
|
runWithModelContext(model, fn) {
|
|
@@ -2410,7 +2393,7 @@ var TokenCounter = class _TokenCounter {
|
|
|
2410
2393
|
*/
|
|
2411
2394
|
countString(text) {
|
|
2412
2395
|
if (!text) return 0;
|
|
2413
|
-
return
|
|
2396
|
+
return estimateTokenCount(text);
|
|
2414
2397
|
}
|
|
2415
2398
|
readOrPersistPartEstimate(part, kind, payload) {
|
|
2416
2399
|
const key = buildEstimateKey(kind, payload);
|
|
@@ -3306,7 +3289,7 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
3306
3289
|
),
|
|
3307
3290
|
instruction: config.reflection?.instruction
|
|
3308
3291
|
};
|
|
3309
|
-
this.tokenCounter = new TokenCounter(
|
|
3292
|
+
this.tokenCounter = new TokenCounter({
|
|
3310
3293
|
model: typeof observationModel === "string" ? observationModel : void 0
|
|
3311
3294
|
});
|
|
3312
3295
|
this.onDebugEvent = config.onDebugEvent;
|
|
@@ -6718,5 +6701,5 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
6718
6701
|
};
|
|
6719
6702
|
|
|
6720
6703
|
export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTINUATION_HINT, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, extractCurrentTask, formatMessagesForObserver, hasCurrentTaskSection, optimizeObservationsForContext, parseObserverOutput };
|
|
6721
|
-
//# sourceMappingURL=chunk-
|
|
6722
|
-
//# sourceMappingURL=chunk-
|
|
6704
|
+
//# sourceMappingURL=chunk-M7RAJAZ6.js.map
|
|
6705
|
+
//# sourceMappingURL=chunk-M7RAJAZ6.js.map
|