@mastra/client-js 0.0.0-vector-query-tool-provider-options-20250828222356 → 0.0.0-vector-extension-schema-20250922130418
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +429 -4
- package/README.md +7 -9
- package/dist/client.d.ts +37 -21
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +871 -417
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +869 -417
- package/dist/index.js.map +1 -1
- package/dist/resources/agent-builder.d.ts +160 -0
- package/dist/resources/agent-builder.d.ts.map +1 -0
- package/dist/resources/agent.d.ts +56 -11
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/resources/index.d.ts +1 -1
- package/dist/resources/index.d.ts.map +1 -1
- package/dist/resources/legacy-workflow.d.ts +5 -2
- package/dist/resources/legacy-workflow.d.ts.map +1 -1
- package/dist/resources/mcp-tool.d.ts +2 -1
- package/dist/resources/mcp-tool.d.ts.map +1 -1
- package/dist/resources/observability.d.ts.map +1 -1
- package/dist/resources/tool.d.ts +2 -1
- package/dist/resources/tool.d.ts.map +1 -1
- package/dist/resources/vNextNetwork.d.ts +2 -1
- package/dist/resources/vNextNetwork.d.ts.map +1 -1
- package/dist/resources/vector.d.ts +5 -2
- package/dist/resources/vector.d.ts.map +1 -1
- package/dist/resources/workflow.d.ts +110 -10
- package/dist/resources/workflow.d.ts.map +1 -1
- package/dist/tools.d.ts +22 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/types.d.ts +36 -21
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/process-mastra-stream.d.ts +5 -1
- package/dist/utils/process-mastra-stream.d.ts.map +1 -1
- package/package.json +19 -15
- package/.turbo/turbo-build.log +0 -18
- package/dist/adapters/agui.d.ts +0 -23
- package/dist/adapters/agui.d.ts.map +0 -1
- package/dist/resources/network.d.ts +0 -30
- package/dist/resources/network.d.ts.map +0 -1
- package/eslint.config.js +0 -11
- package/integration-tests/agui-adapter.test.ts +0 -122
- package/integration-tests/package.json +0 -18
- package/integration-tests/src/mastra/index.ts +0 -35
- package/integration-tests/vitest.config.ts +0 -9
- package/src/adapters/agui.test.ts +0 -293
- package/src/adapters/agui.ts +0 -257
- package/src/client.ts +0 -644
- package/src/example.ts +0 -95
- package/src/index.test.ts +0 -1253
- package/src/index.ts +0 -3
- package/src/resources/a2a.ts +0 -98
- package/src/resources/agent.ts +0 -1460
- package/src/resources/base.ts +0 -77
- package/src/resources/index.ts +0 -11
- package/src/resources/legacy-workflow.ts +0 -242
- package/src/resources/mcp-tool.ts +0 -48
- package/src/resources/memory-thread.test.ts +0 -285
- package/src/resources/memory-thread.ts +0 -99
- package/src/resources/network-memory-thread.test.ts +0 -269
- package/src/resources/network-memory-thread.ts +0 -81
- package/src/resources/network.ts +0 -86
- package/src/resources/observability.ts +0 -53
- package/src/resources/tool.ts +0 -45
- package/src/resources/vNextNetwork.ts +0 -194
- package/src/resources/vector.ts +0 -83
- package/src/resources/workflow.ts +0 -410
- package/src/types.ts +0 -534
- package/src/utils/index.ts +0 -11
- package/src/utils/process-client-tools.ts +0 -32
- package/src/utils/process-mastra-stream.test.ts +0 -353
- package/src/utils/process-mastra-stream.ts +0 -49
- package/src/utils/zod-to-json-schema.ts +0 -30
- package/src/v2-messages.test.ts +0 -180
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -5
- package/tsup.config.ts +0 -17
- package/vitest.config.js +0 -8
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var client = require('@ag-ui/client');
|
|
4
|
-
var rxjs = require('rxjs');
|
|
5
3
|
var uiUtils = require('@ai-sdk/ui-utils');
|
|
6
4
|
var uuid = require('@lukeed/uuid');
|
|
7
5
|
var runtimeContext = require('@mastra/core/runtime-context');
|
|
@@ -13,205 +11,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
13
11
|
|
|
14
12
|
var originalZodToJsonSchema__default = /*#__PURE__*/_interopDefault(originalZodToJsonSchema);
|
|
15
13
|
|
|
16
|
-
// src/
|
|
17
|
-
var AGUIAdapter = class extends client.AbstractAgent {
|
|
18
|
-
agent;
|
|
19
|
-
resourceId;
|
|
20
|
-
constructor({ agent, agentId, resourceId, ...rest }) {
|
|
21
|
-
super({
|
|
22
|
-
agentId,
|
|
23
|
-
...rest
|
|
24
|
-
});
|
|
25
|
-
this.agent = agent;
|
|
26
|
-
this.resourceId = resourceId;
|
|
27
|
-
}
|
|
28
|
-
run(input) {
|
|
29
|
-
return new rxjs.Observable((subscriber) => {
|
|
30
|
-
const convertedMessages = convertMessagesToMastraMessages(input.messages);
|
|
31
|
-
subscriber.next({
|
|
32
|
-
type: client.EventType.RUN_STARTED,
|
|
33
|
-
threadId: input.threadId,
|
|
34
|
-
runId: input.runId
|
|
35
|
-
});
|
|
36
|
-
this.agent.stream({
|
|
37
|
-
threadId: input.threadId,
|
|
38
|
-
resourceId: this.resourceId ?? "",
|
|
39
|
-
runId: input.runId,
|
|
40
|
-
messages: convertedMessages,
|
|
41
|
-
clientTools: input.tools.reduce(
|
|
42
|
-
(acc, tool) => {
|
|
43
|
-
acc[tool.name] = {
|
|
44
|
-
id: tool.name,
|
|
45
|
-
description: tool.description,
|
|
46
|
-
inputSchema: tool.parameters
|
|
47
|
-
};
|
|
48
|
-
return acc;
|
|
49
|
-
},
|
|
50
|
-
{}
|
|
51
|
-
)
|
|
52
|
-
}).then((response) => {
|
|
53
|
-
let currentMessageId = void 0;
|
|
54
|
-
let isInTextMessage = false;
|
|
55
|
-
return response.processDataStream({
|
|
56
|
-
onTextPart: (text) => {
|
|
57
|
-
if (currentMessageId === void 0) {
|
|
58
|
-
currentMessageId = generateUUID();
|
|
59
|
-
const message2 = {
|
|
60
|
-
type: client.EventType.TEXT_MESSAGE_START,
|
|
61
|
-
messageId: currentMessageId,
|
|
62
|
-
role: "assistant"
|
|
63
|
-
};
|
|
64
|
-
subscriber.next(message2);
|
|
65
|
-
isInTextMessage = true;
|
|
66
|
-
}
|
|
67
|
-
const message = {
|
|
68
|
-
type: client.EventType.TEXT_MESSAGE_CONTENT,
|
|
69
|
-
messageId: currentMessageId,
|
|
70
|
-
delta: text
|
|
71
|
-
};
|
|
72
|
-
subscriber.next(message);
|
|
73
|
-
},
|
|
74
|
-
onFinishMessagePart: () => {
|
|
75
|
-
if (currentMessageId !== void 0) {
|
|
76
|
-
const message = {
|
|
77
|
-
type: client.EventType.TEXT_MESSAGE_END,
|
|
78
|
-
messageId: currentMessageId
|
|
79
|
-
};
|
|
80
|
-
subscriber.next(message);
|
|
81
|
-
isInTextMessage = false;
|
|
82
|
-
}
|
|
83
|
-
subscriber.next({
|
|
84
|
-
type: client.EventType.RUN_FINISHED,
|
|
85
|
-
threadId: input.threadId,
|
|
86
|
-
runId: input.runId
|
|
87
|
-
});
|
|
88
|
-
subscriber.complete();
|
|
89
|
-
},
|
|
90
|
-
onToolCallPart(streamPart) {
|
|
91
|
-
const parentMessageId = currentMessageId || generateUUID();
|
|
92
|
-
if (isInTextMessage) {
|
|
93
|
-
const message = {
|
|
94
|
-
type: client.EventType.TEXT_MESSAGE_END,
|
|
95
|
-
messageId: parentMessageId
|
|
96
|
-
};
|
|
97
|
-
subscriber.next(message);
|
|
98
|
-
isInTextMessage = false;
|
|
99
|
-
}
|
|
100
|
-
subscriber.next({
|
|
101
|
-
type: client.EventType.TOOL_CALL_START,
|
|
102
|
-
toolCallId: streamPart.toolCallId,
|
|
103
|
-
toolCallName: streamPart.toolName,
|
|
104
|
-
parentMessageId
|
|
105
|
-
});
|
|
106
|
-
subscriber.next({
|
|
107
|
-
type: client.EventType.TOOL_CALL_ARGS,
|
|
108
|
-
toolCallId: streamPart.toolCallId,
|
|
109
|
-
delta: JSON.stringify(streamPart.args),
|
|
110
|
-
parentMessageId
|
|
111
|
-
});
|
|
112
|
-
subscriber.next({
|
|
113
|
-
type: client.EventType.TOOL_CALL_END,
|
|
114
|
-
toolCallId: streamPart.toolCallId,
|
|
115
|
-
parentMessageId
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}).catch((error) => {
|
|
120
|
-
console.error("error", error);
|
|
121
|
-
subscriber.error(error);
|
|
122
|
-
});
|
|
123
|
-
return () => {
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
function generateUUID() {
|
|
129
|
-
if (typeof crypto !== "undefined") {
|
|
130
|
-
if (typeof crypto.randomUUID === "function") {
|
|
131
|
-
return crypto.randomUUID();
|
|
132
|
-
}
|
|
133
|
-
if (typeof crypto.getRandomValues === "function") {
|
|
134
|
-
const buffer = new Uint8Array(16);
|
|
135
|
-
crypto.getRandomValues(buffer);
|
|
136
|
-
buffer[6] = buffer[6] & 15 | 64;
|
|
137
|
-
buffer[8] = buffer[8] & 63 | 128;
|
|
138
|
-
let hex = "";
|
|
139
|
-
for (let i = 0; i < 16; i++) {
|
|
140
|
-
hex += buffer[i].toString(16).padStart(2, "0");
|
|
141
|
-
if (i === 3 || i === 5 || i === 7 || i === 9) hex += "-";
|
|
142
|
-
}
|
|
143
|
-
return hex;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
147
|
-
const r = Math.random() * 16 | 0;
|
|
148
|
-
const v = c === "x" ? r : r & 3 | 8;
|
|
149
|
-
return v.toString(16);
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
function convertMessagesToMastraMessages(messages) {
|
|
153
|
-
const result = [];
|
|
154
|
-
const toolCallsWithResults = /* @__PURE__ */ new Set();
|
|
155
|
-
for (const message of messages) {
|
|
156
|
-
if (message.role === "tool" && message.toolCallId) {
|
|
157
|
-
toolCallsWithResults.add(message.toolCallId);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
for (const message of messages) {
|
|
161
|
-
if (message.role === "assistant") {
|
|
162
|
-
const parts = message.content ? [{ type: "text", text: message.content }] : [];
|
|
163
|
-
for (const toolCall of message.toolCalls ?? []) {
|
|
164
|
-
parts.push({
|
|
165
|
-
type: "tool-call",
|
|
166
|
-
toolCallId: toolCall.id,
|
|
167
|
-
toolName: toolCall.function.name,
|
|
168
|
-
args: JSON.parse(toolCall.function.arguments)
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
result.push({
|
|
172
|
-
role: "assistant",
|
|
173
|
-
content: parts
|
|
174
|
-
});
|
|
175
|
-
if (message.toolCalls?.length) {
|
|
176
|
-
for (const toolCall of message.toolCalls) {
|
|
177
|
-
if (!toolCallsWithResults.has(toolCall.id)) {
|
|
178
|
-
result.push({
|
|
179
|
-
role: "tool",
|
|
180
|
-
content: [
|
|
181
|
-
{
|
|
182
|
-
type: "tool-result",
|
|
183
|
-
toolCallId: toolCall.id,
|
|
184
|
-
toolName: toolCall.function.name,
|
|
185
|
-
result: JSON.parse(toolCall.function.arguments)
|
|
186
|
-
// This is still wrong but matches test expectations
|
|
187
|
-
}
|
|
188
|
-
]
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
} else if (message.role === "user") {
|
|
194
|
-
result.push({
|
|
195
|
-
role: "user",
|
|
196
|
-
content: message.content || ""
|
|
197
|
-
});
|
|
198
|
-
} else if (message.role === "tool") {
|
|
199
|
-
result.push({
|
|
200
|
-
role: "tool",
|
|
201
|
-
content: [
|
|
202
|
-
{
|
|
203
|
-
type: "tool-result",
|
|
204
|
-
toolCallId: message.toolCallId || "unknown",
|
|
205
|
-
toolName: "unknown",
|
|
206
|
-
// toolName is not available in tool messages from CopilotKit
|
|
207
|
-
result: message.content
|
|
208
|
-
}
|
|
209
|
-
]
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
return result;
|
|
214
|
-
}
|
|
14
|
+
// src/resources/agent.ts
|
|
215
15
|
function parseClientRuntimeContext(runtimeContext$1) {
|
|
216
16
|
if (runtimeContext$1) {
|
|
217
17
|
if (runtimeContext$1 instanceof runtimeContext.RuntimeContext) {
|
|
@@ -221,6 +21,20 @@ function parseClientRuntimeContext(runtimeContext$1) {
|
|
|
221
21
|
}
|
|
222
22
|
return void 0;
|
|
223
23
|
}
|
|
24
|
+
function base64RuntimeContext(runtimeContext) {
|
|
25
|
+
if (runtimeContext) {
|
|
26
|
+
return btoa(JSON.stringify(runtimeContext));
|
|
27
|
+
}
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
function runtimeContextQueryString(runtimeContext) {
|
|
31
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
32
|
+
if (!runtimeContextParam) return "";
|
|
33
|
+
const searchParams = new URLSearchParams();
|
|
34
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
35
|
+
const queryString = searchParams.toString();
|
|
36
|
+
return queryString ? `?${queryString}` : "";
|
|
37
|
+
}
|
|
224
38
|
function isZodType(value) {
|
|
225
39
|
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
226
40
|
}
|
|
@@ -232,7 +46,7 @@ function zodToJsonSchema(zodSchema) {
|
|
|
232
46
|
const fn = "toJSONSchema";
|
|
233
47
|
return zod.z[fn].call(zod.z, zodSchema);
|
|
234
48
|
}
|
|
235
|
-
return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "
|
|
49
|
+
return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "relative" });
|
|
236
50
|
}
|
|
237
51
|
|
|
238
52
|
// src/utils/process-client-tools.ts
|
|
@@ -265,7 +79,7 @@ function processClientTools(clientTools) {
|
|
|
265
79
|
}
|
|
266
80
|
|
|
267
81
|
// src/utils/process-mastra-stream.ts
|
|
268
|
-
async function
|
|
82
|
+
async function sharedProcessMastraStream({
|
|
269
83
|
stream,
|
|
270
84
|
onChunk
|
|
271
85
|
}) {
|
|
@@ -283,7 +97,7 @@ async function processMastraStream({
|
|
|
283
97
|
if (line.startsWith("data: ")) {
|
|
284
98
|
const data = line.slice(6);
|
|
285
99
|
if (data === "[DONE]") {
|
|
286
|
-
console.
|
|
100
|
+
console.info("\u{1F3C1} Stream finished");
|
|
287
101
|
return;
|
|
288
102
|
}
|
|
289
103
|
try {
|
|
@@ -299,6 +113,24 @@ async function processMastraStream({
|
|
|
299
113
|
reader.releaseLock();
|
|
300
114
|
}
|
|
301
115
|
}
|
|
116
|
+
async function processMastraNetworkStream({
|
|
117
|
+
stream,
|
|
118
|
+
onChunk
|
|
119
|
+
}) {
|
|
120
|
+
return sharedProcessMastraStream({
|
|
121
|
+
stream,
|
|
122
|
+
onChunk
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
async function processMastraStream({
|
|
126
|
+
stream,
|
|
127
|
+
onChunk
|
|
128
|
+
}) {
|
|
129
|
+
return sharedProcessMastraStream({
|
|
130
|
+
stream,
|
|
131
|
+
onChunk
|
|
132
|
+
});
|
|
133
|
+
}
|
|
302
134
|
|
|
303
135
|
// src/resources/base.ts
|
|
304
136
|
var BaseResource = class {
|
|
@@ -461,17 +293,21 @@ var AgentVoice = class extends BaseResource {
|
|
|
461
293
|
}
|
|
462
294
|
/**
|
|
463
295
|
* Get available speakers for the agent's voice provider
|
|
296
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
297
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
464
298
|
* @returns Promise containing list of available speakers
|
|
465
299
|
*/
|
|
466
|
-
getSpeakers() {
|
|
467
|
-
return this.request(`/api/agents/${this.agentId}/voice/speakers`);
|
|
300
|
+
getSpeakers(runtimeContext) {
|
|
301
|
+
return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
|
|
468
302
|
}
|
|
469
303
|
/**
|
|
470
304
|
* Get the listener configuration for the agent's voice provider
|
|
305
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
306
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
471
307
|
* @returns Promise containing a check if the agent has listening capabilities
|
|
472
308
|
*/
|
|
473
|
-
getListener() {
|
|
474
|
-
return this.request(`/api/agents/${this.agentId}/voice/listener`);
|
|
309
|
+
getListener(runtimeContext) {
|
|
310
|
+
return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
|
|
475
311
|
}
|
|
476
312
|
};
|
|
477
313
|
var Agent = class extends BaseResource {
|
|
@@ -483,12 +319,19 @@ var Agent = class extends BaseResource {
|
|
|
483
319
|
voice;
|
|
484
320
|
/**
|
|
485
321
|
* Retrieves details about the agent
|
|
322
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
486
323
|
* @returns Promise containing agent details including model and instructions
|
|
487
324
|
*/
|
|
488
|
-
details() {
|
|
489
|
-
return this.request(`/api/agents/${this.agentId}`);
|
|
325
|
+
details(runtimeContext) {
|
|
326
|
+
return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
|
|
490
327
|
}
|
|
491
328
|
async generate(params) {
|
|
329
|
+
console.warn(
|
|
330
|
+
"Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 23rd, 2025. Please use generateLegacy if you don't want to upgrade just yet."
|
|
331
|
+
);
|
|
332
|
+
return this.generateLegacy(params);
|
|
333
|
+
}
|
|
334
|
+
async generateLegacy(params) {
|
|
492
335
|
const processedParams = {
|
|
493
336
|
...params,
|
|
494
337
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
@@ -498,7 +341,7 @@ var Agent = class extends BaseResource {
|
|
|
498
341
|
};
|
|
499
342
|
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
500
343
|
const response = await this.request(
|
|
501
|
-
`/api/agents/${this.agentId}/generate`,
|
|
344
|
+
`/api/agents/${this.agentId}/generate-legacy`,
|
|
502
345
|
{
|
|
503
346
|
method: "POST",
|
|
504
347
|
body: processedParams
|
|
@@ -553,12 +396,25 @@ var Agent = class extends BaseResource {
|
|
|
553
396
|
}
|
|
554
397
|
return response;
|
|
555
398
|
}
|
|
556
|
-
async generateVNext(
|
|
399
|
+
async generateVNext(messagesOrParams, options) {
|
|
400
|
+
let params;
|
|
401
|
+
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
402
|
+
params = messagesOrParams;
|
|
403
|
+
} else {
|
|
404
|
+
params = {
|
|
405
|
+
messages: messagesOrParams,
|
|
406
|
+
...options
|
|
407
|
+
};
|
|
408
|
+
}
|
|
557
409
|
const processedParams = {
|
|
558
410
|
...params,
|
|
559
411
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
560
412
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
561
|
-
clientTools: processClientTools(params.clientTools)
|
|
413
|
+
clientTools: processClientTools(params.clientTools),
|
|
414
|
+
structuredOutput: params.structuredOutput ? {
|
|
415
|
+
...params.structuredOutput,
|
|
416
|
+
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
417
|
+
} : void 0
|
|
562
418
|
};
|
|
563
419
|
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
564
420
|
const response = await this.request(
|
|
@@ -849,6 +705,17 @@ var Agent = class extends BaseResource {
|
|
|
849
705
|
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
850
706
|
*/
|
|
851
707
|
async stream(params) {
|
|
708
|
+
console.warn(
|
|
709
|
+
"Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 23rd, 2025. Please use streamLegacy if you don't want to upgrade just yet."
|
|
710
|
+
);
|
|
711
|
+
return this.streamLegacy(params);
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Streams a response from the agent
|
|
715
|
+
* @param params - Stream parameters including prompt
|
|
716
|
+
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
717
|
+
*/
|
|
718
|
+
async streamLegacy(params) {
|
|
852
719
|
const processedParams = {
|
|
853
720
|
...params,
|
|
854
721
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
@@ -1052,7 +919,7 @@ var Agent = class extends BaseResource {
|
|
|
1052
919
|
step,
|
|
1053
920
|
toolCallId: chunk.payload.toolCallId,
|
|
1054
921
|
toolName: chunk.payload.toolName,
|
|
1055
|
-
args:
|
|
922
|
+
args: chunk.payload.args
|
|
1056
923
|
};
|
|
1057
924
|
message.toolInvocations.push(invocation);
|
|
1058
925
|
updateToolInvocationPart(chunk.payload.toolCallId, invocation);
|
|
@@ -1106,14 +973,14 @@ var Agent = class extends BaseResource {
|
|
|
1106
973
|
}
|
|
1107
974
|
case "step-finish": {
|
|
1108
975
|
step += 1;
|
|
1109
|
-
currentTextPart = chunk.payload.isContinued ? currentTextPart : void 0;
|
|
976
|
+
currentTextPart = chunk.payload.stepResult.isContinued ? currentTextPart : void 0;
|
|
1110
977
|
currentReasoningPart = void 0;
|
|
1111
978
|
currentReasoningTextDetail = void 0;
|
|
1112
979
|
execUpdate();
|
|
1113
980
|
break;
|
|
1114
981
|
}
|
|
1115
982
|
case "finish": {
|
|
1116
|
-
finishReason = chunk.payload.
|
|
983
|
+
finishReason = chunk.payload.stepResult.reason;
|
|
1117
984
|
if (chunk.payload.usage != null) {
|
|
1118
985
|
usage = chunk.payload.usage;
|
|
1119
986
|
}
|
|
@@ -1137,9 +1004,28 @@ var Agent = class extends BaseResource {
|
|
|
1137
1004
|
let toolCalls = [];
|
|
1138
1005
|
let messages = [];
|
|
1139
1006
|
const [streamForWritable, streamForProcessing] = response.body.tee();
|
|
1140
|
-
streamForWritable.pipeTo(
|
|
1141
|
-
|
|
1142
|
-
|
|
1007
|
+
streamForWritable.pipeTo(
|
|
1008
|
+
new WritableStream({
|
|
1009
|
+
async write(chunk) {
|
|
1010
|
+
try {
|
|
1011
|
+
const text = new TextDecoder().decode(chunk);
|
|
1012
|
+
if (text.includes("[DONE]")) {
|
|
1013
|
+
return;
|
|
1014
|
+
}
|
|
1015
|
+
} catch {
|
|
1016
|
+
}
|
|
1017
|
+
const writer = writable.getWriter();
|
|
1018
|
+
try {
|
|
1019
|
+
await writer.write(chunk);
|
|
1020
|
+
} finally {
|
|
1021
|
+
writer.releaseLock();
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
}),
|
|
1025
|
+
{
|
|
1026
|
+
preventClose: true
|
|
1027
|
+
}
|
|
1028
|
+
).catch((error) => {
|
|
1143
1029
|
console.error("Error piping to writable stream:", error);
|
|
1144
1030
|
});
|
|
1145
1031
|
this.processChatResponse_vNext({
|
|
@@ -1176,7 +1062,8 @@ var Agent = class extends BaseResource {
|
|
|
1176
1062
|
toolCallId: toolCall2?.toolCallId
|
|
1177
1063
|
}
|
|
1178
1064
|
);
|
|
1179
|
-
const
|
|
1065
|
+
const lastMessageRaw = messages[messages.length - 1];
|
|
1066
|
+
const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
|
|
1180
1067
|
const toolInvocationPart = lastMessage?.parts?.find(
|
|
1181
1068
|
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
1182
1069
|
);
|
|
@@ -1194,25 +1081,13 @@ var Agent = class extends BaseResource {
|
|
|
1194
1081
|
toolInvocation.state = "result";
|
|
1195
1082
|
toolInvocation.result = result;
|
|
1196
1083
|
}
|
|
1197
|
-
const writer = writable.getWriter();
|
|
1198
|
-
try {
|
|
1199
|
-
await writer.write(
|
|
1200
|
-
new TextEncoder().encode(
|
|
1201
|
-
"a:" + JSON.stringify({
|
|
1202
|
-
toolCallId: toolCall2.toolCallId,
|
|
1203
|
-
result
|
|
1204
|
-
}) + "\n"
|
|
1205
|
-
)
|
|
1206
|
-
);
|
|
1207
|
-
} finally {
|
|
1208
|
-
writer.releaseLock();
|
|
1209
|
-
}
|
|
1210
1084
|
const originalMessages = processedParams.messages;
|
|
1211
1085
|
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1086
|
+
const updatedMessages = lastMessage != null ? [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messageArray, ...messages];
|
|
1212
1087
|
this.processStreamResponse_vNext(
|
|
1213
1088
|
{
|
|
1214
1089
|
...processedParams,
|
|
1215
|
-
messages:
|
|
1090
|
+
messages: updatedMessages
|
|
1216
1091
|
},
|
|
1217
1092
|
writable
|
|
1218
1093
|
).catch((error) => {
|
|
@@ -1235,12 +1110,49 @@ var Agent = class extends BaseResource {
|
|
|
1235
1110
|
}
|
|
1236
1111
|
return response;
|
|
1237
1112
|
}
|
|
1238
|
-
async
|
|
1113
|
+
async network(params) {
|
|
1114
|
+
const response = await this.request(`/api/agents/${this.agentId}/network`, {
|
|
1115
|
+
method: "POST",
|
|
1116
|
+
body: params,
|
|
1117
|
+
stream: true
|
|
1118
|
+
});
|
|
1119
|
+
if (!response.body) {
|
|
1120
|
+
throw new Error("No response body");
|
|
1121
|
+
}
|
|
1122
|
+
const streamResponse = new Response(response.body, {
|
|
1123
|
+
status: response.status,
|
|
1124
|
+
statusText: response.statusText,
|
|
1125
|
+
headers: response.headers
|
|
1126
|
+
});
|
|
1127
|
+
streamResponse.processDataStream = async ({
|
|
1128
|
+
onChunk
|
|
1129
|
+
}) => {
|
|
1130
|
+
await processMastraNetworkStream({
|
|
1131
|
+
stream: streamResponse.body,
|
|
1132
|
+
onChunk
|
|
1133
|
+
});
|
|
1134
|
+
};
|
|
1135
|
+
return streamResponse;
|
|
1136
|
+
}
|
|
1137
|
+
async streamVNext(messagesOrParams, options) {
|
|
1138
|
+
let params;
|
|
1139
|
+
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
1140
|
+
params = messagesOrParams;
|
|
1141
|
+
} else {
|
|
1142
|
+
params = {
|
|
1143
|
+
messages: messagesOrParams,
|
|
1144
|
+
...options
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1239
1147
|
const processedParams = {
|
|
1240
1148
|
...params,
|
|
1241
1149
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
1242
1150
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
1243
|
-
clientTools: processClientTools(params.clientTools)
|
|
1151
|
+
clientTools: processClientTools(params.clientTools),
|
|
1152
|
+
structuredOutput: params.structuredOutput ? {
|
|
1153
|
+
...params.structuredOutput,
|
|
1154
|
+
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
1155
|
+
} : void 0
|
|
1244
1156
|
};
|
|
1245
1157
|
const { readable, writable } = new TransformStream();
|
|
1246
1158
|
const response = await this.processStreamResponse_vNext(processedParams, writable);
|
|
@@ -1263,7 +1175,7 @@ var Agent = class extends BaseResource {
|
|
|
1263
1175
|
* Processes the stream response and handles tool calls
|
|
1264
1176
|
*/
|
|
1265
1177
|
async processStreamResponse(processedParams, writable) {
|
|
1266
|
-
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
1178
|
+
const response = await this.request(`/api/agents/${this.agentId}/stream-legacy`, {
|
|
1267
1179
|
method: "POST",
|
|
1268
1180
|
body: processedParams,
|
|
1269
1181
|
stream: true
|
|
@@ -1376,10 +1288,11 @@ var Agent = class extends BaseResource {
|
|
|
1376
1288
|
/**
|
|
1377
1289
|
* Gets details about a specific tool available to the agent
|
|
1378
1290
|
* @param toolId - ID of the tool to retrieve
|
|
1291
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1379
1292
|
* @returns Promise containing tool details
|
|
1380
1293
|
*/
|
|
1381
|
-
getTool(toolId) {
|
|
1382
|
-
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
1294
|
+
getTool(toolId, runtimeContext) {
|
|
1295
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1383
1296
|
}
|
|
1384
1297
|
/**
|
|
1385
1298
|
* Executes a tool for the agent
|
|
@@ -1390,7 +1303,7 @@ var Agent = class extends BaseResource {
|
|
|
1390
1303
|
executeTool(toolId, params) {
|
|
1391
1304
|
const body = {
|
|
1392
1305
|
data: params.data,
|
|
1393
|
-
runtimeContext:
|
|
1306
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1394
1307
|
};
|
|
1395
1308
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
1396
1309
|
method: "POST",
|
|
@@ -1399,17 +1312,19 @@ var Agent = class extends BaseResource {
|
|
|
1399
1312
|
}
|
|
1400
1313
|
/**
|
|
1401
1314
|
* Retrieves evaluation results for the agent
|
|
1315
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1402
1316
|
* @returns Promise containing agent evaluations
|
|
1403
1317
|
*/
|
|
1404
|
-
evals() {
|
|
1405
|
-
return this.request(`/api/agents/${this.agentId}/evals/ci`);
|
|
1318
|
+
evals(runtimeContext) {
|
|
1319
|
+
return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
|
|
1406
1320
|
}
|
|
1407
1321
|
/**
|
|
1408
1322
|
* Retrieves live evaluation results for the agent
|
|
1323
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1409
1324
|
* @returns Promise containing live agent evaluations
|
|
1410
1325
|
*/
|
|
1411
|
-
liveEvals() {
|
|
1412
|
-
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
1326
|
+
liveEvals(runtimeContext) {
|
|
1327
|
+
return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
|
|
1413
1328
|
}
|
|
1414
1329
|
/**
|
|
1415
1330
|
* Updates the model for the agent
|
|
@@ -1423,62 +1338,6 @@ var Agent = class extends BaseResource {
|
|
|
1423
1338
|
});
|
|
1424
1339
|
}
|
|
1425
1340
|
};
|
|
1426
|
-
var Network = class extends BaseResource {
|
|
1427
|
-
constructor(options, networkId) {
|
|
1428
|
-
super(options);
|
|
1429
|
-
this.networkId = networkId;
|
|
1430
|
-
}
|
|
1431
|
-
/**
|
|
1432
|
-
* Retrieves details about the network
|
|
1433
|
-
* @returns Promise containing network details
|
|
1434
|
-
*/
|
|
1435
|
-
details() {
|
|
1436
|
-
return this.request(`/api/networks/${this.networkId}`);
|
|
1437
|
-
}
|
|
1438
|
-
/**
|
|
1439
|
-
* Generates a response from the agent
|
|
1440
|
-
* @param params - Generation parameters including prompt
|
|
1441
|
-
* @returns Promise containing the generated response
|
|
1442
|
-
*/
|
|
1443
|
-
generate(params) {
|
|
1444
|
-
const processedParams = {
|
|
1445
|
-
...params,
|
|
1446
|
-
output: zodToJsonSchema(params.output),
|
|
1447
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1448
|
-
};
|
|
1449
|
-
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
1450
|
-
method: "POST",
|
|
1451
|
-
body: processedParams
|
|
1452
|
-
});
|
|
1453
|
-
}
|
|
1454
|
-
/**
|
|
1455
|
-
* Streams a response from the agent
|
|
1456
|
-
* @param params - Stream parameters including prompt
|
|
1457
|
-
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
1458
|
-
*/
|
|
1459
|
-
async stream(params) {
|
|
1460
|
-
const processedParams = {
|
|
1461
|
-
...params,
|
|
1462
|
-
output: zodToJsonSchema(params.output),
|
|
1463
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1464
|
-
};
|
|
1465
|
-
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
1466
|
-
method: "POST",
|
|
1467
|
-
body: processedParams,
|
|
1468
|
-
stream: true
|
|
1469
|
-
});
|
|
1470
|
-
if (!response.body) {
|
|
1471
|
-
throw new Error("No response body");
|
|
1472
|
-
}
|
|
1473
|
-
response.processDataStream = async (options = {}) => {
|
|
1474
|
-
await uiUtils.processDataStream({
|
|
1475
|
-
stream: response.body,
|
|
1476
|
-
...options
|
|
1477
|
-
});
|
|
1478
|
-
};
|
|
1479
|
-
return response;
|
|
1480
|
-
}
|
|
1481
|
-
};
|
|
1482
1341
|
|
|
1483
1342
|
// src/resources/memory-thread.ts
|
|
1484
1343
|
var MemoryThread = class extends BaseResource {
|
|
@@ -1567,10 +1426,13 @@ var Vector = class extends BaseResource {
|
|
|
1567
1426
|
/**
|
|
1568
1427
|
* Retrieves details about a specific vector index
|
|
1569
1428
|
* @param indexName - Name of the index to get details for
|
|
1429
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1570
1430
|
* @returns Promise containing vector index details
|
|
1571
1431
|
*/
|
|
1572
|
-
details(indexName) {
|
|
1573
|
-
return this.request(
|
|
1432
|
+
details(indexName, runtimeContext) {
|
|
1433
|
+
return this.request(
|
|
1434
|
+
`/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
|
|
1435
|
+
);
|
|
1574
1436
|
}
|
|
1575
1437
|
/**
|
|
1576
1438
|
* Deletes a vector index
|
|
@@ -1584,10 +1446,11 @@ var Vector = class extends BaseResource {
|
|
|
1584
1446
|
}
|
|
1585
1447
|
/**
|
|
1586
1448
|
* Retrieves a list of all available indexes
|
|
1449
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1587
1450
|
* @returns Promise containing array of index names
|
|
1588
1451
|
*/
|
|
1589
|
-
getIndexes() {
|
|
1590
|
-
return this.request(`/api/vector/${this.vectorName}/indexes`);
|
|
1452
|
+
getIndexes(runtimeContext) {
|
|
1453
|
+
return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
|
|
1591
1454
|
}
|
|
1592
1455
|
/**
|
|
1593
1456
|
* Creates a new vector index
|
|
@@ -1633,17 +1496,20 @@ var LegacyWorkflow = class extends BaseResource {
|
|
|
1633
1496
|
}
|
|
1634
1497
|
/**
|
|
1635
1498
|
* Retrieves details about the legacy workflow
|
|
1499
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1636
1500
|
* @returns Promise containing legacy workflow details including steps and graphs
|
|
1637
1501
|
*/
|
|
1638
|
-
details() {
|
|
1639
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}`);
|
|
1502
|
+
details(runtimeContext) {
|
|
1503
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1640
1504
|
}
|
|
1641
1505
|
/**
|
|
1642
1506
|
* Retrieves all runs for a legacy workflow
|
|
1643
1507
|
* @param params - Parameters for filtering runs
|
|
1508
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1644
1509
|
* @returns Promise containing legacy workflow runs array
|
|
1645
1510
|
*/
|
|
1646
|
-
runs(params) {
|
|
1511
|
+
runs(params, runtimeContext) {
|
|
1512
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
1647
1513
|
const searchParams = new URLSearchParams();
|
|
1648
1514
|
if (params?.fromDate) {
|
|
1649
1515
|
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
@@ -1660,6 +1526,9 @@ var LegacyWorkflow = class extends BaseResource {
|
|
|
1660
1526
|
if (params?.resourceId) {
|
|
1661
1527
|
searchParams.set("resourceId", params.resourceId);
|
|
1662
1528
|
}
|
|
1529
|
+
if (runtimeContextParam) {
|
|
1530
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
1531
|
+
}
|
|
1663
1532
|
if (searchParams.size) {
|
|
1664
1533
|
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
1665
1534
|
} else {
|
|
@@ -1813,10 +1682,11 @@ var Tool = class extends BaseResource {
|
|
|
1813
1682
|
}
|
|
1814
1683
|
/**
|
|
1815
1684
|
* Retrieves details about the tool
|
|
1685
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1816
1686
|
* @returns Promise containing tool details including description and schemas
|
|
1817
1687
|
*/
|
|
1818
|
-
details() {
|
|
1819
|
-
return this.request(`/api/tools/${this.toolId}`);
|
|
1688
|
+
details(runtimeContext) {
|
|
1689
|
+
return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1820
1690
|
}
|
|
1821
1691
|
/**
|
|
1822
1692
|
* Executes the tool with the provided parameters
|
|
@@ -1893,17 +1763,20 @@ var Workflow = class extends BaseResource {
|
|
|
1893
1763
|
}
|
|
1894
1764
|
/**
|
|
1895
1765
|
* Retrieves details about the workflow
|
|
1766
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1896
1767
|
* @returns Promise containing workflow details including steps and graphs
|
|
1897
1768
|
*/
|
|
1898
|
-
details() {
|
|
1899
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
1769
|
+
details(runtimeContext) {
|
|
1770
|
+
return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1900
1771
|
}
|
|
1901
1772
|
/**
|
|
1902
1773
|
* Retrieves all runs for a workflow
|
|
1903
1774
|
* @param params - Parameters for filtering runs
|
|
1775
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1904
1776
|
* @returns Promise containing workflow runs array
|
|
1905
1777
|
*/
|
|
1906
|
-
runs(params) {
|
|
1778
|
+
runs(params, runtimeContext) {
|
|
1779
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
1907
1780
|
const searchParams = new URLSearchParams();
|
|
1908
1781
|
if (params?.fromDate) {
|
|
1909
1782
|
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
@@ -1920,6 +1793,9 @@ var Workflow = class extends BaseResource {
|
|
|
1920
1793
|
if (params?.resourceId) {
|
|
1921
1794
|
searchParams.set("resourceId", params.resourceId);
|
|
1922
1795
|
}
|
|
1796
|
+
if (runtimeContextParam) {
|
|
1797
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
1798
|
+
}
|
|
1923
1799
|
if (searchParams.size) {
|
|
1924
1800
|
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
1925
1801
|
} else {
|
|
@@ -1929,18 +1805,22 @@ var Workflow = class extends BaseResource {
|
|
|
1929
1805
|
/**
|
|
1930
1806
|
* Retrieves a specific workflow run by its ID
|
|
1931
1807
|
* @param runId - The ID of the workflow run to retrieve
|
|
1808
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1932
1809
|
* @returns Promise containing the workflow run details
|
|
1933
1810
|
*/
|
|
1934
|
-
runById(runId) {
|
|
1935
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
|
|
1811
|
+
runById(runId, runtimeContext) {
|
|
1812
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1936
1813
|
}
|
|
1937
1814
|
/**
|
|
1938
1815
|
* Retrieves the execution result for a specific workflow run by its ID
|
|
1939
1816
|
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1817
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1940
1818
|
* @returns Promise containing the workflow run execution result
|
|
1941
1819
|
*/
|
|
1942
|
-
runExecutionResult(runId) {
|
|
1943
|
-
return this.request(
|
|
1820
|
+
runExecutionResult(runId, runtimeContext) {
|
|
1821
|
+
return this.request(
|
|
1822
|
+
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
|
|
1823
|
+
);
|
|
1944
1824
|
}
|
|
1945
1825
|
/**
|
|
1946
1826
|
* Cancels a specific workflow run by its ID
|
|
@@ -1963,27 +1843,61 @@ var Workflow = class extends BaseResource {
|
|
|
1963
1843
|
body: { event: params.event, data: params.data }
|
|
1964
1844
|
});
|
|
1965
1845
|
}
|
|
1846
|
+
/**
|
|
1847
|
+
* @deprecated Use createRunAsync() instead.
|
|
1848
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
1849
|
+
*/
|
|
1850
|
+
async createRun(_params) {
|
|
1851
|
+
throw new Error(
|
|
1852
|
+
"createRun() has been deprecated. Please use createRunAsync() instead.\n\nMigration guide:\n Before: const run = workflow.createRun();\n After: const run = await workflow.createRunAsync();\n\nNote: createRunAsync() is an async method, so make sure your calling function is async."
|
|
1853
|
+
);
|
|
1854
|
+
}
|
|
1966
1855
|
/**
|
|
1967
1856
|
* Creates a new workflow run
|
|
1968
1857
|
* @param params - Optional object containing the optional runId
|
|
1969
|
-
* @returns Promise containing the runId of the created run
|
|
1858
|
+
* @returns Promise containing the runId of the created run with methods to control execution
|
|
1970
1859
|
*/
|
|
1971
|
-
|
|
1860
|
+
async createRunAsync(params) {
|
|
1972
1861
|
const searchParams = new URLSearchParams();
|
|
1973
1862
|
if (!!params?.runId) {
|
|
1974
1863
|
searchParams.set("runId", params.runId);
|
|
1975
1864
|
}
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1865
|
+
const res = await this.request(
|
|
1866
|
+
`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
|
|
1867
|
+
{
|
|
1868
|
+
method: "POST"
|
|
1869
|
+
}
|
|
1870
|
+
);
|
|
1871
|
+
const runId = res.runId;
|
|
1872
|
+
return {
|
|
1873
|
+
runId,
|
|
1874
|
+
start: async (p) => {
|
|
1875
|
+
return this.start({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
|
|
1876
|
+
},
|
|
1877
|
+
startAsync: async (p) => {
|
|
1878
|
+
return this.startAsync({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
|
|
1879
|
+
},
|
|
1880
|
+
watch: async (onRecord) => {
|
|
1881
|
+
return this.watch({ runId }, onRecord);
|
|
1882
|
+
},
|
|
1883
|
+
stream: async (p) => {
|
|
1884
|
+
return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
|
|
1885
|
+
},
|
|
1886
|
+
resume: async (p) => {
|
|
1887
|
+
return this.resume({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
|
|
1888
|
+
},
|
|
1889
|
+
resumeAsync: async (p) => {
|
|
1890
|
+
return this.resumeAsync({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
|
|
1891
|
+
},
|
|
1892
|
+
resumeStreamVNext: async (p) => {
|
|
1893
|
+
return this.resumeStreamVNext({
|
|
1894
|
+
runId,
|
|
1895
|
+
step: p.step,
|
|
1896
|
+
resumeData: p.resumeData,
|
|
1897
|
+
runtimeContext: p.runtimeContext
|
|
1898
|
+
});
|
|
1899
|
+
}
|
|
1900
|
+
};
|
|
1987
1901
|
}
|
|
1988
1902
|
/**
|
|
1989
1903
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
@@ -2011,7 +1925,6 @@ var Workflow = class extends BaseResource {
|
|
|
2011
1925
|
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
2012
1926
|
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
2013
1927
|
method: "POST",
|
|
2014
|
-
stream: true,
|
|
2015
1928
|
body: {
|
|
2016
1929
|
step,
|
|
2017
1930
|
resumeData,
|
|
@@ -2055,7 +1968,7 @@ var Workflow = class extends BaseResource {
|
|
|
2055
1968
|
}
|
|
2056
1969
|
);
|
|
2057
1970
|
if (!response.ok) {
|
|
2058
|
-
throw new Error(`Failed to stream
|
|
1971
|
+
throw new Error(`Failed to stream workflow: ${response.statusText}`);
|
|
2059
1972
|
}
|
|
2060
1973
|
if (!response.body) {
|
|
2061
1974
|
throw new Error("Response body is null");
|
|
@@ -2087,57 +2000,171 @@ var Workflow = class extends BaseResource {
|
|
|
2087
2000
|
return response.body.pipeThrough(transformStream);
|
|
2088
2001
|
}
|
|
2089
2002
|
/**
|
|
2090
|
-
*
|
|
2091
|
-
* @param params - Object containing the runId
|
|
2092
|
-
* @returns Promise containing the workflow
|
|
2003
|
+
* Observes workflow stream for a workflow run
|
|
2004
|
+
* @param params - Object containing the runId
|
|
2005
|
+
* @returns Promise containing the workflow execution results
|
|
2093
2006
|
*/
|
|
2094
|
-
|
|
2095
|
-
const
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2007
|
+
async observeStream(params) {
|
|
2008
|
+
const searchParams = new URLSearchParams();
|
|
2009
|
+
searchParams.set("runId", params.runId);
|
|
2010
|
+
const response = await this.request(
|
|
2011
|
+
`/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
|
|
2012
|
+
{
|
|
2013
|
+
method: "POST",
|
|
2014
|
+
stream: true
|
|
2102
2015
|
}
|
|
2103
|
-
|
|
2104
|
-
}
|
|
2105
|
-
/**
|
|
2106
|
-
* Watches workflow transitions in real-time
|
|
2107
|
-
* @param runId - Optional run ID to filter the watch stream
|
|
2108
|
-
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
2109
|
-
*/
|
|
2110
|
-
async watch({ runId }, onRecord) {
|
|
2111
|
-
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
2112
|
-
stream: true
|
|
2113
|
-
});
|
|
2016
|
+
);
|
|
2114
2017
|
if (!response.ok) {
|
|
2115
|
-
throw new Error(`Failed to
|
|
2018
|
+
throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
|
|
2116
2019
|
}
|
|
2117
2020
|
if (!response.body) {
|
|
2118
2021
|
throw new Error("Response body is null");
|
|
2119
2022
|
}
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
}
|
|
2124
|
-
|
|
2125
|
-
}
|
|
2126
|
-
}
|
|
2127
|
-
}
|
|
2128
|
-
/**
|
|
2129
|
-
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
2130
|
-
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
2131
|
-
*
|
|
2132
|
-
* @param records - An iterable or async iterable of objects to stream
|
|
2133
|
-
* @returns A ReadableStream emitting the records as JSON strings separated by the record separator
|
|
2134
|
-
*/
|
|
2135
|
-
static createRecordStream(records) {
|
|
2136
|
-
const encoder = new TextEncoder();
|
|
2137
|
-
return new ReadableStream({
|
|
2138
|
-
async start(controller) {
|
|
2023
|
+
let failedChunk = void 0;
|
|
2024
|
+
const transformStream = new TransformStream({
|
|
2025
|
+
start() {
|
|
2026
|
+
},
|
|
2027
|
+
async transform(chunk, controller) {
|
|
2139
2028
|
try {
|
|
2140
|
-
|
|
2029
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2030
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2031
|
+
for (const chunk2 of chunks) {
|
|
2032
|
+
if (chunk2) {
|
|
2033
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2034
|
+
try {
|
|
2035
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2036
|
+
controller.enqueue(parsedChunk);
|
|
2037
|
+
failedChunk = void 0;
|
|
2038
|
+
} catch {
|
|
2039
|
+
failedChunk = newChunk;
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
} catch {
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
});
|
|
2047
|
+
return response.body.pipeThrough(transformStream);
|
|
2048
|
+
}
|
|
2049
|
+
/**
|
|
2050
|
+
* Starts a workflow run and returns a stream
|
|
2051
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
2052
|
+
* @returns Promise containing the workflow execution results
|
|
2053
|
+
*/
|
|
2054
|
+
async streamVNext(params) {
|
|
2055
|
+
const searchParams = new URLSearchParams();
|
|
2056
|
+
if (!!params?.runId) {
|
|
2057
|
+
searchParams.set("runId", params.runId);
|
|
2058
|
+
}
|
|
2059
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2060
|
+
const response = await this.request(
|
|
2061
|
+
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
2062
|
+
{
|
|
2063
|
+
method: "POST",
|
|
2064
|
+
body: { inputData: params.inputData, runtimeContext, closeOnSuspend: params.closeOnSuspend },
|
|
2065
|
+
stream: true
|
|
2066
|
+
}
|
|
2067
|
+
);
|
|
2068
|
+
if (!response.ok) {
|
|
2069
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
2070
|
+
}
|
|
2071
|
+
if (!response.body) {
|
|
2072
|
+
throw new Error("Response body is null");
|
|
2073
|
+
}
|
|
2074
|
+
let failedChunk = void 0;
|
|
2075
|
+
const transformStream = new TransformStream({
|
|
2076
|
+
start() {
|
|
2077
|
+
},
|
|
2078
|
+
async transform(chunk, controller) {
|
|
2079
|
+
try {
|
|
2080
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2081
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2082
|
+
for (const chunk2 of chunks) {
|
|
2083
|
+
if (chunk2) {
|
|
2084
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2085
|
+
try {
|
|
2086
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2087
|
+
controller.enqueue(parsedChunk);
|
|
2088
|
+
failedChunk = void 0;
|
|
2089
|
+
} catch {
|
|
2090
|
+
failedChunk = newChunk;
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
} catch {
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
});
|
|
2098
|
+
return response.body.pipeThrough(transformStream);
|
|
2099
|
+
}
|
|
2100
|
+
/**
|
|
2101
|
+
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
2102
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
2103
|
+
* @returns Promise containing the workflow resume results
|
|
2104
|
+
*/
|
|
2105
|
+
resumeAsync(params) {
|
|
2106
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2107
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
2108
|
+
method: "POST",
|
|
2109
|
+
body: {
|
|
2110
|
+
step: params.step,
|
|
2111
|
+
resumeData: params.resumeData,
|
|
2112
|
+
runtimeContext
|
|
2113
|
+
}
|
|
2114
|
+
});
|
|
2115
|
+
}
|
|
2116
|
+
/**
|
|
2117
|
+
* Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
|
|
2118
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
2119
|
+
* @returns Promise containing the workflow resume results
|
|
2120
|
+
*/
|
|
2121
|
+
resumeStreamVNext(params) {
|
|
2122
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2123
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-stream?runId=${params.runId}`, {
|
|
2124
|
+
method: "POST",
|
|
2125
|
+
body: {
|
|
2126
|
+
step: params.step,
|
|
2127
|
+
resumeData: params.resumeData,
|
|
2128
|
+
runtimeContext
|
|
2129
|
+
}
|
|
2130
|
+
});
|
|
2131
|
+
}
|
|
2132
|
+
/**
|
|
2133
|
+
* Watches workflow transitions in real-time
|
|
2134
|
+
* @param runId - Optional run ID to filter the watch stream
|
|
2135
|
+
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
2136
|
+
*/
|
|
2137
|
+
async watch({ runId }, onRecord) {
|
|
2138
|
+
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
2139
|
+
stream: true
|
|
2140
|
+
});
|
|
2141
|
+
if (!response.ok) {
|
|
2142
|
+
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
2143
|
+
}
|
|
2144
|
+
if (!response.body) {
|
|
2145
|
+
throw new Error("Response body is null");
|
|
2146
|
+
}
|
|
2147
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
2148
|
+
if (typeof record === "string") {
|
|
2149
|
+
onRecord(JSON.parse(record));
|
|
2150
|
+
} else {
|
|
2151
|
+
onRecord(record);
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
/**
|
|
2156
|
+
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
2157
|
+
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
2158
|
+
*
|
|
2159
|
+
* @param records - An iterable or async iterable of objects to stream
|
|
2160
|
+
* @returns A ReadableStream emitting the records as JSON strings separated by the record separator
|
|
2161
|
+
*/
|
|
2162
|
+
static createRecordStream(records) {
|
|
2163
|
+
const encoder = new TextEncoder();
|
|
2164
|
+
return new ReadableStream({
|
|
2165
|
+
async start(controller) {
|
|
2166
|
+
try {
|
|
2167
|
+
for await (const record of records) {
|
|
2141
2168
|
const json = JSON.stringify(record) + RECORD_SEPARATOR2;
|
|
2142
2169
|
controller.enqueue(encoder.encode(json));
|
|
2143
2170
|
}
|
|
@@ -2236,10 +2263,11 @@ var MCPTool = class extends BaseResource {
|
|
|
2236
2263
|
}
|
|
2237
2264
|
/**
|
|
2238
2265
|
* Retrieves details about this specific tool from the MCP server.
|
|
2266
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2239
2267
|
* @returns Promise containing the tool's information (name, description, schema).
|
|
2240
2268
|
*/
|
|
2241
|
-
details() {
|
|
2242
|
-
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
2269
|
+
details(runtimeContext) {
|
|
2270
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
2243
2271
|
}
|
|
2244
2272
|
/**
|
|
2245
2273
|
* Executes this specific tool on the MCP server.
|
|
@@ -2259,6 +2287,375 @@ var MCPTool = class extends BaseResource {
|
|
|
2259
2287
|
}
|
|
2260
2288
|
};
|
|
2261
2289
|
|
|
2290
|
+
// src/resources/agent-builder.ts
|
|
2291
|
+
var RECORD_SEPARATOR3 = "";
|
|
2292
|
+
var AgentBuilder = class extends BaseResource {
|
|
2293
|
+
constructor(options, actionId) {
|
|
2294
|
+
super(options);
|
|
2295
|
+
this.actionId = actionId;
|
|
2296
|
+
}
|
|
2297
|
+
// Helper function to transform workflow result to action result
|
|
2298
|
+
transformWorkflowResult(result) {
|
|
2299
|
+
if (result.status === "success") {
|
|
2300
|
+
return {
|
|
2301
|
+
success: result.result.success || false,
|
|
2302
|
+
applied: result.result.applied || false,
|
|
2303
|
+
branchName: result.result.branchName,
|
|
2304
|
+
message: result.result.message || "Agent builder action completed",
|
|
2305
|
+
validationResults: result.result.validationResults,
|
|
2306
|
+
error: result.result.error,
|
|
2307
|
+
errors: result.result.errors,
|
|
2308
|
+
stepResults: result.result.stepResults
|
|
2309
|
+
};
|
|
2310
|
+
} else if (result.status === "failed") {
|
|
2311
|
+
return {
|
|
2312
|
+
success: false,
|
|
2313
|
+
applied: false,
|
|
2314
|
+
message: `Agent builder action failed: ${result.error.message}`,
|
|
2315
|
+
error: result.error.message
|
|
2316
|
+
};
|
|
2317
|
+
} else {
|
|
2318
|
+
return {
|
|
2319
|
+
success: false,
|
|
2320
|
+
applied: false,
|
|
2321
|
+
message: "Agent builder action was suspended",
|
|
2322
|
+
error: "Workflow suspended - manual intervention required"
|
|
2323
|
+
};
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
/**
|
|
2327
|
+
* @deprecated Use createRunAsync() instead.
|
|
2328
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
2329
|
+
*/
|
|
2330
|
+
async createRun(_params) {
|
|
2331
|
+
throw new Error(
|
|
2332
|
+
"createRun() has been deprecated. Please use createRunAsync() instead.\n\nMigration guide:\n Before: const run = agentBuilder.createRun();\n After: const run = await agentBuilder.createRunAsync();\n\nNote: createRunAsync() is an async method, so make sure your calling function is async."
|
|
2333
|
+
);
|
|
2334
|
+
}
|
|
2335
|
+
/**
|
|
2336
|
+
* Creates a new agent builder action run and returns the runId.
|
|
2337
|
+
* This calls `/api/agent-builder/:actionId/create-run`.
|
|
2338
|
+
*/
|
|
2339
|
+
async createRunAsync(params) {
|
|
2340
|
+
const searchParams = new URLSearchParams();
|
|
2341
|
+
if (!!params?.runId) {
|
|
2342
|
+
searchParams.set("runId", params.runId);
|
|
2343
|
+
}
|
|
2344
|
+
const url = `/api/agent-builder/${this.actionId}/create-run${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2345
|
+
return this.request(url, {
|
|
2346
|
+
method: "POST"
|
|
2347
|
+
});
|
|
2348
|
+
}
|
|
2349
|
+
/**
|
|
2350
|
+
* Starts agent builder action asynchronously and waits for completion.
|
|
2351
|
+
* This calls `/api/agent-builder/:actionId/start-async`.
|
|
2352
|
+
*/
|
|
2353
|
+
async startAsync(params, runId) {
|
|
2354
|
+
const searchParams = new URLSearchParams();
|
|
2355
|
+
if (runId) {
|
|
2356
|
+
searchParams.set("runId", runId);
|
|
2357
|
+
}
|
|
2358
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2359
|
+
const { runtimeContext: _, ...actionParams } = params;
|
|
2360
|
+
const url = `/api/agent-builder/${this.actionId}/start-async${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2361
|
+
const result = await this.request(url, {
|
|
2362
|
+
method: "POST",
|
|
2363
|
+
body: { ...actionParams, runtimeContext }
|
|
2364
|
+
});
|
|
2365
|
+
return this.transformWorkflowResult(result);
|
|
2366
|
+
}
|
|
2367
|
+
/**
|
|
2368
|
+
* Starts an existing agent builder action run.
|
|
2369
|
+
* This calls `/api/agent-builder/:actionId/start`.
|
|
2370
|
+
*/
|
|
2371
|
+
async startActionRun(params, runId) {
|
|
2372
|
+
const searchParams = new URLSearchParams();
|
|
2373
|
+
searchParams.set("runId", runId);
|
|
2374
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2375
|
+
const { runtimeContext: _, ...actionParams } = params;
|
|
2376
|
+
const url = `/api/agent-builder/${this.actionId}/start?${searchParams.toString()}`;
|
|
2377
|
+
return this.request(url, {
|
|
2378
|
+
method: "POST",
|
|
2379
|
+
body: { ...actionParams, runtimeContext }
|
|
2380
|
+
});
|
|
2381
|
+
}
|
|
2382
|
+
/**
|
|
2383
|
+
* Resumes a suspended agent builder action step.
|
|
2384
|
+
* This calls `/api/agent-builder/:actionId/resume`.
|
|
2385
|
+
*/
|
|
2386
|
+
async resume(params, runId) {
|
|
2387
|
+
const searchParams = new URLSearchParams();
|
|
2388
|
+
searchParams.set("runId", runId);
|
|
2389
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2390
|
+
const { runtimeContext: _, ...resumeParams } = params;
|
|
2391
|
+
const url = `/api/agent-builder/${this.actionId}/resume?${searchParams.toString()}`;
|
|
2392
|
+
return this.request(url, {
|
|
2393
|
+
method: "POST",
|
|
2394
|
+
body: { ...resumeParams, runtimeContext }
|
|
2395
|
+
});
|
|
2396
|
+
}
|
|
2397
|
+
/**
|
|
2398
|
+
* Resumes a suspended agent builder action step asynchronously.
|
|
2399
|
+
* This calls `/api/agent-builder/:actionId/resume-async`.
|
|
2400
|
+
*/
|
|
2401
|
+
async resumeAsync(params, runId) {
|
|
2402
|
+
const searchParams = new URLSearchParams();
|
|
2403
|
+
searchParams.set("runId", runId);
|
|
2404
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2405
|
+
const { runtimeContext: _, ...resumeParams } = params;
|
|
2406
|
+
const url = `/api/agent-builder/${this.actionId}/resume-async?${searchParams.toString()}`;
|
|
2407
|
+
const result = await this.request(url, {
|
|
2408
|
+
method: "POST",
|
|
2409
|
+
body: { ...resumeParams, runtimeContext }
|
|
2410
|
+
});
|
|
2411
|
+
return this.transformWorkflowResult(result);
|
|
2412
|
+
}
|
|
2413
|
+
/**
|
|
2414
|
+
* Creates an async generator that processes a readable stream and yields action records
|
|
2415
|
+
* separated by the Record Separator character (\x1E)
|
|
2416
|
+
*
|
|
2417
|
+
* @param stream - The readable stream to process
|
|
2418
|
+
* @returns An async generator that yields parsed records
|
|
2419
|
+
*/
|
|
2420
|
+
async *streamProcessor(stream) {
|
|
2421
|
+
const reader = stream.getReader();
|
|
2422
|
+
let doneReading = false;
|
|
2423
|
+
let buffer = "";
|
|
2424
|
+
try {
|
|
2425
|
+
while (!doneReading) {
|
|
2426
|
+
const { done, value } = await reader.read();
|
|
2427
|
+
doneReading = done;
|
|
2428
|
+
if (done && !value) continue;
|
|
2429
|
+
try {
|
|
2430
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2431
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
2432
|
+
buffer = chunks.pop() || "";
|
|
2433
|
+
for (const chunk of chunks) {
|
|
2434
|
+
if (chunk) {
|
|
2435
|
+
if (typeof chunk === "string") {
|
|
2436
|
+
try {
|
|
2437
|
+
const parsedChunk = JSON.parse(chunk);
|
|
2438
|
+
yield parsedChunk;
|
|
2439
|
+
} catch {
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
} catch {
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
if (buffer) {
|
|
2448
|
+
try {
|
|
2449
|
+
yield JSON.parse(buffer);
|
|
2450
|
+
} catch {
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
} finally {
|
|
2454
|
+
reader.cancel().catch(() => {
|
|
2455
|
+
});
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
/**
|
|
2459
|
+
* Streams agent builder action progress in real-time.
|
|
2460
|
+
* This calls `/api/agent-builder/:actionId/stream`.
|
|
2461
|
+
*/
|
|
2462
|
+
async stream(params, runId) {
|
|
2463
|
+
const searchParams = new URLSearchParams();
|
|
2464
|
+
if (runId) {
|
|
2465
|
+
searchParams.set("runId", runId);
|
|
2466
|
+
}
|
|
2467
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2468
|
+
const { runtimeContext: _, ...actionParams } = params;
|
|
2469
|
+
const url = `/api/agent-builder/${this.actionId}/stream${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2470
|
+
const response = await this.request(url, {
|
|
2471
|
+
method: "POST",
|
|
2472
|
+
body: { ...actionParams, runtimeContext },
|
|
2473
|
+
stream: true
|
|
2474
|
+
});
|
|
2475
|
+
if (!response.ok) {
|
|
2476
|
+
throw new Error(`Failed to stream agent builder action: ${response.statusText}`);
|
|
2477
|
+
}
|
|
2478
|
+
if (!response.body) {
|
|
2479
|
+
throw new Error("Response body is null");
|
|
2480
|
+
}
|
|
2481
|
+
let failedChunk = void 0;
|
|
2482
|
+
const transformStream = new TransformStream({
|
|
2483
|
+
start() {
|
|
2484
|
+
},
|
|
2485
|
+
async transform(chunk, controller) {
|
|
2486
|
+
try {
|
|
2487
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2488
|
+
const chunks = decoded.split(RECORD_SEPARATOR3);
|
|
2489
|
+
for (const chunk2 of chunks) {
|
|
2490
|
+
if (chunk2) {
|
|
2491
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2492
|
+
try {
|
|
2493
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2494
|
+
controller.enqueue(parsedChunk);
|
|
2495
|
+
failedChunk = void 0;
|
|
2496
|
+
} catch {
|
|
2497
|
+
failedChunk = newChunk;
|
|
2498
|
+
}
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2501
|
+
} catch {
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
});
|
|
2505
|
+
return response.body.pipeThrough(transformStream);
|
|
2506
|
+
}
|
|
2507
|
+
/**
|
|
2508
|
+
* Streams agent builder action progress in real-time using VNext streaming.
|
|
2509
|
+
* This calls `/api/agent-builder/:actionId/streamVNext`.
|
|
2510
|
+
*/
|
|
2511
|
+
async streamVNext(params, runId) {
|
|
2512
|
+
const searchParams = new URLSearchParams();
|
|
2513
|
+
if (runId) {
|
|
2514
|
+
searchParams.set("runId", runId);
|
|
2515
|
+
}
|
|
2516
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2517
|
+
const { runtimeContext: _, ...actionParams } = params;
|
|
2518
|
+
const url = `/api/agent-builder/${this.actionId}/streamVNext${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2519
|
+
const response = await this.request(url, {
|
|
2520
|
+
method: "POST",
|
|
2521
|
+
body: { ...actionParams, runtimeContext },
|
|
2522
|
+
stream: true
|
|
2523
|
+
});
|
|
2524
|
+
if (!response.ok) {
|
|
2525
|
+
throw new Error(`Failed to stream agent builder action VNext: ${response.statusText}`);
|
|
2526
|
+
}
|
|
2527
|
+
if (!response.body) {
|
|
2528
|
+
throw new Error("Response body is null");
|
|
2529
|
+
}
|
|
2530
|
+
let failedChunk = void 0;
|
|
2531
|
+
const transformStream = new TransformStream({
|
|
2532
|
+
start() {
|
|
2533
|
+
},
|
|
2534
|
+
async transform(chunk, controller) {
|
|
2535
|
+
try {
|
|
2536
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2537
|
+
const chunks = decoded.split(RECORD_SEPARATOR3);
|
|
2538
|
+
for (const chunk2 of chunks) {
|
|
2539
|
+
if (chunk2) {
|
|
2540
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2541
|
+
try {
|
|
2542
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2543
|
+
controller.enqueue(parsedChunk);
|
|
2544
|
+
failedChunk = void 0;
|
|
2545
|
+
} catch {
|
|
2546
|
+
failedChunk = newChunk;
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
} catch {
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
});
|
|
2554
|
+
return response.body.pipeThrough(transformStream);
|
|
2555
|
+
}
|
|
2556
|
+
/**
|
|
2557
|
+
* Watches an existing agent builder action run by runId.
|
|
2558
|
+
* This is used for hot reload recovery - it loads the existing run state
|
|
2559
|
+
* and streams any remaining progress.
|
|
2560
|
+
* This calls `/api/agent-builder/:actionId/watch`.
|
|
2561
|
+
*/
|
|
2562
|
+
async watch({ runId, eventType }, onRecord) {
|
|
2563
|
+
const url = `/api/agent-builder/${this.actionId}/watch?runId=${runId}${eventType ? `&eventType=${eventType}` : ""}`;
|
|
2564
|
+
const response = await this.request(url, {
|
|
2565
|
+
method: "GET",
|
|
2566
|
+
stream: true
|
|
2567
|
+
});
|
|
2568
|
+
if (!response.ok) {
|
|
2569
|
+
throw new Error(`Failed to watch agent builder action: ${response.statusText}`);
|
|
2570
|
+
}
|
|
2571
|
+
if (!response.body) {
|
|
2572
|
+
throw new Error("Response body is null");
|
|
2573
|
+
}
|
|
2574
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
2575
|
+
if (typeof record === "string") {
|
|
2576
|
+
onRecord(JSON.parse(record));
|
|
2577
|
+
} else {
|
|
2578
|
+
onRecord(record);
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
/**
|
|
2583
|
+
* Gets a specific action run by its ID.
|
|
2584
|
+
* This calls `/api/agent-builder/:actionId/runs/:runId`.
|
|
2585
|
+
*/
|
|
2586
|
+
async runById(runId) {
|
|
2587
|
+
const url = `/api/agent-builder/${this.actionId}/runs/${runId}`;
|
|
2588
|
+
return this.request(url, {
|
|
2589
|
+
method: "GET"
|
|
2590
|
+
});
|
|
2591
|
+
}
|
|
2592
|
+
/**
|
|
2593
|
+
* Gets details about this agent builder action.
|
|
2594
|
+
* This calls `/api/agent-builder/:actionId`.
|
|
2595
|
+
*/
|
|
2596
|
+
async details() {
|
|
2597
|
+
const result = await this.request(`/api/agent-builder/${this.actionId}`);
|
|
2598
|
+
return result;
|
|
2599
|
+
}
|
|
2600
|
+
/**
|
|
2601
|
+
* Gets all runs for this agent builder action.
|
|
2602
|
+
* This calls `/api/agent-builder/:actionId/runs`.
|
|
2603
|
+
*/
|
|
2604
|
+
async runs(params) {
|
|
2605
|
+
const searchParams = new URLSearchParams();
|
|
2606
|
+
if (params?.fromDate) {
|
|
2607
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
2608
|
+
}
|
|
2609
|
+
if (params?.toDate) {
|
|
2610
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
2611
|
+
}
|
|
2612
|
+
if (params?.limit !== void 0) {
|
|
2613
|
+
searchParams.set("limit", String(params.limit));
|
|
2614
|
+
}
|
|
2615
|
+
if (params?.offset !== void 0) {
|
|
2616
|
+
searchParams.set("offset", String(params.offset));
|
|
2617
|
+
}
|
|
2618
|
+
if (params?.resourceId) {
|
|
2619
|
+
searchParams.set("resourceId", params.resourceId);
|
|
2620
|
+
}
|
|
2621
|
+
const url = `/api/agent-builder/${this.actionId}/runs${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2622
|
+
return this.request(url, {
|
|
2623
|
+
method: "GET"
|
|
2624
|
+
});
|
|
2625
|
+
}
|
|
2626
|
+
/**
|
|
2627
|
+
* Gets the execution result of an agent builder action run.
|
|
2628
|
+
* This calls `/api/agent-builder/:actionId/runs/:runId/execution-result`.
|
|
2629
|
+
*/
|
|
2630
|
+
async runExecutionResult(runId) {
|
|
2631
|
+
const url = `/api/agent-builder/${this.actionId}/runs/${runId}/execution-result`;
|
|
2632
|
+
return this.request(url, {
|
|
2633
|
+
method: "GET"
|
|
2634
|
+
});
|
|
2635
|
+
}
|
|
2636
|
+
/**
|
|
2637
|
+
* Cancels an agent builder action run.
|
|
2638
|
+
* This calls `/api/agent-builder/:actionId/runs/:runId/cancel`.
|
|
2639
|
+
*/
|
|
2640
|
+
async cancelRun(runId) {
|
|
2641
|
+
const url = `/api/agent-builder/${this.actionId}/runs/${runId}/cancel`;
|
|
2642
|
+
return this.request(url, {
|
|
2643
|
+
method: "POST"
|
|
2644
|
+
});
|
|
2645
|
+
}
|
|
2646
|
+
/**
|
|
2647
|
+
* Sends an event to an agent builder action run.
|
|
2648
|
+
* This calls `/api/agent-builder/:actionId/runs/:runId/send-event`.
|
|
2649
|
+
*/
|
|
2650
|
+
async sendRunEvent(params) {
|
|
2651
|
+
const url = `/api/agent-builder/${this.actionId}/runs/${params.runId}/send-event`;
|
|
2652
|
+
return this.request(url, {
|
|
2653
|
+
method: "POST",
|
|
2654
|
+
body: { event: params.event, data: params.data }
|
|
2655
|
+
});
|
|
2656
|
+
}
|
|
2657
|
+
};
|
|
2658
|
+
|
|
2262
2659
|
// src/resources/observability.ts
|
|
2263
2660
|
var Observability = class extends BaseResource {
|
|
2264
2661
|
constructor(options) {
|
|
@@ -2280,7 +2677,7 @@ var Observability = class extends BaseResource {
|
|
|
2280
2677
|
getTraces(params) {
|
|
2281
2678
|
const { pagination, filters } = params;
|
|
2282
2679
|
const { page, perPage, dateRange } = pagination || {};
|
|
2283
|
-
const { name, spanType } = filters || {};
|
|
2680
|
+
const { name, spanType, entityId, entityType } = filters || {};
|
|
2284
2681
|
const searchParams = new URLSearchParams();
|
|
2285
2682
|
if (page !== void 0) {
|
|
2286
2683
|
searchParams.set("page", String(page));
|
|
@@ -2294,6 +2691,10 @@ var Observability = class extends BaseResource {
|
|
|
2294
2691
|
if (spanType !== void 0) {
|
|
2295
2692
|
searchParams.set("spanType", String(spanType));
|
|
2296
2693
|
}
|
|
2694
|
+
if (entityId && entityType) {
|
|
2695
|
+
searchParams.set("entityId", entityId);
|
|
2696
|
+
searchParams.set("entityType", entityType);
|
|
2697
|
+
}
|
|
2297
2698
|
if (dateRange) {
|
|
2298
2699
|
const dateRangeStr = JSON.stringify({
|
|
2299
2700
|
start: dateRange.start instanceof Date ? dateRange.start.toISOString() : dateRange.start,
|
|
@@ -2370,7 +2771,7 @@ var NetworkMemoryThread = class extends BaseResource {
|
|
|
2370
2771
|
};
|
|
2371
2772
|
|
|
2372
2773
|
// src/resources/vNextNetwork.ts
|
|
2373
|
-
var
|
|
2774
|
+
var RECORD_SEPARATOR4 = "";
|
|
2374
2775
|
var VNextNetwork = class extends BaseResource {
|
|
2375
2776
|
constructor(options, networkId) {
|
|
2376
2777
|
super(options);
|
|
@@ -2378,10 +2779,11 @@ var VNextNetwork = class extends BaseResource {
|
|
|
2378
2779
|
}
|
|
2379
2780
|
/**
|
|
2380
2781
|
* Retrieves details about the network
|
|
2782
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2381
2783
|
* @returns Promise containing vNext network details
|
|
2382
2784
|
*/
|
|
2383
|
-
details() {
|
|
2384
|
-
return this.request(`/api/networks/v-next/${this.networkId}`);
|
|
2785
|
+
details(runtimeContext) {
|
|
2786
|
+
return this.request(`/api/networks/v-next/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
|
|
2385
2787
|
}
|
|
2386
2788
|
/**
|
|
2387
2789
|
* Generates a response from the v-next network
|
|
@@ -2422,7 +2824,7 @@ var VNextNetwork = class extends BaseResource {
|
|
|
2422
2824
|
if (done && !value) continue;
|
|
2423
2825
|
try {
|
|
2424
2826
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2425
|
-
const chunks = (buffer + decoded).split(
|
|
2827
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR4);
|
|
2426
2828
|
buffer = chunks.pop() || "";
|
|
2427
2829
|
for (const chunk of chunks) {
|
|
2428
2830
|
if (chunk) {
|
|
@@ -2516,25 +2918,17 @@ var MastraClient = class extends BaseResource {
|
|
|
2516
2918
|
}
|
|
2517
2919
|
/**
|
|
2518
2920
|
* Retrieves all available agents
|
|
2921
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2519
2922
|
* @returns Promise containing map of agent IDs to agent details
|
|
2520
2923
|
*/
|
|
2521
|
-
getAgents() {
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
acc[agentId] = new AGUIAdapter({
|
|
2530
|
-
agentId,
|
|
2531
|
-
agent,
|
|
2532
|
-
resourceId
|
|
2533
|
-
});
|
|
2534
|
-
return acc;
|
|
2535
|
-
},
|
|
2536
|
-
{}
|
|
2537
|
-
);
|
|
2924
|
+
getAgents(runtimeContext) {
|
|
2925
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2926
|
+
const searchParams = new URLSearchParams();
|
|
2927
|
+
if (runtimeContextParam) {
|
|
2928
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2929
|
+
}
|
|
2930
|
+
const queryString = searchParams.toString();
|
|
2931
|
+
return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
|
|
2538
2932
|
}
|
|
2539
2933
|
/**
|
|
2540
2934
|
* Gets an agent instance by ID
|
|
@@ -2552,6 +2946,14 @@ var MastraClient = class extends BaseResource {
|
|
|
2552
2946
|
getMemoryThreads(params) {
|
|
2553
2947
|
return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
|
|
2554
2948
|
}
|
|
2949
|
+
/**
|
|
2950
|
+
* Retrieves memory config for a resource
|
|
2951
|
+
* @param params - Parameters containing the resource ID
|
|
2952
|
+
* @returns Promise containing array of memory threads
|
|
2953
|
+
*/
|
|
2954
|
+
getMemoryConfig(params) {
|
|
2955
|
+
return this.request(`/api/memory/config?agentId=${params.agentId}`);
|
|
2956
|
+
}
|
|
2555
2957
|
/**
|
|
2556
2958
|
* Creates a new memory thread
|
|
2557
2959
|
* @param params - Parameters for creating the memory thread
|
|
@@ -2568,6 +2970,24 @@ var MastraClient = class extends BaseResource {
|
|
|
2568
2970
|
getMemoryThread(threadId, agentId) {
|
|
2569
2971
|
return new MemoryThread(this.options, threadId, agentId);
|
|
2570
2972
|
}
|
|
2973
|
+
getThreadMessages(threadId, opts = {}) {
|
|
2974
|
+
let url = "";
|
|
2975
|
+
if (opts.agentId) {
|
|
2976
|
+
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
|
|
2977
|
+
} else if (opts.networkId) {
|
|
2978
|
+
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
|
|
2979
|
+
}
|
|
2980
|
+
return this.request(url);
|
|
2981
|
+
}
|
|
2982
|
+
deleteThread(threadId, opts = {}) {
|
|
2983
|
+
let url = "";
|
|
2984
|
+
if (opts.agentId) {
|
|
2985
|
+
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
|
|
2986
|
+
} else if (opts.networkId) {
|
|
2987
|
+
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
|
|
2988
|
+
}
|
|
2989
|
+
return this.request(url, { method: "DELETE" });
|
|
2990
|
+
}
|
|
2571
2991
|
/**
|
|
2572
2992
|
* Saves messages to memory
|
|
2573
2993
|
* @param params - Parameters containing messages to save
|
|
@@ -2630,10 +3050,17 @@ var MastraClient = class extends BaseResource {
|
|
|
2630
3050
|
}
|
|
2631
3051
|
/**
|
|
2632
3052
|
* Retrieves all available tools
|
|
3053
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2633
3054
|
* @returns Promise containing map of tool IDs to tool details
|
|
2634
3055
|
*/
|
|
2635
|
-
getTools() {
|
|
2636
|
-
|
|
3056
|
+
getTools(runtimeContext) {
|
|
3057
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
3058
|
+
const searchParams = new URLSearchParams();
|
|
3059
|
+
if (runtimeContextParam) {
|
|
3060
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
3061
|
+
}
|
|
3062
|
+
const queryString = searchParams.toString();
|
|
3063
|
+
return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
|
|
2637
3064
|
}
|
|
2638
3065
|
/**
|
|
2639
3066
|
* Gets a tool instance by ID
|
|
@@ -2660,10 +3087,17 @@ var MastraClient = class extends BaseResource {
|
|
|
2660
3087
|
}
|
|
2661
3088
|
/**
|
|
2662
3089
|
* Retrieves all available workflows
|
|
3090
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2663
3091
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
2664
3092
|
*/
|
|
2665
|
-
getWorkflows() {
|
|
2666
|
-
|
|
3093
|
+
getWorkflows(runtimeContext) {
|
|
3094
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
3095
|
+
const searchParams = new URLSearchParams();
|
|
3096
|
+
if (runtimeContextParam) {
|
|
3097
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
3098
|
+
}
|
|
3099
|
+
const queryString = searchParams.toString();
|
|
3100
|
+
return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
|
|
2667
3101
|
}
|
|
2668
3102
|
/**
|
|
2669
3103
|
* Gets a workflow instance by ID
|
|
@@ -2673,6 +3107,20 @@ var MastraClient = class extends BaseResource {
|
|
|
2673
3107
|
getWorkflow(workflowId) {
|
|
2674
3108
|
return new Workflow(this.options, workflowId);
|
|
2675
3109
|
}
|
|
3110
|
+
/**
|
|
3111
|
+
* Gets all available agent builder actions
|
|
3112
|
+
* @returns Promise containing map of action IDs to action details
|
|
3113
|
+
*/
|
|
3114
|
+
getAgentBuilderActions() {
|
|
3115
|
+
return this.request("/api/agent-builder/");
|
|
3116
|
+
}
|
|
3117
|
+
/**
|
|
3118
|
+
* Gets an agent builder instance for executing agent-builder workflows
|
|
3119
|
+
* @returns AgentBuilder instance
|
|
3120
|
+
*/
|
|
3121
|
+
getAgentBuilderAction(actionId) {
|
|
3122
|
+
return new AgentBuilder(this.options, actionId);
|
|
3123
|
+
}
|
|
2676
3124
|
/**
|
|
2677
3125
|
* Gets a vector instance by name
|
|
2678
3126
|
* @param vectorName - Name of the vector to retrieve
|
|
@@ -2817,13 +3265,6 @@ var MastraClient = class extends BaseResource {
|
|
|
2817
3265
|
return this.request(`/api/telemetry`);
|
|
2818
3266
|
}
|
|
2819
3267
|
}
|
|
2820
|
-
/**
|
|
2821
|
-
* Retrieves all available networks
|
|
2822
|
-
* @returns Promise containing map of network IDs to network details
|
|
2823
|
-
*/
|
|
2824
|
-
getNetworks() {
|
|
2825
|
-
return this.request("/api/networks");
|
|
2826
|
-
}
|
|
2827
3268
|
/**
|
|
2828
3269
|
* Retrieves all available vNext networks
|
|
2829
3270
|
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
@@ -2831,14 +3272,6 @@ var MastraClient = class extends BaseResource {
|
|
|
2831
3272
|
getVNextNetworks() {
|
|
2832
3273
|
return this.request("/api/networks/v-next");
|
|
2833
3274
|
}
|
|
2834
|
-
/**
|
|
2835
|
-
* Gets a network instance by ID
|
|
2836
|
-
* @param networkId - ID of the network to retrieve
|
|
2837
|
-
* @returns Network instance
|
|
2838
|
-
*/
|
|
2839
|
-
getNetwork(networkId) {
|
|
2840
|
-
return new Network(this.options, networkId);
|
|
2841
|
-
}
|
|
2842
3275
|
/**
|
|
2843
3276
|
* Gets a vNext network instance by ID
|
|
2844
3277
|
* @param networkId - ID of the vNext network to retrieve
|
|
@@ -3031,6 +3464,27 @@ var MastraClient = class extends BaseResource {
|
|
|
3031
3464
|
}
|
|
3032
3465
|
};
|
|
3033
3466
|
|
|
3467
|
+
// src/tools.ts
|
|
3468
|
+
var ClientTool = class {
|
|
3469
|
+
id;
|
|
3470
|
+
description;
|
|
3471
|
+
inputSchema;
|
|
3472
|
+
outputSchema;
|
|
3473
|
+
execute;
|
|
3474
|
+
constructor(opts) {
|
|
3475
|
+
this.id = opts.id;
|
|
3476
|
+
this.description = opts.description;
|
|
3477
|
+
this.inputSchema = opts.inputSchema;
|
|
3478
|
+
this.outputSchema = opts.outputSchema;
|
|
3479
|
+
this.execute = opts.execute;
|
|
3480
|
+
}
|
|
3481
|
+
};
|
|
3482
|
+
function createTool(opts) {
|
|
3483
|
+
return new ClientTool(opts);
|
|
3484
|
+
}
|
|
3485
|
+
|
|
3486
|
+
exports.ClientTool = ClientTool;
|
|
3034
3487
|
exports.MastraClient = MastraClient;
|
|
3488
|
+
exports.createTool = createTool;
|
|
3035
3489
|
//# sourceMappingURL=index.cjs.map
|
|
3036
3490
|
//# sourceMappingURL=index.cjs.map
|