@mastra/memory 1.18.1-alpha.0 → 1.18.2-alpha.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 +60 -0
- package/dist/{chunk-LCRYFBV3.cjs → chunk-4AQHFADP.cjs} +48 -3
- package/dist/chunk-4AQHFADP.cjs.map +1 -0
- package/dist/{chunk-KGYJHNI6.js → chunk-LCALB7W6.js} +48 -3
- package/dist/chunk-LCALB7W6.js.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +29 -29
- package/dist/index.cjs +13 -13
- package/dist/index.js +4 -4
- package/dist/{observational-memory-5UNUGOE5.cjs → observational-memory-7M2T5EOV.cjs} +26 -26
- package/dist/{observational-memory-5UNUGOE5.cjs.map → observational-memory-7M2T5EOV.cjs.map} +1 -1
- package/dist/{observational-memory-7PMPJCPD.js → observational-memory-SYNXJVL4.js} +3 -3
- package/dist/{observational-memory-7PMPJCPD.js.map → observational-memory-SYNXJVL4.js.map} +1 -1
- package/dist/processors/index.cjs +24 -24
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/token-counter.d.ts.map +1 -1
- package/package.json +7 -7
- package/dist/chunk-KGYJHNI6.js.map +0 -1
- package/dist/chunk-LCRYFBV3.cjs.map +0 -1
|
@@ -5532,7 +5532,7 @@ var IMAGE_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
5532
5532
|
"heif",
|
|
5533
5533
|
"avif"
|
|
5534
5534
|
]);
|
|
5535
|
-
var TOKEN_ESTIMATE_CACHE_VERSION =
|
|
5535
|
+
var TOKEN_ESTIMATE_CACHE_VERSION = 7;
|
|
5536
5536
|
var CLIENT_TOKEN_ESTIMATE_SOURCE = "client";
|
|
5537
5537
|
var DEFAULT_IMAGE_ESTIMATOR = {
|
|
5538
5538
|
baseTokens: 85,
|
|
@@ -6043,6 +6043,42 @@ function estimateAnthropicImageTokens(dimensions, sourceStats) {
|
|
|
6043
6043
|
}
|
|
6044
6044
|
return 1600;
|
|
6045
6045
|
}
|
|
6046
|
+
function estimateFileTokensFromBytes(provider, mimeType, sizeBytes) {
|
|
6047
|
+
const normalizedMime = (mimeType ?? "").toLowerCase().split(";", 1)[0].trim();
|
|
6048
|
+
const isPdf = normalizedMime === "application/pdf";
|
|
6049
|
+
const isTextish = normalizedMime.startsWith("text/") || ["application/json", "application/xml", "application/x-yaml", "application/yaml"].includes(normalizedMime);
|
|
6050
|
+
if (isPdf) {
|
|
6051
|
+
if (provider === "google") return Math.max(258, Math.ceil(sizeBytes / 20));
|
|
6052
|
+
if (provider === "anthropic") return Math.max(1500, Math.ceil(sizeBytes / 3));
|
|
6053
|
+
return Math.max(500, Math.ceil(sizeBytes / 4));
|
|
6054
|
+
}
|
|
6055
|
+
if (isTextish) return Math.max(1, Math.ceil(sizeBytes / 4));
|
|
6056
|
+
return Math.max(1, Math.ceil(sizeBytes / 4));
|
|
6057
|
+
}
|
|
6058
|
+
function estimateNonImageFileTokens(modelContext, part) {
|
|
6059
|
+
const sourceStats = resolveImageSourceStats(getObjectValue(part, "data"));
|
|
6060
|
+
if (sourceStats.sizeBytes === void 0) {
|
|
6061
|
+
return void 0;
|
|
6062
|
+
}
|
|
6063
|
+
const provider = resolveProviderId(modelContext);
|
|
6064
|
+
const modelId = modelContext?.modelId ?? null;
|
|
6065
|
+
const mimeType = getAttachmentMimeType(part, "application/octet-stream");
|
|
6066
|
+
const filename = getAttachmentFilename(part) ?? null;
|
|
6067
|
+
const tokens = estimateFileTokensFromBytes(provider, mimeType, sourceStats.sizeBytes);
|
|
6068
|
+
return {
|
|
6069
|
+
tokens,
|
|
6070
|
+
cachePayload: JSON.stringify({
|
|
6071
|
+
kind: "non-image-file",
|
|
6072
|
+
provider: provider ?? "fallback",
|
|
6073
|
+
modelId,
|
|
6074
|
+
estimator: "bytes",
|
|
6075
|
+
source: sourceStats.source,
|
|
6076
|
+
sizeBytes: sourceStats.sizeBytes,
|
|
6077
|
+
mimeType,
|
|
6078
|
+
filename
|
|
6079
|
+
})
|
|
6080
|
+
};
|
|
6081
|
+
}
|
|
6046
6082
|
function estimateGoogleImageTokens(modelContext, part, dimensions) {
|
|
6047
6083
|
if (isGoogleGemini3Model(modelContext)) {
|
|
6048
6084
|
const mediaResolution = resolveGoogleMediaResolution(part);
|
|
@@ -6470,6 +6506,15 @@ var TokenCounter = class _TokenCounter {
|
|
|
6470
6506
|
return this.readOrPersistFixedPartEstimate(part, "image-like-file", estimate.cachePayload, estimate.tokens);
|
|
6471
6507
|
}
|
|
6472
6508
|
if (part.type === "file") {
|
|
6509
|
+
const byteEstimate = estimateNonImageFileTokens(this.getModelContext(), part);
|
|
6510
|
+
if (byteEstimate) {
|
|
6511
|
+
return this.readOrPersistFixedPartEstimate(
|
|
6512
|
+
part,
|
|
6513
|
+
"non-image-file",
|
|
6514
|
+
byteEstimate.cachePayload,
|
|
6515
|
+
byteEstimate.tokens
|
|
6516
|
+
);
|
|
6517
|
+
}
|
|
6473
6518
|
return this.readOrPersistPartEstimate(part, "file-descriptor", serializeNonImageFilePartForTokenCounting(part));
|
|
6474
6519
|
}
|
|
6475
6520
|
return void 0;
|
|
@@ -9660,5 +9705,5 @@ function getObservationsAsOf(activeObservations, asOf) {
|
|
|
9660
9705
|
}
|
|
9661
9706
|
|
|
9662
9707
|
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 };
|
|
9663
|
-
//# sourceMappingURL=chunk-
|
|
9664
|
-
//# sourceMappingURL=chunk-
|
|
9708
|
+
//# sourceMappingURL=chunk-LCALB7W6.js.map
|
|
9709
|
+
//# sourceMappingURL=chunk-LCALB7W6.js.map
|