Skip to content

Commit 9cad5ff

Browse files
authored
improvement(search): skip the Slack channel lookup on channel-scoped searches and read channel names in any script (#10023)
1 parent 3caa269 commit 9cad5ff

3 files changed

Lines changed: 44 additions & 9 deletions

File tree

‎apps/sim/lib/knowledge/mcp/tool-arguments.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ export function repairToolCallMessage(message: Record<string, unknown>) {
8888
}
8989

9090
/**
91-
* Unrecognized field names logged per schema issue, each cut short. The schema caps native queries
92-
* at nine, so a rejection's log line stays bounded.
91+
* Unrecognized field names logged per schema issue, each cut short. The route's request body cap
92+
* bounds how many issues one rejection can carry.
9393
*/
9494
const MAX_LOGGED_KEYS = 5
9595
const MAX_LOGGED_KEY_CHARACTERS = 64

‎apps/sim/lib/sim-search/live/providers.test.ts‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ describe('Slack channels', () => {
448448
filters: { startDate: '2026-10-30T00:00:00Z' },
449449
native: { provider: 'slack', query: '', modifiers: 'in:#announcements' },
450450
})
451-
expect(result.message).toContain('No channel named #announcements is visible to this account.')
451+
expect(result.message).toContain('No channel named #announcements can be searched here.')
452452
expect(result.message).toContain(
453453
'Channels with similar names: #company-announcements (in:<#C7>).'
454454
)
@@ -485,6 +485,38 @@ describe('Slack channels', () => {
485485
expect(result.message).not.toContain('#announcements')
486486
})
487487

488+
it('looks up no channel when the query is already scoped to a channel ID', async () => {
489+
const api = client()
490+
api.json.mockResolvedValue(rts([]))
491+
const result = await searchSlack(api, {
492+
...input,
493+
scopes,
494+
native: { provider: 'slack', query: 'launch in:<#C1>', modifiers: 'in:#announcements' },
495+
})
496+
expect(api.json).toHaveBeenCalledTimes(1)
497+
expect(result.message).not.toContain('#announcements')
498+
})
499+
500+
it.each([
501+
['in:#launch-team.', 'launch-team'],
502+
['in:#équipe_ventes,', 'équipe_ventes'],
503+
['in:#हिंदी-टीम', 'हिंदी-टीम'],
504+
])('looks up the whole channel name in %s', async (modifiers, name) => {
505+
const api = client()
506+
api.json.mockResolvedValue(rts([]))
507+
await searchSlack(api, {
508+
...input,
509+
query: '',
510+
scopes,
511+
filters: { startDate: '2026-10-30T00:00:00Z' },
512+
native: { provider: 'slack', query: '', modifiers },
513+
})
514+
expect(api.json.mock.calls[1]?.[1]?.body).toMatchObject({
515+
query: name,
516+
content_types: ['channels'],
517+
})
518+
})
519+
488520
it('keeps the empty search when the channel lookup fails', async () => {
489521
const api = client()
490522
api.json

‎apps/sim/lib/sim-search/live/slack.ts‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,15 @@ function searchableChannels(data: Record<string, unknown>, input: NativeSearchIn
6565
const channelLabel = ({ id, name, archived }: SlackChannel) =>
6666
`#${name} (in:<#${id}>${archived ? ', archived' : ''})`
6767

68-
/** The channel name an `in:#name` filter in the query or modifiers names, if any. */
68+
/**
69+
* The channel name an `in:#name` filter in the query or modifiers names, without a trailing period.
70+
* A query that also carries an `in:<#ID>` scope gets no lookup: a source limited to selected
71+
* channels adds one to each search it runs per channel and drops the notes of the empty ones.
72+
*/
6973
function filteredChannelName(input: NativeSearchInput): string | undefined {
70-
return [nativeText(input), input.native?.modifiers]
71-
.join(' ')
72-
.match(/(?:^|\s)in:#([\w.-]+)/i)?.[1]
73-
?.toLowerCase()
74+
const text = [nativeText(input), input.native?.modifiers].join(' ')
75+
if (text.includes('in:<#')) return undefined
76+
return text.match(/(?:^|\s)in:#([\p{L}\p{M}\p{N}_.-]*[\p{L}\p{M}\p{N}_-])/iu)?.[1]?.toLowerCase()
7477
}
7578

7679
/**
@@ -108,7 +111,7 @@ async function channelFilterNote(
108111
const complete = !string(object(data.response_metadata).next_cursor)
109112
const similar = channels.slice(0, MAX_LISTED_CHANNELS).map(channelLabel).join(', ')
110113
return joinMessages([
111-
complete ? `No channel named #${name} is visible to this account.` : '',
114+
complete ? `No channel named #${name} can be searched here.` : '',
112115
similar ? `Channels with similar names: ${similar}.` : '',
113116
])
114117
}

0 commit comments

Comments
 (0)