@mastra/convex 1.7.5-alpha.1 → 1.7.6-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.
@@ -1,4 +1,3 @@
1
- //#region src/memory/index.d.ts
2
1
  /**
3
2
  * Shared rules for observational memory lifecycle writes. Every storage adapter applies
4
3
  * these inside its own atomic section (lock, transaction, or conditional update), so the
@@ -9,18 +8,18 @@
9
8
  * into the table schema they get from `@mastra/core`, so the columns exist even when the
10
9
  * installed core predates them.
11
10
  */
12
- declare const OBSERVATIONAL_MEMORY_LIFECYCLE_COLUMNS: {
11
+ export declare const OBSERVATIONAL_MEMORY_LIFECYCLE_COLUMNS: {
13
12
  readonly supersededBy: {
14
13
  readonly type: 'text';
15
14
  readonly nullable: true;
16
15
  };
17
16
  };
18
17
  /** `schema` plus {@link OBSERVATIONAL_MEMORY_LIFECYCLE_COLUMNS}; `undefined` when `schema` is. */
19
- declare function withObservationalMemoryLifecycleColumns<T extends object>(schema: T | undefined): (T & typeof OBSERVATIONAL_MEMORY_LIFECYCLE_COLUMNS) | undefined;
18
+ export declare function withObservationalMemoryLifecycleColumns<T extends object>(schema: T | undefined): (T & typeof OBSERVATIONAL_MEMORY_LIFECYCLE_COLUMNS) | undefined;
20
19
  /**
21
20
  * Result of `commitActiveObservations`.
22
21
  */
23
- interface UpdateActiveObservationsResult {
22
+ export interface UpdateActiveObservationsResult {
24
23
  /** Whether the observations were written. */
25
24
  applied: boolean;
26
25
  /**
@@ -38,14 +37,14 @@ interface UpdateActiveObservationsResult {
38
37
  * the head's cursor. Chunks carry `lastObservedAt = max message time + 1ms`, so a chunk is
39
38
  * wholly covered iff `head.lastObservedAt >= chunk.lastObservedAt - 1ms`.
40
39
  */
41
- interface UpdateBufferedObservationsResult {
40
+ export interface UpdateBufferedObservationsResult {
42
41
  /** Whether the chunk was stored. */
43
42
  persisted: boolean;
44
43
  /** The record the chunk was written to (or would have been written to). */
45
44
  recordId: string;
46
45
  }
47
46
  /** The fields of an observational memory record that decide head order. */
48
- interface ObservationalMemoryHeadOrderFields {
47
+ export interface ObservationalMemoryHeadOrderFields {
49
48
  generationCount: number;
50
49
  createdAt: Date | string;
51
50
  id: string;
@@ -54,16 +53,16 @@ interface ObservationalMemoryHeadOrderFields {
54
53
  * Canonical head order: `generationCount DESC, createdAt ASC, id ASC`.
55
54
  * Returns a negative number when `a` sorts before `b` (i.e. `a` is the better head candidate).
56
55
  */
57
- declare function compareObservationalMemoryHeadOrder(a: ObservationalMemoryHeadOrderFields, b: ObservationalMemoryHeadOrderFields): number;
56
+ export declare function compareObservationalMemoryHeadOrder(a: ObservationalMemoryHeadOrderFields, b: ObservationalMemoryHeadOrderFields): number;
58
57
  /**
59
58
  * A buffered chunk stores `lastObservedAt = max message time + 1ms`. It is wholly covered
60
59
  * (every message it observed is already at or before the cursor) iff
61
60
  * `cursor >= chunk.lastObservedAt - 1ms`.
62
61
  */
63
- declare function isBufferedChunkCoveredByCursor(chunkLastObservedAt: Date | string, cursor: Date | string | null | undefined): boolean;
62
+ export declare function isBufferedChunkCoveredByCursor(chunkLastObservedAt: Date | string, cursor: Date | string | null | undefined): boolean;
64
63
  /** The later of two cursors; `undefined` only when both are absent. */
65
- declare function maxObservationCursor(a: Date | string | null | undefined, b: Date | string | null | undefined): Date | undefined;
66
- interface ReflectionTextPlan {
64
+ export declare function maxObservationCursor(a: Date | string | null | undefined, b: Date | string | null | undefined): Date | undefined;
65
+ export interface ReflectionTextPlan {
67
66
  /** `equal`: stored text equals the snapshot. `append`: observations were appended after the snapshot. */
68
67
  mode: 'equal' | 'append';
69
68
  observations: string;
@@ -78,7 +77,7 @@ interface ReflectionTextPlan {
78
77
  * after the reflection, and its tokens are added.
79
78
  * - Anything else (a non-append rewrite): `null` — the reflection must not be applied.
80
79
  */
81
- declare function planReflectionGenerationText(input: {
80
+ export declare function planReflectionGenerationText(input: {
82
81
  storedObservations: string;
83
82
  storedObservationTokenCount: number;
84
83
  snapshotObservations: string;
@@ -91,12 +90,10 @@ declare function planReflectionGenerationText(input: {
91
90
  * Callers of `updateActiveObservations` (which resolves `void`) can't see a commit result, so a
92
91
  * write that was not applied throws instead of resolving as if it had committed.
93
92
  */
94
- declare function assertActiveObservationsApplied(result: UpdateActiveObservationsResult, id: string): void;
93
+ export declare function assertActiveObservationsApplied(result: UpdateActiveObservationsResult, id: string): void;
95
94
  /**
96
95
  * Whether the stored text can still accept a reflection built from `snapshot`
97
96
  * (equal, or only appended to since).
98
97
  */
99
- declare function isAppendOnlySince(storedObservations: string, snapshotObservations: string): boolean;
100
- //#endregion
101
- export { OBSERVATIONAL_MEMORY_LIFECYCLE_COLUMNS, ObservationalMemoryHeadOrderFields, ReflectionTextPlan, UpdateActiveObservationsResult, UpdateBufferedObservationsResult, assertActiveObservationsApplied, compareObservationalMemoryHeadOrder, isAppendOnlySince, isBufferedChunkCoveredByCursor, maxObservationCursor, planReflectionGenerationText, withObservationalMemoryLifecycleColumns };
98
+ export declare function isAppendOnlySince(storedObservations: string, snapshotObservations: string): boolean;
102
99
  //# sourceMappingURL=index.d.ts.map
@@ -3,7 +3,7 @@ name: mastra-convex
3
3
  description: Documentation for @mastra/convex. Use when working with @mastra/convex APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/convex"
6
- version: "1.7.5-alpha.1"
6
+ version: "1.7.6-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.7.5-alpha.1",
2
+ "version": "1.7.6-alpha.0",
3
3
  "package": "@mastra/convex",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_server = require("./server-BxQKtmhb.cjs");
2
+ const require_server = require("./server-BwpzJLxa.cjs");
3
3
  const require_schema = require("./schema.cjs");
4
4
  let _mastra_core_cache = require("@mastra/core/cache");
5
5
  let _mastra_core_storage = require("@mastra/core/storage");
@@ -8,7 +8,7 @@ let _mastra_core_agent = require("@mastra/core/agent");
8
8
  let _mastra_core_error = require("@mastra/core/error");
9
9
  let _mastra_core_vector = require("@mastra/core/vector");
10
10
  let _mastra_core_storage_constants = require("@mastra/core/storage/constants");
11
- //#region src/cache/client.ts
11
+ // src/cache/client.ts
12
12
  const DEFAULT_CACHE_FUNCTION = "mastra/cache:handle";
13
13
  const DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
14
14
  const trimTrailingSlashes = (value) => {
@@ -86,8 +86,7 @@ var ConvexCacheClient = class {
86
86
  return result;
87
87
  }
88
88
  };
89
- //#endregion
90
- //#region src/cache/index.ts
89
+ // src/cache/index.ts
91
90
  const DEFAULT_KEY_PREFIX = "mastra:cache:";
92
91
  const DEFAULT_TTL_MS = 3e5;
93
92
  const MAX_CACHE_OPERATION_BATCHES = 1e3;
@@ -175,8 +174,7 @@ var ConvexServerCache = class extends _mastra_core_cache.MastraServerCache {
175
174
  }));
176
175
  }
177
176
  };
178
- //#endregion
179
- //#region src/storage/client.ts
177
+ // src/storage/client.ts
180
178
  const DEFAULT_STORAGE_FUNCTION = "mastra/storage:handle";
181
179
  var ConvexAdminClient = class {
182
180
  deploymentUrl;
@@ -253,8 +251,7 @@ var ConvexAdminClient = class {
253
251
  return result;
254
252
  }
255
253
  };
256
- //#endregion
257
- //#region src/storage/run-fencing.ts
254
+ // src/storage/run-fencing.ts
258
255
  const READ_OPS = /* @__PURE__ */ new Set([
259
256
  "load",
260
257
  "loadMany",
@@ -412,16 +409,14 @@ async function pruneRunClaims(client, tableName, column, cutoff, limit) {
412
409
  }, "prune");
413
410
  return result;
414
411
  }
415
- //#endregion
416
- //#region src/storage/types.ts
412
+ // src/storage/types.ts
417
413
  /**
418
414
  * Observational memory table name. Defined locally (not value-imported from
419
415
  * core) following the mongodb/pg convention: core exports the constant, but
420
416
  * OM is optional and the constant is absent from older cores in the peer range.
421
417
  */
422
418
  const TABLE_OBSERVATIONAL_MEMORY$1 = "mastra_observational_memory";
423
- //#endregion
424
- //#region src/storage/db/index.ts
419
+ // src/storage/db/index.ts
425
420
  const LOAD_MANY_REQUEST_BATCH_SIZE = 10;
426
421
  /**
427
422
  * Resolves ConvexDomainConfig to a ConvexAdminClient.
@@ -741,8 +736,7 @@ var ConvexDB = class ConvexDB extends _mastra_core_base.MastraBase {
741
736
  return normalized;
742
737
  }
743
738
  };
744
- //#endregion
745
- //#region src/storage/domains/background-tasks/index.ts
739
+ // src/storage/domains/background-tasks/index.ts
746
740
  function serializeJson$1(v) {
747
741
  if (v === void 0 || v === null) return null;
748
742
  return JSON.stringify(v);
@@ -956,8 +950,7 @@ var BackgroundTasksConvex = class extends _mastra_core_storage.BackgroundTasksSt
956
950
  return total;
957
951
  }
958
952
  };
959
- //#endregion
960
- //#region src/storage/domains/channels/index.ts
953
+ // src/storage/domains/channels/index.ts
961
954
  const statusPriority = {
962
955
  active: 0,
963
956
  pending: 1,
@@ -1094,8 +1087,7 @@ var ChannelsConvex = class extends _mastra_core_storage.ChannelsStorage {
1094
1087
  await this.#db.deleteMany(_mastra_core_storage.TABLE_CHANNEL_CONFIG, [platform]);
1095
1088
  }
1096
1089
  };
1097
- //#endregion
1098
- //#region ../../packages/_internal-core/dist/memory/index.js
1090
+ // ../../packages/_internal-core/dist/memory/index.js
1099
1091
  /**
1100
1092
  * Backs `updateActiveObservations` in adapters that implement `commitActiveObservations`.
1101
1093
  * Callers of `updateActiveObservations` (which resolves `void`) can't see a commit result, so a
@@ -1105,8 +1097,7 @@ function assertActiveObservationsApplied(result, id) {
1105
1097
  if (result.applied) return;
1106
1098
  throw new Error(result.reason === "retired" ? `Observational memory record ${id} was superseded by a newer generation; observations were not written` : `Observational memory record ${id} changed since the observations were composed; observations were not written`);
1107
1099
  }
1108
- //#endregion
1109
- //#region src/storage/domains/memory/index.ts
1100
+ // src/storage/domains/memory/index.ts
1110
1101
  function parseStoredThread(row) {
1111
1102
  return {
1112
1103
  ...row,
@@ -1230,13 +1221,14 @@ var MemoryConvex = class MemoryConvex extends _mastra_core_storage.MemoryStorage
1230
1221
  }
1231
1222
  async init() {}
1232
1223
  async prune(policies, options) {
1224
+ const targets = (0, _mastra_core_storage.resolveRetentionTargets)({
1225
+ policies,
1226
+ descriptor: MemoryConvex.retentionTables,
1227
+ order: ["runFences"]
1228
+ });
1233
1229
  return (0, _mastra_core_storage.executeRetentionPrune)({
1234
1230
  domain: "memory",
1235
- targets: (0, _mastra_core_storage.resolveRetentionTargets)({
1236
- policies,
1237
- descriptor: MemoryConvex.retentionTables,
1238
- order: ["runFences"]
1239
- }),
1231
+ targets,
1240
1232
  options,
1241
1233
  cutoffFor: (target, now) => (0, _mastra_core_storage.retentionCutoffMs)(target.policy, now),
1242
1234
  deleteBatch: (_target, cutoff, limit) => pruneRunClaims(this.#client, _mastra_core_storage.TABLE_MEMORY_RUN_FENCES, "retiredAt", Number(cutoff), limit)
@@ -1992,8 +1984,7 @@ var MemoryConvex = class MemoryConvex extends _mastra_core_storage.MemoryStorage
1992
1984
  });
1993
1985
  }
1994
1986
  };
1995
- //#endregion
1996
- //#region src/storage/domains/schedules/index.ts
1987
+ // src/storage/domains/schedules/index.ts
1997
1988
  const SCHEDULE_LIST_LIMIT = 8e3;
1998
1989
  function serializeJson(value) {
1999
1990
  return JSON.stringify(value);
@@ -2210,8 +2201,7 @@ var SchedulesConvex = class extends _mastra_core_storage.SchedulesStorage {
2210
2201
  })).map(recordToTrigger);
2211
2202
  }
2212
2203
  };
2213
- //#endregion
2214
- //#region src/storage/domains/scores/index.ts
2204
+ // src/storage/domains/scores/index.ts
2215
2205
  var ScoresConvex = class extends _mastra_core_storage.ScoresStorage {
2216
2206
  #db;
2217
2207
  constructor(config) {
@@ -2305,8 +2295,7 @@ var ScoresConvex = class extends _mastra_core_storage.ScoresStorage {
2305
2295
  };
2306
2296
  }
2307
2297
  };
2308
- //#endregion
2309
- //#region src/storage/domains/workflows/index.ts
2298
+ // src/storage/domains/workflows/index.ts
2310
2299
  var WorkflowsConvex = class WorkflowsConvex extends _mastra_core_storage.WorkflowsStorage {
2311
2300
  /**
2312
2301
  * Tables `prune()` can clean up. Run ownership records anchor on `updatedAt` (epoch ms), which every
@@ -2334,13 +2323,14 @@ var WorkflowsConvex = class WorkflowsConvex extends _mastra_core_storage.Workflo
2334
2323
  }
2335
2324
  async init() {}
2336
2325
  async prune(policies, options) {
2326
+ const targets = (0, _mastra_core_storage.resolveRetentionTargets)({
2327
+ policies,
2328
+ descriptor: WorkflowsConvex.retentionTables,
2329
+ order: ["runOwnership"]
2330
+ });
2337
2331
  return (0, _mastra_core_storage.executeRetentionPrune)({
2338
2332
  domain: "workflows",
2339
- targets: (0, _mastra_core_storage.resolveRetentionTargets)({
2340
- policies,
2341
- descriptor: WorkflowsConvex.retentionTables,
2342
- order: ["runOwnership"]
2343
- }),
2333
+ targets,
2344
2334
  options,
2345
2335
  cutoffFor: (target, now) => (0, _mastra_core_storage.retentionCutoffMs)(target.policy, now),
2346
2336
  deleteBatch: (_target, cutoff, limit) => pruneRunClaims(this.#client, _mastra_core_storage.TABLE_WORKFLOW_RUN_OWNERS, "updatedAt", Number(cutoff), limit)
@@ -2499,8 +2489,7 @@ var WorkflowsConvex = class WorkflowsConvex extends _mastra_core_storage.Workflo
2499
2489
  return JSON.parse(JSON.stringify(run.snapshot));
2500
2490
  }
2501
2491
  };
2502
- //#endregion
2503
- //#region src/storage/index.ts
2492
+ // src/storage/index.ts
2504
2493
  /**
2505
2494
  * Type guard for pre-configured client config
2506
2495
  */
@@ -2546,8 +2535,7 @@ var ConvexStore = class extends _mastra_core_storage.MastraCompositeStore {
2546
2535
  };
2547
2536
  }
2548
2537
  };
2549
- //#endregion
2550
- //#region src/vector/index.ts
2538
+ // src/vector/index.ts
2551
2539
  const INDEX_METADATA_TABLE = "mastra_vector_indexes";
2552
2540
  const VECTOR_QUERY_PAGE_SIZE = 256;
2553
2541
  var ConvexVector = class extends _mastra_core_vector.MastraVector {
@@ -2815,8 +2803,7 @@ function cosineSimilarity(a, b) {
2815
2803
  if (magA === 0 || magB === 0) return -1;
2816
2804
  return dot / (Math.sqrt(magA) * Math.sqrt(magB));
2817
2805
  }
2818
- //#endregion
2819
- //#region src/vector/native.ts
2806
+ // src/vector/native.ts
2820
2807
  const DEFAULT_VECTOR_INDEX = "by_embedding";
2821
2808
  const DEFAULT_ID_FIELD = "id";
2822
2809
  const DEFAULT_ID_INDEX = "by_record_id";
@@ -3001,23 +2988,72 @@ var ConvexNativeVector = class extends _mastra_core_vector.MastraVector {
3001
2988
  return typeof metadata === "object" && metadata !== null && !Array.isArray(metadata);
3002
2989
  }
3003
2990
  };
3004
- //#endregion
3005
2991
  exports.ConvexCacheClient = ConvexCacheClient;
3006
2992
  exports.ConvexNativeVector = ConvexNativeVector;
3007
2993
  exports.ConvexServerCache = ConvexServerCache;
3008
2994
  exports.ConvexStore = ConvexStore;
3009
2995
  exports.ConvexVector = ConvexVector;
3010
- exports.TABLE_BACKGROUND_TASKS = _mastra_core_storage_constants.TABLE_BACKGROUND_TASKS;
3011
- exports.TABLE_CHANNEL_CONFIG = _mastra_core_storage_constants.TABLE_CHANNEL_CONFIG;
3012
- exports.TABLE_CHANNEL_INSTALLATIONS = _mastra_core_storage_constants.TABLE_CHANNEL_INSTALLATIONS;
3013
- exports.TABLE_MESSAGES = _mastra_core_storage_constants.TABLE_MESSAGES;
2996
+ Object.defineProperty(exports, "TABLE_BACKGROUND_TASKS", {
2997
+ enumerable: true,
2998
+ get: function() {
2999
+ return _mastra_core_storage_constants.TABLE_BACKGROUND_TASKS;
3000
+ }
3001
+ });
3002
+ Object.defineProperty(exports, "TABLE_CHANNEL_CONFIG", {
3003
+ enumerable: true,
3004
+ get: function() {
3005
+ return _mastra_core_storage_constants.TABLE_CHANNEL_CONFIG;
3006
+ }
3007
+ });
3008
+ Object.defineProperty(exports, "TABLE_CHANNEL_INSTALLATIONS", {
3009
+ enumerable: true,
3010
+ get: function() {
3011
+ return _mastra_core_storage_constants.TABLE_CHANNEL_INSTALLATIONS;
3012
+ }
3013
+ });
3014
+ Object.defineProperty(exports, "TABLE_MESSAGES", {
3015
+ enumerable: true,
3016
+ get: function() {
3017
+ return _mastra_core_storage_constants.TABLE_MESSAGES;
3018
+ }
3019
+ });
3014
3020
  exports.TABLE_OBSERVATIONAL_MEMORY = require_schema.TABLE_OBSERVATIONAL_MEMORY;
3015
- exports.TABLE_RESOURCES = _mastra_core_storage_constants.TABLE_RESOURCES;
3016
- exports.TABLE_SCHEDULES = _mastra_core_storage_constants.TABLE_SCHEDULES;
3017
- exports.TABLE_SCHEDULE_TRIGGERS = _mastra_core_storage_constants.TABLE_SCHEDULE_TRIGGERS;
3018
- exports.TABLE_SCORERS = _mastra_core_storage_constants.TABLE_SCORERS;
3019
- exports.TABLE_THREADS = _mastra_core_storage_constants.TABLE_THREADS;
3020
- exports.TABLE_WORKFLOW_SNAPSHOT = _mastra_core_storage_constants.TABLE_WORKFLOW_SNAPSHOT;
3021
+ Object.defineProperty(exports, "TABLE_RESOURCES", {
3022
+ enumerable: true,
3023
+ get: function() {
3024
+ return _mastra_core_storage_constants.TABLE_RESOURCES;
3025
+ }
3026
+ });
3027
+ Object.defineProperty(exports, "TABLE_SCHEDULES", {
3028
+ enumerable: true,
3029
+ get: function() {
3030
+ return _mastra_core_storage_constants.TABLE_SCHEDULES;
3031
+ }
3032
+ });
3033
+ Object.defineProperty(exports, "TABLE_SCHEDULE_TRIGGERS", {
3034
+ enumerable: true,
3035
+ get: function() {
3036
+ return _mastra_core_storage_constants.TABLE_SCHEDULE_TRIGGERS;
3037
+ }
3038
+ });
3039
+ Object.defineProperty(exports, "TABLE_SCORERS", {
3040
+ enumerable: true,
3041
+ get: function() {
3042
+ return _mastra_core_storage_constants.TABLE_SCORERS;
3043
+ }
3044
+ });
3045
+ Object.defineProperty(exports, "TABLE_THREADS", {
3046
+ enumerable: true,
3047
+ get: function() {
3048
+ return _mastra_core_storage_constants.TABLE_THREADS;
3049
+ }
3050
+ });
3051
+ Object.defineProperty(exports, "TABLE_WORKFLOW_SNAPSHOT", {
3052
+ enumerable: true,
3053
+ get: function() {
3054
+ return _mastra_core_storage_constants.TABLE_WORKFLOW_SNAPSHOT;
3055
+ }
3056
+ });
3021
3057
  exports.defineMastraNativeVectorTable = require_schema.defineMastraNativeVectorTable;
3022
3058
  exports.mastraBackgroundTasksTable = require_schema.mastraBackgroundTasksTable;
3023
3059
  exports.mastraCache = require_server.mastraCache;