@mastra/client-js 1.17.2-alpha.2 → 1.18.0-alpha.4
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/CHANGELOG.md +37 -0
- package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +27 -15
- 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/reference-client-js-agents.md +26 -1
- package/dist/index.cjs +150 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +146 -4
- package/dist/index.js.map +1 -1
- package/dist/resources/a2a.d.ts +11 -2
- package/dist/resources/a2a.d.ts.map +1 -1
- package/dist/resources/agent.d.ts +11 -0
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/route-types.generated.d.ts +206 -13
- package/dist/route-types.generated.d.ts.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/verify-agent-card-signature.d.ts +21 -0
- package/dist/utils/verify-agent-card-signature.d.ts.map +1 -0
- package/package.json +6 -4
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './client.js';
|
|
|
2
2
|
export * from './types.js';
|
|
3
3
|
export * from './tools.js';
|
|
4
4
|
export type { ChannelPlatformInfo, ChannelInstallationInfo, ChannelConnectOAuth, ChannelConnectDeepLink, ChannelConnectImmediate, ChannelConnectResult, } from './resources/channels.js';
|
|
5
|
+
export type { AgentCardSignatureKeyProviderInput, AgentCardVerificationKey, GetAgentCardOptions, VerifyAgentCardSignatureOptions, } from './resources/a2a.js';
|
|
5
6
|
export { RequestContext } from '@mastra/core/request-context';
|
|
6
7
|
export type { UIMessageWithMetadata } from '@mastra/core/agent';
|
|
7
8
|
export type { Body, Client, ClientMethod, ClientPath, ClientRequest, ClientResponse, ClientResponseKind, ClientRoute, PathParams, QueryParams, RouteKey, RouteRequest, RouteResponse, RouteResponseType, RouteTypes, } from './route-types.generated.js';
|
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,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,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,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,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,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,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
|
@@ -6,6 +6,8 @@ import { RequestContext } from '@mastra/core/request-context';
|
|
|
6
6
|
export { RequestContext } from '@mastra/core/request-context';
|
|
7
7
|
import { zodToJsonSchema as zodToJsonSchema$1 } from '@mastra/schema-compat/zod-to-json';
|
|
8
8
|
import { MastraA2AError } from '@mastra/core/a2a';
|
|
9
|
+
import canonicalize from 'canonicalize';
|
|
10
|
+
import { base64url, decodeProtectedHeader, compactVerify, importX509, importSPKI, importJWK } from 'jose';
|
|
9
11
|
|
|
10
12
|
// src/resources/agent.ts
|
|
11
13
|
function normalizeRoutePath(path) {
|
|
@@ -1639,6 +1641,43 @@ var Agent = class extends BaseResource {
|
|
|
1639
1641
|
};
|
|
1640
1642
|
return streamResponse;
|
|
1641
1643
|
}
|
|
1644
|
+
/**
|
|
1645
|
+
* Resumes a suspended agent stream until idle with custom resume data.
|
|
1646
|
+
* Used to continue execution after a suspension point (e.g., workflow suspend within an agent).
|
|
1647
|
+
*/
|
|
1648
|
+
async resumeStreamUntilIdle(resumeData, options) {
|
|
1649
|
+
const processedParams = {
|
|
1650
|
+
...options,
|
|
1651
|
+
resumeData,
|
|
1652
|
+
requestContext: parseClientRequestContext(options.requestContext),
|
|
1653
|
+
clientTools: processClientTools(options.clientTools),
|
|
1654
|
+
structuredOutput: options.structuredOutput ? {
|
|
1655
|
+
...options.structuredOutput,
|
|
1656
|
+
schema: standardSchemaToJSONSchema(toStandardSchema(options.structuredOutput.schema))
|
|
1657
|
+
} : void 0
|
|
1658
|
+
};
|
|
1659
|
+
let readableController;
|
|
1660
|
+
const readable = new ReadableStream({
|
|
1661
|
+
start(controller) {
|
|
1662
|
+
readableController = controller;
|
|
1663
|
+
}
|
|
1664
|
+
});
|
|
1665
|
+
const response = await this.processStreamResponse(processedParams, readableController, "resume-stream-until-idle");
|
|
1666
|
+
const streamResponse = new Response(readable, {
|
|
1667
|
+
status: response.status,
|
|
1668
|
+
statusText: response.statusText,
|
|
1669
|
+
headers: response.headers
|
|
1670
|
+
});
|
|
1671
|
+
streamResponse.processDataStream = async ({
|
|
1672
|
+
onChunk
|
|
1673
|
+
}) => {
|
|
1674
|
+
await processMastraStream({
|
|
1675
|
+
stream: streamResponse.body,
|
|
1676
|
+
onChunk
|
|
1677
|
+
});
|
|
1678
|
+
};
|
|
1679
|
+
return streamResponse;
|
|
1680
|
+
}
|
|
1642
1681
|
/**
|
|
1643
1682
|
* Approves a pending tool call and returns the complete response (non-streaming).
|
|
1644
1683
|
* Used when `requireToolApproval` is enabled with generate() to allow the agent to proceed.
|
|
@@ -2774,6 +2813,102 @@ async function* processA2AStream(stream) {
|
|
|
2774
2813
|
reader.releaseLock();
|
|
2775
2814
|
}
|
|
2776
2815
|
}
|
|
2816
|
+
var DEFAULT_AGENT_CARD_SIGNATURE_ALGORITHMS = [
|
|
2817
|
+
"ES256",
|
|
2818
|
+
"ES384",
|
|
2819
|
+
"ES512",
|
|
2820
|
+
"RS256",
|
|
2821
|
+
"RS384",
|
|
2822
|
+
"RS512",
|
|
2823
|
+
"PS256",
|
|
2824
|
+
"PS384",
|
|
2825
|
+
"PS512"
|
|
2826
|
+
];
|
|
2827
|
+
function stripAgentCardSignatures(agentCard) {
|
|
2828
|
+
const unsignedCard = structuredClone(agentCard);
|
|
2829
|
+
delete unsignedCard.signatures;
|
|
2830
|
+
return unsignedCard;
|
|
2831
|
+
}
|
|
2832
|
+
function isCryptoKey(value) {
|
|
2833
|
+
const cryptoKeyConstructor = globalThis.CryptoKey;
|
|
2834
|
+
return typeof cryptoKeyConstructor !== "undefined" && value instanceof cryptoKeyConstructor;
|
|
2835
|
+
}
|
|
2836
|
+
function isPem(value) {
|
|
2837
|
+
return value.includes("-----BEGIN ");
|
|
2838
|
+
}
|
|
2839
|
+
function isCertificate(value) {
|
|
2840
|
+
return value.includes("-----BEGIN CERTIFICATE-----");
|
|
2841
|
+
}
|
|
2842
|
+
async function importVerificationKey(key, algorithm) {
|
|
2843
|
+
if (isCryptoKey(key) || key instanceof Uint8Array) {
|
|
2844
|
+
return key;
|
|
2845
|
+
}
|
|
2846
|
+
if (key instanceof ArrayBuffer) {
|
|
2847
|
+
return new Uint8Array(key);
|
|
2848
|
+
}
|
|
2849
|
+
if (typeof key === "string") {
|
|
2850
|
+
if (algorithm.startsWith("HS")) {
|
|
2851
|
+
return new TextEncoder().encode(key);
|
|
2852
|
+
}
|
|
2853
|
+
if (!isPem(key)) {
|
|
2854
|
+
throw new Error("Expected a PEM-encoded public key or certificate string for Agent Card verification");
|
|
2855
|
+
}
|
|
2856
|
+
if (isCertificate(key)) {
|
|
2857
|
+
return importX509(key, algorithm);
|
|
2858
|
+
}
|
|
2859
|
+
return importSPKI(key, algorithm);
|
|
2860
|
+
}
|
|
2861
|
+
return importJWK(key, algorithm);
|
|
2862
|
+
}
|
|
2863
|
+
async function verifyAgentCardSignatureIfPresent(agentCard, options) {
|
|
2864
|
+
const signatures = agentCard.signatures ?? [];
|
|
2865
|
+
if (signatures.length === 0) {
|
|
2866
|
+
return agentCard;
|
|
2867
|
+
}
|
|
2868
|
+
const canonicalPayload = canonicalize(stripAgentCardSignatures(agentCard));
|
|
2869
|
+
if (!canonicalPayload) {
|
|
2870
|
+
throw new MastraClientError(200, "OK", "Failed to canonicalize A2A Agent Card for signature verification");
|
|
2871
|
+
}
|
|
2872
|
+
const allowedAlgorithms = options.algorithms ?? [...DEFAULT_AGENT_CARD_SIGNATURE_ALGORITHMS];
|
|
2873
|
+
const encodedPayload = base64url.encode(canonicalPayload);
|
|
2874
|
+
const verificationErrors = [];
|
|
2875
|
+
for (const [index, signature] of signatures.entries()) {
|
|
2876
|
+
try {
|
|
2877
|
+
const compactJws = `${signature.protected}.${encodedPayload}.${signature.signature}`;
|
|
2878
|
+
const protectedHeader = decodeProtectedHeader(compactJws);
|
|
2879
|
+
if (typeof protectedHeader.alg !== "string") {
|
|
2880
|
+
throw new Error('Agent Card signature is missing a protected "alg" header');
|
|
2881
|
+
}
|
|
2882
|
+
if (!allowedAlgorithms.includes(protectedHeader.alg)) {
|
|
2883
|
+
throw new Error(`Agent Card signature algorithm "${protectedHeader.alg}" is not allowed`);
|
|
2884
|
+
}
|
|
2885
|
+
const verificationKey = await options.keyProvider({
|
|
2886
|
+
agentCard,
|
|
2887
|
+
signature,
|
|
2888
|
+
protectedHeader,
|
|
2889
|
+
alg: protectedHeader.alg,
|
|
2890
|
+
kid: typeof protectedHeader.kid === "string" ? protectedHeader.kid : void 0,
|
|
2891
|
+
jku: typeof protectedHeader.jku === "string" ? protectedHeader.jku : void 0,
|
|
2892
|
+
index
|
|
2893
|
+
});
|
|
2894
|
+
if (!verificationKey) {
|
|
2895
|
+
throw new Error("No verification key was provided for Agent Card signature verification");
|
|
2896
|
+
}
|
|
2897
|
+
const importedKey = await importVerificationKey(verificationKey, protectedHeader.alg);
|
|
2898
|
+
await compactVerify(compactJws, importedKey, {
|
|
2899
|
+
algorithms: allowedAlgorithms
|
|
2900
|
+
});
|
|
2901
|
+
return agentCard;
|
|
2902
|
+
} catch (error) {
|
|
2903
|
+
verificationErrors.push(error instanceof Error ? error.message : "Unknown verification failure");
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
throw new MastraClientError(
|
|
2907
|
+
200,
|
|
2908
|
+
"OK",
|
|
2909
|
+
`A2A Agent Card signature verification failed: ${verificationErrors.join("; ")}`
|
|
2910
|
+
);
|
|
2911
|
+
}
|
|
2777
2912
|
|
|
2778
2913
|
// src/resources/a2a.ts
|
|
2779
2914
|
function createA2AJsonRpcError(response) {
|
|
@@ -2816,16 +2951,21 @@ var A2A = class extends BaseResource {
|
|
|
2816
2951
|
agentId;
|
|
2817
2952
|
/**
|
|
2818
2953
|
* Get the agent card with metadata about the agent.
|
|
2954
|
+
* @param options - Optional Agent Card verification settings
|
|
2819
2955
|
* @returns Promise containing the agent card information
|
|
2820
2956
|
*/
|
|
2821
|
-
async getAgentCard() {
|
|
2822
|
-
|
|
2957
|
+
async getAgentCard(options) {
|
|
2958
|
+
const agentCard = await this.request(`/.well-known/${this.agentId}/agent-card.json`);
|
|
2959
|
+
if (!options?.verifySignature) {
|
|
2960
|
+
return agentCard;
|
|
2961
|
+
}
|
|
2962
|
+
return verifyAgentCardSignatureIfPresent(agentCard, options.verifySignature);
|
|
2823
2963
|
}
|
|
2824
2964
|
/**
|
|
2825
2965
|
* @deprecated Use getAgentCard() instead.
|
|
2826
2966
|
*/
|
|
2827
|
-
async getCard() {
|
|
2828
|
-
return this.getAgentCard();
|
|
2967
|
+
async getCard(options) {
|
|
2968
|
+
return this.getAgentCard(options);
|
|
2829
2969
|
}
|
|
2830
2970
|
/**
|
|
2831
2971
|
* Get the authenticated extended agent card.
|
|
@@ -6213,6 +6353,8 @@ var MastraClient = class extends BaseResource {
|
|
|
6213
6353
|
if (params.runId) searchParams.set("runId", params.runId);
|
|
6214
6354
|
if (params.threadId) searchParams.set("threadId", params.threadId);
|
|
6215
6355
|
if (params.resourceId) searchParams.set("resourceId", params.resourceId);
|
|
6356
|
+
if (params.toolName) searchParams.set("toolName", params.toolName);
|
|
6357
|
+
if (params.toolCallId) searchParams.set("toolCallId", params.toolCallId);
|
|
6216
6358
|
if (params.fromDate) searchParams.set("fromDate", params.fromDate.toISOString());
|
|
6217
6359
|
if (params.toDate) searchParams.set("toDate", params.toDate.toISOString());
|
|
6218
6360
|
if (params.dateFilterBy) searchParams.set("dateFilterBy", params.dateFilterBy);
|