@mastra/client-js 0.0.0-generate-message-id-20250512171942 → 0.0.0-gl-test-20250917080133

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 (78) hide show
  1. package/CHANGELOG.md +1708 -4
  2. package/LICENSE.md +11 -42
  3. package/README.md +8 -9
  4. package/dist/client.d.ts +284 -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 +2790 -608
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.ts +5 -790
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +2791 -611
  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 +160 -0
  17. package/dist/resources/agent-builder.d.ts.map +1 -0
  18. package/dist/resources/agent.d.ts +175 -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 +13 -0
  23. package/dist/resources/index.d.ts.map +1 -0
  24. package/dist/resources/legacy-workflow.d.ts +90 -0
  25. package/dist/resources/legacy-workflow.d.ts.map +1 -0
  26. package/dist/resources/mcp-tool.d.ts +28 -0
  27. package/dist/resources/mcp-tool.d.ts.map +1 -0
  28. package/dist/resources/memory-thread.d.ts +53 -0
  29. package/dist/resources/memory-thread.d.ts.map +1 -0
  30. package/dist/resources/network-memory-thread.d.ts +47 -0
  31. package/dist/resources/network-memory-thread.d.ts.map +1 -0
  32. package/dist/resources/network.d.ts +32 -0
  33. package/dist/resources/network.d.ts.map +1 -0
  34. package/dist/resources/observability.d.ts +19 -0
  35. package/dist/resources/observability.d.ts.map +1 -0
  36. package/dist/resources/tool.d.ts +24 -0
  37. package/dist/resources/tool.d.ts.map +1 -0
  38. package/dist/resources/vNextNetwork.d.ts +43 -0
  39. package/dist/resources/vNextNetwork.d.ts.map +1 -0
  40. package/dist/resources/vector.d.ts +51 -0
  41. package/dist/resources/vector.d.ts.map +1 -0
  42. package/dist/resources/workflow.d.ts +226 -0
  43. package/dist/resources/workflow.d.ts.map +1 -0
  44. package/dist/tools.d.ts +22 -0
  45. package/dist/tools.d.ts.map +1 -0
  46. package/dist/types.d.ts +469 -0
  47. package/dist/types.d.ts.map +1 -0
  48. package/dist/utils/index.d.ts +5 -0
  49. package/dist/utils/index.d.ts.map +1 -0
  50. package/dist/utils/process-client-tools.d.ts +3 -0
  51. package/dist/utils/process-client-tools.d.ts.map +1 -0
  52. package/dist/utils/process-mastra-stream.d.ts +11 -0
  53. package/dist/utils/process-mastra-stream.d.ts.map +1 -0
  54. package/dist/utils/zod-to-json-schema.d.ts +3 -0
  55. package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
  56. package/package.json +37 -20
  57. package/dist/index.d.cts +0 -790
  58. package/eslint.config.js +0 -6
  59. package/src/adapters/agui.test.ts +0 -180
  60. package/src/adapters/agui.ts +0 -239
  61. package/src/client.ts +0 -268
  62. package/src/example.ts +0 -65
  63. package/src/index.test.ts +0 -710
  64. package/src/index.ts +0 -2
  65. package/src/resources/a2a.ts +0 -88
  66. package/src/resources/agent.ts +0 -196
  67. package/src/resources/base.ts +0 -70
  68. package/src/resources/index.ts +0 -9
  69. package/src/resources/memory-thread.ts +0 -53
  70. package/src/resources/network.ts +0 -86
  71. package/src/resources/tool.ts +0 -44
  72. package/src/resources/vector.ts +0 -83
  73. package/src/resources/vnext-workflow.ts +0 -261
  74. package/src/resources/workflow.ts +0 -251
  75. package/src/types.ts +0 -262
  76. package/src/utils/zod-to-json-schema.ts +0 -10
  77. package/tsconfig.json +0 -5
  78. package/vitest.config.js +0 -8
@@ -1,261 +0,0 @@
1
- import { 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
- const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined;
160
- return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
161
- method: 'POST',
162
- body: { inputData: params?.inputData, runtimeContext },
163
- });
164
- }
165
-
166
- /**
167
- * Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
168
- * @param params - Object containing the runId, step, resumeData and runtimeContext
169
- * @returns Promise containing success message
170
- */
171
- resume({
172
- step,
173
- runId,
174
- resumeData,
175
- ...rest
176
- }: {
177
- step: string | string[];
178
- runId: string;
179
- resumeData?: Record<string, any>;
180
- runtimeContext?: RuntimeContext;
181
- }): Promise<{ message: string }> {
182
- const runtimeContext = rest.runtimeContext ? Object.fromEntries(rest.runtimeContext.entries()) : undefined;
183
- return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
184
- method: 'POST',
185
- stream: true,
186
- body: {
187
- step,
188
- resumeData,
189
- runtimeContext,
190
- },
191
- });
192
- }
193
-
194
- /**
195
- * Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
196
- * @param params - Object containing the optional runId, inputData and runtimeContext
197
- * @returns Promise containing the vNext workflow execution results
198
- */
199
- startAsync(params: {
200
- runId?: string;
201
- inputData: Record<string, any>;
202
- runtimeContext?: RuntimeContext;
203
- }): Promise<VNextWorkflowRunResult> {
204
- const searchParams = new URLSearchParams();
205
-
206
- if (!!params?.runId) {
207
- searchParams.set('runId', params.runId);
208
- }
209
-
210
- const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined;
211
- return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
212
- method: 'POST',
213
- body: { inputData: params.inputData, runtimeContext },
214
- });
215
- }
216
-
217
- /**
218
- * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
219
- * @param params - Object containing the runId, step, resumeData and runtimeContext
220
- * @returns Promise containing the vNext workflow resume results
221
- */
222
- resumeAsync(params: {
223
- runId: string;
224
- step: string | string[];
225
- resumeData?: Record<string, any>;
226
- runtimeContext?: RuntimeContext;
227
- }): Promise<VNextWorkflowRunResult> {
228
- const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined;
229
- return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
230
- method: 'POST',
231
- body: {
232
- step: params.step,
233
- resumeData: params.resumeData,
234
- runtimeContext,
235
- },
236
- });
237
- }
238
-
239
- /**
240
- * Watches vNext workflow transitions in real-time
241
- * @param runId - Optional run ID to filter the watch stream
242
- * @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
243
- */
244
- async watch({ runId }: { runId?: string }, onRecord: (record: VNextWorkflowWatchResult) => void) {
245
- const response: Response = await this.request(`/api/workflows/v-next/${this.workflowId}/watch?runId=${runId}`, {
246
- stream: true,
247
- });
248
-
249
- if (!response.ok) {
250
- throw new Error(`Failed to watch vNext workflow: ${response.statusText}`);
251
- }
252
-
253
- if (!response.body) {
254
- throw new Error('Response body is null');
255
- }
256
-
257
- for await (const record of this.streamProcessor(response.body)) {
258
- onRecord(record);
259
- }
260
- }
261
- }
@@ -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
- }