@mastra/client-js 0.0.0-ai-v5-20250710191716 → 0.0.0-ai-v5-20250718021026

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,5 +1,5 @@
1
1
 
2
- > @mastra/client-js@0.10.11 build /home/runner/work/mastra/mastra/client-sdks/client-js
2
+ > @mastra/client-js@0.10.15-alpha.1 build /home/runner/work/mastra/mastra/client-sdks/client-js
3
3
  > tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -9,11 +9,11 @@
9
9
  CLI Cleaning output folder
10
10
  ESM Build start
11
11
  CJS Build start
12
- ESM dist/index.js 69.76 KB
13
- ESM ⚡️ Build success in 2133ms
14
- CJS dist/index.cjs 70.04 KB
15
- CJS ⚡️ Build success in 2147ms
16
12
  DTS Build start
17
- DTS ⚡️ Build success in 18199ms
18
- DTS dist/index.d.ts 40.88 KB
19
- DTS dist/index.d.cts 40.88 KB
13
+ ESM dist/index.js 71.36 KB
14
+ ESM ⚡️ Build success in 2104ms
15
+ CJS dist/index.cjs 71.66 KB
16
+ CJS ⚡️ Build success in 2109ms
17
+ DTS ⚡️ Build success in 18106ms
18
+ DTS dist/index.d.ts 42.03 KB
19
+ DTS dist/index.d.cts 42.03 KB
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @mastra/client-js
2
2
 
3
- ## 0.0.0-ai-v5-20250710191716
3
+ ## 0.0.0-ai-v5-20250718021026
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -8,9 +8,86 @@
8
8
 
9
9
  ### Patch Changes
10
10
 
11
- - Updated dependencies [5237998]
11
+ - 7827943: Handle streaming large data
12
12
  - Updated dependencies [66858d4]
13
- - @mastra/core@0.0.0-ai-v5-20250710191716
13
+ - Updated dependencies [7827943]
14
+ - Updated dependencies [bf1e7e7]
15
+ - Updated dependencies [cbddd18]
16
+ - @mastra/core@0.0.0-ai-v5-20250718021026
17
+
18
+ ## 0.10.15-alpha.1
19
+
20
+ ### Patch Changes
21
+
22
+ - @mastra/core@0.11.0-alpha.1
23
+
24
+ ## 0.10.15-alpha.0
25
+
26
+ ### Patch Changes
27
+
28
+ - 7827943: Handle streaming large data
29
+ - Updated dependencies [7827943]
30
+ - Updated dependencies [bf1e7e7]
31
+ - Updated dependencies [cbddd18]
32
+ - @mastra/core@0.11.0-alpha.0
33
+
34
+ ## 0.10.14
35
+
36
+ ### Patch Changes
37
+
38
+ - 31f9f6b: Replace crypto randomUUID in client SDK"
39
+ - 1aa60b1: Pipe runtimeContext to vNext network agent stream and generate steps, wire up runtimeContext for vNext Networks in cliet SDK & playground
40
+ - 626b0f4: [Cloud-126] Working Memory Playground - Added working memory to playground to allow users to view/edit working memory
41
+ - Updated dependencies [0b56518]
42
+ - Updated dependencies [db5cc15]
43
+ - Updated dependencies [2ba5b76]
44
+ - Updated dependencies [5237998]
45
+ - Updated dependencies [c3a30de]
46
+ - Updated dependencies [37c1acd]
47
+ - Updated dependencies [1aa60b1]
48
+ - Updated dependencies [89ec9d4]
49
+ - Updated dependencies [cf3a184]
50
+ - Updated dependencies [d6bfd60]
51
+ - Updated dependencies [626b0f4]
52
+ - Updated dependencies [c22a91f]
53
+ - Updated dependencies [f7403ab]
54
+ - Updated dependencies [6c89d7f]
55
+ - @mastra/core@0.10.15
56
+
57
+ ## 0.10.14-alpha.1
58
+
59
+ ### Patch Changes
60
+
61
+ - Updated dependencies [0b56518]
62
+ - Updated dependencies [2ba5b76]
63
+ - Updated dependencies [c3a30de]
64
+ - Updated dependencies [cf3a184]
65
+ - Updated dependencies [d6bfd60]
66
+ - @mastra/core@0.10.15-alpha.1
67
+
68
+ ## 0.10.14-alpha.0
69
+
70
+ ### Patch Changes
71
+
72
+ - 31f9f6b: Replace crypto randomUUID in client SDK"
73
+ - 1aa60b1: Pipe runtimeContext to vNext network agent stream and generate steps, wire up runtimeContext for vNext Networks in cliet SDK & playground
74
+ - 626b0f4: [Cloud-126] Working Memory Playground - Added working memory to playground to allow users to view/edit working memory
75
+ - Updated dependencies [db5cc15]
76
+ - Updated dependencies [5237998]
77
+ - Updated dependencies [37c1acd]
78
+ - Updated dependencies [1aa60b1]
79
+ - Updated dependencies [89ec9d4]
80
+ - Updated dependencies [626b0f4]
81
+ - Updated dependencies [c22a91f]
82
+ - Updated dependencies [f7403ab]
83
+ - Updated dependencies [6c89d7f]
84
+ - @mastra/core@0.10.15-alpha.0
85
+
86
+ ## 0.10.13
87
+
88
+ ### Patch Changes
89
+
90
+ - @mastra/core@0.10.14
14
91
 
15
92
  ## 0.10.11
16
93
 
package/dist/index.cjs CHANGED
@@ -6,6 +6,7 @@ var uiUtils = require('@ai-sdk/ui-utils');
6
6
  var zod = require('zod');
7
7
  var originalZodToJsonSchema = require('zod-to-json-schema');
8
8
  var tools = require('@mastra/core/tools');
9
+ var uuid = require('@lukeed/uuid');
9
10
  var runtimeContext = require('@mastra/core/runtime-context');
10
11
 
11
12
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -438,7 +439,7 @@ var Agent = class extends BaseResource {
438
439
  return Math.max(max, toolInvocation.step ?? 0);
439
440
  }, 0) ?? 0) : 0;
