@mastra/connect 0.7.0-alpha.0 → 0.7.0-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.
Files changed (42) hide show
  1. package/dist/index.cjs +67 -185
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +67 -185
  4. package/dist/index.js.map +1 -1
  5. package/dist/providers/channels.d.ts.map +1 -1
  6. package/dist/providers/discord/index.d.ts.map +1 -1
  7. package/dist/providers/discord/tools/_bot-token.d.ts +11 -0
  8. package/dist/providers/discord/tools/_bot-token.d.ts.map +1 -0
  9. package/dist/providers/discord/tools/add-guild-member-role.d.ts.map +1 -1
  10. package/dist/providers/discord/tools/create-channel.d.ts.map +1 -1
  11. package/dist/providers/discord/tools/create-message.d.ts.map +1 -1
  12. package/dist/providers/discord/tools/create-reaction.d.ts.map +1 -1
  13. package/dist/providers/discord/tools/create-role.d.ts.map +1 -1
  14. package/dist/providers/discord/tools/create-thread-from-message.d.ts.map +1 -1
  15. package/dist/providers/discord/tools/create-webhook.d.ts.map +1 -1
  16. package/dist/providers/discord/tools/delete-channel.d.ts.map +1 -1
  17. package/dist/providers/discord/tools/delete-guild-member.d.ts.map +1 -1
  18. package/dist/providers/discord/tools/delete-guild.d.ts.map +1 -1
  19. package/dist/providers/discord/tools/delete-message.d.ts.map +1 -1
  20. package/dist/providers/discord/tools/delete-reaction.d.ts.map +1 -1
  21. package/dist/providers/discord/tools/delete-role.d.ts.map +1 -1
  22. package/dist/providers/discord/tools/delete-webhook.d.ts.map +1 -1
  23. package/dist/providers/discord/tools/get-channel.d.ts.map +1 -1
  24. package/dist/providers/discord/tools/get-guild-member.d.ts.map +1 -1
  25. package/dist/providers/discord/tools/get-guild.d.ts.map +1 -1
  26. package/dist/providers/discord/tools/get-message.d.ts.map +1 -1
  27. package/dist/providers/discord/tools/get-role.d.ts.map +1 -1
  28. package/dist/providers/discord/tools/get-webhook.d.ts.map +1 -1
  29. package/dist/providers/discord/tools/list-channels.d.ts.map +1 -1
  30. package/dist/providers/discord/tools/list-guild-members.d.ts.map +1 -1
  31. package/dist/providers/discord/tools/list-guilds.d.ts.map +1 -1
  32. package/dist/providers/discord/tools/list-messages.d.ts.map +1 -1
  33. package/dist/providers/discord/tools/list-roles.d.ts.map +1 -1
  34. package/dist/providers/discord/tools/list-webhooks.d.ts.map +1 -1
  35. package/dist/providers/discord/tools/remove-guild-member-role.d.ts.map +1 -1
  36. package/dist/providers/discord/tools/update-channel.d.ts.map +1 -1
  37. package/dist/providers/discord/tools/update-guild-member.d.ts.map +1 -1
  38. package/dist/providers/discord/tools/update-guild.d.ts.map +1 -1
  39. package/dist/providers/discord/tools/update-message.d.ts.map +1 -1
  40. package/dist/providers/discord/tools/update-role.d.ts.map +1 -1
  41. package/dist/providers/discord/tools/update-webhook.d.ts.map +1 -1
  42. package/package.json +5 -5
