Skip to content

Commit d17c78f

Browse files
authored
feat(search-experts): find who knows a topic from contributors across connected sources (#10565)
* feat(search-experts): find who knows a topic from contributors across connected sources Adds search_experts to the Search MCP, the Assistant and the Organization Search block. Live providers report each result's contributors when asked; the use case ranks them by role, source, recency and rank, matches them to the People directory by email, Slack account or an unambiguous name, and returns evidence links to the items. * fix(search-experts): add up a person's work across sources, cite evidence, keep self-declared emails out of identity - Contributors resolve to their directory person before ranking, so an email in one source and a unique name in another add up. - An item two connected accounts both return counts once. - GitHub people are named by login; git commit emails and GitLab public emails no longer identify anyone; Slack file authors count. - Linear emails and the Drive last editor are fetched only for expert searches. - A Slack ID that two workspaces give different people resolves to no one, and Slack emails are folded. - The Assistant's citation readers collect expert evidence; its summary mentions outside contributors. - Without directory access, department and location filters no longer hide every contributor; the note says they were not applied. - The workflow tool projects every filter a secret could fill, not only the query. * fix(search-experts): project Assistant arguments, keep partial coverage when compacted, match only unshared emails - The Assistant tool projects the query, department and location through the turn's secret registry and refuses protected content, as search_workspace does. - Compacted expert results keep their partial-coverage marker. - An email two directory people share resolves to neither, as names already did. - GitLab results with only the singular assignee field keep that assignee. * fix(search-experts): account for content in Chat, and prove the argument masking and shared-identity rules - search_experts admits its content up front, as live search does; in Chat the nested search's accounting does not reach the outer operation, so every Assistant call failed as unaccounted content. - The Assistant tool sends the connected sources only the projected query and never answers with a secret filter. - The workflow tool projects a secret-filled department out of returned profiles. - An email two directory people share, or a Slack ID that two workspaces give different people, matches no one. * chore(search-experts): sync the Assistant tool contract copy, drop a stray doc line, regenerate after staging * fix(search-experts): project a run's secrets out of directory profiles on every surface The Assistant answered with a directory department that matched a run secret; profiles and outside contributors are now projected through the result registry in the use case, and the Assistant test asserts on a returned expert so it cannot pass vacuously. * fix(search-experts): say when the filter, not the topic, left no expert; test a withheld member directory When contributors were found but none matched the department or location filter, the note now says so instead of claiming no one worked on the topic. The directory-closed tests now also cover a plain member kept out by a withheld member directory, with People enabled.
1 parent 84ba80a commit d17c78f

45 files changed

Lines changed: 1996 additions & 82 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/sim/blocks/blocks/organization.ts‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const OrganizationBlock: BlockConfig = {
4747
{ text: 'since', field: 'historyStartDate' },
4848
],
4949
list_my_activity: ['List my activity', { text: 'in', field: 'source' }],
50+
search_experts: ['Find experts', { text: 'on', field: 'query' }],
5051
},
5152
},
5253
},
@@ -65,30 +66,30 @@ export const OrganizationBlock: BlockConfig = {
6566
title: 'Query',
6667
type: 'long-input',
6768
placeholder: 'What to look for',
68-
condition: { field: 'operation', value: ['search', 'search_people'] },
69+
condition: { field: 'operation', value: ['search', 'search_people', 'search_experts'] },
6970
},
7071
{
7172
id: 'source',
7273
title: 'Source',
7374
type: 'short-input',
7475
placeholder: 'slack, jira, confluence, google_drive, gitlab…',
75-
condition: { field: 'operation', value: ['search', 'list_my_activity'] },
76+
condition: { field: 'operation', value: ['search', 'list_my_activity', 'search_experts'] },
7677
mode: 'advanced',
7778
},
7879
{
7980
id: 'startDate',
8081
title: 'Start Date',
8182
type: 'short-input',
8283
placeholder: '2026-01-01T00:00:00-08:00 (inclusive)',
83-
condition: { field: 'operation', value: ['search', 'list_my_activity'] },
84+
condition: { field: 'operation', value: ['search', 'list_my_activity', 'search_experts'] },
8485
mode: 'advanced',
8586
},
8687
{
8788
id: 'endDate',
8889
title: 'End Date',
8990
type: 'short-input',
9091
placeholder: '2026-02-01T00:00:00-08:00 (exclusive)',
91-
condition: { field: 'operation', value: ['search', 'list_my_activity'] },
92+
condition: { field: 'operation', value: ['search', 'list_my_activity', 'search_experts'] },
9293
mode: 'advanced',
9394
},
9495
{
@@ -190,10 +191,10 @@ export const OrganizationBlock: BlockConfig = {
190191
id: 'topK',
191192
title: 'Max Results',
192193
type: 'short-input',
193-
placeholder: '20 for Search, 25 for activity, 50 for chat history',
194+
placeholder: '20 for Search, 10 for experts, 25 for activity, 50 for chat history',
194195
condition: {
195196
field: 'operation',
196-
value: ['search', 'list_my_chat_history', 'list_my_activity'],
197+
value: ['search', 'list_my_chat_history', 'list_my_activity', 'search_experts'],
197198
},
198199
mode: 'advanced',
199200
},
@@ -257,15 +258,15 @@ export const OrganizationBlock: BlockConfig = {
257258
title: 'Department',
258259
type: 'short-input',
259260
placeholder: 'Part of a department',
260-
condition: { field: 'operation', value: 'search_people' },
261+
condition: { field: 'operation', value: ['search_people', 'search_experts'] },
261262
mode: 'advanced',
262263
},
263264
{
264265
id: 'location',
265266
title: 'Location',
266267
type: 'short-input',
267268
placeholder: 'Part of a location',
268-
condition: { field: 'operation', value: 'search_people' },
269+
condition: { field: 'operation', value: ['search_people', 'search_experts'] },
269270
mode: 'advanced',
270271
},
271272
{
@@ -399,14 +400,20 @@ export const OrganizationBlock: BlockConfig = {
399400
type: 'number',
400401
description: 'List My Chat History: questions in the window, on the first page only',
401402
},
402-
note: { type: 'string', description: 'Search People: guidance when no one matches' },
403+
note: { type: 'string', description: 'Search People and Search Experts: guidance' },
403404
window: { type: 'json', description: 'List My Activity: the window read' },
404405
items: { type: 'array', description: 'List My Activity: activity entries, newest first' },
405406
truncated: { type: 'boolean', description: 'List My Activity: whether more entries remain' },
406407
coverage: { type: 'string', description: 'List My Activity: complete or partial' },
407408
sources: {
408409
type: 'array',
409-
description: 'List My Activity: each source’s status and where to connect it',
410+
description:
411+
'List My Activity and Search Experts: each source’s status and where to connect it',
412+
},
413+
experts: { type: 'array', description: 'Search Experts: ranked experts with evidence' },
414+
otherContributors: {
415+
type: 'array',
416+
description: 'Search Experts: strong contributors outside the directory',
410417
},
411418
},
412419
}