440
441
  const message = replaceLastMessage ? structuredClone(lastMessage) : {
441
- id: crypto.randomUUID(),
442
+ id: uuid.v4(),
442
443
  createdAt: getCurrentDate(),
443
444
  role: "assistant",
444
445
  content: "",
@@ -483,7 +484,7 @@ var Agent = class extends BaseResource {
483
484
  // changes. This is why we need to add a revision id to ensure that the message
484
485
  // is updated with SWR (without it, the changes get stuck in SWR and are not
485
486
  // forwarded to rendering):
486
- revisionId: crypto.randomUUID()
487
+ revisionId: uuid.v4()
487
488
  };
488
489
  update({
489
490
  message: copiedMessage,
@@ -1480,6 +1481,7 @@ var Workflow = class extends BaseResource {
1480
1481
  if (!response.body) {
1481
1482
  throw new Error("Response body is null");
1482
1483
  }
1484
+ let failedChunk = void 0;
1483
1485
  const transformStream = new TransformStream({
1484
1486
  start() {
1485
1487
  },
@@ -1489,10 +1491,13 @@ var Workflow = class extends BaseResource {
1489
1491
  const chunks = decoded.split(RECORD_SEPARATOR2);
1490
1492
  for (const chunk2 of chunks) {
1491
1493
  if (chunk2) {
1494
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1492
1495
  try {
1493
- const parsedChunk = JSON.parse(chunk2);
1496
+ const parsedChunk = JSON.parse(newChunk);
1494
1497
  controller.enqueue(parsedChunk);
1495
- } catch {
1498
+ failedChunk = void 0;
1499
+ } catch (error) {
1500
+ failedChunk = newChunk;
1496
1501
  }
1497
1502
  }
1498
1503
  }
@@ -1674,6 +1679,54 @@ var MCPTool = class extends BaseResource {
1674
1679
  }
1675
1680
  };
1676
1681
 
1682
+ // src/resources/network-memory-thread.ts
1683
+ var NetworkMemoryThread = class extends BaseResource {
1684
+ constructor(options, threadId, networkId) {
1685
+ super(options);
1686
+ this.threadId = threadId;
1687
+ this.networkId = networkId;
1688
+ }
1689
+ /**
1690
+ * Retrieves the memory thread details
1691
+ * @returns Promise containing thread details including title and metadata
1692
+ */
1693
+ get() {
1694
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
1695
+ }
1696
+ /**
1697
+ * Updates the memory thread properties
1698
+ * @param params - Update parameters including title and metadata
1699
+ * @returns Promise containing updated thread details
1700
+ */
1701
+ update(params) {
1702
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1703
+ method: "PATCH",
1704
+ body: params
1705
+ });
1706
+ }
1707
+ /**
1708
+ * Deletes the memory thread
1709
+ * @returns Promise containing deletion result
1710
+ */
1711
+ delete() {
1712
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1713
+ method: "DELETE"
1714
+ });
1715
+ }
1716
+ /**
1717
+ * Retrieves messages associated with the thread
1718
+ * @param params - Optional parameters including limit for number of messages to retrieve
1719
+ * @returns Promise containing thread messages and UI messages
1720
+ */
1721
+ getMessages(params) {
1722
+ const query = new URLSearchParams({
1723
+ networkId: this.networkId,
1724
+ ...params?.limit ? { limit: params.limit.toString() } : {}
1725
+ });
1726
+ return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
1727
+ }
1728
+ };
1729
+
1677
1730
  // src/resources/vNextNetwork.ts
1678
1731
  var RECORD_SEPARATOR3 = "";
1679
1732
  var VNextNetwork = class extends BaseResource {
@@ -1696,7 +1749,10 @@ var VNextNetwork = class extends BaseResource {
1696
1749
  generate(params) {
1697
1750
  return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
1698
1751
  method: "POST",
1699
- body: params
1752
+ body: {
1753
+ ...params,
1754
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1755
+ }
1700
1756
  });
1701
1757
  }
1702
1758
  /**
@@ -1707,7 +1763,10 @@ var VNextNetwork = class extends BaseResource {
1707
1763
  loop(params) {
1708
1764
  return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
1709
1765
  method: "POST",
1710
- body: params
1766
+ body: {
1767
+ ...params,
1768
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1769
+ }
1711
1770
  });
1712
1771
  }
1713
1772
  async *streamProcessor(stream) {
@@ -1756,7 +1815,10 @@ var VNextNetwork = class extends BaseResource {
1756
1815
  async stream(params, onRecord) {
1757
1816
  const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
1758
1817
  method: "POST",
1759
- body: params,
1818
+ body: {
1819
+ ...params,
1820
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1821
+ },
1760
1822
  stream: true
1761
1823
  });
1762
1824
  if (!response.ok) {
@@ -1781,7 +1843,10 @@ var VNextNetwork = class extends BaseResource {
1781
1843
  async loopStream(params, onRecord) {
1782
1844
  const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
1783
1845
  method: "POST",
1784
- body: params,
1846
+ body: {
1847
+ ...params,
1848
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1849
+ },
1785
1850
  stream: true
1786
1851
  });
1787
1852
  if (!response.ok) {
@@ -1800,54 +1865,6 @@ var VNextNetwork = class extends BaseResource {
1800
1865
  }
1801
1866
  };
1802
1867
 
1803
- // src/resources/network-memory-thread.ts
1804
- var NetworkMemoryThread = class extends BaseResource {
1805
- constructor(options, threadId, networkId) {
1806
- super(options);
1807
- this.threadId = threadId;
1808
- this.networkId = networkId;
1809
- }
1810
- /**
1811
- * Retrieves the memory thread details
1812
- * @returns Promise containing thread details including title and metadata
1813
- */
1814
- get() {
1815
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
1816
- }
1817
- /**
1818
- * Updates the memory thread properties
1819
- * @param params - Update parameters including title and metadata
1820
- * @returns Promise containing updated thread details
1821
- */
1822
- update(params) {
1823
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1824
- method: "PATCH",
1825
- body: params
1826
- });
1827
- }
1828
- /**
1829
- * Deletes the memory thread
1830
- * @returns Promise containing deletion result
1831
- */
1832
- delete() {
1833
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1834
- method: "DELETE"
1835
- });
1836
- }
1837
- /**
1838
- * Retrieves messages associated with the thread
1839
- * @param params - Optional parameters including limit for number of messages to retrieve
1840
- * @returns Promise containing thread messages and UI messages
1841
- */
1842
- getMessages(params) {
1843
- const query = new URLSearchParams({
1844
- networkId: this.networkId,
1845
- ...params?.limit ? { limit: params.limit.toString() } : {}
1846
- });
1847
- return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
1848
- }
1849
- };
1850
-
1851
1868
  // src/client.ts
