@mastra/client-js 0.10.17 → 0.10.18-alpha.0

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 (58) hide show
  1. package/.turbo/turbo-build.log +2 -17
  2. package/CHANGELOG.md +12 -0
  3. package/dist/adapters/agui.d.ts +23 -0
  4. package/dist/adapters/agui.d.ts.map +1 -0
  5. package/dist/client.d.ts +265 -0
  6. package/dist/client.d.ts.map +1 -0
  7. package/dist/example.d.ts +2 -0
  8. package/dist/example.d.ts.map +1 -0
  9. package/dist/index.cjs +2 -0
  10. package/dist/index.cjs.map +1 -0
  11. package/dist/index.d.ts +4 -1328
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +2 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/resources/a2a.d.ts +44 -0
  16. package/dist/resources/a2a.d.ts.map +1 -0
  17. package/dist/resources/agent.d.ts +112 -0
  18. package/dist/resources/agent.d.ts.map +1 -0
  19. package/dist/resources/base.d.ts +13 -0
  20. package/dist/resources/base.d.ts.map +1 -0
  21. package/dist/resources/index.d.ts +11 -0
  22. package/dist/resources/index.d.ts.map +1 -0
  23. package/dist/resources/legacy-workflow.d.ts +87 -0
  24. package/dist/resources/legacy-workflow.d.ts.map +1 -0
  25. package/dist/resources/mcp-tool.d.ts +27 -0
  26. package/dist/resources/mcp-tool.d.ts.map +1 -0
  27. package/dist/resources/memory-thread.d.ts +53 -0
  28. package/dist/resources/memory-thread.d.ts.map +1 -0
  29. package/dist/resources/network-memory-thread.d.ts +47 -0
  30. package/dist/resources/network-memory-thread.d.ts.map +1 -0
  31. package/dist/resources/network.d.ts +30 -0
  32. package/dist/resources/network.d.ts.map +1 -0
  33. package/dist/resources/tool.d.ts +23 -0
  34. package/dist/resources/tool.d.ts.map +1 -0
  35. package/dist/resources/vNextNetwork.d.ts +42 -0
  36. package/dist/resources/vNextNetwork.d.ts.map +1 -0
  37. package/dist/resources/vector.d.ts +48 -0
  38. package/dist/resources/vector.d.ts.map +1 -0
  39. package/dist/resources/workflow.d.ts +154 -0
  40. package/dist/resources/workflow.d.ts.map +1 -0
  41. package/dist/types.d.ts +422 -0
  42. package/dist/types.d.ts.map +1 -0
  43. package/dist/utils/index.d.ts +3 -0
  44. package/dist/utils/index.d.ts.map +1 -0
  45. package/dist/utils/process-client-tools.d.ts +3 -0
  46. package/dist/utils/process-client-tools.d.ts.map +1 -0
  47. package/dist/utils/zod-to-json-schema.d.ts +105 -0
  48. package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
  49. package/integration-tests/agui-adapter.test.ts +122 -0
  50. package/integration-tests/package.json +18 -0
  51. package/integration-tests/src/mastra/index.ts +35 -0
  52. package/integration-tests/vitest.config.ts +9 -0
  53. package/package.json +8 -5
  54. package/src/adapters/agui.test.ts +145 -3
  55. package/tsconfig.build.json +9 -0
  56. package/tsconfig.json +1 -1
  57. package/tsup.config.ts +22 -0
  58. package/dist/index.d.cts +0 -1328
@@ -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
+ });
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true,
6
+ testTimeout: 30000, // 30 seconds for integration tests
7
+ hookTimeout: 20000, // 20 seconds for setup/teardown
8
+ },
9
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/client-js",
3
- "version": "0.10.17",
3
+ "version": "0.10.18-alpha.0",
4
4
  "description": "The official TypeScript library for the Mastra Client API",
5
5
  "author": "",
6
6
  "type": "module",
@@ -27,14 +27,14 @@
27
27
  "homepage": "https://github.com/mastra-ai/mastra/tree/main/client-sdks/client-js#readme",
28
28
  "license": "Apache-2.0",
29
29
  "dependencies": {
30
- "@ag-ui/client": "^0.0.27",
30
+ "@ag-ui/client": "^0.0.35",
31
31
  "@ai-sdk/ui-utils": "^1.2.11",
32
32
  "@lukeed/uuid": "^2.0.1",
33
33
  "json-schema": "^0.4.0",
34
34
  "rxjs": "7.8.1",
35
35
  "zod": "^3.25.67",
36
36
  "zod-to-json-schema": "^3.24.5",
37
- "@mastra/core": "0.12.0"
37
+ "@mastra/core": "0.12.1-alpha.0"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "zod": "^3.0.0"
@@ -45,14 +45,17 @@
45
45
  "@tsconfig/recommended": "^1.0.9",
46
46
  "@types/json-schema": "^7.0.15",
47
47
  "@types/node": "^20.19.0",
48
+ "ai": "^4.3.19",
48
49
  "tsup": "^8.5.0",
49
50
  "typescript": "^5.8.3",
50
51
  "vitest": "^3.2.4",
51
52
  "@internal/lint": "0.0.24"
52
53
  },
53
54
  "scripts": {
54
- "build": "tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting",
55
+ "build": "tsup --silent --config tsup.config.ts",
55
56
  "dev": "pnpm build --watch",
56
- "test": "vitest run"
57
+ "test": "vitest run && pnpm run test:integration",
58
+ "test:unit": "vitest run",
59
+ "test:integration": "cd integration-tests && pnpm test"
57
60
  }
58
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', () => {
@@ -178,3 +181,142 @@ describe('convertMessagesToMastraMessages', () => {
178
181
  expect(result[3].role).toBe('assistant');
179
182
  });
180
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
+ });
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": ["./tsconfig.json", "../../tsconfig.build.json"],
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": ["src/**/*"],
8
+ "exclude": ["node_modules", "**/*.test.ts", "src/**/*.mock.ts"]
9
+ }
package/tsconfig.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "extends": "../../tsconfig.node.json",
3
- "include": ["src/**/*"],
3
+ "include": ["src/**/*", "tsup.config.ts"],
4
4
  "exclude": ["node_modules", "**/*.test.ts"]
5
5
  }
package/tsup.config.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { spawn } from 'child_process';
2
+ import { promisify } from 'util';
3
+ import { defineConfig } from 'tsup';
4
+
5
+ const exec = promisify(spawn);
6
+
7
+ export default defineConfig({
8
+ entry: ['src/index.ts'],
9
+ format: ['esm', 'cjs'],
10
+ clean: true,
11
+ dts: false,
12
+ splitting: true,
13
+ treeshake: {
14
+ preset: 'smallest',
15
+ },
16
+ sourcemap: true,
17
+ onSuccess: async () => {
18
+ await exec('pnpm', ['tsc', '-p', 'tsconfig.build.json'], {
19
+ stdio: 'inherit',
20
+ });
21
+ },
22
+ });