@mastra/client-js 0.0.0-fix-message-embedding-20250506021742 → 0.0.0-fix-fetch-workflow-runs-20250624231457
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 +594 -2
- package/README.md +1 -1
- package/dist/index.cjs +1129 -121
- package/dist/index.d.cts +467 -83
- package/dist/index.d.ts +467 -83
- package/dist/index.js +1126 -122
- package/package.json +20 -15
- package/src/adapters/agui.test.ts +19 -6
- package/src/adapters/agui.ts +31 -11
- package/src/client.ts +243 -22
- package/src/example.ts +33 -31
- package/src/index.test.ts +121 -1
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +574 -43
- package/src/resources/base.ts +2 -1
- package/src/resources/index.ts +4 -2
- package/src/resources/{vnext-workflow.ts → legacy-workflow.ts} +124 -139
- 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 +6 -13
- package/src/resources/tool.ts +9 -2
- package/src/resources/vNextNetwork.ts +147 -0
- package/src/resources/workflow.ts +220 -98
- package/src/types.ts +160 -22
- 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.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { AbstractAgent, EventType } from '@ag-ui/client';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
-
import { processDataStream } from '@ai-sdk/ui-utils';
|
|
3
|
+
import { processDataStream, parsePartialJson } from '@ai-sdk/ui-utils';
|
|
4
4
|
import { ZodSchema } from 'zod';
|
|
5
|
-
import
|
|
5
|
+
import originalZodToJsonSchema from 'zod-to-json-schema';
|
|
6
|
+
import { isVercelTool } from '@mastra/core/tools';
|
|
7
|
+
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
6
8
|
|
|
7
9
|
// src/adapters/agui.ts
|
|
8
10
|
var AGUIAdapter = class extends AbstractAgent {
|
|
@@ -42,6 +44,7 @@ var AGUIAdapter = class extends AbstractAgent {
|
|
|
42
44
|
)
|
|
43
45
|
}).then((response) => {
|
|
44
46
|
let currentMessageId = void 0;
|
|
47
|
+
let isInTextMessage = false;
|
|
45
48
|
return response.processDataStream({
|
|
46
49
|
onTextPart: (text) => {
|
|
47
50
|
if (currentMessageId === void 0) {
|
|
@@ -52,6 +55,7 @@ var AGUIAdapter = class extends AbstractAgent {
|
|
|
52
55
|
role: "assistant"
|
|
53
56
|
};
|
|
54
57
|
subscriber.next(message2);
|
|
58
|
+
isInTextMessage = true;
|
|
55
59
|
}
|
|
56
60
|
const message = {
|
|
57
61
|
type: EventType.TEXT_MESSAGE_CONTENT,
|
|
@@ -60,14 +64,14 @@ var AGUIAdapter = class extends AbstractAgent {
|
|
|
60
64
|
};
|
|
61
65
|
subscriber.next(message);
|
|
62
66
|
},
|
|
63
|
-
onFinishMessagePart: (
|
|
64
|
-
console.log("onFinishMessagePart", message);
|
|
67
|
+
onFinishMessagePart: () => {
|
|
65
68
|
if (currentMessageId !== void 0) {
|
|
66
|
-
const
|
|
69
|
+
const message = {
|
|
67
70
|
type: EventType.TEXT_MESSAGE_END,
|
|
68
71
|
messageId: currentMessageId
|
|
69
72
|
};
|
|
70
|
-
subscriber.next(
|
|
73
|
+
subscriber.next(message);
|
|
74
|
+
isInTextMessage = false;
|
|
71
75
|
}
|
|
72
76
|
subscriber.next({
|
|
73
77
|
type: EventType.RUN_FINISHED,
|
|
@@ -78,6 +82,14 @@ var AGUIAdapter = class extends AbstractAgent {
|
|
|
78
82
|
},
|
|
79
83
|
onToolCallPart(streamPart) {
|
|
80
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
|
+
}
|
|
81
93
|
subscriber.next({
|
|
82
94
|
type: EventType.TOOL_CALL_START,
|
|
83
95
|
toolCallId: streamPart.toolCallId,
|
|
@@ -98,7 +110,7 @@ var AGUIAdapter = class extends AbstractAgent {
|
|
|
98
110
|
}
|
|
99
111
|
});
|
|
100
112
|
}).catch((error) => {
|
|
101
|
-
console.
|
|
113
|
+
console.error("error", error);
|
|
102
114
|
subscriber.error(error);
|
|
103
115
|
});
|
|
104
116
|
return () => {
|
|
@@ -147,6 +159,17 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
147
159
|
role: "assistant",
|
|
148
160
|
content: parts
|
|
149
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
|
+
}
|
|
150
173
|
} else if (message.role === "user") {
|
|
151
174
|
result.push({
|
|
152
175
|
role: "user",
|
|
@@ -168,6 +191,39 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
168
191
|
}
|
|
169
192
|
return result;
|
|
170
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
|
+
}
|
|
171
227
|
|
|
172
228
|
// src/resources/base.ts
|
|
173
229
|
var BaseResource = class {
|
|
@@ -187,9 +243,10 @@ var BaseResource = class {
|
|
|
187
243
|
let delay = backoffMs;
|
|
188
244
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
189
245
|
try {
|
|
190
|
-
const response = await fetch(`${baseUrl}${path}`, {
|
|
246
|
+
const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
|
|
191
247
|
...options,
|
|
192
248
|
headers: {
|
|
249
|
+
...options.method === "POST" || options.method === "PUT" ? { "content-type": "application/json" } : {},
|
|
193
250
|
...headers,
|
|
194
251
|
...options.headers
|
|
195
252
|
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
|
@@ -227,8 +284,15 @@ var BaseResource = class {
|
|
|
227
284
|
throw lastError || new Error("Request failed");
|
|
228
285
|
}
|
|
229
286
|
};
|
|
230
|
-
|
|
231
|
-
|
|
287
|
+
function parseClientRuntimeContext(runtimeContext) {
|
|
288
|
+
if (runtimeContext) {
|
|
289
|
+
if (runtimeContext instanceof RuntimeContext) {
|
|
290
|
+
return Object.fromEntries(runtimeContext.entries());
|
|
291
|
+
}
|
|
292
|
+
return runtimeContext;
|
|
293
|
+
}
|
|
294
|
+
return void 0;
|
|
295
|
+
}
|
|
232
296
|
var AgentVoice = class extends BaseResource {
|
|
233
297
|
constructor(options, agentId) {
|
|
234
298
|
super(options);
|
|
@@ -275,6 +339,13 @@ var AgentVoice = class extends BaseResource {
|
|
|
275
339
|
getSpeakers() {
|
|
276
340
|
return this.request(`/api/agents/${this.agentId}/voice/speakers`);
|
|
277
341
|
}
|
|
342
|
+
/**
|
|
343
|
+
* Get the listener configuration for the agent's voice provider
|
|
344
|
+
* @returns Promise containing a check if the agent has listening capabilities
|
|
345
|
+
*/
|
|
346
|
+
getListener() {
|
|
347
|
+
return this.request(`/api/agents/${this.agentId}/voice/listener`);
|
|
348
|
+
}
|
|
278
349
|
};
|
|
279
350
|
var Agent = class extends BaseResource {
|
|
280
351
|
constructor(options, agentId) {
|
|
@@ -290,21 +361,318 @@ var Agent = class extends BaseResource {
|
|
|
290
361
|
details() {
|
|
291
362
|
return this.request(`/api/agents/${this.agentId}`);
|
|
292
363
|
}
|
|
293
|
-
|
|
294
|
-
* Generates a response from the agent
|
|
295
|
-
* @param params - Generation parameters including prompt
|
|
296
|
-
* @returns Promise containing the generated response
|
|
297
|
-
*/
|
|
298
|
-
generate(params) {
|
|
364
|
+
async generate(params) {
|
|
299
365
|
const processedParams = {
|
|
300
366
|
...params,
|
|
301
|
-
output: params.output
|
|
302
|
-
experimental_output: params.experimental_output
|
|
367
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
368
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
369
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
370
|
+
clientTools: processClientTools(params.clientTools)
|
|
303
371
|
};
|
|
304
|
-
|
|
372
|
+
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
373
|
+
const response = await this.request(`/api/agents/${this.agentId}/generate`, {
|
|
305
374
|
method: "POST",
|
|
306
375
|
body: processedParams
|
|
307
376
|
});
|
|
377
|
+
if (response.finishReason === "tool-calls") {
|
|
378
|
+
for (const toolCall of response.toolCalls) {
|
|
379
|
+
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
380
|
+
if (clientTool && clientTool.execute) {
|
|
381
|
+
const result = await clientTool.execute(
|
|
382
|
+
{ context: toolCall?.args, runId, resourceId, threadId, runtimeContext },
|
|
383
|
+
{
|
|
384
|
+
messages: response.messages,
|
|
385
|
+
toolCallId: toolCall?.toolCallId
|
|
386
|
+
}
|
|
387
|
+
);
|
|
388
|
+
const updatedMessages = [
|
|
389
|
+
{
|
|
390
|
+
role: "user",
|
|
391
|
+
content: params.messages
|
|
392
|
+
},
|
|
393
|
+
...response.response.messages,
|
|
394
|
+
{
|
|
395
|
+
role: "tool",
|
|
396
|
+
content: [
|
|
397
|
+
{
|
|
398
|
+
type: "tool-result",
|
|
399
|
+
toolCallId: toolCall.toolCallId,
|
|
400
|
+
toolName: toolCall.toolName,
|
|
401
|
+
result
|
|
402
|
+
}
|
|
403
|
+
]
|
|
404
|
+
}
|
|
405
|
+
];
|
|
406
|
+
return this.generate({
|
|
407
|
+
...params,
|
|
408
|
+
messages: updatedMessages
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return response;
|
|
414
|
+
}
|
|
415
|
+
async processChatResponse({
|
|
416
|
+
stream,
|
|
417
|
+
update,
|
|
418
|
+
onToolCall,
|
|
419
|
+
onFinish,
|
|
420
|
+
getCurrentDate = () => /* @__PURE__ */ new Date(),
|
|
421
|
+
lastMessage
|
|
422
|
+
}) {
|
|
423
|
+
const replaceLastMessage = lastMessage?.role === "assistant";
|
|
424
|
+
let step = replaceLastMessage ? 1 + // find max step in existing tool invocations:
|
|
425
|
+
(lastMessage.toolInvocations?.reduce((max, toolInvocation) => {
|
|
426
|
+
return Math.max(max, toolInvocation.step ?? 0);
|
|
427
|
+
}, 0) ?? 0) : 0;
|
|
428
|
+
const message = replaceLastMessage ? structuredClone(lastMessage) : {
|
|
429
|
+
id: crypto.randomUUID(),
|
|
430
|
+
createdAt: getCurrentDate(),
|
|
431
|
+
role: "assistant",
|
|
432
|
+
content: "",
|
|
433
|
+
parts: []
|
|
434
|
+
};
|
|
435
|
+
let currentTextPart = void 0;
|
|
436
|
+
let currentReasoningPart = void 0;
|
|
437
|
+
let currentReasoningTextDetail = void 0;
|
|
438
|
+
function updateToolInvocationPart(toolCallId, invocation) {
|
|
439
|
+
const part = message.parts.find(
|
|
440
|
+
(part2) => part2.type === "tool-invocation" && part2.toolInvocation.toolCallId === toolCallId
|
|
441
|
+
);
|
|
442
|
+
if (part != null) {
|
|
443
|
+
part.toolInvocation = invocation;
|
|
444
|
+
} else {
|
|
445
|
+
message.parts.push({
|
|
446
|
+
type: "tool-invocation",
|
|
447
|
+
toolInvocation: invocation
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
const data = [];
|
|
452
|
+
let messageAnnotations = replaceLastMessage ? lastMessage?.annotations : void 0;
|
|
453
|
+
const partialToolCalls = {};
|
|
454
|
+
let usage = {
|
|
455
|
+
completionTokens: NaN,
|
|
456
|
+
promptTokens: NaN,
|
|
457
|
+
totalTokens: NaN
|
|
458
|
+
};
|
|
459
|
+
let finishReason = "unknown";
|
|
460
|
+
function execUpdate() {
|
|
461
|
+
const copiedData = [...data];
|
|
462
|
+
if (messageAnnotations?.length) {
|
|
463
|
+
message.annotations = messageAnnotations;
|
|
464
|
+
}
|
|
465
|
+
const copiedMessage = {
|
|
466
|
+
// deep copy the message to ensure that deep changes (msg attachments) are updated
|
|
467
|
+
// with SolidJS. SolidJS uses referential integration of sub-objects to detect changes.
|
|
468
|
+
...structuredClone(message),
|
|
469
|
+
// add a revision id to ensure that the message is updated with SWR. SWR uses a
|
|
470
|
+
// hashing approach by default to detect changes, but it only works for shallow
|
|
471
|
+
// changes. This is why we need to add a revision id to ensure that the message
|
|
472
|
+
// is updated with SWR (without it, the changes get stuck in SWR and are not
|
|
473
|
+
// forwarded to rendering):
|
|
474
|
+
revisionId: crypto.randomUUID()
|
|
475
|
+
};
|
|
476
|
+
update({
|
|
477
|
+
message: copiedMessage,
|
|
478
|
+
data: copiedData,
|
|
479
|
+
replaceLastMessage
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
await processDataStream({
|
|
483
|
+
stream,
|
|
484
|
+
onTextPart(value) {
|
|
485
|
+
if (currentTextPart == null) {
|
|
486
|
+
currentTextPart = {
|
|
487
|
+
type: "text",
|
|
488
|
+
text: value
|
|
489
|
+
};
|
|
490
|
+
message.parts.push(currentTextPart);
|
|
491
|
+
} else {
|
|
492
|
+
currentTextPart.text += value;
|
|
493
|
+
}
|
|
494
|
+
message.content += value;
|
|
495
|
+
execUpdate();
|
|
496
|
+
},
|
|
497
|
+
onReasoningPart(value) {
|
|
498
|
+
if (currentReasoningTextDetail == null) {
|
|
499
|
+
currentReasoningTextDetail = { type: "text", text: value };
|
|
500
|
+
if (currentReasoningPart != null) {
|
|
501
|
+
currentReasoningPart.details.push(currentReasoningTextDetail);
|
|
502
|
+
}
|
|
503
|
+
} else {
|
|
504
|
+
currentReasoningTextDetail.text += value;
|
|
505
|
+
}
|
|
506
|
+
if (currentReasoningPart == null) {
|
|
507
|
+
currentReasoningPart = {
|
|
508
|
+
type: "reasoning",
|
|
509
|
+
reasoning: value,
|
|
510
|
+
details: [currentReasoningTextDetail]
|
|
511
|
+
};
|
|
512
|
+
message.parts.push(currentReasoningPart);
|
|
513
|
+
} else {
|
|
514
|
+
currentReasoningPart.reasoning += value;
|
|
515
|
+
}
|
|
516
|
+
message.reasoning = (message.reasoning ?? "") + value;
|
|
517
|
+
execUpdate();
|
|
518
|
+
},
|
|
519
|
+
onReasoningSignaturePart(value) {
|
|
520
|
+
if (currentReasoningTextDetail != null) {
|
|
521
|
+
currentReasoningTextDetail.signature = value.signature;
|
|
522
|
+
}
|
|
523
|
+
},
|
|
524
|
+
onRedactedReasoningPart(value) {
|
|
525
|
+
if (currentReasoningPart == null) {
|
|
526
|
+
currentReasoningPart = {
|
|
527
|
+
type: "reasoning",
|
|
528
|
+
reasoning: "",
|
|
529
|
+
details: []
|
|
530
|
+
};
|
|
531
|
+
message.parts.push(currentReasoningPart);
|
|
532
|
+
}
|
|
533
|
+
currentReasoningPart.details.push({
|
|
534
|
+
type: "redacted",
|
|
535
|
+
data: value.data
|
|
536
|
+
});
|
|
537
|
+
currentReasoningTextDetail = void 0;
|
|
538
|
+
execUpdate();
|
|
539
|
+
},
|
|
540
|
+
onFilePart(value) {
|
|
541
|
+
message.parts.push({
|
|
542
|
+
type: "file",
|
|
543
|
+
mimeType: value.mimeType,
|
|
544
|
+
data: value.data
|
|
545
|
+
});
|
|
546
|
+
execUpdate();
|
|
547
|
+
},
|
|
548
|
+
onSourcePart(value) {
|
|
549
|
+
message.parts.push({
|
|
550
|
+
type: "source",
|
|
551
|
+
source: value
|
|
552
|
+
});
|
|
553
|
+
execUpdate();
|
|
554
|
+
},
|
|
555
|
+
onToolCallStreamingStartPart(value) {
|
|
556
|
+
if (message.toolInvocations == null) {
|
|
557
|
+
message.toolInvocations = [];
|
|
558
|
+
}
|
|
559
|
+
partialToolCalls[value.toolCallId] = {
|
|
560
|
+
text: "",
|
|
561
|
+
step,
|
|
562
|
+
toolName: value.toolName,
|
|
563
|
+
index: message.toolInvocations.length
|
|
564
|
+
};
|
|
565
|
+
const invocation = {
|
|
566
|
+
state: "partial-call",
|
|
567
|
+
step,
|
|
568
|
+
toolCallId: value.toolCallId,
|
|
569
|
+
toolName: value.toolName,
|
|
570
|
+
args: void 0
|
|
571
|
+
};
|
|
572
|
+
message.toolInvocations.push(invocation);
|
|
573
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
574
|
+
execUpdate();
|
|
575
|
+
},
|
|
576
|
+
onToolCallDeltaPart(value) {
|
|
577
|
+
const partialToolCall = partialToolCalls[value.toolCallId];
|
|
578
|
+
partialToolCall.text += value.argsTextDelta;
|
|
579
|
+
const { value: partialArgs } = parsePartialJson(partialToolCall.text);
|
|
580
|
+
const invocation = {
|
|
581
|
+
state: "partial-call",
|
|
582
|
+
step: partialToolCall.step,
|
|
583
|
+
toolCallId: value.toolCallId,
|
|
584
|
+
toolName: partialToolCall.toolName,
|
|
585
|
+
args: partialArgs
|
|
586
|
+
};
|
|
587
|
+
message.toolInvocations[partialToolCall.index] = invocation;
|
|
588
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
589
|
+
execUpdate();
|
|
590
|
+
},
|
|
591
|
+
async onToolCallPart(value) {
|
|
592
|
+
const invocation = {
|
|
593
|
+
state: "call",
|
|
594
|
+
step,
|
|
595
|
+
...value
|
|
596
|
+
};
|
|
597
|
+
if (partialToolCalls[value.toolCallId] != null) {
|
|
598
|
+
message.toolInvocations[partialToolCalls[value.toolCallId].index] = invocation;
|
|
599
|
+
} else {
|
|
600
|
+
if (message.toolInvocations == null) {
|
|
601
|
+
message.toolInvocations = [];
|
|
602
|
+
}
|
|
603
|
+
message.toolInvocations.push(invocation);
|
|
604
|
+
}
|
|
605
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
606
|
+
execUpdate();
|
|
607
|
+
if (onToolCall) {
|
|
608
|
+
const result = await onToolCall({ toolCall: value });
|
|
609
|
+
if (result != null) {
|
|
610
|
+
const invocation2 = {
|
|
611
|
+
state: "result",
|
|
612
|
+
step,
|
|
613
|
+
...value,
|
|
614
|
+
result
|
|
615
|
+
};
|
|
616
|
+
message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
|
|
617
|
+
updateToolInvocationPart(value.toolCallId, invocation2);
|
|
618
|
+
execUpdate();
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
},
|
|
622
|
+
onToolResultPart(value) {
|
|
623
|
+
const toolInvocations = message.toolInvocations;
|
|
624
|
+
if (toolInvocations == null) {
|
|
625
|
+
throw new Error("tool_result must be preceded by a tool_call");
|
|
626
|
+
}
|
|
627
|
+
const toolInvocationIndex = toolInvocations.findIndex((invocation2) => invocation2.toolCallId === value.toolCallId);
|
|
628
|
+
if (toolInvocationIndex === -1) {
|
|
629
|
+
throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
|
|
630
|
+
}
|
|
631
|
+
const invocation = {
|
|
632
|
+
...toolInvocations[toolInvocationIndex],
|
|
633
|
+
state: "result",
|
|
634
|
+
...value
|
|
635
|
+
};
|
|
636
|
+
toolInvocations[toolInvocationIndex] = invocation;
|
|
637
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
638
|
+
execUpdate();
|
|
639
|
+
},
|
|
640
|
+
onDataPart(value) {
|
|
641
|
+
data.push(...value);
|
|
642
|
+
execUpdate();
|
|
643
|
+
},
|
|
644
|
+
onMessageAnnotationsPart(value) {
|
|
645
|
+
if (messageAnnotations == null) {
|
|
646
|
+
messageAnnotations = [...value];
|
|
647
|
+
} else {
|
|
648
|
+
messageAnnotations.push(...value);
|
|
649
|
+
}
|
|
650
|
+
execUpdate();
|
|
651
|
+
},
|
|
652
|
+
onFinishStepPart(value) {
|
|
653
|
+
step += 1;
|
|
654
|
+
currentTextPart = value.isContinued ? currentTextPart : void 0;
|
|
655
|
+
currentReasoningPart = void 0;
|
|
656
|
+
currentReasoningTextDetail = void 0;
|
|
657
|
+
},
|
|
658
|
+
onStartStepPart(value) {
|
|
659
|
+
if (!replaceLastMessage) {
|
|
660
|
+
message.id = value.messageId;
|
|
661
|
+
}
|
|
662
|
+
message.parts.push({ type: "step-start" });
|
|
663
|
+
execUpdate();
|
|
664
|
+
},
|
|
665
|
+
onFinishMessagePart(value) {
|
|
666
|
+
finishReason = value.finishReason;
|
|
667
|
+
if (value.usage != null) {
|
|
668
|
+
usage = value.usage;
|
|
669
|
+
}
|
|
670
|
+
},
|
|
671
|
+
onErrorPart(error) {
|
|
672
|
+
throw new Error(error);
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
onFinish?.({ message, finishReason, usage });
|
|
308
676
|
}
|
|
309
677
|
/**
|
|
310
678
|
* Streams a response from the agent
|
|
@@ -314,9 +682,30 @@ var Agent = class extends BaseResource {
|
|
|
314
682
|
async stream(params) {
|
|
315
683
|
const processedParams = {
|
|
316
684
|
...params,
|
|
317
|
-
output: params.output
|
|
318
|
-
experimental_output: params.experimental_output
|
|
685
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
686
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
687
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
688
|
+
clientTools: processClientTools(params.clientTools)
|
|
689
|
+
};
|
|
690
|
+
const { readable, writable } = new TransformStream();
|
|
691
|
+
const response = await this.processStreamResponse(processedParams, writable);
|
|
692
|
+
const streamResponse = new Response(readable, {
|
|
693
|
+
status: response.status,
|
|
694
|
+
statusText: response.statusText,
|
|
695
|
+
headers: response.headers
|
|
696
|
+
});
|
|
697
|
+
streamResponse.processDataStream = async (options = {}) => {
|
|
698
|
+
await processDataStream({
|
|
699
|
+
stream: streamResponse.body,
|
|
700
|
+
...options
|
|
701
|
+
});
|
|
319
702
|
};
|
|
703
|
+
return streamResponse;
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Processes the stream response and handles tool calls
|
|
707
|
+
*/
|
|
708
|
+
async processStreamResponse(processedParams, writable) {
|
|
320
709
|
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
321
710
|
method: "POST",
|
|
322
711
|
body: processedParams,
|
|
@@ -325,12 +714,79 @@ var Agent = class extends BaseResource {
|
|
|
325
714
|
if (!response.body) {
|
|
326
715
|
throw new Error("No response body");
|
|
327
716
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
717
|
+
try {
|
|
718
|
+
let toolCalls = [];
|
|
719
|
+
let finishReasonToolCalls = false;
|
|
720
|
+
let messages = [];
|
|
721
|
+
let hasProcessedToolCalls = false;
|
|
722
|
+
response.clone().body.pipeTo(writable);
|
|
723
|
+
await this.processChatResponse({
|
|
724
|
+
stream: response.clone().body,
|
|
725
|
+
update: ({ message }) => {
|
|
726
|
+
messages.push(message);
|
|
727
|
+
},
|
|
728
|
+
onFinish: ({ finishReason, message }) => {
|
|
729
|
+
if (finishReason === "tool-calls") {
|
|
730
|
+
finishReasonToolCalls = true;
|
|
731
|
+
const toolCall = [...message?.parts ?? []].reverse().find((part) => part.type === "tool-invocation")?.toolInvocation;
|
|
732
|
+
if (toolCall) {
|
|
733
|
+
toolCalls.push(toolCall);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
},
|
|
737
|
+
lastMessage: void 0
|
|
332
738
|
});
|
|
333
|
-
|
|
739
|
+
if (finishReasonToolCalls && !hasProcessedToolCalls) {
|
|
740
|
+
hasProcessedToolCalls = true;
|
|
741
|
+
for (const toolCall of toolCalls) {
|
|
742
|
+
const clientTool = processedParams.clientTools?.[toolCall.toolName];
|
|
743
|
+
if (clientTool && clientTool.execute) {
|
|
744
|
+
const result = await clientTool.execute(
|
|
745
|
+
{
|
|
746
|
+
context: toolCall?.args,
|
|
747
|
+
runId: processedParams.runId,
|
|
748
|
+
resourceId: processedParams.resourceId,
|
|
749
|
+
threadId: processedParams.threadId,
|
|
750
|
+
runtimeContext: processedParams.runtimeContext
|
|
751
|
+
},
|
|
752
|
+
{
|
|
753
|
+
messages: response.messages,
|
|
754
|
+
toolCallId: toolCall?.toolCallId
|
|
755
|
+
}
|
|
756
|
+
);
|
|
757
|
+
const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
|
|
758
|
+
const toolInvocationPart = lastMessage?.parts?.find(
|
|
759
|
+
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall.toolCallId
|
|
760
|
+
);
|
|
761
|
+
if (toolInvocationPart) {
|
|
762
|
+
toolInvocationPart.toolInvocation = {
|
|
763
|
+
...toolInvocationPart.toolInvocation,
|
|
764
|
+
state: "result",
|
|
765
|
+
result
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
const toolInvocation = lastMessage?.toolInvocations?.find(
|
|
769
|
+
(toolInvocation2) => toolInvocation2.toolCallId === toolCall.toolCallId
|
|
770
|
+
);
|
|
771
|
+
if (toolInvocation) {
|
|
772
|
+
toolInvocation.state = "result";
|
|
773
|
+
toolInvocation.result = result;
|
|
774
|
+
}
|
|
775
|
+
const originalMessages = processedParams.messages;
|
|
776
|
+
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
777
|
+
this.processStreamResponse(
|
|
778
|
+
{
|
|
779
|
+
...processedParams,
|
|
780
|
+
messages: [...messageArray, ...messages, lastMessage]
|
|
781
|
+
},
|
|
782
|
+
writable
|
|
783
|
+
);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
} catch (error) {
|
|
788
|
+
console.error("Error processing stream response:", error);
|
|
789
|
+
}
|
|
334
790
|
return response;
|
|
335
791
|
}
|
|
336
792
|
/**
|
|
@@ -341,6 +797,22 @@ var Agent = class extends BaseResource {
|
|
|
341
797
|
getTool(toolId) {
|
|
342
798
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
343
799
|
}
|
|
800
|
+
/**
|
|
801
|
+
* Executes a tool for the agent
|
|
802
|
+
* @param toolId - ID of the tool to execute
|
|
803
|
+
* @param params - Parameters required for tool execution
|
|
804
|
+
* @returns Promise containing the tool execution results
|
|
805
|
+
*/
|
|
806
|
+
executeTool(toolId, params) {
|
|
807
|
+
const body = {
|
|
808
|
+
data: params.data,
|
|
809
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
810
|
+
};
|
|
811
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
812
|
+
method: "POST",
|
|
813
|
+
body
|
|
814
|
+
});
|
|
815
|
+
}
|
|
344
816
|
/**
|
|
345
817
|
* Retrieves evaluation results for the agent
|
|
346
818
|
* @returns Promise containing agent evaluations
|
|
@@ -376,8 +848,8 @@ var Network = class extends BaseResource {
|
|
|
376
848
|
generate(params) {
|
|
377
849
|
const processedParams = {
|
|
378
850
|
...params,
|
|
379
|
-
output:
|
|
380
|
-
experimental_output:
|
|
851
|
+
output: zodToJsonSchema(params.output),
|
|
852
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
381
853
|
};
|
|
382
854
|
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
383
855
|
method: "POST",
|
|
@@ -392,8 +864,8 @@ var Network = class extends BaseResource {
|
|
|
392
864
|
async stream(params) {
|
|
393
865
|
const processedParams = {
|
|
394
866
|
...params,
|
|
395
|
-
output:
|
|
396
|
-
experimental_output:
|
|
867
|
+
output: zodToJsonSchema(params.output),
|
|
868
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
397
869
|
};
|
|
398
870
|
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
399
871
|
method: "POST",
|
|
@@ -449,10 +921,15 @@ var MemoryThread = class extends BaseResource {
|
|
|
449
921
|
}
|
|
450
922
|
/**
|
|
451
923
|
* Retrieves messages associated with the thread
|
|
924
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
452
925
|
* @returns Promise containing thread messages and UI messages
|
|
453
926
|
*/
|
|
454
|
-
getMessages() {
|
|
455
|
-
|
|
927
|
+
getMessages(params) {
|
|
928
|
+
const query = new URLSearchParams({
|
|
929
|
+
agentId: this.agentId,
|
|
930
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
931
|
+
});
|
|
932
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
456
933
|
}
|
|
457
934
|
};
|
|
458
935
|
|
|
@@ -522,24 +999,24 @@ var Vector = class extends BaseResource {
|
|
|
522
999
|
}
|
|
523
1000
|
};
|
|
524
1001
|
|
|
525
|
-
// src/resources/workflow.ts
|
|
1002
|
+
// src/resources/legacy-workflow.ts
|
|
526
1003
|
var RECORD_SEPARATOR = "";
|
|
527
|
-
var
|
|
1004
|
+
var LegacyWorkflow = class extends BaseResource {
|
|
528
1005
|
constructor(options, workflowId) {
|
|
529
1006
|
super(options);
|
|
530
1007
|
this.workflowId = workflowId;
|
|
531
1008
|
}
|
|
532
1009
|
/**
|
|
533
|
-
* Retrieves details about the workflow
|
|
534
|
-
* @returns Promise containing workflow details including steps and graphs
|
|
1010
|
+
* Retrieves details about the legacy workflow
|
|
1011
|
+
* @returns Promise containing legacy workflow details including steps and graphs
|
|
535
1012
|
*/
|
|
536
1013
|
details() {
|
|
537
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
1014
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}`);
|
|
538
1015
|
}
|
|
539
1016
|
/**
|
|
540
|
-
* Retrieves all runs for a workflow
|
|
1017
|
+
* Retrieves all runs for a legacy workflow
|
|
541
1018
|
* @param params - Parameters for filtering runs
|
|
542
|
-
* @returns Promise containing workflow runs array
|
|
1019
|
+
* @returns Promise containing legacy workflow runs array
|
|
543
1020
|
*/
|
|
544
1021
|
runs(params) {
|
|
545
1022
|
const searchParams = new URLSearchParams();
|
|
@@ -559,25 +1036,13 @@ var Workflow = class extends BaseResource {
|
|
|
559
1036
|
searchParams.set("resourceId", params.resourceId);
|
|
560
1037
|
}
|
|
561
1038
|
if (searchParams.size) {
|
|
562
|
-
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
1039
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
563
1040
|
} else {
|
|
564
|
-
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
1041
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
565
1042
|
}
|
|
566
1043
|
}
|
|
567
1044
|
/**
|
|
568
|
-
*
|
|
569
|
-
* Executes the workflow with the provided parameters
|
|
570
|
-
* @param params - Parameters required for workflow execution
|
|
571
|
-
* @returns Promise containing the workflow execution results
|
|
572
|
-
*/
|
|
573
|
-
execute(params) {
|
|
574
|
-
return this.request(`/api/workflows/${this.workflowId}/execute`, {
|
|
575
|
-
method: "POST",
|
|
576
|
-
body: params
|
|
577
|
-
});
|
|
578
|
-
}
|
|
579
|
-
/**
|
|
580
|
-
* Creates a new workflow run
|
|
1045
|
+
* Creates a new legacy workflow run
|
|
581
1046
|
* @returns Promise containing the generated run ID
|
|
582
1047
|
*/
|
|
583
1048
|
createRun(params) {
|
|
@@ -585,34 +1050,34 @@ var Workflow = class extends BaseResource {
|
|
|
585
1050
|
if (!!params?.runId) {
|
|
586
1051
|
searchParams.set("runId", params.runId);
|
|
587
1052
|
}
|
|
588
|
-
return this.request(`/api/workflows/${this.workflowId}/
|
|
1053
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
589
1054
|
method: "POST"
|
|
590
1055
|
});
|
|
591
1056
|
}
|
|
592
1057
|
/**
|
|
593
|
-
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1058
|
+
* Starts a legacy workflow run synchronously without waiting for the workflow to complete
|
|
594
1059
|
* @param params - Object containing the runId and triggerData
|
|
595
1060
|
* @returns Promise containing success message
|
|
596
1061
|
*/
|
|
597
1062
|
start(params) {
|
|
598
|
-
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1063
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
599
1064
|
method: "POST",
|
|
600
1065
|
body: params?.triggerData
|
|
601
1066
|
});
|
|
602
1067
|
}
|
|
603
1068
|
/**
|
|
604
|
-
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
1069
|
+
* Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
|
|
605
1070
|
* @param stepId - ID of the step to resume
|
|
606
|
-
* @param runId - ID of the workflow run
|
|
607
|
-
* @param context - Context to resume the workflow with
|
|
608
|
-
* @returns Promise containing the workflow resume results
|
|
1071
|
+
* @param runId - ID of the legacy workflow run
|
|
1072
|
+
* @param context - Context to resume the legacy workflow with
|
|
1073
|
+
* @returns Promise containing the legacy workflow resume results
|
|
609
1074
|
*/
|
|
610
1075
|
resume({
|
|
611
1076
|
stepId,
|
|
612
1077
|
runId,
|
|
613
1078
|
context
|
|
614
1079
|
}) {
|
|
615
|
-
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1080
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
616
1081
|
method: "POST",
|
|
617
1082
|
body: {
|
|
618
1083
|
stepId,
|
|
@@ -630,18 +1095,18 @@ var Workflow = class extends BaseResource {
|
|
|
630
1095
|
if (!!params?.runId) {
|
|
631
1096
|
searchParams.set("runId", params.runId);
|
|
632
1097
|
}
|
|
633
|
-
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1098
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
634
1099
|
method: "POST",
|
|
635
1100
|
body: params?.triggerData
|
|
636
1101
|
});
|
|
637
1102
|
}
|
|
638
1103
|
/**
|
|
639
|
-
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
1104
|
+
* Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
640
1105
|
* @param params - Object containing the runId, stepId, and context
|
|
641
1106
|
* @returns Promise containing the workflow resume results
|
|
642
1107
|
*/
|
|
643
1108
|
resumeAsync(params) {
|
|
644
|
-
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
1109
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
645
1110
|
method: "POST",
|
|
646
1111
|
body: {
|
|
647
1112
|
stepId: params.stepId,
|
|
@@ -695,16 +1160,16 @@ var Workflow = class extends BaseResource {
|
|
|
695
1160
|
}
|
|
696
1161
|
}
|
|
697
1162
|
/**
|
|
698
|
-
* Watches workflow transitions in real-time
|
|
1163
|
+
* Watches legacy workflow transitions in real-time
|
|
699
1164
|
* @param runId - Optional run ID to filter the watch stream
|
|
700
|
-
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
1165
|
+
* @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
|
|
701
1166
|
*/
|
|
702
1167
|
async watch({ runId }, onRecord) {
|
|
703
|
-
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
1168
|
+
const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
|
|
704
1169
|
stream: true
|
|
705
1170
|
});
|
|
706
1171
|
if (!response.ok) {
|
|
707
|
-
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
1172
|
+
throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
|
|
708
1173
|
}
|
|
709
1174
|
if (!response.body) {
|
|
710
1175
|
throw new Error("Response body is null");
|
|
@@ -716,7 +1181,7 @@ var Workflow = class extends BaseResource {
|
|
|
716
1181
|
};
|
|
717
1182
|
|
|
718
1183
|
// src/resources/tool.ts
|
|
719
|
-
var
|
|
1184
|
+
var Tool2 = class extends BaseResource {
|
|
720
1185
|
constructor(options, toolId) {
|
|
721
1186
|
super(options);
|
|
722
1187
|
this.toolId = toolId;
|
|
@@ -738,22 +1203,26 @@ var Tool = class extends BaseResource {
|
|
|
738
1203
|
if (params.runId) {
|
|
739
1204
|
url.set("runId", params.runId);
|
|
740
1205
|
}
|
|
1206
|
+
const body = {
|
|
1207
|
+
data: params.data,
|
|
1208
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1209
|
+
};
|
|
741
1210
|
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
742
1211
|
method: "POST",
|
|
743
|
-
body
|
|
1212
|
+
body
|
|
744
1213
|
});
|
|
745
1214
|
}
|
|
746
1215
|
};
|
|
747
1216
|
|
|
748
|
-
// src/resources/
|
|
1217
|
+
// src/resources/workflow.ts
|
|
749
1218
|
var RECORD_SEPARATOR2 = "";
|
|
750
|
-
var
|
|
1219
|
+
var Workflow = class extends BaseResource {
|
|
751
1220
|
constructor(options, workflowId) {
|
|
752
1221
|
super(options);
|
|
753
1222
|
this.workflowId = workflowId;
|
|
754
1223
|
}
|
|
755
1224
|
/**
|
|
756
|
-
* Creates an async generator that processes a readable stream and yields
|
|
1225
|
+
* Creates an async generator that processes a readable stream and yields workflow records
|
|
757
1226
|
* separated by the Record Separator character (\x1E)
|
|
758
1227
|
*
|
|
759
1228
|
* @param stream - The readable stream to process
|
|
@@ -798,16 +1267,16 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
798
1267
|
}
|
|
799
1268
|
}
|
|
800
1269
|
/**
|
|
801
|
-
* Retrieves details about the
|
|
802
|
-
* @returns Promise containing
|
|
1270
|
+
* Retrieves details about the workflow
|
|
1271
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
803
1272
|
*/
|
|
804
1273
|
details() {
|
|
805
|
-
return this.request(`/api/workflows
|
|
1274
|
+
return this.request(`/api/workflows/${this.workflowId}`);
|
|
806
1275
|
}
|
|
807
1276
|
/**
|
|
808
|
-
* Retrieves all runs for a
|
|
1277
|
+
* Retrieves all runs for a workflow
|
|
809
1278
|
* @param params - Parameters for filtering runs
|
|
810
|
-
* @returns Promise containing
|
|
1279
|
+
* @returns Promise containing workflow runs array
|
|
811
1280
|
*/
|
|
812
1281
|
runs(params) {
|
|
813
1282
|
const searchParams = new URLSearchParams();
|
|
@@ -817,23 +1286,39 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
817
1286
|
if (params?.toDate) {
|
|
818
1287
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
819
1288
|
}
|
|
820
|
-
if (params?.limit) {
|
|
1289
|
+
if (params?.limit !== void 0) {
|
|
821
1290
|
searchParams.set("limit", String(params.limit));
|
|
822
1291
|
}
|
|
823
|
-
if (params?.offset) {
|
|
1292
|
+
if (params?.offset !== void 0) {
|
|
824
1293
|
searchParams.set("offset", String(params.offset));
|
|
825
1294
|
}
|
|
826
1295
|
if (params?.resourceId) {
|
|
827
1296
|
searchParams.set("resourceId", params.resourceId);
|
|
828
1297
|
}
|
|
829
1298
|
if (searchParams.size) {
|
|
830
|
-
return this.request(`/api/workflows
|
|
1299
|
+
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
831
1300
|
} else {
|
|
832
|
-
return this.request(`/api/workflows
|
|
1301
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
833
1302
|
}
|
|
834
1303
|
}
|
|
835
1304
|
/**
|
|
836
|
-
*
|
|
1305
|
+
* Retrieves a specific workflow run by its ID
|
|
1306
|
+
* @param runId - The ID of the workflow run to retrieve
|
|
1307
|
+
* @returns Promise containing the workflow run details
|
|
1308
|
+
*/
|
|
1309
|
+
runById(runId) {
|
|
1310
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
|
|
1311
|
+
}
|
|
1312
|
+
/**
|
|
1313
|
+
* Retrieves the execution result for a specific workflow run by its ID
|
|
1314
|
+
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1315
|
+
* @returns Promise containing the workflow run execution result
|
|
1316
|
+
*/
|
|
1317
|
+
runExecutionResult(runId) {
|
|
1318
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
|
|
1319
|
+
}
|
|
1320
|
+
/**
|
|
1321
|
+
* Creates a new workflow run
|
|
837
1322
|
* @param params - Optional object containing the optional runId
|
|
838
1323
|
* @returns Promise containing the runId of the created run
|
|
839
1324
|
*/
|
|
@@ -842,23 +1327,24 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
842
1327
|
if (!!params?.runId) {
|
|
843
1328
|
searchParams.set("runId", params.runId);
|
|
844
1329
|
}
|
|
845
|
-
return this.request(`/api/workflows
|
|
1330
|
+
return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
846
1331
|
method: "POST"
|
|
847
1332
|
});
|
|
848
1333
|
}
|
|
849
1334
|
/**
|
|
850
|
-
* Starts a
|
|
1335
|
+
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
851
1336
|
* @param params - Object containing the runId, inputData and runtimeContext
|
|
852
1337
|
* @returns Promise containing success message
|
|
853
1338
|
*/
|
|
854
1339
|
start(params) {
|
|
855
|
-
|
|
1340
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1341
|
+
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
856
1342
|
method: "POST",
|
|
857
|
-
body: { inputData: params?.inputData, runtimeContext
|
|
1343
|
+
body: { inputData: params?.inputData, runtimeContext }
|
|
858
1344
|
});
|
|
859
1345
|
}
|
|
860
1346
|
/**
|
|
861
|
-
* Resumes a suspended
|
|
1347
|
+
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
862
1348
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
863
1349
|
* @returns Promise containing success message
|
|
864
1350
|
*/
|
|
@@ -866,9 +1352,10 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
866
1352
|
step,
|
|
867
1353
|
runId,
|
|
868
1354
|
resumeData,
|
|
869
|
-
|
|
1355
|
+
...rest
|
|
870
1356
|
}) {
|
|
871
|
-
|
|
1357
|
+
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
1358
|
+
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
872
1359
|
method: "POST",
|
|
873
1360
|
stream: true,
|
|
874
1361
|
body: {
|
|
@@ -879,53 +1366,386 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
879
1366
|
});
|
|
880
1367
|
}
|
|
881
1368
|
/**
|
|
882
|
-
* Starts a
|
|
1369
|
+
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
883
1370
|
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
884
|
-
* @returns Promise containing the
|
|
1371
|
+
* @returns Promise containing the workflow execution results
|
|
885
1372
|
*/
|
|
886
1373
|
startAsync(params) {
|
|
887
1374
|
const searchParams = new URLSearchParams();
|
|
888
1375
|
if (!!params?.runId) {
|
|
889
1376
|
searchParams.set("runId", params.runId);
|
|
890
1377
|
}
|
|
891
|
-
|
|
1378
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1379
|
+
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
892
1380
|
method: "POST",
|
|
893
|
-
body: { inputData: params.inputData, runtimeContext
|
|
1381
|
+
body: { inputData: params.inputData, runtimeContext }
|
|
1382
|
+
});
|
|
1383
|
+
}
|
|
1384
|
+
/**
|
|
1385
|
+
* Starts a workflow run and returns a stream
|
|
1386
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
1387
|
+
* @returns Promise containing the workflow execution results
|
|
1388
|
+
*/
|
|
1389
|
+
async stream(params) {
|
|
1390
|
+
const searchParams = new URLSearchParams();
|
|
1391
|
+
if (!!params?.runId) {
|
|
1392
|
+
searchParams.set("runId", params.runId);
|
|
1393
|
+
}
|
|
1394
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1395
|
+
const response = await this.request(
|
|
1396
|
+
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1397
|
+
{
|
|
1398
|
+
method: "POST",
|
|
1399
|
+
body: { inputData: params.inputData, runtimeContext },
|
|
1400
|
+
stream: true
|
|
1401
|
+
}
|
|
1402
|
+
);
|
|
1403
|
+
if (!response.ok) {
|
|
1404
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
1405
|
+
}
|
|
1406
|
+
if (!response.body) {
|
|
1407
|
+
throw new Error("Response body is null");
|
|
1408
|
+
}
|
|
1409
|
+
const transformStream = new TransformStream({
|
|
1410
|
+
start() {
|
|
1411
|
+
},
|
|
1412
|
+
async transform(chunk, controller) {
|
|
1413
|
+
try {
|
|
1414
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1415
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
1416
|
+
for (const chunk2 of chunks) {
|
|
1417
|
+
if (chunk2) {
|
|
1418
|
+
try {
|
|
1419
|
+
const parsedChunk = JSON.parse(chunk2);
|
|
1420
|
+
controller.enqueue(parsedChunk);
|
|
1421
|
+
} catch {
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
} catch {
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
894
1428
|
});
|
|
1429
|
+
return response.body.pipeThrough(transformStream);
|
|
895
1430
|
}
|
|
896
1431
|
/**
|
|
897
|
-
* Resumes a suspended
|
|
1432
|
+
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
898
1433
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
899
|
-
* @returns Promise containing the
|
|
1434
|
+
* @returns Promise containing the workflow resume results
|
|
900
1435
|
*/
|
|
901
1436
|
resumeAsync(params) {
|
|
902
|
-
|
|
1437
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1438
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
903
1439
|
method: "POST",
|
|
904
1440
|
body: {
|
|
905
1441
|
step: params.step,
|
|
906
1442
|
resumeData: params.resumeData,
|
|
907
|
-
runtimeContext
|
|
1443
|
+
runtimeContext
|
|
908
1444
|
}
|
|
909
1445
|
});
|
|
910
1446
|
}
|
|
911
1447
|
/**
|
|
912
|
-
* Watches
|
|
1448
|
+
* Watches workflow transitions in real-time
|
|
913
1449
|
* @param runId - Optional run ID to filter the watch stream
|
|
914
|
-
* @returns AsyncGenerator that yields parsed records from the
|
|
1450
|
+
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
915
1451
|
*/
|
|
916
1452
|
async watch({ runId }, onRecord) {
|
|
917
|
-
const response = await this.request(`/api/workflows
|
|
1453
|
+
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
918
1454
|
stream: true
|
|
919
1455
|
});
|
|
920
1456
|
if (!response.ok) {
|
|
921
|
-
throw new Error(`Failed to watch
|
|
1457
|
+
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
922
1458
|
}
|
|
923
1459
|
if (!response.body) {
|
|
924
1460
|
throw new Error("Response body is null");
|
|
925
1461
|
}
|
|
926
1462
|
for await (const record of this.streamProcessor(response.body)) {
|
|
927
|
-
|
|
1463
|
+
if (typeof record === "string") {
|
|
1464
|
+
onRecord(JSON.parse(record));
|
|
1465
|
+
} else {
|
|
1466
|
+
onRecord(record);
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
/**
|
|
1471
|
+
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
1472
|
+
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
1473
|
+
*
|
|
1474
|
+
* @param records - An iterable or async iterable of objects to stream
|
|
1475
|
+
* @returns A ReadableStream emitting the records as JSON strings separated by the record separator
|
|
1476
|
+
*/
|
|
1477
|
+
static createRecordStream(records) {
|
|
1478
|
+
const encoder = new TextEncoder();
|
|
1479
|
+
return new ReadableStream({
|
|
1480
|
+
async start(controller) {
|
|
1481
|
+
try {
|
|
1482
|
+
for await (const record of records) {
|
|
1483
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR2;
|
|
1484
|
+
controller.enqueue(encoder.encode(json));
|
|
1485
|
+
}
|
|
1486
|
+
controller.close();
|
|
1487
|
+
} catch (err) {
|
|
1488
|
+
controller.error(err);
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
});
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1494
|
+
|
|
1495
|
+
// src/resources/a2a.ts
|
|
1496
|
+
var A2A = class extends BaseResource {
|
|
1497
|
+
constructor(options, agentId) {
|
|
1498
|
+
super(options);
|
|
1499
|
+
this.agentId = agentId;
|
|
1500
|
+
}
|
|
1501
|
+
/**
|
|
1502
|
+
* Get the agent card with metadata about the agent
|
|
1503
|
+
* @returns Promise containing the agent card information
|
|
1504
|
+
*/
|
|
1505
|
+
async getCard() {
|
|
1506
|
+
return this.request(`/.well-known/${this.agentId}/agent.json`);
|
|
1507
|
+
}
|
|
1508
|
+
/**
|
|
1509
|
+
* Send a message to the agent and get a response
|
|
1510
|
+
* @param params - Parameters for the task
|
|
1511
|
+
* @returns Promise containing the task response
|
|
1512
|
+
*/
|
|
1513
|
+
async sendMessage(params) {
|
|
1514
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1515
|
+
method: "POST",
|
|
1516
|
+
body: {
|
|
1517
|
+
method: "tasks/send",
|
|
1518
|
+
params
|
|
1519
|
+
}
|
|
1520
|
+
});
|
|
1521
|
+
return { task: response.result };
|
|
1522
|
+
}
|
|
1523
|
+
/**
|
|
1524
|
+
* Get the status and result of a task
|
|
1525
|
+
* @param params - Parameters for querying the task
|
|
1526
|
+
* @returns Promise containing the task response
|
|
1527
|
+
*/
|
|
1528
|
+
async getTask(params) {
|
|
1529
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1530
|
+
method: "POST",
|
|
1531
|
+
body: {
|
|
1532
|
+
method: "tasks/get",
|
|
1533
|
+
params
|
|
1534
|
+
}
|
|
1535
|
+
});
|
|
1536
|
+
return response.result;
|
|
1537
|
+
}
|
|
1538
|
+
/**
|
|
1539
|
+
* Cancel a running task
|
|
1540
|
+
* @param params - Parameters identifying the task to cancel
|
|
1541
|
+
* @returns Promise containing the task response
|
|
1542
|
+
*/
|
|
1543
|
+
async cancelTask(params) {
|
|
1544
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
1545
|
+
method: "POST",
|
|
1546
|
+
body: {
|
|
1547
|
+
method: "tasks/cancel",
|
|
1548
|
+
params
|
|
1549
|
+
}
|
|
1550
|
+
});
|
|
1551
|
+
}
|
|
1552
|
+
/**
|
|
1553
|
+
* Send a message and subscribe to streaming updates (not fully implemented)
|
|
1554
|
+
* @param params - Parameters for the task
|
|
1555
|
+
* @returns Promise containing the task response
|
|
1556
|
+
*/
|
|
1557
|
+
async sendAndSubscribe(params) {
|
|
1558
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
1559
|
+
method: "POST",
|
|
1560
|
+
body: {
|
|
1561
|
+
method: "tasks/sendSubscribe",
|
|
1562
|
+
params
|
|
1563
|
+
},
|
|
1564
|
+
stream: true
|
|
1565
|
+
});
|
|
1566
|
+
}
|
|
1567
|
+
};
|
|
1568
|
+
|
|
1569
|
+
// src/resources/mcp-tool.ts
|
|
1570
|
+
var MCPTool = class extends BaseResource {
|
|
1571
|
+
serverId;
|
|
1572
|
+
toolId;
|
|
1573
|
+
constructor(options, serverId, toolId) {
|
|
1574
|
+
super(options);
|
|
1575
|
+
this.serverId = serverId;
|
|
1576
|
+
this.toolId = toolId;
|
|
1577
|
+
}
|
|
1578
|
+
/**
|
|
1579
|
+
* Retrieves details about this specific tool from the MCP server.
|
|
1580
|
+
* @returns Promise containing the tool's information (name, description, schema).
|
|
1581
|
+
*/
|
|
1582
|
+
details() {
|
|
1583
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
1584
|
+
}
|
|
1585
|
+
/**
|
|
1586
|
+
* Executes this specific tool on the MCP server.
|
|
1587
|
+
* @param params - Parameters for tool execution, including data/args and optional runtimeContext.
|
|
1588
|
+
* @returns Promise containing the result of the tool execution.
|
|
1589
|
+
*/
|
|
1590
|
+
execute(params) {
|
|
1591
|
+
const body = {};
|
|
1592
|
+
if (params.data !== void 0) body.data = params.data;
|
|
1593
|
+
if (params.runtimeContext !== void 0) {
|
|
1594
|
+
body.runtimeContext = params.runtimeContext;
|
|
928
1595
|
}
|
|
1596
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
|
|
1597
|
+
method: "POST",
|
|
1598
|
+
body: Object.keys(body).length > 0 ? body : void 0
|
|
1599
|
+
});
|
|
1600
|
+
}
|
|
1601
|
+
};
|
|
1602
|
+
|
|
1603
|
+
// src/resources/vNextNetwork.ts
|
|
1604
|
+
var RECORD_SEPARATOR3 = "";
|
|
1605
|
+
var VNextNetwork = class extends BaseResource {
|
|
1606
|
+
constructor(options, networkId) {
|
|
1607
|
+
super(options);
|
|
1608
|
+
this.networkId = networkId;
|
|
1609
|
+
}
|
|
1610
|
+
/**
|
|
1611
|
+
* Retrieves details about the network
|
|
1612
|
+
* @returns Promise containing vNext network details
|
|
1613
|
+
*/
|
|
1614
|
+
details() {
|
|
1615
|
+
return this.request(`/api/networks/v-next/${this.networkId}`);
|
|
1616
|
+
}
|
|
1617
|
+
/**
|
|
1618
|
+
* Generates a response from the v-next network
|
|
1619
|
+
* @param params - Generation parameters including message
|
|
1620
|
+
* @returns Promise containing the generated response
|
|
1621
|
+
*/
|
|
1622
|
+
generate(params) {
|
|
1623
|
+
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
1624
|
+
method: "POST",
|
|
1625
|
+
body: params
|
|
1626
|
+
});
|
|
1627
|
+
}
|
|
1628
|
+
/**
|
|
1629
|
+
* Generates a response from the v-next network using multiple primitives
|
|
1630
|
+
* @param params - Generation parameters including message
|
|
1631
|
+
* @returns Promise containing the generated response
|
|
1632
|
+
*/
|
|
1633
|
+
loop(params) {
|
|
1634
|
+
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
1635
|
+
method: "POST",
|
|
1636
|
+
body: params
|
|
1637
|
+
});
|
|
1638
|
+
}
|
|
1639
|
+
async *streamProcessor(stream) {
|
|
1640
|
+
const reader = stream.getReader();
|
|
1641
|
+
let doneReading = false;
|
|
1642
|
+
let buffer = "";
|
|
1643
|
+
try {
|
|
1644
|
+
while (!doneReading) {
|
|
1645
|
+
const { done, value } = await reader.read();
|
|
1646
|
+
doneReading = done;
|
|
1647
|
+
if (done && !value) continue;
|
|
1648
|
+
try {
|
|
1649
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1650
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
1651
|
+
buffer = chunks.pop() || "";
|
|
1652
|
+
for (const chunk of chunks) {
|
|
1653
|
+
if (chunk) {
|
|
1654
|
+
if (typeof chunk === "string") {
|
|
1655
|
+
try {
|
|
1656
|
+
const parsedChunk = JSON.parse(chunk);
|
|
1657
|
+
yield parsedChunk;
|
|
1658
|
+
} catch {
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
} catch {
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
if (buffer) {
|
|
1667
|
+
try {
|
|
1668
|
+
yield JSON.parse(buffer);
|
|
1669
|
+
} catch {
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
} finally {
|
|
1673
|
+
reader.cancel().catch(() => {
|
|
1674
|
+
});
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
/**
|
|
1678
|
+
* Streams a response from the v-next network
|
|
1679
|
+
* @param params - Stream parameters including message
|
|
1680
|
+
* @returns Promise containing the results
|
|
1681
|
+
*/
|
|
1682
|
+
async stream(params, onRecord) {
|
|
1683
|
+
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
1684
|
+
method: "POST",
|
|
1685
|
+
body: params,
|
|
1686
|
+
stream: true
|
|
1687
|
+
});
|
|
1688
|
+
if (!response.ok) {
|
|
1689
|
+
throw new Error(`Failed to stream vNext network: ${response.statusText}`);
|
|
1690
|
+
}
|
|
1691
|
+
if (!response.body) {
|
|
1692
|
+
throw new Error("Response body is null");
|
|
1693
|
+
}
|
|
1694
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
1695
|
+
if (typeof record === "string") {
|
|
1696
|
+
onRecord(JSON.parse(record));
|
|
1697
|
+
} else {
|
|
1698
|
+
onRecord(record);
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
};
|
|
1703
|
+
|
|
1704
|
+
// src/resources/network-memory-thread.ts
|
|
1705
|
+
var NetworkMemoryThread = class extends BaseResource {
|
|
1706
|
+
constructor(options, threadId, networkId) {
|
|
1707
|
+
super(options);
|
|
1708
|
+
this.threadId = threadId;
|
|
1709
|
+
this.networkId = networkId;
|
|
1710
|
+
}
|
|
1711
|
+
/**
|
|
1712
|
+
* Retrieves the memory thread details
|
|
1713
|
+
* @returns Promise containing thread details including title and metadata
|
|
1714
|
+
*/
|
|
1715
|
+
get() {
|
|
1716
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
1717
|
+
}
|
|
1718
|
+
/**
|
|
1719
|
+
* Updates the memory thread properties
|
|
1720
|
+
* @param params - Update parameters including title and metadata
|
|
1721
|
+
* @returns Promise containing updated thread details
|
|
1722
|
+
*/
|
|
1723
|
+
update(params) {
|
|
1724
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1725
|
+
method: "PATCH",
|
|
1726
|
+
body: params
|
|
1727
|
+
});
|
|
1728
|
+
}
|
|
1729
|
+
/**
|
|
1730
|
+
* Deletes the memory thread
|
|
1731
|
+
* @returns Promise containing deletion result
|
|
1732
|
+
*/
|
|
1733
|
+
delete() {
|
|
1734
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1735
|
+
method: "DELETE"
|
|
1736
|
+
});
|
|
1737
|
+
}
|
|
1738
|
+
/**
|
|
1739
|
+
* Retrieves messages associated with the thread
|
|
1740
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
1741
|
+
* @returns Promise containing thread messages and UI messages
|
|
1742
|
+
*/
|
|
1743
|
+
getMessages(params) {
|
|
1744
|
+
const query = new URLSearchParams({
|
|
1745
|
+
networkId: this.networkId,
|
|
1746
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
1747
|
+
});
|
|
1748
|
+
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
929
1749
|
}
|
|
930
1750
|
};
|
|
931
1751
|
|
|
@@ -1006,6 +1826,48 @@ var MastraClient = class extends BaseResource {
|
|
|
1006
1826
|
getMemoryStatus(agentId) {
|
|
1007
1827
|
return this.request(`/api/memory/status?agentId=${agentId}`);
|
|
1008
1828
|
}
|
|
1829
|
+
/**
|
|
1830
|
+
* Retrieves memory threads for a resource
|
|
1831
|
+
* @param params - Parameters containing the resource ID
|
|
1832
|
+
* @returns Promise containing array of memory threads
|
|
1833
|
+
*/
|
|
1834
|
+
getNetworkMemoryThreads(params) {
|
|
1835
|
+
return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
|
|
1836
|
+
}
|
|
1837
|
+
/**
|
|
1838
|
+
* Creates a new memory thread
|
|
1839
|
+
* @param params - Parameters for creating the memory thread
|
|
1840
|
+
* @returns Promise containing the created memory thread
|
|
1841
|
+
*/
|
|
1842
|
+
createNetworkMemoryThread(params) {
|
|
1843
|
+
return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: "POST", body: params });
|
|
1844
|
+
}
|
|
1845
|
+
/**
|
|
1846
|
+
* Gets a memory thread instance by ID
|
|
1847
|
+
* @param threadId - ID of the memory thread to retrieve
|
|
1848
|
+
* @returns MemoryThread instance
|
|
1849
|
+
*/
|
|
1850
|
+
getNetworkMemoryThread(threadId, networkId) {
|
|
1851
|
+
return new NetworkMemoryThread(this.options, threadId, networkId);
|
|
1852
|
+
}
|
|
1853
|
+
/**
|
|
1854
|
+
* Saves messages to memory
|
|
1855
|
+
* @param params - Parameters containing messages to save
|
|
1856
|
+
* @returns Promise containing the saved messages
|
|
1857
|
+
*/
|
|
1858
|
+
saveNetworkMessageToMemory(params) {
|
|
1859
|
+
return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
|
|
1860
|
+
method: "POST",
|
|
1861
|
+
body: params
|
|
1862
|
+
});
|
|
1863
|
+
}
|
|
1864
|
+
/**
|
|
1865
|
+
* Gets the status of the memory system
|
|
1866
|
+
* @returns Promise containing memory system status
|
|
1867
|
+
*/
|
|
1868
|
+
getNetworkMemoryStatus(networkId) {
|
|
1869
|
+
return this.request(`/api/memory/network/status?networkId=${networkId}`);
|
|
1870
|
+
}
|
|
1009
1871
|
/**
|
|
1010
1872
|
* Retrieves all available tools
|
|
1011
1873
|
* @returns Promise containing map of tool IDs to tool details
|
|
@@ -1019,7 +1881,22 @@ var MastraClient = class extends BaseResource {
|
|
|
1019
1881
|
* @returns Tool instance
|
|
1020
1882
|
*/
|
|
1021
1883
|
getTool(toolId) {
|
|
1022
|
-
return new
|
|
1884
|
+
return new Tool2(this.options, toolId);
|
|
1885
|
+
}
|
|
1886
|
+
/**
|
|
1887
|
+
* Retrieves all available legacy workflows
|
|
1888
|
+
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
1889
|
+
*/
|
|
1890
|
+
getLegacyWorkflows() {
|
|
1891
|
+
return this.request("/api/workflows/legacy");
|
|
1892
|
+
}
|
|
1893
|
+
/**
|
|
1894
|
+
* Gets a legacy workflow instance by ID
|
|
1895
|
+
* @param workflowId - ID of the legacy workflow to retrieve
|
|
1896
|
+
* @returns Legacy Workflow instance
|
|
1897
|
+
*/
|
|
1898
|
+
getLegacyWorkflow(workflowId) {
|
|
1899
|
+
return new LegacyWorkflow(this.options, workflowId);
|
|
1023
1900
|
}
|
|
1024
1901
|
/**
|
|
1025
1902
|
* Retrieves all available workflows
|
|
@@ -1036,21 +1913,6 @@ var MastraClient = class extends BaseResource {
|
|
|
1036
1913
|
getWorkflow(workflowId) {
|
|
1037
1914
|
return new Workflow(this.options, workflowId);
|
|
1038
1915
|
}
|
|
1039
|
-
/**
|
|
1040
|
-
* Retrieves all available vNext workflows
|
|
1041
|
-
* @returns Promise containing map of vNext workflow IDs to vNext workflow details
|
|
1042
|
-
*/
|
|
1043
|
-
getVNextWorkflows() {
|
|
1044
|
-
return this.request("/api/workflows/v-next");
|
|
1045
|
-
}
|
|
1046
|
-
/**
|
|
1047
|
-
* Gets a vNext workflow instance by ID
|
|
1048
|
-
* @param workflowId - ID of the vNext workflow to retrieve
|
|
1049
|
-
* @returns vNext Workflow instance
|
|
1050
|
-
*/
|
|
1051
|
-
getVNextWorkflow(workflowId) {
|
|
1052
|
-
return new VNextWorkflow(this.options, workflowId);
|
|
1053
|
-
}
|
|
1054
1916
|
/**
|
|
1055
1917
|
* Gets a vector instance by name
|
|
1056
1918
|
* @param vectorName - Name of the vector to retrieve
|
|
@@ -1065,7 +1927,41 @@ var MastraClient = class extends BaseResource {
|
|
|
1065
1927
|
* @returns Promise containing array of log messages
|
|
1066
1928
|
*/
|
|
1067
1929
|
getLogs(params) {
|
|
1068
|
-
|
|
1930
|
+
const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
1931
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
1932
|
+
const searchParams = new URLSearchParams();
|
|
1933
|
+
if (transportId) {
|
|
1934
|
+
searchParams.set("transportId", transportId);
|
|
1935
|
+
}
|
|
1936
|
+
if (fromDate) {
|
|
1937
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
1938
|
+
}
|
|
1939
|
+
if (toDate) {
|
|
1940
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
1941
|
+
}
|
|
1942
|
+
if (logLevel) {
|
|
1943
|
+
searchParams.set("logLevel", logLevel);
|
|
1944
|
+
}
|
|
1945
|
+
if (page) {
|
|
1946
|
+
searchParams.set("page", String(page));
|
|
1947
|
+
}
|
|
1948
|
+
if (perPage) {
|
|
1949
|
+
searchParams.set("perPage", String(perPage));
|
|
1950
|
+
}
|
|
1951
|
+
if (_filters) {
|
|
1952
|
+
if (Array.isArray(_filters)) {
|
|
1953
|
+
for (const filter of _filters) {
|
|
1954
|
+
searchParams.append("filters", filter);
|
|
1955
|
+
}
|
|
1956
|
+
} else {
|
|
1957
|
+
searchParams.set("filters", _filters);
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
if (searchParams.size) {
|
|
1961
|
+
return this.request(`/api/logs?${searchParams}`);
|
|
1962
|
+
} else {
|
|
1963
|
+
return this.request(`/api/logs`);
|
|
1964
|
+
}
|
|
1069
1965
|
}
|
|
1070
1966
|
/**
|
|
1071
1967
|
* Gets logs for a specific run
|
|
@@ -1073,7 +1969,44 @@ var MastraClient = class extends BaseResource {
|
|
|
1073
1969
|
* @returns Promise containing array of log messages
|
|
1074
1970
|
*/
|
|
1075
1971
|
getLogForRun(params) {
|
|
1076
|
-
|
|
1972
|
+
const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
1973
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
1974
|
+
const searchParams = new URLSearchParams();
|
|
1975
|
+
if (runId) {
|
|
1976
|
+
searchParams.set("runId", runId);
|
|
1977
|
+
}
|
|
1978
|
+
if (transportId) {
|
|
1979
|
+
searchParams.set("transportId", transportId);
|
|
1980
|
+
}
|
|
1981
|
+
if (fromDate) {
|
|
1982
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
1983
|
+
}
|
|
1984
|
+
if (toDate) {
|
|
1985
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
1986
|
+
}
|
|
1987
|
+
if (logLevel) {
|
|
1988
|
+
searchParams.set("logLevel", logLevel);
|
|
1989
|
+
}
|
|
1990
|
+
if (page) {
|
|
1991
|
+
searchParams.set("page", String(page));
|
|
1992
|
+
}
|
|
1993
|
+
if (perPage) {
|
|
1994
|
+
searchParams.set("perPage", String(perPage));
|
|
1995
|
+
}
|
|
1996
|
+
if (_filters) {
|
|
1997
|
+
if (Array.isArray(_filters)) {
|
|
1998
|
+
for (const filter of _filters) {
|
|
1999
|
+
searchParams.append("filters", filter);
|
|
2000
|
+
}
|
|
2001
|
+
} else {
|
|
2002
|
+
searchParams.set("filters", _filters);
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
if (searchParams.size) {
|
|
2006
|
+
return this.request(`/api/logs/${runId}?${searchParams}`);
|
|
2007
|
+
} else {
|
|
2008
|
+
return this.request(`/api/logs/${runId}`);
|
|
2009
|
+
}
|
|
1077
2010
|
}
|
|
1078
2011
|
/**
|
|
1079
2012
|
* List of all log transports
|
|
@@ -1131,6 +2064,13 @@ var MastraClient = class extends BaseResource {
|
|
|
1131
2064
|
getNetworks() {
|
|
1132
2065
|
return this.request("/api/networks");
|
|
1133
2066
|
}
|
|
2067
|
+
/**
|
|
2068
|
+
* Retrieves all available vNext networks
|
|
2069
|
+
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
2070
|
+
*/
|
|
2071
|
+
getVNextNetworks() {
|
|
2072
|
+
return this.request("/api/networks/v-next");
|
|
2073
|
+
}
|
|
1134
2074
|
/**
|
|
1135
2075
|
* Gets a network instance by ID
|
|
1136
2076
|
* @param networkId - ID of the network to retrieve
|
|
@@ -1139,6 +2079,70 @@ var MastraClient = class extends BaseResource {
|
|
|
1139
2079
|
getNetwork(networkId) {
|
|
1140
2080
|
return new Network(this.options, networkId);
|
|
1141
2081
|
}
|
|
2082
|
+
/**
|
|
2083
|
+
* Gets a vNext network instance by ID
|
|
2084
|
+
* @param networkId - ID of the vNext network to retrieve
|
|
2085
|
+
* @returns vNext Network instance
|
|
2086
|
+
*/
|
|
2087
|
+
getVNextNetwork(networkId) {
|
|
2088
|
+
return new VNextNetwork(this.options, networkId);
|
|
2089
|
+
}
|
|
2090
|
+
/**
|
|
2091
|
+
* Retrieves a list of available MCP servers.
|
|
2092
|
+
* @param params - Optional parameters for pagination (limit, offset).
|
|
2093
|
+
* @returns Promise containing the list of MCP servers and pagination info.
|
|
2094
|
+
*/
|
|
2095
|
+
getMcpServers(params) {
|
|
2096
|
+
const searchParams = new URLSearchParams();
|
|
2097
|
+
if (params?.limit !== void 0) {
|
|
2098
|
+
searchParams.set("limit", String(params.limit));
|
|
2099
|
+
}
|
|
2100
|
+
if (params?.offset !== void 0) {
|
|
2101
|
+
searchParams.set("offset", String(params.offset));
|
|
2102
|
+
}
|
|
2103
|
+
const queryString = searchParams.toString();
|
|
2104
|
+
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
|
|
2105
|
+
}
|
|
2106
|
+
/**
|
|
2107
|
+
* Retrieves detailed information for a specific MCP server.
|
|
2108
|
+
* @param serverId - The ID of the MCP server to retrieve.
|
|
2109
|
+
* @param params - Optional parameters, e.g., specific version.
|
|
2110
|
+
* @returns Promise containing the detailed MCP server information.
|
|
2111
|
+
*/
|
|
2112
|
+
getMcpServerDetails(serverId, params) {
|
|
2113
|
+
const searchParams = new URLSearchParams();
|
|
2114
|
+
if (params?.version) {
|
|
2115
|
+
searchParams.set("version", params.version);
|
|
2116
|
+
}
|
|
2117
|
+
const queryString = searchParams.toString();
|
|
2118
|
+
return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ""}`);
|
|
2119
|
+
}
|
|
2120
|
+
/**
|
|
2121
|
+
* Retrieves a list of tools for a specific MCP server.
|
|
2122
|
+
* @param serverId - The ID of the MCP server.
|
|
2123
|
+
* @returns Promise containing the list of tools.
|
|
2124
|
+
*/
|
|
2125
|
+
getMcpServerTools(serverId) {
|
|
2126
|
+
return this.request(`/api/mcp/${serverId}/tools`);
|
|
2127
|
+
}
|
|
2128
|
+
/**
|
|
2129
|
+
* Gets an MCPTool resource instance for a specific tool on an MCP server.
|
|
2130
|
+
* This instance can then be used to fetch details or execute the tool.
|
|
2131
|
+
* @param serverId - The ID of the MCP server.
|
|
2132
|
+
* @param toolId - The ID of the tool.
|
|
2133
|
+
* @returns MCPTool instance.
|
|
2134
|
+
*/
|
|
2135
|
+
getMcpServerTool(serverId, toolId) {
|
|
2136
|
+
return new MCPTool(this.options, serverId, toolId);
|
|
2137
|
+
}
|
|
2138
|
+
/**
|
|
2139
|
+
* Gets an A2A client for interacting with an agent via the A2A protocol
|
|
2140
|
+
* @param agentId - ID of the agent to interact with
|
|
2141
|
+
* @returns A2A client instance
|
|
2142
|
+
*/
|
|
2143
|
+
getA2A(agentId) {
|
|
2144
|
+
return new A2A(this.options, agentId);
|
|
2145
|
+
}
|
|
1142
2146
|
};
|
|
1143
2147
|
|
|
1144
2148
|
export { MastraClient };
|