@mastra/client-js 0.0.0-vnext-inngest-20250508131921 → 0.0.0-vnext-20251104230439

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.
Files changed (68) hide show
  1. package/CHANGELOG.md +2389 -2
  2. package/LICENSE.md +11 -42
  3. package/README.md +12 -15
  4. package/dist/client.d.ts +254 -0
  5. package/dist/client.d.ts.map +1 -0
  6. package/dist/example.d.ts +2 -0
  7. package/dist/example.d.ts.map +1 -0
  8. package/dist/index.cjs +2594 -548
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.ts +5 -730
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +2593 -553
  13. package/dist/index.js.map +1 -0
  14. package/dist/resources/a2a.d.ts +41 -0
  15. package/dist/resources/a2a.d.ts.map +1 -0
  16. package/dist/resources/agent-builder.d.ts +186 -0
  17. package/dist/resources/agent-builder.d.ts.map +1 -0
  18. package/dist/resources/agent.d.ts +181 -0
  19. package/dist/resources/agent.d.ts.map +1 -0
  20. package/dist/resources/base.d.ts +13 -0
  21. package/dist/resources/base.d.ts.map +1 -0
  22. package/dist/resources/index.d.ts +11 -0
  23. package/dist/resources/index.d.ts.map +1 -0
  24. package/dist/resources/mcp-tool.d.ts +28 -0
  25. package/dist/resources/mcp-tool.d.ts.map +1 -0
  26. package/dist/resources/memory-thread.d.ts +61 -0
  27. package/dist/resources/memory-thread.d.ts.map +1 -0
  28. package/dist/resources/observability.d.ts +35 -0
  29. package/dist/resources/observability.d.ts.map +1 -0
  30. package/dist/resources/tool.d.ts +24 -0
  31. package/dist/resources/tool.d.ts.map +1 -0
  32. package/dist/resources/vector.d.ts +51 -0
  33. package/dist/resources/vector.d.ts.map +1 -0
  34. package/dist/resources/workflow.d.ts +216 -0
  35. package/dist/resources/workflow.d.ts.map +1 -0
  36. package/dist/tools.d.ts +22 -0
  37. package/dist/tools.d.ts.map +1 -0
  38. package/dist/types.d.ts +457 -0
  39. package/dist/types.d.ts.map +1 -0
  40. package/dist/utils/index.d.ts +11 -0
  41. package/dist/utils/index.d.ts.map +1 -0
  42. package/dist/utils/process-client-tools.d.ts +3 -0
  43. package/dist/utils/process-client-tools.d.ts.map +1 -0
  44. package/dist/utils/process-mastra-stream.d.ts +11 -0
  45. package/dist/utils/process-mastra-stream.d.ts.map +1 -0
  46. package/dist/utils/zod-to-json-schema.d.ts +3 -0
  47. package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
  48. package/package.json +38 -20
  49. package/dist/index.d.cts +0 -730
  50. package/eslint.config.js +0 -6
  51. package/src/adapters/agui.test.ts +0 -167
  52. package/src/adapters/agui.ts +0 -219
  53. package/src/client.ts +0 -259
  54. package/src/example.ts +0 -65
  55. package/src/index.test.ts +0 -710
  56. package/src/index.ts +0 -2
  57. package/src/resources/agent.ts +0 -206
  58. package/src/resources/base.ts +0 -70
  59. package/src/resources/index.ts +0 -8
  60. package/src/resources/memory-thread.ts +0 -53
  61. package/src/resources/network.ts +0 -92
  62. package/src/resources/tool.ts +0 -38
  63. package/src/resources/vector.ts +0 -83
  64. package/src/resources/vnext-workflow.ts +0 -257
  65. package/src/resources/workflow.ts +0 -251
  66. package/src/types.ts +0 -262
  67. package/tsconfig.json +0 -5
  68. package/vitest.config.js +0 -8