‎apps/sim/blocks/sdk-names.generated.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ const BLOCKS: Record<string, string> = {
320320
openai: '{"namespace":"legacy.openai"}',
321321
oracle_fusion_financials: '{"namespace":"oracleFusionFinancials","methods":{"oracle_fusion_financials_apply_receivables_receipt":"applyReceivablesReceipt","oracle_fusion_financials_approve_receivables_invoice":"approveReceivablesInvoice","oracle_fusion_financials_create_expense_line":"createExpenseLine","oracle_fusion_financials_create_expense_report":"createExpenseReport","oracle_fusion_financials_create_receivables_credit_memo":"createReceivablesCreditMemo","oracle_fusion_financials_create_receivables_invoice":"createReceivablesInvoice","oracle_fusion_financials_create_receivables_receipt":"createReceivablesReceipt","oracle_fusion_financials_get_expense_line":"getExpenseLine","oracle_fusion_financials_get_expense_report":"getExpenseReport","oracle_fusion_financials_get_gl_journal_batch":"getGlJournalBatch","oracle_fusion_financials_get_gl_ledger":"getGlLedger","oracle_fusion_financials_get_payables_invoice":"getPayablesInvoice","oracle_fusion_financials_get_payables_invoice_line":"getPayablesInvoiceLine","oracle_fusion_financials_get_payables_payment":"getPayablesPayment","oracle_fusion_financials_get_receivables_credit_memo":"getReceivablesCreditMemo","oracle_fusion_financials_get_receivables_invoice":"getReceivablesInvoice","oracle_fusion_financials_get_receivables_invoice_installment":"getReceivablesInvoiceInstallment","oracle_fusion_financials_get_receivables_invoice_line":"getReceivablesInvoiceLine","oracle_fusion_financials_get_receivables_receipt":"getReceivablesReceipt","oracle_fusion_financials_list_expense_lines":"listExpenseLines","oracle_fusion_financials_list_expense_reports":"listExpenseReports","oracle_fusion_financials_list_gl_balances":"listGlBalances","oracle_fusion_financials_list_gl_journal_batches":"listGlJournalBatches","oracle_fusion_financials_list_gl_ledgers":"listGlLedgers","oracle_fusion_financials_list_payables_invoice_lines":"listPayablesInvoiceLines","oracle_fusion_financials_list_payables_invoices":"listPayablesInvoices","oracle_fusion_financials_list_payables_payments":"listPayablesPayments","oracle_fusion_financials_list_receivables_credit_memos":"listReceivablesCreditMemos","oracle_fusion_financials_list_receivables_invoice_installments":"listReceivablesInvoiceInstallments","oracle_fusion_financials_list_receivables_invoice_lines":"listReceivablesInvoiceLines","oracle_fusion_financials_list_receivables_invoices":"listReceivablesInvoices","oracle_fusion_financials_list_receivables_receipts":"listReceivablesReceipts","oracle_fusion_financials_submit_expense_report":"submitExpenseReport","oracle_fusion_financials_update_expense_line":"updateExpenseLine","oracle_fusion_financials_update_expense_report":"updateExpenseReport","oracle_fusion_financials_update_receivables_invoice":"updateReceivablesInvoice"},"paramAliases":{"action":{"oauthCredential":"credential"}}}',
322322
oracledb: '{"namespace":"oracledb","methods":{"delete":"deleteData","execute":"executeSql","insert":"insertData","introspect":"introspectSchema","query":"querySelect","update":"updateData"},"paramAliases":{"action":{"oauthCredential":"credential"}}}',
323-
organization: '{"namespace":"organization","methods":{"list_my_activity":"listMyActivity","list_my_chat_history":"listMyChatHistory","read_document":"readDocument","search":"search","search_people":"searchPeople"}}',
323+
organization: '{"namespace":"organization","methods":{"list_my_activity":"listMyActivity","list_my_chat_history":"listMyChatHistory","read_document":"readDocument","search":"search","search_experts":"searchExperts","search_people":"searchPeople"}}',
324324
otter: '{"namespace":"legacy.otter","methods":{"create_conversation":"importRecording","get_conversation":"getConversation","get_conversation_audio":"getConversationAudio","get_workspace":"getWorkspace","list_channel_members":"listChannelMembers","list_channels":"listChannels","list_conversations":"listConversations","list_workspace_conversations":"listWorkspaceConversations"},"triggers":{"otter_conversation_completed":"conversationCompleted","otter_conversation_shared":"conversationShared","otter_webhook":"webhook"}}',
325325
otter_v2: '{"namespace":"otter","methods":{"create_conversation":"importRecording","get_conversation":"getConversation","get_conversation_audio":"getConversationAudio","get_workspace":"getWorkspace","list_channel_members":"listChannelMembers","list_channels":"listChannels","list_conversations":"listConversations","list_workspace_conversations":"listWorkspaceConversations"},"triggers":{"otter_conversation_completed":"conversationCompleted","otter_conversation_shared":"conversationShared","otter_webhook":"webhook"},"paramAliases":{"action":{"oauthCredential":"credential"}}}',
326326
outlook: '{"namespace":"outlook","methods":{"copy_outlook":"copyEmail","create_event_calendar":"createEvent","create_folder_outlook":"createFolder","delete_event_calendar":"deleteEvent","delete_outlook":"deleteEmail","draft_outlook":"draftEmail","forward_outlook":"forwardEmail","get_attachment_outlook":"getAttachment","get_event_calendar":"getCalendarEvent","list_attachments_outlook":"listAttachments","list_events_calendar":"listCalendarEvents","list_folders_outlook":"listFolders","mark_read_outlook":"markAsRead","mark_unread_outlook":"markAsUnread","move_outlook":"moveEmail","read_outlook":"readEmail","reply_all_outlook":"replyAll","reply_outlook":"replyToEmail","respond_calendar":"respondToInvite","search_outlook":"searchEmail","send_outlook":"sendEmail","update_event_calendar":"updateEvent","update_message_outlook":"setCategoriesFlag"},"triggers":{"outlook_poller":"poller"},"paramAliases":{"action":{"oauthCredential":"credential"},"trigger":{"oauthCredential":"credential"}}}',

‎apps/sim/blocks/sdk-names/organization.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"list_my_chat_history": "listMyChatHistory",
66
"read_document": "readDocument",
77
"search": "search",
8+
"search_experts": "searchExperts",
89
"search_people": "searchPeople"
910
}
1011
}

