@mastra/memory 1.36.0-alpha.3 → 1.36.0-alpha.4

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.
@@ -18784,8 +18784,38 @@ const TRANSIENT_MESSAGE_SUBSTRINGS = [
18784
18784
  "request timed out",
18785
18785
  "request timeout",
18786
18786
  "connection reset",
18787
- "connection closed"
18787
+ "connection closed",
18788
+ "finished with finishreason \"other\""
18788
18789
  ];
18790
+ const INCOMPLETE_FINISH_REASONS = /* @__PURE__ */ new Set(["other", "unknown"]);
18791
+ /**
18792
+ * A model reply that ended before the model finished. Carries the AI SDK's
18793
+ * `isRetryable` flag, which `isTransientLLMError` and core's error processors
18794
+ * already recognize.
18795
+ *
18796
+ * @internal
18797
+ */
18798
+ var OmIncompleteResponseError = class extends Error {
18799
+ finishReason;
18800
+ isRetryable = true;
18801
+ constructor(label, finishReason) {
18802
+ super(`${label} response ended early (finishReason: ${finishReason})`);
18803
+ this.finishReason = finishReason;
18804
+ this.name = "OmIncompleteResponseError";
18805
+ }
18806
+ };
18807
+ /**
18808
+ * OM calls are single-step (`maxSteps: 1`). A step that ends with `other` or
18809
+ * `unknown` means the stream closed before the model finished, so its text is
18810
+ * partial. Throw a retryable error so `withRetry` re-runs the whole call
18811
+ * instead of saving it.
18812
+ *
18813
+ * @internal
18814
+ */
18815
+ function assertCompleteModelResponse(output, label) {
18816
+ if (output.finishReason && INCOMPLETE_FINISH_REASONS.has(output.finishReason)) throw new OmIncompleteResponseError(label, output.finishReason);
18817
+ return output;
18818
+ }
18789
18819
  function isRecord$5(value) {
18790
18820
  return typeof value === "object" && value !== null;
18791
18821
  }