package/dist/index.cjs CHANGED
@@ -783,9 +783,11 @@ const CHANNELS$1 = [
783
783
  return {
784
784
  provider,
785
785
  async sync() {
786
+ const credential = await runtime.getCredential();
787
+ if (credential.type !== "api_key") throw new MastraConnectError("unsupported_credential_type", `Discord connection ${runtime.getConnectionId()} returned a '${credential.type}' credential, but the Discord channel requires the bot token as an API-key credential (the 'discord' integration). OAuth Discord connections yield user Bearer tokens, which Discord rejects for bot auth.`);
788
+ const botToken = credential.apiKey;
789
+ if (typeof botToken !== "string" || botToken.length === 0) throw new MastraConnectError("no_active_connection", `Discord connection ${runtime.getConnectionId()} has no bot token on its credential.`);
786
790
  const metadata = (await runtime.getConnectionContext())?.metadata ?? {};
787
- const botToken = typeof metadata.botToken === "string" && metadata.botToken || typeof metadata.bot_token === "string" && metadata.bot_token || void 0;
788
- if (!botToken) throw new MastraConnectError("no_active_connection", `Discord connection ${runtime.getConnectionId()} has no botToken in its metadata. Store the bot token on the connection (Nango setMetadata) to activate the Discord channel.`);
789
791
  const applicationId = optionsAppId ?? (typeof metadata.applicationId === "string" ? metadata.applicationId : void 0) ?? (typeof metadata.application_id === "string" ? metadata.application_id : void 0);
790
792
  const publicKey = optionsPublicKey ?? (typeof metadata.publicKey === "string" ? metadata.publicKey : void 0) ?? (typeof metadata.public_key === "string" ? metadata.public_key : void 0);
791
793
  const credentials = { botToken };
@@ -3703,8 +3705,25 @@ const clerkProvider = {
3703
3705
  createTools: createClerkTools
3704
3706
  };
3705
3707
  //#endregion
3708
+ //#region src/providers/discord/tools/_bot-token.ts
3709
+ /**
3710
+ * Resolves the Discord bot token from the connection's credentials. Nango's
3711
+ * `discord` provider is API_KEY-typed and stores the bot token as its
3712
+ * secret, so the platform serves it back as `credentials.apiKey` (the wire
3713
+ * shape templates are written against). Throws a ToolActionError with a
3714
+ * consistent `missing_credentials` payload so exec bodies don't need to repeat
3715
+ * the guard.
3716
+ */
3717
+ async function resolveDiscordBotToken(platformProxy) {
3718
+ const credentials = (await platformProxy.getConnectionWithCredentials()).credentials;
3719
+ if (credentials && typeof credentials.apiKey === "string" && credentials.apiKey) return credentials.apiKey;
3720
+ throw new platformProxy.ActionError({
3721
+ type: "missing_credentials",
3722
+ message: "Discord bot token is missing from the connection credentials. Reconnect the discord integration with a valid bot token."
3723
+ });
3724
+ }
3725
+ //#endregion
3706
3726
  //#region src/providers/discord/tools/add-guild-member-role.ts
3707
- const MetadataSchema$7 = zod.z.object({ botToken: zod.z.string() });
3708
3727
  const addGuildMemberRoleInputSchema = zod.z.object({
3709
3728
  guildId: zod.z.string().describe("Guild ID. Example: \"123456789012345678\""),
3710
3729
  userId: zod.z.string().describe("User ID. Example: \"987654321098765432\""),
@@ -3719,12 +3738,7 @@ function addGuildMemberRoleTool(proxy) {
3719
3738
  outputSchema: addGuildMemberRoleOutputSchema,
3720
3739
  execute: async (input, { requestContext }) => {
3721
3740
  const platformProxy = proxy.withRequestContext(requestContext);
3722
- const metadataResult = MetadataSchema$7.safeParse(await platformProxy.getMetadata());
3723
- if (!metadataResult.success) throw new platformProxy.ActionError({
3724
- type: "invalid_metadata",
3725
- message: "botToken is required in metadata."
3726
- });
3727
- const { botToken } = metadataResult.data;
3741
+ const botToken = await resolveDiscordBotToken(platformProxy);
3728
3742
  const response = await platformProxy.put({
3729
3743
  endpoint: `/api/v10/guilds/${input.guildId}/members/${input.userId}/roles/${input.roleId}`,
3730
3744
  headers: { Authorization: `Bot ${botToken}` },
@@ -3740,7 +3754,6 @@ function addGuildMemberRoleTool(proxy) {
3740
3754
  }
3741
3755
  //#endregion
3742
3756
  //#region src/providers/discord/tools/create-channel.ts
3743
- zod.z.object({ botToken: zod.z.string().describe("Discord bot token from the Discord Developer Portal") });
3744
3757
  const createChannelInputSchema$2 = zod.z.object({
3745
3758
  guildId: zod.z.string().describe("The ID of the guild to create the channel in. Example: \"41771983423143937\""),
3746
3759
  name: zod.z.string().min(1).max(100).describe("Channel name (1-100 characters). Example: \"general\""),
@@ -3810,11 +3823,7 @@ function createChannelTool$2(proxy) {
3810
3823
  outputSchema: createChannelOutputSchema$2,
3811
3824
  execute: async (input, { requestContext }) => {
3812
3825
  const platformProxy = proxy.withRequestContext(requestContext);
3813
- const metadata = await platformProxy.getMetadata();
3814
- if (!metadata.botToken) throw new platformProxy.ActionError({
3815
- type: "invalid_metadata",
3816
- message: "botToken is required in metadata. Please provide a Discord bot token."
3817
- });
3826
+ const botToken = await resolveDiscordBotToken(platformProxy);
3818
3827
  if (!input.guildId) throw new platformProxy.ActionError({
3819
3828
  type: "invalid_input",
3820
3829
  message: "guildId is required to create a channel."
@@ -3840,7 +3849,7 @@ function createChannelTool$2(proxy) {
3840
3849
  const response = await platformProxy.post({
3841
3850
  endpoint: `/api/v10/guilds/${input.guildId}/channels`,
3842
3851
  data: requestBody,
3843
- headers: { Authorization: `Bot ${metadata.botToken}` },
3852
+ headers: { Authorization: `Bot ${botToken}` },
3844
3853
  retries: 3
3845
3854
  });
3846
3855
  const providerChannel = ProviderChannelSchema$10.parse(response.data);
@@ -3934,11 +3943,7 @@ function createMessageTool(proxy) {
3934
3943
  outputSchema: createMessageOutputSchema,
3935
3944
  execute: async (input, { requestContext }) => {
3936
3945
  const platformProxy = proxy.withRequestContext(requestContext);
3937
- const botToken = (await platformProxy.getMetadata())?.botToken;
3938
- if (!botToken) throw new platformProxy.ActionError({
3939
- type: "invalid_metadata",
3940
- message: "botToken is required in connection metadata."
3941
- });
3946
+ const botToken = await resolveDiscordBotToken(platformProxy);
3942
3947
  const requestBody = {};
3943
3948
  if (input.content !== void 0) requestBody["content"] = input.content;
3944
3949
  if (input.embeds !== void 0) requestBody["embeds"] = input.embeds;
@@ -3990,11 +3995,7 @@ function createReactionTool(proxy) {
3990
3995
  outputSchema: createReactionOutputSchema,
3991
3996
  execute: async (input, { requestContext }) => {
3992
3997
  const platformProxy = proxy.withRequestContext(requestContext);
3993
- const botToken = (await platformProxy.getMetadata())?.botToken;
3994
- if (!botToken) throw new platformProxy.ActionError({
3995
- type: "invalid_metadata",
3996
- message: "botToken is required in metadata. Please configure the Discord bot token."
3997
- });
3998
+ const botToken = await resolveDiscordBotToken(platformProxy);
3998
3999
  await platformProxy.put({
3999
4000
  endpoint: `/api/v10/channels/${input.channel_id}/messages/${input.message_id}/reactions/${encodeURIComponent(input.emoji)}/@me`,
4000
4001
  headers: { Authorization: `Bot ${botToken}` },
@@ -4069,7 +4070,6 @@ const createRoleOutputSchema = zod.z.object({
4069
4070
  tags: RoleTagsSchema$3.optional(),
4070
4071
  flags: zod.z.number().int()
4071
4072
  });
4072
- zod.z.object({ botToken: zod.z.string() });
4073
4073
  function createRoleTool(proxy) {
4074
4074
  return (0, _mastra_core_tools.createTool)({
4075
4075
  id: "discord_create_role",
@@ -4078,11 +4078,7 @@ function createRoleTool(proxy) {
4078
4078
  outputSchema: createRoleOutputSchema,
4079
4079
  execute: async (input, { requestContext }) => {
4080
4080
  const platformProxy = proxy.withRequestContext(requestContext);
4081
- const botToken = (await platformProxy.getMetadata())?.botToken;
4082
- if (!botToken) throw new platformProxy.ActionError({
4083
- type: "invalid_metadata",
4084
- message: "botToken is required in metadata."
4085
- });
4081
+ const botToken = await resolveDiscordBotToken(platformProxy);
4086
4082
  const response = await platformProxy.post({
4087
4083
  endpoint: `/api/v10/guilds/${input.guildId}/roles`,
4088
4084
  headers: { Authorization: `Bot ${botToken}` },
@@ -4183,7 +4179,7 @@ function createThreadFromMessageTool(proxy) {
4183
4179
  outputSchema: createThreadFromMessageOutputSchema,
4184
4180
  execute: async (input, { requestContext }) => {
4185
4181
  const platformProxy = proxy.withRequestContext(requestContext);
4186
- const botToken = (await platformProxy.getMetadata())?.botToken || "";
4182
+ const botToken = await resolveDiscordBotToken(platformProxy);
4187
4183
  const requestData = { name: input.name };
4188
4184
  if (input.auto_archive_duration !== void 0) requestData["auto_archive_duration"] = input.auto_archive_duration;
4189
4185
  if (input.rate_limit_per_user !== void 0) requestData["rate_limit_per_user"] = input.rate_limit_per_user;
@@ -4257,10 +4253,6 @@ const createWebhookOutputSchema$1 = zod.z.object({
4257
4253
  token: zod.z.string().optional().describe("Webhook token (only for Incoming webhooks)"),
4258
4254
  applicationId: zod.z.string().optional()
4259
4255
  });
4260
- zod.z.object({
4261
- botToken: zod.z.string().describe("Discord bot token for authentication"),
4262
- channelId: zod.z.string().optional().describe("Optional default channel ID for creating webhooks")
4263
- });
4264
4256
  function createWebhookTool$1(proxy) {
4265
4257
  return (0, _mastra_core_tools.createTool)({
4266
4258
  id: "discord_create_webhook",
@@ -4269,13 +4261,9 @@ function createWebhookTool$1(proxy) {
4269
4261
  outputSchema: createWebhookOutputSchema$1,
4270
4262
  execute: async (input, { requestContext }) => {
4271
4263
  const platformProxy = proxy.withRequestContext(requestContext);
4264
+ const botToken = await resolveDiscordBotToken(platformProxy);
4272
4265
  const metadata = await platformProxy.getMetadata();
4273
- const botToken = metadata?.botToken;
4274
4266
  const channelId = input.channelId ?? metadata?.channelId;
4275
- if (!botToken) throw new platformProxy.ActionError({
4276
- type: "missing_metadata",
4277
- message: "botToken is required in connection metadata."
4278
- });
4279
4267
  if (!channelId) throw new platformProxy.ActionError({
4280
4268
  type: "missing_channel",
4281
4269
  message: "channelId is required in input or metadata."
@@ -4360,11 +4348,7 @@ function deleteChannelTool$1(proxy) {
4360
4348
  outputSchema: deleteChannelOutputSchema$1,
4361
4349
  execute: async (input, { requestContext }) => {
4362
4350
  const platformProxy = proxy.withRequestContext(requestContext);
4363
- const botToken = (await platformProxy.getMetadata())?.botToken;
4364
- if (!botToken) throw new platformProxy.ActionError({
4365
- type: "invalid_metadata",
4366
- message: "botToken is required in metadata. Please provide a Discord bot token."
4367
- });
4351
+ const botToken = await resolveDiscordBotToken(platformProxy);
4368
4352
  const response = await platformProxy.delete({
4369
4353
  endpoint: `/api/v10/channels/${input.channelId}`,
4370
4354
  headers: { Authorization: `Bot ${botToken}` },
@@ -4388,7 +4372,6 @@ function deleteChannelTool$1(proxy) {
4388
4372
  }
4389
4373
  //#endregion
4390
4374
  //#region src/providers/discord/tools/delete-guild-member.ts
4391
- zod.z.object({ botToken: zod.z.string().describe("Discord bot token for authentication") });
4392
4375
  const deleteGuildMemberInputSchema = zod.z.object({
4393
4376
  guild_id: zod.z.string().describe("Guild ID. Example: \"123456789012345678\""),
4394
4377
  user_id: zod.z.string().describe("User ID of the member to delete. Example: \"987654321098765432\"")
@@ -4405,16 +4388,12 @@ function deleteGuildMemberTool(proxy) {
4405
4388
  outputSchema: deleteGuildMemberOutputSchema,
4406
4389
  execute: async (input, { requestContext }) => {
4407
4390
  const platformProxy = proxy.withRequestContext(requestContext);
4408
- const metadata = await platformProxy.getMetadata();
4409
- if (!metadata?.botToken) throw new platformProxy.ActionError({
4410
- type: "invalid_metadata",
4411
- message: "botToken is required in connection metadata"
4412
- });
4391
+ const botToken = await resolveDiscordBotToken(platformProxy);
4413
4392
  let response;
4414
4393
  try {
4415
4394
  response = await platformProxy.delete({
4416
4395
  endpoint: `/api/v10/guilds/${input.guild_id}/members/${input.user_id}`,
4417
- headers: { Authorization: `Bot ${metadata.botToken}` },
4396
+ headers: { Authorization: `Bot ${botToken}` },
4418
4397
  retries: 1
4419
4398
  });
4420
4399
  } catch (err) {
@@ -4437,7 +4416,6 @@ function deleteGuildMemberTool(proxy) {
4437
4416
  }
4438
4417
  //#endregion
4439
4418
  //#region src/providers/discord/tools/delete-guild.ts
4440
- const MetadataSchema$6 = zod.z.object({ botToken: zod.z.string().describe("Discord bot token from the Discord Developer Portal") });
4441
4419
  const deleteGuildInputSchema = zod.z.object({ guild_id: zod.z.string().describe("The ID of the guild for the bot to leave.") });
4442
4420
  const deleteGuildOutputSchema = zod.z.object({
4443
4421
  success: zod.z.boolean().describe("Whether the bot successfully left the guild"),
@@ -4451,13 +4429,7 @@ function deleteGuildTool(proxy) {
4451
4429
  outputSchema: deleteGuildOutputSchema,
4452
4430
  execute: async (input, { requestContext }) => {
4453
4431
  const platformProxy = proxy.withRequestContext(requestContext);
4454
- const metadata = await platformProxy.getMetadata();
4455
- const parsedMetadata = MetadataSchema$6.safeParse(metadata);
4456
- if (!parsedMetadata.success) throw new platformProxy.ActionError({
4457
- type: "invalid_metadata",
4458
- message: "botToken is required in metadata. Please configure the bot token in the connection metadata."
4459
- });
4460
- const botToken = parsedMetadata.data.botToken;
4432
+ const botToken = await resolveDiscordBotToken(platformProxy);
4461
4433
  const response = await platformProxy.delete({
4462
4434
  endpoint: `/api/v10/users/@me/guilds/${input.guild_id}`,
4463
4435
  headers: { Authorization: `Bot ${botToken}` },
@@ -4477,7 +4449,6 @@ function deleteGuildTool(proxy) {
4477
4449
  }
4478
4450
  //#endregion
4479
4451
  //#region src/providers/discord/tools/delete-message.ts
4480
- const MetadataSchema$5 = zod.z.object({ botToken: zod.z.string().describe("Discord bot token") });
4481
4452
  const deleteMessageInputSchema$2 = zod.z.object({
4482
4453
  channelId: zod.z.string().describe("Channel ID where the message exists. Example: \"1234567890123456789\""),
4483
4454
  messageId: zod.z.string().describe("Message ID to delete. Example: \"9876543210987654321\"")
@@ -4495,12 +4466,7 @@ function deleteMessageTool$2(proxy) {
4495
4466
  outputSchema: deleteMessageOutputSchema$2,
4496
4467
  execute: async (input, { requestContext }) => {
4497
4468
  const platformProxy = proxy.withRequestContext(requestContext);
4498
- const metadata = MetadataSchema$5.safeParse(await platformProxy.getMetadata());
4499
- if (!metadata.success) throw new platformProxy.ActionError({
4500
- type: "invalid_metadata",
4501
- message: "Invalid metadata: botToken is required."
4502
- });
4503
- const botToken = metadata.data.botToken;
4469
+ const botToken = await resolveDiscordBotToken(platformProxy);
4504
4470
  await platformProxy.delete({
4505
4471
  endpoint: `/api/v10/channels/${input.channelId}/messages/${input.messageId}`,
4506
4472
  headers: { Authorization: `Bot ${botToken}` },
@@ -4530,11 +4496,7 @@ function deleteReactionTool(proxy) {
4530
4496
  outputSchema: deleteReactionOutputSchema,
4531
4497
  execute: async (input, { requestContext }) => {
4532
4498
  const platformProxy = proxy.withRequestContext(requestContext);
4533
- const botToken = (await platformProxy.getMetadata())?.botToken;
4534
- if (!botToken) throw new platformProxy.ActionError({
4535
- type: "invalid_metadata",
4536
- message: "botToken is required in metadata. Please configure the bot token from Discord Developer Portal."
4537
- });
4499
+ const botToken = await resolveDiscordBotToken(platformProxy);
4538
4500
  await platformProxy.delete({
4539
4501
  endpoint: `/api/v10/channels/${input.channel_id}/messages/${input.message_id}/reactions/${encodeURIComponent(input.emoji)}/@me`,
4540
4502
  headers: { Authorization: `Bot ${botToken}` },
@@ -4576,7 +4538,7 @@ function deleteRoleTool(proxy) {
4576
4538
  outputSchema: deleteRoleOutputSchema,
4577
4539
  execute: async (input, { requestContext }) => {
4578
4540
  const platformProxy = proxy.withRequestContext(requestContext);
4579
- const botToken = (await platformProxy.getMetadata())?.botToken;
4541
+ const botToken = await resolveDiscordBotToken(platformProxy);
4580
4542
  if (!botToken) throw new platformProxy.ActionError({
4581
4543
  type: "invalid_metadata",
4582
4544
  message: "botToken is required in metadata. Please provide the Discord bot token from your Discord application settings."
@@ -4610,11 +4572,7 @@ function deleteWebhookTool$1(proxy) {
4610
4572
  outputSchema: deleteWebhookOutputSchema$1,
4611
4573
  execute: async (input, { requestContext }) => {
4612
4574
  const platformProxy = proxy.withRequestContext(requestContext);
4613
- const botToken = (await platformProxy.getMetadata())?.botToken;
4614
- if (!botToken) throw new platformProxy.ActionError({
4615
- type: "invalid_metadata",
4616
- message: "botToken is required in metadata. Please ensure the Discord connection has a botToken configured."
4617
- });
4575
+ const botToken = await resolveDiscordBotToken(platformProxy);
4618
4576
  const response = await platformProxy.delete({
4619
4577
  endpoint: `/api/v10/webhooks/${input.webhookId}`,
4620
4578
  headers: { Authorization: `Bot ${botToken}` },
@@ -4718,14 +4676,10 @@ function getChannelTool$2(proxy) {
4718
4676
  outputSchema: getChannelOutputSchema$2,
4719
4677
  execute: async (input, { requestContext }) => {
4720
4678
  const platformProxy = proxy.withRequestContext(requestContext);
4721
- const metadata = await platformProxy.getMetadata();
4722
- if (!metadata?.botToken) throw new platformProxy.ActionError({
4723
- type: "invalid_metadata",
4724
- message: "botToken is required in metadata. Please set up the connection with botToken in metadata."
4725
- });
4679
+ const botToken = await resolveDiscordBotToken(platformProxy);
4726
4680
  const response = await platformProxy.get({
4727
4681
  endpoint: `/api/v10/channels/${input.channelId}`,
4728
- headers: { Authorization: `Bot ${metadata.botToken}` },
4682
+ headers: { Authorization: `Bot ${botToken}` },
4729
4683
  retries: 3
4730
4684
  });
4731
4685
  if (!response.data) throw new platformProxy.ActionError({
@@ -4824,14 +4778,10 @@ function getGuildMemberTool(proxy) {
4824
4778
  outputSchema: getGuildMemberOutputSchema,
4825
4779
  execute: async (input, { requestContext }) => {
4826
4780
  const platformProxy = proxy.withRequestContext(requestContext);
4827
- const metadata = await platformProxy.getMetadata();
4828
- if (!metadata?.botToken) throw new platformProxy.ActionError({
4829
- type: "invalid_metadata",
4830
- message: "botToken is required in metadata."
4831
- });
4781
+ const botToken = await resolveDiscordBotToken(platformProxy);
4832
4782
  const response = await platformProxy.get({
4833
4783
  endpoint: `/api/v10/guilds/${input.guild_id}/members/${input.user_id}`,
4834
- headers: { Authorization: `Bot ${metadata.botToken}` },
4784
+ headers: { Authorization: `Bot ${botToken}` },
4835
4785
  retries: 3
4836
4786
  });
4837
4787
  if (response.status === 404) throw new platformProxy.ActionError({
@@ -4874,11 +4824,7 @@ function getGuildTool(proxy) {
4874
4824
  outputSchema: getGuildOutputSchema,
4875
4825
  execute: async (input, { requestContext }) => {
4876
4826
  const platformProxy = proxy.withRequestContext(requestContext);
4877
- const botToken = (await platformProxy.getMetadata())?.botToken;
4878
- if (!botToken) throw new platformProxy.ActionError({
4879
- type: "invalid_metadata",
4880
- message: "botToken is required in metadata. Please configure the bot token from Discord Developer Portal."
4881
- });
4827
+ const botToken = await resolveDiscordBotToken(platformProxy);
4882
4828
  const response = await platformProxy.get({
4883
4829
  endpoint: `/api/v10/guilds/${input.guildId}`,
4884
4830
  headers: { Authorization: `Bot ${botToken}` },
@@ -4989,14 +4935,10 @@ function getMessageTool$1(proxy) {
4989
4935
  outputSchema: getMessageOutputSchema$1,
4990
4936
  execute: async (input, { requestContext }) => {
4991
4937
  const platformProxy = proxy.withRequestContext(requestContext);
4992
- const metadata = await platformProxy.getMetadata();
4993
- if (!metadata?.botToken) throw new platformProxy.ActionError({
4994
- type: "invalid_metadata",
4995
- message: "botToken is required in metadata."
4996
- });
4938
+ const botToken = await resolveDiscordBotToken(platformProxy);
4997
4939
  const response = await platformProxy.get({
4998
4940
  endpoint: `/api/v10/channels/${input.channelId}/messages/${input.messageId}`,
4999
- headers: { Authorization: `Bot ${metadata.botToken}` },
4941
+ headers: { Authorization: `Bot ${botToken}` },
5000
4942
  retries: 3
5001
4943
  });
5002
4944
  if (!response.data) throw new platformProxy.ActionError({
@@ -5107,14 +5049,10 @@ function getRoleTool(proxy) {
5107
5049
  outputSchema: getRoleOutputSchema,
5108
5050
  execute: async (input, { requestContext }) => {
5109
5051
  const platformProxy = proxy.withRequestContext(requestContext);
5110
- const metadata = await platformProxy.getMetadata();
5111
- if (!metadata?.botToken) throw new platformProxy.ActionError({
5112
- type: "invalid_metadata",
5113
- message: "botToken is required in metadata."
5114
- });
5052
+ const botToken = await resolveDiscordBotToken(platformProxy);
5115
5053
  const response = await platformProxy.get({
5116
5054
  endpoint: `/api/v10/guilds/${input.guild_id}/roles/${input.role_id}`,
5117
- headers: { Authorization: `Bot ${metadata.botToken}` },
5055
+ headers: { Authorization: `Bot ${botToken}` },
5118
5056
  retries: 3
5119
5057
  });
5120
5058
  if (!response.data) throw new platformProxy.ActionError({
@@ -5189,14 +5127,10 @@ function getWebhookTool$1(proxy) {
5189
5127
  outputSchema: getWebhookOutputSchema$1,
5190
5128
  execute: async (input, { requestContext }) => {
5191
5129
  const platformProxy = proxy.withRequestContext(requestContext);
5192
- const metadata = await platformProxy.getMetadata();
5193
- if (!metadata?.botToken) throw new platformProxy.ActionError({
5194
- type: "invalid_metadata",
5195
- message: "botToken is required in connection metadata."
5196
- });
5130
+ const botToken = await resolveDiscordBotToken(platformProxy);
5197
5131
  const response = await platformProxy.get({
5198
5132
  endpoint: `/api/v10/webhooks/${input.webhookId}`,
5199
- headers: { Authorization: `Bot ${metadata.botToken}` },
5133
+ headers: { Authorization: `Bot ${botToken}` },
5200
5134
  retries: 3
5201
5135
  });
5202
5136
  if (!response.data) throw new platformProxy.ActionError({
@@ -5267,7 +5201,7 @@ function listChannelsTool$2(proxy) {
5267
5201
  outputSchema: listChannelsOutputSchema$2,
5268
5202
  execute: async (input, { requestContext }) => {
5269
5203
  const platformProxy = proxy.withRequestContext(requestContext);
5270
- const botToken = (await platformProxy.getMetadata())?.botToken;
5204
+ const botToken = await resolveDiscordBotToken(platformProxy);
5271
5205
  if (!botToken) throw new platformProxy.ActionError({
5272
5206
  type: "invalid_metadata",
5273
5207
  message: "botToken is required in metadata. Please configure the Discord connection with a bot token from your Discord application settings."
@@ -5360,12 +5294,7 @@ function listGuildMembersTool(proxy) {
5360
5294
  outputSchema: listGuildMembersOutputSchema,
5361
5295
  execute: async (input, { requestContext }) => {
5362
5296
  const platformProxy = proxy.withRequestContext(requestContext);
5363
- const metadata = await platformProxy.getMetadata();
5364
- const parsedMetadata = zod.z.object({ botToken: zod.z.string() }).safeParse(metadata);
5365
- if (!parsedMetadata.success) throw new platformProxy.ActionError({
5366
- type: "missing_bot_token",
5367
- message: "botToken is required in connection metadata."
5368
- });
5297
+ const botToken = await resolveDiscordBotToken(platformProxy);
5369
5298
  const limit = input.limit ?? 100;
5370
5299
  const response = await platformProxy.get({
5371
5300
  endpoint: `/api/v10/guilds/${input.guild_id}/members`,
@@ -5373,7 +5302,7 @@ function listGuildMembersTool(proxy) {
5373
5302
  limit: String(limit),
5374
5303
  ...input.after !== void 0 && { after: input.after }
5375
5304
  },
5376
- headers: { Authorization: `Bot ${parsedMetadata.data.botToken}` },
5305
+ headers: { Authorization: `Bot ${botToken}` },
5377
5306
  retries: 3
5378
5307
  });
5379
5308
  const rawMembers = zod.z.array(zod.z.unknown()).parse(response.data);
@@ -5443,11 +5372,7 @@ function listGuildsTool(proxy) {
5443
5372
  outputSchema: listGuildsOutputSchema,
5444
5373
  execute: async (input, { requestContext }) => {
5445
5374
  const platformProxy = proxy.withRequestContext(requestContext);
5446
- const botToken = (await platformProxy.getMetadata())?.botToken;
5447
- if (!botToken) throw new platformProxy.ActionError({
5448
- type: "invalid_metadata",
5449
- message: "botToken is required in metadata."
5450
- });
5375
+ const botToken = await resolveDiscordBotToken(platformProxy);
5451
5376
  const limit = input.limit ?? 200;
5452
5377
  const response = await platformProxy.get({
5453
5378
  endpoint: "/api/v10/users/@me/guilds",
@@ -5566,7 +5491,7 @@ function listMessagesTool$1(proxy) {
5566
5491
  outputSchema: listMessagesOutputSchema$1,
5567
5492
  execute: async (input, { requestContext }) => {
5568
5493
  const platformProxy = proxy.withRequestContext(requestContext);
5569
- const botToken = (await platformProxy.getMetadata())?.botToken;
5494
+ const botToken = await resolveDiscordBotToken(platformProxy);
5570
5495
  if (!botToken) throw new platformProxy.ActionError({
5571
5496
  type: "missing_bot_token",
5572
5497
  message: "Bot token is required in connection metadata. Please configure the bot token in your Nango connection."
@@ -5681,11 +5606,7 @@ function listRolesTool$1(proxy) {
5681
5606
  outputSchema: listRolesOutputSchema$1,
5682
5607
  execute: async (input, { requestContext }) => {
5683
5608
  const platformProxy = proxy.withRequestContext(requestContext);
5684
- const botToken = (await platformProxy.getMetadata())?.botToken;
5685
- if (!botToken) throw new platformProxy.ActionError({
5686
- type: "invalid_metadata",
5687
- message: "botToken is required in metadata."
5688
- });
5609
+ const botToken = await resolveDiscordBotToken(platformProxy);
5689
5610
  const response = await platformProxy.get({
5690
5611
  endpoint: `/api/v10/guilds/${input.guild_id}/roles`,
5691
5612
  headers: { Authorization: `Bot ${botToken}` },
@@ -5745,7 +5666,6 @@ const WebhookSchema = zod.z.object({
5745
5666
  url: zod.z.string().optional()
5746
5667
  });
5747
5668
  const listWebhooksOutputSchema$1 = zod.z.object({ webhooks: zod.z.array(WebhookSchema) });
5748
- zod.z.object({ botToken: zod.z.string() });
5749
5669
  function listWebhooksTool$1(proxy) {
5750
5670
  return (0, _mastra_core_tools.createTool)({
5751
5671
  id: "discord_list_webhooks",
@@ -5754,14 +5674,10 @@ function listWebhooksTool$1(proxy) {
5754
5674
  outputSchema: listWebhooksOutputSchema$1,
5755
5675
  execute: async (input, { requestContext }) => {
5756
5676
  const platformProxy = proxy.withRequestContext(requestContext);
5757
- const metadata = await platformProxy.getMetadata();
5758
- if (!metadata?.botToken) throw new platformProxy.ActionError({
5759
- type: "missing_bot_token",
5760
- message: "Bot token is required in connection metadata."
5761
- });
5677
+ const botToken = await resolveDiscordBotToken(platformProxy);
5762
5678
  const response = await platformProxy.get({
5763
5679
  endpoint: `/api/v10/channels/${input.channelId}/webhooks`,
5764
- headers: { Authorization: `Bot ${metadata.botToken}` },
5680
+ headers: { Authorization: `Bot ${botToken}` },
5765
5681
  retries: 3
5766
5682
  });
5767
5683
  return { webhooks: zod.z.array(WebhookSchema).parse(response.data) };
@@ -5789,11 +5705,7 @@ function removeGuildMemberRoleTool(proxy) {
5789
5705
  outputSchema: removeGuildMemberRoleOutputSchema,
5790
5706
  execute: async (input, { requestContext }) => {
5791
5707
  const platformProxy = proxy.withRequestContext(requestContext);
5792
- const botToken = (await platformProxy.getMetadata())?.botToken;
5793
- if (!botToken) throw new platformProxy.ActionError({
5794
- type: "missing_bot_token",
5795
- message: "Bot token is required in metadata. Please configure the botToken in your connection metadata."
5796
- });
5708
+ const botToken = await resolveDiscordBotToken(platformProxy);
5797
5709
  const response = await platformProxy.delete({
5798
5710
  endpoint: `/api/v10/guilds/${input.guild_id}/members/${input.user_id}/roles/${input.role_id}`,
5799
5711
  headers: { Authorization: `Bot ${botToken}` },
@@ -5859,7 +5771,6 @@ const ProviderChannelSchema$7 = zod.z.object({
5859
5771
  default_auto_archive_duration: zod.z.number().int().optional(),
5860
5772
  flags: zod.z.number().int().optional()
5861
5773
  });
5862
- const MetadataSchema$4 = zod.z.object({ botToken: zod.z.string() });
5863
5774
  const updateChannelOutputSchema$1 = zod.z.object({
5864
5775
  id: zod.z.string(),
5865
5776
  type: zod.z.number().int(),
@@ -5890,12 +5801,7 @@ function updateChannelTool$1(proxy) {
5890
5801
  outputSchema: updateChannelOutputSchema$1,
5891
5802
  execute: async (input, { requestContext }) => {
5892
5803
  const platformProxy = proxy.withRequestContext(requestContext);
5893
- const rawMetadata = await platformProxy.getMetadata();
5894
- const metadata = MetadataSchema$4.safeParse(rawMetadata);
5895
- if (!metadata.success || !metadata.data.botToken) throw new platformProxy.ActionError({
5896
- type: "invalid_metadata",
5897
- message: "botToken is required in metadata. Please set the Discord bot token in the connection metadata."
5898
- });
5804
+ const botToken = await resolveDiscordBotToken(platformProxy);
5899
5805
  const updateData = {};
5900
5806
  if (input["name"] !== void 0) updateData["name"] = input["name"];
5901
5807
  if (input["type"] !== void 0) updateData["type"] = input["type"];
@@ -5911,7 +5817,7 @@ function updateChannelTool$1(proxy) {
5911
5817
  if (input["flags"] !== void 0) updateData["flags"] = input["flags"];
5912
5818
  const response = await platformProxy.patch({
5913
5819
  endpoint: `/api/v10/channels/${input.channel_id}`,
5914
- headers: { Authorization: `Bot ${metadata.data.botToken}` },
5820
+ headers: { Authorization: `Bot ${botToken}` },
5915
5821
  data: updateData,
5916
5822
  retries: 10
5917
5823
  });
@@ -6019,11 +5925,7 @@ function updateGuildMemberTool(proxy) {
6019
5925
  outputSchema: updateGuildMemberOutputSchema,
6020
5926
  execute: async (input, { requestContext }) => {
6021
5927
  const platformProxy = proxy.withRequestContext(requestContext);
6022
- const metadata = await platformProxy.getMetadata();
6023
- if (!metadata?.botToken) throw new platformProxy.ActionError({
6024
- type: "invalid_metadata",
6025
- message: "botToken is required in metadata. Please provide the bot token from your Discord application."
6026
- });
5928
+ const botToken = await resolveDiscordBotToken(platformProxy);
6027
5929
  const body = {};
6028
5930
  if (input["nick"] !== void 0) body["nick"] = input["nick"];
6029
5931
  if (input["roles"] !== void 0) body["roles"] = input["roles"];
@@ -6032,7 +5934,7 @@ function updateGuildMemberTool(proxy) {
6032
5934
  if (input["channel_id"] !== void 0) body["channel_id"] = input["channel_id"];
6033
5935
  if (input["communication_disabled_until"] !== void 0) body["communication_disabled_until"] = input["communication_disabled_until"];
6034
5936
  if (input["flags"] !== void 0) body["flags"] = input["flags"];
6035
- const headers = { Authorization: `Bot ${metadata.botToken}` };
5937
+ const headers = { Authorization: `Bot ${botToken}` };
6036
5938
  if (input.reason) headers["X-Audit-Log-Reason"] = input.reason;
6037
5939
  if (input["user_id"] === "@me") {
6038
5940
  const currentMemberBody = {};
@@ -6083,7 +5985,6 @@ function updateGuildMemberTool(proxy) {
6083
5985
  }
6084
5986
  //#endregion
6085
5987
  //#region src/providers/discord/tools/update-guild.ts
6086
- zod.z.object({ botToken: zod.z.string() });
6087
5988
  const updateGuildInputSchema = zod.z.object({
6088
5989
  guild_id: zod.z.string().describe("Guild ID to update. Example: \"197038439483310086\""),
6089
5990
  name: zod.z.string().min(2).max(100).optional().describe("Guild name (2-100 characters)"),
@@ -6139,11 +6040,7 @@ function updateGuildTool(proxy) {
6139
6040
  outputSchema: updateGuildOutputSchema,
6140
6041
  execute: async (input, { requestContext }) => {
6141
6042
  const platformProxy = proxy.withRequestContext(requestContext);
6142
- const metadata = await platformProxy.getMetadata();
6143
- if (!metadata?.botToken) throw new platformProxy.ActionError({
6144
- type: "invalid_metadata",
6145
- message: "botToken is required in metadata."
6146
- });
6043
+ const botToken = await resolveDiscordBotToken(platformProxy);
6147
6044
  const payload = {};
6148
6045
  if (input.name !== void 0) payload["name"] = input.name;
6149
6046
  if (input.region !== void 0) payload["region"] = input.region;
@@ -6168,7 +6065,7 @@ function updateGuildTool(proxy) {
6168
6065
  if (input.safety_alerts_channel_id !== void 0) payload["safety_alerts_channel_id"] = input.safety_alerts_channel_id;
6169
6066
  const response = await platformProxy.patch({
6170
6067
  endpoint: `/api/v10/guilds/${input.guild_id}`,
6171
- headers: { Authorization: `Bot ${metadata.botToken}` },
6068
+ headers: { Authorization: `Bot ${botToken}` },
6172
6069
  data: payload,
6173
6070
  retries: 3
6174
6071
  });
@@ -6277,13 +6174,7 @@ function updateMessageTool$1(proxy) {
6277
6174
  outputSchema: updateMessageOutputSchema$1,
6278
6175
  execute: async (input, { requestContext }) => {
6279
6176
  const platformProxy = proxy.withRequestContext(requestContext);
6280
- const metadata = await platformProxy.getMetadata();
6281
- const parsedMetadata = zod.z.object({ botToken: zod.z.string() }).safeParse(metadata);
6282
- if (!parsedMetadata.success) throw new platformProxy.ActionError({
6283
- type: "invalid_metadata",
6284
- message: "botToken is required in metadata."
6285
- });
6286
- const botToken = parsedMetadata.data.botToken;
6177
+ const botToken = await resolveDiscordBotToken(platformProxy);
6287
6178
  const response = await platformProxy.patch({
6288
6179
  endpoint: `/api/v10/channels/${input.channel_id}/messages/${input.message_id}`,
6289
6180
  headers: { Authorization: `Bot ${botToken}` },
@@ -6369,11 +6260,7 @@ function updateRoleTool(proxy) {
6369
6260
  outputSchema: updateRoleOutputSchema,
6370
6261
  execute: async (input, { requestContext }) => {
6371
6262
  const platformProxy = proxy.withRequestContext(requestContext);
6372
- const botToken = (await platformProxy.getMetadata())?.botToken;
6373
- if (!botToken) throw new platformProxy.ActionError({
6374
- type: "invalid_metadata",
6375
- message: "botToken is required in metadata."
6376
- });
6263
+ const botToken = await resolveDiscordBotToken(platformProxy);
6377
6264
  if (input.icon !== void 0 && input.icon !== null && input.unicodeEmoji !== void 0 && input.unicodeEmoji !== null) throw new platformProxy.ActionError({
6378
6265
  type: "invalid_input",
6379
6266
  message: "icon and unicodeEmoji are mutually exclusive; provide at most one."
@@ -6456,12 +6343,7 @@ function updateWebhookTool$1(proxy) {
6456
6343
  outputSchema: updateWebhookOutputSchema$1,
6457
6344
  execute: async (input, { requestContext }) => {
6458
6345
  const platformProxy = proxy.withRequestContext(requestContext);
6459
- const metadata = await platformProxy.getMetadata();
6460
- const botToken = metadata && typeof metadata === "object" && "botToken" in metadata && typeof metadata.botToken === "string" ? metadata.botToken : void 0;
6461
- if (!botToken) throw new platformProxy.ActionError({
6462
- type: "invalid_metadata",
6463
- message: "botToken is required in metadata."
6464
- });
6346
+ const botToken = await resolveDiscordBotToken(platformProxy);
6465
6347
  const requestBody = {};
6466
6348
  if (input.name !== void 0) requestBody["name"] = input.name;
6467
6349
  if (input.avatar !== void 0) requestBody["avatar"] = input.avatar;