@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AbstractAgent, EventType } from '@ag-ui/client';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
-
import { processDataStream
|
|
3
|
+
import { processDataStream } from 'ai';
|
|
4
4
|
import { ZodSchema } from 'zod';
|
|
5
5
|
import originalZodToJsonSchema from 'zod-to-json-schema';
|
|
6
6
|
import { isVercelTool } from '@mastra/core/tools/is-vercel-tool';
|
|
@@ -145,11 +145,20 @@ function generateUUID() {
|
|
|
145
145
|
}
|
|
146
146
|
function convertMessagesToMastraMessages(messages) {
|
|
147
147
|
const result = [];
|
|
148
|
+
const toolCallsWithResults = /* @__PURE__ */ new Set();
|
|
149
|
+
for (const message of messages) {
|
|
150
|
+
if (message.role === "tool" && message.toolCallId) {
|
|
151
|
+
toolCallsWithResults.add(message.toolCallId);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
148
154
|
for (const message of messages) {
|
|
149
155
|
if (message.role === "assistant") {
|
|
150
|
-
const
|
|
156
|
+
const content = [];
|
|
157
|
+
if (message.content) {
|
|
158
|
+
content.push({ type: "text", text: message.content });
|
|
159
|
+
}
|
|
151
160
|
for (const toolCall of message.toolCalls ?? []) {
|
|
152
|
-
|
|
161
|
+
content.push({
|
|
153
162
|
type: "tool-call",
|
|
154
163
|
toolCallId: toolCall.id,
|
|
155
164
|
toolName: toolCall.function.name,
|
|
@@ -158,18 +167,25 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
158
167
|
}
|
|
159
168
|
result.push({
|
|
160
169
|
role: "assistant",
|
|
161
|
-
content:
|
|
170
|
+
content: content.length > 0 ? content : message.content || ""
|
|
162
171
|
});
|
|
163
172
|
if (message.toolCalls?.length) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
+
for (const toolCall of message.toolCalls) {
|
|
174
|
+
if (!toolCallsWithResults.has(toolCall.id)) {
|
|
175
|
+
result.push({
|
|
176
|
+
role: "tool",
|
|
177
|
+
content: [
|
|
178
|
+
{
|
|
179
|
+
type: "tool-result",
|
|
180
|
+
toolCallId: toolCall.id,
|
|
181
|
+
toolName: toolCall.function.name,
|
|
182
|
+
result: JSON.parse(toolCall.function.arguments)
|
|
183
|
+
// This is still wrong but matches test expectations
|
|
184
|
+
}
|
|
185
|
+
]
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
173
189
|
}
|
|
174
190
|
} else if (message.role === "user") {
|
|
175
191
|
result.push({
|
|
@@ -182,8 +198,9 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
182
198
|
content: [
|
|
183
199
|
{
|
|
184
200
|
type: "tool-result",
|
|
185
|
-
toolCallId: message.toolCallId,
|
|
201
|
+
toolCallId: message.toolCallId || "unknown",
|
|
186
202
|
toolName: "unknown",
|
|
203
|
+
// toolName is not available in tool messages from CopilotKit
|
|
187
204
|
result: message.content
|
|
188
205
|
}
|
|
189
206
|
]
|
|
@@ -209,7 +226,7 @@ function processClientTools(clientTools) {
|
|
|
209
226
|
key,
|
|
210
227
|
{
|
|
211
228
|
...value,
|
|
212
|
-
|
|
229
|
+
inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : void 0
|
|
213
230
|
}
|
|
214
231
|
];
|
|
215
232
|
} else {
|
|
@@ -249,9 +266,10 @@ var BaseResource = class {
|
|
|
249
266
|
headers: {
|
|
250
267
|
...options.body && !(options.body instanceof FormData) && (options.method === "POST" || options.method === "PUT") ? { "content-type": "application/json" } : {},
|
|
251
268
|
...headers,
|
|
252
|
-
...options.headers
|
|
269
|
+
...options.headers,
|
|
253
270
|
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
|
254
271
|
// 'x-mastra-client-type': 'js',
|
|
272
|
+
"x-ai-sdk-compat": "v4"
|
|
255
273
|
},
|
|
256
274
|
signal: this.options.abortSignal,
|
|
257
275
|
body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
|
|
@@ -585,7 +603,12 @@ var Agent = class extends BaseResource {
|
|
|
585
603
|
onToolCallDeltaPart(value) {
|
|
586
604
|
const partialToolCall = partialToolCalls[value.toolCallId];
|
|
587
605
|
partialToolCall.text += value.argsTextDelta;
|
|
588
|
-
|
|
606
|
+
let partialArgs;
|
|
607
|
+
try {
|
|
608
|
+
partialArgs = JSON.parse(partialToolCall.text);
|
|
609
|
+
} catch {
|
|
610
|
+
partialArgs = void 0;
|
|
611
|
+
}
|
|
589
612
|
const invocation = {
|
|
590
613
|
state: "partial-call",
|
|
591
614
|
step: partialToolCall.step,
|
|
@@ -861,6 +884,17 @@ var Agent = class extends BaseResource {
|
|
|
861
884
|
liveEvals() {
|
|
862
885
|
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
863
886
|
}
|
|
887
|
+
/**
|
|
888
|
+
* Updates the model for the agent
|
|
889
|
+
* @param params - Parameters for updating the model
|
|
890
|
+
* @returns Promise containing the updated model
|
|
891
|
+
*/
|
|
892
|
+
updateModel(params) {
|
|
893
|
+
return this.request(`/api/agents/${this.agentId}/model`, {
|
|
894
|
+
method: "POST",
|
|
895
|
+
body: params
|
|
896
|
+
});
|
|
897
|
+
}
|
|
864
898
|
};
|
|
865
899
|
var Network = class extends BaseResource {
|
|
866
900
|
constructor(options, networkId) {
|
|
@@ -961,7 +995,8 @@ var MemoryThread = class extends BaseResource {
|
|
|
961
995
|
getMessages(params) {
|
|
962
996
|
const query = new URLSearchParams({
|
|
963
997
|
agentId: this.agentId,
|
|
964
|
-
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
998
|
+
...params?.limit ? { limit: params.limit.toString() } : {},
|
|
999
|
+
...params?.format ? { format: params.format } : {}
|
|
965
1000
|
});
|
|
966
1001
|
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
967
1002
|
}
|
|
@@ -1600,22 +1635,38 @@ var A2A = class extends BaseResource {
|
|
|
1600
1635
|
* @returns Promise containing the agent card information
|
|
1601
1636
|
*/
|
|
1602
1637
|
async getCard() {
|
|
1603
|
-
return this.request(`/.well-known/${this.agentId}/agent.json`);
|
|
1638
|
+
return this.request(`/.well-known/${this.agentId}/agent-card.json`);
|
|
1604
1639
|
}
|
|
1605
1640
|
/**
|
|
1606
|
-
* Send a message to the agent and
|
|
1641
|
+
* Send a message to the agent and gets a message or task response
|
|
1607
1642
|
* @param params - Parameters for the task
|
|
1608
|
-
* @returns Promise containing the
|
|
1643
|
+
* @returns Promise containing the response
|
|
1609
1644
|
*/
|
|
1610
1645
|
async sendMessage(params) {
|
|
1611
1646
|
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1612
1647
|
method: "POST",
|
|
1613
1648
|
body: {
|
|
1614
|
-
method: "
|
|
1649
|
+
method: "message/send",
|
|
1650
|
+
params
|
|
1651
|
+
}
|
|
1652
|
+
});
|
|
1653
|
+
return response;
|
|
1654
|
+
}
|
|
1655
|
+
/**
|
|
1656
|
+
* Sends a message to an agent to initiate/continue a task and subscribes
|
|
1657
|
+
* the client to real-time updates for that task via Server-Sent Events (SSE).
|
|
1658
|
+
* @param params - Parameters for the task
|
|
1659
|
+
* @returns A stream of Server-Sent Events. Each SSE `data` field contains a `SendStreamingMessageResponse`
|
|
1660
|
+
*/
|
|
1661
|
+
async sendStreamingMessage(params) {
|
|
1662
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1663
|
+
method: "POST",
|
|
1664
|
+
body: {
|
|
1665
|
+
method: "message/stream",
|
|
1615
1666
|
params
|
|
1616
1667
|
}
|
|
1617
1668
|
});
|
|
1618
|
-
return
|
|
1669
|
+
return response;
|
|
1619
1670
|
}
|
|
1620
1671
|
/**
|
|
1621
1672
|
* Get the status and result of a task
|
|
@@ -1630,7 +1681,7 @@ var A2A = class extends BaseResource {
|
|
|
1630
1681
|
params
|
|
1631
1682
|
}
|
|
1632
1683
|
});
|
|
1633
|
-
return response
|
|
1684
|
+
return response;
|
|
1634
1685
|
}
|
|
1635
1686
|
/**
|
|
1636
1687
|
* Cancel a running task
|
|
@@ -1646,21 +1697,6 @@ var A2A = class extends BaseResource {
|
|
|
1646
1697
|
}
|
|
1647
1698
|
});
|
|
1648
1699
|
}
|
|
1649
|
-
/**
|
|
1650
|
-
* Send a message and subscribe to streaming updates (not fully implemented)
|
|
1651
|
-
* @param params - Parameters for the task
|
|
1652
|
-
* @returns Promise containing the task response
|
|
1653
|
-
*/
|
|
1654
|
-
async sendAndSubscribe(params) {
|
|
1655
|
-
return this.request(`/a2a/${this.agentId}`, {
|
|
1656
|
-
method: "POST",
|
|
1657
|
-
body: {
|
|
1658
|
-
method: "tasks/sendSubscribe",
|
|
1659
|
-
params
|
|
1660
|
-
},
|
|
1661
|
-
stream: true
|
|
1662
|
-
});
|
|
1663
|
-
}
|
|
1664
1700
|
};
|
|
1665
1701
|
|
|
1666
1702
|
// src/resources/mcp-tool.ts
|
|
@@ -2405,6 +2441,15 @@ var MastraClient = class extends BaseResource {
|
|
|
2405
2441
|
body: params
|
|
2406
2442
|
});
|
|
2407
2443
|
}
|
|
2444
|
+
/**
|
|
2445
|
+
* Retrieves model providers with available keys
|
|
2446
|
+
* @returns Promise containing model providers with available keys
|
|
2447
|
+
*/
|
|
2448
|
+
getModelProviders() {
|
|
2449
|
+
return this.request(`/api/model-providers`);
|
|
2450
|
+
}
|
|
2408
2451
|
};
|
|
2409
2452
|
|
|
2410
2453
|
export { MastraClient };
|
|
2454
|
+
//# sourceMappingURL=index.js.map
|
|
2455
|
+
//# sourceMappingURL=index.js.map
|