@mastra/client-js 0.0.0-ai-v5-20250729181825 → 0.0.0-ai-v5-20250813235735
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 +215 -20
- 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 +85 -41
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3 -1331
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +82 -38
- 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 +12 -8
- package/src/adapters/agui.test.ts +145 -3
- package/src/adapters/agui.ts +41 -17
- package/src/client.ts +8 -0
- package/src/resources/a2a.ts +35 -25
- package/src/resources/agent.ts +26 -18
- package/src/resources/base.ts +1 -0
- package/src/resources/network.ts +1 -1
- package/src/types.ts +1 -1
- 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 -1331
|
@@ -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) {
|
|
@@ -1601,22 +1635,38 @@ var A2A = class extends BaseResource {
|
|
|
1601
1635
|
* @returns Promise containing the agent card information
|
|
1602
1636
|
*/
|
|
1603
1637
|
async getCard() {
|
|
1604
|
-
return this.request(`/.well-known/${this.agentId}/agent.json`);
|
|
1638
|
+
return this.request(`/.well-known/${this.agentId}/agent-card.json`);
|
|
1605
1639
|
}
|
|
1606
1640
|
/**
|
|
1607
|
-
* Send a message to the agent and
|
|
1641
|
+
* Send a message to the agent and gets a message or task response
|
|
1608
1642
|
* @param params - Parameters for the task
|
|
1609
|
-
* @returns Promise containing the
|
|
1643
|
+
* @returns Promise containing the response
|
|
1610
1644
|
*/
|
|
1611
1645
|
async sendMessage(params) {
|
|
1612
1646
|
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1613
1647
|
method: "POST",
|
|
1614
1648
|
body: {
|
|
1615
|
-
method: "
|
|
1649
|
+
method: "message/send",
|
|
1616
1650
|
params
|
|
1617
1651
|
}
|
|
1618
1652
|
});
|
|
1619
|
-
return
|
|
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",
|
|
1666
|
+
params
|
|
1667
|
+
}
|
|
1668
|
+
});
|
|
1669
|
+
return response;
|
|
1620
1670
|
}
|
|
1621
1671
|
/**
|
|
1622
1672
|
* Get the status and result of a task
|
|
@@ -1631,7 +1681,7 @@ var A2A = class extends BaseResource {
|
|
|
1631
1681
|
params
|
|
1632
1682
|
}
|
|
1633
1683
|
});
|
|
1634
|
-
return response
|
|
1684
|
+
return response;
|
|
1635
1685
|
}
|
|
1636
1686
|
/**
|
|
1637
1687
|
* Cancel a running task
|
|
@@ -1647,21 +1697,6 @@ var A2A = class extends BaseResource {
|
|
|
1647
1697
|
}
|
|
1648
1698
|
});
|
|
1649
1699
|
}
|
|
1650
|
-
/**
|
|
1651
|
-
* Send a message and subscribe to streaming updates (not fully implemented)
|
|
1652
|
-
* @param params - Parameters for the task
|
|
1653
|
-
* @returns Promise containing the task response
|
|
1654
|
-
*/
|
|
1655
|
-
async sendAndSubscribe(params) {
|
|
1656
|
-
return this.request(`/a2a/${this.agentId}`, {
|
|
1657
|
-
method: "POST",
|
|
1658
|
-
body: {
|
|
1659
|
-
method: "tasks/sendSubscribe",
|
|
1660
|
-
params
|
|
1661
|
-
},
|
|
1662
|
-
stream: true
|
|
1663
|
-
});
|
|
1664
|
-
}
|
|
1665
1700
|
};
|
|
1666
1701
|
|
|
1667
1702
|
// src/resources/mcp-tool.ts
|
|
@@ -2406,6 +2441,15 @@ var MastraClient = class extends BaseResource {
|
|
|
2406
2441
|
body: params
|
|
2407
2442
|
});
|
|
2408
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
|
+
}
|
|
2409
2451
|
};
|
|
2410
2452
|
|
|
2411
2453
|
export { MastraClient };
|
|
2454
|
+
//# sourceMappingURL=index.js.map
|
|
2455
|
+
//# sourceMappingURL=index.js.map
|