@mastra/server 1.62.0-alpha.2 → 1.62.0-alpha.3

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @mastra/server
2
2
 
3
+ ## 1.62.0-alpha.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`2c85f42`](https://github.com/mastra-ai/mastra/commit/2c85f428e04ccd63ea31a7ec80b5b327afdad555), [`11bbeb9`](https://github.com/mastra-ai/mastra/commit/11bbeb9b108ef2264e05acefc6dafb9cbb342921), [`1a485f3`](https://github.com/mastra-ai/mastra/commit/1a485f3538f5ec64d58bd8b5e1e99de0c695c87b), [`0d37487`](https://github.com/mastra-ai/mastra/commit/0d37487d9f349388a3f1cef6a536cf9dcc4b6273), [`8661d7d`](https://github.com/mastra-ai/mastra/commit/8661d7d7179f0a024456aabdd8679bcecd09ac28), [`575e343`](https://github.com/mastra-ai/mastra/commit/575e343900451021d96110916497d334af7bc252), [`cacb839`](https://github.com/mastra-ai/mastra/commit/cacb8392d9e74189b56d857290b0615f98a2683d), [`b47b26e`](https://github.com/mastra-ai/mastra/commit/b47b26e6fe95cb8a3482be2c5e52de157fe59d0b), [`0d37487`](https://github.com/mastra-ai/mastra/commit/0d37487d9f349388a3f1cef6a536cf9dcc4b6273), [`c46eb09`](https://github.com/mastra-ai/mastra/commit/c46eb09ce4987509af57a0ac582c61241a6dd2f1), [`30ed33e`](https://github.com/mastra-ai/mastra/commit/30ed33ee14084a26019aba15fceadda6d6ddefaf), [`91ad69d`](https://github.com/mastra-ai/mastra/commit/91ad69d64994c89199b0c55399e64ed91c61df2f), [`8dc408d`](https://github.com/mastra-ai/mastra/commit/8dc408d34438f9e13297f792c11a5cfd6cf952e1), [`c92def1`](https://github.com/mastra-ai/mastra/commit/c92def10a13c822972c96f0a4ca6ffc1f4258aed), [`c5eaec5`](https://github.com/mastra-ai/mastra/commit/c5eaec5a860d80d0e3805e67db0414b87ac8cbed), [`e66b2ba`](https://github.com/mastra-ai/mastra/commit/e66b2ba100db63eaeab6e21e1ea34b113f2ec781)]:
8
+ - @mastra/core@1.62.0-alpha.3
9
+
3
10
  ## 1.62.0-alpha.2
4
11
 
5
12
  ### Patch Changes
@@ -921,9 +921,17 @@ declare const createScoreBodySchema: z.ZodObject<{
921
921
  runId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
922
922
  entityType: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof EntityType>>>;
923
923
  tags: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
924
+ scorerId: z.ZodString;
925
+ score: z.ZodNumber;
926
+ scoreId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
924
927
  traceId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
925
928
  spanId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
929
+ scorerName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
930
+ scorerVersion: z.ZodOptional<z.ZodNullable<z.ZodString>>;
931
+ scoreSource: z.ZodOptional<z.ZodNullable<z.ZodString>>;
926
932
  source: z.ZodOptional<z.ZodNullable<z.ZodString>>;
933
+ reason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
934
+ scoreTraceId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
927
935
  metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
928
936
  executionSource: z.ZodOptional<z.ZodNullable<z.ZodString>>;
929
937
  entityId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -947,14 +955,6 @@ declare const createScoreBodySchema: z.ZodObject<{
947
955
  parentEntityVersionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
948
956
  rootEntityVersionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
949
957
  experimentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
950
- scorerId: z.ZodString;
951
- score: z.ZodNumber;
952
- scoreId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
953
- scorerName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
954
- scorerVersion: z.ZodOptional<z.ZodNullable<z.ZodString>>;
955
- scoreSource: z.ZodOptional<z.ZodNullable<z.ZodString>>;
956
- reason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
957
- scoreTraceId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
958
958
  }, z.core.$strip>;
959
959
  }, z.core.$strip>;