1852
1869
  var MastraClient = class extends BaseResource {
1853
1870
  constructor(options) {
@@ -2242,6 +2259,41 @@ var MastraClient = class extends BaseResource {
2242
2259
  getA2A(agentId) {
2243
2260
  return new A2A(this.options, agentId);
2244
2261
  }
2262
+ /**
2263
+ * Retrieves the working memory for a specific thread (optionally resource-scoped).
2264
+ * @param agentId - ID of the agent.
2265
+ * @param threadId - ID of the thread.
2266
+ * @param resourceId - Optional ID of the resource.
2267
+ * @returns Working memory for the specified thread or resource.
2268
+ */
2269
+ getWorkingMemory({
2270
+ agentId,
2271
+ threadId,
2272
+ resourceId
2273
+ }) {
2274
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
2275
+ }
2276
+ /**
2277
+ * Updates the working memory for a specific thread (optionally resource-scoped).
2278
+ * @param agentId - ID of the agent.
2279
+ * @param threadId - ID of the thread.
2280
+ * @param workingMemory - The new working memory content.
2281
+ * @param resourceId - Optional ID of the resource.
2282
+ */
2283
+ updateWorkingMemory({
2284
+ agentId,
2285
+ threadId,
2286
+ workingMemory,
2287
+ resourceId
2288
+ }) {
2289
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
2290
+ method: "POST",
2291
+ body: {
2292
+ workingMemory,
2293
+ resourceId
2294
+ }
2295
+ });
2296
+ }
2245
2297
  };
2246
2298
 
2247
2299
  exports.MastraClient = MastraClient;
package/dist/index.d.cts CHANGED
@@ -337,12 +337,14 @@ interface GenerateOrStreamVNextNetworkParams {
337
337
  message: string;
338
338
  threadId?: string;
339
339
  resourceId?: string;
340
+ runtimeContext?: RuntimeContext | Record<string, any>;
340
341
  }
341
342
  interface LoopStreamVNextNetworkParams {
342
343
  message: string;
343
344
  threadId?: string;
344
345
  resourceId?: string;
345
346
  maxIterations?: number;
347
+ runtimeContext?: RuntimeContext | Record<string, any>;
346
348
  }
347
349
  interface LoopVNextNetworkResponse {
348
350
  status: 'success';
@@ -896,6 +898,36 @@ declare class MCPTool extends BaseResource {
896
898
  }): Promise<any>;
897
899
  }
898
900
 
