@mastra/convex 0.0.0-new-button-export-20251219133013 → 0.0.0-salesman-20260127182805

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,6 +1,6 @@
1
1
  export { mastraStorage } from './chunk-KSAPIIEJ.js';
2
- export { TABLE_MESSAGES, TABLE_RESOURCES, TABLE_SCORERS, TABLE_THREADS, TABLE_WORKFLOW_SNAPSHOT, mastraDocumentsTable, mastraMessagesTable, mastraResourcesTable, mastraScoresTable, mastraThreadsTable, mastraVectorIndexesTable, mastraVectorsTable, mastraWorkflowSnapshotsTable } from './chunk-PKUUSREO.js';
3
- import { MastraStorage, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_RESOURCES, createStorageErrorId, normalizePerPage, calculatePagination, safelyParseJSON, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, ScoresStorage, TABLE_SCORERS } from '@mastra/core/storage';
2
+ export { TABLE_MESSAGES, TABLE_RESOURCES, TABLE_SCORERS, TABLE_THREADS, TABLE_WORKFLOW_SNAPSHOT, mastraDocumentsTable, mastraMessagesTable, mastraResourcesTable, mastraScoresTable, mastraThreadsTable, mastraVectorIndexesTable, mastraVectorsTable, mastraWorkflowSnapshotsTable } from './chunk-G5FLGAPE.js';
3
+ import { MastraCompositeStore, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_RESOURCES, createStorageErrorId, normalizePerPage, calculatePagination, filterByDateRange, safelyParseJSON, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, ScoresStorage, TABLE_SCORERS } from '@mastra/core/storage';
4
4
  import { MessageList } from '@mastra/core/agent';
5
5
  import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
6
6
  import crypto from 'crypto';
