@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.
- package/CHANGELOG.md +1110 -2
- package/LICENSE.md +11 -42
- package/README.md +2 -1
- package/dist/adapters/agui.d.ts +23 -0
- package/dist/adapters/agui.d.ts.map +1 -0
- package/dist/client.d.ts +265 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/example.d.ts +2 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/index.cjs +1403 -131
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -730
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1401 -133
- package/dist/index.js.map +1 -0
- package/dist/resources/a2a.d.ts +44 -0
- package/dist/resources/a2a.d.ts.map +1 -0
- package/dist/resources/agent.d.ts +112 -0
- package/dist/resources/agent.d.ts.map +1 -0
- package/dist/resources/base.d.ts +13 -0
- package/dist/resources/base.d.ts.map +1 -0
- package/dist/resources/index.d.ts +11 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/legacy-workflow.d.ts +87 -0
- package/dist/resources/legacy-workflow.d.ts.map +1 -0
- package/dist/resources/mcp-tool.d.ts +27 -0
- package/dist/resources/mcp-tool.d.ts.map +1 -0
- package/dist/resources/memory-thread.d.ts +53 -0
- package/dist/resources/memory-thread.d.ts.map +1 -0
- package/dist/resources/network-memory-thread.d.ts +47 -0
- package/dist/resources/network-memory-thread.d.ts.map +1 -0
- package/dist/resources/network.d.ts +30 -0
- package/dist/resources/network.d.ts.map +1 -0
- package/dist/resources/tool.d.ts +23 -0
- package/dist/resources/tool.d.ts.map +1 -0
- package/dist/resources/vNextNetwork.d.ts +42 -0
- package/dist/resources/vNextNetwork.d.ts.map +1 -0
- package/dist/resources/vector.d.ts +48 -0
- package/dist/resources/vector.d.ts.map +1 -0
- package/dist/resources/workflow.d.ts +154 -0
- package/dist/resources/workflow.d.ts.map +1 -0
- package/dist/types.d.ts +422 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/process-client-tools.d.ts +3 -0
- package/dist/utils/process-client-tools.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema.d.ts +105 -0
- package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
- package/integration-tests/agui-adapter.test.ts +122 -0
- package/integration-tests/package.json +18 -0
- package/integration-tests/src/mastra/index.ts +35 -0
- package/integration-tests/vitest.config.ts +9 -0
- package/package.json +28 -19
- package/src/adapters/agui.test.ts +164 -9
- package/src/adapters/agui.ts +31 -11
- package/src/client.ts +386 -22
- package/src/example.ts +59 -29
- package/src/index.test.ts +522 -6
- package/src/index.ts +1 -0
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +629 -48
- package/src/resources/base.ts +7 -1
- package/src/resources/index.ts +4 -2
- package/src/resources/{vnext-workflow.ts → legacy-workflow.ts} +124 -139
- package/src/resources/mcp-tool.ts +48 -0
- package/src/resources/memory-thread.test.ts +285 -0
- package/src/resources/memory-thread.ts +49 -3
- package/src/resources/network-memory-thread.test.ts +269 -0
- package/src/resources/network-memory-thread.ts +81 -0
- package/src/resources/network.ts +10 -16
- package/src/resources/tool.ts +9 -2
- package/src/resources/vNextNetwork.ts +194 -0
- package/src/resources/workflow.ts +255 -96
- package/src/types.ts +265 -25
- package/src/utils/index.ts +11 -0
- package/src/utils/process-client-tools.ts +32 -0
- package/src/utils/zod-to-json-schema.ts +10 -0
- package/src/v2-messages.test.ts +180 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +1 -1
- package/tsup.config.ts +22 -0
- package/dist/index.d.cts +0 -730
package/src/resources/network.ts
CHANGED
|
@@ -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<
|
|
33
|
-
|
|
34
|
-
|
|
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:
|
|
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:
|
|
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 & {
|
package/src/resources/tool.ts
CHANGED
|
@@ -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
|
|
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
|
+
}
|