901
+ declare class NetworkMemoryThread extends BaseResource {
902
+ private threadId;
903
+ private networkId;
904
+ constructor(options: ClientOptions, threadId: string, networkId: string);
905
+ /**
906
+ * Retrieves the memory thread details
907
+ * @returns Promise containing thread details including title and metadata
908
+ */
909
+ get(): Promise<StorageThreadType>;
910
+ /**
911
+ * Updates the memory thread properties
912
+ * @param params - Update parameters including title and metadata
913
+ * @returns Promise containing updated thread details
914
+ */
915
+ update(params: UpdateMemoryThreadParams): Promise<StorageThreadType>;
916
+ /**
917
+ * Deletes the memory thread
918
+ * @returns Promise containing deletion result
919
+ */
920
+ delete(): Promise<{
921
+ result: string;
922
+ }>;
923
+ /**
924
+ * Retrieves messages associated with the thread
925
+ * @param params - Optional parameters including limit for number of messages to retrieve
926
+ * @returns Promise containing thread messages and UI messages
927
+ */
928
+ getMessages(params?: GetMemoryThreadMessagesParams): Promise<GetMemoryThreadMessagesResponse>;
929
+ }
930
+
899
931
  declare class VNextNetwork extends BaseResource {
900
932
  private networkId;
901
933
  constructor(options: ClientOptions, networkId: string);
@@ -917,6 +949,7 @@ declare class VNextNetwork extends BaseResource {
917
949
  */
918
950
  loop(params: {
919
951
  message: string;
952
+ runtimeContext?: RuntimeContext | Record<string, any>;
920
953
  }): Promise<LoopVNextNetworkResponse>;
921
954
  private streamProcessor;
922
955
  /**
@@ -933,36 +966,6 @@ declare class VNextNetwork extends BaseResource {
933
966
  loopStream(params: LoopStreamVNextNetworkParams, onRecord: (record: WatchEvent) => void): Promise<void>;
934
967
  }
935
968
 
936
- declare class NetworkMemoryThread extends BaseResource {
937
- private threadId;
938
- private networkId;
939
- constructor(options: ClientOptions, threadId: string, networkId: string);
940
- /**
941
- * Retrieves the memory thread details
942
- * @returns Promise containing thread details including title and metadata
943
- */
944
- get(): Promise<StorageThreadType>;
945
- /**
946
- * Updates the memory thread properties
947
- * @param params - Update parameters including title and metadata
948
- * @returns Promise containing updated thread details
949
- */
950
- update(params: UpdateMemoryThreadParams): Promise<StorageThreadType>;
951
- /**
952
- * Deletes the memory thread
953
- * @returns Promise containing deletion result
954
- */
955
- delete(): Promise<{
956
- result: string;
957
- }>;
958
- /**
959
- * Retrieves messages associated with the thread
960
- * @param params - Optional parameters including limit for number of messages to retrieve
961
- * @returns Promise containing thread messages and UI messages
962
- */
963
- getMessages(params?: GetMemoryThreadMessagesParams): Promise<GetMemoryThreadMessagesResponse>;
964
- }
965
-
966
969
  declare class MastraClient extends BaseResource {
967
970
  constructor(options: ClientOptions);
968
971
  /**
@@ -1165,6 +1168,31 @@ declare class MastraClient extends BaseResource {
1165
1168
  * @returns A2A client instance
1166
1169
  */
1167
1170
  getA2A(agentId: string): A2A;
1171
+ /**
1172
+ * Retrieves the working memory for a specific thread (optionally resource-scoped).
1173
+ * @param agentId - ID of the agent.
1174
+ * @param threadId - ID of the thread.
1175
+ * @param resourceId - Optional ID of the resource.
1176
+ * @returns Working memory for the specified thread or resource.
1177
+ */
1178
+ getWorkingMemory({ agentId, threadId, resourceId, }: {
1179
+ agentId: string;
1180
+ threadId: string;
1181
+ resourceId?: string;
1182
+ }): Promise<unknown>;
1183
+ /**
1184
+ * Updates the working memory for a specific thread (optionally resource-scoped).
1185
+ * @param agentId - ID of the agent.
1186
+ * @param threadId - ID of the thread.
1187
+ * @param workingMemory - The new working memory content.
1188
+ * @param resourceId - Optional ID of the resource.
1189
+ */
1190
+ updateWorkingMemory({ agentId, threadId, workingMemory, resourceId, }: {
1191
+ agentId: string;
1192
+ threadId: string;
1193
+ workingMemory: string;
1194
+ resourceId?: string;
1195
+ }): Promise<unknown>;
1168
1196
  }
1169
1197
 
1170
1198
  export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type CreateNetworkMemoryThreadParams, type GenerateOrStreamVNextNetworkParams, type GenerateParams, type GenerateVNextNetworkResponse, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLegacyWorkflowResponse, type GetLegacyWorkflowRunsResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesParams, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetNetworkMemoryThreadParams, type GetNetworkResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVNextNetworkResponse, type GetVectorIndexResponse, type GetWorkflowResponse, type GetWorkflowRunByIdResponse, type GetWorkflowRunExecutionResultResponse, type GetWorkflowRunsParams, type GetWorkflowRunsResponse, type LegacyWorkflowRunResult, type LoopStreamVNextNetworkParams, type LoopVNextNetworkResponse, MastraClient, type McpServerListResponse, type McpServerToolListResponse, type McpToolInfo, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type SaveNetworkMessageToMemoryParams, type StreamParams, type UpdateMemoryThreadParams, type UpsertVectorParams, type WorkflowRunResult, type WorkflowWatchResult };
package/dist/index.d.ts CHANGED
@@ -337,12 +337,14 @@ interface GenerateOrStreamVNextNetworkParams {
337
337
  message: string;
338
338
  threadId?: string;
339
339
  resourceId?: string;
340
+ runtimeContext?: RuntimeContext | Record<string, any>;
340
341
  }
341
342
  interface LoopStreamVNextNetworkParams {
342
343
  message: string;
343
344
  threadId?: string;
344
345
  resourceId?: string;
345
346
  maxIterations?: number;
347
+ runtimeContext?: RuntimeContext | Record<string, any>;
346
348
  }
347
349
  interface LoopVNextNetworkResponse {
348
350
  status: 'success';
@@ -896,6 +898,36 @@ declare class MCPTool extends BaseResource {
896
898
  }): Promise<any>;
897
899
  }
898
900
 
