Skip to content

Commit e3c8c71

Browse files
authored
fix(search-mcp): skip Slack for an email person filter without users:read.email, and quote Gmail person addresses (#10454)
- A Slack account without users:read.email cannot find a member by email, so an involving email search now skips it with the cannot-filter status instead of asking for a reconnect that the default Slack connection cannot satisfy. - Gmail person clauses quote the address, so characters valid in an email local part ({ } |) no longer break the {from: to: cc:} group.
1 parent 7ef574c commit e3c8c71

4 files changed

Lines changed: 38 additions & 6 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,8 @@ const liveKnowledgeSearch = defineAuthorizedKnowledgeUseCase({
554554
.sort(compareAccounts)
555555
/** A person filter skips the sources that cannot apply it rather than return them unfiltered. */
556556
const eligible = reachable.filter(
557-
(account) => !input.involving || filtersByPerson(account.provider, input.involving)
557+
(account) =>
558+
!input.involving || filtersByPerson(account.provider, input.involving, account.scopes)
558559
)
559560
const nothingSearched = !queries && reachable.length === 0
560561
const selected = eligible.slice(0, MAX_ACCOUNTS)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,9 @@ function gmailDocument(row: Record<string, unknown>): NativeDocument {
258258
*/
259259
function gmailPersonClause(involving: string | undefined): string {
260260
if (!involving) return ''
261-
return involving === 'me' ? 'from:me' : `{from:${involving} to:${involving} cc:${involving}}`
261+
if (involving === 'me') return 'from:me'
262+
const address = `"${involving}"`
263+
return `{from:${address} to:${address} cc:${address}}`
262264
}
263265

264266
export async function searchGmail(

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import {
55
withSearchProviderDiagnostics,
66
} from '@/lib/knowledge/search/diagnostics'
77
import { readGitHub, searchGitHub } from '@/lib/sim-search/live/github'
8-
import { searchCalendar, searchDrive } from '@/lib/sim-search/live/google'
8+
import { searchCalendar, searchDrive, searchGmail } from '@/lib/sim-search/live/google'
99
import { defaultLiveSearchPolicy } from '@/lib/sim-search/live/policy-schema'
10+
import { filtersByPerson } from '@/lib/sim-search/live/providers'
1011
import { searchSlack } from '@/lib/sim-search/live/slack'
1112
import type { NativeClient } from '@/lib/sim-search/live/types'
1213

@@ -116,6 +117,20 @@ describe('native search endpoints', () => {
116117
).rejects.toThrow('ORs repeated involves:')
117118
expect(api.json.mock.calls.some(([path]) => path.startsWith('/search/'))).toBe(false)
118119
})
120+
it('keeps a Gmail person group intact when the address holds Gmail operator characters', async () => {
121+
const api = client()
122+
api.json.mockResolvedValue({ messages: [] })
123+
await searchGmail(api, { ...input, query: '', involving: 'a}{b|c@example.com' })
124+
const address = '"a}{b|c@example.com"'
125+
expect(api.json.mock.calls[0]?.[1]?.query?.q).toBe(
126+
`{from:${address} to:${address} cc:${address}}`
127+
)
128+
})
129+
it('skips Slack for a person found by email unless the account can look members up by email', () => {
130+
expect(filtersByPerson('slack', 'me', [])).toBe(true)
131+
expect(filtersByPerson('slack', 'jane@example.com', [])).toBe(false)
132+
expect(filtersByPerson('slack', 'jane@example.com', ['users:read.email'])).toBe(true)
133+
})
119134
it('keeps only calendar events a person organizes or attends without declining', async () => {
120135
const api = client()
121136
const event = (id: string, extra: Record<string, unknown>) => ({

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ interface NativeProvider {
5252
involving?: string
5353
/** The involving filter accepts only `me`: the provider cannot find anyone else by email. */
5454
involvingMeOnly?: true
55+
/** The permission finding someone other than `me` by email needs; without it only `me` applies. */
56+
involvingByEmailScope?: string
5557
/** Plain queries must contain every word, so an underfilled search retries with any term. */
5658
requiresEveryTerm?: true
5759
/**
@@ -175,6 +177,7 @@ export const LIVE_SEARCH_PROVIDERS = {
175177
},
176178
slack: {
177179
involving: 'messages they sent',
180+
involvingByEmailScope: 'users:read.email',
178181
guide: {
179182
syntax:
180183
'Real-time Search: a question (what/how/…?) enables meaning-based matching where Slack AI is on; keyword retrieval (keywordOnly, sortBy newest or oldest, or no Slack AI) requires every word and does not support OR. "exact phrase" and prefix matching such as psca* work.',
@@ -375,10 +378,21 @@ export function searchNativeProvider(
375378
return adapter.search(client, input, origin)
376379
}
377380

378-
/** True when the provider can limit a search to the items this person (`me` or an email) took part in. */
379-
export function filtersByPerson(provider: LiveSearchProviderId, involving: string): boolean {
381+
/**
382+
* True when the account can limit a search to the items this person (`me` or an email) took part
383+
* in: the provider supports the filter and, for an email, the account holds the scope finding
384+
* someone by email needs.
385+
*/
386+
export function filtersByPerson(
387+
provider: LiveSearchProviderId,
388+
involving: string,
389+
scopes: readonly string[]
390+
): boolean {
380391
const adapter: NativeProvider | ManagedMcpProvider = LIVE_SEARCH_PROVIDERS[provider]
381-
return 'involving' in adapter && (involving === 'me' || !('involvingMeOnly' in adapter))
392+
if (!('involving' in adapter)) return false
393+
if (involving === 'me') return true
394+
if ('involvingMeOnly' in adapter) return false
395+
return !adapter.involvingByEmailScope || scopes.includes(adapter.involvingByEmailScope)
382396
}
383397

384398
/** True when the provider's plain-text search matches only items containing every query word. */

0 commit comments

Comments
 (0)