@mastra/memory 1.38.0 → 1.39.0-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.
@@ -26517,7 +26517,8 @@ function hasGoogleGenerativeAIKey() {
26517
26517
  /**
26518
26518
  * Resolve the concrete model ID `'auto'` selects for a main model ID.
26519
26519
  *
26520
- * Order: Gemini when `GOOGLE_GENERATIVE_AI_API_KEY` is set; else the main provider's low-cost
26520
+ * Order: Gemini when Google is usable (`canUseProvider('google')`, or `GOOGLE_GENERATIVE_AI_API_KEY`
26521
+ * when no check is given); else the main provider's low-cost
26521
26522
  * model (keeping a `mastra/` gateway prefix); else the main model ID itself. Returns `undefined`
26522
26523
  * only when there is no Google key and no main model ID.
26523
26524
  */
@@ -26526,7 +26527,7 @@ function resolveAutoModelId(mainModelId, options) {
26526
26527
  ...AUTO_MODEL_BY_PROVIDER,
26527
26528
  ...options?.autoModels
26528
26529
  };
26529
- if (hasGoogleGenerativeAIKey() && models.google) return models.google;
26530
+ if ((options?.canUseProvider ? options.canUseProvider("google") : hasGoogleGenerativeAIKey()) && models.google) return models.google;
26530
26531
  if (!mainModelId) return;
26531
26532
  const prefix = mainModelId.startsWith(ROUTE_PREFIX) ? ROUTE_PREFIX : "";
26532
26533
  const provider = mainModelId.slice(prefix.length).split("/", 1)[0];
@@ -31207,6 +31208,7 @@ var ObservationalMemory = class ObservationalMemory {
31207
31208
  mastra;
31208
31209
  autoModels;
31209
31210
  resolveAutoModelHook;
31211
+ canUseProvider;
31210
31212
  memory;
31211
31213
  /**
31212
31214
  * Track message IDs observed during this instance's lifetime.
@@ -31305,6 +31307,7 @@ var ObservationalMemory = class ObservationalMemory {
31305
31307
  this.hooks = config.hooks;
31306
31308
  this.autoModels = config.autoModels;
31307
31309
  this.resolveAutoModelHook = config.resolveModel;
31310
+ this.canUseProvider = config.canUseProvider;
31308
31311
  this.hookExecution = config.hookExecution ?? "non-blocking";
31309
31312
  this.mastra = config.mastra;
31310
31313
  this.memory = config.memory;
@@ -31504,11 +31507,18 @@ var ObservationalMemory = class ObservationalMemory {
31504
31507
  model: await this.resolveAutoModel(options)
31505
31508
  };
31506
31509
  }
31510
+ autoModelOptions(requestContext) {
31511
+ const canUseProvider = this.canUseProvider;
31512
+ return {
31513
+ autoModels: this.autoModels,
31514
+ canUseProvider: canUseProvider ? (providerId) => canUseProvider(providerId, { requestContext }) : void 0
31515
+ };
31516
+ }
31507
31517
  async resolveAutoModel(options) {
31508
31518
  let mainModel = options?.currentModel?.model;
31509
31519
  if (!mainModel && options?.mainAgent) mainModel = await options.mainAgent.getModel({ requestContext: options.requestContext });
31510
31520
  const mainModelId = getModelId(mainModel);
31511
- const pick = resolveAutoModelId(mainModelId, { autoModels: this.autoModels }) ?? (mainModel ? void 0 : OBSERVATIONAL_MEMORY_DEFAULTS.observation.model);
31521
+ const pick = resolveAutoModelId(mainModelId, this.autoModelOptions(options?.requestContext)) ?? (mainModel ? void 0 : OBSERVATIONAL_MEMORY_DEFAULTS.observation.model);
31512
31522
  if (mainModel && (!pick || pick === mainModelId)) return mainModel;
31513
31523
  const modelId = pick;
31514
31524
  return this.resolveAutoModelHook ? await this.resolveAutoModelHook(modelId, { requestContext: options?.requestContext }) : modelId;
@@ -31575,7 +31585,7 @@ var ObservationalMemory = class ObservationalMemory {
31575
31585
  async getCompressionStartLevel(requestContext) {
31576
31586
  try {
31577
31587
  const reflectionModel = await this.resolveModelFunction(this.reflectionConfig.model, requestContext);
31578
- if ((reflectionModel === "auto" ? resolveAutoModelId(void 0, { autoModels: this.autoModels }) ?? "" : (await this.resolveModelContext(reflectionModel, requestContext))?.modelId ?? "").includes("gemini-2.5-flash")) return 2;
31588
+ if ((reflectionModel === "auto" ? resolveAutoModelId(void 0, this.autoModelOptions(requestContext)) ?? "" : (await this.resolveModelContext(reflectionModel, requestContext))?.modelId ?? "").includes("gemini-2.5-flash")) return 2;
31579
31589
  return 1;
31580
31590
  } catch {
31581
31591
  return 1;
@@ -35562,6 +35572,7 @@ ${workingMemory}`;
35562
35572
  shareTokenBudget: omConfig.shareTokenBudget,
35563
35573
  model: omConfig.model,
35564
35574
  autoModels: omConfig.autoModels,
35575
+ canUseProvider: omConfig.canUseProvider,
35565
35576
  resolveModel: omConfig.resolveModel,
35566
35577
  mastra: this._mastraInstance,
35567
35578
  onIndexObservations,
@@ -36717,4 +36728,4 @@ Notes:
36717
36728
  //#endregion
36718
36729
  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 };
36719
36730
 
36720
- //# sourceMappingURL=src-CTyZJ6A-.js.map
36731
+ //# sourceMappingURL=src-D9Uu93Xu.js.map