901
+ declare class NetworkMemoryThread extends BaseResource {
902
+ private threadId;
903
+ private networkId;
904
+ constructor(options: ClientOptions, threadId: string, networkId: string);
905
+ /**
906
+ * Retrieves the memory thread details
907
+ * @returns Promise containing thread details including title and metadata
908
+ */
909
+ get(): Promise<StorageThreadType>;
910
+ /**
911
+ * Updates the memory thread properties
912
+ * @param params - Update parameters including title and metadata
913
+ * @returns Promise containing updated thread details
914
+ */
915
+ update(params: UpdateMemoryThreadParams): Promise<StorageThreadType>;
916
+ /**
917
+ * Deletes the memory thread
918
+ * @returns Promise containing deletion result
919
+ */
920
+ delete(): Promise<{
921
+ result: string;
922
+ }>;
923
+ /**
924
+ * Retrieves messages associated with the thread
925
+ * @param params - Optional parameters including limit for number of messages to retrieve
926
+ * @returns Promise containing thread messages and UI messages
927
+ */
928
+ getMessages(params?: GetMemoryThreadMessagesParams): Promise<GetMemoryThreadMessagesResponse>;
929
+ }
930
+
899
931
  declare class VNextNetwork extends BaseResource {
900
932
  private networkId;
901
933
  constructor(options: ClientOptions, networkId: string);
@@ -917,6 +949,7 @@ declare class VNextNetwork extends BaseResource {
917
949
  */
918
950
  loop(params: {
919
951
  message: string;
952
+ runtimeContext?: RuntimeContext | Record<string, any>;
920
953
  }): Promise<LoopVNextNetworkResponse>;
921
954
  private streamProcessor;
922
955
  /**
@@ -933,36 +966,6 @@ declare class VNextNetwork extends BaseResource {
933
966
  loopStream(params: LoopStreamVNextNetworkParams, onRecord: (record: WatchEvent) => void): Promise<void>;
934
967
  }
935
968
 
936
- declare class NetworkMemoryThread extends BaseResource {
937
- private threadId;
938
- private networkId;
939
- constructor(options: ClientOptions, threadId: string, networkId: string);
940
- /**
941
- * Retrieves the memory thread details
942
- * @returns Promise containing thread details including title and metadata
943
- */
944
- get(): Promise<StorageThreadType>;
945
- /**
946
- * Updates the memory thread properties
947
- * @param params - Update parameters including title and metadata
948
- * @returns Promise containing updated thread details
949
- */
950
- update(params: UpdateMemoryThreadParams): Promise<StorageThreadType>;
951
- /**
952
- * Deletes the memory thread
953
- * @returns Promise containing deletion result
954
- */
955
- delete(): Promise<{
956
- result: string;
957
- }>;
958
- /**
959
- * Retrieves messages associated with the thread
960
- * @param params - Optional parameters including limit for number of messages to retrieve
961
- * @returns Promise containing thread messages and UI messages
962
- */
963
- getMessages(params?: GetMemoryThreadMessagesParams): Promise<GetMemoryThreadMessagesResponse>;
964
- }
965
-
966
969
  declare class MastraClient extends BaseResource {
967
970
  constructor(options: ClientOptions);
968
971
  /**
@@ -1165,6 +1168,31 @@ declare class MastraClient extends BaseResource {
1165
1168
  * @returns A2A client instance
1166
1169
  */
1167
1170
  getA2A(agentId: string): A2A;
1171
+ /**
1172
+ * Retrieves the working memory for a specific thread (optionally resource-scoped).
1173
+ * @param agentId - ID of the agent.
1174
+ * @param threadId - ID of the thread.
1175
+ * @param resourceId - Optional ID of the resource.
1176
+ * @returns Working memory for the specified thread or resource.
1177
+ */
1178
+ getWorkingMemory({ agentId, threadId, resourceId, }: {
1179
+ agentId: string;
1180
+ threadId: string;
1181
+ resourceId?: string;
1182
+ }): Promise<unknown>;
1183
+ /**
1184
+ * Updates the working memory for a specific thread (optionally resource-scoped).
1185
+ * @param agentId - ID of the agent.
1186
+ * @param threadId - ID of the thread.
1187
+ * @param workingMemory - The new working memory content.
1188
+ * @param resourceId - Optional ID of the resource.
1189
+ */
1190
+ updateWorkingMemory({ agentId, threadId, workingMemory, resourceId, }: {
1191
+ agentId: string;
1192
+ threadId: string;
1193
+ workingMemory: string;
1194
+ resourceId?: string;
1195
+ }): Promise<unknown>;
1168
1196
  }
1169
1197
 
1170
1198
  export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type CreateNetworkMemoryThreadParams, type GenerateOrStreamVNextNetworkParams, type GenerateParams, type GenerateVNextNetworkResponse, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLegacyWorkflowResponse, type GetLegacyWorkflowRunsResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesParams, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetNetworkMemoryThreadParams, type GetNetworkResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVNextNetworkResponse, type GetVectorIndexResponse, type GetWorkflowResponse, type GetWorkflowRunByIdResponse, type GetWorkflowRunExecutionResultResponse, type GetWorkflowRunsParams, type GetWorkflowRunsResponse, type LegacyWorkflowRunResult, type LoopStreamVNextNetworkParams, type LoopVNextNetworkResponse, MastraClient, type McpServerListResponse, type McpServerToolListResponse, type McpToolInfo, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type SaveNetworkMessageToMemoryParams, type StreamParams, type UpdateMemoryThreadParams, type UpsertVectorParams, type WorkflowRunResult, type WorkflowWatchResult };
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import { processTextStream, processDataStream, parsePartialJson } from '@ai-sdk/
4
4
  import { ZodSchema } from 'zod';
5
5
  import originalZodToJsonSchema from 'zod-to-json-schema';
6
6
  import { isVercelTool } from '@mastra/core/tools';
7
+ import { v4 } from '@lukeed/uuid';
7
8
  import { RuntimeContext } from '@mastra/core/runtime-context';
8
9
 
9
10
  // src/adapters/agui.ts
@@ -432,7 +433,7 @@ var Agent = class extends BaseResource {
432
433
  return Math.max(max, toolInvocation.step ?? 0);
433
434
  }, 0) ?? 0) : 0;
