@mastra/client-js 0.0.0-cloud-deployer-for-core-0.19.1-20251001164939 → 0.0.0-cloud-storage-adapter-20251106204059
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 +855 -4
- package/README.md +12 -14
- package/dist/client.d.ts +54 -90
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +630 -832
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +630 -832
- 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 +50 -60
- 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 +47 -109
- package/dist/resources/workflow.d.ts.map +1 -1
- package/dist/types.d.ts +104 -131
- 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 +9 -5
- package/dist/resources/network-memory-thread.d.ts +0 -47
- package/dist/resources/network-memory-thread.d.ts.map +0 -1
- package/dist/resources/vNextNetwork.d.ts +0 -43
- package/dist/resources/vNextNetwork.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,27 +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
325
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
326
|
+
enhanceInstructions(instructions, comment) {
|
|
327
|
+
return this.request(`/api/agents/${this.agentId}/instructions/enhance`, {
|
|
328
|
+
method: "POST",
|
|
329
|
+
body: { instructions, comment }
|
|
330
|
+
});
|
|
331
331
|
}
|
|
332
332
|
async generateLegacy(params) {
|
|
333
333
|
const processedParams = {
|
|
334
334
|
...params,
|
|
335
335
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
336
336
|
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
337
|
-
|
|
337
|
+
requestContext: parseClientRequestContext(params.requestContext),
|
|
338
338
|
clientTools: processClientTools(params.clientTools)
|
|
339
339
|
};
|
|
340
|
-
const {
|
|
340
|
+
const { resourceId, threadId, requestContext } = processedParams;
|
|
341
341
|
const response = await this.request(
|
|
342
342
|
`/api/agents/${this.agentId}/generate-legacy`,
|
|
343
343
|
{
|
|
@@ -353,22 +353,18 @@ var Agent = class extends BaseResource {
|
|
|
353
353
|
for (const toolCall of toolCalls) {
|
|
354
354
|
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
355
355
|
if (clientTool && clientTool.execute) {
|
|
356
|
-
const result = await clientTool.execute(
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
resourceId,
|
|
361
|
-
threadId,
|
|
362
|
-
runtimeContext,
|
|
363
|
-
tracingContext: { currentSpan: void 0 },
|
|
364
|
-
suspend: async () => {
|
|
365
|
-
}
|
|
366
|
-
},
|
|
367
|
-
{
|
|
356
|
+
const result = await clientTool.execute(toolCall?.args, {
|
|
357
|
+
requestContext,
|
|
358
|
+
tracingContext: { currentSpan: void 0 },
|
|
359
|
+
agent: {
|
|
368
360
|
messages: response.messages,
|
|
369
|
-
toolCallId: toolCall?.toolCallId
|
|
361
|
+
toolCallId: toolCall?.toolCallId,
|
|
362
|
+
suspend: async () => {
|
|
363
|
+
},
|
|
364
|
+
threadId,
|
|
365
|
+
resourceId
|
|
370
366
|
}
|
|
371
|
-
);
|
|
367
|
+
});
|
|
372
368
|
const updatedMessages = [
|
|
373
369
|
...response.response.messages,
|
|
374
370
|
{
|
|
@@ -392,7 +388,7 @@ var Agent = class extends BaseResource {
|
|
|
392
388
|
}
|
|
393
389
|
return response;
|
|
394
390
|
}
|
|
395
|
-
async
|
|
391
|
+
async generate(messagesOrParams, options) {
|
|
396
392
|
let params;
|
|
397
393
|
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
398
394
|
params = messagesOrParams;
|
|
@@ -404,17 +400,16 @@ var Agent = class extends BaseResource {
|
|
|
404
400
|
}
|
|
405
401
|
const processedParams = {
|
|
406
402
|
...params,
|
|
407
|
-
|
|
408
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
403
|
+
requestContext: parseClientRequestContext(params.requestContext),
|
|
409
404
|
clientTools: processClientTools(params.clientTools),
|
|
410
405
|
structuredOutput: params.structuredOutput ? {
|
|
411
406
|
...params.structuredOutput,
|
|
412
407
|
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
413
408
|
} : void 0
|
|
414
409
|
};
|
|
415
|
-
const {
|
|
410
|
+
const { resourceId, threadId, requestContext } = processedParams;
|
|
416
411
|
const response = await this.request(
|
|
417
|
-
`/api/agents/${this.agentId}/generate
|
|
412
|
+
`/api/agents/${this.agentId}/generate`,
|
|
418
413
|
{
|
|
419
414
|
method: "POST",
|
|
420
415
|
body: processedParams
|
|
@@ -424,11 +419,10 @@ var Agent = class extends BaseResource {
|
|
|
424
419
|
return executeToolCallAndRespond({
|
|
425
420
|
response,
|
|
426
421
|
params,
|
|
427
|
-
runId,
|
|
428
422
|
resourceId,
|
|
429
423
|
threadId,
|
|
430
|
-
|
|
431
|
-
respondFn: this.
|
|
424
|
+
requestContext,
|
|
425
|
+
respondFn: this.generate.bind(this)
|
|
432
426
|
});
|
|
433
427
|
}
|
|
434
428
|
return response;
|
|
@@ -695,17 +689,6 @@ var Agent = class extends BaseResource {
|
|
|
695
689
|
});
|
|
696
690
|
onFinish?.({ message, finishReason, usage });
|
|
697
691
|
}
|
|
698
|
-
/**
|
|
699
|
-
* Streams a response from the agent
|
|
700
|
-
* @param params - Stream parameters including prompt
|
|
701
|
-
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
702
|
-
*/
|
|
703
|
-
async stream(params) {
|
|
704
|
-
console.warn(
|
|
705
|
-
"Deprecation NOTICE:\nStream method will switch to use streamVNext implementation the week of September 30th, 2025. Please use streamLegacy if you don't want to upgrade just yet."
|
|
706
|
-
);
|
|
707
|
-
return this.streamLegacy(params);
|
|
708
|
-
}
|
|
709
692
|
/**
|
|
710
693
|
* Streams a response from the agent
|
|
711
694
|
* @param params - Stream parameters including prompt
|
|
@@ -716,11 +699,11 @@ var Agent = class extends BaseResource {
|
|
|
716
699
|
...params,
|
|
717
700
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
718
701
|
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
719
|
-
|
|
702
|
+
requestContext: parseClientRequestContext(params.requestContext),
|
|
720
703
|
clientTools: processClientTools(params.clientTools)
|
|
721
704
|
};
|
|
722
705
|
const { readable, writable } = new TransformStream();
|
|
723
|
-
const response = await this.
|
|
706
|
+
const response = await this.processStreamResponseLegacy(processedParams, writable);
|
|
724
707
|
const streamResponse = new Response(readable, {
|
|
725
708
|
status: response.status,
|
|
726
709
|
statusText: response.statusText,
|
|
@@ -807,6 +790,14 @@ var Agent = class extends BaseResource {
|
|
|
807
790
|
// but this is completely wrong and this fn is probably broken. Remove ":any" and you'll see a bunch of type errors
|
|
808
791
|
onChunk: async (chunk) => {
|
|
809
792
|
switch (chunk.type) {
|
|
793
|
+
case "tripwire": {
|
|
794
|
+
message.parts.push({
|
|
795
|
+
type: "text",
|
|
796
|
+
text: chunk.payload.tripwireReason
|
|
797
|
+
});
|
|
798
|
+
execUpdate();
|
|
799
|
+
break;
|
|
800
|
+
}
|
|
810
801
|
case "step-start": {
|
|
811
802
|
if (!replaceLastMessage) {
|
|
812
803
|
message.id = chunk.payload.messageId;
|
|
@@ -960,7 +951,10 @@ var Agent = class extends BaseResource {
|
|
|
960
951
|
break;
|
|
961
952
|
}
|
|
962
953
|
case "error": {
|
|
963
|
-
throw
|
|
954
|
+
throw error.getErrorFromUnknown(chunk.payload.error, {
|
|
955
|
+
fallbackMessage: "Unknown error in stream",
|
|
956
|
+
supportSerialization: false
|
|
957
|
+
});
|
|
964
958
|
}
|
|
965
959
|
case "data": {
|
|
966
960
|
data.push(...chunk.payload.data);
|
|
@@ -987,8 +981,8 @@ var Agent = class extends BaseResource {
|
|
|
987
981
|
});
|
|
988
982
|
onFinish?.({ message, finishReason, usage });
|
|
989
983
|
}
|
|
990
|
-
async
|
|
991
|
-
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}`, {
|
|
992
986
|
method: "POST",
|
|
993
987
|
body: processedParams,
|
|
994
988
|
stream: true
|
|
@@ -1000,21 +994,20 @@ var Agent = class extends BaseResource {
|
|
|
1000
994
|
let toolCalls = [];
|
|
1001
995
|
let messages = [];
|
|
1002
996
|
const [streamForWritable, streamForProcessing] = response.body.tee();
|
|
1003
|
-
|
|
997
|
+
streamForWritable.pipeTo(
|
|
1004
998
|
new WritableStream({
|
|
1005
999
|
async write(chunk) {
|
|
1000
|
+
let writer;
|
|
1006
1001
|
try {
|
|
1002
|
+
writer = writable.getWriter();
|
|
1007
1003
|
const text = new TextDecoder().decode(chunk);
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1004
|
+
const lines = text.split("\n\n");
|
|
1005
|
+
const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
|
|
1006
|
+
await writer.write(new TextEncoder().encode(readableLines));
|
|
1011
1007
|
} catch {
|
|
1012
|
-
|
|
1013
|
-
const writer = writable.getWriter();
|
|
1014
|
-
try {
|
|
1015
|
-
await writer.write(chunk);
|
|
1008
|
+
await writer?.write(chunk);
|
|
1016
1009
|
} finally {
|
|
1017
|
-
writer
|
|
1010
|
+
writer?.releaseLock();
|
|
1018
1011
|
}
|
|
1019
1012
|
}
|
|
1020
1013
|
}),
|
|
@@ -1024,7 +1017,7 @@ var Agent = class extends BaseResource {
|
|
|
1024
1017
|
).catch((error) => {
|
|
1025
1018
|
console.error("Error piping to writable stream:", error);
|
|
1026
1019
|
});
|
|
1027
|
-
|
|
1020
|
+
this.processChatResponse_vNext({
|
|
1028
1021
|
stream: streamForProcessing,
|
|
1029
1022
|
update: ({ message }) => {
|
|
1030
1023
|
const existingIndex = messages.findIndex((m) => m.id === message.id);
|
|
@@ -1045,23 +1038,19 @@ var Agent = class extends BaseResource {
|
|
|
1045
1038
|
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
1046
1039
|
if (clientTool && clientTool.execute) {
|
|
1047
1040
|
shouldExecuteClientTool = true;
|
|
1048
|
-
const result = await clientTool.execute(
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
threadId: processedParams.threadId,
|
|
1054
|
-
runtimeContext: processedParams.runtimeContext,
|
|
1055
|
-
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1056
|
-
tracingContext: { currentSpan: void 0 },
|
|
1057
|
-
suspend: async () => {
|
|
1058
|
-
}
|
|
1059
|
-
},
|
|
1060
|
-
{
|
|
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: {
|
|
1061
1046
|
messages: response.messages,
|
|
1062
|
-
toolCallId: toolCall2?.toolCallId
|
|
1047
|
+
toolCallId: toolCall2?.toolCallId,
|
|
1048
|
+
suspend: async () => {
|
|
1049
|
+
},
|
|
1050
|
+
threadId: processedParams.threadId,
|
|
1051
|
+
resourceId: processedParams.resourceId
|
|
1063
1052
|
}
|
|
1064
|
-
);
|
|
1053
|
+
});
|
|
1065
1054
|
const lastMessageRaw = messages[messages.length - 1];
|
|
1066
1055
|
const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
|
|
1067
1056
|
const toolInvocationPart = lastMessage?.parts?.find(
|
|
@@ -1082,26 +1071,31 @@ var Agent = class extends BaseResource {
|
|
|
1082
1071
|
toolInvocation.result = result;
|
|
1083
1072
|
}
|
|
1084
1073
|
const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
|
|
1085
|
-
|
|
1086
|
-
await this.processStreamResponse_vNext(
|
|
1074
|
+
this.processStreamResponse(
|
|
1087
1075
|
{
|
|
1088
1076
|
...processedParams,
|
|
1089
1077
|
messages: updatedMessages
|
|
1090
1078
|
},
|
|
1091
1079
|
writable
|
|
1092
|
-
)
|
|
1080
|
+
).catch((error) => {
|
|
1081
|
+
console.error("Error processing stream response:", error);
|
|
1082
|
+
});
|
|
1093
1083
|
}
|
|
1094
1084
|
}
|
|
1095
1085
|
if (!shouldExecuteClientTool) {
|
|
1096
|
-
|
|
1097
|
-
|
|
1086
|
+
setTimeout(() => {
|
|
1087
|
+
writable.close();
|
|
1088
|
+
}, 0);
|
|
1098
1089
|
}
|
|
1099
1090
|
} else {
|
|
1100
|
-
|
|
1101
|
-
|
|
1091
|
+
setTimeout(() => {
|
|
1092
|
+
writable.close();
|
|
1093
|
+
}, 0);
|
|
1102
1094
|
}
|
|
1103
1095
|
},
|
|
1104
1096
|
lastMessage: void 0
|
|
1097
|
+
}).catch((error) => {
|
|
1098
|
+
console.error("Error processing stream response:", error);
|
|
1105
1099
|
});
|
|
1106
1100
|
} catch (error) {
|
|
1107
1101
|
console.error("Error processing stream response:", error);
|
|
@@ -1132,7 +1126,7 @@ var Agent = class extends BaseResource {
|
|
|
1132
1126
|
};
|
|
1133
1127
|
return streamResponse;
|
|
1134
1128
|
}
|
|
1135
|
-
async
|
|
1129
|
+
async stream(messagesOrParams, options) {
|
|
1136
1130
|
let params;
|
|
1137
1131
|
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
1138
1132
|
params = messagesOrParams;
|
|
@@ -1144,8 +1138,7 @@ var Agent = class extends BaseResource {
|
|
|
1144
1138
|
}
|
|
1145
1139
|
const processedParams = {
|
|
1146
1140
|
...params,
|
|
1147
|
-
|
|
1148
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
1141
|
+
requestContext: parseClientRequestContext(params.requestContext),
|
|
1149
1142
|
clientTools: processClientTools(params.clientTools),
|
|
1150
1143
|
structuredOutput: params.structuredOutput ? {
|
|
1151
1144
|
...params.structuredOutput,
|
|
@@ -1153,7 +1146,43 @@ var Agent = class extends BaseResource {
|
|
|
1153
1146
|
} : void 0
|
|
1154
1147
|
};
|
|
1155
1148
|
const { readable, writable } = new TransformStream();
|
|
1156
|
-
const response = await this.
|
|
1149
|
+
const response = await this.processStreamResponse(processedParams, writable);
|
|
1150
|
+
const streamResponse = new Response(readable, {
|
|
1151
|
+
status: response.status,
|
|
1152
|
+
statusText: response.statusText,
|
|
1153
|
+
headers: response.headers
|
|
1154
|
+
});
|
|
1155
|
+
streamResponse.processDataStream = async ({
|
|
1156
|
+
onChunk
|
|
1157
|
+
}) => {
|
|
1158
|
+
await processMastraStream({
|
|
1159
|
+
stream: streamResponse.body,
|
|
1160
|
+
onChunk
|
|
1161
|
+
});
|
|
1162
|
+
};
|
|
1163
|
+
return streamResponse;
|
|
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");
|
|
1157
1186
|
const streamResponse = new Response(readable, {
|
|
1158
1187
|
status: response.status,
|
|
1159
1188
|
statusText: response.statusText,
|
|
@@ -1172,7 +1201,7 @@ var Agent = class extends BaseResource {
|
|
|
1172
1201
|
/**
|
|
1173
1202
|
* Processes the stream response and handles tool calls
|
|
1174
1203
|
*/
|
|
1175
|
-
async
|
|
1204
|
+
async processStreamResponseLegacy(processedParams, writable) {
|
|
1176
1205
|
const response = await this.request(`/api/agents/${this.agentId}/stream-legacy`, {
|
|
1177
1206
|
method: "POST",
|
|
1178
1207
|
body: processedParams,
|
|
@@ -1209,23 +1238,19 @@ var Agent = class extends BaseResource {
|
|
|
1209
1238
|
for (const toolCall2 of toolCalls) {
|
|
1210
1239
|
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
1211
1240
|
if (clientTool && clientTool.execute) {
|
|
1212
|
-
const result = await clientTool.execute(
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
threadId: processedParams.threadId,
|
|
1218
|
-
runtimeContext: processedParams.runtimeContext,
|
|
1219
|
-
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1220
|
-
tracingContext: { currentSpan: void 0 },
|
|
1221
|
-
suspend: async () => {
|
|
1222
|
-
}
|
|
1223
|
-
},
|
|
1224
|
-
{
|
|
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: {
|
|
1225
1246
|
messages: response.messages,
|
|
1226
|
-
toolCallId: toolCall2?.toolCallId
|
|
1247
|
+
toolCallId: toolCall2?.toolCallId,
|
|
1248
|
+
suspend: async () => {
|
|
1249
|
+
},
|
|
1250
|
+
threadId: processedParams.threadId,
|
|
1251
|
+
resourceId: processedParams.resourceId
|
|
1227
1252
|
}
|
|
1228
|
-
);
|
|
1253
|
+
});
|
|
1229
1254
|
const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
|
|
1230
1255
|
const toolInvocationPart = lastMessage?.parts?.find(
|
|
1231
1256
|
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
@@ -1257,7 +1282,7 @@ var Agent = class extends BaseResource {
|
|
|
1257
1282
|
} finally {
|
|
1258
1283
|
writer.releaseLock();
|
|
1259
1284
|
}
|
|
1260
|
-
this.
|
|
1285
|
+
this.processStreamResponseLegacy(
|
|
1261
1286
|
{
|
|
1262
1287
|
...processedParams,
|
|
1263
1288
|
messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
|
|
@@ -1286,11 +1311,11 @@ var Agent = class extends BaseResource {
|
|
|
1286
1311
|
/**
|
|
1287
1312
|
* Gets details about a specific tool available to the agent
|
|
1288
1313
|
* @param toolId - ID of the tool to retrieve
|
|
1289
|
-
* @param
|
|
1314
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1290
1315
|
* @returns Promise containing tool details
|
|
1291
1316
|
*/
|
|
1292
|
-
getTool(toolId,
|
|
1293
|
-
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)}`);
|
|
1294
1319
|
}
|
|
1295
1320
|
/**
|
|
1296
1321
|
* Executes a tool for the agent
|
|
@@ -1301,29 +1326,13 @@ var Agent = class extends BaseResource {
|
|
|
1301
1326
|
executeTool(toolId, params) {
|
|
1302
1327
|
const body = {
|
|
1303
1328
|
data: params.data,
|
|
1304
|
-
|
|
1329
|
+
requestContext: parseClientRequestContext(params.requestContext)
|
|
1305
1330
|
};
|
|
1306
1331
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
1307
1332
|
method: "POST",
|
|
1308
1333
|
body
|
|
1309
1334
|
});
|
|
1310
1335
|
}
|
|
1311
|
-
/**
|
|
1312
|
-
* Retrieves evaluation results for the agent
|
|
1313
|
-
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1314
|
-
* @returns Promise containing agent evaluations
|
|
1315
|
-
*/
|
|
1316
|
-
evals(runtimeContext) {
|
|
1317
|
-
return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
|
|
1318
|
-
}
|
|
1319
|
-
/**
|
|
1320
|
-
* Retrieves live evaluation results for the agent
|
|
1321
|
-
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1322
|
-
* @returns Promise containing live agent evaluations
|
|
1323
|
-
*/
|
|
1324
|
-
liveEvals(runtimeContext) {
|
|
1325
|
-
return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
|
|
1326
|
-
}
|
|
1327
1336
|
/**
|
|
1328
1337
|
* Updates the model for the agent
|
|
1329
1338
|
* @param params - Parameters for updating the model
|
|
@@ -1335,6 +1344,15 @@ var Agent = class extends BaseResource {
|
|
|
1335
1344
|
body: params
|
|
1336
1345
|
});
|
|
1337
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
|
+
}
|
|
1338
1356
|
/**
|
|
1339
1357
|
* Updates the model for the agent in the model list
|
|
1340
1358
|
* @param params - Parameters for updating the model
|
|
@@ -1368,72 +1386,78 @@ var MemoryThread = class extends BaseResource {
|
|
|
1368
1386
|
}
|
|
1369
1387
|
/**
|
|
1370
1388
|
* Retrieves the memory thread details
|
|
1389
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1371
1390
|
* @returns Promise containing thread details including title and metadata
|
|
1372
1391
|
*/
|
|
1373
|
-
get() {
|
|
1374
|
-
return this.request(
|
|
1392
|
+
get(requestContext) {
|
|
1393
|
+
return this.request(
|
|
1394
|
+
`/api/memory/threads/${this.threadId}?agentId=${this.agentId}${requestContextQueryString(requestContext, "&")}`
|
|
1395
|
+
);
|
|
1375
1396
|
}
|
|
1376
1397
|
/**
|
|
1377
1398
|
* Updates the memory thread properties
|
|
1378
|
-
* @param params - Update parameters including title and
|
|
1399
|
+
* @param params - Update parameters including title, metadata, and optional request context
|
|
1379
1400
|
* @returns Promise containing updated thread details
|
|
1380
1401
|
*/
|
|
1381
1402
|
update(params) {
|
|
1382
|
-
return this.request(
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
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
|
+
);
|
|
1386
1410
|
}
|
|
1387
1411
|
/**
|
|
1388
1412
|
* Deletes the memory thread
|
|
1413
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1389
1414
|
* @returns Promise containing deletion result
|
|
1390
1415
|
*/
|
|
1391
|
-
delete() {
|
|
1392
|
-
return this.request(
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
1399
|
-
* @returns Promise containing thread messages and UI messages
|
|
1400
|
-
*/
|
|
1401
|
-
getMessages(params) {
|
|
1402
|
-
const query = new URLSearchParams({
|
|
1403
|
-
agentId: this.agentId,
|
|
1404
|
-
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
1405
|
-
});
|
|
1406
|
-
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
|
+
);
|
|
1407
1423
|
}
|
|
1408
1424
|
/**
|
|
1409
|
-
* Retrieves paginated messages associated with the thread with
|
|
1410
|
-
* @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
|
|
1411
1427
|
* @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
|
|
1412
1428
|
*/
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
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);
|
|
1422
1442
|
}
|
|
1423
1443
|
/**
|
|
1424
1444
|
* Deletes one or more messages from the thread
|
|
1425
1445
|
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
1426
1446
|
* message object with id property, or array of message objects
|
|
1447
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1427
1448
|
* @returns Promise containing deletion result
|
|
1428
1449
|
*/
|
|
1429
|
-
deleteMessages(messageIds) {
|
|
1450
|
+
deleteMessages(messageIds, requestContext) {
|
|
1430
1451
|
const query = new URLSearchParams({
|
|
1431
1452
|
agentId: this.agentId
|
|
1432
1453
|
});
|
|
1433
|
-
return this.request(
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1454
|
+
return this.request(
|
|
1455
|
+
`/api/memory/messages/delete?${query.toString()}${requestContextQueryString(requestContext, "&")}`,
|
|
1456
|
+
{
|
|
1457
|
+
method: "POST",
|
|
1458
|
+
body: { messageIds }
|
|
1459
|
+
}
|
|
1460
|
+
);
|
|
1437
1461
|
}
|
|
1438
1462
|
};
|
|
1439
1463
|
|
|
@@ -1446,12 +1470,12 @@ var Vector = class extends BaseResource {
|
|
|
1446
1470
|
/**
|
|
1447
1471
|
* Retrieves details about a specific vector index
|
|
1448
1472
|
* @param indexName - Name of the index to get details for
|
|
1449
|
-
* @param
|
|
1473
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1450
1474
|
* @returns Promise containing vector index details
|
|
1451
1475
|
*/
|
|
1452
|
-
details(indexName,
|
|
1476
|
+
details(indexName, requestContext) {
|
|
1453
1477
|
return this.request(
|
|
1454
|
-
`/api/vector/${this.vectorName}/indexes/${indexName}${
|
|
1478
|
+
`/api/vector/${this.vectorName}/indexes/${indexName}${requestContextQueryString(requestContext)}`
|
|
1455
1479
|
);
|
|
1456
1480
|
}
|
|
1457
1481
|
/**
|
|
@@ -1466,11 +1490,11 @@ var Vector = class extends BaseResource {
|
|
|
1466
1490
|
}
|
|
1467
1491
|
/**
|
|
1468
1492
|
* Retrieves a list of all available indexes
|
|
1469
|
-
* @param
|
|
1493
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1470
1494
|
* @returns Promise containing array of index names
|
|
1471
1495
|
*/
|
|
1472
|
-
getIndexes(
|
|
1473
|
-
return this.request(`/api/vector/${this.vectorName}/indexes${
|
|
1496
|
+
getIndexes(requestContext) {
|
|
1497
|
+
return this.request(`/api/vector/${this.vectorName}/indexes${requestContextQueryString(requestContext)}`);
|
|
1474
1498
|
}
|
|
1475
1499
|
/**
|
|
1476
1500
|
* Creates a new vector index
|
|
@@ -1515,11 +1539,11 @@ var Tool = class extends BaseResource {
|
|
|
1515
1539
|
}
|
|
1516
1540
|
/**
|
|
1517
1541
|
* Retrieves details about the tool
|
|
1518
|
-
* @param
|
|
1542
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1519
1543
|
* @returns Promise containing tool details including description and schemas
|
|
1520
1544
|
*/
|
|
1521
|
-
details(
|
|
1522
|
-
return this.request(`/api/tools/${this.toolId}${
|
|
1545
|
+
details(requestContext) {
|
|
1546
|
+
return this.request(`/api/tools/${this.toolId}${requestContextQueryString(requestContext)}`);
|
|
1523
1547
|
}
|
|
1524
1548
|
/**
|
|
1525
1549
|
* Executes the tool with the provided parameters
|
|
@@ -1533,7 +1557,7 @@ var Tool = class extends BaseResource {
|
|
|
1533
1557
|
}
|
|
1534
1558
|
const body = {
|
|
1535
1559
|
data: params.data,
|
|
1536
|
-
|
|
1560
|
+
requestContext: parseClientRequestContext(params.requestContext)
|
|
1537
1561
|
};
|
|
1538
1562
|
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
1539
1563
|
method: "POST",
|
|
@@ -1549,67 +1573,22 @@ var Workflow = class extends BaseResource {
|
|
|
1549
1573
|
super(options);
|
|
1550
1574
|
this.workflowId = workflowId;
|
|
1551
1575
|
}
|
|
1552
|
-
/**
|
|
1553
|
-
* Creates an async generator that processes a readable stream and yields workflow records
|
|
1554
|
-
* separated by the Record Separator character (\x1E)
|
|
1555
|
-
*
|
|
1556
|
-
* @param stream - The readable stream to process
|
|
1557
|
-
* @returns An async generator that yields parsed records
|
|
1558
|
-
*/
|
|
1559
|
-
async *streamProcessor(stream) {
|
|
1560
|
-
const reader = stream.getReader();
|
|
1561
|
-
let doneReading = false;
|
|
1562
|
-
let buffer = "";
|
|
1563
|
-
try {
|
|
1564
|
-
while (!doneReading) {
|
|
1565
|
-
const { done, value } = await reader.read();
|
|
1566
|
-
doneReading = done;
|
|
1567
|
-
if (done && !value) continue;
|
|
1568
|
-
try {
|
|
1569
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1570
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
1571
|
-
buffer = chunks.pop() || "";
|
|
1572
|
-
for (const chunk of chunks) {
|
|
1573
|
-
if (chunk) {
|
|
1574
|
-
if (typeof chunk === "string") {
|
|
1575
|
-
try {
|
|
1576
|
-
const parsedChunk = JSON.parse(chunk);
|
|
1577
|
-
yield parsedChunk;
|
|
1578
|
-
} catch {
|
|
1579
|
-
}
|
|
1580
|
-
}
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
} catch {
|
|
1584
|
-
}
|
|
1585
|
-
}
|
|
1586
|
-
if (buffer) {
|
|
1587
|
-
try {
|
|
1588
|
-
yield JSON.parse(buffer);
|
|
1589
|
-
} catch {
|
|
1590
|
-
}
|
|
1591
|
-
}
|
|
1592
|
-
} finally {
|
|
1593
|
-
reader.cancel().catch(() => {
|
|
1594
|
-
});
|
|
1595
|
-
}
|
|
1596
|
-
}
|
|
1597
1576
|
/**
|
|
1598
1577
|
* Retrieves details about the workflow
|
|
1599
|
-
* @param
|
|
1578
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1600
1579
|
* @returns Promise containing workflow details including steps and graphs
|
|
1601
1580
|
*/
|
|
1602
|
-
details(
|
|
1603
|
-
return this.request(`/api/workflows/${this.workflowId}${
|
|
1581
|
+
details(requestContext) {
|
|
1582
|
+
return this.request(`/api/workflows/${this.workflowId}${requestContextQueryString(requestContext)}`);
|
|
1604
1583
|
}
|
|
1605
1584
|
/**
|
|
1606
1585
|
* Retrieves all runs for a workflow
|
|
1607
1586
|
* @param params - Parameters for filtering runs
|
|
1608
|
-
* @param
|
|
1587
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1609
1588
|
* @returns Promise containing workflow runs array
|
|
1610
1589
|
*/
|
|
1611
|
-
runs(params,
|
|
1612
|
-
const
|
|
1590
|
+
runs(params, requestContext) {
|
|
1591
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
1613
1592
|
const searchParams = new URLSearchParams();
|
|
1614
1593
|
if (params?.fromDate) {
|
|
1615
1594
|
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
@@ -1617,17 +1596,21 @@ var Workflow = class extends BaseResource {
|
|
|
1617
1596
|
if (params?.toDate) {
|
|
1618
1597
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
1619
1598
|
}
|
|
1620
|
-
if (params?.
|
|
1621
|
-
|
|
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
|
+
}
|
|
1622
1605
|
}
|
|
1623
|
-
if (params?.
|
|
1624
|
-
searchParams.set("
|
|
1606
|
+
if (params?.page !== null && params?.page !== void 0 && !isNaN(Number(params?.page))) {
|
|
1607
|
+
searchParams.set("page", String(params.page));
|
|
1625
1608
|
}
|
|
1626
1609
|
if (params?.resourceId) {
|
|
1627
1610
|
searchParams.set("resourceId", params.resourceId);
|
|
1628
1611
|
}
|
|
1629
|
-
if (
|
|
1630
|
-
searchParams.set("
|
|
1612
|
+
if (requestContextParam) {
|
|
1613
|
+
searchParams.set("requestContext", requestContextParam);
|
|
1631
1614
|
}
|
|
1632
1615
|
if (searchParams.size) {
|
|
1633
1616
|
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
@@ -1638,21 +1621,21 @@ var Workflow = class extends BaseResource {
|
|
|
1638
1621
|
/**
|
|
1639
1622
|
* Retrieves a specific workflow run by its ID
|
|
1640
1623
|
* @param runId - The ID of the workflow run to retrieve
|
|
1641
|
-
* @param
|
|
1624
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1642
1625
|
* @returns Promise containing the workflow run details
|
|
1643
1626
|
*/
|
|
1644
|
-
runById(runId,
|
|
1645
|
-
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)}`);
|
|
1646
1629
|
}
|
|
1647
1630
|
/**
|
|
1648
1631
|
* Retrieves the execution result for a specific workflow run by its ID
|
|
1649
1632
|
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1650
|
-
* @param
|
|
1633
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
1651
1634
|
* @returns Promise containing the workflow run execution result
|
|
1652
1635
|
*/
|
|
1653
|
-
runExecutionResult(runId,
|
|
1636
|
+
runExecutionResult(runId, requestContext) {
|
|
1654
1637
|
return this.request(
|
|
1655
|
-
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${
|
|
1638
|
+
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${requestContextQueryString(requestContext)}`
|
|
1656
1639
|
);
|
|
1657
1640
|
}
|
|
1658
1641
|
/**
|
|
@@ -1665,32 +1648,12 @@ var Workflow = class extends BaseResource {
|
|
|
1665
1648
|
method: "POST"
|
|
1666
1649
|
});
|
|
1667
1650
|
}
|
|
1668
|
-
/**
|
|
1669
|
-
* Sends an event to a specific workflow run by its ID
|
|
1670
|
-
* @param params - Object containing the runId, event and data
|
|
1671
|
-
* @returns Promise containing a success message
|
|
1672
|
-
*/
|
|
1673
|
-
sendRunEvent(params) {
|
|
1674
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
|
|
1675
|
-
method: "POST",
|
|
1676
|
-
body: { event: params.event, data: params.data }
|
|
1677
|
-
});
|
|
1678
|
-
}
|
|
1679
|
-
/**
|
|
1680
|
-
* @deprecated Use createRunAsync() instead.
|
|
1681
|
-
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
1682
|
-
*/
|
|
1683
|
-
async createRun(_params) {
|
|
1684
|
-
throw new Error(
|
|
1685
|
-
"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."
|
|
1686
|
-
);
|
|
1687
|
-
}
|
|
1688
1651
|
/**
|
|
1689
1652
|
* Creates a new workflow run
|
|
1690
1653
|
* @param params - Optional object containing the optional runId
|
|
1691
1654
|
* @returns Promise containing the runId of the created run with methods to control execution
|
|
1692
1655
|
*/
|
|
1693
|
-
async
|
|
1656
|
+
async createRun(params) {
|
|
1694
1657
|
const searchParams = new URLSearchParams();
|
|
1695
1658
|
if (!!params?.runId) {
|
|
1696
1659
|
searchParams.set("runId", params.runId);
|
|
@@ -1708,7 +1671,7 @@ var Workflow = class extends BaseResource {
|
|
|
1708
1671
|
return this.start({
|
|
1709
1672
|
runId,
|
|
1710
1673
|
inputData: p.inputData,
|
|
1711
|
-
|
|
1674
|
+
requestContext: p.requestContext,
|
|
1712
1675
|
tracingOptions: p.tracingOptions
|
|
1713
1676
|
});
|
|
1714
1677
|
},
|
|
@@ -1716,22 +1679,19 @@ var Workflow = class extends BaseResource {
|
|
|
1716
1679
|
return this.startAsync({
|
|
1717
1680
|
runId,
|
|
1718
1681
|
inputData: p.inputData,
|
|
1719
|
-
|
|
1682
|
+
requestContext: p.requestContext,
|
|
1720
1683
|
tracingOptions: p.tracingOptions
|
|
1721
1684
|
});
|
|
1722
1685
|
},
|
|
1723
|
-
watch: async (onRecord) => {
|
|
1724
|
-
return this.watch({ runId }, onRecord);
|
|
1725
|
-
},
|
|
1726
1686
|
stream: async (p) => {
|
|
1727
|
-
return this.stream({ runId, inputData: p.inputData,
|
|
1687
|
+
return this.stream({ runId, inputData: p.inputData, requestContext: p.requestContext });
|
|
1728
1688
|
},
|
|
1729
1689
|
resume: async (p) => {
|
|
1730
1690
|
return this.resume({
|
|
1731
1691
|
runId,
|
|
1732
1692
|
step: p.step,
|
|
1733
1693
|
resumeData: p.resumeData,
|
|
1734
|
-
|
|
1694
|
+
requestContext: p.requestContext,
|
|
1735
1695
|
tracingOptions: p.tracingOptions
|
|
1736
1696
|
});
|
|
1737
1697
|
},
|
|
@@ -1740,7 +1700,7 @@ var Workflow = class extends BaseResource {
|
|
|
1740
1700
|
runId,
|
|
1741
1701
|
step: p.step,
|
|
1742
1702
|
resumeData: p.resumeData,
|
|
1743
|
-
|
|
1703
|
+
requestContext: p.requestContext,
|
|
1744
1704
|
tracingOptions: p.tracingOptions
|
|
1745
1705
|
});
|
|
1746
1706
|
},
|
|
@@ -1749,26 +1709,26 @@ var Workflow = class extends BaseResource {
|
|
|
1749
1709
|
runId,
|
|
1750
1710
|
step: p.step,
|
|
1751
1711
|
resumeData: p.resumeData,
|
|
1752
|
-
|
|
1712
|
+
requestContext: p.requestContext
|
|
1753
1713
|
});
|
|
1754
1714
|
}
|
|
1755
1715
|
};
|
|
1756
1716
|
}
|
|
1757
1717
|
/**
|
|
1758
1718
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1759
|
-
* @param params - Object containing the runId, inputData and
|
|
1719
|
+
* @param params - Object containing the runId, inputData and requestContext
|
|
1760
1720
|
* @returns Promise containing success message
|
|
1761
1721
|
*/
|
|
1762
1722
|
start(params) {
|
|
1763
|
-
const
|
|
1723
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1764
1724
|
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1765
1725
|
method: "POST",
|
|
1766
|
-
body: { inputData: params?.inputData,
|
|
1726
|
+
body: { inputData: params?.inputData, requestContext, tracingOptions: params.tracingOptions }
|
|
1767
1727
|
});
|
|
1768
1728
|
}
|
|
1769
1729
|
/**
|
|
1770
1730
|
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
1771
|
-
* @param params - Object containing the runId, step, resumeData and
|
|
1731
|
+
* @param params - Object containing the runId, step, resumeData and requestContext
|
|
1772
1732
|
* @returns Promise containing success message
|
|
1773
1733
|
*/
|
|
1774
1734
|
resume({
|
|
@@ -1778,20 +1738,20 @@ var Workflow = class extends BaseResource {
|
|
|
1778
1738
|
tracingOptions,
|
|
1779
1739
|
...rest
|
|
1780
1740
|
}) {
|
|
1781
|
-
const
|
|
1741
|
+
const requestContext = parseClientRequestContext(rest.requestContext);
|
|
1782
1742
|
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1783
1743
|
method: "POST",
|
|
1784
1744
|
body: {
|
|
1785
1745
|
step,
|
|
1786
1746
|
resumeData,
|
|
1787
|
-
|
|
1747
|
+
requestContext,
|
|
1788
1748
|
tracingOptions
|
|
1789
1749
|
}
|
|
1790
1750
|
});
|
|
1791
1751
|
}
|
|
1792
1752
|
/**
|
|
1793
1753
|
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
1794
|
-
* @param params - Object containing the optional runId, inputData and
|
|
1754
|
+
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1795
1755
|
* @returns Promise containing the workflow execution results
|
|
1796
1756
|
*/
|
|
1797
1757
|
startAsync(params) {
|
|
@@ -1799,15 +1759,15 @@ var Workflow = class extends BaseResource {
|
|
|
1799
1759
|
if (!!params?.runId) {
|
|
1800
1760
|
searchParams.set("runId", params.runId);
|
|
1801
1761
|
}
|
|
1802
|
-
const
|
|
1762
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1803
1763
|
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1804
1764
|
method: "POST",
|
|
1805
|
-
body: { inputData: params.inputData,
|
|
1765
|
+
body: { inputData: params.inputData, requestContext, tracingOptions: params.tracingOptions }
|
|
1806
1766
|
});
|
|
1807
1767
|
}
|
|
1808
1768
|
/**
|
|
1809
1769
|
* Starts a workflow run and returns a stream
|
|
1810
|
-
* @param params - Object containing the optional runId, inputData and
|
|
1770
|
+
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1811
1771
|
* @returns Promise containing the workflow execution results
|
|
1812
1772
|
*/
|
|
1813
1773
|
async stream(params) {
|
|
@@ -1815,12 +1775,12 @@ var Workflow = class extends BaseResource {
|
|
|
1815
1775
|
if (!!params?.runId) {
|
|
1816
1776
|
searchParams.set("runId", params.runId);
|
|
1817
1777
|
}
|
|
1818
|
-
const
|
|
1778
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1819
1779
|
const response = await this.request(
|
|
1820
1780
|
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1821
1781
|
{
|
|
1822
1782
|
method: "POST",
|
|
1823
|
-
body: { inputData: params.inputData,
|
|
1783
|
+
body: { inputData: params.inputData, requestContext, tracingOptions: params.tracingOptions },
|
|
1824
1784
|
stream: true
|
|
1825
1785
|
}
|
|
1826
1786
|
);
|
|
@@ -1905,7 +1865,7 @@ var Workflow = class extends BaseResource {
|
|
|
1905
1865
|
}
|
|
1906
1866
|
/**
|
|
1907
1867
|
* Starts a workflow run and returns a stream
|
|
1908
|
-
* @param params - Object containing the optional runId, inputData and
|
|
1868
|
+
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1909
1869
|
* @returns Promise containing the workflow execution results
|
|
1910
1870
|
*/
|
|
1911
1871
|
async streamVNext(params) {
|
|
@@ -1913,14 +1873,14 @@ var Workflow = class extends BaseResource {
|
|
|
1913
1873
|
if (!!params?.runId) {
|
|
1914
1874
|
searchParams.set("runId", params.runId);
|
|
1915
1875
|
}
|
|
1916
|
-
const
|
|
1876
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1917
1877
|
const response = await this.request(
|
|
1918
1878
|
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
1919
1879
|
{
|
|
1920
1880
|
method: "POST",
|
|
1921
1881
|
body: {
|
|
1922
1882
|
inputData: params.inputData,
|
|
1923
|
-
|
|
1883
|
+
requestContext,
|
|
1924
1884
|
closeOnSuspend: params.closeOnSuspend,
|
|
1925
1885
|
tracingOptions: params.tracingOptions
|
|
1926
1886
|
},
|
|
@@ -1959,62 +1919,123 @@ var Workflow = class extends BaseResource {
|
|
|
1959
1919
|
});
|
|
1960
1920
|
return response.body.pipeThrough(transformStream);
|
|
1961
1921
|
}
|
|
1922
|
+
/**
|
|
1923
|
+
* Observes workflow vNext stream for a workflow run
|
|
1924
|
+
* @param params - Object containing the runId
|
|
1925
|
+
* @returns Promise containing the workflow execution results
|
|
1926
|
+
*/
|
|
1927
|
+
async observeStreamVNext(params) {
|
|
1928
|
+
const searchParams = new URLSearchParams();
|
|
1929
|
+
searchParams.set("runId", params.runId);
|
|
1930
|
+
const response = await this.request(
|
|
1931
|
+
`/api/workflows/${this.workflowId}/observe-streamVNext?${searchParams.toString()}`,
|
|
1932
|
+
{
|
|
1933
|
+
method: "POST",
|
|
1934
|
+
stream: true
|
|
1935
|
+
}
|
|
1936
|
+
);
|
|
1937
|
+
if (!response.ok) {
|
|
1938
|
+
throw new Error(`Failed to observe stream vNext workflow: ${response.statusText}`);
|
|
1939
|
+
}
|
|
1940
|
+
if (!response.body) {
|
|
1941
|
+
throw new Error("Response body is null");
|
|
1942
|
+
}
|
|
1943
|
+
let failedChunk = void 0;
|
|
1944
|
+
const transformStream = new TransformStream({
|
|
1945
|
+
start() {
|
|
1946
|
+
},
|
|
1947
|
+
async transform(chunk, controller) {
|
|
1948
|
+
try {
|
|
1949
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1950
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1951
|
+
for (const chunk2 of chunks) {
|
|
1952
|
+
if (chunk2) {
|
|
1953
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1954
|
+
try {
|
|
1955
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1956
|
+
controller.enqueue(parsedChunk);
|
|
1957
|
+
failedChunk = void 0;
|
|
1958
|
+
} catch {
|
|
1959
|
+
failedChunk = newChunk;
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
} catch {
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
});
|
|
1967
|
+
return response.body.pipeThrough(transformStream);
|
|
1968
|
+
}
|
|
1962
1969
|
/**
|
|
1963
1970
|
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
1964
|
-
* @param params - Object containing the runId, step, resumeData and
|
|
1971
|
+
* @param params - Object containing the runId, step, resumeData and requestContext
|
|
1965
1972
|
* @returns Promise containing the workflow resume results
|
|
1966
1973
|
*/
|
|
1967
1974
|
resumeAsync(params) {
|
|
1968
|
-
const
|
|
1975
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1969
1976
|
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
1970
1977
|
method: "POST",
|
|
1971
1978
|
body: {
|
|
1972
1979
|
step: params.step,
|
|
1973
1980
|
resumeData: params.resumeData,
|
|
1974
|
-
|
|
1981
|
+
requestContext,
|
|
1975
1982
|
tracingOptions: params.tracingOptions
|
|
1976
1983
|
}
|
|
1977
1984
|
});
|
|
1978
1985
|
}
|
|
1979
1986
|
/**
|
|
1980
1987
|
* Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
|
|
1981
|
-
* @param params - Object containing the runId, step, resumeData and
|
|
1988
|
+
* @param params - Object containing the runId, step, resumeData and requestContext
|
|
1982
1989
|
* @returns Promise containing the workflow resume results
|
|
1983
1990
|
*/
|
|
1984
|
-
resumeStreamVNext(params) {
|
|
1985
|
-
const
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1991
|
+
async resumeStreamVNext(params) {
|
|
1992
|
+
const searchParams = new URLSearchParams();
|
|
1993
|
+
searchParams.set("runId", params.runId);
|
|
1994
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1995
|
+
const response = await this.request(
|
|
1996
|
+
`/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
|
|
1997
|
+
{
|
|
1998
|
+
method: "POST",
|
|
1999
|
+
body: {
|
|
2000
|
+
step: params.step,
|
|
2001
|
+
resumeData: params.resumeData,
|
|
2002
|
+
requestContext,
|
|
2003
|
+
tracingOptions: params.tracingOptions
|
|
2004
|
+
},
|
|
2005
|
+
stream: true
|
|
1993
2006
|
}
|
|
1994
|
-
|
|
1995
|
-
}
|
|
1996
|
-
/**
|
|
1997
|
-
* Watches workflow transitions in real-time
|
|
1998
|
-
* @param runId - Optional run ID to filter the watch stream
|
|
1999
|
-
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
2000
|
-
*/
|
|
2001
|
-
async watch({ runId }, onRecord) {
|
|
2002
|
-
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
2003
|
-
stream: true
|
|
2004
|
-
});
|
|
2007
|
+
);
|
|
2005
2008
|
if (!response.ok) {
|
|
2006
|
-
throw new Error(`Failed to
|
|
2009
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
2007
2010
|
}
|
|
2008
2011
|
if (!response.body) {
|
|
2009
2012
|
throw new Error("Response body is null");
|
|
2010
2013
|
}
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
}
|
|
2015
|
-
|
|
2014
|
+
let failedChunk = void 0;
|
|
2015
|
+
const transformStream = new TransformStream({
|
|
2016
|
+
start() {
|
|
2017
|
+
},
|
|
2018
|
+
async transform(chunk, controller) {
|
|
2019
|
+
try {
|
|
2020
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2021
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
2022
|
+
for (const chunk2 of chunks) {
|
|
2023
|
+
if (chunk2) {
|
|
2024
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2025
|
+
try {
|
|
2026
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2027
|
+
controller.enqueue(parsedChunk);
|
|
2028
|
+
failedChunk = void 0;
|
|
2029
|
+
} catch {
|
|
2030
|
+
failedChunk = newChunk;
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
} catch {
|
|
2035
|
+
}
|
|
2016
2036
|
}
|
|
2017
|
-
}
|
|
2037
|
+
});
|
|
2038
|
+
return response.body.pipeThrough(transformStream);
|
|
2018
2039
|
}
|
|
2019
2040
|
/**
|
|
2020
2041
|
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
@@ -2127,22 +2148,22 @@ var MCPTool = class extends BaseResource {
|
|
|
2127
2148
|
}
|
|
2128
2149
|
/**
|
|
2129
2150
|
* Retrieves details about this specific tool from the MCP server.
|
|
2130
|
-
* @param
|
|
2151
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2131
2152
|
* @returns Promise containing the tool's information (name, description, schema).
|
|
2132
2153
|
*/
|
|
2133
|
-
details(
|
|
2134
|
-
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)}`);
|
|
2135
2156
|
}
|
|
2136
2157
|
/**
|
|
2137
2158
|
* Executes this specific tool on the MCP server.
|
|
2138
|
-
* @param params - Parameters for tool execution, including data/args and optional
|
|
2159
|
+
* @param params - Parameters for tool execution, including data/args and optional requestContext.
|
|
2139
2160
|
* @returns Promise containing the result of the tool execution.
|
|
2140
2161
|
*/
|
|
2141
2162
|
execute(params) {
|
|
2142
2163
|
const body = {};
|
|
2143
2164
|
if (params.data !== void 0) body.data = params.data;
|
|
2144
|
-
if (params.
|
|
2145
|
-
body.
|
|
2165
|
+
if (params.requestContext !== void 0) {
|
|
2166
|
+
body.requestContext = params.requestContext;
|
|
2146
2167
|
}
|
|
2147
2168
|
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
|
|
2148
2169
|
method: "POST",
|
|
@@ -2188,19 +2209,39 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2188
2209
|
}
|
|
2189
2210
|
}
|
|
2190
2211
|
/**
|
|
2191
|
-
*
|
|
2192
|
-
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
2212
|
+
* Creates a transform stream that parses binary chunks into JSON records.
|
|
2193
2213
|
*/
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
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
|
+
});
|
|
2198
2239
|
}
|
|
2199
2240
|
/**
|
|
2200
2241
|
* Creates a new agent builder action run and returns the runId.
|
|
2201
2242
|
* This calls `/api/agent-builder/:actionId/create-run`.
|
|
2202
2243
|
*/
|
|
2203
|
-
async
|
|
2244
|
+
async createRun(params) {
|
|
2204
2245
|
const searchParams = new URLSearchParams();
|
|
2205
2246
|
if (!!params?.runId) {
|
|
2206
2247
|
searchParams.set("runId", params.runId);
|
|
@@ -2219,12 +2260,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2219
2260
|
if (runId) {
|
|
2220
2261
|
searchParams.set("runId", runId);
|
|
2221
2262
|
}
|
|
2222
|
-
const
|
|
2223
|
-
const {
|
|
2263
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2264
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2224
2265
|
const url = `/api/agent-builder/${this.actionId}/start-async${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2225
2266
|
const result = await this.request(url, {
|
|
2226
2267
|
method: "POST",
|
|
2227
|
-
body: { ...actionParams,
|
|
2268
|
+
body: { ...actionParams, requestContext }
|
|
2228
2269
|
});
|
|
2229
2270
|
return this.transformWorkflowResult(result);
|
|
2230
2271
|
}
|
|
@@ -2235,12 +2276,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2235
2276
|
async startActionRun(params, runId) {
|
|
2236
2277
|
const searchParams = new URLSearchParams();
|
|
2237
2278
|
searchParams.set("runId", runId);
|
|
2238
|
-
const
|
|
2239
|
-
const {
|
|
2279
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2280
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2240
2281
|
const url = `/api/agent-builder/${this.actionId}/start?${searchParams.toString()}`;
|
|
2241
2282
|
return this.request(url, {
|
|
2242
2283
|
method: "POST",
|
|
2243
|
-
body: { ...actionParams,
|
|
2284
|
+
body: { ...actionParams, requestContext }
|
|
2244
2285
|
});
|
|
2245
2286
|
}
|
|
2246
2287
|
/**
|
|
@@ -2250,12 +2291,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2250
2291
|
async resume(params, runId) {
|
|
2251
2292
|
const searchParams = new URLSearchParams();
|
|
2252
2293
|
searchParams.set("runId", runId);
|
|
2253
|
-
const
|
|
2254
|
-
const {
|
|
2294
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2295
|
+
const { requestContext: _, ...resumeParams } = params;
|
|
2255
2296
|
const url = `/api/agent-builder/${this.actionId}/resume?${searchParams.toString()}`;
|
|
2256
2297
|
return this.request(url, {
|
|
2257
2298
|
method: "POST",
|
|
2258
|
-
body: { ...resumeParams,
|
|
2299
|
+
body: { ...resumeParams, requestContext }
|
|
2259
2300
|
});
|
|
2260
2301
|
}
|
|
2261
2302
|
/**
|
|
@@ -2265,12 +2306,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2265
2306
|
async resumeAsync(params, runId) {
|
|
2266
2307
|
const searchParams = new URLSearchParams();
|
|
2267
2308
|
searchParams.set("runId", runId);
|
|
2268
|
-
const
|
|
2269
|
-
const {
|
|
2309
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2310
|
+
const { requestContext: _, ...resumeParams } = params;
|
|
2270
2311
|
const url = `/api/agent-builder/${this.actionId}/resume-async?${searchParams.toString()}`;
|
|
2271
2312
|
const result = await this.request(url, {
|
|
2272
2313
|
method: "POST",
|
|
2273
|
-
body: { ...resumeParams,
|
|
2314
|
+
body: { ...resumeParams, requestContext }
|
|
2274
2315
|
});
|
|
2275
2316
|
return this.transformWorkflowResult(result);
|
|
2276
2317
|
}
|
|
@@ -2328,12 +2369,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2328
2369
|
if (runId) {
|
|
2329
2370
|
searchParams.set("runId", runId);
|
|
2330
2371
|
}
|
|
2331
|
-
const
|
|
2332
|
-
const {
|
|
2372
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2373
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2333
2374
|
const url = `/api/agent-builder/${this.actionId}/stream${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2334
2375
|
const response = await this.request(url, {
|
|
2335
2376
|
method: "POST",
|
|
2336
|
-
body: { ...actionParams,
|
|
2377
|
+
body: { ...actionParams, requestContext },
|
|
2337
2378
|
stream: true
|
|
2338
2379
|
});
|
|
2339
2380
|
if (!response.ok) {
|
|
@@ -2342,31 +2383,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2342
2383
|
if (!response.body) {
|
|
2343
2384
|
throw new Error("Response body is null");
|
|
2344
2385
|
}
|
|
2345
|
-
|
|
2346
|
-
const transformStream = new TransformStream({
|
|
2347
|
-
start() {
|
|
2348
|
-
},
|
|
2349
|
-
async transform(chunk, controller) {
|
|
2350
|
-
try {
|
|
2351
|
-
const decoded = new TextDecoder().decode(chunk);
|
|
2352
|
-
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2353
|
-
for (const chunk2 of chunks) {
|
|
2354
|
-
if (chunk2) {
|
|
2355
|
-
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2356
|
-
try {
|
|
2357
|
-
const parsedChunk = JSON.parse(newChunk);
|
|
2358
|
-
controller.enqueue(parsedChunk);
|
|
2359
|
-
failedChunk = void 0;
|
|
2360
|
-
} catch {
|
|
2361
|
-
failedChunk = newChunk;
|
|
2362
|
-
}
|
|
2363
|
-
}
|
|
2364
|
-
}
|
|
2365
|
-
} catch {
|
|
2366
|
-
}
|
|
2367
|
-
}
|
|
2368
|
-
});
|
|
2369
|
-
return response.body.pipeThrough(transformStream);
|
|
2386
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2370
2387
|
}
|
|
2371
2388
|
/**
|
|
2372
2389
|
* Streams agent builder action progress in real-time using VNext streaming.
|
|
@@ -2377,12 +2394,12 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2377
2394
|
if (runId) {
|
|
2378
2395
|
searchParams.set("runId", runId);
|
|
2379
2396
|
}
|
|
2380
|
-
const
|
|
2381
|
-
const {
|
|
2397
|
+
const requestContext = parseClientRequestContext(params.requestContext);
|
|
2398
|
+
const { requestContext: _, ...actionParams } = params;
|
|
2382
2399
|
const url = `/api/agent-builder/${this.actionId}/streamVNext${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2383
2400
|
const response = await this.request(url, {
|
|
2384
2401
|
method: "POST",
|
|
2385
|
-
body: { ...actionParams,
|
|
2402
|
+
body: { ...actionParams, requestContext },
|
|
2386
2403
|
stream: true
|
|
2387
2404
|
});
|
|
2388
2405
|
if (!response.ok) {
|
|
@@ -2391,57 +2408,94 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2391
2408
|
if (!response.body) {
|
|
2392
2409
|
throw new Error("Response body is null");
|
|
2393
2410
|
}
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
} catch {
|
|
2410
|
-
failedChunk = newChunk;
|
|
2411
|
-
}
|
|
2412
|
-
}
|
|
2413
|
-
}
|
|
2414
|
-
} catch {
|
|
2415
|
-
}
|
|
2416
|
-
}
|
|
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
|
|
2417
2426
|
});
|
|
2418
|
-
|
|
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());
|
|
2419
2434
|
}
|
|
2420
2435
|
/**
|
|
2421
|
-
*
|
|
2422
|
-
*
|
|
2423
|
-
*
|
|
2424
|
-
* This calls `/api/agent-builder/:actionId/watch`.
|
|
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`.
|
|
2425
2439
|
*/
|
|
2426
|
-
async
|
|
2427
|
-
const
|
|
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()}`;
|
|
2428
2444
|
const response = await this.request(url, {
|
|
2429
|
-
method: "
|
|
2445
|
+
method: "POST",
|
|
2430
2446
|
stream: true
|
|
2431
2447
|
});
|
|
2432
2448
|
if (!response.ok) {
|
|
2433
|
-
throw new Error(`Failed to
|
|
2449
|
+
throw new Error(`Failed to observe agent builder action stream VNext: ${response.statusText}`);
|
|
2434
2450
|
}
|
|
2435
2451
|
if (!response.body) {
|
|
2436
2452
|
throw new Error("Response body is null");
|
|
2437
2453
|
}
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2454
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2455
|
+
}
|
|
2456
|
+
/**
|
|
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`.
|
|
2460
|
+
*/
|
|
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()}`;
|
|
2465
|
+
const response = await this.request(url, {
|
|
2466
|
+
method: "POST",
|
|
2467
|
+
stream: true
|
|
2468
|
+
});
|
|
2469
|
+
if (!response.ok) {
|
|
2470
|
+
throw new Error(`Failed to observe agent builder action stream legacy: ${response.statusText}`);
|
|
2471
|
+
}
|
|
2472
|
+
if (!response.body) {
|
|
2473
|
+
throw new Error("Response body is null");
|
|
2474
|
+
}
|
|
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");
|
|
2444
2497
|
}
|
|
2498
|
+
return response.body.pipeThrough(this.createRecordParserTransform());
|
|
2445
2499
|
}
|
|
2446
2500
|
/**
|
|
2447
2501
|
* Gets a specific action run by its ID.
|
|
@@ -2473,11 +2527,11 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2473
2527
|
if (params?.toDate) {
|
|
2474
2528
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
2475
2529
|
}
|
|
2476
|
-
if (params?.
|
|
2477
|
-
searchParams.set("
|
|
2530
|
+
if (params?.perPage !== void 0) {
|
|
2531
|
+
searchParams.set("perPage", String(params.perPage));
|
|
2478
2532
|
}
|
|
2479
|
-
if (params?.
|
|
2480
|
-
searchParams.set("
|
|
2533
|
+
if (params?.page !== void 0) {
|
|
2534
|
+
searchParams.set("page", String(params.page));
|
|
2481
2535
|
}
|
|
2482
2536
|
if (params?.resourceId) {
|
|
2483
2537
|
searchParams.set("resourceId", params.resourceId);
|
|
@@ -2507,17 +2561,6 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2507
2561
|
method: "POST"
|
|
2508
2562
|
});
|
|
2509
2563
|
}
|
|
2510
|
-
/**
|
|
2511
|
-
* Sends an event to an agent builder action run.
|
|
2512
|
-
* This calls `/api/agent-builder/:actionId/runs/:runId/send-event`.
|
|
2513
|
-
*/
|
|
2514
|
-
async sendRunEvent(params) {
|
|
2515
|
-
const url = `/api/agent-builder/${this.actionId}/runs/${params.runId}/send-event`;
|
|
2516
|
-
return this.request(url, {
|
|
2517
|
-
method: "POST",
|
|
2518
|
-
body: { event: params.event, data: params.data }
|
|
2519
|
-
});
|
|
2520
|
-
}
|
|
2521
2564
|
};
|
|
2522
2565
|
|
|
2523
2566
|
// src/resources/observability.ts
|
|
@@ -2526,15 +2569,15 @@ var Observability = class extends BaseResource {
|
|
|
2526
2569
|
super(options);
|
|
2527
2570
|
}
|
|
2528
2571
|
/**
|
|
2529
|
-
* Retrieves a specific
|
|
2572
|
+
* Retrieves a specific trace by ID
|
|
2530
2573
|
* @param traceId - ID of the trace to retrieve
|
|
2531
|
-
* @returns Promise containing the
|
|
2574
|
+
* @returns Promise containing the trace with all its spans
|
|
2532
2575
|
*/
|
|
2533
2576
|
getTrace(traceId) {
|
|
2534
2577
|
return this.request(`/api/observability/traces/${traceId}`);
|
|
2535
2578
|
}
|
|
2536
2579
|
/**
|
|
2537
|
-
* Retrieves paginated list of
|
|
2580
|
+
* Retrieves paginated list of traces with optional filtering
|
|
2538
2581
|
* @param params - Parameters for pagination and filtering
|
|
2539
2582
|
* @returns Promise containing paginated traces and pagination info
|
|
2540
2583
|
*/
|
|
@@ -2574,7 +2617,7 @@ var Observability = class extends BaseResource {
|
|
|
2574
2617
|
* @param params - Parameters containing trace ID, span ID, and pagination options
|
|
2575
2618
|
* @returns Promise containing scores and pagination info
|
|
2576
2619
|
*/
|
|
2577
|
-
|
|
2620
|
+
listScoresBySpan(params) {
|
|
2578
2621
|
const { traceId, spanId, page, perPage } = params;
|
|
2579
2622
|
const searchParams = new URLSearchParams();
|
|
2580
2623
|
if (page !== void 0) {
|
|
@@ -2596,208 +2639,6 @@ var Observability = class extends BaseResource {
|
|
|
2596
2639
|
}
|
|
2597
2640
|
};
|
|
2598
2641
|
|
|
2599
|
-
// src/resources/network-memory-thread.ts
|
|
2600
|
-
var NetworkMemoryThread = class extends BaseResource {
|
|
2601
|
-
constructor(options, threadId, networkId) {
|
|
2602
|
-
super(options);
|
|
2603
|
-
this.threadId = threadId;
|
|
2604
|
-
this.networkId = networkId;
|
|
2605
|
-
}
|
|
2606
|
-
/**
|
|
2607
|
-
* Retrieves the memory thread details
|
|
2608
|
-
* @returns Promise containing thread details including title and metadata
|
|
2609
|
-
*/
|
|
2610
|
-
get() {
|
|
2611
|
-
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
2612
|
-
}
|
|
2613
|
-
/**
|
|
2614
|
-
* Updates the memory thread properties
|
|
2615
|
-
* @param params - Update parameters including title and metadata
|
|
2616
|
-
* @returns Promise containing updated thread details
|
|
2617
|
-
*/
|
|
2618
|
-
update(params) {
|
|
2619
|
-
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
2620
|
-
method: "PATCH",
|
|
2621
|
-
body: params
|
|
2622
|
-
});
|
|
2623
|
-
}
|
|
2624
|
-
/**
|
|
2625
|
-
* Deletes the memory thread
|
|
2626
|
-
* @returns Promise containing deletion result
|
|
2627
|
-
*/
|
|
2628
|
-
delete() {
|
|
2629
|
-
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
2630
|
-
method: "DELETE"
|
|
2631
|
-
});
|
|
2632
|
-
}
|
|
2633
|
-
/**
|
|
2634
|
-
* Retrieves messages associated with the thread
|
|
2635
|
-
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
2636
|
-
* @returns Promise containing thread messages and UI messages
|
|
2637
|
-
*/
|
|
2638
|
-
getMessages(params) {
|
|
2639
|
-
const query = new URLSearchParams({
|
|
2640
|
-
networkId: this.networkId,
|
|
2641
|
-
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
2642
|
-
});
|
|
2643
|
-
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
2644
|
-
}
|
|
2645
|
-
/**
|
|
2646
|
-
* Deletes one or more messages from the thread
|
|
2647
|
-
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
2648
|
-
* message object with id property, or array of message objects
|
|
2649
|
-
* @returns Promise containing deletion result
|
|
2650
|
-
*/
|
|
2651
|
-
deleteMessages(messageIds) {
|
|
2652
|
-
const query = new URLSearchParams({
|
|
2653
|
-
networkId: this.networkId
|
|
2654
|
-
});
|
|
2655
|
-
return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
|
|
2656
|
-
method: "POST",
|
|
2657
|
-
body: { messageIds }
|
|
2658
|
-
});
|
|
2659
|
-
}
|
|
2660
|
-
};
|
|
2661
|
-
|
|
2662
|
-
// src/resources/vNextNetwork.ts
|
|
2663
|
-
var RECORD_SEPARATOR3 = "";
|
|
2664
|
-
var VNextNetwork = class extends BaseResource {
|
|
2665
|
-
constructor(options, networkId) {
|
|
2666
|
-
super(options);
|
|
2667
|
-
this.networkId = networkId;
|
|
2668
|
-
}
|
|
2669
|
-
/**
|
|
2670
|
-
* Retrieves details about the network
|
|
2671
|
-
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2672
|
-
* @returns Promise containing vNext network details
|
|
2673
|
-
*/
|
|
2674
|
-
details(runtimeContext) {
|
|
2675
|
-
return this.request(`/api/networks/v-next/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
|
|
2676
|
-
}
|
|
2677
|
-
/**
|
|
2678
|
-
* Generates a response from the v-next network
|
|
2679
|
-
* @param params - Generation parameters including message
|
|
2680
|
-
* @returns Promise containing the generated response
|
|
2681
|
-
*/
|
|
2682
|
-
generate(params) {
|
|
2683
|
-
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
2684
|
-
method: "POST",
|
|
2685
|
-
body: {
|
|
2686
|
-
...params,
|
|
2687
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2688
|
-
}
|
|
2689
|
-
});
|
|
2690
|
-
}
|
|
2691
|
-
/**
|
|
2692
|
-
* Generates a response from the v-next network using multiple primitives
|
|
2693
|
-
* @param params - Generation parameters including message
|
|
2694
|
-
* @returns Promise containing the generated response
|
|
2695
|
-
*/
|
|
2696
|
-
loop(params) {
|
|
2697
|
-
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
2698
|
-
method: "POST",
|
|
2699
|
-
body: {
|
|
2700
|
-
...params,
|
|
2701
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2702
|
-
}
|
|
2703
|
-
});
|
|
2704
|
-
}
|
|
2705
|
-
async *streamProcessor(stream) {
|
|
2706
|
-
const reader = stream.getReader();
|
|
2707
|
-
let doneReading = false;
|
|
2708
|
-
let buffer = "";
|
|
2709
|
-
try {
|
|
2710
|
-
while (!doneReading) {
|
|
2711
|
-
const { done, value } = await reader.read();
|
|
2712
|
-
doneReading = done;
|
|
2713
|
-
if (done && !value) continue;
|
|
2714
|
-
try {
|
|
2715
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2716
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
2717
|
-
buffer = chunks.pop() || "";
|
|
2718
|
-
for (const chunk of chunks) {
|
|
2719
|
-
if (chunk) {
|
|
2720
|
-
if (typeof chunk === "string") {
|
|
2721
|
-
try {
|
|
2722
|
-
const parsedChunk = JSON.parse(chunk);
|
|
2723
|
-
yield parsedChunk;
|
|
2724
|
-
} catch {
|
|
2725
|
-
}
|
|
2726
|
-
}
|
|
2727
|
-
}
|
|
2728
|
-
}
|
|
2729
|
-
} catch {
|
|
2730
|
-
}
|
|
2731
|
-
}
|
|
2732
|
-
if (buffer) {
|
|
2733
|
-
try {
|
|
2734
|
-
yield JSON.parse(buffer);
|
|
2735
|
-
} catch {
|
|
2736
|
-
}
|
|
2737
|
-
}
|
|
2738
|
-
} finally {
|
|
2739
|
-
reader.cancel().catch(() => {
|
|
2740
|
-
});
|
|
2741
|
-
}
|
|
2742
|
-
}
|
|
2743
|
-
/**
|
|
2744
|
-
* Streams a response from the v-next network
|
|
2745
|
-
* @param params - Stream parameters including message
|
|
2746
|
-
* @returns Promise containing the results
|
|
2747
|
-
*/
|
|
2748
|
-
async stream(params, onRecord) {
|
|
2749
|
-
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
2750
|
-
method: "POST",
|
|
2751
|
-
body: {
|
|
2752
|
-
...params,
|
|
2753
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2754
|
-
},
|
|
2755
|
-
stream: true
|
|
2756
|
-
});
|
|
2757
|
-
if (!response.ok) {
|
|
2758
|
-
throw new Error(`Failed to stream vNext network: ${response.statusText}`);
|
|
2759
|
-
}
|
|
2760
|
-
if (!response.body) {
|
|
2761
|
-
throw new Error("Response body is null");
|
|
2762
|
-
}
|
|
2763
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
2764
|
-
if (typeof record === "string") {
|
|
2765
|
-
onRecord(JSON.parse(record));
|
|
2766
|
-
} else {
|
|
2767
|
-
onRecord(record);
|
|
2768
|
-
}
|
|
2769
|
-
}
|
|
2770
|
-
}
|
|
2771
|
-
/**
|
|
2772
|
-
* Streams a response from the v-next network loop
|
|
2773
|
-
* @param params - Stream parameters including message
|
|
2774
|
-
* @returns Promise containing the results
|
|
2775
|
-
*/
|
|
2776
|
-
async loopStream(params, onRecord) {
|
|
2777
|
-
const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
2778
|
-
method: "POST",
|
|
2779
|
-
body: {
|
|
2780
|
-
...params,
|
|
2781
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2782
|
-
},
|
|
2783
|
-
stream: true
|
|
2784
|
-
});
|
|
2785
|
-
if (!response.ok) {
|
|
2786
|
-
throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
|
|
2787
|
-
}
|
|
2788
|
-
if (!response.body) {
|
|
2789
|
-
throw new Error("Response body is null");
|
|
2790
|
-
}
|
|
2791
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
2792
|
-
if (typeof record === "string") {
|
|
2793
|
-
onRecord(JSON.parse(record));
|
|
2794
|
-
} else {
|
|
2795
|
-
onRecord(record);
|
|
2796
|
-
}
|
|
2797
|
-
}
|
|
2798
|
-
}
|
|
2799
|
-
};
|
|
2800
|
-
|
|
2801
2642
|
// src/client.ts
|
|
2802
2643
|
var MastraClient = class extends BaseResource {
|
|
2803
2644
|
observability;
|
|
@@ -2807,18 +2648,21 @@ var MastraClient = class extends BaseResource {
|
|
|
2807
2648
|
}
|
|
2808
2649
|
/**
|
|
2809
2650
|
* Retrieves all available agents
|
|
2810
|
-
* @param
|
|
2651
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2811
2652
|
* @returns Promise containing map of agent IDs to agent details
|
|
2812
2653
|
*/
|
|
2813
|
-
|
|
2814
|
-
const
|
|
2654
|
+
listAgents(requestContext) {
|
|
2655
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2815
2656
|
const searchParams = new URLSearchParams();
|
|
2816
|
-
if (
|
|
2817
|
-
searchParams.set("
|
|
2657
|
+
if (requestContextParam) {
|
|
2658
|
+
searchParams.set("requestContext", requestContextParam);
|
|
2818
2659
|
}
|
|
2819
2660
|
const queryString = searchParams.toString();
|
|
2820
2661
|
return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
|
|
2821
2662
|
}
|
|
2663
|
+
listAgentsModelProviders() {
|
|
2664
|
+
return this.request(`/api/agents/providers`);
|
|
2665
|
+
}
|
|
2822
2666
|
/**
|
|
2823
2667
|
* Gets an agent instance by ID
|
|
2824
2668
|
* @param agentId - ID of the agent to retrieve
|
|
@@ -2828,125 +2672,115 @@ var MastraClient = class extends BaseResource {
|
|
|
2828
2672
|
return new Agent(this.options, agentId);
|
|
2829
2673
|
}
|
|
2830
2674
|
/**
|
|
2831
|
-
*
|
|
2832
|
-
* @param params - Parameters containing
|
|
2833
|
-
* @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
|
|
2834
2678
|
*/
|
|
2835
|
-
|
|
2836
|
-
|
|
2679
|
+
async 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
|
+
const response = await this.request(
|
|
2690
|
+
`/api/memory/threads?${queryParams.toString()}${requestContextQueryString(params.requestContext, "&")}`
|
|
2691
|
+
);
|
|
2692
|
+
const actualResponse = "threads" in response ? response : {
|
|
2693
|
+
threads: response,
|
|
2694
|
+
total: response.length,
|
|
2695
|
+
page: params.page ?? 0,
|
|
2696
|
+
perPage: params.perPage ?? 100,
|
|
2697
|
+
hasMore: false
|
|
2698
|
+
};
|
|
2699
|
+
return actualResponse;
|
|
2837
2700
|
}
|
|
2838
2701
|
/**
|
|
2839
2702
|
* Retrieves memory config for a resource
|
|
2840
|
-
* @param params - Parameters containing the resource ID
|
|
2841
|
-
* @returns Promise containing
|
|
2703
|
+
* @param params - Parameters containing the resource ID and optional request context
|
|
2704
|
+
* @returns Promise containing memory configuration
|
|
2842
2705
|
*/
|
|
2843
2706
|
getMemoryConfig(params) {
|
|
2844
|
-
return this.request(
|
|
2707
|
+
return this.request(
|
|
2708
|
+
`/api/memory/config?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`
|
|
2709
|
+
);
|
|
2845
2710
|
}
|
|
2846
2711
|
/**
|
|
2847
2712
|
* Creates a new memory thread
|
|
2848
|
-
* @param params - Parameters for creating the memory thread
|
|
2713
|
+
* @param params - Parameters for creating the memory thread including optional request context
|
|
2849
2714
|
* @returns Promise containing the created memory thread
|
|
2850
2715
|
*/
|
|
2851
2716
|
createMemoryThread(params) {
|
|
2852
|
-
return this.request(
|
|
2717
|
+
return this.request(
|
|
2718
|
+
`/api/memory/threads?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`,
|
|
2719
|
+
{ method: "POST", body: params }
|
|
2720
|
+
);
|
|
2853
2721
|
}
|
|
2854
2722
|
/**
|
|
2855
2723
|
* Gets a memory thread instance by ID
|
|
2856
2724
|
* @param threadId - ID of the memory thread to retrieve
|
|
2857
2725
|
* @returns MemoryThread instance
|
|
2858
2726
|
*/
|
|
2859
|
-
getMemoryThread(threadId, agentId) {
|
|
2727
|
+
getMemoryThread({ threadId, agentId }) {
|
|
2860
2728
|
return new MemoryThread(this.options, threadId, agentId);
|
|
2861
2729
|
}
|
|
2862
|
-
|
|
2730
|
+
listThreadMessages(threadId, opts = {}) {
|
|
2731
|
+
if (!opts.agentId && !opts.networkId) {
|
|
2732
|
+
throw new Error("Either agentId or networkId must be provided");
|
|
2733
|
+
}
|
|
2863
2734
|
let url = "";
|
|
2864
2735
|
if (opts.agentId) {
|
|
2865
|
-
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
|
|
2736
|
+
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2866
2737
|
} else if (opts.networkId) {
|
|
2867
|
-
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
|
|
2738
|
+
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2868
2739
|
}
|
|
2869
2740
|
return this.request(url);
|
|
2870
2741
|
}
|
|
2871
2742
|
deleteThread(threadId, opts = {}) {
|
|
2872
2743
|
let url = "";
|
|
2873
2744
|
if (opts.agentId) {
|
|
2874
|
-
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
|
|
2745
|
+
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2875
2746
|
} else if (opts.networkId) {
|
|
2876
|
-
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
|
|
2747
|
+
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
2877
2748
|
}
|
|
2878
2749
|
return this.request(url, { method: "DELETE" });
|
|
2879
2750
|
}
|
|
2880
2751
|
/**
|
|
2881
2752
|
* Saves messages to memory
|
|
2882
|
-
* @param params - Parameters containing messages to save
|
|
2753
|
+
* @param params - Parameters containing messages to save and optional request context
|
|
2883
2754
|
* @returns Promise containing the saved messages
|
|
2884
2755
|
*/
|
|
2885
2756
|
saveMessageToMemory(params) {
|
|
2886
|
-
return this.request(
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
* @returns Promise containing memory system status
|
|
2894
|
-
*/
|
|
2895
|
-
getMemoryStatus(agentId) {
|
|
2896
|
-
return this.request(`/api/memory/status?agentId=${agentId}`);
|
|
2897
|
-
}
|
|
2898
|
-
/**
|
|
2899
|
-
* Retrieves memory threads for a resource
|
|
2900
|
-
* @param params - Parameters containing the resource ID
|
|
2901
|
-
* @returns Promise containing array of memory threads
|
|
2902
|
-
*/
|
|
2903
|
-
getNetworkMemoryThreads(params) {
|
|
2904
|
-
return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
|
|
2905
|
-
}
|
|
2906
|
-
/**
|
|
2907
|
-
* Creates a new memory thread
|
|
2908
|
-
* @param params - Parameters for creating the memory thread
|
|
2909
|
-
* @returns Promise containing the created memory thread
|
|
2910
|
-
*/
|
|
2911
|
-
createNetworkMemoryThread(params) {
|
|
2912
|
-
return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: "POST", body: params });
|
|
2913
|
-
}
|
|
2914
|
-
/**
|
|
2915
|
-
* Gets a memory thread instance by ID
|
|
2916
|
-
* @param threadId - ID of the memory thread to retrieve
|
|
2917
|
-
* @returns MemoryThread instance
|
|
2918
|
-
*/
|
|
2919
|
-
getNetworkMemoryThread(threadId, networkId) {
|
|
2920
|
-
return new NetworkMemoryThread(this.options, threadId, networkId);
|
|
2921
|
-
}
|
|
2922
|
-
/**
|
|
2923
|
-
* Saves messages to memory
|
|
2924
|
-
* @param params - Parameters containing messages to save
|
|
2925
|
-
* @returns Promise containing the saved messages
|
|
2926
|
-
*/
|
|
2927
|
-
saveNetworkMessageToMemory(params) {
|
|
2928
|
-
return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
|
|
2929
|
-
method: "POST",
|
|
2930
|
-
body: params
|
|
2931
|
-
});
|
|
2757
|
+
return this.request(
|
|
2758
|
+
`/api/memory/save-messages?agentId=${params.agentId}${requestContextQueryString(params.requestContext, "&")}`,
|
|
2759
|
+
{
|
|
2760
|
+
method: "POST",
|
|
2761
|
+
body: params
|
|
2762
|
+
}
|
|
2763
|
+
);
|
|
2932
2764
|
}
|
|
2933
2765
|
/**
|
|
2934
2766
|
* Gets the status of the memory system
|
|
2767
|
+
* @param agentId - The agent ID
|
|
2768
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2935
2769
|
* @returns Promise containing memory system status
|
|
2936
2770
|
*/
|
|
2937
|
-
|
|
2938
|
-
return this.request(`/api/memory/
|
|
2771
|
+
getMemoryStatus(agentId, requestContext) {
|
|
2772
|
+
return this.request(`/api/memory/status?agentId=${agentId}${requestContextQueryString(requestContext, "&")}`);
|
|
2939
2773
|
}
|
|
2940
2774
|
/**
|
|
2941
2775
|
* Retrieves all available tools
|
|
2942
|
-
* @param
|
|
2776
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2943
2777
|
* @returns Promise containing map of tool IDs to tool details
|
|
2944
2778
|
*/
|
|
2945
|
-
|
|
2946
|
-
const
|
|
2779
|
+
listTools(requestContext) {
|
|
2780
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2947
2781
|
const searchParams = new URLSearchParams();
|
|
2948
|
-
if (
|
|
2949
|
-
searchParams.set("
|
|
2782
|
+
if (requestContextParam) {
|
|
2783
|
+
searchParams.set("requestContext", requestContextParam);
|
|
2950
2784
|
}
|
|
2951
2785
|
const queryString = searchParams.toString();
|
|
2952
2786
|
return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
|
|
@@ -2961,14 +2795,14 @@ var MastraClient = class extends BaseResource {
|
|
|
2961
2795
|
}
|
|
2962
2796
|
/**
|
|
2963
2797
|
* Retrieves all available workflows
|
|
2964
|
-
* @param
|
|
2798
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
2965
2799
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
2966
2800
|
*/
|
|
2967
|
-
|
|
2968
|
-
const
|
|
2801
|
+
listWorkflows(requestContext) {
|
|
2802
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2969
2803
|
const searchParams = new URLSearchParams();
|
|
2970
|
-
if (
|
|
2971
|
-
searchParams.set("
|
|
2804
|
+
if (requestContextParam) {
|
|
2805
|
+
searchParams.set("requestContext", requestContextParam);
|
|
2972
2806
|
}
|
|
2973
2807
|
const queryString = searchParams.toString();
|
|
2974
2808
|
return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
|
|
@@ -3008,7 +2842,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3008
2842
|
* @param params - Parameters for filtering logs
|
|
3009
2843
|
* @returns Promise containing array of log messages
|
|
3010
2844
|
*/
|
|
3011
|
-
|
|
2845
|
+
listLogs(params) {
|
|
3012
2846
|
const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
3013
2847
|
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
3014
2848
|
const searchParams = new URLSearchParams();
|
|
@@ -3094,78 +2928,21 @@ var MastraClient = class extends BaseResource {
|
|
|
3094
2928
|
* List of all log transports
|
|
3095
2929
|
* @returns Promise containing list of log transports
|
|
3096
2930
|
*/
|
|
3097
|
-
|
|
2931
|
+
listLogTransports() {
|
|
3098
2932
|
return this.request("/api/logs/transports");
|
|
3099
2933
|
}
|
|
3100
|
-
/**
|
|
3101
|
-
* List of all traces (paged)
|
|
3102
|
-
* @param params - Parameters for filtering traces
|
|
3103
|
-
* @returns Promise containing telemetry data
|
|
3104
|
-
*/
|
|
3105
|
-
getTelemetry(params) {
|
|
3106
|
-
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
3107
|
-
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
3108
|
-
const searchParams = new URLSearchParams();
|
|
3109
|
-
if (name) {
|
|
3110
|
-
searchParams.set("name", name);
|
|
3111
|
-
}
|
|
3112
|
-
if (scope) {
|
|
3113
|
-
searchParams.set("scope", scope);
|
|
3114
|
-
}
|
|
3115
|
-
if (page) {
|
|
3116
|
-
searchParams.set("page", String(page));
|
|
3117
|
-
}
|
|
3118
|
-
if (perPage) {
|
|
3119
|
-
searchParams.set("perPage", String(perPage));
|
|
3120
|
-
}
|
|
3121
|
-
if (_attribute) {
|
|
3122
|
-
if (Array.isArray(_attribute)) {
|
|
3123
|
-
for (const attr of _attribute) {
|
|
3124
|
-
searchParams.append("attribute", attr);
|
|
3125
|
-
}
|
|
3126
|
-
} else {
|
|
3127
|
-
searchParams.set("attribute", _attribute);
|
|
3128
|
-
}
|
|
3129
|
-
}
|
|
3130
|
-
if (fromDate) {
|
|
3131
|
-
searchParams.set("fromDate", fromDate.toISOString());
|
|
3132
|
-
}
|
|
3133
|
-
if (toDate) {
|
|
3134
|
-
searchParams.set("toDate", toDate.toISOString());
|
|
3135
|
-
}
|
|
3136
|
-
if (searchParams.size) {
|
|
3137
|
-
return this.request(`/api/telemetry?${searchParams}`);
|
|
3138
|
-
} else {
|
|
3139
|
-
return this.request(`/api/telemetry`);
|
|
3140
|
-
}
|
|
3141
|
-
}
|
|
3142
|
-
/**
|
|
3143
|
-
* Retrieves all available vNext networks
|
|
3144
|
-
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
3145
|
-
*/
|
|
3146
|
-
getVNextNetworks() {
|
|
3147
|
-
return this.request("/api/networks/v-next");
|
|
3148
|
-
}
|
|
3149
|
-
/**
|
|
3150
|
-
* Gets a vNext network instance by ID
|
|
3151
|
-
* @param networkId - ID of the vNext network to retrieve
|
|
3152
|
-
* @returns vNext Network instance
|
|
3153
|
-
*/
|
|
3154
|
-
getVNextNetwork(networkId) {
|
|
3155
|
-
return new VNextNetwork(this.options, networkId);
|
|
3156
|
-
}
|
|
3157
2934
|
/**
|
|
3158
2935
|
* Retrieves a list of available MCP servers.
|
|
3159
|
-
* @param params - Optional parameters for pagination (
|
|
2936
|
+
* @param params - Optional parameters for pagination (perPage, page).
|
|
3160
2937
|
* @returns Promise containing the list of MCP servers and pagination info.
|
|
3161
2938
|
*/
|
|
3162
2939
|
getMcpServers(params) {
|
|
3163
2940
|
const searchParams = new URLSearchParams();
|
|
3164
|
-
if (params?.
|
|
3165
|
-
searchParams.set("
|
|
2941
|
+
if (params?.perPage !== void 0) {
|
|
2942
|
+
searchParams.set("perPage", String(params.perPage));
|
|
3166
2943
|
}
|
|
3167
|
-
if (params?.
|
|
3168
|
-
searchParams.set("
|
|
2944
|
+
if (params?.page !== void 0) {
|
|
2945
|
+
searchParams.set("page", String(params.page));
|
|
3169
2946
|
}
|
|
3170
2947
|
const queryString = searchParams.toString();
|
|
3171
2948
|
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
|
|
@@ -3220,9 +2997,33 @@ var MastraClient = class extends BaseResource {
|
|
|
3220
2997
|
getWorkingMemory({
|
|
3221
2998
|
agentId,
|
|
3222
2999
|
threadId,
|
|
3223
|
-
resourceId
|
|
3000
|
+
resourceId,
|
|
3001
|
+
requestContext
|
|
3224
3002
|
}) {
|
|
3225
|
-
return this.request(
|
|
3003
|
+
return this.request(
|
|
3004
|
+
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}${requestContextQueryString(requestContext, "&")}`
|
|
3005
|
+
);
|
|
3006
|
+
}
|
|
3007
|
+
searchMemory({
|
|
3008
|
+
agentId,
|
|
3009
|
+
resourceId,
|
|
3010
|
+
threadId,
|
|
3011
|
+
searchQuery,
|
|
3012
|
+
memoryConfig,
|
|
3013
|
+
requestContext
|
|
3014
|
+
}) {
|
|
3015
|
+
const params = new URLSearchParams({
|
|
3016
|
+
searchQuery,
|
|
3017
|
+
resourceId,
|
|
3018
|
+
agentId
|
|
3019
|
+
});
|
|
3020
|
+
if (threadId) {
|
|
3021
|
+
params.append("threadId", threadId);
|
|
3022
|
+
}
|
|
3023
|
+
if (memoryConfig) {
|
|
3024
|
+
params.append("memoryConfig", JSON.stringify(memoryConfig));
|
|
3025
|
+
}
|
|
3026
|
+
return this.request(`/api/memory/search?${params}${requestContextQueryString(requestContext, "&")}`);
|
|
3226
3027
|
}
|
|
3227
3028
|
/**
|
|
3228
3029
|
* Updates the working memory for a specific thread (optionally resource-scoped).
|
|
@@ -3235,21 +3036,25 @@ var MastraClient = class extends BaseResource {
|
|
|
3235
3036
|
agentId,
|
|
3236
3037
|
threadId,
|
|
3237
3038
|
workingMemory,
|
|
3238
|
-
resourceId
|
|
3039
|
+
resourceId,
|
|
3040
|
+
requestContext
|
|
3239
3041
|
}) {
|
|
3240
|
-
return this.request(
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3042
|
+
return this.request(
|
|
3043
|
+
`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}${requestContextQueryString(requestContext, "&")}`,
|
|
3044
|
+
{
|
|
3045
|
+
method: "POST",
|
|
3046
|
+
body: {
|
|
3047
|
+
workingMemory,
|
|
3048
|
+
resourceId
|
|
3049
|
+
}
|
|
3245
3050
|
}
|
|
3246
|
-
|
|
3051
|
+
);
|
|
3247
3052
|
}
|
|
3248
3053
|
/**
|
|
3249
3054
|
* Retrieves all available scorers
|
|
3250
3055
|
* @returns Promise containing list of available scorers
|
|
3251
3056
|
*/
|
|
3252
|
-
|
|
3057
|
+
listScorers() {
|
|
3253
3058
|
return this.request("/api/scores/scorers");
|
|
3254
3059
|
}
|
|
3255
3060
|
/**
|
|
@@ -3260,7 +3065,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3260
3065
|
getScorer(scorerId) {
|
|
3261
3066
|
return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
|
|
3262
3067
|
}
|
|
3263
|
-
|
|
3068
|
+
listScoresByScorerId(params) {
|
|
3264
3069
|
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
3265
3070
|
const searchParams = new URLSearchParams();
|
|
3266
3071
|
if (entityId) {
|
|
@@ -3283,7 +3088,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3283
3088
|
* @param params - Parameters containing run ID and pagination options
|
|
3284
3089
|
* @returns Promise containing scores and pagination info
|
|
3285
3090
|
*/
|
|
3286
|
-
|
|
3091
|
+
listScoresByRunId(params) {
|
|
3287
3092
|
const { runId, page, perPage } = params;
|
|
3288
3093
|
const searchParams = new URLSearchParams();
|
|
3289
3094
|
if (page !== void 0) {
|
|
@@ -3300,7 +3105,7 @@ var MastraClient = class extends BaseResource {
|
|
|
3300
3105
|
* @param params - Parameters containing entity ID, type, and pagination options
|
|
3301
3106
|
* @returns Promise containing scores and pagination info
|
|
3302
3107
|
*/
|
|
3303
|
-
|
|
3108
|
+
listScoresByEntityId(params) {
|
|
3304
3109
|
const { entityId, entityType, page, perPage } = params;
|
|
3305
3110
|
const searchParams = new URLSearchParams();
|
|
3306
3111
|
if (page !== void 0) {
|
|
@@ -3325,21 +3130,14 @@ var MastraClient = class extends BaseResource {
|
|
|
3325
3130
|
body: params
|
|
3326
3131
|
});
|
|
3327
3132
|
}
|
|
3328
|
-
|
|
3329
|
-
* Retrieves model providers with available keys
|
|
3330
|
-
* @returns Promise containing model providers with available keys
|
|
3331
|
-
*/
|
|
3332
|
-
getModelProviders() {
|
|
3333
|
-
return this.request(`/api/model-providers`);
|
|
3334
|
-
}
|
|
3335
|
-
getAITrace(traceId) {
|
|
3133
|
+
getTrace(traceId) {
|
|
3336
3134
|
return this.observability.getTrace(traceId);
|
|
3337
3135
|
}
|
|
3338
|
-
|
|
3136
|
+
getTraces(params) {
|
|
3339
3137
|
return this.observability.getTraces(params);
|
|
3340
3138
|
}
|
|
3341
|
-
|
|
3342
|
-
return this.observability.
|
|
3139
|
+
listScoresBySpan(params) {
|
|
3140
|
+
return this.observability.listScoresBySpan(params);
|
|
3343
3141
|
}
|
|
3344
3142
|
score(params) {
|
|
3345
3143
|
return this.observability.score(params);
|