@mastra/client-js 0.0.0-fix-fetching-workflow-snapshots-20250625000954 → 0.0.0-http-transporter-20250702160118

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.6-alpha.5 build /home/runner/work/mastra/mastra/client-sdks/client-js
2
+ > @mastra/client-js@0.10.9-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
- CJS dist/index.cjs 66.50 KB
13
- CJS ⚡️ Build success in 356ms
14
- ESM dist/index.js 66.21 KB
15
- ESM ⚡️ Build success in 357ms
12
+ ESM dist/index.js 68.47 KB
13
+ ESM ⚡️ Build success in 1254ms
14
+ CJS dist/index.cjs 68.75 KB
15
+ CJS ⚡️ Build success in 1958ms
16
16
  DTS Build start
17
- DTS ⚡️ Build success in 2466ms
18
- DTS dist/index.d.ts 39.17 KB
19
- DTS dist/index.d.cts 39.17 KB
17
+ DTS ⚡️ Build success in 17089ms
18
+ DTS dist/index.d.ts 40.58 KB
19
+ DTS dist/index.d.cts 40.58 KB
package/CHANGELOG.md CHANGED
@@ -1,6 +1,110 @@
1
1
  # @mastra/client-js
2
2
 
3
- ## 0.0.0-fix-fetching-workflow-snapshots-20250625000954
3
+ ## 0.0.0-http-transporter-20250702160118
4
+
5
+ ### Patch Changes
6
+
7
+ - b60f510: Fix getWorkflowRuns by limit and offset
8
+ - 6997af1: add send event to server, deployer, client-js and playground-ui
9
+ - Updated dependencies [4d3fbdf]
10
+ - @mastra/core@0.0.0-http-transporter-20250702160118
11
+
12
+ ## 0.10.9-alpha.1
13
+
14
+ ### Patch Changes
15
+
16
+ - b60f510: Fix getWorkflowRuns by limit and offset
17
+ - 6997af1: add send event to server, deployer, client-js and playground-ui
18
+ - @mastra/core@0.10.10-alpha.1
19
+
20
+ ## 0.10.9-alpha.0
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies [4d3fbdf]
25
+ - @mastra/core@0.10.10-alpha.0
26
+
27
+ ## 0.10.8
28
+
29
+ ### Patch Changes
30
+
31
+ - 9047bda: clientTools - stream tool-result part
32
+ - a606c75: show right suspend schema for nested workflow on playground
33
+ - 1760a1c: Use workflow stream in playground instead of watch
34
+ - 038e5ae: Add cancel workflow run
35
+ - 7e801dd: Add tools to network api response
36
+ - Updated dependencies [9dda1ac]
37
+ - Updated dependencies [c984582]
38
+ - Updated dependencies [7e801dd]
39
+ - Updated dependencies [a606c75]
40
+ - Updated dependencies [7aa70a4]
41
+ - Updated dependencies [764f86a]
42
+ - Updated dependencies [1760a1c]
43
+ - Updated dependencies [038e5ae]
44
+ - Updated dependencies [7dda16a]
45
+ - Updated dependencies [5ebfcdd]
46
+ - Updated dependencies [b2d0c91]
47
+ - Updated dependencies [4e809ad]
48
+ - Updated dependencies [57929df]
49
+ - Updated dependencies [b7852ed]
50
+ - Updated dependencies [6320a61]
51
+ - @mastra/core@0.10.9
52
+
53
+ ## 0.10.8-alpha.0
54
+
55
+ ### Patch Changes
56
+
57
+ - 9047bda: clientTools - stream tool-result part
58
+ - a606c75: show right suspend schema for nested workflow on playground
59
+ - 1760a1c: Use workflow stream in playground instead of watch
60
+ - 038e5ae: Add cancel workflow run
61
+ - 7e801dd: Add tools to network api response
62
+ - Updated dependencies [9dda1ac]
63
+ - Updated dependencies [c984582]
64
+ - Updated dependencies [7e801dd]
65
+ - Updated dependencies [a606c75]
66
+ - Updated dependencies [7aa70a4]
67
+ - Updated dependencies [764f86a]
68
+ - Updated dependencies [1760a1c]
69
+ - Updated dependencies [038e5ae]
70
+ - Updated dependencies [7dda16a]
71
+ - Updated dependencies [5ebfcdd]
72
+ - Updated dependencies [b2d0c91]
73
+ - Updated dependencies [4e809ad]
74
+ - Updated dependencies [57929df]
75
+ - Updated dependencies [b7852ed]
76
+ - Updated dependencies [6320a61]
77
+ - @mastra/core@0.10.9-alpha.0
78
+
79
+ ## 0.10.7
80
+
81
+ ### Patch Changes
82
+
83
+ - a344ac7: Fix tool streaming in agent network
84
+ - Updated dependencies [b8f16b2]
85
+ - Updated dependencies [3e04487]
86
+ - Updated dependencies [a344ac7]
87
+ - Updated dependencies [dc4ca0a]
88
+ - @mastra/core@0.10.8
89
+
90
+ ## 0.10.7-alpha.1
91
+
92
+ ### Patch Changes
93
+
94
+ - Updated dependencies [b8f16b2]
95
+ - Updated dependencies [3e04487]
96
+ - Updated dependencies [dc4ca0a]
97
+ - @mastra/core@0.10.8-alpha.1
98
+
99
+ ## 0.10.7-alpha.0
100
+
101
+ ### Patch Changes
102
+
103
+ - a344ac7: Fix tool streaming in agent network
104
+ - Updated dependencies [a344ac7]
105
+ - @mastra/core@0.10.8-alpha.0
106
+
107
+ ## 0.10.6
4
108
 
