@mastra/client-js 0.0.0-ai-sdk-network-text-delta-20251017172601 → 0.0.0-allow-to-pass-a-mastra-url-instance-20251105224938
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 +365 -3
- package/README.md +8 -10
- package/dist/client.d.ts +54 -78
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +500 -641
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +500 -641
- package/dist/index.js.map +1 -1
- package/dist/resources/agent-builder.d.ts +51 -36
- package/dist/resources/agent-builder.d.ts.map +1 -1
- package/dist/resources/agent.d.ts +41 -44
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/resources/mcp-tool.d.ts +5 -5
- package/dist/resources/memory-thread.d.ts +14 -14
- package/dist/resources/memory-thread.d.ts.map +1 -1
- package/dist/resources/observability.d.ts +8 -8
- package/dist/resources/observability.d.ts.map +1 -1
- package/dist/resources/tool.d.ts +4 -4
- package/dist/resources/vector.d.ts +5 -5
- package/dist/resources/workflow.d.ts +38 -103
- package/dist/resources/workflow.d.ts.map +1 -1
- package/dist/types.d.ts +90 -119
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/index.d.ts +10 -4
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/process-mastra-stream.d.ts.map +1 -1
- package/package.json +8 -4
- package/dist/resources/network-memory-thread.d.ts +0 -47
- package/dist/resources/network-memory-thread.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var uiUtils = require('@ai-sdk/ui-utils');
|
|
4
4
|
var uuid = require('@lukeed/uuid');
|
|
5
|
-
var
|
|
5
|
+
var error = require('@mastra/core/error');
|
|
6
|
+
var requestContext = require('@mastra/core/request-context');
|
|
6
7
|
var isVercelTool = require('@mastra/core/tools/is-vercel-tool');
|
|
7
8
|
var zod = require('zod');
|
|
8
9
|
var originalZodToJsonSchema = require('zod-to-json-schema');
|
|
@@ -12,28 +13,28 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
12
13
|
var originalZodToJsonSchema__default = /*#__PURE__*/_interopDefault(originalZodToJsonSchema);
|
|
13
14
|
|
|
14
15
|
// src/resources/agent.ts
|
|
15
|
-
function
|
|
16
|
-
if (
|
|
17
|
-
if (
|
|
18
|
-
return Object.fromEntries(
|
|
16
|
+
function parseClientRequestContext(requestContext$1) {
|
|
17
|
+
if (requestContext$1) {
|
|
18
|
+
if (requestContext$1 instanceof requestContext.RequestContext) {
|
|
19
|
+
return Object.fromEntries(requestContext$1.entries());
|
|
19
20
|
}
|
|
20
|
-
return
|
|
21
|
+
return requestContext$1;
|
|
21
22
|
}
|
|
22
23
|
return void 0;
|
|
23
24
|
}
|
|
24
|
-
function
|
|
25
|
-
if (
|
|
26
|
-
return btoa(JSON.stringify(
|
|
25
|
+
function base64RequestContext(requestContext) {
|
|
26
|
+
if (requestContext) {
|
|
27
|
+
return btoa(JSON.stringify(requestContext));
|
|
27
28
|
}
|
|
28
29
|
return void 0;
|
|
29
30
|
}
|
|
30
|
-
function
|
|
31
|
-
const
|
|
32
|
-
if (!
|
|
31
|
+
function requestContextQueryString(requestContext, delimiter = "?") {
|
|
32
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
33
|
+
if (!requestContextParam) return "";
|
|
33
34
|
const searchParams = new URLSearchParams();
|
|
34
|
-
searchParams.set("
|
|
35
|
+
searchParams.set("requestContext", requestContextParam);
|
|
35
36
|
const queryString = searchParams.toString();
|
|
36
|
-
return queryString ?
|
|
37
|
+
return queryString ? `${delimiter}${queryString}` : "";
|
|
37
38
|
}
|
|
38
39
|
function isZodType(value) {
|
|
39
40
|
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
@@ -100,11 +101,15 @@ async function sharedProcessMastraStream({
|
|
|
100
101
|
console.info("\u{1F3C1} Stream finished");
|
|
101
102
|
return;
|
|
102
103
|
}
|
|
104
|
+
let json;
|
|
103
105
|
try {
|
|
104
|
-
|
|
105
|
-
await onChunk(json);
|
|
106
|
+
json = JSON.parse(data);
|
|
106
107
|
} catch (error) {
|
|
107
108
|
console.error("\u274C JSON parse error:", error, "Data:", data);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (json) {
|
|
112
|
+
await onChunk(json);
|
|
108
113
|
}
|
|
109
114
|
}
|
|
110
115
|
}
|
|
@@ -198,10 +203,9 @@ var BaseResource = class {
|
|
|
198
203
|
async function executeToolCallAndRespond({
|
|
199
204
|
response,
|
|
200
205
|
params,
|
|
201
|
-
runId,
|
|
202
206
|
resourceId,
|
|
203
207
|
threadId,
|
|
204
|
-
|
|
208
|
+
requestContext,
|
|
205
209
|
respondFn
|
|
206
210
|
}) {
|
|
207
211
|
if (response.finishReason === "tool-calls") {
|
|
@@ -212,22 +216,18 @@ async function executeToolCallAndRespond({
|
|
|
212
216
|
for (const toolCall of toolCalls) {
|
|
213
217
|
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
214
218
|
if (clientTool && clientTool.execute) {
|
|
215
|
-
const result = await clientTool.execute(
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
resourceId,
|
|
220
|
-
threadId,
|
|
221
|
-
runtimeContext,
|
|
222
|
-
tracingContext: { currentSpan: void 0 },
|
|
223
|
-
suspend: async () => {
|
|
224
|
-
}
|
|
225
|
-
},
|
|
226
|
-
{
|
|
219
|
+
const result = await clientTool.execute(toolCall?.args, {
|
|
220
|
+
requestContext,
|
|
221
|
+
tracingContext: { currentSpan: void 0 },
|
|
222
|
+
agent: {
|
|
227
223
|
messages: response.messages,
|
|
228
|
-
toolCallId: toolCall?.toolCallId
|
|
224
|
+
toolCallId: toolCall?.toolCallId,
|
|
225
|
+
suspend: async () => {
|
|
226
|
+
},
|
|
227
|
+
threadId,
|
|
228
|
+
resourceId
|
|
229
229
|
}
|
|
230
|
-
);
|
|
230
|
+
});
|
|
231
231
|
const updatedMessages = [
|
|
232
232
|
...response.response.messages || [],
|
|
233
233
|
{
|
|
@@ -291,21 +291,21 @@ var AgentVoice = class extends BaseResource {
|
|
|
291
291
|
}
|
|
292
292
|
/**
|
|
293
293
|
* Get available speakers for the agent's voice provider
|
|
294
|
-
* @param
|
|
295
|
-
* @param
|
|
294
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
295
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
296
296
|
* @returns Promise containing list of available speakers
|
|
297
297
|
*/
|
|
298
|
-
getSpeakers(
|
|
299
|
-
return this.request(`/api/agents/${this.agentId}/voice/speakers${
|
|
298
|
+
getSpeakers(requestContext) {
|
|
299
|
+
return this.request(`/api/agents/${this.agentId}/voice/speakers${requestContextQueryString(requestContext)}`);
|
|
300
300
|
}
|
|
301
301
|
/**
|
|
302
302
|
* Get the listener configuration for the agent's voice provider
|
|
303
|
-
* @param
|
|
304
|
-
* @param
|
|
303
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
304
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
305
305
|
* @returns Promise containing a check if the agent has listening capabilities
|
|
306
306
|
*/
|
|
307
|
-
getListener(
|
|
308
|
-
return this.request(`/api/agents/${this.agentId}/voice/listener${
|
|
307
|
+
getListener(requestContext) {
|
|
308
|
+
return this.request(`/api/agents/${this.agentId}/voice/listener${requestContextQueryString(requestContext)}`);
|
|
309
309
|
}
|
|
310
310
|
};
|
|
311
311
|
var Agent = class extends BaseResource {
|
|
@@ -317,21 +317,27 @@ var Agent = class extends BaseResource {
|
|
|
317
317
|
voice;
|
|
318
318
|
/**
|
|
319
319
|
* Retrieves details about the agent
|
|
320
|
-
* @param
|
|
320
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
321
321
|
* @returns Promise containing agent details including model and instructions
|
|
322
322
|
*/
|
|
323
|
-
details(
|
|
324
|
-
return this.request(`/api/agents/${this.agentId}${
|
|
323
|
+
details(requestContext) {
|
|
324
|
+
return this.request(`/api/agents/${this.agentId}${requestContextQueryString(requestContext)}`);
|
|
325
|
+
}
|
|
326
|
+
enhanceInstructions(instructions, comment) {
|
|
327
|
+
return this.request(`/api/agents/${this.agentId}/instructions/enhance`, {
|
|
328
|
+
method: "POST",
|
|
329
|
+
body: { instructions, comment }
|
|
330
|
+
});
|
|
325
331
|
}
|
|
326
332
|
async generateLegacy(params) {
|
|
327
333
|
const processedParams = {
|
|
328
334
|
...params,
|
|
329
335
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
330
336
|
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
331
|
-
|
|
337
|
+
requestContext: parseClientRequestContext(params.requestContext),
|
|
332
338
|
clientTools: processClientTools(params.clientTools)
|
|
333
339
|
};
|
|
334
|
-
const {
|
|
340
|
+
const { resourceId, threadId, requestContext } = processedParams;
|
|
335
341
|
const response = await this.request(
|
|
336
342
|
`/api/agents/${this.agentId}/generate-legacy`,
|
|
337
343
|
{
|
|
@@ -347,22 +353,18 @@ var Agent = class extends BaseResource {
|
|
|
347
353
|
for (const toolCall of toolCalls) {
|
|
348
354
|
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
349
355
|
if (clientTool && clientTool.execute) {
|
|
350
|
-
const result = await clientTool.execute(
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
resourceId,
|
|
355
|
-
threadId,
|
|
356
|
-
runtimeContext,
|
|
357
|
-
tracingContext: { currentSpan: void 0 },
|
|
358
|
-
suspend: async () => {
|
|
359
|
-
}
|
|
360
|
-
},
|
|
361
|
-
{
|
|
356
|
+
const result = await clientTool.execute(toolCall?.args, {
|
|
357
|
+
requestContext,
|
|
358
|
+
tracingContext: { currentSpan: void 0 },
|
|
359
|
+
agent: {
|
|
362
360
|
messages: response.messages,
|
|
363
|
-
toolCallId: toolCall?.toolCallId
|
|
361
|
+
toolCallId: toolCall?.toolCallId,
|
|
362
|
+
suspend: async () => {
|
|
363
|
+
},
|
|
364
|
+
threadId,
|
|
365
|
+
resourceId
|
|
364
366
|
}
|
|
365
|
-
);
|
|
367
|
+
});
|
|
366
368
|
const updatedMessages = [
|
|
367
369
|
...response.response.messages,
|
|
368
370
|
{
|
|
@@ -398,15 +400,14 @@ var Agent = class extends BaseResource {
|
|
|
398
400
|
}
|
|
399
401
|
const processedParams = {
|
|
400
402
|
...params,
|
|
401
|
-
|
|
402
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
403
|
+
requestContext: parseClientRequestContext(params.requestContext),
|
|
403
404
|
clientTools: processClientTools(params.clientTools),
|
|
404
405
|
structuredOutput: params.structuredOutput ? {
|
|
405
406
|
...params.structuredOutput,
|
|
406
407
|
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
407
408
|
} : void 0
|
|
408
409
|
};
|
|
409
|
-
const {
|
|
410
|
+
const { resourceId, threadId, requestContext } = processedParams;
|
|
410
411
|
const response = await this.request(
|
|
411
412
|
`/api/agents/${this.agentId}/generate`,
|
|
412
413
|
{
|
|
@@ -418,10 +419,9 @@ var Agent = class extends BaseResource {
|
|
|
418
419
|
return executeToolCallAndRespond({
|
|
419
420
|
response,
|
|
420
421
|
params,
|
|
421
|
-
runId,
|
|
422
422
|
resourceId,
|
|
423
423
|
threadId,
|
|
424
|
-
|
|
424
|
+
requestContext,
|
|
425
425
|
respondFn: this.generate.bind(this)
|
|
426
426
|
});
|
|
427
427
|
}
|
|
@@ -699,7 +699,7 @@ var Agent = class extends BaseResource {
|
|
|
699
699
|
...params,
|
|
700
700
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
701
701
|
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
702
|
-
|
|
702
|
+
requestContext: parseClientRequestContext(params.requestContext),
|
|
703
703
|
clientTools: processClientTools(params.clientTools)
|
|
704
704
|
};
|
|
705
705
|
const { readable, writable } = new TransformStream();
|
|
@@ -951,7 +951,10 @@ var Agent = class extends BaseResource {
|
|
|
951
951
|
break;
|
|
952
952
|
}
|
|
953
953
|
case "error": {
|
|
954
|
-
throw
|
|
954
|
+
throw error.getErrorFromUnknown(chunk.payload.error, {
|
|
955
|
+
fallbackMessage: "Unknown error in stream",
|
|
956
|
+
supportSerialization: false
|
|
957
|
+
});
|
|
955
958
|
}
|
|
956
959
|
case "data": {
|
|
957
960
|
data.push(...chunk.payload.data);
|
|
@@ -978,8 +981,8 @@ var Agent = class extends BaseResource {
|
|
|
978
981
|
});
|
|
979
982
|
onFinish?.({ message, finishReason, usage });
|
|
980
983
|
}
|
|
981
|
-
async processStreamResponse(processedParams, writable) {
|
|
982
|
-
const response = await this.request(`/api/agents/${this.agentId}
|
|
984
|
+
async processStreamResponse(processedParams, writable, route = "stream") {
|
|
985
|
+
const response = await this.request(`/api/agents/${this.agentId}/${route}`, {
|
|
983
986
|
method: "POST",
|
|
984
987
|
body: processedParams,
|
|
985
988
|
stream: true
|
|
@@ -1035,23 +1038,19 @@ var Agent = class extends BaseResource {
|
|
|
1035
1038
|
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
1036
1039
|
if (clientTool && clientTool.execute) {
|
|
1037
1040
|
shouldExecuteClientTool = true;
|
|
1038
|
-
const result = await clientTool.execute(
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
threadId: processedParams.threadId,
|
|
1044
|
-
runtimeContext: processedParams.runtimeContext,
|
|
1045
|
-
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1046
|
-
tracingContext: { currentSpan: void 0 },
|
|
1047
|
-
suspend: async () => {
|
|
1048
|
-
}
|
|
1049
|
-
},
|
|
1050
|
-
{
|
|
1041
|
+
const result = await clientTool.execute(toolCall2?.args, {
|
|
1042
|
+
requestContext: processedParams.requestContext,
|
|
1043
|
+
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1044
|
+
tracingContext: { currentSpan: void 0 },
|
|
1045
|
+
agent: {
|
|
1051
1046
|
messages: response.messages,
|
|
1052
|
-
toolCallId: toolCall2?.toolCallId
|
|
1047
|
+
toolCallId: toolCall2?.toolCallId,
|
|
1048
|
+
suspend: async () => {
|
|
1049
|
+
},
|
|
1050
|
+
threadId: processedParams.threadId,
|
|
1051
|
+
resourceId: processedParams.resourceId
|
|
1053
1052
|
}
|
|
1054
|
-
);
|
|
1053
|
+
});
|
|
1055
1054
|
const lastMessageRaw = messages[messages.length - 1];
|
|
1056
1055
|
const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
|
|
1057
1056
|
const toolInvocationPart = lastMessage?.parts?.find(
|
|
@@ -1139,8 +1138,7 @@ var Agent = class extends BaseResource {
|
|
|
1139
1138
|
}
|
|
1140
1139
|
const processedParams = {
|
|
1141
1140
|
...params,
|
|
1142
|
-
|
|
1143
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
1141
|
+
requestContext: parseClientRequestContext(params.requestContext),
|
|
1144
1142
|
clientTools: processClientTools(params.clientTools),
|
|
1145
1143
|
structuredOutput: params.structuredOutput ? {
|
|
1146
1144
|
...params.structuredOutput,
|
|
@@ -1164,6 +1162,42 @@ var Agent = class extends BaseResource {
|
|
|
1164
1162
|
};
|
|
1165
1163
|
return streamResponse;
|
|
1166
1164
|
}
|
|
1165
|
+
async approveToolCall(params) {
|
|
1166
|
+
const { readable, writable } = new TransformStream();
|
|
1167
|
+
const response = await this.processStreamResponse(params, writable, "approve-tool-call");
|
|
1168
|
+
const streamResponse = new Response(readable, {
|
|
1169
|
+
status: response.status,
|
|
1170
|
+
statusText: response.statusText,
|
|
1171
|
+
headers: response.headers
|
|
1172
|
+
});
|
|
1173
|
+
streamResponse.processDataStream = async ({
|
|
1174
|
+
onChunk
|
|
1175
|
+
}) => {
|
|
1176
|
+
await processMastraStream({
|
|
1177
|
+
stream: streamResponse.body,
|
|
1178
|
+
onChunk
|
|
1179
|
+
});
|
|
1180
|
+
};
|
|
1181
|
+
return streamResponse;
|
|
1182
|
+
}
|
|
1183
|
+
async declineToolCall(params) {
|
|
1184
|
+
const { readable, writable } = new TransformStream();
|
|
1185
|
+
const response = await this.processStreamResponse(params, writable, "decline-tool-call");
|
|
1186
|
+
const streamResponse = new Response(readable, {
|
|
1187
|
+
status: response.status,
|
|
1188
|
+
statusText: response.statusText,
|
|
1189
|
+
headers: response.headers
|
|
1190
|
+
});
|
|
1191
|
+
streamResponse.processDataStream = async ({
|
|
1192
|
+
onChunk
|
|
1193
|
+
}) => {
|
|
1194
|
+
await processMastraStream({
|
|
1195
|
+
stream: streamResponse.body,
|
|
1196
|
+
onChunk
|
|
1197
|
+
});
|
|
1198
|
+
};
|
|
1199
|
+
return streamResponse;
|
|
1200
|
+
}
|
|
1167
1201
|
/**
|
|
1168
1202
|
* Processes the stream response and handles tool calls
|
|
1169
1203
|
*/
|
|
@@ -1204,23 +1238,19 @@ var Agent = class extends BaseResource {
|
|
|
1204
1238
|
for (const toolCall2 of toolCalls) {
|
|
1205
1239
|
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
1206
1240
|
if (clientTool && clientTool.execute) {
|
|
1207
|
-
const result = await clientTool.execute(
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
threadId: processedParams.threadId,
|
|
1213
|
-
runtimeContext: processedParams.runtimeContext,
|
|
1214
|
-
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1215
|
-
tracingContext: { currentSpan: void 0 },
|
|
1216
|
-
suspend: async () => {
|
|
1217
|
-
}
|
|
1218
|
-
},
|
|
1219
|
-
{
|
|
1241
|
+
const result = await clientTool.execute(toolCall2?.args, {
|
|
1242
|
+
requestContext: processedParams.requestContext,
|
|
1243
|
+
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1244
|
+
tracingContext: { currentSpan: void 0 },
|
|
1245
|
+
agent: {
|
|
1220
1246
|
messages: response.messages,
|
|
1221
|
-
toolCallId: toolCall2?.toolCallId
|
|
1247
|
+
toolCallId: toolCall2?.toolCallId,
|
|
1248
|
+
suspend: async () => {
|
|
1249
|
+
},
|
|
1250
|
+
threadId: processedParams.threadId,
|
|
1251
|
+
resourceId: processedParams.resourceId
|
|
1222
1252
|
}
|
|
1223
|
-
);
|
|
1253
|
+
});
|
|
1224
1254
|
const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
|
|
1225
1255
|
const toolInvocationPart = lastMessage?.parts?.find(
|
|
1226
1256
|
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
@@ -1281,11 +1311,11 @@ var Agent = class extends BaseResource {
|
|
|
1281
1311
|
/**
|
|
1282
1312
|
* Gets details about a specific tool available to the agent
|
|
1283
1313
|
* @param toolId - ID of the tool to retrieve
|
|
1284
|
-
* @param
|
|
1314
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1285
1315
|
* @returns Promise containing tool details
|
|
1286
1316
|
*/
|
|
1287
|
-
getTool(toolId,
|
|
1288
|
-
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${
|
|
1317
|
+
getTool(toolId, requestContext) {
|
|
1318
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${requestContextQueryString(requestContext)}`);
|
|
1289
1319
|
}
|
|
1290
1320
|
/**
|
|
1291
1321
|
* Executes a tool for the agent
|
|
@@ -1296,29 +1326,13 @@ var Agent = class extends BaseResource {
|
|
|
1296
1326
|
executeTool(toolId, params) {
|
|
1297
1327
|
const body = {
|
|
1298
1328
|
data: params.data,
|
|
1299
|
-
|
|
1329
|
+
requestContext: parseClientRequestContext(params.requestContext)
|
|
1300
1330
|
};
|
|
1301
1331
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
1302
1332
|
method: "POST",
|
|
1303
1333
|
body
|
|
1304
1334
|
});
|
|
1305
1335
|
}
|
|
1306
|
-
/**
|
|
1307
|
-
* Retrieves evaluation results for the agent
|
|
1308
|
-
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1309
|
-
* @returns Promise containing agent evaluations
|
|
1310
|
-
*/
|
|
1311
|
-
evals(runtimeContext) {
|
|
1312
|
-
return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
|
|
1313
|
-
}
|
|
1314
|
-
/**
|
|
1315
|
-
* Retrieves live evaluation results for the agent
|
|
1316
|
-
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1317
|
-
* @returns Promise containing live agent evaluations
|
|
1318
|
-
*/
|
|
1319
|
-
liveEvals(runtimeContext) {
|
|
1320
|
-
return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
|
|
1321
|
-
}
|
|
1322
1336
|
/**
|
|
1323
1337
|
* Updates the model for the agent
|
|
1324
1338
|
* @param params - Parameters for updating the model
|
|
@@ -1330,6 +1344,15 @@ var Agent = class extends BaseResource {
|
|
|
1330
1344
|
body: params
|
|
1331
1345
|
});
|
|
1332
1346
|
}
|
|
1347
|
+
/**
|
|
1348
|
+
* Resets the agent's model to the original model that was set during construction
|
|
1349
|
+
* @returns Promise containing a success message
|
|
1350
|
+
*/
|
|
1351
|
+
resetModel() {
|
|
1352
|
+
return this.request(`/api/agents/${this.agentId}/model/reset`, {
|
|
1353
|
+
method: "POST"
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1333
1356
|
/**
|
|
1334
1357
|
* Updates the model for the agent in the model list
|
|
1335
1358
|
* @param params - Parameters for updating the model
|
|
@@ -1352,12 +1375,6 @@ var Agent = class extends BaseResource {
|
|
|
1352
1375
|
body: params
|
|
1353
1376
|
});
|
|
1354
1377
|
}
|
|
1355
|
-
async generateVNext(_messagesOrParams, _options) {
|
|
1356
|
-
throw new Error("generateVNext has been renamed to generate. Please use generate instead.");
|
|
1357
|
-
}
|
|
1358
|
-
async streamVNext(_messagesOrParams, _options) {
|
|
1359
|
-
throw new Error("streamVNext has been renamed to stream. Please use stream instead.");
|
|
1360
|
-
}
|
|
1361
1378
|
};
|
|
1362
1379
|
|
|
1363
1380
|
// src/resources/memory-thread.ts
|
|
@@ -1369,72 +1386,78 @@ var MemoryThread = class extends BaseResource {
|
|
|
1369
1386
|
}
|
|
1370
1387
|
/**
|
|
1371
1388
|
* Retrieves the memory thread details
|
|
1389
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1372
1390
|
* @returns Promise containing thread details including title and metadata
|
|
1373
1391
|
*/
|
|
1374
|
-
get() {
|
|
1375
|
-
return this.request(
|
|
1392
|
+
get(requestContext) {
|
|
1393
|
+
return this.request(
|
|
1394
|
+
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(requestContext, "&")}`
|
|
1395
|
+
);
|
|
1376
1396
|
}
|
|
1377
1397
|
/**
|
|
1378
1398
|
* Updates the memory thread properties
|
|
1379
|
-
* @param params - Update parameters including title and
|
|
1399
|
+
* @param params - Update parameters including title, metadata, and optional request context
|
|
1380
1400
|
* @returns Promise containing updated thread details
|
|
1381
1401
|
*/
|
|
1382
1402
|
update(params) {
|
|
1383
|
-
return this.request(
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1403
|
+
return this.request(
|
|
1404
|
+
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(params.requestContext, "&")}`,
|
|
1405
|
+
{
|
|
1406
|
+
method: "PATCH",
|
|
1407
|
+
body: params
|
|
1408
|
+
}
|
|
1409
|
+
);
|
|
1387
1410
|
}
|
|
1388
1411
|
/**
|
|
1389
1412
|
* Deletes the memory thread
|
|
1413
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1390
1414
|
* @returns Promise containing deletion result
|
|
1391
1415
|
*/
|
|
1392
|
-
delete() {
|
|
1393
|
-
return this.request(
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
1400
|
-
* @returns Promise containing thread messages and UI messages
|
|
1401
|
-
*/
|
|
1402
|
-
getMessages(params) {
|
|
1403
|
-
const query = new URLSearchParams({
|
|
1404
|
-
agentId: this.agentId,
|
|
1405
|
-
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
1406
|
-
});
|
|
1407
|
-
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
1416
|
+
delete(requestContext) {
|
|
1417
|
+
return this.request(
|
|
1418
|
+
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(requestContext, "&")}`,
|
|
1419
|
+
{
|
|
1420
|
+
method: "DELETE"
|
|
1421
|
+
}
|
|
1422
|
+
);
|
|
1408
1423
|
}
|
|
1409
1424
|
/**
|
|
1410
|
-
* Retrieves paginated messages associated with the thread with
|
|
1411
|
-
* @param params - Pagination parameters including
|
|
1425
|
+
* Retrieves paginated messages associated with the thread with filtering and ordering options
|
|
1426
|
+
* @param params - Pagination parameters including page, perPage, orderBy, filter, include options, and request context
|
|
1412
1427
|
* @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
|
|
1413
1428
|
*/
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1429
|
+
listMessages(params = {}) {
|
|
1430
|
+
const { page, perPage, orderBy, filter, include, resourceId, requestContext } = params;
|
|
1431
|
+
const queryParams = {};
|
|
1432
|
+
if (resourceId) queryParams.resourceId = resourceId;
|
|
1433
|
+
if (page !== void 0) queryParams.page = String(page);
|
|
1434
|
+
if (perPage !== void 0) queryParams.perPage = String(perPage);
|
|
1435
|
+
if (orderBy) queryParams.orderBy = JSON.stringify(orderBy);
|
|
1436
|
+
if (filter) queryParams.filter = JSON.stringify(filter);
|
|
1437
|
+
if (include) queryParams.include = JSON.stringify(include);
|
|
1438
|
+
const query = new URLSearchParams(queryParams);
|
|
1439
|
+
const queryString = query.toString();
|
|
1440
|
+
const url = `/api/memory/threads/${this.threadId}/messages${queryString ? `?${queryString}` : ""}${requestContextQueryString(requestContext, queryString ? "&" : "?")}`;
|
|
1441
|
+
return this.request(url);
|
|
1423
1442
|
}
|
|
1424
1443
|
/**
|
|
1425
1444
|
* Deletes one or more messages from the thread
|
|
1426
1445
|
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
1427
1446
|
* message object with id property, or array of message objects
|
|
1447
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1428
1448
|
* @returns Promise containing deletion result
|
|
1429
1449
|
*/
|
|
1430
|
-
deleteMessages(messageIds) {
|
|
1450
|
+
deleteMessages(messageIds, requestContext) {
|
|
1431
1451
|
const query = new URLSearchParams({
|
|
1432
1452
|
agentId: this.agentId
|
|
1433
1453
|
});
|
|
1434
|
-
return this.request(
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1454
|
+
return this.request(
|
|
1455
|
+
`/api/memory/messages/delete?${query.toString()}${requestContextQueryString(requestContext, "&")}`,
|
|
1456
|
+
{
|
|
1457
|
+
method: "POST",
|
|
1458
|
+
body: { messageIds }
|
|
1459
|
+
}
|
|
1460
|
+
);
|
|
1438
1461
|
}
|
|
1439
1462
|
};
|
|
1440
1463
|
|
|
@@ -1447,12 +1470,12 @@ var Vector = class extends BaseResource {
|
|
|
1447
1470
|
/**
|
|
1448
1471
|
* Retrieves details about a specific vector index
|
|
1449
1472
|
* @param indexName - Name of the index to get details for
|
|
1450
|
-
* @param
|
|
1473
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1451
1474
|
* @returns Promise containing vector index details
|
|
1452
1475
|
*/
|
|
1453
|
-
details(indexName,
|
|
1476
|
+
details(indexName, requestContext) {
|
|
1454
1477
|
return this.request(
|
|
1455
|
-
`/api/vector/${this.vectorName}/indexes/${indexName}${
|
|
1478
|
+
`/api/vector/${this.vectorName}/indexes/${indexName}${requestContextQueryString(requestContext)}`
|
|
1456
1479
|
);
|
|
1457
1480
|
}
|
|
1458
1481
|
/**
|
|
@@ -1467,11 +1490,11 @@ var Vector = class extends BaseResource {
|
|
|
1467
1490
|
}
|
|
1468
1491
|
/**
|
|
1469
1492
|
* Retrieves a list of all available indexes
|
|
1470
|
-
* @param
|
|
1493
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1471
1494
|
* @returns Promise containing array of index names
|
|
1472
1495
|
*/
|
|
1473
|
-
getIndexes(
|
|
1474
|
-
return this.request(`/api/vector/${this.vectorName}/indexes${
|
|
1496
|
+
getIndexes(requestContext) {
|
|
1497
|
+
return this.request(`/api/vector/${this.vectorName}/indexes${requestContextQueryString(requestContext)}`);
|
|
1475
1498
|
}
|
|
1476
1499
|
/**
|
|
1477
1500
|
* Creates a new vector index
|
|
@@ -1516,11 +1539,11 @@ var Tool = class extends BaseResource {
|
|
|
1516
1539
|
}
|
|
1517
1540
|
/**
|
|
1518
1541
|
* Retrieves details about the tool
|
|
1519
|
-
* @param
|
|
1542
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1520
1543
|
* @returns Promise containing tool details including description and schemas
|
|
1521
1544
|
*/
|
|
1522
|
-
details(
|
|
1523
|
-
return this.request(`/api/tools/${this.toolId}${
|
|
1545
|
+
details(requestContext) {
|
|
1546
|
+
return this.request(`/api/tools/${this.toolId}${requestContextQueryString(requestContext)}`);
|
|
1524
1547
|
}
|
|
1525
1548
|
/**
|
|
1526
1549
|
* Executes the tool with the provided parameters
|
|
@@ -1534,7 +1557,7 @@ var Tool = class extends BaseResource {
|
|
|
1534
1557
|
}
|
|
1535
1558
|
const body = {
|
|
1536
1559
|
data: params.data,
|
|
1537
|
-
|
|
1560
|
+
requestContext: parseClientRequestContext(params.requestContext)
|
|
1538
1561
|
};
|
|
1539
1562
|
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
1540
1563
|
method: "POST",
|
|
@@ -1550,67 +1573,22 @@ var Workflow = class extends BaseResource {
|
|
|
1550
1573
|
super(options);
|
|
1551
1574
|
this.workflowId = workflowId;
|
|
1552
1575
|
}
|
|
1553
|
-
/**
|
|
1554
|
-
* Creates an async generator that processes a readable stream and yields workflow records
|
|
1555
|
-
* separated by the Record Separator character (\x1E)
|
|
1556
|
-
*
|
|
1557
|
-
* @param stream - The readable stream to process
|
|
1558
|
-
* @returns An async generator that yields parsed records
|
|
1559
|
-
*/
|
|
1560
|
-
async *streamProcessor(stream) {
|
|
1561
|
-
const reader = stream.getReader();
|
|
1562
|
-
let doneReading = false;
|
|
1563
|
-
let buffer = "";
|
|
1564
|
-
try {
|
|
1565
|
-
while (!doneReading) {
|
|
1566
|
-
const { done, value } = await reader.read();
|
|
1567
|
-
doneReading = done;
|
|
1568
|
-
if (done && !value) continue;
|
|
1569
|
-
try {
|
|
1570
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1571
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
1572
|
-
buffer = chunks.pop() || "";
|
|
1573
|
-
for (const chunk of chunks) {
|
|
1574
|
-
if (chunk) {
|
|
1575
|
-
if (typeof chunk === "string") {
|
|
1576
|
-
try {
|
|
1577
|
-
const parsedChunk = JSON.parse(chunk);
|
|
1578
|
-
yield parsedChunk;
|
|
1579
|
-
} catch {
|
|
1580
|
-
}
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
}
|
|
1584
|
-
} catch {
|
|
1585
|
-
}
|
|
1586
|
-
}
|
|
1587
|
-
if (buffer) {
|
|
1588
|
-
try {
|
|
1589
|
-
yield JSON.parse(buffer);
|
|
1590
|
-
} catch {
|
|
1591
|
-
}
|
|
1592
|
-
}
|
|
1593
|
-
} finally {
|
|
1594
|
-
reader.cancel().catch(() => {
|
|
1595
|
-
});
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
1576
|
/**
|
|
1599
1577
|
* Retrieves details about the workflow
|
|
1600
|
-
* @param
|
|
1578
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1601
1579
|
* @returns Promise containing workflow details including steps and graphs
|
|
1602
1580
|
*/
|
|
1603
|
-
details(
|
|
1604
|
-
return this.request(`/api/workflows/${this.workflowId}${
|
|
1581
|
+
details(requestContext) {
|
|
1582
|
+
return this.request(`/api/workflows/${this.workflowId}${requestContextQueryString(requestContext)}`);
|
|
1605
1583
|
}
|
|
1606
1584
|
/**
|
|
1607
1585
|
* Retrieves all runs for a workflow
|
|
1608
1586
|
* @param params - Parameters for filtering runs
|
|
1609
|
-
* @param
|
|
1587
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1610
1588
|
* @returns Promise containing workflow runs array
|
|
1611
1589
|
*/
|
|
1612
|
-
runs(params,
|
|
1613
|
-
const
|
|
1590
|
+
runs(params, requestContext) {
|
|
1591
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
1614
1592
|
const searchParams = new URLSearchParams();
|
|
1615
1593
|
if (params?.fromDate) {
|
|
1616
1594
|
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
@@ -1618,17 +1596,21 @@ var Workflow = class extends BaseResource {
|
|
|
1618
1596
|
if (params?.toDate) {
|
|
1619
1597
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
1620
1598
|
}
|
|
1621
|
-
if (params?.
|
|
1622
|
-
|
|
1599
|
+
if (params?.perPage !== null && params?.perPage !== void 0) {
|
|
1600
|
+
if (params.perPage === false) {
|
|
1601
|
+
searchParams.set("perPage", "false");
|
|
1602
|
+
} else if (typeof params.perPage === "number" && params.perPage > 0 && Number.isInteger(params.perPage)) {
|
|
1603
|
+
searchParams.set("perPage", String(params.perPage));
|
|
1604
|
+
}
|
|
1623
1605
|
}
|
|
1624
|
-
if (params?.
|
|
1625
|
-
searchParams.set("
|
|
1606
|
+
if (params?.page !== null && params?.page !== void 0 && !isNaN(Number(params?.page))) {
|
|
1607
|
+
searchParams.set("page", String(params.page));
|
|
1626
1608
|
}
|
|
1627
1609
|
if (params?.resourceId) {
|
|
1628
1610
|
searchParams.set("resourceId", params.resourceId);
|
|
1629
1611
|
}
|
|
1630
|
-
if (
|
|
1631
|
-
searchParams.set("
|
|
1612
|
+
if (requestContextParam) {
|
|
1613
|
+
searchParams.set("requestContext", requestContextParam);
|
|
1632
1614
|
}
|
|
1633
1615
|
if (searchParams.size) {
|
|
1634
1616
|
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
@@ -1639,21 +1621,21 @@ var Workflow = class extends BaseResource {
|
|
|
1639
1621
|
/**
|
|
1640
1622
|
* Retrieves a specific workflow run by its ID
|
|
1641
1623
|
* @param runId - The ID of the workflow run to retrieve
|
|
1642
|
-
* @param
|
|
1624
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1643
1625
|
* @returns Promise containing the workflow run details
|
|
1644
1626
|
*/
|
|
1645
|
-
runById(runId,
|
|
1646
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${
|
|
1627
|
+
runById(runId, requestContext) {
|
|
1628
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${requestContextQueryString(requestContext)}`);
|
|
1647
1629
|
}
|
|
1648
1630
|
/**
|
|
1649
1631
|
* Retrieves the execution result for a specific workflow run by its ID
|
|
1650
1632
|
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1651
|
-
* @param
|
|
1633
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1652
1634
|
* @returns Promise containing the workflow run execution result
|
|
1653
1635
|
*/
|
|
1654
|
-
runExecutionResult(runId,
|
|
1636
|
+
runExecutionResult(runId, requestContext) {
|
|
1655
1637
|
return this.request(
|
|
1656
|
-
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${
|
|
1638
|
+
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${requestContextQueryString(requestContext)}`
|
|
1657
1639
|
);
|
|
1658
1640
|
}
|
|
1659
1641
|
/**
|
|
@@ -1666,32 +1648,12 @@ var Workflow = class extends BaseResource {
|
|
|
1666
1648
|
method: "POST"
|
|
1667
1649
|
});
|
|
1668
1650
|
}
|
|
1669
|
-
/**
|
|
1670
|
-
* Sends an event to a specific workflow run by its ID
|
|
1671
|
-
* @param params - Object containing the runId, event and data
|
|
1672
|
-
* @returns Promise containing a success message
|
|
1673
|
-
*/
|
|
1674
|
-
sendRunEvent(params) {
|
|
1675
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
|
|
1676
|
-
method: "POST",
|
|
1677
|
-
body: { event: params.event, data: params.data }
|
|
1678
|
-
});
|
|
1679
|
-
}
|
|
1680
|
-
/**
|
|
1681
|
-
* @deprecated Use createRunAsync() instead.
|
|
1682
|
-
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
1683
|
-
*/
|
|
1684
|
-
async createRun(_params) {
|
|
1685
|
-
throw new Error(
|
|
1686
|
-
"createRun() has been deprecated. Please use createRunAsync() instead.\n\nMigration guide:\n Before: const run = workflow.createRun();\n After: const run = await workflow.createRunAsync();\n\nNote: createRunAsync() is an async method, so make sure your calling function is async."
|
|
1687
|
-
);
|
|
1688
|
-
}
|
|
1689
1651
|
/**
|
|
1690
1652
|
* Creates a new workflow run
|
|
1691
1653
|
* @param params - Optional object containing the optional runId
|
|
1692
1654
|
* @returns Promise containing the runId of the created run with methods to control execution
|
|
1693
1655
|
*/
|
|
1694
|
-
async
|
|
1656
|
+
async createRun(params) {
|
|
1695
1657
|
const searchParams = new URLSearchParams();
|
|
1696
1658
|
if (!!params?.runId) {
|
|
1697
1659
|
searchParams.set("runId", params.runId);
|
|
@@ -1709,7 +1671,7 @@ var Workflow = class extends BaseResource {
|
|
|
1709
1671
|
return this.start({
|
|
1710
1672
|
runId,
|
|
1711
1673
|
inputData: p.inputData,
|
|
1712
|
-
|
|
1674
|
+
requestContext: p.requestContext,
|
|
1713
1675
|
tracingOptions: p.tracingOptions
|
|
1714
1676
|
});
|
|
1715
1677
|
},
|
|
@@ -1717,22 +1679,19 @@ var Workflow = class extends BaseResource {
|
|
|
1717
1679
|
return this.startAsync({
|
|
1718
1680
|
runId,
|
|
1719
1681
|
inputData: p.inputData,
|
|
1720
|
-
|
|
1682
|
+
requestContext: p.requestContext,
|
|
1721
1683
|
tracingOptions: p.tracingOptions
|
|
1722
1684
|
});
|
|
1723
1685
|
},
|
|
1724
|
-
watch: async (onRecord) => {
|
|
1725
|
-
return this.watch({ runId }, onRecord);
|
|
1726
|
-
},
|
|
1727
1686
|
stream: async (p) => {
|
|
1728
|
-
return this.stream({ runId, inputData: p.inputData,
|
|
1687
|
+
return this.stream({ runId, inputData: p.inputData, requestContext: p.requestContext });
|
|
1729
1688
|
},
|
|
1730
1689
|
resume: async (p) => {
|
|
1731
1690
|
return this.resume({
|
|
1732
1691
|
runId,
|
|
1733
1692
|
step: p.step,
|
|
1734
1693
|
resumeData: p.resumeData,
|
|
1735
|
-
|
|
1694
|
+
requestContext: p.requestContext,
|
|
1736
1695
|
tracingOptions: p.tracingOptions
|
|
1737
1696
|
});
|
|
1738
1697
|
},
|
|
@@ -1741,7 +1700,7 @@ var Workflow = class extends BaseResource {
|
|
|
1741
1700
|
runId,
|
|
1742
1701
|
step: p.step,
|
|
1743
1702
|
resumeData: p.resumeData,
|
|
1744
|
-
|
|
1703
|
+
requestContext: p.requestContext,
|
|
1745
1704
|
tracingOptions: p.tracingOptions
|
|
1746
1705
|
});
|
|
1747
1706
|
},
|
|
@@ -1750,26 +1709,26 @@ var Workflow = class extends BaseResource {
|
|
|
1750
1709
|
runId,
|
|
1751
1710
|
step: p.step,
|
|
1752
1711
|
resumeData: p.resumeData,
|
|
1753
|
-
|
|
1712
|
+
requestContext: p.requestContext
|
|
1754
1713
|
});
|
|
1755
1714
|
}
|
|
1756
1715
|
};
|
|
1757
1716
|
}
|
|
1758
1717
|
/**
|
|
1759
1718
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1760
|
-
* @param params - Object containing the runId, inputData and
|
|
1719
|
+
* @param params - Object containing the runId, inputData and requestContext
|
|
1761
1720
|
* @returns Promise containing success message
|
|
1762
1721
|
*/
|
|
1763
1722
|
start(params) {
|
|
1764
|
-
const
|
|
1723
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1765
1724
|
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1766
1725
|
method: "POST",
|
|
1767
|
-
body: { inputData: params?.inputData,
|
|
1726
|
+
body: { inputData: params?.inputData, requestContext, tracingOptions: params.tracingOptions }
|
|
1768
1727
|
});
|
|
1769
1728
|
}
|
|
1770
1729
|
/**
|
|
1771
1730
|
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
1772
|
-
* @param params - Object containing the runId, step, resumeData and
|
|
1731
|
+
* @param params - Object containing the runId, step, resumeData and requestContext
|
|
1773
1732
|
* @returns Promise containing success message
|
|
1774
1733
|
*/
|
|
1775
1734
|
resume({
|
|
@@ -1779,20 +1738,20 @@ var Workflow = class extends BaseResource {
|
|
|
1779
1738
|
tracingOptions,
|
|
1780
1739
|
...rest
|
|
1781
1740
|
}) {
|
|
1782
|
-
const
|
|
1741
|
+
const requestContext = parseClientRequestContext(rest.requestContext);
|
|
1783
1742
|
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1784
1743
|
method: "POST",
|
|
1785
1744
|
body: {
|
|
1786
1745
|
step,
|
|
1787
1746
|
resumeData,
|
|
1788
|
-
|
|
1747
|
+
requestContext,
|
|
1789
1748
|
tracingOptions
|
|
1790
1749
|
}
|
|
1791
1750
|
});
|
|
1792
1751
|
}
|
|
1793
1752
|
/**
|
|
1794
1753
|
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
1795
|
-
* @param params - Object containing the optional runId, inputData and
|
|
1754
|
+
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1796
1755
|
* @returns Promise containing the workflow execution results
|
|
1797
1756
|
*/
|
|
1798
1757
|
startAsync(params) {
|
|
@@ -1800,15 +1759,15 @@ var Workflow = class extends BaseResource {
|
|
|
1800
1759
|
if (!!params?.runId) {
|
|
1801
1760
|
searchParams.set("runId", params.runId);
|
|
1802
1761
|
}
|
|
1803
|
-
const
|
|
1762
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1804
1763
|
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1805
1764
|
method: "POST",
|
|
1806
|
-
body: { inputData: params.inputData,
|
|
1765
|
+
body: { inputData: params.inputData, requestContext, tracingOptions: params.tracingOptions }
|
|
1807
1766
|
});
|
|
1808
1767
|
}
|
|
1809
1768
|
/**
|
|
1810
1769
|
* Starts a workflow run and returns a stream
|
|
1811
|
-
* @param params - Object containing the optional runId, inputData and
|
|
1770
|
+
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1812
1771
|
* @returns Promise containing the workflow execution results
|
|
1813
1772
|
*/
|
|
1814
1773
|
async stream(params) {
|
|
@@ -1816,12 +1775,12 @@ var Workflow = class extends BaseResource {
|
|
|
1816
1775
|
if (!!params?.runId) {
|
|
1817
1776
|
searchParams.set("runId", params.runId);
|
|
1818
1777
|
}
|
|
1819
|
-
const
|
|
1778
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1820
1779
|
const response = await this.request(
|
|
1821
1780
|
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1822
1781
|
{
|
|
1823
1782
|
method: "POST",
|
|
1824
|
-
body: { inputData: params.inputData,
|
|
1783
|
+
body: { inputData: params.inputData, requestContext, tracingOptions: params.tracingOptions },
|
|
1825
1784
|
stream: true
|
|
1826
1785
|
}
|
|
1827
1786
|
);
|
|
@@ -1906,7 +1865,7 @@ var Workflow = class extends BaseResource {
|
|
|
1906
1865
|
}
|
|
1907
1866
|
/**
|
|
1908
1867
|
* Starts a workflow run and returns a stream
|
|
1909
|
-
* @param params - Object containing the optional runId, inputData and
|
|
1868
|
+
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1910
1869
|
* @returns Promise containing the workflow execution results
|
|
1911
1870
|
*/
|
|
1912
1871
|
async streamVNext(params) {
|
|
@@ -1914,14 +1873,14 @@ var Workflow = class extends BaseResource {
|
|
|
1914
1873
|
if (!!params?.runId) {
|
|
1915
1874
|
searchParams.set("runId", params.runId);
|
|
1916
1875
|
}
|
|
1917
|
-
const
|
|
1876
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1918
1877
|
const response = await this.request(
|
|
1919
1878
|
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
1920
1879
|
{
|
|
1921
1880
|
method: "POST",
|
|
1922
1881
|
body: {
|
|
1923
1882
|
inputData: params.inputData,
|
|
1924
|
-
|
|
1883
|
+
requestContext,
|
|
1925
1884
|
closeOnSuspend: params.closeOnSuspend,
|
|
1926
1885
|
tracingOptions: params.tracingOptions
|
|
1927
1886
|
},
|
|
@@ -2009,30 +1968,30 @@ var Workflow = class extends BaseResource {
|
|
|
2009
1968
|
}
|
|
2010
1969
|
/**
|
|
2011
1970
|
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
2012
|
-
* @param params - Object containing the runId, step, resumeData and
|
|
1971
|
+
* @param params - Object containing the runId, step, resumeData and requestContext
|
|
2013
1972
|
* @returns Promise containing the workflow resume results
|
|
2014
1973
|
*/
|
|
2015
1974
|
resumeAsync(params) {
|
|
2016
|
-
const
|
|
1975
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2017
1976
|
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
2018
1977
|
method: "POST",
|
|
2019
1978
|
body: {
|
|
2020
1979
|
step: params.step,
|
|
2021
1980
|
resumeData: params.resumeData,
|
|
2022
|
-
|
|
1981
|
+
requestContext,
|
|
2023
1982
|
tracingOptions: params.tracingOptions
|
|
2024
1983
|
}
|
|
2025
1984
|
});
|
|
2026
1985
|
}
|
|
2027
1986
|
/**
|
|
2028
1987
|
* Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
|
|
2029
|
-
* @param params - Object containing the runId, step, resumeData and
|
|
1988
|
+
* @param params - Object containing the runId, step, resumeData and requestContext
|
|
2030
1989
|
* @returns Promise containing the workflow resume results
|
|
2031
1990
|
*/
|
|
2032
1991
|
async resumeStreamVNext(params) {
|
|
2033
1992
|
const searchParams = new URLSearchParams();
|
|
2034
1993
|
searchParams.set("runId", params.runId);
|
|
2035
|
-
const
|
|
1994
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2036
1995
|
const response = await this.request(
|
|
2037
1996
|
`/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
|
|
2038
1997
|
{
|
|
@@ -2040,7 +1999,7 @@ var Workflow = class extends BaseResource {
|
|
|
2040
1999
|
body: {
|
|
2041
2000
|
step: params.step,
|
|
2042
2001
|
resumeData: params.resumeData,
|
|
2043
|
-
|
|
2002
|
+
requestContext,
|
|
2044
2003
|
tracingOptions: params.tracingOptions
|
|
2045
2004
|
},
|
|
2046
2005
|
stream: true
|
|
@@ -2078,29 +2037,6 @@ var Workflow = class extends BaseResource {
|
|
|
2078
2037
|
});
|
|
2079
2038
|
return response.body.pipeThrough(transformStream);
|
|
2080
2039
|
}
|
|
2081
|
-
/**
|
|
2082
|
-
* Watches workflow transitions in real-time
|
|
2083
|
-
* @param runId - Optional run ID to filter the watch stream
|
|
2084
|
-
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
2085
|
-
*/
|
|
2086
|
-
async watch({ runId }, onRecord) {
|
|
2087
|
-
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
2088
|
-
stream: true
|
|
2089
|
-
});
|
|
2090
|
-
if (!response.ok) {
|
|
2091
|
-
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
2092
|
-
}
|
|
2093
|
-
if (!response.body) {
|
|
2094
|
-
throw new Error("Response body is null");
|
|
2095
|
-
}
|
|
2096
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
2097
|
-
if (typeof record === "string") {
|
|
2098
|
-
onRecord(JSON.parse(record));
|
|
2099
|
-
} else {
|
|
2100
|
-
onRecord(record);
|
|
2101
|
-
}
|
|
2102
|
-
}
|
|
2103
|
-
}
|
|
2104
2040
|
/**
|
|
2105
2041
|
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
2106
2042
|
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
@@ -2212,22 +2148,22 @@ var MCPTool = class extends BaseResource {
|
|
|
2212
2148
|
}
|
|
2213
2149
|
/**
|
|
2214
2150
|
* Retrieves details about this specific tool from the MCP server.
|
|
2215
|
-
* @param
|
|
2151
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2216
2152
|
* @returns Promise containing the tool's information (name, description, schema).
|
|
2217
2153
|
*/
|
|
2218
|
-
details(
|
|
2219
|
-
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${
|
|
2154
|
+
details(requestContext) {
|
|
2155
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${requestContextQueryString(requestContext)}`);
|
|
2220
2156
|
}
|
|
2221
2157
|
/**
|
|
2222
2158
|
* Executes this specific tool on the MCP server.
|
|
2223
|
-
* @param params - Parameters for tool execution, including data/args and optional
|
|
2159
|
+
* @param params - Parameters for tool execution, including data/args and optional requestContext.
|
|
2224
2160
|
* @returns Promise containing the result of the tool execution.
|
|
2225
2161
|
*/
|
|
2226
2162
|
execute(params) {
|
|
2227
2163
|
const body = {};
|
|
2228
2164
|
if (params.data !== void 0) body.data = params.data;
|
|
2229
|
-
if (params.
|
|
2230
|
-
body.
|
|
2165
|
+
if (params.requestContext !== void 0) {
|
|
2166
|
+
body.requestContext = params.requestContext;
|
|
2231
2167
|
}
|
|
2232
2168
|
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
|
|
2233
2169
|
method: "POST",
|
|
@@ -2273,19 +2209,39 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2273
2209
|
}
|
|
2274
2210
|
}
|
|
2275
2211
|
/**
|
|
2276
|
-
*
|
|
2277
|
-
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
2212
|
+
* Creates a transform stream that parses binary chunks into JSON records.
|
|
2278
2213
|
*/
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2214
|
+
createRecordParserTransform() {
|
|
2215
|
+
let failedChunk = void 0;
|
|
2216
|
+
return new TransformStream({
|
|
2217
|
+
start() {
|
|
2218
|
+
},
|
|
2219
|
+
async transform(chunk, controller) {
|
|
2220
|
+
try {
|
|
2221
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2222
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2223
|
+
for (const chunk2 of chunks) {
|
|
2224
|
+
if (chunk2) {
|
|
2225
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2226
|
+
try {
|
|
2227
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2228
|
+
controller.enqueue(parsedChunk);
|
|
2229
|
+
failedChunk = void 0;
|
|
2230
|
+
} catch {
|
|
2231
|
+
failedChunk = newChunk;
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
} catch {
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
});
|
|
2283
2239
|
}
|
|
2284
2240
|
/**
|
|
2285
2241
|
* Creates a new agent builder action run and returns the runId.
|
|
2286
2242
|
* This calls `/api/agent-builder/:actionId/create-run`.
|
|
2287
2243
|
*/
|
|
2288
|
-
async
|
|
2244
|
+
async createRun(params) {
|
|
2289
2245
|
const searchParams = new URLSearchParams();
|
|
2290
2246
|
if (!!params?.runId) {
|
|
2291
2247
|
searchParams.set("runId", params.runId);
|
|
@@ -2304,12 +2260,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2304
2260
|
if (runId) {
|
|
2305
2261
|
searchParams.set("runId", runId);
|
|
2306
2262
|
}
|
|
2307
|
-
const
|
|
2308
|
-
const {
|
|
2263
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2264
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2309
2265
|
const url = `/api/agent-builder/${this.actionId}/start-async${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2310
2266
|
const result = await this.request(url, {
|
|
2311
2267
|
method: "POST",
|
|
2312
|
-
body: { ...actionParams,
|
|
2268
|
+
body: { ...actionParams, requestContext }
|
|
2313
2269
|
});
|
|
2314
2270
|
return this.transformWorkflowResult(result);
|
|
2315
2271
|
}
|
|
@@ -2320,12 +2276,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2320
2276
|
async startActionRun(params, runId) {
|
|
2321
2277
|
const searchParams = new URLSearchParams();
|
|
2322
2278
|
searchParams.set("runId", runId);
|
|
2323
|
-
const
|
|
2324
|
-
const {
|
|
2279
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2280
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2325
2281
|
const url = `/api/agent-builder/${this.actionId}/start?${searchParams.toString()}`;
|
|
2326
2282
|
return this.request(url, {
|
|
2327
2283
|
method: "POST",
|
|
2328
|
-
body: { ...actionParams,
|
|
2284
|
+
body: { ...actionParams, requestContext }
|
|
2329
2285
|
});
|
|
2330
2286
|
}
|
|
2331
2287
|
/**
|
|
@@ -2335,12 +2291,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2335
2291
|
async resume(params, runId) {
|
|
2336
2292
|
const searchParams = new URLSearchParams();
|
|
2337
2293
|
searchParams.set("runId", runId);
|
|
2338
|
-
const
|
|
2339
|
-
const {
|
|
2294
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2295
|
+
const { requestContext: _, ...resumeParams } = params;
|
|
2340
2296
|
const url = `/api/agent-builder/${this.actionId}/resume?${searchParams.toString()}`;
|
|
2341
2297
|
return this.request(url, {
|
|
2342
2298
|
method: "POST",
|
|
2343
|
-
body: { ...resumeParams,
|
|
2299
|
+
body: { ...resumeParams, requestContext }
|
|
2344
2300
|
});
|
|
2345
2301
|
}
|
|
2346
2302
|
/**
|
|
@@ -2350,12 +2306,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2350
2306
|
async resumeAsync(params, runId) {
|
|
2351
2307
|
const searchParams = new URLSearchParams();
|
|
2352
2308
|
searchParams.set("runId", runId);
|
|
2353
|
-
const
|
|
2354
|
-
const {
|
|
2309
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2310
|
+
const { requestContext: _, ...resumeParams } = params;
|
|
2355
2311
|
const url = `/api/agent-builder/${this.actionId}/resume-async?${searchParams.toString()}`;
|
|
2356
2312
|
const result = await this.request(url, {
|
|
2357
2313
|
method: "POST",
|
|
2358
|
-
body: { ...resumeParams,
|
|
2314
|
+
body: { ...resumeParams, requestContext }
|
|
2359
2315
|
});
|
|
2360
2316
|
return this.transformWorkflowResult(result);
|
|
2361
2317
|
}
|
|
@@ -2413,12 +2369,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2413
2369
|
if (runId) {
|
|
2414
2370
|
searchParams.set("runId", runId);
|
|
2415
2371
|
}
|
|
2416
|
-
const
|
|
2417
|
-
const {
|
|
2372
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2373
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2418
2374
|
const url = `/api/agent-builder/${this.actionId}/stream${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2419
2375
|
const response = await this.request(url, {
|
|
2420
2376
|
method: "POST",
|
|
2421
|
-
body: { ...actionParams,
|
|
2377
|
+
body: { ...actionParams, requestContext },
|
|
2422
2378
|
stream: true
|
|
2423
2379
|
});
|
|
2424
2380
|
if (!response.ok) {
|
|
@@ -2427,31 +2383,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2427
2383
|
if (!response.body) {
|
|
2428
2384
|
throw new Error("Response body is null");
|
|
2429
2385
|
}
|
|
2430
|
-
|
|
2431
|
-
const transformStream = new TransformStream({
|
|
2432
|
-
start() {
|
|
2433
|
-
},
|
|
2434
|
-
async transform(chunk, controller) {
|
|
2435
|
-
try {
|
|
2436
|
-
const decoded = new TextDecoder().decode(chunk);
|
|
2437
|
-
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2438
|
-
for (const chunk2 of chunks) {
|
|
2439
|
-
if (chunk2) {
|
|
2440
|
-
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2441
|
-
try {
|
|
2442
|
-
const parsedChunk = JSON.parse(newChunk);
|
|
2443
|
-
controller.enqueue(parsedChunk);
|
|
2444
|
-
failedChunk = void 0;
|
|
2445
|
-
} catch {
|
|
2446
|
-
failedChunk = newChunk;
|
|
2447
|
-
}
|
|
2448
|
-
}
|
|
2449
|
-
}
|
|
2450
|
-
} catch {
|
|
2451
|
-
}
|
|
2452
|
-
}
|
|
2453
|
-
});
|
|
2454
|
-
return response.body.pipeThrough(transformStream);
|
|
2386
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2455
2387
|
}
|
|
2456
2388
|
/**
|
|
2457
2389
|
* Streams agent builder action progress in real-time using VNext streaming.
|
|
@@ -2462,12 +2394,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2462
2394
|
if (runId) {
|
|
2463
2395
|
searchParams.set("runId", runId);
|
|
2464
2396
|
}
|
|
2465
|
-
const
|
|
2466
|
-
const {
|
|
2397
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2398
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2467
2399
|
const url = `/api/agent-builder/${this.actionId}/streamVNext${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2468
2400
|
const response = await this.request(url, {
|
|
2469
2401
|
method: "POST",
|
|
2470
|
-
body: { ...actionParams,
|
|
2402
|
+
body: { ...actionParams, requestContext },
|
|
2471
2403
|
stream: true
|
|
2472
2404
|
});
|
|
2473
2405
|
if (!response.ok) {
|
|
@@ -2476,57 +2408,94 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2476
2408
|
if (!response.body) {
|
|
2477
2409
|
throw new Error("Response body is null");
|
|
2478
2410
|
}
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
} catch {
|
|
2495
|
-
failedChunk = newChunk;
|
|
2496
|
-
}
|
|
2497
|
-
}
|
|
2498
|
-
}
|
|
2499
|
-
} catch {
|
|
2500
|
-
}
|
|
2501
|
-
}
|
|
2411
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2412
|
+
}
|
|
2413
|
+
/**
|
|
2414
|
+
* Observes an existing agent builder action run stream.
|
|
2415
|
+
* Replays cached execution from the beginning, then continues with live stream.
|
|
2416
|
+
* This is the recommended method for recovery after page refresh/hot reload.
|
|
2417
|
+
* This calls `/api/agent-builder/:actionId/observe` (which delegates to observeStreamVNext).
|
|
2418
|
+
*/
|
|
2419
|
+
async observeStream(params) {
|
|
2420
|
+
const searchParams = new URLSearchParams();
|
|
2421
|
+
searchParams.set("runId", params.runId);
|
|
2422
|
+
const url = `/api/agent-builder/${this.actionId}/observe?${searchParams.toString()}`;
|
|
2423
|
+
const response = await this.request(url, {
|
|
2424
|
+
method: "POST",
|
|
2425
|
+
stream: true
|
|
2502
2426
|
});
|
|
2503
|
-
|
|
2427
|
+
if (!response.ok) {
|
|
2428
|
+
throw new Error(`Failed to observe agent builder action stream: ${response.statusText}`);
|
|
2429
|
+
}
|
|
2430
|
+
if (!response.body) {
|
|
2431
|
+
throw new Error("Response body is null");
|
|
2432
|
+
}
|
|
2433
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2434
|
+
}
|
|
2435
|
+
/**
|
|
2436
|
+
* Observes an existing agent builder action run stream using VNext streaming API.
|
|
2437
|
+
* Replays cached execution from the beginning, then continues with live stream.
|
|
2438
|
+
* This calls `/api/agent-builder/:actionId/observe-streamVNext`.
|
|
2439
|
+
*/
|
|
2440
|
+
async observeStreamVNext(params) {
|
|
2441
|
+
const searchParams = new URLSearchParams();
|
|
2442
|
+
searchParams.set("runId", params.runId);
|
|
2443
|
+
const url = `/api/agent-builder/${this.actionId}/observe-streamVNext?${searchParams.toString()}`;
|
|
2444
|
+
const response = await this.request(url, {
|
|
2445
|
+
method: "POST",
|
|
2446
|
+
stream: true
|
|
2447
|
+
});
|
|
2448
|
+
if (!response.ok) {
|
|
2449
|
+
throw new Error(`Failed to observe agent builder action stream VNext: ${response.statusText}`);
|
|
2450
|
+
}
|
|
2451
|
+
if (!response.body) {
|
|
2452
|
+
throw new Error("Response body is null");
|
|
2453
|
+
}
|
|
2454
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2504
2455
|
}
|
|
2505
2456
|
/**
|
|
2506
|
-
*
|
|
2507
|
-
*
|
|
2508
|
-
*
|
|
2509
|
-
* This calls `/api/agent-builder/:actionId/watch`.
|
|
2457
|
+
* Observes an existing agent builder action run stream using legacy streaming API.
|
|
2458
|
+
* Replays cached execution from the beginning, then continues with live stream.
|
|
2459
|
+
* This calls `/api/agent-builder/:actionId/observe-stream-legacy`.
|
|
2510
2460
|
*/
|
|
2511
|
-
async
|
|
2512
|
-
const
|
|
2461
|
+
async observeStreamLegacy(params) {
|
|
2462
|
+
const searchParams = new URLSearchParams();
|
|
2463
|
+
searchParams.set("runId", params.runId);
|
|
2464
|
+
const url = `/api/agent-builder/${this.actionId}/observe-stream-legacy?${searchParams.toString()}`;
|
|
2513
2465
|
const response = await this.request(url, {
|
|
2514
|
-
method: "
|
|
2466
|
+
method: "POST",
|
|
2515
2467
|
stream: true
|
|
2516
2468
|
});
|
|
2517
2469
|
if (!response.ok) {
|
|
2518
|
-
throw new Error(`Failed to
|
|
2470
|
+
throw new Error(`Failed to observe agent builder action stream legacy: ${response.statusText}`);
|
|
2519
2471
|
}
|
|
2520
2472
|
if (!response.body) {
|
|
2521
2473
|
throw new Error("Response body is null");
|
|
2522
2474
|
}
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2475
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2476
|
+
}
|
|
2477
|
+
/**
|
|
2478
|
+
* Resumes a suspended agent builder action and streams the results.
|
|
2479
|
+
* This calls `/api/agent-builder/:actionId/resume-stream`.
|
|
2480
|
+
*/
|
|
2481
|
+
async resumeStream(params) {
|
|
2482
|
+
const searchParams = new URLSearchParams();
|
|
2483
|
+
searchParams.set("runId", params.runId);
|
|
2484
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2485
|
+
const { runId: _, requestContext: __, ...resumeParams } = params;
|
|
2486
|
+
const url = `/api/agent-builder/${this.actionId}/resume-stream?${searchParams.toString()}`;
|
|
2487
|
+
const response = await this.request(url, {
|
|
2488
|
+
method: "POST",
|
|
2489
|
+
body: { ...resumeParams, requestContext },
|
|
2490
|
+
stream: true
|
|
2491
|
+
});
|
|
2492
|
+
if (!response.ok) {
|
|
2493
|
+
throw new Error(`Failed to resume agent builder action stream: ${response.statusText}`);
|
|
2494
|
+
}
|
|
2495
|
+
if (!response.body) {
|
|
2496
|
+
throw new Error("Response body is null");
|
|
2529
2497
|
}
|
|
2498
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2530
2499
|
}
|
|
2531
2500
|
/**
|
|
2532
2501
|
* Gets a specific action run by its ID.
|
|
@@ -2558,11 +2527,11 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2558
2527
|
if (params?.toDate) {
|
|
2559
2528
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
2560
2529
|
}
|
|
2561
|
-
if (params?.
|
|
2562
|
-
searchParams.set("
|
|
2530
|
+
if (params?.perPage !== void 0) {
|
|
2531
|
+
searchParams.set("perPage", String(params.perPage));
|
|
2563
2532
|
}
|
|
2564
|
-
if (params?.
|
|
2565
|
-
searchParams.set("
|
|
2533
|
+
if (params?.page !== void 0) {
|
|
2534
|
+
searchParams.set("page", String(params.page));
|
|
2566
2535
|
}
|
|
2567
2536
|
if (params?.resourceId) {
|
|
2568
2537
|
searchParams.set("resourceId", params.resourceId);
|
|
@@ -2592,17 +2561,6 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2592
2561
|
method: "POST"
|
|
2593
2562
|
});
|
|
2594
2563
|
}
|
|
2595
|
-
/**
|
|
2596
|
-
* Sends an event to an agent builder action run.
|
|
2597
|
-
* This calls `/api/agent-builder/:actionId/runs/:runId/send-event`.
|
|
2598
|
-
*/
|
|
2599
|
-
async sendRunEvent(params) {
|
|
2600
|
-
const url = `/api/agent-builder/${this.actionId}/runs/${params.runId}/send-event`;
|
|
2601
|
-
return this.request(url, {
|
|
2602
|
-
method: "POST",
|
|
2603
|
-
body: { event: params.event, data: params.data }
|
|
2604
|
-
});
|
|
2605
|
-
}
|
|
2606
2564
|
};
|
|
2607
2565
|
|
|
2608
2566
|
// src/resources/observability.ts
|
|
@@ -2611,15 +2569,15 @@ var Observability = class extends BaseResource {
|
|
|
2611
2569
|
super(options);
|
|
2612
2570
|
}
|
|
2613
2571
|
/**
|
|
2614
|
-
* Retrieves a specific
|
|
2572
|
+
* Retrieves a specific trace by ID
|
|
2615
2573
|
* @param traceId - ID of the trace to retrieve
|
|
2616
|
-
* @returns Promise containing the
|
|
2574
|
+
* @returns Promise containing the trace with all its spans
|
|
2617
2575
|
*/
|
|
2618
2576
|
getTrace(traceId) {
|
|
2619
2577
|
return this.request(`/api/observability/traces/${traceId}`);
|
|
2620
2578
|
}
|
|
2621
2579
|
/**
|
|
2622
|
-
* Retrieves paginated list of
|
|
2580
|
+
* Retrieves paginated list of traces with optional filtering
|
|
2623
2581
|
* @param params - Parameters for pagination and filtering
|
|
2624
2582
|
* @returns Promise containing paginated traces and pagination info
|
|
2625
2583
|
*/
|
|
@@ -2659,7 +2617,7 @@ var Observability = class extends BaseResource {
|
|
|
2659
2617
|
* @param params - Parameters containing trace ID, span ID, and pagination options
|
|
2660
2618
|
* @returns Promise containing scores and pagination info
|
|
2661
2619
|
*/
|
|
2662
|
-
|
|
2620
|
+
listScoresBySpan(params) {
|
|
2663
2621
|
const { traceId, spanId, page, perPage } = params;
|
|
2664
2622
|
const searchParams = new URLSearchParams();
|
|
2665
2623
|
if (page !== void 0) {
|
|
@@ -2681,69 +2639,6 @@ var Observability = class extends BaseResource {
|
|
|
2681
2639
|
}
|
|
2682
2640
|
};
|
|
2683
2641
|
|
|
2684
|
-
// src/resources/network-memory-thread.ts
|
|
2685
|
-
var NetworkMemoryThread = class extends BaseResource {
|
|
2686
|
-
constructor(options, threadId, networkId) {
|
|
2687
|
-
super(options);
|
|
2688
|
-
this.threadId = threadId;
|
|
2689
|
-
this.networkId = networkId;
|
|
2690
|
-
}
|
|
2691
|
-
/**
|
|
2692
|
-
* Retrieves the memory thread details
|
|
2693
|
-
* @returns Promise containing thread details including title and metadata
|
|
2694
|
-
*/
|
|
2695
|
-
get() {
|
|
2696
|
-
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
2697
|
-
}
|
|
2698
|
-
/**
|
|
2699
|
-
* Updates the memory thread properties
|
|
2700
|
-
* @param params - Update parameters including title and metadata
|
|
2701
|
-
* @returns Promise containing updated thread details
|
|
2702
|
-
*/
|
|
2703
|
-
update(params) {
|
|
2704
|
-
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
2705
|
-
method: "PATCH",
|
|
2706
|
-
body: params
|
|
2707
|
-
});
|
|
2708
|
-
}
|
|
2709
|
-
/**
|
|
2710
|
-
* Deletes the memory thread
|
|
2711
|
-
* @returns Promise containing deletion result
|
|
2712
|
-
*/
|
|
2713
|
-
delete() {
|
|
2714
|
-
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
2715
|
-
method: "DELETE"
|
|
2716
|
-
});
|
|
2717
|
-
}
|
|
2718
|
-
/**
|
|
2719
|
-
* Retrieves messages associated with the thread
|
|
2720
|
-
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
2721
|
-
* @returns Promise containing thread messages and UI messages
|
|
2722
|
-
*/
|
|
2723
|
-
getMessages(params) {
|
|
2724
|
-
const query = new URLSearchParams({
|
|
2725
|
-
networkId: this.networkId,
|
|
2726
|
-
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
2727
|
-
});
|
|
2728
|
-
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
2729
|
-
}
|
|
2730
|
-
/**
|
|
2731
|
-
* Deletes one or more messages from the thread
|
|
2732
|
-
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
2733
|
-
* message object with id property, or array of message objects
|
|
2734
|
-
* @returns Promise containing deletion result
|
|
2735
|
-
*/
|
|
2736
|
-
deleteMessages(messageIds) {
|
|
2737
|
-
const query = new URLSearchParams({
|
|
2738
|
-
networkId: this.networkId
|
|
2739
|
-
});
|
|
2740
|
-
return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
|
|
2741
|
-
method: "POST",
|
|
2742
|
-
body: { messageIds }
|
|
2743
|
-
});
|
|
2744
|
-
}
|
|
2745
|
-
};
|
|
2746
|
-
|
|
2747
2642
|
// src/client.ts
|
|
2748
2643
|
var MastraClient = class extends BaseResource {
|
|
2749
2644
|
observability;
|
|
@@ -2753,18 +2648,21 @@ var MastraClient = class extends BaseResource {
|
|
|
2753
2648
|
}
|
|
2754
2649
|
/**
|
|
2755
2650
|
* Retrieves all available agents
|
|
2756
|
-
* @param
|
|
2651
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2757
2652
|
* @returns Promise containing map of agent IDs to agent details
|
|
2758
2653
|
*/
|
|
2759
|
-
|
|
2760
|
-
const
|
|
2654
|
+
listAgents(requestContext) {
|
|
2655
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2761
2656
|
const searchParams = new URLSearchParams();
|
|
2762
|
-
if (
|
|
2763
|
-
searchParams.set("
|
|
2657
|
+
if (requestContextParam) {
|
|
2658
|
+
searchParams.set("requestContext", requestContextParam);
|
|
2764
2659
|
}
|
|
2765
2660
|
const queryString = searchParams.toString();
|
|
2766
2661
|
return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
|
|
2767
2662
|
}
|
|
2663
|
+
listAgentsModelProviders() {
|
|
2664
|
+
return this.request(`/api/agents/providers`);
|
|
2665
|
+
}
|
|
2768
2666
|
/**
|
|
2769
2667
|
* Gets an agent instance by ID
|
|
2770
2668
|
* @param agentId - ID of the agent to retrieve
|
|
@@ -2774,125 +2672,107 @@ var MastraClient = class extends BaseResource {
|
|
|
2774
2672
|
return new Agent(this.options, agentId);
|
|
2775
2673
|
}
|
|
2776
2674
|
/**
|
|
2777
|
-
*
|
|
2778
|
-
* @param params - Parameters containing
|
|
2779
|
-
* @returns Promise containing array of memory threads
|
|
2675
|
+
* Lists memory threads for a resource with pagination support
|
|
2676
|
+
* @param params - Parameters containing resource ID, pagination options, and optional request context
|
|
2677
|
+
* @returns Promise containing paginated array of memory threads with metadata
|
|
2780
2678
|
*/
|
|
2781
|
-
|
|
2782
|
-
|
|
2679
|
+
listMemoryThreads(params) {
|
|
2680
|
+
const queryParams = new URLSearchParams({
|
|
2681
|
+
resourceId: params.resourceId,
|
|
2682
|
+
resourceid: params.resourceId,
|
|
2683
|
+
agentId: params.agentId,
|
|
2684
|
+
...params.page !== void 0 && { page: params.page.toString() },
|
|
2685
|
+
...params.perPage !== void 0 && { perPage: params.perPage.toString() },
|
|
2686
|
+
...params.orderBy && { orderBy: params.orderBy },
|
|
2687
|
+
...params.sortDirection && { sortDirection: params.sortDirection }
|
|
2688
|
+
});
|
|
2689
|
+
return this.request(
|
|
2690
|
+
`/api/memory/threads?${queryParams.toString()}${requestContextQueryString(params.requestContext, "&")}`
|
|
2691
|
+
);
|
|
2783
2692
|
}
|
|
2784
2693
|
/**
|
|
2785
2694
|
* Retrieves memory config for a resource
|
|
2786
|
-
* @param params - Parameters containing the resource ID
|
|
2787
|
-
* @returns Promise containing
|
|
2695
|
+
* @param params - Parameters containing the resource ID and optional request context
|
|
2696
|
+
* @returns Promise containing memory configuration
|
|
2788
2697
|
*/
|
|
2789
2698
|
getMemoryConfig(params) {
|
|
2790
|
-
return this.request(
|
|
2699
|
+
return this.request(
|
|
2700
|
+
`/api/memory/config?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`
|
|
2701
|
+
);
|
|
2791
2702
|
}
|
|
2792
2703
|
/**
|
|
2793
2704
|
* Creates a new memory thread
|
|
2794
|
-
* @param params - Parameters for creating the memory thread
|
|
2705
|
+
* @param params - Parameters for creating the memory thread including optional request context
|
|
2795
2706
|
* @returns Promise containing the created memory thread
|
|
2796
2707
|
*/
|
|
2797
2708
|
createMemoryThread(params) {
|
|
2798
|
-
return this.request(
|
|
2709
|
+
return this.request(
|
|
2710
|
+
`/api/memory/threads?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`,
|
|
2711
|
+
{ method: "POST", body: params }
|
|
2712
|
+
);
|
|
2799
2713
|
}
|
|
2800
2714
|
/**
|
|
2801
2715
|
* Gets a memory thread instance by ID
|
|
2802
2716
|
* @param threadId - ID of the memory thread to retrieve
|
|
2803
2717
|
* @returns MemoryThread instance
|
|
2804
2718
|
*/
|
|
2805
|
-
getMemoryThread(threadId, agentId) {
|
|
2719
|
+
getMemoryThread({ threadId, agentId }) {
|
|
2806
2720
|
return new MemoryThread(this.options, threadId, agentId);
|
|
2807
2721
|
}
|
|
2808
|
-
|
|
2722
|
+
listThreadMessages(threadId, opts = {}) {
|
|
2723
|
+
if (!opts.agentId && !opts.networkId) {
|
|
2724
|
+
throw new Error("Either agentId or networkId must be provided");
|
|
2725
|
+
}
|
|
2809
2726
|
let url = "";
|
|
2810
2727
|
if (opts.agentId) {
|
|
2811
|
-
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
|
|
2728
|
+
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2812
2729
|
} else if (opts.networkId) {
|
|
2813
|
-
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
|
|
2730
|
+
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2814
2731
|
}
|
|
2815
2732
|
return this.request(url);
|
|
2816
2733
|
}
|
|
2817
2734
|
deleteThread(threadId, opts = {}) {
|
|
2818
2735
|
let url = "";
|
|
2819
2736
|
if (opts.agentId) {
|
|
2820
|
-
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
|
|
2737
|
+
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2821
2738
|
} else if (opts.networkId) {
|
|
2822
|
-
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
|
|
2739
|
+
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2823
2740
|
}
|
|
2824
2741
|
return this.request(url, { method: "DELETE" });
|
|
2825
2742
|
}
|
|
2826
2743
|
/**
|
|
2827
2744
|
* Saves messages to memory
|
|
2828
|
-
* @param params - Parameters containing messages to save
|
|
2745
|
+
* @param params - Parameters containing messages to save and optional request context
|
|
2829
2746
|
* @returns Promise containing the saved messages
|
|
2830
2747
|
*/
|
|
2831
2748
|
saveMessageToMemory(params) {
|
|
2832
|
-
return this.request(
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
* @returns Promise containing memory system status
|
|
2840
|
-
*/
|
|
2841
|
-
getMemoryStatus(agentId) {
|
|
2842
|
-
return this.request(`/api/memory/status?agentId=${agentId}`);
|
|
2843
|
-
}
|
|
2844
|
-
/**
|
|
2845
|
-
* Retrieves memory threads for a resource
|
|
2846
|
-
* @param params - Parameters containing the resource ID
|
|
2847
|
-
* @returns Promise containing array of memory threads
|
|
2848
|
-
*/
|
|
2849
|
-
getNetworkMemoryThreads(params) {
|
|
2850
|
-
return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
|
|
2851
|
-
}
|
|
2852
|
-
/**
|
|
2853
|
-
* Creates a new memory thread
|
|
2854
|
-
* @param params - Parameters for creating the memory thread
|
|
2855
|
-
* @returns Promise containing the created memory thread
|
|
2856
|
-
*/
|
|
2857
|
-
createNetworkMemoryThread(params) {
|
|
2858
|
-
return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: "POST", body: params });
|
|
2859
|
-
}
|
|
2860
|
-
/**
|
|
2861
|
-
* Gets a memory thread instance by ID
|
|
2862
|
-
* @param threadId - ID of the memory thread to retrieve
|
|
2863
|
-
* @returns MemoryThread instance
|
|
2864
|
-
*/
|
|
2865
|
-
getNetworkMemoryThread(threadId, networkId) {
|
|
2866
|
-
return new NetworkMemoryThread(this.options, threadId, networkId);
|
|
2867
|
-
}
|
|
2868
|
-
/**
|
|
2869
|
-
* Saves messages to memory
|
|
2870
|
-
* @param params - Parameters containing messages to save
|
|
2871
|
-
* @returns Promise containing the saved messages
|
|
2872
|
-
*/
|
|
2873
|
-
saveNetworkMessageToMemory(params) {
|
|
2874
|
-
return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
|
|
2875
|
-
method: "POST",
|
|
2876
|
-
body: params
|
|
2877
|
-
});
|
|
2749
|
+
return this.request(
|
|
2750
|
+
`/api/memory/save-messages?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`,
|
|
2751
|
+
{
|
|
2752
|
+
method: "POST",
|
|
2753
|
+
body: params
|
|
2754
|
+
}
|
|
2755
|
+
);
|
|
2878
2756
|
}
|
|
2879
2757
|
/**
|
|
2880
2758
|
* Gets the status of the memory system
|
|
2759
|
+
* @param agentId - The agent ID
|
|
2760
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2881
2761
|
* @returns Promise containing memory system status
|
|
2882
2762
|
*/
|
|
2883
|
-
|
|
2884
|
-
return this.request(`/api/memory/
|
|
2763
|
+
getMemoryStatus(agentId, requestContext) {
|
|
2764
|
+
return this.request(`/api/memory/status?agentId=${agentId}${requestContextQueryString(requestContext, "&")}`);
|
|
2885
2765
|
}
|
|
2886
2766
|
/**
|
|
2887
2767
|
* Retrieves all available tools
|
|
2888
|
-
* @param
|
|
2768
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2889
2769
|
* @returns Promise containing map of tool IDs to tool details
|
|
2890
2770
|
*/
|
|
2891
|
-
|
|
2892
|
-
const
|
|
2771
|
+
listTools(requestContext) {
|
|
2772
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2893
2773
|
const searchParams = new URLSearchParams();
|
|
2894
|
-
if (
|
|
2895
|
-
searchParams.set("
|
|
2774
|
+
if (requestContextParam) {
|
|
2775
|
+
searchParams.set("requestContext", requestContextParam);
|
|
2896
2776
|
}
|
|
2897
2777
|
const queryString = searchParams.toString();
|
|
2898
2778
|
return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
|
|
@@ -2907,14 +2787,14 @@ var MastraClient = class extends BaseResource {
|
|
|
2907
2787
|
}
|
|
2908
2788
|
/**
|
|
2909
2789
|
* Retrieves all available workflows
|
|
2910
|
-
* @param
|
|
2790
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2911
2791
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
2912
2792
|
*/
|
|
2913
|
-
|
|
2914
|
-
const
|
|
2793
|
+
listWorkflows(requestContext) {
|
|
2794
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2915
2795
|
const searchParams = new URLSearchParams();
|
|
2916
|
-
if (
|
|
2917
|
-
searchParams.set("
|
|
2796
|
+
if (requestContextParam) {
|
|
2797
|
+
searchParams.set("requestContext", requestContextParam);
|
|
2918
2798
|
}
|
|
2919
2799
|
const queryString = searchParams.toString();
|
|
2920
2800
|
return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
|
|
@@ -2954,7 +2834,7 @@ var MastraClient = class extends BaseResource {
|
|
|
2954
2834
|
* @param params - Parameters for filtering logs
|
|
2955
2835
|
* @returns Promise containing array of log messages
|
|
2956
2836
|
*/
|
|
2957
|
-
|
|
2837
|
+
listLogs(params) {
|
|
2958
2838
|
const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
2959
2839
|
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
2960
2840
|
const searchParams = new URLSearchParams();
|
|
@@ -3040,63 +2920,21 @@ var MastraClient = class extends BaseResource {
|
|
|
3040
2920
|
* List of all log transports
|
|
3041
2921
|
* @returns Promise containing list of log transports
|
|
3042
2922
|
*/
|
|
3043
|
-
|
|
2923
|
+
listLogTransports() {
|
|
3044
2924
|
return this.request("/api/logs/transports");
|
|
3045
2925
|
}
|
|
3046
|
-
/**
|
|
3047
|
-
* List of all traces (paged)
|
|
3048
|
-
* @param params - Parameters for filtering traces
|
|
3049
|
-
* @returns Promise containing telemetry data
|
|
3050
|
-
*/
|
|
3051
|
-
getTelemetry(params) {
|
|
3052
|
-
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
3053
|
-
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
3054
|
-
const searchParams = new URLSearchParams();
|
|
3055
|
-
if (name) {
|
|
3056
|
-
searchParams.set("name", name);
|
|
3057
|
-
}
|
|
3058
|
-
if (scope) {
|
|
3059
|
-
searchParams.set("scope", scope);
|
|
3060
|
-
}
|
|
3061
|
-
if (page) {
|
|
3062
|
-
searchParams.set("page", String(page));
|
|
3063
|
-
}
|
|
3064
|
-
if (perPage) {
|
|
3065
|
-
searchParams.set("perPage", String(perPage));
|
|
3066
|
-
}
|
|
3067
|
-
if (_attribute) {
|
|
3068
|
-
if (Array.isArray(_attribute)) {
|
|
3069
|
-
for (const attr of _attribute) {
|
|
3070
|
-
searchParams.append("attribute", attr);
|
|
3071
|
-
}
|
|
3072
|
-
} else {
|
|
3073
|
-
searchParams.set("attribute", _attribute);
|
|
3074
|
-
}
|
|
3075
|
-
}
|
|
3076
|
-
if (fromDate) {
|
|
3077
|
-
searchParams.set("fromDate", fromDate.toISOString());
|
|
3078
|
-
}
|
|
3079
|
-
if (toDate) {
|
|
3080
|
-
searchParams.set("toDate", toDate.toISOString());
|
|
3081
|
-
}
|
|
3082
|
-
if (searchParams.size) {
|
|
3083
|
-
return this.request(`/api/telemetry?${searchParams}`);
|
|
3084
|
-
} else {
|
|
3085
|
-
return this.request(`/api/telemetry`);
|
|
3086
|
-
}
|
|
3087
|
-
}
|
|
3088
2926
|
/**
|
|
3089
2927
|
* Retrieves a list of available MCP servers.
|
|
3090
|
-
* @param params - Optional parameters for pagination (
|
|
2928
|
+
* @param params - Optional parameters for pagination (perPage, page).
|
|
3091
2929
|
* @returns Promise containing the list of MCP servers and pagination info.
|
|
3092
2930
|
*/
|
|
3093
2931
|
getMcpServers(params) {
|
|
3094
2932
|
const searchParams = new URLSearchParams();
|
|
3095
|
-
if (params?.
|
|
3096
|
-
searchParams.set("
|
|
2933
|
+
if (params?.perPage !== void 0) {
|
|
2934
|
+
searchParams.set("perPage", String(params.perPage));
|
|
3097
2935
|
}
|
|
3098
|
-
if (params?.
|
|
3099
|
-
searchParams.set("
|
|
2936
|
+
if (params?.page !== void 0) {
|
|
2937
|
+
searchParams.set("page", String(params.page));
|
|
3100
2938
|
}
|
|
3101
2939
|
const queryString = searchParams.toString();
|
|
3102
2940
|
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
|
|
@@ -3151,9 +2989,33 @@ var MastraClient = class extends BaseResource {
|
|
|
3151
2989
|
getWorkingMemory({
|
|
3152
2990
|
agentId,
|
|
3153
2991
|
threadId,
|
|
3154
|
-
resourceId
|
|
2992
|
+
resourceId,
|
|
2993
|
+
requestContext
|
|
2994
|
+
}) {
|
|
2995
|
+
return this.request(
|
|
2996
|
+
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}${requestContextQueryString(requestContext, "&")}`
|
|
2997
|
+
);
|
|
2998
|
+
}
|
|
2999
|
+
searchMemory({
|
|
3000
|
+
agentId,
|
|
3001
|
+
resourceId,
|
|
3002
|
+
threadId,
|
|
3003
|
+
searchQuery,
|
|
3004
|
+
memoryConfig,
|
|
3005
|
+
requestContext
|
|
3155
3006
|
}) {
|
|
3156
|
-
|
|
3007
|
+
const params = new URLSearchParams({
|
|
3008
|
+
searchQuery,
|
|
3009
|
+
resourceId,
|
|
3010
|
+
agentId
|
|
3011
|
+
});
|
|
3012
|
+
if (threadId) {
|
|
3013
|
+
params.append("threadId", threadId);
|
|
3014
|
+
}
|
|
3015
|
+
if (memoryConfig) {
|
|
3016
|
+
params.append("memoryConfig", JSON.stringify(memoryConfig));
|
|
3017
|
+
}
|
|
3018
|
+
return this.request(`/api/memory/search?${params}${requestContextQueryString(requestContext, "&")}`);
|
|
3157
3019
|
}
|
|
3158
3020
|
/**
|
|
3159
3021
|
* Updates the working memory for a specific thread (optionally resource-scoped).
|
|
@@ -3166,21 +3028,25 @@ var MastraClient = class extends BaseResource {
|
|
|
3166
3028
|
agentId,
|
|
3167
3029
|
threadId,
|
|
3168
3030
|
workingMemory,
|
|
3169
|
-
resourceId
|
|
3031
|
+
resourceId,
|
|
3032
|
+
requestContext
|
|
3170
3033
|
}) {
|
|
3171
|
-
return this.request(
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3034
|
+
return this.request(
|
|
3035
|
+
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}${requestContextQueryString(requestContext, "&")}`,
|
|
3036
|
+
{
|
|
3037
|
+
method: "POST",
|
|
3038
|
+
body: {
|
|
3039
|
+
workingMemory,
|
|
3040
|
+
resourceId
|
|
3041
|
+
}
|
|
3176
3042
|
}
|
|
3177
|
-
|
|
3043
|
+
);
|
|
3178
3044
|
}
|
|
3179
3045
|
/**
|
|
3180
3046
|
* Retrieves all available scorers
|
|
3181
3047
|
* @returns Promise containing list of available scorers
|
|
3182
3048
|
*/
|
|
3183
|
-
|
|
3049
|
+
listScorers() {
|
|
3184
3050
|
return this.request("/api/scores/scorers");
|
|
3185
3051
|
}
|
|
3186
3052
|
/**
|
|
@@ -3191,7 +3057,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3191
3057
|
getScorer(scorerId) {
|
|
3192
3058
|
return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
|
|
3193
3059
|
}
|
|
3194
|
-
|
|
3060
|
+
listScoresByScorerId(params) {
|
|
3195
3061
|
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
3196
3062
|
const searchParams = new URLSearchParams();
|
|
3197
3063
|
if (entityId) {
|
|
@@ -3214,7 +3080,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3214
3080
|
* @param params - Parameters containing run ID and pagination options
|
|
3215
3081
|
* @returns Promise containing scores and pagination info
|
|
3216
3082
|
*/
|
|
3217
|
-
|
|
3083
|
+
listScoresByRunId(params) {
|
|
3218
3084
|
const { runId, page, perPage } = params;
|
|
3219
3085
|
const searchParams = new URLSearchParams();
|
|
3220
3086
|
if (page !== void 0) {
|
|
@@ -3231,7 +3097,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3231
3097
|
* @param params - Parameters containing entity ID, type, and pagination options
|
|
3232
3098
|
* @returns Promise containing scores and pagination info
|
|
3233
3099
|
*/
|
|
3234
|
-
|
|
3100
|
+
listScoresByEntityId(params) {
|
|
3235
3101
|
const { entityId, entityType, page, perPage } = params;
|
|
3236
3102
|
const searchParams = new URLSearchParams();
|
|
3237
3103
|
if (page !== void 0) {
|
|
@@ -3256,21 +3122,14 @@ var MastraClient = class extends BaseResource {
|
|
|
3256
3122
|
body: params
|
|
3257
3123
|
});
|
|
3258
3124
|
}
|
|
3259
|
-
|
|
3260
|
-
* Retrieves model providers with available keys
|
|
3261
|
-
* @returns Promise containing model providers with available keys
|
|
3262
|
-
*/
|
|
3263
|
-
getModelProviders() {
|
|
3264
|
-
return this.request(`/api/model-providers`);
|
|
3265
|
-
}
|
|
3266
|
-
getAITrace(traceId) {
|
|
3125
|
+
getTrace(traceId) {
|
|
3267
3126
|
return this.observability.getTrace(traceId);
|
|
3268
3127
|
}
|
|
3269
|
-
|
|
3128
|
+
getTraces(params) {
|
|
3270
3129
|
return this.observability.getTraces(params);
|
|
3271
3130
|
}
|
|
3272
|
-
|
|
3273
|
-
return this.observability.
|
|
3131
|
+
listScoresBySpan(params) {
|
|
3132
|
+
return this.observability.listScoresBySpan(params);
|
|
3274
3133
|
}
|
|
3275
3134
|
score(params) {
|
|
3276
3135
|
return this.observability.score(params);
|