@mastra/client-js 0.0.0-switch-to-core-20250424015131 → 0.0.0-tool-call-parts-20250630193309
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/.turbo/turbo-build.log +19 -0
- package/CHANGELOG.md +813 -2
- package/README.md +1 -1
- package/dist/index.cjs +1546 -93
- package/dist/index.d.cts +588 -40
- package/dist/index.d.ts +588 -40
- package/dist/index.js +1545 -96
- package/package.json +22 -15
- package/src/adapters/agui.test.ts +180 -0
- package/src/adapters/agui.ts +239 -0
- package/src/client.ts +271 -5
- package/src/example.ts +33 -31
- package/src/index.test.ts +125 -5
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +585 -45
- package/src/resources/base.ts +3 -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 +13 -3
- package/src/resources/network-memory-thread.ts +63 -0
- package/src/resources/network.ts +7 -14
- package/src/resources/tool.ts +16 -3
- package/src/resources/vNextNetwork.ts +177 -0
- package/src/resources/workflow.ts +254 -96
- package/src/types.ts +204 -17
- package/src/utils/index.ts +11 -0
- package/src/utils/process-client-tools.ts +32 -0
- package/src/utils/zod-to-json-schema.ts +10 -0
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,235 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var client = require('@ag-ui/client');
|
|
4
|
+
var rxjs = require('rxjs');
|
|
5
5
|
var uiUtils = require('@ai-sdk/ui-utils');
|
|
6
|
+
var zod = require('zod');
|
|
7
|
+
var originalZodToJsonSchema = require('zod-to-json-schema');
|
|
8
|
+
var tools = require('@mastra/core/tools');
|
|
9
|
+
var runtimeContext = require('@mastra/core/runtime-context');
|
|
10
|
+
|
|
11
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
|
|
13
|
+
var originalZodToJsonSchema__default = /*#__PURE__*/_interopDefault(originalZodToJsonSchema);
|
|
6
14
|
|
|
7
|
-
// src/
|
|
15
|
+
// src/adapters/agui.ts
|
|
16
|
+
var AGUIAdapter = class extends client.AbstractAgent {
|
|
17
|
+
agent;
|
|
18
|
+
resourceId;
|
|
19
|
+
constructor({ agent, agentId, resourceId, ...rest }) {
|
|
20
|
+
super({
|
|
21
|
+
agentId,
|
|
22
|
+
...rest
|
|
23
|
+
});
|
|
24
|
+
this.agent = agent;
|
|
25
|
+
this.resourceId = resourceId;
|
|
26
|
+
}
|
|
27
|
+
run(input) {
|
|
28
|
+
return new rxjs.Observable((subscriber) => {
|
|
29
|
+
const convertedMessages = convertMessagesToMastraMessages(input.messages);
|
|
30
|
+
subscriber.next({
|
|
31
|
+
type: client.EventType.RUN_STARTED,
|
|
32
|
+
threadId: input.threadId,
|
|
33
|
+
runId: input.runId
|
|
34
|
+
});
|
|
35
|
+
this.agent.stream({
|
|
36
|
+
threadId: input.threadId,
|
|
37
|
+
resourceId: this.resourceId ?? "",
|
|
38
|
+
runId: input.runId,
|
|
39
|
+
messages: convertedMessages,
|
|
40
|
+
clientTools: input.tools.reduce(
|
|
41
|
+
(acc, tool) => {
|
|
42
|
+
acc[tool.name] = {
|
|
43
|
+
id: tool.name,
|
|
44
|
+
description: tool.description,
|
|
45
|
+
inputSchema: tool.parameters
|
|
46
|
+
};
|
|
47
|
+
return acc;
|
|
48
|
+
},
|
|
49
|
+
{}
|
|
50
|
+
)
|
|
51
|
+
}).then((response) => {
|
|
52
|
+
let currentMessageId = void 0;
|
|
53
|
+
let isInTextMessage = false;
|
|
54
|
+
return response.processDataStream({
|
|
55
|
+
onTextPart: (text) => {
|
|
56
|
+
if (currentMessageId === void 0) {
|
|
57
|
+
currentMessageId = generateUUID();
|
|
58
|
+
const message2 = {
|
|
59
|
+
type: client.EventType.TEXT_MESSAGE_START,
|
|
60
|
+
messageId: currentMessageId,
|
|
61
|
+
role: "assistant"
|
|
62
|
+
};
|
|
63
|
+
subscriber.next(message2);
|
|
64
|
+
isInTextMessage = true;
|
|
65
|
+
}
|
|
66
|
+
const message = {
|
|
67
|
+
type: client.EventType.TEXT_MESSAGE_CONTENT,
|
|
68
|
+
messageId: currentMessageId,
|
|
69
|
+
delta: text
|
|
70
|
+
};
|
|
71
|
+
subscriber.next(message);
|
|
72
|
+
},
|
|
73
|
+
onFinishMessagePart: () => {
|
|
74
|
+
if (currentMessageId !== void 0) {
|
|
75
|
+
const message = {
|
|
76
|
+
type: client.EventType.TEXT_MESSAGE_END,
|
|
77
|
+
messageId: currentMessageId
|
|
78
|
+
};
|
|
79
|
+
subscriber.next(message);
|
|
80
|
+
isInTextMessage = false;
|
|
81
|
+
}
|
|
82
|
+
subscriber.next({
|
|
83
|
+
type: client.EventType.RUN_FINISHED,
|
|
84
|
+
threadId: input.threadId,
|
|
85
|
+
runId: input.runId
|
|
86
|
+
});
|
|
87
|
+
subscriber.complete();
|
|
88
|
+
},
|
|
89
|
+
onToolCallPart(streamPart) {
|
|
90
|
+
const parentMessageId = currentMessageId || generateUUID();
|
|
91
|
+
if (isInTextMessage) {
|
|
92
|
+
const message = {
|
|
93
|
+
type: client.EventType.TEXT_MESSAGE_END,
|
|
94
|
+
messageId: parentMessageId
|
|
95
|
+
};
|
|
96
|
+
subscriber.next(message);
|
|
97
|
+
isInTextMessage = false;
|
|
98
|
+
}
|
|
99
|
+
subscriber.next({
|
|
100
|
+
type: client.EventType.TOOL_CALL_START,
|
|
101
|
+
toolCallId: streamPart.toolCallId,
|
|
102
|
+
toolCallName: streamPart.toolName,
|
|
103
|
+
parentMessageId
|
|
104
|
+
});
|
|
105
|
+
subscriber.next({
|
|
106
|
+
type: client.EventType.TOOL_CALL_ARGS,
|
|
107
|
+
toolCallId: streamPart.toolCallId,
|
|
108
|
+
delta: JSON.stringify(streamPart.args),
|
|
109
|
+
parentMessageId
|
|
110
|
+
});
|
|
111
|
+
subscriber.next({
|
|
112
|
+
type: client.EventType.TOOL_CALL_END,
|
|
113
|
+
toolCallId: streamPart.toolCallId,
|
|
114
|
+
parentMessageId
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}).catch((error) => {
|
|
119
|
+
console.error("error", error);
|
|
120
|
+
subscriber.error(error);
|
|
121
|
+
});
|
|
122
|
+
return () => {
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
function generateUUID() {
|
|
128
|
+
if (typeof crypto !== "undefined") {
|
|
129
|
+
if (typeof crypto.randomUUID === "function") {
|
|
130
|
+
return crypto.randomUUID();
|
|
131
|
+
}
|
|
132
|
+
if (typeof crypto.getRandomValues === "function") {
|
|
133
|
+
const buffer = new Uint8Array(16);
|
|
134
|
+
crypto.getRandomValues(buffer);
|
|
135
|
+
buffer[6] = buffer[6] & 15 | 64;
|
|
136
|
+
buffer[8] = buffer[8] & 63 | 128;
|
|
137
|
+
let hex = "";
|
|
138
|
+
for (let i = 0; i < 16; i++) {
|
|
139
|
+
hex += buffer[i].toString(16).padStart(2, "0");
|
|
140
|
+
if (i === 3 || i === 5 || i === 7 || i === 9) hex += "-";
|
|
141
|
+
}
|
|
142
|
+
return hex;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
146
|
+
const r = Math.random() * 16 | 0;
|
|
147
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
148
|
+
return v.toString(16);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function convertMessagesToMastraMessages(messages) {
|
|
152
|
+
const result = [];
|
|
153
|
+
for (const message of messages) {
|
|
154
|
+
if (message.role === "assistant") {
|
|
155
|
+
const parts = message.content ? [{ type: "text", text: message.content }] : [];
|
|
156
|
+
for (const toolCall of message.toolCalls ?? []) {
|
|
157
|
+
parts.push({
|
|
158
|
+
type: "tool-call",
|
|
159
|
+
toolCallId: toolCall.id,
|
|
160
|
+
toolName: toolCall.function.name,
|
|
161
|
+
args: JSON.parse(toolCall.function.arguments)
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
result.push({
|
|
165
|
+
role: "assistant",
|
|
166
|
+
content: parts
|
|
167
|
+
});
|
|
168
|
+
if (message.toolCalls?.length) {
|
|
169
|
+
result.push({
|
|
170
|
+
role: "tool",
|
|
171
|
+
content: message.toolCalls.map((toolCall) => ({
|
|
172
|
+
type: "tool-result",
|
|
173
|
+
toolCallId: toolCall.id,
|
|
174
|
+
toolName: toolCall.function.name,
|
|
175
|
+
result: JSON.parse(toolCall.function.arguments)
|
|
176
|
+
}))
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
} else if (message.role === "user") {
|
|
180
|
+
result.push({
|
|
181
|
+
role: "user",
|
|
182
|
+
content: message.content || ""
|
|
183
|
+
});
|
|
184
|
+
} else if (message.role === "tool") {
|
|
185
|
+
result.push({
|
|
186
|
+
role: "tool",
|
|
187
|
+
content: [
|
|
188
|
+
{
|
|
189
|
+
type: "tool-result",
|
|
190
|
+
toolCallId: message.toolCallId,
|
|
191
|
+
toolName: "unknown",
|
|
192
|
+
result: message.content
|
|
193
|
+
}
|
|
194
|
+
]
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
function zodToJsonSchema(zodSchema) {
|
|
201
|
+
if (!(zodSchema instanceof zod.ZodSchema)) {
|
|
202
|
+
return zodSchema;
|
|
203
|
+
}
|
|
204
|
+
return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "none" });
|
|
205
|
+
}
|
|
206
|
+
function processClientTools(clientTools) {
|
|
207
|
+
if (!clientTools) {
|
|
208
|
+
return void 0;
|
|
209
|
+
}
|
|
210
|
+
return Object.fromEntries(
|
|
211
|
+
Object.entries(clientTools).map(([key, value]) => {
|
|
212
|
+
if (tools.isVercelTool(value)) {
|
|
213
|
+
return [
|
|
214
|
+
key,
|
|
215
|
+
{
|
|
216
|
+
...value,
|
|
217
|
+
parameters: value.parameters ? zodToJsonSchema(value.parameters) : void 0
|
|
218
|
+
}
|
|
219
|
+
];
|
|
220
|
+
} else {
|
|
221
|
+
return [
|
|
222
|
+
key,
|
|
223
|
+
{
|
|
224
|
+
...value,
|
|
225
|
+
inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : void 0,
|
|
226
|
+
outputSchema: value.outputSchema ? zodToJsonSchema(value.outputSchema) : void 0
|
|
227
|
+
}
|
|
228
|
+
];
|
|
229
|
+
}
|
|
230
|
+
})
|
|
231
|
+
);
|
|
232
|
+
}
|
|
8
233
|
|
|
9
234
|
// src/resources/base.ts
|
|
10
235
|
var BaseResource = class {
|
|
@@ -24,9 +249,10 @@ var BaseResource = class {
|
|
|
24
249
|
let delay = backoffMs;
|
|
25
250
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
26
251
|
try {
|
|
27
|
-
const response = await fetch(`${baseUrl}${path}`, {
|
|
252
|
+
const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
|
|
28
253
|
...options,
|
|
29
254
|
headers: {
|
|
255
|
+
...options.method === "POST" || options.method === "PUT" ? { "content-type": "application/json" } : {},
|
|
30
256
|
...headers,
|
|
31
257
|
...options.headers
|
|
32
258
|
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
|
@@ -64,8 +290,15 @@ var BaseResource = class {
|
|
|
64
290
|
throw lastError || new Error("Request failed");
|
|
65
291
|
}
|
|
66
292
|
};
|
|
67
|
-
|
|
68
|
-
|
|
293
|
+
function parseClientRuntimeContext(runtimeContext$1) {
|
|
294
|
+
if (runtimeContext$1) {
|
|
295
|
+
if (runtimeContext$1 instanceof runtimeContext.RuntimeContext) {
|
|
296
|
+
return Object.fromEntries(runtimeContext$1.entries());
|
|
297
|
+
}
|
|
298
|
+
return runtimeContext$1;
|
|
299
|
+
}
|
|
300
|
+
return void 0;
|
|
301
|
+
}
|
|
69
302
|
var AgentVoice = class extends BaseResource {
|
|
70
303
|
constructor(options, agentId) {
|
|
71
304
|
super(options);
|
|
@@ -112,6 +345,13 @@ var AgentVoice = class extends BaseResource {
|
|
|
112
345
|
getSpeakers() {
|
|
113
346
|
return this.request(`/api/agents/${this.agentId}/voice/speakers`);
|
|
114
347
|
}
|
|
348
|
+
/**
|
|
349
|
+
* Get the listener configuration for the agent's voice provider
|
|
350
|
+
* @returns Promise containing a check if the agent has listening capabilities
|
|
351
|
+
*/
|
|
352
|
+
getListener() {
|
|
353
|
+
return this.request(`/api/agents/${this.agentId}/voice/listener`);
|
|
354
|
+
}
|
|
115
355
|
};
|
|
116
356
|
var Agent = class extends BaseResource {
|
|
117
357
|
constructor(options, agentId) {
|
|
@@ -127,21 +367,318 @@ var Agent = class extends BaseResource {
|
|
|
127
367
|
details() {
|
|
128
368
|
return this.request(`/api/agents/${this.agentId}`);
|
|
129
369
|
}
|
|
130
|
-
|
|
131
|
-
* Generates a response from the agent
|
|
132
|
-
* @param params - Generation parameters including prompt
|
|
133
|
-
* @returns Promise containing the generated response
|
|
134
|
-
*/
|
|
135
|
-
generate(params) {
|
|
370
|
+
async generate(params) {
|
|
136
371
|
const processedParams = {
|
|
137
372
|
...params,
|
|
138
|
-
output: params.output
|
|
139
|
-
experimental_output: params.experimental_output
|
|
373
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
374
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
375
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
376
|
+
clientTools: processClientTools(params.clientTools)
|
|
140
377
|
};
|
|
141
|
-
|
|
378
|
+
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
379
|
+
const response = await this.request(`/api/agents/${this.agentId}/generate`, {
|
|
142
380
|
method: "POST",
|
|
143
381
|
body: processedParams
|
|
144
382
|
});
|
|
383
|
+
if (response.finishReason === "tool-calls") {
|
|
384
|
+
for (const toolCall of response.toolCalls) {
|
|
385
|
+
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
386
|
+
if (clientTool && clientTool.execute) {
|
|
387
|
+
const result = await clientTool.execute(
|
|
388
|
+
{ context: toolCall?.args, runId, resourceId, threadId, runtimeContext },
|
|
389
|
+
{
|
|
390
|
+
messages: response.messages,
|
|
391
|
+
toolCallId: toolCall?.toolCallId
|
|
392
|
+
}
|
|
393
|
+
);
|
|
394
|
+
const updatedMessages = [
|
|
395
|
+
{
|
|
396
|
+
role: "user",
|
|
397
|
+
content: params.messages
|
|
398
|
+
},
|
|
399
|
+
...response.response.messages,
|
|
400
|
+
{
|
|
401
|
+
role: "tool",
|
|
402
|
+
content: [
|
|
403
|
+
{
|
|
404
|
+
type: "tool-result",
|
|
405
|
+
toolCallId: toolCall.toolCallId,
|
|
406
|
+
toolName: toolCall.toolName,
|
|
407
|
+
result
|
|
408
|
+
}
|
|
409
|
+
]
|
|
410
|
+
}
|
|
411
|
+
];
|
|
412
|
+
return this.generate({
|
|
413
|
+
...params,
|
|
414
|
+
messages: updatedMessages
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return response;
|
|
420
|
+
}
|
|
421
|
+
async processChatResponse({
|
|
422
|
+
stream,
|
|
423
|
+
update,
|
|
424
|
+
onToolCall,
|
|
425
|
+
onFinish,
|
|
426
|
+
getCurrentDate = () => /* @__PURE__ */ new Date(),
|
|
427
|
+
lastMessage
|
|
428
|
+
}) {
|
|
429
|
+
const replaceLastMessage = lastMessage?.role === "assistant";
|
|
430
|
+
let step = replaceLastMessage ? 1 + // find max step in existing tool invocations:
|
|
431
|
+
(lastMessage.toolInvocations?.reduce((max, toolInvocation) => {
|
|
432
|
+
return Math.max(max, toolInvocation.step ?? 0);
|
|
433
|
+
}, 0) ?? 0) : 0;
|
|
434
|
+
const message = replaceLastMessage ? structuredClone(lastMessage) : {
|
|
435
|
+
id: crypto.randomUUID(),
|
|
436
|
+
createdAt: getCurrentDate(),
|
|
437
|
+
role: "assistant",
|
|
438
|
+
content: "",
|
|
439
|
+
parts: []
|
|
440
|
+
};
|
|
441
|
+
let currentTextPart = void 0;
|
|
442
|
+
let currentReasoningPart = void 0;
|
|
443
|
+
let currentReasoningTextDetail = void 0;
|
|
444
|
+
function updateToolInvocationPart(toolCallId, invocation) {
|
|
445
|
+
const part = message.parts.find(
|
|
446
|
+
(part2) => part2.type === "tool-invocation" && part2.toolInvocation.toolCallId === toolCallId
|
|
447
|
+
);
|
|
448
|
+
if (part != null) {
|
|
449
|
+
part.toolInvocation = invocation;
|
|
450
|
+
} else {
|
|
451
|
+
message.parts.push({
|
|
452
|
+
type: "tool-invocation",
|
|
453
|
+
toolInvocation: invocation
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
const data = [];
|
|
458
|
+
let messageAnnotations = replaceLastMessage ? lastMessage?.annotations : void 0;
|
|
459
|
+
const partialToolCalls = {};
|
|
460
|
+
let usage = {
|
|
461
|
+
completionTokens: NaN,
|
|
462
|
+
promptTokens: NaN,
|
|
463
|
+
totalTokens: NaN
|
|
464
|
+
};
|
|
465
|
+
let finishReason = "unknown";
|
|
466
|
+
function execUpdate() {
|
|
467
|
+
const copiedData = [...data];
|
|
468
|
+
if (messageAnnotations?.length) {
|
|
469
|
+
message.annotations = messageAnnotations;
|
|
470
|
+
}
|
|
471
|
+
const copiedMessage = {
|
|
472
|
+
// deep copy the message to ensure that deep changes (msg attachments) are updated
|
|
473
|
+
// with SolidJS. SolidJS uses referential integration of sub-objects to detect changes.
|
|
474
|
+
...structuredClone(message),
|
|
475
|
+
// add a revision id to ensure that the message is updated with SWR. SWR uses a
|
|
476
|
+
// hashing approach by default to detect changes, but it only works for shallow
|
|
477
|
+
// changes. This is why we need to add a revision id to ensure that the message
|
|
478
|
+
// is updated with SWR (without it, the changes get stuck in SWR and are not
|
|
479
|
+
// forwarded to rendering):
|
|
480
|
+
revisionId: crypto.randomUUID()
|
|
481
|
+
};
|
|
482
|
+
update({
|
|
483
|
+
message: copiedMessage,
|
|
484
|
+
data: copiedData,
|
|
485
|
+
replaceLastMessage
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
await uiUtils.processDataStream({
|
|
489
|
+
stream,
|
|
490
|
+
onTextPart(value) {
|
|
491
|
+
if (currentTextPart == null) {
|
|
492
|
+
currentTextPart = {
|
|
493
|
+
type: "text",
|
|
494
|
+
text: value
|
|
495
|
+
};
|
|
496
|
+
message.parts.push(currentTextPart);
|
|
497
|
+
} else {
|
|
498
|
+
currentTextPart.text += value;
|
|
499
|
+
}
|
|
500
|
+
message.content += value;
|
|
501
|
+
execUpdate();
|
|
502
|
+
},
|
|
503
|
+
onReasoningPart(value) {
|
|
504
|
+
if (currentReasoningTextDetail == null) {
|
|
505
|
+
currentReasoningTextDetail = { type: "text", text: value };
|
|
506
|
+
if (currentReasoningPart != null) {
|
|
507
|
+
currentReasoningPart.details.push(currentReasoningTextDetail);
|
|
508
|
+
}
|
|
509
|
+
} else {
|
|
510
|
+
currentReasoningTextDetail.text += value;
|
|
511
|
+
}
|
|
512
|
+
if (currentReasoningPart == null) {
|
|
513
|
+
currentReasoningPart = {
|
|
514
|
+
type: "reasoning",
|
|
515
|
+
reasoning: value,
|
|
516
|
+
details: [currentReasoningTextDetail]
|
|
517
|
+
};
|
|
518
|
+
message.parts.push(currentReasoningPart);
|
|
519
|
+
} else {
|
|
520
|
+
currentReasoningPart.reasoning += value;
|
|
521
|
+
}
|
|
522
|
+
message.reasoning = (message.reasoning ?? "") + value;
|
|
523
|
+
execUpdate();
|
|
524
|
+
},
|
|
525
|
+
onReasoningSignaturePart(value) {
|
|
526
|
+
if (currentReasoningTextDetail != null) {
|
|
527
|
+
currentReasoningTextDetail.signature = value.signature;
|
|
528
|
+
}
|
|
529
|
+
},
|
|
530
|
+
onRedactedReasoningPart(value) {
|
|
531
|
+
if (currentReasoningPart == null) {
|
|
532
|
+
currentReasoningPart = {
|
|
533
|
+
type: "reasoning",
|
|
534
|
+
reasoning: "",
|
|
535
|
+
details: []
|
|
536
|
+
};
|
|
537
|
+
message.parts.push(currentReasoningPart);
|
|
538
|
+
}
|
|
539
|
+
currentReasoningPart.details.push({
|
|
540
|
+
type: "redacted",
|
|
541
|
+
data: value.data
|
|
542
|
+
});
|
|
543
|
+
currentReasoningTextDetail = void 0;
|
|
544
|
+
execUpdate();
|
|
545
|
+
},
|
|
546
|
+
onFilePart(value) {
|
|
547
|
+
message.parts.push({
|
|
548
|
+
type: "file",
|
|
549
|
+
mimeType: value.mimeType,
|
|
550
|
+
data: value.data
|
|
551
|
+
});
|
|
552
|
+
execUpdate();
|
|
553
|
+
},
|
|
554
|
+
onSourcePart(value) {
|
|
555
|
+
message.parts.push({
|
|
556
|
+
type: "source",
|
|
557
|
+
source: value
|
|
558
|
+
});
|
|
559
|
+
execUpdate();
|
|
560
|
+
},
|
|
561
|
+
onToolCallStreamingStartPart(value) {
|
|
562
|
+
if (message.toolInvocations == null) {
|
|
563
|
+
message.toolInvocations = [];
|
|
564
|
+
}
|
|
565
|
+
partialToolCalls[value.toolCallId] = {
|
|
566
|
+
text: "",
|
|
567
|
+
step,
|
|
568
|
+
toolName: value.toolName,
|
|
569
|
+
index: message.toolInvocations.length
|
|
570
|
+
};
|
|
571
|
+
const invocation = {
|
|
572
|
+
state: "partial-call",
|
|
573
|
+
step,
|
|
574
|
+
toolCallId: value.toolCallId,
|
|
575
|
+
toolName: value.toolName,
|
|
576
|
+
args: void 0
|
|
577
|
+
};
|
|
578
|
+
message.toolInvocations.push(invocation);
|
|
579
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
580
|
+
execUpdate();
|
|
581
|
+
},
|
|
582
|
+
onToolCallDeltaPart(value) {
|
|
583
|
+
const partialToolCall = partialToolCalls[value.toolCallId];
|
|
584
|
+
partialToolCall.text += value.argsTextDelta;
|
|
585
|
+
const { value: partialArgs } = uiUtils.parsePartialJson(partialToolCall.text);
|
|
586
|
+
const invocation = {
|
|
587
|
+
state: "partial-call",
|
|
588
|
+
step: partialToolCall.step,
|
|
589
|
+
toolCallId: value.toolCallId,
|
|
590
|
+
toolName: partialToolCall.toolName,
|
|
591
|
+
args: partialArgs
|
|
592
|
+
};
|
|
593
|
+
message.toolInvocations[partialToolCall.index] = invocation;
|
|
594
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
595
|
+
execUpdate();
|
|
596
|
+
},
|
|
597
|
+
async onToolCallPart(value) {
|
|
598
|
+
const invocation = {
|
|
599
|
+
state: "call",
|
|
600
|
+
step,
|
|
601
|
+
...value
|
|
602
|
+
};
|
|
603
|
+
if (partialToolCalls[value.toolCallId] != null) {
|
|
604
|
+
message.toolInvocations[partialToolCalls[value.toolCallId].index] = invocation;
|
|
605
|
+
} else {
|
|
606
|
+
if (message.toolInvocations == null) {
|
|
607
|
+
message.toolInvocations = [];
|
|
608
|
+
}
|
|
609
|
+
message.toolInvocations.push(invocation);
|
|
610
|
+
}
|
|
611
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
612
|
+
execUpdate();
|
|
613
|
+
if (onToolCall) {
|
|
614
|
+
const result = await onToolCall({ toolCall: value });
|
|
615
|
+
if (result != null) {
|
|
616
|
+
const invocation2 = {
|
|
617
|
+
state: "result",
|
|
618
|
+
step,
|
|
619
|
+
...value,
|
|
620
|
+
result
|
|
621
|
+
};
|
|
622
|
+
message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
|
|
623
|
+
updateToolInvocationPart(value.toolCallId, invocation2);
|
|
624
|
+
execUpdate();
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
},
|
|
628
|
+
onToolResultPart(value) {
|
|
629
|
+
const toolInvocations = message.toolInvocations;
|
|
630
|
+
if (toolInvocations == null) {
|
|
631
|
+
throw new Error("tool_result must be preceded by a tool_call");
|
|
632
|
+
}
|
|
633
|
+
const toolInvocationIndex = toolInvocations.findIndex((invocation2) => invocation2.toolCallId === value.toolCallId);
|
|
634
|
+
if (toolInvocationIndex === -1) {
|
|
635
|
+
throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
|
|
636
|
+
}
|
|
637
|
+
const invocation = {
|
|
638
|
+
...toolInvocations[toolInvocationIndex],
|
|
639
|
+
state: "result",
|
|
640
|
+
...value
|
|
641
|
+
};
|
|
642
|
+
toolInvocations[toolInvocationIndex] = invocation;
|
|
643
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
644
|
+
execUpdate();
|
|
645
|
+
},
|
|
646
|
+
onDataPart(value) {
|
|
647
|
+
data.push(...value);
|
|
648
|
+
execUpdate();
|
|
649
|
+
},
|
|
650
|
+
onMessageAnnotationsPart(value) {
|
|
651
|
+
if (messageAnnotations == null) {
|
|
652
|
+
messageAnnotations = [...value];
|
|
653
|
+
} else {
|
|
654
|
+
messageAnnotations.push(...value);
|
|
655
|
+
}
|
|
656
|
+
execUpdate();
|
|
657
|
+
},
|
|
658
|
+
onFinishStepPart(value) {
|
|
659
|
+
step += 1;
|
|
660
|
+
currentTextPart = value.isContinued ? currentTextPart : void 0;
|
|
661
|
+
currentReasoningPart = void 0;
|
|
662
|
+
currentReasoningTextDetail = void 0;
|
|
663
|
+
},
|
|
664
|
+
onStartStepPart(value) {
|
|
665
|
+
if (!replaceLastMessage) {
|
|
666
|
+
message.id = value.messageId;
|
|
667
|
+
}
|
|
668
|
+
message.parts.push({ type: "step-start" });
|
|
669
|
+
execUpdate();
|
|
670
|
+
},
|
|
671
|
+
onFinishMessagePart(value) {
|
|
672
|
+
finishReason = value.finishReason;
|
|
673
|
+
if (value.usage != null) {
|
|
674
|
+
usage = value.usage;
|
|
675
|
+
}
|
|
676
|
+
},
|
|
677
|
+
onErrorPart(error) {
|
|
678
|
+
throw new Error(error);
|
|
679
|
+
}
|
|
680
|
+
});
|
|
681
|
+
onFinish?.({ message, finishReason, usage });
|
|
145
682
|
}
|
|
146
683
|
/**
|
|
147
684
|
* Streams a response from the agent
|
|
@@ -151,9 +688,30 @@ var Agent = class extends BaseResource {
|
|
|
151
688
|
async stream(params) {
|
|
152
689
|
const processedParams = {
|
|
153
690
|
...params,
|
|
154
|
-
output: params.output
|
|
155
|
-
experimental_output: params.experimental_output
|
|
691
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
692
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
693
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
694
|
+
clientTools: processClientTools(params.clientTools)
|
|
695
|
+
};
|
|
696
|
+
const { readable, writable } = new TransformStream();
|
|
697
|
+
const response = await this.processStreamResponse(processedParams, writable);
|
|
698
|
+
const streamResponse = new Response(readable, {
|
|
699
|
+
status: response.status,
|
|
700
|
+
statusText: response.statusText,
|
|
701
|
+
headers: response.headers
|
|
702
|
+
});
|
|
703
|
+
streamResponse.processDataStream = async (options = {}) => {
|
|
704
|
+
await uiUtils.processDataStream({
|
|
705
|
+
stream: streamResponse.body,
|
|
706
|
+
...options
|
|
707
|
+
});
|
|
156
708
|
};
|
|
709
|
+
return streamResponse;
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Processes the stream response and handles tool calls
|
|
713
|
+
*/
|
|
714
|
+
async processStreamResponse(processedParams, writable) {
|
|
157
715
|
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
158
716
|
method: "POST",
|
|
159
717
|
body: processedParams,
|
|
@@ -162,12 +720,82 @@ var Agent = class extends BaseResource {
|
|
|
162
720
|
if (!response.body) {
|
|
163
721
|
throw new Error("No response body");
|
|
164
722
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
723
|
+
try {
|
|
724
|
+
let toolCalls = [];
|
|
725
|
+
let messages = [];
|
|
726
|
+
const [streamForWritable, streamForProcessing] = response.body.tee();
|
|
727
|
+
streamForWritable.pipeTo(writable, {
|
|
728
|
+
preventClose: true
|
|
729
|
+
}).catch((error) => {
|
|
730
|
+
console.error("Error piping to writable stream:", error);
|
|
169
731
|
});
|
|
170
|
-
|
|
732
|
+
this.processChatResponse({
|
|
733
|
+
stream: streamForProcessing,
|
|
734
|
+
update: ({ message }) => {
|
|
735
|
+
messages.push(message);
|
|
736
|
+
},
|
|
737
|
+
onFinish: async ({ finishReason, message }) => {
|
|
738
|
+
if (finishReason === "tool-calls") {
|
|
739
|
+
const toolCall = [...message?.parts ?? []].reverse().find((part) => part.type === "tool-invocation")?.toolInvocation;
|
|
740
|
+
if (toolCall) {
|
|
741
|
+
toolCalls.push(toolCall);
|
|
742
|
+
}
|
|
743
|
+
for (const toolCall2 of toolCalls) {
|
|
744
|
+
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
745
|
+
if (clientTool && clientTool.execute) {
|
|
746
|
+
const result = await clientTool.execute(
|
|
747
|
+
{
|
|
748
|
+
context: toolCall2?.args,
|
|
749
|
+
runId: processedParams.runId,
|
|
750
|
+
resourceId: processedParams.resourceId,
|
|
751
|
+
threadId: processedParams.threadId,
|
|
752
|
+
runtimeContext: processedParams.runtimeContext
|
|
753
|
+
},
|
|
754
|
+
{
|
|
755
|
+
messages: response.messages,
|
|
756
|
+
toolCallId: toolCall2?.toolCallId
|
|
757
|
+
}
|
|
758
|
+
);
|
|
759
|
+
const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
|
|
760
|
+
const toolInvocationPart = lastMessage?.parts?.find(
|
|
761
|
+
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
762
|
+
);
|
|
763
|
+
if (toolInvocationPart) {
|
|
764
|
+
toolInvocationPart.toolInvocation = {
|
|
765
|
+
...toolInvocationPart.toolInvocation,
|
|
766
|
+
state: "result",
|
|
767
|
+
result
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
const toolInvocation = lastMessage?.toolInvocations?.find(
|
|
771
|
+
(toolInvocation2) => toolInvocation2.toolCallId === toolCall2.toolCallId
|
|
772
|
+
);
|
|
773
|
+
if (toolInvocation) {
|
|
774
|
+
toolInvocation.state = "result";
|
|
775
|
+
toolInvocation.result = result;
|
|
776
|
+
}
|
|
777
|
+
const originalMessages = processedParams.messages;
|
|
778
|
+
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
779
|
+
this.processStreamResponse(
|
|
780
|
+
{
|
|
781
|
+
...processedParams,
|
|
782
|
+
messages: [...messageArray, ...messages, lastMessage]
|
|
783
|
+
},
|
|
784
|
+
writable
|
|
785
|
+
);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
} else {
|
|
789
|
+
setTimeout(() => {
|
|
790
|
+
writable.close();
|
|
791
|
+
}, 0);
|
|
792
|
+
}
|
|
793
|
+
},
|
|
794
|
+
lastMessage: void 0
|
|
795
|
+
});
|
|
796
|
+
} catch (error) {
|
|
797
|
+
console.error("Error processing stream response:", error);
|
|
798
|
+
}
|
|
171
799
|
return response;
|
|
172
800
|
}
|
|
173
801
|
/**
|
|
@@ -178,6 +806,22 @@ var Agent = class extends BaseResource {
|
|
|
178
806
|
getTool(toolId) {
|
|
179
807
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
180
808
|
}
|
|
809
|
+
/**
|
|
810
|
+
* Executes a tool for the agent
|
|
811
|
+
* @param toolId - ID of the tool to execute
|
|
812
|
+
* @param params - Parameters required for tool execution
|
|
813
|
+
* @returns Promise containing the tool execution results
|
|
814
|
+
*/
|
|
815
|
+
executeTool(toolId, params) {
|
|
816
|
+
const body = {
|
|
817
|
+
data: params.data,
|
|
818
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
819
|
+
};
|
|
820
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
821
|
+
method: "POST",
|
|
822
|
+
body
|
|
823
|
+
});
|
|
824
|
+
}
|
|
181
825
|
/**
|
|
182
826
|
* Retrieves evaluation results for the agent
|
|
183
827
|
* @returns Promise containing agent evaluations
|
|
@@ -213,8 +857,8 @@ var Network = class extends BaseResource {
|
|
|
213
857
|
generate(params) {
|
|
214
858
|
const processedParams = {
|
|
215
859
|
...params,
|
|
216
|
-
output:
|
|
217
|
-
experimental_output:
|
|
860
|
+
output: zodToJsonSchema(params.output),
|
|
861
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
218
862
|
};
|
|
219
863
|
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
220
864
|
method: "POST",
|
|
@@ -229,8 +873,8 @@ var Network = class extends BaseResource {
|
|
|
229
873
|
async stream(params) {
|
|
230
874
|
const processedParams = {
|
|
231
875
|
...params,
|
|
232
|
-
output:
|
|
233
|
-
experimental_output:
|
|
876
|
+
output: zodToJsonSchema(params.output),
|
|
877
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
234
878
|
};
|
|
235
879
|
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
236
880
|
method: "POST",
|
|
@@ -286,10 +930,15 @@ var MemoryThread = class extends BaseResource {
|
|
|
286
930
|
}
|
|
287
931
|
/**
|
|
288
932
|
* Retrieves messages associated with the thread
|
|
933
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
289
934
|
* @returns Promise containing thread messages and UI messages
|
|
290
935
|
*/
|
|
291
|
-
getMessages() {
|
|
292
|
-
|
|
936
|
+
getMessages(params) {
|
|
937
|
+
const query = new URLSearchParams({
|
|
938
|
+
agentId: this.agentId,
|
|
939
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
940
|
+
});
|
|
941
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
293
942
|
}
|
|
294
943
|
};
|
|
295
944
|
|
|
@@ -359,34 +1008,50 @@ var Vector = class extends BaseResource {
|
|
|
359
1008
|
}
|
|
360
1009
|
};
|
|
361
1010
|
|
|
362
|
-
// src/resources/workflow.ts
|
|
1011
|
+
// src/resources/legacy-workflow.ts
|
|
363
1012
|
var RECORD_SEPARATOR = "";
|
|
364
|
-
var
|
|
1013
|
+
var LegacyWorkflow = class extends BaseResource {
|
|
365
1014
|
constructor(options, workflowId) {
|
|
366
1015
|
super(options);
|
|
367
1016
|
this.workflowId = workflowId;
|
|
368
1017
|
}
|
|
369
1018
|
/**
|
|
370
|
-
* Retrieves details about the workflow
|
|
371
|
-
* @returns Promise containing workflow details including steps and graphs
|
|
1019
|
+
* Retrieves details about the legacy workflow
|
|
1020
|
+
* @returns Promise containing legacy workflow details including steps and graphs
|
|
372
1021
|
*/
|
|
373
1022
|
details() {
|
|
374
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
1023
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}`);
|
|
375
1024
|
}
|
|
376
1025
|
/**
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
* @
|
|
380
|
-
* @returns Promise containing the workflow execution results
|
|
1026
|
+
* Retrieves all runs for a legacy workflow
|
|
1027
|
+
* @param params - Parameters for filtering runs
|
|
1028
|
+
* @returns Promise containing legacy workflow runs array
|
|
381
1029
|
*/
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
}
|
|
1030
|
+
runs(params) {
|
|
1031
|
+
const searchParams = new URLSearchParams();
|
|
1032
|
+
if (params?.fromDate) {
|
|
1033
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
1034
|
+
}
|
|
1035
|
+
if (params?.toDate) {
|
|
1036
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
1037
|
+
}
|
|
1038
|
+
if (params?.limit) {
|
|
1039
|
+
searchParams.set("limit", String(params.limit));
|
|
1040
|
+
}
|
|
1041
|
+
if (params?.offset) {
|
|
1042
|
+
searchParams.set("offset", String(params.offset));
|
|
1043
|
+
}
|
|
1044
|
+
if (params?.resourceId) {
|
|
1045
|
+
searchParams.set("resourceId", params.resourceId);
|
|
1046
|
+
}
|
|
1047
|
+
if (searchParams.size) {
|
|
1048
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
1049
|
+
} else {
|
|
1050
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
1051
|
+
}
|
|
387
1052
|
}
|
|
388
1053
|
/**
|
|
389
|
-
* Creates a new workflow run
|
|
1054
|
+
* Creates a new legacy workflow run
|
|
390
1055
|
* @returns Promise containing the generated run ID
|
|
391
1056
|
*/
|
|
392
1057
|
createRun(params) {
|
|
@@ -394,34 +1059,34 @@ var Workflow = class extends BaseResource {
|
|
|
394
1059
|
if (!!params?.runId) {
|
|
395
1060
|
searchParams.set("runId", params.runId);
|
|
396
1061
|
}
|
|
397
|
-
return this.request(`/api/workflows/${this.workflowId}/
|
|
1062
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
398
1063
|
method: "POST"
|
|
399
1064
|
});
|
|
400
1065
|
}
|
|
401
1066
|
/**
|
|
402
|
-
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1067
|
+
* Starts a legacy workflow run synchronously without waiting for the workflow to complete
|
|
403
1068
|
* @param params - Object containing the runId and triggerData
|
|
404
1069
|
* @returns Promise containing success message
|
|
405
1070
|
*/
|
|
406
1071
|
start(params) {
|
|
407
|
-
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1072
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
408
1073
|
method: "POST",
|
|
409
1074
|
body: params?.triggerData
|
|
410
1075
|
});
|
|
411
1076
|
}
|
|
412
1077
|
/**
|
|
413
|
-
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
1078
|
+
* Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
|
|
414
1079
|
* @param stepId - ID of the step to resume
|
|
415
|
-
* @param runId - ID of the workflow run
|
|
416
|
-
* @param context - Context to resume the workflow with
|
|
417
|
-
* @returns Promise containing the workflow resume results
|
|
1080
|
+
* @param runId - ID of the legacy workflow run
|
|
1081
|
+
* @param context - Context to resume the legacy workflow with
|
|
1082
|
+
* @returns Promise containing the legacy workflow resume results
|
|
418
1083
|
*/
|
|
419
1084
|
resume({
|
|
420
1085
|
stepId,
|
|
421
1086
|
runId,
|
|
422
1087
|
context
|
|
423
1088
|
}) {
|
|
424
|
-
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1089
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
425
1090
|
method: "POST",
|
|
426
1091
|
body: {
|
|
427
1092
|
stepId,
|
|
@@ -439,18 +1104,18 @@ var Workflow = class extends BaseResource {
|
|
|
439
1104
|
if (!!params?.runId) {
|
|
440
1105
|
searchParams.set("runId", params.runId);
|
|
441
1106
|
}
|
|
442
|
-
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1107
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
443
1108
|
method: "POST",
|
|
444
1109
|
body: params?.triggerData
|
|
445
1110
|
});
|
|
446
1111
|
}
|
|
447
1112
|
/**
|
|
448
|
-
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
1113
|
+
* Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
449
1114
|
* @param params - Object containing the runId, stepId, and context
|
|
450
1115
|
* @returns Promise containing the workflow resume results
|
|
451
1116
|
*/
|
|
452
1117
|
resumeAsync(params) {
|
|
453
|
-
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
1118
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
454
1119
|
method: "POST",
|
|
455
1120
|
body: {
|
|
456
1121
|
stepId: params.stepId,
|
|
@@ -489,7 +1154,7 @@ var Workflow = class extends BaseResource {
|
|
|
489
1154
|
}
|
|
490
1155
|
}
|
|
491
1156
|
}
|
|
492
|
-
} catch
|
|
1157
|
+
} catch {
|
|
493
1158
|
}
|
|
494
1159
|
}
|
|
495
1160
|
if (buffer) {
|
|
@@ -504,16 +1169,16 @@ var Workflow = class extends BaseResource {
|
|
|
504
1169
|
}
|
|
505
1170
|
}
|
|
506
1171
|
/**
|
|
507
|
-
* Watches workflow transitions in real-time
|
|
1172
|
+
* Watches legacy workflow transitions in real-time
|
|
508
1173
|
* @param runId - Optional run ID to filter the watch stream
|
|
509
|
-
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
1174
|
+
* @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
|
|
510
1175
|
*/
|
|
511
1176
|
async watch({ runId }, onRecord) {
|
|
512
|
-
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
1177
|
+
const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
|
|
513
1178
|
stream: true
|
|
514
1179
|
});
|
|
515
1180
|
if (!response.ok) {
|
|
516
|
-
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
1181
|
+
throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
|
|
517
1182
|
}
|
|
518
1183
|
if (!response.body) {
|
|
519
1184
|
throw new Error("Response body is null");
|
|
@@ -525,7 +1190,7 @@ var Workflow = class extends BaseResource {
|
|
|
525
1190
|
};
|
|
526
1191
|
|
|
527
1192
|
// src/resources/tool.ts
|
|
528
|
-
var
|
|
1193
|
+
var Tool2 = class extends BaseResource {
|
|
529
1194
|
constructor(options, toolId) {
|
|
530
1195
|
super(options);
|
|
531
1196
|
this.toolId = toolId;
|
|
@@ -543,56 +1208,639 @@ var Tool = class extends BaseResource {
|
|
|
543
1208
|
* @returns Promise containing the tool execution results
|
|
544
1209
|
*/
|
|
545
1210
|
execute(params) {
|
|
546
|
-
|
|
1211
|
+
const url = new URLSearchParams();
|
|
1212
|
+
if (params.runId) {
|
|
1213
|
+
url.set("runId", params.runId);
|
|
1214
|
+
}
|
|
1215
|
+
const body = {
|
|
1216
|
+
data: params.data,
|
|
1217
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1218
|
+
};
|
|
1219
|
+
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
547
1220
|
method: "POST",
|
|
548
|
-
body
|
|
1221
|
+
body
|
|
549
1222
|
});
|
|
550
1223
|
}
|
|
551
1224
|
};
|
|
552
1225
|
|
|
553
|
-
// src/
|
|
554
|
-
var
|
|
555
|
-
|
|
1226
|
+
// src/resources/workflow.ts
|
|
1227
|
+
var RECORD_SEPARATOR2 = "";
|
|
1228
|
+
var Workflow = class extends BaseResource {
|
|
1229
|
+
constructor(options, workflowId) {
|
|
556
1230
|
super(options);
|
|
1231
|
+
this.workflowId = workflowId;
|
|
557
1232
|
}
|
|
558
1233
|
/**
|
|
559
|
-
*
|
|
560
|
-
*
|
|
1234
|
+
* Creates an async generator that processes a readable stream and yields workflow records
|
|
1235
|
+
* separated by the Record Separator character (\x1E)
|
|
1236
|
+
*
|
|
1237
|
+
* @param stream - The readable stream to process
|
|
1238
|
+
* @returns An async generator that yields parsed records
|
|
561
1239
|
*/
|
|
562
|
-
|
|
563
|
-
|
|
1240
|
+
async *streamProcessor(stream) {
|
|
1241
|
+
const reader = stream.getReader();
|
|
1242
|
+
let doneReading = false;
|
|
1243
|
+
let buffer = "";
|
|
1244
|
+
try {
|
|
1245
|
+
while (!doneReading) {
|
|
1246
|
+
const { done, value } = await reader.read();
|
|
1247
|
+
doneReading = done;
|
|
1248
|
+
if (done && !value) continue;
|
|
1249
|
+
try {
|
|
1250
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1251
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
1252
|
+
buffer = chunks.pop() || "";
|
|
1253
|
+
for (const chunk of chunks) {
|
|
1254
|
+
if (chunk) {
|
|
1255
|
+
if (typeof chunk === "string") {
|
|
1256
|
+
try {
|
|
1257
|
+
const parsedChunk = JSON.parse(chunk);
|
|
1258
|
+
yield parsedChunk;
|
|
1259
|
+
} catch {
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
} catch {
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
if (buffer) {
|
|
1268
|
+
try {
|
|
1269
|
+
yield JSON.parse(buffer);
|
|
1270
|
+
} catch {
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
} finally {
|
|
1274
|
+
reader.cancel().catch(() => {
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
564
1277
|
}
|
|
565
1278
|
/**
|
|
566
|
-
*
|
|
567
|
-
* @
|
|
568
|
-
* @returns Agent instance
|
|
1279
|
+
* Retrieves details about the workflow
|
|
1280
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
569
1281
|
*/
|
|
570
|
-
|
|
571
|
-
return
|
|
1282
|
+
details() {
|
|
1283
|
+
return this.request(`/api/workflows/${this.workflowId}`);
|
|
572
1284
|
}
|
|
573
1285
|
/**
|
|
574
|
-
* Retrieves
|
|
575
|
-
* @param params - Parameters
|
|
576
|
-
* @returns Promise containing
|
|
1286
|
+
* Retrieves all runs for a workflow
|
|
1287
|
+
* @param params - Parameters for filtering runs
|
|
1288
|
+
* @returns Promise containing workflow runs array
|
|
577
1289
|
*/
|
|
578
|
-
|
|
579
|
-
|
|
1290
|
+
runs(params) {
|
|
1291
|
+
const searchParams = new URLSearchParams();
|
|
1292
|
+
if (params?.fromDate) {
|
|
1293
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
1294
|
+
}
|
|
1295
|
+
if (params?.toDate) {
|
|
1296
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
1297
|
+
}
|
|
1298
|
+
if (params?.limit) {
|
|
1299
|
+
searchParams.set("limit", String(params.limit));
|
|
1300
|
+
}
|
|
1301
|
+
if (params?.offset) {
|
|
1302
|
+
searchParams.set("offset", String(params.offset));
|
|
1303
|
+
}
|
|
1304
|
+
if (params?.resourceId) {
|
|
1305
|
+
searchParams.set("resourceId", params.resourceId);
|
|
1306
|
+
}
|
|
1307
|
+
if (searchParams.size) {
|
|
1308
|
+
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
1309
|
+
} else {
|
|
1310
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
1311
|
+
}
|
|
580
1312
|
}
|
|
581
1313
|
/**
|
|
582
|
-
*
|
|
583
|
-
* @param
|
|
584
|
-
* @returns Promise containing the
|
|
1314
|
+
* Retrieves a specific workflow run by its ID
|
|
1315
|
+
* @param runId - The ID of the workflow run to retrieve
|
|
1316
|
+
* @returns Promise containing the workflow run details
|
|
585
1317
|
*/
|
|
586
|
-
|
|
587
|
-
return this.request(`/api/
|
|
1318
|
+
runById(runId) {
|
|
1319
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
|
|
588
1320
|
}
|
|
589
1321
|
/**
|
|
590
|
-
*
|
|
591
|
-
* @param
|
|
592
|
-
* @returns
|
|
1322
|
+
* Retrieves the execution result for a specific workflow run by its ID
|
|
1323
|
+
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1324
|
+
* @returns Promise containing the workflow run execution result
|
|
593
1325
|
*/
|
|
594
|
-
|
|
595
|
-
return
|
|
1326
|
+
runExecutionResult(runId) {
|
|
1327
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
|
|
1328
|
+
}
|
|
1329
|
+
/**
|
|
1330
|
+
* Creates a new workflow run
|
|
1331
|
+
* @param params - Optional object containing the optional runId
|
|
1332
|
+
* @returns Promise containing the runId of the created run
|
|
1333
|
+
*/
|
|
1334
|
+
createRun(params) {
|
|
1335
|
+
const searchParams = new URLSearchParams();
|
|
1336
|
+
if (!!params?.runId) {
|
|
1337
|
+
searchParams.set("runId", params.runId);
|
|
1338
|
+
}
|
|
1339
|
+
return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
1340
|
+
method: "POST"
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1343
|
+
/**
|
|
1344
|
+
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1345
|
+
* @param params - Object containing the runId, inputData and runtimeContext
|
|
1346
|
+
* @returns Promise containing success message
|
|
1347
|
+
*/
|
|
1348
|
+
start(params) {
|
|
1349
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1350
|
+
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1351
|
+
method: "POST",
|
|
1352
|
+
body: { inputData: params?.inputData, runtimeContext }
|
|
1353
|
+
});
|
|
1354
|
+
}
|
|
1355
|
+
/**
|
|
1356
|
+
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
1357
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
1358
|
+
* @returns Promise containing success message
|
|
1359
|
+
*/
|
|
1360
|
+
resume({
|
|
1361
|
+
step,
|
|
1362
|
+
runId,
|
|
1363
|
+
resumeData,
|
|
1364
|
+
...rest
|
|
1365
|
+
}) {
|
|
1366
|
+
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
1367
|
+
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1368
|
+
method: "POST",
|
|
1369
|
+
stream: true,
|
|
1370
|
+
body: {
|
|
1371
|
+
step,
|
|
1372
|
+
resumeData,
|
|
1373
|
+
runtimeContext
|
|
1374
|
+
}
|
|
1375
|
+
});
|
|
1376
|
+
}
|
|
1377
|
+
/**
|
|
1378
|
+
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
1379
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
1380
|
+
* @returns Promise containing the workflow execution results
|
|
1381
|
+
*/
|
|
1382
|
+
startAsync(params) {
|
|
1383
|
+
const searchParams = new URLSearchParams();
|
|
1384
|
+
if (!!params?.runId) {
|
|
1385
|
+
searchParams.set("runId", params.runId);
|
|
1386
|
+
}
|
|
1387
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1388
|
+
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1389
|
+
method: "POST",
|
|
1390
|
+
body: { inputData: params.inputData, runtimeContext }
|
|
1391
|
+
});
|
|
1392
|
+
}
|
|
1393
|
+
/**
|
|
1394
|
+
* Starts a workflow run and returns a stream
|
|
1395
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
1396
|
+
* @returns Promise containing the workflow execution results
|
|
1397
|
+
*/
|
|
1398
|
+
async stream(params) {
|
|
1399
|
+
const searchParams = new URLSearchParams();
|
|
1400
|
+
if (!!params?.runId) {
|
|
1401
|
+
searchParams.set("runId", params.runId);
|
|
1402
|
+
}
|
|
1403
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1404
|
+
const response = await this.request(
|
|
1405
|
+
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1406
|
+
{
|
|
1407
|
+
method: "POST",
|
|
1408
|
+
body: { inputData: params.inputData, runtimeContext },
|
|
1409
|
+
stream: true
|
|
1410
|
+
}
|
|
1411
|
+
);
|
|
1412
|
+
if (!response.ok) {
|
|
1413
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
1414
|
+
}
|
|
1415
|
+
if (!response.body) {
|
|
1416
|
+
throw new Error("Response body is null");
|
|
1417
|
+
}
|
|
1418
|
+
const transformStream = new TransformStream({
|
|
1419
|
+
start() {
|
|
1420
|
+
},
|
|
1421
|
+
async transform(chunk, controller) {
|
|
1422
|
+
try {
|
|
1423
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1424
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
1425
|
+
for (const chunk2 of chunks) {
|
|
1426
|
+
if (chunk2) {
|
|
1427
|
+
try {
|
|
1428
|
+
const parsedChunk = JSON.parse(chunk2);
|
|
1429
|
+
controller.enqueue(parsedChunk);
|
|
1430
|
+
} catch {
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
} catch {
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
});
|
|
1438
|
+
return response.body.pipeThrough(transformStream);
|
|
1439
|
+
}
|
|
1440
|
+
/**
|
|
1441
|
+
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
1442
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
1443
|
+
* @returns Promise containing the workflow resume results
|
|
1444
|
+
*/
|
|
1445
|
+
resumeAsync(params) {
|
|
1446
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1447
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
1448
|
+
method: "POST",
|
|
1449
|
+
body: {
|
|
1450
|
+
step: params.step,
|
|
1451
|
+
resumeData: params.resumeData,
|
|
1452
|
+
runtimeContext
|
|
1453
|
+
}
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
/**
|
|
1457
|
+
* Watches workflow transitions in real-time
|
|
1458
|
+
* @param runId - Optional run ID to filter the watch stream
|
|
1459
|
+
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
1460
|
+
*/
|
|
1461
|
+
async watch({ runId }, onRecord) {
|
|
1462
|
+
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
1463
|
+
stream: true
|
|
1464
|
+
});
|
|
1465
|
+
if (!response.ok) {
|
|
1466
|
+
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
1467
|
+
}
|
|
1468
|
+
if (!response.body) {
|
|
1469
|
+
throw new Error("Response body is null");
|
|
1470
|
+
}
|
|
1471
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
1472
|
+
if (typeof record === "string") {
|
|
1473
|
+
onRecord(JSON.parse(record));
|
|
1474
|
+
} else {
|
|
1475
|
+
onRecord(record);
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
/**
|
|
1480
|
+
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
1481
|
+
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
1482
|
+
*
|
|
1483
|
+
* @param records - An iterable or async iterable of objects to stream
|
|
1484
|
+
* @returns A ReadableStream emitting the records as JSON strings separated by the record separator
|
|
1485
|
+
*/
|
|
1486
|
+
static createRecordStream(records) {
|
|
1487
|
+
const encoder = new TextEncoder();
|
|
1488
|
+
return new ReadableStream({
|
|
1489
|
+
async start(controller) {
|
|
1490
|
+
try {
|
|
1491
|
+
for await (const record of records) {
|
|
1492
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR2;
|
|
1493
|
+
controller.enqueue(encoder.encode(json));
|
|
1494
|
+
}
|
|
1495
|
+
controller.close();
|
|
1496
|
+
} catch (err) {
|
|
1497
|
+
controller.error(err);
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
});
|
|
1501
|
+
}
|
|
1502
|
+
};
|
|
1503
|
+
|
|
1504
|
+
// src/resources/a2a.ts
|
|
1505
|
+
var A2A = class extends BaseResource {
|
|
1506
|
+
constructor(options, agentId) {
|
|
1507
|
+
super(options);
|
|
1508
|
+
this.agentId = agentId;
|
|
1509
|
+
}
|
|
1510
|
+
/**
|
|
1511
|
+
* Get the agent card with metadata about the agent
|
|
1512
|
+
* @returns Promise containing the agent card information
|
|
1513
|
+
*/
|
|
1514
|
+
async getCard() {
|
|
1515
|
+
return this.request(`/.well-known/${this.agentId}/agent.json`);
|
|
1516
|
+
}
|
|
1517
|
+
/**
|
|
1518
|
+
* Send a message to the agent and get a response
|
|
1519
|
+
* @param params - Parameters for the task
|
|
1520
|
+
* @returns Promise containing the task response
|
|
1521
|
+
*/
|
|
1522
|
+
async sendMessage(params) {
|
|
1523
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1524
|
+
method: "POST",
|
|
1525
|
+
body: {
|
|
1526
|
+
method: "tasks/send",
|
|
1527
|
+
params
|
|
1528
|
+
}
|
|
1529
|
+
});
|
|
1530
|
+
return { task: response.result };
|
|
1531
|
+
}
|
|
1532
|
+
/**
|
|
1533
|
+
* Get the status and result of a task
|
|
1534
|
+
* @param params - Parameters for querying the task
|
|
1535
|
+
* @returns Promise containing the task response
|
|
1536
|
+
*/
|
|
1537
|
+
async getTask(params) {
|
|
1538
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1539
|
+
method: "POST",
|
|
1540
|
+
body: {
|
|
1541
|
+
method: "tasks/get",
|
|
1542
|
+
params
|
|
1543
|
+
}
|
|
1544
|
+
});
|
|
1545
|
+
return response.result;
|
|
1546
|
+
}
|
|
1547
|
+
/**
|
|
1548
|
+
* Cancel a running task
|
|
1549
|
+
* @param params - Parameters identifying the task to cancel
|
|
1550
|
+
* @returns Promise containing the task response
|
|
1551
|
+
*/
|
|
1552
|
+
async cancelTask(params) {
|
|
1553
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
1554
|
+
method: "POST",
|
|
1555
|
+
body: {
|
|
1556
|
+
method: "tasks/cancel",
|
|
1557
|
+
params
|
|
1558
|
+
}
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1561
|
+
/**
|
|
1562
|
+
* Send a message and subscribe to streaming updates (not fully implemented)
|
|
1563
|
+
* @param params - Parameters for the task
|
|
1564
|
+
* @returns Promise containing the task response
|
|
1565
|
+
*/
|
|
1566
|
+
async sendAndSubscribe(params) {
|
|
1567
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
1568
|
+
method: "POST",
|
|
1569
|
+
body: {
|
|
1570
|
+
method: "tasks/sendSubscribe",
|
|
1571
|
+
params
|
|
1572
|
+
},
|
|
1573
|
+
stream: true
|
|
1574
|
+
});
|
|
1575
|
+
}
|
|
1576
|
+
};
|
|
1577
|
+
|
|
1578
|
+
// src/resources/mcp-tool.ts
|
|
1579
|
+
var MCPTool = class extends BaseResource {
|
|
1580
|
+
serverId;
|
|
1581
|
+
toolId;
|
|
1582
|
+
constructor(options, serverId, toolId) {
|
|
1583
|
+
super(options);
|
|
1584
|
+
this.serverId = serverId;
|
|
1585
|
+
this.toolId = toolId;
|
|
1586
|
+
}
|
|
1587
|
+
/**
|
|
1588
|
+
* Retrieves details about this specific tool from the MCP server.
|
|
1589
|
+
* @returns Promise containing the tool's information (name, description, schema).
|
|
1590
|
+
*/
|
|
1591
|
+
details() {
|
|
1592
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
1593
|
+
}
|
|
1594
|
+
/**
|
|
1595
|
+
* Executes this specific tool on the MCP server.
|
|
1596
|
+
* @param params - Parameters for tool execution, including data/args and optional runtimeContext.
|
|
1597
|
+
* @returns Promise containing the result of the tool execution.
|
|
1598
|
+
*/
|
|
1599
|
+
execute(params) {
|
|
1600
|
+
const body = {};
|
|
1601
|
+
if (params.data !== void 0) body.data = params.data;
|
|
1602
|
+
if (params.runtimeContext !== void 0) {
|
|
1603
|
+
body.runtimeContext = params.runtimeContext;
|
|
1604
|
+
}
|
|
1605
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
|
|
1606
|
+
method: "POST",
|
|
1607
|
+
body: Object.keys(body).length > 0 ? body : void 0
|
|
1608
|
+
});
|
|
1609
|
+
}
|
|
1610
|
+
};
|
|
1611
|
+
|
|
1612
|
+
// src/resources/vNextNetwork.ts
|
|
1613
|
+
var RECORD_SEPARATOR3 = "";
|
|
1614
|
+
var VNextNetwork = class extends BaseResource {
|
|
1615
|
+
constructor(options, networkId) {
|
|
1616
|
+
super(options);
|
|
1617
|
+
this.networkId = networkId;
|
|
1618
|
+
}
|
|
1619
|
+
/**
|
|
1620
|
+
* Retrieves details about the network
|
|
1621
|
+
* @returns Promise containing vNext network details
|
|
1622
|
+
*/
|
|
1623
|
+
details() {
|
|
1624
|
+
return this.request(`/api/networks/v-next/${this.networkId}`);
|
|
1625
|
+
}
|
|
1626
|
+
/**
|
|
1627
|
+
* Generates a response from the v-next network
|
|
1628
|
+
* @param params - Generation parameters including message
|
|
1629
|
+
* @returns Promise containing the generated response
|
|
1630
|
+
*/
|
|
1631
|
+
generate(params) {
|
|
1632
|
+
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
1633
|
+
method: "POST",
|
|
1634
|
+
body: params
|
|
1635
|
+
});
|
|
1636
|
+
}
|
|
1637
|
+
/**
|
|
1638
|
+
* Generates a response from the v-next network using multiple primitives
|
|
1639
|
+
* @param params - Generation parameters including message
|
|
1640
|
+
* @returns Promise containing the generated response
|
|
1641
|
+
*/
|
|
1642
|
+
loop(params) {
|
|
1643
|
+
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
1644
|
+
method: "POST",
|
|
1645
|
+
body: params
|
|
1646
|
+
});
|
|
1647
|
+
}
|
|
1648
|
+
async *streamProcessor(stream) {
|
|
1649
|
+
const reader = stream.getReader();
|
|
1650
|
+
let doneReading = false;
|
|
1651
|
+
let buffer = "";
|
|
1652
|
+
try {
|
|
1653
|
+
while (!doneReading) {
|
|
1654
|
+
const { done, value } = await reader.read();
|
|
1655
|
+
doneReading = done;
|
|
1656
|
+
if (done && !value) continue;
|
|
1657
|
+
try {
|
|
1658
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1659
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
1660
|
+
buffer = chunks.pop() || "";
|
|
1661
|
+
for (const chunk of chunks) {
|
|
1662
|
+
if (chunk) {
|
|
1663
|
+
if (typeof chunk === "string") {
|
|
1664
|
+
try {
|
|
1665
|
+
const parsedChunk = JSON.parse(chunk);
|
|
1666
|
+
yield parsedChunk;
|
|
1667
|
+
} catch {
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
} catch {
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
if (buffer) {
|
|
1676
|
+
try {
|
|
1677
|
+
yield JSON.parse(buffer);
|
|
1678
|
+
} catch {
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
} finally {
|
|
1682
|
+
reader.cancel().catch(() => {
|
|
1683
|
+
});
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
/**
|
|
1687
|
+
* Streams a response from the v-next network
|
|
1688
|
+
* @param params - Stream parameters including message
|
|
1689
|
+
* @returns Promise containing the results
|
|
1690
|
+
*/
|
|
1691
|
+
async stream(params, onRecord) {
|
|
1692
|
+
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
1693
|
+
method: "POST",
|
|
1694
|
+
body: params,
|
|
1695
|
+
stream: true
|
|
1696
|
+
});
|
|
1697
|
+
if (!response.ok) {
|
|
1698
|
+
throw new Error(`Failed to stream vNext network: ${response.statusText}`);
|
|
1699
|
+
}
|
|
1700
|
+
if (!response.body) {
|
|
1701
|
+
throw new Error("Response body is null");
|
|
1702
|
+
}
|
|
1703
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
1704
|
+
if (typeof record === "string") {
|
|
1705
|
+
onRecord(JSON.parse(record));
|
|
1706
|
+
} else {
|
|
1707
|
+
onRecord(record);
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
/**
|
|
1712
|
+
* Streams a response from the v-next network loop
|
|
1713
|
+
* @param params - Stream parameters including message
|
|
1714
|
+
* @returns Promise containing the results
|
|
1715
|
+
*/
|
|
1716
|
+
async loopStream(params, onRecord) {
|
|
1717
|
+
const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
1718
|
+
method: "POST",
|
|
1719
|
+
body: params,
|
|
1720
|
+
stream: true
|
|
1721
|
+
});
|
|
1722
|
+
if (!response.ok) {
|
|
1723
|
+
throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
|
|
1724
|
+
}
|
|
1725
|
+
if (!response.body) {
|
|
1726
|
+
throw new Error("Response body is null");
|
|
1727
|
+
}
|
|
1728
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
1729
|
+
if (typeof record === "string") {
|
|
1730
|
+
onRecord(JSON.parse(record));
|
|
1731
|
+
} else {
|
|
1732
|
+
onRecord(record);
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
};
|
|
1737
|
+
|
|
1738
|
+
// src/resources/network-memory-thread.ts
|
|
1739
|
+
var NetworkMemoryThread = class extends BaseResource {
|
|
1740
|
+
constructor(options, threadId, networkId) {
|
|
1741
|
+
super(options);
|
|
1742
|
+
this.threadId = threadId;
|
|
1743
|
+
this.networkId = networkId;
|
|
1744
|
+
}
|
|
1745
|
+
/**
|
|
1746
|
+
* Retrieves the memory thread details
|
|
1747
|
+
* @returns Promise containing thread details including title and metadata
|
|
1748
|
+
*/
|
|
1749
|
+
get() {
|
|
1750
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
1751
|
+
}
|
|
1752
|
+
/**
|
|
1753
|
+
* Updates the memory thread properties
|
|
1754
|
+
* @param params - Update parameters including title and metadata
|
|
1755
|
+
* @returns Promise containing updated thread details
|
|
1756
|
+
*/
|
|
1757
|
+
update(params) {
|
|
1758
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1759
|
+
method: "PATCH",
|
|
1760
|
+
body: params
|
|
1761
|
+
});
|
|
1762
|
+
}
|
|
1763
|
+
/**
|
|
1764
|
+
* Deletes the memory thread
|
|
1765
|
+
* @returns Promise containing deletion result
|
|
1766
|
+
*/
|
|
1767
|
+
delete() {
|
|
1768
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1769
|
+
method: "DELETE"
|
|
1770
|
+
});
|
|
1771
|
+
}
|
|
1772
|
+
/**
|
|
1773
|
+
* Retrieves messages associated with the thread
|
|
1774
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
1775
|
+
* @returns Promise containing thread messages and UI messages
|
|
1776
|
+
*/
|
|
1777
|
+
getMessages(params) {
|
|
1778
|
+
const query = new URLSearchParams({
|
|
1779
|
+
networkId: this.networkId,
|
|
1780
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
1781
|
+
});
|
|
1782
|
+
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
1783
|
+
}
|
|
1784
|
+
};
|
|
1785
|
+
|
|
1786
|
+
// src/client.ts
|
|
1787
|
+
var MastraClient = class extends BaseResource {
|
|
1788
|
+
constructor(options) {
|
|
1789
|
+
super(options);
|
|
1790
|
+
}
|
|
1791
|
+
/**
|
|
1792
|
+
* Retrieves all available agents
|
|
1793
|
+
* @returns Promise containing map of agent IDs to agent details
|
|
1794
|
+
*/
|
|
1795
|
+
getAgents() {
|
|
1796
|
+
return this.request("/api/agents");
|
|
1797
|
+
}
|
|
1798
|
+
async getAGUI({ resourceId }) {
|
|
1799
|
+
const agents = await this.getAgents();
|
|
1800
|
+
return Object.entries(agents).reduce(
|
|
1801
|
+
(acc, [agentId]) => {
|
|
1802
|
+
const agent = this.getAgent(agentId);
|
|
1803
|
+
acc[agentId] = new AGUIAdapter({
|
|
1804
|
+
agentId,
|
|
1805
|
+
agent,
|
|
1806
|
+
resourceId
|
|
1807
|
+
});
|
|
1808
|
+
return acc;
|
|
1809
|
+
},
|
|
1810
|
+
{}
|
|
1811
|
+
);
|
|
1812
|
+
}
|
|
1813
|
+
/**
|
|
1814
|
+
* Gets an agent instance by ID
|
|
1815
|
+
* @param agentId - ID of the agent to retrieve
|
|
1816
|
+
* @returns Agent instance
|
|
1817
|
+
*/
|
|
1818
|
+
getAgent(agentId) {
|
|
1819
|
+
return new Agent(this.options, agentId);
|
|
1820
|
+
}
|
|
1821
|
+
/**
|
|
1822
|
+
* Retrieves memory threads for a resource
|
|
1823
|
+
* @param params - Parameters containing the resource ID
|
|
1824
|
+
* @returns Promise containing array of memory threads
|
|
1825
|
+
*/
|
|
1826
|
+
getMemoryThreads(params) {
|
|
1827
|
+
return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
|
|
1828
|
+
}
|
|
1829
|
+
/**
|
|
1830
|
+
* Creates a new memory thread
|
|
1831
|
+
* @param params - Parameters for creating the memory thread
|
|
1832
|
+
* @returns Promise containing the created memory thread
|
|
1833
|
+
*/
|
|
1834
|
+
createMemoryThread(params) {
|
|
1835
|
+
return this.request(`/api/memory/threads?agentId=${params.agentId}`, { method: "POST", body: params });
|
|
1836
|
+
}
|
|
1837
|
+
/**
|
|
1838
|
+
* Gets a memory thread instance by ID
|
|
1839
|
+
* @param threadId - ID of the memory thread to retrieve
|
|
1840
|
+
* @returns MemoryThread instance
|
|
1841
|
+
*/
|
|
1842
|
+
getMemoryThread(threadId, agentId) {
|
|
1843
|
+
return new MemoryThread(this.options, threadId, agentId);
|
|
596
1844
|
}
|
|
597
1845
|
/**
|
|
598
1846
|
* Saves messages to memory
|
|
@@ -612,6 +1860,48 @@ var MastraClient = class extends BaseResource {
|
|
|
612
1860
|
getMemoryStatus(agentId) {
|
|
613
1861
|
return this.request(`/api/memory/status?agentId=${agentId}`);
|
|
614
1862
|
}
|
|
1863
|
+
/**
|
|
1864
|
+
* Retrieves memory threads for a resource
|
|
1865
|
+
* @param params - Parameters containing the resource ID
|
|
1866
|
+
* @returns Promise containing array of memory threads
|
|
1867
|
+
*/
|
|
1868
|
+
getNetworkMemoryThreads(params) {
|
|
1869
|
+
return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
|
|
1870
|
+
}
|
|
1871
|
+
/**
|
|
1872
|
+
* Creates a new memory thread
|
|
1873
|
+
* @param params - Parameters for creating the memory thread
|
|
1874
|
+
* @returns Promise containing the created memory thread
|
|
1875
|
+
*/
|
|
1876
|
+
createNetworkMemoryThread(params) {
|
|
1877
|
+
return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: "POST", body: params });
|
|
1878
|
+
}
|
|
1879
|
+
/**
|
|
1880
|
+
* Gets a memory thread instance by ID
|
|
1881
|
+
* @param threadId - ID of the memory thread to retrieve
|
|
1882
|
+
* @returns MemoryThread instance
|
|
1883
|
+
*/
|
|
1884
|
+
getNetworkMemoryThread(threadId, networkId) {
|
|
1885
|
+
return new NetworkMemoryThread(this.options, threadId, networkId);
|
|
1886
|
+
}
|
|
1887
|
+
/**
|
|
1888
|
+
* Saves messages to memory
|
|
1889
|
+
* @param params - Parameters containing messages to save
|
|
1890
|
+
* @returns Promise containing the saved messages
|
|
1891
|
+
*/
|
|
1892
|
+
saveNetworkMessageToMemory(params) {
|
|
1893
|
+
return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
|
|
1894
|
+
method: "POST",
|
|
1895
|
+
body: params
|
|
1896
|
+
});
|
|
1897
|
+
}
|
|
1898
|
+
/**
|
|
1899
|
+
* Gets the status of the memory system
|
|
1900
|
+
* @returns Promise containing memory system status
|
|
1901
|
+
*/
|
|
1902
|
+
getNetworkMemoryStatus(networkId) {
|
|
1903
|
+
return this.request(`/api/memory/network/status?networkId=${networkId}`);
|
|
1904
|
+
}
|
|
615
1905
|
/**
|
|
616
1906
|
* Retrieves all available tools
|
|
617
1907
|
* @returns Promise containing map of tool IDs to tool details
|
|
@@ -625,7 +1915,22 @@ var MastraClient = class extends BaseResource {
|
|
|
625
1915
|
* @returns Tool instance
|
|
626
1916
|
*/
|
|
627
1917
|
getTool(toolId) {
|
|
628
|
-
return new
|
|
1918
|
+
return new Tool2(this.options, toolId);
|
|
1919
|
+
}
|
|
1920
|
+
/**
|
|
1921
|
+
* Retrieves all available legacy workflows
|
|
1922
|
+
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
1923
|
+
*/
|
|
1924
|
+
getLegacyWorkflows() {
|
|
1925
|
+
return this.request("/api/workflows/legacy");
|
|
1926
|
+
}
|
|
1927
|
+
/**
|
|
1928
|
+
* Gets a legacy workflow instance by ID
|
|
1929
|
+
* @param workflowId - ID of the legacy workflow to retrieve
|
|
1930
|
+
* @returns Legacy Workflow instance
|
|
1931
|
+
*/
|
|
1932
|
+
getLegacyWorkflow(workflowId) {
|
|
1933
|
+
return new LegacyWorkflow(this.options, workflowId);
|
|
629
1934
|
}
|
|
630
1935
|
/**
|
|
631
1936
|
* Retrieves all available workflows
|
|
@@ -656,7 +1961,41 @@ var MastraClient = class extends BaseResource {
|
|
|
656
1961
|
* @returns Promise containing array of log messages
|
|
657
1962
|
*/
|
|
658
1963
|
getLogs(params) {
|
|
659
|
-
|
|
1964
|
+
const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
1965
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
1966
|
+
const searchParams = new URLSearchParams();
|
|
1967
|
+
if (transportId) {
|
|
1968
|
+
searchParams.set("transportId", transportId);
|
|
1969
|
+
}
|
|
1970
|
+
if (fromDate) {
|
|
1971
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
1972
|
+
}
|
|
1973
|
+
if (toDate) {
|
|
1974
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
1975
|
+
}
|
|
1976
|
+
if (logLevel) {
|
|
1977
|
+
searchParams.set("logLevel", logLevel);
|
|
1978
|
+
}
|
|
1979
|
+
if (page) {
|
|
1980
|
+
searchParams.set("page", String(page));
|
|
1981
|
+
}
|
|
1982
|
+
if (perPage) {
|
|
1983
|
+
searchParams.set("perPage", String(perPage));
|
|
1984
|
+
}
|
|
1985
|
+
if (_filters) {
|
|
1986
|
+
if (Array.isArray(_filters)) {
|
|
1987
|
+
for (const filter of _filters) {
|
|
1988
|
+
searchParams.append("filters", filter);
|
|
1989
|
+
}
|
|
1990
|
+
} else {
|
|
1991
|
+
searchParams.set("filters", _filters);
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
if (searchParams.size) {
|
|
1995
|
+
return this.request(`/api/logs?${searchParams}`);
|
|
1996
|
+
} else {
|
|
1997
|
+
return this.request(`/api/logs`);
|
|
1998
|
+
}
|
|
660
1999
|
}
|
|
661
2000
|
/**
|
|
662
2001
|
* Gets logs for a specific run
|
|
@@ -664,7 +2003,44 @@ var MastraClient = class extends BaseResource {
|
|
|
664
2003
|
* @returns Promise containing array of log messages
|
|
665
2004
|
*/
|
|
666
2005
|
getLogForRun(params) {
|
|
667
|
-
|
|
2006
|
+
const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
2007
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
2008
|
+
const searchParams = new URLSearchParams();
|
|
2009
|
+
if (runId) {
|
|
2010
|
+
searchParams.set("runId", runId);
|
|
2011
|
+
}
|
|
2012
|
+
if (transportId) {
|
|
2013
|
+
searchParams.set("transportId", transportId);
|
|
2014
|
+
}
|
|
2015
|
+
if (fromDate) {
|
|
2016
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
2017
|
+
}
|
|
2018
|
+
if (toDate) {
|
|
2019
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
2020
|
+
}
|
|
2021
|
+
if (logLevel) {
|
|
2022
|
+
searchParams.set("logLevel", logLevel);
|
|
2023
|
+
}
|
|
2024
|
+
if (page) {
|
|
2025
|
+
searchParams.set("page", String(page));
|
|
2026
|
+
}
|
|
2027
|
+
if (perPage) {
|
|
2028
|
+
searchParams.set("perPage", String(perPage));
|
|
2029
|
+
}
|
|
2030
|
+
if (_filters) {
|
|
2031
|
+
if (Array.isArray(_filters)) {
|
|
2032
|
+
for (const filter of _filters) {
|
|
2033
|
+
searchParams.append("filters", filter);
|
|
2034
|
+
}
|
|
2035
|
+
} else {
|
|
2036
|
+
searchParams.set("filters", _filters);
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
if (searchParams.size) {
|
|
2040
|
+
return this.request(`/api/logs/${runId}?${searchParams}`);
|
|
2041
|
+
} else {
|
|
2042
|
+
return this.request(`/api/logs/${runId}`);
|
|
2043
|
+
}
|
|
668
2044
|
}
|
|
669
2045
|
/**
|
|
670
2046
|
* List of all log transports
|
|
@@ -679,7 +2055,7 @@ var MastraClient = class extends BaseResource {
|
|
|
679
2055
|
* @returns Promise containing telemetry data
|
|
680
2056
|
*/
|
|
681
2057
|
getTelemetry(params) {
|
|
682
|
-
const { name, scope, page, perPage, attribute } = params || {};
|
|
2058
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
683
2059
|
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
684
2060
|
const searchParams = new URLSearchParams();
|
|
685
2061
|
if (name) {
|
|
@@ -703,6 +2079,12 @@ var MastraClient = class extends BaseResource {
|
|
|
703
2079
|
searchParams.set("attribute", _attribute);
|
|
704
2080
|
}
|
|
705
2081
|
}
|
|
2082
|
+
if (fromDate) {
|
|
2083
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
2084
|
+
}
|
|
2085
|
+
if (toDate) {
|
|
2086
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
2087
|
+
}
|
|
706
2088
|
if (searchParams.size) {
|
|
707
2089
|
return this.request(`/api/telemetry?${searchParams}`);
|
|
708
2090
|
} else {
|
|
@@ -716,6 +2098,13 @@ var MastraClient = class extends BaseResource {
|
|
|
716
2098
|
getNetworks() {
|
|
717
2099
|
return this.request("/api/networks");
|
|
718
2100
|
}
|
|
2101
|
+
/**
|
|
2102
|
+
* Retrieves all available vNext networks
|
|
2103
|
+
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
2104
|
+
*/
|
|
2105
|
+
getVNextNetworks() {
|
|
2106
|
+
return this.request("/api/networks/v-next");
|
|
2107
|
+
}
|
|
719
2108
|
/**
|
|
720
2109
|
* Gets a network instance by ID
|
|
721
2110
|
* @param networkId - ID of the network to retrieve
|
|
@@ -724,6 +2113,70 @@ var MastraClient = class extends BaseResource {
|
|
|
724
2113
|
getNetwork(networkId) {
|
|
725
2114
|
return new Network(this.options, networkId);
|
|
726
2115
|
}
|
|
2116
|
+
/**
|
|
2117
|
+
* Gets a vNext network instance by ID
|
|
2118
|
+
* @param networkId - ID of the vNext network to retrieve
|
|
2119
|
+
* @returns vNext Network instance
|
|
2120
|
+
*/
|
|
2121
|
+
getVNextNetwork(networkId) {
|
|
2122
|
+
return new VNextNetwork(this.options, networkId);
|
|
2123
|
+
}
|
|
2124
|
+
/**
|
|
2125
|
+
* Retrieves a list of available MCP servers.
|
|
2126
|
+
* @param params - Optional parameters for pagination (limit, offset).
|
|
2127
|
+
* @returns Promise containing the list of MCP servers and pagination info.
|
|
2128
|
+
*/
|
|
2129
|
+
getMcpServers(params) {
|
|
2130
|
+
const searchParams = new URLSearchParams();
|
|
2131
|
+
if (params?.limit !== void 0) {
|
|
2132
|
+
searchParams.set("limit", String(params.limit));
|
|
2133
|
+
}
|
|
2134
|
+
if (params?.offset !== void 0) {
|
|
2135
|
+
searchParams.set("offset", String(params.offset));
|
|
2136
|
+
}
|
|
2137
|
+
const queryString = searchParams.toString();
|
|
2138
|
+
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
|
|
2139
|
+
}
|
|
2140
|
+
/**
|
|
2141
|
+
* Retrieves detailed information for a specific MCP server.
|
|
2142
|
+
* @param serverId - The ID of the MCP server to retrieve.
|
|
2143
|
+
* @param params - Optional parameters, e.g., specific version.
|
|
2144
|
+
* @returns Promise containing the detailed MCP server information.
|
|
2145
|
+
*/
|
|
2146
|
+
getMcpServerDetails(serverId, params) {
|
|
2147
|
+
const searchParams = new URLSearchParams();
|
|
2148
|
+
if (params?.version) {
|
|
2149
|
+
searchParams.set("version", params.version);
|
|
2150
|
+
}
|
|
2151
|
+
const queryString = searchParams.toString();
|
|
2152
|
+
return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ""}`);
|
|
2153
|
+
}
|
|
2154
|
+
/**
|
|
2155
|
+
* Retrieves a list of tools for a specific MCP server.
|
|
2156
|
+
* @param serverId - The ID of the MCP server.
|
|
2157
|
+
* @returns Promise containing the list of tools.
|
|
2158
|
+
*/
|
|
2159
|
+
getMcpServerTools(serverId) {
|
|
2160
|
+
return this.request(`/api/mcp/${serverId}/tools`);
|
|
2161
|
+
}
|
|
2162
|
+
/**
|
|
2163
|
+
* Gets an MCPTool resource instance for a specific tool on an MCP server.
|
|
2164
|
+
* This instance can then be used to fetch details or execute the tool.
|
|
2165
|
+
* @param serverId - The ID of the MCP server.
|
|
2166
|
+
* @param toolId - The ID of the tool.
|
|
2167
|
+
* @returns MCPTool instance.
|
|
2168
|
+
*/
|
|
2169
|
+
getMcpServerTool(serverId, toolId) {
|
|
2170
|
+
return new MCPTool(this.options, serverId, toolId);
|
|
2171
|
+
}
|
|
2172
|
+
/**
|
|
2173
|
+
* Gets an A2A client for interacting with an agent via the A2A protocol
|
|
2174
|
+
* @param agentId - ID of the agent to interact with
|
|
2175
|
+
* @returns A2A client instance
|
|
2176
|
+
*/
|
|
2177
|
+
getA2A(agentId) {
|
|
2178
|
+
return new A2A(this.options, agentId);
|
|
2179
|
+
}
|
|
727
2180
|
};
|
|
728
2181
|
|
|
729
2182
|
exports.MastraClient = MastraClient;
|