@mastra/client-js 1.0.0-beta.0 → 1.0.0-beta.10
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/CHANGELOG.md +183 -0
- package/README.md +2 -0
- package/dist/client.d.ts +28 -6
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +379 -79
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +379 -75
- package/dist/index.js.map +1 -1
- package/dist/resources/a2a.d.ts.map +1 -1
- package/dist/resources/agent-builder.d.ts +2 -8
- package/dist/resources/agent-builder.d.ts.map +1 -1
- package/dist/resources/agent.d.ts +1 -1
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/resources/base.d.ts.map +1 -1
- package/dist/resources/index.d.ts +1 -0
- package/dist/resources/index.d.ts.map +1 -1
- package/dist/resources/stored-agent.d.ts +26 -0
- package/dist/resources/stored-agent.d.ts.map +1 -0
- package/dist/resources/workflow.d.ts +78 -7
- package/dist/resources/workflow.d.ts.map +1 -1
- package/dist/types.d.ts +122 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/process-mastra-stream.d.ts +1 -1
- package/dist/utils/process-mastra-stream.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema.d.ts +9 -1
- package/dist/utils/zod-to-json-schema.d.ts.map +1 -1
- package/package.json +11 -13
package/dist/index.js
CHANGED
|
@@ -3,8 +3,7 @@ import { v4 } from '@lukeed/uuid';
|
|
|
3
3
|
import { getErrorFromUnknown } from '@mastra/core/error';
|
|
4
4
|
import { RequestContext } from '@mastra/core/request-context';
|
|
5
5
|
import { isVercelTool } from '@mastra/core/tools/is-vercel-tool';
|
|
6
|
-
import {
|
|
7
|
-
import originalZodToJsonSchema from 'zod-to-json-schema';
|
|
6
|
+
import { zodToJsonSchema as zodToJsonSchema$1 } from '@mastra/schema-compat/zod-to-json';
|
|
8
7
|
|
|
9
8
|
// src/resources/agent.ts
|
|
10
9
|
function parseClientRequestContext(requestContext) {
|
|
@@ -37,11 +36,7 @@ function zodToJsonSchema(zodSchema) {
|
|
|
37
36
|
if (!isZodType(zodSchema)) {
|
|
38
37
|
return zodSchema;
|
|
39
38
|
}
|
|
40
|
-
|
|
41
|
-
const fn = "toJSONSchema";
|
|
42
|
-
return z[fn].call(z, zodSchema);
|
|
43
|
-
}
|
|
44
|
-
return originalZodToJsonSchema(zodSchema, { $refStrategy: "relative" });
|
|
39
|
+
return zodToJsonSchema$1(zodSchema);
|
|
45
40
|
}
|
|
46
41
|
|
|
47
42
|
// src/utils/process-client-tools.ts
|
|
@@ -92,7 +87,6 @@ async function sharedProcessMastraStream({
|
|
|
92
87
|
if (line.startsWith("data: ")) {
|
|
93
88
|
const data = line.slice(6);
|
|
94
89
|
if (data === "[DONE]") {
|
|
95
|
-
console.info("\u{1F3C1} Stream finished");
|
|
96
90
|
return;
|
|
97
91
|
}
|
|
98
92
|
let json;
|
|
@@ -145,11 +139,20 @@ var BaseResource = class {
|
|
|
145
139
|
*/
|
|
146
140
|
async request(path, options = {}) {
|
|
147
141
|
let lastError = null;
|
|
148
|
-
const {
|
|
142
|
+
const {
|
|
143
|
+
baseUrl,
|
|
144
|
+
retries = 3,
|
|
145
|
+
backoffMs = 100,
|
|
146
|
+
maxBackoffMs = 1e3,
|
|
147
|
+
headers = {},
|
|
148
|
+
credentials,
|
|
149
|
+
fetch: customFetch
|
|
150
|
+
} = this.options;
|
|
151
|
+
const fetchFn = customFetch || fetch;
|
|
149
152
|
let delay = backoffMs;
|
|
150
153
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
151
154
|
try {
|
|
152
|
-
const response = await
|
|
155
|
+
const response = await fetchFn(`${baseUrl.replace(/\/$/, "")}${path}`, {
|
|
153
156
|
...options,
|
|
154
157
|
headers: {
|
|
155
158
|
...options.body && !(options.body instanceof FormData) && (options.method === "POST" || options.method === "PUT") ? { "content-type": "application/json" } : {},
|
|
@@ -208,14 +211,14 @@ async function executeToolCallAndRespond({
|
|
|
208
211
|
return response;
|
|
209
212
|
}
|
|
210
213
|
for (const toolCall of toolCalls) {
|
|
211
|
-
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
214
|
+
const clientTool = params.clientTools?.[toolCall.payload.toolName];
|
|
212
215
|
if (clientTool && clientTool.execute) {
|
|
213
|
-
const result = await clientTool.execute(toolCall?.args, {
|
|
216
|
+
const result = await clientTool.execute(toolCall?.payload.args, {
|
|
214
217
|
requestContext,
|
|
215
218
|
tracingContext: { currentSpan: void 0 },
|
|
216
219
|
agent: {
|
|
217
220
|
messages: response.messages,
|
|
218
|
-
toolCallId: toolCall?.toolCallId,
|
|
221
|
+
toolCallId: toolCall?.payload.toolCallId,
|
|
219
222
|
suspend: async () => {
|
|
220
223
|
},
|
|
221
224
|
threadId,
|
|
@@ -229,8 +232,8 @@ async function executeToolCallAndRespond({
|
|
|
229
232
|
content: [
|
|
230
233
|
{
|
|
231
234
|
type: "tool-result",
|
|
232
|
-
toolCallId: toolCall.toolCallId,
|
|
233
|
-
toolName: toolCall.toolName,
|
|
235
|
+
toolCallId: toolCall.payload.toolCallId,
|
|
236
|
+
toolName: toolCall.payload.toolName,
|
|
234
237
|
result
|
|
235
238
|
}
|
|
236
239
|
]
|
|
@@ -243,6 +246,7 @@ async function executeToolCallAndRespond({
|
|
|
243
246
|
}
|
|
244
247
|
}
|
|
245
248
|
}
|
|
249
|
+
return response;
|
|
246
250
|
}
|
|
247
251
|
var AgentVoice = class extends BaseResource {
|
|
248
252
|
constructor(options, agentId) {
|
|
@@ -975,7 +979,7 @@ var Agent = class extends BaseResource {
|
|
|
975
979
|
});
|
|
976
980
|
onFinish?.({ message, finishReason, usage });
|
|
977
981
|
}
|
|
978
|
-
async processStreamResponse(processedParams,
|
|
982
|
+
async processStreamResponse(processedParams, controller, route = "stream") {
|
|
979
983
|
const response = await this.request(`/api/agents/${this.agentId}/${route}`, {
|
|
980
984
|
method: "POST",
|
|
981
985
|
body: processedParams,
|
|
@@ -987,29 +991,30 @@ var Agent = class extends BaseResource {
|
|
|
987
991
|
try {
|
|
988
992
|
let toolCalls = [];
|
|
989
993
|
let messages = [];
|
|
990
|
-
const [
|
|
991
|
-
|
|
994
|
+
const [streamForController, streamForProcessing] = response.body.tee();
|
|
995
|
+
const pipePromise = streamForController.pipeTo(
|
|
992
996
|
new WritableStream({
|
|
993
997
|
async write(chunk) {
|
|
994
|
-
let writer;
|
|
995
998
|
try {
|
|
996
|
-
writer = writable.getWriter();
|
|
997
999
|
const text = new TextDecoder().decode(chunk);
|
|
998
1000
|
const lines = text.split("\n\n");
|
|
999
|
-
const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1001
|
+
const readableLines = lines.filter((line) => line.trim() !== "[DONE]" && line.trim() !== "data: [DONE]").join("\n\n");
|
|
1002
|
+
if (readableLines) {
|
|
1003
|
+
const encoded = new TextEncoder().encode(readableLines);
|
|
1004
|
+
controller.enqueue(encoded);
|
|
1005
|
+
}
|
|
1006
|
+
} catch (error) {
|
|
1007
|
+
console.error("Error enqueueing to controller:", error);
|
|
1008
|
+
controller.enqueue(chunk);
|
|
1005
1009
|
}
|
|
1006
1010
|
}
|
|
1007
|
-
})
|
|
1008
|
-
{
|
|
1009
|
-
preventClose: true
|
|
1010
|
-
}
|
|
1011
|
+
})
|
|
1011
1012
|
).catch((error) => {
|
|
1012
|
-
console.error("Error piping to
|
|
1013
|
+
console.error("Error piping to controller:", error);
|
|
1014
|
+
try {
|
|
1015
|
+
controller.close();
|
|
1016
|
+
} catch {
|
|
1017
|
+
}
|
|
1013
1018
|
});
|
|
1014
1019
|
this.processChatResponse_vNext({
|
|
1015
1020
|
stream: streamForProcessing,
|
|
@@ -1065,31 +1070,36 @@ var Agent = class extends BaseResource {
|
|
|
1065
1070
|
toolInvocation.result = result;
|
|
1066
1071
|
}
|
|
1067
1072
|
const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
})
|
|
1073
|
+
try {
|
|
1074
|
+
await this.processStreamResponse(
|
|
1075
|
+
{
|
|
1076
|
+
...processedParams,
|
|
1077
|
+
messages: updatedMessages
|
|
1078
|
+
},
|
|
1079
|
+
controller
|
|
1080
|
+
);
|
|
1081
|
+
} catch (error) {
|
|
1082
|
+
console.error("Error processing recursive stream response:", error);
|
|
1083
|
+
}
|
|
1077
1084
|
}
|
|
1078
1085
|
}
|
|
1079
1086
|
if (!shouldExecuteClientTool) {
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
}, 0);
|
|
1087
|
+
await pipePromise;
|
|
1088
|
+
controller.close();
|
|
1083
1089
|
}
|
|
1084
1090
|
} else {
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
}, 0);
|
|
1091
|
+
await pipePromise;
|
|
1092
|
+
controller.close();
|
|
1088
1093
|
}
|
|
1089
1094
|
},
|
|
1090
1095
|
lastMessage: void 0
|
|
1091
|
-
}).catch((error) => {
|
|
1096
|
+
}).catch(async (error) => {
|
|
1092
1097
|
console.error("Error processing stream response:", error);
|
|
1098
|
+
try {
|
|
1099
|
+
await pipePromise;
|
|
1100
|
+
controller.close();
|
|
1101
|
+
} catch {
|
|
1102
|
+
}
|
|
1093
1103
|
});
|
|
1094
1104
|
} catch (error) {
|
|
1095
1105
|
console.error("Error processing stream response:", error);
|
|
@@ -1139,8 +1149,13 @@ var Agent = class extends BaseResource {
|
|
|
1139
1149
|
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
1140
1150
|
} : void 0
|
|
1141
1151
|
};
|
|
1142
|
-
|
|
1143
|
-
const
|
|
1152
|
+
let readableController;
|
|
1153
|
+
const readable = new ReadableStream({
|
|
1154
|
+
start(controller) {
|
|
1155
|
+
readableController = controller;
|
|
1156
|
+
}
|
|
1157
|
+
});
|
|
1158
|
+
const response = await this.processStreamResponse(processedParams, readableController);
|
|
1144
1159
|
const streamResponse = new Response(readable, {
|
|
1145
1160
|
status: response.status,
|
|
1146
1161
|
statusText: response.statusText,
|
|
@@ -1157,8 +1172,13 @@ var Agent = class extends BaseResource {
|
|
|
1157
1172
|
return streamResponse;
|
|
1158
1173
|
}
|
|
1159
1174
|
async approveToolCall(params) {
|
|
1160
|
-
|
|
1161
|
-
const
|
|
1175
|
+
let readableController;
|
|
1176
|
+
const readable = new ReadableStream({
|
|
1177
|
+
start(controller) {
|
|
1178
|
+
readableController = controller;
|
|
1179
|
+
}
|
|
1180
|
+
});
|
|
1181
|
+
const response = await this.processStreamResponse(params, readableController, "approve-tool-call");
|
|
1162
1182
|
const streamResponse = new Response(readable, {
|
|
1163
1183
|
status: response.status,
|
|
1164
1184
|
statusText: response.statusText,
|
|
@@ -1175,8 +1195,13 @@ var Agent = class extends BaseResource {
|
|
|
1175
1195
|
return streamResponse;
|
|
1176
1196
|
}
|
|
1177
1197
|
async declineToolCall(params) {
|
|
1178
|
-
|
|
1179
|
-
const
|
|
1198
|
+
let readableController;
|
|
1199
|
+
const readable = new ReadableStream({
|
|
1200
|
+
start(controller) {
|
|
1201
|
+
readableController = controller;
|
|
1202
|
+
}
|
|
1203
|
+
});
|
|
1204
|
+
const response = await this.processStreamResponse(params, readableController, "decline-tool-call");
|
|
1180
1205
|
const streamResponse = new Response(readable, {
|
|
1181
1206
|
status: response.status,
|
|
1182
1207
|
statusText: response.statusText,
|
|
@@ -1431,7 +1456,7 @@ var MemoryThread = class extends BaseResource {
|
|
|
1431
1456
|
if (include) queryParams.include = JSON.stringify(include);
|
|
1432
1457
|
const query = new URLSearchParams(queryParams);
|
|
1433
1458
|
const queryString = query.toString();
|
|
1434
|
-
const url = `/api/memory/threads/${this.threadId}/messages${queryString ?
|
|
1459
|
+
const url = `/api/memory/threads/${this.threadId}/messages?agentId=${this.agentId}${queryString ? `&${queryString}` : ""}${requestContextQueryString(requestContext, "&")}`;
|
|
1435
1460
|
return this.request(url);
|
|
1436
1461
|
}
|
|
1437
1462
|
/**
|
|
@@ -1590,15 +1615,21 @@ var Workflow = class extends BaseResource {
|
|
|
1590
1615
|
if (params?.toDate) {
|
|
1591
1616
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
1592
1617
|
}
|
|
1593
|
-
if (params?.
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1618
|
+
if (params?.page !== void 0) {
|
|
1619
|
+
searchParams.set("page", String(params.page));
|
|
1620
|
+
}
|
|
1621
|
+
if (params?.perPage !== void 0) {
|
|
1622
|
+
searchParams.set("perPage", String(params.perPage));
|
|
1623
|
+
}
|
|
1624
|
+
if (params?.limit !== null && params?.limit !== void 0) {
|
|
1625
|
+
if (params.limit === false) {
|
|
1626
|
+
searchParams.set("limit", "false");
|
|
1627
|
+
} else if (typeof params.limit === "number" && params.limit > 0 && Number.isInteger(params.limit)) {
|
|
1628
|
+
searchParams.set("limit", String(params.limit));
|
|
1598
1629
|
}
|
|
1599
1630
|
}
|
|
1600
|
-
if (params?.
|
|
1601
|
-
searchParams.set("
|
|
1631
|
+
if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
|
|
1632
|
+
searchParams.set("offset", String(params.offset));
|
|
1602
1633
|
}
|
|
1603
1634
|
if (params?.resourceId) {
|
|
1604
1635
|
searchParams.set("resourceId", params.resourceId);
|
|
@@ -1621,6 +1652,16 @@ var Workflow = class extends BaseResource {
|
|
|
1621
1652
|
runById(runId, requestContext) {
|
|
1622
1653
|
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${requestContextQueryString(requestContext)}`);
|
|
1623
1654
|
}
|
|
1655
|
+
/**
|
|
1656
|
+
* Deletes a specific workflow run by its ID
|
|
1657
|
+
* @param runId - The ID of the workflow run to delete
|
|
1658
|
+
* @returns Promise containing a success message
|
|
1659
|
+
*/
|
|
1660
|
+
deleteRunById(runId) {
|
|
1661
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`, {
|
|
1662
|
+
method: "DELETE"
|
|
1663
|
+
});
|
|
1664
|
+
}
|
|
1624
1665
|
/**
|
|
1625
1666
|
* Retrieves the execution result for a specific workflow run by its ID
|
|
1626
1667
|
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
@@ -1665,6 +1706,7 @@ var Workflow = class extends BaseResource {
|
|
|
1665
1706
|
return this.start({
|
|
1666
1707
|
runId,
|
|
1667
1708
|
inputData: p.inputData,
|
|
1709
|
+
initialState: p.initialState,
|
|
1668
1710
|
requestContext: p.requestContext,
|
|
1669
1711
|
tracingOptions: p.tracingOptions
|
|
1670
1712
|
});
|
|
@@ -1673,12 +1715,18 @@ var Workflow = class extends BaseResource {
|
|
|
1673
1715
|
return this.startAsync({
|
|
1674
1716
|
runId,
|
|
1675
1717
|
inputData: p.inputData,
|
|
1718
|
+
initialState: p.initialState,
|
|
1676
1719
|
requestContext: p.requestContext,
|
|
1677
1720
|
tracingOptions: p.tracingOptions
|
|
1678
1721
|
});
|
|
1679
1722
|
},
|
|
1680
1723
|
stream: async (p) => {
|
|
1681
|
-
return this.stream({
|
|
1724
|
+
return this.stream({
|
|
1725
|
+
runId,
|
|
1726
|
+
inputData: p.inputData,
|
|
1727
|
+
initialState: p.initialState,
|
|
1728
|
+
requestContext: p.requestContext
|
|
1729
|
+
});
|
|
1682
1730
|
},
|
|
1683
1731
|
resume: async (p) => {
|
|
1684
1732
|
return this.resume({
|
|
@@ -1710,14 +1758,19 @@ var Workflow = class extends BaseResource {
|
|
|
1710
1758
|
}
|
|
1711
1759
|
/**
|
|
1712
1760
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1713
|
-
* @param params - Object containing the runId, inputData and requestContext
|
|
1761
|
+
* @param params - Object containing the runId, inputData, initialState and requestContext
|
|
1714
1762
|
* @returns Promise containing success message
|
|
1715
1763
|
*/
|
|
1716
1764
|
start(params) {
|
|
1717
1765
|
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1718
1766
|
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1719
1767
|
method: "POST",
|
|
1720
|
-
body: {
|
|
1768
|
+
body: {
|
|
1769
|
+
inputData: params?.inputData,
|
|
1770
|
+
initialState: params?.initialState,
|
|
1771
|
+
requestContext,
|
|
1772
|
+
tracingOptions: params.tracingOptions
|
|
1773
|
+
}
|
|
1721
1774
|
});
|
|
1722
1775
|
}
|
|
1723
1776
|
/**
|
|
@@ -1745,7 +1798,7 @@ var Workflow = class extends BaseResource {
|
|
|
1745
1798
|
}
|
|
1746
1799
|
/**
|
|
1747
1800
|
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
1748
|
-
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1801
|
+
* @param params - Object containing the optional runId, inputData, initialState and requestContext
|
|
1749
1802
|
* @returns Promise containing the workflow execution results
|
|
1750
1803
|
*/
|
|
1751
1804
|
startAsync(params) {
|
|
@@ -1756,12 +1809,17 @@ var Workflow = class extends BaseResource {
|
|
|
1756
1809
|
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1757
1810
|
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1758
1811
|
method: "POST",
|
|
1759
|
-
body: {
|
|
1812
|
+
body: {
|
|
1813
|
+
inputData: params.inputData,
|
|
1814
|
+
initialState: params.initialState,
|
|
1815
|
+
requestContext,
|
|
1816
|
+
tracingOptions: params.tracingOptions
|
|
1817
|
+
}
|
|
1760
1818
|
});
|
|
1761
1819
|
}
|
|
1762
1820
|
/**
|
|
1763
1821
|
* Starts a workflow run and returns a stream
|
|
1764
|
-
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1822
|
+
* @param params - Object containing the optional runId, inputData, initialState and requestContext
|
|
1765
1823
|
* @returns Promise containing the workflow execution results
|
|
1766
1824
|
*/
|
|
1767
1825
|
async stream(params) {
|
|
@@ -1774,7 +1832,12 @@ var Workflow = class extends BaseResource {
|
|
|
1774
1832
|
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1775
1833
|
{
|
|
1776
1834
|
method: "POST",
|
|
1777
|
-
body: {
|
|
1835
|
+
body: {
|
|
1836
|
+
inputData: params.inputData,
|
|
1837
|
+
initialState: params.initialState,
|
|
1838
|
+
requestContext,
|
|
1839
|
+
tracingOptions: params.tracingOptions
|
|
1840
|
+
},
|
|
1778
1841
|
stream: true
|
|
1779
1842
|
}
|
|
1780
1843
|
);
|
|
@@ -1859,7 +1922,7 @@ var Workflow = class extends BaseResource {
|
|
|
1859
1922
|
}
|
|
1860
1923
|
/**
|
|
1861
1924
|
* Starts a workflow run and returns a stream
|
|
1862
|
-
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1925
|
+
* @param params - Object containing the optional runId, inputData, initialState and requestContext
|
|
1863
1926
|
* @returns Promise containing the workflow execution results
|
|
1864
1927
|
*/
|
|
1865
1928
|
async streamVNext(params) {
|
|
@@ -1874,6 +1937,7 @@ var Workflow = class extends BaseResource {
|
|
|
1874
1937
|
method: "POST",
|
|
1875
1938
|
body: {
|
|
1876
1939
|
inputData: params.inputData,
|
|
1940
|
+
initialState: params.initialState,
|
|
1877
1941
|
requestContext,
|
|
1878
1942
|
closeOnSuspend: params.closeOnSuspend,
|
|
1879
1943
|
tracingOptions: params.tracingOptions
|
|
@@ -2054,6 +2118,142 @@ var Workflow = class extends BaseResource {
|
|
|
2054
2118
|
}
|
|
2055
2119
|
});
|
|
2056
2120
|
}
|
|
2121
|
+
/**
|
|
2122
|
+
* Restarts an active workflow run synchronously without waiting for the workflow to complete
|
|
2123
|
+
* @param params - Object containing the runId and requestContext
|
|
2124
|
+
* @returns Promise containing success message
|
|
2125
|
+
*/
|
|
2126
|
+
restart(params) {
|
|
2127
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2128
|
+
return this.request(`/api/workflows/${this.workflowId}/restart?runId=${params.runId}`, {
|
|
2129
|
+
method: "POST",
|
|
2130
|
+
body: {
|
|
2131
|
+
requestContext,
|
|
2132
|
+
tracingOptions: params.tracingOptions
|
|
2133
|
+
}
|
|
2134
|
+
});
|
|
2135
|
+
}
|
|
2136
|
+
/**
|
|
2137
|
+
* Restarts an active workflow run asynchronously
|
|
2138
|
+
* @param params - Object containing the runId and requestContext
|
|
2139
|
+
* @returns Promise containing the workflow restart results
|
|
2140
|
+
*/
|
|
2141
|
+
restartAsync(params) {
|
|
2142
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2143
|
+
return this.request(`/api/workflows/${this.workflowId}/restart-async?runId=${params.runId}`, {
|
|
2144
|
+
method: "POST",
|
|
2145
|
+
body: {
|
|
2146
|
+
requestContext,
|
|
2147
|
+
tracingOptions: params.tracingOptions
|
|
2148
|
+
}
|
|
2149
|
+
});
|
|
2150
|
+
}
|
|
2151
|
+
/**
|
|
2152
|
+
* Restart all active workflow runs synchronously without waiting for the workflow to complete
|
|
2153
|
+
* @returns Promise containing success message
|
|
2154
|
+
*/
|
|
2155
|
+
restartAllActiveWorkflowRuns() {
|
|
2156
|
+
return this.request(`/api/workflows/${this.workflowId}/restart-all-active-workflow-runs`, {
|
|
2157
|
+
method: "POST"
|
|
2158
|
+
});
|
|
2159
|
+
}
|
|
2160
|
+
/**
|
|
2161
|
+
* Restart all active workflow runs asynchronously
|
|
2162
|
+
* @returns Promise containing success message
|
|
2163
|
+
*/
|
|
2164
|
+
restartAllActiveWorkflowRunsAsync() {
|
|
2165
|
+
return this.request(`/api/workflows/${this.workflowId}/restart-all-active-workflow-runs-async`, {
|
|
2166
|
+
method: "POST"
|
|
2167
|
+
});
|
|
2168
|
+
}
|
|
2169
|
+
/**
|
|
2170
|
+
* Time travels a workflow run synchronously without waiting for the workflow to complete
|
|
2171
|
+
* @param params - Object containing the runId, step, inputData, resumeData, initialState, context, nestedStepsContext, requestContext and tracingOptions
|
|
2172
|
+
* @returns Promise containing success message
|
|
2173
|
+
*/
|
|
2174
|
+
timeTravel({
|
|
2175
|
+
runId,
|
|
2176
|
+
requestContext: paramsRequestContext,
|
|
2177
|
+
...params
|
|
2178
|
+
}) {
|
|
2179
|
+
const requestContext = parseClientRequestContext(paramsRequestContext);
|
|
2180
|
+
return this.request(`/api/workflows/${this.workflowId}/time-travel?runId=${runId}`, {
|
|
2181
|
+
method: "POST",
|
|
2182
|
+
body: {
|
|
2183
|
+
...params,
|
|
2184
|
+
requestContext
|
|
2185
|
+
}
|
|
2186
|
+
});
|
|
2187
|
+
}
|
|
2188
|
+
/**
|
|
2189
|
+
* Time travels a workflow run asynchronously
|
|
2190
|
+
* @param params - Object containing the runId, step, inputData, resumeData, initialState, context, nestedStepsContext, requestContext and tracingOptions
|
|
2191
|
+
* @returns Promise containing the workflow time travel results
|
|
2192
|
+
*/
|
|
2193
|
+
timeTravelAsync({
|
|
2194
|
+
runId,
|
|
2195
|
+
requestContext: paramsRequestContext,
|
|
2196
|
+
...params
|
|
2197
|
+
}) {
|
|
2198
|
+
const requestContext = parseClientRequestContext(paramsRequestContext);
|
|
2199
|
+
return this.request(`/api/workflows/${this.workflowId}/time-travel-async?runId=${runId}`, {
|
|
2200
|
+
method: "POST",
|
|
2201
|
+
body: {
|
|
2202
|
+
...params,
|
|
2203
|
+
requestContext
|
|
2204
|
+
}
|
|
2205
|
+
});
|
|
2206
|
+
}
|
|
2207
|
+
/**
|
|
2208
|
+
* Time travels a workflow run and returns a stream
|
|
2209
|
+
* @param params - Object containing the runId, step, inputData, resumeData, initialState, context, nestedStepsContext, requestContext and tracingOptions
|
|
2210
|
+
* @returns Promise containing the workflow execution results
|
|
2211
|
+
*/
|
|
2212
|
+
async timeTravelStream({ runId, requestContext: paramsRequestContext, ...params }) {
|
|
2213
|
+
const requestContext = parseClientRequestContext(paramsRequestContext);
|
|
2214
|
+
const response = await this.request(
|
|
2215
|
+
`/api/workflows/${this.workflowId}/time-travel-stream?runId=${runId}`,
|
|
2216
|
+
{
|
|
2217
|
+
method: "POST",
|
|
2218
|
+
body: {
|
|
2219
|
+
...params,
|
|
2220
|
+
requestContext
|
|
2221
|
+
},
|
|
2222
|
+
stream: true
|
|
2223
|
+
}
|
|
2224
|
+
);
|
|
2225
|
+
if (!response.ok) {
|
|
2226
|
+
throw new Error(`Failed to time travel workflow: ${response.statusText}`);
|
|
2227
|
+
}
|
|
2228
|
+
if (!response.body) {
|
|
2229
|
+
throw new Error("Response body is null");
|
|
2230
|
+
}
|
|
2231
|
+
let failedChunk = void 0;
|
|
2232
|
+
const transformStream = new TransformStream({
|
|
2233
|
+
start() {
|
|
2234
|
+
},
|
|
2235
|
+
async transform(chunk, controller) {
|
|
2236
|
+
try {
|
|
2237
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2238
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
2239
|
+
for (const chunk2 of chunks) {
|
|
2240
|
+
if (chunk2) {
|
|
2241
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2242
|
+
try {
|
|
2243
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2244
|
+
controller.enqueue(parsedChunk);
|
|
2245
|
+
failedChunk = void 0;
|
|
2246
|
+
} catch {
|
|
2247
|
+
failedChunk = newChunk;
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
} catch {
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
});
|
|
2255
|
+
return response.body.pipeThrough(transformStream);
|
|
2256
|
+
}
|
|
2057
2257
|
};
|
|
2058
2258
|
|
|
2059
2259
|
// src/resources/a2a.ts
|
|
@@ -2096,7 +2296,8 @@ var A2A = class extends BaseResource {
|
|
|
2096
2296
|
body: {
|
|
2097
2297
|
method: "message/stream",
|
|
2098
2298
|
params
|
|
2099
|
-
}
|
|
2299
|
+
},
|
|
2300
|
+
stream: true
|
|
2100
2301
|
});
|
|
2101
2302
|
return response;
|
|
2102
2303
|
}
|
|
@@ -2527,6 +2728,16 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2527
2728
|
if (params?.page !== void 0) {
|
|
2528
2729
|
searchParams.set("page", String(params.page));
|
|
2529
2730
|
}
|
|
2731
|
+
if (params?.limit !== null && params?.limit !== void 0) {
|
|
2732
|
+
if (params.limit === false) {
|
|
2733
|
+
searchParams.set("limit", "false");
|
|
2734
|
+
} else if (typeof params.limit === "number" && params.limit > 0 && Number.isInteger(params.limit)) {
|
|
2735
|
+
searchParams.set("limit", String(params.limit));
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
|
|
2739
|
+
searchParams.set("offset", String(params.offset));
|
|
2740
|
+
}
|
|
2530
2741
|
if (params?.resourceId) {
|
|
2531
2742
|
searchParams.set("resourceId", params.resourceId);
|
|
2532
2743
|
}
|
|
@@ -2633,6 +2844,41 @@ var Observability = class extends BaseResource {
|
|
|
2633
2844
|
}
|
|
2634
2845
|
};
|
|
2635
2846
|
|
|
2847
|
+
// src/resources/stored-agent.ts
|
|
2848
|
+
var StoredAgent = class extends BaseResource {
|
|
2849
|
+
constructor(options, storedAgentId) {
|
|
2850
|
+
super(options);
|
|
2851
|
+
this.storedAgentId = storedAgentId;
|
|
2852
|
+
}
|
|
2853
|
+
/**
|
|
2854
|
+
* Retrieves details about the stored agent
|
|
2855
|
+
* @returns Promise containing stored agent details
|
|
2856
|
+
*/
|
|
2857
|
+
details() {
|
|
2858
|
+
return this.request(`/api/stored/agents/${encodeURIComponent(this.storedAgentId)}`);
|
|
2859
|
+
}
|
|
2860
|
+
/**
|
|
2861
|
+
* Updates the stored agent with the provided fields
|
|
2862
|
+
* @param params - Fields to update
|
|
2863
|
+
* @returns Promise containing the updated stored agent
|
|
2864
|
+
*/
|
|
2865
|
+
update(params) {
|
|
2866
|
+
return this.request(`/api/stored/agents/${encodeURIComponent(this.storedAgentId)}`, {
|
|
2867
|
+
method: "PATCH",
|
|
2868
|
+
body: params
|
|
2869
|
+
});
|
|
2870
|
+
}
|
|
2871
|
+
/**
|
|
2872
|
+
* Deletes the stored agent
|
|
2873
|
+
* @returns Promise containing deletion confirmation
|
|
2874
|
+
*/
|
|
2875
|
+
delete() {
|
|
2876
|
+
return this.request(`/api/stored/agents/${encodeURIComponent(this.storedAgentId)}`, {
|
|
2877
|
+
method: "DELETE"
|
|
2878
|
+
});
|
|
2879
|
+
}
|
|
2880
|
+
};
|
|
2881
|
+
|
|
2636
2882
|
// src/client.ts
|
|
2637
2883
|
var MastraClient = class extends BaseResource {
|
|
2638
2884
|
observability;
|
|
@@ -2645,12 +2891,15 @@ var MastraClient = class extends BaseResource {
|
|
|
2645
2891
|
* @param requestContext - Optional request context to pass as query parameter
|
|
2646
2892
|
* @returns Promise containing map of agent IDs to agent details
|
|
2647
2893
|
*/
|
|
2648
|
-
listAgents(requestContext) {
|
|
2894
|
+
listAgents(requestContext, partial) {
|
|
2649
2895
|
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2650
2896
|
const searchParams = new URLSearchParams();
|
|
2651
2897
|
if (requestContextParam) {
|
|
2652
2898
|
searchParams.set("requestContext", requestContextParam);
|
|
2653
2899
|
}
|
|
2900
|
+
if (partial) {
|
|
2901
|
+
searchParams.set("partial", "true");
|
|
2902
|
+
}
|
|
2654
2903
|
const queryString = searchParams.toString();
|
|
2655
2904
|
return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
|
|
2656
2905
|
}
|
|
@@ -2792,12 +3041,15 @@ var MastraClient = class extends BaseResource {
|
|
|
2792
3041
|
* @param requestContext - Optional request context to pass as query parameter
|
|
2793
3042
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
2794
3043
|
*/
|
|
2795
|
-
listWorkflows(requestContext) {
|
|
3044
|
+
listWorkflows(requestContext, partial) {
|
|
2796
3045
|
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2797
3046
|
const searchParams = new URLSearchParams();
|
|
2798
3047
|
if (requestContextParam) {
|
|
2799
3048
|
searchParams.set("requestContext", requestContextParam);
|
|
2800
3049
|
}
|
|
3050
|
+
if (partial) {
|
|
3051
|
+
searchParams.set("partial", "true");
|
|
3052
|
+
}
|
|
2801
3053
|
const queryString = searchParams.toString();
|
|
2802
3054
|
return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
|
|
2803
3055
|
}
|
|
@@ -2927,16 +3179,22 @@ var MastraClient = class extends BaseResource {
|
|
|
2927
3179
|
}
|
|
2928
3180
|
/**
|
|
2929
3181
|
* Retrieves a list of available MCP servers.
|
|
2930
|
-
* @param params - Optional parameters for pagination (perPage,
|
|
3182
|
+
* @param params - Optional parameters for pagination (page, perPage, or deprecated offset, limit).
|
|
2931
3183
|
* @returns Promise containing the list of MCP servers and pagination info.
|
|
2932
3184
|
*/
|
|
2933
3185
|
getMcpServers(params) {
|
|
2934
3186
|
const searchParams = new URLSearchParams();
|
|
3187
|
+
if (params?.page !== void 0) {
|
|
3188
|
+
searchParams.set("page", String(params.page));
|
|
3189
|
+
}
|
|
2935
3190
|
if (params?.perPage !== void 0) {
|
|
2936
3191
|
searchParams.set("perPage", String(params.perPage));
|
|
2937
3192
|
}
|
|
2938
|
-
if (params?.
|
|
2939
|
-
searchParams.set("
|
|
3193
|
+
if (params?.limit !== void 0) {
|
|
3194
|
+
searchParams.set("limit", String(params.limit));
|
|
3195
|
+
}
|
|
3196
|
+
if (params?.offset !== void 0) {
|
|
3197
|
+
searchParams.set("offset", String(params.offset));
|
|
2940
3198
|
}
|
|
2941
3199
|
const queryString = searchParams.toString();
|
|
2942
3200
|
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
|
|
@@ -3136,6 +3394,52 @@ var MastraClient = class extends BaseResource {
|
|
|
3136
3394
|
score(params) {
|
|
3137
3395
|
return this.observability.score(params);
|
|
3138
3396
|
}
|
|
3397
|
+
// ============================================================================
|
|
3398
|
+
// Stored Agents
|
|
3399
|
+
// ============================================================================
|
|
3400
|
+
/**
|
|
3401
|
+
* Lists all stored agents with optional pagination
|
|
3402
|
+
* @param params - Optional pagination and ordering parameters
|
|
3403
|
+
* @returns Promise containing paginated list of stored agents
|
|
3404
|
+
*/
|
|
3405
|
+
listStoredAgents(params) {
|
|
3406
|
+
const searchParams = new URLSearchParams();
|
|
3407
|
+
if (params?.page !== void 0) {
|
|
3408
|
+
searchParams.set("page", String(params.page));
|
|
3409
|
+
}
|
|
3410
|
+
if (params?.perPage !== void 0) {
|
|
3411
|
+
searchParams.set("perPage", String(params.perPage));
|
|
3412
|
+
}
|
|
3413
|
+
if (params?.orderBy) {
|
|
3414
|
+
if (params.orderBy.field) {
|
|
3415
|
+
searchParams.set("orderBy[field]", params.orderBy.field);
|
|
3416
|
+
}
|
|
3417
|
+
if (params.orderBy.direction) {
|
|
3418
|
+
searchParams.set("orderBy[direction]", params.orderBy.direction);
|
|
3419
|
+
}
|
|
3420
|
+
}
|
|
3421
|
+
const queryString = searchParams.toString();
|
|
3422
|
+
return this.request(`/api/stored/agents${queryString ? `?${queryString}` : ""}`);
|
|
3423
|
+
}
|
|
3424
|
+
/**
|
|
3425
|
+
* Creates a new stored agent
|
|
3426
|
+
* @param params - Agent configuration including id, name, instructions, model, etc.
|
|
3427
|
+
* @returns Promise containing the created stored agent
|
|
3428
|
+
*/
|
|
3429
|
+
createStoredAgent(params) {
|
|
3430
|
+
return this.request("/api/stored/agents", {
|
|
3431
|
+
method: "POST",
|
|
3432
|
+
body: params
|
|
3433
|
+
});
|
|
3434
|
+
}
|
|
3435
|
+
/**
|
|
3436
|
+
* Gets a stored agent instance by ID for further operations (details, update, delete)
|
|
3437
|
+
* @param storedAgentId - ID of the stored agent to retrieve
|
|
3438
|
+
* @returns StoredAgent instance
|
|
3439
|
+
*/
|
|
3440
|
+
getStoredAgent(storedAgentId) {
|
|
3441
|
+
return new StoredAgent(this.options, storedAgentId);
|
|
3442
|
+
}
|
|
3139
3443
|
};
|
|
3140
3444
|
|
|
3141
3445
|
// src/tools.ts
|