Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/docs/content/docs/integrations/slack.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Custom-bot Slack triggers can stream workflow outputs directly back into the con
- Loop and parallel invocations each create their own Slack response.
- The response status label defaults to `Running` and can be customized in the trigger's advanced settings.
- Optional thinking and tool-call updates appear as Slack tasks in a timeline or plan.
- **Show progress from** (`streamTimelineSources`) shows an Agent's tool steps, and its thinking when enabled, without posting its text. Use it when an Agent's output is reviewed or reformatted by a later block: the steps and the first streamed answer share one Slack reply. Agents in child workflows can be selected. A block cannot be both an output to stream and a progress source.
- **Tool step labels** (`streamToolLabels`) renames tool steps by tool name, for example `lc_cur` → `Reading AWS cost data`. Unlisted tools use a generated name. Steps never show tool arguments.
- With PII block-output redaction on, Agent output is not streamed live, so no progress steps appear; selected outputs are still sent when their block completes.
- Slack Agent Sessions remain in processing state for the run, return to active when it finishes, and the native Slack stop button cancels active workflow executions.

Automatic trigger responses require a custom bot created by the Slack setup wizard. They are not available with the shared Sim Slack app. Where the deployment enables shared-app triggers, the Sim app can receive its subscribed event subset without automatic streaming.
Expand Down Expand Up @@ -3867,6 +3870,8 @@ Trigger from Slack events, interactions, and slash commands
| `threads` | string | No | Include thread replies, exclude them \(top-level only\), or fire only on thread replies. |
| `streamResponse` | boolean | No | Create a Slack agent session and stream selected workflow outputs into the conversation that started this run. Custom bots only. |
| `streamOutputs` | workflow-output-selector | No | Use `<blockName>.<outputPath>` for this workflow or `<childWorkflowId>.<blockName>.<outputPath>` for a child workflow. Selecting a child workflow applies to every invocation of it. Agent outputs stream live; other outputs are sent when the block completes. |
| `streamTimelineSources` | workflow-output-selector | No | Agent blocks, including ones in child workflows, whose tool steps appear in the reply while they run. Their text is never posted. No steps appear when PII block-output redaction is on. |
| `streamToolLabels` | table | No | Optional names for tool steps, keyed by tool name \(an MCP tool by its own name, like lc_cur\). Unlisted tools use a generated name. |
| `streamTaskTitle` | string | No | Optional status Slack shows while each selected response is being produced. Leave empty to use Running. |
| `streamTaskDisplayMode` | string | No | Choose how Slack displays thinking and tool progress. |
| `streamIncludeThinking` | boolean | No | Show agent thinking as Slack task updates while the response is generated. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
buildWorkflowOutputMenu,
buildWorkflowOutputOptions,
collectReferencedWorkflowIds,
selectBlockPathOptions,
type WorkflowOutputMenuNode,
type WorkflowOutputOption,
} from '@/lib/workflows/streaming/nested-output-options'
Expand Down Expand Up @@ -42,6 +43,8 @@ interface OutputSelectProps {
disabled?: boolean
/** Placeholder text when no outputs are selected */
placeholder?: string
/** Offers one option per block of this type, selecting this output path */
outputFilter?: { blockType: string; path: string }
/** Whether to emit internal IDs, display labels, or public dot selectors */
valueMode?: 'id' | 'label' | 'public'
/** Alignment of the dropdown relative to the trigger */
Expand Down Expand Up @@ -127,6 +130,7 @@ function OutputSelectContent({
onOutputSelect,
disabled = false,
placeholder = 'Select outputs',
outputFilter,
valueMode = 'id',
align = 'start',
maxHeight = 200,
Expand Down Expand Up @@ -206,14 +210,17 @@ function OutputSelectContent({
const thirdLevelStates = useWorkflowStates(thirdLevelWorkflowIds)

const workflowStates = new Map([...firstLevelStates, ...secondLevelStates, ...thirdLevelStates])
const workflowOutputs = workflowId
const allWorkflowOutputs = workflowId
? buildWorkflowOutputOptions({
rootWorkflowId: workflowId,
rootState,
workflowStates,
maxChildDepth: DEFAULTS.MAX_SSE_CHILD_DEPTH,
})
: []
const workflowOutputs = outputFilter
? selectBlockPathOptions(allWorkflowOutputs, outputFilter.blockType, outputFilter.path)
: allWorkflowOutputs
const outputMenu = buildWorkflowOutputMenu(workflowOutputs)
const outputMenuRevision = JSON.stringify([
workflowId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface WorkflowOutputSelectorProps {
previewValue?: string[] | null
disabled?: boolean
placeholder?: string
outputFilter?: { blockType: string; path: string }
}

export function WorkflowOutputSelector({
Expand All @@ -20,6 +21,7 @@ export function WorkflowOutputSelector({
previewValue,
disabled = false,
placeholder,
outputFilter,
}: WorkflowOutputSelectorProps) {
const workflowId = useWorkflowRegistry((state) => state.activeWorkflowId)
const [storedValue, setStoredValue] = useSubBlockValue<string[]>(blockId, subBlockId)
Expand All @@ -34,6 +36,7 @@ export function WorkflowOutputSelector({
onOutputSelect={setStoredValue}
disabled={disabled || isPreview}
placeholder={placeholder}
outputFilter={outputFilter}
valueMode='public'
size='md'
className='w-full'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,7 @@ function SubBlockComponent({
previewValue={previewValue as string[] | null | undefined}
disabled={isDisabled}
placeholder={config.placeholder}
outputFilter={config.outputFilter}
/>
)

Expand Down
1 change: 1 addition & 0 deletions apps/sim/blocks/blocks/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3551,6 +3551,7 @@ export const SlackV2Block: BlockConfig = {
'Build Slack workflows with messages, conversations, files, reactions, pins, bookmarks, user groups, profiles, Lists, canvases, and Agent Sessions. Operations that need additional app scopes use custom Slack bots. Lists require lists:read/lists:write and a paid Slack plan. Native Sim connections retain their existing permissions. Page through list outputs explicitly.',
bestPractices: `${SlackBlock.bestPractices}
Native agent-session streaming uses a custom Slack bot and a supported trigger event. Enable streamResponse and select the intended outputs in streamOutputs; Sim Chat (mothership) streams its content output. The trigger owns the streamed reply, so another send needs a separate purpose.
To show an Agent's tool steps without posting its text (for example an analyst whose output a later block reviews), list that Agent in streamTimelineSources while streamOutputs keeps the block that posts the answer (a block cannot be in both), and optionally name its tools in streamToolLabels.
The custom-bot manifest's baseline agent scopes are ${SLACK_AGENT_SCOPES.join(', ')}. Selected capabilities add their required scopes and event subscriptions. Verify the installed app's grants, resource access and event configuration; a saved credential or edited manifest alone does not prove access.
streamIncludeToolCalls displays tool activity; it does not authorize tool execution. Configure Sim Chat's selected operations and their credentials separately. Choose streamIncludeThinking deliberately for the destination audience.
Block Kit messages can contain buttons, selects and forms, but interactions require the app's interactivity request URL and the corresponding interaction trigger. Treat message events, button/select callbacks and modal submissions as separate paths. A control's action_id/value correlates work; runtime actor and state checks authorize it.`,
Expand Down
2 changes: 2 additions & 0 deletions apps/sim/blocks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ export interface SubBlockConfig {
min?: number
max?: number
columns?: string[]
/** Limits a `workflow-output-selector` to blocks of one type, each selecting `path`. */
outputFilter?: { blockType: string; path: string }
placeholder?: string
/**
* Conceals the stored value in the editor until the field is focused.
Expand Down
4 changes: 3 additions & 1 deletion apps/sim/lib/mothership/tools/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,9 @@ export function getToolDisplayTitle(name: string, args?: Record<string, unknown>
}
}

return TOOL_TITLES[name] ?? CLI_TOOL_TITLES[name] ?? humanizeToolName(name)
if (Object.hasOwn(TOOL_TITLES, name)) return TOOL_TITLES[name]
if (Object.hasOwn(CLI_TOOL_TITLES, name)) return CLI_TOOL_TITLES[name]
return humanizeToolName(name)
}

/** First positional after the synthetic CLI command path; shared by resource and operation labels. */
Expand Down
209 changes: 209 additions & 0 deletions apps/sim/lib/webhooks/slack-execution-stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const BASE_CONFIG: SlackStreamResponseConfig = {
includeToolCalls: true,
taskTitle: 'Running',
taskDisplayMode: 'plan',
timelineSources: [],
toolLabels: {},
}

function createLoggingSession() {
Expand Down Expand Up @@ -729,6 +731,213 @@ describe('SlackExecutionStreamController', () => {
controller.assertSucceeded()
})

describe('timeline sources', () => {
const TIMELINE_CONFIG: SlackStreamResponseConfig = {
...BASE_CONFIG,
outputConfigs: [{ blockId: 'reply', path: 'result' }],
timelineSources: [{ workflowId: 'child-workflow', blockId: 'analyst' }],
toolLabels: { lc_cur: 'Reading AWS cost data' },
}
const TIMELINE_EVENTS: AgentStreamEvent[] = [
{ type: 'tool_call_start', id: 'tool-1', name: 'mcp-6da535c1-lc_cur' },
{ type: 'tool_call_end', id: 'tool-1', name: 'mcp-6da535c1-lc_cur', status: 'success' },
{ type: 'tool_call_start', id: 'tool-2', name: 'mcp-6da535c1-lc_other' },
{ type: 'tool_call_end', id: 'tool-2', name: 'mcp-6da535c1-lc_other', status: 'success' },
{ type: 'text_delta', text: '{"secret":"analyst json"}', turn: 'pending' },
{ type: 'turn_end', turn: 'final' },
]

async function streamTimeline(
controller: SlackExecutionStreamController,
events: AgentStreamEvent[] = TIMELINE_EVENTS
) {
await controller.callbacks.onStream?.({
blockId: 'child-workflow.analyst',
childWorkflowInstanceId: 'child-instance-1',
executionOrder: 2,
stream: createByteStream('{"secret":"analyst json"}'),
execution: { success: true, output: {} },
clientStreamTransformed: false,
subscribe: ({ onEvent }) => {
for (const event of events) void onEvent(event)
return vi.fn()
},
})
}

function allChunks(): SlackStreamChunk[] {
return [
...mockStartSlackAgentStream.mock.calls.flatMap((call) => call[2]),
...mockAppendSlackAgentStream.mock.calls.flatMap((call) => call[3]),
...mockStopSlackAgentStream.mock.calls.flatMap((call) => call[6] ?? []),
]
}

it('streams the source as a block selector so the executor streams it', async () => {
const { controller } = await createController(TIMELINE_CONFIG)
expect(controller.selectedOutputs).toEqual(['reply_result', 'child-workflow.analyst_content'])
})

it('shows tool steps without the source text and posts the answer in the same message', async () => {
const { controller } = await createController(TIMELINE_CONFIG)
await streamTimeline(controller)
await controller.callbacks.onBlockComplete?.('reply', 'Reply', 'function', {
output: { result: 'Reviewed answer' },
executionOrder: 3,
executionTime: 1,
startedAt: '2026-11-24T00:00:00Z',
endedAt: '2026-11-24T00:00:01Z',
})
await controller.finalize({ success: true, status: 'completed', output: {} })

controller.assertSucceeded()
expect(mockStartSlackAgentStream).toHaveBeenCalledTimes(1)
expect(mockStopSlackAgentStream).toHaveBeenCalledTimes(1)
const text = allChunks()
.filter((chunk) => chunk.type === 'markdown_text')
.map((chunk) => (chunk.type === 'markdown_text' ? chunk.text : ''))
.join('')
expect(text).toBe('Reviewed answer')
const toolTitles = allChunks().flatMap((chunk) =>
chunk.type === 'task_update' && chunk.id.includes('-tool-') ? [chunk.title] : []
)
expect(new Set(toolTitles)).toEqual(new Set(['Reading AWS cost data', 'Lc Other']))
expect(mockStopSlackAgentStream.mock.calls[0][3]).toBe('processing')
})

it('stops a timeline-only message once with an error status when the run fails', async () => {
const { controller } = await createController(TIMELINE_CONFIG)
await streamTimeline(controller, [
{ type: 'tool_call_start', id: 'tool-1', name: 'mcp-6da535c1-lc_cur' },
])
await controller.finalize({ success: false, output: {} })

expect(mockStartSlackAgentStream).toHaveBeenCalledTimes(1)
expect(mockStopSlackAgentStream).toHaveBeenCalledTimes(1)
expect(mockStopSlackAgentStream.mock.calls[0][3]).toBe('suspended')
expect(mockStopSlackAgentStream.mock.calls[0][6]).toEqual(
expect.arrayContaining([
expect.objectContaining({ type: 'task_update', title: 'Running', status: 'error' }),
expect.objectContaining({
type: 'task_update',
id: expect.stringContaining('-tool-tool-1'),
status: 'error',
}),
])
)
})

it('never overlaps appends from the timeline and the answer on the shared message', async () => {
let inFlight = 0
let maxInFlight = 0
mockAppendSlackAgentStream.mockImplementation(async () => {
inFlight++
maxInFlight = Math.max(maxInFlight, inFlight)
for (let tick = 0; tick < 20; tick++) await Promise.resolve()
inFlight--
})
const { controller } = await createController({
...TIMELINE_CONFIG,
outputConfigs: [{ blockId: 'reply', path: 'content' }],
})
await Promise.all([
streamTimeline(controller),
controller.callbacks.onStream?.({
blockId: 'reply',
executionOrder: 3,
stream: createByteStream(),
execution: { success: true, output: {} },
clientStreamTransformed: false,
subscribe: ({ onEvent }) => {
void onEvent({ type: 'text_delta', text: 'Reviewed answer. ', turn: 'pending' })
void onEvent({ type: 'turn_end', turn: 'final' })
return vi.fn()
},
}),
])

expect(mockStartSlackAgentStream).toHaveBeenCalledTimes(1)
expect(mockAppendSlackAgentStream.mock.calls.length).toBeGreaterThan(1)
expect(maxInFlight).toBe(1)
})

it('still rejects a stream from a block in neither list', async () => {
const { controller } = await createController(TIMELINE_CONFIG)
await expect(
controller.callbacks.onStream?.({
blockId: 'other',
executionOrder: 1,
stream: createByteStream(),
execution: { success: true, output: {} },
})
).rejects.toThrow('unselected block')
})
})

describe('per-invocation outcomes', () => {
const unfinishedTool: AgentStreamEvent[] = [
{ type: 'tool_call_start', id: 'tool-1', name: 'read_file' },
]

function streamEvents(
controller: SlackExecutionStreamController,
executionOrder: number,
events: AgentStreamEvent[]
) {
return controller.callbacks.onStream?.({
blockId: 'agent',
executionOrder,
stream: createByteStream(),
execution: { success: true, output: {} },
clientStreamTransformed: false,
subscribe: ({ onEvent }) => {
for (const event of events) void onEvent(event)
return vi.fn()
},
})
}

it('does not mark an earlier answer failed when a later one fails', async () => {
mockStartSlackAgentStream
.mockResolvedValueOnce({ channel: 'C123', ts: 'first' })
.mockResolvedValueOnce({ channel: 'C123', ts: 'second' })
const { controller } = await createController()
await streamEvents(controller, 1, [
{ type: 'text_delta', text: 'First answer', turn: 'pending' },
{ type: 'turn_end', turn: 'final' },
])
await streamEvents(controller, 2, unfinishedTool)
await controller.finalize({ success: true, status: 'completed', output: {} })

const statusByTs = Object.fromEntries(
mockStopSlackAgentStream.mock.calls.map((call) => [call[2], call[3]])
)
expect(statusByTs).toEqual({ first: 'processing', second: 'suspended' })
})

it('posts no empty reply for a later invocation after an earlier one failed', async () => {
const { controller } = await createController()
await streamEvents(controller, 1, unfinishedTool)
await streamEvents(controller, 2, [])
await controller.finalize({ success: true, status: 'completed', output: {} })

expect(mockStartSlackAgentStream).toHaveBeenCalledTimes(1)
expect(mockStopSlackAgentStream).toHaveBeenCalledTimes(1)
})

it('titles a tool whose name is an object property', async () => {
const { controller } = await createController({ ...BASE_CONFIG, toolLabels: {} })
await streamEvents(controller, 1, [
{ type: 'tool_call_start', id: 'tool-1', name: 'toString' },
{ type: 'tool_call_end', id: 'tool-1', name: 'toString', status: 'success' },
])
const toolChunk = mockAppendSlackAgentStream.mock.calls
.flatMap((call) => call[3] as SlackStreamChunk[])
.find((chunk) => chunk.type === 'task_update' && chunk.id.includes('-tool-'))
expect(toolChunk).toMatchObject({ title: expect.any(String) })
})
})

it('rejects credentials that do not belong to the workflow workspace', async () => {
mockGetSlackBotCredential.mockResolvedValue({
botToken: 'xoxb-token',
Expand Down
Loading
Loading