@@ -1,257 +0,0 @@
1
- import type { RuntimeContext } from '@mastra/core/runtime-context';
2
- import type {
3
- ClientOptions,
4
- GetVNextWorkflowResponse,
5
- GetWorkflowRunsParams,
6
- GetWorkflowRunsResponse,
7
- VNextWorkflowRunResult,
8
- VNextWorkflowWatchResult,
9
- } from '../types';
10
-
11
- import { BaseResource } from './base';
12
-
13
- const RECORD_SEPARATOR = '\x1E';
14
-
15
- export class VNextWorkflow extends BaseResource {
16
- constructor(
17
- options: ClientOptions,
18
- private workflowId: string,
19
- ) {
20
- super(options);
21
- }
22
-
23
- /**
24
- * Creates an async generator that processes a readable stream and yields vNext workflow records
25
- * separated by the Record Separator character (\x1E)
26
- *
27
- * @param stream - The readable stream to process
28
- * @returns An async generator that yields parsed records
29
- */
30
- private async *streamProcessor(stream: ReadableStream): AsyncGenerator<VNextWorkflowWatchResult, void, unknown> {
31
- const reader = stream.getReader();
32
-
33
- // Track if we've finished reading from the stream
34
- let doneReading = false;
35
- // Buffer to accumulate partial chunks
36
- let buffer = '';
37
-
38
- try {
39
- while (!doneReading) {
40
- // Read the next chunk from the stream
41
- const { done, value } = await reader.read();
42
- doneReading = done;
43
-
44
- // Skip processing if we're done and there's no value
45
- if (done && !value) continue;
46
-
47
- try {
48
- // Decode binary data to text
49
- const decoded = value ? new TextDecoder().decode(value) : '';
50
-
51
- // Split the combined buffer and new data by record separator
52
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
53
-
54
- // The last chunk might be incomplete, so save it for the next iteration
55
- buffer = chunks.pop() || '';
56
-
57
- // Process complete chunks
58
- for (const chunk of chunks) {
59
- if (chunk) {
60
- // Only process non-empty chunks
61
- if (typeof chunk === 'string') {
62
- try {
63
- const parsedChunk = JSON.parse(chunk);
64
- yield parsedChunk;
65
- } catch {
66
- // Silently ignore parsing errors to maintain stream processing
67
- // This allows the stream to continue even if one record is malformed
68
- }
69
- }
70
- }
71
- }
72
- } catch {
73
- // Silently ignore parsing errors to maintain stream processing
74
- // This allows the stream to continue even if one record is malformed
75
- }
76
- }
77
-
78
- // Process any remaining data in the buffer after stream is done
79
- if (buffer) {
80
- try {
81
- yield JSON.parse(buffer);
82
- } catch {
83
- // Ignore parsing error for final chunk
84
- }
85
- }
86
- } finally {
87
- // Always ensure we clean up the reader
88
- reader.cancel().catch(() => {
89
- // Ignore cancel errors
90
- });
91
- }
92
- }
93
-
94
- /**
95
- * Retrieves details about the vNext workflow
96
- * @returns Promise containing vNext workflow details including steps and graphs
97
- */
98
- details(): Promise<GetVNextWorkflowResponse> {
99
- return this.request(`/api/workflows/v-next/${this.workflowId}`);
100
- }
101
-
102
- /**
103
- * Retrieves all runs for a vNext workflow
104
- * @param params - Parameters for filtering runs
105
- * @returns Promise containing vNext workflow runs array
106
- */
107
- runs(params?: GetWorkflowRunsParams): Promise<GetWorkflowRunsResponse> {
108
- const searchParams = new URLSearchParams();
109
- if (params?.fromDate) {
110
- searchParams.set('fromDate', params.fromDate.toISOString());
111
- }
112
- if (params?.toDate) {
113
- searchParams.set('toDate', params.toDate.toISOString());
114
- }
115
- if (params?.limit) {
116
- searchParams.set('limit', String(params.limit));
117
- }
118
- if (params?.offset) {
119
- searchParams.set('offset', String(params.offset));
120
- }
121
- if (params?.resourceId) {
122
- searchParams.set('resourceId', params.resourceId);
123
- }
124
-
125
- if (searchParams.size) {
126
- return this.request(`/api/workflows/v-next/${this.workflowId}/runs?${searchParams}`);
127
- } else {
128
- return this.request(`/api/workflows/v-next/${this.workflowId}/runs`);
129
- }
130
- }
131
-
132
- /**
133
- * Creates a new vNext workflow run
134
- * @param params - Optional object containing the optional runId
135
- * @returns Promise containing the runId of the created run
136
- */
137
- createRun(params?: { runId?: string }): Promise<{ runId: string }> {
138
- const searchParams = new URLSearchParams();
139
-
140
- if (!!params?.runId) {
141
- searchParams.set('runId', params.runId);
142
- }
143
-
144
- return this.request(`/api/workflows/v-next/${this.workflowId}/create-run?${searchParams.toString()}`, {
145
- method: 'POST',
146
- });
147
- }
148
-
149
- /**
150
- * Starts a vNext workflow run synchronously without waiting for the workflow to complete
151
- * @param params - Object containing the runId, inputData and runtimeContext
152
- * @returns Promise containing success message
153
- */
154
- start(params: {
155
- runId: string;
156
- inputData: Record<string, any>;
157
- runtimeContext?: RuntimeContext;
158
- }): Promise<{ message: string }> {
159
- return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
160
- method: 'POST',
161
- body: { inputData: params?.inputData, runtimeContext: params.runtimeContext },
162
- });
163
- }
164
-
165
- /**
166
- * Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
167
- * @param params - Object containing the runId, step, resumeData and runtimeContext
168
- * @returns Promise containing success message
169
- */
170
- resume({
171
- step,
172
- runId,
173
- resumeData,
174
- runtimeContext,
175
- }: {
176
- step: string | string[];
177
- runId: string;
178
- resumeData?: Record<string, any>;
179
- runtimeContext?: RuntimeContext;
180
- }): Promise<{ message: string }> {
181
- return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
182
- method: 'POST',
183
- stream: true,
184
- body: {
185
- step,
186
- resumeData,
187
- runtimeContext,
188
- },
189
- });
190
- }
191
-
192
- /**
193
- * Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
194
- * @param params - Object containing the optional runId, inputData and runtimeContext
195
- * @returns Promise containing the vNext workflow execution results
196
- */
197
- startAsync(params: {
198
- runId?: string;
199
- inputData: Record<string, any>;
200
- runtimeContext?: RuntimeContext;
201
- }): Promise<VNextWorkflowRunResult> {
202
- const searchParams = new URLSearchParams();
203
-
204
- if (!!params?.runId) {
205
- searchParams.set('runId', params.runId);
206
- }
207
-
208
- return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
209
- method: 'POST',
210
- body: { inputData: params.inputData, runtimeContext: params.runtimeContext },
211
- });
212
- }
213
-
214
- /**
215
- * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
216
- * @param params - Object containing the runId, step, resumeData and runtimeContext
217
- * @returns Promise containing the vNext workflow resume results
218
- */
219
- resumeAsync(params: {
220
- runId: string;
221
- step: string | string[];
222
- resumeData?: Record<string, any>;
223
- runtimeContext?: RuntimeContext;
224
- }): Promise<VNextWorkflowRunResult> {
225
- return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
226
- method: 'POST',
227
- body: {
228
- step: params.step,
229
- resumeData: params.resumeData,
230
- runtimeContext: params.runtimeContext,
231
- },
232
- });
233
- }
234
-
235
- /**
236
- * Watches vNext workflow transitions in real-time
237
- * @param runId - Optional run ID to filter the watch stream
238
- * @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
239
- */
240
- async watch({ runId }: { runId?: string }, onRecord: (record: VNextWorkflowWatchResult) => void) {
241
- const response: Response = await this.request(`/api/workflows/v-next/${this.workflowId}/watch?runId=${runId}`, {
242
- stream: true,
243
- });
244
-
245
- if (!response.ok) {
246
- throw new Error(`Failed to watch vNext workflow: ${response.statusText}`);
247
- }
248
-
249
- if (!response.body) {
250
- throw new Error('Response body is null');
251
- }
252
-
253
- for await (const record of this.streamProcessor(response.body)) {
254
- onRecord(record);
255
- }
256
- }
257
- }
@@ -1,251 +0,0 @@
1
- import type {
2
- GetWorkflowResponse,
3
- ClientOptions,
4
- WorkflowRunResult,
5
- GetWorkflowRunsResponse,
6
- GetWorkflowRunsParams,
7
- } from '../types';
8
-
9
- import { BaseResource } from './base';
10
-
11
- const RECORD_SEPARATOR = '\x1E';
12
-
13
- export class Workflow extends BaseResource {
14
- constructor(
15
- options: ClientOptions,
16
- private workflowId: string,
17
- ) {
18
- super(options);
19
- }
20
-
21
- /**
22
- * Retrieves details about the workflow
23
- * @returns Promise containing workflow details including steps and graphs
24
- */
25
- details(): Promise<GetWorkflowResponse> {
26
- return this.request(`/api/workflows/${this.workflowId}`);
27
- }
28
-
29
- /**
30
- * Retrieves all runs for a workflow
31
- * @param params - Parameters for filtering runs
32
- * @returns Promise containing workflow runs array
33
- */
34
- runs(params?: GetWorkflowRunsParams): Promise<GetWorkflowRunsResponse> {
35
- const searchParams = new URLSearchParams();
36
- if (params?.fromDate) {
37
- searchParams.set('fromDate', params.fromDate.toISOString());
38
- }
39
- if (params?.toDate) {
40
- searchParams.set('toDate', params.toDate.toISOString());
41
- }
42
- if (params?.limit) {
43
- searchParams.set('limit', String(params.limit));
44
- }
45
- if (params?.offset) {
46
- searchParams.set('offset', String(params.offset));
47
- }
48
- if (params?.resourceId) {
49
- searchParams.set('resourceId', params.resourceId);
50
- }
51
-
52
- if (searchParams.size) {
53
- return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
54
- } else {
55
- return this.request(`/api/workflows/${this.workflowId}/runs`);
56
- }
57
- }
58
-
59
- /**
60
- * @deprecated Use `startAsync` instead
61
- * Executes the workflow with the provided parameters
62
- * @param params - Parameters required for workflow execution
63
- * @returns Promise containing the workflow execution results
64
- */
65
- execute(params: Record<string, any>): Promise<WorkflowRunResult> {
66
- return this.request(`/api/workflows/${this.workflowId}/execute`, {
67
- method: 'POST',
68
- body: params,
69
- });
70
- }
71
-
72
- /**
73
- * Creates a new workflow run
74
- * @returns Promise containing the generated run ID
75
- */
76
- createRun(params?: { runId?: string }): Promise<{ runId: string }> {
77
- const searchParams = new URLSearchParams();
78
-
79
- if (!!params?.runId) {
80
- searchParams.set('runId', params.runId);
81
- }
82
-
83
- return this.request(`/api/workflows/${this.workflowId}/createRun?${searchParams.toString()}`, {
84
- method: 'POST',
85
- });
86
- }
87
-
88
- /**
89
- * Starts a workflow run synchronously without waiting for the workflow to complete
90
- * @param params - Object containing the runId and triggerData
91
- * @returns Promise containing success message
92
- */
93
- start(params: { runId: string; triggerData: Record<string, any> }): Promise<{ message: string }> {
94
- return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
95
- method: 'POST',
96
- body: params?.triggerData,
97
- });
98
- }
99
-
100
- /**
101
- * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
102
- * @param stepId - ID of the step to resume
103
- * @param runId - ID of the workflow run
104
- * @param context - Context to resume the workflow with
105
- * @returns Promise containing the workflow resume results
106
- */
107
- resume({
108
- stepId,
109
- runId,
110
- context,
111
- }: {
112
- stepId: string;
113
- runId: string;
114
- context: Record<string, any>;
115
- }): Promise<{ message: string }> {
116
- return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
117
- method: 'POST',
118
- body: {
119
- stepId,
120
- context,
121
- },
122
- });
123
- }
124
-
125
- /**
126
- * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
127
- * @param params - Object containing the optional runId and triggerData
128
- * @returns Promise containing the workflow execution results
129
- */
130
- startAsync(params: { runId?: string; triggerData: Record<string, any> }): Promise<WorkflowRunResult> {
131
- const searchParams = new URLSearchParams();
132
-
133
- if (!!params?.runId) {
134
- searchParams.set('runId', params.runId);
135
- }
136
-
137
- return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
138
- method: 'POST',
139
- body: params?.triggerData,
140
- });
141
- }
142
-
143
- /**
144
- * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
145
- * @param params - Object containing the runId, stepId, and context
146
- * @returns Promise containing the workflow resume results
147
- */
148
- resumeAsync(params: { runId: string; stepId: string; context: Record<string, any> }): Promise<WorkflowRunResult> {
149
- return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
150
- method: 'POST',
151
- body: {
152
- stepId: params.stepId,
153
- context: params.context,
154
- },
155
- });
156
- }
157
-
158
- /**
159
- * Creates an async generator that processes a readable stream and yields records
160
- * separated by the Record Separator character (\x1E)
161
- *
162
- * @param stream - The readable stream to process
163
- * @returns An async generator that yields parsed records
164
- */
165
- private async *streamProcessor(stream: ReadableStream): AsyncGenerator<WorkflowRunResult, void, unknown> {
166
- const reader = stream.getReader();
167
-
168
- // Track if we've finished reading from the stream
169
- let doneReading = false;
170
- // Buffer to accumulate partial chunks
171
- let buffer = '';
172
-
173
- try {
174
- while (!doneReading) {
175
- // Read the next chunk from the stream
176
- const { done, value } = await reader.read();
177
- doneReading = done;
178
-
179
- // Skip processing if we're done and there's no value
180
- if (done && !value) continue;
181
-
182
- try {
183
- // Decode binary data to text
184
- const decoded = value ? new TextDecoder().decode(value) : '';
185
-
186
- // Split the combined buffer and new data by record separator
187
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
188
-
189
- // The last chunk might be incomplete, so save it for the next iteration
190
- buffer = chunks.pop() || '';
191
-
192
- // Process complete chunks
193
- for (const chunk of chunks) {
194
- if (chunk) {
195
- // Only process non-empty chunks
196
- if (typeof chunk === 'string') {
197
- try {
198
- const parsedChunk = JSON.parse(chunk);
199
- yield parsedChunk;
200
- } catch {
201
- // Silently ignore parsing errors to maintain stream processing
202
- // This allows the stream to continue even if one record is malformed
203
- }
204
- }
205
- }
206
- }
207
- } catch {
208
- // Silently ignore parsing errors to maintain stream processing
209
- // This allows the stream to continue even if one record is malformed
210
- }
211
- }
212
-
213
- // Process any remaining data in the buffer after stream is done
214
- if (buffer) {
215
- try {
216
- yield JSON.parse(buffer);
217
- } catch {
218
- // Ignore parsing error for final chunk
219
- }
220
- }
221
- } finally {
222
- // Always ensure we clean up the reader
223
- reader.cancel().catch(() => {
224
- // Ignore cancel errors
225
- });
226
- }
227
- }
228
-
229
- /**
230
- * Watches workflow transitions in real-time
231
- * @param runId - Optional run ID to filter the watch stream
232
- * @returns AsyncGenerator that yields parsed records from the workflow watch stream
233
- */
234
- async watch({ runId }: { runId?: string }, onRecord: (record: WorkflowRunResult) => void) {
235
- const response: Response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
236
- stream: true,
237
- });
238
-
239
- if (!response.ok) {
240
- throw new Error(`Failed to watch workflow: ${response.statusText}`);
241
- }
242
-
243
- if (!response.body) {
244
- throw new Error('Response body is null');
245
- }
246
-
247
- for await (const record of this.streamProcessor(response.body)) {
248
- onRecord(record);
249
- }
250
- }
251
- }