@mastra/client-js 0.0.0-trigger-playground-ui-package-20250506151043 → 0.0.0-update-scorers-api-20250801170445

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 (83) hide show
  1. package/CHANGELOG.md +1110 -2
  2. package/LICENSE.md +11 -42
  3. package/README.md +2 -1
  4. package/dist/adapters/agui.d.ts +23 -0
  5. package/dist/adapters/agui.d.ts.map +1 -0
  6. package/dist/client.d.ts +265 -0
  7. package/dist/client.d.ts.map +1 -0
  8. package/dist/example.d.ts +2 -0
  9. package/dist/example.d.ts.map +1 -0
  10. package/dist/index.cjs +1403 -131
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.d.ts +4 -730
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +1401 -133
  15. package/dist/index.js.map +1 -0
  16. package/dist/resources/a2a.d.ts +44 -0
  17. package/dist/resources/a2a.d.ts.map +1 -0
  18. package/dist/resources/agent.d.ts +112 -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/legacy-workflow.d.ts +87 -0
  25. package/dist/resources/legacy-workflow.d.ts.map +1 -0
  26. package/dist/resources/mcp-tool.d.ts +27 -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 +30 -0
  33. package/dist/resources/network.d.ts.map +1 -0
  34. package/dist/resources/tool.d.ts +23 -0
  35. package/dist/resources/tool.d.ts.map +1 -0
  36. package/dist/resources/vNextNetwork.d.ts +42 -0
  37. package/dist/resources/vNextNetwork.d.ts.map +1 -0
  38. package/dist/resources/vector.d.ts +48 -0
  39. package/dist/resources/vector.d.ts.map +1 -0
  40. package/dist/resources/workflow.d.ts +154 -0
  41. package/dist/resources/workflow.d.ts.map +1 -0
  42. package/dist/types.d.ts +422 -0
  43. package/dist/types.d.ts.map +1 -0
  44. package/dist/utils/index.d.ts +3 -0
  45. package/dist/utils/index.d.ts.map +1 -0
  46. package/dist/utils/process-client-tools.d.ts +3 -0
  47. package/dist/utils/process-client-tools.d.ts.map +1 -0
  48. package/dist/utils/zod-to-json-schema.d.ts +105 -0
  49. package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
  50. package/integration-tests/agui-adapter.test.ts +122 -0
  51. package/integration-tests/package.json +18 -0
  52. package/integration-tests/src/mastra/index.ts +35 -0
  53. package/integration-tests/vitest.config.ts +9 -0
  54. package/package.json +28 -19
  55. package/src/adapters/agui.test.ts +164 -9
  56. package/src/adapters/agui.ts +31 -11
  57. package/src/client.ts +386 -22
  58. package/src/example.ts +59 -29
  59. package/src/index.test.ts +522 -6
  60. package/src/index.ts +1 -0
  61. package/src/resources/a2a.ts +88 -0
  62. package/src/resources/agent.ts +629 -48
  63. package/src/resources/base.ts +7 -1
  64. package/src/resources/index.ts +4 -2
  65. package/src/resources/{vnext-workflow.ts → legacy-workflow.ts} +124 -139
  66. package/src/resources/mcp-tool.ts +48 -0
  67. package/src/resources/memory-thread.test.ts +285 -0
  68. package/src/resources/memory-thread.ts +49 -3
  69. package/src/resources/network-memory-thread.test.ts +269 -0
  70. package/src/resources/network-memory-thread.ts +81 -0
  71. package/src/resources/network.ts +10 -16
  72. package/src/resources/tool.ts +9 -2
  73. package/src/resources/vNextNetwork.ts +194 -0
  74. package/src/resources/workflow.ts +255 -96
  75. package/src/types.ts +265 -25
  76. package/src/utils/index.ts +11 -0
  77. package/src/utils/process-client-tools.ts +32 -0
  78. package/src/utils/zod-to-json-schema.ts +10 -0
  79. package/src/v2-messages.test.ts +180 -0
  80. package/tsconfig.build.json +9 -0
  81. package/tsconfig.json +1 -1
  82. package/tsup.config.ts +22 -0
  83. package/dist/index.d.cts +0 -730
@@ -1,10 +1,9 @@
1
1
  import { processDataStream } from '@ai-sdk/ui-utils';
2
2
  import type { GenerateReturn } from '@mastra/core';
3
3
  import type { JSONSchema7 } from 'json-schema';
4
- import { ZodSchema } from 'zod';
5
- import { zodToJsonSchema } from 'zod-to-json-schema';
6
-
4
+ import type { ZodSchema } from 'zod';
7
5
  import type { GenerateParams, ClientOptions, StreamParams, GetNetworkResponse } from '../types';
