@mastra/client-js 0.0.0-consolidate-changesets-20250904042643 → 0.0.0-createToolOptions-20250926094418
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 +369 -35
- package/README.md +2 -6
- package/dist/client.d.ts +36 -31
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +476 -591
- 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 +475 -592
- package/dist/index.js.map +1 -1
- package/dist/resources/agent-builder.d.ts +14 -2
- package/dist/resources/agent-builder.d.ts.map +1 -1
- package/dist/resources/agent.d.ts +47 -11
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/resources/index.d.ts +0 -2
- package/dist/resources/index.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 +10 -0
- 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 +51 -63
- 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 +8 -11
- package/dist/adapters/agui.d.ts +0 -23
- package/dist/adapters/agui.d.ts.map +0 -1
- package/dist/resources/legacy-workflow.d.ts +0 -87
- package/dist/resources/legacy-workflow.d.ts.map +0 -1
- package/dist/resources/network.d.ts +0 -30
- package/dist/resources/network.d.ts.map +0 -1
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 {
|
|
@@ -387,7 +219,9 @@ async function executeToolCallAndRespond({
|
|
|
387
219
|
resourceId,
|
|
388
220
|
threadId,
|
|
389
221
|
runtimeContext,
|
|
390
|
-
tracingContext: { currentSpan: void 0 }
|
|
222
|
+
tracingContext: { currentSpan: void 0 },
|
|
223
|
+
suspend: async () => {
|
|
224
|
+
}
|
|
391
225
|
},
|
|
392
226
|
{
|
|
393
227
|
messages: response.messages,
|
|
@@ -395,11 +229,7 @@ async function executeToolCallAndRespond({
|
|
|
395
229
|
}
|
|
396
230
|
);
|
|
397
231
|
const updatedMessages = [
|
|
398
|
-
|
|
399
|
-
role: "user",
|
|
400
|
-
content: params.messages
|
|
401
|
-
},
|
|
402
|
-
...response.response.messages,
|
|
232
|
+
...response.response.messages || [],
|
|
403
233
|
{
|
|
404
234
|
role: "tool",
|
|
405
235
|
content: [
|
|
@@ -461,17 +291,21 @@ var AgentVoice = class extends BaseResource {
|
|
|
461
291
|
}
|
|
462
292
|
/**
|
|
463
293
|
* Get available speakers for the agent's voice provider
|
|
294
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
295
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
464
296
|
* @returns Promise containing list of available speakers
|
|
465
297
|
*/
|
|
466
|
-
getSpeakers() {
|
|
467
|
-
return this.request(`/api/agents/${this.agentId}/voice/speakers`);
|
|
298
|
+
getSpeakers(runtimeContext) {
|
|
299
|
+
return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
|
|
468
300
|
}
|
|
469
301
|
/**
|
|
470
302
|
* Get the listener configuration for the agent's voice provider
|
|
303
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
304
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
471
305
|
* @returns Promise containing a check if the agent has listening capabilities
|
|
472
306
|
*/
|
|
473
|
-
getListener() {
|
|
474
|
-
return this.request(`/api/agents/${this.agentId}/voice/listener`);
|
|
307
|
+
getListener(runtimeContext) {
|
|
308
|
+
return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
|
|
475
309
|
}
|
|
476
310
|
};
|
|
477
311
|
var Agent = class extends BaseResource {
|
|
@@ -483,14 +317,15 @@ var Agent = class extends BaseResource {
|
|
|
483
317
|
voice;
|
|
484
318
|
/**
|
|
485
319
|
* Retrieves details about the agent
|
|
320
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
486
321
|
* @returns Promise containing agent details including model and instructions
|
|
487
322
|
*/
|
|
488
|
-
details() {
|
|
489
|
-
return this.request(`/api/agents/${this.agentId}`);
|
|
323
|
+
details(runtimeContext) {
|
|
324
|
+
return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
|
|
490
325
|
}
|
|
491
326
|
async generate(params) {
|
|
492
327
|
console.warn(
|
|
493
|
-
"Deprecation NOTICE:Generate method will switch to use generateVNext implementation September
|
|
328
|
+
"Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 30th, 2025. Please use generateLegacy if you don't want to upgrade just yet."
|
|
494
329
|
);
|
|
495
330
|
return this.generateLegacy(params);
|
|
496
331
|
}
|
|
@@ -525,7 +360,9 @@ var Agent = class extends BaseResource {
|
|
|
525
360
|
resourceId,
|
|
526
361
|
threadId,
|
|
527
362
|
runtimeContext,
|
|
528
|
-
tracingContext: { currentSpan: void 0 }
|
|
363
|
+
tracingContext: { currentSpan: void 0 },
|
|
364
|
+
suspend: async () => {
|
|
365
|
+
}
|
|
529
366
|
},
|
|
530
367
|
{
|
|
531
368
|
messages: response.messages,
|
|
@@ -533,10 +370,6 @@ var Agent = class extends BaseResource {
|
|
|
533
370
|
}
|
|
534
371
|
);
|
|
535
372
|
const updatedMessages = [
|
|
536
|
-
{
|
|
537
|
-
role: "user",
|
|
538
|
-
content: params.messages
|
|
539
|
-
},
|
|
540
373
|
...response.response.messages,
|
|
541
374
|
{
|
|
542
375
|
role: "tool",
|
|
@@ -559,12 +392,25 @@ var Agent = class extends BaseResource {
|
|
|
559
392
|
}
|
|
560
393
|
return response;
|
|
561
394
|
}
|
|
562
|
-
async generateVNext(
|
|
395
|
+
async generateVNext(messagesOrParams, options) {
|
|
396
|
+
let params;
|
|
397
|
+
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
398
|
+
params = messagesOrParams;
|
|
399
|
+
} else {
|
|
400
|
+
params = {
|
|
401
|
+
messages: messagesOrParams,
|
|
402
|
+
...options
|
|
403
|
+
};
|
|
404
|
+
}
|
|
563
405
|
const processedParams = {
|
|
564
406
|
...params,
|
|
565
407
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
566
408
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
567
|
-
clientTools: processClientTools(params.clientTools)
|
|
409
|
+
clientTools: processClientTools(params.clientTools),
|
|
410
|
+
structuredOutput: params.structuredOutput ? {
|
|
411
|
+
...params.structuredOutput,
|
|
412
|
+
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
413
|
+
} : void 0
|
|
568
414
|
};
|
|
569
415
|
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
570
416
|
const response = await this.request(
|
|
@@ -856,7 +702,7 @@ var Agent = class extends BaseResource {
|
|
|
856
702
|
*/
|
|
857
703
|
async stream(params) {
|
|
858
704
|
console.warn(
|
|
859
|
-
"Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September
|
|
705
|
+
"Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 30th, 2025. Please use streamLegacy if you don't want to upgrade just yet."
|
|
860
706
|
);
|
|
861
707
|
return this.streamLegacy(params);
|
|
862
708
|
}
|
|
@@ -1069,7 +915,7 @@ var Agent = class extends BaseResource {
|
|
|
1069
915
|
step,
|
|
1070
916
|
toolCallId: chunk.payload.toolCallId,
|
|
1071
917
|
toolName: chunk.payload.toolName,
|
|
1072
|
-
args:
|
|
918
|
+
args: chunk.payload.args
|
|
1073
919
|
};
|
|
1074
920
|
message.toolInvocations.push(invocation);
|
|
1075
921
|
updateToolInvocationPart(chunk.payload.toolCallId, invocation);
|
|
@@ -1123,14 +969,14 @@ var Agent = class extends BaseResource {
|
|
|
1123
969
|
}
|
|
1124
970
|
case "step-finish": {
|
|
1125
971
|
step += 1;
|
|
1126
|
-
currentTextPart = chunk.payload.isContinued ? currentTextPart : void 0;
|
|
972
|
+
currentTextPart = chunk.payload.stepResult.isContinued ? currentTextPart : void 0;
|
|
1127
973
|
currentReasoningPart = void 0;
|
|
1128
974
|
currentReasoningTextDetail = void 0;
|
|
1129
975
|
execUpdate();
|
|
1130
976
|
break;
|
|
1131
977
|
}
|
|
1132
978
|
case "finish": {
|
|
1133
|
-
finishReason = chunk.payload.
|
|
979
|
+
finishReason = chunk.payload.stepResult.reason;
|
|
1134
980
|
if (chunk.payload.usage != null) {
|
|
1135
981
|
usage = chunk.payload.usage;
|
|
1136
982
|
}
|
|
@@ -1154,9 +1000,28 @@ var Agent = class extends BaseResource {
|
|
|
1154
1000
|
let toolCalls = [];
|
|
1155
1001
|
let messages = [];
|
|
1156
1002
|
const [streamForWritable, streamForProcessing] = response.body.tee();
|
|
1157
|
-
streamForWritable.pipeTo(
|
|
1158
|
-
|
|
1159
|
-
|
|
1003
|
+
streamForWritable.pipeTo(
|
|
1004
|
+
new WritableStream({
|
|
1005
|
+
async write(chunk) {
|
|
1006
|
+
try {
|
|
1007
|
+
const text = new TextDecoder().decode(chunk);
|
|
1008
|
+
if (text.includes("[DONE]")) {
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
} catch {
|
|
1012
|
+
}
|
|
1013
|
+
const writer = writable.getWriter();
|
|
1014
|
+
try {
|
|
1015
|
+
await writer.write(chunk);
|
|
1016
|
+
} finally {
|
|
1017
|
+
writer.releaseLock();
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
}),
|
|
1021
|
+
{
|
|
1022
|
+
preventClose: true
|
|
1023
|
+
}
|
|
1024
|
+
).catch((error) => {
|
|
1160
1025
|
console.error("Error piping to writable stream:", error);
|
|
1161
1026
|
});
|
|
1162
1027
|
this.processChatResponse_vNext({
|
|
@@ -1186,14 +1051,17 @@ var Agent = class extends BaseResource {
|
|
|
1186
1051
|
threadId: processedParams.threadId,
|
|
1187
1052
|
runtimeContext: processedParams.runtimeContext,
|
|
1188
1053
|
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1189
|
-
tracingContext: { currentSpan: void 0 }
|
|
1054
|
+
tracingContext: { currentSpan: void 0 },
|
|
1055
|
+
suspend: async () => {
|
|
1056
|
+
}
|
|
1190
1057
|
},
|
|
1191
1058
|
{
|
|
1192
1059
|
messages: response.messages,
|
|
1193
1060
|
toolCallId: toolCall2?.toolCallId
|
|
1194
1061
|
}
|
|
1195
1062
|
);
|
|
1196
|
-
const
|
|
1063
|
+
const lastMessageRaw = messages[messages.length - 1];
|
|
1064
|
+
const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
|
|
1197
1065
|
const toolInvocationPart = lastMessage?.parts?.find(
|
|
1198
1066
|
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
1199
1067
|
);
|
|
@@ -1211,25 +1079,11 @@ var Agent = class extends BaseResource {
|
|
|
1211
1079
|
toolInvocation.state = "result";
|
|
1212
1080
|
toolInvocation.result = result;
|
|
1213
1081
|
}
|
|
1214
|
-
const
|
|
1215
|
-
try {
|
|
1216
|
-
await writer.write(
|
|
1217
|
-
new TextEncoder().encode(
|
|
1218
|
-
"a:" + JSON.stringify({
|
|
1219
|
-
toolCallId: toolCall2.toolCallId,
|
|
1220
|
-
result
|
|
1221
|
-
}) + "\n"
|
|
1222
|
-
)
|
|
1223
|
-
);
|
|
1224
|
-
} finally {
|
|
1225
|
-
writer.releaseLock();
|
|
1226
|
-
}
|
|
1227
|
-
const originalMessages = processedParams.messages;
|
|
1228
|
-
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1082
|
+
const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
|
|
1229
1083
|
this.processStreamResponse_vNext(
|
|
1230
1084
|
{
|
|
1231
1085
|
...processedParams,
|
|
1232
|
-
messages:
|
|
1086
|
+
messages: updatedMessages
|
|
1233
1087
|
},
|
|
1234
1088
|
writable
|
|
1235
1089
|
).catch((error) => {
|
|
@@ -1252,12 +1106,49 @@ var Agent = class extends BaseResource {
|
|
|
1252
1106
|
}
|
|
1253
1107
|
return response;
|
|
1254
1108
|
}
|
|
1255
|
-
async
|
|
1109
|
+
async network(params) {
|
|
1110
|
+
const response = await this.request(`/api/agents/${this.agentId}/network`, {
|
|
1111
|
+
method: "POST",
|
|
1112
|
+
body: params,
|
|
1113
|
+
stream: true
|
|
1114
|
+
});
|
|
1115
|
+
if (!response.body) {
|
|
1116
|
+
throw new Error("No response body");
|
|
1117
|
+
}
|
|
1118
|
+
const streamResponse = new Response(response.body, {
|
|
1119
|
+
status: response.status,
|
|
1120
|
+
statusText: response.statusText,
|
|
1121
|
+
headers: response.headers
|
|
1122
|
+
});
|
|
1123
|
+
streamResponse.processDataStream = async ({
|
|
1124
|
+
onChunk
|
|
1125
|
+
}) => {
|
|
1126
|
+
await processMastraNetworkStream({
|
|
1127
|
+
stream: streamResponse.body,
|
|
1128
|
+
onChunk
|
|
1129
|
+
});
|
|
1130
|
+
};
|
|
1131
|
+
return streamResponse;
|
|
1132
|
+
}
|
|
1133
|
+
async streamVNext(messagesOrParams, options) {
|
|
1134
|
+
let params;
|
|
1135
|
+
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
1136
|
+
params = messagesOrParams;
|
|
1137
|
+
} else {
|
|
1138
|
+
params = {
|
|
1139
|
+
messages: messagesOrParams,
|
|
1140
|
+
...options
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1256
1143
|
const processedParams = {
|
|
1257
1144
|
...params,
|
|
1258
1145
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
1259
1146
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
1260
|
-
clientTools: processClientTools(params.clientTools)
|
|
1147
|
+
clientTools: processClientTools(params.clientTools),
|
|
1148
|
+
structuredOutput: params.structuredOutput ? {
|
|
1149
|
+
...params.structuredOutput,
|
|
1150
|
+
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
1151
|
+
} : void 0
|
|
1261
1152
|
};
|
|
1262
1153
|
const { readable, writable } = new TransformStream();
|
|
1263
1154
|
const response = await this.processStreamResponse_vNext(processedParams, writable);
|
|
@@ -1324,7 +1215,9 @@ var Agent = class extends BaseResource {
|
|
|
1324
1215
|
threadId: processedParams.threadId,
|
|
1325
1216
|
runtimeContext: processedParams.runtimeContext,
|
|
1326
1217
|
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1327
|
-
tracingContext: { currentSpan: void 0 }
|
|
1218
|
+
tracingContext: { currentSpan: void 0 },
|
|
1219
|
+
suspend: async () => {
|
|
1220
|
+
}
|
|
1328
1221
|
},
|
|
1329
1222
|
{
|
|
1330
1223
|
messages: response.messages,
|
|
@@ -1362,12 +1255,10 @@ var Agent = class extends BaseResource {
|
|
|
1362
1255
|
} finally {
|
|
1363
1256
|
writer.releaseLock();
|
|
1364
1257
|
}
|
|
1365
|
-
const originalMessages = processedParams.messages;
|
|
1366
|
-
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1367
1258
|
this.processStreamResponse(
|
|
1368
1259
|
{
|
|
1369
1260
|
...processedParams,
|
|
1370
|
-
messages: [...
|
|
1261
|
+
messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
|
|
1371
1262
|
},
|
|
1372
1263
|
writable
|
|
1373
1264
|
).catch((error) => {
|
|
@@ -1393,10 +1284,11 @@ var Agent = class extends BaseResource {
|
|
|
1393
1284
|
/**
|
|
1394
1285
|
* Gets details about a specific tool available to the agent
|
|
1395
1286
|
* @param toolId - ID of the tool to retrieve
|
|
1287
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1396
1288
|
* @returns Promise containing tool details
|
|
1397
1289
|
*/
|
|
1398
|
-
getTool(toolId) {
|
|
1399
|
-
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
1290
|
+
getTool(toolId, runtimeContext) {
|
|
1291
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1400
1292
|
}
|
|
1401
1293
|
/**
|
|
1402
1294
|
* Executes a tool for the agent
|
|
@@ -1407,7 +1299,7 @@ var Agent = class extends BaseResource {
|
|
|
1407
1299
|
executeTool(toolId, params) {
|
|
1408
1300
|
const body = {
|
|
1409
1301
|
data: params.data,
|
|
1410
|
-
runtimeContext:
|
|
1302
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1411
1303
|
};
|
|
1412
1304
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
1413
1305
|
method: "POST",
|
|
@@ -1416,17 +1308,19 @@ var Agent = class extends BaseResource {
|
|
|
1416
1308
|
}
|
|
1417
1309
|
/**
|
|
1418
1310
|
* Retrieves evaluation results for the agent
|
|
1311
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1419
1312
|
* @returns Promise containing agent evaluations
|
|
1420
1313
|
*/
|
|
1421
|
-
evals() {
|
|
1422
|
-
return this.request(`/api/agents/${this.agentId}/evals/ci`);
|
|
1314
|
+
evals(runtimeContext) {
|
|
1315
|
+
return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
|
|
1423
1316
|
}
|
|
1424
1317
|
/**
|
|
1425
1318
|
* Retrieves live evaluation results for the agent
|
|
1319
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1426
1320
|
* @returns Promise containing live agent evaluations
|
|
1427
1321
|
*/
|
|
1428
|
-
liveEvals() {
|
|
1429
|
-
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
1322
|
+
liveEvals(runtimeContext) {
|
|
1323
|
+
return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
|
|
1430
1324
|
}
|
|
1431
1325
|
/**
|
|
1432
1326
|
* Updates the model for the agent
|
|
@@ -1439,61 +1333,27 @@ var Agent = class extends BaseResource {
|
|
|
1439
1333
|
body: params
|
|
1440
1334
|
});
|
|
1441
1335
|
}
|
|
1442
|
-
};
|
|
1443
|
-
var Network = class extends BaseResource {
|
|
1444
|
-
constructor(options, networkId) {
|
|
1445
|
-
super(options);
|
|
1446
|
-
this.networkId = networkId;
|
|
1447
|
-
}
|
|
1448
|
-
/**
|
|
1449
|
-
* Retrieves details about the network
|
|
1450
|
-
* @returns Promise containing network details
|
|
1451
|
-
*/
|
|
1452
|
-
details() {
|
|
1453
|
-
return this.request(`/api/networks/${this.networkId}`);
|
|
1454
|
-
}
|
|
1455
1336
|
/**
|
|
1456
|
-
*
|
|
1457
|
-
* @param params -
|
|
1458
|
-
* @returns Promise containing the
|
|
1337
|
+
* Updates the model for the agent in the model list
|
|
1338
|
+
* @param params - Parameters for updating the model
|
|
1339
|
+
* @returns Promise containing the updated model
|
|
1459
1340
|
*/
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
...params,
|
|
1463
|
-
output: zodToJsonSchema(params.output),
|
|
1464
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1465
|
-
};
|
|
1466
|
-
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
1341
|
+
updateModelInModelList({ modelConfigId, ...params }) {
|
|
1342
|
+
return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
|
|
1467
1343
|
method: "POST",
|
|
1468
|
-
body:
|
|
1344
|
+
body: params
|
|
1469
1345
|
});
|
|
1470
1346
|
}
|
|
1471
1347
|
/**
|
|
1472
|
-
*
|
|
1473
|
-
* @param params -
|
|
1474
|
-
* @returns Promise containing the
|
|
1348
|
+
* Reorders the models for the agent
|
|
1349
|
+
* @param params - Parameters for reordering the model list
|
|
1350
|
+
* @returns Promise containing the updated model list
|
|
1475
1351
|
*/
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
...params,
|
|
1479
|
-
output: zodToJsonSchema(params.output),
|
|
1480
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1481
|
-
};
|
|
1482
|
-
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
1352
|
+
reorderModelList(params) {
|
|
1353
|
+
return this.request(`/api/agents/${this.agentId}/models/reorder`, {
|
|
1483
1354
|
method: "POST",
|
|
1484
|
-
body:
|
|
1485
|
-
stream: true
|
|
1355
|
+
body: params
|
|
1486
1356
|
});
|
|
1487
|
-
if (!response.body) {
|
|
1488
|
-
throw new Error("No response body");
|
|
1489
|
-
}
|
|
1490
|
-
response.processDataStream = async (options = {}) => {
|
|
1491
|
-
await uiUtils.processDataStream({
|
|
1492
|
-
stream: response.body,
|
|
1493
|
-
...options
|
|
1494
|
-
});
|
|
1495
|
-
};
|
|
1496
|
-
return response;
|
|
1497
1357
|
}
|
|
1498
1358
|
};
|
|
1499
1359
|
|
|
@@ -1584,10 +1444,13 @@ var Vector = class extends BaseResource {
|
|
|
1584
1444
|
/**
|
|
1585
1445
|
* Retrieves details about a specific vector index
|
|
1586
1446
|
* @param indexName - Name of the index to get details for
|
|
1447
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1587
1448
|
* @returns Promise containing vector index details
|
|
1588
1449
|
*/
|
|
1589
|
-
details(indexName) {
|
|
1590
|
-
return this.request(
|
|
1450
|
+
details(indexName, runtimeContext) {
|
|
1451
|
+
return this.request(
|
|
1452
|
+
`/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
|
|
1453
|
+
);
|
|
1591
1454
|
}
|
|
1592
1455
|
/**
|
|
1593
1456
|
* Deletes a vector index
|
|
@@ -1601,10 +1464,11 @@ var Vector = class extends BaseResource {
|
|
|
1601
1464
|
}
|
|
1602
1465
|
/**
|
|
1603
1466
|
* Retrieves a list of all available indexes
|
|
1467
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1604
1468
|
* @returns Promise containing array of index names
|
|
1605
1469
|
*/
|
|
1606
|
-
getIndexes() {
|
|
1607
|
-
return this.request(`/api/vector/${this.vectorName}/indexes`);
|
|
1470
|
+
getIndexes(runtimeContext) {
|
|
1471
|
+
return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
|
|
1608
1472
|
}
|
|
1609
1473
|
/**
|
|
1610
1474
|
* Creates a new vector index
|
|
@@ -1641,187 +1505,6 @@ var Vector = class extends BaseResource {
|
|
|
1641
1505
|
}
|
|
1642
1506
|
};
|
|
1643
1507
|
|
|
1644
|
-
// src/resources/legacy-workflow.ts
|
|
1645
|
-
var RECORD_SEPARATOR = "";
|
|
1646
|
-
var LegacyWorkflow = class extends BaseResource {
|
|
1647
|
-
constructor(options, workflowId) {
|
|
1648
|
-
super(options);
|
|
1649
|
-
this.workflowId = workflowId;
|
|
1650
|
-
}
|
|
1651
|
-
/**
|
|
1652
|
-
* Retrieves details about the legacy workflow
|
|
1653
|
-
* @returns Promise containing legacy workflow details including steps and graphs
|
|
1654
|
-
*/
|
|
1655
|
-
details() {
|
|
1656
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}`);
|
|
1657
|
-
}
|
|
1658
|
-
/**
|
|
1659
|
-
* Retrieves all runs for a legacy workflow
|
|
1660
|
-
* @param params - Parameters for filtering runs
|
|
1661
|
-
* @returns Promise containing legacy workflow runs array
|
|
1662
|
-
*/
|
|
1663
|
-
runs(params) {
|
|
1664
|
-
const searchParams = new URLSearchParams();
|
|
1665
|
-
if (params?.fromDate) {
|
|
1666
|
-
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
1667
|
-
}
|
|
1668
|
-
if (params?.toDate) {
|
|
1669
|
-
searchParams.set("toDate", params.toDate.toISOString());
|
|
1670
|
-
}
|
|
1671
|
-
if (params?.limit) {
|
|
1672
|
-
searchParams.set("limit", String(params.limit));
|
|
1673
|
-
}
|
|
1674
|
-
if (params?.offset) {
|
|
1675
|
-
searchParams.set("offset", String(params.offset));
|
|
1676
|
-
}
|
|
1677
|
-
if (params?.resourceId) {
|
|
1678
|
-
searchParams.set("resourceId", params.resourceId);
|
|
1679
|
-
}
|
|
1680
|
-
if (searchParams.size) {
|
|
1681
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
1682
|
-
} else {
|
|
1683
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
1684
|
-
}
|
|
1685
|
-
}
|
|
1686
|
-
/**
|
|
1687
|
-
* Creates a new legacy workflow run
|
|
1688
|
-
* @returns Promise containing the generated run ID
|
|
1689
|
-
*/
|
|
1690
|
-
createRun(params) {
|
|
1691
|
-
const searchParams = new URLSearchParams();
|
|
1692
|
-
if (!!params?.runId) {
|
|
1693
|
-
searchParams.set("runId", params.runId);
|
|
1694
|
-
}
|
|
1695
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
1696
|
-
method: "POST"
|
|
1697
|
-
});
|
|
1698
|
-
}
|
|
1699
|
-
/**
|
|
1700
|
-
* Starts a legacy workflow run synchronously without waiting for the workflow to complete
|
|
1701
|
-
* @param params - Object containing the runId and triggerData
|
|
1702
|
-
* @returns Promise containing success message
|
|
1703
|
-
*/
|
|
1704
|
-
start(params) {
|
|
1705
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1706
|
-
method: "POST",
|
|
1707
|
-
body: params?.triggerData
|
|
1708
|
-
});
|
|
1709
|
-
}
|
|
1710
|
-
/**
|
|
1711
|
-
* Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
|
|
1712
|
-
* @param stepId - ID of the step to resume
|
|
1713
|
-
* @param runId - ID of the legacy workflow run
|
|
1714
|
-
* @param context - Context to resume the legacy workflow with
|
|
1715
|
-
* @returns Promise containing the legacy workflow resume results
|
|
1716
|
-
*/
|
|
1717
|
-
resume({
|
|
1718
|
-
stepId,
|
|
1719
|
-
runId,
|
|
1720
|
-
context
|
|
1721
|
-
}) {
|
|
1722
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
1723
|
-
method: "POST",
|
|
1724
|
-
body: {
|
|
1725
|
-
stepId,
|
|
1726
|
-
context
|
|
1727
|
-
}
|
|
1728
|
-
});
|
|
1729
|
-
}
|
|
1730
|
-
/**
|
|
1731
|
-
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
1732
|
-
* @param params - Object containing the optional runId and triggerData
|
|
1733
|
-
* @returns Promise containing the workflow execution results
|
|
1734
|
-
*/
|
|
1735
|
-
startAsync(params) {
|
|
1736
|
-
const searchParams = new URLSearchParams();
|
|
1737
|
-
if (!!params?.runId) {
|
|
1738
|
-
searchParams.set("runId", params.runId);
|
|
1739
|
-
}
|
|
1740
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1741
|
-
method: "POST",
|
|
1742
|
-
body: params?.triggerData
|
|
1743
|
-
});
|
|
1744
|
-
}
|
|
1745
|
-
/**
|
|
1746
|
-
* Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
1747
|
-
* @param params - Object containing the runId, stepId, and context
|
|
1748
|
-
* @returns Promise containing the workflow resume results
|
|
1749
|
-
*/
|
|
1750
|
-
resumeAsync(params) {
|
|
1751
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
1752
|
-
method: "POST",
|
|
1753
|
-
body: {
|
|
1754
|
-
stepId: params.stepId,
|
|
1755
|
-
context: params.context
|
|
1756
|
-
}
|
|
1757
|
-
});
|
|
1758
|
-
}
|
|
1759
|
-
/**
|
|
1760
|
-
* Creates an async generator that processes a readable stream and yields records
|
|
1761
|
-
* separated by the Record Separator character (\x1E)
|
|
1762
|
-
*
|
|
1763
|
-
* @param stream - The readable stream to process
|
|
1764
|
-
* @returns An async generator that yields parsed records
|
|
1765
|
-
*/
|
|
1766
|
-
async *streamProcessor(stream) {
|
|
1767
|
-
const reader = stream.getReader();
|
|
1768
|
-
let doneReading = false;
|
|
1769
|
-
let buffer = "";
|
|
1770
|
-
try {
|
|
1771
|
-
while (!doneReading) {
|
|
1772
|
-
const { done, value } = await reader.read();
|
|
1773
|
-
doneReading = done;
|
|
1774
|
-
if (done && !value) continue;
|
|
1775
|
-
try {
|
|
1776
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1777
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
1778
|
-
buffer = chunks.pop() || "";
|
|
1779
|
-
for (const chunk of chunks) {
|
|
1780
|
-
if (chunk) {
|
|
1781
|
-
if (typeof chunk === "string") {
|
|
1782
|
-
try {
|
|
1783
|
-
const parsedChunk = JSON.parse(chunk);
|
|
1784
|
-
yield parsedChunk;
|
|
1785
|
-
} catch {
|
|
1786
|
-
}
|
|
1787
|
-
}
|
|
1788
|
-
}
|
|
1789
|
-
}
|
|
1790
|
-
} catch {
|
|
1791
|
-
}
|
|
1792
|
-
}
|
|
1793
|
-
if (buffer) {
|
|
1794
|
-
try {
|
|
1795
|
-
yield JSON.parse(buffer);
|
|
1796
|
-
} catch {
|
|
1797
|
-
}
|
|
1798
|
-
}
|
|
1799
|
-
} finally {
|
|
1800
|
-
reader.cancel().catch(() => {
|
|
1801
|
-
});
|
|
1802
|
-
}
|
|
1803
|
-
}
|
|
1804
|
-
/**
|
|
1805
|
-
* Watches legacy workflow transitions in real-time
|
|
1806
|
-
* @param runId - Optional run ID to filter the watch stream
|
|
1807
|
-
* @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
|
|
1808
|
-
*/
|
|
1809
|
-
async watch({ runId }, onRecord) {
|
|
1810
|
-
const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
|
|
1811
|
-
stream: true
|
|
1812
|
-
});
|
|
1813
|
-
if (!response.ok) {
|
|
1814
|
-
throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
|
|
1815
|
-
}
|
|
1816
|
-
if (!response.body) {
|
|
1817
|
-
throw new Error("Response body is null");
|
|
1818
|
-
}
|
|
1819
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
1820
|
-
onRecord(record);
|
|
1821
|
-
}
|
|
1822
|
-
}
|
|
1823
|
-
};
|
|
1824
|
-
|
|
1825
1508
|
// src/resources/tool.ts
|
|
1826
1509
|
var Tool = class extends BaseResource {
|
|
1827
1510
|
constructor(options, toolId) {
|
|
@@ -1830,10 +1513,11 @@ var Tool = class extends BaseResource {
|
|
|
1830
1513
|
}
|
|
1831
1514
|
/**
|
|
1832
1515
|
* Retrieves details about the tool
|
|
1516
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1833
1517
|
* @returns Promise containing tool details including description and schemas
|
|
1834
1518
|
*/
|
|
1835
|
-
details() {
|
|
1836
|
-
return this.request(`/api/tools/${this.toolId}`);
|
|
1519
|
+
details(runtimeContext) {
|
|
1520
|
+
return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1837
1521
|
}
|
|
1838
1522
|
/**
|
|
1839
1523
|
* Executes the tool with the provided parameters
|
|
@@ -1857,7 +1541,7 @@ var Tool = class extends BaseResource {
|
|
|
1857
1541
|
};
|
|
1858
1542
|
|
|
1859
1543
|
// src/resources/workflow.ts
|
|
1860
|
-
var
|
|
1544
|
+
var RECORD_SEPARATOR = "";
|
|
1861
1545
|
var Workflow = class extends BaseResource {
|
|
1862
1546
|
constructor(options, workflowId) {
|
|
1863
1547
|
super(options);
|
|
@@ -1881,7 +1565,7 @@ var Workflow = class extends BaseResource {
|
|
|
1881
1565
|
if (done && !value) continue;
|
|
1882
1566
|
try {
|
|
1883
1567
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1884
|
-
const chunks = (buffer + decoded).split(
|
|
1568
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
1885
1569
|
buffer = chunks.pop() || "";
|
|
1886
1570
|
for (const chunk of chunks) {
|
|
1887
1571
|
if (chunk) {
|
|
@@ -1910,17 +1594,20 @@ var Workflow = class extends BaseResource {
|
|
|
1910
1594
|
}
|
|
1911
1595
|
/**
|
|
1912
1596
|
* Retrieves details about the workflow
|
|
1597
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1913
1598
|
* @returns Promise containing workflow details including steps and graphs
|
|
1914
1599
|
*/
|
|
1915
|
-
details() {
|
|
1916
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
1600
|
+
details(runtimeContext) {
|
|
1601
|
+
return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1917
1602
|
}
|
|
1918
1603
|
/**
|
|
1919
1604
|
* Retrieves all runs for a workflow
|
|
1920
1605
|
* @param params - Parameters for filtering runs
|
|
1606
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1921
1607
|
* @returns Promise containing workflow runs array
|
|
1922
1608
|
*/
|
|
1923
|
-
runs(params) {
|
|
1609
|
+
runs(params, runtimeContext) {
|
|
1610
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
1924
1611
|
const searchParams = new URLSearchParams();
|
|
1925
1612
|
if (params?.fromDate) {
|
|
1926
1613
|
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
@@ -1937,6 +1624,9 @@ var Workflow = class extends BaseResource {
|
|
|
1937
1624
|
if (params?.resourceId) {
|
|
1938
1625
|
searchParams.set("resourceId", params.resourceId);
|
|
1939
1626
|
}
|
|
1627
|
+
if (runtimeContextParam) {
|
|
1628
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
1629
|
+
}
|
|
1940
1630
|
if (searchParams.size) {
|
|
1941
1631
|
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
1942
1632
|
} else {
|
|
@@ -1946,18 +1636,22 @@ var Workflow = class extends BaseResource {
|
|
|
1946
1636
|
/**
|
|
1947
1637
|
* Retrieves a specific workflow run by its ID
|
|
1948
1638
|
* @param runId - The ID of the workflow run to retrieve
|
|
1639
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1949
1640
|
* @returns Promise containing the workflow run details
|
|
1950
1641
|
*/
|
|
1951
|
-
runById(runId) {
|
|
1952
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
|
|
1642
|
+
runById(runId, runtimeContext) {
|
|
1643
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1953
1644
|
}
|
|
1954
1645
|
/**
|
|
1955
1646
|
* Retrieves the execution result for a specific workflow run by its ID
|
|
1956
1647
|
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1648
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1957
1649
|
* @returns Promise containing the workflow run execution result
|
|
1958
1650
|
*/
|
|
1959
|
-
runExecutionResult(runId) {
|
|
1960
|
-
return this.request(
|
|
1651
|
+
runExecutionResult(runId, runtimeContext) {
|
|
1652
|
+
return this.request(
|
|
1653
|
+
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
|
|
1654
|
+
);
|
|
1961
1655
|
}
|
|
1962
1656
|
/**
|
|
1963
1657
|
* Cancels a specific workflow run by its ID
|
|
@@ -1980,27 +1674,61 @@ var Workflow = class extends BaseResource {
|
|
|
1980
1674
|
body: { event: params.event, data: params.data }
|
|
1981
1675
|
});
|
|
1982
1676
|
}
|
|
1677
|
+
/**
|
|
1678
|
+
* @deprecated Use createRunAsync() instead.
|
|
1679
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
1680
|
+
*/
|
|
1681
|
+
async createRun(_params) {
|
|
1682
|
+
throw new Error(
|
|
1683
|
+
"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."
|
|
1684
|
+
);
|
|
1685
|
+
}
|
|
1983
1686
|
/**
|
|
1984
1687
|
* Creates a new workflow run
|
|
1985
1688
|
* @param params - Optional object containing the optional runId
|
|
1986
|
-
* @returns Promise containing the runId of the created run
|
|
1689
|
+
* @returns Promise containing the runId of the created run with methods to control execution
|
|
1987
1690
|
*/
|
|
1988
|
-
|
|
1691
|
+
async createRunAsync(params) {
|
|
1989
1692
|
const searchParams = new URLSearchParams();
|
|
1990
1693
|
if (!!params?.runId) {
|
|
1991
1694
|
searchParams.set("runId", params.runId);
|
|
1992
1695
|
}
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
1696
|
+
const res = await this.request(
|
|
1697
|
+
`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
|
|
1698
|
+
{
|
|
1699
|
+
method: "POST"
|
|
1700
|
+
}
|
|
1701
|
+
);
|
|
1702
|
+
const runId = res.runId;
|
|
1703
|
+
return {
|
|
1704
|
+
runId,
|
|
1705
|
+
start: async (p) => {
|
|
1706
|
+
return this.start({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
|
|
1707
|
+
},
|
|
1708
|
+
startAsync: async (p) => {
|
|
1709
|
+
return this.startAsync({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
|
|
1710
|
+
},
|
|
1711
|
+
watch: async (onRecord) => {
|
|
1712
|
+
return this.watch({ runId }, onRecord);
|
|
1713
|
+
},
|
|
1714
|
+
stream: async (p) => {
|
|
1715
|
+
return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
|
|
1716
|
+
},
|
|
1717
|
+
resume: async (p) => {
|
|
1718
|
+
return this.resume({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
|
|
1719
|
+
},
|
|
1720
|
+
resumeAsync: async (p) => {
|
|
1721
|
+
return this.resumeAsync({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
|
|
1722
|
+
},
|
|
1723
|
+
resumeStreamVNext: async (p) => {
|
|
1724
|
+
return this.resumeStreamVNext({
|
|
1725
|
+
runId,
|
|
1726
|
+
step: p.step,
|
|
1727
|
+
resumeData: p.resumeData,
|
|
1728
|
+
runtimeContext: p.runtimeContext
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
};
|
|
2004
1732
|
}
|
|
2005
1733
|
/**
|
|
2006
1734
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
@@ -2028,7 +1756,6 @@ var Workflow = class extends BaseResource {
|
|
|
2028
1756
|
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
2029
1757
|
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
2030
1758
|
method: "POST",
|
|
2031
|
-
stream: true,
|
|
2032
1759
|
body: {
|
|
2033
1760
|
step,
|
|
2034
1761
|
resumeData,
|
|
@@ -2071,6 +1798,104 @@ var Workflow = class extends BaseResource {
|
|
|
2071
1798
|
stream: true
|
|
2072
1799
|
}
|
|
2073
1800
|
);
|
|
1801
|
+
if (!response.ok) {
|
|
1802
|
+
throw new Error(`Failed to stream workflow: ${response.statusText}`);
|
|
1803
|
+
}
|
|
1804
|
+
if (!response.body) {
|
|
1805
|
+
throw new Error("Response body is null");
|
|
1806
|
+
}
|
|
1807
|
+
let failedChunk = void 0;
|
|
1808
|
+
const transformStream = new TransformStream({
|
|
1809
|
+
start() {
|
|
1810
|
+
},
|
|
1811
|
+
async transform(chunk, controller) {
|
|
1812
|
+
try {
|
|
1813
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1814
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1815
|
+
for (const chunk2 of chunks) {
|
|
1816
|
+
if (chunk2) {
|
|
1817
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1818
|
+
try {
|
|
1819
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1820
|
+
controller.enqueue(parsedChunk);
|
|
1821
|
+
failedChunk = void 0;
|
|
1822
|
+
} catch {
|
|
1823
|
+
failedChunk = newChunk;
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
} catch {
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
});
|
|
1831
|
+
return response.body.pipeThrough(transformStream);
|
|
1832
|
+
}
|
|
1833
|
+
/**
|
|
1834
|
+
* Observes workflow stream for a workflow run
|
|
1835
|
+
* @param params - Object containing the runId
|
|
1836
|
+
* @returns Promise containing the workflow execution results
|
|
1837
|
+
*/
|
|
1838
|
+
async observeStream(params) {
|
|
1839
|
+
const searchParams = new URLSearchParams();
|
|
1840
|
+
searchParams.set("runId", params.runId);
|
|
1841
|
+
const response = await this.request(
|
|
1842
|
+
`/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
|
|
1843
|
+
{
|
|
1844
|
+
method: "POST",
|
|
1845
|
+
stream: true
|
|
1846
|
+
}
|
|
1847
|
+
);
|
|
1848
|
+
if (!response.ok) {
|
|
1849
|
+
throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
|
|
1850
|
+
}
|
|
1851
|
+
if (!response.body) {
|
|
1852
|
+
throw new Error("Response body is null");
|
|
1853
|
+
}
|
|
1854
|
+
let failedChunk = void 0;
|
|
1855
|
+
const transformStream = new TransformStream({
|
|
1856
|
+
start() {
|
|
1857
|
+
},
|
|
1858
|
+
async transform(chunk, controller) {
|
|
1859
|
+
try {
|
|
1860
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1861
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1862
|
+
for (const chunk2 of chunks) {
|
|
1863
|
+
if (chunk2) {
|
|
1864
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1865
|
+
try {
|
|
1866
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1867
|
+
controller.enqueue(parsedChunk);
|
|
1868
|
+
failedChunk = void 0;
|
|
1869
|
+
} catch {
|
|
1870
|
+
failedChunk = newChunk;
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
} catch {
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
});
|
|
1878
|
+
return response.body.pipeThrough(transformStream);
|
|
1879
|
+
}
|
|
1880
|
+
/**
|
|
1881
|
+
* Starts a workflow run and returns a stream
|
|
1882
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
1883
|
+
* @returns Promise containing the workflow execution results
|
|
1884
|
+
*/
|
|
1885
|
+
async streamVNext(params) {
|
|
1886
|
+
const searchParams = new URLSearchParams();
|
|
1887
|
+
if (!!params?.runId) {
|
|
1888
|
+
searchParams.set("runId", params.runId);
|
|
1889
|
+
}
|
|
1890
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1891
|
+
const response = await this.request(
|
|
1892
|
+
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
1893
|
+
{
|
|
1894
|
+
method: "POST",
|
|
1895
|
+
body: { inputData: params.inputData, runtimeContext, closeOnSuspend: params.closeOnSuspend },
|
|
1896
|
+
stream: true
|
|
1897
|
+
}
|
|
1898
|
+
);
|
|
2074
1899
|
if (!response.ok) {
|
|
2075
1900
|
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
2076
1901
|
}
|
|
@@ -2084,7 +1909,7 @@ var Workflow = class extends BaseResource {
|
|
|
2084
1909
|
async transform(chunk, controller) {
|
|
2085
1910
|
try {
|
|
2086
1911
|
const decoded = new TextDecoder().decode(chunk);
|
|
2087
|
-
const chunks = decoded.split(
|
|
1912
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
2088
1913
|
for (const chunk2 of chunks) {
|
|
2089
1914
|
if (chunk2) {
|
|
2090
1915
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2119,6 +1944,22 @@ var Workflow = class extends BaseResource {
|
|
|
2119
1944
|
}
|
|
2120
1945
|
});
|
|
2121
1946
|
}
|
|
1947
|
+
/**
|
|
1948
|
+
* Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
|
|
1949
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
1950
|
+
* @returns Promise containing the workflow resume results
|
|
1951
|
+
*/
|
|
1952
|
+
resumeStreamVNext(params) {
|
|
1953
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1954
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-stream?runId=${params.runId}`, {
|
|
1955
|
+
method: "POST",
|
|
1956
|
+
body: {
|
|
1957
|
+
step: params.step,
|
|
1958
|
+
resumeData: params.resumeData,
|
|
1959
|
+
runtimeContext
|
|
1960
|
+
}
|
|
1961
|
+
});
|
|
1962
|
+
}
|
|
2122
1963
|
/**
|
|
2123
1964
|
* Watches workflow transitions in real-time
|
|
2124
1965
|
* @param runId - Optional run ID to filter the watch stream
|
|
@@ -2155,7 +1996,7 @@ var Workflow = class extends BaseResource {
|
|
|
2155
1996
|
async start(controller) {
|
|
2156
1997
|
try {
|
|
2157
1998
|
for await (const record of records) {
|
|
2158
|
-
const json = JSON.stringify(record) +
|
|
1999
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR;
|
|
2159
2000
|
controller.enqueue(encoder.encode(json));
|
|
2160
2001
|
}
|
|
2161
2002
|
controller.close();
|
|
@@ -2253,10 +2094,11 @@ var MCPTool = class extends BaseResource {
|
|
|
2253
2094
|
}
|
|
2254
2095
|
/**
|
|
2255
2096
|
* Retrieves details about this specific tool from the MCP server.
|
|
2097
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2256
2098
|
* @returns Promise containing the tool's information (name, description, schema).
|
|
2257
2099
|
*/
|
|
2258
|
-
details() {
|
|
2259
|
-
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
2100
|
+
details(runtimeContext) {
|
|
2101
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
2260
2102
|
}
|
|
2261
2103
|
/**
|
|
2262
2104
|
* Executes this specific tool on the MCP server.
|
|
@@ -2277,7 +2119,7 @@ var MCPTool = class extends BaseResource {
|
|
|
2277
2119
|
};
|
|
2278
2120
|
|
|
2279
2121
|
// src/resources/agent-builder.ts
|
|
2280
|
-
var
|
|
2122
|
+
var RECORD_SEPARATOR2 = "";
|
|
2281
2123
|
var AgentBuilder = class extends BaseResource {
|
|
2282
2124
|
constructor(options, actionId) {
|
|
2283
2125
|
super(options);
|
|
@@ -2312,21 +2154,27 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2312
2154
|
};
|
|
2313
2155
|
}
|
|
2314
2156
|
}
|
|
2157
|
+
/**
|
|
2158
|
+
* @deprecated Use createRunAsync() instead.
|
|
2159
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
2160
|
+
*/
|
|
2161
|
+
async createRun(_params) {
|
|
2162
|
+
throw new Error(
|
|
2163
|
+
"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."
|
|
2164
|
+
);
|
|
2165
|
+
}
|
|
2315
2166
|
/**
|
|
2316
2167
|
* Creates a new agent builder action run and returns the runId.
|
|
2317
2168
|
* This calls `/api/agent-builder/:actionId/create-run`.
|
|
2318
2169
|
*/
|
|
2319
|
-
async
|
|
2170
|
+
async createRunAsync(params) {
|
|
2320
2171
|
const searchParams = new URLSearchParams();
|
|
2321
|
-
if (runId) {
|
|
2322
|
-
searchParams.set("runId", runId);
|
|
2172
|
+
if (!!params?.runId) {
|
|
2173
|
+
searchParams.set("runId", params.runId);
|
|
2323
2174
|
}
|
|
2324
|
-
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2325
|
-
const { runtimeContext: _, ...actionParams } = params;
|
|
2326
2175
|
const url = `/api/agent-builder/${this.actionId}/create-run${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2327
2176
|
return this.request(url, {
|
|
2328
|
-
method: "POST"
|
|
2329
|
-
body: { ...actionParams, runtimeContext }
|
|
2177
|
+
method: "POST"
|
|
2330
2178
|
});
|
|
2331
2179
|
}
|
|
2332
2180
|
/**
|
|
@@ -2411,7 +2259,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2411
2259
|
if (done && !value) continue;
|
|
2412
2260
|
try {
|
|
2413
2261
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2414
|
-
const chunks = (buffer + decoded).split(
|
|
2262
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
2415
2263
|
buffer = chunks.pop() || "";
|
|
2416
2264
|
for (const chunk of chunks) {
|
|
2417
2265
|
if (chunk) {
|
|
@@ -2468,7 +2316,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2468
2316
|
async transform(chunk, controller) {
|
|
2469
2317
|
try {
|
|
2470
2318
|
const decoded = new TextDecoder().decode(chunk);
|
|
2471
|
-
const chunks = decoded.split(
|
|
2319
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2472
2320
|
for (const chunk2 of chunks) {
|
|
2473
2321
|
if (chunk2) {
|
|
2474
2322
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2517,7 +2365,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2517
2365
|
async transform(chunk, controller) {
|
|
2518
2366
|
try {
|
|
2519
2367
|
const decoded = new TextDecoder().decode(chunk);
|
|
2520
|
-
const chunks = decoded.split(
|
|
2368
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2521
2369
|
for (const chunk2 of chunks) {
|
|
2522
2370
|
if (chunk2) {
|
|
2523
2371
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2542,8 +2390,8 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2542
2390
|
* and streams any remaining progress.
|
|
2543
2391
|
* This calls `/api/agent-builder/:actionId/watch`.
|
|
2544
2392
|
*/
|
|
2545
|
-
async watch({ runId }, onRecord) {
|
|
2546
|
-
const url = `/api/agent-builder/${this.actionId}/watch?runId=${runId}`;
|
|
2393
|
+
async watch({ runId, eventType }, onRecord) {
|
|
2394
|
+
const url = `/api/agent-builder/${this.actionId}/watch?runId=${runId}${eventType ? `&eventType=${eventType}` : ""}`;
|
|
2547
2395
|
const response = await this.request(url, {
|
|
2548
2396
|
method: "GET",
|
|
2549
2397
|
stream: true
|
|
@@ -2660,7 +2508,7 @@ var Observability = class extends BaseResource {
|
|
|
2660
2508
|
getTraces(params) {
|
|
2661
2509
|
const { pagination, filters } = params;
|
|
2662
2510
|
const { page, perPage, dateRange } = pagination || {};
|
|
2663
|
-
const { name, spanType } = filters || {};
|
|
2511
|
+
const { name, spanType, entityId, entityType } = filters || {};
|
|
2664
2512
|
const searchParams = new URLSearchParams();
|
|
2665
2513
|
if (page !== void 0) {
|
|
2666
2514
|
searchParams.set("page", String(page));
|
|
@@ -2674,6 +2522,10 @@ var Observability = class extends BaseResource {
|
|
|
2674
2522
|
if (spanType !== void 0) {
|
|
2675
2523
|
searchParams.set("spanType", String(spanType));
|
|
2676
2524
|
}
|
|
2525
|
+
if (entityId && entityType) {
|
|
2526
|
+
searchParams.set("entityId", entityId);
|
|
2527
|
+
searchParams.set("entityType", entityType);
|
|
2528
|
+
}
|
|
2677
2529
|
if (dateRange) {
|
|
2678
2530
|
const dateRangeStr = JSON.stringify({
|
|
2679
2531
|
start: dateRange.start instanceof Date ? dateRange.start.toISOString() : dateRange.start,
|
|
@@ -2684,6 +2536,12 @@ var Observability = class extends BaseResource {
|
|
|
2684
2536
|
const queryString = searchParams.toString();
|
|
2685
2537
|
return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
|
|
2686
2538
|
}
|
|
2539
|
+
score(params) {
|
|
2540
|
+
return this.request(`/api/observability/traces/score`, {
|
|
2541
|
+
method: "POST",
|
|
2542
|
+
body: { ...params }
|
|
2543
|
+
});
|
|
2544
|
+
}
|
|
2687
2545
|
};
|
|
2688
2546
|
|
|
2689
2547
|
// src/resources/network-memory-thread.ts
|
|
@@ -2750,7 +2608,7 @@ var NetworkMemoryThread = class extends BaseResource {
|
|
|
2750
2608
|
};
|
|
2751
2609
|
|
|
2752
2610
|
// src/resources/vNextNetwork.ts
|
|
2753
|
-
var
|
|
2611
|
+
var RECORD_SEPARATOR3 = "";
|
|
2754
2612
|
var VNextNetwork = class extends BaseResource {
|
|
2755
2613
|
constructor(options, networkId) {
|
|
2756
2614
|
super(options);
|
|
@@ -2758,10 +2616,11 @@ var VNextNetwork = class extends BaseResource {
|
|
|
2758
2616
|
}
|
|
2759
2617
|
/**
|
|
2760
2618
|
* Retrieves details about the network
|
|
2619
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2761
2620
|
* @returns Promise containing vNext network details
|
|
2762
2621
|
*/
|
|
2763
|
-
details() {
|
|
2764
|
-
return this.request(`/api/networks/v-next/${this.networkId}`);
|
|
2622
|
+
details(runtimeContext) {
|
|
2623
|
+
return this.request(`/api/networks/v-next/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
|
|
2765
2624
|
}
|
|
2766
2625
|
/**
|
|
2767
2626
|
* Generates a response from the v-next network
|
|
@@ -2802,7 +2661,7 @@ var VNextNetwork = class extends BaseResource {
|
|
|
2802
2661
|
if (done && !value) continue;
|
|
2803
2662
|
try {
|
|
2804
2663
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2805
|
-
const chunks = (buffer + decoded).split(
|
|
2664
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
2806
2665
|
buffer = chunks.pop() || "";
|
|
2807
2666
|
for (const chunk of chunks) {
|
|
2808
2667
|
if (chunk) {
|
|
@@ -2896,25 +2755,17 @@ var MastraClient = class extends BaseResource {
|
|
|
2896
2755
|
}
|
|
2897
2756
|
/**
|
|
2898
2757
|
* Retrieves all available agents
|
|
2758
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2899
2759
|
* @returns Promise containing map of agent IDs to agent details
|
|
2900
2760
|
*/
|
|
2901
|
-
getAgents() {
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
acc[agentId] = new AGUIAdapter({
|
|
2910
|
-
agentId,
|
|
2911
|
-
agent,
|
|
2912
|
-
resourceId
|
|
2913
|
-
});
|
|
2914
|
-
return acc;
|
|
2915
|
-
},
|
|
2916
|
-
{}
|
|
2917
|
-
);
|
|
2761
|
+
getAgents(runtimeContext) {
|
|
2762
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2763
|
+
const searchParams = new URLSearchParams();
|
|
2764
|
+
if (runtimeContextParam) {
|
|
2765
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2766
|
+
}
|
|
2767
|
+
const queryString = searchParams.toString();
|
|
2768
|
+
return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
|
|
2918
2769
|
}
|
|
2919
2770
|
/**
|
|
2920
2771
|
* Gets an agent instance by ID
|
|
@@ -2932,6 +2783,14 @@ var MastraClient = class extends BaseResource {
|
|
|
2932
2783
|
getMemoryThreads(params) {
|
|
2933
2784
|
return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
|
|
2934
2785
|
}
|
|
2786
|
+
/**
|
|
2787
|
+
* Retrieves memory config for a resource
|
|
2788
|
+
* @param params - Parameters containing the resource ID
|
|
2789
|
+
* @returns Promise containing array of memory threads
|
|
2790
|
+
*/
|
|
2791
|
+
getMemoryConfig(params) {
|
|
2792
|
+
return this.request(`/api/memory/config?agentId=${params.agentId}`);
|
|
2793
|
+
}
|
|
2935
2794
|
/**
|
|
2936
2795
|
* Creates a new memory thread
|
|
2937
2796
|
* @param params - Parameters for creating the memory thread
|
|
@@ -2948,6 +2807,24 @@ var MastraClient = class extends BaseResource {
|
|
|
2948
2807
|
getMemoryThread(threadId, agentId) {
|
|
2949
2808
|
return new MemoryThread(this.options, threadId, agentId);
|
|
2950
2809
|
}
|
|
2810
|
+
getThreadMessages(threadId, opts = {}) {
|
|
2811
|
+
let url = "";
|
|
2812
|
+
if (opts.agentId) {
|
|
2813
|
+
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
|
|
2814
|
+
} else if (opts.networkId) {
|
|
2815
|
+
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
|
|
2816
|
+
}
|
|
2817
|
+
return this.request(url);
|
|
2818
|
+
}
|
|
2819
|
+
deleteThread(threadId, opts = {}) {
|
|
2820
|
+
let url = "";
|
|
2821
|
+
if (opts.agentId) {
|
|
2822
|
+
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
|
|
2823
|
+
} else if (opts.networkId) {
|
|
2824
|
+
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
|
|
2825
|
+
}
|
|
2826
|
+
return this.request(url, { method: "DELETE" });
|
|
2827
|
+
}
|
|
2951
2828
|
/**
|
|
2952
2829
|
* Saves messages to memory
|
|
2953
2830
|
* @param params - Parameters containing messages to save
|
|
@@ -3010,10 +2887,17 @@ var MastraClient = class extends BaseResource {
|
|
|
3010
2887
|
}
|
|
3011
2888
|
/**
|
|
3012
2889
|
* Retrieves all available tools
|
|
2890
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
3013
2891
|
* @returns Promise containing map of tool IDs to tool details
|
|
3014
2892
|
*/
|
|
3015
|
-
getTools() {
|
|
3016
|
-
|
|
2893
|
+
getTools(runtimeContext) {
|
|
2894
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2895
|
+
const searchParams = new URLSearchParams();
|
|
2896
|
+
if (runtimeContextParam) {
|
|
2897
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2898
|
+
}
|
|
2899
|
+
const queryString = searchParams.toString();
|
|
2900
|
+
return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
|
|
3017
2901
|
}
|
|
3018
2902
|
/**
|
|
3019
2903
|
* Gets a tool instance by ID
|
|
@@ -3023,27 +2907,19 @@ var MastraClient = class extends BaseResource {
|
|
|
3023
2907
|
getTool(toolId) {
|
|
3024
2908
|
return new Tool(this.options, toolId);
|
|
3025
2909
|
}
|
|
3026
|
-
/**
|
|
3027
|
-
* Retrieves all available legacy workflows
|
|
3028
|
-
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
3029
|
-
*/
|
|
3030
|
-
getLegacyWorkflows() {
|
|
3031
|
-
return this.request("/api/workflows/legacy");
|
|
3032
|
-
}
|
|
3033
|
-
/**
|
|
3034
|
-
* Gets a legacy workflow instance by ID
|
|
3035
|
-
* @param workflowId - ID of the legacy workflow to retrieve
|
|
3036
|
-
* @returns Legacy Workflow instance
|
|
3037
|
-
*/
|
|
3038
|
-
getLegacyWorkflow(workflowId) {
|
|
3039
|
-
return new LegacyWorkflow(this.options, workflowId);
|
|
3040
|
-
}
|
|
3041
2910
|
/**
|
|
3042
2911
|
* Retrieves all available workflows
|
|
2912
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
3043
2913
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
3044
2914
|
*/
|
|
3045
|
-
getWorkflows() {
|
|
3046
|
-
|
|
2915
|
+
getWorkflows(runtimeContext) {
|
|
2916
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2917
|
+
const searchParams = new URLSearchParams();
|
|
2918
|
+
if (runtimeContextParam) {
|
|
2919
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2920
|
+
}
|
|
2921
|
+
const queryString = searchParams.toString();
|
|
2922
|
+
return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
|
|
3047
2923
|
}
|
|
3048
2924
|
/**
|
|
3049
2925
|
* Gets a workflow instance by ID
|
|
@@ -3211,13 +3087,6 @@ var MastraClient = class extends BaseResource {
|
|
|
3211
3087
|
return this.request(`/api/telemetry`);
|
|
3212
3088
|
}
|
|
3213
3089
|
}
|
|
3214
|
-
/**
|
|
3215
|
-
* Retrieves all available networks
|
|
3216
|
-
* @returns Promise containing map of network IDs to network details
|
|
3217
|
-
*/
|
|
3218
|
-
getNetworks() {
|
|
3219
|
-
return this.request("/api/networks");
|
|
3220
|
-
}
|
|
3221
3090
|
/**
|
|
3222
3091
|
* Retrieves all available vNext networks
|
|
3223
3092
|
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
@@ -3225,14 +3094,6 @@ var MastraClient = class extends BaseResource {
|
|
|
3225
3094
|
getVNextNetworks() {
|
|
3226
3095
|
return this.request("/api/networks/v-next");
|
|
3227
3096
|
}
|
|
3228
|
-
/**
|
|
3229
|
-
* Gets a network instance by ID
|
|
3230
|
-
* @param networkId - ID of the network to retrieve
|
|
3231
|
-
* @returns Network instance
|
|
3232
|
-
*/
|
|
3233
|
-
getNetwork(networkId) {
|
|
3234
|
-
return new Network(this.options, networkId);
|
|
3235
|
-
}
|
|
3236
3097
|
/**
|
|
3237
3098
|
* Gets a vNext network instance by ID
|
|
3238
3099
|
* @param networkId - ID of the vNext network to retrieve
|
|
@@ -3423,8 +3284,32 @@ var MastraClient = class extends BaseResource {
|
|
|
3423
3284
|
getAITraces(params) {
|
|
3424
3285
|
return this.observability.getTraces(params);
|
|
3425
3286
|
}
|
|
3287
|
+
score(params) {
|
|
3288
|
+
return this.observability.score(params);
|
|
3289
|
+
}
|
|
3426
3290
|
};
|
|
3427
3291
|
|
|
3292
|
+
// src/tools.ts
|
|
3293
|
+
var ClientTool = class {
|
|
3294
|
+
id;
|
|
3295
|
+
description;
|
|
3296
|
+
inputSchema;
|
|
3297
|
+
outputSchema;
|
|
3298
|
+
execute;
|
|
3299
|
+
constructor(opts) {
|
|
3300
|
+
this.id = opts.id;
|
|
3301
|
+
this.description = opts.description;
|
|
3302
|
+
this.inputSchema = opts.inputSchema;
|
|
3303
|
+
this.outputSchema = opts.outputSchema;
|
|
3304
|
+
this.execute = opts.execute;
|
|
3305
|
+
}
|
|
3306
|
+
};
|
|
3307
|
+
function createTool(opts) {
|
|
3308
|
+
return new ClientTool(opts);
|
|
3309
|
+
}
|
|
3310
|
+
|
|
3311
|
+
exports.ClientTool = ClientTool;
|
|
3428
3312
|
exports.MastraClient = MastraClient;
|
|
3313
|
+
exports.createTool = createTool;
|
|
3429
3314
|
//# sourceMappingURL=index.cjs.map
|
|
3430
3315
|
//# sourceMappingURL=index.cjs.map
|