@mastra/convex 1.7.3 → 1.7.4-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.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { a as mastraCache, i as mastraStorage, n as mastraNativeVectorMutation, r as mastraNativeVectorQuery, t as mastraNativeVectorAction } from "./server-B8RSiOmu.js";
1
+ import { a as mastraCache, i as mastraStorage, n as mastraNativeVectorMutation, r as mastraNativeVectorQuery, t as mastraNativeVectorAction } from "./server-DCzSpppl.js";
2
2
  import { TABLE_BACKGROUND_TASKS, TABLE_CHANNEL_CONFIG, TABLE_CHANNEL_INSTALLATIONS, TABLE_MESSAGES, TABLE_OBSERVATIONAL_MEMORY, TABLE_RESOURCES, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, TABLE_SCORERS, TABLE_THREADS, TABLE_WORKFLOW_SNAPSHOT, defineMastraNativeVectorTable, mastraBackgroundTasksTable, mastraCacheListItemsTable, mastraCacheTable, mastraChannelConfigTable, mastraChannelInstallationsTable, mastraDocumentsTable, mastraMessagesTable, mastraObservationalMemoryTable, mastraResourcesTable, mastraScheduleTriggersTable, mastraSchedulesTable, mastraScoresTable, mastraThreadsTable, mastraVectorIndexesTable, mastraVectorsTable, mastraWorkflowSnapshotsTable } from "./schema.js";
3
3
  import { MastraServerCache } from "@mastra/core/cache";
4
- import { BackgroundTasksStorage, ChannelsStorage, MastraCompositeStore, MemoryStorage, RUN_FENCE_CONFLICT_ERROR_ID, RunFenceConflictError, SchedulesStorage, ScoresStorage, TABLE_BACKGROUND_TASKS as TABLE_BACKGROUND_TASKS$1, TABLE_CHANNEL_CONFIG as TABLE_CHANNEL_CONFIG$1, TABLE_CHANNEL_INSTALLATIONS as TABLE_CHANNEL_INSTALLATIONS$1, TABLE_MEMORY_RUN_FENCES, TABLE_MESSAGES as TABLE_MESSAGES$1, TABLE_RESOURCES as TABLE_RESOURCES$1, TABLE_SCHEDULES as TABLE_SCHEDULES$1, TABLE_SCHEDULE_TRIGGERS as TABLE_SCHEDULE_TRIGGERS$1, TABLE_SCORERS as TABLE_SCORERS$1, TABLE_THREADS as TABLE_THREADS$1, TABLE_WORKFLOW_RUN_OWNERS, TABLE_WORKFLOW_SNAPSHOT as TABLE_WORKFLOW_SNAPSHOT$1, WorkflowsStorage, calculatePagination, createStorageErrorId, createVectorErrorId, filterByDateRange, normalizePerPage, normalizeScheduleTarget, resolveRunFence, safelyParseJSON, storageMessageMatchesMetadataFilter, validateStorageMetadataFilter } from "@mastra/core/storage";
4
+ import { BackgroundTasksStorage, ChannelsStorage, MastraCompositeStore, MemoryStorage, RUN_FENCE_CONFLICT_ERROR_ID, RunFenceConflictError, SchedulesStorage, ScoresStorage, TABLE_BACKGROUND_TASKS as TABLE_BACKGROUND_TASKS$1, TABLE_CHANNEL_CONFIG as TABLE_CHANNEL_CONFIG$1, TABLE_CHANNEL_INSTALLATIONS as TABLE_CHANNEL_INSTALLATIONS$1, TABLE_MEMORY_RUN_FENCES, TABLE_MESSAGES as TABLE_MESSAGES$1, TABLE_RESOURCES as TABLE_RESOURCES$1, TABLE_SCHEDULES as TABLE_SCHEDULES$1, TABLE_SCHEDULE_TRIGGERS as TABLE_SCHEDULE_TRIGGERS$1, TABLE_SCORERS as TABLE_SCORERS$1, TABLE_THREADS as TABLE_THREADS$1, TABLE_WORKFLOW_RUN_OWNERS, TABLE_WORKFLOW_SNAPSHOT as TABLE_WORKFLOW_SNAPSHOT$1, WorkflowsStorage, calculatePagination, createStorageErrorId, createVectorErrorId, executeRetentionPrune, filterByDateRange, normalizePerPage, normalizeScheduleTarget, resolveRetentionTargets, resolveRunFence, retentionCutoffMs, safelyParseJSON, storageMessageMatchesMetadataFilter, validateStorageMetadataFilter } from "@mastra/core/storage";
5
5
  import { MastraBase } from "@mastra/core/base";
6
6
  import { MessageList } from "@mastra/core/agent";
7
7
  import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
@@ -399,6 +399,17 @@ async function retireRunFence(client, fence) {
399
399
  });
400
400
  return applied;
401
401
  }