960
960
  /** Body for creating a score in client/server */
@@ -1050,14 +1050,14 @@ declare const scoresFilterSchema: z.ZodObject<{
1050
1050
  type ScoresFilter = z.infer<typeof scoresFilterSchema>;
1051
1051
  /** Fields available for ordering score results */
1052
1052
  declare const scoresOrderByFieldSchema: z.ZodEnum<{
1053
- timestamp: "timestamp";
1054
1053
  score: "score";
1054
+ timestamp: "timestamp";
1055
1055
  }>;
1056
1056
  /** Order by configuration for score queries */
1057
1057
  declare const scoresOrderBySchema: z.ZodObject<{
1058
1058
  field: z.ZodDefault<z.ZodEnum<{
1059
- timestamp: "timestamp";
1060
1059
  score: "score";
1060
+ timestamp: "timestamp";
1061
1061
  }>>;
1062
1062
  direction: z.ZodDefault<z.ZodEnum<{
1063
1063
  ASC: "ASC";
@@ -1110,8 +1110,8 @@ declare const listScoresArgsSchema: z.ZodPipe<z.ZodObject<{
1110
1110
  }, z.core.$strip>>;
1111
1111
  orderBy: z.ZodOptional<z.ZodObject<{
1112
1112
  field: z.ZodDefault<z.ZodEnum<{
1113
- timestamp: "timestamp";
1114
1113
  score: "score";
1114
+ timestamp: "timestamp";
1115
1115
  }>>;
1116
1116
  direction: z.ZodDefault<z.ZodEnum<{
1117
1117
  ASC: "ASC";
@@ -1162,7 +1162,7 @@ declare const listScoresArgsSchema: z.ZodPipe<z.ZodObject<{
1162
1162
  perPage: number;
1163
1163
  };
1164
1164
  orderBy: {
1165
- field: "timestamp" | "score";
1165
+ field: "score" | "timestamp";
1166
1166
  direction: "ASC" | "DESC";
1167
1167
  };
1168
1168
  after: DeltaCursor | undefined;
@@ -1209,7 +1209,7 @@ declare const listScoresArgsSchema: z.ZodPipe<z.ZodObject<{
1209
1209
  perPage: number;
1210
1210
  } | undefined;
1211
1211
  orderBy?: {
1212
- field: "timestamp" | "score";
1212
+ field: "score" | "timestamp";
1213
1213
  direction: "ASC" | "DESC";
1214
1214
  } | undefined;
1215
1215
  after?: string | undefined;
@@ -4693,7 +4693,7 @@ function splitLines(text) {
4693
4693
  return result;
4694
4694
  }
4695
4695
  //#endregion
4696
- //#region ../memory/dist/src-aTfbkxBl.js
4696
+ //#region ../memory/dist/src-BlQjkJzk.js
4697
4697
  var __defProp$3 = Object.defineProperty;
4698
4698
  var __exportAll = (all, no_symbols) => {
4699
4699
  let target = {};
@@ -23824,7 +23824,19 @@ async function withOmTracingSpan({ phase, model, inputTokens, requestContext, ob
23824
23824
  });
23825
23825
  const childObservabilityContext = createObservabilityContext({ currentSpan: span });
23826
23826
  if (!span) return callback(childObservabilityContext);
23827
- return span.executeInContext(() => callback(childObservabilityContext));
23827
+ return span.executeInContext(async () => {
23828
+ try {
23829
+ const result = await callback(childObservabilityContext);
23830
+ span.end();
23831
+ return result;
23832
+ } catch (error) {
23833
+ span.error({
23834
+ error,
23835
+ endSpan: true
23836
+ });
23837
+ throw error;
23838
+ }
23839
+ });
23828
23840
  }
23829
23841
  function filterObserverExtractors(extractors, skipContinuationHints) {
23830
23842
  const configuredExtractors = extractors ?? [];
@@ -28917,10 +28929,11 @@ ObservationStrategy.create = ((om, opts) => {
28917
28929
  if (deps.scope === "resource" && opts.resourceId) return new ResourceScopedObservationStrategy(deps, opts);
28918
28930
  return new SyncObservationStrategy(deps, opts);
28919
28931
  });
28920
- async function loadMemoryContextMessages({ memory, messageList, threadId, resourceId }) {
28932
+ async function loadMemoryContextMessages({ memory, messageList, threadId, resourceId, runState }) {
28921
28933
  const ctx = await memory.getContext({
28922
28934
  threadId,
28923
- resourceId
28935
+ resourceId,
28936
+ runState
28924
28937
  });
28925
28938
  for (const msg of ctx.messages) if (msg.role !== "system") messageList.add(msg, "memory");
28926
28939
  return ctx;
@@ -29374,10 +29387,11 @@ var ObservationTurn = class {
29374
29387
  * If a MemoryContextProvider is passed, loads historical messages and adds
29375
29388
  * them to the MessageList. Without a provider, only fetches/caches the record.
29376
29389
  */
29377
- async start(memory) {
29390
+ async start(memory, runState) {
29378
29391
  if (this._started) throw new Error("Turn already started");
29379
29392
  this._started = true;
29380
29393
  this._record = await this.om.getOrCreateRecord(this.threadId, this.resourceId);
29394
+ runState?.set(`observational-memory:record:${this.threadId}:${this.resourceId ?? ""}`, this._record);
29381
29395
  this._generationCountAtStart = this._record.generationCount;
29382
29396
  this.memory = memory;
29383
29397
  if (memory) {
@@ -29385,7 +29399,8 @@ var ObservationTurn = class {
29385
29399
  memory,
29386
29400
  messageList: this.messageList,
29387
29401
  threadId: this.threadId,
29388
- resourceId: this.resourceId
29402
+ resourceId: this.resourceId,
29403
+ runState
29389
29404
  });
29390
29405
  this._context = {
29391
29406
  messages: ctx.messages,
@@ -33455,7 +33470,9 @@ var ObservationalMemoryProcessor = class {
33455
33470
  return messageList;
33456
33471
  }
33457
33472
  const { threadId, resourceId } = context;
33458
- const readOnly = parseMemoryRequestContext(requestContext)?.memoryConfig?.readOnly;
33473
+ const memoryContext = parseMemoryRequestContext(requestContext);
33474
+ const runState = memoryContext?.runState?.();
33475
+ const readOnly = memoryContext?.memoryConfig?.readOnly;
33459
33476
  const actorModelContext = model?.modelId ? {
33460
33477
  provider: model.provider,
33461
33478
  modelId: model.modelId,
@@ -33472,7 +33489,8 @@ var ObservationalMemoryProcessor = class {
33472
33489
  memory: this.memory,
33473
33490
  messageList,
33474
33491
  threadId,
33475
- resourceId
33492
+ resourceId,
33493
+ runState
33476
33494
  });
33477
33495
  const systemMessages = ctx.omRecord ? await this.engine.buildContextSystemMessages({
33478
33496
  threadId,
@@ -33513,7 +33531,7 @@ var ObservationalMemoryProcessor = class {
33513
33531
  this.turn.sendStateSignal = args.sendStateSignal;
33514
33532
  this.turn.agent = args.agent;
33515
33533
  this.turn.requestContext = requestContext;
33516
- await this.turn.start(this.memory);
33534
+ await this.turn.start(this.memory, runState);
33517
33535
  if (stepNumber === 0 && this.temporalMarkers) await insertTemporalGapMarkers({
33518
33536
  messageList,
33519
33537
  sendSignal: args.sendSignal
@@ -34660,14 +34678,18 @@ ${workingMemory}`;
34660
34678
  if (!this.threadConfig.workingMemory?.enabled) return null;
34661
34679
  return extractWorkingMemoryContent(text)?.trim() ?? null;
34662
34680
  }
34663
- async getWorkingMemory({ threadId, resourceId, memoryConfig }) {
34681
+ async getWorkingMemory({ threadId, resourceId, memoryConfig, runState }) {
34664
34682
  const config = this.getMergedThreadConfig(memoryConfig || {});
34665
34683
  if (!config.workingMemory?.enabled) return null;
34666
34684
  const scope = config.workingMemory.scope || "resource";
34667
34685
  let workingMemoryData = null;
34668
34686
  if (scope === "resource" && !resourceId) throw new Error("Memory error: Resource-scoped working memory is enabled but no resourceId was provided. Either provide a resourceId or explicitly set workingMemory.scope to 'thread'.");
34669
- if (scope === "resource" && resourceId) workingMemoryData = (await (await this.getMemoryStore()).getResourceById({ resourceId }))?.workingMemory || null;
34670
- else workingMemoryData = (await this.getThreadById({ threadId }))?.metadata?.workingMemory;
34687
+ if (scope === "resource" && resourceId) {
34688
+ const loadWorkingMemory = async () => {
34689
+ return (await (await this.getMemoryStore()).getResourceById({ resourceId }))?.workingMemory || null;
34690
+ };
34691
+ workingMemoryData = runState ? await runState.load(`working-memory:resource:${resourceId}`, loadWorkingMemory) : await loadWorkingMemory();
34692
+ } else workingMemoryData = (runState?.threadLoaded ? runState.thread : await this.getThreadById({ threadId }))?.metadata?.workingMemory;
34671
34693
  if (!workingMemoryData) return null;
34672
34694
  return workingMemoryData;
34673
34695
  }
@@ -34699,16 +34721,18 @@ ${workingMemory}`;
34699
34721
  content: (config.workingMemory.template || this.defaultWorkingMemoryTemplate).trim()
34700
34722
  };
34701
34723
  }
34702
- async getSystemMessage({ threadId, resourceId, memoryConfig }) {
34724
+ async getSystemMessage({ threadId, resourceId, memoryConfig, runState }) {
34703
34725
  const config = this.getMergedThreadConfig(memoryConfig);
34704
34726
  this.assertWorkingMemoryStateSignalsCompatibility(config);
34705
34727
  if (!config.workingMemory?.enabled) return null;
34706
34728
  if (config.workingMemory?.useStateSignals) return null;
34707
- const workingMemoryTemplate = await this.getWorkingMemoryTemplate({ memoryConfig });
34729
+ const loadTemplate = () => this.getWorkingMemoryTemplate({ memoryConfig });
34730
+ const workingMemoryTemplate = runState ? await runState.load("working-memory:template", loadTemplate) : await loadTemplate();
34708
34731
  const workingMemoryData = await this.getWorkingMemory({
34709
34732
  threadId,
34710
34733
  resourceId,
34711
- memoryConfig: config
34734
+ memoryConfig: config,
34735
+ runState
34712
34736
  });
34713
34737
  if (!workingMemoryTemplate) return null;
34714
34738
  const workingMemoryConfig = config.workingMemory;
@@ -34741,7 +34765,7 @@ ${workingMemory}`;
34741
34765
  * ```
34742
34766
  */
34743
34767
  async getContext(opts) {
34744
- const { threadId, resourceId, memoryConfig } = opts;
34768
+ const { threadId, resourceId, memoryConfig, runState } = opts;
34745
34769
  const config = this.getMergedThreadConfig(memoryConfig);
34746
34770
  const memoryStore = await this.getMemoryStore();
34747
34771
  const systemParts = [];
@@ -34751,10 +34775,14 @@ ${workingMemory}`;
34751
34775
  let otherThreadsContext;
34752
34776
  const omEngine = await this.omEngine;
34753
34777
  if (omEngine) {
34754
- omRecord = await omEngine.getRecord(threadId, resourceId);
34778
+ const loadOmRecord = () => omEngine.getRecord(threadId, resourceId);
34779
+ omRecord = runState ? await runState.load(`observational-memory:record:${threadId}:${resourceId ?? ""}`, loadOmRecord) : await loadOmRecord();
34755
34780
  if (omRecord?.activeObservations) {
34756
34781
  hasObservations = true;
34757
- if (omEngine.scope === "resource" && resourceId) otherThreadsContext = await omEngine.getOtherThreadsContext(resourceId, threadId);
34782
+ if (omEngine.scope === "resource" && resourceId) {
34783
+ const loadOtherThreadsContext = () => omEngine.getOtherThreadsContext(resourceId, threadId);
34784
+ otherThreadsContext = runState ? await runState.load(`observational-memory:other-threads:${resourceId}:${threadId}:${omRecord.lastObservedAt ?? ""}`, loadOtherThreadsContext) : await loadOtherThreadsContext();
34785
+ }
34758
34786
  const obsSystemMessage = await omEngine.buildContextSystemMessage({
34759
34787
  threadId,
34760
34788
  resourceId,
@@ -34782,30 +34810,41 @@ ${workingMemory}`;
34782
34810
  const workingMemoryMessage = await this.getSystemMessage({
34783
34811
  threadId,
34784
34812
  resourceId,
34785
- memoryConfig: config
34813
+ memoryConfig: config,
34814
+ runState
34786
34815
  });
34787
34816
  if (workingMemoryMessage) systemParts.push(workingMemoryMessage);
34788
34817
  let messages;
34789
34818
  if (omEngine && omRecord) {
34790
34819
  const dateFilter = omRecord.lastObservedAt ? { dateRange: { start: new Date(new Date(omRecord.lastObservedAt).getTime() + 1) } } : void 0;
34791
- if (omEngine.scope === "resource" && resourceId) messages = (await memoryStore.listMessagesByResourceId({
34792
- resourceId,
34793
- orderBy: {
34794
- field: "createdAt",
34795
- direction: "ASC"
34796
- },
34797
- perPage: false,
34798
- filter: dateFilter
34799
- })).messages;
34800
- else messages = (await memoryStore.listMessages({
34801
- threadId,
34802
- orderBy: {
34803
- field: "createdAt",
34804
- direction: "ASC"
34805
- },
34806
- perPage: false,
34807
- filter: dateFilter
34808
- })).messages;
34820
+ const boundary = omRecord.lastObservedAt ? new Date(omRecord.lastObservedAt).toISOString() : "";
34821
+ if (omEngine.scope === "resource" && resourceId) {
34822
+ const loadMessages = async () => {
34823
+ return (await memoryStore.listMessagesByResourceId({
34824
+ resourceId,
34825
+ orderBy: {
34826
+ field: "createdAt",
34827
+ direction: "ASC"
34828
+ },
34829
+ perPage: false,
34830
+ filter: dateFilter
34831
+ })).messages;
34832
+ };
34833
+ messages = runState ? await runState.load(`observational-memory:messages:resource:${resourceId}:${boundary}`, loadMessages) : await loadMessages();
34834
+ } else {
34835
+ const loadMessages = async () => {
34836
+ return (await memoryStore.listMessages({
34837
+ threadId,
34838
+ orderBy: {
34839
+ field: "createdAt",
34840
+ direction: "ASC"
34841
+ },
34842
+ perPage: false,
34843
+ filter: dateFilter
34844
+ })).messages;
34845
+ };
34846
+ messages = runState ? await runState.load(`observational-memory:messages:thread:${threadId}:${boundary}`, loadMessages) : await loadMessages();
34847
+ }
34809
34848
  } else {
34810
34849
  const lastMessages = config.lastMessages;
34811
34850
  if (lastMessages === false) messages = [];
@@ -46196,4 +46235,4 @@ const agentBuilderWorkflows = {
46196
46235
  //#endregion
46197
46236
  export { agentBuilderWorkflows };
46198
46237
 
46199
- //# sourceMappingURL=dist-Cw-T1gX6.js.map
46238
+ //# sourceMappingURL=dist-HzWDFjPH.js.map