@@ -84,6 +84,19 @@ var ConvexDB = class extends MastraBase {
84
84
  async hasColumn(_table, _column) {
85
85
  return true;
86
86
  }
87
+ async createTable({
88
+ tableName,
89
+ schema: _schema
90
+ }) {
91
+ this.logger.debug(`ConvexDB: createTable called for ${tableName} (schema managed server-side)`);
92
+ }
93
+ async alterTable({
94
+ tableName,
95
+ schema: _schema,
96
+ ifNotExists: _ifNotExists
97
+ }) {
98
+ this.logger.debug(`ConvexDB: alterTable called for ${tableName} (schema managed server-side)`);
99
+ }
87
100
  async clearTable({ tableName }) {
88
101
  let hasMore = true;
89
102
  while (hasMore) {
@@ -235,18 +248,41 @@ var MemoryConvex = class extends MemoryStorage {
235
248
  );
236
249
  await this.#db.deleteMany(TABLE_THREADS, [threadId]);
237
250
  }
238
- async listThreadsByResourceId(args) {
239
- const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
251
+ async listThreads(args) {
252
+ const { page = 0, perPage: perPageInput, orderBy, filter } = args;
253
+ try {
254
+ this.validatePaginationInput(page, perPageInput ?? 100);
255
+ } catch (error) {
256
+ throw new MastraError(
257
+ {
258
+ id: createStorageErrorId("CONVEX", "LIST_THREADS", "INVALID_PAGE"),
259
+ domain: ErrorDomain.STORAGE,
260
+ category: ErrorCategory.USER,
261
+ details: { page, ...perPageInput !== void 0 && { perPage: perPageInput } }
262
+ },
263
+ error instanceof Error ? error : new Error("Invalid pagination parameters")
264
+ );
265
+ }
240
266
  const perPage = normalizePerPage(perPageInput, 100);
241
267
  const { field, direction } = this.parseOrderBy(orderBy);
242
268
  const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
243
- const rows = await this.#db.queryTable(TABLE_THREADS, [{ field: "resourceId", value: resourceId }]);
244
- const threads = rows.map((row) => ({
269
+ const queryFilters = [];
270
+ if (filter?.resourceId) {
271
+ queryFilters.push({ field: "resourceId", value: filter.resourceId });
272
+ }
273
+ const rows = await this.#db.queryTable(TABLE_THREADS, queryFilters);
274
+ let threads = rows.map((row) => ({
245
275
  ...row,
246
276
  metadata: typeof row.metadata === "string" ? JSON.parse(row.metadata) : row.metadata,
247
277
  createdAt: new Date(row.createdAt),
248
278
  updatedAt: new Date(row.updatedAt)
249
279
  }));
280
+ if (filter?.metadata && Object.keys(filter.metadata).length > 0) {
281
+ threads = threads.filter((thread) => {
282
+ if (!thread.metadata) return false;
283
+ return Object.entries(filter.metadata).every(([key, value]) => thread.metadata[key] === value);
284
+ });
285
+ }
250
286
  threads.sort((a, b) => {
251
287
  const aValue = a[field];
252
288
  const bValue = b[field];
@@ -289,15 +325,7 @@ var MemoryConvex = class extends MemoryStorage {
289
325
  if (resourceId) {
290
326
  rows = rows.filter((row) => row.resourceId === resourceId);
291
327
  }
292
- if (filter?.dateRange) {
293
- const { start, end } = filter.dateRange;
294
- rows = rows.filter((row) => {
295
- const created = new Date(row.createdAt).getTime();
296
- if (start && created < start.getTime()) return false;
297
- if (end && created > end.getTime()) return false;
298
- return true;
299
- });
300
- }
328
+ rows = filterByDateRange(rows, (row) => new Date(row.createdAt), filter?.dateRange);
301
329
  rows.sort((a, b) => {
302
330
  const aValue = field === "createdAt" || field === "updatedAt" ? new Date(a[field]).getTime() : a[field];
303
331
  const bValue = field === "createdAt" || field === "updatedAt" ? new Date(b[field]).getTime() : b[field];
@@ -853,143 +881,23 @@ var WorkflowsConvex = class extends WorkflowsStorage {
853
881
  };
854
882
 
855
883
  // src/storage/index.ts
856
- var ConvexStore = class extends MastraStorage {
857
- memory;
858
- workflows;
859
- scores;
884
+ var isClientConfig = (config) => {
885
+ return "client" in config;
886
+ };
887
+ var ConvexStore = class extends MastraCompositeStore {
860
888
  constructor(config) {
861
889
  super({ id: config.id, name: config.name ?? "ConvexStore", disableInit: config.disableInit });
862
- const client = new ConvexAdminClient(config);
890
+ const client = isClientConfig(config) ? config.client : new ConvexAdminClient(config);
863
891
  const domainConfig = { client };
864
- this.memory = new MemoryConvex(domainConfig);
865
- this.workflows = new WorkflowsConvex(domainConfig);
866
- this.scores = new ScoresConvex(domainConfig);
892
+ const memory = new MemoryConvex(domainConfig);
893
+ const workflows = new WorkflowsConvex(domainConfig);
894
+ const scores = new ScoresConvex(domainConfig);
867
895
  this.stores = {
868
- memory: this.memory,
869
- workflows: this.workflows,
870
- scores: this.scores
871
- };
872
- }
873
- get supports() {
874
- return {
875
- selectByIncludeResourceScope: true,
876
- resourceWorkingMemory: true,
877
- hasColumn: false,
878
- createTable: false,
879
- deleteMessages: true,
880
- observabilityInstance: false,
881
- listScoresBySpan: false
896
+ memory,
897
+ workflows,
898
+ scores
882
899
  };
883
900
  }
884
- async getThreadById({ threadId }) {
885
- return this.memory.getThreadById({ threadId });
886
- }
887
- async saveThread({ thread }) {
888
- return this.memory.saveThread({ thread });
889
- }
890
- async updateThread({
891
- id,
892
- title,
893
- metadata
894
- }) {
895
- return this.memory.updateThread({ id, title, metadata });
896
- }
897
- async deleteThread({ threadId }) {
898
- await this.memory.deleteThread({ threadId });
899
- }
900
- async listMessages(args) {
901
- return this.memory.listMessages(args);
902
- }
903
- async listMessagesById({ messageIds }) {
904
- return this.memory.listMessagesById({ messageIds });
905
- }
906
- async saveMessages(args) {
907
- return this.memory.saveMessages(args);
908
- }
909
- async updateMessages({
910
- messages
911
- }) {
912
- return this.memory.updateMessages({ messages });
913
- }
914
- async deleteMessages(messageIds) {
915
- await this.memory.deleteMessages(messageIds);
916
- }
917
- async listThreadsByResourceId(args) {
918
- return this.memory.listThreadsByResourceId(args);
919
- }
920
- async getResourceById({ resourceId }) {
921
- return this.memory.getResourceById({ resourceId });
922
- }
923
- async saveResource({ resource }) {
924
- return this.memory.saveResource({ resource });
925
- }
926
- async updateResource({
927
- resourceId,
928
- workingMemory,
929
- metadata
930
- }) {
931
- return this.memory.updateResource({ resourceId, workingMemory, metadata });
932
- }
933
- async updateWorkflowResults(params) {
934
- return this.workflows.updateWorkflowResults(params);
935
- }
936
- async updateWorkflowState(params) {
937
- return this.workflows.updateWorkflowState(params);
938
- }
939
- async persistWorkflowSnapshot({
940
- workflowName,
941
- runId,
942
- resourceId,
943
- snapshot
944
- }) {
945
- await this.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
946
- }
947
- async loadWorkflowSnapshot({
948
- workflowName,
949
- runId
950
- }) {
951
- return this.workflows.loadWorkflowSnapshot({ workflowName, runId });
952
- }
953
- async listWorkflowRuns(args) {
954
- return this.workflows.listWorkflowRuns(args);
955
- }
956
- async getWorkflowRunById({
957
- runId,
958
- workflowName
959
- }) {
960
- return this.workflows.getWorkflowRunById({ runId, workflowName });
961
- }
962
- async deleteWorkflowRunById({ runId, workflowName }) {
963
- return this.workflows.deleteWorkflowRunById({ runId, workflowName });
964
- }
965
- async getScoreById({ id }) {
966
- return this.scores.getScoreById({ id });
967
- }
968
- async saveScore(score) {
969
- return this.scores.saveScore(score);
970
- }
971
- async listScoresByScorerId({
972
- scorerId,
973
- pagination,
974
- entityId,
975
- entityType,
976
- source
977
- }) {
978
- return this.scores.listScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
979
- }
980
- async listScoresByRunId({
981
- runId,
982
- pagination
983
- }) {
984
- return this.scores.listScoresByRunId({ runId, pagination });
985
- }
986
- async listScoresByEntityId({
987
- entityId,
988
- entityType,
989
- pagination
990
- }) {
991
- return this.scores.listScoresByEntityId({ entityId, entityType, pagination });
992
- }
993
901
  };
994
902
  var INDEX_METADATA_TABLE = "mastra_vector_indexes";
995
903
  var ConvexVector = class extends MastraVector {