@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.cjs
CHANGED
|
@@ -5,12 +5,7 @@ var uuid = require('@lukeed/uuid');
|
|
|
5
5
|
var error = require('@mastra/core/error');
|
|
6
6
|
var requestContext = require('@mastra/core/request-context');
|
|
7
7
|
var isVercelTool = require('@mastra/core/tools/is-vercel-tool');
|
|
8
|
-
var
|
|
9
|
-
var originalZodToJsonSchema = require('zod-to-json-schema');
|
|
10
|
-
|
|
11
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
-
|
|
13
|
-
var originalZodToJsonSchema__default = /*#__PURE__*/_interopDefault(originalZodToJsonSchema);
|
|
8
|
+
var zodToJson = require('@mastra/schema-compat/zod-to-json');
|
|
14
9
|
|
|
15
10
|
// src/resources/agent.ts
|
|
16
11
|
function parseClientRequestContext(requestContext$1) {
|
|
@@ -43,11 +38,7 @@ function zodToJsonSchema(zodSchema) {
|
|
|
43
38
|
if (!isZodType(zodSchema)) {
|
|
44
39
|
return zodSchema;
|
|
45
40
|
}
|
|
46
|
-
|
|
47
|
-
const fn = "toJSONSchema";
|
|
48
|
-
return zod.z[fn].call(zod.z, zodSchema);
|
|
49
|
-
}
|
|
50
|
-
return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "relative" });
|
|
41
|
+
return zodToJson.zodToJsonSchema(zodSchema);
|
|
51
42
|
}
|
|
52
43
|
|
|
53
44
|
// src/utils/process-client-tools.ts
|
|
@@ -98,7 +89,6 @@ async function sharedProcessMastraStream({
|
|
|
98
89
|
if (line.startsWith("data: ")) {
|
|
99
90
|
const data = line.slice(6);
|
|
100
91
|
if (data === "[DONE]") {
|
|
101
|
-
console.info("\u{1F3C1} Stream finished");
|
|
102
92
|
return;
|
|
103
93
|
}
|
|
104
94
|
let json;
|
|
@@ -151,11 +141,20 @@ var BaseResource = class {
|
|
|
151
141
|
*/
|
|
152
142
|
async request(path, options = {}) {
|
|
153
143
|
let lastError = null;
|
|
154
|
-
const {
|
|
144
|
+
const {
|
|
145
|
+
baseUrl,
|
|
146
|
+
retries = 3,
|
|
147
|
+
backoffMs = 100,
|
|
148
|
+
maxBackoffMs = 1e3,
|
|
149
|
+
headers = {},
|
|
150
|
+
credentials,
|
|
151
|
+
fetch: customFetch
|
|
152
|
+
} = this.options;
|
|
153
|
+
const fetchFn = customFetch || fetch;
|
|
155
154
|
let delay = backoffMs;
|
|
156
155
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
157
156
|
try {
|
|
158
|
-
const response = await
|
|
157
|
+
const response = await fetchFn(`${baseUrl.replace(/\/$/, "")}${path}`, {
|
|
159
158
|
...options,
|
|
160
159
|
headers: {
|
|
161
160
|
...options.body && !(options.body instanceof FormData) && (options.method === "POST" || options.method === "PUT") ? { "content-type": "application/json" } : {},
|
|
@@ -214,14 +213,14 @@ async function executeToolCallAndRespond({
|
|
|
214
213
|
return response;
|
|
215
214
|
}
|
|
216
215
|
for (const toolCall of toolCalls) {
|
|
217
|
-
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
216
|
+
const clientTool = params.clientTools?.[toolCall.payload.toolName];
|
|
218
217
|
if (clientTool && clientTool.execute) {
|
|
219
|
-
const result = await clientTool.execute(toolCall?.args, {
|
|
218
|
+
const result = await clientTool.execute(toolCall?.payload.args, {
|
|
220
219
|
requestContext,
|
|
221
220
|
tracingContext: { currentSpan: void 0 },
|
|
222
221
|
agent: {
|
|
223
222
|
messages: response.messages,
|
|
224
|
-
toolCallId: toolCall?.toolCallId,
|
|
223
|
+
toolCallId: toolCall?.payload.toolCallId,
|
|
225
224
|
suspend: async () => {
|
|
226
225
|
},
|
|
227
226
|
threadId,
|
|
@@ -235,8 +234,8 @@ async function executeToolCallAndRespond({
|
|
|
235
234
|
content: [
|
|
236
235
|
{
|
|
237
236
|
type: "tool-result",
|
|
238
|
-
toolCallId: toolCall.toolCallId,
|
|
239
|
-
toolName: toolCall.toolName,
|
|
237
|
+
toolCallId: toolCall.payload.toolCallId,
|
|
238
|
+
toolName: toolCall.payload.toolName,
|
|
240
239
|
result
|
|
241
240
|
}
|
|
242
241
|
]
|
|
@@ -249,6 +248,7 @@ async function executeToolCallAndRespond({
|
|
|
249
248
|
}
|
|
250
249
|
}
|
|
251
250
|
}
|
|
251
|
+
return response;
|
|
252
252
|
}
|
|
253
253
|
var AgentVoice = class extends BaseResource {
|
|
254
254
|
constructor(options, agentId) {
|
|
@@ -981,7 +981,7 @@ var Agent = class extends BaseResource {
|
|
|
981
981
|
});
|
|
982
982
|
onFinish?.({ message, finishReason, usage });
|
|
983
983
|
}
|
|
984
|
-
async processStreamResponse(processedParams,
|
|
984
|
+
async processStreamResponse(processedParams, controller, route = "stream") {
|
|
985
985
|
const response = await this.request(`/api/agents/${this.agentId}/${route}`, {
|
|
986
986
|
method: "POST",
|
|
987
987
|
body: processedParams,
|
|
@@ -993,29 +993,30 @@ var Agent = class extends BaseResource {
|
|
|
993
993
|
try {
|
|
994
994
|
let toolCalls = [];
|
|
995
995
|
let messages = [];
|
|
996
|
-
const [
|
|
997
|
-
|
|
996
|
+
const [streamForController, streamForProcessing] = response.body.tee();
|
|
997
|
+
const pipePromise = streamForController.pipeTo(
|
|
998
998
|
new WritableStream({
|
|
999
999
|
async write(chunk) {
|
|
1000
|
-
let writer;
|
|
1001
1000
|
try {
|
|
1002
|
-
writer = writable.getWriter();
|
|
1003
1001
|
const text = new TextDecoder().decode(chunk);
|
|
1004
1002
|
const lines = text.split("\n\n");
|
|
1005
|
-
const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1003
|
+
const readableLines = lines.filter((line) => line.trim() !== "[DONE]" && line.trim() !== "data: [DONE]").join("\n\n");
|
|
1004
|
+
if (readableLines) {
|
|
1005
|
+
const encoded = new TextEncoder().encode(readableLines);
|
|
1006
|
+
controller.enqueue(encoded);
|
|
1007
|
+
}
|
|
1008
|
+
} catch (error) {
|
|
1009
|
+
console.error("Error enqueueing to controller:", error);
|
|
1010
|
+
controller.enqueue(chunk);
|
|
1011
1011
|
}
|
|
1012
1012
|
}
|
|
1013
|
-
})
|
|
1014
|
-
{
|
|
1015
|
-
preventClose: true
|
|
1016
|
-
}
|
|
1013
|
+
})
|
|
1017
1014
|
).catch((error) => {
|
|
1018
|
-
console.error("Error piping to
|
|
1015
|
+
console.error("Error piping to controller:", error);
|
|
1016
|
+
try {
|
|
1017
|
+
controller.close();
|
|
1018
|
+
} catch {
|
|
1019
|
+
}
|
|
1019
1020
|
});
|
|
1020
1021
|
this.processChatResponse_vNext({
|
|
1021
1022
|
stream: streamForProcessing,
|
|
@@ -1071,31 +1072,36 @@ var Agent = class extends BaseResource {
|
|
|
1071
1072
|
toolInvocation.result = result;
|
|
1072
1073
|
}
|
|
1073
1074
|
const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
})
|
|
1075
|
+
try {
|
|
1076
|
+
await this.processStreamResponse(
|
|
1077
|
+
{
|
|
1078
|
+
...processedParams,
|
|
1079
|
+
messages: updatedMessages
|
|
1080
|
+
},
|
|
1081
|
+
controller
|
|
1082
|
+
);
|
|
1083
|
+
} catch (error) {
|
|
1084
|
+
console.error("Error processing recursive stream response:", error);
|
|
1085
|
+
}
|
|
1083
1086
|
}
|
|
1084
1087
|
}
|
|
1085
1088
|
if (!shouldExecuteClientTool) {
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
}, 0);
|
|
1089
|
+
await pipePromise;
|
|
1090
|
+
controller.close();
|
|
1089
1091
|
}
|
|
1090
1092
|
} else {
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
}, 0);
|
|
1093
|
+
await pipePromise;
|
|
1094
|
+
controller.close();
|
|
1094
1095
|
}
|
|
1095
1096
|
},
|
|
1096
1097
|
lastMessage: void 0
|
|
1097
|
-
}).catch((error) => {
|
|
1098
|
+
}).catch(async (error) => {
|
|
1098
1099
|
console.error("Error processing stream response:", error);
|
|
1100
|
+
try {
|
|
1101
|
+
await pipePromise;
|
|
1102
|
+
controller.close();
|
|
1103
|
+
} catch {
|
|
1104
|
+
}
|
|
1099
1105
|
});
|
|
1100
1106
|
} catch (error) {
|
|
1101
1107
|
console.error("Error processing stream response:", error);
|
|
@@ -1145,8 +1151,13 @@ var Agent = class extends BaseResource {
|
|
|
1145
1151
|
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
1146
1152
|
} : void 0
|
|
1147
1153
|
};
|
|
1148
|
-
|
|
1149
|
-
const
|
|
1154
|
+
let readableController;
|
|
1155
|
+
const readable = new ReadableStream({
|
|
1156
|
+
start(controller) {
|
|
1157
|
+
readableController = controller;
|
|
1158
|
+
}
|
|
1159
|
+
});
|
|
1160
|
+
const response = await this.processStreamResponse(processedParams, readableController);
|
|
1150
1161
|
const streamResponse = new Response(readable, {
|
|
1151
1162
|
status: response.status,
|
|
1152
1163
|
statusText: response.statusText,
|
|
@@ -1163,8 +1174,13 @@ var Agent = class extends BaseResource {
|
|
|
1163
1174
|
return streamResponse;
|
|
1164
1175
|
}
|
|
1165
1176
|
async approveToolCall(params) {
|
|
1166
|
-
|
|
1167
|
-
const
|
|
1177
|
+
let readableController;
|
|
1178
|
+
const readable = new ReadableStream({
|
|
1179
|
+
start(controller) {
|
|
1180
|
+
readableController = controller;
|
|
1181
|
+
}
|
|
1182
|
+
});
|
|
1183
|
+
const response = await this.processStreamResponse(params, readableController, "approve-tool-call");
|
|
1168
1184
|
const streamResponse = new Response(readable, {
|
|
1169
1185
|
status: response.status,
|
|
1170
1186
|
statusText: response.statusText,
|
|
@@ -1181,8 +1197,13 @@ var Agent = class extends BaseResource {
|
|
|
1181
1197
|
return streamResponse;
|
|
1182
1198
|
}
|
|
1183
1199
|
async declineToolCall(params) {
|
|
1184
|
-
|
|
1185
|
-
const
|
|
1200
|
+
let readableController;
|
|
1201
|
+
const readable = new ReadableStream({
|
|
1202
|
+
start(controller) {
|
|
1203
|
+
readableController = controller;
|
|
1204
|
+
}
|
|
1205
|
+
});
|
|
1206
|
+
const response = await this.processStreamResponse(params, readableController, "decline-tool-call");
|
|
1186
1207
|
const streamResponse = new Response(readable, {
|
|
1187
1208
|
status: response.status,
|
|
1188
1209
|
statusText: response.statusText,
|
|
@@ -1437,7 +1458,7 @@ var MemoryThread = class extends BaseResource {
|
|
|
1437
1458
|
if (include) queryParams.include = JSON.stringify(include);
|
|
1438
1459
|
const query = new URLSearchParams(queryParams);
|
|
1439
1460
|
const queryString = query.toString();
|
|
1440
|
-
const url = `/api/memory/threads/${this.threadId}/messages${queryString ?
|
|
1461
|
+
const url = `/api/memory/threads/${this.threadId}/messages?agentId=${this.agentId}${queryString ? `&${queryString}` : ""}${requestContextQueryString(requestContext, "&")}`;
|
|
1441
1462
|
return this.request(url);
|
|
1442
1463
|
}
|
|
1443
1464
|
/**
|
|
@@ -1596,15 +1617,21 @@ var Workflow = class extends BaseResource {
|
|
|
1596
1617
|
if (params?.toDate) {
|
|
1597
1618
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
1598
1619
|
}
|
|
1599
|
-
if (params?.
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1620
|
+
if (params?.page !== void 0) {
|
|
1621
|
+
searchParams.set("page", String(params.page));
|
|
1622
|
+
}
|
|
1623
|
+
if (params?.perPage !== void 0) {
|
|
1624
|
+
searchParams.set("perPage", String(params.perPage));
|
|
1625
|
+
}
|
|
1626
|
+
if (params?.limit !== null && params?.limit !== void 0) {
|
|
1627
|
+
if (params.limit === false) {
|
|
1628
|
+
searchParams.set("limit", "false");
|
|
1629
|
+
} else if (typeof params.limit === "number" && params.limit > 0 && Number.isInteger(params.limit)) {
|
|
1630
|
+
searchParams.set("limit", String(params.limit));
|
|
1604
1631
|
}
|
|
1605
1632
|
}
|
|
1606
|
-
if (params?.
|
|
1607
|
-
searchParams.set("
|
|
1633
|
+
if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
|
|
1634
|
+
searchParams.set("offset", String(params.offset));
|
|
1608
1635
|
}
|
|
1609
1636
|
if (params?.resourceId) {
|
|
1610
1637
|
searchParams.set("resourceId", params.resourceId);
|
|
@@ -1627,6 +1654,16 @@ var Workflow = class extends BaseResource {
|
|
|
1627
1654
|
runById(runId, requestContext) {
|
|
1628
1655
|
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${requestContextQueryString(requestContext)}`);
|
|
1629
1656
|
}
|
|
1657
|
+
/**
|
|
1658
|
+
* Deletes a specific workflow run by its ID
|
|
1659
|
+
* @param runId - The ID of the workflow run to delete
|
|
1660
|
+
* @returns Promise containing a success message
|
|
1661
|
+
*/
|
|
1662
|
+
deleteRunById(runId) {
|
|
1663
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`, {
|
|
1664
|
+
method: "DELETE"
|
|
1665
|
+
});
|
|
1666
|
+
}
|
|
1630
1667
|
/**
|
|
1631
1668
|
* Retrieves the execution result for a specific workflow run by its ID
|
|
1632
1669
|
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
@@ -1671,6 +1708,7 @@ var Workflow = class extends BaseResource {
|
|
|
1671
1708
|
return this.start({
|
|
1672
1709
|
runId,
|
|
1673
1710
|
inputData: p.inputData,
|
|
1711
|
+
initialState: p.initialState,
|
|
1674
1712
|
requestContext: p.requestContext,
|
|
1675
1713
|
tracingOptions: p.tracingOptions
|
|
1676
1714
|
});
|
|
@@ -1679,12 +1717,18 @@ var Workflow = class extends BaseResource {
|
|
|
1679
1717
|
return this.startAsync({
|
|
1680
1718
|
runId,
|
|
1681
1719
|
inputData: p.inputData,
|
|
1720
|
+
initialState: p.initialState,
|
|
1682
1721
|
requestContext: p.requestContext,
|
|
1683
1722
|
tracingOptions: p.tracingOptions
|
|
1684
1723
|
});
|
|
1685
1724
|
},
|
|
1686
1725
|
stream: async (p) => {
|
|
1687
|
-
return this.stream({
|
|
1726
|
+
return this.stream({
|
|
1727
|
+
runId,
|
|
1728
|
+
inputData: p.inputData,
|
|
1729
|
+
initialState: p.initialState,
|
|
1730
|
+
requestContext: p.requestContext
|
|
1731
|
+
});
|
|
1688
1732
|
},
|
|
1689
1733
|
resume: async (p) => {
|
|
1690
1734
|
return this.resume({
|
|
@@ -1716,14 +1760,19 @@ var Workflow = class extends BaseResource {
|
|
|
1716
1760
|
}
|
|
1717
1761
|
/**
|
|
1718
1762
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1719
|
-
* @param params - Object containing the runId, inputData and requestContext
|
|
1763
|
+
* @param params - Object containing the runId, inputData, initialState and requestContext
|
|
1720
1764
|
* @returns Promise containing success message
|
|
1721
1765
|
*/
|
|
1722
1766
|
start(params) {
|
|
1723
1767
|
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1724
1768
|
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1725
1769
|
method: "POST",
|
|
1726
|
-
body: {
|
|
1770
|
+
body: {
|
|
1771
|
+
inputData: params?.inputData,
|
|
1772
|
+
initialState: params?.initialState,
|
|
1773
|
+
requestContext,
|
|
1774
|
+
tracingOptions: params.tracingOptions
|
|
1775
|
+
}
|
|
1727
1776
|
});
|
|
1728
1777
|
}
|
|
1729
1778
|
/**
|
|
@@ -1751,7 +1800,7 @@ var Workflow = class extends BaseResource {
|
|
|
1751
1800
|
}
|
|
1752
1801
|
/**
|
|
1753
1802
|
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
1754
|
-
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1803
|
+
* @param params - Object containing the optional runId, inputData, initialState and requestContext
|
|
1755
1804
|
* @returns Promise containing the workflow execution results
|
|
1756
1805
|
*/
|
|
1757
1806
|
startAsync(params) {
|
|
@@ -1762,12 +1811,17 @@ var Workflow = class extends BaseResource {
|
|
|
1762
1811
|
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1763
1812
|
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1764
1813
|
method: "POST",
|
|
1765
|
-
body: {
|
|
1814
|
+
body: {
|
|
1815
|
+
inputData: params.inputData,
|
|
1816
|
+
initialState: params.initialState,
|
|
1817
|
+
requestContext,
|
|
1818
|
+
tracingOptions: params.tracingOptions
|
|
1819
|
+
}
|
|
1766
1820
|
});
|
|
1767
1821
|
}
|
|
1768
1822
|
/**
|
|
1769
1823
|
* Starts a workflow run and returns a stream
|
|
1770
|
-
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1824
|
+
* @param params - Object containing the optional runId, inputData, initialState and requestContext
|
|
1771
1825
|
* @returns Promise containing the workflow execution results
|
|
1772
1826
|
*/
|
|
1773
1827
|
async stream(params) {
|
|
@@ -1780,7 +1834,12 @@ var Workflow = class extends BaseResource {
|
|
|
1780
1834
|
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1781
1835
|
{
|
|
1782
1836
|
method: "POST",
|
|
1783
|
-
body: {
|
|
1837
|
+
body: {
|
|
1838
|
+
inputData: params.inputData,
|
|
1839
|
+
initialState: params.initialState,
|
|
1840
|
+
requestContext,
|
|
1841
|
+
tracingOptions: params.tracingOptions
|
|
1842
|
+
},
|
|
1784
1843
|
stream: true
|
|
1785
1844
|
}
|
|
1786
1845
|
);
|
|
@@ -1865,7 +1924,7 @@ var Workflow = class extends BaseResource {
|
|
|
1865
1924
|
}
|
|
1866
1925
|
/**
|
|
1867
1926
|
* Starts a workflow run and returns a stream
|
|
1868
|
-
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1927
|
+
* @param params - Object containing the optional runId, inputData, initialState and requestContext
|
|
1869
1928
|
* @returns Promise containing the workflow execution results
|
|
1870
1929
|
*/
|
|
1871
1930
|
async streamVNext(params) {
|
|
@@ -1880,6 +1939,7 @@ var Workflow = class extends BaseResource {
|
|
|
1880
1939
|
method: "POST",
|
|
1881
1940
|
body: {
|
|
1882
1941
|
inputData: params.inputData,
|
|
1942
|
+
initialState: params.initialState,
|
|
1883
1943
|
requestContext,
|
|
1884
1944
|
closeOnSuspend: params.closeOnSuspend,
|
|
1885
1945
|
tracingOptions: params.tracingOptions
|
|
@@ -2060,6 +2120,142 @@ var Workflow = class extends BaseResource {
|
|
|
2060
2120
|
}
|
|
2061
2121
|
});
|
|
2062
2122
|
}
|
|
2123
|
+
/**
|
|
2124
|
+
* Restarts an active workflow run synchronously without waiting for the workflow to complete
|
|
2125
|
+
* @param params - Object containing the runId and requestContext
|
|
2126
|
+
* @returns Promise containing success message
|
|
2127
|
+
*/
|
|
2128
|
+
restart(params) {
|
|
2129
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2130
|
+
return this.request(`/api/workflows/${this.workflowId}/restart?runId=${params.runId}`, {
|
|
2131
|
+
method: "POST",
|
|
2132
|
+
body: {
|
|
2133
|
+
requestContext,
|
|
2134
|
+
tracingOptions: params.tracingOptions
|
|
2135
|
+
}
|
|
2136
|
+
});
|
|
2137
|
+
}
|
|
2138
|
+
/**
|
|
2139
|
+
* Restarts an active workflow run asynchronously
|
|
2140
|
+
* @param params - Object containing the runId and requestContext
|
|
2141
|
+
* @returns Promise containing the workflow restart results
|
|
2142
|
+
*/
|
|
2143
|
+
restartAsync(params) {
|
|
2144
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2145
|
+
return this.request(`/api/workflows/${this.workflowId}/restart-async?runId=${params.runId}`, {
|
|
2146
|
+
method: "POST",
|
|
2147
|
+
body: {
|
|
2148
|
+
requestContext,
|
|
2149
|
+
tracingOptions: params.tracingOptions
|
|
2150
|
+
}
|
|
2151
|
+
});
|
|
2152
|
+
}
|
|
2153
|
+
/**
|
|
2154
|
+
* Restart all active workflow runs synchronously without waiting for the workflow to complete
|
|
2155
|
+
* @returns Promise containing success message
|
|
2156
|
+
*/
|
|
2157
|
+
restartAllActiveWorkflowRuns() {
|
|
2158
|
+
return this.request(`/api/workflows/${this.workflowId}/restart-all-active-workflow-runs`, {
|
|
2159
|
+
method: "POST"
|
|
2160
|
+
});
|
|
2161
|
+
}
|
|
2162
|
+
/**
|
|
2163
|
+
* Restart all active workflow runs asynchronously
|
|
2164
|
+
* @returns Promise containing success message
|
|
2165
|
+
*/
|
|
2166
|
+
restartAllActiveWorkflowRunsAsync() {
|
|
2167
|
+
return this.request(`/api/workflows/${this.workflowId}/restart-all-active-workflow-runs-async`, {
|
|
2168
|
+
method: "POST"
|
|
2169
|
+
});
|
|
2170
|
+
}
|
|
2171
|
+
/**
|
|
2172
|
+
* Time travels a workflow run synchronously without waiting for the workflow to complete
|
|
2173
|
+
* @param params - Object containing the runId, step, inputData, resumeData, initialState, context, nestedStepsContext, requestContext and tracingOptions
|
|
2174
|
+
* @returns Promise containing success message
|
|
2175
|
+
*/
|
|
2176
|
+
timeTravel({
|
|
2177
|
+
runId,
|
|
2178
|
+
requestContext: paramsRequestContext,
|
|
2179
|
+
...params
|
|
2180
|
+
}) {
|
|
2181
|
+
const requestContext = parseClientRequestContext(paramsRequestContext);
|
|
2182
|
+
return this.request(`/api/workflows/${this.workflowId}/time-travel?runId=${runId}`, {
|
|
2183
|
+
method: "POST",
|
|
2184
|
+
body: {
|
|
2185
|
+
...params,
|
|
2186
|
+
requestContext
|
|
2187
|
+
}
|
|
2188
|
+
});
|
|
2189
|
+
}
|
|
2190
|
+
/**
|
|
2191
|
+
* Time travels a workflow run asynchronously
|
|
2192
|
+
* @param params - Object containing the runId, step, inputData, resumeData, initialState, context, nestedStepsContext, requestContext and tracingOptions
|
|
2193
|
+
* @returns Promise containing the workflow time travel results
|
|
2194
|
+
*/
|
|
2195
|
+
timeTravelAsync({
|
|
2196
|
+
runId,
|
|
2197
|
+
requestContext: paramsRequestContext,
|
|
2198
|
+
...params
|
|
2199
|
+
}) {
|
|
2200
|
+
const requestContext = parseClientRequestContext(paramsRequestContext);
|
|
2201
|
+
return this.request(`/api/workflows/${this.workflowId}/time-travel-async?runId=${runId}`, {
|
|
2202
|
+
method: "POST",
|
|
2203
|
+
body: {
|
|
2204
|
+
...params,
|
|
2205
|
+
requestContext
|
|
2206
|
+
}
|
|
2207
|
+
});
|
|
2208
|
+
}
|
|
2209
|
+
/**
|
|
2210
|
+
* Time travels a workflow run and returns a stream
|
|
2211
|
+
* @param params - Object containing the runId, step, inputData, resumeData, initialState, context, nestedStepsContext, requestContext and tracingOptions
|
|
2212
|
+
* @returns Promise containing the workflow execution results
|
|
2213
|
+
*/
|
|
2214
|
+
async timeTravelStream({ runId, requestContext: paramsRequestContext, ...params }) {
|
|
2215
|
+
const requestContext = parseClientRequestContext(paramsRequestContext);
|
|
2216
|
+
const response = await this.request(
|
|
2217
|
+
`/api/workflows/${this.workflowId}/time-travel-stream?runId=${runId}`,
|
|
2218
|
+
{
|
|
2219
|
+
method: "POST",
|
|
2220
|
+
body: {
|
|
2221
|
+
...params,
|
|
2222
|
+
requestContext
|
|
2223
|
+
},
|
|
2224
|
+
stream: true
|
|
2225
|
+
}
|
|
2226
|
+
);
|
|
2227
|
+
if (!response.ok) {
|
|
2228
|
+
throw new Error(`Failed to time travel workflow: ${response.statusText}`);
|
|
2229
|
+
}
|
|
2230
|
+
if (!response.body) {
|
|
2231
|
+
throw new Error("Response body is null");
|
|
2232
|
+
}
|
|
2233
|
+
let failedChunk = void 0;
|
|
2234
|
+
const transformStream = new TransformStream({
|
|
2235
|
+
start() {
|
|
2236
|
+
},
|
|
2237
|
+
async transform(chunk, controller) {
|
|
2238
|
+
try {
|
|
2239
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2240
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
2241
|
+
for (const chunk2 of chunks) {
|
|
2242
|
+
if (chunk2) {
|
|
2243
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2244
|
+
try {
|
|
2245
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2246
|
+
controller.enqueue(parsedChunk);
|
|
2247
|
+
failedChunk = void 0;
|
|
2248
|
+
} catch {
|
|
2249
|
+
failedChunk = newChunk;
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
2253
|
+
} catch {
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
});
|
|
2257
|
+
return response.body.pipeThrough(transformStream);
|
|
2258
|
+
}
|
|
2063
2259
|
};
|
|
2064
2260
|
|
|
2065
2261
|
// src/resources/a2a.ts
|
|
@@ -2102,7 +2298,8 @@ var A2A = class extends BaseResource {
|
|
|
2102
2298
|
body: {
|
|
2103
2299
|
method: "message/stream",
|
|
2104
2300
|
params
|
|
2105
|
-
}
|
|
2301
|
+
},
|
|
2302
|
+
stream: true
|
|
2106
2303
|
});
|
|
2107
2304
|
return response;
|
|
2108
2305
|
}
|
|
@@ -2533,6 +2730,16 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2533
2730
|
if (params?.page !== void 0) {
|
|
2534
2731
|
searchParams.set("page", String(params.page));
|
|
2535
2732
|
}
|
|
2733
|
+
if (params?.limit !== null && params?.limit !== void 0) {
|
|
2734
|
+
if (params.limit === false) {
|
|
2735
|
+
searchParams.set("limit", "false");
|
|
2736
|
+
} else if (typeof params.limit === "number" && params.limit > 0 && Number.isInteger(params.limit)) {
|
|
2737
|
+
searchParams.set("limit", String(params.limit));
|
|
2738
|
+
}
|
|
2739
|
+
}
|
|
2740
|
+
if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
|
|
2741
|
+
searchParams.set("offset", String(params.offset));
|
|
2742
|
+
}
|
|
2536
2743
|
if (params?.resourceId) {
|
|
2537
2744
|
searchParams.set("resourceId", params.resourceId);
|
|
2538
2745
|
}
|
|
@@ -2639,6 +2846,41 @@ var Observability = class extends BaseResource {
|
|
|
2639
2846
|
}
|
|
2640
2847
|
};
|
|
2641
2848
|
|
|
2849
|
+
// src/resources/stored-agent.ts
|
|
2850
|
+
var StoredAgent = class extends BaseResource {
|
|
2851
|
+
constructor(options, storedAgentId) {
|
|
2852
|
+
super(options);
|
|
2853
|
+
this.storedAgentId = storedAgentId;
|
|
2854
|
+
}
|
|
2855
|
+
/**
|
|
2856
|
+
* Retrieves details about the stored agent
|
|
2857
|
+
* @returns Promise containing stored agent details
|
|
2858
|
+
*/
|
|
2859
|
+
details() {
|
|
2860
|
+
return this.request(`/api/stored/agents/${encodeURIComponent(this.storedAgentId)}`);
|
|
2861
|
+
}
|
|
2862
|
+
/**
|
|
2863
|
+
* Updates the stored agent with the provided fields
|
|
2864
|
+
* @param params - Fields to update
|
|
2865
|
+
* @returns Promise containing the updated stored agent
|
|
2866
|
+
*/
|
|
2867
|
+
update(params) {
|
|
2868
|
+
return this.request(`/api/stored/agents/${encodeURIComponent(this.storedAgentId)}`, {
|
|
2869
|
+
method: "PATCH",
|
|
2870
|
+
body: params
|
|
2871
|
+
});
|
|
2872
|
+
}
|
|
2873
|
+
/**
|
|
2874
|
+
* Deletes the stored agent
|
|
2875
|
+
* @returns Promise containing deletion confirmation
|
|
2876
|
+
*/
|
|
2877
|
+
delete() {
|
|
2878
|
+
return this.request(`/api/stored/agents/${encodeURIComponent(this.storedAgentId)}`, {
|
|
2879
|
+
method: "DELETE"
|
|
2880
|
+
});
|
|
2881
|
+
}
|
|
2882
|
+
};
|
|
2883
|
+
|
|
2642
2884
|
// src/client.ts
|
|
2643
2885
|
var MastraClient = class extends BaseResource {
|
|
2644
2886
|
observability;
|
|
@@ -2651,12 +2893,15 @@ var MastraClient = class extends BaseResource {
|
|
|
2651
2893
|
* @param requestContext - Optional request context to pass as query parameter
|
|
2652
2894
|
* @returns Promise containing map of agent IDs to agent details
|
|
2653
2895
|
*/
|
|
2654
|
-
listAgents(requestContext) {
|
|
2896
|
+
listAgents(requestContext, partial) {
|
|
2655
2897
|
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2656
2898
|
const searchParams = new URLSearchParams();
|
|
2657
2899
|
if (requestContextParam) {
|
|
2658
2900
|
searchParams.set("requestContext", requestContextParam);
|
|
2659
2901
|
}
|
|
2902
|
+
if (partial) {
|
|
2903
|
+
searchParams.set("partial", "true");
|
|
2904
|
+
}
|
|
2660
2905
|
const queryString = searchParams.toString();
|
|
2661
2906
|
return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
|
|
2662
2907
|
}
|
|
@@ -2798,12 +3043,15 @@ var MastraClient = class extends BaseResource {
|
|
|
2798
3043
|
* @param requestContext - Optional request context to pass as query parameter
|
|
2799
3044
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
2800
3045
|
*/
|
|
2801
|
-
listWorkflows(requestContext) {
|
|
3046
|
+
listWorkflows(requestContext, partial) {
|
|
2802
3047
|
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2803
3048
|
const searchParams = new URLSearchParams();
|
|
2804
3049
|
if (requestContextParam) {
|
|
2805
3050
|
searchParams.set("requestContext", requestContextParam);
|
|
2806
3051
|
}
|
|
3052
|
+
if (partial) {
|
|
3053
|
+
searchParams.set("partial", "true");
|
|
3054
|
+
}
|
|
2807
3055
|
const queryString = searchParams.toString();
|
|
2808
3056
|
return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
|
|
2809
3057
|
}
|
|
@@ -2933,16 +3181,22 @@ var MastraClient = class extends BaseResource {
|
|
|
2933
3181
|
}
|
|
2934
3182
|
/**
|
|
2935
3183
|
* Retrieves a list of available MCP servers.
|
|
2936
|
-
* @param params - Optional parameters for pagination (perPage,
|
|
3184
|
+
* @param params - Optional parameters for pagination (page, perPage, or deprecated offset, limit).
|
|
2937
3185
|
* @returns Promise containing the list of MCP servers and pagination info.
|
|
2938
3186
|
*/
|
|
2939
3187
|
getMcpServers(params) {
|
|
2940
3188
|
const searchParams = new URLSearchParams();
|
|
3189
|
+
if (params?.page !== void 0) {
|
|
3190
|
+
searchParams.set("page", String(params.page));
|
|
3191
|
+
}
|
|
2941
3192
|
if (params?.perPage !== void 0) {
|
|
2942
3193
|
searchParams.set("perPage", String(params.perPage));
|
|
2943
3194
|
}
|
|
2944
|
-
if (params?.
|
|
2945
|
-
searchParams.set("
|
|
3195
|
+
if (params?.limit !== void 0) {
|
|
3196
|
+
searchParams.set("limit", String(params.limit));
|
|
3197
|
+
}
|
|
3198
|
+
if (params?.offset !== void 0) {
|
|
3199
|
+
searchParams.set("offset", String(params.offset));
|
|
2946
3200
|
}
|
|
2947
3201
|
const queryString = searchParams.toString();
|
|
2948
3202
|
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
|
|
@@ -3142,6 +3396,52 @@ var MastraClient = class extends BaseResource {
|
|
|
3142
3396
|
score(params) {
|
|
3143
3397
|
return this.observability.score(params);
|
|
3144
3398
|
}
|
|
3399
|
+
// ============================================================================
|
|
3400
|
+
// Stored Agents
|
|
3401
|
+
// ============================================================================
|
|
3402
|
+
/**
|
|
3403
|
+
* Lists all stored agents with optional pagination
|
|
3404
|
+
* @param params - Optional pagination and ordering parameters
|
|
3405
|
+
* @returns Promise containing paginated list of stored agents
|
|
3406
|
+
*/
|
|
3407
|
+
listStoredAgents(params) {
|
|
3408
|
+
const searchParams = new URLSearchParams();
|
|
3409
|
+
if (params?.page !== void 0) {
|
|
3410
|
+
searchParams.set("page", String(params.page));
|
|
3411
|
+
}
|
|
3412
|
+
if (params?.perPage !== void 0) {
|
|
3413
|
+
searchParams.set("perPage", String(params.perPage));
|
|
3414
|
+
}
|
|
3415
|
+
if (params?.orderBy) {
|
|
3416
|
+
if (params.orderBy.field) {
|
|
3417
|
+
searchParams.set("orderBy[field]", params.orderBy.field);
|
|
3418
|
+
}
|
|
3419
|
+
if (params.orderBy.direction) {
|
|
3420
|
+
searchParams.set("orderBy[direction]", params.orderBy.direction);
|
|
3421
|
+
}
|
|
3422
|
+
}
|
|
3423
|
+
const queryString = searchParams.toString();
|
|
3424
|
+
return this.request(`/api/stored/agents${queryString ? `?${queryString}` : ""}`);
|
|
3425
|
+
}
|
|
3426
|
+
/**
|
|
3427
|
+
* Creates a new stored agent
|
|
3428
|
+
* @param params - Agent configuration including id, name, instructions, model, etc.
|
|
3429
|
+
* @returns Promise containing the created stored agent
|
|
3430
|
+
*/
|
|
3431
|
+
createStoredAgent(params) {
|
|
3432
|
+
return this.request("/api/stored/agents", {
|
|
3433
|
+
method: "POST",
|
|
3434
|
+
body: params
|
|
3435
|
+
});
|
|
3436
|
+
}
|
|
3437
|
+
/**
|
|
3438
|
+
* Gets a stored agent instance by ID for further operations (details, update, delete)
|
|
3439
|
+
* @param storedAgentId - ID of the stored agent to retrieve
|
|
3440
|
+
* @returns StoredAgent instance
|
|
3441
|
+
*/
|
|
3442
|
+
getStoredAgent(storedAgentId) {
|
|
3443
|
+
return new StoredAgent(this.options, storedAgentId);
|
|
3444
|
+
}
|
|
3145
3445
|
};
|
|
3146
3446
|
|
|
3147
3447
|
// src/tools.ts
|