‎apps/sim/lib/api/contracts/mothership-assistant-tools.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,38 @@ export const listMyChatHistoryInputSchema = z
574574
.strict()
575575
export type ListMyChatHistoryInput = z.output<typeof listMyChatHistoryInputSchema>
576576

577+
/** Who knows a topic, ranked by what they did on matching items the caller can read. */
578+
export const searchExpertsInputSchema = z
579+
.object({
580+
query: z
581+
.string()
582+
.trim()
583+
.min(1)
584+
.max(500)
585+
.describe('The topic, system, customer or project to find people for.'),
586+
source: workspaceSearchFiltersSchema.shape.source.describe(
587+
'Only this source, such as jira, confluence, google_drive, slack, gitlab or github.'
588+
),
589+
startDate: z.iso
590+
.datetime({ offset: true })
591+
.optional()
592+
.describe(
593+
`Inclusive start of the activity window, an ISO datetime with offset. With endDate, at most ${MAX_ACTIVITY_WINDOW_DAYS} days; without either, all time, with recent work weighted higher.`
594+
),
595+
endDate: z.iso
596+
.datetime({ offset: true })
597+
.optional()
598+
.describe('Exclusive end of the activity window, an ISO datetime with offset.'),
599+
department: peopleFieldFilter('Only experts whose directory department contains this text.'),
600+
location: peopleFieldFilter('Only experts whose directory location contains this text.'),
601+
topK: z.number().int().min(1).max(25).default(10).describe('Maximum experts to return.'),
602+
})
603+
.strict()
604+
.superRefine(refineActivityWindow)
605+
606+
export const SEARCH_EXPERTS_DESCRIPTION =
607+
'Find who in this organization knows a topic: people ranked by what they did on matching items you can read (Jira issues assigned or reported, Confluence pages written or edited, Drive files owned or edited, Slack messages, GitLab and GitHub merge and pull requests, Linear issues). Each expert comes with a score, their directory profile when they are in it, what they did by source, and evidence links to the items. Only items your own access returns count. Narrow with source, a date window, department or location.'
608+
577609
/** Connection requests name a provider and optionally an owned account to repair. */
578610
export const oauthGetAuthLinkInputSchema = z.object({
579611
providerName: z
@@ -658,6 +690,12 @@ export const assistantToolContracts = [
658690
'List what you did across your connected sources in a date window, newest first: Slack messages and Gmail mail you sent (replied when the message answers another), Google Calendar meetings you organized or accepted, Jira issues you created or that were assigned to you, Confluence pages you created or edited and comments you wrote. Each item has a documentId for read_document. Follow nextCursor for more; a source that failed and recovers on a later page can return entries older than that page. sources reports each source: not_connected and reconnect carry the provider to connect with oauth_get_auth_link.',
659691
inputSchema: listMyActivityInputSchema,
660692
},
693+
{
694+
id: 'search_experts',
695+
route: 'sim',
696+
description: SEARCH_EXPERTS_DESCRIPTION,
697+
inputSchema: searchExpertsInputSchema,
698+
},
661699
{
662700
id: 'oauth_get_auth_link',
663701
route: 'sim',

‎apps/sim/lib/internal/organization-search/execute-tool.integration.ts‎

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
copilotMessages,
1515
environment,
1616
member,
17+
memberProfile,
1718
organization,
1819
organizationSearchIntegration,
1920
permissions,
@@ -35,6 +36,7 @@ import { executeOrganizationSearchTool } from '@/lib/internal/organization-searc
3536
import type { InternalToolOperationContext } from '@/lib/internal/tool-operations/types'
3637
import { listDepartments, listPeople } from '@/lib/people/application/use-cases'
3738
import {
39+
type LiveContributionItem,
3840
listLiveSearchAccounts,
3941
readLiveDocument,
4042
searchLiveKnowledge,
@@ -46,7 +48,31 @@ vi.hoisted(() => {
4648
vi.stubEnv('MY_ACTIVITY', 'true')
4749
})
4850

49-
const { searchAvailable } = vi.hoisted(() => ({ searchAvailable: { value: true } }))
51+
const { searchAvailable, liveItems } = vi.hoisted(() => ({
52+
searchAvailable: { value: true },
53+
/** Items a stubbed live search hands expert search; null searches the connected sources. */
54+
liveItems: { value: null as LiveContributionItem[] | null },
55+
}))
56+
vi.mock('@/lib/sim-search/live/application', async (importOriginal) => {
57+
const actual = await importOriginal<typeof import('@/lib/sim-search/live/application')>()
58+
return {
59+
...actual,
60+
searchLiveKnowledge: {
61+
...actual.searchLiveKnowledge,
62+
operation: actual.searchLiveKnowledge.operation,
63+
execute: async (args: Parameters<typeof actual.searchLiveKnowledge.execute>[0]) => {
64+
if (!liveItems.value) return actual.searchLiveKnowledge.execute(args)
65+
args.input.onContributions?.(liveItems.value)
66+
return {
67+
query: args.input.query,
68+
results: [],
69+
retrieval: { status: 'complete', timedOutLegs: [] },
70+
live: { backend: 'live', accounts: [], guidance: '' },
71+
}
72+
},
73+
},
74+
}
75+
})
5076
vi.mock('@/lib/knowledge/access/availability', async (importOriginal) => ({
5177
...(await importOriginal<typeof import('@/lib/knowledge/access/availability')>()),
5278
requireOrganizationSearchAvailable: async () => {
@@ -58,6 +84,7 @@ vi.mock('@/lib/knowledge/access/availability', async (importOriginal) => ({
5884
const organizationId = generateId()
5985
const memberUserId = generateId()
6086
const colleagueUserId = generateId()
87+
const colleagueMemberId = generateId()
6188
const outsiderUserId = generateId()
6289
const organizationWorkspaceId = generateId()
6390
const personalWorkspaceId = generateId()
@@ -125,7 +152,7 @@ beforeAll(async () => {
125152
.values({ id: organizationId, slug: organizationId, name: 'Search fixture', createdAt: now })
126153
await db.insert(member).values([
127154
{ id: generateId(), organizationId, userId: memberUserId, role: 'member' },
128-
{ id: generateId(), organizationId, userId: colleagueUserId, role: 'member' },
155+
{ id: colleagueMemberId, organizationId, userId: colleagueUserId, role: 'member' },
129156
])
130157
await insertWorkspaceFixture(db, [
131158
{
@@ -244,6 +271,22 @@ describe('Organization Search tools in a workflow run', () => {
244271
expect((await response.json()).person).toMatchObject({ name: colleagueName })
245272
})
246273

274+
it('searches experts in a workflow run, pointing to integrations when no source is connected', async () => {
275+
const response = await executeOrganizationSearchTool({
276+
toolId: 'organization_search_experts',
277+
input: { query: 'billing migration' },
278+
headers: new Headers(),
279+
context: runAs(memberUserId, organizationWorkflowId, organizationWorkspaceId),
280+
requestId: generateId(),
281+
})
282+
expect(response.status).toBe(200)
283+
expect(await response.json()).toMatchObject({
284+
experts: [],
285+
sources: [],
286+
note: expect.stringMatching(/no connected sources.*\/integrations/),
287+
})
288+
})
289+
247290
it('refuses a run in an organization without Search', async () => {
248291
searchAvailable.value = false
249292
try {
@@ -402,6 +445,64 @@ describe('Organization Search tools in a workflow run', () => {
402445
}
403446
})
404447

448+
it('projects a run secret in an expert filter out of the profiles expert search returns', async () => {
449+
const team = `Team ${generateId().slice(0, 8)}`
450+
const { encrypted } = await encryptSecret(team)
451+
await db.insert(memberProfile).values({ memberId: colleagueMemberId, department: team })
452+
await db
453+
.insert(environment)
454+
.values({ id: memberUserId, userId: memberUserId, variables: { TEAM: encrypted } })
455+
liveItems.value = [
456+
{
457+
provider: 'jira',
458+
rank: 1,
459+
contributors: [{ role: 'assignee', email: `${colleagueUserId}@organization-search.test` }],
460+
result: {
461+
documentId: 'ENG-1',
462+
knowledgeBaseId: '',
463+
knowledgeBaseName: 'jira',
464+
documentName: 'Billing migration',
465+
sourceUrl: 'https://example.test/ENG-1',
466+
connectorType: 'jira',
467+
sourceModifiedAt: null,
468+
sourceDate: null,
469+
author: null,
470+
content: '',
471+
chunkIndex: 0,
472+
similarity: 1,
473+
},
474+
},
475+
]
476+
try {
477+
const registry = new ResolvedSecretTraceRegistry(
478+
[{ name: 'TEAM', plaintext: team, encryptedValue: encrypted }],
479+
{ userId: memberUserId, workspaceId: organizationWorkspaceId }
480+
)
481+
registry.recordResolvedAtInputPath('TEAM', team, ['department'])
482+
const headers = new Headers()
483+
const input = addModelInputProvenanceToRequest(
484+
{ query: 'billing migration', department: team },
485+
headers,
486+
createModelInputProvenanceRequestMetadata(registry, [['department']])
487+
)
488+
const response = await executeOrganizationSearchTool({
489+
toolId: 'organization_search_experts',
490+
input,
491+
headers,
492+
context: runAs(memberUserId, organizationWorkflowId, organizationWorkspaceId),
493+
requestId: generateId(),
494+
})
495+
expect(response.status).toBe(200)
496+
const text = await response.text()
497+
expect(text).toContain(colleagueName)
498+
expect(text).not.toContain(team)
499+
} finally {
500+
liveItems.value = null
501+
await db.delete(environment).where(eq(environment.userId, memberUserId))
502+
await db.delete(memberProfile).where(eq(memberProfile.memberId, colleagueMemberId))
503+
}
504+
})
505+
405506
it("refuses a person who is not a member of the workflow's organization", async () => {
406507
const response = await call(
407508
runAs(outsiderUserId, organizationWorkflowId, organizationWorkspaceId),

0 commit comments

Comments
 (0)