@mastra/convex 1.0.7 → 1.0.8

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,23 @@
1
1
  # @mastra/convex
2
2
 
3
+ ## 1.0.8
4
+
5
+ ### Patch Changes
6
+
7
+ - Add `BackgroundTasksStorage` domain implementation so `@mastra/core` background task execution works with any storage adapter. ([#15307](https://github.com/mastra-ai/mastra/pull/15307))
8
+
9
+ - Updated dependencies [[`20f59b8`](https://github.com/mastra-ai/mastra/commit/20f59b876cf91199efbc49a0e36b391240708f08), [`aba393e`](https://github.com/mastra-ai/mastra/commit/aba393e2da7390c69b80e516a4f153cda6f09376), [`3d83d06`](https://github.com/mastra-ai/mastra/commit/3d83d06f776f00fb5f4163dddd32a030c5c20844), [`e2687a7`](https://github.com/mastra-ai/mastra/commit/e2687a7408790c384563816a9a28ed06735684c9), [`fdd54cf`](https://github.com/mastra-ai/mastra/commit/fdd54cf612a9af876e9fdd85e534454f6e7dd518), [`6315317`](https://github.com/mastra-ai/mastra/commit/63153175fe9a7b224e5be7c209bbebc01dd9b0d5), [`a371ac5`](https://github.com/mastra-ai/mastra/commit/a371ac534aa1bb368a1acf9d8b313378dfdc787e), [`0474c2b`](https://github.com/mastra-ai/mastra/commit/0474c2b2e7c7e1ad8691dca031284841391ff1ef), [`0a5fa1d`](https://github.com/mastra-ai/mastra/commit/0a5fa1d3cb0583889d06687155f26fd7d2edc76c), [`7e0e63e`](https://github.com/mastra-ai/mastra/commit/7e0e63e2e485e84442351f4c7a79a424c83539dc), [`ea43e64`](https://github.com/mastra-ai/mastra/commit/ea43e646dd95d507694b6112b0bf1df22ad552b2), [`f607106`](https://github.com/mastra-ai/mastra/commit/f607106854c6416c4a07d4082604b9f66d047221), [`30456b6`](https://github.com/mastra-ai/mastra/commit/30456b6b08c8fd17e109dd093b73d93b65e83bc5), [`9d11a8c`](https://github.com/mastra-ai/mastra/commit/9d11a8c1c8924eb975a245a5884d40ca1b7e0491), [`9d3b24b`](https://github.com/mastra-ai/mastra/commit/9d3b24b19407ae9c09586cf7766d38dc4dff4a69), [`00d1b16`](https://github.com/mastra-ai/mastra/commit/00d1b16b401199cb294fa23f43336547db4dca9b), [`47cee3e`](https://github.com/mastra-ai/mastra/commit/47cee3e137fe39109cf7fffd2a8cf47b76dc702e), [`62919a6`](https://github.com/mastra-ai/mastra/commit/62919a6ee0fbf3779ad21a97b1ec6696515d5104), [`d246696`](https://github.com/mastra-ai/mastra/commit/d246696139a3144a5b21b042d41c532688e957e1), [`354f9ce`](https://github.com/mastra-ai/mastra/commit/354f9ce1ca6af2074b6a196a23f8ec30012dccca), [`16e34ca`](https://github.com/mastra-ai/mastra/commit/16e34caa98b9a114b17a6125e4e3fd87f169d0d0), [`7020c06`](https://github.com/mastra-ai/mastra/commit/7020c0690b199d9da337f0e805f16948e557922e), [`8786a61`](https://github.com/mastra-ai/mastra/commit/8786a61fa54ba265f85eeff9985ca39863d18bb6), [`9467ea8`](https://github.com/mastra-ai/mastra/commit/9467ea87695749a53dfc041576410ebf9ee7bb67), [`7338d94`](https://github.com/mastra-ai/mastra/commit/7338d949380cf68b095342e8e42610dc51d557c1), [`c80dc16`](https://github.com/mastra-ai/mastra/commit/c80dc16e113e6cc159f510ffde501ad4711b2189), [`af8a57e`](https://github.com/mastra-ai/mastra/commit/af8a57ed9ba9685ad8601d5b71ae3706da6222f9), [`d63ffdb`](https://github.com/mastra-ai/mastra/commit/d63ffdbb2c11e76fe5ea45faab44bc15460f010c), [`47cee3e`](https://github.com/mastra-ai/mastra/commit/47cee3e137fe39109cf7fffd2a8cf47b76dc702e), [`1bd5104`](https://github.com/mastra-ai/mastra/commit/1bd51048b6da93507276d6623e3fd96a9e1a8944), [`e9837b5`](https://github.com/mastra-ai/mastra/commit/e9837b53699e18711b09e0ca010a4106376f2653), [`8f1b280`](https://github.com/mastra-ai/mastra/commit/8f1b280b7fe6999ec654f160cb69c1a8719e7a57), [`92dcf02`](https://github.com/mastra-ai/mastra/commit/92dcf029294210ac91b090900c1a0555a425c57a), [`0fd90a2`](https://github.com/mastra-ai/mastra/commit/0fd90a215caf5fca8099c15a67ca03e4427747a3), [`8fb2405`](https://github.com/mastra-ai/mastra/commit/8fb2405138f2d208b7962ad03f121ca25bcc28c5), [`12df98c`](https://github.com/mastra-ai/mastra/commit/12df98c4904643d9481f5c78f3bed443725b4c96)]:
10
+ - @mastra/core@1.26.0
11
+
12
+ ## 1.0.8-alpha.0
13
+
14
+ ### Patch Changes
15
+
16
+ - Add `BackgroundTasksStorage` domain implementation so `@mastra/core` background task execution works with any storage adapter. ([#15307](https://github.com/mastra-ai/mastra/pull/15307))
17
+
18
+ - Updated dependencies [[`d63ffdb`](https://github.com/mastra-ai/mastra/commit/d63ffdbb2c11e76fe5ea45faab44bc15460f010c)]:
19
+ - @mastra/core@1.25.1-alpha.0
20
+
3
21
  ## 1.0.7
4
22
 
5
23
  ### Patch Changes
@@ -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.0.7"
6
+ version: "1.0.8"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.7",
2
+ "version": "1.0.8",
3
3
  "package": "@mastra/convex",
4
4
  "exports": {
5
5
  "mastraStorage": {
package/dist/index.cjs CHANGED
@@ -3,10 +3,10 @@
3
3
  var chunkPW7BUVK5_cjs = require('./chunk-PW7BUVK5.cjs');
4
4
  var chunkFTVDAP6U_cjs = require('./chunk-FTVDAP6U.cjs');
5
5
  var storage = require('@mastra/core/storage');
6
- var agent = require('@mastra/core/agent');
7
- var error = require('@mastra/core/error');
8
6
  var crypto = require('crypto');
9
7
  var base = require('@mastra/core/base');
8
+ var agent = require('@mastra/core/agent');
9
+ var error = require('@mastra/core/error');
10
10
  var vector = require('@mastra/core/vector');
11
11
 
12
12
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -87,6 +87,7 @@ var ConvexDB = class extends base.MastraBase {
87
87
  super({ name: "convex-db" });
88
88
  this.client = client;
89
89
  }
90
+ client;
90
91
  async hasColumn(_table, _column) {
91
92
  return true;
92
93
  }
@@ -181,7 +182,134 @@ var ConvexDB = class extends base.MastraBase {
181
182
  }
182
183
  };
183
184
 
184
- // src/storage/domains/memory/index.ts
185
+ // src/storage/domains/background-tasks/index.ts
186
+ function serializeJson(v) {
187
+ if (typeof v === "object" && v != null) return JSON.stringify(v);
188
+ return v ?? void 0;
189
+ }
190
+ function toStored(task) {
191
+ return {
192
+ ...task,
193
+ args: serializeJson(task.args),
194
+ result: serializeJson(task.result),
195
+ error: serializeJson(task.error),
196
+ createdAt: task.createdAt.toISOString(),
197
+ startedAt: task.startedAt?.toISOString(),
198
+ completedAt: task.completedAt?.toISOString()
199
+ };
200
+ }
201
+ function fromStored(stored) {
202
+ const parseJson = (val) => {
203
+ if (!val) return void 0;
204
+ try {
205
+ return JSON.parse(val);
206
+ } catch {
207
+ return val;
208
+ }
209
+ };
210
+ return {
211
+ id: stored.id,
212
+ status: stored.status,
213
+ toolName: stored.toolName,
214
+ toolCallId: stored.toolCallId,
215
+ args: parseJson(stored.args) ?? {},
216
+ agentId: stored.agentId,
217
+ threadId: stored.threadId,
218
+ resourceId: stored.resourceId,
219
+ runId: stored.runId,
220
+ result: parseJson(stored.result),
221
+ error: parseJson(stored.error),
222
+ retryCount: stored.retryCount,
223
+ maxRetries: stored.maxRetries,
224
+ timeoutMs: stored.timeoutMs,
225
+ createdAt: new Date(stored.createdAt),
226
+ startedAt: stored.startedAt ? new Date(stored.startedAt) : void 0,
227
+ completedAt: stored.completedAt ? new Date(stored.completedAt) : void 0
228
+ };
229
+ }
230
+ var BackgroundTasksConvex = class extends storage.BackgroundTasksStorage {
231
+ #db;
232
+ constructor(config) {
233
+ super();
234
+ const client = resolveConvexConfig(config);
235
+ this.#db = new ConvexDB(client);
236
+ }
237
+ async dangerouslyClearAll() {
238
+ await this.#db.clearTable({ tableName: storage.TABLE_BACKGROUND_TASKS });
239
+ }
240
+ async createTask(task) {
241
+ await this.#db.insert({ tableName: storage.TABLE_BACKGROUND_TASKS, record: toStored(task) });
242
+ }
243
+ async updateTask(taskId, update) {
244
+ const existing = await this.getTask(taskId);
245
+ if (!existing) return;
246
+ const merged = { ...existing };
247
+ if ("status" in update) merged.status = update.status;
248
+ if ("result" in update) merged.result = update.result;
249
+ if ("error" in update) merged.error = update.error;
250
+ if ("retryCount" in update) merged.retryCount = update.retryCount;
251
+ if ("startedAt" in update) merged.startedAt = update.startedAt;
252
+ if ("completedAt" in update) merged.completedAt = update.completedAt;
253
+ await this.#db.deleteMany(storage.TABLE_BACKGROUND_TASKS, [taskId]);
254
+ await this.#db.insert({ tableName: storage.TABLE_BACKGROUND_TASKS, record: toStored(merged) });
255
+ }
256
+ async getTask(taskId) {
257
+ const data = await this.#db.load({ tableName: storage.TABLE_BACKGROUND_TASKS, keys: { id: taskId } });
258
+ return data ? fromStored(data) : null;
259
+ }
260
+ async listTasks(filter) {
261
+ const all = await this.#db.queryTable(storage.TABLE_BACKGROUND_TASKS);
262
+ let tasks = all.map(fromStored);
263
+ if (filter.status) {
264
+ const s = Array.isArray(filter.status) ? filter.status : [filter.status];
265
+ tasks = tasks.filter((t) => s.includes(t.status));
266
+ }
267
+ if (filter.agentId) tasks = tasks.filter((t) => t.agentId === filter.agentId);
268
+ if (filter.threadId) tasks = tasks.filter((t) => t.threadId === filter.threadId);
269
+ if (filter.toolName) tasks = tasks.filter((t) => t.toolName === filter.toolName);
270
+ if (filter.runId) tasks = tasks.filter((t) => t.runId === filter.runId);
271
+ const dateCol = filter.dateFilterBy ?? "createdAt";
272
+ if (filter.fromDate) {
273
+ tasks = tasks.filter((t) => {
274
+ const val = t[dateCol];
275
+ return val != null && val >= filter.fromDate;
276
+ });
277
+ }
278
+ if (filter.toDate) {
279
+ tasks = tasks.filter((t) => {
280
+ const val = t[dateCol];
281
+ return val != null && val < filter.toDate;
282
+ });
283
+ }
284
+ const orderBy = filter.orderBy ?? "createdAt";
285
+ const dir = filter.orderDirection === "desc" ? -1 : 1;
286
+ tasks.sort((a, b) => ((a[orderBy]?.getTime() ?? 0) - (b[orderBy]?.getTime() ?? 0)) * dir);
287
+ const total = tasks.length;
288
+ if (filter.page != null && filter.perPage != null) {
289
+ const start = filter.page * filter.perPage;
290
+ tasks = tasks.slice(start, start + filter.perPage);
291
+ } else if (filter.perPage != null) {
292
+ tasks = tasks.slice(0, filter.perPage);
293
+ }
294
+ return { tasks, total };
295
+ }
296
+ async deleteTask(taskId) {
297
+ await this.#db.deleteMany(storage.TABLE_BACKGROUND_TASKS, [taskId]);
298
+ }
299
+ async deleteTasks(filter) {
300
+ const { tasks } = await this.listTasks(filter);
301
+ const taskIds = tasks.map((t) => t.id);
302
+ await this.#db.deleteMany(storage.TABLE_BACKGROUND_TASKS, taskIds);
303
+ }
304
+ async getRunningCount() {
305
+ const { total } = await this.listTasks({ status: "running" });
306
+ return total;
307
+ }
308
+ async getRunningCountByAgent(agentId) {
309
+ const { total } = await this.listTasks({ status: "running", agentId });
310
+ return total;
311
+ }
312
+ };
185
313
  var MemoryConvex = class extends storage.MemoryStorage {
186
314
  #db;
187
315
  constructor(config) {
@@ -939,7 +1067,8 @@ var ConvexStore = class extends storage.MastraCompositeStore {
939
1067
  this.stores = {
940
1068
  memory,
941
1069
  workflows,
942
- scores
1070
+ scores,
1071
+ backgroundTasks: new BackgroundTasksConvex(domainConfig)
943
1072
  };
944
1073
  }
945
1074
  };