@mastra/client-js 0.0.0-feat-tool-input-validation-20250731232758 → 0.0.0-feat-support-ai-sdk-5-again-20250813225910
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 +18 -0
- package/CHANGELOG.md +178 -3
- package/dist/adapters/agui.d.ts +22 -0
- package/dist/adapters/agui.d.ts.map +1 -0
- package/dist/client.d.ts +270 -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 +87 -42
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3 -1328
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +84 -39
- package/dist/index.js.map +1 -0
- package/dist/resources/a2a.d.ts +41 -0
- package/dist/resources/a2a.d.ts.map +1 -0
- package/dist/resources/agent.d.ts +123 -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 +427 -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 +17 -0
- package/integration-tests/src/mastra/index.ts +38 -0
- package/integration-tests/vitest.config.ts +9 -0
- package/package.json +11 -7
- package/src/adapters/agui.test.ts +145 -3
- package/src/adapters/agui.ts +41 -17
- package/src/client.ts +8 -0
- package/src/index.ts +0 -1
- package/src/resources/a2a.ts +35 -25
- package/src/resources/agent.ts +26 -18
- package/src/resources/base.ts +1 -0
- package/src/resources/memory-thread.ts +1 -0
- package/src/resources/network.ts +1 -1
- package/src/types.ts +9 -5
- package/src/utils/process-client-tools.ts +1 -1
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +1 -1
- package/tsup.config.ts +17 -0
- package/dist/index.d.cts +0 -1328
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var client = require('@ag-ui/client');
|
|
4
4
|
var rxjs = require('rxjs');
|
|
5
|
-
var
|
|
5
|
+
var ai = require('ai');
|
|
6
6
|
var zod = require('zod');
|
|
7
7
|
var originalZodToJsonSchema = require('zod-to-json-schema');
|
|
8
8
|
var isVercelTool = require('@mastra/core/tools/is-vercel-tool');
|
|
@@ -151,11 +151,20 @@ function generateUUID() {
|
|
|
151
151
|
}
|
|
152
152
|
function convertMessagesToMastraMessages(messages) {
|
|
153
153
|
const result = [];
|
|
154
|
+
const toolCallsWithResults = /* @__PURE__ */ new Set();
|
|
155
|
+
for (const message of messages) {
|
|
156
|
+
if (message.role === "tool" && message.toolCallId) {
|
|
157
|
+
toolCallsWithResults.add(message.toolCallId);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
154
160
|
for (const message of messages) {
|
|
155
161
|
if (message.role === "assistant") {
|
|
156
|
-
const
|
|
162
|
+
const content = [];
|
|
163
|
+
if (message.content) {
|
|
164
|
+
content.push({ type: "text", text: message.content });
|
|
165
|
+
}
|
|
157
166
|
for (const toolCall of message.toolCalls ?? []) {
|
|
158
|
-
|
|
167
|
+
content.push({
|
|
159
168
|
type: "tool-call",
|
|
160
169
|
toolCallId: toolCall.id,
|
|
161
170
|
toolName: toolCall.function.name,
|
|
@@ -164,18 +173,25 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
164
173
|
}
|
|
165
174
|
result.push({
|
|
166
175
|
role: "assistant",
|
|
167
|
-
content:
|
|
176
|
+
content: content.length > 0 ? content : message.content || ""
|
|
168
177
|
});
|
|
169
178
|
if (message.toolCalls?.length) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
+
for (const toolCall of message.toolCalls) {
|
|
180
|
+
if (!toolCallsWithResults.has(toolCall.id)) {
|
|
181
|
+
result.push({
|
|
182
|
+
role: "tool",
|
|
183
|
+
content: [
|
|
184
|
+
{
|
|
185
|
+
type: "tool-result",
|
|
186
|
+
toolCallId: toolCall.id,
|
|
187
|
+
toolName: toolCall.function.name,
|
|
188
|
+
result: JSON.parse(toolCall.function.arguments)
|
|
189
|
+
// This is still wrong but matches test expectations
|
|
190
|
+
}
|
|
191
|
+
]
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
179
195
|
}
|
|
180
196
|
} else if (message.role === "user") {
|
|
181
197
|
result.push({
|
|
@@ -188,8 +204,9 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
188
204
|
content: [
|
|
189
205
|
{
|
|
190
206
|
type: "tool-result",
|
|
191
|
-
toolCallId: message.toolCallId,
|
|
207
|
+
toolCallId: message.toolCallId || "unknown",
|
|
192
208
|
toolName: "unknown",
|
|
209
|
+
// toolName is not available in tool messages from CopilotKit
|
|
193
210
|
result: message.content
|
|
194
211
|
}
|
|
195
212
|
]
|
|
@@ -215,7 +232,7 @@ function processClientTools(clientTools) {
|
|
|
215
232
|
key,
|
|
216
233
|
{
|
|
217
234
|
...value,
|
|
218
|
-
|
|
235
|
+
inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : void 0
|
|
219
236
|
}
|
|
220
237
|
];
|
|
221
238
|
} else {
|
|
@@ -255,9 +272,10 @@ var BaseResource = class {
|
|
|
255
272
|
headers: {
|
|
256
273
|
...options.body && !(options.body instanceof FormData) && (options.method === "POST" || options.method === "PUT") ? { "content-type": "application/json" } : {},
|
|
257
274
|
...headers,
|
|
258
|
-
...options.headers
|
|
275
|
+
...options.headers,
|
|
259
276
|
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
|
260
277
|
// 'x-mastra-client-type': 'js',
|
|
278
|
+
"x-ai-sdk-compat": "v4"
|
|
261
279
|
},
|
|
262
280
|
signal: this.options.abortSignal,
|
|
263
281
|
body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
|
|
@@ -494,7 +512,7 @@ var Agent = class extends BaseResource {
|
|
|
494
512
|
replaceLastMessage
|
|
495
513
|
});
|
|
496
514
|
}
|
|
497
|
-
await
|
|
515
|
+
await ai.processDataStream({
|
|
498
516
|
stream,
|
|
499
517
|
onTextPart(value) {
|
|
500
518
|
if (currentTextPart == null) {
|
|
@@ -591,7 +609,12 @@ var Agent = class extends BaseResource {
|
|
|
591
609
|
onToolCallDeltaPart(value) {
|
|
592
610
|
const partialToolCall = partialToolCalls[value.toolCallId];
|
|
593
611
|
partialToolCall.text += value.argsTextDelta;
|
|
594
|
-
|
|
612
|
+
let partialArgs;
|
|
613
|
+
try {
|
|
614
|
+
partialArgs = JSON.parse(partialToolCall.text);
|
|
615
|
+
} catch {
|
|
616
|
+
partialArgs = void 0;
|
|
617
|
+
}
|
|
595
618
|
const invocation = {
|
|
596
619
|
state: "partial-call",
|
|
597
620
|
step: partialToolCall.step,
|
|
@@ -710,7 +733,7 @@ var Agent = class extends BaseResource {
|
|
|
710
733
|
headers: response.headers
|
|
711
734
|
});
|
|
712
735
|
streamResponse.processDataStream = async (options = {}) => {
|
|
713
|
-
await
|
|
736
|
+
await ai.processDataStream({
|
|
714
737
|
stream: streamResponse.body,
|
|
715
738
|
...options
|
|
716
739
|
});
|
|
@@ -867,6 +890,17 @@ var Agent = class extends BaseResource {
|
|
|
867
890
|
liveEvals() {
|
|
868
891
|
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
869
892
|
}
|
|
893
|
+
/**
|
|
894
|
+
* Updates the model for the agent
|
|
895
|
+
* @param params - Parameters for updating the model
|
|
896
|
+
* @returns Promise containing the updated model
|
|
897
|
+
*/
|
|
898
|
+
updateModel(params) {
|
|
899
|
+
return this.request(`/api/agents/${this.agentId}/model`, {
|
|
900
|
+
method: "POST",
|
|
901
|
+
body: params
|
|
902
|
+
});
|
|
903
|
+
}
|
|
870
904
|
};
|
|
871
905
|
var Network = class extends BaseResource {
|
|
872
906
|
constructor(options, networkId) {
|
|
@@ -916,7 +950,7 @@ var Network = class extends BaseResource {
|
|
|
916
950
|
throw new Error("No response body");
|
|
917
951
|
}
|
|
918
952
|
response.processDataStream = async (options = {}) => {
|
|
919
|
-
await
|
|
953
|
+
await ai.processDataStream({
|
|
920
954
|
stream: response.body,
|
|
921
955
|
...options
|
|
922
956
|
});
|
|
@@ -967,7 +1001,8 @@ var MemoryThread = class extends BaseResource {
|
|
|
967
1001
|
getMessages(params) {
|
|
968
1002
|
const query = new URLSearchParams({
|
|
969
1003
|
agentId: this.agentId,
|
|
970
|
-
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
1004
|
+
...params?.limit ? { limit: params.limit.toString() } : {},
|
|
1005
|
+
...params?.format ? { format: params.format } : {}
|
|
971
1006
|
});
|
|
972
1007
|
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
973
1008
|
}
|
|
@@ -1606,22 +1641,38 @@ var A2A = class extends BaseResource {
|
|
|
1606
1641
|
* @returns Promise containing the agent card information
|
|
1607
1642
|
*/
|
|
1608
1643
|
async getCard() {
|
|
1609
|
-
return this.request(`/.well-known/${this.agentId}/agent.json`);
|
|
1644
|
+
return this.request(`/.well-known/${this.agentId}/agent-card.json`);
|
|
1610
1645
|
}
|
|
1611
1646
|
/**
|
|
1612
|
-
* Send a message to the agent and
|
|
1647
|
+
* Send a message to the agent and gets a message or task response
|
|
1613
1648
|
* @param params - Parameters for the task
|
|
1614
|
-
* @returns Promise containing the
|
|
1649
|
+
* @returns Promise containing the response
|
|
1615
1650
|
*/
|
|
1616
1651
|
async sendMessage(params) {
|
|
1617
1652
|
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1618
1653
|
method: "POST",
|
|
1619
1654
|
body: {
|
|
1620
|
-
method: "
|
|
1655
|
+
method: "message/send",
|
|
1656
|
+
params
|
|
1657
|
+
}
|
|
1658
|
+
});
|
|
1659
|
+
return response;
|
|
1660
|
+
}
|
|
1661
|
+
/**
|
|
1662
|
+
* Sends a message to an agent to initiate/continue a task and subscribes
|
|
1663
|
+
* the client to real-time updates for that task via Server-Sent Events (SSE).
|
|
1664
|
+
* @param params - Parameters for the task
|
|
1665
|
+
* @returns A stream of Server-Sent Events. Each SSE `data` field contains a `SendStreamingMessageResponse`
|
|
1666
|
+
*/
|
|
1667
|
+
async sendStreamingMessage(params) {
|
|
1668
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1669
|
+
method: "POST",
|
|
1670
|
+
body: {
|
|
1671
|
+
method: "message/stream",
|
|
1621
1672
|
params
|
|
1622
1673
|
}
|
|
1623
1674
|
});
|
|
1624
|
-
return
|
|
1675
|
+
return response;
|
|
1625
1676
|
}
|
|
1626
1677
|
/**
|
|
1627
1678
|
* Get the status and result of a task
|
|
@@ -1636,7 +1687,7 @@ var A2A = class extends BaseResource {
|
|
|
1636
1687
|
params
|
|
1637
1688
|
}
|
|
1638
1689
|
});
|
|
1639
|
-
return response
|
|
1690
|
+
return response;
|
|
1640
1691
|
}
|
|
1641
1692
|
/**
|
|
1642
1693
|
* Cancel a running task
|
|
@@ -1652,21 +1703,6 @@ var A2A = class extends BaseResource {
|
|
|
1652
1703
|
}
|
|
1653
1704
|
});
|
|
1654
1705
|
}
|
|
1655
|
-
/**
|
|
1656
|
-
* Send a message and subscribe to streaming updates (not fully implemented)
|
|
1657
|
-
* @param params - Parameters for the task
|
|
1658
|
-
* @returns Promise containing the task response
|
|
1659
|
-
*/
|
|
1660
|
-
async sendAndSubscribe(params) {
|
|
1661
|
-
return this.request(`/a2a/${this.agentId}`, {
|
|
1662
|
-
method: "POST",
|
|
1663
|
-
body: {
|
|
1664
|
-
method: "tasks/sendSubscribe",
|
|
1665
|
-
params
|
|
1666
|
-
},
|
|
1667
|
-
stream: true
|
|
1668
|
-
});
|
|
1669
|
-
}
|
|
1670
1706
|
};
|
|
1671
1707
|
|
|
1672
1708
|
// src/resources/mcp-tool.ts
|
|
@@ -2411,6 +2447,15 @@ var MastraClient = class extends BaseResource {
|
|
|
2411
2447
|
body: params
|
|
2412
2448
|
});
|
|
2413
2449
|
}
|
|
2450
|
+
/**
|
|
2451
|
+
* Retrieves model providers with available keys
|
|
2452
|
+
* @returns Promise containing model providers with available keys
|
|
2453
|
+
*/
|
|
2454
|
+
getModelProviders() {
|
|
2455
|
+
return this.request(`/api/model-providers`);
|
|
2456
|
+
}
|
|
2414
2457
|
};
|
|
2415
2458
|
|
|
2416
2459
|
exports.MastraClient = MastraClient;
|
|
2460
|
+
//# sourceMappingURL=index.cjs.map
|
|
2461
|
+
//# sourceMappingURL=index.cjs.map
|