@mastra/client-js 1.56.0-alpha.9 → 1.57.0-alpha.0
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/client.d.ts +47 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/docs/SKILL.md +5 -3
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-connections-a2a.md +1 -1
- package/dist/docs/references/docs-harness-agent-controller.md +7 -7
- package/dist/docs/references/docs-harness-schedules.md +5 -5
- package/dist/docs/references/docs-server-mastra-client.md +1 -1
- package/dist/docs/references/docs-signals-notifications.md +233 -0
- package/dist/docs/references/docs-signals-sending-signals.md +166 -0
- package/dist/docs/references/docs-signals-thread-streams.md +94 -0
- package/dist/docs/references/docs-studio-editor.md +39 -23
- package/dist/docs/references/reference-client-js-agent-controller.md +1 -1
- package/dist/docs/references/reference-client-js-agents.md +1 -1
- package/dist/docs/references/reference-client-js-observability.md +26 -1
- package/dist/docs/references/reference-observability-tracing-advanced-queries.md +92 -11
- package/dist/index.cjs +259 -67
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +258 -66
- package/dist/index.js.map +1 -1
- package/dist/resources/agent.d.ts +8 -0
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/resources/observability-route-types.d.ts +2 -0
- package/dist/resources/observability-route-types.d.ts.map +1 -1
- package/dist/resources/observability.d.ts +7 -1
- package/dist/resources/observability.d.ts.map +1 -1
- package/dist/route-types.generated.d.ts +665 -446
- package/dist/route-types.generated.d.ts.map +1 -1
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -9
- package/dist/docs/references/docs-harness-signals.md +0 -546
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,6 @@ export type { ObservabilityCollector } from './observability/types.js';
|
|
|
11
11
|
export type { QuerySpansInput, QuerySpansResult, QueryTraceThreadsInput, QueryTraceThreadsResult, QueryTracesInput, QueryTracesDeltaInput, QueryTracesKeysetInput, QueryTracesPaginatedInput, } from './resources/observability.js';
|
|
12
12
|
export type { UIMessageWithMetadata } from '@mastra/core/agent';
|
|
13
13
|
export type { GetMetricTimeSeriesResponse } from './types.js';
|
|
14
|
-
export type { AggregateTracesArgs, AggregateTracesResponse, TraceAggregateDiscovery, GetTraceQueryFieldsArgs, GetTraceQueryFieldsResponse, GetTraceQueryValuesArgs, GetTraceQueryValuesResponse, TraceQueryCanonicalFieldDescriptor, TraceQueryGroupResponse, TraceQueryKeysetTraceResponse, TraceQueryObservedFieldDescriptor, TraceQueryOperator, TraceQueryPredicateScope, TraceQueryResponse, TraceQueryTraceResponse, TraceQueryValueKind, } from './resources/observability-route-types.js';
|
|
14
|
+
export type { AggregateTracesArgs, AggregateTracesResponse, AggregateSpansArgs, AggregateSpansResponse, TraceAggregateDiscovery, GetTraceQueryFieldsArgs, GetTraceQueryFieldsResponse, GetTraceQueryValuesArgs, GetTraceQueryValuesResponse, TraceQueryCanonicalFieldDescriptor, TraceQueryGroupResponse, TraceQueryKeysetTraceResponse, TraceQueryObservedFieldDescriptor, TraceQueryOperator, TraceQueryPredicateScope, TraceQueryResponse, TraceQueryTraceResponse, TraceQueryValueKind, } from './resources/observability-route-types.js';
|
|
15
15
|
export type { Body, Client, ClientMethod, ClientPath, ClientRequest, ClientResponse, ClientResponseKind, ClientRoute, PathParams, QueryParams, RouteKey, RouteRequest, RouteResponse, RouteResponseType, RouteTypes, } from './route-types.generated.js';
|
|
16
16
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,YAAY,EACV,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,kCAAkC,EAClC,wBAAwB,EACxB,mBAAmB,EACnB,+BAA+B,GAChC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,0BAA0B,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AACvG,YAAY,EACV,eAAe,EACf,sBAAsB,EACtB,iBAAiB,EACjB,oBAAoB,EACpB,yBAAyB,EACzB,yBAAyB,EACzB,6BAA6B,EAC7B,sCAAsC,EACtC,2BAA2B,EAC3B,UAAU,EACV,yBAAyB,EACzB,+BAA+B,GAChC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D,YAAY,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACpE,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,EACvB,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;AACnC,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,YAAY,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAC3D,YAAY,EACV,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,2BAA2B,EAC3B,uBAAuB,EACvB,2BAA2B,EAC3B,kCAAkC,EAClC,uBAAuB,EACvB,6BAA6B,EAC7B,iCAAiC,EACjC,kBAAkB,EAClB,wBAAwB,EACxB,kBAAkB,EAClB,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,uCAAuC,CAAC;AAC/C,YAAY,EACV,IAAI,EACJ,MAAM,EACN,YAAY,EACZ,UAAU,EACV,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,UAAU,GACX,MAAM,4BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,YAAY,EACV,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,kCAAkC,EAClC,wBAAwB,EACxB,mBAAmB,EACnB,+BAA+B,GAChC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,0BAA0B,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AACvG,YAAY,EACV,eAAe,EACf,sBAAsB,EACtB,iBAAiB,EACjB,oBAAoB,EACpB,yBAAyB,EACzB,yBAAyB,EACzB,6BAA6B,EAC7B,sCAAsC,EACtC,2BAA2B,EAC3B,UAAU,EACV,yBAAyB,EACzB,+BAA+B,GAChC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D,YAAY,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACpE,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,EACvB,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;AACnC,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,YAAY,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAC3D,YAAY,EACV,mBAAmB,EACnB,uBAAuB,EACvB,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,2BAA2B,EAC3B,uBAAuB,EACvB,2BAA2B,EAC3B,kCAAkC,EAClC,uBAAuB,EACvB,6BAA6B,EAC7B,iCAAiC,EACjC,kBAAkB,EAClB,wBAAwB,EACxB,kBAAkB,EAClB,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,uCAAuC,CAAC;AAC/C,YAAY,EACV,IAAI,EACJ,MAAM,EACN,YAAY,EACZ,UAAU,EACV,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,UAAU,GACX,MAAM,4BAA4B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -59,15 +59,16 @@ function attributesToOtlp(attrs) {
|
|
|
59
59
|
key,
|
|
60
60
|
value: { boolValue: raw }
|
|
61
61
|
});
|
|
62
|
-
else if (typeof raw === "number")
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
else if (typeof raw === "number") {
|
|
63
|
+
if (Number.isInteger(raw)) out.push({
|
|
64
|
+
key,
|
|
65
|
+
value: { intValue: raw }
|
|
66
|
+
});
|
|
67
|
+
else out.push({
|
|
68
|
+
key,
|
|
69
|
+
value: { doubleValue: raw }
|
|
70
|
+
});
|
|
71
|
+
} else try {
|
|
71
72
|
out.push({
|
|
72
73
|
key,
|
|
73
74
|
value: { stringValue: JSON.stringify(raw) }
|
|
@@ -662,7 +663,6 @@ function fixJson(input) {
|
|
|
662
663
|
stack.pop();
|
|
663
664
|
stack.push(swapState);
|
|
664
665
|
stack.push("INSIDE_ARRAY_START");
|
|
665
|
-
break;
|
|
666
666
|
}
|
|
667
667
|
}
|
|
668
668
|
function processAfterObjectValue(char, i) {
|
|
@@ -674,7 +674,6 @@ function fixJson(input) {
|
|
|
674
674
|
case "}":
|
|
675
675
|
lastValidIndex = i;
|
|
676
676
|
stack.pop();
|
|
677
|
-
break;
|
|
678
677
|
}
|
|
679
678
|
}
|
|
680
679
|
function processAfterArrayValue(char, i) {
|
|
@@ -686,7 +685,6 @@ function fixJson(input) {
|
|
|
686
685
|
case "]":
|
|
687
686
|
lastValidIndex = i;
|
|
688
687
|
stack.pop();
|
|
689
|
-
break;
|
|
690
688
|
}
|
|
691
689
|
}
|
|
692
690
|
for (let i = 0; i < input.length; i++) {
|
|
@@ -704,7 +702,6 @@ function fixJson(input) {
|
|
|
704
702
|
case "}":
|
|
705
703
|
lastValidIndex = i;
|
|
706
704
|
stack.pop();
|
|
707
|
-
break;
|
|
708
705
|
}
|
|
709
706
|
break;
|
|
710
707
|
case "INSIDE_OBJECT_AFTER_COMMA":
|
|
@@ -712,7 +709,6 @@ function fixJson(input) {
|
|
|
712
709
|
case "\"":
|
|
713
710
|
stack.pop();
|
|
714
711
|
stack.push("INSIDE_OBJECT_KEY");
|
|
715
|
-
break;
|
|
716
712
|
}
|
|
717
713
|
break;
|
|
718
714
|
case "INSIDE_OBJECT_KEY":
|
|
@@ -720,7 +716,6 @@ function fixJson(input) {
|
|
|
720
716
|
case "\"":
|
|
721
717
|
stack.pop();
|
|
722
718
|
stack.push("INSIDE_OBJECT_AFTER_KEY");
|
|
723
|
-
break;
|
|
724
719
|
}
|
|
725
720
|
break;
|
|
726
721
|
case "INSIDE_OBJECT_AFTER_KEY":
|
|
@@ -728,7 +723,6 @@ function fixJson(input) {
|
|
|
728
723
|
case ":":
|
|
729
724
|
stack.pop();
|
|
730
725
|
stack.push("INSIDE_OBJECT_BEFORE_VALUE");
|
|
731
|
-
break;
|
|
732
726
|
}
|
|
733
727
|
break;
|
|
734
728
|
case "INSIDE_OBJECT_BEFORE_VALUE":
|
|
@@ -758,7 +752,6 @@ function fixJson(input) {
|
|
|
758
752
|
default:
|
|
759
753
|
lastValidIndex = i;
|
|
760
754
|
processValueStart(char, i, "INSIDE_ARRAY_AFTER_VALUE");
|
|
761
|
-
break;
|
|
762
755
|
}
|
|
763
756
|
break;
|
|
764
757
|
case "INSIDE_ARRAY_AFTER_VALUE":
|
|
@@ -771,9 +764,7 @@ function fixJson(input) {
|
|
|
771
764
|
lastValidIndex = i;
|
|
772
765
|
stack.pop();
|
|
773
766
|
break;
|
|
774
|
-
default:
|
|
775
|
-
lastValidIndex = i;
|
|
776
|
-
break;
|
|
767
|
+
default: lastValidIndex = i;
|
|
777
768
|
}
|
|
778
769
|
break;
|
|
779
770
|
case "INSIDE_ARRAY_AFTER_COMMA":
|
|
@@ -814,9 +805,7 @@ function fixJson(input) {
|
|
|
814
805
|
stack.pop();
|
|
815
806
|
if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") processAfterArrayValue(char, i);
|
|
816
807
|
break;
|
|
817
|
-
default:
|
|
818
|
-
stack.pop();
|
|
819
|
-
break;
|
|
808
|
+
default: stack.pop();
|
|
820
809
|
}
|
|
821
810
|
break;
|
|
822
811
|
case "INSIDE_LITERAL": {
|
|
@@ -1225,8 +1214,16 @@ var BaseResource = class {
|
|
|
1225
1214
|
};
|
|
1226
1215
|
//#endregion
|
|
1227
1216
|
//#region src/resources/agent.ts
|
|
1228
|
-
const SIGNAL_RUNTIME_OPTIONS_TTL_MS =
|
|
1217
|
+
const SIGNAL_RUNTIME_OPTIONS_TTL_MS = 3e5;
|
|
1229
1218
|
const signalRuntimeOptionsByRunId = /* @__PURE__ */ new Map();
|
|
1219
|
+
/**
|
|
1220
|
+
* Client tools a resume request can execute, keyed by run. The stream that stayed open from
|
|
1221
|
+
* before the suspension must not run those tools again, but it must run any resumed client tool
|
|
1222
|
+
* the resume request cannot execute (a server-side approve sends no client tools). Held until the
|
|
1223
|
+
* last stream of the run closes, which is after the resume request returns.
|
|
1224
|
+
*/
|
|
1225
|
+
const resumingClientToolNamesByRunKey = /* @__PURE__ */ new Map();
|
|
1226
|
+
const openStreamCountByRunKey = /* @__PURE__ */ new Map();
|
|
1230
1227
|
const latestSignalRuntimeOptionsByThread = /* @__PURE__ */ new Map();
|
|
1231
1228
|
const createSignalRuntimeOptionsEntry = (store, key, streamOptions) => {
|
|
1232
1229
|
const timeout = setTimeout(() => store.delete(key), SIGNAL_RUNTIME_OPTIONS_TTL_MS);
|
|
@@ -1419,6 +1416,49 @@ var Agent = class extends BaseResource {
|
|
|
1419
1416
|
getSignalRuntimeRunKey(runId) {
|
|
1420
1417
|
return `${this.options.baseUrl}|${this.apiPrefix}|${this.agentId}|${runId}`;
|
|
1421
1418
|
}
|
|
1419
|
+
/**
|
|
1420
|
+
* Records that `runId` is being resumed by a request that can execute these client tools, so the
|
|
1421
|
+
* stream that is still open from before the suspension skips them. Released when the last stream
|
|
1422
|
+
* of the run closes, which is after this request returns.
|
|
1423
|
+
*/
|
|
1424
|
+
holdResumingClientTools(runId, clientTools) {
|
|
1425
|
+
const names = Object.entries(clientTools ?? {}).filter(([, tool]) => typeof tool.execute === "function").map(([name]) => name);
|
|
1426
|
+
if (names.length === 0) return () => {};
|
|
1427
|
+
const key = this.getSignalRuntimeRunKey(runId);
|
|
1428
|
+
const held = resumingClientToolNamesByRunKey.get(key) ?? /* @__PURE__ */ new Map();
|
|
1429
|
+
for (const name of names) held.set(name, (held.get(name) ?? 0) + 1);
|
|
1430
|
+
resumingClientToolNamesByRunKey.set(key, held);
|
|
1431
|
+
let released = false;
|
|
1432
|
+
return ({ force = false } = {}) => {
|
|
1433
|
+
if (released || !force && openStreamCountByRunKey.has(key)) return;
|
|
1434
|
+
released = true;
|
|
1435
|
+
const current = resumingClientToolNamesByRunKey.get(key);
|
|
1436
|
+
if (!current) return;
|
|
1437
|
+
for (const name of names) {
|
|
1438
|
+
const count = (current.get(name) ?? 1) - 1;
|
|
1439
|
+
if (count > 0) current.set(name, count);
|
|
1440
|
+
else current.delete(name);
|
|
1441
|
+
}
|
|
1442
|
+
if (current.size === 0) resumingClientToolNamesByRunKey.delete(key);
|
|
1443
|
+
};
|
|
1444
|
+
}
|
|
1445
|
+
/** Drops the held tool names when the last stream of the run closes. */
|
|
1446
|
+
trackOpenStream(runId) {
|
|
1447
|
+
const key = this.getSignalRuntimeRunKey(runId);
|
|
1448
|
+
openStreamCountByRunKey.set(key, (openStreamCountByRunKey.get(key) ?? 0) + 1);
|
|
1449
|
+
let released = false;
|
|
1450
|
+
return () => {
|
|
1451
|
+
if (released) return;
|
|
1452
|
+
released = true;
|
|
1453
|
+
const remaining = (openStreamCountByRunKey.get(key) ?? 1) - 1;
|
|
1454
|
+
if (remaining > 0) {
|
|
1455
|
+
openStreamCountByRunKey.set(key, remaining);
|
|
1456
|
+
return;
|
|
1457
|
+
}
|
|
1458
|
+
openStreamCountByRunKey.delete(key);
|
|
1459
|
+
resumingClientToolNamesByRunKey.delete(key);
|
|
1460
|
+
};
|
|
1461
|
+
}
|
|
1422
1462
|
getSignalRuntimeThreadKey({ resourceId, threadId }) {
|
|
1423
1463
|
if (!threadId) return void 0;
|
|
1424
1464
|
return `${this.options.baseUrl}|${this.apiPrefix}|${this.agentId}|${resourceId ?? ""}|${threadId}`;
|
|
@@ -2556,7 +2596,6 @@ var Agent = class extends BaseResource {
|
|
|
2556
2596
|
case "finish":
|
|
2557
2597
|
finishReason = chunk.payload?.stepResult?.reason ?? finishReason;
|
|
2558
2598
|
if (chunk.payload?.usage != null) usage = chunk.payload.usage;
|
|
2559
|
-
break;
|
|
2560
2599
|
}
|
|
2561
2600
|
}
|
|
2562
2601
|
});
|
|
@@ -2621,6 +2660,9 @@ var Agent = class extends BaseResource {
|
|
|
2621
2660
|
let messages = [];
|
|
2622
2661
|
let streamRunId = processedParams.runId;
|
|
2623
2662
|
let finishedHistory;
|
|
2663
|
+
let suspended = false;
|
|
2664
|
+
const resumedToolCallIds = /* @__PURE__ */ new Set();
|
|
2665
|
+
const releaseOpenStream = streamRunId ? this.trackOpenStream(streamRunId) : () => {};
|
|
2624
2666
|
const [streamForController, streamForProcessing] = response.body.tee();
|
|
2625
2667
|
const decoder = new TextDecoder();
|
|
2626
2668
|
let pendingText = "";
|
|
@@ -2689,6 +2731,9 @@ var Agent = class extends BaseResource {
|
|
|
2689
2731
|
});
|
|
2690
2732
|
}
|
|
2691
2733
|
const executableToolCalls = [...toolInvocationsById.values()].filter((toolCall) => {
|
|
2734
|
+
if (resumedToolCallIds.has(toolCall.toolCallId)) {
|
|
2735
|
+
if ((streamRunId ? resumingClientToolNamesByRunKey.get(this.getSignalRuntimeRunKey(streamRunId)) : void 0)?.has(toolCall.toolName)) return false;
|
|
2736
|
+
}
|
|
2692
2737
|
const clientTool = processedParams.clientTools?.[toolCall.toolName];
|
|
2693
2738
|
return Boolean(clientTool?.execute);
|
|
2694
2739
|
});
|
|
@@ -2730,6 +2775,7 @@ var Agent = class extends BaseResource {
|
|
|
2730
2775
|
payload: {
|
|
2731
2776
|
toolCallId: toolCall.toolCallId,
|
|
2732
2777
|
toolName: toolCall.toolName,
|
|
2778
|
+
args: toolCall.args,
|
|
2733
2779
|
result,
|
|
2734
2780
|
isError: false,
|
|
2735
2781
|
providerExecuted: false
|
|
@@ -2815,6 +2861,12 @@ var Agent = class extends BaseResource {
|
|
|
2815
2861
|
},
|
|
2816
2862
|
onStreamChunk: (chunk) => {
|
|
2817
2863
|
if (!streamRunId && typeof chunk.runId === "string") streamRunId = chunk.runId;
|
|
2864
|
+
if (chunk.type === "tool-call-approval" || chunk.type === "tool-call-suspended") suspended = true;
|
|
2865
|
+
else if (suspended && chunk.type === "tool-call" && typeof chunk.payload?.toolCallId === "string") {
|
|
2866
|
+
const toolName = chunk.payload.toolName;
|
|
2867
|
+
const held = streamRunId ? resumingClientToolNamesByRunKey.get(this.getSignalRuntimeRunKey(streamRunId)) : void 0;
|
|
2868
|
+
if (typeof toolName === "string" && held?.has(toolName)) resumedToolCallIds.add(chunk.payload.toolCallId);
|
|
2869
|
+
}
|
|
2818
2870
|
},
|
|
2819
2871
|
lastMessage: void 0
|
|
2820
2872
|
}).catch(async (error) => {
|
|
@@ -2825,6 +2877,7 @@ var Agent = class extends BaseResource {
|
|
|
2825
2877
|
safeClose();
|
|
2826
2878
|
}).finally(() => {
|
|
2827
2879
|
signal?.removeEventListener("abort", onAbort);
|
|
2880
|
+
releaseOpenStream();
|
|
2828
2881
|
});
|
|
2829
2882
|
} catch (error) {
|
|
2830
2883
|
if (!isAbortError(error)) console.error("Error processing stream response:", error);
|
|
@@ -2992,13 +3045,18 @@ var Agent = class extends BaseResource {
|
|
|
2992
3045
|
}
|
|
2993
3046
|
async approveToolCall(params) {
|
|
2994
3047
|
const { requestContext, ...rest } = params;
|
|
3048
|
+
const executableClientTools = params.clientToolsResolver?.() ?? params.clientTools;
|
|
3049
|
+
const releaseHold = this.holdResumingClientTools(rest.runId, executableClientTools);
|
|
2995
3050
|
const processedParams = {
|
|
2996
3051
|
...rest,
|
|
2997
3052
|
requestContext: parseClientRequestContext(requestContext),
|
|
2998
|
-
clientTools: processClientTools(
|
|
3053
|
+
clientTools: processClientTools(executableClientTools)
|
|
2999
3054
|
};
|
|
3000
3055
|
const { readable, controller: readableController, signal } = this.createCancellableStream(params.abortSignal);
|
|
3001
|
-
const response = await this.processStreamResponse(processedParams, readableController, "approve-tool-call", signal)
|
|
3056
|
+
const response = await this.processStreamResponse(processedParams, readableController, "approve-tool-call", signal).catch((error) => {
|
|
3057
|
+
releaseHold({ force: true });
|
|
3058
|
+
throw error;
|
|
3059
|
+
});
|
|
3002
3060
|
const streamResponse = new Response(readable, {
|
|
3003
3061
|
status: response.status,
|
|
3004
3062
|
statusText: response.statusText,
|
|
@@ -3024,13 +3082,18 @@ var Agent = class extends BaseResource {
|
|
|
3024
3082
|
}
|
|
3025
3083
|
async declineToolCall(params) {
|
|
3026
3084
|
const { requestContext, ...rest } = params;
|
|
3085
|
+
const executableClientTools = params.clientToolsResolver?.() ?? params.clientTools;
|
|
3086
|
+
const releaseHold = this.holdResumingClientTools(rest.runId, executableClientTools);
|
|
3027
3087
|
const processedParams = {
|
|
3028
3088
|
...rest,
|
|
3029
3089
|
requestContext: parseClientRequestContext(requestContext),
|
|
3030
|
-
clientTools: processClientTools(
|
|
3090
|
+
clientTools: processClientTools(executableClientTools)
|
|
3031
3091
|
};
|
|
3032
3092
|
const { readable, controller: readableController, signal } = this.createCancellableStream(params.abortSignal);
|
|
3033
|
-
const response = await this.processStreamResponse(processedParams, readableController, "decline-tool-call", signal)
|
|
3093
|
+
const response = await this.processStreamResponse(processedParams, readableController, "decline-tool-call", signal).catch((error) => {
|
|
3094
|
+
releaseHold({ force: true });
|
|
3095
|
+
throw error;
|
|
3096
|
+
});
|
|
3034
3097
|
const streamResponse = new Response(readable, {
|
|
3035
3098
|
status: response.status,
|
|
3036
3099
|
statusText: response.statusText,
|
|
@@ -3090,18 +3153,23 @@ var Agent = class extends BaseResource {
|
|
|
3090
3153
|
* Used to continue execution after a suspension point (e.g., workflow suspend within an agent).
|
|
3091
3154
|
*/
|
|
3092
3155
|
async resumeStream(resumeData, options) {
|
|
3156
|
+
const executableClientTools = options.clientToolsResolver?.() ?? options.clientTools;
|
|
3157
|
+
const releaseHold = this.holdResumingClientTools(options.runId, executableClientTools);
|
|
3093
3158
|
const processedParams = {
|
|
3094
3159
|
...options,
|
|
3095
3160
|
resumeData,
|
|
3096
3161
|
requestContext: parseClientRequestContext(options.requestContext),
|
|
3097
|
-
clientTools: processClientTools(
|
|
3162
|
+
clientTools: processClientTools(executableClientTools),
|
|
3098
3163
|
structuredOutput: options.structuredOutput ? {
|
|
3099
3164
|
...options.structuredOutput,
|
|
3100
3165
|
schema: standardSchemaToJSONSchema(toStandardSchema(options.structuredOutput.schema))
|
|
3101
3166
|
} : void 0
|
|
3102
3167
|
};
|
|
3103
3168
|
const { readable, controller: readableController, signal } = this.createCancellableStream(options.abortSignal);
|
|
3104
|
-
const response = await this.processStreamResponse(processedParams, readableController, "resume-stream", signal)
|
|
3169
|
+
const response = await this.processStreamResponse(processedParams, readableController, "resume-stream", signal).catch((error) => {
|
|
3170
|
+
releaseHold({ force: true });
|
|
3171
|
+
throw error;
|
|
3172
|
+
});
|
|
3105
3173
|
const streamResponse = new Response(readable, {
|
|
3106
3174
|
status: response.status,
|
|
3107
3175
|
statusText: response.statusText,
|
|
@@ -3154,18 +3222,23 @@ var Agent = class extends BaseResource {
|
|
|
3154
3222
|
* Used to continue execution after a suspension point (e.g., workflow suspend within an agent).
|
|
3155
3223
|
*/
|
|
3156
3224
|
async resumeStreamUntilIdle(resumeData, options) {
|
|
3225
|
+
const executableClientTools = options.clientToolsResolver?.() ?? options.clientTools;
|
|
3226
|
+
const releaseHold = this.holdResumingClientTools(options.runId, executableClientTools);
|
|
3157
3227
|
const processedParams = {
|
|
3158
3228
|
...options,
|
|
3159
3229
|
resumeData,
|
|
3160
3230
|
requestContext: parseClientRequestContext(options.requestContext),
|
|
3161
|
-
clientTools: processClientTools(
|
|
3231
|
+
clientTools: processClientTools(executableClientTools),
|
|
3162
3232
|
structuredOutput: options.structuredOutput ? {
|
|
3163
3233
|
...options.structuredOutput,
|
|
3164
3234
|
schema: standardSchemaToJSONSchema(toStandardSchema(options.structuredOutput.schema))
|
|
3165
3235
|
} : void 0
|
|
3166
3236
|
};
|
|
3167
3237
|
const { readable, controller: readableController, signal } = this.createCancellableStream(options.abortSignal);
|
|
3168
|
-
const response = await this.processStreamResponse(processedParams, readableController, "resume-stream-until-idle", signal)
|
|
3238
|
+
const response = await this.processStreamResponse(processedParams, readableController, "resume-stream-until-idle", signal).catch((error) => {
|
|
3239
|
+
releaseHold({ force: true });
|
|
3240
|
+
throw error;
|
|
3241
|
+
});
|
|
3169
3242
|
const streamResponse = new Response(readable, {
|
|
3170
3243
|
status: response.status,
|
|
3171
3244
|
statusText: response.statusText,
|
|
@@ -3185,20 +3258,32 @@ var Agent = class extends BaseResource {
|
|
|
3185
3258
|
*/
|
|
3186
3259
|
async approveToolCallGenerate(params) {
|
|
3187
3260
|
const { requestContext, clientTools, clientToolsResolver, memory, ...rest } = params;
|
|
3188
|
-
const
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3261
|
+
const executableClientTools = clientToolsResolver?.() ?? clientTools;
|
|
3262
|
+
const releaseHold = this.holdResumingClientTools(rest.runId, executableClientTools);
|
|
3263
|
+
let response;
|
|
3264
|
+
try {
|
|
3265
|
+
response = await this.request(`/agents/${this.agentId}/approve-tool-call-generate`, {
|
|
3266
|
+
method: "POST",
|
|
3267
|
+
body: {
|
|
3268
|
+
...rest,
|
|
3269
|
+
requestContext: parseClientRequestContext(requestContext),
|
|
3270
|
+
clientTools: processClientTools(executableClientTools)
|
|
3271
|
+
}
|
|
3272
|
+
});
|
|
3273
|
+
} catch (error) {
|
|
3274
|
+
releaseHold({ force: true });
|
|
3275
|
+
throw error;
|
|
3276
|
+
}
|
|
3277
|
+
try {
|
|
3278
|
+
return await this.continueResumedGenerate(response, {
|
|
3279
|
+
requestContext,
|
|
3280
|
+
clientTools: executableClientTools,
|
|
3281
|
+
clientToolsResolver,
|
|
3282
|
+
memory
|
|
3283
|
+
});
|
|
3284
|
+
} finally {
|
|
3285
|
+
releaseHold();
|
|
3286
|
+
}
|
|
3202
3287
|
}
|
|
3203
3288
|
/**
|
|
3204
3289
|
* Declines a pending tool call and returns the complete response (non-streaming).
|
|
@@ -3206,20 +3291,32 @@ var Agent = class extends BaseResource {
|
|
|
3206
3291
|
*/
|
|
3207
3292
|
async declineToolCallGenerate(params) {
|
|
3208
3293
|
const { requestContext, clientTools, clientToolsResolver, memory, ...rest } = params;
|
|
3209
|
-
const
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3294
|
+
const executableClientTools = clientToolsResolver?.() ?? clientTools;
|
|
3295
|
+
const releaseHold = this.holdResumingClientTools(rest.runId, executableClientTools);
|
|
3296
|
+
let response;
|
|
3297
|
+
try {
|
|
3298
|
+
response = await this.request(`/agents/${this.agentId}/decline-tool-call-generate`, {
|
|
3299
|
+
method: "POST",
|
|
3300
|
+
body: {
|
|
3301
|
+
...rest,
|
|
3302
|
+
requestContext: parseClientRequestContext(requestContext),
|
|
3303
|
+
clientTools: processClientTools(executableClientTools)
|
|
3304
|
+
}
|
|
3305
|
+
});
|
|
3306
|
+
} catch (error) {
|
|
3307
|
+
releaseHold({ force: true });
|
|
3308
|
+
throw error;
|
|
3309
|
+
}
|
|
3310
|
+
try {
|
|
3311
|
+
return await this.continueResumedGenerate(response, {
|
|
3312
|
+
requestContext,
|
|
3313
|
+
clientTools: executableClientTools,
|
|
3314
|
+
clientToolsResolver,
|
|
3315
|
+
memory
|
|
3316
|
+
});
|
|
3317
|
+
} finally {
|
|
3318
|
+
releaseHold();
|
|
3319
|
+
}
|
|
3223
3320
|
}
|
|
3224
3321
|
/**
|
|
3225
3322
|
* Runs executable client tools the model called after an approval decision and continues on
|
|
@@ -4444,7 +4541,8 @@ async function verifyAgentCardSignatureIfPresent(agentCard, options) {
|
|
|
4444
4541
|
index
|
|
4445
4542
|
});
|
|
4446
4543
|
if (!verificationKey) throw new Error("No verification key was provided for Agent Card signature verification");
|
|
4447
|
-
|
|
4544
|
+
const importedKey = await importVerificationKey(verificationKey, protectedHeader.alg);
|
|
4545
|
+
await compactVerify(compactJws, importedKey, { algorithms: allowedAlgorithms });
|
|
4448
4546
|
return agentCard;
|
|
4449
4547
|
} catch (error) {
|
|
4450
4548
|
verificationErrors.push(error instanceof Error ? error.message : "Unknown verification failure");
|
|
@@ -5169,6 +5267,17 @@ var Observability = class extends BaseResource {
|
|
|
5169
5267
|
body: params
|
|
5170
5268
|
});
|
|
5171
5269
|
}
|
|
5270
|
+
/**
|
|
5271
|
+
* Groups and measures individual completed spans selected by a time range and optional span-query predicate.
|
|
5272
|
+
* Token and cost measures count usage recorded on each span itself. Check `capabilities.spanAggregate` from
|
|
5273
|
+
* `getObservabilityCapabilities()` first; servers without it return 404 or 501.
|
|
5274
|
+
*/
|
|
5275
|
+
aggregateSpans(params) {
|
|
5276
|
+
return this.request("/observability/spans/aggregate", {
|
|
5277
|
+
method: "POST",
|
|
5278
|
+
body: params
|
|
5279
|
+
});
|
|
5280
|
+
}
|
|
5172
5281
|
/** Returns canonical and observed fields available to the advanced trace-query grammar. */
|
|
5173
5282
|
getTraceQueryFields(params, options) {
|
|
5174
5283
|
return this.request("/observability/traces/query/fields", {
|
|
@@ -7696,8 +7805,10 @@ var MastraClient = class extends BaseResource {
|
|
|
7696
7805
|
if (logLevel) searchParams.set("logLevel", logLevel);
|
|
7697
7806
|
if (page !== void 0) searchParams.set("page", String(page));
|
|
7698
7807
|
if (perPage !== void 0) searchParams.set("perPage", String(perPage));
|
|
7699
|
-
if (_filters)
|
|
7700
|
-
|
|
7808
|
+
if (_filters) {
|
|
7809
|
+
if (Array.isArray(_filters)) for (const filter of _filters) searchParams.append("filters", filter);
|
|
7810
|
+
else searchParams.set("filters", _filters);
|
|
7811
|
+
}
|
|
7701
7812
|
if (searchParams.size) return this.request(`/logs?${searchParams}`);
|
|
7702
7813
|
else return this.request(`/logs`);
|
|
7703
7814
|
}
|
|
@@ -7717,8 +7828,10 @@ var MastraClient = class extends BaseResource {
|
|
|
7717
7828
|
if (logLevel) searchParams.set("logLevel", logLevel);
|
|
7718
7829
|
if (page !== void 0) searchParams.set("page", String(page));
|
|
7719
7830
|
if (perPage !== void 0) searchParams.set("perPage", String(perPage));
|
|
7720
|
-
if (_filters)
|
|
7721
|
-
|
|
7831
|
+
if (_filters) {
|
|
7832
|
+
if (Array.isArray(_filters)) for (const filter of _filters) searchParams.append("filters", filter);
|
|
7833
|
+
else searchParams.set("filters", _filters);
|
|
7834
|
+
}
|
|
7722
7835
|
if (searchParams.size) return this.request(`/logs/${runId}?${searchParams}`);
|
|
7723
7836
|
else return this.request(`/logs/${runId}`);
|
|
7724
7837
|
}
|
|
@@ -7795,6 +7908,77 @@ var MastraClient = class extends BaseResource {
|
|
|
7795
7908
|
});
|
|
7796
7909
|
}
|
|
7797
7910
|
/**
|
|
7911
|
+
* Lists the event types an MCP server declares (experimental).
|
|
7912
|
+
* `testEmit` is true when the server serves {@link emitMcpServerEvent} (under `mastra dev`).
|
|
7913
|
+
* @param serverId - The ID of the MCP server.
|
|
7914
|
+
*/
|
|
7915
|
+
getMcpServerEvents(serverId) {
|
|
7916
|
+
return this.request(`/mcp/${encodeURIComponent(serverId)}/events`);
|
|
7917
|
+
}
|
|
7918
|
+
/**
|
|
7919
|
+
* Reads occurrences of an MCP server event type, like the `events/poll` MCP request (experimental).
|
|
7920
|
+
* Pass the returned `cursor` to the next call to resume.
|
|
7921
|
+
* @param serverId - The ID of the MCP server.
|
|
7922
|
+
* @param eventName - The event type name.
|
|
7923
|
+
* @param body - Event arguments, resume cursor and page size.
|
|
7924
|
+
*/
|
|
7925
|
+
pollMcpServerEvent(serverId, eventName, body = {}) {
|
|
7926
|
+
return this.request(`/mcp/${encodeURIComponent(serverId)}/events/${encodeURIComponent(eventName)}/poll`, {
|
|
7927
|
+
method: "POST",
|
|
7928
|
+
body
|
|
7929
|
+
});
|
|
7930
|
+
}
|
|
7931
|
+
/**
|
|
7932
|
+
* Streams occurrences of a push-capable MCP server event type (experimental).
|
|
7933
|
+
* Yields an `active` frame first, then `event`, `heartbeat` and `error` frames, and ends
|
|
7934
|
+
* when the server ends the stream. Abort `options.signal` or break out of the loop to stop.
|
|
7935
|
+
*
|
|
7936
|
+
* @example
|
|
7937
|
+
* ```typescript
|
|
7938
|
+
* const controller = new AbortController();
|
|
7939
|
+
* for await (const frame of client.streamMcpServerEvent('tickets', 'ticket.created', {}, { signal: controller.signal })) {
|
|
7940
|
+
* if (frame.type === 'event') console.log(frame.occurrence.data);
|
|
7941
|
+
* }
|
|
7942
|
+
* ```
|
|
7943
|
+
*/
|
|
7944
|
+
async *streamMcpServerEvent(serverId, eventName, body = {}, options = {}) {
|
|
7945
|
+
const response = await this.request(`/mcp/${encodeURIComponent(serverId)}/events/${encodeURIComponent(eventName)}/stream`, {
|
|
7946
|
+
method: "POST",
|
|
7947
|
+
body,
|
|
7948
|
+
stream: true,
|
|
7949
|
+
signal: options.signal,
|
|
7950
|
+
retries: 0
|
|
7951
|
+
});
|
|
7952
|
+
if (!response.body) throw new Error("Response body is null");
|
|
7953
|
+
const reader = response.body.pipeThrough(createSseJsonTransform()).getReader();
|
|
7954
|
+
const cancel = () => void reader.cancel().catch(() => {});
|
|
7955
|
+
options.signal?.addEventListener("abort", cancel, { once: true });
|
|
7956
|
+
try {
|
|
7957
|
+
while (true) {
|
|
7958
|
+
const { value, done } = await reader.read();
|
|
7959
|
+
if (done) return;
|
|
7960
|
+
yield value;
|
|
7961
|
+
}
|
|
7962
|
+
} finally {
|
|
7963
|
+
options.signal?.removeEventListener("abort", cancel);
|
|
7964
|
+
await reader.cancel().catch(() => {});
|
|
7965
|
+
}
|
|
7966
|
+
}
|
|
7967
|
+
/**
|
|
7968
|
+
* Emits a test occurrence of an emit-fed MCP server event type (experimental).
|
|
7969
|
+
* Only served under `mastra dev`; other servers respond 404. The occurrence's
|
|
7970
|
+
* `eventId` starts with `mastra-test-`.
|
|
7971
|
+
* @param serverId - The ID of the MCP server.
|
|
7972
|
+
* @param eventName - The event type name.
|
|
7973
|
+
* @param data - The event payload; validated against the event's payload schema.
|
|
7974
|
+
*/
|
|
7975
|
+
emitMcpServerEvent(serverId, eventName, data) {
|
|
7976
|
+
return this.request(`/mcp/${encodeURIComponent(serverId)}/events/${encodeURIComponent(eventName)}/emit`, {
|
|
7977
|
+
method: "POST",
|
|
7978
|
+
body: { data }
|
|
7979
|
+
});
|
|
7980
|
+
}
|
|
7981
|
+
/**
|
|
7798
7982
|
* Gets an A2A client for interacting with an agent via the A2A protocol
|
|
7799
7983
|
* @param agentId - ID of the agent to interact with
|
|
7800
7984
|
* @returns A2A client instance
|
|
@@ -7958,6 +8142,14 @@ var MastraClient = class extends BaseResource {
|
|
|
7958
8142
|
aggregateTraces(params) {
|
|
7959
8143
|
return this.observability.aggregateTraces(params);
|
|
7960
8144
|
}
|
|
8145
|
+
/**
|
|
8146
|
+
* Groups and measures individual completed spans selected by a time range and optional span-query predicate.
|
|
8147
|
+
* Token and cost measures count usage recorded on each span itself. Check `capabilities.spanAggregate` from
|
|
8148
|
+
* `getObservabilityCapabilities()` first; servers without it return 404 or 501.
|
|
8149
|
+
*/
|
|
8150
|
+
aggregateSpans(params) {
|
|
8151
|
+
return this.observability.aggregateSpans(params);
|
|
8152
|
+
}
|
|
7961
8153
|
/** Returns canonical and observed fields available to the advanced trace-query grammar. */
|
|
7962
8154
|
getTraceQueryFields(params, options) {
|
|
7963
8155
|
return this.observability.getTraceQueryFields(params, options);
|