@mastra/server 1.83.0-alpha.4 → 1.83.0-alpha.5

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.
Files changed (62) hide show
  1. package/dist/{agent-builder-73cAYGts.cjs → agent-builder-C4H6DCxX.cjs} +2 -2
  2. package/dist/{agent-builder-73cAYGts.cjs.map → agent-builder-C4H6DCxX.cjs.map} +1 -1
  3. package/dist/{agent-builder-pQaGXyFz.js → agent-builder-CM3ahyKi.js} +2 -2
  4. package/dist/{agent-builder-pQaGXyFz.js.map → agent-builder-CM3ahyKi.js.map} +1 -1
  5. package/dist/{api-schema-manifest-C4KWBHOE.cjs → api-schema-manifest-BxJovXGA.cjs} +2 -2
  6. package/dist/{api-schema-manifest-C4KWBHOE.cjs.map → api-schema-manifest-BxJovXGA.cjs.map} +1 -1
  7. package/dist/{api-schema-manifest-BNmKPj1d.js → api-schema-manifest-DyPtNiCm.js} +2 -2
  8. package/dist/{api-schema-manifest-BNmKPj1d.js.map → api-schema-manifest-DyPtNiCm.js.map} +1 -1
  9. package/dist/{dist-Dhi6UZwv.cjs → dist-CeTjOkVU.cjs} +1 -1
  10. package/dist/{dist-DIeKEdwH.cjs → dist-ChFEVV0z.cjs} +56 -20
  11. package/dist/{dist-DIeKEdwH.cjs.map → dist-ChFEVV0z.cjs.map} +1 -1
  12. package/dist/dist-Dd4aPQrP.js +1 -0
  13. package/dist/{dist-CXxA_Jnu.js → dist-cCQ5-Jqn.js} +56 -20
  14. package/dist/{dist-CXxA_Jnu.js.map → dist-cCQ5-Jqn.js.map} +1 -1
  15. package/dist/docs/SKILL.md +1 -1
  16. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  17. package/dist/{helpers-B29a1nM3.js → helpers-C3dENOkQ.js} +183 -53
  18. package/dist/helpers-C3dENOkQ.js.map +1 -0
  19. package/dist/{helpers-CylvUIZm.cjs → helpers-D7d2R3LL.cjs} +188 -52
  20. package/dist/helpers-D7d2R3LL.cjs.map +1 -0
  21. package/dist/{probe-image-size-C2efNs3R.cjs → probe-image-size-BfNwxl51.cjs} +2 -2
  22. package/dist/{probe-image-size-C2efNs3R.cjs.map → probe-image-size-BfNwxl51.cjs.map} +1 -1
  23. package/dist/{probe-image-size-CO02-278.js → probe-image-size-DLmoo3Jh.js} +2 -2
  24. package/dist/{probe-image-size-CO02-278.js.map → probe-image-size-DLmoo3Jh.js.map} +1 -1
  25. package/dist/{routes-BtJyuAGq.cjs → routes-DTAeTr8M.cjs} +2 -2
  26. package/dist/{routes-BtJyuAGq.cjs.map → routes-DTAeTr8M.cjs.map} +1 -1
  27. package/dist/{routes-DgMuPPQr.js → routes-P_uCi0AL.js} +2 -2
  28. package/dist/{routes-DgMuPPQr.js.map → routes-P_uCi0AL.js.map} +1 -1
  29. package/dist/server/auth/custom-route-matcher.d.ts +54 -0
  30. package/dist/server/auth/custom-route-matcher.d.ts.map +1 -0
  31. package/dist/server/auth/helpers.d.ts +14 -5
  32. package/dist/server/auth/helpers.d.ts.map +1 -1
  33. package/dist/server/auth/index.cjs +1 -1
  34. package/dist/server/auth/index.js +1 -1
  35. package/dist/server/auth/path-pattern.d.ts.map +1 -1
  36. package/dist/server/handlers/agent-builder.cjs +1 -1
  37. package/dist/server/handlers/agent-builder.js +1 -1
  38. package/dist/server/handlers/auth.cjs +1 -1
  39. package/dist/server/handlers/auth.js +1 -1
  40. package/dist/server/handlers/datasets.cjs +22 -3
  41. package/dist/server/handlers/datasets.cjs.map +1 -1
  42. package/dist/server/handlers/datasets.d.ts +8 -2
  43. package/dist/server/handlers/datasets.d.ts.map +1 -1
  44. package/dist/server/handlers/datasets.js +22 -3
  45. package/dist/server/handlers/datasets.js.map +1 -1
  46. package/dist/server/handlers/system.cjs +1 -1
  47. package/dist/server/handlers/system.js +1 -1
  48. package/dist/server/handlers.cjs +1 -1
  49. package/dist/server/handlers.js +1 -1
  50. package/dist/server/server-adapter/index.cjs +68 -4
  51. package/dist/server/server-adapter/index.cjs.map +1 -1
  52. package/dist/server/server-adapter/index.d.ts +34 -0
  53. package/dist/server/server-adapter/index.d.ts.map +1 -1
  54. package/dist/server/server-adapter/index.js +68 -4
  55. package/dist/server/server-adapter/index.js.map +1 -1
  56. package/dist/server/server-adapter/routes/datasets.d.ts +8 -2
  57. package/dist/server/server-adapter/routes/datasets.d.ts.map +1 -1
  58. package/dist/server/server-adapter/routes/workspace.d.ts +23 -23
  59. package/package.json +3 -3
  60. package/dist/dist-CQGBYe6U.js +0 -1
  61. package/dist/helpers-B29a1nM3.js.map +0 -1
  62. package/dist/helpers-CylvUIZm.cjs.map +0 -1
