@mastra/client-js 0.0.0-storage-20250225005900 → 0.0.0-taofeeqInngest-20250603090617
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 -16
- package/CHANGELOG.md +1305 -3
- package/{LICENSE → LICENSE.md} +3 -1
- package/README.md +6 -3
- package/dist/index.cjs +1451 -0
- package/dist/index.d.cts +907 -0
- package/dist/index.d.ts +907 -0
- package/dist/index.js +1445 -0
- package/package.json +31 -19
- package/src/adapters/agui.test.ts +180 -0
- package/src/adapters/agui.ts +239 -0
- package/src/client.ts +140 -11
- package/src/example.ts +47 -26
- package/src/index.test.ts +293 -60
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +104 -15
- package/src/resources/base.ts +6 -4
- package/src/resources/index.ts +5 -1
- package/src/resources/legacy-workflow.ts +242 -0
- package/src/resources/mcp-tool.ts +48 -0
- package/src/resources/memory-thread.ts +8 -5
- package/src/resources/network.ts +86 -0
- package/src/resources/tool.ts +16 -3
- package/src/resources/workflow.ts +309 -24
- package/src/types.ts +178 -27
- package/src/utils/index.ts +11 -0
- package/src/utils/zod-to-json-schema.ts +10 -0
- package/dist/index.d.mts +0 -405
- package/dist/index.mjs +0 -487
package/package.json
CHANGED
|
@@ -1,41 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/client-js",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-taofeeqInngest-20250603090617",
|
|
4
4
|
"description": "The official TypeScript library for the Mastra Client API",
|
|
5
5
|
"author": "",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
6
|
+
"type": "module",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"main": "dist/index.js",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
11
|
"import": {
|
|
11
|
-
"types": "./dist/index.d.
|
|
12
|
-
"default": "./dist/index.
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
13
18
|
}
|
|
14
19
|
},
|
|
15
20
|
"./package.json": "./package.json"
|
|
16
21
|
},
|
|
17
22
|
"repository": "github:mastra-ai/client-js",
|
|
18
|
-
"license": "
|
|
23
|
+
"license": "Elastic-2.0",
|
|
19
24
|
"dependencies": {
|
|
25
|
+
"@ag-ui/client": "^0.0.27",
|
|
26
|
+
"@ai-sdk/ui-utils": "^1.1.19",
|
|
20
27
|
"json-schema": "^0.4.0",
|
|
21
|
-
"
|
|
22
|
-
"zod
|
|
23
|
-
"
|
|
28
|
+
"rxjs": "7.8.1",
|
|
29
|
+
"zod": "^3.24.3",
|
|
30
|
+
"zod-to-json-schema": "^3.24.5"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"zod": "^3.0.0",
|
|
34
|
+
"@mastra/core": "^0.10.0-alpha.0"
|
|
24
35
|
},
|
|
25
36
|
"devDependencies": {
|
|
26
|
-
"@babel/preset-env": "^7.26.
|
|
27
|
-
"@babel/preset-typescript": "^7.
|
|
28
|
-
"@tsconfig/recommended": "^1.0.
|
|
37
|
+
"@babel/preset-env": "^7.26.9",
|
|
38
|
+
"@babel/preset-typescript": "^7.27.0",
|
|
39
|
+
"@tsconfig/recommended": "^1.0.8",
|
|
29
40
|
"@types/json-schema": "^7.0.15",
|
|
30
|
-
"@types/node": "^
|
|
31
|
-
"tsup": "^8.0
|
|
32
|
-
"typescript": "^5.
|
|
33
|
-
"vitest": "^3.
|
|
34
|
-
"@internal/lint": "0.0.0"
|
|
41
|
+
"@types/node": "^20.17.27",
|
|
42
|
+
"tsup": "^8.4.0",
|
|
43
|
+
"typescript": "^5.8.2",
|
|
44
|
+
"vitest": "^3.1.2",
|
|
45
|
+
"@internal/lint": "0.0.0-taofeeqInngest-20250603090617",
|
|
46
|
+
"@mastra/core": "0.0.0-taofeeqInngest-20250603090617"
|
|
35
47
|
},
|
|
36
48
|
"scripts": {
|
|
37
|
-
"build": "tsup
|
|
38
|
-
"dev": "
|
|
49
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting",
|
|
50
|
+
"dev": "pnpm build --watch",
|
|
39
51
|
"test": "vitest run"
|
|
40
52
|
}
|
|
41
53
|
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import type { Message } from '@ag-ui/client';
|
|
2
|
+
import { describe, it, expect } from 'vitest';
|
|
3
|
+
import { generateUUID, convertMessagesToMastraMessages } from './agui';
|
|
4
|
+
|
|
5
|
+
describe('generateUUID', () => {
|
|
6
|
+
it('should generate a valid UUID v4 string', () => {
|
|
7
|
+
const uuid = generateUUID();
|
|
8
|
+
// Check UUID format (8-4-4-4-12 hex digits)
|
|
9
|
+
expect(uuid).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should generate unique UUIDs', () => {
|
|
13
|
+
const uuids = new Set();
|
|
14
|
+
for (let i = 0; i < 100; i++) {
|
|
15
|
+
uuids.add(generateUUID());
|
|
16
|
+
}
|
|
17
|
+
// All UUIDs should be unique
|
|
18
|
+
expect(uuids.size).toBe(100);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('convertMessagesToMastraMessages', () => {
|
|
23
|
+
it('should convert user messages correctly', () => {
|
|
24
|
+
const messages: Message[] = [
|
|
25
|
+
{
|
|
26
|
+
id: '1',
|
|
27
|
+
role: 'user',
|
|
28
|
+
content: 'Hello, world!',
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const result = convertMessagesToMastraMessages(messages);
|
|
33
|
+
|
|
34
|
+
expect(result).toEqual([
|
|
35
|
+
{
|
|
36
|
+
role: 'user',
|
|
37
|
+
content: 'Hello, world!',
|
|
38
|
+
},
|
|
39
|
+
]);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should convert assistant messages correctly', () => {
|
|
43
|
+
const messages: Message[] = [
|
|
44
|
+
{
|
|
45
|
+
id: '1',
|
|
46
|
+
role: 'assistant',
|
|
47
|
+
content: 'Hello, I am an assistant',
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
const result = convertMessagesToMastraMessages(messages);
|
|
52
|
+
|
|
53
|
+
expect(result).toEqual([
|
|
54
|
+
{
|
|
55
|
+
role: 'assistant',
|
|
56
|
+
content: [{ type: 'text', text: 'Hello, I am an assistant' }],
|
|
57
|
+
},
|
|
58
|
+
]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should convert assistant messages with tool calls correctly', () => {
|
|
62
|
+
const messages: Message[] = [
|
|
63
|
+
{
|
|
64
|
+
id: '1',
|
|
65
|
+
role: 'assistant',
|
|
66
|
+
content: undefined,
|
|
67
|
+
toolCalls: [
|
|
68
|
+
{
|
|
69
|
+
id: 'tool-call-1',
|
|
70
|
+
type: 'function',
|
|
71
|
+
function: {
|
|
72
|
+
name: 'getWeather',
|
|
73
|
+
arguments: '{"location":"San Francisco"}',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
const result = convertMessagesToMastraMessages(messages);
|
|
81
|
+
|
|
82
|
+
expect(result).toEqual([
|
|
83
|
+
{
|
|
84
|
+
role: 'assistant',
|
|
85
|
+
content: [
|
|
86
|
+
{
|
|
87
|
+
type: 'tool-call',
|
|
88
|
+
toolCallId: 'tool-call-1',
|
|
89
|
+
toolName: 'getWeather',
|
|
90
|
+
args: { location: 'San Francisco' },
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
role: 'tool',
|
|
96
|
+
content: [
|
|
97
|
+
{
|
|
98
|
+
type: 'tool-result',
|
|
99
|
+
toolCallId: 'tool-call-1',
|
|
100
|
+
toolName: 'getWeather',
|
|
101
|
+
result: { location: 'San Francisco' },
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
]);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should convert tool messages correctly', () => {
|
|
109
|
+
const messages: Message[] = [
|
|
110
|
+
{
|
|
111
|
+
id: '1',
|
|
112
|
+
role: 'tool',
|
|
113
|
+
toolCallId: 'tool-call-1',
|
|
114
|
+
content: '{"temperature":72,"unit":"F"}',
|
|
115
|
+
},
|
|
116
|
+
];
|
|
117
|
+
|
|
118
|
+
const result = convertMessagesToMastraMessages(messages);
|
|
119
|
+
|
|
120
|
+
expect(result).toEqual([
|
|
121
|
+
{
|
|
122
|
+
role: 'tool',
|
|
123
|
+
content: [
|
|
124
|
+
{
|
|
125
|
+
type: 'tool-result',
|
|
126
|
+
toolCallId: 'tool-call-1',
|
|
127
|
+
toolName: 'unknown',
|
|
128
|
+
result: '{"temperature":72,"unit":"F"}',
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
]);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('should convert a complex conversation correctly', () => {
|
|
136
|
+
const messages: Message[] = [
|
|
137
|
+
{
|
|
138
|
+
id: '1',
|
|
139
|
+
role: 'user',
|
|
140
|
+
content: "What's the weather in San Francisco?",
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
id: '2',
|
|
144
|
+
role: 'assistant',
|
|
145
|
+
content: undefined,
|
|
146
|
+
toolCalls: [
|
|
147
|
+
{
|
|
148
|
+
id: 'tool-call-1',
|
|
149
|
+
type: 'function',
|
|
150
|
+
function: {
|
|
151
|
+
name: 'getWeather',
|
|
152
|
+
arguments: '{"location":"San Francisco"}',
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
id: '4',
|
|
159
|
+
role: 'assistant',
|
|
160
|
+
content: 'The weather in San Francisco is 72°F.',
|
|
161
|
+
},
|
|
162
|
+
];
|
|
163
|
+
|
|
164
|
+
const result = convertMessagesToMastraMessages(messages);
|
|
165
|
+
|
|
166
|
+
expect(result).toHaveLength(4);
|
|
167
|
+
expect(result[0].role).toBe('user');
|
|
168
|
+
expect(result[1].role).toBe('assistant');
|
|
169
|
+
expect(result[2].role).toBe('tool');
|
|
170
|
+
expect(result[2].content).toEqual([
|
|
171
|
+
{
|
|
172
|
+
type: 'tool-result',
|
|
173
|
+
toolCallId: 'tool-call-1',
|
|
174
|
+
toolName: 'getWeather',
|
|
175
|
+
result: { location: 'San Francisco' },
|
|
176
|
+
},
|
|
177
|
+
]);
|
|
178
|
+
expect(result[3].role).toBe('assistant');
|
|
179
|
+
});
|
|
180
|
+
});
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// Cross-platform UUID generation function
|
|
2
|
+
import type {
|
|
3
|
+
AgentConfig,
|
|
4
|
+
BaseEvent,
|
|
5
|
+
Message,
|
|
6
|
+
RunAgentInput,
|
|
7
|
+
RunFinishedEvent,
|
|
8
|
+
RunStartedEvent,
|
|
9
|
+
TextMessageContentEvent,
|
|
10
|
+
TextMessageEndEvent,
|
|
11
|
+
TextMessageStartEvent,
|
|
12
|
+
ToolCallArgsEvent,
|
|
13
|
+
ToolCallEndEvent,
|
|
14
|
+
ToolCallStartEvent,
|
|
15
|
+
} from '@ag-ui/client';
|
|
16
|
+
import { AbstractAgent, EventType } from '@ag-ui/client';
|
|
17
|
+
import type { CoreMessage } from '@mastra/core';
|
|
18
|
+
import { Observable } from 'rxjs';
|
|
19
|
+
import type { Agent } from '../resources/agent';
|
|
20
|
+
|
|
21
|
+
interface MastraAgentConfig extends AgentConfig {
|
|
22
|
+
agent: Agent;
|
|
23
|
+
agentId: string;
|
|
24
|
+
resourceId?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class AGUIAdapter extends AbstractAgent {
|
|
28
|
+
agent: Agent;
|
|
29
|
+
resourceId?: string;
|
|
30
|
+
constructor({ agent, agentId, resourceId, ...rest }: MastraAgentConfig) {
|
|
31
|
+
super({
|
|
32
|
+
agentId,
|
|
33
|
+
...rest,
|
|
34
|
+
});
|
|
35
|
+
this.agent = agent;
|
|
36
|
+
this.resourceId = resourceId;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
protected run(input: RunAgentInput): Observable<BaseEvent> {
|
|
40
|
+
return new Observable<BaseEvent>(subscriber => {
|
|
41
|
+
const convertedMessages = convertMessagesToMastraMessages(input.messages);
|
|
42
|
+
subscriber.next({
|
|
43
|
+
type: EventType.RUN_STARTED,
|
|
44
|
+
threadId: input.threadId,
|
|
45
|
+
runId: input.runId,
|
|
46
|
+
} as RunStartedEvent);
|
|
47
|
+
|
|
48
|
+
this.agent
|
|
49
|
+
.stream({
|
|
50
|
+
threadId: input.threadId,
|
|
51
|
+
resourceId: this.resourceId ?? '',
|
|
52
|
+
runId: input.runId,
|
|
53
|
+
messages: convertedMessages,
|
|
54
|
+
clientTools: input.tools.reduce(
|
|
55
|
+
(acc, tool) => {
|
|
56
|
+
acc[tool.name as string] = {
|
|
57
|
+
id: tool.name,
|
|
58
|
+
description: tool.description,
|
|
59
|
+
inputSchema: tool.parameters,
|
|
60
|
+
};
|
|
61
|
+
return acc;
|
|
62
|
+
},
|
|
63
|
+
{} as Record<string, any>,
|
|
64
|
+
),
|
|
65
|
+
})
|
|
66
|
+
.then(response => {
|
|
67
|
+
let currentMessageId: string | undefined = undefined;
|
|
68
|
+
let isInTextMessage = false;
|
|
69
|
+
return response.processDataStream({
|
|
70
|
+
onTextPart: text => {
|
|
71
|
+
if (currentMessageId === undefined) {
|
|
72
|
+
currentMessageId = generateUUID();
|
|
73
|
+
const message: TextMessageStartEvent = {
|
|
74
|
+
type: EventType.TEXT_MESSAGE_START,
|
|
75
|
+
messageId: currentMessageId,
|
|
76
|
+
role: 'assistant',
|
|
77
|
+
};
|
|
78
|
+
subscriber.next(message);
|
|
79
|
+
isInTextMessage = true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const message: TextMessageContentEvent = {
|
|
83
|
+
type: EventType.TEXT_MESSAGE_CONTENT,
|
|
84
|
+
messageId: currentMessageId,
|
|
85
|
+
delta: text,
|
|
86
|
+
};
|
|
87
|
+
subscriber.next(message);
|
|
88
|
+
},
|
|
89
|
+
onFinishMessagePart: () => {
|
|
90
|
+
if (currentMessageId !== undefined) {
|
|
91
|
+
const message: TextMessageEndEvent = {
|
|
92
|
+
type: EventType.TEXT_MESSAGE_END,
|
|
93
|
+
messageId: currentMessageId,
|
|
94
|
+
};
|
|
95
|
+
subscriber.next(message);
|
|
96
|
+
isInTextMessage = false;
|
|
97
|
+
}
|
|
98
|
+
// Emit run finished event
|
|
99
|
+
subscriber.next({
|
|
100
|
+
type: EventType.RUN_FINISHED,
|
|
101
|
+
threadId: input.threadId,
|
|
102
|
+
runId: input.runId,
|
|
103
|
+
} as RunFinishedEvent);
|
|
104
|
+
|
|
105
|
+
// Complete the observable
|
|
106
|
+
subscriber.complete();
|
|
107
|
+
},
|
|
108
|
+
onToolCallPart(streamPart) {
|
|
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
|
+
|
|
119
|
+
subscriber.next({
|
|
120
|
+
type: EventType.TOOL_CALL_START,
|
|
121
|
+
toolCallId: streamPart.toolCallId,
|
|
122
|
+
toolCallName: streamPart.toolName,
|
|
123
|
+
parentMessageId,
|
|
124
|
+
} as ToolCallStartEvent);
|
|
125
|
+
|
|
126
|
+
subscriber.next({
|
|
127
|
+
type: EventType.TOOL_CALL_ARGS,
|
|
128
|
+
toolCallId: streamPart.toolCallId,
|
|
129
|
+
delta: JSON.stringify(streamPart.args),
|
|
130
|
+
parentMessageId,
|
|
131
|
+
} as ToolCallArgsEvent);
|
|
132
|
+
|
|
133
|
+
subscriber.next({
|
|
134
|
+
type: EventType.TOOL_CALL_END,
|
|
135
|
+
toolCallId: streamPart.toolCallId,
|
|
136
|
+
parentMessageId,
|
|
137
|
+
} as ToolCallEndEvent);
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
})
|
|
141
|
+
.catch(error => {
|
|
142
|
+
console.error('error', error);
|
|
143
|
+
// Handle error
|
|
144
|
+
subscriber.error(error);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
return () => {};
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Generates a UUID v4 that works in both browser and Node.js environments
|
|
154
|
+
*/
|
|
155
|
+
export function generateUUID(): string {
|
|
156
|
+
// Use crypto.randomUUID() if available (Node.js environment or modern browsers)
|
|
157
|
+
if (typeof crypto !== 'undefined') {
|
|
158
|
+
// Browser crypto API or Node.js crypto global
|
|
159
|
+
if (typeof crypto.randomUUID === 'function') {
|
|
160
|
+
return crypto.randomUUID();
|
|
161
|
+
}
|
|
162
|
+
// Fallback for older browsers
|
|
163
|
+
if (typeof crypto.getRandomValues === 'function') {
|
|
164
|
+
const buffer = new Uint8Array(16);
|
|
165
|
+
crypto.getRandomValues(buffer);
|
|
166
|
+
// Set version (4) and variant (8, 9, A, or B)
|
|
167
|
+
buffer[6] = (buffer[6]! & 0x0f) | 0x40; // version 4
|
|
168
|
+
buffer[8] = (buffer[8]! & 0x3f) | 0x80; // variant
|
|
169
|
+
|
|
170
|
+
// Convert to hex string in UUID format
|
|
171
|
+
let hex = '';
|
|
172
|
+
for (let i = 0; i < 16; i++) {
|
|
173
|
+
hex += buffer[i]!.toString(16).padStart(2, '0');
|
|
174
|
+
// Add hyphens at standard positions
|
|
175
|
+
if (i === 3 || i === 5 || i === 7 || i === 9) hex += '-';
|
|
176
|
+
}
|
|
177
|
+
return hex;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Last resort fallback (less secure but works everywhere)
|
|
182
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
|
183
|
+
const r = (Math.random() * 16) | 0;
|
|
184
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
185
|
+
return v.toString(16);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function convertMessagesToMastraMessages(messages: Message[]): CoreMessage[] {
|
|
190
|
+
const result: CoreMessage[] = [];
|
|
191
|
+
|
|
192
|
+
for (const message of messages) {
|
|
193
|
+
if (message.role === 'assistant') {
|
|
194
|
+
const parts: any[] = message.content ? [{ type: 'text', text: message.content }] : [];
|
|
195
|
+
for (const toolCall of message.toolCalls ?? []) {
|
|
196
|
+
parts.push({
|
|
197
|
+
type: 'tool-call',
|
|
198
|
+
toolCallId: toolCall.id,
|
|
199
|
+
toolName: toolCall.function.name,
|
|
200
|
+
args: JSON.parse(toolCall.function.arguments),
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
result.push({
|
|
204
|
+
role: 'assistant',
|
|
205
|
+
content: parts,
|
|
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
|
+
}
|
|
218
|
+
} else if (message.role === 'user') {
|
|
219
|
+
result.push({
|
|
220
|
+
role: 'user',
|
|
221
|
+
content: message.content || '',
|
|
222
|
+
});
|
|
223
|
+
} else if (message.role === 'tool') {
|
|
224
|
+
result.push({
|
|
225
|
+
role: 'tool',
|
|
226
|
+
content: [
|
|
227
|
+
{
|
|
228
|
+
type: 'tool-result',
|
|
229
|
+
toolCallId: message.toolCallId,
|
|
230
|
+
toolName: 'unknown',
|
|
231
|
+
result: message.content,
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return result;
|
|
239
|
+
}
|
package/src/client.ts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { AbstractAgent } from '@ag-ui/client';
|
|
2
|
+
import type { ServerDetailInfo } from '@mastra/core/mcp';
|
|
3
|
+
import { AGUIAdapter } from './adapters/agui';
|
|
4
|
+
import {
|
|
5
|
+
Agent,
|
|
6
|
+
MemoryThread,
|
|
7
|
+
Tool,
|
|
8
|
+
Workflow,
|
|
9
|
+
Vector,
|
|
10
|
+
BaseResource,
|
|
11
|
+
Network,
|
|
12
|
+
A2A,
|
|
13
|
+
MCPTool,
|
|
14
|
+
LegacyWorkflow,
|
|
15
|
+
} from './resources';
|
|
2
16
|
import type {
|
|
3
17
|
ClientOptions,
|
|
4
18
|
CreateMemoryThreadParams,
|
|
@@ -9,13 +23,16 @@ import type {
|
|
|
9
23
|
GetLogsResponse,
|
|
10
24
|
GetMemoryThreadParams,
|
|
11
25
|
GetMemoryThreadResponse,
|
|
26
|
+
GetNetworkResponse,
|
|
12
27
|
GetTelemetryParams,
|
|
13
28
|
GetTelemetryResponse,
|
|
14
29
|
GetToolResponse,
|
|
15
30
|
GetWorkflowResponse,
|
|
16
|
-
RequestOptions,
|
|
17
31
|
SaveMessageToMemoryParams,
|
|
18
32
|
SaveMessageToMemoryResponse,
|
|
33
|
+
McpServerListResponse,
|
|
34
|
+
McpServerToolListResponse,
|
|
35
|
+
GetLegacyWorkflowResponse,
|
|
19
36
|
} from './types';
|
|
20
37
|
|
|
21
38
|
export class MastraClient extends BaseResource {
|
|
@@ -31,6 +48,25 @@ export class MastraClient extends BaseResource {
|
|
|
31
48
|
return this.request('/api/agents');
|
|
32
49
|
}
|
|
33
50
|
|
|
51
|
+
public async getAGUI({ resourceId }: { resourceId: string }): Promise<Record<string, AbstractAgent>> {
|
|
52
|
+
const agents = await this.getAgents();
|
|
53
|
+
|
|
54
|
+
return Object.entries(agents).reduce(
|
|
55
|
+
(acc, [agentId]) => {
|
|
56
|
+
const agent = this.getAgent(agentId);
|
|
57
|
+
|
|
58
|
+
acc[agentId] = new AGUIAdapter({
|
|
59
|
+
agentId,
|
|
60
|
+
agent,
|
|
61
|
+
resourceId,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return acc;
|
|
65
|
+
},
|
|
66
|
+
{} as Record<string, AbstractAgent>,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
34
70
|
/**
|
|
35
71
|
* Gets an agent instance by ID
|
|
36
72
|
* @param agentId - ID of the agent to retrieve
|
|
@@ -104,6 +140,23 @@ export class MastraClient extends BaseResource {
|
|
|
104
140
|
return new Tool(this.options, toolId);
|
|
105
141
|
}
|
|
106
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Retrieves all available legacy workflows
|
|
145
|
+
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
146
|
+
*/
|
|
147
|
+
public getLegacyWorkflows(): Promise<Record<string, GetLegacyWorkflowResponse>> {
|
|
148
|
+
return this.request('/api/workflows/legacy');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Gets a legacy workflow instance by ID
|
|
153
|
+
* @param workflowId - ID of the legacy workflow to retrieve
|
|
154
|
+
* @returns Legacy Workflow instance
|
|
155
|
+
*/
|
|
156
|
+
public getLegacyWorkflow(workflowId: string) {
|
|
157
|
+
return new LegacyWorkflow(this.options, workflowId);
|
|
158
|
+
}
|
|
159
|
+
|
|
107
160
|
/**
|
|
108
161
|
* Retrieves all available workflows
|
|
109
162
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
@@ -162,17 +215,9 @@ export class MastraClient extends BaseResource {
|
|
|
162
215
|
* @returns Promise containing telemetry data
|
|
163
216
|
*/
|
|
164
217
|
public getTelemetry(params?: GetTelemetryParams): Promise<GetTelemetryResponse> {
|
|
165
|
-
const { name, scope, page, perPage, attribute } = params || {};
|
|
218
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
166
219
|
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
167
220
|
|
|
168
|
-
const queryObj = {
|
|
169
|
-
...(name ? { name } : {}),
|
|
170
|
-
...(scope ? { scope } : {}),
|
|
171
|
-
...(page ? { page: String(page) } : {}),
|
|
172
|
-
...(perPage ? { perPage: String(perPage) } : {}),
|
|
173
|
-
...(_attribute?.length ? { attribute: _attribute } : {}),
|
|
174
|
-
} as const;
|
|
175
|
-
|
|
176
221
|
const searchParams = new URLSearchParams();
|
|
177
222
|
if (name) {
|
|
178
223
|
searchParams.set('name', name);
|
|
@@ -195,6 +240,12 @@ export class MastraClient extends BaseResource {
|
|
|
195
240
|
searchParams.set('attribute', _attribute);
|
|
196
241
|
}
|
|
197
242
|
}
|
|
243
|
+
if (fromDate) {
|
|
244
|
+
searchParams.set('fromDate', fromDate.toISOString());
|
|
245
|
+
}
|
|
246
|
+
if (toDate) {
|
|
247
|
+
searchParams.set('toDate', toDate.toISOString());
|
|
248
|
+
}
|
|
198
249
|
|
|
199
250
|
if (searchParams.size) {
|
|
200
251
|
return this.request(`/api/telemetry?${searchParams}`);
|
|
@@ -202,4 +253,82 @@ export class MastraClient extends BaseResource {
|
|
|
202
253
|
return this.request(`/api/telemetry`);
|
|
203
254
|
}
|
|
204
255
|
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Retrieves all available networks
|
|
259
|
+
* @returns Promise containing map of network IDs to network details
|
|
260
|
+
*/
|
|
261
|
+
public getNetworks(): Promise<Record<string, GetNetworkResponse>> {
|
|
262
|
+
return this.request('/api/networks');
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Gets a network instance by ID
|
|
267
|
+
* @param networkId - ID of the network to retrieve
|
|
268
|
+
* @returns Network instance
|
|
269
|
+
*/
|
|
270
|
+
public getNetwork(networkId: string) {
|
|
271
|
+
return new Network(this.options, networkId);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Retrieves a list of available MCP servers.
|
|
276
|
+
* @param params - Optional parameters for pagination (limit, offset).
|
|
277
|
+
* @returns Promise containing the list of MCP servers and pagination info.
|
|
278
|
+
*/
|
|
279
|
+
public getMcpServers(params?: { limit?: number; offset?: number }): Promise<McpServerListResponse> {
|
|
280
|
+
const searchParams = new URLSearchParams();
|
|
281
|
+
if (params?.limit !== undefined) {
|
|
282
|
+
searchParams.set('limit', String(params.limit));
|
|
283
|
+
}
|
|
284
|
+
if (params?.offset !== undefined) {
|
|
285
|
+
searchParams.set('offset', String(params.offset));
|
|
286
|
+
}
|
|
287
|
+
const queryString = searchParams.toString();
|
|
288
|
+
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ''}`);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Retrieves detailed information for a specific MCP server.
|
|
293
|
+
* @param serverId - The ID of the MCP server to retrieve.
|
|
294
|
+
* @param params - Optional parameters, e.g., specific version.
|
|
295
|
+
* @returns Promise containing the detailed MCP server information.
|
|
296
|
+
*/
|
|
297
|
+
public getMcpServerDetails(serverId: string, params?: { version?: string }): Promise<ServerDetailInfo> {
|
|
298
|
+
const searchParams = new URLSearchParams();
|
|
299
|
+
if (params?.version) {
|
|
300
|
+
searchParams.set('version', params.version);
|
|
301
|
+
}
|
|
302
|
+
const queryString = searchParams.toString();
|
|
303
|
+
return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ''}`);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Retrieves a list of tools for a specific MCP server.
|
|
308
|
+
* @param serverId - The ID of the MCP server.
|
|
309
|
+
* @returns Promise containing the list of tools.
|
|
310
|
+
*/
|
|
311
|
+
public getMcpServerTools(serverId: string): Promise<McpServerToolListResponse> {
|
|
312
|
+
return this.request(`/api/mcp/${serverId}/tools`);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Gets an MCPTool resource instance for a specific tool on an MCP server.
|
|
317
|
+
* This instance can then be used to fetch details or execute the tool.
|
|
318
|
+
* @param serverId - The ID of the MCP server.
|
|
319
|
+
* @param toolId - The ID of the tool.
|
|
320
|
+
* @returns MCPTool instance.
|
|
321
|
+
*/
|
|
322
|
+
public getMcpServerTool(serverId: string, toolId: string): MCPTool {
|
|
323
|
+
return new MCPTool(this.options, serverId, toolId);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Gets an A2A client for interacting with an agent via the A2A protocol
|
|
328
|
+
* @param agentId - ID of the agent to interact with
|
|
329
|
+
* @returns A2A client instance
|
|
330
|
+
*/
|
|
331
|
+
public getA2A(agentId: string) {
|
|
332
|
+
return new A2A(this.options, agentId);
|
|
333
|
+
}
|
|
205
334
|
}
|