Skip to content

Commit da78d74

Browse files
committed
fix(slack): correct thread parent on cursor-resume, complete DM scope hints, reject empty suggested prompts
- get_thread_replies: identify thread parent by ts === thread_ts instead of assuming index 0, so cursor-resumed pages (which omit the parent) no longer mislabel a reply as the parent - get_channel_history + get_thread_replies: include im:history/mpim:history in the missing_scope hint to match the OAuth grant and DM/MPIM reads - set_suggested_prompts: throw a clear error when no valid prompt is provided instead of silently calling Slack with an empty prompts array
1 parent 87fadfb commit da78d74

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

apps/sim/tools/slack/get_channel_history.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export const slackGetChannelHistoryTool: ToolConfig<
113113
limit: params.limit ? Number(params.limit) : 200,
114114
cursor: params.cursor,
115115
maxPages: params.maxPages ? Math.max(Number(params.maxPages), 1) : DEFAULT_MAX_PAGES,
116-
missingScopeHint: 'channels:history, groups:history',
116+
missingScopeHint: 'channels:history, groups:history, im:history, mpim:history',
117117
})
118118

119119
return {

apps/sim/tools/slack/get_thread_replies.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,16 @@ export const slackGetThreadRepliesTool: ToolConfig<
120120
limit: params.limit ? Number(params.limit) : 200,
121121
cursor: params.cursor,
122122
maxPages: params.maxPages ? Math.max(Number(params.maxPages), 1) : DEFAULT_MAX_PAGES,
123-
missingScopeHint: 'channels:history, groups:history',
123+
missingScopeHint: 'channels:history, groups:history, im:history, mpim:history',
124124
})
125125

126126
const messages = result.messages
127-
const parentMessage = messages.length > 0 ? messages[0] : null
128-
const replies = messages.slice(1)
127+
const threadTs = params.threadTs?.trim()
128+
// The thread parent is the message whose ts equals the requested thread_ts.
129+
// It is only present on the first page; cursor-resumed pages contain replies
130+
// only, so identify the parent by ts rather than assuming index 0.
131+
const parentMessage = messages.find((msg) => msg.ts === threadTs) ?? null
132+
const replies = parentMessage ? messages.filter((msg) => msg !== parentMessage) : messages
129133

130134
return {
131135
success: true,

apps/sim/tools/slack/set_suggested_prompts.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ export const slackSetSuggestedPromptsTool: ToolConfig<
103103
}),
104104
body: (params: SlackSetSuggestedPromptsParams) => {
105105
const prompts = normalizePrompts(params.prompts).slice(0, 4)
106+
if (prompts.length === 0) {
107+
throw new Error(
108+
'At least one suggested prompt with a non-empty "title" and "message" is required.'
109+
)
110+
}
106111
const title = params.promptsTitle?.trim()
107112
return {
108113
channel_id: params.channel?.trim(),

0 commit comments

Comments
 (0)