@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
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mastra/client-js-integration-tests",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "vitest run",
|
|
7
|
+
"test:watch": "vitest"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@ag-ui/client": "^0.0.27",
|
|
11
|
+
"@mastra/client-js": "workspace:*",
|
|
12
|
+
"@mastra/core": "workspace:*",
|
|
13
|
+
"ai": "^4.3.19"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"vitest": "^3.2.4"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Mastra } from '@mastra/core';
|
|
2
|
+
import { Agent } from '@mastra/core/agent';
|
|
3
|
+
import { MockLanguageModelV1 } from 'ai/test';
|
|
4
|
+
import { simulateReadableStream } from 'ai';
|
|
5
|
+
|
|
6
|
+
const mockModel = new MockLanguageModelV1({
|
|
7
|
+
doStream: async () => ({
|
|
8
|
+
stream: simulateReadableStream({
|
|
9
|
+
chunks: [
|
|
10
|
+
{ type: 'text-delta', textDelta: 'Hello' },
|
|
11
|
+
{ type: 'text-delta', textDelta: ' from' },
|
|
12
|
+
{ type: 'text-delta', textDelta: ' agent' },
|
|
13
|
+
{
|
|
14
|
+
type: 'finish',
|
|
15
|
+
finishReason: 'stop',
|
|
16
|
+
logprobs: undefined,
|
|
17
|
+
usage: { completionTokens: 3, promptTokens: 10 },
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
}),
|
|
21
|
+
rawCall: { rawPrompt: null, rawSettings: {} },
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const testAgent = new Agent({
|
|
26
|
+
name: 'test',
|
|
27
|
+
instructions: 'You are a test agent',
|
|
28
|
+
model: mockModel,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const mastra = new Mastra({
|
|
32
|
+
agents: {
|
|
33
|
+
test: testAgent,
|
|
34
|
+
},
|
|
35
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/client-js",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-update-scorers-api-20250801170445",
|
|
4
4
|
"description": "The official TypeScript library for the Mastra Client API",
|
|
5
5
|
"author": "",
|
|
6
6
|
"type": "module",
|
|
@@ -19,34 +19,43 @@
|
|
|
19
19
|
},
|
|
20
20
|
"./package.json": "./package.json"
|
|
21
21
|
},
|
|
22
|
-
"repository":
|
|
23
|
-
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/mastra-ai/mastra.git",
|
|
25
|
+
"directory": "client-sdks/client-js"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/mastra-ai/mastra/tree/main/client-sdks/client-js#readme",
|
|
28
|
+
"license": "Apache-2.0",
|
|
24
29
|
"dependencies": {
|
|
25
|
-
"@ag-ui/client": "^0.0.
|
|
26
|
-
"@ai-sdk/ui-utils": "^1.
|
|
30
|
+
"@ag-ui/client": "^0.0.35",
|
|
31
|
+
"@ai-sdk/ui-utils": "^1.2.11",
|
|
32
|
+
"@lukeed/uuid": "^2.0.1",
|
|
27
33
|
"json-schema": "^0.4.0",
|
|
28
34
|
"rxjs": "7.8.1",
|
|
29
|
-
"zod": "^3.
|
|
30
|
-
"zod-to-json-schema": "^3.24.
|
|
31
|
-
"@mastra/core": "0.0.0-
|
|
35
|
+
"zod": "^3.25.67",
|
|
36
|
+
"zod-to-json-schema": "^3.24.5",
|
|
37
|
+
"@mastra/core": "0.0.0-update-scorers-api-20250801170445"
|
|
32
38
|
},
|
|
33
39
|
"peerDependencies": {
|
|
34
|
-
"zod": "^3.
|
|
40
|
+
"zod": "^3.0.0"
|
|
35
41
|
},
|
|
36
42
|
"devDependencies": {
|
|
37
|
-
"@babel/preset-env": "^7.
|
|
38
|
-
"@babel/preset-typescript": "^7.27.
|
|
39
|
-
"@tsconfig/recommended": "^1.0.
|
|
43
|
+
"@babel/preset-env": "^7.28.0",
|
|
44
|
+
"@babel/preset-typescript": "^7.27.1",
|
|
45
|
+
"@tsconfig/recommended": "^1.0.9",
|
|
40
46
|
"@types/json-schema": "^7.0.15",
|
|
41
|
-
"@types/node": "^20.
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
47
|
+
"@types/node": "^20.19.0",
|
|
48
|
+
"ai": "^4.3.19",
|
|
49
|
+
"tsup": "^8.5.0",
|
|
50
|
+
"typescript": "^5.8.3",
|
|
51
|
+
"vitest": "^3.2.4",
|
|
52
|
+
"@internal/lint": "0.0.0-update-scorers-api-20250801170445"
|
|
46
53
|
},
|
|
47
54
|
"scripts": {
|
|
48
|
-
"build": "tsup
|
|
55
|
+
"build": "tsup --silent --config tsup.config.ts",
|
|
49
56
|
"dev": "pnpm build --watch",
|
|
50
|
-
"test": "vitest run"
|
|
57
|
+
"test": "vitest run && pnpm run test:integration",
|
|
58
|
+
"test:unit": "vitest run",
|
|
59
|
+
"test:integration": "cd integration-tests && pnpm test"
|
|
51
60
|
}
|
|
52
61
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type { Message } from '@ag-ui/client';
|
|
2
|
-
import { describe, it, expect } from 'vitest';
|
|
3
|
-
import { generateUUID, convertMessagesToMastraMessages } from './agui';
|
|
1
|
+
import type { Message, BaseEvent } from '@ag-ui/client';
|
|
2
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
3
|
+
import { generateUUID, convertMessagesToMastraMessages, AGUIAdapter } from './agui';
|
|
4
|
+
import { Agent } from '@mastra/core/agent';
|
|
5
|
+
import { MockLanguageModelV1 } from 'ai/test';
|
|
6
|
+
import { simulateReadableStream } from 'ai';
|
|
4
7
|
|
|
5
8
|
describe('generateUUID', () => {
|
|
6
9
|
it('should generate a valid UUID v4 string', () => {
|
|
@@ -91,6 +94,17 @@ describe('convertMessagesToMastraMessages', () => {
|
|
|
91
94
|
},
|
|
92
95
|
],
|
|
93
96
|
},
|
|
97
|
+
{
|
|
98
|
+
role: 'tool',
|
|
99
|
+
content: [
|
|
100
|
+
{
|
|
101
|
+
type: 'tool-result',
|
|
102
|
+
toolCallId: 'tool-call-1',
|
|
103
|
+
toolName: 'getWeather',
|
|
104
|
+
result: { location: 'San Francisco' },
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
},
|
|
94
108
|
]);
|
|
95
109
|
});
|
|
96
110
|
|
|
@@ -143,12 +157,6 @@ describe('convertMessagesToMastraMessages', () => {
|
|
|
143
157
|
},
|
|
144
158
|
],
|
|
145
159
|
},
|
|
146
|
-
{
|
|
147
|
-
id: '3',
|
|
148
|
-
role: 'tool',
|
|
149
|
-
toolCallId: 'tool-call-1',
|
|
150
|
-
content: '{"temperature":72,"unit":"F"}',
|
|
151
|
-
},
|
|
152
160
|
{
|
|
153
161
|
id: '4',
|
|
154
162
|
role: 'assistant',
|
|
@@ -162,6 +170,153 @@ describe('convertMessagesToMastraMessages', () => {
|
|
|
162
170
|
expect(result[0].role).toBe('user');
|
|
163
171
|
expect(result[1].role).toBe('assistant');
|
|
164
172
|
expect(result[2].role).toBe('tool');
|
|
173
|
+
expect(result[2].content).toEqual([
|
|
174
|
+
{
|
|
175
|
+
type: 'tool-result',
|
|
176
|
+
toolCallId: 'tool-call-1',
|
|
177
|
+
toolName: 'getWeather',
|
|
178
|
+
result: { location: 'San Francisco' },
|
|
179
|
+
},
|
|
180
|
+
]);
|
|
165
181
|
expect(result[3].role).toBe('assistant');
|
|
166
182
|
});
|
|
167
183
|
});
|
|
184
|
+
|
|
185
|
+
describe('AGUIAdapter', () => {
|
|
186
|
+
it('should correctly pass parameters to agent stream method', async () => {
|
|
187
|
+
// Create a real agent with MockLanguageModelV1
|
|
188
|
+
const mockModel = new MockLanguageModelV1({
|
|
189
|
+
doStream: async () => ({
|
|
190
|
+
stream: simulateReadableStream({
|
|
191
|
+
chunks: [
|
|
192
|
+
{ type: 'text-delta', textDelta: 'Hello' },
|
|
193
|
+
{ type: 'text-delta', textDelta: ' from' },
|
|
194
|
+
{ type: 'text-delta', textDelta: ' agent' },
|
|
195
|
+
{
|
|
196
|
+
type: 'finish',
|
|
197
|
+
finishReason: 'stop',
|
|
198
|
+
logprobs: undefined,
|
|
199
|
+
usage: { completionTokens: 3, promptTokens: 10 },
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
}),
|
|
203
|
+
rawCall: { rawPrompt: null, rawSettings: {} },
|
|
204
|
+
}),
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const agent = new Agent({
|
|
208
|
+
name: 'Test Agent',
|
|
209
|
+
instructions: 'You are a test agent',
|
|
210
|
+
model: mockModel,
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// Create a mock client agent that simulates the expected behavior
|
|
214
|
+
const clientAgent = {
|
|
215
|
+
stream: vi.fn().mockImplementation(async (params: any) => {
|
|
216
|
+
// Verify the parameters are passed correctly
|
|
217
|
+
expect(params).toHaveProperty('messages');
|
|
218
|
+
expect(params).toHaveProperty('threadId');
|
|
219
|
+
expect(params).toHaveProperty('resourceId');
|
|
220
|
+
expect(params).toHaveProperty('runId');
|
|
221
|
+
expect(params).toHaveProperty('clientTools');
|
|
222
|
+
|
|
223
|
+
// Verify that messages array is passed, not the entire request object
|
|
224
|
+
expect(Array.isArray(params.messages)).toBe(true);
|
|
225
|
+
expect(params.messages[0]).toHaveProperty('role');
|
|
226
|
+
expect(params.messages[0]).toHaveProperty('content');
|
|
227
|
+
|
|
228
|
+
// Return a mock processDataStream that mimics the expected behavior
|
|
229
|
+
return {
|
|
230
|
+
processDataStream: vi.fn().mockImplementation(async ({ onTextPart, onFinishMessagePart }: any) => {
|
|
231
|
+
// Simulate streaming text
|
|
232
|
+
if (onTextPart) {
|
|
233
|
+
onTextPart('Hello from agent');
|
|
234
|
+
}
|
|
235
|
+
if (onFinishMessagePart) {
|
|
236
|
+
onFinishMessagePart();
|
|
237
|
+
}
|
|
238
|
+
return Promise.resolve();
|
|
239
|
+
}),
|
|
240
|
+
};
|
|
241
|
+
}),
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const adapter = new AGUIAdapter({
|
|
245
|
+
agent: clientAgent as any,
|
|
246
|
+
agentId: 'test',
|
|
247
|
+
resourceId: 'testAgent',
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
const input = {
|
|
251
|
+
threadId: 'test-thread-id',
|
|
252
|
+
runId: 'test-run-id',
|
|
253
|
+
messages: [
|
|
254
|
+
{
|
|
255
|
+
id: '1',
|
|
256
|
+
role: 'user' as const,
|
|
257
|
+
content: 'Hello',
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
tools: [],
|
|
261
|
+
context: [],
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
const observable = adapter['run'](input);
|
|
265
|
+
const events: BaseEvent[] = [];
|
|
266
|
+
|
|
267
|
+
await new Promise<void>((resolve, reject) => {
|
|
268
|
+
observable.subscribe({
|
|
269
|
+
next: (event: BaseEvent) => events.push(event),
|
|
270
|
+
complete: () => resolve(),
|
|
271
|
+
error: (error: any) => reject(error),
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
// Verify we received the expected events
|
|
276
|
+
expect(events).toHaveLength(5); // RUN_STARTED, TEXT_MESSAGE_START, TEXT_MESSAGE_CONTENT, TEXT_MESSAGE_END, RUN_FINISHED
|
|
277
|
+
expect(events[0].type).toBe('RUN_STARTED');
|
|
278
|
+
expect(events[1].type).toBe('TEXT_MESSAGE_START');
|
|
279
|
+
expect(events[2].type).toBe('TEXT_MESSAGE_CONTENT');
|
|
280
|
+
expect(events[3].type).toBe('TEXT_MESSAGE_END');
|
|
281
|
+
expect(events[4].type).toBe('RUN_FINISHED');
|
|
282
|
+
|
|
283
|
+
// Verify the stream method was called with the correct parameters
|
|
284
|
+
expect(clientAgent.stream).toHaveBeenCalledWith({
|
|
285
|
+
threadId: 'test-thread-id',
|
|
286
|
+
resourceId: 'testAgent',
|
|
287
|
+
runId: 'test-run-id',
|
|
288
|
+
messages: [{ role: 'user', content: 'Hello' }],
|
|
289
|
+
clientTools: {},
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it('should handle messages without role property in request objects', async () => {
|
|
294
|
+
// This test demonstrates that request objects without role property
|
|
295
|
+
// would cause validation errors if passed directly to MessageList
|
|
296
|
+
const requestObject = {
|
|
297
|
+
threadId: 'test-thread-id',
|
|
298
|
+
resourceId: 'testAgent',
|
|
299
|
+
runId: 'test-run-id',
|
|
300
|
+
messages: [
|
|
301
|
+
{
|
|
302
|
+
role: 'user',
|
|
303
|
+
content: 'Hello',
|
|
304
|
+
},
|
|
305
|
+
],
|
|
306
|
+
clientTools: {},
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
// Request objects don't have role property
|
|
310
|
+
expect('role' in requestObject).toBe(false);
|
|
311
|
+
expect('messages' in requestObject).toBe(true);
|
|
312
|
+
expect('content' in requestObject).toBe(false);
|
|
313
|
+
expect('parts' in requestObject).toBe(false);
|
|
314
|
+
|
|
315
|
+
// This structure would cause validation errors if treated as a message
|
|
316
|
+
// because it lacks required message properties (role, content/parts)
|
|
317
|
+
const hasValidMessageStructure =
|
|
318
|
+
'role' in requestObject && ('content' in requestObject || 'parts' in requestObject);
|
|
319
|
+
|
|
320
|
+
expect(hasValidMessageStructure).toBe(false);
|
|
321
|
+
});
|
|
322
|
+
});
|
package/src/adapters/agui.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
// Cross-platform UUID generation function
|
|
2
|
-
import { AbstractAgent, EventType } from '@ag-ui/client';
|
|
3
2
|
import type {
|
|
3
|
+
AgentConfig,
|
|
4
4
|
BaseEvent,
|
|
5
|
+
Message,
|
|
5
6
|
RunAgentInput,
|
|
6
|
-
AgentConfig,
|
|
7
|
-
RunStartedEvent,
|
|
8
7
|
RunFinishedEvent,
|
|
9
|
-
|
|
8
|
+
RunStartedEvent,
|
|
10
9
|
TextMessageContentEvent,
|
|
11
10
|
TextMessageEndEvent,
|
|
12
|
-
|
|
13
|
-
ToolCallStartEvent,
|
|
11
|
+
TextMessageStartEvent,
|
|
14
12
|
ToolCallArgsEvent,
|
|
15
13
|
ToolCallEndEvent,
|
|
14
|
+
ToolCallStartEvent,
|
|
16
15
|
} from '@ag-ui/client';
|
|
16
|
+
import { AbstractAgent, EventType } from '@ag-ui/client';
|
|
17
17
|
import type { CoreMessage } from '@mastra/core';
|
|
18
18
|
import { Observable } from 'rxjs';
|
|
19
19
|
import type { Agent } from '../resources/agent';
|
|
@@ -39,7 +39,6 @@ export class AGUIAdapter extends AbstractAgent {
|
|
|
39
39
|
protected run(input: RunAgentInput): Observable<BaseEvent> {
|
|
40
40
|
return new Observable<BaseEvent>(subscriber => {
|
|
41
41
|
const convertedMessages = convertMessagesToMastraMessages(input.messages);
|
|
42
|
-
|
|
43
42
|
subscriber.next({
|
|
44
43
|
type: EventType.RUN_STARTED,
|
|
45
44
|
threadId: input.threadId,
|
|
@@ -66,17 +65,18 @@ export class AGUIAdapter extends AbstractAgent {
|
|
|
66
65
|
})
|
|
67
66
|
.then(response => {
|
|
68
67
|
let currentMessageId: string | undefined = undefined;
|
|
68
|
+
let isInTextMessage = false;
|
|
69
69
|
return response.processDataStream({
|
|
70
70
|
onTextPart: text => {
|
|
71
71
|
if (currentMessageId === undefined) {
|
|
72
72
|
currentMessageId = generateUUID();
|
|
73
|
-
|
|
74
73
|
const message: TextMessageStartEvent = {
|
|
75
74
|
type: EventType.TEXT_MESSAGE_START,
|
|
76
75
|
messageId: currentMessageId,
|
|
77
76
|
role: 'assistant',
|
|
78
77
|
};
|
|
79
78
|
subscriber.next(message);
|
|
79
|
+
isInTextMessage = true;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
const message: TextMessageContentEvent = {
|
|
@@ -86,14 +86,14 @@ export class AGUIAdapter extends AbstractAgent {
|
|
|
86
86
|
};
|
|
87
87
|
subscriber.next(message);
|
|
88
88
|
},
|
|
89
|
-
onFinishMessagePart:
|
|
90
|
-
console.log('onFinishMessagePart', message);
|
|
89
|
+
onFinishMessagePart: () => {
|
|
91
90
|
if (currentMessageId !== undefined) {
|
|
92
91
|
const message: TextMessageEndEvent = {
|
|
93
92
|
type: EventType.TEXT_MESSAGE_END,
|
|
94
93
|
messageId: currentMessageId,
|
|
95
94
|
};
|
|
96
95
|
subscriber.next(message);
|
|
96
|
+
isInTextMessage = false;
|
|
97
97
|
}
|
|
98
98
|
// Emit run finished event
|
|
99
99
|
subscriber.next({
|
|
@@ -107,6 +107,15 @@ export class AGUIAdapter extends AbstractAgent {
|
|
|
107
107
|
},
|
|
108
108
|
onToolCallPart(streamPart) {
|
|
109
109
|
const parentMessageId = currentMessageId || generateUUID();
|
|
110
|
+
if (isInTextMessage) {
|
|
111
|
+
const message: TextMessageEndEvent = {
|
|
112
|
+
type: EventType.TEXT_MESSAGE_END,
|
|
113
|
+
messageId: parentMessageId,
|
|
114
|
+
};
|
|
115
|
+
subscriber.next(message);
|
|
116
|
+
isInTextMessage = false;
|
|
117
|
+
}
|
|
118
|
+
|
|
110
119
|
subscriber.next({
|
|
111
120
|
type: EventType.TOOL_CALL_START,
|
|
112
121
|
toolCallId: streamPart.toolCallId,
|
|
@@ -130,7 +139,7 @@ export class AGUIAdapter extends AbstractAgent {
|
|
|
130
139
|
});
|
|
131
140
|
})
|
|
132
141
|
.catch(error => {
|
|
133
|
-
console.
|
|
142
|
+
console.error('error', error);
|
|
134
143
|
// Handle error
|
|
135
144
|
subscriber.error(error);
|
|
136
145
|
});
|
|
@@ -195,6 +204,17 @@ export function convertMessagesToMastraMessages(messages: Message[]): CoreMessag
|
|
|
195
204
|
role: 'assistant',
|
|
196
205
|
content: parts,
|
|
197
206
|
});
|
|
207
|
+
if (message.toolCalls?.length) {
|
|
208
|
+
result.push({
|
|
209
|
+
role: 'tool',
|
|
210
|
+
content: message.toolCalls.map(toolCall => ({
|
|
211
|
+
type: 'tool-result',
|
|
212
|
+
toolCallId: toolCall.id,
|
|
213
|
+
toolName: toolCall.function.name,
|
|
214
|
+
result: JSON.parse(toolCall.function.arguments),
|
|
215
|
+
})),
|
|
216
|
+
});
|
|
217
|
+
}
|
|
198
218
|
} else if (message.role === 'user') {
|
|
199
219
|
result.push({
|
|
200
220
|
role: 'user',
|