@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.cjs
CHANGED
|
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
20
20
|
value: mod,
|
|
21
21
|
enumerable: true
|
|
22
22
|
}) : target, mod));
|
|
@@ -83,15 +83,16 @@ function attributesToOtlp(attrs) {
|
|
|
83
83
|
key,
|
|
84
84
|
value: { boolValue: raw }
|
|
85
85
|
});
|
|
86
|
-
else if (typeof raw === "number")
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
86
|
+
else if (typeof raw === "number") {
|
|
87
|
+
if (Number.isInteger(raw)) out.push({
|
|
88
|
+
key,
|
|
89
|
+
value: { intValue: raw }
|
|
90
|
+
});
|
|
91
|
+
else out.push({
|
|
92
|
+
key,
|
|
93
|
+
value: { doubleValue: raw }
|
|
94
|
+
});
|
|
95
|
+
} else try {
|
|
95
96
|
out.push({
|
|
96
97
|
key,
|
|
97
98
|
value: { stringValue: JSON.stringify(raw) }
|
|
@@ -686,7 +687,6 @@ function fixJson(input) {
|
|
|
686
687
|
stack.pop();
|
|
687
688
|
stack.push(swapState);
|
|
688
689
|
stack.push("INSIDE_ARRAY_START");
|
|
689
|
-
break;
|
|
690
690
|
}
|
|
691
691
|
}
|
|
692
692
|
function processAfterObjectValue(char, i) {
|
|
@@ -698,7 +698,6 @@ function fixJson(input) {
|
|
|
698
698
|
case "}":
|
|
699
699
|
lastValidIndex = i;
|
|
700
700
|
stack.pop();
|
|
701
|
-
break;
|
|
702
701
|
}
|
|
703
702
|
}
|
|
704
703
|
function processAfterArrayValue(char, i) {
|
|
@@ -710,7 +709,6 @@ function fixJson(input) {
|
|
|
710
709
|
case "]":
|
|
711
710
|
lastValidIndex = i;
|
|
712
711
|
stack.pop();
|
|
713
|
-
break;
|
|
714
712
|
}
|
|
715
713
|
}
|
|
716
714
|
for (let i = 0; i < input.length; i++) {
|
|
@@ -728,7 +726,6 @@ function fixJson(input) {
|
|
|
728
726
|
case "}":
|
|
729
727
|
lastValidIndex = i;
|
|
730
728
|
stack.pop();
|
|
731
|
-
break;
|
|
732
729
|
}
|
|
733
730
|
break;
|
|
734
731
|
case "INSIDE_OBJECT_AFTER_COMMA":
|
|
@@ -736,7 +733,6 @@ function fixJson(input) {
|
|
|
736
733
|
case "\"":
|
|
737
734
|
stack.pop();
|
|
738
735
|
stack.push("INSIDE_OBJECT_KEY");
|
|
739
|
-
break;
|
|
740
736
|
}
|
|
741
737
|
break;
|
|
742
738
|
case "INSIDE_OBJECT_KEY":
|
|
@@ -744,7 +740,6 @@ function fixJson(input) {
|
|
|
744
740
|
case "\"":
|
|
745
741
|
stack.pop();
|
|
746
742
|
stack.push("INSIDE_OBJECT_AFTER_KEY");
|
|
747
|
-
break;
|
|
748
743
|
}
|
|
749
744
|
break;
|
|
750
745
|
case "INSIDE_OBJECT_AFTER_KEY":
|
|
@@ -752,7 +747,6 @@ function fixJson(input) {
|
|
|
752
747
|
case ":":
|
|
753
748
|
stack.pop();
|
|
754
749
|
stack.push("INSIDE_OBJECT_BEFORE_VALUE");
|
|
755
|
-
break;
|
|
756
750
|
}
|
|
757
751
|
break;
|
|
758
752
|
case "INSIDE_OBJECT_BEFORE_VALUE":
|
|
@@ -782,7 +776,6 @@ function fixJson(input) {
|
|
|
782
776
|
default:
|
|
783
777
|
lastValidIndex = i;
|
|
784
778
|
processValueStart(char, i, "INSIDE_ARRAY_AFTER_VALUE");
|
|
785
|
-
break;
|
|
786
779
|
}
|
|
787
780
|
break;
|
|
788
781
|
case "INSIDE_ARRAY_AFTER_VALUE":
|
|
@@ -795,9 +788,7 @@ function fixJson(input) {
|
|
|
795
788
|
lastValidIndex = i;
|
|
796
789
|
stack.pop();
|
|
797
790
|
break;
|
|
798
|
-
default:
|
|
799
|
-
lastValidIndex = i;
|
|
800
|
-
break;
|
|
791
|
+
default: lastValidIndex = i;
|
|
801
792
|
}
|
|
802
793
|
break;
|
|
803
794
|
case "INSIDE_ARRAY_AFTER_COMMA":
|
|
@@ -838,9 +829,7 @@ function fixJson(input) {
|
|
|
838
829
|
stack.pop();
|
|
839
830
|
if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") processAfterArrayValue(char, i);
|
|
840
831
|
break;
|
|
841
|
-
default:
|
|
842
|
-
stack.pop();
|
|
843
|
-
break;
|
|
832
|
+
default: stack.pop();
|
|
844
833
|
}
|
|
845
834
|
break;
|
|
846
835
|
case "INSIDE_LITERAL": {
|
|
@@ -1249,8 +1238,16 @@ var BaseResource = class {
|
|
|
1249
1238
|
};
|
|
1250
1239
|
//#endregion
|
|
1251
1240
|
//#region src/resources/agent.ts
|
|
1252
|
-
const SIGNAL_RUNTIME_OPTIONS_TTL_MS =
|
|
1241
|
+
const SIGNAL_RUNTIME_OPTIONS_TTL_MS = 3e5;
|
|
1253
1242
|
const signalRuntimeOptionsByRunId = /* @__PURE__ */ new Map();
|
|
1243
|
+
/**
|
|
1244
|
+
* Client tools a resume request can execute, keyed by run. The stream that stayed open from
|
|
1245
|
+
* before the suspension must not run those tools again, but it must run any resumed client tool
|
|
1246
|
+
* the resume request cannot execute (a server-side approve sends no client tools). Held until the
|
|
1247
|
+
* last stream of the run closes, which is after the resume request returns.
|
|
1248
|
+
*/
|
|
1249
|
+
const resumingClientToolNamesByRunKey = /* @__PURE__ */ new Map();
|
|
1250
|
+
const openStreamCountByRunKey = /* @__PURE__ */ new Map();
|
|
1254
1251
|
const latestSignalRuntimeOptionsByThread = /* @__PURE__ */ new Map();
|
|
1255
1252
|
const createSignalRuntimeOptionsEntry = (store, key, streamOptions) => {
|
|
1256
1253
|
const timeout = setTimeout(() => store.delete(key), SIGNAL_RUNTIME_OPTIONS_TTL_MS);
|
|
@@ -1443,6 +1440,49 @@ var Agent = class extends BaseResource {
|
|
|
1443
1440
|
getSignalRuntimeRunKey(runId) {
|
|
1444
1441
|
return `${this.options.baseUrl}|${this.apiPrefix}|${this.agentId}|${runId}`;
|
|
1445
1442
|
}
|
|
1443
|
+
/**
|
|
1444
|
+
* Records that `runId` is being resumed by a request that can execute these client tools, so the
|
|
1445
|
+
* stream that is still open from before the suspension skips them. Released when the last stream
|
|
1446
|
+
* of the run closes, which is after this request returns.
|
|
1447
|
+
*/
|
|
1448
|
+
holdResumingClientTools(runId, clientTools) {
|
|
1449
|
+
const names = Object.entries(clientTools ?? {}).filter(([, tool]) => typeof tool.execute === "function").map(([name]) => name);
|
|
1450
|
+
if (names.length === 0) return () => {};
|
|
1451
|
+
const key = this.getSignalRuntimeRunKey(runId);
|
|
1452
|
+
const held = resumingClientToolNamesByRunKey.get(key) ?? /* @__PURE__ */ new Map();
|
|
1453
|
+
for (const name of names) held.set(name, (held.get(name) ?? 0) + 1);
|
|
1454
|
+
resumingClientToolNamesByRunKey.set(key, held);
|
|
1455
|
+
let released = false;
|
|
1456
|
+
return ({ force = false } = {}) => {
|
|
1457
|
+
if (released || !force && openStreamCountByRunKey.has(key)) return;
|
|
1458
|
+
released = true;
|
|
1459
|
+
const current = resumingClientToolNamesByRunKey.get(key);
|
|
1460
|
+
if (!current) return;
|
|
1461
|
+
for (const name of names) {
|
|
1462
|
+
const count = (current.get(name) ?? 1) - 1;
|
|
1463
|
+
if (count > 0) current.set(name, count);
|
|
1464
|
+
else current.delete(name);
|
|
1465
|
+
}
|
|
1466
|
+
if (current.size === 0) resumingClientToolNamesByRunKey.delete(key);
|
|
1467
|
+
};
|
|
1468
|
+
}
|
|
1469
|
+
/** Drops the held tool names when the last stream of the run closes. */
|
|
1470
|
+
trackOpenStream(runId) {
|
|
1471
|
+
const key = this.getSignalRuntimeRunKey(runId);
|
|
1472
|
+
openStreamCountByRunKey.set(key, (openStreamCountByRunKey.get(key) ?? 0) + 1);
|
|
1473
|
+
let released = false;
|
|
1474
|
+
return () => {
|
|
1475
|
+
if (released) return;
|
|
1476
|
+
released = true;
|
|
1477
|
+
const remaining = (openStreamCountByRunKey.get(key) ?? 1) - 1;
|
|
1478
|
+
if (remaining > 0) {
|
|
1479
|
+
openStreamCountByRunKey.set(key, remaining);
|
|
1480
|
+
return;
|
|
1481
|
+
}
|
|
1482
|
+
openStreamCountByRunKey.delete(key);
|
|
1483
|
+
resumingClientToolNamesByRunKey.delete(key);
|
|
1484
|
+
};
|
|
1485
|
+
}
|
|
1446
1486
|
getSignalRuntimeThreadKey({ resourceId, threadId }) {
|
|
1447
1487
|
if (!threadId) return void 0;
|
|
1448
1488
|
return `${this.options.baseUrl}|${this.apiPrefix}|${this.agentId}|${resourceId ?? ""}|${threadId}`;
|
|
@@ -2580,7 +2620,6 @@ var Agent = class extends BaseResource {
|
|
|
2580
2620
|
case "finish":
|
|
2581
2621
|
finishReason = chunk.payload?.stepResult?.reason ?? finishReason;
|
|
2582
2622
|
if (chunk.payload?.usage != null) usage = chunk.payload.usage;
|
|
2583
|
-
break;
|
|
2584
2623
|
}
|
|
2585
2624
|
}
|
|
2586
2625
|
});
|
|
@@ -2645,6 +2684,9 @@ var Agent = class extends BaseResource {
|
|
|
2645
2684
|
let messages = [];
|
|
2646
2685
|
let streamRunId = processedParams.runId;
|
|
2647
2686
|
let finishedHistory;
|
|
2687
|
+
let suspended = false;
|
|
2688
|
+
const resumedToolCallIds = /* @__PURE__ */ new Set();
|
|
2689
|
+
const releaseOpenStream = streamRunId ? this.trackOpenStream(streamRunId) : () => {};
|
|
2648
2690
|
const [streamForController, streamForProcessing] = response.body.tee();
|
|
2649
2691
|
const decoder = new TextDecoder();
|
|
2650
2692
|
let pendingText = "";
|
|
@@ -2713,6 +2755,9 @@ var Agent = class extends BaseResource {
|
|
|
2713
2755
|
});
|
|
2714
2756
|
}
|
|
2715
2757
|
const executableToolCalls = [...toolInvocationsById.values()].filter((toolCall) => {
|
|
2758
|
+
if (resumedToolCallIds.has(toolCall.toolCallId)) {
|
|
2759
|
+
if ((streamRunId ? resumingClientToolNamesByRunKey.get(this.getSignalRuntimeRunKey(streamRunId)) : void 0)?.has(toolCall.toolName)) return false;
|
|
2760
|
+
}
|
|
2716
2761
|
const clientTool = processedParams.clientTools?.[toolCall.toolName];
|
|
2717
2762
|
return Boolean(clientTool?.execute);
|
|
2718
2763
|
});
|
|
@@ -2754,6 +2799,7 @@ var Agent = class extends BaseResource {
|
|
|
2754
2799
|
payload: {
|
|
2755
2800
|
toolCallId: toolCall.toolCallId,
|
|
2756
2801
|
toolName: toolCall.toolName,
|
|
2802
|
+
args: toolCall.args,
|
|
2757
2803
|
result,
|
|
2758
2804
|
isError: false,
|
|
2759
2805
|
providerExecuted: false
|
|
@@ -2839,6 +2885,12 @@ var Agent = class extends BaseResource {
|
|
|
2839
2885
|
},
|
|
2840
2886
|
onStreamChunk: (chunk) => {
|
|
2841
2887
|
if (!streamRunId && typeof chunk.runId === "string") streamRunId = chunk.runId;
|
|
2888
|
+
if (chunk.type === "tool-call-approval" || chunk.type === "tool-call-suspended") suspended = true;
|
|
2889
|
+
else if (suspended && chunk.type === "tool-call" && typeof chunk.payload?.toolCallId === "string") {
|
|
2890
|
+
const toolName = chunk.payload.toolName;
|
|
2891
|
+
const held = streamRunId ? resumingClientToolNamesByRunKey.get(this.getSignalRuntimeRunKey(streamRunId)) : void 0;
|
|
2892
|
+
if (typeof toolName === "string" && held?.has(toolName)) resumedToolCallIds.add(chunk.payload.toolCallId);
|
|
2893
|
+
}
|
|
2842
2894
|
},
|
|
2843
2895
|
lastMessage: void 0
|
|
2844
2896
|
}).catch(async (error) => {
|
|
@@ -2849,6 +2901,7 @@ var Agent = class extends BaseResource {
|
|
|
2849
2901
|
safeClose();
|
|
2850
2902
|
}).finally(() => {
|
|
2851
2903
|
signal?.removeEventListener("abort", onAbort);
|
|
2904
|
+
releaseOpenStream();
|
|
2852
2905
|
});
|
|
2853
2906
|
} catch (error) {
|
|
2854
2907
|
if (!isAbortError(error)) console.error("Error processing stream response:", error);
|
|
@@ -3016,13 +3069,18 @@ var Agent = class extends BaseResource {
|
|
|
3016
3069
|
}
|
|
3017
3070
|
async approveToolCall(params) {
|
|
3018
3071
|
const { requestContext, ...rest } = params;
|
|
3072
|
+
const executableClientTools = params.clientToolsResolver?.() ?? params.clientTools;
|
|
3073
|
+
const releaseHold = this.holdResumingClientTools(rest.runId, executableClientTools);
|
|
3019
3074
|
const processedParams = {
|
|
3020
3075
|
...rest,
|
|
3021
3076
|
requestContext: parseClientRequestContext(requestContext),
|
|
3022
|
-
clientTools: processClientTools(
|
|
3077
|
+
clientTools: processClientTools(executableClientTools)
|
|
3023
3078
|
};
|
|
3024
3079
|
const { readable, controller: readableController, signal } = this.createCancellableStream(params.abortSignal);
|
|
3025
|
-
const response = await this.processStreamResponse(processedParams, readableController, "approve-tool-call", signal)
|
|
3080
|
+
const response = await this.processStreamResponse(processedParams, readableController, "approve-tool-call", signal).catch((error) => {
|
|
3081
|
+
releaseHold({ force: true });
|
|
3082
|
+
throw error;
|
|
3083
|
+
});
|
|
3026
3084
|
const streamResponse = new Response(readable, {
|
|
3027
3085
|
status: response.status,
|
|
3028
3086
|
statusText: response.statusText,
|
|
@@ -3048,13 +3106,18 @@ var Agent = class extends BaseResource {
|
|
|
3048
3106
|
}
|
|
3049
3107
|
async declineToolCall(params) {
|
|
3050
3108
|
const { requestContext, ...rest } = params;
|
|
3109
|
+
const executableClientTools = params.clientToolsResolver?.() ?? params.clientTools;
|
|
3110
|
+
const releaseHold = this.holdResumingClientTools(rest.runId, executableClientTools);
|
|
3051
3111
|
const processedParams = {
|
|
3052
3112
|
...rest,
|
|
3053
3113
|
requestContext: parseClientRequestContext(requestContext),
|
|
3054
|
-
clientTools: processClientTools(
|
|
3114
|
+
clientTools: processClientTools(executableClientTools)
|
|
3055
3115
|
};
|
|
3056
3116
|
const { readable, controller: readableController, signal } = this.createCancellableStream(params.abortSignal);
|
|
3057
|
-
const response = await this.processStreamResponse(processedParams, readableController, "decline-tool-call", signal)
|
|
3117
|
+
const response = await this.processStreamResponse(processedParams, readableController, "decline-tool-call", signal).catch((error) => {
|
|
3118
|
+
releaseHold({ force: true });
|
|
3119
|
+
throw error;
|
|
3120
|
+
});
|
|
3058
3121
|
const streamResponse = new Response(readable, {
|
|
3059
3122
|
status: response.status,
|
|
3060
3123
|
statusText: response.statusText,
|
|
@@ -3114,18 +3177,23 @@ var Agent = class extends BaseResource {
|
|
|
3114
3177
|
* Used to continue execution after a suspension point (e.g., workflow suspend within an agent).
|
|
3115
3178
|
*/
|
|
3116
3179
|
async resumeStream(resumeData, options) {
|
|
3180
|
+
const executableClientTools = options.clientToolsResolver?.() ?? options.clientTools;
|
|
3181
|
+
const releaseHold = this.holdResumingClientTools(options.runId, executableClientTools);
|
|
3117
3182
|
const processedParams = {
|
|
3118
3183
|
...options,
|
|
3119
3184
|
resumeData,
|
|
3120
3185
|
requestContext: parseClientRequestContext(options.requestContext),
|
|
3121
|
-
clientTools: processClientTools(
|
|
3186
|
+
clientTools: processClientTools(executableClientTools),
|
|
3122
3187
|
structuredOutput: options.structuredOutput ? {
|
|
3123
3188
|
...options.structuredOutput,
|
|
3124
3189
|
schema: (0, _mastra_schema_compat_schema.standardSchemaToJSONSchema)((0, _mastra_schema_compat_schema.toStandardSchema)(options.structuredOutput.schema))
|
|
3125
3190
|
} : void 0
|
|
3126
3191
|
};
|
|
3127
3192
|
const { readable, controller: readableController, signal } = this.createCancellableStream(options.abortSignal);
|
|
3128
|
-
const response = await this.processStreamResponse(processedParams, readableController, "resume-stream", signal)
|
|
3193
|
+
const response = await this.processStreamResponse(processedParams, readableController, "resume-stream", signal).catch((error) => {
|
|
3194
|
+
releaseHold({ force: true });
|
|
3195
|
+
throw error;
|
|
3196
|
+
});
|
|
3129
3197
|
const streamResponse = new Response(readable, {
|
|
3130
3198
|
status: response.status,
|
|
3131
3199
|
statusText: response.statusText,
|
|
@@ -3178,18 +3246,23 @@ var Agent = class extends BaseResource {
|
|
|
3178
3246
|
* Used to continue execution after a suspension point (e.g., workflow suspend within an agent).
|
|
3179
3247
|
*/
|
|
3180
3248
|
async resumeStreamUntilIdle(resumeData, options) {
|
|
3249
|
+
const executableClientTools = options.clientToolsResolver?.() ?? options.clientTools;
|
|
3250
|
+
const releaseHold = this.holdResumingClientTools(options.runId, executableClientTools);
|
|
3181
3251
|
const processedParams = {
|
|
3182
3252
|
...options,
|
|
3183
3253
|
resumeData,
|
|
3184
3254
|
requestContext: parseClientRequestContext(options.requestContext),
|
|
3185
|
-
clientTools: processClientTools(
|
|
3255
|
+
clientTools: processClientTools(executableClientTools),
|
|
3186
3256
|
structuredOutput: options.structuredOutput ? {
|
|
3187
3257
|
...options.structuredOutput,
|
|
3188
3258
|
schema: (0, _mastra_schema_compat_schema.standardSchemaToJSONSchema)((0, _mastra_schema_compat_schema.toStandardSchema)(options.structuredOutput.schema))
|
|
3189
3259
|
} : void 0
|
|
3190
3260
|
};
|
|
3191
3261
|
const { readable, controller: readableController, signal } = this.createCancellableStream(options.abortSignal);
|
|
3192
|
-
const response = await this.processStreamResponse(processedParams, readableController, "resume-stream-until-idle", signal)
|
|
3262
|
+
const response = await this.processStreamResponse(processedParams, readableController, "resume-stream-until-idle", signal).catch((error) => {
|
|
3263
|
+
releaseHold({ force: true });
|
|
3264
|
+
throw error;
|
|
3265
|
+
});
|
|
3193
3266
|
const streamResponse = new Response(readable, {
|
|
3194
3267
|
status: response.status,
|
|
3195
3268
|
statusText: response.statusText,
|
|
@@ -3209,20 +3282,32 @@ var Agent = class extends BaseResource {
|
|
|
3209
3282
|
*/
|
|
3210
3283
|
async approveToolCallGenerate(params) {
|
|
3211
3284
|
const { requestContext, clientTools, clientToolsResolver, memory, ...rest } = params;
|
|
3212
|
-
const
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3285
|
+
const executableClientTools = clientToolsResolver?.() ?? clientTools;
|
|
3286
|
+
const releaseHold = this.holdResumingClientTools(rest.runId, executableClientTools);
|
|
3287
|
+
let response;
|
|
3288
|
+
try {
|
|
3289
|
+
response = await this.request(`/agents/${this.agentId}/approve-tool-call-generate`, {
|
|
3290
|
+
method: "POST",
|
|
3291
|
+
body: {
|
|
3292
|
+
...rest,
|
|
3293
|
+
requestContext: parseClientRequestContext(requestContext),
|
|
3294
|
+
clientTools: processClientTools(executableClientTools)
|
|
3295
|
+
}
|
|
3296
|
+
});
|
|
3297
|
+
} catch (error) {
|
|
3298
|
+
releaseHold({ force: true });
|
|
3299
|
+
throw error;
|
|
3300
|
+
}
|
|
3301
|
+
try {
|
|
3302
|
+
return await this.continueResumedGenerate(response, {
|
|
3303
|
+
requestContext,
|
|
3304
|
+
clientTools: executableClientTools,
|
|
3305
|
+
clientToolsResolver,
|
|
3306
|
+
memory
|
|
3307
|
+
});
|
|
3308
|
+
} finally {
|
|
3309
|
+
releaseHold();
|
|
3310
|
+
}
|
|
3226
3311
|
}
|
|
3227
3312
|
/**
|
|
3228
3313
|
* Declines a pending tool call and returns the complete response (non-streaming).
|
|
@@ -3230,20 +3315,32 @@ var Agent = class extends BaseResource {
|
|
|
3230
3315
|
*/
|
|
3231
3316
|
async declineToolCallGenerate(params) {
|
|
3232
3317
|
const { requestContext, clientTools, clientToolsResolver, memory, ...rest } = params;
|
|
3233
|
-
const
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3318
|
+
const executableClientTools = clientToolsResolver?.() ?? clientTools;
|
|
3319
|
+
const releaseHold = this.holdResumingClientTools(rest.runId, executableClientTools);
|
|
3320
|
+
let response;
|
|
3321
|
+
try {
|
|
3322
|
+
response = await this.request(`/agents/${this.agentId}/decline-tool-call-generate`, {
|
|
3323
|
+
method: "POST",
|
|
3324
|
+
body: {
|
|
3325
|
+
...rest,
|
|
3326
|
+
requestContext: parseClientRequestContext(requestContext),
|
|
3327
|
+
clientTools: processClientTools(executableClientTools)
|
|
3328
|
+
}
|
|
3329
|
+
});
|
|
3330
|
+
} catch (error) {
|
|
3331
|
+
releaseHold({ force: true });
|
|
3332
|
+
throw error;
|
|
3333
|
+
}
|
|
3334
|
+
try {
|
|
3335
|
+
return await this.continueResumedGenerate(response, {
|
|
3336
|
+
requestContext,
|
|
3337
|
+
clientTools: executableClientTools,
|
|
3338
|
+
clientToolsResolver,
|
|
3339
|
+
memory
|
|
3340
|
+
});
|
|
3341
|
+
} finally {
|
|
3342
|
+
releaseHold();
|
|
3343
|
+
}
|
|
3247
3344
|
}
|
|
3248
3345
|
/**
|
|
3249
3346
|
* Runs executable client tools the model called after an approval decision and continues on
|
|
@@ -4468,7 +4565,8 @@ async function verifyAgentCardSignatureIfPresent(agentCard, options) {
|
|
|
4468
4565
|
index
|
|
4469
4566
|
});
|
|
4470
4567
|
if (!verificationKey) throw new Error("No verification key was provided for Agent Card signature verification");
|
|
4471
|
-
|
|
4568
|
+
const importedKey = await importVerificationKey(verificationKey, protectedHeader.alg);
|
|
4569
|
+
await (0, jose.compactVerify)(compactJws, importedKey, { algorithms: allowedAlgorithms });
|
|
4472
4570
|
return agentCard;
|
|
4473
4571
|
} catch (error) {
|
|
4474
4572
|
verificationErrors.push(error instanceof Error ? error.message : "Unknown verification failure");
|
|
@@ -5193,6 +5291,17 @@ var Observability = class extends BaseResource {
|
|
|
5193
5291
|
body: params
|
|
5194
5292
|
});
|
|
5195
5293
|
}
|
|
5294
|
+
/**
|
|
5295
|
+
* Groups and measures individual completed spans selected by a time range and optional span-query predicate.
|
|
5296
|
+
* Token and cost measures count usage recorded on each span itself. Check `capabilities.spanAggregate` from
|
|
5297
|
+
* `getObservabilityCapabilities()` first; servers without it return 404 or 501.
|
|
5298
|
+
*/
|
|
5299
|
+
aggregateSpans(params) {
|
|
5300
|
+
return this.request("/observability/spans/aggregate", {
|
|
5301
|
+
method: "POST",
|
|
5302
|
+
body: params
|
|
5303
|
+
});
|
|
5304
|
+
}
|
|
5196
5305
|
/** Returns canonical and observed fields available to the advanced trace-query grammar. */
|
|
5197
5306
|
getTraceQueryFields(params, options) {
|
|
5198
5307
|
return this.request("/observability/traces/query/fields", {
|
|
@@ -7720,8 +7829,10 @@ var MastraClient = class extends BaseResource {
|
|
|
7720
7829
|
if (logLevel) searchParams.set("logLevel", logLevel);
|
|
7721
7830
|
if (page !== void 0) searchParams.set("page", String(page));
|
|
7722
7831
|
if (perPage !== void 0) searchParams.set("perPage", String(perPage));
|
|
7723
|
-
if (_filters)
|
|
7724
|
-
|
|
7832
|
+
if (_filters) {
|
|
7833
|
+
if (Array.isArray(_filters)) for (const filter of _filters) searchParams.append("filters", filter);
|
|
7834
|
+
else searchParams.set("filters", _filters);
|
|
7835
|
+
}
|
|
7725
7836
|
if (searchParams.size) return this.request(`/logs?${searchParams}`);
|
|
7726
7837
|
else return this.request(`/logs`);
|
|
7727
7838
|
}
|
|
@@ -7741,8 +7852,10 @@ var MastraClient = class extends BaseResource {
|
|
|
7741
7852
|
if (logLevel) searchParams.set("logLevel", logLevel);
|
|
7742
7853
|
if (page !== void 0) searchParams.set("page", String(page));
|
|
7743
7854
|
if (perPage !== void 0) searchParams.set("perPage", String(perPage));
|
|
7744
|
-
if (_filters)
|
|
7745
|
-
|
|
7855
|
+
if (_filters) {
|
|
7856
|
+
if (Array.isArray(_filters)) for (const filter of _filters) searchParams.append("filters", filter);
|
|
7857
|
+
else searchParams.set("filters", _filters);
|
|
7858
|
+
}
|
|
7746
7859
|
if (searchParams.size) return this.request(`/logs/${runId}?${searchParams}`);
|
|
7747
7860
|
else return this.request(`/logs/${runId}`);
|
|
7748
7861
|
}
|
|
@@ -7819,6 +7932,77 @@ var MastraClient = class extends BaseResource {
|
|
|
7819
7932
|
});
|
|
7820
7933
|
}
|
|
7821
7934
|
/**
|
|
7935
|
+
* Lists the event types an MCP server declares (experimental).
|
|
7936
|
+
* `testEmit` is true when the server serves {@link emitMcpServerEvent} (under `mastra dev`).
|
|
7937
|
+
* @param serverId - The ID of the MCP server.
|
|
7938
|
+
*/
|
|
7939
|
+
getMcpServerEvents(serverId) {
|
|
7940
|
+
return this.request(`/mcp/${encodeURIComponent(serverId)}/events`);
|
|
7941
|
+
}
|
|
7942
|
+
/**
|
|
7943
|
+
* Reads occurrences of an MCP server event type, like the `events/poll` MCP request (experimental).
|
|
7944
|
+
* Pass the returned `cursor` to the next call to resume.
|
|
7945
|
+
* @param serverId - The ID of the MCP server.
|
|
7946
|
+
* @param eventName - The event type name.
|
|
7947
|
+
* @param body - Event arguments, resume cursor and page size.
|
|
7948
|
+
*/
|
|
7949
|
+
pollMcpServerEvent(serverId, eventName, body = {}) {
|
|
7950
|
+
return this.request(`/mcp/${encodeURIComponent(serverId)}/events/${encodeURIComponent(eventName)}/poll`, {
|
|
7951
|
+
method: "POST",
|
|
7952
|
+
body
|
|
7953
|
+
});
|
|
7954
|
+
}
|
|
7955
|
+
/**
|
|
7956
|
+
* Streams occurrences of a push-capable MCP server event type (experimental).
|
|
7957
|
+
* Yields an `active` frame first, then `event`, `heartbeat` and `error` frames, and ends
|
|
7958
|
+
* when the server ends the stream. Abort `options.signal` or break out of the loop to stop.
|
|
7959
|
+
*
|
|
7960
|
+
* @example
|
|
7961
|
+
* ```typescript
|
|
7962
|
+
* const controller = new AbortController();
|
|
7963
|
+
* for await (const frame of client.streamMcpServerEvent('tickets', 'ticket.created', {}, { signal: controller.signal })) {
|
|
7964
|
+
* if (frame.type === 'event') console.log(frame.occurrence.data);
|
|
7965
|
+
* }
|
|
7966
|
+
* ```
|
|
7967
|
+
*/
|
|
7968
|
+
async *streamMcpServerEvent(serverId, eventName, body = {}, options = {}) {
|
|
7969
|
+
const response = await this.request(`/mcp/${encodeURIComponent(serverId)}/events/${encodeURIComponent(eventName)}/stream`, {
|
|
7970
|
+
method: "POST",
|
|
7971
|
+
body,
|
|
7972
|
+
stream: true,
|
|
7973
|
+
signal: options.signal,
|
|
7974
|
+
retries: 0
|
|
7975
|
+
});
|
|
7976
|
+
if (!response.body) throw new Error("Response body is null");
|
|
7977
|
+
const reader = response.body.pipeThrough(createSseJsonTransform()).getReader();
|
|
7978
|
+
const cancel = () => void reader.cancel().catch(() => {});
|
|
7979
|
+
options.signal?.addEventListener("abort", cancel, { once: true });
|
|
7980
|
+
try {
|
|
7981
|
+
while (true) {
|
|
7982
|
+
const { value, done } = await reader.read();
|
|
7983
|
+
if (done) return;
|
|
7984
|
+
yield value;
|
|
7985
|
+
}
|
|
7986
|
+
} finally {
|
|
7987
|
+
options.signal?.removeEventListener("abort", cancel);
|
|
7988
|
+
await reader.cancel().catch(() => {});
|
|
7989
|
+
}
|
|
7990
|
+
}
|
|
7991
|
+
/**
|
|
7992
|
+
* Emits a test occurrence of an emit-fed MCP server event type (experimental).
|
|
7993
|
+
* Only served under `mastra dev`; other servers respond 404. The occurrence's
|
|
7994
|
+
* `eventId` starts with `mastra-test-`.
|
|
7995
|
+
* @param serverId - The ID of the MCP server.
|
|
7996
|
+
* @param eventName - The event type name.
|
|
7997
|
+
* @param data - The event payload; validated against the event's payload schema.
|
|
7998
|
+
*/
|
|
7999
|
+
emitMcpServerEvent(serverId, eventName, data) {
|
|
8000
|
+
return this.request(`/mcp/${encodeURIComponent(serverId)}/events/${encodeURIComponent(eventName)}/emit`, {
|
|
8001
|
+
method: "POST",
|
|
8002
|
+
body: { data }
|
|
8003
|
+
});
|
|
8004
|
+
}
|
|
8005
|
+
/**
|
|
7822
8006
|
* Gets an A2A client for interacting with an agent via the A2A protocol
|
|
7823
8007
|
* @param agentId - ID of the agent to interact with
|
|
7824
8008
|
* @returns A2A client instance
|
|
@@ -7982,6 +8166,14 @@ var MastraClient = class extends BaseResource {
|
|
|
7982
8166
|
aggregateTraces(params) {
|
|
7983
8167
|
return this.observability.aggregateTraces(params);
|
|
7984
8168
|
}
|
|
8169
|
+
/**
|
|
8170
|
+
* Groups and measures individual completed spans selected by a time range and optional span-query predicate.
|
|
8171
|
+
* Token and cost measures count usage recorded on each span itself. Check `capabilities.spanAggregate` from
|
|
8172
|
+
* `getObservabilityCapabilities()` first; servers without it return 404 or 501.
|
|
8173
|
+
*/
|
|
8174
|
+
aggregateSpans(params) {
|
|
8175
|
+
return this.observability.aggregateSpans(params);
|
|
8176
|
+
}
|
|
7985
8177
|
/** Returns canonical and observed fields available to the advanced trace-query grammar. */
|
|
7986
8178
|
getTraceQueryFields(params, options) {
|
|
7987
8179
|
return this.observability.getTraceQueryFields(params, options);
|