@mastra/client-js 1.13.4 → 1.13.5-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
@@ -5662,6 +5662,79 @@ var MastraClient = class extends BaseResource {
5662
5662
  body
5663
5663
  });
5664
5664
  }
5665
+ // ============================================================================
5666
+ // Background Tasks
5667
+ // ============================================================================
5668
+ /**
5669
+ * Lists background tasks with optional filtering and pagination.
5670
+ */
5671
+ listBackgroundTasks(params = {}) {
5672
+ const searchParams = new URLSearchParams();
5673
+ if (params.agentId) searchParams.set("agentId", params.agentId);
5674
+ if (params.status) searchParams.set("status", params.status);
5675
+ if (params.runId) searchParams.set("runId", params.runId);
5676
+ if (params.threadId) searchParams.set("threadId", params.threadId);
5677
+ if (params.resourceId) searchParams.set("resourceId", params.resourceId);
5678
+ if (params.fromDate) searchParams.set("fromDate", params.fromDate.toISOString());
5679
+ if (params.toDate) searchParams.set("toDate", params.toDate.toISOString());
5680
+ if (params.dateFilterBy) searchParams.set("dateFilterBy", params.dateFilterBy);
5681
+ if (params.orderBy) searchParams.set("orderBy", params.orderBy);
5682
+ if (params.orderDirection) searchParams.set("orderDirection", params.orderDirection);
5683
+ if (params.page !== void 0) searchParams.set("page", String(params.page));
5684
+ if (params.perPage !== void 0) searchParams.set("perPage", String(params.perPage));
5685
+ const qs = searchParams.toString();
5686
+ return this.request(`/background-tasks${qs ? `?${qs}` : ""}`);
5687
+ }
5688
+ /**
5689
+ * Gets a single background task by ID.
5690
+ */
5691
+ getBackgroundTask(backgroundTaskId) {
5692
+ return this.request(`/background-tasks/${encodeURIComponent(backgroundTaskId)}`);
5693
+ }
5694
+ /**
5695
+ * Opens an SSE stream of background task events (completed/failed).
5696
+ * Returns a Response that can be consumed as a ReadableStream.
5697
+ */
5698
+ async streamBackgroundTasks(params = {}) {
5699
+ const searchParams = new URLSearchParams();
5700
+ if (params.agentId) searchParams.set("agentId", params.agentId);
5701
+ if (params.runId) searchParams.set("runId", params.runId);
5702
+ if (params.threadId) searchParams.set("threadId", params.threadId);
5703
+ if (params.resourceId) searchParams.set("resourceId", params.resourceId);
5704
+ const qs = searchParams.toString();
5705
+ const response = await this.request(`/background-tasks/stream${qs ? `?${qs}` : ""}`, { stream: true });
5706
+ if (!response.ok) {
5707
+ throw new Error(`Failed to stream background tasks: ${response.statusText}`);
5708
+ }
5709
+ if (!response.body) {
5710
+ throw new Error("Response body is null");
5711
+ }
5712
+ let failedChunk = void 0;
5713
+ return response.body.pipeThrough(
5714
+ new TransformStream({
5715
+ async transform(chunk, controller) {
5716
+ try {
5717
+ const decoded = new TextDecoder().decode(chunk);
5718
+ const chunks = decoded.split("\n\n");
5719
+ for (const chunk2 of chunks) {
5720
+ if (chunk2) {
5721
+ const cleanChunk = chunk2.substring("data: ".length);
5722
+ const newChunk = failedChunk ? failedChunk + cleanChunk : cleanChunk;
5723
+ try {
5724
+ const parsedChunk = JSON.parse(newChunk);
5725
+ controller.enqueue(parsedChunk);
5726
+ failedChunk = void 0;
5727
+ } catch {
5728
+ failedChunk = newChunk;
5729
+ }
5730
+ }
5731
+ }
5732
+ } catch {
5733
+ }
5734
+ }
5735
+ })
5736
+ );
5737
+ }
5665
5738
  };
5666
5739
 
5667
5740
  // src/tools.ts