@mastra/client-js 0.0.0-vector-query-sources-20250516172905 → 0.0.0-vector-query-tool-provider-options-20250828222356
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 +18 -0
- package/CHANGELOG.md +1318 -2
- 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 +274 -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 +1801 -137
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -883
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1803 -139
- package/dist/index.js.map +1 -0
- package/dist/resources/a2a.d.ts +41 -0
- package/dist/resources/a2a.d.ts.map +1 -0
- package/dist/resources/agent.d.ts +130 -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 +12 -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/observability.d.ts +19 -0
- package/dist/resources/observability.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 +449 -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/process-mastra-stream.d.ts +7 -0
- package/dist/utils/process-mastra-stream.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema.d.ts +3 -0
- package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
- package/eslint.config.js +6 -1
- 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 +32 -19
- package/src/adapters/agui.test.ts +116 -3
- package/src/adapters/agui.ts +30 -12
- package/src/client.ts +333 -24
- package/src/example.ts +46 -15
- package/src/index.test.ts +429 -6
- package/src/index.ts +1 -0
- package/src/resources/a2a.ts +35 -25
- package/src/resources/agent.ts +1284 -20
- package/src/resources/base.ts +8 -1
- package/src/resources/index.ts +3 -2
- package/src/resources/{vnext-workflow.ts → legacy-workflow.ts} +124 -143
- package/src/resources/memory-thread.test.ts +285 -0
- package/src/resources/memory-thread.ts +37 -1
- package/src/resources/network-memory-thread.test.ts +269 -0
- package/src/resources/network-memory-thread.ts +81 -0
- package/src/resources/network.ts +7 -7
- package/src/resources/observability.ts +53 -0
- package/src/resources/tool.ts +4 -3
- package/src/resources/vNextNetwork.ts +194 -0
- package/src/resources/workflow.ts +255 -96
- package/src/types.ts +262 -36
- package/src/utils/index.ts +11 -0
- package/src/utils/process-client-tools.ts +32 -0
- package/src/utils/process-mastra-stream.test.ts +353 -0
- package/src/utils/process-mastra-stream.ts +49 -0
- package/src/utils/zod-to-json-schema.ts +23 -3
- package/src/v2-messages.test.ts +180 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +2 -2
- package/tsup.config.ts +17 -0
- package/dist/index.d.cts +0 -883
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
var client = require('@ag-ui/client');
|
|
4
4
|
var rxjs = require('rxjs');
|
|
5
5
|
var uiUtils = require('@ai-sdk/ui-utils');
|
|
6
|
+
var uuid = require('@lukeed/uuid');
|
|
7
|
+
var runtimeContext = require('@mastra/core/runtime-context');
|
|
8
|
+
var isVercelTool = require('@mastra/core/tools/is-vercel-tool');
|
|
6
9
|
var zod = require('zod');
|
|
7
10
|
var originalZodToJsonSchema = require('zod-to-json-schema');
|
|
8
11
|
|
|
@@ -148,6 +151,12 @@ function generateUUID() {
|
|
|
148
151
|
}
|
|
149
152
|
function convertMessagesToMastraMessages(messages) {
|
|
150
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
|
+
}
|
|
151
160
|
for (const message of messages) {
|
|
152
161
|
if (message.role === "assistant") {
|
|
153
162
|
const parts = message.content ? [{ type: "text", text: message.content }] : [];
|
|
@@ -164,15 +173,22 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
164
173
|
content: parts
|
|
165
174
|
});
|
|
166
175
|
if (message.toolCalls?.length) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
+
}
|
|
176
192
|
}
|
|
177
193
|
} else if (message.role === "user") {
|
|
178
194
|
result.push({
|
|
@@ -185,8 +201,9 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
185
201
|
content: [
|
|
186
202
|
{
|
|
187
203
|
type: "tool-result",
|
|
188
|
-
toolCallId: message.toolCallId,
|
|
204
|
+
toolCallId: message.toolCallId || "unknown",
|
|
189
205
|
toolName: "unknown",
|
|
206
|
+
// toolName is not available in tool messages from CopilotKit
|
|
190
207
|
result: message.content
|
|
191
208
|
}
|
|
192
209
|
]
|
|
@@ -195,13 +212,94 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
195
212
|
}
|
|
196
213
|
return result;
|
|
197
214
|
}
|
|
215
|
+
function parseClientRuntimeContext(runtimeContext$1) {
|
|
216
|
+
if (runtimeContext$1) {
|
|
217
|
+
if (runtimeContext$1 instanceof runtimeContext.RuntimeContext) {
|
|
218
|
+
return Object.fromEntries(runtimeContext$1.entries());
|
|
219
|
+
}
|
|
220
|
+
return runtimeContext$1;
|
|
221
|
+
}
|
|
222
|
+
return void 0;
|
|
223
|
+
}
|
|
224
|
+
function isZodType(value) {
|
|
225
|
+
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
226
|
+
}
|
|
198
227
|
function zodToJsonSchema(zodSchema) {
|
|
199
|
-
if (!(zodSchema
|
|
228
|
+
if (!isZodType(zodSchema)) {
|
|
200
229
|
return zodSchema;
|
|
201
230
|
}
|
|
231
|
+
if ("toJSONSchema" in zod.z) {
|
|
232
|
+
const fn = "toJSONSchema";
|
|
233
|
+
return zod.z[fn].call(zod.z, zodSchema);
|
|
234
|
+
}
|
|
202
235
|
return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "none" });
|
|
203
236
|
}
|
|
204
237
|
|
|
238
|
+
// src/utils/process-client-tools.ts
|
|
239
|
+
function processClientTools(clientTools) {
|
|
240
|
+
if (!clientTools) {
|
|
241
|
+
return void 0;
|
|
242
|
+
}
|
|
243
|
+
return Object.fromEntries(
|
|
244
|
+
Object.entries(clientTools).map(([key, value]) => {
|
|
245
|
+
if (isVercelTool.isVercelTool(value)) {
|
|
246
|
+
return [
|
|
247
|
+
key,
|
|
248
|
+
{
|
|
249
|
+
...value,
|
|
250
|
+
parameters: value.parameters ? zodToJsonSchema(value.parameters) : void 0
|
|
251
|
+
}
|
|
252
|
+
];
|
|
253
|
+
} else {
|
|
254
|
+
return [
|
|
255
|
+
key,
|
|
256
|
+
{
|
|
257
|
+
...value,
|
|
258
|
+
inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : void 0,
|
|
259
|
+
outputSchema: value.outputSchema ? zodToJsonSchema(value.outputSchema) : void 0
|
|
260
|
+
}
|
|
261
|
+
];
|
|
262
|
+
}
|
|
263
|
+
})
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// src/utils/process-mastra-stream.ts
|
|
268
|
+
async function processMastraStream({
|
|
269
|
+
stream,
|
|
270
|
+
onChunk
|
|
271
|
+
}) {
|
|
272
|
+
const reader = stream.getReader();
|
|
273
|
+
const decoder = new TextDecoder();
|
|
274
|
+
let buffer = "";
|
|
275
|
+
try {
|
|
276
|
+
while (true) {
|
|
277
|
+
const { done, value } = await reader.read();
|
|
278
|
+
if (done) break;
|
|
279
|
+
buffer += decoder.decode(value, { stream: true });
|
|
280
|
+
const lines = buffer.split("\n\n");
|
|
281
|
+
buffer = lines.pop() || "";
|
|
282
|
+
for (const line of lines) {
|
|
283
|
+
if (line.startsWith("data: ")) {
|
|
284
|
+
const data = line.slice(6);
|
|
285
|
+
if (data === "[DONE]") {
|
|
286
|
+
console.log("\u{1F3C1} Stream finished");
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
try {
|
|
290
|
+
const json = JSON.parse(data);
|
|
291
|
+
await onChunk(json);
|
|
292
|
+
} catch (error) {
|
|
293
|
+
console.error("\u274C JSON parse error:", error, "Data:", data);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
} finally {
|
|
299
|
+
reader.releaseLock();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
205
303
|
// src/resources/base.ts
|
|
206
304
|
var BaseResource = class {
|
|
207
305
|
options;
|
|
@@ -216,18 +314,21 @@ var BaseResource = class {
|
|
|
216
314
|
*/
|
|
217
315
|
async request(path, options = {}) {
|
|
218
316
|
let lastError = null;
|
|
219
|
-
const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {} } = this.options;
|
|
317
|
+
const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {}, credentials } = this.options;
|
|
220
318
|
let delay = backoffMs;
|
|
221
319
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
222
320
|
try {
|
|
223
321
|
const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
|
|
224
322
|
...options,
|
|
225
323
|
headers: {
|
|
324
|
+
...options.body && !(options.body instanceof FormData) && (options.method === "POST" || options.method === "PUT") ? { "content-type": "application/json" } : {},
|
|
226
325
|
...headers,
|
|
227
326
|
...options.headers
|
|
228
327
|
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
|
229
328
|
// 'x-mastra-client-type': 'js',
|
|
230
329
|
},
|
|
330
|
+
signal: this.options.abortSignal,
|
|
331
|
+
credentials: options.credentials ?? credentials,
|
|
231
332
|
body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
|
|
232
333
|
});
|
|
233
334
|
if (!response.ok) {
|
|
@@ -262,6 +363,63 @@ var BaseResource = class {
|
|
|
262
363
|
};
|
|
263
364
|
|
|
264
365
|
// src/resources/agent.ts
|
|
366
|
+
async function executeToolCallAndRespond({
|
|
367
|
+
response,
|
|
368
|
+
params,
|
|
369
|
+
runId,
|
|
370
|
+
resourceId,
|
|
371
|
+
threadId,
|
|
372
|
+
runtimeContext,
|
|
373
|
+
respondFn
|
|
374
|
+
}) {
|
|
375
|
+
if (response.finishReason === "tool-calls") {
|
|
376
|
+
const toolCalls = response.toolCalls;
|
|
377
|
+
if (!toolCalls || !Array.isArray(toolCalls)) {
|
|
378
|
+
return response;
|
|
379
|
+
}
|
|
380
|
+
for (const toolCall of toolCalls) {
|
|
381
|
+
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
382
|
+
if (clientTool && clientTool.execute) {
|
|
383
|
+
const result = await clientTool.execute(
|
|
384
|
+
{
|
|
385
|
+
context: toolCall?.args,
|
|
386
|
+
runId,
|
|
387
|
+
resourceId,
|
|
388
|
+
threadId,
|
|
389
|
+
runtimeContext,
|
|
390
|
+
tracingContext: { currentSpan: void 0 }
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
messages: response.messages,
|
|
394
|
+
toolCallId: toolCall?.toolCallId
|
|
395
|
+
}
|
|
396
|
+
);
|
|
397
|
+
const updatedMessages = [
|
|
398
|
+
{
|
|
399
|
+
role: "user",
|
|
400
|
+
content: params.messages
|
|
401
|
+
},
|
|
402
|
+
...response.response.messages,
|
|
403
|
+
{
|
|
404
|
+
role: "tool",
|
|
405
|
+
content: [
|
|
406
|
+
{
|
|
407
|
+
type: "tool-result",
|
|
408
|
+
toolCallId: toolCall.toolCallId,
|
|
409
|
+
toolName: toolCall.toolName,
|
|
410
|
+
result
|
|
411
|
+
}
|
|
412
|
+
]
|
|
413
|
+
}
|
|
414
|
+
];
|
|
415
|
+
return respondFn({
|
|
416
|
+
...params,
|
|
417
|
+
messages: updatedMessages
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
265
423
|
var AgentVoice = class extends BaseResource {
|
|
266
424
|
constructor(options, agentId) {
|
|
267
425
|
super(options);
|
|
@@ -308,6 +466,13 @@ var AgentVoice = class extends BaseResource {
|
|
|
308
466
|
getSpeakers() {
|
|
309
467
|
return this.request(`/api/agents/${this.agentId}/voice/speakers`);
|
|
310
468
|
}
|
|
469
|
+
/**
|
|
470
|
+
* Get the listener configuration for the agent's voice provider
|
|
471
|
+
* @returns Promise containing a check if the agent has listening capabilities
|
|
472
|
+
*/
|
|
473
|
+
getListener() {
|
|
474
|
+
return this.request(`/api/agents/${this.agentId}/voice/listener`);
|
|
475
|
+
}
|
|
311
476
|
};
|
|
312
477
|
var Agent = class extends BaseResource {
|
|
313
478
|
constructor(options, agentId) {
|
|
@@ -323,22 +488,360 @@ var Agent = class extends BaseResource {
|
|
|
323
488
|
details() {
|
|
324
489
|
return this.request(`/api/agents/${this.agentId}`);
|
|
325
490
|
}
|
|
326
|
-
|
|
327
|
-
* Generates a response from the agent
|
|
328
|
-
* @param params - Generation parameters including prompt
|
|
329
|
-
* @returns Promise containing the generated response
|
|
330
|
-
*/
|
|
331
|
-
generate(params) {
|
|
491
|
+
async generate(params) {
|
|
332
492
|
const processedParams = {
|
|
333
493
|
...params,
|
|
334
494
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
335
495
|
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
336
|
-
runtimeContext:
|
|
496
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
497
|
+
clientTools: processClientTools(params.clientTools)
|
|
337
498
|
};
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
499
|
+
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
500
|
+
const response = await this.request(
|
|
501
|
+
`/api/agents/${this.agentId}/generate`,
|
|
502
|
+
{
|
|
503
|
+
method: "POST",
|
|
504
|
+
body: processedParams
|
|
505
|
+
}
|
|
506
|
+
);
|
|
507
|
+
if (response.finishReason === "tool-calls") {
|
|
508
|
+
const toolCalls = response.toolCalls;
|
|
509
|
+
if (!toolCalls || !Array.isArray(toolCalls)) {
|
|
510
|
+
return response;
|
|
511
|
+
}
|
|
512
|
+
for (const toolCall of toolCalls) {
|
|
513
|
+
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
514
|
+
if (clientTool && clientTool.execute) {
|
|
515
|
+
const result = await clientTool.execute(
|
|
516
|
+
{
|
|
517
|
+
context: toolCall?.args,
|
|
518
|
+
runId,
|
|
519
|
+
resourceId,
|
|
520
|
+
threadId,
|
|
521
|
+
runtimeContext,
|
|
522
|
+
tracingContext: { currentSpan: void 0 }
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
messages: response.messages,
|
|
526
|
+
toolCallId: toolCall?.toolCallId
|
|
527
|
+
}
|
|
528
|
+
);
|
|
529
|
+
const updatedMessages = [
|
|
530
|
+
{
|
|
531
|
+
role: "user",
|
|
532
|
+
content: params.messages
|
|
533
|
+
},
|
|
534
|
+
...response.response.messages,
|
|
535
|
+
{
|
|
536
|
+
role: "tool",
|
|
537
|
+
content: [
|
|
538
|
+
{
|
|
539
|
+
type: "tool-result",
|
|
540
|
+
toolCallId: toolCall.toolCallId,
|
|
541
|
+
toolName: toolCall.toolName,
|
|
542
|
+
result
|
|
543
|
+
}
|
|
544
|
+
]
|
|
545
|
+
}
|
|
546
|
+
];
|
|
547
|
+
return this.generate({
|
|
548
|
+
...params,
|
|
549
|
+
messages: updatedMessages
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return response;
|
|
555
|
+
}
|
|
556
|
+
async generateVNext(params) {
|
|
557
|
+
const processedParams = {
|
|
558
|
+
...params,
|
|
559
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
560
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
561
|
+
clientTools: processClientTools(params.clientTools)
|
|
562
|
+
};
|
|
563
|
+
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
564
|
+
const response = await this.request(
|
|
565
|
+
`/api/agents/${this.agentId}/generate/vnext`,
|
|
566
|
+
{
|
|
567
|
+
method: "POST",
|
|
568
|
+
body: processedParams
|
|
569
|
+
}
|
|
570
|
+
);
|
|
571
|
+
if (response.finishReason === "tool-calls") {
|
|
572
|
+
return executeToolCallAndRespond({
|
|
573
|
+
response,
|
|
574
|
+
params,
|
|
575
|
+
runId,
|
|
576
|
+
resourceId,
|
|
577
|
+
threadId,
|
|
578
|
+
runtimeContext,
|
|
579
|
+
respondFn: this.generateVNext.bind(this)
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
return response;
|
|
583
|
+
}
|
|
584
|
+
async processChatResponse({
|
|
585
|
+
stream,
|
|
586
|
+
update,
|
|
587
|
+
onToolCall,
|
|
588
|
+
onFinish,
|
|
589
|
+
getCurrentDate = () => /* @__PURE__ */ new Date(),
|
|
590
|
+
lastMessage
|
|
591
|
+
}) {
|
|
592
|
+
const replaceLastMessage = lastMessage?.role === "assistant";
|
|
593
|
+
let step = replaceLastMessage ? 1 + // find max step in existing tool invocations:
|
|
594
|
+
(lastMessage.toolInvocations?.reduce((max, toolInvocation) => {
|
|
595
|
+
return Math.max(max, toolInvocation.step ?? 0);
|
|
596
|
+
}, 0) ?? 0) : 0;
|
|
597
|
+
const message = replaceLastMessage ? structuredClone(lastMessage) : {
|
|
598
|
+
id: uuid.v4(),
|
|
599
|
+
createdAt: getCurrentDate(),
|
|
600
|
+
role: "assistant",
|
|
601
|
+
content: "",
|
|
602
|
+
parts: []
|
|
603
|
+
};
|
|
604
|
+
let currentTextPart = void 0;
|
|
605
|
+
let currentReasoningPart = void 0;
|
|
606
|
+
let currentReasoningTextDetail = void 0;
|
|
607
|
+
function updateToolInvocationPart(toolCallId, invocation) {
|
|
608
|
+
const part = message.parts.find(
|
|
609
|
+
(part2) => part2.type === "tool-invocation" && part2.toolInvocation.toolCallId === toolCallId
|
|
610
|
+
);
|
|
611
|
+
if (part != null) {
|
|
612
|
+
part.toolInvocation = invocation;
|
|
613
|
+
} else {
|
|
614
|
+
message.parts.push({
|
|
615
|
+
type: "tool-invocation",
|
|
616
|
+
toolInvocation: invocation
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
const data = [];
|
|
621
|
+
let messageAnnotations = replaceLastMessage ? lastMessage?.annotations : void 0;
|
|
622
|
+
const partialToolCalls = {};
|
|
623
|
+
let usage = {
|
|
624
|
+
completionTokens: NaN,
|
|
625
|
+
promptTokens: NaN,
|
|
626
|
+
totalTokens: NaN
|
|
627
|
+
};
|
|
628
|
+
let finishReason = "unknown";
|
|
629
|
+
function execUpdate() {
|
|
630
|
+
const copiedData = [...data];
|
|
631
|
+
if (messageAnnotations?.length) {
|
|
632
|
+
message.annotations = messageAnnotations;
|
|
633
|
+
}
|
|
634
|
+
const copiedMessage = {
|
|
635
|
+
// deep copy the message to ensure that deep changes (msg attachments) are updated
|
|
636
|
+
// with SolidJS. SolidJS uses referential integration of sub-objects to detect changes.
|
|
637
|
+
...structuredClone(message),
|
|
638
|
+
// add a revision id to ensure that the message is updated with SWR. SWR uses a
|
|
639
|
+
// hashing approach by default to detect changes, but it only works for shallow
|
|
640
|
+
// changes. This is why we need to add a revision id to ensure that the message
|
|
641
|
+
// is updated with SWR (without it, the changes get stuck in SWR and are not
|
|
642
|
+
// forwarded to rendering):
|
|
643
|
+
revisionId: uuid.v4()
|
|
644
|
+
};
|
|
645
|
+
update({
|
|
646
|
+
message: copiedMessage,
|
|
647
|
+
data: copiedData,
|
|
648
|
+
replaceLastMessage
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
await uiUtils.processDataStream({
|
|
652
|
+
stream,
|
|
653
|
+
onTextPart(value) {
|
|
654
|
+
if (currentTextPart == null) {
|
|
655
|
+
currentTextPart = {
|
|
656
|
+
type: "text",
|
|
657
|
+
text: value
|
|
658
|
+
};
|
|
659
|
+
message.parts.push(currentTextPart);
|
|
660
|
+
} else {
|
|
661
|
+
currentTextPart.text += value;
|
|
662
|
+
}
|
|
663
|
+
message.content += value;
|
|
664
|
+
execUpdate();
|
|
665
|
+
},
|
|
666
|
+
onReasoningPart(value) {
|
|
667
|
+
if (currentReasoningTextDetail == null) {
|
|
668
|
+
currentReasoningTextDetail = { type: "text", text: value };
|
|
669
|
+
if (currentReasoningPart != null) {
|
|
670
|
+
currentReasoningPart.details.push(currentReasoningTextDetail);
|
|
671
|
+
}
|
|
672
|
+
} else {
|
|
673
|
+
currentReasoningTextDetail.text += value;
|
|
674
|
+
}
|
|
675
|
+
if (currentReasoningPart == null) {
|
|
676
|
+
currentReasoningPart = {
|
|
677
|
+
type: "reasoning",
|
|
678
|
+
reasoning: value,
|
|
679
|
+
details: [currentReasoningTextDetail]
|
|
680
|
+
};
|
|
681
|
+
message.parts.push(currentReasoningPart);
|
|
682
|
+
} else {
|
|
683
|
+
currentReasoningPart.reasoning += value;
|
|
684
|
+
}
|
|
685
|
+
message.reasoning = (message.reasoning ?? "") + value;
|
|
686
|
+
execUpdate();
|
|
687
|
+
},
|
|
688
|
+
onReasoningSignaturePart(value) {
|
|
689
|
+
if (currentReasoningTextDetail != null) {
|
|
690
|
+
currentReasoningTextDetail.signature = value.signature;
|
|
691
|
+
}
|
|
692
|
+
},
|
|
693
|
+
onRedactedReasoningPart(value) {
|
|
694
|
+
if (currentReasoningPart == null) {
|
|
695
|
+
currentReasoningPart = {
|
|
696
|
+
type: "reasoning",
|
|
697
|
+
reasoning: "",
|
|
698
|
+
details: []
|
|
699
|
+
};
|
|
700
|
+
message.parts.push(currentReasoningPart);
|
|
701
|
+
}
|
|
702
|
+
currentReasoningPart.details.push({
|
|
703
|
+
type: "redacted",
|
|
704
|
+
data: value.data
|
|
705
|
+
});
|
|
706
|
+
currentReasoningTextDetail = void 0;
|
|
707
|
+
execUpdate();
|
|
708
|
+
},
|
|
709
|
+
onFilePart(value) {
|
|
710
|
+
message.parts.push({
|
|
711
|
+
type: "file",
|
|
712
|
+
mimeType: value.mimeType,
|
|
713
|
+
data: value.data
|
|
714
|
+
});
|
|
715
|
+
execUpdate();
|
|
716
|
+
},
|
|
717
|
+
onSourcePart(value) {
|
|
718
|
+
message.parts.push({
|
|
719
|
+
type: "source",
|
|
720
|
+
source: value
|
|
721
|
+
});
|
|
722
|
+
execUpdate();
|
|
723
|
+
},
|
|
724
|
+
onToolCallStreamingStartPart(value) {
|
|
725
|
+
if (message.toolInvocations == null) {
|
|
726
|
+
message.toolInvocations = [];
|
|
727
|
+
}
|
|
728
|
+
partialToolCalls[value.toolCallId] = {
|
|
729
|
+
text: "",
|
|
730
|
+
step,
|
|
731
|
+
toolName: value.toolName,
|
|
732
|
+
index: message.toolInvocations.length
|
|
733
|
+
};
|
|
734
|
+
const invocation = {
|
|
735
|
+
state: "partial-call",
|
|
736
|
+
step,
|
|
737
|
+
toolCallId: value.toolCallId,
|
|
738
|
+
toolName: value.toolName,
|
|
739
|
+
args: void 0
|
|
740
|
+
};
|
|
741
|
+
message.toolInvocations.push(invocation);
|
|
742
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
743
|
+
execUpdate();
|
|
744
|
+
},
|
|
745
|
+
onToolCallDeltaPart(value) {
|
|
746
|
+
const partialToolCall = partialToolCalls[value.toolCallId];
|
|
747
|
+
partialToolCall.text += value.argsTextDelta;
|
|
748
|
+
const { value: partialArgs } = uiUtils.parsePartialJson(partialToolCall.text);
|
|
749
|
+
const invocation = {
|
|
750
|
+
state: "partial-call",
|
|
751
|
+
step: partialToolCall.step,
|
|
752
|
+
toolCallId: value.toolCallId,
|
|
753
|
+
toolName: partialToolCall.toolName,
|
|
754
|
+
args: partialArgs
|
|
755
|
+
};
|
|
756
|
+
message.toolInvocations[partialToolCall.index] = invocation;
|
|
757
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
758
|
+
execUpdate();
|
|
759
|
+
},
|
|
760
|
+
async onToolCallPart(value) {
|
|
761
|
+
const invocation = {
|
|
762
|
+
state: "call",
|
|
763
|
+
step,
|
|
764
|
+
...value
|
|
765
|
+
};
|
|
766
|
+
if (partialToolCalls[value.toolCallId] != null) {
|
|
767
|
+
message.toolInvocations[partialToolCalls[value.toolCallId].index] = invocation;
|
|
768
|
+
} else {
|
|
769
|
+
if (message.toolInvocations == null) {
|
|
770
|
+
message.toolInvocations = [];
|
|
771
|
+
}
|
|
772
|
+
message.toolInvocations.push(invocation);
|
|
773
|
+
}
|
|
774
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
775
|
+
execUpdate();
|
|
776
|
+
if (onToolCall) {
|
|
777
|
+
const result = await onToolCall({ toolCall: value });
|
|
778
|
+
if (result != null) {
|
|
779
|
+
const invocation2 = {
|
|
780
|
+
state: "result",
|
|
781
|
+
step,
|
|
782
|
+
...value,
|
|
783
|
+
result
|
|
784
|
+
};
|
|
785
|
+
message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
|
|
786
|
+
updateToolInvocationPart(value.toolCallId, invocation2);
|
|
787
|
+
execUpdate();
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
},
|
|
791
|
+
onToolResultPart(value) {
|
|
792
|
+
const toolInvocations = message.toolInvocations;
|
|
793
|
+
if (toolInvocations == null) {
|
|
794
|
+
throw new Error("tool_result must be preceded by a tool_call");
|
|
795
|
+
}
|
|
796
|
+
const toolInvocationIndex = toolInvocations.findIndex((invocation2) => invocation2.toolCallId === value.toolCallId);
|
|
797
|
+
if (toolInvocationIndex === -1) {
|
|
798
|
+
throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
|
|
799
|
+
}
|
|
800
|
+
const invocation = {
|
|
801
|
+
...toolInvocations[toolInvocationIndex],
|
|
802
|
+
state: "result",
|
|
803
|
+
...value
|
|
804
|
+
};
|
|
805
|
+
toolInvocations[toolInvocationIndex] = invocation;
|
|
806
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
807
|
+
execUpdate();
|
|
808
|
+
},
|
|
809
|
+
onDataPart(value) {
|
|
810
|
+
data.push(...value);
|
|
811
|
+
execUpdate();
|
|
812
|
+
},
|
|
813
|
+
onMessageAnnotationsPart(value) {
|
|
814
|
+
if (messageAnnotations == null) {
|
|
815
|
+
messageAnnotations = [...value];
|
|
816
|
+
} else {
|
|
817
|
+
messageAnnotations.push(...value);
|
|
818
|
+
}
|
|
819
|
+
execUpdate();
|
|
820
|
+
},
|
|
821
|
+
onFinishStepPart(value) {
|
|
822
|
+
step += 1;
|
|
823
|
+
currentTextPart = value.isContinued ? currentTextPart : void 0;
|
|
824
|
+
currentReasoningPart = void 0;
|
|
825
|
+
currentReasoningTextDetail = void 0;
|
|
826
|
+
},
|
|
827
|
+
onStartStepPart(value) {
|
|
828
|
+
if (!replaceLastMessage) {
|
|
829
|
+
message.id = value.messageId;
|
|
830
|
+
}
|
|
831
|
+
message.parts.push({ type: "step-start" });
|
|
832
|
+
execUpdate();
|
|
833
|
+
},
|
|
834
|
+
onFinishMessagePart(value) {
|
|
835
|
+
finishReason = value.finishReason;
|
|
836
|
+
if (value.usage != null) {
|
|
837
|
+
usage = value.usage;
|
|
838
|
+
}
|
|
839
|
+
},
|
|
840
|
+
onErrorPart(error) {
|
|
841
|
+
throw new Error(error);
|
|
842
|
+
}
|
|
341
843
|
});
|
|
844
|
+
onFinish?.({ message, finishReason, usage });
|
|
342
845
|
}
|
|
343
846
|
/**
|
|
344
847
|
* Streams a response from the agent
|
|
@@ -350,9 +853,279 @@ var Agent = class extends BaseResource {
|
|
|
350
853
|
...params,
|
|
351
854
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
352
855
|
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
353
|
-
runtimeContext:
|
|
856
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
857
|
+
clientTools: processClientTools(params.clientTools)
|
|
354
858
|
};
|
|
355
|
-
const
|
|
859
|
+
const { readable, writable } = new TransformStream();
|
|
860
|
+
const response = await this.processStreamResponse(processedParams, writable);
|
|
861
|
+
const streamResponse = new Response(readable, {
|
|
862
|
+
status: response.status,
|
|
863
|
+
statusText: response.statusText,
|
|
864
|
+
headers: response.headers
|
|
865
|
+
});
|
|
866
|
+
streamResponse.processDataStream = async (options = {}) => {
|
|
867
|
+
await uiUtils.processDataStream({
|
|
868
|
+
stream: streamResponse.body,
|
|
869
|
+
...options
|
|
870
|
+
});
|
|
871
|
+
};
|
|
872
|
+
return streamResponse;
|
|
873
|
+
}
|
|
874
|
+
async processChatResponse_vNext({
|
|
875
|
+
stream,
|
|
876
|
+
update,
|
|
877
|
+
onToolCall,
|
|
878
|
+
onFinish,
|
|
879
|
+
getCurrentDate = () => /* @__PURE__ */ new Date(),
|
|
880
|
+
lastMessage
|
|
881
|
+
}) {
|
|
882
|
+
const replaceLastMessage = lastMessage?.role === "assistant";
|
|
883
|
+
let step = replaceLastMessage ? 1 + // find max step in existing tool invocations:
|
|
884
|
+
(lastMessage.toolInvocations?.reduce((max, toolInvocation) => {
|
|
885
|
+
return Math.max(max, toolInvocation.step ?? 0);
|
|
886
|
+
}, 0) ?? 0) : 0;
|
|
887
|
+
const message = replaceLastMessage ? structuredClone(lastMessage) : {
|
|
888
|
+
id: uuid.v4(),
|
|
889
|
+
createdAt: getCurrentDate(),
|
|
890
|
+
role: "assistant",
|
|
891
|
+
content: "",
|
|
892
|
+
parts: []
|
|
893
|
+
};
|
|
894
|
+
let currentTextPart = void 0;
|
|
895
|
+
let currentReasoningPart = void 0;
|
|
896
|
+
let currentReasoningTextDetail = void 0;
|
|
897
|
+
function updateToolInvocationPart(toolCallId, invocation) {
|
|
898
|
+
const part = message.parts.find(
|
|
899
|
+
(part2) => part2.type === "tool-invocation" && part2.toolInvocation.toolCallId === toolCallId
|
|
900
|
+
);
|
|
901
|
+
if (part != null) {
|
|
902
|
+
part.toolInvocation = invocation;
|
|
903
|
+
} else {
|
|
904
|
+
message.parts.push({
|
|
905
|
+
type: "tool-invocation",
|
|
906
|
+
toolInvocation: invocation
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
const data = [];
|
|
911
|
+
let messageAnnotations = replaceLastMessage ? lastMessage?.annotations : void 0;
|
|
912
|
+
const partialToolCalls = {};
|
|
913
|
+
let usage = {
|
|
914
|
+
completionTokens: NaN,
|
|
915
|
+
promptTokens: NaN,
|
|
916
|
+
totalTokens: NaN
|
|
917
|
+
};
|
|
918
|
+
let finishReason = "unknown";
|
|
919
|
+
function execUpdate() {
|
|
920
|
+
const copiedData = [...data];
|
|
921
|
+
if (messageAnnotations?.length) {
|
|
922
|
+
message.annotations = messageAnnotations;
|
|
923
|
+
}
|
|
924
|
+
const copiedMessage = {
|
|
925
|
+
// deep copy the message to ensure that deep changes (msg attachments) are updated
|
|
926
|
+
// with SolidJS. SolidJS uses referential integration of sub-objects to detect changes.
|
|
927
|
+
...structuredClone(message),
|
|
928
|
+
// add a revision id to ensure that the message is updated with SWR. SWR uses a
|
|
929
|
+
// hashing approach by default to detect changes, but it only works for shallow
|
|
930
|
+
// changes. This is why we need to add a revision id to ensure that the message
|
|
931
|
+
// is updated with SWR (without it, the changes get stuck in SWR and are not
|
|
932
|
+
// forwarded to rendering):
|
|
933
|
+
revisionId: uuid.v4()
|
|
934
|
+
};
|
|
935
|
+
update({
|
|
936
|
+
message: copiedMessage,
|
|
937
|
+
data: copiedData,
|
|
938
|
+
replaceLastMessage
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
await processMastraStream({
|
|
942
|
+
stream,
|
|
943
|
+
// TODO: casting as any here because the stream types were all typed as any before in core.
|
|
944
|
+
// but this is completely wrong and this fn is probably broken. Remove ":any" and you'll see a bunch of type errors
|
|
945
|
+
onChunk: async (chunk) => {
|
|
946
|
+
switch (chunk.type) {
|
|
947
|
+
case "step-start": {
|
|
948
|
+
if (!replaceLastMessage) {
|
|
949
|
+
message.id = chunk.payload.messageId;
|
|
950
|
+
}
|
|
951
|
+
message.parts.push({ type: "step-start" });
|
|
952
|
+
execUpdate();
|
|
953
|
+
break;
|
|
954
|
+
}
|
|
955
|
+
case "text-delta": {
|
|
956
|
+
if (currentTextPart == null) {
|
|
957
|
+
currentTextPart = {
|
|
958
|
+
type: "text",
|
|
959
|
+
text: chunk.payload.text
|
|
960
|
+
};
|
|
961
|
+
message.parts.push(currentTextPart);
|
|
962
|
+
} else {
|
|
963
|
+
currentTextPart.text += chunk.payload.text;
|
|
964
|
+
}
|
|
965
|
+
message.content += chunk.payload.text;
|
|
966
|
+
execUpdate();
|
|
967
|
+
break;
|
|
968
|
+
}
|
|
969
|
+
case "reasoning-delta": {
|
|
970
|
+
if (currentReasoningTextDetail == null) {
|
|
971
|
+
currentReasoningTextDetail = { type: "text", text: chunk.payload.text };
|
|
972
|
+
if (currentReasoningPart != null) {
|
|
973
|
+
currentReasoningPart.details.push(currentReasoningTextDetail);
|
|
974
|
+
}
|
|
975
|
+
} else {
|
|
976
|
+
currentReasoningTextDetail.text += chunk.payload.text;
|
|
977
|
+
}
|
|
978
|
+
if (currentReasoningPart == null) {
|
|
979
|
+
currentReasoningPart = {
|
|
980
|
+
type: "reasoning",
|
|
981
|
+
reasoning: chunk.payload.text,
|
|
982
|
+
details: [currentReasoningTextDetail]
|
|
983
|
+
};
|
|
984
|
+
message.parts.push(currentReasoningPart);
|
|
985
|
+
} else {
|
|
986
|
+
currentReasoningPart.reasoning += chunk.payload.text;
|
|
987
|
+
}
|
|
988
|
+
message.reasoning = (message.reasoning ?? "") + chunk.payload.text;
|
|
989
|
+
execUpdate();
|
|
990
|
+
break;
|
|
991
|
+
}
|
|
992
|
+
case "file": {
|
|
993
|
+
message.parts.push({
|
|
994
|
+
type: "file",
|
|
995
|
+
mimeType: chunk.payload.mimeType,
|
|
996
|
+
data: chunk.payload.data
|
|
997
|
+
});
|
|
998
|
+
execUpdate();
|
|
999
|
+
break;
|
|
1000
|
+
}
|
|
1001
|
+
case "source": {
|
|
1002
|
+
message.parts.push({
|
|
1003
|
+
type: "source",
|
|
1004
|
+
source: chunk.payload.source
|
|
1005
|
+
});
|
|
1006
|
+
execUpdate();
|
|
1007
|
+
break;
|
|
1008
|
+
}
|
|
1009
|
+
case "tool-call": {
|
|
1010
|
+
const invocation = {
|
|
1011
|
+
state: "call",
|
|
1012
|
+
step,
|
|
1013
|
+
...chunk.payload
|
|
1014
|
+
};
|
|
1015
|
+
if (partialToolCalls[chunk.payload.toolCallId] != null) {
|
|
1016
|
+
message.toolInvocations[partialToolCalls[chunk.payload.toolCallId].index] = invocation;
|
|
1017
|
+
} else {
|
|
1018
|
+
if (message.toolInvocations == null) {
|
|
1019
|
+
message.toolInvocations = [];
|
|
1020
|
+
}
|
|
1021
|
+
message.toolInvocations.push(invocation);
|
|
1022
|
+
}
|
|
1023
|
+
updateToolInvocationPart(chunk.payload.toolCallId, invocation);
|
|
1024
|
+
execUpdate();
|
|
1025
|
+
if (onToolCall) {
|
|
1026
|
+
const result = await onToolCall({ toolCall: chunk.payload });
|
|
1027
|
+
if (result != null) {
|
|
1028
|
+
const invocation2 = {
|
|
1029
|
+
state: "result",
|
|
1030
|
+
step,
|
|
1031
|
+
...chunk.payload,
|
|
1032
|
+
result
|
|
1033
|
+
};
|
|
1034
|
+
message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
|
|
1035
|
+
updateToolInvocationPart(chunk.payload.toolCallId, invocation2);
|
|
1036
|
+
execUpdate();
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
case "tool-call-input-streaming-start": {
|
|
1041
|
+
if (message.toolInvocations == null) {
|
|
1042
|
+
message.toolInvocations = [];
|
|
1043
|
+
}
|
|
1044
|
+
partialToolCalls[chunk.payload.toolCallId] = {
|
|
1045
|
+
text: "",
|
|
1046
|
+
step,
|
|
1047
|
+
toolName: chunk.payload.toolName,
|
|
1048
|
+
index: message.toolInvocations.length
|
|
1049
|
+
};
|
|
1050
|
+
const invocation = {
|
|
1051
|
+
state: "partial-call",
|
|
1052
|
+
step,
|
|
1053
|
+
toolCallId: chunk.payload.toolCallId,
|
|
1054
|
+
toolName: chunk.payload.toolName,
|
|
1055
|
+
args: void 0
|
|
1056
|
+
};
|
|
1057
|
+
message.toolInvocations.push(invocation);
|
|
1058
|
+
updateToolInvocationPart(chunk.payload.toolCallId, invocation);
|
|
1059
|
+
execUpdate();
|
|
1060
|
+
break;
|
|
1061
|
+
}
|
|
1062
|
+
case "tool-call-delta": {
|
|
1063
|
+
const partialToolCall = partialToolCalls[chunk.payload.toolCallId];
|
|
1064
|
+
partialToolCall.text += chunk.payload.argsTextDelta;
|
|
1065
|
+
const { value: partialArgs } = uiUtils.parsePartialJson(partialToolCall.text);
|
|
1066
|
+
const invocation = {
|
|
1067
|
+
state: "partial-call",
|
|
1068
|
+
step: partialToolCall.step,
|
|
1069
|
+
toolCallId: chunk.payload.toolCallId,
|
|
1070
|
+
toolName: partialToolCall.toolName,
|
|
1071
|
+
args: partialArgs
|
|
1072
|
+
};
|
|
1073
|
+
message.toolInvocations[partialToolCall.index] = invocation;
|
|
1074
|
+
updateToolInvocationPart(chunk.payload.toolCallId, invocation);
|
|
1075
|
+
execUpdate();
|
|
1076
|
+
break;
|
|
1077
|
+
}
|
|
1078
|
+
case "tool-result": {
|
|
1079
|
+
const toolInvocations = message.toolInvocations;
|
|
1080
|
+
if (toolInvocations == null) {
|
|
1081
|
+
throw new Error("tool_result must be preceded by a tool_call");
|
|
1082
|
+
}
|
|
1083
|
+
const toolInvocationIndex = toolInvocations.findIndex(
|
|
1084
|
+
(invocation2) => invocation2.toolCallId === chunk.payload.toolCallId
|
|
1085
|
+
);
|
|
1086
|
+
if (toolInvocationIndex === -1) {
|
|
1087
|
+
throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
|
|
1088
|
+
}
|
|
1089
|
+
const invocation = {
|
|
1090
|
+
...toolInvocations[toolInvocationIndex],
|
|
1091
|
+
state: "result",
|
|
1092
|
+
...chunk.payload
|
|
1093
|
+
};
|
|
1094
|
+
toolInvocations[toolInvocationIndex] = invocation;
|
|
1095
|
+
updateToolInvocationPart(chunk.payload.toolCallId, invocation);
|
|
1096
|
+
execUpdate();
|
|
1097
|
+
break;
|
|
1098
|
+
}
|
|
1099
|
+
case "error": {
|
|
1100
|
+
throw new Error(chunk.payload.error);
|
|
1101
|
+
}
|
|
1102
|
+
case "data": {
|
|
1103
|
+
data.push(...chunk.payload.data);
|
|
1104
|
+
execUpdate();
|
|
1105
|
+
break;
|
|
1106
|
+
}
|
|
1107
|
+
case "step-finish": {
|
|
1108
|
+
step += 1;
|
|
1109
|
+
currentTextPart = chunk.payload.isContinued ? currentTextPart : void 0;
|
|
1110
|
+
currentReasoningPart = void 0;
|
|
1111
|
+
currentReasoningTextDetail = void 0;
|
|
1112
|
+
execUpdate();
|
|
1113
|
+
break;
|
|
1114
|
+
}
|
|
1115
|
+
case "finish": {
|
|
1116
|
+
finishReason = chunk.payload.finishReason;
|
|
1117
|
+
if (chunk.payload.usage != null) {
|
|
1118
|
+
usage = chunk.payload.usage;
|
|
1119
|
+
}
|
|
1120
|
+
break;
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
});
|
|
1125
|
+
onFinish?.({ message, finishReason, usage });
|
|
1126
|
+
}
|
|
1127
|
+
async processStreamResponse_vNext(processedParams, writable) {
|
|
1128
|
+
const response = await this.request(`/api/agents/${this.agentId}/stream/vnext`, {
|
|
356
1129
|
method: "POST",
|
|
357
1130
|
body: processedParams,
|
|
358
1131
|
stream: true
|
|
@@ -360,12 +1133,244 @@ var Agent = class extends BaseResource {
|
|
|
360
1133
|
if (!response.body) {
|
|
361
1134
|
throw new Error("No response body");
|
|
362
1135
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
1136
|
+
try {
|
|
1137
|
+
let toolCalls = [];
|
|
1138
|
+
let messages = [];
|
|
1139
|
+
const [streamForWritable, streamForProcessing] = response.body.tee();
|
|
1140
|
+
streamForWritable.pipeTo(writable, {
|
|
1141
|
+
preventClose: true
|
|
1142
|
+
}).catch((error) => {
|
|
1143
|
+
console.error("Error piping to writable stream:", error);
|
|
1144
|
+
});
|
|
1145
|
+
this.processChatResponse_vNext({
|
|
1146
|
+
stream: streamForProcessing,
|
|
1147
|
+
update: ({ message }) => {
|
|
1148
|
+
const existingIndex = messages.findIndex((m) => m.id === message.id);
|
|
1149
|
+
if (existingIndex !== -1) {
|
|
1150
|
+
messages[existingIndex] = message;
|
|
1151
|
+
} else {
|
|
1152
|
+
messages.push(message);
|
|
1153
|
+
}
|
|
1154
|
+
},
|
|
1155
|
+
onFinish: async ({ finishReason, message }) => {
|
|
1156
|
+
if (finishReason === "tool-calls") {
|
|
1157
|
+
const toolCall = [...message?.parts ?? []].reverse().find((part) => part.type === "tool-invocation")?.toolInvocation;
|
|
1158
|
+
if (toolCall) {
|
|
1159
|
+
toolCalls.push(toolCall);
|
|
1160
|
+
}
|
|
1161
|
+
for (const toolCall2 of toolCalls) {
|
|
1162
|
+
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
1163
|
+
if (clientTool && clientTool.execute) {
|
|
1164
|
+
const result = await clientTool.execute(
|
|
1165
|
+
{
|
|
1166
|
+
context: toolCall2?.args,
|
|
1167
|
+
runId: processedParams.runId,
|
|
1168
|
+
resourceId: processedParams.resourceId,
|
|
1169
|
+
threadId: processedParams.threadId,
|
|
1170
|
+
runtimeContext: processedParams.runtimeContext,
|
|
1171
|
+
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1172
|
+
tracingContext: { currentSpan: void 0 }
|
|
1173
|
+
},
|
|
1174
|
+
{
|
|
1175
|
+
messages: response.messages,
|
|
1176
|
+
toolCallId: toolCall2?.toolCallId
|
|
1177
|
+
}
|
|
1178
|
+
);
|
|
1179
|
+
const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
|
|
1180
|
+
const toolInvocationPart = lastMessage?.parts?.find(
|
|
1181
|
+
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
1182
|
+
);
|
|
1183
|
+
if (toolInvocationPart) {
|
|
1184
|
+
toolInvocationPart.toolInvocation = {
|
|
1185
|
+
...toolInvocationPart.toolInvocation,
|
|
1186
|
+
state: "result",
|
|
1187
|
+
result
|
|
1188
|
+
};
|
|
1189
|
+
}
|
|
1190
|
+
const toolInvocation = lastMessage?.toolInvocations?.find(
|
|
1191
|
+
(toolInvocation2) => toolInvocation2.toolCallId === toolCall2.toolCallId
|
|
1192
|
+
);
|
|
1193
|
+
if (toolInvocation) {
|
|
1194
|
+
toolInvocation.state = "result";
|
|
1195
|
+
toolInvocation.result = result;
|
|
1196
|
+
}
|
|
1197
|
+
const writer = writable.getWriter();
|
|
1198
|
+
try {
|
|
1199
|
+
await writer.write(
|
|
1200
|
+
new TextEncoder().encode(
|
|
1201
|
+
"a:" + JSON.stringify({
|
|
1202
|
+
toolCallId: toolCall2.toolCallId,
|
|
1203
|
+
result
|
|
1204
|
+
}) + "\n"
|
|
1205
|
+
)
|
|
1206
|
+
);
|
|
1207
|
+
} finally {
|
|
1208
|
+
writer.releaseLock();
|
|
1209
|
+
}
|
|
1210
|
+
const originalMessages = processedParams.messages;
|
|
1211
|
+
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1212
|
+
this.processStreamResponse_vNext(
|
|
1213
|
+
{
|
|
1214
|
+
...processedParams,
|
|
1215
|
+
messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
|
|
1216
|
+
},
|
|
1217
|
+
writable
|
|
1218
|
+
).catch((error) => {
|
|
1219
|
+
console.error("Error processing stream response:", error);
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
} else {
|
|
1224
|
+
setTimeout(() => {
|
|
1225
|
+
writable.close();
|
|
1226
|
+
}, 0);
|
|
1227
|
+
}
|
|
1228
|
+
},
|
|
1229
|
+
lastMessage: void 0
|
|
1230
|
+
}).catch((error) => {
|
|
1231
|
+
console.error("Error processing stream response:", error);
|
|
1232
|
+
});
|
|
1233
|
+
} catch (error) {
|
|
1234
|
+
console.error("Error processing stream response:", error);
|
|
1235
|
+
}
|
|
1236
|
+
return response;
|
|
1237
|
+
}
|
|
1238
|
+
async streamVNext(params) {
|
|
1239
|
+
const processedParams = {
|
|
1240
|
+
...params,
|
|
1241
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
1242
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
1243
|
+
clientTools: processClientTools(params.clientTools)
|
|
1244
|
+
};
|
|
1245
|
+
const { readable, writable } = new TransformStream();
|
|
1246
|
+
const response = await this.processStreamResponse_vNext(processedParams, writable);
|
|
1247
|
+
const streamResponse = new Response(readable, {
|
|
1248
|
+
status: response.status,
|
|
1249
|
+
statusText: response.statusText,
|
|
1250
|
+
headers: response.headers
|
|
1251
|
+
});
|
|
1252
|
+
streamResponse.processDataStream = async ({
|
|
1253
|
+
onChunk
|
|
1254
|
+
}) => {
|
|
1255
|
+
await processMastraStream({
|
|
1256
|
+
stream: streamResponse.body,
|
|
1257
|
+
onChunk
|
|
367
1258
|
});
|
|
368
1259
|
};
|
|
1260
|
+
return streamResponse;
|
|
1261
|
+
}
|
|
1262
|
+
/**
|
|
1263
|
+
* Processes the stream response and handles tool calls
|
|
1264
|
+
*/
|
|
1265
|
+
async processStreamResponse(processedParams, writable) {
|
|
1266
|
+
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
1267
|
+
method: "POST",
|
|
1268
|
+
body: processedParams,
|
|
1269
|
+
stream: true
|
|
1270
|
+
});
|
|
1271
|
+
if (!response.body) {
|
|
1272
|
+
throw new Error("No response body");
|
|
1273
|
+
}
|
|
1274
|
+
try {
|
|
1275
|
+
let toolCalls = [];
|
|
1276
|
+
let messages = [];
|
|
1277
|
+
const [streamForWritable, streamForProcessing] = response.body.tee();
|
|
1278
|
+
streamForWritable.pipeTo(writable, {
|
|
1279
|
+
preventClose: true
|
|
1280
|
+
}).catch((error) => {
|
|
1281
|
+
console.error("Error piping to writable stream:", error);
|
|
1282
|
+
});
|
|
1283
|
+
this.processChatResponse({
|
|
1284
|
+
stream: streamForProcessing,
|
|
1285
|
+
update: ({ message }) => {
|
|
1286
|
+
const existingIndex = messages.findIndex((m) => m.id === message.id);
|
|
1287
|
+
if (existingIndex !== -1) {
|
|
1288
|
+
messages[existingIndex] = message;
|
|
1289
|
+
} else {
|
|
1290
|
+
messages.push(message);
|
|
1291
|
+
}
|
|
1292
|
+
},
|
|
1293
|
+
onFinish: async ({ finishReason, message }) => {
|
|
1294
|
+
if (finishReason === "tool-calls") {
|
|
1295
|
+
const toolCall = [...message?.parts ?? []].reverse().find((part) => part.type === "tool-invocation")?.toolInvocation;
|
|
1296
|
+
if (toolCall) {
|
|
1297
|
+
toolCalls.push(toolCall);
|
|
1298
|
+
}
|
|
1299
|
+
for (const toolCall2 of toolCalls) {
|
|
1300
|
+
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
1301
|
+
if (clientTool && clientTool.execute) {
|
|
1302
|
+
const result = await clientTool.execute(
|
|
1303
|
+
{
|
|
1304
|
+
context: toolCall2?.args,
|
|
1305
|
+
runId: processedParams.runId,
|
|
1306
|
+
resourceId: processedParams.resourceId,
|
|
1307
|
+
threadId: processedParams.threadId,
|
|
1308
|
+
runtimeContext: processedParams.runtimeContext,
|
|
1309
|
+
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1310
|
+
tracingContext: { currentSpan: void 0 }
|
|
1311
|
+
},
|
|
1312
|
+
{
|
|
1313
|
+
messages: response.messages,
|
|
1314
|
+
toolCallId: toolCall2?.toolCallId
|
|
1315
|
+
}
|
|
1316
|
+
);
|
|
1317
|
+
const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
|
|
1318
|
+
const toolInvocationPart = lastMessage?.parts?.find(
|
|
1319
|
+
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
1320
|
+
);
|
|
1321
|
+
if (toolInvocationPart) {
|
|
1322
|
+
toolInvocationPart.toolInvocation = {
|
|
1323
|
+
...toolInvocationPart.toolInvocation,
|
|
1324
|
+
state: "result",
|
|
1325
|
+
result
|
|
1326
|
+
};
|
|
1327
|
+
}
|
|
1328
|
+
const toolInvocation = lastMessage?.toolInvocations?.find(
|
|
1329
|
+
(toolInvocation2) => toolInvocation2.toolCallId === toolCall2.toolCallId
|
|
1330
|
+
);
|
|
1331
|
+
if (toolInvocation) {
|
|
1332
|
+
toolInvocation.state = "result";
|
|
1333
|
+
toolInvocation.result = result;
|
|
1334
|
+
}
|
|
1335
|
+
const writer = writable.getWriter();
|
|
1336
|
+
try {
|
|
1337
|
+
await writer.write(
|
|
1338
|
+
new TextEncoder().encode(
|
|
1339
|
+
"a:" + JSON.stringify({
|
|
1340
|
+
toolCallId: toolCall2.toolCallId,
|
|
1341
|
+
result
|
|
1342
|
+
}) + "\n"
|
|
1343
|
+
)
|
|
1344
|
+
);
|
|
1345
|
+
} finally {
|
|
1346
|
+
writer.releaseLock();
|
|
1347
|
+
}
|
|
1348
|
+
const originalMessages = processedParams.messages;
|
|
1349
|
+
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1350
|
+
this.processStreamResponse(
|
|
1351
|
+
{
|
|
1352
|
+
...processedParams,
|
|
1353
|
+
messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
|
|
1354
|
+
},
|
|
1355
|
+
writable
|
|
1356
|
+
).catch((error) => {
|
|
1357
|
+
console.error("Error processing stream response:", error);
|
|
1358
|
+
});
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
} else {
|
|
1362
|
+
setTimeout(() => {
|
|
1363
|
+
writable.close();
|
|
1364
|
+
}, 0);
|
|
1365
|
+
}
|
|
1366
|
+
},
|
|
1367
|
+
lastMessage: void 0
|
|
1368
|
+
}).catch((error) => {
|
|
1369
|
+
console.error("Error processing stream response:", error);
|
|
1370
|
+
});
|
|
1371
|
+
} catch (error) {
|
|
1372
|
+
console.error("Error processing stream response:", error);
|
|
1373
|
+
}
|
|
369
1374
|
return response;
|
|
370
1375
|
}
|
|
371
1376
|
/**
|
|
@@ -406,6 +1411,17 @@ var Agent = class extends BaseResource {
|
|
|
406
1411
|
liveEvals() {
|
|
407
1412
|
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
408
1413
|
}
|
|
1414
|
+
/**
|
|
1415
|
+
* Updates the model for the agent
|
|
1416
|
+
* @param params - Parameters for updating the model
|
|
1417
|
+
* @returns Promise containing the updated model
|
|
1418
|
+
*/
|
|
1419
|
+
updateModel(params) {
|
|
1420
|
+
return this.request(`/api/agents/${this.agentId}/model`, {
|
|
1421
|
+
method: "POST",
|
|
1422
|
+
body: params
|
|
1423
|
+
});
|
|
1424
|
+
}
|
|
409
1425
|
};
|
|
410
1426
|
var Network = class extends BaseResource {
|
|
411
1427
|
constructor(options, networkId) {
|
|
@@ -510,6 +1526,36 @@ var MemoryThread = class extends BaseResource {
|
|
|
510
1526
|
});
|
|
511
1527
|
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
512
1528
|
}
|
|
1529
|
+
/**
|
|
1530
|
+
* Retrieves paginated messages associated with the thread with advanced filtering and selection options
|
|
1531
|
+
* @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
|
|
1532
|
+
* @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
|
|
1533
|
+
*/
|
|
1534
|
+
getMessagesPaginated({
|
|
1535
|
+
selectBy,
|
|
1536
|
+
...rest
|
|
1537
|
+
}) {
|
|
1538
|
+
const query = new URLSearchParams({
|
|
1539
|
+
...rest,
|
|
1540
|
+
...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
|
|
1541
|
+
});
|
|
1542
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
|
|
1543
|
+
}
|
|
1544
|
+
/**
|
|
1545
|
+
* Deletes one or more messages from the thread
|
|
1546
|
+
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
1547
|
+
* message object with id property, or array of message objects
|
|
1548
|
+
* @returns Promise containing deletion result
|
|
1549
|
+
*/
|
|
1550
|
+
deleteMessages(messageIds) {
|
|
1551
|
+
const query = new URLSearchParams({
|
|
1552
|
+
agentId: this.agentId
|
|
1553
|
+
});
|
|
1554
|
+
return this.request(`/api/memory/messages/delete?${query.toString()}`, {
|
|
1555
|
+
method: "POST",
|
|
1556
|
+
body: { messageIds }
|
|
1557
|
+
});
|
|
1558
|
+
}
|
|
513
1559
|
};
|
|
514
1560
|
|
|
515
1561
|
// src/resources/vector.ts
|
|
@@ -578,24 +1624,24 @@ var Vector = class extends BaseResource {
|
|
|
578
1624
|
}
|
|
579
1625
|
};
|
|
580
1626
|
|
|
581
|
-
// src/resources/workflow.ts
|
|
1627
|
+
// src/resources/legacy-workflow.ts
|
|
582
1628
|
var RECORD_SEPARATOR = "";
|
|
583
|
-
var
|
|
1629
|
+
var LegacyWorkflow = class extends BaseResource {
|
|
584
1630
|
constructor(options, workflowId) {
|
|
585
1631
|
super(options);
|
|
586
1632
|
this.workflowId = workflowId;
|
|
587
1633
|
}
|
|
588
1634
|
/**
|
|
589
|
-
* Retrieves details about the workflow
|
|
590
|
-
* @returns Promise containing workflow details including steps and graphs
|
|
1635
|
+
* Retrieves details about the legacy workflow
|
|
1636
|
+
* @returns Promise containing legacy workflow details including steps and graphs
|
|
591
1637
|
*/
|
|
592
1638
|
details() {
|
|
593
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
1639
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}`);
|
|
594
1640
|
}
|
|
595
1641
|
/**
|
|
596
|
-
* Retrieves all runs for a workflow
|
|
1642
|
+
* Retrieves all runs for a legacy workflow
|
|
597
1643
|
* @param params - Parameters for filtering runs
|
|
598
|
-
* @returns Promise containing workflow runs array
|
|
1644
|
+
* @returns Promise containing legacy workflow runs array
|
|
599
1645
|
*/
|
|
600
1646
|
runs(params) {
|
|
601
1647
|
const searchParams = new URLSearchParams();
|
|
@@ -615,25 +1661,13 @@ var Workflow = class extends BaseResource {
|
|
|
615
1661
|
searchParams.set("resourceId", params.resourceId);
|
|
616
1662
|
}
|
|
617
1663
|
if (searchParams.size) {
|
|
618
|
-
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
1664
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
619
1665
|
} else {
|
|
620
|
-
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
1666
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
621
1667
|
}
|
|
622
1668
|
}
|
|
623
1669
|
/**
|
|
624
|
-
*
|
|
625
|
-
* Executes the workflow with the provided parameters
|
|
626
|
-
* @param params - Parameters required for workflow execution
|
|
627
|
-
* @returns Promise containing the workflow execution results
|
|
628
|
-
*/
|
|
629
|
-
execute(params) {
|
|
630
|
-
return this.request(`/api/workflows/${this.workflowId}/execute`, {
|
|
631
|
-
method: "POST",
|
|
632
|
-
body: params
|
|
633
|
-
});
|
|
634
|
-
}
|
|
635
|
-
/**
|
|
636
|
-
* Creates a new workflow run
|
|
1670
|
+
* Creates a new legacy workflow run
|
|
637
1671
|
* @returns Promise containing the generated run ID
|
|
638
1672
|
*/
|
|
639
1673
|
createRun(params) {
|
|
@@ -641,34 +1675,34 @@ var Workflow = class extends BaseResource {
|
|
|
641
1675
|
if (!!params?.runId) {
|
|
642
1676
|
searchParams.set("runId", params.runId);
|
|
643
1677
|
}
|
|
644
|
-
return this.request(`/api/workflows/${this.workflowId}/
|
|
1678
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
645
1679
|
method: "POST"
|
|
646
1680
|
});
|
|
647
1681
|
}
|
|
648
1682
|
/**
|
|
649
|
-
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1683
|
+
* Starts a legacy workflow run synchronously without waiting for the workflow to complete
|
|
650
1684
|
* @param params - Object containing the runId and triggerData
|
|
651
1685
|
* @returns Promise containing success message
|
|
652
1686
|
*/
|
|
653
1687
|
start(params) {
|
|
654
|
-
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1688
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
655
1689
|
method: "POST",
|
|
656
1690
|
body: params?.triggerData
|
|
657
1691
|
});
|
|
658
1692
|
}
|
|
659
1693
|
/**
|
|
660
|
-
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
1694
|
+
* Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
|
|
661
1695
|
* @param stepId - ID of the step to resume
|
|
662
|
-
* @param runId - ID of the workflow run
|
|
663
|
-
* @param context - Context to resume the workflow with
|
|
664
|
-
* @returns Promise containing the workflow resume results
|
|
1696
|
+
* @param runId - ID of the legacy workflow run
|
|
1697
|
+
* @param context - Context to resume the legacy workflow with
|
|
1698
|
+
* @returns Promise containing the legacy workflow resume results
|
|
665
1699
|
*/
|
|
666
1700
|
resume({
|
|
667
1701
|
stepId,
|
|
668
1702
|
runId,
|
|
669
1703
|
context
|
|
670
1704
|
}) {
|
|
671
|
-
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1705
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
672
1706
|
method: "POST",
|
|
673
1707
|
body: {
|
|
674
1708
|
stepId,
|
|
@@ -686,18 +1720,18 @@ var Workflow = class extends BaseResource {
|
|
|
686
1720
|
if (!!params?.runId) {
|
|
687
1721
|
searchParams.set("runId", params.runId);
|
|
688
1722
|
}
|
|
689
|
-
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1723
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
690
1724
|
method: "POST",
|
|
691
1725
|
body: params?.triggerData
|
|
692
1726
|
});
|
|
693
1727
|
}
|
|
694
1728
|
/**
|
|
695
|
-
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
1729
|
+
* Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
696
1730
|
* @param params - Object containing the runId, stepId, and context
|
|
697
1731
|
* @returns Promise containing the workflow resume results
|
|
698
1732
|
*/
|
|
699
1733
|
resumeAsync(params) {
|
|
700
|
-
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
1734
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
701
1735
|
method: "POST",
|
|
702
1736
|
body: {
|
|
703
1737
|
stepId: params.stepId,
|
|
@@ -751,16 +1785,16 @@ var Workflow = class extends BaseResource {
|
|
|
751
1785
|
}
|
|
752
1786
|
}
|
|
753
1787
|
/**
|
|
754
|
-
* Watches workflow transitions in real-time
|
|
1788
|
+
* Watches legacy workflow transitions in real-time
|
|
755
1789
|
* @param runId - Optional run ID to filter the watch stream
|
|
756
|
-
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
1790
|
+
* @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
|
|
757
1791
|
*/
|
|
758
1792
|
async watch({ runId }, onRecord) {
|
|
759
|
-
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
1793
|
+
const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
|
|
760
1794
|
stream: true
|
|
761
1795
|
});
|
|
762
1796
|
if (!response.ok) {
|
|
763
|
-
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
1797
|
+
throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
|
|
764
1798
|
}
|
|
765
1799
|
if (!response.body) {
|
|
766
1800
|
throw new Error("Response body is null");
|
|
@@ -796,7 +1830,7 @@ var Tool = class extends BaseResource {
|
|
|
796
1830
|
}
|
|
797
1831
|
const body = {
|
|
798
1832
|
data: params.data,
|
|
799
|
-
runtimeContext:
|
|
1833
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
800
1834
|
};
|
|
801
1835
|
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
802
1836
|
method: "POST",
|
|
@@ -805,15 +1839,15 @@ var Tool = class extends BaseResource {
|
|
|
805
1839
|
}
|
|
806
1840
|
};
|
|
807
1841
|
|
|
808
|
-
// src/resources/
|
|
1842
|
+
// src/resources/workflow.ts
|
|
809
1843
|
var RECORD_SEPARATOR2 = "";
|
|
810
|
-
var
|
|
1844
|
+
var Workflow = class extends BaseResource {
|
|
811
1845
|
constructor(options, workflowId) {
|
|
812
1846
|
super(options);
|
|
813
1847
|
this.workflowId = workflowId;
|
|
814
1848
|
}
|
|
815
1849
|
/**
|
|
816
|
-
* Creates an async generator that processes a readable stream and yields
|
|
1850
|
+
* Creates an async generator that processes a readable stream and yields workflow records
|
|
817
1851
|
* separated by the Record Separator character (\x1E)
|
|
818
1852
|
*
|
|
819
1853
|
* @param stream - The readable stream to process
|
|
@@ -858,16 +1892,16 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
858
1892
|
}
|
|
859
1893
|
}
|
|
860
1894
|
/**
|
|
861
|
-
* Retrieves details about the
|
|
862
|
-
* @returns Promise containing
|
|
1895
|
+
* Retrieves details about the workflow
|
|
1896
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
863
1897
|
*/
|
|
864
1898
|
details() {
|
|
865
|
-
return this.request(`/api/workflows
|
|
1899
|
+
return this.request(`/api/workflows/${this.workflowId}`);
|
|
866
1900
|
}
|
|
867
1901
|
/**
|
|
868
|
-
* Retrieves all runs for a
|
|
1902
|
+
* Retrieves all runs for a workflow
|
|
869
1903
|
* @param params - Parameters for filtering runs
|
|
870
|
-
* @returns Promise containing
|
|
1904
|
+
* @returns Promise containing workflow runs array
|
|
871
1905
|
*/
|
|
872
1906
|
runs(params) {
|
|
873
1907
|
const searchParams = new URLSearchParams();
|
|
@@ -877,23 +1911,60 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
877
1911
|
if (params?.toDate) {
|
|
878
1912
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
879
1913
|
}
|
|
880
|
-
if (params?.limit) {
|
|
1914
|
+
if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
|
|
881
1915
|
searchParams.set("limit", String(params.limit));
|
|
882
1916
|
}
|
|
883
|
-
if (params?.offset) {
|
|
1917
|
+
if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
|
|
884
1918
|
searchParams.set("offset", String(params.offset));
|
|
885
1919
|
}
|
|
886
1920
|
if (params?.resourceId) {
|
|
887
1921
|
searchParams.set("resourceId", params.resourceId);
|
|
888
1922
|
}
|
|
889
1923
|
if (searchParams.size) {
|
|
890
|
-
return this.request(`/api/workflows
|
|
1924
|
+
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
891
1925
|
} else {
|
|
892
|
-
return this.request(`/api/workflows
|
|
1926
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
893
1927
|
}
|
|
894
1928
|
}
|
|
895
1929
|
/**
|
|
896
|
-
*
|
|
1930
|
+
* Retrieves a specific workflow run by its ID
|
|
1931
|
+
* @param runId - The ID of the workflow run to retrieve
|
|
1932
|
+
* @returns Promise containing the workflow run details
|
|
1933
|
+
*/
|
|
1934
|
+
runById(runId) {
|
|
1935
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
|
|
1936
|
+
}
|
|
1937
|
+
/**
|
|
1938
|
+
* Retrieves the execution result for a specific workflow run by its ID
|
|
1939
|
+
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1940
|
+
* @returns Promise containing the workflow run execution result
|
|
1941
|
+
*/
|
|
1942
|
+
runExecutionResult(runId) {
|
|
1943
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
|
|
1944
|
+
}
|
|
1945
|
+
/**
|
|
1946
|
+
* Cancels a specific workflow run by its ID
|
|
1947
|
+
* @param runId - The ID of the workflow run to cancel
|
|
1948
|
+
* @returns Promise containing a success message
|
|
1949
|
+
*/
|
|
1950
|
+
cancelRun(runId) {
|
|
1951
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/cancel`, {
|
|
1952
|
+
method: "POST"
|
|
1953
|
+
});
|
|
1954
|
+
}
|
|
1955
|
+
/**
|
|
1956
|
+
* Sends an event to a specific workflow run by its ID
|
|
1957
|
+
* @param params - Object containing the runId, event and data
|
|
1958
|
+
* @returns Promise containing a success message
|
|
1959
|
+
*/
|
|
1960
|
+
sendRunEvent(params) {
|
|
1961
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
|
|
1962
|
+
method: "POST",
|
|
1963
|
+
body: { event: params.event, data: params.data }
|
|
1964
|
+
});
|
|
1965
|
+
}
|
|
1966
|
+
/**
|
|
1967
|
+
* Creates a new workflow run
|
|
897
1968
|
* @param params - Optional object containing the optional runId
|
|
898
1969
|
* @returns Promise containing the runId of the created run
|
|
899
1970
|
*/
|
|
@@ -902,24 +1973,32 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
902
1973
|
if (!!params?.runId) {
|
|
903
1974
|
searchParams.set("runId", params.runId);
|
|
904
1975
|
}
|
|
905
|
-
return this.request(`/api/workflows
|
|
1976
|
+
return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
906
1977
|
method: "POST"
|
|
907
1978
|
});
|
|
908
1979
|
}
|
|
909
1980
|
/**
|
|
910
|
-
*
|
|
1981
|
+
* Creates a new workflow run (alias for createRun)
|
|
1982
|
+
* @param params - Optional object containing the optional runId
|
|
1983
|
+
* @returns Promise containing the runId of the created run
|
|
1984
|
+
*/
|
|
1985
|
+
createRunAsync(params) {
|
|
1986
|
+
return this.createRun(params);
|
|
1987
|
+
}
|
|
1988
|
+
/**
|
|
1989
|
+
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
911
1990
|
* @param params - Object containing the runId, inputData and runtimeContext
|
|
912
1991
|
* @returns Promise containing success message
|
|
913
1992
|
*/
|
|
914
1993
|
start(params) {
|
|
915
|
-
const runtimeContext =
|
|
916
|
-
return this.request(`/api/workflows
|
|
1994
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1995
|
+
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
917
1996
|
method: "POST",
|
|
918
1997
|
body: { inputData: params?.inputData, runtimeContext }
|
|
919
1998
|
});
|
|
920
1999
|
}
|
|
921
2000
|
/**
|
|
922
|
-
* Resumes a suspended
|
|
2001
|
+
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
923
2002
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
924
2003
|
* @returns Promise containing success message
|
|
925
2004
|
*/
|
|
@@ -929,8 +2008,8 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
929
2008
|
resumeData,
|
|
930
2009
|
...rest
|
|
931
2010
|
}) {
|
|
932
|
-
const runtimeContext =
|
|
933
|
-
return this.request(`/api/workflows
|
|
2011
|
+
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
2012
|
+
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
934
2013
|
method: "POST",
|
|
935
2014
|
stream: true,
|
|
936
2015
|
body: {
|
|
@@ -941,29 +2020,80 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
941
2020
|
});
|
|
942
2021
|
}
|
|
943
2022
|
/**
|
|
944
|
-
* Starts a
|
|
2023
|
+
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
945
2024
|
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
946
|
-
* @returns Promise containing the
|
|
2025
|
+
* @returns Promise containing the workflow execution results
|
|
947
2026
|
*/
|
|
948
2027
|
startAsync(params) {
|
|
949
2028
|
const searchParams = new URLSearchParams();
|
|
950
2029
|
if (!!params?.runId) {
|
|
951
2030
|
searchParams.set("runId", params.runId);
|
|
952
2031
|
}
|
|
953
|
-
const runtimeContext =
|
|
954
|
-
return this.request(`/api/workflows
|
|
2032
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2033
|
+
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
955
2034
|
method: "POST",
|
|
956
2035
|
body: { inputData: params.inputData, runtimeContext }
|
|
957
2036
|
});
|
|
958
2037
|
}
|
|
959
2038
|
/**
|
|
960
|
-
*
|
|
2039
|
+
* Starts a workflow run and returns a stream
|
|
2040
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
2041
|
+
* @returns Promise containing the workflow execution results
|
|
2042
|
+
*/
|
|
2043
|
+
async stream(params) {
|
|
2044
|
+
const searchParams = new URLSearchParams();
|
|
2045
|
+
if (!!params?.runId) {
|
|
2046
|
+
searchParams.set("runId", params.runId);
|
|
2047
|
+
}
|
|
2048
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2049
|
+
const response = await this.request(
|
|
2050
|
+
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
2051
|
+
{
|
|
2052
|
+
method: "POST",
|
|
2053
|
+
body: { inputData: params.inputData, runtimeContext },
|
|
2054
|
+
stream: true
|
|
2055
|
+
}
|
|
2056
|
+
);
|
|
2057
|
+
if (!response.ok) {
|
|
2058
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
2059
|
+
}
|
|
2060
|
+
if (!response.body) {
|
|
2061
|
+
throw new Error("Response body is null");
|
|
2062
|
+
}
|
|
2063
|
+
let failedChunk = void 0;
|
|
2064
|
+
const transformStream = new TransformStream({
|
|
2065
|
+
start() {
|
|
2066
|
+
},
|
|
2067
|
+
async transform(chunk, controller) {
|
|
2068
|
+
try {
|
|
2069
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2070
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2071
|
+
for (const chunk2 of chunks) {
|
|
2072
|
+
if (chunk2) {
|
|
2073
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2074
|
+
try {
|
|
2075
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2076
|
+
controller.enqueue(parsedChunk);
|
|
2077
|
+
failedChunk = void 0;
|
|
2078
|
+
} catch {
|
|
2079
|
+
failedChunk = newChunk;
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
} catch {
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
});
|
|
2087
|
+
return response.body.pipeThrough(transformStream);
|
|
2088
|
+
}
|
|
2089
|
+
/**
|
|
2090
|
+
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
961
2091
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
962
|
-
* @returns Promise containing the
|
|
2092
|
+
* @returns Promise containing the workflow resume results
|
|
963
2093
|
*/
|
|
964
2094
|
resumeAsync(params) {
|
|
965
|
-
const runtimeContext =
|
|
966
|
-
return this.request(`/api/workflows
|
|
2095
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2096
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
967
2097
|
method: "POST",
|
|
968
2098
|
body: {
|
|
969
2099
|
step: params.step,
|
|
@@ -973,24 +2103,51 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
973
2103
|
});
|
|
974
2104
|
}
|
|
975
2105
|
/**
|
|
976
|
-
* Watches
|
|
2106
|
+
* Watches workflow transitions in real-time
|
|
977
2107
|
* @param runId - Optional run ID to filter the watch stream
|
|
978
|
-
* @returns AsyncGenerator that yields parsed records from the
|
|
2108
|
+
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
979
2109
|
*/
|
|
980
2110
|
async watch({ runId }, onRecord) {
|
|
981
|
-
const response = await this.request(`/api/workflows
|
|
2111
|
+
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
982
2112
|
stream: true
|
|
983
2113
|
});
|
|
984
2114
|
if (!response.ok) {
|
|
985
|
-
throw new Error(`Failed to watch
|
|
2115
|
+
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
986
2116
|
}
|
|
987
2117
|
if (!response.body) {
|
|
988
2118
|
throw new Error("Response body is null");
|
|
989
2119
|
}
|
|
990
2120
|
for await (const record of this.streamProcessor(response.body)) {
|
|
991
|
-
|
|
2121
|
+
if (typeof record === "string") {
|
|
2122
|
+
onRecord(JSON.parse(record));
|
|
2123
|
+
} else {
|
|
2124
|
+
onRecord(record);
|
|
2125
|
+
}
|
|
992
2126
|
}
|
|
993
2127
|
}
|
|
2128
|
+
/**
|
|
2129
|
+
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
2130
|
+
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
2131
|
+
*
|
|
2132
|
+
* @param records - An iterable or async iterable of objects to stream
|
|
2133
|
+
* @returns A ReadableStream emitting the records as JSON strings separated by the record separator
|
|
2134
|
+
*/
|
|
2135
|
+
static createRecordStream(records) {
|
|
2136
|
+
const encoder = new TextEncoder();
|
|
2137
|
+
return new ReadableStream({
|
|
2138
|
+
async start(controller) {
|
|
2139
|
+
try {
|
|
2140
|
+
for await (const record of records) {
|
|
2141
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR2;
|
|
2142
|
+
controller.enqueue(encoder.encode(json));
|
|
2143
|
+
}
|
|
2144
|
+
controller.close();
|
|
2145
|
+
} catch (err) {
|
|
2146
|
+
controller.error(err);
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
});
|
|
2150
|
+
}
|
|
994
2151
|
};
|
|
995
2152
|
|
|
996
2153
|
// src/resources/a2a.ts
|
|
@@ -1004,22 +2161,38 @@ var A2A = class extends BaseResource {
|
|
|
1004
2161
|
* @returns Promise containing the agent card information
|
|
1005
2162
|
*/
|
|
1006
2163
|
async getCard() {
|
|
1007
|
-
return this.request(`/.well-known/${this.agentId}/agent.json`);
|
|
2164
|
+
return this.request(`/.well-known/${this.agentId}/agent-card.json`);
|
|
1008
2165
|
}
|
|
1009
2166
|
/**
|
|
1010
|
-
* Send a message to the agent and
|
|
2167
|
+
* Send a message to the agent and gets a message or task response
|
|
1011
2168
|
* @param params - Parameters for the task
|
|
1012
|
-
* @returns Promise containing the
|
|
2169
|
+
* @returns Promise containing the response
|
|
1013
2170
|
*/
|
|
1014
2171
|
async sendMessage(params) {
|
|
1015
2172
|
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1016
2173
|
method: "POST",
|
|
1017
2174
|
body: {
|
|
1018
|
-
method: "
|
|
2175
|
+
method: "message/send",
|
|
1019
2176
|
params
|
|
1020
2177
|
}
|
|
1021
2178
|
});
|
|
1022
|
-
return
|
|
2179
|
+
return response;
|
|
2180
|
+
}
|
|
2181
|
+
/**
|
|
2182
|
+
* Sends a message to an agent to initiate/continue a task and subscribes
|
|
2183
|
+
* the client to real-time updates for that task via Server-Sent Events (SSE).
|
|
2184
|
+
* @param params - Parameters for the task
|
|
2185
|
+
* @returns A stream of Server-Sent Events. Each SSE `data` field contains a `SendStreamingMessageResponse`
|
|
2186
|
+
*/
|
|
2187
|
+
async sendStreamingMessage(params) {
|
|
2188
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
2189
|
+
method: "POST",
|
|
2190
|
+
body: {
|
|
2191
|
+
method: "message/stream",
|
|
2192
|
+
params
|
|
2193
|
+
}
|
|
2194
|
+
});
|
|
2195
|
+
return response;
|
|
1023
2196
|
}
|
|
1024
2197
|
/**
|
|
1025
2198
|
* Get the status and result of a task
|
|
@@ -1034,7 +2207,7 @@ var A2A = class extends BaseResource {
|
|
|
1034
2207
|
params
|
|
1035
2208
|
}
|
|
1036
2209
|
});
|
|
1037
|
-
return response
|
|
2210
|
+
return response;
|
|
1038
2211
|
}
|
|
1039
2212
|
/**
|
|
1040
2213
|
* Cancel a running task
|
|
@@ -1050,21 +2223,6 @@ var A2A = class extends BaseResource {
|
|
|
1050
2223
|
}
|
|
1051
2224
|
});
|
|
1052
2225
|
}
|
|
1053
|
-
/**
|
|
1054
|
-
* Send a message and subscribe to streaming updates (not fully implemented)
|
|
1055
|
-
* @param params - Parameters for the task
|
|
1056
|
-
* @returns Promise containing the task response
|
|
1057
|
-
*/
|
|
1058
|
-
async sendAndSubscribe(params) {
|
|
1059
|
-
return this.request(`/a2a/${this.agentId}`, {
|
|
1060
|
-
method: "POST",
|
|
1061
|
-
body: {
|
|
1062
|
-
method: "tasks/sendSubscribe",
|
|
1063
|
-
params
|
|
1064
|
-
},
|
|
1065
|
-
stream: true
|
|
1066
|
-
});
|
|
1067
|
-
}
|
|
1068
2226
|
};
|
|
1069
2227
|
|
|
1070
2228
|
// src/resources/mcp-tool.ts
|
|
@@ -1101,10 +2259,260 @@ var MCPTool = class extends BaseResource {
|
|
|
1101
2259
|
}
|
|
1102
2260
|
};
|
|
1103
2261
|
|
|
2262
|
+
// src/resources/observability.ts
|
|
2263
|
+
var Observability = class extends BaseResource {
|
|
2264
|
+
constructor(options) {
|
|
2265
|
+
super(options);
|
|
2266
|
+
}
|
|
2267
|
+
/**
|
|
2268
|
+
* Retrieves a specific AI trace by ID
|
|
2269
|
+
* @param traceId - ID of the trace to retrieve
|
|
2270
|
+
* @returns Promise containing the AI trace with all its spans
|
|
2271
|
+
*/
|
|
2272
|
+
getTrace(traceId) {
|
|
2273
|
+
return this.request(`/api/observability/traces/${traceId}`);
|
|
2274
|
+
}
|
|
2275
|
+
/**
|
|
2276
|
+
* Retrieves paginated list of AI traces with optional filtering
|
|
2277
|
+
* @param params - Parameters for pagination and filtering
|
|
2278
|
+
* @returns Promise containing paginated traces and pagination info
|
|
2279
|
+
*/
|
|
2280
|
+
getTraces(params) {
|
|
2281
|
+
const { pagination, filters } = params;
|
|
2282
|
+
const { page, perPage, dateRange } = pagination || {};
|
|
2283
|
+
const { name, spanType } = filters || {};
|
|
2284
|
+
const searchParams = new URLSearchParams();
|
|
2285
|
+
if (page !== void 0) {
|
|
2286
|
+
searchParams.set("page", String(page));
|
|
2287
|
+
}
|
|
2288
|
+
if (perPage !== void 0) {
|
|
2289
|
+
searchParams.set("perPage", String(perPage));
|
|
2290
|
+
}
|
|
2291
|
+
if (name) {
|
|
2292
|
+
searchParams.set("name", name);
|
|
2293
|
+
}
|
|
2294
|
+
if (spanType !== void 0) {
|
|
2295
|
+
searchParams.set("spanType", String(spanType));
|
|
2296
|
+
}
|
|
2297
|
+
if (dateRange) {
|
|
2298
|
+
const dateRangeStr = JSON.stringify({
|
|
2299
|
+
start: dateRange.start instanceof Date ? dateRange.start.toISOString() : dateRange.start,
|
|
2300
|
+
end: dateRange.end instanceof Date ? dateRange.end.toISOString() : dateRange.end
|
|
2301
|
+
});
|
|
2302
|
+
searchParams.set("dateRange", dateRangeStr);
|
|
2303
|
+
}
|
|
2304
|
+
const queryString = searchParams.toString();
|
|
2305
|
+
return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
|
|
2306
|
+
}
|
|
2307
|
+
};
|
|
2308
|
+
|
|
2309
|
+
// src/resources/network-memory-thread.ts
|
|
2310
|
+
var NetworkMemoryThread = class extends BaseResource {
|
|
2311
|
+
constructor(options, threadId, networkId) {
|
|
2312
|
+
super(options);
|
|
2313
|
+
this.threadId = threadId;
|
|
2314
|
+
this.networkId = networkId;
|
|
2315
|
+
}
|
|
2316
|
+
/**
|
|
2317
|
+
* Retrieves the memory thread details
|
|
2318
|
+
* @returns Promise containing thread details including title and metadata
|
|
2319
|
+
*/
|
|
2320
|
+
get() {
|
|
2321
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
2322
|
+
}
|
|
2323
|
+
/**
|
|
2324
|
+
* Updates the memory thread properties
|
|
2325
|
+
* @param params - Update parameters including title and metadata
|
|
2326
|
+
* @returns Promise containing updated thread details
|
|
2327
|
+
*/
|
|
2328
|
+
update(params) {
|
|
2329
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
2330
|
+
method: "PATCH",
|
|
2331
|
+
body: params
|
|
2332
|
+
});
|
|
2333
|
+
}
|
|
2334
|
+
/**
|
|
2335
|
+
* Deletes the memory thread
|
|
2336
|
+
* @returns Promise containing deletion result
|
|
2337
|
+
*/
|
|
2338
|
+
delete() {
|
|
2339
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
2340
|
+
method: "DELETE"
|
|
2341
|
+
});
|
|
2342
|
+
}
|
|
2343
|
+
/**
|
|
2344
|
+
* Retrieves messages associated with the thread
|
|
2345
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
2346
|
+
* @returns Promise containing thread messages and UI messages
|
|
2347
|
+
*/
|
|
2348
|
+
getMessages(params) {
|
|
2349
|
+
const query = new URLSearchParams({
|
|
2350
|
+
networkId: this.networkId,
|
|
2351
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
2352
|
+
});
|
|
2353
|
+
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
2354
|
+
}
|
|
2355
|
+
/**
|
|
2356
|
+
* Deletes one or more messages from the thread
|
|
2357
|
+
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
2358
|
+
* message object with id property, or array of message objects
|
|
2359
|
+
* @returns Promise containing deletion result
|
|
2360
|
+
*/
|
|
2361
|
+
deleteMessages(messageIds) {
|
|
2362
|
+
const query = new URLSearchParams({
|
|
2363
|
+
networkId: this.networkId
|
|
2364
|
+
});
|
|
2365
|
+
return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
|
|
2366
|
+
method: "POST",
|
|
2367
|
+
body: { messageIds }
|
|
2368
|
+
});
|
|
2369
|
+
}
|
|
2370
|
+
};
|
|
2371
|
+
|
|
2372
|
+
// src/resources/vNextNetwork.ts
|
|
2373
|
+
var RECORD_SEPARATOR3 = "";
|
|
2374
|
+
var VNextNetwork = class extends BaseResource {
|
|
2375
|
+
constructor(options, networkId) {
|
|
2376
|
+
super(options);
|
|
2377
|
+
this.networkId = networkId;
|
|
2378
|
+
}
|
|
2379
|
+
/**
|
|
2380
|
+
* Retrieves details about the network
|
|
2381
|
+
* @returns Promise containing vNext network details
|
|
2382
|
+
*/
|
|
2383
|
+
details() {
|
|
2384
|
+
return this.request(`/api/networks/v-next/${this.networkId}`);
|
|
2385
|
+
}
|
|
2386
|
+
/**
|
|
2387
|
+
* Generates a response from the v-next network
|
|
2388
|
+
* @param params - Generation parameters including message
|
|
2389
|
+
* @returns Promise containing the generated response
|
|
2390
|
+
*/
|
|
2391
|
+
generate(params) {
|
|
2392
|
+
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
2393
|
+
method: "POST",
|
|
2394
|
+
body: {
|
|
2395
|
+
...params,
|
|
2396
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2397
|
+
}
|
|
2398
|
+
});
|
|
2399
|
+
}
|
|
2400
|
+
/**
|
|
2401
|
+
* Generates a response from the v-next network using multiple primitives
|
|
2402
|
+
* @param params - Generation parameters including message
|
|
2403
|
+
* @returns Promise containing the generated response
|
|
2404
|
+
*/
|
|
2405
|
+
loop(params) {
|
|
2406
|
+
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
2407
|
+
method: "POST",
|
|
2408
|
+
body: {
|
|
2409
|
+
...params,
|
|
2410
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2411
|
+
}
|
|
2412
|
+
});
|
|
2413
|
+
}
|
|
2414
|
+
async *streamProcessor(stream) {
|
|
2415
|
+
const reader = stream.getReader();
|
|
2416
|
+
let doneReading = false;
|
|
2417
|
+
let buffer = "";
|
|
2418
|
+
try {
|
|
2419
|
+
while (!doneReading) {
|
|
2420
|
+
const { done, value } = await reader.read();
|
|
2421
|
+
doneReading = done;
|
|
2422
|
+
if (done && !value) continue;
|
|
2423
|
+
try {
|
|
2424
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2425
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
2426
|
+
buffer = chunks.pop() || "";
|
|
2427
|
+
for (const chunk of chunks) {
|
|
2428
|
+
if (chunk) {
|
|
2429
|
+
if (typeof chunk === "string") {
|
|
2430
|
+
try {
|
|
2431
|
+
const parsedChunk = JSON.parse(chunk);
|
|
2432
|
+
yield parsedChunk;
|
|
2433
|
+
} catch {
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
} catch {
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
if (buffer) {
|
|
2442
|
+
try {
|
|
2443
|
+
yield JSON.parse(buffer);
|
|
2444
|
+
} catch {
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
} finally {
|
|
2448
|
+
reader.cancel().catch(() => {
|
|
2449
|
+
});
|
|
2450
|
+
}
|
|
2451
|
+
}
|
|
2452
|
+
/**
|
|
2453
|
+
* Streams a response from the v-next network
|
|
2454
|
+
* @param params - Stream parameters including message
|
|
2455
|
+
* @returns Promise containing the results
|
|
2456
|
+
*/
|
|
2457
|
+
async stream(params, onRecord) {
|
|
2458
|
+
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
2459
|
+
method: "POST",
|
|
2460
|
+
body: {
|
|
2461
|
+
...params,
|
|
2462
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2463
|
+
},
|
|
2464
|
+
stream: true
|
|
2465
|
+
});
|
|
2466
|
+
if (!response.ok) {
|
|
2467
|
+
throw new Error(`Failed to stream vNext network: ${response.statusText}`);
|
|
2468
|
+
}
|
|
2469
|
+
if (!response.body) {
|
|
2470
|
+
throw new Error("Response body is null");
|
|
2471
|
+
}
|
|
2472
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
2473
|
+
if (typeof record === "string") {
|
|
2474
|
+
onRecord(JSON.parse(record));
|
|
2475
|
+
} else {
|
|
2476
|
+
onRecord(record);
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
}
|
|
2480
|
+
/**
|
|
2481
|
+
* Streams a response from the v-next network loop
|
|
2482
|
+
* @param params - Stream parameters including message
|
|
2483
|
+
* @returns Promise containing the results
|
|
2484
|
+
*/
|
|
2485
|
+
async loopStream(params, onRecord) {
|
|
2486
|
+
const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
2487
|
+
method: "POST",
|
|
2488
|
+
body: {
|
|
2489
|
+
...params,
|
|
2490
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2491
|
+
},
|
|
2492
|
+
stream: true
|
|
2493
|
+
});
|
|
2494
|
+
if (!response.ok) {
|
|
2495
|
+
throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
|
|
2496
|
+
}
|
|
2497
|
+
if (!response.body) {
|
|
2498
|
+
throw new Error("Response body is null");
|
|
2499
|
+
}
|
|
2500
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
2501
|
+
if (typeof record === "string") {
|
|
2502
|
+
onRecord(JSON.parse(record));
|
|
2503
|
+
} else {
|
|
2504
|
+
onRecord(record);
|
|
2505
|
+
}
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
};
|
|
2509
|
+
|
|
1104
2510
|
// src/client.ts
|
|
1105
2511
|
var MastraClient = class extends BaseResource {
|
|
2512
|
+
observability;
|
|
1106
2513
|
constructor(options) {
|
|
1107
2514
|
super(options);
|
|
2515
|
+
this.observability = new Observability(options);
|
|
1108
2516
|
}
|
|
1109
2517
|
/**
|
|
1110
2518
|
* Retrieves all available agents
|
|
@@ -1178,6 +2586,48 @@ var MastraClient = class extends BaseResource {
|
|
|
1178
2586
|
getMemoryStatus(agentId) {
|
|
1179
2587
|
return this.request(`/api/memory/status?agentId=${agentId}`);
|
|
1180
2588
|
}
|
|
2589
|
+
/**
|
|
2590
|
+
* Retrieves memory threads for a resource
|
|
2591
|
+
* @param params - Parameters containing the resource ID
|
|
2592
|
+
* @returns Promise containing array of memory threads
|
|
2593
|
+
*/
|
|
2594
|
+
getNetworkMemoryThreads(params) {
|
|
2595
|
+
return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
|
|
2596
|
+
}
|
|
2597
|
+
/**
|
|
2598
|
+
* Creates a new memory thread
|
|
2599
|
+
* @param params - Parameters for creating the memory thread
|
|
2600
|
+
* @returns Promise containing the created memory thread
|
|
2601
|
+
*/
|
|
2602
|
+
createNetworkMemoryThread(params) {
|
|
2603
|
+
return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: "POST", body: params });
|
|
2604
|
+
}
|
|
2605
|
+
/**
|
|
2606
|
+
* Gets a memory thread instance by ID
|
|
2607
|
+
* @param threadId - ID of the memory thread to retrieve
|
|
2608
|
+
* @returns MemoryThread instance
|
|
2609
|
+
*/
|
|
2610
|
+
getNetworkMemoryThread(threadId, networkId) {
|
|
2611
|
+
return new NetworkMemoryThread(this.options, threadId, networkId);
|
|
2612
|
+
}
|
|
2613
|
+
/**
|
|
2614
|
+
* Saves messages to memory
|
|
2615
|
+
* @param params - Parameters containing messages to save
|
|
2616
|
+
* @returns Promise containing the saved messages
|
|
2617
|
+
*/
|
|
2618
|
+
saveNetworkMessageToMemory(params) {
|
|
2619
|
+
return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
|
|
2620
|
+
method: "POST",
|
|
2621
|
+
body: params
|
|
2622
|
+
});
|
|
2623
|
+
}
|
|
2624
|
+
/**
|
|
2625
|
+
* Gets the status of the memory system
|
|
2626
|
+
* @returns Promise containing memory system status
|
|
2627
|
+
*/
|
|
2628
|
+
getNetworkMemoryStatus(networkId) {
|
|
2629
|
+
return this.request(`/api/memory/network/status?networkId=${networkId}`);
|
|
2630
|
+
}
|
|
1181
2631
|
/**
|
|
1182
2632
|
* Retrieves all available tools
|
|
1183
2633
|
* @returns Promise containing map of tool IDs to tool details
|
|
@@ -1193,6 +2643,21 @@ var MastraClient = class extends BaseResource {
|
|
|
1193
2643
|
getTool(toolId) {
|
|
1194
2644
|
return new Tool(this.options, toolId);
|
|
1195
2645
|
}
|
|
2646
|
+
/**
|
|
2647
|
+
* Retrieves all available legacy workflows
|
|
2648
|
+
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
2649
|
+
*/
|
|
2650
|
+
getLegacyWorkflows() {
|
|
2651
|
+
return this.request("/api/workflows/legacy");
|
|
2652
|
+
}
|
|
2653
|
+
/**
|
|
2654
|
+
* Gets a legacy workflow instance by ID
|
|
2655
|
+
* @param workflowId - ID of the legacy workflow to retrieve
|
|
2656
|
+
* @returns Legacy Workflow instance
|
|
2657
|
+
*/
|
|
2658
|
+
getLegacyWorkflow(workflowId) {
|
|
2659
|
+
return new LegacyWorkflow(this.options, workflowId);
|
|
2660
|
+
}
|
|
1196
2661
|
/**
|
|
1197
2662
|
* Retrieves all available workflows
|
|
1198
2663
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
@@ -1208,21 +2673,6 @@ var MastraClient = class extends BaseResource {
|
|
|
1208
2673
|
getWorkflow(workflowId) {
|
|
1209
2674
|
return new Workflow(this.options, workflowId);
|
|
1210
2675
|
}
|
|
1211
|
-
/**
|
|
1212
|
-
* Retrieves all available vNext workflows
|
|
1213
|
-
* @returns Promise containing map of vNext workflow IDs to vNext workflow details
|
|
1214
|
-
*/
|
|
1215
|
-
getVNextWorkflows() {
|
|
1216
|
-
return this.request("/api/workflows/v-next");
|
|
1217
|
-
}
|
|
1218
|
-
/**
|
|
1219
|
-
* Gets a vNext workflow instance by ID
|
|
1220
|
-
* @param workflowId - ID of the vNext workflow to retrieve
|
|
1221
|
-
* @returns vNext Workflow instance
|
|
1222
|
-
*/
|
|
1223
|
-
getVNextWorkflow(workflowId) {
|
|
1224
|
-
return new VNextWorkflow(this.options, workflowId);
|
|
1225
|
-
}
|
|
1226
2676
|
/**
|
|
1227
2677
|
* Gets a vector instance by name
|
|
1228
2678
|
* @param vectorName - Name of the vector to retrieve
|
|
@@ -1237,7 +2687,41 @@ var MastraClient = class extends BaseResource {
|
|
|
1237
2687
|
* @returns Promise containing array of log messages
|
|
1238
2688
|
*/
|
|
1239
2689
|
getLogs(params) {
|
|
1240
|
-
|
|
2690
|
+
const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
2691
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
2692
|
+
const searchParams = new URLSearchParams();
|
|
2693
|
+
if (transportId) {
|
|
2694
|
+
searchParams.set("transportId", transportId);
|
|
2695
|
+
}
|
|
2696
|
+
if (fromDate) {
|
|
2697
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
2698
|
+
}
|
|
2699
|
+
if (toDate) {
|
|
2700
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
2701
|
+
}
|
|
2702
|
+
if (logLevel) {
|
|
2703
|
+
searchParams.set("logLevel", logLevel);
|
|
2704
|
+
}
|
|
2705
|
+
if (page) {
|
|
2706
|
+
searchParams.set("page", String(page));
|
|
2707
|
+
}
|
|
2708
|
+
if (perPage) {
|
|
2709
|
+
searchParams.set("perPage", String(perPage));
|
|
2710
|
+
}
|
|
2711
|
+
if (_filters) {
|
|
2712
|
+
if (Array.isArray(_filters)) {
|
|
2713
|
+
for (const filter of _filters) {
|
|
2714
|
+
searchParams.append("filters", filter);
|
|
2715
|
+
}
|
|
2716
|
+
} else {
|
|
2717
|
+
searchParams.set("filters", _filters);
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
if (searchParams.size) {
|
|
2721
|
+
return this.request(`/api/logs?${searchParams}`);
|
|
2722
|
+
} else {
|
|
2723
|
+
return this.request(`/api/logs`);
|
|
2724
|
+
}
|
|
1241
2725
|
}
|
|
1242
2726
|
/**
|
|
1243
2727
|
* Gets logs for a specific run
|
|
@@ -1245,7 +2729,44 @@ var MastraClient = class extends BaseResource {
|
|
|
1245
2729
|
* @returns Promise containing array of log messages
|
|
1246
2730
|
*/
|
|
1247
2731
|
getLogForRun(params) {
|
|
1248
|
-
|
|
2732
|
+
const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
2733
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
2734
|
+
const searchParams = new URLSearchParams();
|
|
2735
|
+
if (runId) {
|
|
2736
|
+
searchParams.set("runId", runId);
|
|
2737
|
+
}
|
|
2738
|
+
if (transportId) {
|
|
2739
|
+
searchParams.set("transportId", transportId);
|
|
2740
|
+
}
|
|
2741
|
+
if (fromDate) {
|
|
2742
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
2743
|
+
}
|
|
2744
|
+
if (toDate) {
|
|
2745
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
2746
|
+
}
|
|
2747
|
+
if (logLevel) {
|
|
2748
|
+
searchParams.set("logLevel", logLevel);
|
|
2749
|
+
}
|
|
2750
|
+
if (page) {
|
|
2751
|
+
searchParams.set("page", String(page));
|
|
2752
|
+
}
|
|
2753
|
+
if (perPage) {
|
|
2754
|
+
searchParams.set("perPage", String(perPage));
|
|
2755
|
+
}
|
|
2756
|
+
if (_filters) {
|
|
2757
|
+
if (Array.isArray(_filters)) {
|
|
2758
|
+
for (const filter of _filters) {
|
|
2759
|
+
searchParams.append("filters", filter);
|
|
2760
|
+
}
|
|
2761
|
+
} else {
|
|
2762
|
+
searchParams.set("filters", _filters);
|
|
2763
|
+
}
|
|
2764
|
+
}
|
|
2765
|
+
if (searchParams.size) {
|
|
2766
|
+
return this.request(`/api/logs/${runId}?${searchParams}`);
|
|
2767
|
+
} else {
|
|
2768
|
+
return this.request(`/api/logs/${runId}`);
|
|
2769
|
+
}
|
|
1249
2770
|
}
|
|
1250
2771
|
/**
|
|
1251
2772
|
* List of all log transports
|
|
@@ -1303,6 +2824,13 @@ var MastraClient = class extends BaseResource {
|
|
|
1303
2824
|
getNetworks() {
|
|
1304
2825
|
return this.request("/api/networks");
|
|
1305
2826
|
}
|
|
2827
|
+
/**
|
|
2828
|
+
* Retrieves all available vNext networks
|
|
2829
|
+
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
2830
|
+
*/
|
|
2831
|
+
getVNextNetworks() {
|
|
2832
|
+
return this.request("/api/networks/v-next");
|
|
2833
|
+
}
|
|
1306
2834
|
/**
|
|
1307
2835
|
* Gets a network instance by ID
|
|
1308
2836
|
* @param networkId - ID of the network to retrieve
|
|
@@ -1311,6 +2839,14 @@ var MastraClient = class extends BaseResource {
|
|
|
1311
2839
|
getNetwork(networkId) {
|
|
1312
2840
|
return new Network(this.options, networkId);
|
|
1313
2841
|
}
|
|
2842
|
+
/**
|
|
2843
|
+
* Gets a vNext network instance by ID
|
|
2844
|
+
* @param networkId - ID of the vNext network to retrieve
|
|
2845
|
+
* @returns vNext Network instance
|
|
2846
|
+
*/
|
|
2847
|
+
getVNextNetwork(networkId) {
|
|
2848
|
+
return new VNextNetwork(this.options, networkId);
|
|
2849
|
+
}
|
|
1314
2850
|
/**
|
|
1315
2851
|
* Retrieves a list of available MCP servers.
|
|
1316
2852
|
* @param params - Optional parameters for pagination (limit, offset).
|
|
@@ -1367,6 +2903,134 @@ var MastraClient = class extends BaseResource {
|
|
|
1367
2903
|
getA2A(agentId) {
|
|
1368
2904
|
return new A2A(this.options, agentId);
|
|
1369
2905
|
}
|
|
2906
|
+
/**
|
|
2907
|
+
* Retrieves the working memory for a specific thread (optionally resource-scoped).
|
|
2908
|
+
* @param agentId - ID of the agent.
|
|
2909
|
+
* @param threadId - ID of the thread.
|
|
2910
|
+
* @param resourceId - Optional ID of the resource.
|
|
2911
|
+
* @returns Working memory for the specified thread or resource.
|
|
2912
|
+
*/
|
|
2913
|
+
getWorkingMemory({
|
|
2914
|
+
agentId,
|
|
2915
|
+
threadId,
|
|
2916
|
+
resourceId
|
|
2917
|
+
}) {
|
|
2918
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
|
|
2919
|
+
}
|
|
2920
|
+
/**
|
|
2921
|
+
* Updates the working memory for a specific thread (optionally resource-scoped).
|
|
2922
|
+
* @param agentId - ID of the agent.
|
|
2923
|
+
* @param threadId - ID of the thread.
|
|
2924
|
+
* @param workingMemory - The new working memory content.
|
|
2925
|
+
* @param resourceId - Optional ID of the resource.
|
|
2926
|
+
*/
|
|
2927
|
+
updateWorkingMemory({
|
|
2928
|
+
agentId,
|
|
2929
|
+
threadId,
|
|
2930
|
+
workingMemory,
|
|
2931
|
+
resourceId
|
|
2932
|
+
}) {
|
|
2933
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
|
|
2934
|
+
method: "POST",
|
|
2935
|
+
body: {
|
|
2936
|
+
workingMemory,
|
|
2937
|
+
resourceId
|
|
2938
|
+
}
|
|
2939
|
+
});
|
|
2940
|
+
}
|
|
2941
|
+
/**
|
|
2942
|
+
* Retrieves all available scorers
|
|
2943
|
+
* @returns Promise containing list of available scorers
|
|
2944
|
+
*/
|
|
2945
|
+
getScorers() {
|
|
2946
|
+
return this.request("/api/scores/scorers");
|
|
2947
|
+
}
|
|
2948
|
+
/**
|
|
2949
|
+
* Retrieves a scorer by ID
|
|
2950
|
+
* @param scorerId - ID of the scorer to retrieve
|
|
2951
|
+
* @returns Promise containing the scorer
|
|
2952
|
+
*/
|
|
2953
|
+
getScorer(scorerId) {
|
|
2954
|
+
return this.request(`/api/scores/scorers/${scorerId}`);
|
|
2955
|
+
}
|
|
2956
|
+
getScoresByScorerId(params) {
|
|
2957
|
+
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
2958
|
+
const searchParams = new URLSearchParams();
|
|
2959
|
+
if (entityId) {
|
|
2960
|
+
searchParams.set("entityId", entityId);
|
|
2961
|
+
}
|
|
2962
|
+
if (entityType) {
|
|
2963
|
+
searchParams.set("entityType", entityType);
|
|
2964
|
+
}
|
|
2965
|
+
if (page !== void 0) {
|
|
2966
|
+
searchParams.set("page", String(page));
|
|
2967
|
+
}
|
|
2968
|
+
if (perPage !== void 0) {
|
|
2969
|
+
searchParams.set("perPage", String(perPage));
|
|
2970
|
+
}
|
|
2971
|
+
const queryString = searchParams.toString();
|
|
2972
|
+
return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
|
|
2973
|
+
}
|
|
2974
|
+
/**
|
|
2975
|
+
* Retrieves scores by run ID
|
|
2976
|
+
* @param params - Parameters containing run ID and pagination options
|
|
2977
|
+
* @returns Promise containing scores and pagination info
|
|
2978
|
+
*/
|
|
2979
|
+
getScoresByRunId(params) {
|
|
2980
|
+
const { runId, page, perPage } = params;
|
|
2981
|
+
const searchParams = new URLSearchParams();
|
|
2982
|
+
if (page !== void 0) {
|
|
2983
|
+
searchParams.set("page", String(page));
|
|
2984
|
+
}
|
|
2985
|
+
if (perPage !== void 0) {
|
|
2986
|
+
searchParams.set("perPage", String(perPage));
|
|
2987
|
+
}
|
|
2988
|
+
const queryString = searchParams.toString();
|
|
2989
|
+
return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
|
|
2990
|
+
}
|
|
2991
|
+
/**
|
|
2992
|
+
* Retrieves scores by entity ID and type
|
|
2993
|
+
* @param params - Parameters containing entity ID, type, and pagination options
|
|
2994
|
+
* @returns Promise containing scores and pagination info
|
|
2995
|
+
*/
|
|
2996
|
+
getScoresByEntityId(params) {
|
|
2997
|
+
const { entityId, entityType, page, perPage } = params;
|
|
2998
|
+
const searchParams = new URLSearchParams();
|
|
2999
|
+
if (page !== void 0) {
|
|
3000
|
+
searchParams.set("page", String(page));
|
|
3001
|
+
}
|
|
3002
|
+
if (perPage !== void 0) {
|
|
3003
|
+
searchParams.set("perPage", String(perPage));
|
|
3004
|
+
}
|
|
3005
|
+
const queryString = searchParams.toString();
|
|
3006
|
+
return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ""}`);
|
|
3007
|
+
}
|
|
3008
|
+
/**
|
|
3009
|
+
* Saves a score
|
|
3010
|
+
* @param params - Parameters containing the score data to save
|
|
3011
|
+
* @returns Promise containing the saved score
|
|
3012
|
+
*/
|
|
3013
|
+
saveScore(params) {
|
|
3014
|
+
return this.request("/api/scores", {
|
|
3015
|
+
method: "POST",
|
|
3016
|
+
body: params
|
|
3017
|
+
});
|
|
3018
|
+
}
|
|
3019
|
+
/**
|
|
3020
|
+
* Retrieves model providers with available keys
|
|
3021
|
+
* @returns Promise containing model providers with available keys
|
|
3022
|
+
*/
|
|
3023
|
+
getModelProviders() {
|
|
3024
|
+
return this.request(`/api/model-providers`);
|
|
3025
|
+
}
|
|
3026
|
+
getAITrace(traceId) {
|
|
3027
|
+
return this.observability.getTrace(traceId);
|
|
3028
|
+
}
|
|
3029
|
+
getAITraces(params) {
|
|
3030
|
+
return this.observability.getTraces(params);
|
|
3031
|
+
}
|
|
1370
3032
|
};
|
|
1371
3033
|
|
|
1372
3034
|
exports.MastraClient = MastraClient;
|
|
3035
|
+
//# sourceMappingURL=index.cjs.map
|
|
3036
|
+
//# sourceMappingURL=index.cjs.map
|