@mastra/slack 1.1.1 → 1.2.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/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Mastra } from '@mastra/core/mastra';
2
- import { ChannelProvider, ChannelConnectResult, ChannelInstallationInfo, ChannelPlatformInfo } from '@mastra/core/channels';
2
+ import { ChannelAdapterConfig, ChannelConfig, ChannelHandlers, ChannelProvider, ChannelConnectResult, ChannelInstallationInfo, ChannelPlatformInfo } from '@mastra/core/channels';
3
3
  import { ApiRoute } from '@mastra/core/server';
4
- import { SlackAdapter } from '@chat-adapter/slack';
4
+ import { SlackAdapterConfig, SlackAdapter } from '@chat-adapter/slack';
5
5
  export { SlackAdapter, createSlackAdapter } from '@chat-adapter/slack';
6
6
  import { z } from 'zod';
7
7
  import { ChannelsStorage } from '@mastra/core/storage';
@@ -203,10 +203,50 @@ interface SlackConfigTokens {
203
203
  updatedAt: Date;
204
204
  }
205
205
 
206
+ /**
207
+ * Per-adapter overrides forwarded to the SlackAdapter entry inside
208
+ * `AgentChannels.adapters` — equivalent to passing
209
+ * `{ adapter, ...adapterConfig }` when wiring up `AgentChannels` manually.
210
+ * The `adapter` instance itself is created by the provider.
211
+ */
212
+ type SlackAdapterChannelConfig = Omit<ChannelAdapterConfig, 'adapter'>;
213
+ /** AgentChannels fields that the provider forwards. `adapters` and `userName` are provider-managed. */
214
+ type ForwardedAgentChannelsOptions = Pick<ChannelConfig, 'inlineMedia' | 'inlineLinks' | 'state' | 'threadContext' | 'tools' | 'chatOptions'>;
206
215
  /**
207
216
  * Configuration for SlackProvider at the Mastra level.
217
+ *
218
+ * In addition to the provider-specific fields documented below, this accepts
219
+ * options that are forwarded to the underlying `AgentChannels` instances
220
+ * managed by the provider — for example `handlers`, `inlineMedia`, and
221
+ * `adapterConfig`.
208
222
  */
