@mastra/slack 1.4.0 → 1.5.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.
- package/CHANGELOG.md +59 -0
- package/dist/index.cjs +18 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -1
- package/dist/index.d.ts +34 -1
- package/dist/index.js +20 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Mastra } from '@mastra/core/mastra';
|
|
2
|
-
import { ChannelAdapterConfig, StreamingConfig, ToolDisplay, StaticToolDisplay, ChannelHandlers, ChannelConfig, ChannelProvider, ChannelConnectResult, ChannelInstallationInfo, ChannelPlatformInfo } from '@mastra/core/channels';
|
|
2
|
+
import { ChannelAdapterConfig, StreamingConfig, ToolDisplay, StaticToolDisplay, ChannelHandlers, ChannelConfig, WaitUntilFn, WaitUntilResolver, ChannelProvider, ChannelConnectResult, ChannelInstallationInfo, ChannelPlatformInfo } from '@mastra/core/channels';
|
|
3
3
|
import { ApiRoute } from '@mastra/core/server';
|
|
4
4
|
import { SlackAdapterConfig, SlackAdapter } from '@chat-adapter/slack';
|
|
5
5
|
export { SlackAdapter, createSlackAdapter } from '@chat-adapter/slack';
|
|
@@ -281,6 +281,39 @@ interface SlackProviderConfigBase extends SlackAdapterChannelConfigBase {
|
|
|
281
281
|
* Use a 32+ character random string. Can be set via MASTRA_ENCRYPTION_KEY env var.
|
|
282
282
|
*/
|
|
283
283
|
encryptionKey?: string;
|
|
284
|
+
/**
|
|
285
|
+
* Resolver that returns a `waitUntil` for the current Slack webhook request.
|
|
286
|
+
*
|
|
287
|
+
* Required on serverless runtimes where Hono can't bridge the platform's
|
|
288
|
+
* `ExecutionContext` automatically (Vercel, AWS Lambda). Without `waitUntil`, the
|
|
289
|
+
* runtime freezes the invocation as soon as the 200 ack returns, killing the
|
|
290
|
+
* agent run mid-flight and leaving the user with no Slack reply.
|
|
291
|
+
*
|
|
292
|
+
* Pass the bare `waitUntil(promise)` function from your platform's SDK. If your
|
|
293
|
+
* runtime requires the Hono `Context` to derive `waitUntil`, use
|
|
294
|
+
* {@link resolveWaitUntil} instead.
|
|
295
|
+
*
|
|
296
|
+
* Cloudflare Workers and Netlify users typically don't need this — Mastra's
|
|
297
|
+
* default helper already reads `c.executionCtx.waitUntil` and
|
|
298
|
+
* `c.env.context.waitUntil`.
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* ```ts
|
|
302
|
+
* import { waitUntil } from '@vercel/functions';
|
|
303
|
+
* new SlackProvider({ waitUntil });
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
waitUntil?: WaitUntilFn;
|
|
307
|
+
/**
|
|
308
|
+
* Resolve `waitUntil` from the request's Hono `Context`. Use this when the runtime
|
|
309
|
+
* exposes `waitUntil` through the request and core's default doesn't cover it.
|
|
310
|
+
*
|
|
311
|
+
* For platforms whose `waitUntil` is a bare import (e.g. `@vercel/functions`),
|
|
312
|
+
* pass it via {@link waitUntil} instead.
|
|
313
|
+
*
|
|
314
|
+
* Resolution order: {@link waitUntil} → {@link resolveWaitUntil} → core default.
|
|
315
|
+
*/
|
|
316
|
+
resolveWaitUntil?: WaitUntilResolver;
|
|
284
317
|
/**
|
|
285
318
|
* Per-adapter overrides applied to the Slack adapter entry inside
|
|
286
319
|
* `AgentChannels.adapters` — for example `toolDisplay`, `streaming`,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Mastra } from '@mastra/core/mastra';
|
|
2
|
-
import { ChannelAdapterConfig, StreamingConfig, ToolDisplay, StaticToolDisplay, ChannelHandlers, ChannelConfig, ChannelProvider, ChannelConnectResult, ChannelInstallationInfo, ChannelPlatformInfo } from '@mastra/core/channels';
|
|
2
|
+
import { ChannelAdapterConfig, StreamingConfig, ToolDisplay, StaticToolDisplay, ChannelHandlers, ChannelConfig, WaitUntilFn, WaitUntilResolver, ChannelProvider, ChannelConnectResult, ChannelInstallationInfo, ChannelPlatformInfo } from '@mastra/core/channels';
|
|
3
3
|
import { ApiRoute } from '@mastra/core/server';
|
|
4
4
|
import { SlackAdapterConfig, SlackAdapter } from '@chat-adapter/slack';
|
|
5
5
|
export { SlackAdapter, createSlackAdapter } from '@chat-adapter/slack';
|
|
@@ -281,6 +281,39 @@ interface SlackProviderConfigBase extends SlackAdapterChannelConfigBase {
|
|
|
281
281
|
* Use a 32+ character random string. Can be set via MASTRA_ENCRYPTION_KEY env var.
|
|
282
282
|
*/
|
|
283
283
|
encryptionKey?: string;
|
|
284
|
+
/**
|
|
285
|
+
* Resolver that returns a `waitUntil` for the current Slack webhook request.
|
|
286
|
+
*
|
|
287
|
+
* Required on serverless runtimes where Hono can't bridge the platform's
|
|
288
|
+
* `ExecutionContext` automatically (Vercel, AWS Lambda). Without `waitUntil`, the
|
|
289
|
+
* runtime freezes the invocation as soon as the 200 ack returns, killing the
|
|
290
|
+
* agent run mid-flight and leaving the user with no Slack reply.
|
|
291
|
+
*
|
|
292
|
+
* Pass the bare `waitUntil(promise)` function from your platform's SDK. If your
|
|
293
|
+
* runtime requires the Hono `Context` to derive `waitUntil`, use
|
|
294
|
+
* {@link resolveWaitUntil} instead.
|
|
295
|
+
*
|
|
296
|
+
* Cloudflare Workers and Netlify users typically don't need this — Mastra's
|
|
297
|
+
* default helper already reads `c.executionCtx.waitUntil` and
|
|
298
|
+
* `c.env.context.waitUntil`.
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* ```ts
|
|
302
|
+
* import { waitUntil } from '@vercel/functions';
|
|
303
|
+
* new SlackProvider({ waitUntil });
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
waitUntil?: WaitUntilFn;
|
|
307
|
+
/**
|
|
308
|
+
* Resolve `waitUntil` from the request's Hono `Context`. Use this when the runtime
|
|
309
|
+
* exposes `waitUntil` through the request and core's default doesn't cover it.
|
|
310
|
+
*
|
|
311
|
+
* For platforms whose `waitUntil` is a bare import (e.g. `@vercel/functions`),
|
|
312
|
+
* pass it via {@link waitUntil} instead.
|
|
313
|
+
*
|
|
314
|
+
* Resolution order: {@link waitUntil} → {@link resolveWaitUntil} → core default.
|
|
315
|
+
*/
|
|
316
|
+
resolveWaitUntil?: WaitUntilResolver;
|
|
284
317
|
/**
|
|
285
318
|
* Per-adapter overrides applied to the Slack adapter entry inside
|
|
286
319
|
* `AgentChannels.adapters` — for example `toolDisplay`, `streaming`,
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,8 @@ var __export = (target, all) => {
|
|
|
7
7
|
// src/provider.ts
|
|
8
8
|
import * as crypto from "crypto";
|
|
9
9
|
import {
|
|
10
|
-
AgentChannels
|
|
10
|
+
AgentChannels,
|
|
11
|
+
resolveWaitUntil
|
|
11
12
|
} from "@mastra/core/channels";
|
|
12
13
|
import "@mastra/core/storage";
|
|
13
14
|
import { createSlackAdapter } from "@chat-adapter/slack";
|
|
@@ -14899,6 +14900,13 @@ var SlackConfigDataSchema = external_exports.object({
|
|
|
14899
14900
|
|
|
14900
14901
|
// src/provider.ts
|
|
14901
14902
|
var PLATFORM = "slack";
|
|
14903
|
+
function stripTrailingSlash(url2) {
|
|
14904
|
+
let end = url2.length;
|
|
14905
|
+
while (end > 0 && url2.charCodeAt(end - 1) === 47) {
|
|
14906
|
+
end--;
|
|
14907
|
+
}
|
|
14908
|
+
return end === url2.length ? url2 : url2.slice(0, end);
|
|
14909
|
+
}
|
|
14902
14910
|
function hashConfig(opts, baseUrl, resolvedAppName, resolvedDescription) {
|
|
14903
14911
|
const normalized = JSON.stringify({
|
|
14904
14912
|
name: resolvedAppName,
|
|
@@ -15310,7 +15318,7 @@ var SlackProvider = class {
|
|
|
15310
15318
|
*/
|
|
15311
15319
|
#getBaseUrl() {
|
|
15312
15320
|
if (this.#baseUrl) {
|
|
15313
|
-
return this.#baseUrl;
|
|
15321
|
+
return stripTrailingSlash(this.#baseUrl);
|
|
15314
15322
|
}
|
|
15315
15323
|
const server = this.#mastra?.getServer();
|
|
15316
15324
|
const protocol = server?.studioProtocol ?? "http";
|
|
@@ -15324,7 +15332,7 @@ var SlackProvider = class {
|
|
|
15324
15332
|
* Only needed if not using Mastra server config.
|
|
15325
15333
|
*/
|
|
15326
15334
|
setBaseUrl(baseUrl) {
|
|
15327
|
-
this.#baseUrl = baseUrl;
|
|
15335
|
+
this.#baseUrl = stripTrailingSlash(baseUrl);
|
|
15328
15336
|
}
|
|
15329
15337
|
/**
|
|
15330
15338
|
* Restore active Slack installations from storage.
|
|
@@ -15525,7 +15533,6 @@ var SlackProvider = class {
|
|
|
15525
15533
|
const slackEntry = Object.keys(adapterConfig).length > 0 ? { adapter, ...adapterConfig } : adapter;
|
|
15526
15534
|
const existing = agent.getChannels();
|
|
15527
15535
|
const existingConfig = existing?.channelConfig;
|
|
15528
|
-
existing?.close();
|
|
15529
15536
|
const agentChannels = new AgentChannels({
|
|
15530
15537
|
...existingConfig,
|
|
15531
15538
|
...this.#forwardedChannelOptions(),
|
|
@@ -16013,8 +16020,13 @@ var SlackProvider = class {
|
|
|
16013
16020
|
headers: c.req.raw.headers,
|
|
16014
16021
|
body: rawBody
|
|
16015
16022
|
});
|
|
16023
|
+
const waitUntilFn = this.#channelConfig.waitUntil ?? this.#channelConfig.resolveWaitUntil?.(c) ?? resolveWaitUntil(c);
|
|
16016
16024
|
try {
|
|
16017
|
-
return await agentChannels.handleWebhookEvent(
|
|
16025
|
+
return await agentChannels.handleWebhookEvent(
|
|
16026
|
+
"slack",
|
|
16027
|
+
delegateRequest,
|
|
16028
|
+
waitUntilFn ? { waitUntil: waitUntilFn } : void 0
|
|
16029
|
+
);
|
|
16018
16030
|
} catch (error51) {
|
|
16019
16031
|
console.error("[Slack] Error delegating to AgentChannels:", error51);
|
|
16020
16032
|
return c.json({ ok: true });
|
|
@@ -16068,7 +16080,7 @@ var SlackProvider = class {
|
|
|
16068
16080
|
signal: AbortSignal.timeout(3e4)
|
|
16069
16081
|
});
|
|
16070
16082
|
};
|
|
16071
|
-
(async () => {
|
|
16083
|
+
const task = (async () => {
|
|
16072
16084
|
try {
|
|
16073
16085
|
const result = await agent.generate(prompt);
|
|
16074
16086
|
const text = typeof result.text === "string" ? result.text : JSON.stringify(result.text);
|
|
@@ -16079,6 +16091,8 @@ var SlackProvider = class {
|
|
|
16079
16091
|
await sendDelayedResponse(`Error: ${message}`);
|
|
16080
16092
|
}
|
|
16081
16093
|
})();
|
|
16094
|
+
const slashWaitUntil = this.#channelConfig.waitUntil ?? this.#channelConfig.resolveWaitUntil?.(c) ?? resolveWaitUntil(c);
|
|
16095
|
+
slashWaitUntil?.(task);
|
|
16082
16096
|
return c.json({ response_type: "ephemeral", text: "Processing..." });
|
|
16083
16097
|
}
|
|
16084
16098
|
// ===========================================================================
|