434
435
  const message = replaceLastMessage ? structuredClone(lastMessage) : {
435
- id: crypto.randomUUID(),
436
+ id: v4(),
436
437
  createdAt: getCurrentDate(),
437
438
  role: "assistant",
438
439
  content: "",
@@ -477,7 +478,7 @@ var Agent = class extends BaseResource {
477
478
  // changes. This is why we need to add a revision id to ensure that the message
478
479
  // is updated with SWR (without it, the changes get stuck in SWR and are not
479
480
  // forwarded to rendering):
480
- revisionId: crypto.randomUUID()
481
+ revisionId: v4()
481
482
  };
482
483
  update({
483
484
  message: copiedMessage,
@@ -1474,6 +1475,7 @@ var Workflow = class extends BaseResource {
1474
1475
  if (!response.body) {
1475
1476
  throw new Error("Response body is null");
1476
1477
  }
1478
+ let failedChunk = void 0;
1477
1479
  const transformStream = new TransformStream({
1478
1480
  start() {
1479
1481
  },
@@ -1483,10 +1485,13 @@ var Workflow = class extends BaseResource {
1483
1485
  const chunks = decoded.split(RECORD_SEPARATOR2);
1484
1486
  for (const chunk2 of chunks) {
1485
1487
  if (chunk2) {
1488
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
1486
1489
  try {
1487
- const parsedChunk = JSON.parse(chunk2);
1490
+ const parsedChunk = JSON.parse(newChunk);
1488
1491
  controller.enqueue(parsedChunk);
1489
- } catch {
1492
+ failedChunk = void 0;
1493
+ } catch (error) {
1494
+ failedChunk = newChunk;
1490
1495
  }
1491
1496
  }
1492
1497
  }
@@ -1668,6 +1673,54 @@ var MCPTool = class extends BaseResource {
1668
1673
  }
1669
1674
  };
1670
1675
 
1676
+ // src/resources/network-memory-thread.ts
1677
+ var NetworkMemoryThread = class extends BaseResource {
1678
+ constructor(options, threadId, networkId) {
1679
+ super(options);
1680
+ this.threadId = threadId;
1681
+ this.networkId = networkId;
1682
+ }
1683
+ /**
1684
+ * Retrieves the memory thread details
1685
+ * @returns Promise containing thread details including title and metadata
1686
+ */
1687
+ get() {
1688
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
1689
+ }
1690
+ /**
1691
+ * Updates the memory thread properties
1692
+ * @param params - Update parameters including title and metadata
1693
+ * @returns Promise containing updated thread details
1694
+ */
1695
+ update(params) {
1696
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1697
+ method: "PATCH",
1698
+ body: params
1699
+ });
1700
+ }
1701
+ /**
1702
+ * Deletes the memory thread
1703
+ * @returns Promise containing deletion result
1704
+ */
1705
+ delete() {
1706
+ return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1707
+ method: "DELETE"
1708
+ });
1709
+ }
1710
+ /**
1711
+ * Retrieves messages associated with the thread
1712
+ * @param params - Optional parameters including limit for number of messages to retrieve
1713
+ * @returns Promise containing thread messages and UI messages
1714
+ */
1715
+ getMessages(params) {
1716
+ const query = new URLSearchParams({
1717
+ networkId: this.networkId,
1718
+ ...params?.limit ? { limit: params.limit.toString() } : {}
1719
+ });
1720
+ return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
1721
+ }
1722
+ };
1723
+
1671
1724
  // src/resources/vNextNetwork.ts
1672
1725
  var RECORD_SEPARATOR3 = "";
1673
1726
  var VNextNetwork = class extends BaseResource {
@@ -1690,7 +1743,10 @@ var VNextNetwork = class extends BaseResource {
1690
1743
  generate(params) {
1691
1744
  return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
1692
1745
  method: "POST",
1693
- body: params
1746
+ body: {
1747
+ ...params,
1748
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1749
+ }
1694
1750
  });
1695
1751
  }
1696
1752
  /**
@@ -1701,7 +1757,10 @@ var VNextNetwork = class extends BaseResource {
1701
1757
  loop(params) {
1702
1758
  return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
1703
1759
  method: "POST",
1704
- body: params
1760
+ body: {
1761
+ ...params,
1762
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1763
+ }
1705
1764
  });
1706
1765
  }
1707
1766
  async *streamProcessor(stream) {
@@ -1750,7 +1809,10 @@ var VNextNetwork = class extends BaseResource {
1750
1809
  async stream(params, onRecord) {
1751
1810
  const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
1752
1811
  method: "POST",
1753
- body: params,
1812
+ body: {
1813
+ ...params,
1814
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1815
+ },
1754
1816
  stream: true
1755
1817
  });
1756
1818
  if (!response.ok) {
@@ -1775,7 +1837,10 @@ var VNextNetwork = class extends BaseResource {
1775
1837
  async loopStream(params, onRecord) {
1776
1838
  const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
1777
1839
  method: "POST",
1778
- body: params,
1840
+ body: {
1841
+ ...params,
1842
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1843
+ },
1779
1844
  stream: true
1780
1845
  });
1781
1846
  if (!response.ok) {
@@ -1794,54 +1859,6 @@ var VNextNetwork = class extends BaseResource {
1794
1859
  }
1795
1860
  };
1796
1861
 
1797
- // src/resources/network-memory-thread.ts
1798
- var NetworkMemoryThread = class extends BaseResource {
1799
- constructor(options, threadId, networkId) {
1800
- super(options);
1801
- this.threadId = threadId;
1802
- this.networkId = networkId;
1803
- }
1804
- /**
1805
- * Retrieves the memory thread details
1806
- * @returns Promise containing thread details including title and metadata
1807
- */
1808
- get() {
1809
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
1810
- }
1811
- /**
1812
- * Updates the memory thread properties
1813
- * @param params - Update parameters including title and metadata
1814
- * @returns Promise containing updated thread details
1815
- */
1816
- update(params) {
1817
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1818
- method: "PATCH",
1819
- body: params
1820
- });
1821
- }
1822
- /**
1823
- * Deletes the memory thread
1824
- * @returns Promise containing deletion result
1825
- */
1826
- delete() {
1827
- return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
1828
- method: "DELETE"
1829
- });
1830
- }
1831
- /**
1832
- * Retrieves messages associated with the thread
1833
- * @param params - Optional parameters including limit for number of messages to retrieve
1834
- * @returns Promise containing thread messages and UI messages
1835
- */
1836
- getMessages(params) {
1837
- const query = new URLSearchParams({
1838
- networkId: this.networkId,
1839
- ...params?.limit ? { limit: params.limit.toString() } : {}
1840
- });
1841
- return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
1842
- }
1843
- };
1844
-
1845
1862
  // src/client.ts
1846
1863
  var MastraClient = class extends BaseResource {
1847
1864
  constructor(options) {
@@ -2236,6 +2253,41 @@ var MastraClient = class extends BaseResource {
2236
2253
  getA2A(agentId) {
2237
2254
  return new A2A(this.options, agentId);
2238
2255
  }
2256
+ /**
2257
+ * Retrieves the working memory for a specific thread (optionally resource-scoped).
2258
+ * @param agentId - ID of the agent.
2259
+ * @param threadId - ID of the thread.
2260
+ * @param resourceId - Optional ID of the resource.
2261
+ * @returns Working memory for the specified thread or resource.
2262
+ */
2263
+ getWorkingMemory({
2264
+ agentId,
2265
+ threadId,
2266
+ resourceId
2267
+ }) {
2268
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
2269
+ }
2270
+ /**
2271
+ * Updates the working memory for a specific thread (optionally resource-scoped).
2272
+ * @param agentId - ID of the agent.
2273
+ * @param threadId - ID of the thread.
2274
+ * @param workingMemory - The new working memory content.
2275
+ * @param resourceId - Optional ID of the resource.
2276
+ */
2277
+ updateWorkingMemory({
2278
+ agentId,
2279
+ threadId,
2280
+ workingMemory,
2281
+ resourceId
2282
+ }) {
2283
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
2284
+ method: "POST",
2285
+ body: {
2286
+ workingMemory,
2287
+ resourceId
2288
+ }
2289
+ });
2290
+ }
2239
2291
  };
