@mastra/memory 1.39.1-alpha.2 → 1.39.1-alpha.3
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/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +56 -56
- package/dist/docs/references/reference-vectors-mongodb.md +5 -5
- package/dist/docs/references/reference-vectors-upstash.md +8 -4
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/processors/index.cjs +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/observer-agent.d.ts.map +1 -1
- package/dist/processors/observational-memory/observer-runner.d.ts.map +1 -1
- package/dist/processors/observational-memory/processor.d.ts.map +1 -1
- package/dist/processors/observational-memory/retry.d.ts +3 -2
- package/dist/processors/observational-memory/retry.d.ts.map +1 -1
- package/dist/{src-CwOBNoJs.cjs → src-IwP0x4uF.cjs} +43 -66
- package/dist/src-IwP0x4uF.cjs.map +1 -0
- package/dist/{src-stSVckwY.js → src-kIpEG6XZ.js} +44 -67
- package/dist/src-kIpEG6XZ.js.map +1 -0
- package/package.json +6 -6
- package/dist/processors/observational-memory/context-overflow.d.ts +0 -2
- package/dist/processors/observational-memory/context-overflow.d.ts.map +0 -1
- package/dist/src-CwOBNoJs.cjs.map +0 -1
- package/dist/src-stSVckwY.js.map +0 -1
|
@@ -4,7 +4,7 @@ import * as z4 from "zod/v4";
|
|
|
4
4
|
import { any, array, boolean, custom, discriminatedUnion, enum as enum$1, instanceof as instanceof$1, json, lazy, literal, looseObject, never, null as null$1, number, object, record, safeParseAsync, string, union, unknown, z as z$1 } from "zod/v4";
|
|
5
5
|
import { toJSONSchema } from "zod/v4/core";
|
|
6
6
|
import { Agent, MessageList } from "@mastra/core/agent";
|
|
7
|
-
import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
|
|
7
|
+
import { ErrorCategory, ErrorDomain, MastraError, classifyProviderError } from "@mastra/core/error";
|
|
8
8
|
import { coreFeatures } from "@mastra/core/features";
|
|
9
9
|
import { MastraMemory, getMemoryTokenBoundary, getThreadOMMetadata, isAfterMemoryTokenBoundary, isThreadTitlePinned, loadMessageHistory, normalizeMessageHistoryConfig, parseMemoryRequestContext, setThreadOMMetadata } from "@mastra/core/memory";
|
|
10
10
|
import { EntityType, SpanType, createObservabilityContext, getOrCreateSpan } from "@mastra/core/observability";
|
|
@@ -27105,15 +27105,16 @@ var OmIncompleteResponseError = class extends Error {
|
|
|
27105
27105
|
}
|
|
27106
27106
|
};
|
|
27107
27107
|
/**
|
|
27108
|
-
* A model reply that finished but
|
|
27108
|
+
* A model reply that finished but carries nothing usable: no text, only whitespace,
|
|
27109
|
+
* or text with no recognised Observer sections (e.g. a refusal).
|
|
27109
27110
|
* Retryable, so an empty reply is retried like a transport error.
|
|
27110
27111
|
*
|
|
27111
27112
|
* @internal
|
|
27112
27113
|
*/
|
|
27113
27114
|
var OmEmptyResponseError = class extends Error {
|
|
27114
27115
|
isRetryable = true;
|
|
27115
|
-
constructor(label) {
|
|
27116
|
-
super(`${label} returned
|
|
27116
|
+
constructor(label, what = "empty output") {
|
|
27117
|
+
super(`${label} returned ${what}`);
|
|
27117
27118
|
this.name = "OmEmptyResponseError";
|
|
27118
27119
|
}
|
|
27119
27120
|
};
|
|
@@ -29644,13 +29645,15 @@ function parseMemorySectionXml(content) {
|
|
|
29644
29645
|
suggestedResponse: "",
|
|
29645
29646
|
threadTitle: ""
|
|
29646
29647
|
};
|
|
29647
|
-
const observationsMatches = [...content.matchAll(/^[ \t]*<observations>([\s\S]*?)^[ \t]*<\/observations
|
|
29648
|
-
if (observationsMatches.length > 0) result.observations = observationsMatches.map((m) => m[1]?.trim() ?? "").filter(Boolean).join("\n");
|
|
29648
|
+
const observationsMatches = [...content.matchAll(/^[ \t]*<observations>(?:([^\r\n]*?)<\/observations>[ \t]*$|([\s\S]*?)^[ \t]*<\/observations>)/gim)];
|
|
29649
|
+
if (observationsMatches.length > 0) result.observations = observationsMatches.map((m) => (m[1] ?? m[2])?.trim() ?? "").filter(Boolean).join("\n");
|
|
29649
29650
|
else result.observations = extractListItemsOnly(content);
|
|
29650
|
-
const currentTaskMatch = content.match(/^[ \t]*<current-task>([\s\S]*?)^[ \t]*<\/current-task
|
|
29651
|
-
|
|
29652
|
-
|
|
29653
|
-
|
|
29651
|
+
const currentTaskMatch = content.match(/^[ \t]*<current-task>(?:([^\r\n]*?)<\/current-task>[ \t]*$|([\s\S]*?)^[ \t]*<\/current-task>)/im);
|
|
29652
|
+
const currentTask = currentTaskMatch?.[1] ?? currentTaskMatch?.[2];
|
|
29653
|
+
if (currentTask) result.currentTask = currentTask.trim();
|
|
29654
|
+
const suggestedResponseMatch = content.match(/^[ \t]*<suggested-response>(?:([^\r\n]*?)<\/suggested-response>[ \t]*$|([\s\S]*?)^[ \t]*<\/suggested-response>)/im);
|
|
29655
|
+
const suggestedResponse = suggestedResponseMatch?.[1] ?? suggestedResponseMatch?.[2];
|
|
29656
|
+
if (suggestedResponse) result.suggestedResponse = suggestedResponse.trim();
|
|
29654
29657
|
const threadTitleMatch = content.match(/^[ \t]*<thread-title>([\s\S]*?)<\/thread-title>/im);
|
|
29655
29658
|
if (threadTitleMatch?.[1]) result.threadTitle = threadTitleMatch[1].trim();
|
|
29656
29659
|
return result;
|
|
@@ -30223,7 +30226,7 @@ var ObserverRunner = class {
|
|
|
30223
30226
|
callback: (childObservabilityContext) => this.withAbortCheck(async () => {
|
|
30224
30227
|
try {
|
|
30225
30228
|
attemptMemory = temporaryMemory?.newThread();
|
|
30226
|
-
return assertNonEmptyObserverOutput(assertCompleteModelResponse(await (await agent.stream(observerMessages, {
|
|
30229
|
+
return assertRecognizedObserverOutput(assertNonEmptyObserverOutput(assertCompleteModelResponse(await (await agent.stream(observerMessages, {
|
|
30227
30230
|
maxSteps: 1,
|
|
30228
30231
|
modelSettings: { ...this.observationConfig.modelSettings },
|
|
30229
30232
|
providerOptions: this.observationConfig.providerOptions,
|
|
@@ -30232,7 +30235,7 @@ var ObserverRunner = class {
|
|
|
30232
30235
|
onChunk: onActivity,
|
|
30233
30236
|
...internalRequestContext ? { requestContext: internalRequestContext } : {},
|
|
30234
30237
|
...childObservabilityContext
|
|
30235
|
-
})).getFullOutput(), "OM observer"), "OM observer");
|
|
30238
|
+
})).getFullOutput(), "OM observer"), "OM observer"), "OM observer", (text) => hasSingleThreadObserverContent(text, activeExtractors));
|
|
30236
30239
|
} catch (error) {
|
|
30237
30240
|
this.mastra?.getLogger?.().error("OM observer provider call failed", {
|
|
30238
30241
|
diagnostic: formatOmError(error),
|
|
@@ -30335,7 +30338,7 @@ var ObserverRunner = class {
|
|
|
30335
30338
|
for (const threadId of allThreadOrder) {
|
|
30336
30339
|
const threadResult = output.results.get(threadId);
|
|
30337
30340
|
if (!threadResult) {
|
|
30338
|
-
output.results.set(threadId, { observations: "" });
|
|
30341
|
+
if (!messagesByThread.has(threadId)) output.results.set(threadId, { observations: "" });
|
|
30339
30342
|
continue;
|
|
30340
30343
|
}
|
|
30341
30344
|
threadResult.observations = await applyTextTransform(this.hooks, "afterObservation", threadResult.observations, contextFor(threadId));
|
|
@@ -30437,7 +30440,7 @@ var ObserverRunner = class {
|
|
|
30437
30440
|
},
|
|
30438
30441
|
callback: (childObservabilityContext) => this.withAbortCheck(async () => {
|
|
30439
30442
|
try {
|
|
30440
|
-
return assertNonEmptyObserverOutput(assertCompleteModelResponse(await (await agent.stream(observerMessages, {
|
|
30443
|
+
return assertRecognizedObserverOutput(assertNonEmptyObserverOutput(assertCompleteModelResponse(await (await agent.stream(observerMessages, {
|
|
30441
30444
|
maxSteps: 1,
|
|
30442
30445
|
modelSettings: { ...this.observationConfig.modelSettings },
|
|
30443
30446
|
providerOptions: this.observationConfig.providerOptions,
|
|
@@ -30445,7 +30448,7 @@ var ObserverRunner = class {
|
|
|
30445
30448
|
onChunk: onActivity,
|
|
30446
30449
|
...internalRequestContext ? { requestContext: internalRequestContext } : {},
|
|
30447
30450
|
...childObservabilityContext
|
|
30448
|
-
})).getFullOutput(), "OM multi-thread observer"), "OM multi-thread observer");
|
|
30451
|
+
})).getFullOutput(), "OM multi-thread observer"), "OM multi-thread observer"), "OM multi-thread observer", (text) => hasMultiThreadObserverContent(text, activeExtractors, threadOrder));
|
|
30449
30452
|
} catch (error) {
|
|
30450
30453
|
this.mastra?.getLogger?.().error("OM multi-thread observer provider call failed", {
|
|
30451
30454
|
diagnostic: formatOmError(error),
|
|
@@ -30522,8 +30525,7 @@ var ObserverRunner = class {
|
|
|
30522
30525
|
extractors: activeExtractors
|
|
30523
30526
|
});
|
|
30524
30527
|
}
|
|
30525
|
-
for (const threadId of
|
|
30526
|
-
for (const msgs of messagesByThread.values()) for (const msg of msgs) this.observedMessageIds.add(msg.id);
|
|
30528
|
+
for (const threadId of results.keys()) for (const msg of messagesByThread.get(threadId) ?? []) this.observedMessageIds.add(msg.id);
|
|
30527
30529
|
const usage = result.totalUsage ?? result.usage;
|
|
30528
30530
|
return {
|
|
30529
30531
|
results,
|
|
@@ -30546,6 +30548,29 @@ function assertNonEmptyObserverOutput(output, label) {
|
|
|
30546
30548
|
if (!output.text?.trim()) throw new OmEmptyResponseError(label);
|
|
30547
30549
|
return output;
|
|
30548
30550
|
}
|
|
30551
|
+
/**
|
|
30552
|
+
* A reply with text but nothing the parser recognises (e.g. a refusal like
|
|
30553
|
+
* "I can't help with that") parses to zero observations. Committing it would drop
|
|
30554
|
+
* the observed messages the same way an empty reply does, so it gets the same retry.
|
|
30555
|
+
* Degenerate replies pass through; the degenerate retry handles them.
|
|
30556
|
+
*/
|
|
30557
|
+
function assertRecognizedObserverOutput(output, label, isRecognized) {
|
|
30558
|
+
if (!isRecognized(output.text)) throw new OmEmptyResponseError(label, "no observations");
|
|
30559
|
+
return output;
|
|
30560
|
+
}
|
|
30561
|
+
function hasSingleThreadObserverContent(text, extractors) {
|
|
30562
|
+
if (/^[ \t]*<observations>/im.test(text)) return true;
|
|
30563
|
+
const parsed = parseObserverOutput(text, extractors);
|
|
30564
|
+
return Boolean(parsed.degenerate || parsed.observations || parsed.currentTask || parsed.suggestedContinuation || parsed.threadTitle || Object.keys(parsed.extractedValues ?? {}).length || parsed.extractionFailures?.length);
|
|
30565
|
+
}
|
|
30566
|
+
/**
|
|
30567
|
+
* Multi-thread replies carry every recognised section inside `<thread>` blocks, so a reply
|
|
30568
|
+
* with no block for any requested thread has nothing to record.
|
|
30569
|
+
*/
|
|
30570
|
+
function hasMultiThreadObserverContent(text, extractors, threadOrder) {
|
|
30571
|
+
const parsed = parseMultiThreadObserverOutput(text, extractors);
|
|
30572
|
+
return Boolean(parsed.degenerate || threadOrder.some((threadId) => parsed.threads.has(threadId)));
|
|
30573
|
+
}
|
|
30549
30574
|
// src/processors/observational-memory/measure-image-buffer.ts
|
|
30550
30575
|
/**
|
|
30551
30576
|
* Synchronous image dimension lookup for in-memory image buffers.
|
|
@@ -42080,54 +42105,6 @@ ${formattedMessages}
|
|
|
42080
42105
|
});
|
|
42081
42106
|
}
|
|
42082
42107
|
};
|
|
42083
|
-
// src/processors/observational-memory/context-overflow.ts
|
|
42084
|
-
/**
|
|
42085
|
-
* Detects provider errors that reject a request for exceeding the model's context window.
|
|
42086
|
-
*
|
|
42087
|
-
* Providers report this with different codes and wording, so this matches the known shapes
|
|
42088
|
-
* (OpenAI and OpenAI-compatible APIs, Anthropic, Google, Bedrock, xAI, Mistral, local servers)
|
|
42089
|
-
* against the error's message, code, response body and causes.
|
|
42090
|
-
*/
|
|
42091
|
-
const CONTEXT_OVERFLOW_PATTERNS = [
|
|
42092
|
-
/context[_ ]length[_ ]exceeded/i,
|
|
42093
|
-
/maximum context length/i,
|
|
42094
|
-
/maximum prompt length/i,
|
|
42095
|
-
/prompt is too long/i,
|
|
42096
|
-
/input is too long/i,
|
|
42097
|
-
/exceed\w*\b[^.]{0,40}\bcontext (?:window|length|limit|size)/i,
|
|
42098
|
-
/input token count[^.]{0,40}exceeds the maximum/i,
|
|
42099
|
-
/reduce the length of the (?:messages|prompt|input)/i
|
|
42100
|
-
];
|
|
42101
|
-
const MAX_CAUSE_DEPTH = 4;
|
|
42102
|
-
function collectErrorText(error, depth = 0) {
|
|
42103
|
-
if (depth > MAX_CAUSE_DEPTH || error == null) return [];
|
|
42104
|
-
if (typeof error === "string") return [error];
|
|
42105
|
-
if (typeof error !== "object") return [];
|
|
42106
|
-
const record = error;
|
|
42107
|
-
const texts = [];
|
|
42108
|
-
for (const key of [
|
|
42109
|
-
"message",
|
|
42110
|
-
"code",
|
|
42111
|
-
"type",
|
|
42112
|
-
"responseBody"
|
|
42113
|
-
]) {
|
|
42114
|
-
const value = record[key];
|
|
42115
|
-
if (typeof value === "string") texts.push(value);
|
|
42116
|
-
}
|
|
42117
|
-
if (record.data && typeof record.data === "object") texts.push(...collectErrorText(record.data.error ?? record.data, depth + 1));
|
|
42118
|
-
if (record.error && typeof record.error === "object") texts.push(...collectErrorText(record.error, depth + 1));
|
|
42119
|
-
texts.push(...collectErrorText(record.cause, depth + 1));
|
|
42120
|
-
return texts;
|
|
42121
|
-
}
|
|
42122
|
-
function isRateLimited(error, depth = 0) {
|
|
42123
|
-
if (depth > MAX_CAUSE_DEPTH || error == null || typeof error !== "object") return false;
|
|
42124
|
-
const record = error;
|
|
42125
|
-
return record.statusCode === 429 || isRateLimited(record.cause, depth + 1);
|
|
42126
|
-
}
|
|
42127
|
-
function isContextOverflowError(error) {
|
|
42128
|
-
if (isRateLimited(error)) return false;
|
|
42129
|
-
return collectErrorText(error).some((text) => CONTEXT_OVERFLOW_PATTERNS.some((pattern) => pattern.test(text)));
|
|
42130
|
-
}
|
|
42131
42108
|
// src/processors/observational-memory/temporal-markers.ts
|
|
42132
42109
|
const TEMPORAL_GAP_REMINDER_TYPE = "temporal-gap";
|
|
42133
42110
|
function getTemporalGapReminderText(gapText, timestamp) {
|
|
@@ -42529,7 +42506,7 @@ var ObservationalMemoryProcessor = class {
|
|
|
42529
42506
|
if (!this.engine.getObservationConfig().observeOnContextOverflow) return;
|
|
42530
42507
|
if (state[GATEWAY_STATE_KEY]) return;
|
|
42531
42508
|
if (state[CONTEXT_OVERFLOW_STEP_KEY] === stepNumber) return;
|
|
42532
|
-
if (
|
|
42509
|
+
if (classifyProviderError(error) !== "context_overflow") return;
|
|
42533
42510
|
const context = this.engine.getThreadContext(requestContext, messageList);
|
|
42534
42511
|
if (!context) return;
|
|
42535
42512
|
if (parseMemoryRequestContext(requestContext)?.memoryConfig?.readOnly) return;
|
|
@@ -45341,4 +45318,4 @@ Notes:
|
|
|
45341
45318
|
};
|
|
45342
45319
|
export { renderSubconsciousActivity as $, buildObserverSystemPrompt as A, OBSERVATION_CONTEXT_INSTRUCTIONS as B, WorkingMemoryExtractor as C, TokenCounter as D, summarizeConversation as E, parseObserverOutput as F, Subconscious as G, OBSERVATION_CONTEXT_PROMPT_THREAD as H, injectAnchorIds as I, SubconsciousRemindExtractor as J, KnowledgeSemanticIndexCoordinator as K, parseAnchorId as L, formatMessagesForObserver as M, hasCurrentTaskSection as N, OBSERVER_SYSTEM_PROMPT as O, optimizeObservationsForContext as P, publishSubconsciousActivity as Q, stripEphemeralAnchorIds as R, wrapInObservationGroup as S, SUMMARIZE_THREAD_DEFAULTS as T, OBSERVATION_CONTINUATION_HINT as U, OBSERVATION_CONTEXT_PROMPT as V, getObservationContextPrompt as W, SUBCONSCIOUS_ACTIVITY_STATE_ID as X, ModelByInputTokens as Y, buildSubconsciousActivitySnapshot as Z, deriveObservationGroupProvenance as _, extractWorkingMemoryContent as a, renderObservationGroupsForReflection as b, getObservationsAsOf as c, AUTO_MODEL_BY_PROVIDER as d, Extractor as et, resolveAutoModelId as f, combineObservationGroupRanges as g, WorkingMemoryStateProcessor as h, WorkingMemory as i, extractCurrentTask as j, buildObserverPrompt as k, ObservationalMemoryProcessor as l, WORKING_MEMORY_STATE_PROCESSOR_ID as m, MessageHistory$1 as n, extractWorkingMemoryTags as o, WORKING_MEMORY_STATE_ID as p, StaleKnowledgeSemanticIndexError as q, SemanticRecall as r, removeWorkingMemoryTags as s, Memory as t, ObservationalMemory as u, parseObservationGroups as v, deepMergeWorkingMemory as w, stripObservationGroups as x, reconcileObservationGroupsFromReflection as y, OBSERVATIONAL_MEMORY_DEFAULTS as z };
|
|
45343
45320
|
|
|
45344
|
-
//# sourceMappingURL=src-
|
|
45321
|
+
//# sourceMappingURL=src-kIpEG6XZ.js.map
|