@mastra/mcp-docs-server 1.2.2 → 1.2.3-alpha.11
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/.docs/docs/{harness → agent-controller}/modes.md +19 -19
- package/.docs/docs/agent-controller/overview.md +128 -0
- package/.docs/docs/agent-controller/session.md +143 -0
- package/.docs/docs/{harness → agent-controller}/subagents.md +12 -12
- package/.docs/docs/agent-controller/threads-and-state.md +141 -0
- package/.docs/docs/{harness → agent-controller}/tool-approvals.md +23 -23
- package/.docs/docs/agents/agent-approval.md +38 -0
- package/.docs/docs/agents/channels.md +47 -0
- package/.docs/docs/agents/heartbeats.md +211 -0
- package/.docs/docs/agents/signals.md +25 -1
- package/.docs/docs/observability/metrics/overview.md +2 -2
- package/.docs/models/gateways/openrouter.md +1 -2
- package/.docs/models/gateways/vercel.md +3 -1
- package/.docs/models/index.md +1 -1
- package/.docs/models/providers/anthropic.md +4 -5
- package/.docs/models/providers/chutes.md +17 -43
- package/.docs/models/providers/deepinfra.md +3 -2
- package/.docs/models/providers/friendli.md +1 -3
- package/.docs/models/providers/gmicloud.md +18 -15
- package/.docs/models/providers/huggingface.md +2 -1
- package/.docs/models/providers/inceptron.md +10 -8
- package/.docs/models/providers/llmgateway.md +3 -6
- package/.docs/models/providers/neuralwatt.md +9 -5
- package/.docs/models/providers/novita-ai.md +1 -1
- package/.docs/models/providers/nvidia.md +2 -1
- package/.docs/models/providers/siliconflow-cn.md +50 -78
- package/.docs/models/providers/siliconflow.md +52 -73
- package/.docs/models/providers/stepfun.md +1 -1
- package/.docs/models/providers/subconscious.md +71 -0
- package/.docs/models/providers/synthetic.md +8 -6
- package/.docs/models/providers/tinfoil.md +77 -0
- package/.docs/models/providers/xiaomi.md +2 -2
- package/.docs/models/providers.md +2 -0
- package/.docs/reference/{harness/harness-class.md → agent-controller/agent-controller-class.md} +106 -106
- package/.docs/reference/{harness → agent-controller}/session.md +97 -91
- package/.docs/reference/agents/channels.md +3 -1
- package/.docs/reference/agents/listSuspendedRuns.md +91 -0
- package/.docs/reference/channels/channel-provider.md +65 -0
- package/.docs/reference/channels/slack-provider.md +226 -0
- package/.docs/reference/client-js/agents.md +21 -0
- package/.docs/reference/index.md +6 -2
- package/.docs/reference/observability/metrics/automatic-metrics.md +2 -2
- package/.docs/reference/pubsub/lease-provider.md +131 -0
- package/.docs/reference/pubsub/redis-streams.md +10 -2
- package/CHANGELOG.md +42 -0
- package/package.json +4 -4
- package/.docs/docs/harness/overview.md +0 -128
- package/.docs/docs/harness/session.md +0 -143
- package/.docs/docs/harness/threads-and-state.md +0 -141
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Agent.listSuspendedRuns()
|
|
2
|
+
|
|
3
|
+
**Added in:** `@mastra/core@1.43.0`
|
|
4
|
+
|
|
5
|
+
The `.listSuspendedRuns()` method lists suspended agent runs from workflow snapshot storage: runs waiting on a tool call requiring [approval](https://mastra.ai/docs/agents/agent-approval), or on a tool that called `suspend()`. Because discovery is backed by storage rather than in-memory state, it works after a server restart and across multiple server instances.
|
|
6
|
+
|
|
7
|
+
Pass the returned `runId` to [`resumeStream()`](https://mastra.ai/docs/agents/agent-approval), `approveToolCall()`, or `declineToolCall()` to continue the run.
|
|
8
|
+
|
|
9
|
+
The filter contract mirrors the workflow run listing APIs (`listWorkflowRuns`), plus the agent-level `threadId` filter.
|
|
10
|
+
|
|
11
|
+
## Usage example
|
|
12
|
+
|
|
13
|
+
Discover the pending run for a conversation and continue it. Check `requiresApproval` to pick the right continuation — `approveToolCall()` / `declineToolCall()` for approval suspensions, `resumeStream()` with resume data for `suspend()`-based suspensions:
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
const { runs } = await agent.listSuspendedRuns({
|
|
17
|
+
threadId: 'thread-123',
|
|
18
|
+
resourceId: 'user-456',
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
const run = runs[0]
|
|
22
|
+
const toolCall = run?.toolCalls[0]
|
|
23
|
+
|
|
24
|
+
if (run && toolCall) {
|
|
25
|
+
const stream = toolCall.requiresApproval
|
|
26
|
+
? await agent.approveToolCall({ runId: run.runId, toolCallId: toolCall.toolCallId })
|
|
27
|
+
: await agent.resumeStream({ name: 'San Francisco' }, { runId: run.runId })
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Parameters
|
|
32
|
+
|
|
33
|
+
**options** (`AgentListSuspendedRunsOptions`): Filters and pagination for scoping the results. (Default: `{}`)
|
|
34
|
+
|
|
35
|
+
**options.threadId** (`string`): Only return runs that belong to this memory thread.
|
|
36
|
+
|
|
37
|
+
**options.resourceId** (`string`): Only return runs that belong to this memory resource.
|
|
38
|
+
|
|
39
|
+
**options.fromDate** (`Date`): Only return runs created at or after this date.
|
|
40
|
+
|
|
41
|
+
**options.toDate** (`Date`): Only return runs created at or before this date.
|
|
42
|
+
|
|
43
|
+
**options.perPage** (`number`): Number of items per page. Pagination is applied when both perPage and page are provided; otherwise all matching runs are returned.
|
|
44
|
+
|
|
45
|
+
**options.page** (`number`): Zero-indexed page number.
|
|
46
|
+
|
|
47
|
+
## Returns
|
|
48
|
+
|
|
49
|
+
**result** (`Promise<AgentListSuspendedRunsResult>`): A promise that resolves to the matching runs and the total count before pagination.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
interface AgentListSuspendedRunsResult {
|
|
53
|
+
runs: AgentRun[]
|
|
54
|
+
/** Total number of matching runs, before pagination */
|
|
55
|
+
total: number
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface AgentRun {
|
|
59
|
+
/** Run ID accepted by resumeStream(), approveToolCall(), and declineToolCall() */
|
|
60
|
+
runId: string
|
|
61
|
+
status: 'suspended'
|
|
62
|
+
threadId?: string
|
|
63
|
+
resourceId?: string
|
|
64
|
+
/** When the run suspended */
|
|
65
|
+
suspendedAt: Date
|
|
66
|
+
/** Suspended tool calls awaiting approval or resume data */
|
|
67
|
+
toolCalls: AgentRunToolCall[]
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface AgentRunToolCall {
|
|
71
|
+
toolCallId?: string
|
|
72
|
+
toolName?: string
|
|
73
|
+
/** Arguments the model supplied (approval suspensions only) */
|
|
74
|
+
args?: unknown
|
|
75
|
+
/** True when the run is waiting on a tool-call approval */
|
|
76
|
+
requiresApproval: boolean
|
|
77
|
+
/** The tool-defined suspend payload when the tool called suspend() */
|
|
78
|
+
suspendPayload?: unknown
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Discovery scope
|
|
83
|
+
|
|
84
|
+
Results are scoped to runs started by the agent you call `listSuspendedRuns()` on: snapshots persist the owning agent's id, so runs started by other agents on the same Mastra instance are not returned. In [supervisor setups](https://mastra.ai/docs/agents/agent-approval) the supervisor sees its outer run — the one to resume — while a subagent's inner run is only visible from the subagent itself. Filter by `threadId` and `resourceId` to scope results to one conversation.
|
|
85
|
+
|
|
86
|
+
Run snapshots are only persisted while a run is waiting on input and are deleted when it finishes, so suspended runs are the only runs discoverable from storage. Suspended runs only survive restarts when the Mastra instance has a persistent [storage provider](https://mastra.ai/docs/memory/storage) configured. With the default in-memory store, snapshots are lost on restart.
|
|
87
|
+
|
|
88
|
+
## Related
|
|
89
|
+
|
|
90
|
+
- [Agent approval](https://mastra.ai/docs/agents/agent-approval)
|
|
91
|
+
- [Storage](https://mastra.ai/docs/memory/storage)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# ChannelProvider
|
|
2
|
+
|
|
3
|
+
`ChannelProvider` is the interface that platform integrations implement to connect agents to a messaging platform. A provider owns the full lifecycle of an integration: app provisioning and OAuth, webhook routing and event handling, adapter creation and agent wiring, and credential management.
|
|
4
|
+
|
|
5
|
+
Register providers on the `Mastra` constructor under `channels`, keyed by an id you choose. Each provider's routes are merged into the server's API routes automatically, and `initialize()` runs during Mastra startup.
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { Mastra } from '@mastra/core/mastra'
|
|
9
|
+
import { SlackProvider } from '@mastra/slack'
|
|
10
|
+
|
|
11
|
+
export const mastra = new Mastra({
|
|
12
|
+
channels: {
|
|
13
|
+
slack: new SlackProvider({
|
|
14
|
+
refreshToken: process.env.SLACK_REFRESH_TOKEN!,
|
|
15
|
+
baseUrl: process.env.MASTRA_BASE_URL,
|
|
16
|
+
}),
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The provider's `baseUrl` is the public URL the platform sends webhooks and events to. In production this is your deployed Mastra server URL. For local development, the platform can't reach `http://localhost:4111`, so run a tunnel (such as [cloudflared](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/) or [ngrok](https://ngrok.com/)) and point `baseUrl` at the tunnel URL (for example `https://abc123.trycloudflare.com`) so events reach your local dev process.
|
|
22
|
+
|
|
23
|
+
[`SlackProvider`](https://mastra.ai/reference/channels/slack-provider) is the first built-in implementation. Build a custom provider by implementing this interface.
|
|
24
|
+
|
|
25
|
+
## Properties
|
|
26
|
+
|
|
27
|
+
**id** (`string`): Unique identifier for this channel type, for example 'slack' or 'discord'. Used as the key when routing events and looking the provider up from Mastra.
|
|
28
|
+
|
|
29
|
+
## Methods
|
|
30
|
+
|
|
31
|
+
**getRoutes** (`() => ApiRoute[]`): Returns the API routes for this channel (OAuth, webhooks, events). These are merged into the server's apiRoutes automatically.
|
|
32
|
+
|
|
33
|
+
**initialize** (`() => Promise<void>`): Called during Mastra initialization after all agents are registered. Use it for async setup such as restoring active installations. Does not provision new apps.
|
|
34
|
+
|
|
35
|
+
**configure** (`(credentials: Record<string, unknown> | null) => void | Promise<void>`): Provides or clears platform credentials at runtime. Pass null to clear credentials and delete stored tokens.
|
|
36
|
+
|
|
37
|
+
**getInfo** (`() => ChannelPlatformInfo`): Returns discovery metadata for the editor UI: platform name, configuration status, and the connect options schema.
|
|
38
|
+
|
|
39
|
+
**connect** (`(agentId: string, options?: Record<string, unknown>) => Promise<ChannelConnectResult>`): Connects an agent to the platform. Returns a discriminated result describing the authorization flow required to finish the connection.
|
|
40
|
+
|
|
41
|
+
**disconnect** (`(agentId: string) => Promise<void>`): Disconnects an agent from the platform. Deletes the platform app and cleans up stored state.
|
|
42
|
+
|
|
43
|
+
**listInstallations** (`() => Promise<ChannelInstallationInfo[]>`): Lists active installations for this platform. Returns public info only, never secrets.
|
|
44
|
+
|
|
45
|
+
## Accessing a provider
|
|
46
|
+
|
|
47
|
+
Access a registered provider through the `channels` getter, keyed by the id you registered it under. The getter is typed from the constructor config, so `mastra.channels.slack` is the concrete provider with its full method surface.
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
await mastra.channels.slack.configure({ refreshToken })
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
When the key is only known at runtime, look the provider up by string id instead. `getChannelProvider` takes the concrete type as a generic, and `getChannelProviders` returns every registered provider keyed by id.
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import type { SlackProvider } from '@mastra/slack'
|
|
57
|
+
|
|
58
|
+
const slack = mastra.getChannelProvider<SlackProvider>('slack')
|
|
59
|
+
const all = mastra.getChannelProviders()
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Related
|
|
63
|
+
|
|
64
|
+
- [SlackProvider](https://mastra.ai/reference/channels/slack-provider)
|
|
65
|
+
- [Channels](https://mastra.ai/docs/agents/channels)
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# SlackProvider
|
|
2
|
+
|
|
3
|
+
`SlackProvider` is the managed path for connecting agents to Slack. Register it on `Mastra.channels` and it provisions Slack apps via the Manifest API, runs the OAuth install flow, rotates configuration tokens, and routes Slack events to your agents. Use it when you want Mastra to own app creation and installation. For the lower-level path where you create the Slack app and configure scopes and webhooks yourself, use [`createSlackAdapter`](https://mastra.ai/docs/agents/channels) on the agent's `channels.adapters` instead.
|
|
4
|
+
|
|
5
|
+
## Usage example
|
|
6
|
+
|
|
7
|
+
Register the provider on the `Mastra` constructor. The refresh token is single-use and rotates on startup; the resulting access tokens are persisted to `Mastra.storage`.
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { Mastra } from '@mastra/core/mastra'
|
|
11
|
+
import { SlackProvider } from '@mastra/slack'
|
|
12
|
+
|
|
13
|
+
export const mastra = new Mastra({
|
|
14
|
+
storage,
|
|
15
|
+
channels: {
|
|
16
|
+
slack: new SlackProvider({
|
|
17
|
+
refreshToken: process.env.SLACK_APP_CONFIG_REFRESH_TOKEN,
|
|
18
|
+
baseUrl: process.env.MASTRA_BASE_URL,
|
|
19
|
+
}),
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
When credentials aren't available at construction time (for example, entered through the Editor UI or loaded from a vault), construct the provider without them and call [`configure()`](#configurecredentials) later:
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
const slack = new SlackProvider()
|
|
28
|
+
|
|
29
|
+
await slack.configure({
|
|
30
|
+
refreshToken: process.env.SLACK_APP_CONFIG_REFRESH_TOKEN,
|
|
31
|
+
})
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Constructor parameters
|
|
35
|
+
|
|
36
|
+
`SlackProviderConfig` combines Slack-specific fields, Slack-adapter overrides (`toolDisplay`, `streaming`, `typingStatus`), and a curated subset of [`ChannelConfig`](https://mastra.ai/reference/agents/channels) options (such as `handlers`, `inlineMedia`, and `state`) forwarded to every connected agent. All fields are optional.
|
|
37
|
+
|
|
38
|
+
**refreshToken** (`string`): Slack App Configuration refresh token, used for automatic token rotation. Single-use; each rotation returns a new pair. Can also be provided later via \`configure()\`. If omitted, the provider starts unconfigured and cannot create apps until \`configure()\` is called or tokens are loaded from storage. Generate it under "Your App Configuration Tokens" at api.slack.com/apps.
|
|
39
|
+
|
|
40
|
+
**token** (`string`): Slack App Configuration access token for programmatic app creation. Optional, because the provider rotates to a fresh token on startup using \`refreshToken\`.
|
|
41
|
+
|
|
42
|
+
**baseUrl** (`string`): Public base URL for webhook and OAuth callbacks. Required when calling \`connect()\` to create apps. Can also be set via \`setBaseUrl()\` or auto-detected from the Mastra server config. For local development, use a tunnel such as \`cloudflared\`.
|
|
43
|
+
|
|
44
|
+
**encryptionKey** (`string`): Encryption key for sensitive stored data (client secret, signing secret, bot token). Use a 32+ character random string. Can be set via the \`MASTRA\_ENCRYPTION\_KEY\` env var. If omitted, secrets are stored in plaintext (not recommended for production).
|
|
45
|
+
|
|
46
|
+
**storage** (`ChannelsStorage`): Custom storage for installations. Defaults to Mastra's \`ChannelsStorage\` from the global storage. Throws if no persistent storage is available.
|
|
47
|
+
|
|
48
|
+
**redirectPath** (`string`): Path to redirect to after OAuth completion. (Default: `"/"`)
|
|
49
|
+
|
|
50
|
+
**onInstall** (`(installation: SlackInstallation) => Promise<void>`): Called when a workspace successfully installs the app.
|
|
51
|
+
|
|
52
|
+
**streaming** (`StreamingConfig | false`): Stream agent text deltas to Slack as they're generated. Pass \`{ updateIntervalMs }\` to customize the post-and-edit interval, or \`false\` to buffer text until step-finish. Disabling streaming restricts \`toolDisplay\` to static modes. (Default: `true`)
|
|
53
|
+
|
|
54
|
+
**toolDisplay** (`ToolDisplay`): How tool calls are rendered in Slack: \`'cards'\`, \`'text'\`, \`'timeline'\`, \`'grouped'\`, \`'hidden'\`, or a function. \`'hidden'\` suppresses tool call/result rendering entirely. \`'timeline'\` and \`'grouped'\` require streaming. With \`streaming: false\`, only static modes are available and the default is \`'cards'\`. (Default: `'grouped'`)
|
|
55
|
+
|
|
56
|
+
**typingStatus** (`boolean | TypingStatusFn`): Show a typing indicator while the agent works. Set \`false\` to disable, or pass a function to return custom status text per stream chunk (return \`undefined\` to fall back to the default for that chunk). (Default: `true`)
|
|
57
|
+
|
|
58
|
+
**waitUntil** (`WaitUntilFn`): Returns a \`waitUntil\` for the current Slack webhook request. Required on serverless runtimes where Hono can't bridge the platform's \`ExecutionContext\` (Vercel, AWS Lambda). Without it, the invocation freezes after the 200 ack and kills the run mid-flight. Pass the bare \`waitUntil(promise)\` from your platform SDK (for example, \`@vercel/functions\`). Cloudflare Workers and Netlify users typically don't need this.
|
|
59
|
+
|
|
60
|
+
**resolveWaitUntil** (`WaitUntilResolver`): Resolve \`waitUntil\` from the request's Hono \`Context\` when the runtime exposes it through the request and core's default doesn't cover it. Resolution order: \`waitUntil\` → \`resolveWaitUntil\` → core default.
|
|
61
|
+
|
|
62
|
+
**handlers** (`ChannelHandlers`): Override built-in event handlers (\`onDirectMessage\`, \`onMention\`). Forwarded to \`AgentChannels\` for every agent connected via this provider.
|
|
63
|
+
|
|
64
|
+
**inlineMedia** (`ChannelConfig['inlineMedia']`): Which media types to send inline to the model.
|
|
65
|
+
|
|
66
|
+
**inlineLinks** (`ChannelConfig['inlineLinks']`): Promote URLs in message text to file parts.
|
|
67
|
+
|
|
68
|
+
**threadContext** (`ChannelConfig['threadContext']`): Fetch recent thread messages from Slack when the agent joins mid-conversation.
|
|
69
|
+
|
|
70
|
+
**tools** (`ChannelConfig['tools']`): Whether to include channel tools (\`add\_reaction\`, \`remove\_reaction\`).
|
|
71
|
+
|
|
72
|
+
**state** (`ChannelConfig['state']`): State adapter for message deduplication, locking, and subscriptions. Defaults to the \`MastraStateAdapter\` backed by the Mastra instance's configured storage, so subscriptions persist across restarts.
|
|
73
|
+
|
|
74
|
+
**chatOptions** (`ChannelConfig['chatOptions']`): Additional options passed directly to the Chat SDK.
|
|
75
|
+
|
|
76
|
+
**logger** (`SlackAdapterConfig['logger']`): Logger forwarded to the underlying \`SlackAdapter\`. Defaults to the adapter's \`ConsoleLogger\`.
|
|
77
|
+
|
|
78
|
+
## Methods
|
|
79
|
+
|
|
80
|
+
### Agent connections
|
|
81
|
+
|
|
82
|
+
#### `connect(agentId, options?)`
|
|
83
|
+
|
|
84
|
+
Creates a new Slack app for the agent via the Manifest API and returns an OAuth result with the authorization URL to redirect the user to. Requires `baseUrl` to be set. If a pending installation already exists for the agent, returns its existing authorization URL instead of creating a duplicate app.
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
const result = await slack.connect('support-agent', {
|
|
88
|
+
name: 'Support Bot',
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
// Redirect the user to result.authorizationUrl to install the app
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Returns: `Promise<ChannelConnectResult>`
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
interface ChannelConnectResult {
|
|
98
|
+
type: 'oauth'
|
|
99
|
+
installationId: string
|
|
100
|
+
authorizationUrl: string
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`SlackConnectOptions` is serializable and can be stored for stored agents:
|
|
105
|
+
|
|
106
|
+
**name** (`string`): Display name for the Slack bot. Defaults to the agent name, then the agent ID.
|
|
107
|
+
|
|
108
|
+
**description** (`string`): Bot description shown in Slack. Defaults to "{name} - Powered by Mastra".
|
|
109
|
+
|
|
110
|
+
**iconUrl** (`string`): URL to a square image (min 512x512) for the app icon. Downloaded and uploaded to Slack automatically.
|
|
111
|
+
|
|
112
|
+
**manifest** (`(defaults: SlackAppManifest) => SlackAppManifest`): Customize the Slack app manifest before it is sent to the Manifest API. Receives the default manifest and returns the final one. Use it for custom scopes, additional events, or interactivity settings.
|
|
113
|
+
|
|
114
|
+
**redirectUrl** (`string`): URL to redirect to after successful OAuth completion. Defaults to the provider's \`redirectPath\` or \`/\`.
|
|
115
|
+
|
|
116
|
+
#### `disconnect(agentId)`
|
|
117
|
+
|
|
118
|
+
Disconnects an agent from Slack by deleting its app and removing the installation from storage.
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
await slack.disconnect('support-agent')
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Returns: `Promise<void>`
|
|
125
|
+
|
|
126
|
+
#### `getInstallation(agentId)`
|
|
127
|
+
|
|
128
|
+
Returns the Slack installation for an agent, or `null` if none exists.
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
const installation = await slack.getInstallation('support-agent')
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Returns: `Promise<SlackInstallation | null>`
|
|
135
|
+
|
|
136
|
+
#### `listInstallations()`
|
|
137
|
+
|
|
138
|
+
Lists all Slack installations (public info only), including active and pending.
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
const installations = await slack.listInstallations()
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Returns: `Promise<ChannelInstallationInfo[]>`
|
|
145
|
+
|
|
146
|
+
### Configuration
|
|
147
|
+
|
|
148
|
+
#### `configure(credentials)`
|
|
149
|
+
|
|
150
|
+
Provides or clears Slack App Configuration credentials at runtime. Use this when credentials aren't available at construction time. Pass `null` to clear credentials and delete stored tokens.
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
// Provide credentials (persists to storage immediately)
|
|
154
|
+
await slack.configure({ refreshToken: 'xoxe-1-...' })
|
|
155
|
+
|
|
156
|
+
// Clear credentials and stored tokens
|
|
157
|
+
await slack.configure(null)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Returns: `Promise<void>`
|
|
161
|
+
|
|
162
|
+
#### `setBaseUrl(baseUrl)`
|
|
163
|
+
|
|
164
|
+
Sets the public base URL used for webhook and OAuth callbacks. Use this when the URL isn't known at construction time and can't be auto-detected from the server config.
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
slack.setBaseUrl('https://abc123.trycloudflare.com')
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
#### `initialize()`
|
|
171
|
+
|
|
172
|
+
Recreates a `SlackAdapter` for each active installation in storage and injects `AgentChannels` into the corresponding agent so it receives Slack events on startup. Does not auto-provision new apps; use `connect()` to create one. Mastra calls this automatically, so you rarely call it directly.
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
await slack.initialize()
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Returns: `Promise<void>`
|
|
179
|
+
|
|
180
|
+
## Default manifest
|
|
181
|
+
|
|
182
|
+
When `connect()` builds a Slack app, the generated manifest requests a default set of bot scopes and event subscriptions. Override them with the `manifest` option on `connect()`.
|
|
183
|
+
|
|
184
|
+
| Default bot scopes | Default bot events |
|
|
185
|
+
| ------------------- | ------------------ |
|
|
186
|
+
| `chat:write` | `app_mention` |
|
|
187
|
+
| `chat:write.public` | `message.channels` |
|
|
188
|
+
| `im:write` | `message.groups` |
|
|
189
|
+
| `channels:history` | `message.im` |
|
|
190
|
+
| `channels:read` | `message.mpim` |
|
|
191
|
+
| `groups:history` | |
|
|
192
|
+
| `groups:read` | |
|
|
193
|
+
| `im:history` | |
|
|
194
|
+
| `im:read` | |
|
|
195
|
+
| `mpim:history` | |
|
|
196
|
+
| `mpim:read` | |
|
|
197
|
+
| `app_mentions:read` | |
|
|
198
|
+
| `users:read` | |
|
|
199
|
+
| `reactions:write` | |
|
|
200
|
+
| `files:read` | |
|
|
201
|
+
| `assistant:write` | |
|
|
202
|
+
|
|
203
|
+
## Accessing the provider
|
|
204
|
+
|
|
205
|
+
Access the registered provider through the typed `channels` getter, keyed by the id you registered it under:
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
const result = await mastra.channels.slack.connect('support-agent')
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
When the key is only known at runtime, look it up by string id and pass the concrete type:
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
const slack = mastra.getChannelProvider<SlackProvider>('slack')
|
|
215
|
+
const result = await slack.connect('support-agent')
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Storage requirement
|
|
219
|
+
|
|
220
|
+
`SlackProvider` requires persistent storage on `Mastra` to encrypt and persist installations and rotating configuration tokens. The constructor throws if no persistent storage is available and no custom `storage` is passed.
|
|
221
|
+
|
|
222
|
+
## Related
|
|
223
|
+
|
|
224
|
+
- [ChannelProvider](https://mastra.ai/reference/channels/channel-provider): the interface `SlackProvider` implements
|
|
225
|
+
- [Channels](https://mastra.ai/docs/agents/channels): concepts, platform setup, and the `createSlackAdapter` path
|
|
226
|
+
- [Channels reference](https://mastra.ai/reference/agents/channels): the `channels` config on the `Agent` constructor
|
|
@@ -362,6 +362,27 @@ response.processDataStream({
|
|
|
362
362
|
})
|
|
363
363
|
```
|
|
364
364
|
|
|
365
|
+
### `listSuspendedRuns()`
|
|
366
|
+
|
|
367
|
+
List suspended runs for the agent from storage — runs waiting on a tool-call approval or on a tool that suspended. Discovery is backed by storage, so it works after a server restart and across server instances. Pass the returned `runId` to `approveToolCall()`, `declineToolCall()`, or `resumeStream()`.
|
|
368
|
+
|
|
369
|
+
```typescript
|
|
370
|
+
const { runs, total } = await agent.listSuspendedRuns({
|
|
371
|
+
threadId: 'thread-456',
|
|
372
|
+
resourceId: 'user-123',
|
|
373
|
+
})
|
|
374
|
+
|
|
375
|
+
if (runs[0]) {
|
|
376
|
+
console.log(runs[0].toolCalls) // [{ toolCallId, toolName, args, requiresApproval }]
|
|
377
|
+
await agent.approveToolCall({
|
|
378
|
+
runId: runs[0].runId,
|
|
379
|
+
toolCallId: runs[0].toolCalls[0].toolCallId,
|
|
380
|
+
})
|
|
381
|
+
}
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
Accepts optional filters (`threadId`, `resourceId`, `fromDate`, `toDate`) and pagination (`perPage`, `page`). Returns `{ runs, total }`, where `total` is the number of matching runs before pagination. See [`Agent.listSuspendedRuns()`](https://mastra.ai/reference/agents/listSuspendedRuns) for details on the returned run shape.
|
|
385
|
+
|
|
365
386
|
### `approveToolCall()`
|
|
366
387
|
|
|
367
388
|
Approve a pending tool call and return a continuation stream. Use this when you are rendering the resumed chunks from the approval response.
|
package/.docs/reference/index.md
CHANGED
|
@@ -4,6 +4,8 @@ The Reference section provides documentation of Mastra's API, including paramete
|
|
|
4
4
|
|
|
5
5
|
- [AcpAgent](https://mastra.ai/reference/acp/acp-agent)
|
|
6
6
|
- [createACPTool()](https://mastra.ai/reference/acp/create-acp-tool)
|
|
7
|
+
- [AgentController Class](https://mastra.ai/reference/agent-controller/agent-controller-class)
|
|
8
|
+
- [Session Class](https://mastra.ai/reference/agent-controller/session)
|
|
7
9
|
- [Agent Class](https://mastra.ai/reference/agents/agent)
|
|
8
10
|
- [Channels](https://mastra.ai/reference/agents/channels)
|
|
9
11
|
- [createInngestAgent()](https://mastra.ai/reference/agents/inngest-agent)
|
|
@@ -26,6 +28,7 @@ The Reference section provides documentation of Mastra's API, including paramete
|
|
|
26
28
|
- [.listAgents()](https://mastra.ai/reference/agents/listAgents)
|
|
27
29
|
- [.listScorers()](https://mastra.ai/reference/agents/listScorers)
|
|
28
30
|
- [.listSkills()](https://mastra.ai/reference/agents/listSkills)
|
|
31
|
+
- [.listSuspendedRuns()](https://mastra.ai/reference/agents/listSuspendedRuns)
|
|
29
32
|
- [.listTools()](https://mastra.ai/reference/agents/listTools)
|
|
30
33
|
- [.listWorkflows()](https://mastra.ai/reference/agents/listWorkflows)
|
|
31
34
|
- [.network()](https://mastra.ai/reference/agents/network)
|
|
@@ -54,6 +57,8 @@ The Reference section provides documentation of Mastra's API, including paramete
|
|
|
54
57
|
- [BrowserViewer](https://mastra.ai/reference/browser/browser-viewer)
|
|
55
58
|
- [MastraBrowser Class](https://mastra.ai/reference/browser/mastra-browser)
|
|
56
59
|
- [StagehandBrowser](https://mastra.ai/reference/browser/stagehand-browser)
|
|
60
|
+
- [ChannelProvider](https://mastra.ai/reference/channels/channel-provider)
|
|
61
|
+
- [SlackProvider](https://mastra.ai/reference/channels/slack-provider)
|
|
57
62
|
- [create-mastra](https://mastra.ai/reference/cli/create-mastra)
|
|
58
63
|
- [mastra](https://mastra.ai/reference/cli/mastra)
|
|
59
64
|
- [Agent Builder API](https://mastra.ai/reference/client-js/agent-builder)
|
|
@@ -165,8 +170,6 @@ The Reference section provides documentation of Mastra's API, including paramete
|
|
|
165
170
|
- [.startExperimentAsync()](https://mastra.ai/reference/datasets/startExperimentAsync)
|
|
166
171
|
- [.update()](https://mastra.ai/reference/datasets/update)
|
|
167
172
|
- [.updateItem()](https://mastra.ai/reference/datasets/updateItem)
|
|
168
|
-
- [Harness Class](https://mastra.ai/reference/harness/harness-class)
|
|
169
|
-
- [Session Class](https://mastra.ai/reference/harness/session)
|
|
170
173
|
- [API Reference](https://mastra.ai/reference/mastra-platform/api)
|
|
171
174
|
- [Cloned Thread Utilities](https://mastra.ai/reference/memory/clone-utilities)
|
|
172
175
|
- [Memory Class](https://mastra.ai/reference/memory/memory-class)
|
|
@@ -209,6 +212,7 @@ The Reference section provides documentation of Mastra's API, including paramete
|
|
|
209
212
|
- [CachingPubSub](https://mastra.ai/reference/pubsub/caching-pubsub)
|
|
210
213
|
- [EventEmitterPubSub](https://mastra.ai/reference/pubsub/event-emitter)
|
|
211
214
|
- [GoogleCloudPubSub](https://mastra.ai/reference/pubsub/google-cloud-pubsub)
|
|
215
|
+
- [LeaseProvider](https://mastra.ai/reference/pubsub/lease-provider)
|
|
212
216
|
- [PubSub](https://mastra.ai/reference/pubsub/base)
|
|
213
217
|
- [RedisStreamsPubSub](https://mastra.ai/reference/pubsub/redis-streams)
|
|
214
218
|
- [UnixSocketPubSub](https://mastra.ai/reference/pubsub/unix-socket-pubsub)
|
|
@@ -13,7 +13,7 @@ Metrics are extracted from spans when they end. The observability layer inspects
|
|
|
13
13
|
Two conditions must be true for a metric to reach storage:
|
|
14
14
|
|
|
15
15
|
1. `MastraStorageExporter` is configured as an exporter.
|
|
16
|
-
2. The storage backend supports metrics (ClickHouse or
|
|
16
|
+
2. The storage backend supports metrics (ClickHouse, DuckDB, or Postgres v-next with the observability domain enabled).
|
|
17
17
|
|
|
18
18
|
If metrics aren't available, see [troubleshooting](#troubleshooting).
|
|
19
19
|
|
|
@@ -116,7 +116,7 @@ When you spot a spike in latency or token usage on the Metrics dashboard, correl
|
|
|
116
116
|
|
|
117
117
|
- **Observability is configured**: Verify that your `Mastra` instance has an `observability` config with at least one exporter.
|
|
118
118
|
- **`MastraStorageExporter` or `MastraPlatformExporter` is present**: Other exporters (Datadog, Langfuse, etc.) don't surface metrics in Mastra. `MastraStorageExporter` is required for the local Studio dashboard, and `MastraPlatformExporter` is required to view metrics in Mastra platform.
|
|
119
|
-
- **Storage supports metrics**: Metrics require an
|
|
119
|
+
- **Storage supports metrics**: Metrics require an analytics-capable store (ClickHouse, DuckDB, or Postgres v-next with the observability domain enabled). Other row-oriented databases (LibSQL, MSSQL) and document stores (MongoDB) aren't supported for metrics.
|
|
120
120
|
- **Sampling isn't 0%**: If sampling probability is `0` or strategy is `never`, all spans become no-ops and no metrics are extracted.
|
|
121
121
|
|
|
122
122
|
### Duration metrics are missing
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# LeaseProvider
|
|
2
|
+
|
|
3
|
+
`LeaseProvider` is the distributed leasing contract, separate from event delivery ([`PubSub`](https://mastra.ai/reference/pubsub/base)). Mastra's [signals layer](https://mastra.ai/docs/agents/signals) uses it to elect a single owner across multiple processes (for example, serverless invocations) for a given resource, most commonly a thread key. The owner is the process that wakes and runs the agent stream, so other processes route follow-up work to it instead of starting a competing run.
|
|
4
|
+
|
|
5
|
+
Leasing is a distinct concern from pub/sub. A backend implements `LeaseProvider` only when it can genuinely coordinate a lock, such as Redis via atomic `SET`/Lua, or an in-memory map for single-process. Backends that cannot lease omit it; the signals runtime feature-detects the capability and falls back to a no-op provider, preserving single-process behavior.
|
|
6
|
+
|
|
7
|
+
The built-in [`RedisStreamsPubSub`](https://mastra.ai/reference/pubsub/redis-streams) implements `LeaseProvider`, which is what enables signals to coordinate across instances in distributed and serverless deployments.
|
|
8
|
+
|
|
9
|
+
## Usage example
|
|
10
|
+
|
|
11
|
+
You don't construct a `LeaseProvider` directly. Configure a pub/sub backend that implements it (such as `RedisStreamsPubSub`) on the `Mastra` constructor, and the signals runtime uses it automatically for cross-process coordination.
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Mastra } from '@mastra/core'
|
|
15
|
+
import { RedisStreamsPubSub } from '@mastra/redis-streams'
|
|
16
|
+
|
|
17
|
+
export const mastra = new Mastra({
|
|
18
|
+
// RedisStreamsPubSub implements both PubSub and LeaseProvider
|
|
19
|
+
pubsub: new RedisStreamsPubSub({
|
|
20
|
+
url: process.env.REDIS_URL,
|
|
21
|
+
}),
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
To implement leasing in a custom backend, implement the methods below. The signals runtime detects the capability structurally (so it works across package boundaries) and only uses it when all methods are present.
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { PubSub } from '@mastra/core/events'
|
|
29
|
+
import type { LeaseProvider } from '@mastra/core/events'
|
|
30
|
+
|
|
31
|
+
export class CustomPubSub extends PubSub implements LeaseProvider {
|
|
32
|
+
async acquireLease(key: string, owner: string, ttlMs: number) {
|
|
33
|
+
// Atomically claim the lease, or report the current holder.
|
|
34
|
+
return { acquired: true, owner }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ...getLeaseOwner, releaseLease, renewLease, transferLease
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Methods
|
|
42
|
+
|
|
43
|
+
### Leasing
|
|
44
|
+
|
|
45
|
+
#### `acquireLease(key, owner, ttlMs)`
|
|
46
|
+
|
|
47
|
+
Atomically tries to acquire a lease on a key. Returns `{ acquired: true, owner }` if the caller claimed the lease, or `{ acquired: false, owner }` where `owner` is the current holder, so the caller can route follow-up work to them. The same owner can call `acquireLease` idempotently to renew or re-claim.
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
const result = await pubsub.acquireLease('thread:abc', runId, 15000)
|
|
51
|
+
|
|
52
|
+
if (result.acquired) {
|
|
53
|
+
// This process owns the thread, so wake and run the agent.
|
|
54
|
+
} else {
|
|
55
|
+
// result.owner holds the lease, so route the signal to them.
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Returns: `Promise<{ acquired: boolean; owner?: string }>`
|
|
60
|
+
|
|
61
|
+
**key** (`string`): The lease key, such as a thread key.
|
|
62
|
+
|
|
63
|
+
**owner** (`string`): Identifier for the owner, such as a \`runId\`. The same owner can call \`acquireLease\` idempotently to renew or release.
|
|
64
|
+
|
|
65
|
+
**ttlMs** (`number`): Time-to-live in milliseconds for the lease.
|
|
66
|
+
|
|
67
|
+
#### `getLeaseOwner(key)`
|
|
68
|
+
|
|
69
|
+
Reads the current owner of a lease, or `undefined` if no lease is held.
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
const owner = await pubsub.getLeaseOwner('thread:abc')
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Returns: `Promise<string | undefined>`
|
|
76
|
+
|
|
77
|
+
#### `releaseLease(key, owner)`
|
|
78
|
+
|
|
79
|
+
Releases a lease. This is a no-op if the caller is not the current owner: implementations check ownership atomically before releasing, so a concurrent renewal by another owner is never clobbered.
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
await pubsub.releaseLease('thread:abc', runId)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Returns: `Promise<void>`
|
|
86
|
+
|
|
87
|
+
#### `renewLease(key, owner, ttlMs)`
|
|
88
|
+
|
|
89
|
+
Renews an existing lease owned by `owner`, extending its TTL. Returns `true` if the renewal succeeded and the caller still owns the lease, or `false` if the lease was lost (TTL expired or another owner took it).
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
const stillOwned = await pubsub.renewLease('thread:abc', runId, 15000)
|
|
93
|
+
|
|
94
|
+
if (!stillOwned) {
|
|
95
|
+
// Lost the lease, so stop renewing and let the new owner take over.
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Returns: `Promise<boolean>`
|
|
100
|
+
|
|
101
|
+
#### `transferLease(key, fromOwner, toOwner, ttlMs)`
|
|
102
|
+
|
|
103
|
+
Atomically hands a held lease from `fromOwner` to `toOwner`, refreshing its TTL, without releasing the key in between. This is the gap-free primitive used when one owner finishes but a follow-up owner must take over the same key immediately, for example when a thread run completes and a queued follow-up run drains on the same thread. A naive release-then-acquire would briefly leave the key empty, letting a racing process win the freed lease and start a competing run.
|
|
104
|
+
|
|
105
|
+
Returns `true` if `fromOwner` still held the lease and ownership moved to `toOwner`, or `false` if the lease was already lost, in which case the caller should fall back to a fresh `acquireLease`.
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
const transferred = await pubsub.transferLease('thread:abc', currentRunId, nextRunId, 15000)
|
|
109
|
+
|
|
110
|
+
if (!transferred) {
|
|
111
|
+
// Lease was lost, so acquire fresh instead.
|
|
112
|
+
await pubsub.acquireLease('thread:abc', nextRunId, 15000)
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Returns: `Promise<boolean>`
|
|
117
|
+
|
|
118
|
+
> **Warning:** Backends that cannot perform the transfer atomically must still implement it as a best-effort `releaseLease(fromOwner)` followed by `acquireLease(toOwner)`, and document that the swap is non-atomic, since a racing process can win the key in the gap. Keeping the method required means callers have a single code path and atomicity is an explicit per-backend decision.
|
|
119
|
+
|
|
120
|
+
## Capability detection
|
|
121
|
+
|
|
122
|
+
The signals runtime detects `LeaseProvider` structurally rather than with `instanceof`, so detection works even when a separately published backend resolves a different copy of `@mastra/core`. A value is treated as a `LeaseProvider` when it exposes all five methods (`acquireLease`, `getLeaseOwner`, `releaseLease`, `renewLease`, `transferLease`).
|
|
123
|
+
|
|
124
|
+
When the configured pub/sub backend does not implement `LeaseProvider`, the runtime falls back to an always-win no-op provider. Every caller wins its own lease race, and release, renew, and transfer are inert, which preserves the expected single-process behavior.
|
|
125
|
+
|
|
126
|
+
## Related
|
|
127
|
+
|
|
128
|
+
- [PubSub](https://mastra.ai/reference/pubsub/base): The event delivery contract, separate from leasing
|
|
129
|
+
- [RedisStreamsPubSub](https://mastra.ai/reference/pubsub/redis-streams): The built-in backend that implements `LeaseProvider`
|
|
130
|
+
- [Signals](https://mastra.ai/docs/agents/signals): The runtime that uses leasing to coordinate thread runs across processes
|
|
131
|
+
- [Channels](https://mastra.ai/docs/agents/channels): Uses leasing to coordinate agent runs in serverless and multi-instance deployments
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# RedisStreamsPubSub
|
|
2
2
|
|
|
3
|
-
`RedisStreamsPubSub` is a [`PubSub`](https://mastra.ai/reference/pubsub/base) implementation backed by [Redis Streams](https://redis.io/docs/latest/develop/data-types/streams/). It delivers events across processes and hosts, with persistence, consumer groups, and redelivery on failure.
|
|
3
|
+
`RedisStreamsPubSub` is a [`PubSub`](https://mastra.ai/reference/pubsub/base) implementation backed by [Redis Streams](https://redis.io/docs/latest/develop/data-types/streams/). It delivers events across processes and hosts, with persistence, consumer groups, and redelivery on failure. It also implements [`LeaseProvider`](https://mastra.ai/reference/pubsub/lease-provider), so the signals layer can elect a single owner per resource across instances, which is what lets signals coordinate runs in distributed and serverless deployments.
|
|
4
4
|
|
|
5
5
|
Use it for distributed deployments where several services share an event stream. For single-process delivery, use [`EventEmitterPubSub`](https://mastra.ai/reference/pubsub/event-emitter). For Google Cloud, use [`GoogleCloudPubSub`](https://mastra.ai/reference/pubsub/google-cloud-pubsub).
|
|
6
6
|
|
|
@@ -105,4 +105,12 @@ await pubsub.close()
|
|
|
105
105
|
|
|
106
106
|
## Redelivery and reclaim
|
|
107
107
|
|
|
108
|
-
When a subscriber calls `nack`, the event is republished with an incremented `deliveryAttempt` and the original is acknowledged. Once an event reaches `maxDeliveryAttempts`, it's dropped instead of redelivered. Separately, each subscription periodically reclaims events that an earlier consumer in the group read but never acknowledged, controlled by `reclaimIntervalMs` and `reclaimIdleMs`.
|
|
108
|
+
When a subscriber calls `nack`, the event is republished with an incremented `deliveryAttempt` and the original is acknowledged. Once an event reaches `maxDeliveryAttempts`, it's dropped instead of redelivered. Separately, each subscription periodically reclaims events that an earlier consumer in the group read but never acknowledged, controlled by `reclaimIntervalMs` and `reclaimIdleMs`.
|
|
109
|
+
|
|
110
|
+
## Distributed leasing
|
|
111
|
+
|
|
112
|
+
`RedisStreamsPubSub` implements the [`LeaseProvider`](https://mastra.ai/reference/pubsub/lease-provider) contract on top of the same Redis connection. The [signals runtime](https://mastra.ai/docs/agents/signals) uses it to elect a single owner (usually per thread key) so that across instances only one process wakes and runs the agent, and others route follow-up work to the holder. This is what makes signals work on serverless and multi-instance deployments; without a shared lease, each instance would start its own competing run.
|
|
113
|
+
|
|
114
|
+
Lease keys are namespaced under the same `keyPrefix` as topics, as `<keyPrefix>:lease:<key>`. All operations are atomic: `acquireLease` uses `SET NX PX` and refreshes its own TTL idempotently, while `releaseLease`, `renewLease`, and `transferLease` use Lua scripts that check ownership before mutating, so a concurrent renewal from another owner is never clobbered.
|
|
115
|
+
|
|
116
|
+
You don't call these methods directly. Configuring `RedisStreamsPubSub` as the `pubsub` backend is enough for the runtime to detect and use the capability. See [`LeaseProvider`](https://mastra.ai/reference/pubsub/lease-provider) for the full method contract.
|