Skip to content

Commit 80bd914

Browse files
committed
fix(search-assistant): keep person-filtered searches out of Search tabs and people reads to Assistant turns
1 parent 00ba38c commit 80bd914

4 files changed

Lines changed: 28 additions & 4 deletions

File tree

‎apps/sim/lib/mothership/application/execute-people-use-case.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { OrganizationDelegatedPrincipal } from '@sim/auth/principal'
2+
import { OrchestrationError } from '@/lib/core/orchestration/types'
23
import {
34
COPILOT_APPLICATION_DELEGATION_TTL_MS,
45
type CopilotExecutionContext,
@@ -14,15 +15,21 @@ interface CopilotPeopleScope {
1415
}
1516

1617
/**
17-
* Runs a People directory read for the organization Assistant: the subject and organization come
18-
* from the trusted turn, the delegation is bound to the member's private chat, and the People use
19-
* cases the read calls still check the feature, the membership and the directory capability.
18+
* Runs a People directory read for the organization Assistant, the only mode Sim grants the
19+
* `people` entitlement in. The subject and organization come from the trusted turn, the
20+
* delegation is bound to the member's private chat, and the People use cases the read calls
21+
* still check the feature, the membership and the directory capability.
2022
*/
2123
export async function executeCopilotPeopleRead<R>(
2224
context: CopilotExecutionContext | undefined,
2325
read: (scope: CopilotPeopleScope) => Promise<R>
2426
): Promise<R> {
2527
const trusted = requireTrustedOrganizationCopilotContext(context)
28+
if (context?.requestMode !== 'assistant')
29+
throw new OrchestrationError(
30+
'forbidden',
31+
'The People directory is available only in organization Assistant conversations'
32+
)
2633
const principal = createTrustedOrganizationCopilotPrincipal(
2734
{ ...trusted, delegationId: trusted.toolCallId },
2835
{

‎apps/sim/lib/mothership/resources/search-tool-result.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ export function searchResourceFromToolResult(
3333
topK,
3434
query: _query,
3535
nativeQueries,
36+
involving,
3637
...requestedFilters
3738
} = searchWorkspaceInputSchema.parse(params)
39+
/** A Search tab cannot repeat a person filter, so refreshing it would drop the restriction. */
40+
if (involving) return undefined
3841
const nativeProjection = nativeQueries
3942
? context.resolvedSecretTraceRegistry &&
4043
projectResolvedSecretModelContent(nativeQueries, context.resolvedSecretTraceRegistry)

‎apps/sim/lib/mothership/resources/search.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ describe('Search resource addresses', () => {
4848
expect(mothershipResourceSchema.parse(resource)).toEqual(resource)
4949
expect(sanitizeChatResources([resource])).toEqual([resource])
5050
})
51+
it('publishes no Search tab for a person-filtered search it could not repeat', () => {
52+
expect(
53+
searchResourceFromToolResult({ query: 'roadmap', involving: 'me' }, output, context)
54+
).toBeUndefined()
55+
})
5156
it('keeps date-only and native search addresses for an exact result-panel refresh', () => {
5257
const nativeQueries = [
5358
{ provider: 'github' as const, query: 'repo:simstudioai/sim deployment' },

‎apps/sim/lib/mothership/tools/server/knowledge/people.integration.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,20 @@ it('refuses a chat owner who is no longer a member of the organization', async (
115115
expect(JSON.stringify(result)).not.toContain('Grace Lead')
116116
})
117117

118-
it('offers the directory only in organization conversations', async () => {
118+
it('offers the directory only in organization Assistant conversations', async () => {
119119
expect(
120120
await searchPeopleServerTool.execute(
121121
{ query: 'grace' },
122122
{ ...turn(readerId, readerChat), organizationId: undefined, workspaceId: generateId() }
123123
)
124124
).toMatchObject({ success: false })
125+
expect(
126+
await searchPeopleServerTool.execute(
127+
{ query: 'grace' },
128+
{ ...turn(readerId, readerChat), requestMode: 'agent' }
129+
)
130+
).toEqual({
131+
success: false,
132+
message: 'The People directory is available only in organization Assistant conversations',
133+
})
125134
})

0 commit comments

Comments
 (0)