5
109
  ### Patch Changes
6
110
 
@@ -10,6 +114,7 @@
10
114
  - 18a5d59: clientTools client side execution
11
115
  - 5d74aab: vNext network in playground
12
116
  - bee3fe4: Fix client side tool calling
117
+ - c0d41f6: Fix streaming for agent tool calls
13
118
  - Updated dependencies [15e9d26]
14
119
  - Updated dependencies [d1baedb]
15
120
  - Updated dependencies [d8f2d19]
@@ -27,7 +132,13 @@
27
132
  - Updated dependencies [8ba1b51]
28
133
  - Updated dependencies [4efcfa0]
29
134
  - Updated dependencies [0e17048]
30
- - @mastra/core@0.0.0-fix-fetching-workflow-snapshots-20250625000954
135
+ - @mastra/core@0.10.7
136
+
137
+ ## 0.10.6-alpha.6
138
+
139
+ ### Patch Changes
140
+
141
+ - c0d41f6: Fix streaming for agent tool calls
31
142
 
32
143
  ## 0.10.6-alpha.5
33
144
 
package/dist/index.cjs CHANGED
@@ -722,74 +722,90 @@ var Agent = class extends BaseResource {
722
722
  }
723
723
  try {
724
724
  let toolCalls = [];
725
- let finishReasonToolCalls = false;
726
725
  let messages = [];
727
- let hasProcessedToolCalls = false;
728
- response.clone().body.pipeTo(writable);
729
- await this.processChatResponse({
730
- stream: response.clone().body,
726
+ const [streamForWritable, streamForProcessing] = response.body.tee();
727
+ streamForWritable.pipeTo(writable, {
728
+ preventClose: true
729
+ }).catch((error) => {
730
+ console.error("Error piping to writable stream:", error);
731
+ });
732
+ this.processChatResponse({
733
+ stream: streamForProcessing,
731
734
  update: ({ message }) => {
732
735
  messages.push(message);
733
736
  },
734
- onFinish: ({ finishReason, message }) => {
737
+ onFinish: async ({ finishReason, message }) => {
735
738
  if (finishReason === "tool-calls") {
736
- finishReasonToolCalls = true;
737
739
  const toolCall = [...message?.parts ?? []].reverse().find((part) => part.type === "tool-invocation")?.toolInvocation;
738
740
  if (toolCall) {
739
741
  toolCalls.push(toolCall);
740
742
  }
743
+ for (const toolCall2 of toolCalls) {
744
+ const clientTool = processedParams.clientTools?.[toolCall2.toolName];
745
+ if (clientTool && clientTool.execute) {
746
+ const result = await clientTool.execute(
747
+ {
748
+ context: toolCall2?.args,
749
+ runId: processedParams.runId,
750
+ resourceId: processedParams.resourceId,
751
+ threadId: processedParams.threadId,
752
+ runtimeContext: processedParams.runtimeContext
753
+ },
754
+ {
755
+ messages: response.messages,
756
+ toolCallId: toolCall2?.toolCallId
757
+ }
758
+ );
759
+ const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
760
+ const toolInvocationPart = lastMessage?.parts?.find(
761
+ (part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
762
+ );
763
+ if (toolInvocationPart) {
764
+ toolInvocationPart.toolInvocation = {
765
+ ...toolInvocationPart.toolInvocation,
766
+ state: "result",
767
+ result
768
+ };
769
+ }
770
+ const toolInvocation = lastMessage?.toolInvocations?.find(
771
+ (toolInvocation2) => toolInvocation2.toolCallId === toolCall2.toolCallId
772
+ );
773
+ if (toolInvocation) {
774
+ toolInvocation.state = "result";
775
+ toolInvocation.result = result;
776
+ }
777
+ const writer = writable.getWriter();
778
+ try {
779
+ await writer.write(
780
+ new TextEncoder().encode(
781
+ "a:" + JSON.stringify({
782
+ toolCallId: toolCall2.toolCallId,
783
+ result
784
+ }) + "\n"
785
+ )
786
+ );
787
+ } finally {
788
+ writer.releaseLock();
789
+ }
790
+ const originalMessages = processedParams.messages;
791
+ const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
792
+ this.processStreamResponse(
793
+ {
794
+ ...processedParams,
795
+ messages: [...messageArray, ...messages, lastMessage]
796
+ },
797
+ writable
798
+ );
799
+ }
800
+ }
801
+ } else {
802
+ setTimeout(() => {
803
+ writable.close();
804
+ }, 0);
741
805
  }
742
806
  },
743
807
  lastMessage: void 0
744
808
  });
745
- if (finishReasonToolCalls && !hasProcessedToolCalls) {
746
- hasProcessedToolCalls = true;
747
- for (const toolCall of toolCalls) {
748
- const clientTool = processedParams.clientTools?.[toolCall.toolName];
749
- if (clientTool && clientTool.execute) {
750
- const result = await clientTool.execute(
751
- {
752
- context: toolCall?.args,
753
- runId: processedParams.runId,
754
- resourceId: processedParams.resourceId,
755
- threadId: processedParams.threadId,
756
- runtimeContext: processedParams.runtimeContext
757
- },
758
- {
759
- messages: response.messages,
760
- toolCallId: toolCall?.toolCallId
761
- }
762
- );
763
- const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
764
- const toolInvocationPart = lastMessage?.parts?.find(
765
- (part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall.toolCallId
766
- );
767
- if (toolInvocationPart) {
768
- toolInvocationPart.toolInvocation = {
769
- ...toolInvocationPart.toolInvocation,
770
- state: "result",
771
- result
772
- };
773
- }
774
- const toolInvocation = lastMessage?.toolInvocations?.find(
775
- (toolInvocation2) => toolInvocation2.toolCallId === toolCall.toolCallId
776
- );
777
- if (toolInvocation) {
778
- toolInvocation.state = "result";
779
- toolInvocation.result = result;
780
- }
781
- const originalMessages = processedParams.messages;
782
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
783
- this.processStreamResponse(
784
- {
785
- ...processedParams,
786
- messages: [...messageArray, ...messages, lastMessage]
787
- },
788
- writable
789
- );
790
- }
791
- }
792
- }
793
809
  } catch (error) {
794
810
  console.error("Error processing stream response:", error);
795
811
  }
@@ -1292,10 +1308,10 @@ var Workflow = class extends BaseResource {
1292
1308
  if (params?.toDate) {
1293
1309
  searchParams.set("toDate", params.toDate.toISOString());
1294
1310
  }
1295
- if (params?.limit !== void 0) {
1311
+ if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
1296
1312
  searchParams.set("limit", String(params.limit));
1297
1313
  }
1298
- if (params?.offset !== void 0) {
1314
+ if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
1299
1315
  searchParams.set("offset", String(params.offset));
1300
1316
  }
1301
1317
  if (params?.resourceId) {
@@ -1323,6 +1339,27 @@ var Workflow = class extends BaseResource {
1323
1339
  runExecutionResult(runId) {
1324
1340
  return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
1325
1341
  }
1342
+ /**
1343
+ * Cancels a specific workflow run by its ID
1344
+ * @param runId - The ID of the workflow run to cancel
1345
+ * @returns Promise containing a success message
1346
+ */
1347
+ cancelRun(runId) {
1348
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/cancel`, {
1349
+ method: "POST"
1350
+ });
1351
+ }
1352
+ /**
1353
+ * Sends an event to a specific workflow run by its ID
1354
+ * @param params - Object containing the runId, event and data
1355
+ * @returns Promise containing a success message
1356
+ */
1357
+ sendRunEvent(params) {
1358
+ return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
1359
+ method: "POST",
1360
+ body: { event: params.event, data: params.data }
1361
+ });
1362
+ }
1326
1363
  /**
1327
1364
  * Creates a new workflow run
1328
1365
  * @param params - Optional object containing the optional runId
@@ -1705,6 +1742,31 @@ var VNextNetwork = class extends BaseResource {
1705
1742
  }
1706
1743
  }
1707
1744
  }
1745
+ /**
1746
+ * Streams a response from the v-next network loop
1747
+ * @param params - Stream parameters including message
1748
+ * @returns Promise containing the results
1749
+ */
1750
+ async loopStream(params, onRecord) {
1751
+ const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
1752
+ method: "POST",
1753
+ body: params,
1754
+ stream: true
1755
+ });
1756
+ if (!response.ok) {
1757
+ throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
1758
+ }
1759
+ if (!response.body) {
1760
+ throw new Error("Response body is null");
1761
+ }
1762
+ for await (const record of this.streamProcessor(response.body)) {
1763
+ if (typeof record === "string") {
1764
+ onRecord(JSON.parse(record));
1765
+ } else {
1766
+ onRecord(record);
1767
+ }
1768
+ }
1769
+ }
1708
1770
  };
1709
1771
 
1710
1772
  // src/resources/network-memory-thread.ts
package/dist/index.d.cts CHANGED
@@ -114,6 +114,17 @@ interface GetWorkflowResponse {
114
114
  suspendSchema: string;
115
115
  };
116
116
  };
117
+ allSteps: {
118
+ [key: string]: {
119
+ id: string;
120
+ description: string;
121
+ inputSchema: string;
122
+ outputSchema: string;
123
+ resumeSchema: string;
124
+ suspendSchema: string;
125
+ isWorkflow: boolean;
126
+ };
127
+ };
117
128
  stepGraph: Workflow$1['serializedStepGraph'];
118
129
  inputSchema: string;
119
130
  outputSchema: string;
@@ -306,6 +317,10 @@ interface GetVNextNetworkResponse {
306
317
  inputSchema: string | undefined;
307
318
  outputSchema: string | undefined;
308
319
  }>;
320
+ tools: Array<{
321
+ id: string;
322
+ description: string;
323
+ }>;
309
324
  }
310
325
  interface GenerateVNextNetworkResponse {
311
326
  task: string;
@@ -318,6 +333,12 @@ interface GenerateOrStreamVNextNetworkParams {
318
333
  threadId?: string;
319
334
  resourceId?: string;
320
335
  }
336
+ interface LoopStreamVNextNetworkParams {
337
+ message: string;
338
+ threadId?: string;
339
+ resourceId?: string;
340
+ maxIterations?: number;
341
+ }
321
342
  interface LoopVNextNetworkResponse {
322
343
  status: 'success';
323
344
  result: {
@@ -697,6 +718,26 @@ declare class Workflow extends BaseResource {
697
718
  * @returns Promise containing the workflow run execution result
698
719
  */
699
720
  runExecutionResult(runId: string): Promise<GetWorkflowRunExecutionResultResponse>;
721
+ /**
722
+ * Cancels a specific workflow run by its ID
723
+ * @param runId - The ID of the workflow run to cancel
724
+ * @returns Promise containing a success message
725
+ */
726
+ cancelRun(runId: string): Promise<{
727
+ message: string;
728
+ }>;
729
+ /**
730
+ * Sends an event to a specific workflow run by its ID
731
+ * @param params - Object containing the runId, event and data
732
+ * @returns Promise containing a success message
733
+ */
734
+ sendRunEvent(params: {
735
+ runId: string;
736
+ event: string;
737
+ data: unknown;
738
+ }): Promise<{
739
+ message: string;
740
+ }>;
700
741
  /**
701
742
  * Creates a new workflow run
702
743
  * @param params - Optional object containing the optional runId
@@ -751,7 +792,10 @@ declare class Workflow extends BaseResource {
751
792
  runId?: string;
752
793
  inputData: Record<string, any>;
753
794
  runtimeContext?: RuntimeContext;
754
- }): Promise<stream_web.ReadableStream<WorkflowWatchResult>>;
795
+ }): Promise<stream_web.ReadableStream<{
796
+ type: string;
797
+ payload: any;
798
+ }>>;
755
799
  /**
756
800
  * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
757
801
  * @param params - Object containing the runId, step, resumeData and runtimeContext
@@ -875,6 +919,12 @@ declare class VNextNetwork extends BaseResource {
875
919
  * @returns Promise containing the results
876
920
  */
877
921
  stream(params: GenerateOrStreamVNextNetworkParams, onRecord: (record: WatchEvent) => void): Promise<void>;
922
+ /**
923
+ * Streams a response from the v-next network loop
924
+ * @param params - Stream parameters including message
925
+ * @returns Promise containing the results
926
+ */
927
+ loopStream(params: LoopStreamVNextNetworkParams, onRecord: (record: WatchEvent) => void): Promise<void>;
878
928
  }
879
929
 
880
930
  declare class NetworkMemoryThread extends BaseResource {
@@ -1111,4 +1161,4 @@ declare class MastraClient extends BaseResource {
1111
1161
  getA2A(agentId: string): A2A;
1112
1162
  }
1113
1163
 
1114
- 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 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 };
1164
+ 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
@@ -114,6 +114,17 @@ interface GetWorkflowResponse {
114
114
  suspendSchema: string;
115
115
  };
116
116
  };
117
+ allSteps: {
118
+ [key: string]: {
119
+ id: string;
120
+ description: string;
121
+ inputSchema: string;
122
+ outputSchema: string;
123
+ resumeSchema: string;
124
+ suspendSchema: string;
125
+ isWorkflow: boolean;
126
+ };
127
+ };
117
128
  stepGraph: Workflow$1['serializedStepGraph'];
118
129
  inputSchema: string;
119
130
  outputSchema: string;
@@ -306,6 +317,10 @@ interface GetVNextNetworkResponse {
306
317
  inputSchema: string | undefined;
307
318
  outputSchema: string | undefined;
308
319
  }>;
320
+ tools: Array<{
321
+ id: string;
322
+ description: string;
323
+ }>;
309
324
  }
310
325
  interface GenerateVNextNetworkResponse {
311
326
  task: string;
@@ -318,6 +333,12 @@ interface GenerateOrStreamVNextNetworkParams {
318
333
  threadId?: string;
319
334
  resourceId?: string;
320
335
  }
336
+ interface LoopStreamVNextNetworkParams {
337
+ message: string;
338
+ threadId?: string;
339
+ resourceId?: string;
340
+ maxIterations?: number;
341
+ }
321
342
  interface LoopVNextNetworkResponse {
322
343
  status: 'success';
323
344
  result: {
@@ -697,6 +718,26 @@ declare class Workflow extends BaseResource {
697
718
  * @returns Promise containing the workflow run execution result
698
719
  */
699
720
  runExecutionResult(runId: string): Promise<GetWorkflowRunExecutionResultResponse>;
721
+ /**
722
+ * Cancels a specific workflow run by its ID
723
+ * @param runId - The ID of the workflow run to cancel
724
+ * @returns Promise containing a success message
725
+ */
726
+ cancelRun(runId: string): Promise<{
727
+ message: string;
728
+ }>;
729
+ /**
730
+ * Sends an event to a specific workflow run by its ID
731
+ * @param params - Object containing the runId, event and data
732
+ * @returns Promise containing a success message
733
+ */
734
+ sendRunEvent(params: {
735
+ runId: string;
736
+ event: string;
737
+ data: unknown;
738
+ }): Promise<{
739
+ message: string;
740
+ }>;
700
741
  /**
701
742
  * Creates a new workflow run
702
743
  * @param params - Optional object containing the optional runId
@@ -751,7 +792,10 @@ declare class Workflow extends BaseResource {
751
792
  runId?: string;
752
793
  inputData: Record<string, any>;
753
794
  runtimeContext?: RuntimeContext;
754
- }): Promise<stream_web.ReadableStream<WorkflowWatchResult>>;
795
+ }): Promise<stream_web.ReadableStream<{
796
+ type: string;
797
+ payload: any;
798
+ }>>;
755
799
  /**
756
800
  * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
757
801
  * @param params - Object containing the runId, step, resumeData and runtimeContext
@@ -875,6 +919,12 @@ declare class VNextNetwork extends BaseResource {
875
919
  * @returns Promise containing the results
876
920
  */
877
921
  stream(params: GenerateOrStreamVNextNetworkParams, onRecord: (record: WatchEvent) => void): Promise<void>;
922
+ /**
923
+ * Streams a response from the v-next network loop
924
+ * @param params - Stream parameters including message
925
+ * @returns Promise containing the results
926
+ */
927
+ loopStream(params: LoopStreamVNextNetworkParams, onRecord: (record: WatchEvent) => void): Promise<void>;
878
928
  }
879
929
 
880
930
  declare class NetworkMemoryThread extends BaseResource {
@@ -1111,4 +1161,4 @@ declare class MastraClient extends BaseResource {
1111
1161
  getA2A(agentId: string): A2A;
1112
1162
  }
1113
1163
 
1114
- 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 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 };
1164
+ 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
@@ -716,74 +716,90 @@ var Agent = class extends BaseResource {
716
716
  }
717
717
  try {
718
718
  let toolCalls = [];
719
- let finishReasonToolCalls = false;
720
719
  let messages = [];
721
- let hasProcessedToolCalls = false;
722
- response.clone().body.pipeTo(writable);
723
- await this.processChatResponse({
724
- stream: response.clone().body,
720
+ const [streamForWritable, streamForProcessing] = response.body.tee();
721
+ streamForWritable.pipeTo(writable, {
722
+ preventClose: true
723
+ }).catch((error) => {
724
+ console.error("Error piping to writable stream:", error);
725
+ });
726
+ this.processChatResponse({
727
+ stream: streamForProcessing,
725
728
  update: ({ message }) => {
726
729
  messages.push(message);
727
730
  },
728
- onFinish: ({ finishReason, message }) => {
731
+ onFinish: async ({ finishReason, message }) => {
729
732
  if (finishReason === "tool-calls") {
730
- finishReasonToolCalls = true;
731
733
  const toolCall = [...message?.parts ?? []].reverse().find((part) => part.type === "tool-invocation")?.toolInvocation;
732
734
  if (toolCall) {
733
735
  toolCalls.push(toolCall);
734
736
  }
737
+ for (const toolCall2 of toolCalls) {
738
+ const clientTool = processedParams.clientTools?.[toolCall2.toolName];
739
+ if (clientTool && clientTool.execute) {
740
+ const result = await clientTool.execute(
741
+ {
742
+ context: toolCall2?.args,
743
+ runId: processedParams.runId,
744
+ resourceId: processedParams.resourceId,
745
+ threadId: processedParams.threadId,
746
+ runtimeContext: processedParams.runtimeContext
747
+ },
748
+ {
749
+ messages: response.messages,
750
+ toolCallId: toolCall2?.toolCallId
751
+ }
752
+ );
753
+ const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
754
+ const toolInvocationPart = lastMessage?.parts?.find(
755
+ (part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
756
+ );
757
+ if (toolInvocationPart) {
758
+ toolInvocationPart.toolInvocation = {
759
+ ...toolInvocationPart.toolInvocation,
760
+ state: "result",
761
+ result
762
+ };
763
+ }
764
+ const toolInvocation = lastMessage?.toolInvocations?.find(
765
+ (toolInvocation2) => toolInvocation2.toolCallId === toolCall2.toolCallId
766
+ );
767
+ if (toolInvocation) {
768
+ toolInvocation.state = "result";
769
+ toolInvocation.result = result;
770
+ }
771
+ const writer = writable.getWriter();
772
+ try {
773
+ await writer.write(
774
+ new TextEncoder().encode(
775
+ "a:" + JSON.stringify({
776
+ toolCallId: toolCall2.toolCallId,
777
+ result
778
+ }) + "\n"
779
+ )
780
+ );
781
+ } finally {
782
+ writer.releaseLock();
783
+ }
784
+ const originalMessages = processedParams.messages;
785
+ const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
786
+ this.processStreamResponse(
787
+ {
788
+ ...processedParams,
789
+ messages: [...messageArray, ...messages, lastMessage]
790
+ },
791
+ writable
792
+ );
793
+ }
794
+ }
795
+ } else {
796
+ setTimeout(() => {
797
+ writable.close();
798
+ }, 0);
735
799
  }
736
800
  },
737
801
  lastMessage: void 0
738
802
  });
739
- if (finishReasonToolCalls && !hasProcessedToolCalls) {
740
- hasProcessedToolCalls = true;
741
- for (const toolCall of toolCalls) {
742
- const clientTool = processedParams.clientTools?.[toolCall.toolName];
743
- if (clientTool && clientTool.execute) {
744
- const result = await clientTool.execute(
745
- {
746
- context: toolCall?.args,
747
- runId: processedParams.runId,
748
- resourceId: processedParams.resourceId,
749
- threadId: processedParams.threadId,
750
- runtimeContext: processedParams.runtimeContext
751
- },
752
- {
753
- messages: response.messages,
754
- toolCallId: toolCall?.toolCallId
755
- }
756
- );
757
- const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
758
- const toolInvocationPart = lastMessage?.parts?.find(
759
- (part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall.toolCallId
760
- );
761
- if (toolInvocationPart) {
762
- toolInvocationPart.toolInvocation = {
763
- ...toolInvocationPart.toolInvocation,
764
- state: "result",
765
- result
766
- };
767
- }
768
- const toolInvocation = lastMessage?.toolInvocations?.find(
769
- (toolInvocation2) => toolInvocation2.toolCallId === toolCall.toolCallId
770
- );
771
- if (toolInvocation) {
772
- toolInvocation.state = "result";
773
- toolInvocation.result = result;
774
- }
775
- const originalMessages = processedParams.messages;
776
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
777
- this.processStreamResponse(
778
- {
779
- ...processedParams,
780
- messages: [...messageArray, ...messages, lastMessage]
781
- },
782
- writable
783
- );
784
- }
785
- }
786
- }
787
803
  } catch (error) {
788
804
  console.error("Error processing stream response:", error);
789
805
  }
@@ -1286,10 +1302,10 @@ var Workflow = class extends BaseResource {
1286
1302
  if (params?.toDate) {
1287
1303
  searchParams.set("toDate", params.toDate.toISOString());
1288
1304
  }
1289
- if (params?.limit !== void 0) {
1305
+ if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
1290
1306
  searchParams.set("limit", String(params.limit));
1291
1307
  }
1292
- if (params?.offset !== void 0) {
1308
+ if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
1293
1309
  searchParams.set("offset", String(params.offset));
1294
1310
  }
1295
1311
  if (params?.resourceId) {
@@ -1317,6 +1333,27 @@ var Workflow = class extends BaseResource {
1317
1333
  runExecutionResult(runId) {
1318
1334
  return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
1319
1335
  }
1336
+ /**
1337
+ * Cancels a specific workflow run by its ID
1338
+ * @param runId - The ID of the workflow run to cancel
1339
+ * @returns Promise containing a success message
1340
+ */
1341
+ cancelRun(runId) {
1342
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/cancel`, {
1343
+ method: "POST"
1344
+ });
1345
+ }
1346
+ /**
1347
+ * Sends an event to a specific workflow run by its ID
1348
+ * @param params - Object containing the runId, event and data
1349
+ * @returns Promise containing a success message
1350
+ */
1351
+ sendRunEvent(params) {
1352
+ return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
1353
+ method: "POST",
1354
+ body: { event: params.event, data: params.data }
1355
+ });
1356
+ }
1320
1357
  /**
1321
1358
  * Creates a new workflow run
1322
1359
  * @param params - Optional object containing the optional runId
@@ -1699,6 +1736,31 @@ var VNextNetwork = class extends BaseResource {
1699
1736
  }
1700
1737
  }
1701
1738
  }
1739
+ /**
1740
+ * Streams a response from the v-next network loop
1741
+ * @param params - Stream parameters including message
1742
+ * @returns Promise containing the results
1743
+ */
1744
+ async loopStream(params, onRecord) {
1745
+ const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
1746
+ method: "POST",
1747
+ body: params,
1748
+ stream: true
1749
+ });
1750
+ if (!response.ok) {
1751
+ throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
1752
+ }
1753
+ if (!response.body) {
1754
+ throw new Error("Response body is null");
1755
+ }
1756
+ for await (const record of this.streamProcessor(response.body)) {
1757
+ if (typeof record === "string") {
1758
+ onRecord(JSON.parse(record));
1759
+ } else {
1760
+ onRecord(record);
1761
+ }
1762
+ }
1763
+ }
1702
1764
  };
1703
1765
 
1704
1766
  // src/resources/network-memory-thread.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/client-js",
3
- "version": "0.0.0-fix-fetching-workflow-snapshots-20250625000954",
3
+ "version": "0.0.0-http-transporter-20250702160118",
4
4
  "description": "The official TypeScript library for the Mastra Client API",
5
5
  "author": "",
6
6
  "type": "module",
@@ -33,7 +33,7 @@
33
33
  "rxjs": "7.8.1",
34
34
  "zod": "^3.25.67",
35
35
  "zod-to-json-schema": "^3.24.5",
36
- "@mastra/core": "0.0.0-fix-fetching-workflow-snapshots-20250625000954"
36
+ "@mastra/core": "0.0.0-http-transporter-20250702160118"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "zod": "^3.0.0"
@@ -46,8 +46,8 @@
46
46
  "@types/node": "^20.19.0",
47
47
  "tsup": "^8.5.0",
48
48
  "typescript": "^5.8.3",
49
- "vitest": "^3.2.3",
50
- "@internal/lint": "0.0.0-fix-fetching-workflow-snapshots-20250625000954"
49
+ "vitest": "^3.2.4",
50
+ "@internal/lint": "0.0.0-http-transporter-20250702160118"
51
51
  },
52
52
  "scripts": {
53
53
  "build": "tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting",
@@ -604,87 +604,115 @@ export class Agent extends BaseResource {
604
604
  let messages: UIMessage[] = [];
605
605
  let hasProcessedToolCalls = false;
606
606
 
607
- response.clone().body!.pipeTo(writable);
607
+ // Use tee() to split the stream into two branches
608
+ const [streamForWritable, streamForProcessing] = response.body.tee();
609
+
610
+ // Pipe one branch to the writable stream
611
+ streamForWritable
612
+ .pipeTo(writable, {
613
+ preventClose: true,
614
+ })
615
+ .catch(error => {
616
+ console.error('Error piping to writable stream:', error);
617
+ });
608
618
 
609
- await this.processChatResponse({
610
- stream: response.clone().body!,
619
+ // Process the other branch for chat response handling
620
+ this.processChatResponse({
621
+ stream: streamForProcessing,
611
622
  update: ({ message }) => {
612
623
  messages.push(message);
613
624
  },
614
- onFinish: ({ finishReason, message }) => {
625
+ onFinish: async ({ finishReason, message }) => {
615
626
  if (finishReason === 'tool-calls') {
616
- finishReasonToolCalls = true;
617
627
  const toolCall = [...(message?.parts ?? [])]
618
628
  .reverse()
619
629
  .find(part => part.type === 'tool-invocation')?.toolInvocation;
620
630
  if (toolCall) {
621
631
  toolCalls.push(toolCall);
622
632
  }
633
+
634
+ // Handle tool calls if needed
635
+ for (const toolCall of toolCalls) {
636
+ const clientTool = processedParams.clientTools?.[toolCall.toolName] as Tool;
637
+ if (clientTool && clientTool.execute) {
638
+ const result = await clientTool.execute(
639
+ {
640
+ context: toolCall?.args,
641
+ runId: processedParams.runId,
642
+ resourceId: processedParams.resourceId,
643
+ threadId: processedParams.threadId,
644
+ runtimeContext: processedParams.runtimeContext as RuntimeContext,
645
+ },
646
+ {
647
+ messages: (response as unknown as { messages: CoreMessage[] }).messages,
648
+ toolCallId: toolCall?.toolCallId,
649
+ },
650
+ );
651
+
652
+ const lastMessage: UIMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
653
+
654
+ const toolInvocationPart = lastMessage?.parts?.find(
655
+ part => part.type === 'tool-invocation' && part.toolInvocation?.toolCallId === toolCall.toolCallId,
656
+ ) as ToolInvocationUIPart | undefined;
657
+
658
+ if (toolInvocationPart) {
659
+ toolInvocationPart.toolInvocation = {
660
+ ...toolInvocationPart.toolInvocation,
661
+ state: 'result',
662
+ result,
663
+ };
664
+ }
665
+
666
+ const toolInvocation = lastMessage?.toolInvocations?.find(
667
+ toolInvocation => toolInvocation.toolCallId === toolCall.toolCallId,
668
+ ) as ToolInvocation | undefined;
669
+
670
+ if (toolInvocation) {
671
+ toolInvocation.state = 'result';
672
+ // @ts-ignore
673
+ toolInvocation.result = result;
674
+ }
675
+
676
+ // write the tool result part to the stream
677
+ const writer = writable.getWriter();
678
+
679
+ try {
680
+ await writer.write(
681
+ new TextEncoder().encode(
682
+ 'a:' +
683
+ JSON.stringify({
684
+ toolCallId: toolCall.toolCallId,
685
+ result,
686
+ }) +
687
+ '\n',
688
+ ),
689
+ );
690
+ } finally {
691
+ writer.releaseLock();
692
+ }
693
+
694
+ // Convert messages to the correct format for the recursive call
695
+ const originalMessages = processedParams.messages;
696
+ const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
697
+
698
+ // Recursively call stream with updated messages
699
+ this.processStreamResponse(
700
+ {
701
+ ...processedParams,
702
+ messages: [...messageArray, ...messages, lastMessage],
703
+ },
704
+ writable,
705
+ );
706
+ }
707
+ }
708
+ } else {
709
+ setTimeout(() => {
710
+ writable.close();
711
+ }, 0);
623
712
  }
624
713
  },
625
714
  lastMessage: undefined,
626
715
  });
627
-
628
- // Handle tool calls if needed
629
- if (finishReasonToolCalls && !hasProcessedToolCalls) {
630
- hasProcessedToolCalls = true;
631
-
632
- for (const toolCall of toolCalls) {
633
- const clientTool = processedParams.clientTools?.[toolCall.toolName] as Tool;
634
- if (clientTool && clientTool.execute) {
635
- const result = await clientTool.execute(
636
- {
637
- context: toolCall?.args,
638
- runId: processedParams.runId,
639
- resourceId: processedParams.resourceId,
640
- threadId: processedParams.threadId,
641
- runtimeContext: processedParams.runtimeContext as RuntimeContext,
642
- },
643
- {
644
- messages: (response as unknown as { messages: CoreMessage[] }).messages,
645
- toolCallId: toolCall?.toolCallId,
646
- },
647
- );
648
-
649
- const lastMessage: UIMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
650
-
651
- const toolInvocationPart = lastMessage?.parts?.find(
652
- part => part.type === 'tool-invocation' && part.toolInvocation?.toolCallId === toolCall.toolCallId,
653
- ) as ToolInvocationUIPart | undefined;
654
-
655
- if (toolInvocationPart) {
656
- toolInvocationPart.toolInvocation = {
657
- ...toolInvocationPart.toolInvocation,
658
- state: 'result',
659
- result,
660
- };
661
- }
662
-
663
- const toolInvocation = lastMessage?.toolInvocations?.find(
664
- toolInvocation => toolInvocation.toolCallId === toolCall.toolCallId,
665
- ) as ToolInvocation | undefined;
666
-
667
- if (toolInvocation) {
668
- toolInvocation.state = 'result';
669
- // @ts-ignore
670
- toolInvocation.result = result;
671
- }
672
-
673
- // Convert messages to the correct format for the recursive call
674
- const originalMessages = processedParams.messages;
675
- const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
676
-
677
- // Recursively call stream with updated messages
678
- this.processStreamResponse(
679
- {
680
- ...processedParams,
681
- messages: [...messageArray, ...messages, lastMessage],
682
- },
683
- writable,
684
- );
685
- }
686
- }
687
- }
688
716
  } catch (error) {
689
717
  console.error('Error processing stream response:', error);
690
718
  }
@@ -6,6 +6,7 @@ import type {
6
6
  GenerateVNextNetworkResponse,
7
7
  LoopVNextNetworkResponse,
8
8
  GenerateOrStreamVNextNetworkParams,
9
+ LoopStreamVNextNetworkParams,
9
10
  } from '../types';
10
11
 
11
12
  import { BaseResource } from './base';
@@ -144,4 +145,33 @@ export class VNextNetwork extends BaseResource {
144
145
  }
145
146
  }
146
147
  }
148
+
149
+ /**
150
+ * Streams a response from the v-next network loop
151
+ * @param params - Stream parameters including message
152
+ * @returns Promise containing the results
153
+ */
154
+ async loopStream(params: LoopStreamVNextNetworkParams, onRecord: (record: WatchEvent) => void) {
155
+ const response: Response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
156
+ method: 'POST',
157
+ body: params,
158
+ stream: true,
159
+ });
160
+
161
+ if (!response.ok) {
162
+ throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
163
+ }
164
+
165
+ if (!response.body) {
166
+ throw new Error('Response body is null');
167
+ }
168
+
169
+ for await (const record of this.streamProcessor(response.body)) {
170
+ if (typeof record === 'string') {
171
+ onRecord(JSON.parse(record));
172
+ } else {
173
+ onRecord(record);
174
+ }
175
+ }
176
+ }
147
177
  }
