@mastra/client-js 0.0.0-custom-instrumentation-20250626084921 → 0.0.0-declaration-maps-20250729202623
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/.turbo/turbo-build.log +8 -10
- package/CHANGELOG.md +452 -2
- package/LICENSE.md +11 -42
- package/README.md +1 -0
- 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 +305 -69
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -1126
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +304 -68
- 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/package.json +8 -7
- package/src/client.ts +145 -2
- package/src/example.ts +45 -17
- package/src/index.test.ts +402 -6
- package/src/index.ts +1 -0
- package/src/resources/agent.ts +64 -24
- package/src/resources/base.ts +6 -1
- package/src/resources/memory-thread.test.ts +285 -0
- package/src/resources/memory-thread.ts +36 -0
- package/src/resources/network-memory-thread.test.ts +269 -0
- package/src/resources/network-memory-thread.ts +18 -0
- package/src/resources/network.ts +4 -3
- package/src/resources/vNextNetwork.ts +22 -5
- package/src/resources/workflow.ts +43 -6
- package/src/types.ts +105 -10
- package/src/utils/process-client-tools.ts +1 -1
- package/src/v2-messages.test.ts +180 -0
- package/tsconfig.build.json +9 -0
- package/dist/index.d.cts +0 -1126
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { describe, expect, beforeEach, it, vi } from 'vitest';
|
|
2
|
+
import { NetworkMemoryThread } from './network-memory-thread';
|
|
3
|
+
import type { ClientOptions } from '../types';
|
|
4
|
+
|
|
5
|
+
// Mock fetch globally
|
|
6
|
+
global.fetch = vi.fn();
|
|
7
|
+
|
|
8
|
+
describe('NetworkMemoryThread', () => {
|
|
9
|
+
let thread: NetworkMemoryThread;
|
|
10
|
+
const clientOptions: ClientOptions = {
|
|
11
|
+
baseUrl: 'http://localhost:4111',
|
|
12
|
+
headers: {
|
|
13
|
+
Authorization: 'Bearer test-key',
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
const threadId = 'test-thread-id';
|
|
17
|
+
const networkId = 'test-network-id';
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
vi.clearAllMocks();
|
|
21
|
+
thread = new NetworkMemoryThread(clientOptions, threadId, networkId);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const mockFetchResponse = (data: any) => {
|
|
25
|
+
(global.fetch as any).mockResolvedValueOnce({
|
|
26
|
+
ok: true,
|
|
27
|
+
status: 200,
|
|
28
|
+
json: async () => data,
|
|
29
|
+
headers: new Headers({
|
|
30
|
+
'content-type': 'application/json',
|
|
31
|
+
}),
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
describe('get', () => {
|
|
36
|
+
it('should retrieve thread details', async () => {
|
|
37
|
+
const mockThread = {
|
|
38
|
+
id: threadId,
|
|
39
|
+
title: 'Test Thread',
|
|
40
|
+
metadata: { test: true },
|
|
41
|
+
createdAt: new Date().toISOString(),
|
|
42
|
+
updatedAt: new Date().toISOString(),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
mockFetchResponse(mockThread);
|
|
46
|
+
|
|
47
|
+
const result = await thread.get();
|
|
48
|
+
|
|
49
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
50
|
+
`http://localhost:4111/api/memory/network/threads/${threadId}?networkId=${networkId}`,
|
|
51
|
+
expect.objectContaining({
|
|
52
|
+
headers: expect.objectContaining({
|
|
53
|
+
Authorization: 'Bearer test-key',
|
|
54
|
+
}),
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
expect(result).toEqual(mockThread);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('update', () => {
|
|
62
|
+
it('should update thread properties', async () => {
|
|
63
|
+
const updateParams = {
|
|
64
|
+
title: 'Updated Title',
|
|
65
|
+
metadata: { updated: true },
|
|
66
|
+
resourceid: 'resource-1',
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const mockUpdatedThread = {
|
|
70
|
+
id: threadId,
|
|
71
|
+
...updateParams,
|
|
72
|
+
createdAt: new Date().toISOString(),
|
|
73
|
+
updatedAt: new Date().toISOString(),
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
mockFetchResponse(mockUpdatedThread);
|
|
77
|
+
|
|
78
|
+
const result = await thread.update(updateParams);
|
|
79
|
+
|
|
80
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
81
|
+
`http://localhost:4111/api/memory/network/threads/${threadId}?networkId=${networkId}`,
|
|
82
|
+
expect.objectContaining({
|
|
83
|
+
method: 'PATCH',
|
|
84
|
+
headers: expect.objectContaining({
|
|
85
|
+
Authorization: 'Bearer test-key',
|
|
86
|
+
}),
|
|
87
|
+
body: JSON.stringify(updateParams),
|
|
88
|
+
}),
|
|
89
|
+
);
|
|
90
|
+
expect(result).toEqual(mockUpdatedThread);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('delete', () => {
|
|
95
|
+
it('should delete the thread', async () => {
|
|
96
|
+
const mockResponse = { result: 'Thread deleted' };
|
|
97
|
+
mockFetchResponse(mockResponse);
|
|
98
|
+
|
|
99
|
+
const result = await thread.delete();
|
|
100
|
+
|
|
101
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
102
|
+
`http://localhost:4111/api/memory/network/threads/${threadId}?networkId=${networkId}`,
|
|
103
|
+
expect.objectContaining({
|
|
104
|
+
method: 'DELETE',
|
|
105
|
+
headers: expect.objectContaining({
|
|
106
|
+
Authorization: 'Bearer test-key',
|
|
107
|
+
}),
|
|
108
|
+
}),
|
|
109
|
+
);
|
|
110
|
+
expect(result).toEqual(mockResponse);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe('getMessages', () => {
|
|
115
|
+
it('should retrieve thread messages', async () => {
|
|
116
|
+
const mockMessages = {
|
|
117
|
+
messages: [
|
|
118
|
+
{ id: 'msg-1', content: 'Hello', role: 'user' },
|
|
119
|
+
{ id: 'msg-2', content: 'Hi there', role: 'assistant' },
|
|
120
|
+
],
|
|
121
|
+
uiMessages: [
|
|
122
|
+
{ id: 'msg-1', content: 'Hello', role: 'user' },
|
|
123
|
+
{ id: 'msg-2', content: 'Hi there', role: 'assistant' },
|
|
124
|
+
],
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
mockFetchResponse(mockMessages);
|
|
128
|
+
|
|
129
|
+
const result = await thread.getMessages();
|
|
130
|
+
|
|
131
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
132
|
+
`http://localhost:4111/api/memory/network/threads/${threadId}/messages?networkId=${networkId}`,
|
|
133
|
+
expect.objectContaining({
|
|
134
|
+
headers: expect.objectContaining({
|
|
135
|
+
Authorization: 'Bearer test-key',
|
|
136
|
+
}),
|
|
137
|
+
}),
|
|
138
|
+
);
|
|
139
|
+
expect(result).toEqual(mockMessages);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('should retrieve thread messages with limit', async () => {
|
|
143
|
+
const mockMessages = {
|
|
144
|
+
messages: [{ id: 'msg-1', content: 'Hello', role: 'user' }],
|
|
145
|
+
uiMessages: [{ id: 'msg-1', content: 'Hello', role: 'user' }],
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
mockFetchResponse(mockMessages);
|
|
149
|
+
|
|
150
|
+
const result = await thread.getMessages({ limit: 5 });
|
|
151
|
+
|
|
152
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
153
|
+
`http://localhost:4111/api/memory/network/threads/${threadId}/messages?networkId=${networkId}&limit=5`,
|
|
154
|
+
expect.objectContaining({
|
|
155
|
+
headers: expect.objectContaining({
|
|
156
|
+
Authorization: 'Bearer test-key',
|
|
157
|
+
}),
|
|
158
|
+
}),
|
|
159
|
+
);
|
|
160
|
+
expect(result).toEqual(mockMessages);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe('deleteMessages', () => {
|
|
165
|
+
it('should delete a single message by string ID', async () => {
|
|
166
|
+
const messageId = 'test-message-id';
|
|
167
|
+
const mockResponse = { success: true, message: '1 message deleted successfully' };
|
|
168
|
+
|
|
169
|
+
mockFetchResponse(mockResponse);
|
|
170
|
+
|
|
171
|
+
const result = await thread.deleteMessages(messageId);
|
|
172
|
+
|
|
173
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
174
|
+
`http://localhost:4111/api/memory/network/messages/delete?networkId=${networkId}`,
|
|
175
|
+
expect.objectContaining({
|
|
176
|
+
method: 'POST',
|
|
177
|
+
headers: expect.objectContaining({
|
|
178
|
+
'content-type': 'application/json',
|
|
179
|
+
Authorization: 'Bearer test-key',
|
|
180
|
+
}),
|
|
181
|
+
body: JSON.stringify({ messageIds: messageId }),
|
|
182
|
+
}),
|
|
183
|
+
);
|
|
184
|
+
expect(result).toEqual(mockResponse);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('should delete multiple messages by array of string IDs', async () => {
|
|
188
|
+
const messageIds = ['msg-1', 'msg-2', 'msg-3'];
|
|
189
|
+
const mockResponse = { success: true, message: '3 messages deleted successfully' };
|
|
190
|
+
|
|
191
|
+
mockFetchResponse(mockResponse);
|
|
192
|
+
|
|
193
|
+
const result = await thread.deleteMessages(messageIds);
|
|
194
|
+
|
|
195
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
196
|
+
`http://localhost:4111/api/memory/network/messages/delete?networkId=${networkId}`,
|
|
197
|
+
expect.objectContaining({
|
|
198
|
+
method: 'POST',
|
|
199
|
+
headers: expect.objectContaining({
|
|
200
|
+
'content-type': 'application/json',
|
|
201
|
+
Authorization: 'Bearer test-key',
|
|
202
|
+
}),
|
|
203
|
+
body: JSON.stringify({ messageIds }),
|
|
204
|
+
}),
|
|
205
|
+
);
|
|
206
|
+
expect(result).toEqual(mockResponse);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('should delete a message by object with id property', async () => {
|
|
210
|
+
const messageObj = { id: 'test-message-id' };
|
|
211
|
+
const mockResponse = { success: true, message: '1 message deleted successfully' };
|
|
212
|
+
|
|
213
|
+
mockFetchResponse(mockResponse);
|
|
214
|
+
|
|
215
|
+
const result = await thread.deleteMessages(messageObj);
|
|
216
|
+
|
|
217
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
218
|
+
`http://localhost:4111/api/memory/network/messages/delete?networkId=${networkId}`,
|
|
219
|
+
expect.objectContaining({
|
|
220
|
+
method: 'POST',
|
|
221
|
+
headers: expect.objectContaining({
|
|
222
|
+
'content-type': 'application/json',
|
|
223
|
+
Authorization: 'Bearer test-key',
|
|
224
|
+
}),
|
|
225
|
+
body: JSON.stringify({ messageIds: messageObj }),
|
|
226
|
+
}),
|
|
227
|
+
);
|
|
228
|
+
expect(result).toEqual(mockResponse);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('should delete messages by array of objects', async () => {
|
|
232
|
+
const messageObjs = [{ id: 'msg-1' }, { id: 'msg-2' }];
|
|
233
|
+
const mockResponse = { success: true, message: '2 messages deleted successfully' };
|
|
234
|
+
|
|
235
|
+
mockFetchResponse(mockResponse);
|
|
236
|
+
|
|
237
|
+
const result = await thread.deleteMessages(messageObjs);
|
|
238
|
+
|
|
239
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
240
|
+
`http://localhost:4111/api/memory/network/messages/delete?networkId=${networkId}`,
|
|
241
|
+
expect.objectContaining({
|
|
242
|
+
method: 'POST',
|
|
243
|
+
headers: expect.objectContaining({
|
|
244
|
+
'content-type': 'application/json',
|
|
245
|
+
Authorization: 'Bearer test-key',
|
|
246
|
+
}),
|
|
247
|
+
body: JSON.stringify({ messageIds: messageObjs }),
|
|
248
|
+
}),
|
|
249
|
+
);
|
|
250
|
+
expect(result).toEqual(mockResponse);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it('should handle delete messages errors', async () => {
|
|
254
|
+
const messageId = 'non-existent-id';
|
|
255
|
+
|
|
256
|
+
(global.fetch as any).mockResolvedValueOnce({
|
|
257
|
+
ok: false,
|
|
258
|
+
status: 404,
|
|
259
|
+
statusText: 'Not Found',
|
|
260
|
+
json: async () => ({ error: 'Message not found' }),
|
|
261
|
+
headers: new Headers({
|
|
262
|
+
'content-type': 'application/json',
|
|
263
|
+
}),
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
await expect(thread.deleteMessages(messageId)).rejects.toThrow();
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
});
|
|
@@ -60,4 +60,22 @@ export class NetworkMemoryThread extends BaseResource {
|
|
|
60
60
|
});
|
|
61
61
|
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
62
62
|
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Deletes one or more messages from the thread
|
|
66
|
+
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
67
|
+
* message object with id property, or array of message objects
|
|
68
|
+
* @returns Promise containing deletion result
|
|
69
|
+
*/
|
|
70
|
+
deleteMessages(
|
|
71
|
+
messageIds: string | string[] | { id: string } | { id: string }[],
|
|
72
|
+
): Promise<{ success: boolean; message: string }> {
|
|
73
|
+
const query = new URLSearchParams({
|
|
74
|
+
networkId: this.networkId,
|
|
75
|
+
});
|
|
76
|
+
return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
|
|
77
|
+
method: 'POST',
|
|
78
|
+
body: { messageIds },
|
|
79
|
+
});
|
|
80
|
+
}
|
|
63
81
|
}
|
package/src/resources/network.ts
CHANGED
|
@@ -28,9 +28,10 @@ export class Network extends BaseResource {
|
|
|
28
28
|
* @param params - Generation parameters including prompt
|
|
29
29
|
* @returns Promise containing the generated response
|
|
30
30
|
*/
|
|
31
|
-
generate<
|
|
32
|
-
|
|
33
|
-
|
|
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>> {
|
|
34
35
|
const processedParams = {
|
|
35
36
|
...params,
|
|
36
37
|
output: zodToJsonSchema(params.output),
|
|
@@ -10,6 +10,8 @@ import type {
|
|
|
10
10
|
} from '../types';
|
|
11
11
|
|
|
12
12
|
import { BaseResource } from './base';
|
|
13
|
+
import { parseClientRuntimeContext } from '../utils';
|
|
14
|
+
import type { RuntimeContext } from '@mastra/core/runtime-context';
|
|
13
15
|
|
|
14
16
|
const RECORD_SEPARATOR = '\x1E';
|
|
15
17
|
|
|
@@ -37,7 +39,10 @@ export class VNextNetwork extends BaseResource {
|
|
|
37
39
|
generate(params: GenerateOrStreamVNextNetworkParams): Promise<GenerateVNextNetworkResponse> {
|
|
38
40
|
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
39
41
|
method: 'POST',
|
|
40
|
-
body:
|
|
42
|
+
body: {
|
|
43
|
+
...params,
|
|
44
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
45
|
+
},
|
|
41
46
|
});
|
|
42
47
|
}
|
|
43
48
|
|
|
@@ -46,10 +51,16 @@ export class VNextNetwork extends BaseResource {
|
|
|
46
51
|
* @param params - Generation parameters including message
|
|
47
52
|
* @returns Promise containing the generated response
|
|
48
53
|
*/
|
|
49
|
-
loop(params: {
|
|
54
|
+
loop(params: {
|
|
55
|
+
message: string;
|
|
56
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
57
|
+
}): Promise<LoopVNextNetworkResponse> {
|
|
50
58
|
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
51
59
|
method: 'POST',
|
|
52
|
-
body:
|
|
60
|
+
body: {
|
|
61
|
+
...params,
|
|
62
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
63
|
+
},
|
|
53
64
|
});
|
|
54
65
|
}
|
|
55
66
|
|
|
@@ -125,7 +136,10 @@ export class VNextNetwork extends BaseResource {
|
|
|
125
136
|
async stream(params: GenerateOrStreamVNextNetworkParams, onRecord: (record: WatchEvent) => void) {
|
|
126
137
|
const response: Response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
127
138
|
method: 'POST',
|
|
128
|
-
body:
|
|
139
|
+
body: {
|
|
140
|
+
...params,
|
|
141
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
142
|
+
},
|
|
129
143
|
stream: true,
|
|
130
144
|
});
|
|
131
145
|
|
|
@@ -154,7 +168,10 @@ export class VNextNetwork extends BaseResource {
|
|
|
154
168
|
async loopStream(params: LoopStreamVNextNetworkParams, onRecord: (record: WatchEvent) => void) {
|
|
155
169
|
const response: Response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
156
170
|
method: 'POST',
|
|
157
|
-
body:
|
|
171
|
+
body: {
|
|
172
|
+
...params,
|
|
173
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
174
|
+
},
|
|
158
175
|
stream: true,
|
|
159
176
|
});
|
|
160
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) {
|
|
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) {
|
|
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
|
|
@@ -167,6 +190,15 @@ export class Workflow extends BaseResource {
|
|
|
167
190
|
});
|
|
168
191
|
}
|
|
169
192
|
|
|
193
|
+
/**
|
|
194
|
+
* Creates a new workflow run (alias for createRun)
|
|
195
|
+
* @param params - Optional object containing the optional runId
|
|
196
|
+
* @returns Promise containing the runId of the created run
|
|
197
|
+
*/
|
|
198
|
+
createRunAsync(params?: { runId?: string }): Promise<{ runId: string }> {
|
|
199
|
+
return this.createRun(params);
|
|
200
|
+
}
|
|
201
|
+
|
|
170
202
|
/**
|
|
171
203
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
172
204
|
* @param params - Object containing the runId, inputData and runtimeContext
|
|
@@ -266,8 +298,11 @@ export class Workflow extends BaseResource {
|
|
|
266
298
|
throw new Error('Response body is null');
|
|
267
299
|
}
|
|
268
300
|
|
|
301
|
+
//using undefined instead of empty string to avoid parsing errors
|
|
302
|
+
let failedChunk: string | undefined = undefined;
|
|
303
|
+
|
|
269
304
|
// Create a transform stream that processes the response body
|
|
270
|
-
const transformStream = new TransformStream<ArrayBuffer,
|
|
305
|
+
const transformStream = new TransformStream<ArrayBuffer, { type: string; payload: any }>({
|
|
271
306
|
start() {},
|
|
272
307
|
async transform(chunk, controller) {
|
|
273
308
|
try {
|
|
@@ -280,11 +315,13 @@ export class Workflow extends BaseResource {
|
|
|
280
315
|
// Process each chunk
|
|
281
316
|
for (const chunk of chunks) {
|
|
282
317
|
if (chunk) {
|
|
318
|
+
const newChunk: string = failedChunk ? failedChunk + chunk : chunk;
|
|
283
319
|
try {
|
|
284
|
-
const parsedChunk = JSON.parse(
|
|
320
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
285
321
|
controller.enqueue(parsedChunk);
|
|
286
|
-
|
|
287
|
-
|
|
322
|
+
failedChunk = undefined;
|
|
323
|
+
} catch (error) {
|
|
324
|
+
failedChunk = newChunk;
|
|
288
325
|
}
|
|
289
326
|
}
|
|
290
327
|
}
|
package/src/types.ts
CHANGED
|
@@ -7,12 +7,16 @@ import type {
|
|
|
7
7
|
WorkflowRuns,
|
|
8
8
|
WorkflowRun,
|
|
9
9
|
LegacyWorkflowRuns,
|
|
10
|
+
StorageGetMessagesArg,
|
|
11
|
+
PaginationInfo,
|
|
12
|
+
MastraMessageV2,
|
|
10
13
|
} from '@mastra/core';
|
|
11
|
-
import type { AgentGenerateOptions, AgentStreamOptions, ToolsInput } from '@mastra/core/agent';
|
|
14
|
+
import type { AgentGenerateOptions, AgentStreamOptions, ToolsInput, UIMessageWithMetadata } from '@mastra/core/agent';
|
|
12
15
|
import type { BaseLogMessage, LogLevel } from '@mastra/core/logger';
|
|
13
16
|
|
|
14
17
|
import type { MCPToolType, ServerInfo } from '@mastra/core/mcp';
|
|
15
18
|
import type { RuntimeContext } from '@mastra/core/runtime-context';
|
|
19
|
+
import type { MastraScorer, MastraScorerEntry, ScoreRowData } from '@mastra/core/scores';
|
|
16
20
|
import type { Workflow, WatchEvent, WorkflowResult } from '@mastra/core/workflows';
|
|
17
21
|
import type {
|
|
18
22
|
StepAction,
|
|
@@ -34,6 +38,7 @@ export interface ClientOptions {
|
|
|
34
38
|
/** Custom headers to include with requests */
|
|
35
39
|
headers?: Record<string, string>;
|
|
36
40
|
/** Abort signal for request */
|
|
41
|
+
abortSignal?: AbortSignal;
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
export interface RequestOptions {
|
|
@@ -41,7 +46,6 @@ export interface RequestOptions {
|
|
|
41
46
|
headers?: Record<string, string>;
|
|
42
47
|
body?: any;
|
|
43
48
|
stream?: boolean;
|
|
44
|
-
signal?: AbortSignal;
|
|
45
49
|
}
|
|
46
50
|
|
|
47
51
|
type WithoutMethods<T> = {
|
|
@@ -66,20 +70,24 @@ export interface GetAgentResponse {
|
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
export type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
69
|
-
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
73
|
+
messages: string | string[] | CoreMessage[] | AiMessageType[] | UIMessageWithMetadata[];
|
|
70
74
|
output?: T;
|
|
71
75
|
experimental_output?: T;
|
|
72
76
|
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
73
77
|
clientTools?: ToolsInput;
|
|
74
|
-
} & WithoutMethods<
|
|
78
|
+
} & WithoutMethods<
|
|
79
|
+
Omit<AgentGenerateOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools' | 'abortSignal'>
|
|
80
|
+
>;
|
|
75
81
|
|
|
76
82
|
export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
77
|
-
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
83
|
+
messages: string | string[] | CoreMessage[] | AiMessageType[] | UIMessageWithMetadata[];
|
|
78
84
|
output?: T;
|
|
79
85
|
experimental_output?: T;
|
|
80
86
|
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
81
87
|
clientTools?: ToolsInput;
|
|
82
|
-
} & WithoutMethods<
|
|
88
|
+
} & WithoutMethods<
|
|
89
|
+
Omit<AgentStreamOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools' | 'abortSignal'>
|
|
90
|
+
>;
|
|
83
91
|
|
|
84
92
|
export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
85
93
|
evals: any[];
|
|
@@ -140,6 +148,17 @@ export interface GetWorkflowResponse {
|
|
|
140
148
|
suspendSchema: string;
|
|
141
149
|
};
|
|
142
150
|
};
|
|
151
|
+
allSteps: {
|
|
152
|
+
[key: string]: {
|
|
153
|
+
id: string;
|
|
154
|
+
description: string;
|
|
155
|
+
inputSchema: string;
|
|
156
|
+
outputSchema: string;
|
|
157
|
+
resumeSchema: string;
|
|
158
|
+
suspendSchema: string;
|
|
159
|
+
isWorkflow: boolean;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
143
162
|
stepGraph: Workflow['serializedStepGraph'];
|
|
144
163
|
inputSchema: string;
|
|
145
164
|
outputSchema: string;
|
|
@@ -179,16 +198,16 @@ export interface GetVectorIndexResponse {
|
|
|
179
198
|
}
|
|
180
199
|
|
|
181
200
|
export interface SaveMessageToMemoryParams {
|
|
182
|
-
messages: MastraMessageV1[];
|
|
201
|
+
messages: (MastraMessageV1 | MastraMessageV2)[];
|
|
183
202
|
agentId: string;
|
|
184
203
|
}
|
|
185
204
|
|
|
186
205
|
export interface SaveNetworkMessageToMemoryParams {
|
|
187
|
-
messages: MastraMessageV1[];
|
|
206
|
+
messages: (MastraMessageV1 | MastraMessageV2)[];
|
|
188
207
|
networkId: string;
|
|
189
208
|
}
|
|
190
209
|
|
|
191
|
-
export type SaveMessageToMemoryResponse = MastraMessageV1[];
|
|
210
|
+
export type SaveMessageToMemoryResponse = (MastraMessageV1 | MastraMessageV2)[];
|
|
192
211
|
|
|
193
212
|
export interface CreateMemoryThreadParams {
|
|
194
213
|
title?: string;
|
|
@@ -233,11 +252,17 @@ export interface GetMemoryThreadMessagesParams {
|
|
|
233
252
|
limit?: number;
|
|
234
253
|
}
|
|
235
254
|
|
|
255
|
+
export type GetMemoryThreadMessagesPaginatedParams = Omit<StorageGetMessagesArg, 'threadConfig' | 'threadId'>;
|
|
256
|
+
|
|
236
257
|
export interface GetMemoryThreadMessagesResponse {
|
|
237
258
|
messages: CoreMessage[];
|
|
238
259
|
uiMessages: AiMessageType[];
|
|
239
260
|
}
|
|
240
261
|
|
|
262
|
+
export type GetMemoryThreadMessagesPaginatedResponse = PaginationInfo & {
|
|
263
|
+
messages: MastraMessageV1[] | MastraMessageV2[];
|
|
264
|
+
};
|
|
265
|
+
|
|
241
266
|
export interface GetLogsParams {
|
|
242
267
|
transportId: string;
|
|
243
268
|
fromDate?: Date;
|
|
@@ -358,6 +383,10 @@ export interface GetVNextNetworkResponse {
|
|
|
358
383
|
inputSchema: string | undefined;
|
|
359
384
|
outputSchema: string | undefined;
|
|
360
385
|
}>;
|
|
386
|
+
tools: Array<{
|
|
387
|
+
id: string;
|
|
388
|
+
description: string;
|
|
389
|
+
}>;
|
|
361
390
|
}
|
|
362
391
|
|
|
363
392
|
export interface GenerateVNextNetworkResponse {
|
|
@@ -371,6 +400,7 @@ export interface GenerateOrStreamVNextNetworkParams {
|
|
|
371
400
|
message: string;
|
|
372
401
|
threadId?: string;
|
|
373
402
|
resourceId?: string;
|
|
403
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
374
404
|
}
|
|
375
405
|
|
|
376
406
|
export interface LoopStreamVNextNetworkParams {
|
|
@@ -378,12 +408,23 @@ export interface LoopStreamVNextNetworkParams {
|
|
|
378
408
|
threadId?: string;
|
|
379
409
|
resourceId?: string;
|
|
380
410
|
maxIterations?: number;
|
|
411
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
381
412
|
}
|
|
382
413
|
|
|
383
414
|
export interface LoopVNextNetworkResponse {
|
|
384
415
|
status: 'success';
|
|
385
416
|
result: {
|
|
386
|
-
|
|
417
|
+
task: string;
|
|
418
|
+
resourceId: string;
|
|
419
|
+
resourceType: 'agent' | 'workflow' | 'none' | 'tool';
|
|
420
|
+
result: string;
|
|
421
|
+
iteration: number;
|
|
422
|
+
isOneOff: boolean;
|
|
423
|
+
prompt: string;
|
|
424
|
+
threadId?: string | undefined;
|
|
425
|
+
threadResourceId?: string | undefined;
|
|
426
|
+
isComplete?: boolean | undefined;
|
|
427
|
+
completionReason?: string | undefined;
|
|
387
428
|
};
|
|
388
429
|
steps: WorkflowResult<any, any>['steps'];
|
|
389
430
|
}
|
|
@@ -405,3 +446,57 @@ export interface McpToolInfo {
|
|
|
405
446
|
export interface McpServerToolListResponse {
|
|
406
447
|
tools: McpToolInfo[];
|
|
407
448
|
}
|
|
449
|
+
|
|
450
|
+
export type ClientScoreRowData = Omit<ScoreRowData, 'createdAt' | 'updatedAt'> & {
|
|
451
|
+
createdAt: string;
|
|
452
|
+
updatedAt: string;
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
// Scores-related types
|
|
456
|
+
export interface GetScoresByRunIdParams {
|
|
457
|
+
runId: string;
|
|
458
|
+
page?: number;
|
|
459
|
+
perPage?: number;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export interface GetScoresByScorerIdParams {
|
|
463
|
+
scorerId: string;
|
|
464
|
+
entityId?: string;
|
|
465
|
+
entityType?: string;
|
|
466
|
+
page?: number;
|
|
467
|
+
perPage?: number;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
export interface GetScoresByEntityIdParams {
|
|
471
|
+
entityId: string;
|
|
472
|
+
entityType: string;
|
|
473
|
+
page?: number;
|
|
474
|
+
perPage?: number;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
export interface SaveScoreParams {
|
|
478
|
+
score: Omit<ScoreRowData, 'id' | 'createdAt' | 'updatedAt'>;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export interface GetScoresResponse {
|
|
482
|
+
pagination: {
|
|
483
|
+
total: number;
|
|
484
|
+
page: number;
|
|
485
|
+
perPage: number;
|
|
486
|
+
hasMore: boolean;
|
|
487
|
+
};
|
|
488
|
+
scores: ClientScoreRowData[];
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
export interface SaveScoreResponse {
|
|
492
|
+
score: ClientScoreRowData;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
export type GetScorerResponse = MastraScorerEntry & {
|
|
496
|
+
agentIds: string[];
|
|
497
|
+
workflowIds: string[];
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
export interface GetScorersResponse {
|
|
501
|
+
scorers: Array<GetScorerResponse>;
|
|
502
|
+
}
|