402
+ /** Deletes up to `limit` claims whose epoch-ms `column` is older than `cutoff`. Returns how many were deleted. */
403
+ async function pruneRunClaims(client, tableName, column, cutoff, limit) {
404
+ const { result } = await callRunClaim(client, {
405
+ op: "pruneRunClaims",
406
+ tableName,
407
+ column,
408
+ cutoff,
409
+ limit
410
+ }, "prune");
411
+ return result;
412
+ }
402
413
  //#endregion
403
414
  //#region src/storage/types.ts
404
415
  /**
@@ -1172,7 +1183,18 @@ function parseStoredOMRecord(doc) {
1172
1183
  supersededBy: doc.supersededBy ?? null
1173
1184
  };
1174
1185
  }
1175
- var MemoryConvex = class extends MemoryStorage {
1186
+ var MemoryConvex = class MemoryConvex extends MemoryStorage {
1187
+ /**
1188
+ * Tables `prune()` can clean up. Run fences anchor on `retiredAt` (epoch ms), which stays unset until the
1189
+ * execution holding the fence settles, so a running execution's fence is
1190
+ * never pruned.
1191
+ */
1192
+ static retentionTables = { runFences: {
1193
+ table: TABLE_MEMORY_RUN_FENCES,
1194
+ column: "retiredAt",
1195
+ indexed: false,
1196
+ anchorType: "epoch-ms"
1197
+ } };
1176
1198
  supportsPartialThreadUpdate = true;
1177
1199
  supportsObservationalMemory = true;
1178
1200
  supportsObservationalMemoryHistorySearch = true;
@@ -1205,6 +1227,19 @@ var MemoryConvex = class extends MemoryStorage {
1205
1227
  return this.#db.fenced(this.#runFenceCheck(fence, operation));
1206
1228
  }
1207
1229
  async init() {}
1230
+ async prune(policies, options) {
1231
+ return executeRetentionPrune({
1232
+ domain: "memory",
1233
+ targets: resolveRetentionTargets({
1234
+ policies,
1235
+ descriptor: MemoryConvex.retentionTables,
1236
+ order: ["runFences"]
1237
+ }),
1238
+ options,
1239
+ cutoffFor: (target, now) => retentionCutoffMs(target.policy, now),
1240
+ deleteBatch: (_target, cutoff, limit) => pruneRunClaims(this.#client, TABLE_MEMORY_RUN_FENCES, "retiredAt", Number(cutoff), limit)
1241
+ });
1242
+ }
1208
1243
  async dangerouslyClearAll() {
1209
1244
  await this.#db.clearTable({ tableName: TABLE_THREADS$1 });
1210
1245
  await this.#db.clearTable({ tableName: TABLE_MESSAGES$1 });
@@ -2270,7 +2305,18 @@ var ScoresConvex = class extends ScoresStorage {
2270
2305
  };
2271
2306
  //#endregion
2272
2307
  //#region src/storage/domains/workflows/index.ts
2273
- var WorkflowsConvex = class extends WorkflowsStorage {
2308
+ var WorkflowsConvex = class WorkflowsConvex extends WorkflowsStorage {
2309
+ /**
2310
+ * Tables `prune()` can clean up. Run ownership records anchor on `updatedAt` (epoch ms), which every
2311
+ * claim, renewal and release refreshes, so a live execution's record is never
2312
+ * older than its renew interval.
2313
+ */
2314
+ static retentionTables = { runOwnership: {
2315
+ table: TABLE_WORKFLOW_RUN_OWNERS,
2316
+ column: "updatedAt",
2317
+ indexed: false,
2318
+ anchorType: "epoch-ms"
2319
+ } };
2274
2320
  #db;
2275
2321
  #client;
2276
2322
  constructor(config) {
@@ -2285,6 +2331,19 @@ var WorkflowsConvex = class extends WorkflowsStorage {
2285
2331
  return true;
2286
2332
  }
2287
2333
  async init() {}
2334
+ async prune(policies, options) {
2335
+ return executeRetentionPrune({
2336
+ domain: "workflows",
2337
+ targets: resolveRetentionTargets({
2338
+ policies,
2339
+ descriptor: WorkflowsConvex.retentionTables,
2340
+ order: ["runOwnership"]
2341
+ }),
2342
+ options,
2343
+ cutoffFor: (target, now) => retentionCutoffMs(target.policy, now),
2344
+ deleteBatch: (_target, cutoff, limit) => pruneRunClaims(this.#client, TABLE_WORKFLOW_RUN_OWNERS, "updatedAt", Number(cutoff), limit)
2345
+ });
2346
+ }
2288
2347
  async dangerouslyClearAll() {
2289
2348
  await this.#db.clearTable({ tableName: TABLE_WORKFLOW_SNAPSHOT$1 });
2290
2349
  await this.#db.clearTable({ tableName: TABLE_WORKFLOW_RUN_OWNERS });