@mastra/server 1.66.0 → 1.66.1-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.
@@ -4694,7 +4694,7 @@ function splitLines(text) {
4694
4694
  return result;
4695
4695
  }
4696
4696
  //#endregion
4697
- //#region ../memory/dist/src-BNB8ko_o.js
4697
+ //#region ../memory/dist/src-C4x5Wx9t.js
4698
4698
  var __defProp$3 = Object.defineProperty;
4699
4699
  var __exportAll = (all, no_symbols) => {
4700
4700
  let target = {};
@@ -22475,6 +22475,44 @@ async function applyExtractorHooks(opts) {
22475
22475
  failures: mergeExtractionFailures(failures)
22476
22476
  };
22477
22477
  }
22478
+ function isRecord$4(value) {
22479
+ return typeof value === "object" && value !== null;
22480
+ }
22481
+ /** Keep provider diagnostics in streamed/persisted markers, not whole API request/response objects. */
22482
+ function formatOmError(error) {
22483
+ const details = /* @__PURE__ */ new Set();
22484
+ const visited = /* @__PURE__ */ new Set();
22485
+ const add = (value) => {
22486
+ if (typeof value === "string" && value.trim()) details.add(value.trim().slice(0, 2e3));
22487
+ };
22488
+ function collectErrorDetails(value, depth) {
22489
+ if (depth > 5) return;
22490
+ if (!isRecord$4(value)) {
22491
+ if (value !== void 0) add(String(value));
22492
+ return;
22493
+ }
22494
+ if (visited.has(value)) return;
22495
+ visited.add(value);
22496
+ add(value.message);
22497
+ if (typeof value.statusCode === "number") add(`HTTP ${value.statusCode}`);
22498
+ if (typeof value.responseBody === "string") try {
22499
+ const body = JSON.parse(value.responseBody);
22500
+ if (isRecord$4(body)) {
22501
+ add(body.message);
22502
+ add(body.detail);
22503
+ if (isRecord$4(body.error)) add(body.error.message);
22504
+ else add(body.error);
22505
+ }
22506
+ } catch {}
22507
+ if (value.cause !== void 0) collectErrorDetails(value.cause, depth + 1);
22508
+ if (value.error !== void 0) collectErrorDetails(value.error, depth + 1);
22509
+ }
22510
+ try {
22511
+ collectErrorDetails(error, 0);
22512
+ } catch {}
22513
+ const message = [...details].join(": ") || "Unknown error";
22514
+ return message.length > 2e3 ? `${message.slice(0, 1997)}...` : message;
22515
+ }
22478
22516
  function isAbortError$1(error, abortSignal) {
22479
22517
  return abortSignal?.aborted === true || error instanceof DOMException && error.name === "AbortError" || error instanceof Error && error.name === "AbortError";
22480
22518
  }
@@ -23464,11 +23502,11 @@ function formatObserverAttachmentPlaceholder(part, counter) {
23464
23502
  const label = resolveObserverAttachmentLabel(part);
23465
23503
  return label ? `[${attachmentType} #${attachmentId}: ${label}]` : `[${attachmentType} #${attachmentId}]`;
23466
23504
  }
