@mastra/client-js 0.0.0-trigger-playground-ui-package-20250506151043 → 0.0.0-tsconfig-compile-20250703214351
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 +19 -0
- package/CHANGELOG.md +711 -2
- package/README.md +1 -1
- package/dist/index.cjs +1211 -141
- package/dist/index.d.cts +517 -83
- package/dist/index.d.ts +517 -83
- package/dist/index.js +1210 -144
- package/package.json +20 -15
- package/src/adapters/agui.test.ts +19 -6
- package/src/adapters/agui.ts +31 -11
- package/src/client.ts +243 -22
- package/src/example.ts +33 -31
- package/src/index.test.ts +121 -1
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +603 -44
- package/src/resources/base.ts +2 -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.ts +13 -3
- package/src/resources/network-memory-thread.ts +63 -0
- package/src/resources/network.ts +6 -13
- package/src/resources/tool.ts +9 -2
- package/src/resources/vNextNetwork.ts +177 -0
- package/src/resources/workflow.ts +241 -96
- package/src/types.ts +182 -22
- 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/index.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, beforeEach, it, vi } from 'vitest';
|
|
2
|
-
|
|
3
2
|
import { MastraClient } from './client';
|
|
3
|
+
import type { McpServerListResponse, ServerDetailInfo } from './types';
|
|
4
4
|
|
|
5
5
|
// Mock fetch globally
|
|
6
6
|
global.fetch = vi.fn();
|
|
@@ -236,6 +236,7 @@ describe('MastraClient Resources', () => {
|
|
|
236
236
|
model: 'gpt-4',
|
|
237
237
|
instructions: 'Test instructions',
|
|
238
238
|
tools: {},
|
|
239
|
+
workflows: {},
|
|
239
240
|
};
|
|
240
241
|
mockFetchResponse(mockResponse);
|
|
241
242
|
|
|
@@ -552,6 +553,35 @@ describe('MastraClient Resources', () => {
|
|
|
552
553
|
}),
|
|
553
554
|
);
|
|
554
555
|
});
|
|
556
|
+
|
|
557
|
+
it('should get thread messages with limit', async () => {
|
|
558
|
+
const mockResponse = {
|
|
559
|
+
messages: [
|
|
560
|
+
{
|
|
561
|
+
id: '1',
|
|
562
|
+
content: 'test',
|
|
563
|
+
threadId,
|
|
564
|
+
role: 'user',
|
|
565
|
+
type: 'text',
|
|
566
|
+
resourceId: 'test-resource',
|
|
567
|
+
createdAt: new Date(),
|
|
568
|
+
},
|
|
569
|
+
],
|
|
570
|
+
uiMessages: [],
|
|
571
|
+
};
|
|
572
|
+
mockFetchResponse(mockResponse);
|
|
573
|
+
|
|
574
|
+
const limit = 5;
|
|
575
|
+
const result = await memoryThread.getMessages({ limit });
|
|
576
|
+
|
|
577
|
+
expect(result).toEqual(mockResponse);
|
|
578
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
579
|
+
`${clientOptions.baseUrl}/api/memory/threads/${threadId}/messages?agentId=${agentId}&limit=${limit}`,
|
|
580
|
+
expect.objectContaining({
|
|
581
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
582
|
+
}),
|
|
583
|
+
);
|
|
584
|
+
});
|
|
555
585
|
});
|
|
556
586
|
|
|
557
587
|
describe('Tool Resource', () => {
|
|
@@ -707,4 +737,94 @@ describe('MastraClient Resources', () => {
|
|
|
707
737
|
);
|
|
708
738
|
});
|
|
709
739
|
});
|
|
740
|
+
|
|
741
|
+
describe('MCP Server Registry Client Methods', () => {
|
|
742
|
+
const mockServerInfo1 = {
|
|
743
|
+
id: 'mcp-server-1',
|
|
744
|
+
name: 'Test MCP Server 1',
|
|
745
|
+
version_detail: { version: '1.0.0', release_date: '2023-01-01T00:00:00Z', is_latest: true },
|
|
746
|
+
};
|
|
747
|
+
const mockServerInfo2 = {
|
|
748
|
+
id: 'mcp-server-2',
|
|
749
|
+
name: 'Test MCP Server 2',
|
|
750
|
+
version_detail: { version: '1.1.0', release_date: '2023-02-01T00:00:00Z', is_latest: true },
|
|
751
|
+
};
|
|
752
|
+
|
|
753
|
+
const mockServerDetail1: ServerDetailInfo = {
|
|
754
|
+
...mockServerInfo1,
|
|
755
|
+
description: 'Detailed description for server 1',
|
|
756
|
+
package_canonical: 'npm',
|
|
757
|
+
packages: [{ registry_name: 'npm', name: '@example/server1', version: '1.0.0' }],
|
|
758
|
+
remotes: [{ transport_type: 'sse', url: 'http://localhost/sse1' }],
|
|
759
|
+
};
|
|
760
|
+
|
|
761
|
+
describe('getMcpServers()', () => {
|
|
762
|
+
it('should fetch a list of MCP servers', async () => {
|
|
763
|
+
const mockResponse: McpServerListResponse = {
|
|
764
|
+
servers: [mockServerInfo1, mockServerInfo2],
|
|
765
|
+
total_count: 2,
|
|
766
|
+
next: null,
|
|
767
|
+
};
|
|
768
|
+
mockFetchResponse(mockResponse);
|
|
769
|
+
|
|
770
|
+
const result = await client.getMcpServers();
|
|
771
|
+
expect(result).toEqual(mockResponse);
|
|
772
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
773
|
+
`${clientOptions.baseUrl}/api/mcp/v0/servers`,
|
|
774
|
+
expect.objectContaining({
|
|
775
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
776
|
+
}),
|
|
777
|
+
);
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
it('should fetch MCP servers with limit and offset parameters', async () => {
|
|
781
|
+
const mockResponse: McpServerListResponse = {
|
|
782
|
+
servers: [mockServerInfo1],
|
|
783
|
+
total_count: 2,
|
|
784
|
+
next: '/api/mcp/v0/servers?limit=1&offset=1',
|
|
785
|
+
};
|
|
786
|
+
mockFetchResponse(mockResponse);
|
|
787
|
+
|
|
788
|
+
const result = await client.getMcpServers({ limit: 1, offset: 0 });
|
|
789
|
+
expect(result).toEqual(mockResponse);
|
|
790
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
791
|
+
`${clientOptions.baseUrl}/api/mcp/v0/servers?limit=1&offset=0`,
|
|
792
|
+
expect.objectContaining({
|
|
793
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
794
|
+
}),
|
|
795
|
+
);
|
|
796
|
+
});
|
|
797
|
+
});
|
|
798
|
+
|
|
799
|
+
describe('getMcpServerDetails()', () => {
|
|
800
|
+
const serverId = 'mcp-server-1';
|
|
801
|
+
|
|
802
|
+
it('should fetch details for a specific MCP server', async () => {
|
|
803
|
+
mockFetchResponse(mockServerDetail1);
|
|
804
|
+
|
|
805
|
+
const result = await client.getMcpServerDetails(serverId);
|
|
806
|
+
expect(result).toEqual(mockServerDetail1);
|
|
807
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
808
|
+
`${clientOptions.baseUrl}/api/mcp/v0/servers/${serverId}`,
|
|
809
|
+
expect.objectContaining({
|
|
810
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
811
|
+
}),
|
|
812
|
+
);
|
|
813
|
+
});
|
|
814
|
+
|
|
815
|
+
it('should fetch MCP server details with a version parameter', async () => {
|
|
816
|
+
mockFetchResponse(mockServerDetail1);
|
|
817
|
+
const version = '1.0.0';
|
|
818
|
+
|
|
819
|
+
const result = await client.getMcpServerDetails(serverId, { version });
|
|
820
|
+
expect(result).toEqual(mockServerDetail1);
|
|
821
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
822
|
+
`${clientOptions.baseUrl}/api/mcp/v0/servers/${serverId}?version=${version}`,
|
|
823
|
+
expect.objectContaining({
|
|
824
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
825
|
+
}),
|
|
826
|
+
);
|
|
827
|
+
});
|
|
828
|
+
});
|
|
829
|
+
});
|
|
710
830
|
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { TaskSendParams, TaskQueryParams, TaskIdParams, Task, AgentCard, JSONRPCResponse } from '@mastra/core/a2a';
|
|
2
|
+
import type { ClientOptions } from '../types';
|
|
3
|
+
import { BaseResource } from './base';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Class for interacting with an agent via the A2A protocol
|
|
7
|
+
*/
|
|
8
|
+
export class A2A extends BaseResource {
|
|
9
|
+
constructor(
|
|
10
|
+
options: ClientOptions,
|
|
11
|
+
private agentId: string,
|
|
12
|
+
) {
|
|
13
|
+
super(options);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Get the agent card with metadata about the agent
|
|
18
|
+
* @returns Promise containing the agent card information
|
|
19
|
+
*/
|
|
20
|
+
async getCard(): Promise<AgentCard> {
|
|
21
|
+
return this.request(`/.well-known/${this.agentId}/agent.json`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Send a message to the agent and get a response
|
|
26
|
+
* @param params - Parameters for the task
|
|
27
|
+
* @returns Promise containing the task response
|
|
28
|
+
*/
|
|
29
|
+
async sendMessage(params: TaskSendParams): Promise<{ task: Task }> {
|
|
30
|
+
const response = await this.request<JSONRPCResponse<Task>>(`/a2a/${this.agentId}`, {
|
|
31
|
+
method: 'POST',
|
|
32
|
+
body: {
|
|
33
|
+
method: 'tasks/send',
|
|
34
|
+
params,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return { task: response.result! };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Get the status and result of a task
|
|
43
|
+
* @param params - Parameters for querying the task
|
|
44
|
+
* @returns Promise containing the task response
|
|
45
|
+
*/
|
|
46
|
+
async getTask(params: TaskQueryParams): Promise<Task> {
|
|
47
|
+
const response = await this.request<JSONRPCResponse<Task>>(`/a2a/${this.agentId}`, {
|
|
48
|
+
method: 'POST',
|
|
49
|
+
body: {
|
|
50
|
+
method: 'tasks/get',
|
|
51
|
+
params,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return response.result!;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Cancel a running task
|
|
60
|
+
* @param params - Parameters identifying the task to cancel
|
|
61
|
+
* @returns Promise containing the task response
|
|
62
|
+
*/
|
|
63
|
+
async cancelTask(params: TaskIdParams): Promise<{ task: Task }> {
|
|
64
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
65
|
+
method: 'POST',
|
|
66
|
+
body: {
|
|
67
|
+
method: 'tasks/cancel',
|
|
68
|
+
params,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Send a message and subscribe to streaming updates (not fully implemented)
|
|
75
|
+
* @param params - Parameters for the task
|
|
76
|
+
* @returns Promise containing the task response
|
|
77
|
+
*/
|
|
78
|
+
async sendAndSubscribe(params: TaskSendParams): Promise<Response> {
|
|
79
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
80
|
+
method: 'POST',
|
|
81
|
+
body: {
|
|
82
|
+
method: 'tasks/sendSubscribe',
|
|
83
|
+
params,
|
|
84
|
+
},
|
|
85
|
+
stream: true,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|