@@ -115,10 +115,10 @@ export class Workflow extends BaseResource {
115
115
  if (params?.toDate) {
116
116
  searchParams.set('toDate', params.toDate.toISOString());
117
117
  }
118
- if (params?.limit !== undefined) {
118
+ if (params?.limit !== null && params?.limit !== undefined && !isNaN(Number(params?.limit))) {
119
119
  searchParams.set('limit', String(params.limit));
120
120
  }
121
- if (params?.offset !== undefined) {
121
+ if (params?.offset !== null && params?.offset !== undefined && !isNaN(Number(params?.offset))) {
122
122
  searchParams.set('offset', String(params.offset));
123
123
  }
124
124
  if (params?.resourceId) {
@@ -150,6 +150,29 @@ export class Workflow extends BaseResource {
150
150
  return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
151
151
  }
152
152
 
153
+ /**
154
+ * Cancels a specific workflow run by its ID
155
+ * @param runId - The ID of the workflow run to cancel
156
+ * @returns Promise containing a success message
157
+ */
158
+ cancelRun(runId: string): Promise<{ message: string }> {
159
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/cancel`, {
160
+ method: 'POST',
161
+ });
162
+ }
163
+
164
+ /**
165
+ * Sends an event to a specific workflow run by its ID
166
+ * @param params - Object containing the runId, event and data
167
+ * @returns Promise containing a success message
168
+ */
169
+ sendRunEvent(params: { runId: string; event: string; data: unknown }): Promise<{ message: string }> {
170
+ return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
171
+ method: 'POST',
172
+ body: { event: params.event, data: params.data },
173
+ });
174
+ }
175
+
153
176
  /**
154
177
  * Creates a new workflow run
155
178
  * @param params - Optional object containing the optional runId
@@ -267,7 +290,7 @@ export class Workflow extends BaseResource {
267
290
  }
268
291
 
269
292
  // Create a transform stream that processes the response body
270
- const transformStream = new TransformStream<ArrayBuffer, WorkflowWatchResult>({
293
+ const transformStream = new TransformStream<ArrayBuffer, { type: string; payload: any }>({
271
294
  start() {},
272
295
  async transform(chunk, controller) {
273
296
  try {
package/src/types.ts CHANGED
@@ -140,6 +140,17 @@ export interface GetWorkflowResponse {
140
140
  suspendSchema: string;
141
141
  };
142
142
  };
143
+ allSteps: {
144
+ [key: string]: {
145
+ id: string;
146
+ description: string;
147
+ inputSchema: string;
148
+ outputSchema: string;
149
+ resumeSchema: string;
150
+ suspendSchema: string;
151
+ isWorkflow: boolean;
152
+ };
153
+ };
143
154
  stepGraph: Workflow['serializedStepGraph'];
144
155
  inputSchema: string;
145
156
  outputSchema: string;
@@ -358,6 +369,10 @@ export interface GetVNextNetworkResponse {
358
369
  inputSchema: string | undefined;
359
370
  outputSchema: string | undefined;
360
371
  }>;
372
+ tools: Array<{
373
+ id: string;
374
+ description: string;
375
+ }>;
361
376
  }
362
377
 
363
378
  export interface GenerateVNextNetworkResponse {
@@ -373,6 +388,13 @@ export interface GenerateOrStreamVNextNetworkParams {
373
388
  resourceId?: string;
374
389
  }
375
390
 
391
+ export interface LoopStreamVNextNetworkParams {
392
+ message: string;
393
+ threadId?: string;
394
+ resourceId?: string;
395
+ maxIterations?: number;
396
+ }
397
+
376
398
  export interface LoopVNextNetworkResponse {
377
399
  status: 'success';
378
400
  result: {