@mastra/teams 0.1.2-alpha.0 → 0.1.2-alpha.1
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/index.cjs +24 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -113101,6 +113101,22 @@ function authJson(token) {
|
|
|
113101
113101
|
};
|
|
113102
113102
|
}
|
|
113103
113103
|
/**
|
|
113104
|
+
* Best-effort extraction of the `tid` (tenant id) claim from a Microsoft
|
|
113105
|
+
* access token. Used to default `appTenantId` for single-tenant bot
|
|
113106
|
+
* provisioning when the caller did not supply one. Returns `undefined` for
|
|
113107
|
+
* opaque or malformed tokens — never throws.
|
|
113108
|
+
*/
|
|
113109
|
+
function decodeTenantId(accessToken) {
|
|
113110
|
+
const parts = accessToken.split(".");
|
|
113111
|
+
if (parts.length < 2) return void 0;
|
|
113112
|
+
try {
|
|
113113
|
+
const payload = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
|
|
113114
|
+
return typeof payload.tid === "string" && payload.tid.length > 0 ? payload.tid : void 0;
|
|
113115
|
+
} catch {
|
|
113116
|
+
return;
|
|
113117
|
+
}
|
|
113118
|
+
}
|
|
113119
|
+
/**
|
|
113104
113120
|
* Create an Entra application for a per-agent bot.
|
|
113105
113121
|
* @see https://learn.microsoft.com/graph/api/application-post-applications
|
|
113106
113122
|
*/
|
|
@@ -113604,12 +113620,15 @@ var TeamsProvider = class {
|
|
|
113604
113620
|
const baseUrl = this.#getBaseUrl();
|
|
113605
113621
|
if (!baseUrl) throw new Error("TeamsProvider needs a baseUrl to register a bot messaging endpoint. Set `baseUrl` or configure the Mastra server.");
|
|
113606
113622
|
const botName = options.name ?? agentId;
|
|
113607
|
-
const appType = this.#config.appType ?? "
|
|
113608
|
-
|
|
113609
|
-
if (appType === "SingleTenant" && !appTenantId) throw new Error("TeamsProvider is configured for SingleTenant bots but no appTenantId is available. Set `appTenantId` on the provider or pass it to connect().");
|
|
113623
|
+
const appType = this.#config.appType ?? "SingleTenant";
|
|
113624
|
+
let appTenantId = options.appTenantId ?? this.#config.appTenantId;
|
|
113610
113625
|
const webhookId = existing?.webhookId ?? (0, crypto$1.randomUUID)();
|
|
113611
113626
|
const messagingEndpoint = `${baseUrl}/${PLATFORM}/events/${webhookId}`;
|
|
113612
113627
|
const graphToken = await tokenResolver(TEAMS_GRAPH_SCOPE, appTenantId);
|
|
113628
|
+
if (appType === "SingleTenant" && !appTenantId) {
|
|
113629
|
+
appTenantId = decodeTenantId(graphToken);
|
|
113630
|
+
if (!appTenantId) throw new Error("TeamsProvider provisions SingleTenant bots but no appTenantId is available and the Graph access token carries no `tid` claim. Set `appTenantId` on the provider or pass it to connect().");
|
|
113631
|
+
}
|
|
113613
113632
|
const application = await createApplication(graphToken, {
|
|
113614
113633
|
displayName: botName,
|
|
113615
113634
|
signInAudience: appType === "SingleTenant" ? "AzureADMyOrg" : "AzureADMultipleOrgs"
|
|
@@ -113627,7 +113646,8 @@ var TeamsProvider = class {
|
|
|
113627
113646
|
description: `Mastra agent "${agentId}"`,
|
|
113628
113647
|
iconUrl: this.#config.botIconUrl ?? "",
|
|
113629
113648
|
messagingEndpoint,
|
|
113630
|
-
callingEndpoint: ""
|
|
113649
|
+
callingEndpoint: "",
|
|
113650
|
+
isSingleTenant: appType === "SingleTenant"
|
|
113631
113651
|
}, this.#config.devPortalBaseUrl);
|
|
113632
113652
|
botRegistered = true;
|
|
113633
113653
|
installation = {
|