2240
2292
 
2241
2293
  export { MastraClient };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/client-js",
3
- "version": "0.0.0-ai-v5-20250710191716",
3
+ "version": "0.0.0-ai-v5-20250718021026",
4
4
  "description": "The official TypeScript library for the Mastra Client API",
5
5
  "author": "",
6
6
  "type": "module",
@@ -29,11 +29,12 @@
29
29
  "dependencies": {
30
30
  "@ag-ui/client": "^0.0.27",
31
31
  "@ai-sdk/ui-utils": "latest",
32
+ "@lukeed/uuid": "^2.0.1",
32
33
  "json-schema": "^0.4.0",
33
34
  "rxjs": "7.8.1",
34
35
  "zod": "^3.25.67",
35
36
  "zod-to-json-schema": "^3.24.5",
36
- "@mastra/core": "0.0.0-ai-v5-20250710191716"
37
+ "@mastra/core": "0.0.0-ai-v5-20250718021026"
37
38
  },
38
39
  "peerDependencies": {
39
40
  "zod": "^3.0.0"
@@ -47,7 +48,7 @@
47
48
  "tsup": "^8.5.0",
48
49
  "typescript": "^5.8.3",
49
50
  "vitest": "^3.2.4",
50
- "@internal/lint": "0.0.0-ai-v5-20250710191716"
51
+ "@internal/lint": "0.0.0-ai-v5-20250718021026"
51
52
  },