@@ -0,0 +1 @@
1
+ export { n as openai } from "./dist-cCQ5-Jqn.js";
@@ -8654,7 +8654,7 @@ function splitLines(text) {
8654
8654
  else result.push(result.pop().slice(0, -1));
8655
8655
  return result;
8656
8656
  }
8657
- // ../memory/dist/src-BL6KZcyR.js
8657
+ // ../memory/dist/src-wMl-5Ms8.js
8658
8658
  var __defProp$3 = Object.defineProperty;
8659
8659
  var __exportAll = (all, no_symbols) => {
8660
8660
  let target = {};
@@ -32492,6 +32492,9 @@ Observation groups with range IDs and your recall tool allows you to think back
32492
32492
  ### Additional recall guidance
32493
32493
  ${custom}`;
32494
32494
  }
32495
+ /** Sentinel a required inline section uses to signal that no update is needed. */
32496
+ const UNCHANGED_EXTRACTOR_VALUE = "UNCHANGED";
32497
+ const UNCHANGED_PATTERN = new RegExp(`^[\\s\`'"*]*${UNCHANGED_EXTRACTOR_VALUE}[\\s\`'"*.!]*$`, "i");
32495
32498
  const BUILT_IN_SLUGS = /* @__PURE__ */ new Set([
32496
32499
  "current-task",
32497
32500
  "suggested-response",
@@ -32557,11 +32560,16 @@ var Extractor = class Extractor {
32557
32560
  metadataKeyPath;
32558
32561
  onExtracted;
32559
32562
  retryStructuredExtractionOnEmptyObject;
32563
+ /**
32564
+ * @internal Require this inline section in single-thread observer calls. A missing section is recorded as an
32565
+ * extraction failure, and `UNCHANGED` is skipped rather than stored. Batched multi-thread calls treat it as optional.
32566
+ */
32567
+ required;
32560
32568
  /** @internal */
32561
32569
  internal;
32562
32570
  instructionsConfig;
32563
32571
  schemaConfig;
32564
- constructor(config, internal = false) {
32572
+ constructor(config, internal = false, required = false) {
32565
32573
  const name = config.name.trim();
32566
32574
  const instructions = typeof config.instructions === "string" ? config.instructions.trim() : void 0;
32567
32575
  const slug = slugifyExtractorName(name);
@@ -32584,6 +32592,7 @@ var Extractor = class Extractor {
32584
32592
  this.metadataKeyPath = isHook ? false : config.metadataKeyPath ?? `extracted.${slug}`;
32585
32593
  this.onExtracted = config.onExtracted;
32586
32594
  this.retryStructuredExtractionOnEmptyObject = config.retryStructuredExtractionOnEmptyObject ?? false;
32595
+ this.required = required;
32587
32596
  this.internal = internal;
32588
32597
  }
32589
32598
  async resolve(context) {
@@ -32599,7 +32608,7 @@ var Extractor = class Extractor {
32599
32608
  metadataKeyPath: this.metadataKeyPath,
32600
32609
  onExtracted: this.onExtracted,
32601
32610
  retryStructuredExtractionOnEmptyObject: this.retryStructuredExtractionOnEmptyObject
32602
- }, this.internal);
32611
+ }, this.internal, this.required);
32603
32612
  }
32604
32613
  };
32605
32614
  async function resolveExtractors(extractors, context) {
@@ -32654,6 +32663,7 @@ function parseExtractedValues(output, extractors) {
32654
32663
  const values = {};
32655
32664
  const failures = [];
32656
32665
  const inlineExtractors = extractors.filter((extractor) => extractor.mode === "inline");
32666
+ const unchangedSlugs = /* @__PURE__ */ new Set();
32657
32667
  const regex = new RegExp(`<${EXTRACTED_VALUES_TAG}>([\\s\\S]*?)<\\/${EXTRACTED_VALUES_TAG}>`, "gi");
32658
32668
  const matches = [...output.matchAll(regex)];
32659
32669
  for (const match of matches) try {
@@ -32663,6 +32673,10 @@ function parseExtractedValues(output, extractors) {
32663
32673
  if (!Object.prototype.hasOwnProperty.call(extractedValues, extractor.slug)) continue;
32664
32674
  const rawValue = extractedValues[extractor.slug];
32665
32675
  if (rawValue === void 0 || rawValue === null || rawValue === "") continue;
32676
+ if (extractor.required && typeof rawValue === "string" && UNCHANGED_PATTERN.test(rawValue)) {
32677
+ unchangedSlugs.add(extractor.slug);
32678
+ continue;
32679
+ }
32666
32680
  const parsed = extractor.schema.safeParse(rawValue);
32667
32681
  if (parsed.success) values[extractor.slug] = parsed.data;
32668
32682
  else failures.push({
@@ -32677,10 +32691,17 @@ function parseExtractedValues(output, extractors) {
32677
32691
  });
32678
32692
  }
32679
32693
  for (const extractor of inlineExtractors) {
32680
- if (Object.prototype.hasOwnProperty.call(values, extractor.slug)) continue;
32694
+ if (Object.prototype.hasOwnProperty.call(values, extractor.slug) || unchangedSlugs.has(extractor.slug)) continue;
32681
32695
  const tagRegex = new RegExp(`<${extractor.slug}>([\\s\\S]*?)<\\/${extractor.slug}>`, "gi");
32682
32696
  const rawValue = [...output.matchAll(tagRegex)].at(-1)?.[1]?.trim();
32683
- if (!rawValue) continue;
32697
+ if (!rawValue) {
32698
+ if (extractor.required) failures.push({
32699
+ slug: extractor.slug,
32700
+ error: `Observer output did not include the required <${extractor.slug}> section`
32701
+ });
32702
+ continue;
32703
+ }
32704
+ if (extractor.required && UNCHANGED_PATTERN.test(rawValue)) continue;
32684
32705
  try {
32685
32706
  values[extractor.slug] = parseExtractorValue(extractor, rawValue);
32686
32707
  } catch (error) {
@@ -32701,13 +32722,21 @@ function stripExtractorSections(output, extractors) {
32701
32722
  for (const extractor of inlineExtractors) stripped = stripped.replace(new RegExp(`[ \\t]*<${extractor.slug}>[\\s\\S]*?<\\/${extractor.slug}>\\s*`, "gi"), "");
32702
32723
  return stripped;
32703
32724
  }
32725
+ /**
32726
+ * Batched multi-thread observer calls share one output across threads, so a per-thread required
32727
+ * section would duplicate resource-level values and record spurious failures. Treat them as optional there.
32728
+ */
32729
+ function withoutRequiredSections(extractors) {
32730
+ return extractors.map((extractor) => extractor.required ? Object.assign(Object.create(Object.getPrototypeOf(extractor)), extractor, { required: false }) : extractor);
32731
+ }
32704
32732
  function buildExtractorOutputSections(extractors) {
32705
32733
  const inlineExtractors = extractors.filter((extractor) => extractor.mode === "inline");
32706
32734
  if (inlineExtractors.length === 0) return "";
32707
- return `Additional optional XML sections:\nIf the observations include information relevant to any of these tags, output that tag after <observations> and include the relevant information.\n${inlineExtractors.map((extractor) => `<${extractor.slug}>
32735
+ const sections = inlineExtractors.map((extractor) => `<${extractor.slug}>
32708
32736
  ${extractor.instructions}
32709
- Include this section when the observations contain relevant information for <${extractor.slug}>. Write only that information inside the tag.
32710
- </${extractor.slug}>`).join("\n\n")}`;
32737
+ ${extractor.required ? `This section is REQUIRED: always output <${extractor.slug}>. If nothing needs to change, write exactly ${UNCHANGED_EXTRACTOR_VALUE} inside the tag.` : `Include this section when the observations contain relevant information for <${extractor.slug}>. Write only that information inside the tag.`}
32738
+ </${extractor.slug}>`).join("\n\n");
32739
+ return `${inlineExtractors.some((extractor) => extractor.required) ? "Additional XML sections:\nOutput these tags after <observations>, following the instructions in each tag." : "Additional optional XML sections:\nIf the observations include information relevant to any of these tags, output that tag after <observations> and include the relevant information."}\n${sections}`;
32711
32740
  }
32712
32741
  function renderPriorValue(value) {
32713
32742
  return typeof value === "string" ? value : JSON.stringify(value);
@@ -36136,6 +36165,11 @@ var ObserverRunner = class {
36136
36165
  });
36137
36166
  const extractedValues = mergeExtractedValues(parsed.extractedValues, structuredExtraction.values);
36138
36167
  const extractionFailures = mergeExtractionFailures(parsed.extractionFailures, structuredExtraction.failures);
36168
+ const failedSlugs = activeExtractors.filter((extractor) => extractor.mode === "inline" && extractor.required).map((extractor) => extractor.slug).filter((slug) => parsed.extractionFailures?.some((failure) => failure.slug === slug));
36169
+ if (failedSlugs.length > 0) this.mastra?.getLogger?.().warn("OM observer could not extract required sections", {
36170
+ failedSlugs,
36171
+ threadId: messagesToObserve[0]?.threadId
36172
+ });
36139
36173
  const builtIns = getBuiltInExtractedValues(extractedValues);
36140
36174
  const systemPrompt = buildObserverSystemPrompt(false, this.observationConfig.instruction, this.observationConfig.threadTitle, activeExtractors);
36141
36175
  this.lastExchange = {
@@ -36268,10 +36302,11 @@ var ObserverRunner = class {
36268
36302
  usage: totalUsage
36269
36303
  };
36270
36304
  }
36271
- const agent = this.createAgent(resolvedModel.model, true, void 0, activeExtractors);
36305
+ const batchExtractors = withoutRequiredSections(activeExtractors);
36306
+ const agent = this.createAgent(resolvedModel.model, true, void 0, batchExtractors);
36272
36307
  const internalRequestContext = withOmInternalThreadId(requestContext, agent.id);
36273
36308
  const multiThreadAttachmentFilter = this.resolveAttachmentFilter(resolvedModel.model, requestContext);
36274
- const observerMessages = [buildMultiThreadObserverRequestMessage(existingObservations, messagesByThread, threadOrder, priorMetadataByThread, wasTruncated, this.observationConfig.threadTitle, activeExtractors, {
36309
+ const observerMessages = [buildMultiThreadObserverRequestMessage(existingObservations, messagesByThread, threadOrder, priorMetadataByThread, wasTruncated, this.observationConfig.threadTitle, batchExtractors, {
36275
36310
  attachmentFilter: multiThreadAttachmentFilter,
36276
36311
  timeZone
36277
36312
  })];
@@ -36327,12 +36362,12 @@ var ObserverRunner = class {
36327
36362
  });
36328
36363
  };
36329
36364
  let result = await doGenerate();
36330
- let parsed = parseMultiThreadObserverOutput(result.text, activeExtractors);
36365
+ let parsed = parseMultiThreadObserverOutput(result.text, batchExtractors);
36331
36366
  let retriedDueToDegenerate = false;
36332
36367
  if (parsed.degenerate) {
36333
36368
  omDebug(`[OM:callMultiThreadObserver] degenerate repetition detected, retrying once. ${describeDegenerateOutput(result.text, 2e3)}`);
36334
36369
  result = await doGenerate();
36335
- parsed = parseMultiThreadObserverOutput(result.text, activeExtractors);
36370
+ parsed = parseMultiThreadObserverOutput(result.text, batchExtractors);
36336
36371
  retriedDueToDegenerate = true;
36337
36372
  if (parsed.degenerate) {
36338
36373
  omDebug(`[OM:callMultiThreadObserver] degenerate repetition on retry, failing. ${describeDegenerateOutput(result.text, 2e3)}`);
@@ -36343,7 +36378,7 @@ var ObserverRunner = class {
36343
36378
  const aggregatedExtractedValues = mergeExtractedValues(...Array.from(parsed.threads, ([threadId, threadResult]) => mergeExtractedValues(threadResult.extractedValues, structuredExtractionByThread.get(threadId)?.values)));
36344
36379
  const aggregatedExtractionFailures = mergeExtractionFailures(...Array.from(parsed.threads, ([threadId, threadResult]) => mergeExtractionFailures(threadResult.extractionFailures, structuredExtractionByThread.get(threadId)?.failures)));
36345
36380
  const aggregatedBuiltIns = getBuiltInExtractedValues(aggregatedExtractedValues);
36346
- const systemPrompt = buildObserverSystemPrompt(true, this.observationConfig.instruction, this.observationConfig.threadTitle, activeExtractors);
36381
+ const systemPrompt = buildObserverSystemPrompt(true, this.observationConfig.instruction, this.observationConfig.threadTitle, batchExtractors);
36347
36382
  this.lastExchange = {
36348
36383
  systemPrompt,
36349
36384
  observerMessages,
@@ -36375,7 +36410,7 @@ var ObserverRunner = class {
36375
36410
  threadTitle: builtIns.threadTitle ?? threadResult.threadTitle,
36376
36411
  extractedValues,
36377
36412
  extractionFailures,
36378
- extractors: activeExtractors
36413
+ extractors: batchExtractors
36379
36414
  });
36380
36415
  }
36381
36416
  for (const threadId of results.keys()) for (const msg of messagesByThread.get(threadId) ?? []) this.observedMessageIds.add(msg.id);
@@ -36414,7 +36449,8 @@ function assertRecognizedObserverOutput(output, label, isRecognized) {
36414
36449
  function hasSingleThreadObserverContent(text, extractors) {
36415
36450
  if (/^[ \t]*<observations>/im.test(text)) return true;
36416
36451
  const parsed = parseObserverOutput(text, extractors);
36417
- return Boolean(parsed.degenerate || parsed.observations || parsed.currentTask || parsed.suggestedContinuation || parsed.threadTitle || Object.keys(parsed.extractedValues ?? {}).length || parsed.extractionFailures?.length);
36452
+ const requiredSlugs = new Set(extractors.filter((extractor) => extractor.mode === "inline" && extractor.required).map((extractor) => extractor.slug));
36453
+ return Boolean(parsed.degenerate || parsed.observations || parsed.currentTask || parsed.suggestedContinuation || parsed.threadTitle || Object.keys(parsed.extractedValues ?? {}).length || parsed.extractionFailures?.some((failure) => !requiredSlugs.has(failure.slug)));
36418
36454
  }
36419
36455
  /**
36420
36456
  * Multi-thread replies carry every recognised section inside `<thread>` blocks, so a reply
@@ -36735,7 +36771,7 @@ async function resolveImageDimensionsAsync(part) {
36735
36771
  const url = resolveHttpAssetUrl(getObjectValue(part, "image") ?? getObjectValue(part, "data"));
36736
36772
  if (!url) return existing;
36737
36773
  try {
36738
- const probeImageSize = (await import("./probe-image-size-CO02-278.js").then((m) => /* @__PURE__ */ __toESM$1(m.default, 1))).default;
36774
+ const probeImageSize = (await import("./probe-image-size-DLmoo3Jh.js").then((m) => /* @__PURE__ */ __toESM$1(m.default, 1))).default;
36739
36775
  const probed = await probeImageSize(url, {
36740
36776
  open_timeout: REMOTE_IMAGE_PROBE_TIMEOUT_MS,
36741
36777
  response_timeout: REMOTE_IMAGE_PROBE_TIMEOUT_MS,
@@ -38312,7 +38348,7 @@ var WorkingMemoryExtractor = class extends Extractor {
38312
38348
  });
38313
38349
  return document;
38314
38350
  }
38315
- });
38351
+ }, false, true);
38316
38352
  }
38317
38353
  };
38318
38354
  /**
@@ -49125,7 +49161,7 @@ var Memory = class Memory extends MastraMemory {
49125
49161
  const config = this.getMergedThreadConfig(memoryConfig || {});
49126
49162
  this.assertWorkingMemoryStateSignalsCompatibility(config);
49127
49163
  if (!config.workingMemory?.enabled) throw new Error("Working memory is not enabled for this memory instance");
49128
- const mutexKey = memoryConfig?.workingMemory?.scope === `resource` ? `resource-${resourceId}` : `thread-${threadId}`;
49164
+ const mutexKey = (config.workingMemory.scope || "resource") === "resource" ? `resource-${resourceId}` : `thread-${threadId}`;
49129
49165
  const mutex = this.updateWorkingMemoryMutexes.has(mutexKey) ? this.updateWorkingMemoryMutexes.get(mutexKey) : new Mutex();
49130
49166
  this.updateWorkingMemoryMutexes.set(mutexKey, mutex);
49131
49167
  const release = await mutex.acquire();
@@ -51946,7 +51982,7 @@ const createModelInstance = async (provider, modelId, version = "v2") => {
51946
51982
  try {
51947
51983
  const providerFn = version === `v1` ? { v1: {
51948
51984
  openai: async () => {
51949
- const { openai } = await import("./dist-CQGBYe6U.js");
51985
+ const { openai } = await import("./dist-Dd4aPQrP.js");
51950
51986
  return openai(modelId);
51951
51987
  },
51952
51988
  anthropic: async () => {
@@ -59702,4 +59738,4 @@ function createAgentBuilderWorkflows() {
59702
59738
  }
59703
59739
  export { require_tiff as a, require_png as c, createAgentBuilderWorkflows, require_gif as d, require_bmp as f, require_webp as i, require_jpeg as l, require_utils as m, openai as n, require_svg as o, require_avif as p, require_sync as r, require_psd as s, createOpenAI as t, require_ico as u };
59704
59740
 
59705
- //# sourceMappingURL=dist-CXxA_Jnu.js.map
59741
+ //# sourceMappingURL=dist-cCQ5-Jqn.js.map