@mastra/client-js 0.0.0-fix-network-silence-20250930164151 → 0.0.0-fix-runtimeContext-passing-chatRoute-20251008220150

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.cjs CHANGED
@@ -323,12 +323,6 @@ var Agent = class extends BaseResource {
323
323
  details(runtimeContext) {
324
324
  return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
325
325
  }
326
- async generate(params) {
327
- console.warn(
328
- "Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 30th, 2025. Please use generateLegacy if you don't want to upgrade just yet."
329
- );
330
- return this.generateLegacy(params);
331
- }
332
326
  async generateLegacy(params) {
333
327
  const processedParams = {
334
328
  ...params,
@@ -392,7 +386,7 @@ var Agent = class extends BaseResource {
392
386
  }
393
387
  return response;
394
388
  }
395
- async generateVNext(messagesOrParams, options) {
389
+ async generate(messagesOrParams, options) {
396
390
  let params;
397
391
  if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
398
392
  params = messagesOrParams;
@@ -414,7 +408,7 @@ var Agent = class extends BaseResource {
414
408
  };
415
409
  const { runId, resourceId, threadId, runtimeContext } = processedParams;
416
410
  const response = await this.request(
417
- `/api/agents/${this.agentId}/generate/vnext`,
411
+ `/api/agents/${this.agentId}/generate`,
418
412
  {
419
413
  method: "POST",
420
414
  body: processedParams
@@ -428,7 +422,7 @@ var Agent = class extends BaseResource {
428
422
  resourceId,
429
423
  threadId,
430
424
  runtimeContext,
431
- respondFn: this.generateVNext.bind(this)
425
+ respondFn: this.generate.bind(this)
432
426
  });
433
427
  }
434
428
  return response;
@@ -695,17 +689,6 @@ var Agent = class extends BaseResource {
695
689
  });
696
690
  onFinish?.({ message, finishReason, usage });
697
691
  }
698
- /**
699
- * Streams a response from the agent
700
- * @param params - Stream parameters including prompt
701
- * @returns Promise containing the enhanced Response object with processDataStream method
702
- */
703
- async stream(params) {
704
- console.warn(
705
- "Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 30th, 2025. Please use streamLegacy if you don't want to upgrade just yet."
706
- );
707
- return this.streamLegacy(params);
708
- }
709
692
  /**
710
693
  * Streams a response from the agent
711
694
  * @param params - Stream parameters including prompt
@@ -807,6 +790,14 @@ var Agent = class extends BaseResource {
807
790
  // but this is completely wrong and this fn is probably broken. Remove ":any" and you'll see a bunch of type errors
808
791
  onChunk: async (chunk) => {
809
792
  switch (chunk.type) {
793
+ case "tripwire": {
794
+ message.parts.push({
795
+ type: "text",
796
+ text: chunk.payload.tripwireReason
797
+ });
798
+ execUpdate();
799
+ break;
800
+ }
810
801
  case "step-start": {
811
802
  if (!replaceLastMessage) {
812
803
  message.id = chunk.payload.messageId;
@@ -988,7 +979,7 @@ var Agent = class extends BaseResource {
988
979
  onFinish?.({ message, finishReason, usage });
989
980
  }
990
981
  async processStreamResponse_vNext(processedParams, writable) {
991
- const response = await this.request(`/api/agents/${this.agentId}/stream/vnext`, {
982
+ const response = await this.request(`/api/agents/${this.agentId}/stream`, {
992
983
  method: "POST",
993
984
  body: processedParams,
994
985
  stream: true
@@ -1003,18 +994,17 @@ var Agent = class extends BaseResource {
1003
994
  streamForWritable.pipeTo(
1004
995
  new WritableStream({
1005
996
  async write(chunk) {
997
+ let writer;
1006
998
  try {
999
+ writer = writable.getWriter();
1007
1000
  const text = new TextDecoder().decode(chunk);
1008
- if (text.includes("[DONE]")) {
1009
- return;
1010
- }
1001
+ const lines = text.split("\n\n");
1002
+ const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
1003
+ await writer.write(new TextEncoder().encode(readableLines));
1011
1004
  } catch {
1012
- }
1013
- const writer = writable.getWriter();
1014
- try {
1015
- await writer.write(chunk);
1005
+ await writer?.write(chunk);
1016
1006
  } finally {
1017
- writer.releaseLock();
1007
+ writer?.releaseLock();
1018
1008
  }
1019
1009
  }
1020
1010
  }),
@@ -1137,7 +1127,7 @@ var Agent = class extends BaseResource {
1137
1127
  };
1138
1128
  return streamResponse;
1139
1129
  }
1140
- async streamVNext(messagesOrParams, options) {
1130
+ async stream(messagesOrParams, options) {
1141
1131
  let params;
1142
1132
  if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
1143
1133
  params = messagesOrParams;
@@ -1362,6 +1352,12 @@ var Agent = class extends BaseResource {
1362
1352
  body: params
1363
1353
  });
1364
1354
  }
1355
+ async generateVNext(_messagesOrParams, _options) {
1356
+ throw new Error("generateVNext has been renamed to generate. Please use generate instead.");
1357
+ }
1358
+ async streamVNext(_messagesOrParams, _options) {
1359
+ throw new Error("streamVNext has been renamed to stream. Please use stream instead.");
1360
+ }
1365
1361
  };
1366
1362
 
1367
1363
  // src/resources/memory-thread.ts
@@ -1825,7 +1821,7 @@ var Workflow = class extends BaseResource {
1825
1821
  `/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
1826
1822
  {
1827
1823
  method: "POST",
1828
- body: { inputData: params.inputData, runtimeContext },
1824
+ body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions },
1829
1825
  stream: true
1830
1826
  }
1831
1827
  );
@@ -1923,7 +1919,12 @@ var Workflow = class extends BaseResource {
1923
1919
  `/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
1924
1920
  {
1925
1921
  method: "POST",
1926
- body: { inputData: params.inputData, runtimeContext, closeOnSuspend: params.closeOnSuspend },
1922
+ body: {
1923
+ inputData: params.inputData,
1924
+ runtimeContext,
1925
+ closeOnSuspend: params.closeOnSuspend,
1926
+ tracingOptions: params.tracingOptions
1927
+ },
1927
1928
  stream: true
1928
1929
  }
1929
1930
  );
@@ -1959,6 +1960,53 @@ var Workflow = class extends BaseResource {
1959
1960
  });
1960
1961
  return response.body.pipeThrough(transformStream);
1961
1962
  }
1963
+ /**
1964
+ * Observes workflow vNext stream for a workflow run
1965
+ * @param params - Object containing the runId
1966
+ * @returns Promise containing the workflow execution results
1967
+ */
1968
+ async observeStreamVNext(params) {
1969
+ const searchParams = new URLSearchParams();
1970
+ searchParams.set("runId", params.runId);
1971
+ const response = await this.request(
1972
+ `/api/workflows/${this.workflowId}/observe-streamVNext?${searchParams.toString()}`,
1973
+ {
1974
+ method: "POST",
1975
+ stream: true
1976
+ }
1977
+ );
1978
+ if (!response.ok) {
1979
+ throw new Error(`Failed to observe stream vNext workflow: ${response.statusText}`);
1980
+ }
1981
+ if (!response.body) {
1982
+ throw new Error("Response body is null");
1983
+ }
1984
+ let failedChunk = void 0;
1985
+ const transformStream = new TransformStream({
1986
+ start() {
1987
+ },
1988
+ async transform(chunk, controller) {
1989
+ try {
1990
+ const decoded = new TextDecoder().decode(chunk);
1991
+ const chunks = decoded.split(RECORD_SEPARATOR);
1992
+ for (const chunk2 of chunks) {
1993
+ if (chunk2) {
1994
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1995
+ try {
1996
+ const parsedChunk = JSON.parse(newChunk);
1997
+ controller.enqueue(parsedChunk);
1998
+ failedChunk = void 0;
1999
+ } catch {
2000
+ failedChunk = newChunk;
2001
+ }
2002
+ }
2003
+ }
2004
+ } catch {
2005
+ }
2006
+ }
2007
+ });
2008
+ return response.body.pipeThrough(transformStream);
2009
+ }
1962
2010
  /**
1963
2011
  * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
1964
2012
  * @param params - Object containing the runId, step, resumeData and runtimeContext
@@ -1981,17 +2029,54 @@ var Workflow = class extends BaseResource {
1981
2029
  * @param params - Object containing the runId, step, resumeData and runtimeContext
1982
2030
  * @returns Promise containing the workflow resume results
1983
2031
  */
1984
- resumeStreamVNext(params) {
2032
+ async resumeStreamVNext(params) {
2033
+ const searchParams = new URLSearchParams();
2034
+ searchParams.set("runId", params.runId);
1985
2035
  const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
1986
- return this.request(`/api/workflows/${this.workflowId}/resume-stream?runId=${params.runId}`, {
1987
- method: "POST",
1988
- body: {
1989
- step: params.step,
1990
- resumeData: params.resumeData,
1991
- runtimeContext,
1992
- tracingOptions: params.tracingOptions
2036
+ const response = await this.request(
2037
+ `/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
2038
+ {
2039
+ method: "POST",
2040
+ body: {
2041
+ step: params.step,
2042
+ resumeData: params.resumeData,
2043
+ runtimeContext,
2044
+ tracingOptions: params.tracingOptions
2045
+ },
2046
+ stream: true
2047
+ }
2048
+ );
2049
+ if (!response.ok) {
2050
+ throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
2051
+ }
2052
+ if (!response.body) {
2053
+ throw new Error("Response body is null");
2054
+ }
2055
+ let failedChunk = void 0;
2056
+ const transformStream = new TransformStream({
2057
+ start() {
2058
+ },
2059
+ async transform(chunk, controller) {
2060
+ try {
2061
+ const decoded = new TextDecoder().decode(chunk);
2062
+ const chunks = decoded.split(RECORD_SEPARATOR);
2063
+ for (const chunk2 of chunks) {
2064
+ if (chunk2) {
2065
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2066
+ try {
2067
+ const parsedChunk = JSON.parse(newChunk);
2068
+ controller.enqueue(parsedChunk);
2069
+ failedChunk = void 0;
2070
+ } catch {
2071
+ failedChunk = newChunk;
2072
+ }
2073
+ }
2074
+ }
2075
+ } catch {
2076
+ }
1993
2077
  }
1994
2078
  });
2079
+ return response.body.pipeThrough(transformStream);
1995
2080
  }
1996
2081
  /**
1997
2082
  * Watches workflow transitions in real-time
@@ -2659,145 +2744,6 @@ var NetworkMemoryThread = class extends BaseResource {
2659
2744
  }
2660
2745
  };
2661
2746
 
2662
- // src/resources/vNextNetwork.ts
2663
- var RECORD_SEPARATOR3 = "";
2664
- var VNextNetwork = class extends BaseResource {
2665
- constructor(options, networkId) {
2666
- super(options);
2667
- this.networkId = networkId;
2668
- }
2669
- /**
2670
- * Retrieves details about the network
2671
- * @param runtimeContext - Optional runtime context to pass as query parameter
2672
- * @returns Promise containing vNext network details
2673
- */
2674
- details(runtimeContext) {
2675
- return this.request(`/api/networks/v-next/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
2676
- }
2677
- /**
2678
- * Generates a response from the v-next network
2679
- * @param params - Generation parameters including message
2680
- * @returns Promise containing the generated response
2681
- */
2682
- generate(params) {
2683
- return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
2684
- method: "POST",
2685
- body: {
2686
- ...params,
2687
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2688
- }
2689
- });
2690
- }
2691
- /**
2692
- * Generates a response from the v-next network using multiple primitives
2693
- * @param params - Generation parameters including message
2694
- * @returns Promise containing the generated response
2695
- */
2696
- loop(params) {
2697
- return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
2698
- method: "POST",
2699
- body: {
2700
- ...params,
2701
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2702
- }
2703
- });
2704
- }
2705
- async *streamProcessor(stream) {
2706
- const reader = stream.getReader();
2707
- let doneReading = false;
2708
- let buffer = "";
2709
- try {
2710
- while (!doneReading) {
2711
- const { done, value } = await reader.read();
2712
- doneReading = done;
2713
- if (done && !value) continue;
2714
- try {
2715
- const decoded = value ? new TextDecoder().decode(value) : "";
2716
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2717
- buffer = chunks.pop() || "";
2718
- for (const chunk of chunks) {
2719
- if (chunk) {
2720
- if (typeof chunk === "string") {
2721
- try {
2722
- const parsedChunk = JSON.parse(chunk);
2723
- yield parsedChunk;
2724
- } catch {
2725
- }
2726
- }
2727
- }
2728
- }
2729
- } catch {
2730
- }
2731
- }
2732
- if (buffer) {
2733
- try {
2734
- yield JSON.parse(buffer);
2735
- } catch {
2736
- }
2737
- }
2738
- } finally {
2739
- reader.cancel().catch(() => {
2740
- });
2741
- }
2742
- }
2743
- /**
2744
- * Streams a response from the v-next network
2745
- * @param params - Stream parameters including message
2746
- * @returns Promise containing the results
2747
- */
2748
- async stream(params, onRecord) {
2749
- const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
2750
- method: "POST",
2751
- body: {
2752
- ...params,
2753
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2754
- },
2755
- stream: true
2756
- });
2757
- if (!response.ok) {
2758
- throw new Error(`Failed to stream vNext network: ${response.statusText}`);
2759
- }
2760
- if (!response.body) {
2761
- throw new Error("Response body is null");
2762
- }
2763
- for await (const record of this.streamProcessor(response.body)) {
2764
- if (typeof record === "string") {
2765
- onRecord(JSON.parse(record));
2766
- } else {
2767
- onRecord(record);
2768
- }
2769
- }
2770
- }
2771
- /**
2772
- * Streams a response from the v-next network loop
2773
- * @param params - Stream parameters including message
2774
- * @returns Promise containing the results
2775
- */
2776
- async loopStream(params, onRecord) {
2777
- const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
2778
- method: "POST",
2779
- body: {
2780
- ...params,
2781
- runtimeContext: parseClientRuntimeContext(params.runtimeContext)
2782
- },
2783
- stream: true
2784
- });
2785
- if (!response.ok) {
2786
- throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
2787
- }
2788
- if (!response.body) {
2789
- throw new Error("Response body is null");
2790
- }
2791
- for await (const record of this.streamProcessor(response.body)) {
2792
- if (typeof record === "string") {
2793
- onRecord(JSON.parse(record));
2794
- } else {
2795
- onRecord(record);
2796
- }
2797
- }
2798
- }
2799
- };
2800
-
2801
2747
  // src/client.ts
2802
2748
  var MastraClient = class extends BaseResource {
2803
2749
  observability;
@@ -3139,21 +3085,6 @@ var MastraClient = class extends BaseResource {
3139
3085
  return this.request(`/api/telemetry`);
3140
3086
  }
3141
3087
  }
3142
- /**
3143
- * Retrieves all available vNext networks
3144
- * @returns Promise containing map of vNext network IDs to vNext network details
3145
- */
3146
- getVNextNetworks() {
3147
- return this.request("/api/networks/v-next");
3148
- }
3149
- /**
3150
- * Gets a vNext network instance by ID
3151
- * @param networkId - ID of the vNext network to retrieve
3152
- * @returns vNext Network instance
3153
- */
3154
- getVNextNetwork(networkId) {
3155
- return new VNextNetwork(this.options, networkId);
3156
- }
3157
3088
  /**
3158
3089
  * Retrieves a list of available MCP servers.
3159
3090
  * @param params - Optional parameters for pagination (limit, offset).