@@ -21396,20 +21426,20 @@ function optimizeObservationsForContext(observations) {
21396
21426
  //#endregion
21397
21427
  //#region src/processors/observational-memory/temporary-memory.ts
21398
21428
  function createTemporaryOmMemoryContext(prefix) {
21399
- const options = {
21400
- thread: `${prefix}-${globalThis.crypto.randomUUID()}`,
21401
- resource: prefix,
21402
- options: {
21403
- lastMessages: 10,
21404
- generateTitle: false
21405
- }
21429
+ const memoryOptions = {
21430
+ lastMessages: 10,
21431
+ generateTitle: false
21406
21432
  };
21407
21433
  return {
21408
21434
  memory: new Memory({
21409
21435
  storage: new InMemoryStore(),
21410
- options: options.options
21436
+ options: memoryOptions
21411
21437
  }),
21412
- options
21438
+ newThread: () => ({
21439
+ thread: `${prefix}-${globalThis.crypto.randomUUID()}`,
21440
+ resource: prefix,
21441
+ options: memoryOptions
21442
+ })
21413
21443
  };
21414
21444
  }
21415
21445
  //#endregion
@@ -21554,6 +21584,7 @@ var ObserverRunner = class {
21554
21584
  id: isMultiThread ? "multi-thread-observer" : "observational-memory-observer",
21555
21585
  name: isMultiThread ? "multi-thread-observer" : "Observer",
21556
21586
  maxRetries: 0,
21587
+ errorProcessorDefaults: false,
21557
21588
  instructions: buildObserverSystemPrompt(isMultiThread, this.observationConfig.instruction, this.observationConfig.threadTitle, extractors),
21558
21589
  model: agentModel,
21559
21590
  ...memory ? { memory } : {},
@@ -21642,6 +21673,7 @@ var ObserverRunner = class {
21642
21673
  const temporaryMemory = activeExtractors.filter((extractor) => extractor.mode === "structured").length > 0 ? await createTemporaryOmMemoryContext("structured-observer") : void 0;
21643
21674
  const agent = temporaryMemory ? this.createAgent(resolvedModel.model, false, temporaryMemory.memory, activeExtractors) : this.createAgent(resolvedModel.model, false, void 0, activeExtractors);
21644
21675
  const internalRequestContext = withOmInternalThreadId(options?.requestContext, agent.id);
21676
+ let attemptMemory;
21645
21677
  const attachmentFilter = this.resolveAttachmentFilter(resolvedModel.model, options?.requestContext);
21646
21678
  const observerMessages = [buildObserverRequestMessage(existingObservations, messagesToObserve, {
21647
21679
  ...options,
@@ -21669,14 +21701,16 @@ var ObserverRunner = class {
21669
21701
  },
21670
21702
  callback: (childObservabilityContext) => this.withAbortCheck(async () => {
21671
21703
  try {
21672
- return await (await agent.stream(observerMessages, {
21704
+ attemptMemory = temporaryMemory?.newThread();
21705
+ return assertCompleteModelResponse(await (await agent.stream(observerMessages, {
21706
+ maxSteps: 1,
21673
21707
  modelSettings: { ...this.observationConfig.modelSettings },
21674
21708
  providerOptions: this.observationConfig.providerOptions,
21675
- ...temporaryMemory ? { memory: temporaryMemory.options } : {},
21709
+ ...attemptMemory ? { memory: attemptMemory } : {},
21676
21710
  ...abortSignal ? { abortSignal } : {},
21677
21711
  ...internalRequestContext ? { requestContext: internalRequestContext } : {},
21678
21712
  ...childObservabilityContext
21679
- })).getFullOutput();
21713
+ })).getFullOutput(), "OM observer");
21680
21714
  } catch (error) {
21681
21715
  this.mastra?.getLogger?.().error("OM observer provider call failed", {
21682
21716
  diagnostic: formatOmError(error),
@@ -21715,7 +21749,7 @@ var ObserverRunner = class {
21715
21749
  agent,
21716
21750
  source: "observer",
21717
21751
  extractors: activeExtractors,
21718
- memory: temporaryMemory?.options,
21752
+ memory: attemptMemory,
21719
21753
  priorExtractedValues: options?.priorExtractedValues,
21720
21754
  requestContext: internalRequestContext,
21721
21755
  observabilityContext: options?.observabilityContext,
@@ -21875,13 +21909,14 @@ var ObserverRunner = class {
21875
21909
  },
21876
21910
  callback: (childObservabilityContext) => this.withAbortCheck(async () => {
21877
21911
  try {
21878
- return await (await agent.stream(observerMessages, {
21912
+ return assertCompleteModelResponse(await (await agent.stream(observerMessages, {
21913
+ maxSteps: 1,
21879
21914
  modelSettings: { ...this.observationConfig.modelSettings },
21880
21915
  providerOptions: this.observationConfig.providerOptions,
21881
21916
  ...abortSignal ? { abortSignal } : {},
21882
21917
  ...internalRequestContext ? { requestContext: internalRequestContext } : {},
21883
21918
  ...childObservabilityContext
21884
- })).getFullOutput();
21919
+ })).getFullOutput(), "OM multi-thread observer");
21885
21920
  } catch (error) {
21886
21921
  this.mastra?.getLogger?.().error("OM multi-thread observer provider call failed", {
21887
21922
  diagnostic: formatOmError(error),
@@ -28885,6 +28920,7 @@ var ReflectorRunner = class {
28885
28920
  instructions: buildReflectorSystemPrompt(this.reflectionConfig.instruction, extractors),
28886
28921
  model: agentModel,
28887
28922
  maxRetries: 0,
28923
+ errorProcessorDefaults: false,
28888
28924
  ...memory ? { memory } : {},
28889
28925
  ...this.mastra ? { mastra: this.mastra } : {}
28890
28926
  });
@@ -28925,6 +28961,7 @@ var ReflectorRunner = class {
28925
28961
  const temporaryMemory = activeExtractors.filter((extractor) => extractor.mode === "structured").length > 0 ? await createTemporaryOmMemoryContext("structured-reflector") : void 0;
28926
28962
  const agent = temporaryMemory ? this.createAgent(resolvedModel.model, temporaryMemory.memory, activeExtractors) : this.createAgent(resolvedModel.model, void 0, activeExtractors);
28927
28963
  const internalRequestContext = withOmInternalThreadId(requestContext, agent.id);
28964
+ let attemptMemory;
28928
28965
  const targetThreshold = observationTokensThreshold ?? getMaxThreshold(this.reflectionConfig.observationTokens);
28929
28966
  let totalUsage = {
28930
28967
  inputTokens: 0,
@@ -28967,10 +29004,12 @@ var ReflectorRunner = class {
28967
29004
  callback: (childObservabilityContext) => withAbortCheck(async () => {
28968
29005
  chunkCount = 0;
28969
29006
  try {
28970
- return await (await agent.stream(prompt, {
29007
+ attemptMemory = temporaryMemory?.newThread();
29008
+ return assertCompleteModelResponse(await (await agent.stream(prompt, {
29009
+ maxSteps: 1,
28971
29010
  modelSettings: { ...this.reflectionConfig.modelSettings },
28972
29011
  providerOptions: this.reflectionConfig.providerOptions,
28973
- ...temporaryMemory ? { memory: temporaryMemory.options } : {},
29012
+ ...attemptMemory ? { memory: attemptMemory } : {},
28974
29013
  ...abortSignal ? { abortSignal } : {},
28975
29014
  ...internalRequestContext ? { requestContext: internalRequestContext } : {},
28976
29015
  ...childObservabilityContext,
@@ -28992,7 +29031,7 @@ var ReflectorRunner = class {
28992
29031
  omError(`[OM:callReflector] onError after ${chunkCount} chunks`, error);
28993
29032
  }
28994
29033
  } : {}
28995
- })).getFullOutput();
29034
+ })).getFullOutput(), "OM reflector");
28996
29035
  } catch (error) {
28997
29036
  if (abortSignal?.aborted || !isOmModelExecutionFailure(error)) throw error;
28998
29037
  throw new OmModelExecutionError("reflector-model", error);
@@ -29066,7 +29105,7 @@ var ReflectorRunner = class {
29066
29105
  agent,
29067
29106
  source: "reflector",
29068
29107
  extractors: activeExtractors,
29069
- memory: temporaryMemory?.options,
29108
+ memory: attemptMemory,
29070
29109
  priorExtractedValues,
29071
29110
  requestContext: internalRequestContext,
29072
29111
  observabilityContext,
@@ -35297,4 +35336,4 @@ Notes:
35297
35336
  //#endregion
35298
35337
  export { formatMessagesForObserver as A, OBSERVATION_CONTEXT_PROMPT_THREAD as B, SUMMARIZE_THREAD_DEFAULTS as C, buildObserverPrompt as D, OBSERVER_SYSTEM_PROMPT as E, parseAnchorId as F, StaleKnowledgeSemanticIndexError as G, getObservationContextPrompt as H, stripEphemeralAnchorIds as I, SUBCONSCIOUS_ACTIVITY_STATE_ID as J, SubconsciousRemindExtractor as K, OBSERVATIONAL_MEMORY_DEFAULTS as L, optimizeObservationsForContext as M, parseObserverOutput as N, buildObserverSystemPrompt as O, injectAnchorIds as P, Extractor as Q, OBSERVATION_CONTEXT_INSTRUCTIONS as R, deepMergeWorkingMemory as S, TokenCounter as T, Subconscious as U, OBSERVATION_CONTINUATION_HINT as V, KnowledgeSemanticIndexCoordinator as W, publishSubconsciousActivity as X, buildSubconsciousActivitySnapshot as Y, renderSubconsciousActivity as Z, reconcileObservationGroupsFromReflection as _, extractWorkingMemoryContent as a, wrapInObservationGroup as b, getObservationsAsOf as c, WORKING_MEMORY_STATE_ID as d, WORKING_MEMORY_STATE_PROCESSOR_ID as f, parseObservationGroups as g, deriveObservationGroupProvenance as h, WorkingMemory as i, hasCurrentTaskSection as j, extractCurrentTask as k, ObservationalMemoryProcessor as l, combineObservationGroupRanges as m, MessageHistory$1 as n, extractWorkingMemoryTags as o, WorkingMemoryStateProcessor as p, ModelByInputTokens as q, SemanticRecall as r, removeWorkingMemoryTags as s, Memory as t, ObservationalMemory as u, renderObservationGroupsForReflection as v, summarizeConversation as w, WorkingMemoryExtractor as x, stripObservationGroups as y, OBSERVATION_CONTEXT_PROMPT as z };
35299
35338
 
35300
- //# sourceMappingURL=src-BQOm4kZc.js.map
35339
+ //# sourceMappingURL=src-BPHEGTkT.js.map