52
53
  "scripts": {
53
54
  "build": "tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting",
package/src/client.ts CHANGED
@@ -13,6 +13,8 @@ import {
13
13
  MCPTool,
14
14
  LegacyWorkflow,
15
15
  } from './resources';
16
+ import { NetworkMemoryThread } from './resources/network-memory-thread';
17
+ import { VNextNetwork } from './resources/vNextNetwork';
16
18
  import type {
17
19
  ClientOptions,
18
20
  CreateMemoryThreadParams,
@@ -38,8 +40,6 @@ import type {
38
40
  CreateNetworkMemoryThreadParams,
39
41
  SaveNetworkMessageToMemoryParams,
40
42
  } from './types';
41
- import { VNextNetwork } from './resources/vNextNetwork';
42
- import { NetworkMemoryThread } from './resources/network-memory-thread';
43
43
 
44
44
  export class MastraClient extends BaseResource {
45
45
  constructor(options: ClientOptions) {
@@ -477,4 +477,50 @@ export class MastraClient extends BaseResource {
477
477
  public getA2A(agentId: string) {
478
478
  return new A2A(this.options, agentId);
479
479
  }
480
+
481
+ /**
482
+ * Retrieves the working memory for a specific thread (optionally resource-scoped).
483
+ * @param agentId - ID of the agent.
484
+ * @param threadId - ID of the thread.
485
+ * @param resourceId - Optional ID of the resource.
486
+ * @returns Working memory for the specified thread or resource.
487
+ */
488
+ public getWorkingMemory({
489
+ agentId,
490
+ threadId,
491
+ resourceId,
492
+ }: {
493
+ agentId: string;
494
+ threadId: string;
495
+ resourceId?: string;
496
+ }) {
497
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
498
+ }
499
+
500
+ /**
501
+ * Updates the working memory for a specific thread (optionally resource-scoped).
502
+ * @param agentId - ID of the agent.
503
+ * @param threadId - ID of the thread.
504
+ * @param workingMemory - The new working memory content.
505
+ * @param resourceId - Optional ID of the resource.
506
+ */
507
+ public updateWorkingMemory({
508
+ agentId,
509
+ threadId,
510
+ workingMemory,
511
+ resourceId,
512
+ }: {
513
+ agentId: string;
514
+ threadId: string;
515
+ workingMemory: string;
516
+ resourceId?: string;
517
+ }) {
518
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
519
+ method: 'POST',
520
+ body: {
521
+ workingMemory,
522
+ resourceId,
523
+ },
524
+ });
525
+ }
480
526
  }
package/src/index.test.ts CHANGED
@@ -27,7 +27,13 @@ describe('MastraClient Resources', () => {
27
27
  } else {
28
28
  responseBody = new ReadableStream({
29
29
  start(controller) {
30
- controller.enqueue(new TextEncoder().encode(JSON.stringify(data)));
30
+ if (typeof data === 'string') {
31
+ controller.enqueue(new TextEncoder().encode(data));
32
+ } else if (typeof data === 'object' && data !== null) {
33
+ controller.enqueue(new TextEncoder().encode(JSON.stringify(data)));
34
+ } else {
35
+ controller.enqueue(new TextEncoder().encode(String(data)));
36
+ }
31
37
  controller.close();
32
38
  },
33
39
  });
@@ -279,7 +285,7 @@ describe('MastraClient Resources', () => {
279
285
  });
280
286
 
281
287
  it('should stream responses', async () => {
282
- const mockChunk = { content: 'test response' };
288
+ const mockChunk = `0:"test response"\n`;
283
289
  mockFetchResponse(mockChunk, { isStream: true });
284
290
 
285
291
  const response = await agent.stream({
@@ -298,7 +304,7 @@ describe('MastraClient Resources', () => {
298
304
  if (reader) {
299
305
  const { value, done } = await reader.read();
300
306
  expect(done).toBe(false);
301
- expect(new TextDecoder().decode(value)).toBe(JSON.stringify(mockChunk));
307
+ expect(new TextDecoder().decode(value)).toBe(mockChunk);
302
308
  }
303
309
  });
304
310
 
@@ -662,14 +668,14 @@ describe('MastraClient Resources', () => {
662
668
  };
663
669
  mockFetchResponse(mockResponse);
664
670
 
665
- const result = await workflow.startAsync({ triggerData: { test: 'test' } });
671
+ const result = await workflow.startAsync({ inputData: { test: 'test' } });
666
672
  expect(result).toEqual(mockResponse);
667
673
  expect(global.fetch).toHaveBeenCalledWith(
668
674
  `${clientOptions.baseUrl}/api/workflows/test-workflow/start-async?`,
669
675
  expect.objectContaining({
670
676
  method: 'POST',
671
677
  headers: expect.objectContaining(clientOptions.headers),
672
- body: JSON.stringify({ test: 'test' }),
678
+ body: JSON.stringify({ inputData: { test: 'test' } }),
673
679
  }),
674
680
  );
675
681
  });
@@ -15,6 +15,7 @@ import type { JSONSchema7 } from 'json-schema';
15
15
  import { ZodSchema } from 'zod';
16
16
  import { zodToJsonSchema } from '../utils/zod-to-json-schema';
17
17
  import { processClientTools } from '../utils/process-client-tools';
18
+ import { v4 as uuid } from '@lukeed/uuid';
18
19
 
19
20
  import type {
20
21
  GenerateParams,
@@ -228,7 +229,7 @@ export class Agent extends BaseResource {
228
229
  const message: UIMessage = replaceLastMessage
229
230
  ? structuredClone(lastMessage)
230
231
  : {
231
- id: crypto.randomUUID(),
232
+ id: uuid(),
232
233
  createdAt: getCurrentDate(),
233
234
  role: 'assistant',
234
235
  content: '',
@@ -288,7 +289,7 @@ export class Agent extends BaseResource {
288
289
  // changes. This is why we need to add a revision id to ensure that the message
289
290
  // is updated with SWR (without it, the changes get stuck in SWR and are not
290
291
  // forwarded to rendering):
291
- revisionId: crypto.randomUUID(),
292
+ revisionId: uuid(),
292
293
  } as UIMessage;
293
294
 
294
295
  update({
@@ -10,6 +10,8 @@ import type {
10
10
  } from '../types';
11
11
 
12
12
  import { BaseResource } from './base';
13
+ import { parseClientRuntimeContext } from '../utils';
14
+ import type { RuntimeContext } from '@mastra/core/runtime-context';
13
15
 
14
16
  const RECORD_SEPARATOR = '\x1E';
15
17
 
@@ -37,7 +39,10 @@ export class VNextNetwork extends BaseResource {
37
39
  generate(params: GenerateOrStreamVNextNetworkParams): Promise<GenerateVNextNetworkResponse> {
38
40
  return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
39
41
  method: 'POST',
40
- body: params,
42
+ body: {
43
+ ...params,
44
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
45
+ },
41
46
  });
42
47
  }
43
48
 
@@ -46,10 +51,16 @@ export class VNextNetwork extends BaseResource {
46
51
  * @param params - Generation parameters including message
47
52
  * @returns Promise containing the generated response
48
53
  */
49
- loop(params: { message: string }): Promise<LoopVNextNetworkResponse> {
54
+ loop(params: {
55
+ message: string;
56
+ runtimeContext?: RuntimeContext | Record<string, any>;
57
+ }): Promise<LoopVNextNetworkResponse> {
50
58
  return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
51
59
  method: 'POST',
52
- body: params,
60
+ body: {
61
+ ...params,
62
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
63
+ },
53
64
  });
54
65
  }
55
66
 
@@ -125,7 +136,10 @@ export class VNextNetwork extends BaseResource {
125
136
  async stream(params: GenerateOrStreamVNextNetworkParams, onRecord: (record: WatchEvent) => void) {
126
137
  const response: Response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
127
138
  method: 'POST',
128
- body: params,
139
+ body: {
140
+ ...params,
141
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
142
+ },
129
143
  stream: true,
130
144
  });
131
145
 
@@ -154,7 +168,10 @@ export class VNextNetwork extends BaseResource {
154
168
  async loopStream(params: LoopStreamVNextNetworkParams, onRecord: (record: WatchEvent) => void) {
155
169
  const response: Response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
156
170
  method: 'POST',
157
- body: params,
171
+ body: {
172
+ ...params,
173
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
174
+ },
158
175
  stream: true,
159
176
  });
160
177
 
@@ -289,6 +289,9 @@ export class Workflow extends BaseResource {
289
289
  throw new Error('Response body is null');
290
290
  }
291
291
 
292
+ //using undefined instead of empty string to avoid parsing errors
293
+ let failedChunk: string | undefined = undefined;
294
+
292
295
  // Create a transform stream that processes the response body
293
296
  const transformStream = new TransformStream<ArrayBuffer, { type: string; payload: any }>({
294
297
  start() {},
@@ -303,11 +306,13 @@ export class Workflow extends BaseResource {
303
306
  // Process each chunk
304
307
  for (const chunk of chunks) {
305
308
  if (chunk) {
309
+ const newChunk: string = failedChunk ? failedChunk + chunk : chunk;
306
310
  try {
307
- const parsedChunk = JSON.parse(chunk);
311
+ const parsedChunk = JSON.parse(newChunk);
308
312
  controller.enqueue(parsedChunk);
309
- } catch {
310
- // Silently ignore parsing errors
313
+ failedChunk = undefined;
314
+ } catch (error) {
315
+ failedChunk = newChunk;
311
316
  }
312
317
  }
313
318
  }
package/src/types.ts CHANGED
@@ -394,6 +394,7 @@ export interface GenerateOrStreamVNextNetworkParams {
394
394
  message: string;
395
395
  threadId?: string;
396
396
  resourceId?: string;
397
+ runtimeContext?: RuntimeContext | Record<string, any>;
397
398
  }
398
399
 
399
400
  export interface LoopStreamVNextNetworkParams {
@@ -401,6 +402,7 @@ export interface LoopStreamVNextNetworkParams {
401
402
  threadId?: string;
402
403
  resourceId?: string;
403
404
  maxIterations?: number;
405
+ runtimeContext?: RuntimeContext | Record<string, any>;
404
406
  }
405
407
 
406
408
  export interface LoopVNextNetworkResponse {