209
- interface SlackProviderConfig {
223
+ interface SlackProviderConfig extends ForwardedAgentChannelsOptions {
224
+ /**
225
+ * Logger forwarded to the underlying `SlackAdapter` for internal error
226
+ * reporting. Defaults to the adapter's `ConsoleLogger`.
227
+ */
228
+ logger?: SlackAdapterConfig['logger'];
229
+ /**
230
+ * Override built-in event handlers (e.g. `onDirectMessage`, `onMention`).
231
+ * Forwarded to `AgentChannels` for every agent connected via this provider.
232
+ *
233
+ * @example
234
+ * ```ts
235
+ * handlers: {
236
+ * onDirectMessage: async (thread, message, defaultHandler) => {
237
+ * console.log('DM:', message.text);
238
+ * await defaultHandler(thread, message);
239
+ * },
240
+ * }
241
+ * ```
242
+ */
243
+ handlers?: ChannelHandlers;
244
+ /**
245
+ * Per-adapter overrides applied to the Slack adapter entry inside
246
+ * `AgentChannels.adapters` — for example `cards`, `formatToolCall`,
247
+ * `formatError`.
248
+ */
249
+ adapterConfig?: SlackAdapterChannelConfig;
210
250
  /**
211
251
  * Slack App Configuration access token for programmatic app creation.
212
252
  * Generate at: https://api.slack.com/apps > "Your App Configuration Tokens"
@@ -675,4 +715,4 @@ interface BuildManifestOptions {
675
715
  */
676
716
  declare function buildManifest(options: BuildManifestOptions): SlackAppManifest;
677
717
 
678
- export { DEFAULT_BOT_EVENTS, DEFAULT_BOT_SCOPES, type SlackAppManifest, type SlackBlock, type SlackConfigData, SlackConfigDataSchema, type SlackConfigTokens, type SlackConnectOptions, type SlackInstallation, type SlackInstallationData, SlackInstallationDataSchema, SlackManifestClient, type SlackMessage, type SlackPendingData, SlackPendingDataSchema, type SlackPendingInstallation, SlackProvider, type SlackProviderConfig, type SlashCommandConfig, buildManifest, parseSlackFormBody, verifySlackRequest };
718
+ export { DEFAULT_BOT_EVENTS, DEFAULT_BOT_SCOPES, type SlackAdapterChannelConfig, type SlackAppManifest, type SlackBlock, type SlackConfigData, SlackConfigDataSchema, type SlackConfigTokens, type SlackConnectOptions, type SlackInstallation, type SlackInstallationData, SlackInstallationDataSchema, SlackManifestClient, type SlackMessage, type SlackPendingData, SlackPendingDataSchema, type SlackPendingInstallation, SlackProvider, type SlackProviderConfig, type SlashCommandConfig, buildManifest, parseSlackFormBody, verifySlackRequest };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Mastra } from '@mastra/core/mastra';
2
- import { ChannelProvider, ChannelConnectResult, ChannelInstallationInfo, ChannelPlatformInfo } from '@mastra/core/channels';
2
+ import { ChannelAdapterConfig, ChannelConfig, ChannelHandlers, ChannelProvider, ChannelConnectResult, ChannelInstallationInfo, ChannelPlatformInfo } from '@mastra/core/channels';
3
3
  import { ApiRoute } from '@mastra/core/server';
4
- import { SlackAdapter } from '@chat-adapter/slack';
4
+ import { SlackAdapterConfig, SlackAdapter } from '@chat-adapter/slack';
5
5
  export { SlackAdapter, createSlackAdapter } from '@chat-adapter/slack';
6
6
  import { z } from 'zod';
7
7
  import { ChannelsStorage } from '@mastra/core/storage';
@@ -203,10 +203,50 @@ interface SlackConfigTokens {
203
203
  updatedAt: Date;
204
204
  }
205
205
 
206
+ /**
207
+ * Per-adapter overrides forwarded to the SlackAdapter entry inside
208
+ * `AgentChannels.adapters` — equivalent to passing
209
+ * `{ adapter, ...adapterConfig }` when wiring up `AgentChannels` manually.
210
+ * The `adapter` instance itself is created by the provider.
211
+ */
212
+ type SlackAdapterChannelConfig = Omit<ChannelAdapterConfig, 'adapter'>;
213
+ /** AgentChannels fields that the provider forwards. `adapters` and `userName` are provider-managed. */
214
+ type ForwardedAgentChannelsOptions = Pick<ChannelConfig, 'inlineMedia' | 'inlineLinks' | 'state' | 'threadContext' | 'tools' | 'chatOptions'>;
206
215
  /**
207
216
  * Configuration for SlackProvider at the Mastra level.
217
+ *
218
+ * In addition to the provider-specific fields documented below, this accepts
219
+ * options that are forwarded to the underlying `AgentChannels` instances
220
+ * managed by the provider — for example `handlers`, `inlineMedia`, and
221
+ * `adapterConfig`.
208
222
  */
209
- interface SlackProviderConfig {
223
+ interface SlackProviderConfig extends ForwardedAgentChannelsOptions {
224
+ /**
225
+ * Logger forwarded to the underlying `SlackAdapter` for internal error
226
+ * reporting. Defaults to the adapter's `ConsoleLogger`.
227
+ */
228
+ logger?: SlackAdapterConfig['logger'];
229
+ /**
230
+ * Override built-in event handlers (e.g. `onDirectMessage`, `onMention`).
231
+ * Forwarded to `AgentChannels` for every agent connected via this provider.
232
+ *
233
+ * @example
234
+ * ```ts
235
+ * handlers: {
236
+ * onDirectMessage: async (thread, message, defaultHandler) => {
237
+ * console.log('DM:', message.text);
238
+ * await defaultHandler(thread, message);
239
+ * },
240
+ * }
241
+ * ```
242
+ */
243
+ handlers?: ChannelHandlers;
244
+ /**
245
+ * Per-adapter overrides applied to the Slack adapter entry inside
246
+ * `AgentChannels.adapters` — for example `cards`, `formatToolCall`,
247
+ * `formatError`.
248
+ */
249
+ adapterConfig?: SlackAdapterChannelConfig;
210
250
  /**
211
251
  * Slack App Configuration access token for programmatic app creation.
212
252
  * Generate at: https://api.slack.com/apps > "Your App Configuration Tokens"
@@ -675,4 +715,4 @@ interface BuildManifestOptions {
675
715
  */
676
716
  declare function buildManifest(options: BuildManifestOptions): SlackAppManifest;
677
717
 
678
- export { DEFAULT_BOT_EVENTS, DEFAULT_BOT_SCOPES, type SlackAppManifest, type SlackBlock, type SlackConfigData, SlackConfigDataSchema, type SlackConfigTokens, type SlackConnectOptions, type SlackInstallation, type SlackInstallationData, SlackInstallationDataSchema, SlackManifestClient, type SlackMessage, type SlackPendingData, SlackPendingDataSchema, type SlackPendingInstallation, SlackProvider, type SlackProviderConfig, type SlashCommandConfig, buildManifest, parseSlackFormBody, verifySlackRequest };
718
+ export { DEFAULT_BOT_EVENTS, DEFAULT_BOT_SCOPES, type SlackAdapterChannelConfig, type SlackAppManifest, type SlackBlock, type SlackConfigData, SlackConfigDataSchema, type SlackConfigTokens, type SlackConnectOptions, type SlackInstallation, type SlackInstallationData, SlackInstallationDataSchema, SlackManifestClient, type SlackMessage, type SlackPendingData, SlackPendingDataSchema, type SlackPendingInstallation, SlackProvider, type SlackProviderConfig, type SlashCommandConfig, buildManifest, parseSlackFormBody, verifySlackRequest };
package/dist/index.js CHANGED
@@ -4908,6 +4908,7 @@ var SlackProvider = class {
4908
4908
  const agent = this.#mastra?.getAgentById(installation.agentId);
4909
4909
  const displayName = installation.name || agent?.name || installation.agentId;
4910
4910
  const adapter = createSlackAdapter({
4911
+ ...this.#forwardedAdapterOptions(),
4911
4912
  botToken: installation.botToken,
4912
4913
  botUserId: installation.botUserId,
4913
4914
  signingSecret: installation.signingSecret,
@@ -4971,13 +4972,33 @@ var SlackProvider = class {
4971
4972
  }
4972
4973
  }
4973
4974
  }
4975
+ /**
4976
+ * Extract the SlackAdapter fields the provider forwards to every
4977
+ * `createSlackAdapter()` call. Installation-managed credentials/identity are
4978
+ * applied separately.
4979
+ */
4980
+ #forwardedAdapterOptions() {
4981
+ const { logger } = this.#channelConfig;
4982
+ return { logger };
4983
+ }
4984
+ /**
4985
+ * Extract the AgentChannels fields the provider forwards. `adapters` and
4986
+ * `userName` are applied separately by `#createAgentChannels`.
4987
+ */
4988
+ #forwardedChannelOptions() {
4989
+ const { handlers, inlineMedia, inlineLinks, state, threadContext, tools, chatOptions } = this.#channelConfig;
4990
+ return { handlers, inlineMedia, inlineLinks, state, threadContext, tools, chatOptions };
4991
+ }
4974
4992
  /**
4975
4993
  * Create AgentChannels for an agent with the Slack adapter.
4976
4994
  * SlackProvider owns the AgentChannels lifecycle for platform-managed agents.
4977
4995
  */
4978
4996
  #createAgentChannels(agent, adapter) {
4997
+ const { adapterConfig } = this.#channelConfig;
4998
+ const slackEntry = adapterConfig ? { adapter, ...adapterConfig } : adapter;
4979
4999
  const agentChannels = new AgentChannels({
4980
- adapters: { slack: adapter },
5000
+ ...this.#forwardedChannelOptions(),
5001
+ adapters: { slack: slackEntry },
4981
5002
  userName: agent.name
4982
5003
  });
4983
5004
  agent.setChannels(agentChannels);
@@ -5365,6 +5386,7 @@ var SlackProvider = class {
5365
5386
  const agent = this.#mastra?.getAgentById(pending.agentId);
5366
5387
  const displayName = installation.name || agent?.name || pending.agentId;
5367
5388
  const adapter = createSlackAdapter({
5389
+ ...this.#forwardedAdapterOptions(),
5368
5390
  botToken: installation.botToken,
5369
5391
  botUserId: installation.botUserId,
5370
5392
  signingSecret: installation.signingSecret,
@@ -5441,6 +5463,7 @@ var SlackProvider = class {
5441
5463
  }
5442
5464
  const displayName = installation.name || agent.name || installation.agentId;
5443
5465
  const currentAdapter = this.#adapters.get(installation.id) ?? createSlackAdapter({
5466
+ ...this.#forwardedAdapterOptions(),
5444
5467
  botToken: installation.botToken,
5445
5468
  botUserId: installation.botUserId,
5446
5469
  signingSecret: installation.signingSecret,