@mastra/client-js 0.0.0-message-ordering-20250415215612 → 0.0.0-mssql-store-20250804200341
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +1399 -3
- package/LICENSE.md +11 -42
- package/README.md +2 -1
- package/dist/adapters/agui.d.ts +23 -0
- package/dist/adapters/agui.d.ts.map +1 -0
- package/dist/client.d.ts +265 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/example.d.ts +2 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/index.cjs +1775 -86
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -585
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1775 -90
- package/dist/index.js.map +1 -0
- package/dist/resources/a2a.d.ts +44 -0
- package/dist/resources/a2a.d.ts.map +1 -0
- package/dist/resources/agent.d.ts +112 -0
- package/dist/resources/agent.d.ts.map +1 -0
- package/dist/resources/base.d.ts +13 -0
- package/dist/resources/base.d.ts.map +1 -0
- package/dist/resources/index.d.ts +11 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/legacy-workflow.d.ts +87 -0
- package/dist/resources/legacy-workflow.d.ts.map +1 -0
- package/dist/resources/mcp-tool.d.ts +27 -0
- package/dist/resources/mcp-tool.d.ts.map +1 -0
- package/dist/resources/memory-thread.d.ts +53 -0
- package/dist/resources/memory-thread.d.ts.map +1 -0
- package/dist/resources/network-memory-thread.d.ts +47 -0
- package/dist/resources/network-memory-thread.d.ts.map +1 -0
- package/dist/resources/network.d.ts +30 -0
- package/dist/resources/network.d.ts.map +1 -0
- package/dist/resources/tool.d.ts +23 -0
- package/dist/resources/tool.d.ts.map +1 -0
- package/dist/resources/vNextNetwork.d.ts +42 -0
- package/dist/resources/vNextNetwork.d.ts.map +1 -0
- package/dist/resources/vector.d.ts +48 -0
- package/dist/resources/vector.d.ts.map +1 -0
- package/dist/resources/workflow.d.ts +154 -0
- package/dist/resources/workflow.d.ts.map +1 -0
- package/dist/types.d.ts +422 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/process-client-tools.d.ts +3 -0
- package/dist/utils/process-client-tools.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema.d.ts +105 -0
- package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
- package/integration-tests/agui-adapter.test.ts +122 -0
- package/integration-tests/package.json +18 -0
- package/integration-tests/src/mastra/index.ts +35 -0
- package/integration-tests/vitest.config.ts +9 -0
- package/package.json +31 -17
- package/src/adapters/agui.test.ts +322 -0
- package/src/adapters/agui.ts +239 -0
- package/src/client.ts +414 -14
- package/src/example.ts +59 -29
- package/src/index.test.ts +526 -10
- package/src/index.ts +1 -0
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +629 -49
- package/src/resources/base.ts +8 -2
- package/src/resources/index.ts +4 -1
- package/src/resources/legacy-workflow.ts +242 -0
- package/src/resources/mcp-tool.ts +48 -0
- package/src/resources/memory-thread.test.ts +285 -0
- package/src/resources/memory-thread.ts +44 -5
- package/src/resources/network-memory-thread.test.ts +269 -0
- package/src/resources/network-memory-thread.ts +81 -0
- package/src/resources/network.ts +11 -17
- package/src/resources/tool.ts +16 -3
- package/src/resources/vNextNetwork.ts +194 -0
- package/src/resources/workflow.ts +289 -94
- package/src/types.ts +300 -22
- package/src/utils/index.ts +11 -0
- package/src/utils/process-client-tools.ts +32 -0
- package/src/utils/zod-to-json-schema.ts +10 -0
- package/src/v2-messages.test.ts +180 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +1 -1
- package/tsup.config.ts +22 -0
- package/dist/index.d.cts +0 -585
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,236 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var client = require('@ag-ui/client');
|
|
4
|
+
var rxjs = require('rxjs');
|
|
5
5
|
var uiUtils = require('@ai-sdk/ui-utils');
|
|
6
|
+
var zod = require('zod');
|
|
7
|
+
var originalZodToJsonSchema = require('zod-to-json-schema');
|
|
8
|
+
var isVercelTool = require('@mastra/core/tools/is-vercel-tool');
|
|
9
|
+
var uuid = require('@lukeed/uuid');
|
|
10
|
+
var runtimeContext = require('@mastra/core/runtime-context');
|
|
11
|
+
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
|
|
14
|
+
var originalZodToJsonSchema__default = /*#__PURE__*/_interopDefault(originalZodToJsonSchema);
|
|
6
15
|
|
|
7
|
-
// src/
|
|
16
|
+
// src/adapters/agui.ts
|
|
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
|
+
for (const message of messages) {
|
|
155
|
+
if (message.role === "assistant") {
|
|
156
|
+
const parts = message.content ? [{ type: "text", text: message.content }] : [];
|
|
157
|
+
for (const toolCall of message.toolCalls ?? []) {
|
|
158
|
+
parts.push({
|
|
159
|
+
type: "tool-call",
|
|
160
|
+
toolCallId: toolCall.id,
|
|
161
|
+
toolName: toolCall.function.name,
|
|
162
|
+
args: JSON.parse(toolCall.function.arguments)
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
result.push({
|
|
166
|
+
role: "assistant",
|
|
167
|
+
content: parts
|
|
168
|
+
});
|
|
169
|
+
if (message.toolCalls?.length) {
|
|
170
|
+
result.push({
|
|
171
|
+
role: "tool",
|
|
172
|
+
content: message.toolCalls.map((toolCall) => ({
|
|
173
|
+
type: "tool-result",
|
|
174
|
+
toolCallId: toolCall.id,
|
|
175
|
+
toolName: toolCall.function.name,
|
|
176
|
+
result: JSON.parse(toolCall.function.arguments)
|
|
177
|
+
}))
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
} else if (message.role === "user") {
|
|
181
|
+
result.push({
|
|
182
|
+
role: "user",
|
|
183
|
+
content: message.content || ""
|
|
184
|
+
});
|
|
185
|
+
} else if (message.role === "tool") {
|
|
186
|
+
result.push({
|
|
187
|
+
role: "tool",
|
|
188
|
+
content: [
|
|
189
|
+
{
|
|
190
|
+
type: "tool-result",
|
|
191
|
+
toolCallId: message.toolCallId,
|
|
192
|
+
toolName: "unknown",
|
|
193
|
+
result: message.content
|
|
194
|
+
}
|
|
195
|
+
]
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return result;
|
|
200
|
+
}
|
|
201
|
+
function zodToJsonSchema(zodSchema) {
|
|
202
|
+
if (!(zodSchema instanceof zod.ZodSchema)) {
|
|
203
|
+
return zodSchema;
|
|
204
|
+
}
|
|
205
|
+
return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "none" });
|
|
206
|
+
}
|
|
207
|
+
function processClientTools(clientTools) {
|
|
208
|
+
if (!clientTools) {
|
|
209
|
+
return void 0;
|
|
210
|
+
}
|
|
211
|
+
return Object.fromEntries(
|
|
212
|
+
Object.entries(clientTools).map(([key, value]) => {
|
|
213
|
+
if (isVercelTool.isVercelTool(value)) {
|
|
214
|
+
return [
|
|
215
|
+
key,
|
|
216
|
+
{
|
|
217
|
+
...value,
|
|
218
|
+
parameters: value.parameters ? zodToJsonSchema(value.parameters) : void 0
|
|
219
|
+
}
|
|
220
|
+
];
|
|
221
|
+
} else {
|
|
222
|
+
return [
|
|
223
|
+
key,
|
|
224
|
+
{
|
|
225
|
+
...value,
|
|
226
|
+
inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : void 0,
|
|
227
|
+
outputSchema: value.outputSchema ? zodToJsonSchema(value.outputSchema) : void 0
|
|
228
|
+
}
|
|
229
|
+
];
|
|
230
|
+
}
|
|
231
|
+
})
|
|
232
|
+
);
|
|
233
|
+
}
|
|
8
234
|
|
|
9
235
|
// src/resources/base.ts
|
|
10
236
|
var BaseResource = class {
|
|
@@ -24,14 +250,16 @@ var BaseResource = class {
|
|
|
24
250
|
let delay = backoffMs;
|
|
25
251
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
26
252
|
try {
|
|
27
|
-
const response = await fetch(`${baseUrl}${path}`, {
|
|
253
|
+
const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
|
|
28
254
|
...options,
|
|
29
255
|
headers: {
|
|
256
|
+
...options.body && !(options.body instanceof FormData) && (options.method === "POST" || options.method === "PUT") ? { "content-type": "application/json" } : {},
|
|
30
257
|
...headers,
|
|
31
258
|
...options.headers
|
|
32
259
|
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
|
33
260
|
// 'x-mastra-client-type': 'js',
|
|
34
261
|
},
|
|
262
|
+
signal: this.options.abortSignal,
|
|
35
263
|
body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
|
|
36
264
|
});
|
|
37
265
|
if (!response.ok) {
|
|
@@ -64,8 +292,15 @@ var BaseResource = class {
|
|
|
64
292
|
throw lastError || new Error("Request failed");
|
|
65
293
|
}
|
|
66
294
|
};
|
|
67
|
-
|
|
68
|
-
|
|
295
|
+
function parseClientRuntimeContext(runtimeContext$1) {
|
|
296
|
+
if (runtimeContext$1) {
|
|
297
|
+
if (runtimeContext$1 instanceof runtimeContext.RuntimeContext) {
|
|
298
|
+
return Object.fromEntries(runtimeContext$1.entries());
|
|
299
|
+
}
|
|
300
|
+
return runtimeContext$1;
|
|
301
|
+
}
|
|
302
|
+
return void 0;
|
|
303
|
+
}
|
|
69
304
|
var AgentVoice = class extends BaseResource {
|
|
70
305
|
constructor(options, agentId) {
|
|
71
306
|
super(options);
|
|
@@ -112,6 +347,13 @@ var AgentVoice = class extends BaseResource {
|
|
|
112
347
|
getSpeakers() {
|
|
113
348
|
return this.request(`/api/agents/${this.agentId}/voice/speakers`);
|
|
114
349
|
}
|
|
350
|
+
/**
|
|
351
|
+
* Get the listener configuration for the agent's voice provider
|
|
352
|
+
* @returns Promise containing a check if the agent has listening capabilities
|
|
353
|
+
*/
|
|
354
|
+
getListener() {
|
|
355
|
+
return this.request(`/api/agents/${this.agentId}/voice/listener`);
|
|
356
|
+
}
|
|
115
357
|
};
|
|
116
358
|
var Agent = class extends BaseResource {
|
|
117
359
|
constructor(options, agentId) {
|
|
@@ -127,21 +369,325 @@ var Agent = class extends BaseResource {
|
|
|
127
369
|
details() {
|
|
128
370
|
return this.request(`/api/agents/${this.agentId}`);
|
|
129
371
|
}
|
|
130
|
-
|
|
131
|
-
* Generates a response from the agent
|
|
132
|
-
* @param params - Generation parameters including prompt
|
|
133
|
-
* @returns Promise containing the generated response
|
|
134
|
-
*/
|
|
135
|
-
generate(params) {
|
|
372
|
+
async generate(params) {
|
|
136
373
|
const processedParams = {
|
|
137
374
|
...params,
|
|
138
|
-
output: params.output
|
|
139
|
-
experimental_output: params.experimental_output
|
|
375
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
376
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
377
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
378
|
+
clientTools: processClientTools(params.clientTools)
|
|
140
379
|
};
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
380
|
+
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
381
|
+
const response = await this.request(
|
|
382
|
+
`/api/agents/${this.agentId}/generate`,
|
|
383
|
+
{
|
|
384
|
+
method: "POST",
|
|
385
|
+
body: processedParams
|
|
386
|
+
}
|
|
387
|
+
);
|
|
388
|
+
if (response.finishReason === "tool-calls") {
|
|
389
|
+
const toolCalls = response.toolCalls;
|
|
390
|
+
if (!toolCalls || !Array.isArray(toolCalls)) {
|
|
391
|
+
return response;
|
|
392
|
+
}
|
|
393
|
+
for (const toolCall of toolCalls) {
|
|
394
|
+
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
395
|
+
if (clientTool && clientTool.execute) {
|
|
396
|
+
const result = await clientTool.execute(
|
|
397
|
+
{ context: toolCall?.args, runId, resourceId, threadId, runtimeContext },
|
|
398
|
+
{
|
|
399
|
+
messages: response.messages,
|
|
400
|
+
toolCallId: toolCall?.toolCallId
|
|
401
|
+
}
|
|
402
|
+
);
|
|
403
|
+
const updatedMessages = [
|
|
404
|
+
{
|
|
405
|
+
role: "user",
|
|
406
|
+
content: params.messages
|
|
407
|
+
},
|
|
408
|
+
...response.response.messages,
|
|
409
|
+
{
|
|
410
|
+
role: "tool",
|
|
411
|
+
content: [
|
|
412
|
+
{
|
|
413
|
+
type: "tool-result",
|
|
414
|
+
toolCallId: toolCall.toolCallId,
|
|
415
|
+
toolName: toolCall.toolName,
|
|
416
|
+
result
|
|
417
|
+
}
|
|
418
|
+
]
|
|
419
|
+
}
|
|
420
|
+
];
|
|
421
|
+
return this.generate({
|
|
422
|
+
...params,
|
|
423
|
+
messages: updatedMessages
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return response;
|
|
429
|
+
}
|
|
430
|
+
async processChatResponse({
|
|
431
|
+
stream,
|
|
432
|
+
update,
|
|
433
|
+
onToolCall,
|
|
434
|
+
onFinish,
|
|
435
|
+
getCurrentDate = () => /* @__PURE__ */ new Date(),
|
|
436
|
+
lastMessage
|
|
437
|
+
}) {
|
|
438
|
+
const replaceLastMessage = lastMessage?.role === "assistant";
|
|
439
|
+
let step = replaceLastMessage ? 1 + // find max step in existing tool invocations:
|
|
440
|
+
(lastMessage.toolInvocations?.reduce((max, toolInvocation) => {
|
|
441
|
+
return Math.max(max, toolInvocation.step ?? 0);
|
|
442
|
+
}, 0) ?? 0) : 0;
|
|
443
|
+
const message = replaceLastMessage ? structuredClone(lastMessage) : {
|
|
444
|
+
id: uuid.v4(),
|
|
445
|
+
createdAt: getCurrentDate(),
|
|
446
|
+
role: "assistant",
|
|
447
|
+
content: "",
|
|
448
|
+
parts: []
|
|
449
|
+
};
|
|
450
|
+
let currentTextPart = void 0;
|
|
451
|
+
let currentReasoningPart = void 0;
|
|
452
|
+
let currentReasoningTextDetail = void 0;
|
|
453
|
+
function updateToolInvocationPart(toolCallId, invocation) {
|
|
454
|
+
const part = message.parts.find(
|
|
455
|
+
(part2) => part2.type === "tool-invocation" && part2.toolInvocation.toolCallId === toolCallId
|
|
456
|
+
);
|
|
457
|
+
if (part != null) {
|
|
458
|
+
part.toolInvocation = invocation;
|
|
459
|
+
} else {
|
|
460
|
+
message.parts.push({
|
|
461
|
+
type: "tool-invocation",
|
|
462
|
+
toolInvocation: invocation
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
const data = [];
|
|
467
|
+
let messageAnnotations = replaceLastMessage ? lastMessage?.annotations : void 0;
|
|
468
|
+
const partialToolCalls = {};
|
|
469
|
+
let usage = {
|
|
470
|
+
completionTokens: NaN,
|
|
471
|
+
promptTokens: NaN,
|
|
472
|
+
totalTokens: NaN
|
|
473
|
+
};
|
|
474
|
+
let finishReason = "unknown";
|
|
475
|
+
function execUpdate() {
|
|
476
|
+
const copiedData = [...data];
|
|
477
|
+
if (messageAnnotations?.length) {
|
|
478
|
+
message.annotations = messageAnnotations;
|
|
479
|
+
}
|
|
480
|
+
const copiedMessage = {
|
|
481
|
+
// deep copy the message to ensure that deep changes (msg attachments) are updated
|
|
482
|
+
// with SolidJS. SolidJS uses referential integration of sub-objects to detect changes.
|
|
483
|
+
...structuredClone(message),
|
|
484
|
+
// add a revision id to ensure that the message is updated with SWR. SWR uses a
|
|
485
|
+
// hashing approach by default to detect changes, but it only works for shallow
|
|
486
|
+
// changes. This is why we need to add a revision id to ensure that the message
|
|
487
|
+
// is updated with SWR (without it, the changes get stuck in SWR and are not
|
|
488
|
+
// forwarded to rendering):
|
|
489
|
+
revisionId: uuid.v4()
|
|
490
|
+
};
|
|
491
|
+
update({
|
|
492
|
+
message: copiedMessage,
|
|
493
|
+
data: copiedData,
|
|
494
|
+
replaceLastMessage
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
await uiUtils.processDataStream({
|
|
498
|
+
stream,
|
|
499
|
+
onTextPart(value) {
|
|
500
|
+
if (currentTextPart == null) {
|
|
501
|
+
currentTextPart = {
|
|
502
|
+
type: "text",
|
|
503
|
+
text: value
|
|
504
|
+
};
|
|
505
|
+
message.parts.push(currentTextPart);
|
|
506
|
+
} else {
|
|
507
|
+
currentTextPart.text += value;
|
|
508
|
+
}
|
|
509
|
+
message.content += value;
|
|
510
|
+
execUpdate();
|
|
511
|
+
},
|
|
512
|
+
onReasoningPart(value) {
|
|
513
|
+
if (currentReasoningTextDetail == null) {
|
|
514
|
+
currentReasoningTextDetail = { type: "text", text: value };
|
|
515
|
+
if (currentReasoningPart != null) {
|
|
516
|
+
currentReasoningPart.details.push(currentReasoningTextDetail);
|
|
517
|
+
}
|
|
518
|
+
} else {
|
|
519
|
+
currentReasoningTextDetail.text += value;
|
|
520
|
+
}
|
|
521
|
+
if (currentReasoningPart == null) {
|
|
522
|
+
currentReasoningPart = {
|
|
523
|
+
type: "reasoning",
|
|
524
|
+
reasoning: value,
|
|
525
|
+
details: [currentReasoningTextDetail]
|
|
526
|
+
};
|
|
527
|
+
message.parts.push(currentReasoningPart);
|
|
528
|
+
} else {
|
|
529
|
+
currentReasoningPart.reasoning += value;
|
|
530
|
+
}
|
|
531
|
+
message.reasoning = (message.reasoning ?? "") + value;
|
|
532
|
+
execUpdate();
|
|
533
|
+
},
|
|
534
|
+
onReasoningSignaturePart(value) {
|
|
535
|
+
if (currentReasoningTextDetail != null) {
|
|
536
|
+
currentReasoningTextDetail.signature = value.signature;
|
|
537
|
+
}
|
|
538
|
+
},
|
|
539
|
+
onRedactedReasoningPart(value) {
|
|
540
|
+
if (currentReasoningPart == null) {
|
|
541
|
+
currentReasoningPart = {
|
|
542
|
+
type: "reasoning",
|
|
543
|
+
reasoning: "",
|
|
544
|
+
details: []
|
|
545
|
+
};
|
|
546
|
+
message.parts.push(currentReasoningPart);
|
|
547
|
+
}
|
|
548
|
+
currentReasoningPart.details.push({
|
|
549
|
+
type: "redacted",
|
|
550
|
+
data: value.data
|
|
551
|
+
});
|
|
552
|
+
currentReasoningTextDetail = void 0;
|
|
553
|
+
execUpdate();
|
|
554
|
+
},
|
|
555
|
+
onFilePart(value) {
|
|
556
|
+
message.parts.push({
|
|
557
|
+
type: "file",
|
|
558
|
+
mimeType: value.mimeType,
|
|
559
|
+
data: value.data
|
|
560
|
+
});
|
|
561
|
+
execUpdate();
|
|
562
|
+
},
|
|
563
|
+
onSourcePart(value) {
|
|
564
|
+
message.parts.push({
|
|
565
|
+
type: "source",
|
|
566
|
+
source: value
|
|
567
|
+
});
|
|
568
|
+
execUpdate();
|
|
569
|
+
},
|
|
570
|
+
onToolCallStreamingStartPart(value) {
|
|
571
|
+
if (message.toolInvocations == null) {
|
|
572
|
+
message.toolInvocations = [];
|
|
573
|
+
}
|
|
574
|
+
partialToolCalls[value.toolCallId] = {
|
|
575
|
+
text: "",
|
|
576
|
+
step,
|
|
577
|
+
toolName: value.toolName,
|
|
578
|
+
index: message.toolInvocations.length
|
|
579
|
+
};
|
|
580
|
+
const invocation = {
|
|
581
|
+
state: "partial-call",
|
|
582
|
+
step,
|
|
583
|
+
toolCallId: value.toolCallId,
|
|
584
|
+
toolName: value.toolName,
|
|
585
|
+
args: void 0
|
|
586
|
+
};
|
|
587
|
+
message.toolInvocations.push(invocation);
|
|
588
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
589
|
+
execUpdate();
|
|
590
|
+
},
|
|
591
|
+
onToolCallDeltaPart(value) {
|
|
592
|
+
const partialToolCall = partialToolCalls[value.toolCallId];
|
|
593
|
+
partialToolCall.text += value.argsTextDelta;
|
|
594
|
+
const { value: partialArgs } = uiUtils.parsePartialJson(partialToolCall.text);
|
|
595
|
+
const invocation = {
|
|
596
|
+
state: "partial-call",
|
|
597
|
+
step: partialToolCall.step,
|
|
598
|
+
toolCallId: value.toolCallId,
|
|
599
|
+
toolName: partialToolCall.toolName,
|
|
600
|
+
args: partialArgs
|
|
601
|
+
};
|
|
602
|
+
message.toolInvocations[partialToolCall.index] = invocation;
|
|
603
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
604
|
+
execUpdate();
|
|
605
|
+
},
|
|
606
|
+
async onToolCallPart(value) {
|
|
607
|
+
const invocation = {
|
|
608
|
+
state: "call",
|
|
609
|
+
step,
|
|
610
|
+
...value
|
|
611
|
+
};
|
|
612
|
+
if (partialToolCalls[value.toolCallId] != null) {
|
|
613
|
+
message.toolInvocations[partialToolCalls[value.toolCallId].index] = invocation;
|
|
614
|
+
} else {
|
|
615
|
+
if (message.toolInvocations == null) {
|
|
616
|
+
message.toolInvocations = [];
|
|
617
|
+
}
|
|
618
|
+
message.toolInvocations.push(invocation);
|
|
619
|
+
}
|
|
620
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
621
|
+
execUpdate();
|
|
622
|
+
if (onToolCall) {
|
|
623
|
+
const result = await onToolCall({ toolCall: value });
|
|
624
|
+
if (result != null) {
|
|
625
|
+
const invocation2 = {
|
|
626
|
+
state: "result",
|
|
627
|
+
step,
|
|
628
|
+
...value,
|
|
629
|
+
result
|
|
630
|
+
};
|
|
631
|
+
message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
|
|
632
|
+
updateToolInvocationPart(value.toolCallId, invocation2);
|
|
633
|
+
execUpdate();
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
},
|
|
637
|
+
onToolResultPart(value) {
|
|
638
|
+
const toolInvocations = message.toolInvocations;
|
|
639
|
+
if (toolInvocations == null) {
|
|
640
|
+
throw new Error("tool_result must be preceded by a tool_call");
|
|
641
|
+
}
|
|
642
|
+
const toolInvocationIndex = toolInvocations.findIndex((invocation2) => invocation2.toolCallId === value.toolCallId);
|
|
643
|
+
if (toolInvocationIndex === -1) {
|
|
644
|
+
throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
|
|
645
|
+
}
|
|
646
|
+
const invocation = {
|
|
647
|
+
...toolInvocations[toolInvocationIndex],
|
|
648
|
+
state: "result",
|
|
649
|
+
...value
|
|
650
|
+
};
|
|
651
|
+
toolInvocations[toolInvocationIndex] = invocation;
|
|
652
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
653
|
+
execUpdate();
|
|
654
|
+
},
|
|
655
|
+
onDataPart(value) {
|
|
656
|
+
data.push(...value);
|
|
657
|
+
execUpdate();
|
|
658
|
+
},
|
|
659
|
+
onMessageAnnotationsPart(value) {
|
|
660
|
+
if (messageAnnotations == null) {
|
|
661
|
+
messageAnnotations = [...value];
|
|
662
|
+
} else {
|
|
663
|
+
messageAnnotations.push(...value);
|
|
664
|
+
}
|
|
665
|
+
execUpdate();
|
|
666
|
+
},
|
|
667
|
+
onFinishStepPart(value) {
|
|
668
|
+
step += 1;
|
|
669
|
+
currentTextPart = value.isContinued ? currentTextPart : void 0;
|
|
670
|
+
currentReasoningPart = void 0;
|
|
671
|
+
currentReasoningTextDetail = void 0;
|
|
672
|
+
},
|
|
673
|
+
onStartStepPart(value) {
|
|
674
|
+
if (!replaceLastMessage) {
|
|
675
|
+
message.id = value.messageId;
|
|
676
|
+
}
|
|
677
|
+
message.parts.push({ type: "step-start" });
|
|
678
|
+
execUpdate();
|
|
679
|
+
},
|
|
680
|
+
onFinishMessagePart(value) {
|
|
681
|
+
finishReason = value.finishReason;
|
|
682
|
+
if (value.usage != null) {
|
|
683
|
+
usage = value.usage;
|
|
684
|
+
}
|
|
685
|
+
},
|
|
686
|
+
onErrorPart(error) {
|
|
687
|
+
throw new Error(error);
|
|
688
|
+
}
|
|
144
689
|
});
|
|
690
|
+
onFinish?.({ message, finishReason, usage });
|
|
145
691
|
}
|
|
146
692
|
/**
|
|
147
693
|
* Streams a response from the agent
|
|
@@ -151,9 +697,30 @@ var Agent = class extends BaseResource {
|
|
|
151
697
|
async stream(params) {
|
|
152
698
|
const processedParams = {
|
|
153
699
|
...params,
|
|
154
|
-
output: params.output
|
|
155
|
-
experimental_output: params.experimental_output
|
|
700
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
701
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
702
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
703
|
+
clientTools: processClientTools(params.clientTools)
|
|
704
|
+
};
|
|
705
|
+
const { readable, writable } = new TransformStream();
|
|
706
|
+
const response = await this.processStreamResponse(processedParams, writable);
|
|
707
|
+
const streamResponse = new Response(readable, {
|
|
708
|
+
status: response.status,
|
|
709
|
+
statusText: response.statusText,
|
|
710
|
+
headers: response.headers
|
|
711
|
+
});
|
|
712
|
+
streamResponse.processDataStream = async (options = {}) => {
|
|
713
|
+
await uiUtils.processDataStream({
|
|
714
|
+
stream: streamResponse.body,
|
|
715
|
+
...options
|
|
716
|
+
});
|
|
156
717
|
};
|
|
718
|
+
return streamResponse;
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Processes the stream response and handles tool calls
|
|
722
|
+
*/
|
|
723
|
+
async processStreamResponse(processedParams, writable) {
|
|
157
724
|
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
158
725
|
method: "POST",
|
|
159
726
|
body: processedParams,
|
|
@@ -162,12 +729,104 @@ var Agent = class extends BaseResource {
|
|
|
162
729
|
if (!response.body) {
|
|
163
730
|
throw new Error("No response body");
|
|
164
731
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
732
|
+
try {
|
|
733
|
+
let toolCalls = [];
|
|
734
|
+
let messages = [];
|
|
735
|
+
const [streamForWritable, streamForProcessing] = response.body.tee();
|
|
736
|
+
streamForWritable.pipeTo(writable, {
|
|
737
|
+
preventClose: true
|
|
738
|
+
}).catch((error) => {
|
|
739
|
+
console.error("Error piping to writable stream:", error);
|
|
169
740
|
});
|
|
170
|
-
|
|
741
|
+
this.processChatResponse({
|
|
742
|
+
stream: streamForProcessing,
|
|
743
|
+
update: ({ message }) => {
|
|
744
|
+
const existingIndex = messages.findIndex((m) => m.id === message.id);
|
|
745
|
+
if (existingIndex !== -1) {
|
|
746
|
+
messages[existingIndex] = message;
|
|
747
|
+
} else {
|
|
748
|
+
messages.push(message);
|
|
749
|
+
}
|
|
750
|
+
},
|
|
751
|
+
onFinish: async ({ finishReason, message }) => {
|
|
752
|
+
if (finishReason === "tool-calls") {
|
|
753
|
+
const toolCall = [...message?.parts ?? []].reverse().find((part) => part.type === "tool-invocation")?.toolInvocation;
|
|
754
|
+
if (toolCall) {
|
|
755
|
+
toolCalls.push(toolCall);
|
|
756
|
+
}
|
|
757
|
+
for (const toolCall2 of toolCalls) {
|
|
758
|
+
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
759
|
+
if (clientTool && clientTool.execute) {
|
|
760
|
+
const result = await clientTool.execute(
|
|
761
|
+
{
|
|
762
|
+
context: toolCall2?.args,
|
|
763
|
+
runId: processedParams.runId,
|
|
764
|
+
resourceId: processedParams.resourceId,
|
|
765
|
+
threadId: processedParams.threadId,
|
|
766
|
+
runtimeContext: processedParams.runtimeContext
|
|
767
|
+
},
|
|
768
|
+
{
|
|
769
|
+
messages: response.messages,
|
|
770
|
+
toolCallId: toolCall2?.toolCallId
|
|
771
|
+
}
|
|
772
|
+
);
|
|
773
|
+
const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
|
|
774
|
+
const toolInvocationPart = lastMessage?.parts?.find(
|
|
775
|
+
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
776
|
+
);
|
|
777
|
+
if (toolInvocationPart) {
|
|
778
|
+
toolInvocationPart.toolInvocation = {
|
|
779
|
+
...toolInvocationPart.toolInvocation,
|
|
780
|
+
state: "result",
|
|
781
|
+
result
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
const toolInvocation = lastMessage?.toolInvocations?.find(
|
|
785
|
+
(toolInvocation2) => toolInvocation2.toolCallId === toolCall2.toolCallId
|
|
786
|
+
);
|
|
787
|
+
if (toolInvocation) {
|
|
788
|
+
toolInvocation.state = "result";
|
|
789
|
+
toolInvocation.result = result;
|
|
790
|
+
}
|
|
791
|
+
const writer = writable.getWriter();
|
|
792
|
+
try {
|
|
793
|
+
await writer.write(
|
|
794
|
+
new TextEncoder().encode(
|
|
795
|
+
"a:" + JSON.stringify({
|
|
796
|
+
toolCallId: toolCall2.toolCallId,
|
|
797
|
+
result
|
|
798
|
+
}) + "\n"
|
|
799
|
+
)
|
|
800
|
+
);
|
|
801
|
+
} finally {
|
|
802
|
+
writer.releaseLock();
|
|
803
|
+
}
|
|
804
|
+
const originalMessages = processedParams.messages;
|
|
805
|
+
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
806
|
+
this.processStreamResponse(
|
|
807
|
+
{
|
|
808
|
+
...processedParams,
|
|
809
|
+
messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
|
|
810
|
+
},
|
|
811
|
+
writable
|
|
812
|
+
).catch((error) => {
|
|
813
|
+
console.error("Error processing stream response:", error);
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
} else {
|
|
818
|
+
setTimeout(() => {
|
|
819
|
+
writable.close();
|
|
820
|
+
}, 0);
|
|
821
|
+
}
|
|
822
|
+
},
|
|
823
|
+
lastMessage: void 0
|
|
824
|
+
}).catch((error) => {
|
|
825
|
+
console.error("Error processing stream response:", error);
|
|
826
|
+
});
|
|
827
|
+
} catch (error) {
|
|
828
|
+
console.error("Error processing stream response:", error);
|
|
829
|
+
}
|
|
171
830
|
return response;
|
|
172
831
|
}
|
|
173
832
|
/**
|
|
@@ -178,6 +837,22 @@ var Agent = class extends BaseResource {
|
|
|
178
837
|
getTool(toolId) {
|
|
179
838
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
180
839
|
}
|
|
840
|
+
/**
|
|
841
|
+
* Executes a tool for the agent
|
|
842
|
+
* @param toolId - ID of the tool to execute
|
|
843
|
+
* @param params - Parameters required for tool execution
|
|
844
|
+
* @returns Promise containing the tool execution results
|
|
845
|
+
*/
|
|
846
|
+
executeTool(toolId, params) {
|
|
847
|
+
const body = {
|
|
848
|
+
data: params.data,
|
|
849
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
850
|
+
};
|
|
851
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
852
|
+
method: "POST",
|
|
853
|
+
body
|
|
854
|
+
});
|
|
855
|
+
}
|
|
181
856
|
/**
|
|
182
857
|
* Retrieves evaluation results for the agent
|
|
183
858
|
* @returns Promise containing agent evaluations
|
|
@@ -213,8 +888,8 @@ var Network = class extends BaseResource {
|
|
|
213
888
|
generate(params) {
|
|
214
889
|
const processedParams = {
|
|
215
890
|
...params,
|
|
216
|
-
output:
|
|
217
|
-
experimental_output:
|
|
891
|
+
output: zodToJsonSchema(params.output),
|
|
892
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
218
893
|
};
|
|
219
894
|
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
220
895
|
method: "POST",
|
|
@@ -229,8 +904,8 @@ var Network = class extends BaseResource {
|
|
|
229
904
|
async stream(params) {
|
|
230
905
|
const processedParams = {
|
|
231
906
|
...params,
|
|
232
|
-
output:
|
|
233
|
-
experimental_output:
|
|
907
|
+
output: zodToJsonSchema(params.output),
|
|
908
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
234
909
|
};
|
|
235
910
|
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
236
911
|
method: "POST",
|
|
@@ -286,10 +961,45 @@ var MemoryThread = class extends BaseResource {
|
|
|
286
961
|
}
|
|
287
962
|
/**
|
|
288
963
|
* Retrieves messages associated with the thread
|
|
964
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
289
965
|
* @returns Promise containing thread messages and UI messages
|
|
290
966
|
*/
|
|
291
|
-
getMessages() {
|
|
292
|
-
|
|
967
|
+
getMessages(params) {
|
|
968
|
+
const query = new URLSearchParams({
|
|
969
|
+
agentId: this.agentId,
|
|
970
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
971
|
+
});
|
|
972
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* Retrieves paginated messages associated with the thread with advanced filtering and selection options
|
|
976
|
+
* @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
|
|
977
|
+
* @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
|
|
978
|
+
*/
|
|
979
|
+
getMessagesPaginated({
|
|
980
|
+
selectBy,
|
|
981
|
+
...rest
|
|
982
|
+
}) {
|
|
983
|
+
const query = new URLSearchParams({
|
|
984
|
+
...rest,
|
|
985
|
+
...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
|
|
986
|
+
});
|
|
987
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
|
|
988
|
+
}
|
|
989
|
+
/**
|
|
990
|
+
* Deletes one or more messages from the thread
|
|
991
|
+
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
992
|
+
* message object with id property, or array of message objects
|
|
993
|
+
* @returns Promise containing deletion result
|
|
994
|
+
*/
|
|
995
|
+
deleteMessages(messageIds) {
|
|
996
|
+
const query = new URLSearchParams({
|
|
997
|
+
agentId: this.agentId
|
|
998
|
+
});
|
|
999
|
+
return this.request(`/api/memory/messages/delete?${query.toString()}`, {
|
|
1000
|
+
method: "POST",
|
|
1001
|
+
body: { messageIds }
|
|
1002
|
+
});
|
|
293
1003
|
}
|
|
294
1004
|
};
|
|
295
1005
|
|
|
@@ -359,34 +1069,50 @@ var Vector = class extends BaseResource {
|
|
|
359
1069
|
}
|
|
360
1070
|
};
|
|
361
1071
|
|
|
362
|
-
// src/resources/workflow.ts
|
|
1072
|
+
// src/resources/legacy-workflow.ts
|
|
363
1073
|
var RECORD_SEPARATOR = "";
|
|
364
|
-
var
|
|
1074
|
+
var LegacyWorkflow = class extends BaseResource {
|
|
365
1075
|
constructor(options, workflowId) {
|
|
366
1076
|
super(options);
|
|
367
1077
|
this.workflowId = workflowId;
|
|
368
1078
|
}
|
|
369
1079
|
/**
|
|
370
|
-
* Retrieves details about the workflow
|
|
371
|
-
* @returns Promise containing workflow details including steps and graphs
|
|
1080
|
+
* Retrieves details about the legacy workflow
|
|
1081
|
+
* @returns Promise containing legacy workflow details including steps and graphs
|
|
372
1082
|
*/
|
|
373
1083
|
details() {
|
|
374
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
1084
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}`);
|
|
375
1085
|
}
|
|
376
1086
|
/**
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
* @
|
|
380
|
-
* @returns Promise containing the workflow execution results
|
|
1087
|
+
* Retrieves all runs for a legacy workflow
|
|
1088
|
+
* @param params - Parameters for filtering runs
|
|
1089
|
+
* @returns Promise containing legacy workflow runs array
|
|
381
1090
|
*/
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
}
|
|
1091
|
+
runs(params) {
|
|
1092
|
+
const searchParams = new URLSearchParams();
|
|
1093
|
+
if (params?.fromDate) {
|
|
1094
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
1095
|
+
}
|
|
1096
|
+
if (params?.toDate) {
|
|
1097
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
1098
|
+
}
|
|
1099
|
+
if (params?.limit) {
|
|
1100
|
+
searchParams.set("limit", String(params.limit));
|
|
1101
|
+
}
|
|
1102
|
+
if (params?.offset) {
|
|
1103
|
+
searchParams.set("offset", String(params.offset));
|
|
1104
|
+
}
|
|
1105
|
+
if (params?.resourceId) {
|
|
1106
|
+
searchParams.set("resourceId", params.resourceId);
|
|
1107
|
+
}
|
|
1108
|
+
if (searchParams.size) {
|
|
1109
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
1110
|
+
} else {
|
|
1111
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
1112
|
+
}
|
|
387
1113
|
}
|
|
388
1114
|
/**
|
|
389
|
-
* Creates a new workflow run
|
|
1115
|
+
* Creates a new legacy workflow run
|
|
390
1116
|
* @returns Promise containing the generated run ID
|
|
391
1117
|
*/
|
|
392
1118
|
createRun(params) {
|
|
@@ -394,34 +1120,34 @@ var Workflow = class extends BaseResource {
|
|
|
394
1120
|
if (!!params?.runId) {
|
|
395
1121
|
searchParams.set("runId", params.runId);
|
|
396
1122
|
}
|
|
397
|
-
return this.request(`/api/workflows/${this.workflowId}/
|
|
1123
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
398
1124
|
method: "POST"
|
|
399
1125
|
});
|
|
400
1126
|
}
|
|
401
1127
|
/**
|
|
402
|
-
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1128
|
+
* Starts a legacy workflow run synchronously without waiting for the workflow to complete
|
|
403
1129
|
* @param params - Object containing the runId and triggerData
|
|
404
1130
|
* @returns Promise containing success message
|
|
405
1131
|
*/
|
|
406
1132
|
start(params) {
|
|
407
|
-
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1133
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
408
1134
|
method: "POST",
|
|
409
1135
|
body: params?.triggerData
|
|
410
1136
|
});
|
|
411
1137
|
}
|
|
412
1138
|
/**
|
|
413
|
-
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
1139
|
+
* Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
|
|
414
1140
|
* @param stepId - ID of the step to resume
|
|
415
|
-
* @param runId - ID of the workflow run
|
|
416
|
-
* @param context - Context to resume the workflow with
|
|
417
|
-
* @returns Promise containing the workflow resume results
|
|
1141
|
+
* @param runId - ID of the legacy workflow run
|
|
1142
|
+
* @param context - Context to resume the legacy workflow with
|
|
1143
|
+
* @returns Promise containing the legacy workflow resume results
|
|
418
1144
|
*/
|
|
419
1145
|
resume({
|
|
420
1146
|
stepId,
|
|
421
1147
|
runId,
|
|
422
1148
|
context
|
|
423
1149
|
}) {
|
|
424
|
-
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1150
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
425
1151
|
method: "POST",
|
|
426
1152
|
body: {
|
|
427
1153
|
stepId,
|
|
@@ -439,18 +1165,18 @@ var Workflow = class extends BaseResource {
|
|
|
439
1165
|
if (!!params?.runId) {
|
|
440
1166
|
searchParams.set("runId", params.runId);
|
|
441
1167
|
}
|
|
442
|
-
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1168
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
443
1169
|
method: "POST",
|
|
444
1170
|
body: params?.triggerData
|
|
445
1171
|
});
|
|
446
1172
|
}
|
|
447
1173
|
/**
|
|
448
|
-
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
1174
|
+
* Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
449
1175
|
* @param params - Object containing the runId, stepId, and context
|
|
450
1176
|
* @returns Promise containing the workflow resume results
|
|
451
1177
|
*/
|
|
452
1178
|
resumeAsync(params) {
|
|
453
|
-
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
1179
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
454
1180
|
method: "POST",
|
|
455
1181
|
body: {
|
|
456
1182
|
stepId: params.stepId,
|
|
@@ -489,7 +1215,7 @@ var Workflow = class extends BaseResource {
|
|
|
489
1215
|
}
|
|
490
1216
|
}
|
|
491
1217
|
}
|
|
492
|
-
} catch
|
|
1218
|
+
} catch {
|
|
493
1219
|
}
|
|
494
1220
|
}
|
|
495
1221
|
if (buffer) {
|
|
@@ -504,16 +1230,16 @@ var Workflow = class extends BaseResource {
|
|
|
504
1230
|
}
|
|
505
1231
|
}
|
|
506
1232
|
/**
|
|
507
|
-
* Watches workflow transitions in real-time
|
|
1233
|
+
* Watches legacy workflow transitions in real-time
|
|
508
1234
|
* @param runId - Optional run ID to filter the watch stream
|
|
509
|
-
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
1235
|
+
* @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
|
|
510
1236
|
*/
|
|
511
1237
|
async watch({ runId }, onRecord) {
|
|
512
|
-
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
1238
|
+
const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
|
|
513
1239
|
stream: true
|
|
514
1240
|
});
|
|
515
1241
|
if (!response.ok) {
|
|
516
|
-
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
1242
|
+
throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
|
|
517
1243
|
}
|
|
518
1244
|
if (!response.body) {
|
|
519
1245
|
throw new Error("Response body is null");
|
|
@@ -525,7 +1251,7 @@ var Workflow = class extends BaseResource {
|
|
|
525
1251
|
};
|
|
526
1252
|
|
|
527
1253
|
// src/resources/tool.ts
|
|
528
|
-
var
|
|
1254
|
+
var Tool2 = class extends BaseResource {
|
|
529
1255
|
constructor(options, toolId) {
|
|
530
1256
|
super(options);
|
|
531
1257
|
this.toolId = toolId;
|
|
@@ -543,41 +1269,684 @@ var Tool = class extends BaseResource {
|
|
|
543
1269
|
* @returns Promise containing the tool execution results
|
|
544
1270
|
*/
|
|
545
1271
|
execute(params) {
|
|
546
|
-
|
|
1272
|
+
const url = new URLSearchParams();
|
|
1273
|
+
if (params.runId) {
|
|
1274
|
+
url.set("runId", params.runId);
|
|
1275
|
+
}
|
|
1276
|
+
const body = {
|
|
1277
|
+
data: params.data,
|
|
1278
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1279
|
+
};
|
|
1280
|
+
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
547
1281
|
method: "POST",
|
|
548
|
-
body
|
|
1282
|
+
body
|
|
549
1283
|
});
|
|
550
1284
|
}
|
|
551
1285
|
};
|
|
552
1286
|
|
|
553
|
-
// src/
|
|
554
|
-
var
|
|
555
|
-
|
|
1287
|
+
// src/resources/workflow.ts
|
|
1288
|
+
var RECORD_SEPARATOR2 = "";
|
|
1289
|
+
var Workflow = class extends BaseResource {
|
|
1290
|
+
constructor(options, workflowId) {
|
|
556
1291
|
super(options);
|
|
1292
|
+
this.workflowId = workflowId;
|
|
557
1293
|
}
|
|
558
1294
|
/**
|
|
559
|
-
*
|
|
560
|
-
*
|
|
1295
|
+
* Creates an async generator that processes a readable stream and yields workflow records
|
|
1296
|
+
* separated by the Record Separator character (\x1E)
|
|
1297
|
+
*
|
|
1298
|
+
* @param stream - The readable stream to process
|
|
1299
|
+
* @returns An async generator that yields parsed records
|
|
561
1300
|
*/
|
|
562
|
-
|
|
563
|
-
|
|
1301
|
+
async *streamProcessor(stream) {
|
|
1302
|
+
const reader = stream.getReader();
|
|
1303
|
+
let doneReading = false;
|
|
1304
|
+
let buffer = "";
|
|
1305
|
+
try {
|
|
1306
|
+
while (!doneReading) {
|
|
1307
|
+
const { done, value } = await reader.read();
|
|
1308
|
+
doneReading = done;
|
|
1309
|
+
if (done && !value) continue;
|
|
1310
|
+
try {
|
|
1311
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1312
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
1313
|
+
buffer = chunks.pop() || "";
|
|
1314
|
+
for (const chunk of chunks) {
|
|
1315
|
+
if (chunk) {
|
|
1316
|
+
if (typeof chunk === "string") {
|
|
1317
|
+
try {
|
|
1318
|
+
const parsedChunk = JSON.parse(chunk);
|
|
1319
|
+
yield parsedChunk;
|
|
1320
|
+
} catch {
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
} catch {
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
if (buffer) {
|
|
1329
|
+
try {
|
|
1330
|
+
yield JSON.parse(buffer);
|
|
1331
|
+
} catch {
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
} finally {
|
|
1335
|
+
reader.cancel().catch(() => {
|
|
1336
|
+
});
|
|
1337
|
+
}
|
|
564
1338
|
}
|
|
565
1339
|
/**
|
|
566
|
-
*
|
|
567
|
-
* @
|
|
568
|
-
* @returns Agent instance
|
|
1340
|
+
* Retrieves details about the workflow
|
|
1341
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
569
1342
|
*/
|
|
570
|
-
|
|
571
|
-
return
|
|
1343
|
+
details() {
|
|
1344
|
+
return this.request(`/api/workflows/${this.workflowId}`);
|
|
572
1345
|
}
|
|
573
1346
|
/**
|
|
574
|
-
* Retrieves
|
|
575
|
-
* @param params - Parameters
|
|
576
|
-
* @returns Promise containing
|
|
1347
|
+
* Retrieves all runs for a workflow
|
|
1348
|
+
* @param params - Parameters for filtering runs
|
|
1349
|
+
* @returns Promise containing workflow runs array
|
|
577
1350
|
*/
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
1351
|
+
runs(params) {
|
|
1352
|
+
const searchParams = new URLSearchParams();
|
|
1353
|
+
if (params?.fromDate) {
|
|
1354
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
1355
|
+
}
|
|
1356
|
+
if (params?.toDate) {
|
|
1357
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
1358
|
+
}
|
|
1359
|
+
if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
|
|
1360
|
+
searchParams.set("limit", String(params.limit));
|
|
1361
|
+
}
|
|
1362
|
+
if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
|
|
1363
|
+
searchParams.set("offset", String(params.offset));
|
|
1364
|
+
}
|
|
1365
|
+
if (params?.resourceId) {
|
|
1366
|
+
searchParams.set("resourceId", params.resourceId);
|
|
1367
|
+
}
|
|
1368
|
+
if (searchParams.size) {
|
|
1369
|
+
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
1370
|
+
} else {
|
|
1371
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
/**
|
|
1375
|
+
* Retrieves a specific workflow run by its ID
|
|
1376
|
+
* @param runId - The ID of the workflow run to retrieve
|
|
1377
|
+
* @returns Promise containing the workflow run details
|
|
1378
|
+
*/
|
|
1379
|
+
runById(runId) {
|
|
1380
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
|
|
1381
|
+
}
|
|
1382
|
+
/**
|
|
1383
|
+
* Retrieves the execution result for a specific workflow run by its ID
|
|
1384
|
+
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1385
|
+
* @returns Promise containing the workflow run execution result
|
|
1386
|
+
*/
|
|
1387
|
+
runExecutionResult(runId) {
|
|
1388
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* Cancels a specific workflow run by its ID
|
|
1392
|
+
* @param runId - The ID of the workflow run to cancel
|
|
1393
|
+
* @returns Promise containing a success message
|
|
1394
|
+
*/
|
|
1395
|
+
cancelRun(runId) {
|
|
1396
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/cancel`, {
|
|
1397
|
+
method: "POST"
|
|
1398
|
+
});
|
|
1399
|
+
}
|
|
1400
|
+
/**
|
|
1401
|
+
* Sends an event to a specific workflow run by its ID
|
|
1402
|
+
* @param params - Object containing the runId, event and data
|
|
1403
|
+
* @returns Promise containing a success message
|
|
1404
|
+
*/
|
|
1405
|
+
sendRunEvent(params) {
|
|
1406
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
|
|
1407
|
+
method: "POST",
|
|
1408
|
+
body: { event: params.event, data: params.data }
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1411
|
+
/**
|
|
1412
|
+
* Creates a new workflow run
|
|
1413
|
+
* @param params - Optional object containing the optional runId
|
|
1414
|
+
* @returns Promise containing the runId of the created run
|
|
1415
|
+
*/
|
|
1416
|
+
createRun(params) {
|
|
1417
|
+
const searchParams = new URLSearchParams();
|
|
1418
|
+
if (!!params?.runId) {
|
|
1419
|
+
searchParams.set("runId", params.runId);
|
|
1420
|
+
}
|
|
1421
|
+
return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
1422
|
+
method: "POST"
|
|
1423
|
+
});
|
|
1424
|
+
}
|
|
1425
|
+
/**
|
|
1426
|
+
* Creates a new workflow run (alias for createRun)
|
|
1427
|
+
* @param params - Optional object containing the optional runId
|
|
1428
|
+
* @returns Promise containing the runId of the created run
|
|
1429
|
+
*/
|
|
1430
|
+
createRunAsync(params) {
|
|
1431
|
+
return this.createRun(params);
|
|
1432
|
+
}
|
|
1433
|
+
/**
|
|
1434
|
+
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1435
|
+
* @param params - Object containing the runId, inputData and runtimeContext
|
|
1436
|
+
* @returns Promise containing success message
|
|
1437
|
+
*/
|
|
1438
|
+
start(params) {
|
|
1439
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1440
|
+
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1441
|
+
method: "POST",
|
|
1442
|
+
body: { inputData: params?.inputData, runtimeContext }
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
/**
|
|
1446
|
+
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
1447
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
1448
|
+
* @returns Promise containing success message
|
|
1449
|
+
*/
|
|
1450
|
+
resume({
|
|
1451
|
+
step,
|
|
1452
|
+
runId,
|
|
1453
|
+
resumeData,
|
|
1454
|
+
...rest
|
|
1455
|
+
}) {
|
|
1456
|
+
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
1457
|
+
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1458
|
+
method: "POST",
|
|
1459
|
+
stream: true,
|
|
1460
|
+
body: {
|
|
1461
|
+
step,
|
|
1462
|
+
resumeData,
|
|
1463
|
+
runtimeContext
|
|
1464
|
+
}
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
/**
|
|
1468
|
+
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
1469
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
1470
|
+
* @returns Promise containing the workflow execution results
|
|
1471
|
+
*/
|
|
1472
|
+
startAsync(params) {
|
|
1473
|
+
const searchParams = new URLSearchParams();
|
|
1474
|
+
if (!!params?.runId) {
|
|
1475
|
+
searchParams.set("runId", params.runId);
|
|
1476
|
+
}
|
|
1477
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1478
|
+
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1479
|
+
method: "POST",
|
|
1480
|
+
body: { inputData: params.inputData, runtimeContext }
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
/**
|
|
1484
|
+
* Starts a workflow run and returns a stream
|
|
1485
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
1486
|
+
* @returns Promise containing the workflow execution results
|
|
1487
|
+
*/
|
|
1488
|
+
async stream(params) {
|
|
1489
|
+
const searchParams = new URLSearchParams();
|
|
1490
|
+
if (!!params?.runId) {
|
|
1491
|
+
searchParams.set("runId", params.runId);
|
|
1492
|
+
}
|
|
1493
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1494
|
+
const response = await this.request(
|
|
1495
|
+
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1496
|
+
{
|
|
1497
|
+
method: "POST",
|
|
1498
|
+
body: { inputData: params.inputData, runtimeContext },
|
|
1499
|
+
stream: true
|
|
1500
|
+
}
|
|
1501
|
+
);
|
|
1502
|
+
if (!response.ok) {
|
|
1503
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
1504
|
+
}
|
|
1505
|
+
if (!response.body) {
|
|
1506
|
+
throw new Error("Response body is null");
|
|
1507
|
+
}
|
|
1508
|
+
let failedChunk = void 0;
|
|
1509
|
+
const transformStream = new TransformStream({
|
|
1510
|
+
start() {
|
|
1511
|
+
},
|
|
1512
|
+
async transform(chunk, controller) {
|
|
1513
|
+
try {
|
|
1514
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1515
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
1516
|
+
for (const chunk2 of chunks) {
|
|
1517
|
+
if (chunk2) {
|
|
1518
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1519
|
+
try {
|
|
1520
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1521
|
+
controller.enqueue(parsedChunk);
|
|
1522
|
+
failedChunk = void 0;
|
|
1523
|
+
} catch (error) {
|
|
1524
|
+
failedChunk = newChunk;
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
} catch {
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
});
|
|
1532
|
+
return response.body.pipeThrough(transformStream);
|
|
1533
|
+
}
|
|
1534
|
+
/**
|
|
1535
|
+
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
1536
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
1537
|
+
* @returns Promise containing the workflow resume results
|
|
1538
|
+
*/
|
|
1539
|
+
resumeAsync(params) {
|
|
1540
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1541
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
1542
|
+
method: "POST",
|
|
1543
|
+
body: {
|
|
1544
|
+
step: params.step,
|
|
1545
|
+
resumeData: params.resumeData,
|
|
1546
|
+
runtimeContext
|
|
1547
|
+
}
|
|
1548
|
+
});
|
|
1549
|
+
}
|
|
1550
|
+
/**
|
|
1551
|
+
* Watches workflow transitions in real-time
|
|
1552
|
+
* @param runId - Optional run ID to filter the watch stream
|
|
1553
|
+
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
1554
|
+
*/
|
|
1555
|
+
async watch({ runId }, onRecord) {
|
|
1556
|
+
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
1557
|
+
stream: true
|
|
1558
|
+
});
|
|
1559
|
+
if (!response.ok) {
|
|
1560
|
+
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
1561
|
+
}
|
|
1562
|
+
if (!response.body) {
|
|
1563
|
+
throw new Error("Response body is null");
|
|
1564
|
+
}
|
|
1565
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
1566
|
+
if (typeof record === "string") {
|
|
1567
|
+
onRecord(JSON.parse(record));
|
|
1568
|
+
} else {
|
|
1569
|
+
onRecord(record);
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
/**
|
|
1574
|
+
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
1575
|
+
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
1576
|
+
*
|
|
1577
|
+
* @param records - An iterable or async iterable of objects to stream
|
|
1578
|
+
* @returns A ReadableStream emitting the records as JSON strings separated by the record separator
|
|
1579
|
+
*/
|
|
1580
|
+
static createRecordStream(records) {
|
|
1581
|
+
const encoder = new TextEncoder();
|
|
1582
|
+
return new ReadableStream({
|
|
1583
|
+
async start(controller) {
|
|
1584
|
+
try {
|
|
1585
|
+
for await (const record of records) {
|
|
1586
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR2;
|
|
1587
|
+
controller.enqueue(encoder.encode(json));
|
|
1588
|
+
}
|
|
1589
|
+
controller.close();
|
|
1590
|
+
} catch (err) {
|
|
1591
|
+
controller.error(err);
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
});
|
|
1595
|
+
}
|
|
1596
|
+
};
|
|
1597
|
+
|
|
1598
|
+
// src/resources/a2a.ts
|
|
1599
|
+
var A2A = class extends BaseResource {
|
|
1600
|
+
constructor(options, agentId) {
|
|
1601
|
+
super(options);
|
|
1602
|
+
this.agentId = agentId;
|
|
1603
|
+
}
|
|
1604
|
+
/**
|
|
1605
|
+
* Get the agent card with metadata about the agent
|
|
1606
|
+
* @returns Promise containing the agent card information
|
|
1607
|
+
*/
|
|
1608
|
+
async getCard() {
|
|
1609
|
+
return this.request(`/.well-known/${this.agentId}/agent.json`);
|
|
1610
|
+
}
|
|
1611
|
+
/**
|
|
1612
|
+
* Send a message to the agent and get a response
|
|
1613
|
+
* @param params - Parameters for the task
|
|
1614
|
+
* @returns Promise containing the task response
|
|
1615
|
+
*/
|
|
1616
|
+
async sendMessage(params) {
|
|
1617
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1618
|
+
method: "POST",
|
|
1619
|
+
body: {
|
|
1620
|
+
method: "tasks/send",
|
|
1621
|
+
params
|
|
1622
|
+
}
|
|
1623
|
+
});
|
|
1624
|
+
return { task: response.result };
|
|
1625
|
+
}
|
|
1626
|
+
/**
|
|
1627
|
+
* Get the status and result of a task
|
|
1628
|
+
* @param params - Parameters for querying the task
|
|
1629
|
+
* @returns Promise containing the task response
|
|
1630
|
+
*/
|
|
1631
|
+
async getTask(params) {
|
|
1632
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1633
|
+
method: "POST",
|
|
1634
|
+
body: {
|
|
1635
|
+
method: "tasks/get",
|
|
1636
|
+
params
|
|
1637
|
+
}
|
|
1638
|
+
});
|
|
1639
|
+
return response.result;
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1642
|
+
* Cancel a running task
|
|
1643
|
+
* @param params - Parameters identifying the task to cancel
|
|
1644
|
+
* @returns Promise containing the task response
|
|
1645
|
+
*/
|
|
1646
|
+
async cancelTask(params) {
|
|
1647
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
1648
|
+
method: "POST",
|
|
1649
|
+
body: {
|
|
1650
|
+
method: "tasks/cancel",
|
|
1651
|
+
params
|
|
1652
|
+
}
|
|
1653
|
+
});
|
|
1654
|
+
}
|
|
1655
|
+
/**
|
|
1656
|
+
* Send a message and subscribe to streaming updates (not fully implemented)
|
|
1657
|
+
* @param params - Parameters for the task
|
|
1658
|
+
* @returns Promise containing the task response
|
|
1659
|
+
*/
|
|
1660
|
+
async sendAndSubscribe(params) {
|
|
1661
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
1662
|
+
method: "POST",
|
|
1663
|
+
body: {
|
|
1664
|
+
method: "tasks/sendSubscribe",
|
|
1665
|
+
params
|
|
1666
|
+
},
|
|
1667
|
+
stream: true
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
};
|
|
1671
|
+
|
|
1672
|
+
// src/resources/mcp-tool.ts
|
|
1673
|
+
var MCPTool = class extends BaseResource {
|
|
1674
|
+
serverId;
|
|
1675
|
+
toolId;
|
|
1676
|
+
constructor(options, serverId, toolId) {
|
|
1677
|
+
super(options);
|
|
1678
|
+
this.serverId = serverId;
|
|
1679
|
+
this.toolId = toolId;
|
|
1680
|
+
}
|
|
1681
|
+
/**
|
|
1682
|
+
* Retrieves details about this specific tool from the MCP server.
|
|
1683
|
+
* @returns Promise containing the tool's information (name, description, schema).
|
|
1684
|
+
*/
|
|
1685
|
+
details() {
|
|
1686
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
1687
|
+
}
|
|
1688
|
+
/**
|
|
1689
|
+
* Executes this specific tool on the MCP server.
|
|
1690
|
+
* @param params - Parameters for tool execution, including data/args and optional runtimeContext.
|
|
1691
|
+
* @returns Promise containing the result of the tool execution.
|
|
1692
|
+
*/
|
|
1693
|
+
execute(params) {
|
|
1694
|
+
const body = {};
|
|
1695
|
+
if (params.data !== void 0) body.data = params.data;
|
|
1696
|
+
if (params.runtimeContext !== void 0) {
|
|
1697
|
+
body.runtimeContext = params.runtimeContext;
|
|
1698
|
+
}
|
|
1699
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
|
|
1700
|
+
method: "POST",
|
|
1701
|
+
body: Object.keys(body).length > 0 ? body : void 0
|
|
1702
|
+
});
|
|
1703
|
+
}
|
|
1704
|
+
};
|
|
1705
|
+
|
|
1706
|
+
// src/resources/network-memory-thread.ts
|
|
1707
|
+
var NetworkMemoryThread = class extends BaseResource {
|
|
1708
|
+
constructor(options, threadId, networkId) {
|
|
1709
|
+
super(options);
|
|
1710
|
+
this.threadId = threadId;
|
|
1711
|
+
this.networkId = networkId;
|
|
1712
|
+
}
|
|
1713
|
+
/**
|
|
1714
|
+
* Retrieves the memory thread details
|
|
1715
|
+
* @returns Promise containing thread details including title and metadata
|
|
1716
|
+
*/
|
|
1717
|
+
get() {
|
|
1718
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
1719
|
+
}
|
|
1720
|
+
/**
|
|
1721
|
+
* Updates the memory thread properties
|
|
1722
|
+
* @param params - Update parameters including title and metadata
|
|
1723
|
+
* @returns Promise containing updated thread details
|
|
1724
|
+
*/
|
|
1725
|
+
update(params) {
|
|
1726
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1727
|
+
method: "PATCH",
|
|
1728
|
+
body: params
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
/**
|
|
1732
|
+
* Deletes the memory thread
|
|
1733
|
+
* @returns Promise containing deletion result
|
|
1734
|
+
*/
|
|
1735
|
+
delete() {
|
|
1736
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1737
|
+
method: "DELETE"
|
|
1738
|
+
});
|
|
1739
|
+
}
|
|
1740
|
+
/**
|
|
1741
|
+
* Retrieves messages associated with the thread
|
|
1742
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
1743
|
+
* @returns Promise containing thread messages and UI messages
|
|
1744
|
+
*/
|
|
1745
|
+
getMessages(params) {
|
|
1746
|
+
const query = new URLSearchParams({
|
|
1747
|
+
networkId: this.networkId,
|
|
1748
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
1749
|
+
});
|
|
1750
|
+
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
1751
|
+
}
|
|
1752
|
+
/**
|
|
1753
|
+
* Deletes one or more messages from the thread
|
|
1754
|
+
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
1755
|
+
* message object with id property, or array of message objects
|
|
1756
|
+
* @returns Promise containing deletion result
|
|
1757
|
+
*/
|
|
1758
|
+
deleteMessages(messageIds) {
|
|
1759
|
+
const query = new URLSearchParams({
|
|
1760
|
+
networkId: this.networkId
|
|
1761
|
+
});
|
|
1762
|
+
return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
|
|
1763
|
+
method: "POST",
|
|
1764
|
+
body: { messageIds }
|
|
1765
|
+
});
|
|
1766
|
+
}
|
|
1767
|
+
};
|
|
1768
|
+
|
|
1769
|
+
// src/resources/vNextNetwork.ts
|
|
1770
|
+
var RECORD_SEPARATOR3 = "";
|
|
1771
|
+
var VNextNetwork = class extends BaseResource {
|
|
1772
|
+
constructor(options, networkId) {
|
|
1773
|
+
super(options);
|
|
1774
|
+
this.networkId = networkId;
|
|
1775
|
+
}
|
|
1776
|
+
/**
|
|
1777
|
+
* Retrieves details about the network
|
|
1778
|
+
* @returns Promise containing vNext network details
|
|
1779
|
+
*/
|
|
1780
|
+
details() {
|
|
1781
|
+
return this.request(`/api/networks/v-next/${this.networkId}`);
|
|
1782
|
+
}
|
|
1783
|
+
/**
|
|
1784
|
+
* Generates a response from the v-next network
|
|
1785
|
+
* @param params - Generation parameters including message
|
|
1786
|
+
* @returns Promise containing the generated response
|
|
1787
|
+
*/
|
|
1788
|
+
generate(params) {
|
|
1789
|
+
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
1790
|
+
method: "POST",
|
|
1791
|
+
body: {
|
|
1792
|
+
...params,
|
|
1793
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1794
|
+
}
|
|
1795
|
+
});
|
|
1796
|
+
}
|
|
1797
|
+
/**
|
|
1798
|
+
* Generates a response from the v-next network using multiple primitives
|
|
1799
|
+
* @param params - Generation parameters including message
|
|
1800
|
+
* @returns Promise containing the generated response
|
|
1801
|
+
*/
|
|
1802
|
+
loop(params) {
|
|
1803
|
+
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
1804
|
+
method: "POST",
|
|
1805
|
+
body: {
|
|
1806
|
+
...params,
|
|
1807
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1808
|
+
}
|
|
1809
|
+
});
|
|
1810
|
+
}
|
|
1811
|
+
async *streamProcessor(stream) {
|
|
1812
|
+
const reader = stream.getReader();
|
|
1813
|
+
let doneReading = false;
|
|
1814
|
+
let buffer = "";
|
|
1815
|
+
try {
|
|
1816
|
+
while (!doneReading) {
|
|
1817
|
+
const { done, value } = await reader.read();
|
|
1818
|
+
doneReading = done;
|
|
1819
|
+
if (done && !value) continue;
|
|
1820
|
+
try {
|
|
1821
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1822
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
1823
|
+
buffer = chunks.pop() || "";
|
|
1824
|
+
for (const chunk of chunks) {
|
|
1825
|
+
if (chunk) {
|
|
1826
|
+
if (typeof chunk === "string") {
|
|
1827
|
+
try {
|
|
1828
|
+
const parsedChunk = JSON.parse(chunk);
|
|
1829
|
+
yield parsedChunk;
|
|
1830
|
+
} catch {
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
} catch {
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
if (buffer) {
|
|
1839
|
+
try {
|
|
1840
|
+
yield JSON.parse(buffer);
|
|
1841
|
+
} catch {
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
} finally {
|
|
1845
|
+
reader.cancel().catch(() => {
|
|
1846
|
+
});
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
/**
|
|
1850
|
+
* Streams a response from the v-next network
|
|
1851
|
+
* @param params - Stream parameters including message
|
|
1852
|
+
* @returns Promise containing the results
|
|
1853
|
+
*/
|
|
1854
|
+
async stream(params, onRecord) {
|
|
1855
|
+
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
1856
|
+
method: "POST",
|
|
1857
|
+
body: {
|
|
1858
|
+
...params,
|
|
1859
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1860
|
+
},
|
|
1861
|
+
stream: true
|
|
1862
|
+
});
|
|
1863
|
+
if (!response.ok) {
|
|
1864
|
+
throw new Error(`Failed to stream vNext network: ${response.statusText}`);
|
|
1865
|
+
}
|
|
1866
|
+
if (!response.body) {
|
|
1867
|
+
throw new Error("Response body is null");
|
|
1868
|
+
}
|
|
1869
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
1870
|
+
if (typeof record === "string") {
|
|
1871
|
+
onRecord(JSON.parse(record));
|
|
1872
|
+
} else {
|
|
1873
|
+
onRecord(record);
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
/**
|
|
1878
|
+
* Streams a response from the v-next network loop
|
|
1879
|
+
* @param params - Stream parameters including message
|
|
1880
|
+
* @returns Promise containing the results
|
|
1881
|
+
*/
|
|
1882
|
+
async loopStream(params, onRecord) {
|
|
1883
|
+
const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
1884
|
+
method: "POST",
|
|
1885
|
+
body: {
|
|
1886
|
+
...params,
|
|
1887
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1888
|
+
},
|
|
1889
|
+
stream: true
|
|
1890
|
+
});
|
|
1891
|
+
if (!response.ok) {
|
|
1892
|
+
throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
|
|
1893
|
+
}
|
|
1894
|
+
if (!response.body) {
|
|
1895
|
+
throw new Error("Response body is null");
|
|
1896
|
+
}
|
|
1897
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
1898
|
+
if (typeof record === "string") {
|
|
1899
|
+
onRecord(JSON.parse(record));
|
|
1900
|
+
} else {
|
|
1901
|
+
onRecord(record);
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
};
|
|
1906
|
+
|
|
1907
|
+
// src/client.ts
|
|
1908
|
+
var MastraClient = class extends BaseResource {
|
|
1909
|
+
constructor(options) {
|
|
1910
|
+
super(options);
|
|
1911
|
+
}
|
|
1912
|
+
/**
|
|
1913
|
+
* Retrieves all available agents
|
|
1914
|
+
* @returns Promise containing map of agent IDs to agent details
|
|
1915
|
+
*/
|
|
1916
|
+
getAgents() {
|
|
1917
|
+
return this.request("/api/agents");
|
|
1918
|
+
}
|
|
1919
|
+
async getAGUI({ resourceId }) {
|
|
1920
|
+
const agents = await this.getAgents();
|
|
1921
|
+
return Object.entries(agents).reduce(
|
|
1922
|
+
(acc, [agentId]) => {
|
|
1923
|
+
const agent = this.getAgent(agentId);
|
|
1924
|
+
acc[agentId] = new AGUIAdapter({
|
|
1925
|
+
agentId,
|
|
1926
|
+
agent,
|
|
1927
|
+
resourceId
|
|
1928
|
+
});
|
|
1929
|
+
return acc;
|
|
1930
|
+
},
|
|
1931
|
+
{}
|
|
1932
|
+
);
|
|
1933
|
+
}
|
|
1934
|
+
/**
|
|
1935
|
+
* Gets an agent instance by ID
|
|
1936
|
+
* @param agentId - ID of the agent to retrieve
|
|
1937
|
+
* @returns Agent instance
|
|
1938
|
+
*/
|
|
1939
|
+
getAgent(agentId) {
|
|
1940
|
+
return new Agent(this.options, agentId);
|
|
1941
|
+
}
|
|
1942
|
+
/**
|
|
1943
|
+
* Retrieves memory threads for a resource
|
|
1944
|
+
* @param params - Parameters containing the resource ID
|
|
1945
|
+
* @returns Promise containing array of memory threads
|
|
1946
|
+
*/
|
|
1947
|
+
getMemoryThreads(params) {
|
|
1948
|
+
return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
|
|
1949
|
+
}
|
|
581
1950
|
/**
|
|
582
1951
|
* Creates a new memory thread
|
|
583
1952
|
* @param params - Parameters for creating the memory thread
|
|
@@ -612,6 +1981,48 @@ var MastraClient = class extends BaseResource {
|
|
|
612
1981
|
getMemoryStatus(agentId) {
|
|
613
1982
|
return this.request(`/api/memory/status?agentId=${agentId}`);
|
|
614
1983
|
}
|
|
1984
|
+
/**
|
|
1985
|
+
* Retrieves memory threads for a resource
|
|
1986
|
+
* @param params - Parameters containing the resource ID
|
|
1987
|
+
* @returns Promise containing array of memory threads
|
|
1988
|
+
*/
|
|
1989
|
+
getNetworkMemoryThreads(params) {
|
|
1990
|
+
return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
|
|
1991
|
+
}
|
|
1992
|
+
/**
|
|
1993
|
+
* Creates a new memory thread
|
|
1994
|
+
* @param params - Parameters for creating the memory thread
|
|
1995
|
+
* @returns Promise containing the created memory thread
|
|
1996
|
+
*/
|
|
1997
|
+
createNetworkMemoryThread(params) {
|
|
1998
|
+
return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: "POST", body: params });
|
|
1999
|
+
}
|
|
2000
|
+
/**
|
|
2001
|
+
* Gets a memory thread instance by ID
|
|
2002
|
+
* @param threadId - ID of the memory thread to retrieve
|
|
2003
|
+
* @returns MemoryThread instance
|
|
2004
|
+
*/
|
|
2005
|
+
getNetworkMemoryThread(threadId, networkId) {
|
|
2006
|
+
return new NetworkMemoryThread(this.options, threadId, networkId);
|
|
2007
|
+
}
|
|
2008
|
+
/**
|
|
2009
|
+
* Saves messages to memory
|
|
2010
|
+
* @param params - Parameters containing messages to save
|
|
2011
|
+
* @returns Promise containing the saved messages
|
|
2012
|
+
*/
|
|
2013
|
+
saveNetworkMessageToMemory(params) {
|
|
2014
|
+
return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
|
|
2015
|
+
method: "POST",
|
|
2016
|
+
body: params
|
|
2017
|
+
});
|
|
2018
|
+
}
|
|
2019
|
+
/**
|
|
2020
|
+
* Gets the status of the memory system
|
|
2021
|
+
* @returns Promise containing memory system status
|
|
2022
|
+
*/
|
|
2023
|
+
getNetworkMemoryStatus(networkId) {
|
|
2024
|
+
return this.request(`/api/memory/network/status?networkId=${networkId}`);
|
|
2025
|
+
}
|
|
615
2026
|
/**
|
|
616
2027
|
* Retrieves all available tools
|
|
617
2028
|
* @returns Promise containing map of tool IDs to tool details
|
|
@@ -625,7 +2036,22 @@ var MastraClient = class extends BaseResource {
|
|
|
625
2036
|
* @returns Tool instance
|
|
626
2037
|
*/
|
|
627
2038
|
getTool(toolId) {
|
|
628
|
-
return new
|
|
2039
|
+
return new Tool2(this.options, toolId);
|
|
2040
|
+
}
|
|
2041
|
+
/**
|
|
2042
|
+
* Retrieves all available legacy workflows
|
|
2043
|
+
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
2044
|
+
*/
|
|
2045
|
+
getLegacyWorkflows() {
|
|
2046
|
+
return this.request("/api/workflows/legacy");
|
|
2047
|
+
}
|
|
2048
|
+
/**
|
|
2049
|
+
* Gets a legacy workflow instance by ID
|
|
2050
|
+
* @param workflowId - ID of the legacy workflow to retrieve
|
|
2051
|
+
* @returns Legacy Workflow instance
|
|
2052
|
+
*/
|
|
2053
|
+
getLegacyWorkflow(workflowId) {
|
|
2054
|
+
return new LegacyWorkflow(this.options, workflowId);
|
|
629
2055
|
}
|
|
630
2056
|
/**
|
|
631
2057
|
* Retrieves all available workflows
|
|
@@ -656,7 +2082,41 @@ var MastraClient = class extends BaseResource {
|
|
|
656
2082
|
* @returns Promise containing array of log messages
|
|
657
2083
|
*/
|
|
658
2084
|
getLogs(params) {
|
|
659
|
-
|
|
2085
|
+
const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
2086
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
2087
|
+
const searchParams = new URLSearchParams();
|
|
2088
|
+
if (transportId) {
|
|
2089
|
+
searchParams.set("transportId", transportId);
|
|
2090
|
+
}
|
|
2091
|
+
if (fromDate) {
|
|
2092
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
2093
|
+
}
|
|
2094
|
+
if (toDate) {
|
|
2095
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
2096
|
+
}
|
|
2097
|
+
if (logLevel) {
|
|
2098
|
+
searchParams.set("logLevel", logLevel);
|
|
2099
|
+
}
|
|
2100
|
+
if (page) {
|
|
2101
|
+
searchParams.set("page", String(page));
|
|
2102
|
+
}
|
|
2103
|
+
if (perPage) {
|
|
2104
|
+
searchParams.set("perPage", String(perPage));
|
|
2105
|
+
}
|
|
2106
|
+
if (_filters) {
|
|
2107
|
+
if (Array.isArray(_filters)) {
|
|
2108
|
+
for (const filter of _filters) {
|
|
2109
|
+
searchParams.append("filters", filter);
|
|
2110
|
+
}
|
|
2111
|
+
} else {
|
|
2112
|
+
searchParams.set("filters", _filters);
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
if (searchParams.size) {
|
|
2116
|
+
return this.request(`/api/logs?${searchParams}`);
|
|
2117
|
+
} else {
|
|
2118
|
+
return this.request(`/api/logs`);
|
|
2119
|
+
}
|
|
660
2120
|
}
|
|
661
2121
|
/**
|
|
662
2122
|
* Gets logs for a specific run
|
|
@@ -664,7 +2124,44 @@ var MastraClient = class extends BaseResource {
|
|
|
664
2124
|
* @returns Promise containing array of log messages
|
|
665
2125
|
*/
|
|
666
2126
|
getLogForRun(params) {
|
|
667
|
-
|
|
2127
|
+
const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
2128
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
2129
|
+
const searchParams = new URLSearchParams();
|
|
2130
|
+
if (runId) {
|
|
2131
|
+
searchParams.set("runId", runId);
|
|
2132
|
+
}
|
|
2133
|
+
if (transportId) {
|
|
2134
|
+
searchParams.set("transportId", transportId);
|
|
2135
|
+
}
|
|
2136
|
+
if (fromDate) {
|
|
2137
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
2138
|
+
}
|
|
2139
|
+
if (toDate) {
|
|
2140
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
2141
|
+
}
|
|
2142
|
+
if (logLevel) {
|
|
2143
|
+
searchParams.set("logLevel", logLevel);
|
|
2144
|
+
}
|
|
2145
|
+
if (page) {
|
|
2146
|
+
searchParams.set("page", String(page));
|
|
2147
|
+
}
|
|
2148
|
+
if (perPage) {
|
|
2149
|
+
searchParams.set("perPage", String(perPage));
|
|
2150
|
+
}
|
|
2151
|
+
if (_filters) {
|
|
2152
|
+
if (Array.isArray(_filters)) {
|
|
2153
|
+
for (const filter of _filters) {
|
|
2154
|
+
searchParams.append("filters", filter);
|
|
2155
|
+
}
|
|
2156
|
+
} else {
|
|
2157
|
+
searchParams.set("filters", _filters);
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2160
|
+
if (searchParams.size) {
|
|
2161
|
+
return this.request(`/api/logs/${runId}?${searchParams}`);
|
|
2162
|
+
} else {
|
|
2163
|
+
return this.request(`/api/logs/${runId}`);
|
|
2164
|
+
}
|
|
668
2165
|
}
|
|
669
2166
|
/**
|
|
670
2167
|
* List of all log transports
|
|
@@ -679,7 +2176,7 @@ var MastraClient = class extends BaseResource {
|
|
|
679
2176
|
* @returns Promise containing telemetry data
|
|
680
2177
|
*/
|
|
681
2178
|
getTelemetry(params) {
|
|
682
|
-
const { name, scope, page, perPage, attribute } = params || {};
|
|
2179
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
683
2180
|
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
684
2181
|
const searchParams = new URLSearchParams();
|
|
685
2182
|
if (name) {
|
|
@@ -703,6 +2200,12 @@ var MastraClient = class extends BaseResource {
|
|
|
703
2200
|
searchParams.set("attribute", _attribute);
|
|
704
2201
|
}
|
|
705
2202
|
}
|
|
2203
|
+
if (fromDate) {
|
|
2204
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
2205
|
+
}
|
|
2206
|
+
if (toDate) {
|
|
2207
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
2208
|
+
}
|
|
706
2209
|
if (searchParams.size) {
|
|
707
2210
|
return this.request(`/api/telemetry?${searchParams}`);
|
|
708
2211
|
} else {
|
|
@@ -716,6 +2219,13 @@ var MastraClient = class extends BaseResource {
|
|
|
716
2219
|
getNetworks() {
|
|
717
2220
|
return this.request("/api/networks");
|
|
718
2221
|
}
|
|
2222
|
+
/**
|
|
2223
|
+
* Retrieves all available vNext networks
|
|
2224
|
+
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
2225
|
+
*/
|
|
2226
|
+
getVNextNetworks() {
|
|
2227
|
+
return this.request("/api/networks/v-next");
|
|
2228
|
+
}
|
|
719
2229
|
/**
|
|
720
2230
|
* Gets a network instance by ID
|
|
721
2231
|
* @param networkId - ID of the network to retrieve
|
|
@@ -724,6 +2234,185 @@ var MastraClient = class extends BaseResource {
|
|
|
724
2234
|
getNetwork(networkId) {
|
|
725
2235
|
return new Network(this.options, networkId);
|
|
726
2236
|
}
|
|
2237
|
+
/**
|
|
2238
|
+
* Gets a vNext network instance by ID
|
|
2239
|
+
* @param networkId - ID of the vNext network to retrieve
|
|
2240
|
+
* @returns vNext Network instance
|
|
2241
|
+
*/
|
|
2242
|
+
getVNextNetwork(networkId) {
|
|
2243
|
+
return new VNextNetwork(this.options, networkId);
|
|
2244
|
+
}
|
|
2245
|
+
/**
|
|
2246
|
+
* Retrieves a list of available MCP servers.
|
|
2247
|
+
* @param params - Optional parameters for pagination (limit, offset).
|
|
2248
|
+
* @returns Promise containing the list of MCP servers and pagination info.
|
|
2249
|
+
*/
|
|
2250
|
+
getMcpServers(params) {
|
|
2251
|
+
const searchParams = new URLSearchParams();
|
|
2252
|
+
if (params?.limit !== void 0) {
|
|
2253
|
+
searchParams.set("limit", String(params.limit));
|
|
2254
|
+
}
|
|
2255
|
+
if (params?.offset !== void 0) {
|
|
2256
|
+
searchParams.set("offset", String(params.offset));
|
|
2257
|
+
}
|
|
2258
|
+
const queryString = searchParams.toString();
|
|
2259
|
+
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
|
|
2260
|
+
}
|
|
2261
|
+
/**
|
|
2262
|
+
* Retrieves detailed information for a specific MCP server.
|
|
2263
|
+
* @param serverId - The ID of the MCP server to retrieve.
|
|
2264
|
+
* @param params - Optional parameters, e.g., specific version.
|
|
2265
|
+
* @returns Promise containing the detailed MCP server information.
|
|
2266
|
+
*/
|
|
2267
|
+
getMcpServerDetails(serverId, params) {
|
|
2268
|
+
const searchParams = new URLSearchParams();
|
|
2269
|
+
if (params?.version) {
|
|
2270
|
+
searchParams.set("version", params.version);
|
|
2271
|
+
}
|
|
2272
|
+
const queryString = searchParams.toString();
|
|
2273
|
+
return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ""}`);
|
|
2274
|
+
}
|
|
2275
|
+
/**
|
|
2276
|
+
* Retrieves a list of tools for a specific MCP server.
|
|
2277
|
+
* @param serverId - The ID of the MCP server.
|
|
2278
|
+
* @returns Promise containing the list of tools.
|
|
2279
|
+
*/
|
|
2280
|
+
getMcpServerTools(serverId) {
|
|
2281
|
+
return this.request(`/api/mcp/${serverId}/tools`);
|
|
2282
|
+
}
|
|
2283
|
+
/**
|
|
2284
|
+
* Gets an MCPTool resource instance for a specific tool on an MCP server.
|
|
2285
|
+
* This instance can then be used to fetch details or execute the tool.
|
|
2286
|
+
* @param serverId - The ID of the MCP server.
|
|
2287
|
+
* @param toolId - The ID of the tool.
|
|
2288
|
+
* @returns MCPTool instance.
|
|
2289
|
+
*/
|
|
2290
|
+
getMcpServerTool(serverId, toolId) {
|
|
2291
|
+
return new MCPTool(this.options, serverId, toolId);
|
|
2292
|
+
}
|
|
2293
|
+
/**
|
|
2294
|
+
* Gets an A2A client for interacting with an agent via the A2A protocol
|
|
2295
|
+
* @param agentId - ID of the agent to interact with
|
|
2296
|
+
* @returns A2A client instance
|
|
2297
|
+
*/
|
|
2298
|
+
getA2A(agentId) {
|
|
2299
|
+
return new A2A(this.options, agentId);
|
|
2300
|
+
}
|
|
2301
|
+
/**
|
|
2302
|
+
* Retrieves the working memory for a specific thread (optionally resource-scoped).
|
|
2303
|
+
* @param agentId - ID of the agent.
|
|
2304
|
+
* @param threadId - ID of the thread.
|
|
2305
|
+
* @param resourceId - Optional ID of the resource.
|
|
2306
|
+
* @returns Working memory for the specified thread or resource.
|
|
2307
|
+
*/
|
|
2308
|
+
getWorkingMemory({
|
|
2309
|
+
agentId,
|
|
2310
|
+
threadId,
|
|
2311
|
+
resourceId
|
|
2312
|
+
}) {
|
|
2313
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
|
|
2314
|
+
}
|
|
2315
|
+
/**
|
|
2316
|
+
* Updates the working memory for a specific thread (optionally resource-scoped).
|
|
2317
|
+
* @param agentId - ID of the agent.
|
|
2318
|
+
* @param threadId - ID of the thread.
|
|
2319
|
+
* @param workingMemory - The new working memory content.
|
|
2320
|
+
* @param resourceId - Optional ID of the resource.
|
|
2321
|
+
*/
|
|
2322
|
+
updateWorkingMemory({
|
|
2323
|
+
agentId,
|
|
2324
|
+
threadId,
|
|
2325
|
+
workingMemory,
|
|
2326
|
+
resourceId
|
|
2327
|
+
}) {
|
|
2328
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
|
|
2329
|
+
method: "POST",
|
|
2330
|
+
body: {
|
|
2331
|
+
workingMemory,
|
|
2332
|
+
resourceId
|
|
2333
|
+
}
|
|
2334
|
+
});
|
|
2335
|
+
}
|
|
2336
|
+
/**
|
|
2337
|
+
* Retrieves all available scorers
|
|
2338
|
+
* @returns Promise containing list of available scorers
|
|
2339
|
+
*/
|
|
2340
|
+
getScorers() {
|
|
2341
|
+
return this.request("/api/scores/scorers");
|
|
2342
|
+
}
|
|
2343
|
+
/**
|
|
2344
|
+
* Retrieves a scorer by ID
|
|
2345
|
+
* @param scorerId - ID of the scorer to retrieve
|
|
2346
|
+
* @returns Promise containing the scorer
|
|
2347
|
+
*/
|
|
2348
|
+
getScorer(scorerId) {
|
|
2349
|
+
return this.request(`/api/scores/scorers/${scorerId}`);
|
|
2350
|
+
}
|
|
2351
|
+
getScoresByScorerId(params) {
|
|
2352
|
+
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
2353
|
+
const searchParams = new URLSearchParams();
|
|
2354
|
+
if (entityId) {
|
|
2355
|
+
searchParams.set("entityId", entityId);
|
|
2356
|
+
}
|
|
2357
|
+
if (entityType) {
|
|
2358
|
+
searchParams.set("entityType", entityType);
|
|
2359
|
+
}
|
|
2360
|
+
if (page !== void 0) {
|
|
2361
|
+
searchParams.set("page", String(page));
|
|
2362
|
+
}
|
|
2363
|
+
if (perPage !== void 0) {
|
|
2364
|
+
searchParams.set("perPage", String(perPage));
|
|
2365
|
+
}
|
|
2366
|
+
const queryString = searchParams.toString();
|
|
2367
|
+
return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
|
|
2368
|
+
}
|
|
2369
|
+
/**
|
|
2370
|
+
* Retrieves scores by run ID
|
|
2371
|
+
* @param params - Parameters containing run ID and pagination options
|
|
2372
|
+
* @returns Promise containing scores and pagination info
|
|
2373
|
+
*/
|
|
2374
|
+
getScoresByRunId(params) {
|
|
2375
|
+
const { runId, page, perPage } = params;
|
|
2376
|
+
const searchParams = new URLSearchParams();
|
|
2377
|
+
if (page !== void 0) {
|
|
2378
|
+
searchParams.set("page", String(page));
|
|
2379
|
+
}
|
|
2380
|
+
if (perPage !== void 0) {
|
|
2381
|
+
searchParams.set("perPage", String(perPage));
|
|
2382
|
+
}
|
|
2383
|
+
const queryString = searchParams.toString();
|
|
2384
|
+
return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
|
|
2385
|
+
}
|
|
2386
|
+
/**
|
|
2387
|
+
* Retrieves scores by entity ID and type
|
|
2388
|
+
* @param params - Parameters containing entity ID, type, and pagination options
|
|
2389
|
+
* @returns Promise containing scores and pagination info
|
|
2390
|
+
*/
|
|
2391
|
+
getScoresByEntityId(params) {
|
|
2392
|
+
const { entityId, entityType, page, perPage } = params;
|
|
2393
|
+
const searchParams = new URLSearchParams();
|
|
2394
|
+
if (page !== void 0) {
|
|
2395
|
+
searchParams.set("page", String(page));
|
|
2396
|
+
}
|
|
2397
|
+
if (perPage !== void 0) {
|
|
2398
|
+
searchParams.set("perPage", String(perPage));
|
|
2399
|
+
}
|
|
2400
|
+
const queryString = searchParams.toString();
|
|
2401
|
+
return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ""}`);
|
|
2402
|
+
}
|
|
2403
|
+
/**
|
|
2404
|
+
* Saves a score
|
|
2405
|
+
* @param params - Parameters containing the score data to save
|
|
2406
|
+
* @returns Promise containing the saved score
|
|
2407
|
+
*/
|
|
2408
|
+
saveScore(params) {
|
|
2409
|
+
return this.request("/api/scores", {
|
|
2410
|
+
method: "POST",
|
|
2411
|
+
body: params
|
|
2412
|
+
});
|
|
2413
|
+
}
|
|
727
2414
|
};
|
|
728
2415
|
|
|
729
2416
|
exports.MastraClient = MastraClient;
|
|
2417
|
+
//# sourceMappingURL=index.cjs.map
|
|
2418
|
+
//# sourceMappingURL=index.cjs.map
|