Skip to content
Open
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
27 changes: 17 additions & 10 deletions apps/sim/blocks/blocks/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const OrganizationBlock: BlockConfig = {
{ text: 'since', field: 'historyStartDate' },
],
list_my_activity: ['List my activity', { text: 'in', field: 'source' }],
search_experts: ['Find experts', { text: 'on', field: 'query' }],
},
},
},
Expand All @@ -65,30 +66,30 @@ export const OrganizationBlock: BlockConfig = {
title: 'Query',
type: 'long-input',
placeholder: 'What to look for',
condition: { field: 'operation', value: ['search', 'search_people'] },
condition: { field: 'operation', value: ['search', 'search_people', 'search_experts'] },
},
{
id: 'source',
title: 'Source',
type: 'short-input',
placeholder: 'slack, jira, confluence, google_drive, gitlab…',
condition: { field: 'operation', value: ['search', 'list_my_activity'] },
condition: { field: 'operation', value: ['search', 'list_my_activity', 'search_experts'] },
mode: 'advanced',
},
{
id: 'startDate',
title: 'Start Date',
type: 'short-input',
placeholder: '2026-01-01T00:00:00-08:00 (inclusive)',
condition: { field: 'operation', value: ['search', 'list_my_activity'] },
condition: { field: 'operation', value: ['search', 'list_my_activity', 'search_experts'] },
mode: 'advanced',
},
{
id: 'endDate',
title: 'End Date',
type: 'short-input',
placeholder: '2026-02-01T00:00:00-08:00 (exclusive)',
condition: { field: 'operation', value: ['search', 'list_my_activity'] },
condition: { field: 'operation', value: ['search', 'list_my_activity', 'search_experts'] },
mode: 'advanced',
},
{
Expand Down Expand Up @@ -190,10 +191,10 @@ export const OrganizationBlock: BlockConfig = {
id: 'topK',
title: 'Max Results',
type: 'short-input',
placeholder: '20 for Search, 25 for activity, 50 for chat history',
placeholder: '20 for Search, 10 for experts, 25 for activity, 50 for chat history',
condition: {
field: 'operation',
value: ['search', 'list_my_chat_history', 'list_my_activity'],
value: ['search', 'list_my_chat_history', 'list_my_activity', 'search_experts'],
},
mode: 'advanced',
},
Expand Down Expand Up @@ -257,15 +258,15 @@ export const OrganizationBlock: BlockConfig = {
title: 'Department',
type: 'short-input',
placeholder: 'Part of a department',
condition: { field: 'operation', value: 'search_people' },
condition: { field: 'operation', value: ['search_people', 'search_experts'] },
mode: 'advanced',
},
{
id: 'location',
title: 'Location',
type: 'short-input',
placeholder: 'Part of a location',
condition: { field: 'operation', value: 'search_people' },
condition: { field: 'operation', value: ['search_people', 'search_experts'] },
mode: 'advanced',
},
{
Expand Down Expand Up @@ -395,14 +396,20 @@ export const OrganizationBlock: BlockConfig = {
type: 'array',
description: 'List My Chat History: the person’s own questions, newest first by default',
},
note: { type: 'string', description: 'Search People: guidance when no one matches' },
note: { type: 'string', description: 'Search People and Search Experts: guidance' },
window: { type: 'json', description: 'List My Activity: the window read' },
items: { type: 'array', description: 'List My Activity: activity entries, newest first' },
truncated: { type: 'boolean', description: 'List My Activity: whether more entries remain' },
coverage: { type: 'string', description: 'List My Activity: complete or partial' },
sources: {
type: 'array',
description: 'List My Activity: each source’s status and where to connect it',
description:
'List My Activity and Search Experts: each source’s status and where to connect it',
},
experts: { type: 'array', description: 'Search Experts: ranked experts with evidence' },
otherContributors: {
type: 'array',
description: 'Search Experts: strong contributors outside the directory',
},
},
}
2 changes: 1 addition & 1 deletion apps/sim/blocks/sdk-names.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ const BLOCKS: Record<string, string> = {
openai: '{"namespace":"legacy.openai"}',
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"}}}',
oracledb: '{"namespace":"oracledb","methods":{"delete":"deleteData","execute":"executeSql","insert":"insertData","introspect":"introspectSchema","query":"querySelect","update":"updateData"},"paramAliases":{"action":{"oauthCredential":"credential"}}}',
organization: '{"namespace":"organization","methods":{"list_my_activity":"listMyActivity","list_my_chat_history":"listMyChatHistory","read_document":"readDocument","search":"search","search_people":"searchPeople"}}',
organization: '{"namespace":"organization","methods":{"list_my_activity":"listMyActivity","list_my_chat_history":"listMyChatHistory","read_document":"readDocument","search":"search","search_experts":"searchExperts","search_people":"searchPeople"}}',
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"}}',
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"}}}',
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"}}}',
Expand Down
1 change: 1 addition & 0 deletions apps/sim/blocks/sdk-names/organization.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"list_my_chat_history": "listMyChatHistory",
"read_document": "readDocument",
"search": "search",
"search_experts": "searchExperts",
"search_people": "searchPeople"
}
}
39 changes: 39 additions & 0 deletions apps/sim/lib/api/contracts/mothership-assistant-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,39 @@ export const listMyChatHistoryInputSchema = z
.strict()
export type ListMyChatHistoryInput = z.output<typeof listMyChatHistoryInputSchema>

