@mastra/server 1.66.0 → 1.67.0-alpha.1

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.
@@ -4693,7 +4693,7 @@ function splitLines(text) {
4693
4693
  return result;
4694
4694
  }
4695
4695
  //#endregion
4696
- //#region ../memory/dist/src-BNB8ko_o.js
4696
+ //#region ../memory/dist/src-BNyqEQlx.js
4697
4697
  var __defProp$3 = Object.defineProperty;
4698
4698
  var __exportAll = (all, no_symbols) => {
4699
4699
  let target = {};
@@ -22474,6 +22474,44 @@ async function applyExtractorHooks(opts) {
22474
22474
  failures: mergeExtractionFailures(failures)
22475
22475
  };
22476
22476
  }
22477
+ function isRecord$4(value) {
22478
+ return typeof value === "object" && value !== null;
22479
+ }
22480
+ /** Keep provider diagnostics in streamed/persisted markers, not whole API request/response objects. */
22481
+ function formatOmError(error) {
22482
+ const details = /* @__PURE__ */ new Set();
22483
+ const visited = /* @__PURE__ */ new Set();
22484
+ const add = (value) => {
22485
+ if (typeof value === "string" && value.trim()) details.add(value.trim().slice(0, 2e3));
22486
+ };
22487
+ function collectErrorDetails(value, depth) {
22488
+ if (depth > 5) return;
22489
+ if (!isRecord$4(value)) {
22490
+ if (value !== void 0) add(String(value));
22491
+ return;
22492
+ }
22493
+ if (visited.has(value)) return;
22494
+ visited.add(value);
22495
+ add(value.message);
22496
+ if (typeof value.statusCode === "number") add(`HTTP ${value.statusCode}`);
22497
+ if (typeof value.responseBody === "string") try {
22498
+ const body = JSON.parse(value.responseBody);
22499
+ if (isRecord$4(body)) {
22500
+ add(body.message);
22501
+ add(body.detail);
22502
+ if (isRecord$4(body.error)) add(body.error.message);
22503
+ else add(body.error);
22504
+ }
22505
+ } catch {}
22506
+ if (value.cause !== void 0) collectErrorDetails(value.cause, depth + 1);
22507
+ if (value.error !== void 0) collectErrorDetails(value.error, depth + 1);
22508
+ }
22509
+ try {
22510
+ collectErrorDetails(error, 0);
22511
+ } catch {}
22512
+ const message = [...details].join(": ") || "Unknown error";
22513
+ return message.length > 2e3 ? `${message.slice(0, 1997)}...` : message;
22514
+ }
22477
22515
  function isAbortError$1(error, abortSignal) {
22478
22516
  return abortSignal?.aborted === true || error instanceof DOMException && error.name === "AbortError" || error instanceof Error && error.name === "AbortError";
22479
22517
  }
@@ -23463,11 +23501,11 @@ function formatObserverAttachmentPlaceholder(part, counter) {
23463
23501
  const label = resolveObserverAttachmentLabel(part);
23464
23502
  return label ? `[${attachmentType} #${attachmentId}: ${label}]` : `[${attachmentType} #${attachmentId}]`;
23465
23503
  }
