@mastra/client-js 1.47.0-alpha.1 → 1.47.0-alpha.10
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/dist/_types/@ai-sdk_provider/package.json +1 -0
- package/dist/_types/@ai-sdk_provider-utils/dist/index.d.ts +1 -1
- package/dist/_types/@ai-sdk_provider-utils/package.json +1 -0
- package/dist/_types/@ai-sdk_ui-utils/dist/index.d.ts +3 -3
- package/dist/_types/@ai-sdk_ui-utils/package.json +1 -0
- package/dist/client.d.ts +54 -207
- package/dist/client.d.ts.map +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-connections-a2a.md +4 -3
- package/dist/docs/references/docs-harness-agent-controller.md +4 -2
- package/dist/docs/references/reference-client-js-agent-controller.md +77 -16
- package/dist/docs/references/reference-client-js-agents.md +25 -0
- package/dist/docs/references/reference-client-js-mastra-client.md +1 -1
- package/dist/docs/references/reference-client-js-observability.md +49 -1
- package/dist/docs/references/reference-observability-tracing-trace-query.md +110 -9
- package/dist/index.cjs +337 -165
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +338 -166
- package/dist/index.js.map +1 -1
- package/dist/resources/a2a.d.ts +5 -1
- package/dist/resources/a2a.d.ts.map +1 -1
- package/dist/resources/agent-builder.d.ts +25 -40
- package/dist/resources/agent-builder.d.ts.map +1 -1
- package/dist/resources/agent-controller.d.ts +5 -4
- package/dist/resources/agent-controller.d.ts.map +1 -1
- package/dist/resources/agent.d.ts +46 -74
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/resources/base.d.ts.map +1 -1
- package/dist/resources/channels.d.ts +13 -31
- package/dist/resources/channels.d.ts.map +1 -1
- package/dist/resources/conversations.d.ts +6 -3
- package/dist/resources/conversations.d.ts.map +1 -1
- package/dist/resources/mcp-tool.d.ts +9 -6
- package/dist/resources/mcp-tool.d.ts.map +1 -1
- package/dist/resources/memory-thread.d.ts +11 -11
- package/dist/resources/memory-thread.d.ts.map +1 -1
- package/dist/resources/observability-route-types.d.ts +101 -0
- package/dist/resources/observability-route-types.d.ts.map +1 -0
- package/dist/resources/observability.d.ts +24 -9
- package/dist/resources/observability.d.ts.map +1 -1
- package/dist/resources/responses.d.ts +5 -2
- package/dist/resources/responses.d.ts.map +1 -1
- package/dist/resources/run.d.ts +21 -57
- package/dist/resources/run.d.ts.map +1 -1
- package/dist/resources/tool.d.ts +6 -4
- package/dist/resources/tool.d.ts.map +1 -1
- package/dist/resources/vector.d.ts +5 -10
- package/dist/resources/vector.d.ts.map +1 -1
- package/dist/resources/workflow.d.ts +8 -10
- package/dist/resources/workflow.d.ts.map +1 -1
- package/dist/route-types.generated.d.ts +2870 -2116
- package/dist/route-types.generated.d.ts.map +1 -1
- package/dist/types.d.ts +252 -1593
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { standardSchemaToJSONSchema, toStandardSchema } from "@mastra/schema-com
|
|
|
5
5
|
import { RequestContext, RequestContext as RequestContext$1 } from "@mastra/core/request-context";
|
|
6
6
|
import { zodToJsonSchema } from "@mastra/schema-compat/zod-to-json";
|
|
7
7
|
import { MastraA2AError } from "@mastra/core/a2a/client";
|
|
8
|
-
import { AgentCard, CancelTaskRequest, GetTaskRequest, ListTasksRequest, ListTasksResponse, SendMessageRequest, SendMessageResponse, StreamResponse, SubscribeToTaskRequest, Task } from "@mastra/core/a2a/v1";
|
|
8
|
+
import { AgentCard, CancelTaskRequest, DeleteTaskPushNotificationConfigRequest, GetTaskPushNotificationConfigRequest, GetTaskRequest, ListTaskPushNotificationConfigsRequest, ListTaskPushNotificationConfigsResponse, ListTasksRequest, ListTasksResponse, SendMessageRequest, SendMessageResponse, StreamResponse, SubscribeToTaskRequest, Task, TaskPushNotificationConfig } from "@mastra/core/a2a/v1";
|
|
9
9
|
import canonicalize from "canonicalize";
|
|
10
10
|
import { base64url, compactVerify, decodeProtectedHeader, importJWK, importSPKI, importX509 } from "jose";
|
|
11
11
|
//#region src/observability/collector.ts
|
|
@@ -341,6 +341,33 @@ function buildTenancyQuery(tenancy) {
|
|
|
341
341
|
const queryString = searchParams.toString();
|
|
342
342
|
return queryString ? `?${queryString}` : "";
|
|
343
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* Merges multiple optional abort signals into one. Returns `undefined` when no
|
|
346
|
+
* signals are provided, the single signal when only one is provided, and a
|
|
347
|
+
* combined signal otherwise. Uses `AbortSignal.any` when available and falls
|
|
348
|
+
* back to a manual listener merge for runtimes that lack it.
|
|
349
|
+
*/
|
|
350
|
+
function mergeAbortSignals(...signals) {
|
|
351
|
+
const defined = signals.filter((signal) => signal !== void 0);
|
|
352
|
+
if (defined.length === 0) return void 0;
|
|
353
|
+
if (defined.length === 1) return defined[0];
|
|
354
|
+
if (typeof AbortSignal.any === "function") return AbortSignal.any(defined);
|
|
355
|
+
const controller = new AbortController();
|
|
356
|
+
const alreadyAborted = defined.find((signal) => signal.aborted);
|
|
357
|
+
if (alreadyAborted) {
|
|
358
|
+
controller.abort(alreadyAborted.reason);
|
|
359
|
+
return controller.signal;
|
|
360
|
+
}
|
|
361
|
+
const cleanup = () => {
|
|
362
|
+
for (const signal of defined) signal.removeEventListener("abort", onAbort);
|
|
363
|
+
};
|
|
364
|
+
function onAbort() {
|
|
365
|
+
cleanup();
|
|
366
|
+
controller.abort(this.reason);
|
|
367
|
+
}
|
|
368
|
+
for (const signal of defined) signal.addEventListener("abort", onAbort);
|
|
369
|
+
return controller.signal;
|
|
370
|
+
}
|
|
344
371
|
//#endregion
|
|
345
372
|
//#region src/utils/client-tool-model-output.ts
|
|
346
373
|
/**
|
|
@@ -535,43 +562,61 @@ var BaseResource = class {
|
|
|
535
562
|
*/
|
|
536
563
|
async request(path, options = {}) {
|
|
537
564
|
let lastError = null;
|
|
538
|
-
const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {}, credentials, fetch: customFetch } = this.options;
|
|
565
|
+
const { baseUrl, retries: defaultRetries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {}, credentials, fetch: customFetch } = this.options;
|
|
566
|
+
const { retries: requestRetries, ...fetchOptions } = options;
|
|
567
|
+
const retries = requestRetries ?? defaultRetries;
|
|
568
|
+
if (!Number.isSafeInteger(retries) || retries < 0) throw new RangeError("retries must be a non-negative safe integer");
|
|
569
|
+
const signal = mergeAbortSignals(this.options.abortSignal, fetchOptions.signal);
|
|
539
570
|
const fetchFn = customFetch || fetch;
|
|
540
571
|
let delay = backoffMs;
|
|
541
572
|
const fullPath = `${this.apiPrefix}${path}`;
|
|
542
|
-
for (let attempt = 0; attempt <= retries; attempt++)
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
...
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
573
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
574
|
+
if (signal?.aborted) throw signal.reason ?? new DOMException("This operation was aborted", "AbortError");
|
|
575
|
+
try {
|
|
576
|
+
const response = await fetchFn(`${baseUrl.replace(/\/$/, "")}${fullPath}`, {
|
|
577
|
+
...fetchOptions,
|
|
578
|
+
headers: {
|
|
579
|
+
...fetchOptions.body && !(fetchOptions.body instanceof FormData) && (fetchOptions.method === "POST" || fetchOptions.method === "PUT" || fetchOptions.method === "PATCH" || fetchOptions.method === "DELETE") ? { "content-type": "application/json" } : {},
|
|
580
|
+
...headers,
|
|
581
|
+
...fetchOptions.headers
|
|
582
|
+
},
|
|
583
|
+
signal,
|
|
584
|
+
credentials: fetchOptions.credentials ?? credentials,
|
|
585
|
+
body: fetchOptions.body instanceof FormData ? fetchOptions.body : fetchOptions.body ? JSON.stringify(fetchOptions.body) : void 0
|
|
586
|
+
});
|
|
587
|
+
if (!response.ok) {
|
|
588
|
+
const errorBody = await response.text();
|
|
589
|
+
let parsedBody;
|
|
590
|
+
let errorMessage = `HTTP error! status: ${response.status}`;
|
|
591
|
+
try {
|
|
592
|
+
parsedBody = JSON.parse(errorBody);
|
|
593
|
+
errorMessage += ` - ${JSON.stringify(parsedBody)}`;
|
|
594
|
+
} catch {
|
|
595
|
+
if (errorBody) errorMessage += ` - ${errorBody}`;
|
|
596
|
+
}
|
|
597
|
+
throw new MastraClientError(response.status, response.statusText, errorMessage, parsedBody);
|
|
563
598
|
}
|
|
564
|
-
|
|
599
|
+
if (options.stream) return response;
|
|
600
|
+
return await response.json();
|
|
601
|
+
} catch (error) {
|
|
602
|
+
lastError = error;
|
|
603
|
+
if (signal?.aborted || error?.name === "AbortError") throw error;
|
|
604
|
+
const status = error.status;
|
|
605
|
+
if (status !== void 0 && status >= 400 && status < 500) throw error;
|
|
606
|
+
if (attempt === retries) break;
|
|
607
|
+
await new Promise((resolve, reject) => {
|
|
608
|
+
const timer = setTimeout(() => {
|
|
609
|
+
signal?.removeEventListener("abort", onAbort);
|
|
610
|
+
resolve();
|
|
611
|
+
}, delay);
|
|
612
|
+
const onAbort = () => {
|
|
613
|
+
clearTimeout(timer);
|
|
614
|
+
reject(signal?.reason ?? new DOMException("This operation was aborted", "AbortError"));
|
|
615
|
+
};
|
|
616
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
617
|
+
});
|
|
618
|
+
delay = Math.min(delay * 2, maxBackoffMs);
|
|
565
619
|
}
|
|
566
|
-
if (options.stream) return response;
|
|
567
|
-
return await response.json();
|
|
568
|
-
} catch (error) {
|
|
569
|
-
lastError = error;
|
|
570
|
-
const status = error.status;
|
|
571
|
-
if (status !== void 0 && status >= 400 && status < 500) throw error;
|
|
572
|
-
if (attempt === retries) break;
|
|
573
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
574
|
-
delay = Math.min(delay * 2, maxBackoffMs);
|
|
575
620
|
}
|
|
576
621
|
throw lastError || /* @__PURE__ */ new Error("Request failed");
|
|
577
622
|
}
|
|
@@ -895,6 +940,11 @@ var Agent = class extends BaseResource {
|
|
|
895
940
|
* depending on the toolset's scope).
|
|
896
941
|
*
|
|
897
942
|
* @param threadId - Optional thread ID for thread-scoped browser sessions
|
|
943
|
+
*
|
|
944
|
+
* @remarks This is a browser-stream adapter compatibility endpoint, not a
|
|
945
|
+
* `SERVER_ROUTES` route. Its historical deployer implementation returns
|
|
946
|
+
* `{ success: true }`; no generated contract exists while the adapter owns it.
|
|
947
|
+
* The public `boolean` result remains broad for backwards compatibility.
|
|
898
948
|
*/
|
|
899
949
|
closeBrowser(threadId) {
|
|
900
950
|
return this.request(`/agents/${this.agentId}/browser/close`, {
|
|
@@ -1191,12 +1241,13 @@ var Agent = class extends BaseResource {
|
|
|
1191
1241
|
* @experimental Agent signals are experimental and may change in a future release.
|
|
1192
1242
|
*/
|
|
1193
1243
|
async abortThread(params) {
|
|
1194
|
-
const { resourceId, threadId } = params;
|
|
1244
|
+
const { resourceId, threadId, expectedRunId } = params;
|
|
1195
1245
|
return this.request(`/agents/${this.agentId}/threads/abort`, {
|
|
1196
1246
|
method: "POST",
|
|
1197
1247
|
body: {
|
|
1198
1248
|
resourceId,
|
|
1199
|
-
threadId
|
|
1249
|
+
threadId,
|
|
1250
|
+
...expectedRunId === void 0 ? {} : { expectedRunId }
|
|
1200
1251
|
}
|
|
1201
1252
|
});
|
|
1202
1253
|
}
|
|
@@ -1296,8 +1347,10 @@ var Agent = class extends BaseResource {
|
|
|
1296
1347
|
return this.request(`/stored/agents/${encodeURIComponent(this.agentId)}/versions/compare?${queryParams.toString()}${contextString ? `&${contextString.slice(1)}` : ""}`);
|
|
1297
1348
|
}
|
|
1298
1349
|
async generateLegacy(params) {
|
|
1350
|
+
const { abortSignal: perCallSignal, ...bodyParams } = params;
|
|
1351
|
+
const abortSignal = mergeAbortSignals(this.options.abortSignal, perCallSignal);
|
|
1299
1352
|
const processedParams = {
|
|
1300
|
-
...
|
|
1353
|
+
...bodyParams,
|
|
1301
1354
|
output: params.output ? zodToJsonSchema$1(params.output) : void 0,
|
|
1302
1355
|
experimental_output: params.experimental_output ? zodToJsonSchema$1(params.experimental_output) : void 0,
|
|
1303
1356
|
requestContext: parseClientRequestContext(params.requestContext),
|
|
@@ -1306,9 +1359,11 @@ var Agent = class extends BaseResource {
|
|
|
1306
1359
|
const { resourceId, threadId, requestContext } = processedParams;
|
|
1307
1360
|
const response = await this.request(`/agents/${this.agentId}/generate-legacy`, {
|
|
1308
1361
|
method: "POST",
|
|
1309
|
-
body: processedParams
|
|
1362
|
+
body: processedParams,
|
|
1363
|
+
signal: abortSignal
|
|
1310
1364
|
});
|
|
1311
1365
|
if (response.finishReason === "tool-calls") {
|
|
1366
|
+
if (abortSignal?.aborted) throw abortSignal.reason ?? new DOMException("This operation was aborted", "AbortError");
|
|
1312
1367
|
const toolCalls = response.toolCalls;
|
|
1313
1368
|
if (!toolCalls || !Array.isArray(toolCalls)) return response;
|
|
1314
1369
|
for (const toolCall of toolCalls) {
|
|
@@ -1357,8 +1412,10 @@ var Agent = class extends BaseResource {
|
|
|
1357
1412
|
messages
|
|
1358
1413
|
};
|
|
1359
1414
|
const resolvedClientTools = params.clientToolsResolver?.() ?? params.clientTools;
|
|
1415
|
+
const abortSignal = mergeAbortSignals(this.options.abortSignal, params.abortSignal);
|
|
1360
1416
|
const processedParams = {
|
|
1361
1417
|
...params,
|
|
1418
|
+
abortSignal: void 0,
|
|
1362
1419
|
requestContext: parseClientRequestContext(params.requestContext),
|
|
1363
1420
|
clientTools: processClientTools(resolvedClientTools),
|
|
1364
1421
|
structuredOutput: params.structuredOutput ? {
|
|
@@ -1372,20 +1429,24 @@ var Agent = class extends BaseResource {
|
|
|
1372
1429
|
const threadId = typeof thread === "string" ? thread : thread?.id;
|
|
1373
1430
|
const response = await this.request(`/agents/${this.agentId}/generate`, {
|
|
1374
1431
|
method: "POST",
|
|
1375
|
-
body: processedParams
|
|
1376
|
-
|
|
1377
|
-
if (response.finishReason === "tool-calls") return executeToolCallAndRespond({
|
|
1378
|
-
response,
|
|
1379
|
-
params: {
|
|
1380
|
-
...params,
|
|
1381
|
-
clientTools: resolvedClientTools
|
|
1382
|
-
},
|
|
1383
|
-
agentId: this.agentId,
|
|
1384
|
-
resourceId,
|
|
1385
|
-
threadId,
|
|
1386
|
-
requestContext,
|
|
1387
|
-
respondFn: this.generate.bind(this)
|
|
1432
|
+
body: processedParams,
|
|
1433
|
+
signal: abortSignal
|
|
1388
1434
|
});
|
|
1435
|
+
if (response.finishReason === "tool-calls") {
|
|
1436
|
+
if (abortSignal?.aborted) throw abortSignal.reason ?? new DOMException("This operation was aborted", "AbortError");
|
|
1437
|
+
return executeToolCallAndRespond({
|
|
1438
|
+
response,
|
|
1439
|
+
params: {
|
|
1440
|
+
...params,
|
|
1441
|
+
clientTools: resolvedClientTools
|
|
1442
|
+
},
|
|
1443
|
+
agentId: this.agentId,
|
|
1444
|
+
resourceId,
|
|
1445
|
+
threadId,
|
|
1446
|
+
requestContext,
|
|
1447
|
+
respondFn: this.generate.bind(this)
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1389
1450
|
return response;
|
|
1390
1451
|
}
|
|
1391
1452
|
async processChatResponse({ stream, update, onToolCall, onFinish, getCurrentDate = () => /* @__PURE__ */ new Date(), lastMessage }) {
|
|
@@ -1621,7 +1682,7 @@ var Agent = class extends BaseResource {
|
|
|
1621
1682
|
throw new Error(error);
|
|
1622
1683
|
}
|
|
1623
1684
|
});
|
|
1624
|
-
onFinish?.({
|
|
1685
|
+
await onFinish?.({
|
|
1625
1686
|
message,
|
|
1626
1687
|
finishReason,
|
|
1627
1688
|
usage
|
|
@@ -1640,8 +1701,22 @@ var Agent = class extends BaseResource {
|
|
|
1640
1701
|
requestContext: parseClientRequestContext(params.requestContext),
|
|
1641
1702
|
clientTools: processClientTools(params.clientToolsResolver?.() ?? params.clientTools)
|
|
1642
1703
|
};
|
|
1643
|
-
const { readable, writable } = new TransformStream();
|
|
1644
|
-
const
|
|
1704
|
+
const { readable: innerReadable, writable } = new TransformStream();
|
|
1705
|
+
const abortController = new AbortController();
|
|
1706
|
+
const signal = mergeAbortSignals(abortController.signal, params.abortSignal, this.options.abortSignal);
|
|
1707
|
+
const innerReader = innerReadable.getReader();
|
|
1708
|
+
const readable = new ReadableStream({
|
|
1709
|
+
async pull(controller) {
|
|
1710
|
+
const { done, value } = await innerReader.read();
|
|
1711
|
+
if (done) controller.close();
|
|
1712
|
+
else controller.enqueue(value);
|
|
1713
|
+
},
|
|
1714
|
+
cancel(reason) {
|
|
1715
|
+
abortController.abort(reason);
|
|
1716
|
+
return innerReader.cancel(reason).catch(() => {});
|
|
1717
|
+
}
|
|
1718
|
+
});
|
|
1719
|
+
const response = await this.processStreamResponseLegacy(processedParams, writable, signal);
|
|
1645
1720
|
const streamResponse = new Response(readable, {
|
|
1646
1721
|
status: response.status,
|
|
1647
1722
|
statusText: response.statusText,
|
|
@@ -1882,29 +1957,63 @@ var Agent = class extends BaseResource {
|
|
|
1882
1957
|
}
|
|
1883
1958
|
}
|
|
1884
1959
|
});
|
|
1885
|
-
onFinish?.({
|
|
1960
|
+
await onFinish?.({
|
|
1886
1961
|
message,
|
|
1887
1962
|
finishReason,
|
|
1888
1963
|
usage
|
|
1889
1964
|
});
|
|
1890
1965
|
}
|
|
1891
|
-
|
|
1966
|
+
/**
|
|
1967
|
+
* Creates the consumer-facing stream for the streaming methods. Cancelling the
|
|
1968
|
+
* returned stream (or aborting `externalSignal`) aborts the underlying request
|
|
1969
|
+
* and stops any client-tool continuations.
|
|
1970
|
+
*/
|
|
1971
|
+
createCancellableStream(externalSignal) {
|
|
1972
|
+
const abortController = new AbortController();
|
|
1973
|
+
let readableController;
|
|
1974
|
+
return {
|
|
1975
|
+
readable: new ReadableStream({
|
|
1976
|
+
start(controller) {
|
|
1977
|
+
readableController = controller;
|
|
1978
|
+
},
|
|
1979
|
+
cancel(reason) {
|
|
1980
|
+
abortController.abort(reason);
|
|
1981
|
+
}
|
|
1982
|
+
}),
|
|
1983
|
+
controller: readableController,
|
|
1984
|
+
signal: mergeAbortSignals(abortController.signal, externalSignal, this.options.abortSignal)
|
|
1985
|
+
};
|
|
1986
|
+
}
|
|
1987
|
+
async processStreamResponse(processedParams, controller, route = "stream", signal) {
|
|
1892
1988
|
const { memory } = processedParams ?? {};
|
|
1893
1989
|
const { resource, thread } = memory ?? {};
|
|
1894
1990
|
const threadId = processedParams.threadId ?? (typeof thread === "string" ? thread : thread?.id);
|
|
1895
1991
|
const resourceId = processedParams.resourceId ?? resource;
|
|
1896
|
-
|
|
1992
|
+
const { abortSignal: _abortSignal, ...serializableParams } = processedParams;
|
|
1993
|
+
let requestBody = serializableParams;
|
|
1897
1994
|
if (route === "resume-stream") {
|
|
1898
|
-
const { messages: _messages, ...resumeStreamBody } =
|
|
1995
|
+
const { messages: _messages, ...resumeStreamBody } = serializableParams;
|
|
1899
1996
|
requestBody = resumeStreamBody;
|
|
1900
1997
|
}
|
|
1901
1998
|
const requestPath = route === "stream" && this.routeOverrides?.stream ? this.routeOverrides.stream : `/agents/${this.agentId}/${route}`;
|
|
1902
1999
|
const response = await this.request(requestPath, {
|
|
1903
2000
|
method: "POST",
|
|
1904
2001
|
body: requestBody,
|
|
1905
|
-
stream: true
|
|
2002
|
+
stream: true,
|
|
2003
|
+
signal
|
|
1906
2004
|
});
|
|
1907
2005
|
if (!response.body) throw new Error("No response body");
|
|
2006
|
+
const isAborted = () => Boolean(signal?.aborted);
|
|
2007
|
+
const isAbortError = (error) => isAborted() || error?.name === "AbortError";
|
|
2008
|
+
const safeClose = () => {
|
|
2009
|
+
try {
|
|
2010
|
+
controller.close();
|
|
2011
|
+
} catch {}
|
|
2012
|
+
};
|
|
2013
|
+
const safeEnqueue = (chunk) => {
|
|
2014
|
+
if (isAborted()) return;
|
|
2015
|
+
controller.enqueue(chunk);
|
|
2016
|
+
};
|
|
1908
2017
|
try {
|
|
1909
2018
|
let messages = [];
|
|
1910
2019
|
let streamRunId = processedParams.runId;
|
|
@@ -1916,7 +2025,7 @@ var Agent = class extends BaseResource {
|
|
|
1916
2025
|
const lines = pendingText.split("\n\n");
|
|
1917
2026
|
pendingText = isFinal ? "" : lines.pop() ?? "";
|
|
1918
2027
|
const readableLines = lines.filter((line) => line.trim() !== "[DONE]" && line.trim() !== "data: [DONE]").join("\n\n");
|
|
1919
|
-
if (readableLines)
|
|
2028
|
+
if (readableLines) safeEnqueue(new TextEncoder().encode(`${readableLines}\n\n`));
|
|
1920
2029
|
};
|
|
1921
2030
|
const pipePromise = streamForController.pipeTo(new WritableStream({
|
|
1922
2031
|
async write(chunk) {
|
|
@@ -1924,26 +2033,32 @@ var Agent = class extends BaseResource {
|
|
|
1924
2033
|
enqueueReadableText(decoder.decode(chunk, { stream: true }));
|
|
1925
2034
|
} catch (error) {
|
|
1926
2035
|
console.error("Error enqueueing to controller:", error);
|
|
1927
|
-
|
|
2036
|
+
safeEnqueue(chunk);
|
|
1928
2037
|
}
|
|
1929
2038
|
},
|
|
1930
2039
|
close() {
|
|
1931
2040
|
enqueueReadableText(decoder.decode(), true);
|
|
1932
2041
|
}
|
|
1933
|
-
})).catch((error) => {
|
|
1934
|
-
console.error("Error piping to controller:", error);
|
|
2042
|
+
}), { signal }).catch((error) => {
|
|
2043
|
+
if (!isAbortError(error)) console.error("Error piping to controller:", error);
|
|
2044
|
+
safeClose();
|
|
2045
|
+
});
|
|
2046
|
+
const onAbort = () => {
|
|
1935
2047
|
try {
|
|
1936
|
-
controller.
|
|
2048
|
+
controller.error(signal?.reason);
|
|
1937
2049
|
} catch {}
|
|
1938
|
-
}
|
|
2050
|
+
};
|
|
2051
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
2052
|
+
const processingStream = signal ? streamForProcessing.pipeThrough(new TransformStream(), { signal }) : streamForProcessing;
|
|
1939
2053
|
this.processChatResponse_vNext({
|
|
1940
|
-
stream:
|
|
2054
|
+
stream: processingStream,
|
|
1941
2055
|
update: ({ message }) => {
|
|
1942
2056
|
const existingIndex = messages.findIndex((m) => m.id === message.id);
|
|
1943
2057
|
if (existingIndex !== -1) messages[existingIndex] = message;
|
|
1944
2058
|
else messages.push(message);
|
|
1945
2059
|
},
|
|
1946
2060
|
onFinish: async ({ finishReason, message }) => {
|
|
2061
|
+
if (isAborted()) return;
|
|
1947
2062
|
if (finishReason === "tool-calls") {
|
|
1948
2063
|
const toolInvocationsById = /* @__PURE__ */ new Map();
|
|
1949
2064
|
for (const part of message?.parts ?? []) {
|
|
@@ -1970,6 +2085,7 @@ var Agent = class extends BaseResource {
|
|
|
1970
2085
|
const syntheticChunks = [];
|
|
1971
2086
|
const toolResultContents = [];
|
|
1972
2087
|
for (const toolCall of executableToolCalls) {
|
|
2088
|
+
if (isAborted()) return;
|
|
1973
2089
|
const clientTool = processedParams.clientTools?.[toolCall.toolName];
|
|
1974
2090
|
const runId = streamRunId ?? toolCall.toolCallId;
|
|
1975
2091
|
let result;
|
|
@@ -2037,6 +2153,7 @@ var Agent = class extends BaseResource {
|
|
|
2037
2153
|
try {
|
|
2038
2154
|
await pipePromise;
|
|
2039
2155
|
} catch {}
|
|
2156
|
+
if (isAborted()) return;
|
|
2040
2157
|
for (const synthetic of syntheticChunks) try {
|
|
2041
2158
|
const errorForSerialization = synthetic.type === "tool-error" ? synthetic.payload.error : void 0;
|
|
2042
2159
|
const serializedError = errorForSerialization instanceof Error ? {
|
|
@@ -2052,7 +2169,7 @@ var Agent = class extends BaseResource {
|
|
|
2052
2169
|
}
|
|
2053
2170
|
} : synthetic;
|
|
2054
2171
|
const sseLine = `data: ${JSON.stringify(payloadForWire)}\n\n`;
|
|
2055
|
-
|
|
2172
|
+
safeEnqueue(new TextEncoder().encode(sseLine));
|
|
2056
2173
|
} catch (enqueueErr) {
|
|
2057
2174
|
console.error("Failed to enqueue synthetic tool-result chunk:", enqueueErr);
|
|
2058
2175
|
}
|
|
@@ -2066,22 +2183,23 @@ var Agent = class extends BaseResource {
|
|
|
2066
2183
|
toolResultMessage
|
|
2067
2184
|
];
|
|
2068
2185
|
const recursionRoute = route === "resume-stream" ? "stream" : route === "resume-stream-until-idle" ? "stream-until-idle" : route;
|
|
2186
|
+
if (isAborted()) return;
|
|
2069
2187
|
try {
|
|
2070
2188
|
await this.processStreamResponse({
|
|
2071
2189
|
...processedParams,
|
|
2072
2190
|
messages: updatedMessages,
|
|
2073
2191
|
clientTools: processClientTools(processedParams.clientToolsResolver?.() ?? processedParams.clientTools)
|
|
2074
|
-
}, controller, recursionRoute);
|
|
2192
|
+
}, controller, recursionRoute, signal);
|
|
2075
2193
|
} catch (error) {
|
|
2076
|
-
console.error("Error processing recursive stream response:", error);
|
|
2194
|
+
if (!isAbortError(error)) console.error("Error processing recursive stream response:", error);
|
|
2077
2195
|
}
|
|
2078
2196
|
} else {
|
|
2079
2197
|
await pipePromise;
|
|
2080
|
-
|
|
2198
|
+
safeClose();
|
|
2081
2199
|
}
|
|
2082
2200
|
} else {
|
|
2083
2201
|
await pipePromise;
|
|
2084
|
-
|
|
2202
|
+
safeClose();
|
|
2085
2203
|
}
|
|
2086
2204
|
},
|
|
2087
2205
|
onStreamChunk: (chunk) => {
|
|
@@ -2089,14 +2207,16 @@ var Agent = class extends BaseResource {
|
|
|
2089
2207
|
},
|
|
2090
2208
|
lastMessage: void 0
|
|
2091
2209
|
}).catch(async (error) => {
|
|
2092
|
-
console.error("Error processing stream response:", error);
|
|
2210
|
+
if (!isAbortError(error)) console.error("Error processing stream response:", error);
|
|
2093
2211
|
try {
|
|
2094
2212
|
await pipePromise;
|
|
2095
|
-
controller.close();
|
|
2096
2213
|
} catch {}
|
|
2214
|
+
safeClose();
|
|
2215
|
+
}).finally(() => {
|
|
2216
|
+
signal?.removeEventListener("abort", onAbort);
|
|
2097
2217
|
});
|
|
2098
2218
|
} catch (error) {
|
|
2099
|
-
console.error("Error processing stream response:", error);
|
|
2219
|
+
if (!isAbortError(error)) console.error("Error processing stream response:", error);
|
|
2100
2220
|
}
|
|
2101
2221
|
return response;
|
|
2102
2222
|
}
|
|
@@ -2193,11 +2313,8 @@ var Agent = class extends BaseResource {
|
|
|
2193
2313
|
clientTools: processClientTools(params.clientToolsResolver?.() ?? params.clientTools),
|
|
2194
2314
|
structuredOutput
|
|
2195
2315
|
};
|
|
2196
|
-
|
|
2197
|
-
const
|
|
2198
|
-
readableController = controller;
|
|
2199
|
-
} });
|
|
2200
|
-
const response = await this.processStreamResponse(processedParams, readableController);
|
|
2316
|
+
const { readable, controller: readableController, signal } = this.createCancellableStream(params.abortSignal);
|
|
2317
|
+
const response = await this.processStreamResponse(processedParams, readableController, "stream", signal);
|
|
2201
2318
|
const streamResponse = new Response(readable, {
|
|
2202
2319
|
status: response.status,
|
|
2203
2320
|
statusText: response.statusText,
|
|
@@ -2227,11 +2344,8 @@ var Agent = class extends BaseResource {
|
|
|
2227
2344
|
clientTools: processClientTools(params.clientToolsResolver?.() ?? params.clientTools),
|
|
2228
2345
|
structuredOutput
|
|
2229
2346
|
};
|
|
2230
|
-
|
|
2231
|
-
const
|
|
2232
|
-
readableController = controller;
|
|
2233
|
-
} });
|
|
2234
|
-
const response = await this.processStreamResponse(processedParams, readableController, "stream-until-idle");
|
|
2347
|
+
const { readable, controller: readableController, signal } = this.createCancellableStream(params.abortSignal);
|
|
2348
|
+
const response = await this.processStreamResponse(processedParams, readableController, "stream-until-idle", signal);
|
|
2235
2349
|
const streamResponse = new Response(readable, {
|
|
2236
2350
|
status: response.status,
|
|
2237
2351
|
statusText: response.statusText,
|
|
@@ -2271,11 +2385,8 @@ var Agent = class extends BaseResource {
|
|
|
2271
2385
|
...rest,
|
|
2272
2386
|
requestContext: parseClientRequestContext(requestContext)
|
|
2273
2387
|
};
|
|
2274
|
-
|
|
2275
|
-
const
|
|
2276
|
-
readableController = controller;
|
|
2277
|
-
} });
|
|
2278
|
-
const response = await this.processStreamResponse(processedParams, readableController, "approve-tool-call");
|
|
2388
|
+
const { readable, controller: readableController, signal } = this.createCancellableStream(params.abortSignal);
|
|
2389
|
+
const response = await this.processStreamResponse(processedParams, readableController, "approve-tool-call", signal);
|
|
2279
2390
|
const streamResponse = new Response(readable, {
|
|
2280
2391
|
status: response.status,
|
|
2281
2392
|
statusText: response.statusText,
|
|
@@ -2305,11 +2416,8 @@ var Agent = class extends BaseResource {
|
|
|
2305
2416
|
...rest,
|
|
2306
2417
|
requestContext: parseClientRequestContext(requestContext)
|
|
2307
2418
|
};
|
|
2308
|
-
|
|
2309
|
-
const
|
|
2310
|
-
readableController = controller;
|
|
2311
|
-
} });
|
|
2312
|
-
const response = await this.processStreamResponse(processedParams, readableController, "decline-tool-call");
|
|
2419
|
+
const { readable, controller: readableController, signal } = this.createCancellableStream(params.abortSignal);
|
|
2420
|
+
const response = await this.processStreamResponse(processedParams, readableController, "decline-tool-call", signal);
|
|
2313
2421
|
const streamResponse = new Response(readable, {
|
|
2314
2422
|
status: response.status,
|
|
2315
2423
|
statusText: response.statusText,
|
|
@@ -2379,11 +2487,8 @@ var Agent = class extends BaseResource {
|
|
|
2379
2487
|
schema: standardSchemaToJSONSchema(toStandardSchema(options.structuredOutput.schema))
|
|
2380
2488
|
} : void 0
|
|
2381
2489
|
};
|
|
2382
|
-
|
|
2383
|
-
const
|
|
2384
|
-
readableController = controller;
|
|
2385
|
-
} });
|
|
2386
|
-
const response = await this.processStreamResponse(processedParams, readableController, "resume-stream");
|
|
2490
|
+
const { readable, controller: readableController, signal } = this.createCancellableStream(options.abortSignal);
|
|
2491
|
+
const response = await this.processStreamResponse(processedParams, readableController, "resume-stream", signal);
|
|
2387
2492
|
const streamResponse = new Response(readable, {
|
|
2388
2493
|
status: response.status,
|
|
2389
2494
|
statusText: response.statusText,
|
|
@@ -2442,11 +2547,8 @@ var Agent = class extends BaseResource {
|
|
|
2442
2547
|
schema: standardSchemaToJSONSchema(toStandardSchema(options.structuredOutput.schema))
|
|
2443
2548
|
} : void 0
|
|
2444
2549
|
};
|
|
2445
|
-
|
|
2446
|
-
const
|
|
2447
|
-
readableController = controller;
|
|
2448
|
-
} });
|
|
2449
|
-
const response = await this.processStreamResponse(processedParams, readableController, "resume-stream-until-idle");
|
|
2550
|
+
const { readable, controller: readableController, signal } = this.createCancellableStream(options.abortSignal);
|
|
2551
|
+
const response = await this.processStreamResponse(processedParams, readableController, "resume-stream-until-idle", signal);
|
|
2450
2552
|
const streamResponse = new Response(readable, {
|
|
2451
2553
|
status: response.status,
|
|
2452
2554
|
statusText: response.statusText,
|
|
@@ -2491,32 +2593,41 @@ var Agent = class extends BaseResource {
|
|
|
2491
2593
|
/**
|
|
2492
2594
|
* Processes the stream response and handles tool calls
|
|
2493
2595
|
*/
|
|
2494
|
-
async processStreamResponseLegacy(processedParams, writable) {
|
|
2596
|
+
async processStreamResponseLegacy(processedParams, writable, signal) {
|
|
2495
2597
|
const { memory } = processedParams ?? {};
|
|
2496
2598
|
const { resource, thread } = memory ?? {};
|
|
2497
2599
|
const threadId = processedParams.threadId ?? (typeof thread === "string" ? thread : thread?.id);
|
|
2498
2600
|
const resourceId = processedParams.resourceId ?? resource;
|
|
2601
|
+
const { abortSignal: _abortSignal, ...bodyParams } = processedParams ?? {};
|
|
2602
|
+
const isAborted = () => signal?.aborted === true;
|
|
2603
|
+
const isAbortError = (error) => isAborted() || error?.name === "AbortError";
|
|
2499
2604
|
const response = await this.request(this.routeOverrides?.stream ?? `/agents/${this.agentId}/stream-legacy`, {
|
|
2500
2605
|
method: "POST",
|
|
2501
|
-
body:
|
|
2502
|
-
stream: true
|
|
2606
|
+
body: bodyParams,
|
|
2607
|
+
stream: true,
|
|
2608
|
+
signal
|
|
2503
2609
|
});
|
|
2504
2610
|
if (!response.body) throw new Error("No response body");
|
|
2505
2611
|
try {
|
|
2506
2612
|
let toolCalls = [];
|
|
2507
2613
|
let messages = [];
|
|
2508
2614
|
const [streamForWritable, streamForProcessing] = response.body.tee();
|
|
2509
|
-
streamForWritable.pipeTo(writable, {
|
|
2510
|
-
|
|
2615
|
+
streamForWritable.pipeTo(writable, {
|
|
2616
|
+
preventClose: true,
|
|
2617
|
+
signal
|
|
2618
|
+
}).catch((error) => {
|
|
2619
|
+
if (!isAbortError(error)) console.error("Error piping to writable stream:", error);
|
|
2511
2620
|
});
|
|
2621
|
+
const processingStream = signal ? streamForProcessing.pipeThrough(new TransformStream(), { signal }) : streamForProcessing;
|
|
2512
2622
|
this.processChatResponse({
|
|
2513
|
-
stream:
|
|
2623
|
+
stream: processingStream,
|
|
2514
2624
|
update: ({ message }) => {
|
|
2515
2625
|
const existingIndex = messages.findIndex((m) => m.id === message.id);
|
|
2516
2626
|
if (existingIndex !== -1) messages[existingIndex] = message;
|
|
2517
2627
|
else messages.push(message);
|
|
2518
2628
|
},
|
|
2519
2629
|
onFinish: async ({ finishReason, message }) => {
|
|
2630
|
+
if (isAborted()) return;
|
|
2520
2631
|
if (finishReason === "tool-calls") {
|
|
2521
2632
|
const toolCall = [...message?.parts ?? []].reverse().find((part) => part.type === "tool-invocation")?.toolInvocation;
|
|
2522
2633
|
if (toolCall) {
|
|
@@ -2548,6 +2659,7 @@ var Agent = class extends BaseResource {
|
|
|
2548
2659
|
}
|
|
2549
2660
|
}
|
|
2550
2661
|
});
|
|
2662
|
+
if (isAborted()) return;
|
|
2551
2663
|
const writer = writable.getWriter();
|
|
2552
2664
|
try {
|
|
2553
2665
|
await writer.write(new TextEncoder().encode("a:" + JSON.stringify({
|
|
@@ -2577,21 +2689,21 @@ var Agent = class extends BaseResource {
|
|
|
2577
2689
|
...processedParams,
|
|
2578
2690
|
clientTools: processClientTools(processedParams.clientToolsResolver?.() ?? processedParams.clientTools),
|
|
2579
2691
|
messages: updatedMessages
|
|
2580
|
-
}, writable).catch((error) => {
|
|
2581
|
-
console.error("Error processing stream response:", error);
|
|
2692
|
+
}, writable, signal).catch((error) => {
|
|
2693
|
+
if (!isAbortError(error)) console.error("Error processing stream response:", error);
|
|
2582
2694
|
});
|
|
2583
2695
|
}
|
|
2584
2696
|
}
|
|
2585
2697
|
} else setTimeout(() => {
|
|
2586
|
-
writable.close();
|
|
2698
|
+
writable.close().catch(() => {});
|
|
2587
2699
|
}, 0);
|
|
2588
2700
|
},
|
|
2589
2701
|
lastMessage: void 0
|
|
2590
2702
|
}).catch((error) => {
|
|
2591
|
-
console.error("Error processing stream response:", error);
|
|
2703
|
+
if (!isAbortError(error)) console.error("Error processing stream response:", error);
|
|
2592
2704
|
});
|
|
2593
2705
|
} catch (error) {
|
|
2594
|
-
console.error("Error processing stream response:", error);
|
|
2706
|
+
if (!isAbortError(error)) console.error("Error processing stream response:", error);
|
|
2595
2707
|
}
|
|
2596
2708
|
return response;
|
|
2597
2709
|
}
|
|
@@ -2667,6 +2779,22 @@ var Agent = class extends BaseResource {
|
|
|
2667
2779
|
//#endregion
|
|
2668
2780
|
//#region src/resources/memory-thread.ts
|
|
2669
2781
|
/**
|
|
2782
|
+
* Serializes the message-listing filters both memory message routes accept. The network route
|
|
2783
|
+
* takes the same filters under a different path, so the two callers share one serializer.
|
|
2784
|
+
*/
|
|
2785
|
+
const memoryMessagesQuery = ({ agentId, resourceId, page, perPage, orderBy, filter, include, includeSystemReminders }) => {
|
|
2786
|
+
const query = new URLSearchParams();
|
|
2787
|
+
if (agentId) query.set("agentId", agentId);
|
|
2788
|
+
if (resourceId) query.set("resourceId", resourceId);
|
|
2789
|
+
if (page !== void 0) query.set("page", String(page));
|
|
2790
|
+
if (perPage !== void 0) query.set("perPage", String(perPage));
|
|
2791
|
+
if (orderBy) query.set("orderBy", JSON.stringify(orderBy));
|
|
2792
|
+
if (filter) query.set("filter", JSON.stringify(filter));
|
|
2793
|
+
if (include) query.set("include", JSON.stringify(include));
|
|
2794
|
+
if (includeSystemReminders !== void 0) query.set("includeSystemReminders", String(includeSystemReminders));
|
|
2795
|
+
return query;
|
|
2796
|
+
};
|
|
2797
|
+
/**
|
|
2670
2798
|
* MemoryThread resource for interacting with memory threads.
|
|
2671
2799
|
*
|
|
2672
2800
|
* `agentId` is optional for read operations (`get`, `listMessages`) — when omitted the server
|
|
@@ -2742,18 +2870,11 @@ var MemoryThread = class extends BaseResource {
|
|
|
2742
2870
|
* @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
|
|
2743
2871
|
*/
|
|
2744
2872
|
listMessages(params = {}) {
|
|
2745
|
-
const
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
if (perPage !== void 0) queryParams.perPage = String(perPage);
|
|
2751
|
-
if (orderBy) queryParams.orderBy = JSON.stringify(orderBy);
|
|
2752
|
-
if (filter) queryParams.filter = JSON.stringify(filter);
|
|
2753
|
-
if (include) queryParams.include = JSON.stringify(include);
|
|
2754
|
-
if (includeSystemReminders !== void 0) queryParams.includeSystemReminders = String(includeSystemReminders);
|
|
2755
|
-
const queryString = new URLSearchParams(queryParams).toString();
|
|
2756
|
-
const url = `/memory/threads/${this.threadId}/messages${queryString ? `?${queryString}` : ""}${requestContextQueryString(requestContext, queryString ? "&" : "?")}`;
|
|
2873
|
+
const query = memoryMessagesQuery({
|
|
2874
|
+
...params,
|
|
2875
|
+
agentId: params.agentId ?? this.agentId
|
|
2876
|
+
}).toString();
|
|
2877
|
+
const url = `/memory/threads/${this.threadId}/messages${query ? `?${query}` : ""}${requestContextQueryString(params.requestContext, query ? "&" : "?")}`;
|
|
2757
2878
|
return this.request(url);
|
|
2758
2879
|
}
|
|
2759
2880
|
/**
|
|
@@ -3211,7 +3332,7 @@ var Run = class extends BaseResource {
|
|
|
3211
3332
|
resourceId: params.resourceId,
|
|
3212
3333
|
perStep: params.perStep
|
|
3213
3334
|
}
|
|
3214
|
-
}).then(deserializeWorkflowError);
|
|
3335
|
+
}).then((result) => deserializeWorkflowError(result));
|
|
3215
3336
|
}
|
|
3216
3337
|
/**
|
|
3217
3338
|
* Starts a workflow run and returns a stream
|
|
@@ -3293,7 +3414,7 @@ var Run = class extends BaseResource {
|
|
|
3293
3414
|
perStep: params.perStep,
|
|
3294
3415
|
forEachIndex: params.forEachIndex
|
|
3295
3416
|
}
|
|
3296
|
-
}).then(deserializeWorkflowError);
|
|
3417
|
+
}).then((result) => deserializeWorkflowError(result));
|
|
3297
3418
|
}
|
|
3298
3419
|
/**
|
|
3299
3420
|
* Resumes a suspended workflow step without waiting for the workflow to complete (fire-and-forget)
|
|
@@ -3377,7 +3498,7 @@ var Run = class extends BaseResource {
|
|
|
3377
3498
|
requestContext,
|
|
3378
3499
|
tracingOptions: params?.tracingOptions
|
|
3379
3500
|
}
|
|
3380
|
-
}).then(deserializeWorkflowError);
|
|
3501
|
+
}).then((result) => deserializeWorkflowError(result));
|
|
3381
3502
|
}
|
|
3382
3503
|
/**
|
|
3383
3504
|
* Time travels a workflow run synchronously without waiting for the workflow to complete
|
|
@@ -3407,7 +3528,7 @@ var Run = class extends BaseResource {
|
|
|
3407
3528
|
...params,
|
|
3408
3529
|
requestContext
|
|
3409
3530
|
}
|
|
3410
|
-
}).then(deserializeWorkflowError);
|
|
3531
|
+
}).then((result) => deserializeWorkflowError(result));
|
|
3411
3532
|
}
|
|
3412
3533
|
/**
|
|
3413
3534
|
* Time travels a workflow run and returns a stream
|
|
@@ -3919,12 +4040,27 @@ var A2AV1 = class extends BaseResource {
|
|
|
3919
4040
|
}
|
|
3920
4041
|
}));
|
|
3921
4042
|
}
|
|
4043
|
+
async createTaskPushNotificationConfig(params) {
|
|
4044
|
+
const result = await this.rpc("CreateTaskPushNotificationConfig", TaskPushNotificationConfig.toJSON(params));
|
|
4045
|
+
return TaskPushNotificationConfig.fromJSON(result);
|
|
4046
|
+
}
|
|
4047
|
+
async getTaskPushNotificationConfig(params) {
|
|
4048
|
+
const result = await this.rpc("GetTaskPushNotificationConfig", GetTaskPushNotificationConfigRequest.toJSON(params));
|
|
4049
|
+
return TaskPushNotificationConfig.fromJSON(result);
|
|
4050
|
+
}
|
|
4051
|
+
async listTaskPushNotificationConfigs(params) {
|
|
4052
|
+
const result = await this.rpc("ListTaskPushNotificationConfigs", ListTaskPushNotificationConfigsRequest.toJSON(params));
|
|
4053
|
+
return ListTaskPushNotificationConfigsResponse.fromJSON(result);
|
|
4054
|
+
}
|
|
4055
|
+
async deleteTaskPushNotificationConfig(params) {
|
|
4056
|
+
await this.rpc("DeleteTaskPushNotificationConfig", DeleteTaskPushNotificationConfigRequest.toJSON(params));
|
|
4057
|
+
}
|
|
3922
4058
|
async getAgentCard() {
|
|
3923
4059
|
const card = await this.request(`/.well-known/${this.agentId}/agent-card.json`, { headers: { "A2A-Version": "1.0" } });
|
|
3924
4060
|
return AgentCard.fromJSON(card);
|
|
3925
4061
|
}
|
|
3926
4062
|
async sendMessage(params) {
|
|
3927
|
-
const result = await this.rpc("
|
|
4063
|
+
const result = await this.rpc("SendMessage", SendMessageRequest.toJSON(params));
|
|
3928
4064
|
return SendMessageResponse.fromJSON(result);
|
|
3929
4065
|
}
|
|
3930
4066
|
async *sendMessageStream(params) {
|
|
@@ -3934,7 +4070,7 @@ var A2AV1 = class extends BaseResource {
|
|
|
3934
4070
|
body: {
|
|
3935
4071
|
jsonrpc: "2.0",
|
|
3936
4072
|
id: crypto.randomUUID(),
|
|
3937
|
-
method: "
|
|
4073
|
+
method: "SendStreamingMessage",
|
|
3938
4074
|
params: SendMessageRequest.toJSON(params)
|
|
3939
4075
|
},
|
|
3940
4076
|
stream: true
|
|
@@ -3942,15 +4078,15 @@ var A2AV1 = class extends BaseResource {
|
|
|
3942
4078
|
for await (const event of processA2AStream(await requireResponseBody(response, "message/stream"))) yield StreamResponse.fromJSON(event);
|
|
3943
4079
|
}
|
|
3944
4080
|
async getTask(params) {
|
|
3945
|
-
const result = await this.rpc("
|
|
4081
|
+
const result = await this.rpc("GetTask", GetTaskRequest.toJSON(params));
|
|
3946
4082
|
return Task.fromJSON(result);
|
|
3947
4083
|
}
|
|
3948
4084
|
async listTasks(params) {
|
|
3949
|
-
const result = await this.rpc("
|
|
4085
|
+
const result = await this.rpc("ListTasks", ListTasksRequest.toJSON(params));
|
|
3950
4086
|
return ListTasksResponse.fromJSON(result);
|
|
3951
4087
|
}
|
|
3952
4088
|
async cancelTask(params) {
|
|
3953
|
-
const result = await this.rpc("
|
|
4089
|
+
const result = await this.rpc("CancelTask", CancelTaskRequest.toJSON(params));
|
|
3954
4090
|
return Task.fromJSON(result);
|
|
3955
4091
|
}
|
|
3956
4092
|
async *resubscribeTask(params) {
|
|
@@ -3960,7 +4096,7 @@ var A2AV1 = class extends BaseResource {
|
|
|
3960
4096
|
body: {
|
|
3961
4097
|
jsonrpc: "2.0",
|
|
3962
4098
|
id: crypto.randomUUID(),
|
|
3963
|
-
method: "
|
|
4099
|
+
method: "SubscribeToTask",
|
|
3964
4100
|
params: SubscribeToTaskRequest.toJSON(params)
|
|
3965
4101
|
},
|
|
3966
4102
|
stream: true
|
|
@@ -3993,13 +4129,14 @@ var MCPTool = class extends BaseResource {
|
|
|
3993
4129
|
/**
|
|
3994
4130
|
* Executes this specific tool on the MCP server.
|
|
3995
4131
|
* @param params - Parameters for tool execution, including data/args and optional requestContext.
|
|
3996
|
-
*
|
|
4132
|
+
* On a 2026-07-28 server a tool can answer `{ status: 'suspended', suspendPayload, resumeSchema }`;
|
|
4133
|
+
* call again with the same `data` plus `resumeData` (matching `resumeSchema`) and the echoed
|
|
4134
|
+
* `suspendPayload` to continue it.
|
|
4135
|
+
* @returns Promise containing `{ result }`, or the suspended shape described above.
|
|
3997
4136
|
*/
|
|
3998
4137
|
execute(params) {
|
|
3999
|
-
const body =
|
|
4000
|
-
|
|
4001
|
-
if (params.requestContext !== void 0) body.requestContext = params.requestContext;
|
|
4002
|
-
return this.request(`/mcp/${encodeURIComponent(this.serverId)}/tools/${encodeURIComponent(this.toolId)}/execute`, {
|
|
4138
|
+
const { requestContext, ...body } = params;
|
|
4139
|
+
return this.request(`/mcp/${encodeURIComponent(this.serverId)}/tools/${encodeURIComponent(this.toolId)}/execute${requestContextQueryString(requestContext)}`, {
|
|
4003
4140
|
method: "POST",
|
|
4004
4141
|
body
|
|
4005
4142
|
});
|
|
@@ -4017,23 +4154,29 @@ var AgentBuilder = class extends BaseResource {
|
|
|
4017
4154
|
this.actionId = actionId;
|
|
4018
4155
|
}
|
|
4019
4156
|
transformWorkflowResult(result) {
|
|
4020
|
-
if (result.status === "success")
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4157
|
+
if (result.status === "success") {
|
|
4158
|
+
const actionResult = result.result;
|
|
4159
|
+
return {
|
|
4160
|
+
success: actionResult?.success ?? false,
|
|
4161
|
+
applied: actionResult?.applied ?? false,
|
|
4162
|
+
branchName: actionResult?.branchName,
|
|
4163
|
+
message: actionResult?.message ?? "Agent builder action completed",
|
|
4164
|
+
validationResults: actionResult?.validationResults,
|
|
4165
|
+
error: actionResult?.error,
|
|
4166
|
+
errors: actionResult?.errors,
|
|
4167
|
+
stepResults: actionResult?.stepResults
|
|
4168
|
+
};
|
|
4169
|
+
}
|
|
4170
|
+
if (result.status === "failed") {
|
|
4171
|
+
const message = result.error?.message ?? "Agent builder action failed";
|
|
4172
|
+
return {
|
|
4173
|
+
success: false,
|
|
4174
|
+
applied: false,
|
|
4175
|
+
message: `Agent builder action failed: ${message}`,
|
|
4176
|
+
error: message
|
|
4177
|
+
};
|
|
4178
|
+
}
|
|
4179
|
+
return {
|
|
4037
4180
|
success: false,
|
|
4038
4181
|
applied: false,
|
|
4039
4182
|
message: "Agent builder action was suspended",
|
|
@@ -4229,7 +4372,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
4229
4372
|
* This calls `/agent-builder/:actionId`.
|
|
4230
4373
|
*/
|
|
4231
4374
|
async details() {
|
|
4232
|
-
return
|
|
4375
|
+
return this.request(`/agent-builder/${this.actionId}`);
|
|
4233
4376
|
}
|
|
4234
4377
|
/**
|
|
4235
4378
|
* Gets all runs for this agent builder action.
|
|
@@ -4362,6 +4505,24 @@ var Observability = class extends BaseResource {
|
|
|
4362
4505
|
body: params
|
|
4363
4506
|
});
|
|
4364
4507
|
}
|
|
4508
|
+
/** Returns canonical and observed fields available to the advanced trace-query grammar. */
|
|
4509
|
+
getTraceQueryFields(params, options) {
|
|
4510
|
+
return this.request("/observability/traces/query/fields", {
|
|
4511
|
+
method: "POST",
|
|
4512
|
+
body: params,
|
|
4513
|
+
retries: 0,
|
|
4514
|
+
signal: options?.signal
|
|
4515
|
+
});
|
|
4516
|
+
}
|
|
4517
|
+
/** Returns bounded string suggestions for one eligible trace-query field. */
|
|
4518
|
+
getTraceQueryValues(params, options) {
|
|
4519
|
+
return this.request("/observability/traces/query/values", {
|
|
4520
|
+
method: "POST",
|
|
4521
|
+
body: params,
|
|
4522
|
+
retries: 0,
|
|
4523
|
+
signal: options?.signal
|
|
4524
|
+
});
|
|
4525
|
+
}
|
|
4365
4526
|
/**
|
|
4366
4527
|
* Queries thread identities using eligible-trace and cross-trace predicates.
|
|
4367
4528
|
*
|
|
@@ -4458,7 +4619,7 @@ var Observability = class extends BaseResource {
|
|
|
4458
4619
|
deleteTraces(params) {
|
|
4459
4620
|
return this.request(`/observability/traces/delete`, {
|
|
4460
4621
|
method: "POST",
|
|
4461
|
-
body:
|
|
4622
|
+
body: params
|
|
4462
4623
|
});
|
|
4463
4624
|
}
|
|
4464
4625
|
/**
|
|
@@ -6510,12 +6671,15 @@ var MastraClient = class extends BaseResource {
|
|
|
6510
6671
|
* @returns Promise containing the thread messages
|
|
6511
6672
|
*/
|
|
6512
6673
|
listThreadMessages(threadId, opts = {}) {
|
|
6513
|
-
|
|
6514
|
-
|
|
6515
|
-
|
|
6516
|
-
|
|
6517
|
-
|
|
6518
|
-
return this.
|
|
6674
|
+
if (opts.networkId) {
|
|
6675
|
+
const query = memoryMessagesQuery(opts);
|
|
6676
|
+
query.set("networkId", opts.networkId);
|
|
6677
|
+
return this.request(`/memory/network/threads/${threadId}/messages?${query.toString()}${requestContextQueryString(opts.requestContext, "&")}`);
|
|
6678
|
+
}
|
|
6679
|
+
return this.getMemoryThread({
|
|
6680
|
+
threadId,
|
|
6681
|
+
agentId: opts.agentId
|
|
6682
|
+
}).listMessages(opts);
|
|
6519
6683
|
}
|
|
6520
6684
|
deleteThread(threadId, opts) {
|
|
6521
6685
|
if (!opts || !!opts.agentId === !!opts.networkId) throw new Error("MastraClient.deleteThread() requires exactly one of agentId or networkId. The server cannot resolve which memory store owns the thread without one, and passing both is ambiguous.");
|
|
@@ -6940,6 +7104,14 @@ var MastraClient = class extends BaseResource {
|
|
|
6940
7104
|
queryTraces(params) {
|
|
6941
7105
|
return this.observability.queryTraces(params);
|
|
6942
7106
|
}
|
|
7107
|
+
/** Returns canonical and observed fields available to the advanced trace-query grammar. */
|
|
7108
|
+
getTraceQueryFields(params, options) {
|
|
7109
|
+
return this.observability.getTraceQueryFields(params, options);
|
|
7110
|
+
}
|
|
7111
|
+
/** Returns bounded string suggestions for one eligible trace-query field. */
|
|
7112
|
+
getTraceQueryValues(params, options) {
|
|
7113
|
+
return this.observability.getTraceQueryValues(params, options);
|
|
7114
|
+
}
|
|
6943
7115
|
/** Queries thread identities using eligible-trace and cross-trace predicates. */
|
|
6944
7116
|
queryTraceThreads(params) {
|
|
6945
7117
|
return this.observability.queryTraceThreads(params);
|