6
+ import { zodToJsonSchema } from '../utils/zod-to-json-schema';
8
7
 
9
8
  import { BaseResource } from './base';
10
9
 
@@ -29,16 +28,14 @@ export class Network extends BaseResource {
29
28
  * @param params - Generation parameters including prompt
30
29
  * @returns Promise containing the generated response
31
30
  */
32
- generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(
33
- params: GenerateParams<T>,
34
- ): Promise<GenerateReturn<T>> {
31
+ generate<
32
+ Output extends JSONSchema7 | ZodSchema | undefined = undefined,
33
+ StructuredOutput extends JSONSchema7 | ZodSchema | undefined = undefined,
34
+ >(params: GenerateParams<Output>): Promise<GenerateReturn<any, Output, StructuredOutput>> {
35
35
  const processedParams = {
36
36
  ...params,
37
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
38
- experimental_output:
39
- params.experimental_output instanceof ZodSchema
40
- ? zodToJsonSchema(params.experimental_output)
41
- : params.experimental_output,
37
+ output: zodToJsonSchema(params.output),
38
+ experimental_output: zodToJsonSchema(params.experimental_output),
42
39
  };
43
40
 
44
41
  return this.request(`/api/networks/${this.networkId}/generate`, {
@@ -61,11 +58,8 @@ export class Network extends BaseResource {
61
58
  > {
62
59
  const processedParams = {
63
60
  ...params,
64
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
65
- experimental_output:
66
- params.experimental_output instanceof ZodSchema
67
- ? zodToJsonSchema(params.experimental_output)
68
- : params.experimental_output,
61
+ output: zodToJsonSchema(params.output),
62
+ experimental_output: zodToJsonSchema(params.experimental_output),
69
63
  };
70
64
 
71
65
  const response: Response & {
@@ -1,6 +1,8 @@
1
+ import type { RuntimeContext } from '@mastra/core/runtime-context';
1
2
  import type { GetToolResponse, ClientOptions } from '../types';
2
3
 
3
4
  import { BaseResource } from './base';
5
+ import { parseClientRuntimeContext } from '../utils';
4
6
 
5
7
  export class Tool extends BaseResource {
6
8
  constructor(
@@ -23,16 +25,21 @@ export class Tool extends BaseResource {
23
25
  * @param params - Parameters required for tool execution
24
26
  * @returns Promise containing the tool execution results
25
27
  */
26
- execute(params: { data: any; runId?: string }): Promise<any> {
28
+ execute(params: { data: any; runId?: string; runtimeContext?: RuntimeContext | Record<string, any> }): Promise<any> {
27
29
  const url = new URLSearchParams();
28
30
 
29
31
  if (params.runId) {
30
32
  url.set('runId', params.runId);
31
33
  }
32
34
 
35
+ const body = {
36
+ data: params.data,
37
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
38
+ };
39
+
33
40
  return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
34
41
  method: 'POST',
35
- body: params.data,
42
+ body,
36
43
  });
37
44
  }
38
45
  }
@@ -0,0 +1,194 @@
1
+ import type { WatchEvent } from '@mastra/core/workflows';
2
+
3
+ import type {
4
+ ClientOptions,
5
+ GetVNextNetworkResponse,
6
+ GenerateVNextNetworkResponse,
7
+ LoopVNextNetworkResponse,
8
+ GenerateOrStreamVNextNetworkParams,
9
+ LoopStreamVNextNetworkParams,
10
+ } from '../types';
11
+
12
+ import { BaseResource } from './base';
13
+ import { parseClientRuntimeContext } from '../utils';
14
+ import type { RuntimeContext } from '@mastra/core/runtime-context';
15
+
16
+ const RECORD_SEPARATOR = '\x1E';
17
+
18
+ export class VNextNetwork extends BaseResource {
19
+ constructor(
20
+ options: ClientOptions,
21
+ private networkId: string,
22
+ ) {
23
+ super(options);
24
+ }
25
+
26
+ /**
27
+ * Retrieves details about the network
28
+ * @returns Promise containing vNext network details
29
+ */
30
+ details(): Promise<GetVNextNetworkResponse> {
31
+ return this.request(`/api/networks/v-next/${this.networkId}`);
32
+ }
33
+
34
+ /**
35
+ * Generates a response from the v-next network
36
+ * @param params - Generation parameters including message
37
+ * @returns Promise containing the generated response
38
+ */
39
+ generate(params: GenerateOrStreamVNextNetworkParams): Promise<GenerateVNextNetworkResponse> {
40
+ return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
41
+ method: 'POST',
42
+ body: {
43
+ ...params,
44
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
45
+ },
46
+ });
47
+ }
48
+
49
+ /**
50
+ * Generates a response from the v-next network using multiple primitives
51
+ * @param params - Generation parameters including message
52
+ * @returns Promise containing the generated response
53
+ */
54
+ loop(params: {
55
+ message: string;
56
+ runtimeContext?: RuntimeContext | Record<string, any>;
57
+ }): Promise<LoopVNextNetworkResponse> {
58
+ return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
59
+ method: 'POST',
60
+ body: {
61
+ ...params,
62
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
63
+ },
64
+ });
65
+ }
66
+
67
+ private async *streamProcessor(stream: ReadableStream): AsyncGenerator<WatchEvent, void, unknown> {
68
+ const reader = stream.getReader();
69
+
70
+ // Track if we've finished reading from the stream
71
+ let doneReading = false;
72
+ // Buffer to accumulate partial chunks
73
+ let buffer = '';
74
+
75
+ try {
76
+ while (!doneReading) {
77
+ // Read the next chunk from the stream
78
+ const { done, value } = await reader.read();
79
+ doneReading = done;
80
+
81
+ // Skip processing if we're done and there's no value
82
+ if (done && !value) continue;
83
+
84
+ try {
85
+ // Decode binary data to text
86
+ const decoded = value ? new TextDecoder().decode(value) : '';
87
+
88
+ // Split the combined buffer and new data by record separator
89
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
90
+
91
+ // The last chunk might be incomplete, so save it for the next iteration
92
+ buffer = chunks.pop() || '';
93
+
94
+ // Process complete chunks
95
+ for (const chunk of chunks) {
96
+ if (chunk) {
97
+ // Only process non-empty chunks
98
+ if (typeof chunk === 'string') {
99
+ try {
100
+ const parsedChunk = JSON.parse(chunk);
101
+ yield parsedChunk;
102
+ } catch {
103
+ // Silently ignore parsing errors to maintain stream processing
104
+ // This allows the stream to continue even if one record is malformed
105
+ }
106
+ }
107
+ }
108
+ }
109
+ } catch {
110
+ // Silently ignore parsing errors to maintain stream processing
111
+ // This allows the stream to continue even if one record is malformed
112
+ }
113
+ }
114
+
115
+ // Process any remaining data in the buffer after stream is done
116
+ if (buffer) {
117
+ try {
118
+ yield JSON.parse(buffer);
119
+ } catch {
120
+ // Ignore parsing error for final chunk
121
+ }
122
+ }
123
+ } finally {
124
+ // Always ensure we clean up the reader
125
+ reader.cancel().catch(() => {
126
+ // Ignore cancel errors
127
+ });
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Streams a response from the v-next network
133
+ * @param params - Stream parameters including message
134
+ * @returns Promise containing the results
135
+ */
136
+ async stream(params: GenerateOrStreamVNextNetworkParams, onRecord: (record: WatchEvent) => void) {
137
+ const response: Response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
138
+ method: 'POST',
139
+ body: {
140
+ ...params,
141
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
142
+ },
143
+ stream: true,
144
+ });
145
+
146
+ if (!response.ok) {
147
+ throw new Error(`Failed to stream vNext network: ${response.statusText}`);
148
+ }
149
+
150
+ if (!response.body) {
151
+ throw new Error('Response body is null');
152
+ }
153
+
154
+ for await (const record of this.streamProcessor(response.body)) {
155
+ if (typeof record === 'string') {
156
+ onRecord(JSON.parse(record));
157
+ } else {
158
+ onRecord(record);
159
+ }
160
+ }
161
+ }
162
+
163
+ /**
164
+ * Streams a response from the v-next network loop
165
+ * @param params - Stream parameters including message
166
+ * @returns Promise containing the results
167
+ */
168
+ async loopStream(params: LoopStreamVNextNetworkParams, onRecord: (record: WatchEvent) => void) {
169
+ const response: Response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
170
+ method: 'POST',
171
+ body: {
172
+ ...params,
173
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
174
+ },
175
+ stream: true,
176
+ });
177
+
178
+ if (!response.ok) {
179
+ throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
180
+ }
181
+
182
+ if (!response.body) {
183
+ throw new Error('Response body is null');
184
+ }
185
+
186
+ for await (const record of this.streamProcessor(response.body)) {
187
+ if (typeof record === 'string') {
188
+ onRecord(JSON.parse(record));
189
+ } else {
190
+ onRecord(record);
191
+ }
192
+ }
193
+ }
194
+ }