23466
- function isRecord$4(value) {
23504
+ function isRecord$3(value) {
23467
23505
  return !!value && typeof value === "object";
23468
23506
  }
23469
23507
  function mapToolResultBlockToAttachment(block) {
23470
- if (!isRecord$4(block) || typeof block.type !== "string") return;
23508
+ if (!isRecord$3(block) || typeof block.type !== "string") return;
23471
23509
  const mediaType = typeof block.mediaType === "string" ? block.mediaType : void 0;
23472
23510
  const filename = typeof block.filename === "string" ? block.filename : void 0;
23473
23511
  switch (block.type) {
@@ -23528,7 +23566,7 @@ function mapToolResultBlockToAttachment(block) {
23528
23566
  }
23529
23567
  }
23530
23568
  function extractToolResultAttachments(result, counter, attachmentFilter) {
23531
- if (!isRecord$4(result) || result.type !== "content" || !Array.isArray(result.value)) return {
23569
+ if (!isRecord$3(result) || result.type !== "content" || !Array.isArray(result.value)) return {
23532
23570
  resultWithoutAttachments: result,
23533
23571
  attachments: []
23534
23572
  };
@@ -23542,7 +23580,7 @@ function extractToolResultAttachments(result, counter, attachmentFilter) {
23542
23580
  if (shouldIncludeObserverAttachment(attachment, attachmentFilter)) attachments.push(toObserverInputAttachmentPart(attachment));
23543
23581
  const placeholder = formatObserverAttachmentPlaceholder(attachment, counter);
23544
23582
  return {
23545
- type: isRecord$4(block) ? block.type : void 0,
23583
+ type: isRecord$3(block) ? block.type : void 0,
23546
23584
  placeholder
23547
23585
  };
23548
23586
  });
@@ -24161,17 +24199,17 @@ const TRANSIENT_MESSAGE_SUBSTRINGS = [
24161
24199
  "connection reset",
24162
24200
  "connection closed"
24163
24201
  ];
24164
- function isRecord$3(value) {
24202
+ function isRecord$2(value) {
24165
24203
  return typeof value === "object" && value !== null;
24166
24204
  }
24167
24205
  function isAbortError$5(error) {
24168
- if (!isRecord$3(error)) return false;
24206
+ if (!isRecord$2(error)) return false;
24169
24207
  if (error.name === "AbortError") return true;
24170
24208
  if (typeof error.code === "string" && error.code === "ABORT_ERR") return true;
24171
24209
  return false;
24172
24210
  }
24173
24211
  function hasTransientMessage(value) {
24174
- if (!isRecord$3(value)) return false;
24212
+ if (!isRecord$2(value)) return false;
24175
24213
  const message = typeof value.message === "string" ? value.message.toLowerCase() : "";
24176
24214
  if (message && TRANSIENT_MESSAGE_SUBSTRINGS.some((sub) => message.includes(sub))) return true;
24177
24215
  if (typeof value.code === "string" && value.code.toUpperCase().startsWith("UND_ERR_")) return true;
@@ -24182,13 +24220,13 @@ function isRetryableHttpStatus(status) {
24182
24220
  return status >= 500 && status <= 599;
24183
24221
  }
24184
24222
  function hasRetryableHttpStatus(value) {
24185
- if (!isRecord$3(value)) return false;
24223
+ if (!isRecord$2(value)) return false;
24186
24224
  if (typeof value.statusCode === "number" && isRetryableHttpStatus(value.statusCode)) return true;
24187
24225
  if (typeof value.code === "number" && isRetryableHttpStatus(value.code)) return true;
24188
24226
  return false;
24189
24227
  }
24190
24228
  function hasIsRetryableFlag(value) {
24191
- if (!isRecord$3(value)) return false;
24229
+ if (!isRecord$2(value)) return false;
24192
24230
  return value.isRetryable === true;
24193
24231
  }
24194
24232
  /**
@@ -24206,14 +24244,14 @@ function isTransientLLMError(error) {
24206
24244
  if (isAbortError$5(error)) return false;
24207
24245
  const visited = /* @__PURE__ */ new WeakSet();
24208
24246
  function visit(candidate) {
24209
- if (isRecord$3(candidate)) {
24247
+ if (isRecord$2(candidate)) {
24210
24248
  if (visited.has(candidate)) return false;
24211
24249
  visited.add(candidate);
24212
24250
  }
24213
24251
  if (hasTransientMessage(candidate)) return true;
24214
24252
  if (hasRetryableHttpStatus(candidate)) return true;
24215
24253
  if (hasIsRetryableFlag(candidate)) return true;
24216
- if (isRecord$3(candidate)) {
24254
+ if (isRecord$2(candidate)) {
24217
24255
  if (visit(candidate.cause)) return true;
24218
24256
  if (visit(candidate.error)) return true;
24219
24257
  }
@@ -24478,7 +24516,19 @@ var ObserverRunner = class {
24478
24516
  }
24479
24517
  async callObserver(existingObservations, messagesToObserve, abortSignal, options) {
24480
24518
  const inputTokens = this.tokenCounter.countMessages(messagesToObserve);
24481
- const resolvedModel = options?.model ? { model: options.model } : this.resolveModel(inputTokens);
24519
+ const resolvedModel = (() => {
24520
+ try {
24521
+ return options?.model ? { model: options.model } : this.resolveModel(inputTokens);
24522
+ } catch (error) {
24523
+ this.mastra?.getLogger?.().error("OM observer model resolution failed", {
24524
+ diagnostic: formatOmError(error),
24525
+ inputTokens,
24526
+ threadId: messagesToObserve[0]?.threadId,
24527
+ hasRequestContext: Boolean(options?.requestContext)
24528
+ });
24529
+ throw error;
24530
+ }
24531
+ })();
24482
24532
  const activeExtractors = await resolveExtractors(filterObserverExtractors(this.observationConfig.extractors, options?.skipContinuationHints), {
24483
24533
  source: "observer",
24484
24534
  threadId: messagesToObserve[0]?.threadId,
@@ -24516,14 +24566,28 @@ var ObserverRunner = class {
24516
24566
  ...resolvedModel.routingThresholds ? { omRoutingThresholds: resolvedModel.routingThresholds } : {}
24517
24567
  },
24518
24568
  callback: (childObservabilityContext) => this.withAbortCheck(async () => {
24519
- return (await agent.stream(observerMessages, {
24520
- modelSettings: { ...this.observationConfig.modelSettings },
24521
- providerOptions: this.observationConfig.providerOptions,
24522
- ...temporaryMemory ? { memory: temporaryMemory.options } : {},
24523
- ...abortSignal ? { abortSignal } : {},
24524
- ...internalRequestContext ? { requestContext: internalRequestContext } : {},
24525
- ...childObservabilityContext
24526
- })).getFullOutput();
24569
+ try {
24570
+ return await (await agent.stream(observerMessages, {
24571
+ modelSettings: { ...this.observationConfig.modelSettings },
24572
+ providerOptions: this.observationConfig.providerOptions,
24573
+ ...temporaryMemory ? { memory: temporaryMemory.options } : {},
24574
+ ...abortSignal ? { abortSignal } : {},
24575
+ ...internalRequestContext ? { requestContext: internalRequestContext } : {},
24576
+ ...childObservabilityContext
24577
+ })).getFullOutput();
24578
+ } catch (error) {
24579
+ this.mastra?.getLogger?.().error("OM observer provider call failed", {
24580
+ diagnostic: formatOmError(error),
24581
+ model: typeof resolvedModel.model === "function" ? "(dynamic-model)" : this.extractModelRouterId(resolvedModel.model, internalRequestContext),
24582
+ inputTokens,
24583
+ threadId: messagesToObserve[0]?.threadId,
24584
+ observedMessageCount: messagesToObserve.length,
24585
+ providerOptionProviders: Object.keys(this.observationConfig.providerOptions ?? {}),
24586
+ hasRequestContext: Boolean(internalRequestContext),
24587
+ aborted: abortSignal?.aborted ?? false
24588
+ });
24589
+ throw error;
24590
+ }
24527
24591
  }, abortSignal)
24528
24592
  }), {
24529
24593
  label: "observer",
@@ -24620,7 +24684,22 @@ var ObserverRunner = class {
24620
24684
  async callMultiThreadObserver(existingObservations, messagesByThread, threadOrder, abortSignal, requestContext, priorMetadataByThread, observabilityContext, model) {
24621
24685
  if (threadOrder.length === 0) return { results: /* @__PURE__ */ new Map() };
24622
24686
  const inputTokens = Array.from(messagesByThread.values()).reduce((total, messages) => total + this.tokenCounter.countMessages(messages), 0);
24623
- const resolvedModel = model ? { model } : this.resolveModel(inputTokens);
24687
+ const resolvedModel = (() => {
24688
+ try {
24689
+ return model ? { model } : this.resolveModel(inputTokens);
24690
+ } catch (error) {
24691
+ this.mastra?.getLogger?.().error("OM multi-thread observer model resolution failed", {
24692
+ diagnostic: formatOmError(error),
24693
+ inputTokens,
24694
+ threadIds: {
24695
+ sample: threadOrder.slice(0, 10).map((threadId) => threadId.slice(0, 128)),
24696
+ total: threadOrder.length
24697
+ },
24698
+ hasRequestContext: Boolean(requestContext)
24699
+ });
24700
+ throw error;
24701
+ }
24702
+ })();
24624
24703
  const firstThreadMessages = messagesByThread.get(threadOrder[0] ?? "") ?? [];
24625
24704
  const activeExtractors = await resolveExtractors(this.observationConfig.extractors ?? [], {
24626
24705
  source: "observer",
@@ -24690,13 +24769,29 @@ var ObserverRunner = class {
24690
24769
  ...resolvedModel.routingThresholds ? { omRoutingThresholds: resolvedModel.routingThresholds } : {}
24691
24770
  },
24692
24771
  callback: (childObservabilityContext) => this.withAbortCheck(async () => {
24693
- return (await agent.stream(observerMessages, {
24694
- modelSettings: { ...this.observationConfig.modelSettings },
24695
- providerOptions: this.observationConfig.providerOptions,
24696
- ...abortSignal ? { abortSignal } : {},
24697
- ...internalRequestContext ? { requestContext: internalRequestContext } : {},
24698
- ...childObservabilityContext
24699
- })).getFullOutput();
24772
+ try {
24773
+ return await (await agent.stream(observerMessages, {
24774
+ modelSettings: { ...this.observationConfig.modelSettings },
24775
+ providerOptions: this.observationConfig.providerOptions,
24776
+ ...abortSignal ? { abortSignal } : {},
24777
+ ...internalRequestContext ? { requestContext: internalRequestContext } : {},
24778
+ ...childObservabilityContext
24779
+ })).getFullOutput();
24780
+ } catch (error) {
24781
+ this.mastra?.getLogger?.().error("OM multi-thread observer provider call failed", {
24782
+ diagnostic: formatOmError(error),
24783
+ model: typeof resolvedModel.model === "function" ? "(dynamic-model)" : this.extractModelRouterId(resolvedModel.model, internalRequestContext),
24784
+ inputTokens,
24785
+ threadIds: {
24786
+ sample: threadOrder.slice(0, 10).map((threadId) => threadId.slice(0, 128)),
24787
+ total: threadOrder.length
24788
+ },
24789
+ providerOptionProviders: Object.keys(this.observationConfig.providerOptions ?? {}),
24790
+ hasRequestContext: Boolean(internalRequestContext),
24791
+ aborted: abortSignal?.aborted ?? false
24792
+ });
24793
+ throw error;
24794
+ }
24700
24795
  }, abortSignal)
24701
24796
  }), {
24702
24797
  label: "observer-multi-thread",
@@ -27945,43 +28040,6 @@ function didProviderChange(actorModel, lastModel) {
27945
28040
  if (actorContext.provider && lastContext.provider) return actorContext.provider !== lastContext.provider;
27946
28041
  return false;
27947
28042
  }
27948
- function isRecord$2(value) {
27949
- return typeof value === "object" && value !== null;
27950
- }
27951
- /** Keep provider diagnostics in streamed/persisted markers, not whole API request/response objects. */
27952
- function formatOmError(error) {
27953
- const details = /* @__PURE__ */ new Set();
27954
- const visited = /* @__PURE__ */ new Set();
27955
- const add = (value) => {
27956
- if (typeof value === "string" && value.trim()) details.add(value.trim().slice(0, 2e3));
27957
- };
27958
- function collectErrorDetails(value, depth) {
27959
- if (depth > 5) return;
27960
- if (!isRecord$2(value)) {
27961
- if (value !== void 0) add(String(value));
27962
- return;
27963
- }
27964
- if (visited.has(value)) return;
27965
- visited.add(value);
27966
- add(value.message);
27967
- if (typeof value.statusCode === "number") add(`HTTP ${value.statusCode}`);
27968
- if (typeof value.responseBody === "string") try {
27969
- const body = JSON.parse(value.responseBody);
27970
- if (isRecord$2(body)) {
27971
- add(body.message);
27972
- if (isRecord$2(body.error)) add(body.error.message);
27973
- else add(body.error);
27974
- }
27975
- } catch {}
27976
- if (value.cause !== void 0) collectErrorDetails(value.cause, depth + 1);
27977
- if (value.error !== void 0) collectErrorDetails(value.error, depth + 1);
27978
- }
27979
- try {
27980
- collectErrorDetails(error, 0);
27981
- } catch {}
27982
- const message = [...details].join(": ") || "Unknown error";
27983
- return message.length > 2e3 ? `${message.slice(0, 1997)}...` : message;
27984
- }
27985
28043
  /**
27986
28044
  * Create a start marker for when observation begins.
27987
28045
  */
@@ -34636,7 +34694,24 @@ function isSystemReminderMessage(message) {
34636
34694
  const firstTextPart = message.content.parts.find((part) => part.type === "text");
34637
34695
  return typeof firstTextPart?.text === "string" && firstTextPart.text.startsWith("<system-reminder");
34638
34696
  }
34639
- function filterSystemReminderMessages(messages, includeSystemReminders) {
34697
+ function isRecallSignalType(type) {
34698
+ return type === "user" || type === "state" || type === "reactive" || type === "notification" || type === "user-message" || type === "system-reminder";
34699
+ }
34700
+ function getRecallSignalType(message) {
34701
+ if (!isRecord(message.content)) return void 0;
34702
+ for (const part of message.content.parts) if ((part.type === "data-signal" || part.type === "data-user-message") && isRecord(part.data) && isRecallSignalType(part.data.type)) return part.data.type;
34703
+ const metadata = message.content.metadata;
34704
+ if (message.role === "signal" && isRecord(metadata) && isRecord(metadata.signal)) {
34705
+ if (isRecallSignalType(metadata.signal.type)) return metadata.signal.type;
34706
+ }
34707
+ return isSystemReminderMessage(message) ? "system-reminder" : void 0;
34708
+ }
34709
+ function filterSystemReminderMessages(messages, includeSystemReminders, hideSignals) {
34710
+ if (hideSignals === false) return messages;
34711
+ if (hideSignals !== void 0) return messages.filter((message) => {
34712
+ const type = getRecallSignalType(message);
34713
+ return type === void 0 || hideSignals !== true && !hideSignals.includes(type);
34714
+ });
34640
34715
  if (includeSystemReminders) return messages;
34641
34716
  return messages.filter((message) => !isSystemReminderMessage(message));
34642
34717
  }
@@ -34854,7 +34929,7 @@ var Memory = class Memory extends MastraMemory {
34854
34929
  });
34855
34930
  }
34856
34931
  async recall(args) {
34857
- const { threadId, resourceId, perPage: perPageArg, page, orderBy, threadConfig, vectorSearchString, includeSystemReminders, filter, includeTotal } = args;
34932
+ const { threadId, resourceId, perPage: perPageArg, page, orderBy, threadConfig, vectorSearchString, includeSystemReminders, hideSignals, filter, includeTotal } = args;
34858
34933
  const config = this.getMergedThreadConfig(threadConfig || {});
34859
34934
  const semanticRecallEnabled = Boolean(config.semanticRecall);
34860
34935
  const span = this.createMemorySpan("recall", args.observabilityContext, {
@@ -34953,7 +35028,7 @@ var Memory = class Memory extends MastraMemory {
34953
35028
  const messages = filterSystemReminderMessages(new MessageList({
34954
35029
  threadId,
34955
35030
  resourceId
34956
- }).add(rawMessages, "memory").get.all.db(), includeSystemReminders);
35031
+ }).add(rawMessages, "memory").get.all.db(), includeSystemReminders, hideSignals);
34957
35032
  const { total, page: resultPage, perPage: resultPerPage, hasMore } = paginatedResult;
34958
35033
  const recallResult = {
34959
35034
  messages,
@@ -36264,8 +36339,16 @@ Notes:
36264
36339
  */
36265
36340
  async cloneThread(args, memoryConfig) {
36266
36341
  const memoryStore = await this.getMemoryStore();
36267
- const result = await memoryStore.cloneThread(args);
36268
36342
  const config = this.getMergedThreadConfig(memoryConfig);
36343
+ const requestedHydrate = args.options?.hydrateMessages ?? true;
36344
+ const effectiveHydrate = requestedHydrate || Boolean(this.vector && this.embedder && config.semanticRecall);
36345
+ const result = await memoryStore.cloneThread(effectiveHydrate === requestedHydrate ? args : {
36346
+ ...args,
36347
+ options: {
36348
+ ...args.options,
36349
+ hydrateMessages: effectiveHydrate
36350
+ }
36351
+ });
36269
36352
  const sourceResourceId = (await this.getThreadById({ threadId: args.sourceThreadId }))?.resourceId;
36270
36353
  if (config.workingMemory?.enabled) {
36271
36354
  const scope = config.workingMemory.scope || "resource";
@@ -46979,4 +47062,4 @@ const agentBuilderWorkflows = {
46979
47062
  //#endregion
46980
47063
  export { agentBuilderWorkflows };
46981
47064
 
46982
- //# sourceMappingURL=dist-4Qm6OSPJ.js.map
47065
+ //# sourceMappingURL=dist-B8gYiHIX.js.map