23467
- function isRecord$4(value) {
23505
+ function isRecord$3(value) {
23468
23506
  return !!value && typeof value === "object";
23469
23507
  }
23470
23508
  function mapToolResultBlockToAttachment(block) {
23471
- if (!isRecord$4(block) || typeof block.type !== "string") return;
23509
+ if (!isRecord$3(block) || typeof block.type !== "string") return;
23472
23510
  const mediaType = typeof block.mediaType === "string" ? block.mediaType : void 0;
23473
23511
  const filename = typeof block.filename === "string" ? block.filename : void 0;
23474
23512
  switch (block.type) {
@@ -23529,7 +23567,7 @@ function mapToolResultBlockToAttachment(block) {
23529
23567
  }
23530
23568
  }
23531
23569
  function extractToolResultAttachments(result, counter, attachmentFilter) {
23532
- if (!isRecord$4(result) || result.type !== "content" || !Array.isArray(result.value)) return {
23570
+ if (!isRecord$3(result) || result.type !== "content" || !Array.isArray(result.value)) return {
23533
23571
  resultWithoutAttachments: result,
23534
23572
  attachments: []
23535
23573
  };
@@ -23543,7 +23581,7 @@ function extractToolResultAttachments(result, counter, attachmentFilter) {
23543
23581
  if (shouldIncludeObserverAttachment(attachment, attachmentFilter)) attachments.push(toObserverInputAttachmentPart(attachment));
23544
23582
  const placeholder = formatObserverAttachmentPlaceholder(attachment, counter);
23545
23583
  return {
23546
- type: isRecord$4(block) ? block.type : void 0,
23584
+ type: isRecord$3(block) ? block.type : void 0,
23547
23585
  placeholder
23548
23586
  };
23549
23587
  });
@@ -24162,17 +24200,17 @@ const TRANSIENT_MESSAGE_SUBSTRINGS = [
24162
24200
  "connection reset",
24163
24201
  "connection closed"
24164
24202
  ];
24165
- function isRecord$3(value) {
24203
+ function isRecord$2(value) {
24166
24204
  return typeof value === "object" && value !== null;
24167
24205
  }
24168
24206
  function isAbortError$5(error) {
24169
- if (!isRecord$3(error)) return false;
24207
+ if (!isRecord$2(error)) return false;
24170
24208
  if (error.name === "AbortError") return true;
24171
24209
  if (typeof error.code === "string" && error.code === "ABORT_ERR") return true;
24172
24210
  return false;
24173
24211
  }
24174
24212
  function hasTransientMessage(value) {
24175
- if (!isRecord$3(value)) return false;
24213
+ if (!isRecord$2(value)) return false;
24176
24214
  const message = typeof value.message === "string" ? value.message.toLowerCase() : "";
24177
24215
  if (message && TRANSIENT_MESSAGE_SUBSTRINGS.some((sub) => message.includes(sub))) return true;
24178
24216
  if (typeof value.code === "string" && value.code.toUpperCase().startsWith("UND_ERR_")) return true;
@@ -24183,13 +24221,13 @@ function isRetryableHttpStatus(status) {
24183
24221
  return status >= 500 && status <= 599;
24184
24222
  }
24185
24223
  function hasRetryableHttpStatus(value) {
24186
- if (!isRecord$3(value)) return false;
24224
+ if (!isRecord$2(value)) return false;
24187
24225
  if (typeof value.statusCode === "number" && isRetryableHttpStatus(value.statusCode)) return true;
24188
24226
  if (typeof value.code === "number" && isRetryableHttpStatus(value.code)) return true;
24189
24227
  return false;
24190
24228
  }
24191
24229
  function hasIsRetryableFlag(value) {
24192
- if (!isRecord$3(value)) return false;
24230
+ if (!isRecord$2(value)) return false;
24193
24231
  return value.isRetryable === true;
24194
24232
  }
24195
24233
  /**
@@ -24207,14 +24245,14 @@ function isTransientLLMError(error) {
24207
24245
  if (isAbortError$5(error)) return false;
24208
24246
  const visited = /* @__PURE__ */ new WeakSet();
24209
24247
  function visit(candidate) {
24210
- if (isRecord$3(candidate)) {
24248
+ if (isRecord$2(candidate)) {
24211
24249
  if (visited.has(candidate)) return false;
24212
24250
  visited.add(candidate);
24213
24251
  }
24214
24252
  if (hasTransientMessage(candidate)) return true;
24215
24253
  if (hasRetryableHttpStatus(candidate)) return true;
24216
24254
  if (hasIsRetryableFlag(candidate)) return true;
24217
- if (isRecord$3(candidate)) {
24255
+ if (isRecord$2(candidate)) {
24218
24256
  if (visit(candidate.cause)) return true;
24219
24257
  if (visit(candidate.error)) return true;
24220
24258
  }
@@ -24479,7 +24517,19 @@ var ObserverRunner = class {
24479
24517
  }
24480
24518
  async callObserver(existingObservations, messagesToObserve, abortSignal, options) {
24481
24519
  const inputTokens = this.tokenCounter.countMessages(messagesToObserve);
24482
- const resolvedModel = options?.model ? { model: options.model } : this.resolveModel(inputTokens);
24520
+ const resolvedModel = (() => {
24521
+ try {
24522
+ return options?.model ? { model: options.model } : this.resolveModel(inputTokens);
24523
+ } catch (error) {
24524
+ this.mastra?.getLogger?.().error("OM observer model resolution failed", {
24525
+ diagnostic: formatOmError(error),
24526
+ inputTokens,
24527
+ threadId: messagesToObserve[0]?.threadId,
24528
+ hasRequestContext: Boolean(options?.requestContext)
24529
+ });
24530
+ throw error;
24531
+ }
24532
+ })();
24483
24533
  const activeExtractors = await resolveExtractors(filterObserverExtractors(this.observationConfig.extractors, options?.skipContinuationHints), {
24484
24534
  source: "observer",
24485
24535
  threadId: messagesToObserve[0]?.threadId,
@@ -24517,14 +24567,28 @@ var ObserverRunner = class {
24517
24567
  ...resolvedModel.routingThresholds ? { omRoutingThresholds: resolvedModel.routingThresholds } : {}
24518
24568
  },
24519
24569
  callback: (childObservabilityContext) => this.withAbortCheck(async () => {
24520
- return (await agent.stream(observerMessages, {
24521
- modelSettings: { ...this.observationConfig.modelSettings },
24522
- providerOptions: this.observationConfig.providerOptions,
24523
- ...temporaryMemory ? { memory: temporaryMemory.options } : {},
24524
- ...abortSignal ? { abortSignal } : {},
24525
- ...internalRequestContext ? { requestContext: internalRequestContext } : {},
24526
- ...childObservabilityContext
24527
- })).getFullOutput();
24570
+ try {
24571
+ return await (await agent.stream(observerMessages, {
24572
+ modelSettings: { ...this.observationConfig.modelSettings },
24573
+ providerOptions: this.observationConfig.providerOptions,
24574
+ ...temporaryMemory ? { memory: temporaryMemory.options } : {},
24575
+ ...abortSignal ? { abortSignal } : {},
24576
+ ...internalRequestContext ? { requestContext: internalRequestContext } : {},
24577
+ ...childObservabilityContext
24578
+ })).getFullOutput();
24579
+ } catch (error) {
24580
+ this.mastra?.getLogger?.().error("OM observer provider call failed", {
24581
+ diagnostic: formatOmError(error),
24582
+ model: typeof resolvedModel.model === "function" ? "(dynamic-model)" : this.extractModelRouterId(resolvedModel.model, internalRequestContext),
24583
+ inputTokens,
24584
+ threadId: messagesToObserve[0]?.threadId,
24585
+ observedMessageCount: messagesToObserve.length,
24586
+ providerOptionProviders: Object.keys(this.observationConfig.providerOptions ?? {}),
24587
+ hasRequestContext: Boolean(internalRequestContext),
24588
+ aborted: abortSignal?.aborted ?? false
24589
+ });
24590
+ throw error;
24591
+ }
24528
24592
  }, abortSignal)
24529
24593
  }), {
24530
24594
  label: "observer",
@@ -24621,7 +24685,22 @@ var ObserverRunner = class {
24621
24685
  async callMultiThreadObserver(existingObservations, messagesByThread, threadOrder, abortSignal, requestContext, priorMetadataByThread, observabilityContext, model) {
24622
24686
  if (threadOrder.length === 0) return { results: /* @__PURE__ */ new Map() };
24623
24687
  const inputTokens = Array.from(messagesByThread.values()).reduce((total, messages) => total + this.tokenCounter.countMessages(messages), 0);
24624
- const resolvedModel = model ? { model } : this.resolveModel(inputTokens);
24688
+ const resolvedModel = (() => {
24689
+ try {
24690
+ return model ? { model } : this.resolveModel(inputTokens);
24691
+ } catch (error) {
24692
+ this.mastra?.getLogger?.().error("OM multi-thread observer model resolution failed", {
24693
+ diagnostic: formatOmError(error),
24694
+ inputTokens,
24695
+ threadIds: {
24696
+ sample: threadOrder.slice(0, 10).map((threadId) => threadId.slice(0, 128)),
24697
+ total: threadOrder.length
24698
+ },
24699
+ hasRequestContext: Boolean(requestContext)
24700
+ });
24701
+ throw error;
24702
+ }
24703
+ })();
24625
24704
  const firstThreadMessages = messagesByThread.get(threadOrder[0] ?? "") ?? [];
24626
24705
  const activeExtractors = await resolveExtractors(this.observationConfig.extractors ?? [], {
24627
24706
  source: "observer",
@@ -24691,13 +24770,29 @@ var ObserverRunner = class {
24691
24770
  ...resolvedModel.routingThresholds ? { omRoutingThresholds: resolvedModel.routingThresholds } : {}
24692
24771
  },
24693
24772
  callback: (childObservabilityContext) => this.withAbortCheck(async () => {
24694
- return (await agent.stream(observerMessages, {
24695
- modelSettings: { ...this.observationConfig.modelSettings },
24696
- providerOptions: this.observationConfig.providerOptions,
24697
- ...abortSignal ? { abortSignal } : {},
24698
- ...internalRequestContext ? { requestContext: internalRequestContext } : {},
24699
- ...childObservabilityContext
24700
- })).getFullOutput();
24773
+ try {
24774
+ return await (await agent.stream(observerMessages, {
24775
+ modelSettings: { ...this.observationConfig.modelSettings },
24776
+ providerOptions: this.observationConfig.providerOptions,
24777
+ ...abortSignal ? { abortSignal } : {},
24778
+ ...internalRequestContext ? { requestContext: internalRequestContext } : {},
24779
+ ...childObservabilityContext
24780
+ })).getFullOutput();
24781
+ } catch (error) {
24782
+ this.mastra?.getLogger?.().error("OM multi-thread observer provider call failed", {
24783
+ diagnostic: formatOmError(error),
24784
+ model: typeof resolvedModel.model === "function" ? "(dynamic-model)" : this.extractModelRouterId(resolvedModel.model, internalRequestContext),
24785
+ inputTokens,
24786
+ threadIds: {
24787
+ sample: threadOrder.slice(0, 10).map((threadId) => threadId.slice(0, 128)),
24788
+ total: threadOrder.length
24789
+ },
24790
+ providerOptionProviders: Object.keys(this.observationConfig.providerOptions ?? {}),
24791
+ hasRequestContext: Boolean(internalRequestContext),
24792
+ aborted: abortSignal?.aborted ?? false
24793
+ });
24794
+ throw error;
24795
+ }
24701
24796
  }, abortSignal)
24702
24797
  }), {
24703
24798
  label: "observer-multi-thread",
@@ -27946,43 +28041,6 @@ function didProviderChange(actorModel, lastModel) {
27946
28041
  if (actorContext.provider && lastContext.provider) return actorContext.provider !== lastContext.provider;
27947
28042
  return false;
27948
28043
  }
27949
- function isRecord$2(value) {
27950
- return typeof value === "object" && value !== null;
27951
- }
27952
- /** Keep provider diagnostics in streamed/persisted markers, not whole API request/response objects. */
27953
- function formatOmError(error) {
27954
- const details = /* @__PURE__ */ new Set();
27955
- const visited = /* @__PURE__ */ new Set();
27956
- const add = (value) => {
27957
- if (typeof value === "string" && value.trim()) details.add(value.trim().slice(0, 2e3));
27958
- };
27959
- function collectErrorDetails(value, depth) {
27960
- if (depth > 5) return;
27961
- if (!isRecord$2(value)) {
27962
- if (value !== void 0) add(String(value));
27963
- return;
27964
- }
27965
- if (visited.has(value)) return;
27966
- visited.add(value);
27967
- add(value.message);
27968
- if (typeof value.statusCode === "number") add(`HTTP ${value.statusCode}`);
27969
- if (typeof value.responseBody === "string") try {
27970
- const body = JSON.parse(value.responseBody);
27971
- if (isRecord$2(body)) {
27972
- add(body.message);
27973
- if (isRecord$2(body.error)) add(body.error.message);
27974
- else add(body.error);
27975
- }
27976
- } catch {}
27977
- if (value.cause !== void 0) collectErrorDetails(value.cause, depth + 1);
27978
- if (value.error !== void 0) collectErrorDetails(value.error, depth + 1);
27979
- }
27980
- try {
27981
- collectErrorDetails(error, 0);
27982
- } catch {}
27983
- const message = [...details].join(": ") || "Unknown error";
27984
- return message.length > 2e3 ? `${message.slice(0, 1997)}...` : message;
27985
- }
27986
28044
  /**
27987
28045
  * Create a start marker for when observation begins.
27988
28046
  */
@@ -46983,4 +47041,4 @@ const agentBuilderWorkflows = {
46983
47041
  //#endregion
46984
47042
  exports.agentBuilderWorkflows = agentBuilderWorkflows;
46985
47043
 
46986
- //# sourceMappingURL=dist-BmrsK_KX.cjs.map
47044
+ //# sourceMappingURL=dist-B0Yl4ENo.cjs.map