/** The longest activity window an expert search reads. */
/** Who knows a topic, ranked by what they did on matching items the caller can read. */
export const searchExpertsInputSchema = z
.object({
query: z
.string()
.trim()
.min(1)
.max(500)
.describe('The topic, system, customer or project to find people for.'),
source: workspaceSearchFiltersSchema.shape.source.describe(
'Only this source, such as jira, confluence, google_drive, slack, gitlab or github.'
),
startDate: z.iso
.datetime({ offset: true })
.optional()
.describe(
`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.`
),
endDate: z.iso
.datetime({ offset: true })
.optional()
.describe('Exclusive end of the activity window, an ISO datetime with offset.'),
department: peopleFieldFilter('Only experts whose directory department contains this text.'),
location: peopleFieldFilter('Only experts whose directory location contains this text.'),
topK: z.number().int().min(1).max(25).default(10).describe('Maximum experts to return.'),
})
.strict()
.superRefine(refineActivityWindow)
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved

export const SEARCH_EXPERTS_DESCRIPTION =
'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.'

/** Connection requests name a provider and optionally an owned account to repair. */
export const oauthGetAuthLinkInputSchema = z.object({
providerName: z
Expand Down Expand Up @@ -658,6 +691,12 @@ export const assistantToolContracts = [
'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.',
inputSchema: listMyActivityInputSchema,
},
{
id: 'search_experts',
route: 'sim',
description: SEARCH_EXPERTS_DESCRIPTION,
inputSchema: searchExpertsInputSchema,
},
{
id: 'oauth_get_auth_link',
route: 'sim',
Expand Down
105 changes: 103 additions & 2 deletions apps/sim/lib/internal/organization-search/execute-tool.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
copilotMessages,
environment,
member,
memberProfile,
organization,
organizationSearchIntegration,
permissions,
Expand All @@ -35,6 +36,7 @@ import { executeOrganizationSearchTool } from '@/lib/internal/organization-searc
import type { InternalToolOperationContext } from '@/lib/internal/tool-operations/types'
import { listDepartments, listPeople } from '@/lib/people/application/use-cases'
import {
type LiveContributionItem,
listLiveSearchAccounts,
readLiveDocument,
searchLiveKnowledge,
Expand All @@ -46,7 +48,31 @@ vi.hoisted(() => {
vi.stubEnv('MY_ACTIVITY', 'true')
})

const { searchAvailable } = vi.hoisted(() => ({ searchAvailable: { value: true } }))
const { searchAvailable, liveItems } = vi.hoisted(() => ({
searchAvailable: { value: true },
/** Items a stubbed live search hands expert search; null searches the connected sources. */
liveItems: { value: null as LiveContributionItem[] | null },
}))
vi.mock('@/lib/sim-search/live/application', async (importOriginal) => {
const actual = await importOriginal<typeof import('@/lib/sim-search/live/application')>()
return {
...actual,
searchLiveKnowledge: {
...actual.searchLiveKnowledge,
operation: actual.searchLiveKnowledge.operation,
execute: async (args: Parameters<typeof actual.searchLiveKnowledge.execute>[0]) => {
if (!liveItems.value) return actual.searchLiveKnowledge.execute(args)
args.input.onContributions?.(liveItems.value)
return {
query: args.input.query,
results: [],
retrieval: { status: 'complete', timedOutLegs: [] },
live: { backend: 'live', accounts: [], guidance: '' },
}
},
},
}
})
vi.mock('@/lib/knowledge/access/availability', async (importOriginal) => ({
...(await importOriginal<typeof import('@/lib/knowledge/access/availability')>()),
requireOrganizationSearchAvailable: async () => {
Expand All @@ -58,6 +84,7 @@ vi.mock('@/lib/knowledge/access/availability', async (importOriginal) => ({
const organizationId = generateId()
const memberUserId = generateId()
const colleagueUserId = generateId()
const colleagueMemberId = generateId()
const outsiderUserId = generateId()
const organizationWorkspaceId = generateId()
const personalWorkspaceId = generateId()
Expand Down Expand Up @@ -125,7 +152,7 @@ beforeAll(async () => {
.values({ id: organizationId, slug: organizationId, name: 'Search fixture', createdAt: now })
await db.insert(member).values([
{ id: generateId(), organizationId, userId: memberUserId, role: 'member' },
{ id: generateId(), organizationId, userId: colleagueUserId, role: 'member' },
{ id: colleagueMemberId, organizationId, userId: colleagueUserId, role: 'member' },
])
await insertWorkspaceFixture(db, [
{
Expand Down Expand Up @@ -244,6 +271,22 @@ describe('Organization Search tools in a workflow run', () => {
expect((await response.json()).person).toMatchObject({ name: colleagueName })
})

it('searches experts in a workflow run, pointing to integrations when no source is connected', async () => {
const response = await executeOrganizationSearchTool({
toolId: 'organization_search_experts',
input: { query: 'billing migration' },
headers: new Headers(),
context: runAs(memberUserId, organizationWorkflowId, organizationWorkspaceId),
requestId: generateId(),
})
expect(response.status).toBe(200)
expect(await response.json()).toMatchObject({
experts: [],
sources: [],
note: expect.stringMatching(/no connected sources.*\/integrations/),
})
})

it('refuses a run in an organization without Search', async () => {
searchAvailable.value = false
try {
Expand Down Expand Up @@ -402,6 +445,64 @@ describe('Organization Search tools in a workflow run', () => {
}
})

it('projects a run secret in an expert filter out of the profiles expert search returns', async () => {
const team = `Team ${generateId().slice(0, 8)}`
const { encrypted } = await encryptSecret(team)
await db.insert(memberProfile).values({ memberId: colleagueMemberId, department: team })
await db
.insert(environment)
.values({ id: memberUserId, userId: memberUserId, variables: { TEAM: encrypted } })
liveItems.value = [
{
provider: 'jira',
rank: 1,
contributors: [{ role: 'assignee', email: `${colleagueUserId}@organization-search.test` }],
result: {
documentId: 'ENG-1',
knowledgeBaseId: '',
knowledgeBaseName: 'jira',
documentName: 'Billing migration',
sourceUrl: 'https://example.test/ENG-1',
connectorType: 'jira',
sourceModifiedAt: null,
sourceDate: null,
author: null,
content: '',
chunkIndex: 0,
similarity: 1,
},
},
]
try {
const registry = new ResolvedSecretTraceRegistry(
[{ name: 'TEAM', plaintext: team, encryptedValue: encrypted }],
{ userId: memberUserId, workspaceId: organizationWorkspaceId }
)
registry.recordResolvedAtInputPath('TEAM', team, ['department'])
const headers = new Headers()
const input = addModelInputProvenanceToRequest(
{ query: 'billing migration', department: team },
headers,
createModelInputProvenanceRequestMetadata(registry, [['department']])
)
const response = await executeOrganizationSearchTool({
toolId: 'organization_search_experts',
input,
headers,
context: runAs(memberUserId, organizationWorkflowId, organizationWorkspaceId),
requestId: generateId(),
})
expect(response.status).toBe(200)
const text = await response.text()
expect(text).toContain(colleagueName)
expect(text).not.toContain(team)
} finally {
liveItems.value = null
await db.delete(environment).where(eq(environment.userId, memberUserId))
await db.delete(memberProfile).where(eq(memberProfile.memberId, colleagueMemberId))
}
})

it("refuses a person who is not a member of the workflow's organization", async () => {
const response = await call(
runAs(outsiderUserId, organizationWorkflowId, organizationWorkspaceId),
Expand Down
Loading
Loading