@mastra/client-js 0.0.0-vnextWorkflows-20250422081019 → 0.0.0-workflow-deno-20250616115451
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 +662 -2
- package/dist/index.cjs +889 -55
- package/dist/index.d.cts +408 -41
- package/dist/index.d.ts +408 -41
- package/dist/index.js +885 -55
- package/package.json +23 -13
- package/src/adapters/agui.test.ts +180 -0
- package/src/adapters/agui.ts +239 -0
- package/src/client.ts +200 -13
- package/src/example.ts +30 -31
- package/src/index.test.ts +125 -5
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +49 -37
- package/src/resources/base.ts +2 -2
- package/src/resources/index.ts +4 -1
- package/src/resources/legacy-workflow.ts +242 -0
- package/src/resources/mcp-tool.ts +48 -0
- package/src/resources/memory-thread.ts +8 -5
- package/src/resources/network.ts +6 -12
- package/src/resources/tool.ts +16 -3
- package/src/resources/workflow.ts +254 -96
- package/src/types.ts +134 -19
- package/src/utils/index.ts +11 -0
- package/src/utils/process-client-tools.ts +31 -0
- package/src/utils/zod-to-json-schema.ts +10 -0
package/dist/index.js
CHANGED
|
@@ -1,8 +1,229 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { AbstractAgent, EventType } from '@ag-ui/client';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
3
|
import { processDataStream } from '@ai-sdk/ui-utils';
|
|
4
|
+
import { ZodSchema } from 'zod';
|
|
5
|
+
import originalZodToJsonSchema from 'zod-to-json-schema';
|
|
6
|
+
import { isVercelTool } from '@mastra/core/tools';
|
|
7
|
+
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
4
8
|
|
|
5
|
-
// src/
|
|
9
|
+
// src/adapters/agui.ts
|
|
10
|
+
var AGUIAdapter = class extends AbstractAgent {
|
|
11
|
+
agent;
|
|
12
|
+
resourceId;
|
|
13
|
+
constructor({ agent, agentId, resourceId, ...rest }) {
|
|
14
|
+
super({
|
|
15
|
+
agentId,
|
|
16
|
+
...rest
|
|
17
|
+
});
|
|
18
|
+
this.agent = agent;
|
|
19
|
+
this.resourceId = resourceId;
|
|
20
|
+
}
|
|
21
|
+
run(input) {
|
|
22
|
+
return new Observable((subscriber) => {
|
|
23
|
+
const convertedMessages = convertMessagesToMastraMessages(input.messages);
|
|
24
|
+
subscriber.next({
|
|
25
|
+
type: EventType.RUN_STARTED,
|
|
26
|
+
threadId: input.threadId,
|
|
27
|
+
runId: input.runId
|
|
28
|
+
});
|
|
29
|
+
this.agent.stream({
|
|
30
|
+
threadId: input.threadId,
|
|
31
|
+
resourceId: this.resourceId ?? "",
|
|
32
|
+
runId: input.runId,
|
|
33
|
+
messages: convertedMessages,
|
|
34
|
+
clientTools: input.tools.reduce(
|
|
35
|
+
(acc, tool) => {
|
|
36
|
+
acc[tool.name] = {
|
|
37
|
+
id: tool.name,
|
|
38
|
+
description: tool.description,
|
|
39
|
+
inputSchema: tool.parameters
|
|
40
|
+
};
|
|
41
|
+
return acc;
|
|
42
|
+
},
|
|
43
|
+
{}
|
|
44
|
+
)
|
|
45
|
+
}).then((response) => {
|
|
46
|
+
let currentMessageId = void 0;
|
|
47
|
+
let isInTextMessage = false;
|
|
48
|
+
return response.processDataStream({
|
|
49
|
+
onTextPart: (text) => {
|
|
50
|
+
if (currentMessageId === void 0) {
|
|
51
|
+
currentMessageId = generateUUID();
|
|
52
|
+
const message2 = {
|
|
53
|
+
type: EventType.TEXT_MESSAGE_START,
|
|
54
|
+
messageId: currentMessageId,
|
|
55
|
+
role: "assistant"
|
|
56
|
+
};
|
|
57
|
+
subscriber.next(message2);
|
|
58
|
+
isInTextMessage = true;
|
|
59
|
+
}
|
|
60
|
+
const message = {
|
|
61
|
+
type: EventType.TEXT_MESSAGE_CONTENT,
|
|
62
|
+
messageId: currentMessageId,
|
|
63
|
+
delta: text
|
|
64
|
+
};
|
|
65
|
+
subscriber.next(message);
|
|
66
|
+
},
|
|
67
|
+
onFinishMessagePart: () => {
|
|
68
|
+
if (currentMessageId !== void 0) {
|
|
69
|
+
const message = {
|
|
70
|
+
type: EventType.TEXT_MESSAGE_END,
|
|
71
|
+
messageId: currentMessageId
|
|
72
|
+
};
|
|
73
|
+
subscriber.next(message);
|
|
74
|
+
isInTextMessage = false;
|
|
75
|
+
}
|
|
76
|
+
subscriber.next({
|
|
77
|
+
type: EventType.RUN_FINISHED,
|
|
78
|
+
threadId: input.threadId,
|
|
79
|
+
runId: input.runId
|
|
80
|
+
});
|
|
81
|
+
subscriber.complete();
|
|
82
|
+
},
|
|
83
|
+
onToolCallPart(streamPart) {
|
|
84
|
+
const parentMessageId = currentMessageId || generateUUID();
|
|
85
|
+
if (isInTextMessage) {
|
|
86
|
+
const message = {
|
|
87
|
+
type: EventType.TEXT_MESSAGE_END,
|
|
88
|
+
messageId: parentMessageId
|
|
89
|
+
};
|
|
90
|
+
subscriber.next(message);
|
|
91
|
+
isInTextMessage = false;
|
|
92
|
+
}
|
|
93
|
+
subscriber.next({
|
|
94
|
+
type: EventType.TOOL_CALL_START,
|
|
95
|
+
toolCallId: streamPart.toolCallId,
|
|
96
|
+
toolCallName: streamPart.toolName,
|
|
97
|
+
parentMessageId
|
|
98
|
+
});
|
|
99
|
+
subscriber.next({
|
|
100
|
+
type: EventType.TOOL_CALL_ARGS,
|
|
101
|
+
toolCallId: streamPart.toolCallId,
|
|
102
|
+
delta: JSON.stringify(streamPart.args),
|
|
103
|
+
parentMessageId
|
|
104
|
+
});
|
|
105
|
+
subscriber.next({
|
|
106
|
+
type: EventType.TOOL_CALL_END,
|
|
107
|
+
toolCallId: streamPart.toolCallId,
|
|
108
|
+
parentMessageId
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}).catch((error) => {
|
|
113
|
+
console.error("error", error);
|
|
114
|
+
subscriber.error(error);
|
|
115
|
+
});
|
|
116
|
+
return () => {
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
function generateUUID() {
|
|
122
|
+
if (typeof crypto !== "undefined") {
|
|
123
|
+
if (typeof crypto.randomUUID === "function") {
|
|
124
|
+
return crypto.randomUUID();
|
|
125
|
+
}
|
|
126
|
+
if (typeof crypto.getRandomValues === "function") {
|
|
127
|
+
const buffer = new Uint8Array(16);
|
|
128
|
+
crypto.getRandomValues(buffer);
|
|
129
|
+
buffer[6] = buffer[6] & 15 | 64;
|
|
130
|
+
buffer[8] = buffer[8] & 63 | 128;
|
|
131
|
+
let hex = "";
|
|
132
|
+
for (let i = 0; i < 16; i++) {
|
|
133
|
+
hex += buffer[i].toString(16).padStart(2, "0");
|
|
134
|
+
if (i === 3 || i === 5 || i === 7 || i === 9) hex += "-";
|
|
135
|
+
}
|
|
136
|
+
return hex;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
140
|
+
const r = Math.random() * 16 | 0;
|
|
141
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
142
|
+
return v.toString(16);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function convertMessagesToMastraMessages(messages) {
|
|
146
|
+
const result = [];
|
|
147
|
+
for (const message of messages) {
|
|
148
|
+
if (message.role === "assistant") {
|
|
149
|
+
const parts = message.content ? [{ type: "text", text: message.content }] : [];
|
|
150
|
+
for (const toolCall of message.toolCalls ?? []) {
|
|
151
|
+
parts.push({
|
|
152
|
+
type: "tool-call",
|
|
153
|
+
toolCallId: toolCall.id,
|
|
154
|
+
toolName: toolCall.function.name,
|
|
155
|
+
args: JSON.parse(toolCall.function.arguments)
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
result.push({
|
|
159
|
+
role: "assistant",
|
|
160
|
+
content: parts
|
|
161
|
+
});
|
|
162
|
+
if (message.toolCalls?.length) {
|
|
163
|
+
result.push({
|
|
164
|
+
role: "tool",
|
|
165
|
+
content: message.toolCalls.map((toolCall) => ({
|
|
166
|
+
type: "tool-result",
|
|
167
|
+
toolCallId: toolCall.id,
|
|
168
|
+
toolName: toolCall.function.name,
|
|
169
|
+
result: JSON.parse(toolCall.function.arguments)
|
|
170
|
+
}))
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
} else if (message.role === "user") {
|
|
174
|
+
result.push({
|
|
175
|
+
role: "user",
|
|
176
|
+
content: message.content || ""
|
|
177
|
+
});
|
|
178
|
+
} else if (message.role === "tool") {
|
|
179
|
+
result.push({
|
|
180
|
+
role: "tool",
|
|
181
|
+
content: [
|
|
182
|
+
{
|
|
183
|
+
type: "tool-result",
|
|
184
|
+
toolCallId: message.toolCallId,
|
|
185
|
+
toolName: "unknown",
|
|
186
|
+
result: message.content
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
function zodToJsonSchema(zodSchema) {
|
|
195
|
+
if (!(zodSchema instanceof ZodSchema)) {
|
|
196
|
+
return zodSchema;
|
|
197
|
+
}
|
|
198
|
+
return originalZodToJsonSchema(zodSchema, { $refStrategy: "none" });
|
|
199
|
+
}
|
|
200
|
+
function processClientTools(clientTools) {
|
|
201
|
+
if (!clientTools) {
|
|
202
|
+
return void 0;
|
|
203
|
+
}
|
|
204
|
+
return Object.fromEntries(
|
|
205
|
+
Object.entries(clientTools).map(([key, value]) => {
|
|
206
|
+
if (isVercelTool(value)) {
|
|
207
|
+
return [
|
|
208
|
+
key,
|
|
209
|
+
{
|
|
210
|
+
...value,
|
|
211
|
+
parameters: value.parameters ? zodToJsonSchema(value.parameters) : void 0
|
|
212
|
+
}
|
|
213
|
+
];
|
|
214
|
+
} else {
|
|
215
|
+
return [
|
|
216
|
+
key,
|
|
217
|
+
{
|
|
218
|
+
...value,
|
|
219
|
+
inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : void 0,
|
|
220
|
+
outputSchema: value.outputSchema ? zodToJsonSchema(value.outputSchema) : void 0
|
|
221
|
+
}
|
|
222
|
+
];
|
|
223
|
+
}
|
|
224
|
+
})
|
|
225
|
+
);
|
|
226
|
+
}
|
|
6
227
|
|
|
7
228
|
// src/resources/base.ts
|
|
8
229
|
var BaseResource = class {
|
|
@@ -22,7 +243,7 @@ var BaseResource = class {
|
|
|
22
243
|
let delay = backoffMs;
|
|
23
244
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
24
245
|
try {
|
|
25
|
-
const response = await fetch(`${baseUrl}${path}`, {
|
|
246
|
+
const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
|
|
26
247
|
...options,
|
|
27
248
|
headers: {
|
|
28
249
|
...headers,
|
|
@@ -62,6 +283,15 @@ var BaseResource = class {
|
|
|
62
283
|
throw lastError || new Error("Request failed");
|
|
63
284
|
}
|
|
64
285
|
};
|
|
286
|
+
function parseClientRuntimeContext(runtimeContext) {
|
|
287
|
+
if (runtimeContext) {
|
|
288
|
+
if (runtimeContext instanceof RuntimeContext) {
|
|
289
|
+
return Object.fromEntries(runtimeContext.entries());
|
|
290
|
+
}
|
|
291
|
+
return runtimeContext;
|
|
292
|
+
}
|
|
293
|
+
return void 0;
|
|
294
|
+
}
|
|
65
295
|
|
|
66
296
|
// src/resources/agent.ts
|
|
67
297
|
var AgentVoice = class extends BaseResource {
|
|
@@ -110,6 +340,13 @@ var AgentVoice = class extends BaseResource {
|
|
|
110
340
|
getSpeakers() {
|
|
111
341
|
return this.request(`/api/agents/${this.agentId}/voice/speakers`);
|
|
112
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* Get the listener configuration for the agent's voice provider
|
|
345
|
+
* @returns Promise containing a check if the agent has listening capabilities
|
|
346
|
+
*/
|
|
347
|
+
getListener() {
|
|
348
|
+
return this.request(`/api/agents/${this.agentId}/voice/listener`);
|
|
349
|
+
}
|
|
113
350
|
};
|
|
114
351
|
var Agent = class extends BaseResource {
|
|
115
352
|
constructor(options, agentId) {
|
|
@@ -125,16 +362,13 @@ var Agent = class extends BaseResource {
|
|
|
125
362
|
details() {
|
|
126
363
|
return this.request(`/api/agents/${this.agentId}`);
|
|
127
364
|
}
|
|
128
|
-
/**
|
|
129
|
-
* Generates a response from the agent
|
|
130
|
-
* @param params - Generation parameters including prompt
|
|
131
|
-
* @returns Promise containing the generated response
|
|
132
|
-
*/
|
|
133
365
|
generate(params) {
|
|
134
366
|
const processedParams = {
|
|
135
367
|
...params,
|
|
136
|
-
output: params.output
|
|
137
|
-
experimental_output: params.experimental_output
|
|
368
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
369
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
370
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
371
|
+
clientTools: processClientTools(params.clientTools)
|
|
138
372
|
};
|
|
139
373
|
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
140
374
|
method: "POST",
|
|
@@ -149,8 +383,10 @@ var Agent = class extends BaseResource {
|
|
|
149
383
|
async stream(params) {
|
|
150
384
|
const processedParams = {
|
|
151
385
|
...params,
|
|
152
|
-
output: params.output
|
|
153
|
-
experimental_output: params.experimental_output
|
|
386
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
387
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
388
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
389
|
+
clientTools: processClientTools(params.clientTools)
|
|
154
390
|
};
|
|
155
391
|
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
156
392
|
method: "POST",
|
|
@@ -176,6 +412,22 @@ var Agent = class extends BaseResource {
|
|
|
176
412
|
getTool(toolId) {
|
|
177
413
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
178
414
|
}
|
|
415
|
+
/**
|
|
416
|
+
* Executes a tool for the agent
|
|
417
|
+
* @param toolId - ID of the tool to execute
|
|
418
|
+
* @param params - Parameters required for tool execution
|
|
419
|
+
* @returns Promise containing the tool execution results
|
|
420
|
+
*/
|
|
421
|
+
executeTool(toolId, params) {
|
|
422
|
+
const body = {
|
|
423
|
+
data: params.data,
|
|
424
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
425
|
+
};
|
|
426
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
427
|
+
method: "POST",
|
|
428
|
+
body
|
|
429
|
+
});
|
|
430
|
+
}
|
|
179
431
|
/**
|
|
180
432
|
* Retrieves evaluation results for the agent
|
|
181
433
|
* @returns Promise containing agent evaluations
|
|
@@ -211,8 +463,8 @@ var Network = class extends BaseResource {
|
|
|
211
463
|
generate(params) {
|
|
212
464
|
const processedParams = {
|
|
213
465
|
...params,
|
|
214
|
-
output:
|
|
215
|
-
experimental_output:
|
|
466
|
+
output: zodToJsonSchema(params.output),
|
|
467
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
216
468
|
};
|
|
217
469
|
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
218
470
|
method: "POST",
|
|
@@ -227,8 +479,8 @@ var Network = class extends BaseResource {
|
|
|
227
479
|
async stream(params) {
|
|
228
480
|
const processedParams = {
|
|
229
481
|
...params,
|
|
230
|
-
output:
|
|
231
|
-
experimental_output:
|
|
482
|
+
output: zodToJsonSchema(params.output),
|
|
483
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
232
484
|
};
|
|
233
485
|
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
234
486
|
method: "POST",
|
|
@@ -284,10 +536,15 @@ var MemoryThread = class extends BaseResource {
|
|
|
284
536
|
}
|
|
285
537
|
/**
|
|
286
538
|
* Retrieves messages associated with the thread
|
|
539
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
287
540
|
* @returns Promise containing thread messages and UI messages
|
|
288
541
|
*/
|
|
289
|
-
getMessages() {
|
|
290
|
-
|
|
542
|
+
getMessages(params) {
|
|
543
|
+
const query = new URLSearchParams({
|
|
544
|
+
agentId: this.agentId,
|
|
545
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
546
|
+
});
|
|
547
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
291
548
|
}
|
|
292
549
|
};
|
|
293
550
|
|
|
@@ -357,34 +614,50 @@ var Vector = class extends BaseResource {
|
|
|
357
614
|
}
|
|
358
615
|
};
|
|
359
616
|
|
|
360
|
-
// src/resources/workflow.ts
|
|
617
|
+
// src/resources/legacy-workflow.ts
|
|
361
618
|
var RECORD_SEPARATOR = "";
|
|
362
|
-
var
|
|
619
|
+
var LegacyWorkflow = class extends BaseResource {
|
|
363
620
|
constructor(options, workflowId) {
|
|
364
621
|
super(options);
|
|
365
622
|
this.workflowId = workflowId;
|
|
366
623
|
}
|
|
367
624
|
/**
|
|
368
|
-
* Retrieves details about the workflow
|
|
369
|
-
* @returns Promise containing workflow details including steps and graphs
|
|
625
|
+
* Retrieves details about the legacy workflow
|
|
626
|
+
* @returns Promise containing legacy workflow details including steps and graphs
|
|
370
627
|
*/
|
|
371
628
|
details() {
|
|
372
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
629
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}`);
|
|
373
630
|
}
|
|
374
631
|
/**
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
* @
|
|
378
|
-
* @returns Promise containing the workflow execution results
|
|
632
|
+
* Retrieves all runs for a legacy workflow
|
|
633
|
+
* @param params - Parameters for filtering runs
|
|
634
|
+
* @returns Promise containing legacy workflow runs array
|
|
379
635
|
*/
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
636
|
+
runs(params) {
|
|
637
|
+
const searchParams = new URLSearchParams();
|
|
638
|
+
if (params?.fromDate) {
|
|
639
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
640
|
+
}
|
|
641
|
+
if (params?.toDate) {
|
|
642
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
643
|
+
}
|
|
644
|
+
if (params?.limit) {
|
|
645
|
+
searchParams.set("limit", String(params.limit));
|
|
646
|
+
}
|
|
647
|
+
if (params?.offset) {
|
|
648
|
+
searchParams.set("offset", String(params.offset));
|
|
649
|
+
}
|
|
650
|
+
if (params?.resourceId) {
|
|
651
|
+
searchParams.set("resourceId", params.resourceId);
|
|
652
|
+
}
|
|
653
|
+
if (searchParams.size) {
|
|
654
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
655
|
+
} else {
|
|
656
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
657
|
+
}
|
|
385
658
|
}
|
|
386
659
|
/**
|
|
387
|
-
* Creates a new workflow run
|
|
660
|
+
* Creates a new legacy workflow run
|
|
388
661
|
* @returns Promise containing the generated run ID
|
|
389
662
|
*/
|
|
390
663
|
createRun(params) {
|
|
@@ -392,34 +665,34 @@ var Workflow = class extends BaseResource {
|
|
|
392
665
|
if (!!params?.runId) {
|
|
393
666
|
searchParams.set("runId", params.runId);
|
|
394
667
|
}
|
|
395
|
-
return this.request(`/api/workflows/${this.workflowId}/
|
|
668
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
396
669
|
method: "POST"
|
|
397
670
|
});
|
|
398
671
|
}
|
|
399
672
|
/**
|
|
400
|
-
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
673
|
+
* Starts a legacy workflow run synchronously without waiting for the workflow to complete
|
|
401
674
|
* @param params - Object containing the runId and triggerData
|
|
402
675
|
* @returns Promise containing success message
|
|
403
676
|
*/
|
|
404
677
|
start(params) {
|
|
405
|
-
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
678
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
406
679
|
method: "POST",
|
|
407
680
|
body: params?.triggerData
|
|
408
681
|
});
|
|
409
682
|
}
|
|
410
683
|
/**
|
|
411
|
-
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
684
|
+
* Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
|
|
412
685
|
* @param stepId - ID of the step to resume
|
|
413
|
-
* @param runId - ID of the workflow run
|
|
414
|
-
* @param context - Context to resume the workflow with
|
|
415
|
-
* @returns Promise containing the workflow resume results
|
|
686
|
+
* @param runId - ID of the legacy workflow run
|
|
687
|
+
* @param context - Context to resume the legacy workflow with
|
|
688
|
+
* @returns Promise containing the legacy workflow resume results
|
|
416
689
|
*/
|
|
417
690
|
resume({
|
|
418
691
|
stepId,
|
|
419
692
|
runId,
|
|
420
693
|
context
|
|
421
694
|
}) {
|
|
422
|
-
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
695
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
423
696
|
method: "POST",
|
|
424
697
|
body: {
|
|
425
698
|
stepId,
|
|
@@ -437,18 +710,18 @@ var Workflow = class extends BaseResource {
|
|
|
437
710
|
if (!!params?.runId) {
|
|
438
711
|
searchParams.set("runId", params.runId);
|
|
439
712
|
}
|
|
440
|
-
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
713
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
441
714
|
method: "POST",
|
|
442
715
|
body: params?.triggerData
|
|
443
716
|
});
|
|
444
717
|
}
|
|
445
718
|
/**
|
|
446
|
-
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
719
|
+
* Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
447
720
|
* @param params - Object containing the runId, stepId, and context
|
|
448
721
|
* @returns Promise containing the workflow resume results
|
|
449
722
|
*/
|
|
450
723
|
resumeAsync(params) {
|
|
451
|
-
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
724
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
452
725
|
method: "POST",
|
|
453
726
|
body: {
|
|
454
727
|
stepId: params.stepId,
|
|
@@ -487,7 +760,7 @@ var Workflow = class extends BaseResource {
|
|
|
487
760
|
}
|
|
488
761
|
}
|
|
489
762
|
}
|
|
490
|
-
} catch
|
|
763
|
+
} catch {
|
|
491
764
|
}
|
|
492
765
|
}
|
|
493
766
|
if (buffer) {
|
|
@@ -502,16 +775,16 @@ var Workflow = class extends BaseResource {
|
|
|
502
775
|
}
|
|
503
776
|
}
|
|
504
777
|
/**
|
|
505
|
-
* Watches workflow transitions in real-time
|
|
778
|
+
* Watches legacy workflow transitions in real-time
|
|
506
779
|
* @param runId - Optional run ID to filter the watch stream
|
|
507
|
-
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
780
|
+
* @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
|
|
508
781
|
*/
|
|
509
782
|
async watch({ runId }, onRecord) {
|
|
510
|
-
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
783
|
+
const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
|
|
511
784
|
stream: true
|
|
512
785
|
});
|
|
513
786
|
if (!response.ok) {
|
|
514
|
-
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
787
|
+
throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
|
|
515
788
|
}
|
|
516
789
|
if (!response.body) {
|
|
517
790
|
throw new Error("Response body is null");
|
|
@@ -541,9 +814,403 @@ var Tool = class extends BaseResource {
|
|
|
541
814
|
* @returns Promise containing the tool execution results
|
|
542
815
|
*/
|
|
543
816
|
execute(params) {
|
|
544
|
-
|
|
817
|
+
const url = new URLSearchParams();
|
|
818
|
+
if (params.runId) {
|
|
819
|
+
url.set("runId", params.runId);
|
|
820
|
+
}
|
|
821
|
+
const body = {
|
|
822
|
+
data: params.data,
|
|
823
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
824
|
+
};
|
|
825
|
+
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
545
826
|
method: "POST",
|
|
546
|
-
body
|
|
827
|
+
body
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
};
|
|
831
|
+
|
|
832
|
+
// src/resources/workflow.ts
|
|
833
|
+
var RECORD_SEPARATOR2 = "";
|
|
834
|
+
var Workflow = class extends BaseResource {
|
|
835
|
+
constructor(options, workflowId) {
|
|
836
|
+
super(options);
|
|
837
|
+
this.workflowId = workflowId;
|
|
838
|
+
}
|
|
839
|
+
/**
|
|
840
|
+
* Creates an async generator that processes a readable stream and yields workflow records
|
|
841
|
+
* separated by the Record Separator character (\x1E)
|
|
842
|
+
*
|
|
843
|
+
* @param stream - The readable stream to process
|
|
844
|
+
* @returns An async generator that yields parsed records
|
|
845
|
+
*/
|
|
846
|
+
async *streamProcessor(stream) {
|
|
847
|
+
const reader = stream.getReader();
|
|
848
|
+
let doneReading = false;
|
|
849
|
+
let buffer = "";
|
|
850
|
+
try {
|
|
851
|
+
while (!doneReading) {
|
|
852
|
+
const { done, value } = await reader.read();
|
|
853
|
+
doneReading = done;
|
|
854
|
+
if (done && !value) continue;
|
|
855
|
+
try {
|
|
856
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
857
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
858
|
+
buffer = chunks.pop() || "";
|
|
859
|
+
for (const chunk of chunks) {
|
|
860
|
+
if (chunk) {
|
|
861
|
+
if (typeof chunk === "string") {
|
|
862
|
+
try {
|
|
863
|
+
const parsedChunk = JSON.parse(chunk);
|
|
864
|
+
yield parsedChunk;
|
|
865
|
+
} catch {
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
} catch {
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
if (buffer) {
|
|
874
|
+
try {
|
|
875
|
+
yield JSON.parse(buffer);
|
|
876
|
+
} catch {
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
} finally {
|
|
880
|
+
reader.cancel().catch(() => {
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* Retrieves details about the workflow
|
|
886
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
887
|
+
*/
|
|
888
|
+
details() {
|
|
889
|
+
return this.request(`/api/workflows/${this.workflowId}`);
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Retrieves all runs for a workflow
|
|
893
|
+
* @param params - Parameters for filtering runs
|
|
894
|
+
* @returns Promise containing workflow runs array
|
|
895
|
+
*/
|
|
896
|
+
runs(params) {
|
|
897
|
+
const searchParams = new URLSearchParams();
|
|
898
|
+
if (params?.fromDate) {
|
|
899
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
900
|
+
}
|
|
901
|
+
if (params?.toDate) {
|
|
902
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
903
|
+
}
|
|
904
|
+
if (params?.limit) {
|
|
905
|
+
searchParams.set("limit", String(params.limit));
|
|
906
|
+
}
|
|
907
|
+
if (params?.offset) {
|
|
908
|
+
searchParams.set("offset", String(params.offset));
|
|
909
|
+
}
|
|
910
|
+
if (params?.resourceId) {
|
|
911
|
+
searchParams.set("resourceId", params.resourceId);
|
|
912
|
+
}
|
|
913
|
+
if (searchParams.size) {
|
|
914
|
+
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
915
|
+
} else {
|
|
916
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Retrieves a specific workflow run by its ID
|
|
921
|
+
* @param runId - The ID of the workflow run to retrieve
|
|
922
|
+
* @returns Promise containing the workflow run details
|
|
923
|
+
*/
|
|
924
|
+
runById(runId) {
|
|
925
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* Retrieves the execution result for a specific workflow run by its ID
|
|
929
|
+
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
930
|
+
* @returns Promise containing the workflow run execution result
|
|
931
|
+
*/
|
|
932
|
+
runExecutionResult(runId) {
|
|
933
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* Creates a new workflow run
|
|
937
|
+
* @param params - Optional object containing the optional runId
|
|
938
|
+
* @returns Promise containing the runId of the created run
|
|
939
|
+
*/
|
|
940
|
+
createRun(params) {
|
|
941
|
+
const searchParams = new URLSearchParams();
|
|
942
|
+
if (!!params?.runId) {
|
|
943
|
+
searchParams.set("runId", params.runId);
|
|
944
|
+
}
|
|
945
|
+
return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
946
|
+
method: "POST"
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
951
|
+
* @param params - Object containing the runId, inputData and runtimeContext
|
|
952
|
+
* @returns Promise containing success message
|
|
953
|
+
*/
|
|
954
|
+
start(params) {
|
|
955
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
956
|
+
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
957
|
+
method: "POST",
|
|
958
|
+
body: { inputData: params?.inputData, runtimeContext }
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
963
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
964
|
+
* @returns Promise containing success message
|
|
965
|
+
*/
|
|
966
|
+
resume({
|
|
967
|
+
step,
|
|
968
|
+
runId,
|
|
969
|
+
resumeData,
|
|
970
|
+
...rest
|
|
971
|
+
}) {
|
|
972
|
+
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
973
|
+
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
974
|
+
method: "POST",
|
|
975
|
+
stream: true,
|
|
976
|
+
body: {
|
|
977
|
+
step,
|
|
978
|
+
resumeData,
|
|
979
|
+
runtimeContext
|
|
980
|
+
}
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
984
|
+
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
985
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
986
|
+
* @returns Promise containing the workflow execution results
|
|
987
|
+
*/
|
|
988
|
+
startAsync(params) {
|
|
989
|
+
const searchParams = new URLSearchParams();
|
|
990
|
+
if (!!params?.runId) {
|
|
991
|
+
searchParams.set("runId", params.runId);
|
|
992
|
+
}
|
|
993
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
994
|
+
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
995
|
+
method: "POST",
|
|
996
|
+
body: { inputData: params.inputData, runtimeContext }
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
/**
|
|
1000
|
+
* Starts a vNext workflow run and returns a stream
|
|
1001
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
1002
|
+
* @returns Promise containing the vNext workflow execution results
|
|
1003
|
+
*/
|
|
1004
|
+
async stream(params) {
|
|
1005
|
+
const searchParams = new URLSearchParams();
|
|
1006
|
+
if (!!params?.runId) {
|
|
1007
|
+
searchParams.set("runId", params.runId);
|
|
1008
|
+
}
|
|
1009
|
+
const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0;
|
|
1010
|
+
const response = await this.request(
|
|
1011
|
+
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1012
|
+
{
|
|
1013
|
+
method: "POST",
|
|
1014
|
+
body: { inputData: params.inputData, runtimeContext },
|
|
1015
|
+
stream: true
|
|
1016
|
+
}
|
|
1017
|
+
);
|
|
1018
|
+
if (!response.ok) {
|
|
1019
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
1020
|
+
}
|
|
1021
|
+
if (!response.body) {
|
|
1022
|
+
throw new Error("Response body is null");
|
|
1023
|
+
}
|
|
1024
|
+
const transformStream = new TransformStream({
|
|
1025
|
+
start() {
|
|
1026
|
+
},
|
|
1027
|
+
async transform(chunk, controller) {
|
|
1028
|
+
try {
|
|
1029
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1030
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
1031
|
+
for (const chunk2 of chunks) {
|
|
1032
|
+
if (chunk2) {
|
|
1033
|
+
try {
|
|
1034
|
+
const parsedChunk = JSON.parse(chunk2);
|
|
1035
|
+
controller.enqueue(parsedChunk);
|
|
1036
|
+
} catch {
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
} catch {
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
});
|
|
1044
|
+
return response.body.pipeThrough(transformStream);
|
|
1045
|
+
}
|
|
1046
|
+
/**
|
|
1047
|
+
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
1048
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
1049
|
+
* @returns Promise containing the workflow resume results
|
|
1050
|
+
*/
|
|
1051
|
+
resumeAsync(params) {
|
|
1052
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1053
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
1054
|
+
method: "POST",
|
|
1055
|
+
body: {
|
|
1056
|
+
step: params.step,
|
|
1057
|
+
resumeData: params.resumeData,
|
|
1058
|
+
runtimeContext
|
|
1059
|
+
}
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
* Watches workflow transitions in real-time
|
|
1064
|
+
* @param runId - Optional run ID to filter the watch stream
|
|
1065
|
+
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
1066
|
+
*/
|
|
1067
|
+
async watch({ runId }, onRecord) {
|
|
1068
|
+
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
1069
|
+
stream: true
|
|
1070
|
+
});
|
|
1071
|
+
if (!response.ok) {
|
|
1072
|
+
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
1073
|
+
}
|
|
1074
|
+
if (!response.body) {
|
|
1075
|
+
throw new Error("Response body is null");
|
|
1076
|
+
}
|
|
1077
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
1078
|
+
if (typeof record === "string") {
|
|
1079
|
+
onRecord(JSON.parse(record));
|
|
1080
|
+
} else {
|
|
1081
|
+
onRecord(record);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
1087
|
+
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
1088
|
+
*
|
|
1089
|
+
* @param records - An iterable or async iterable of objects to stream
|
|
1090
|
+
* @returns A ReadableStream emitting the records as JSON strings separated by the record separator
|
|
1091
|
+
*/
|
|
1092
|
+
static createRecordStream(records) {
|
|
1093
|
+
const encoder = new TextEncoder();
|
|
1094
|
+
return new ReadableStream({
|
|
1095
|
+
async start(controller) {
|
|
1096
|
+
try {
|
|
1097
|
+
for await (const record of records) {
|
|
1098
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR2;
|
|
1099
|
+
controller.enqueue(encoder.encode(json));
|
|
1100
|
+
}
|
|
1101
|
+
controller.close();
|
|
1102
|
+
} catch (err) {
|
|
1103
|
+
controller.error(err);
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
|
|
1110
|
+
// src/resources/a2a.ts
|
|
1111
|
+
var A2A = class extends BaseResource {
|
|
1112
|
+
constructor(options, agentId) {
|
|
1113
|
+
super(options);
|
|
1114
|
+
this.agentId = agentId;
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Get the agent card with metadata about the agent
|
|
1118
|
+
* @returns Promise containing the agent card information
|
|
1119
|
+
*/
|
|
1120
|
+
async getCard() {
|
|
1121
|
+
return this.request(`/.well-known/${this.agentId}/agent.json`);
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
* Send a message to the agent and get a response
|
|
1125
|
+
* @param params - Parameters for the task
|
|
1126
|
+
* @returns Promise containing the task response
|
|
1127
|
+
*/
|
|
1128
|
+
async sendMessage(params) {
|
|
1129
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1130
|
+
method: "POST",
|
|
1131
|
+
body: {
|
|
1132
|
+
method: "tasks/send",
|
|
1133
|
+
params
|
|
1134
|
+
}
|
|
1135
|
+
});
|
|
1136
|
+
return { task: response.result };
|
|
1137
|
+
}
|
|
1138
|
+
/**
|
|
1139
|
+
* Get the status and result of a task
|
|
1140
|
+
* @param params - Parameters for querying the task
|
|
1141
|
+
* @returns Promise containing the task response
|
|
1142
|
+
*/
|
|
1143
|
+
async getTask(params) {
|
|
1144
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1145
|
+
method: "POST",
|
|
1146
|
+
body: {
|
|
1147
|
+
method: "tasks/get",
|
|
1148
|
+
params
|
|
1149
|
+
}
|
|
1150
|
+
});
|
|
1151
|
+
return response.result;
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* Cancel a running task
|
|
1155
|
+
* @param params - Parameters identifying the task to cancel
|
|
1156
|
+
* @returns Promise containing the task response
|
|
1157
|
+
*/
|
|
1158
|
+
async cancelTask(params) {
|
|
1159
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
1160
|
+
method: "POST",
|
|
1161
|
+
body: {
|
|
1162
|
+
method: "tasks/cancel",
|
|
1163
|
+
params
|
|
1164
|
+
}
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1167
|
+
/**
|
|
1168
|
+
* Send a message and subscribe to streaming updates (not fully implemented)
|
|
1169
|
+
* @param params - Parameters for the task
|
|
1170
|
+
* @returns Promise containing the task response
|
|
1171
|
+
*/
|
|
1172
|
+
async sendAndSubscribe(params) {
|
|
1173
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
1174
|
+
method: "POST",
|
|
1175
|
+
body: {
|
|
1176
|
+
method: "tasks/sendSubscribe",
|
|
1177
|
+
params
|
|
1178
|
+
},
|
|
1179
|
+
stream: true
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
};
|
|
1183
|
+
|
|
1184
|
+
// src/resources/mcp-tool.ts
|
|
1185
|
+
var MCPTool = class extends BaseResource {
|
|
1186
|
+
serverId;
|
|
1187
|
+
toolId;
|
|
1188
|
+
constructor(options, serverId, toolId) {
|
|
1189
|
+
super(options);
|
|
1190
|
+
this.serverId = serverId;
|
|
1191
|
+
this.toolId = toolId;
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
* Retrieves details about this specific tool from the MCP server.
|
|
1195
|
+
* @returns Promise containing the tool's information (name, description, schema).
|
|
1196
|
+
*/
|
|
1197
|
+
details() {
|
|
1198
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* Executes this specific tool on the MCP server.
|
|
1202
|
+
* @param params - Parameters for tool execution, including data/args and optional runtimeContext.
|
|
1203
|
+
* @returns Promise containing the result of the tool execution.
|
|
1204
|
+
*/
|
|
1205
|
+
execute(params) {
|
|
1206
|
+
const body = {};
|
|
1207
|
+
if (params.data !== void 0) body.data = params.data;
|
|
1208
|
+
if (params.runtimeContext !== void 0) {
|
|
1209
|
+
body.runtimeContext = params.runtimeContext;
|
|
1210
|
+
}
|
|
1211
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
|
|
1212
|
+
method: "POST",
|
|
1213
|
+
body: Object.keys(body).length > 0 ? body : void 0
|
|
547
1214
|
});
|
|
548
1215
|
}
|
|
549
1216
|
};
|
|
@@ -560,6 +1227,21 @@ var MastraClient = class extends BaseResource {
|
|
|
560
1227
|
getAgents() {
|
|
561
1228
|
return this.request("/api/agents");
|
|
562
1229
|
}
|
|
1230
|
+
async getAGUI({ resourceId }) {
|
|
1231
|
+
const agents = await this.getAgents();
|
|
1232
|
+
return Object.entries(agents).reduce(
|
|
1233
|
+
(acc, [agentId]) => {
|
|
1234
|
+
const agent = this.getAgent(agentId);
|
|
1235
|
+
acc[agentId] = new AGUIAdapter({
|
|
1236
|
+
agentId,
|
|
1237
|
+
agent,
|
|
1238
|
+
resourceId
|
|
1239
|
+
});
|
|
1240
|
+
return acc;
|
|
1241
|
+
},
|
|
1242
|
+
{}
|
|
1243
|
+
);
|
|
1244
|
+
}
|
|
563
1245
|
/**
|
|
564
1246
|
* Gets an agent instance by ID
|
|
565
1247
|
* @param agentId - ID of the agent to retrieve
|
|
@@ -625,6 +1307,21 @@ var MastraClient = class extends BaseResource {
|
|
|
625
1307
|
getTool(toolId) {
|
|
626
1308
|
return new Tool(this.options, toolId);
|
|
627
1309
|
}
|
|
1310
|
+
/**
|
|
1311
|
+
* Retrieves all available legacy workflows
|
|
1312
|
+
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
1313
|
+
*/
|
|
1314
|
+
getLegacyWorkflows() {
|
|
1315
|
+
return this.request("/api/workflows/legacy");
|
|
1316
|
+
}
|
|
1317
|
+
/**
|
|
1318
|
+
* Gets a legacy workflow instance by ID
|
|
1319
|
+
* @param workflowId - ID of the legacy workflow to retrieve
|
|
1320
|
+
* @returns Legacy Workflow instance
|
|
1321
|
+
*/
|
|
1322
|
+
getLegacyWorkflow(workflowId) {
|
|
1323
|
+
return new LegacyWorkflow(this.options, workflowId);
|
|
1324
|
+
}
|
|
628
1325
|
/**
|
|
629
1326
|
* Retrieves all available workflows
|
|
630
1327
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
@@ -654,7 +1351,41 @@ var MastraClient = class extends BaseResource {
|
|
|
654
1351
|
* @returns Promise containing array of log messages
|
|
655
1352
|
*/
|
|
656
1353
|
getLogs(params) {
|
|
657
|
-
|
|
1354
|
+
const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
1355
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
1356
|
+
const searchParams = new URLSearchParams();
|
|
1357
|
+
if (transportId) {
|
|
1358
|
+
searchParams.set("transportId", transportId);
|
|
1359
|
+
}
|
|
1360
|
+
if (fromDate) {
|
|
1361
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
1362
|
+
}
|
|
1363
|
+
if (toDate) {
|
|
1364
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
1365
|
+
}
|
|
1366
|
+
if (logLevel) {
|
|
1367
|
+
searchParams.set("logLevel", logLevel);
|
|
1368
|
+
}
|
|
1369
|
+
if (page) {
|
|
1370
|
+
searchParams.set("page", String(page));
|
|
1371
|
+
}
|
|
1372
|
+
if (perPage) {
|
|
1373
|
+
searchParams.set("perPage", String(perPage));
|
|
1374
|
+
}
|
|
1375
|
+
if (_filters) {
|
|
1376
|
+
if (Array.isArray(_filters)) {
|
|
1377
|
+
for (const filter of _filters) {
|
|
1378
|
+
searchParams.append("filters", filter);
|
|
1379
|
+
}
|
|
1380
|
+
} else {
|
|
1381
|
+
searchParams.set("filters", _filters);
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
if (searchParams.size) {
|
|
1385
|
+
return this.request(`/api/logs?${searchParams}`);
|
|
1386
|
+
} else {
|
|
1387
|
+
return this.request(`/api/logs`);
|
|
1388
|
+
}
|
|
658
1389
|
}
|
|
659
1390
|
/**
|
|
660
1391
|
* Gets logs for a specific run
|
|
@@ -662,7 +1393,44 @@ var MastraClient = class extends BaseResource {
|
|
|
662
1393
|
* @returns Promise containing array of log messages
|
|
663
1394
|
*/
|
|
664
1395
|
getLogForRun(params) {
|
|
665
|
-
|
|
1396
|
+
const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
1397
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
1398
|
+
const searchParams = new URLSearchParams();
|
|
1399
|
+
if (runId) {
|
|
1400
|
+
searchParams.set("runId", runId);
|
|
1401
|
+
}
|
|
1402
|
+
if (transportId) {
|
|
1403
|
+
searchParams.set("transportId", transportId);
|
|
1404
|
+
}
|
|
1405
|
+
if (fromDate) {
|
|
1406
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
1407
|
+
}
|
|
1408
|
+
if (toDate) {
|
|
1409
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
1410
|
+
}
|
|
1411
|
+
if (logLevel) {
|
|
1412
|
+
searchParams.set("logLevel", logLevel);
|
|
1413
|
+
}
|
|
1414
|
+
if (page) {
|
|
1415
|
+
searchParams.set("page", String(page));
|
|
1416
|
+
}
|
|
1417
|
+
if (perPage) {
|
|
1418
|
+
searchParams.set("perPage", String(perPage));
|
|
1419
|
+
}
|
|
1420
|
+
if (_filters) {
|
|
1421
|
+
if (Array.isArray(_filters)) {
|
|
1422
|
+
for (const filter of _filters) {
|
|
1423
|
+
searchParams.append("filters", filter);
|
|
1424
|
+
}
|
|
1425
|
+
} else {
|
|
1426
|
+
searchParams.set("filters", _filters);
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
if (searchParams.size) {
|
|
1430
|
+
return this.request(`/api/logs/${runId}?${searchParams}`);
|
|
1431
|
+
} else {
|
|
1432
|
+
return this.request(`/api/logs/${runId}`);
|
|
1433
|
+
}
|
|
666
1434
|
}
|
|
667
1435
|
/**
|
|
668
1436
|
* List of all log transports
|
|
@@ -677,7 +1445,7 @@ var MastraClient = class extends BaseResource {
|
|
|
677
1445
|
* @returns Promise containing telemetry data
|
|
678
1446
|
*/
|
|
679
1447
|
getTelemetry(params) {
|
|
680
|
-
const { name, scope, page, perPage, attribute } = params || {};
|
|
1448
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
681
1449
|
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
682
1450
|
const searchParams = new URLSearchParams();
|
|
683
1451
|
if (name) {
|
|
@@ -701,6 +1469,12 @@ var MastraClient = class extends BaseResource {
|
|
|
701
1469
|
searchParams.set("attribute", _attribute);
|
|
702
1470
|
}
|
|
703
1471
|
}
|
|
1472
|
+
if (fromDate) {
|
|
1473
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
1474
|
+
}
|
|
1475
|
+
if (toDate) {
|
|
1476
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
1477
|
+
}
|
|
704
1478
|
if (searchParams.size) {
|
|
705
1479
|
return this.request(`/api/telemetry?${searchParams}`);
|
|
706
1480
|
} else {
|
|
@@ -722,6 +1496,62 @@ var MastraClient = class extends BaseResource {
|
|
|
722
1496
|
getNetwork(networkId) {
|
|
723
1497
|
return new Network(this.options, networkId);
|
|
724
1498
|
}
|
|
1499
|
+
/**
|
|
1500
|
+
* Retrieves a list of available MCP servers.
|
|
1501
|
+
* @param params - Optional parameters for pagination (limit, offset).
|
|
1502
|
+
* @returns Promise containing the list of MCP servers and pagination info.
|
|
1503
|
+
*/
|
|
1504
|
+
getMcpServers(params) {
|
|
1505
|
+
const searchParams = new URLSearchParams();
|
|
1506
|
+
if (params?.limit !== void 0) {
|
|
1507
|
+
searchParams.set("limit", String(params.limit));
|
|
1508
|
+
}
|
|
1509
|
+
if (params?.offset !== void 0) {
|
|
1510
|
+
searchParams.set("offset", String(params.offset));
|
|
1511
|
+
}
|
|
1512
|
+
const queryString = searchParams.toString();
|
|
1513
|
+
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
|
|
1514
|
+
}
|
|
1515
|
+
/**
|
|
1516
|
+
* Retrieves detailed information for a specific MCP server.
|
|
1517
|
+
* @param serverId - The ID of the MCP server to retrieve.
|
|
1518
|
+
* @param params - Optional parameters, e.g., specific version.
|
|
1519
|
+
* @returns Promise containing the detailed MCP server information.
|
|
1520
|
+
*/
|
|
1521
|
+
getMcpServerDetails(serverId, params) {
|
|
1522
|
+
const searchParams = new URLSearchParams();
|
|
1523
|
+
if (params?.version) {
|
|
1524
|
+
searchParams.set("version", params.version);
|
|
1525
|
+
}
|
|
1526
|
+
const queryString = searchParams.toString();
|
|
1527
|
+
return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ""}`);
|
|
1528
|
+
}
|
|
1529
|
+
/**
|
|
1530
|
+
* Retrieves a list of tools for a specific MCP server.
|
|
1531
|
+
* @param serverId - The ID of the MCP server.
|
|
1532
|
+
* @returns Promise containing the list of tools.
|
|
1533
|
+
*/
|
|
1534
|
+
getMcpServerTools(serverId) {
|
|
1535
|
+
return this.request(`/api/mcp/${serverId}/tools`);
|
|
1536
|
+
}
|
|
1537
|
+
/**
|
|
1538
|
+
* Gets an MCPTool resource instance for a specific tool on an MCP server.
|
|
1539
|
+
* This instance can then be used to fetch details or execute the tool.
|
|
1540
|
+
* @param serverId - The ID of the MCP server.
|
|
1541
|
+
* @param toolId - The ID of the tool.
|
|
1542
|
+
* @returns MCPTool instance.
|
|
1543
|
+
*/
|
|
1544
|
+
getMcpServerTool(serverId, toolId) {
|
|
1545
|
+
return new MCPTool(this.options, serverId, toolId);
|
|
1546
|
+
}
|
|
1547
|
+
/**
|
|
1548
|
+
* Gets an A2A client for interacting with an agent via the A2A protocol
|
|
1549
|
+
* @param agentId - ID of the agent to interact with
|
|
1550
|
+
* @returns A2A client instance
|
|
1551
|
+
*/
|
|
1552
|
+
getA2A(agentId) {
|
|
1553
|
+
return new A2A(this.options, agentId);
|
|
1554
|
+
}
|
|
725
1555
|
};
|
|
726
1556
|
|
|
727
1557
|
export { MastraClient };
|