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
1 change: 0 additions & 1 deletion apps/sim/lib/core/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,6 @@ export const env = createEnv({
CHANGELOG: z.boolean().optional(), // Fallback for the `changelog` feature flag off AppConfig
SIM_LINKS: z.boolean().optional(), // Fallback for the `sim-links` feature flag off AppConfig
PEOPLE: z.boolean().optional(), // Fallback for the `people` feature flag off AppConfig
MY_ACTIVITY: z.boolean().optional(), // Fallback for the `my-activity` feature flag off AppConfig
ORGANIZATION_ACTIVITY_ROLLUP_READS: z.boolean().optional(), // Fallback for the `organization-activity-rollup-reads` feature flag off AppConfig
ACTIVITY_ROLLUP_MAINTENANCE: z.boolean().optional(), // Fallback for the `activity-rollup-maintenance` feature flag off AppConfig
ACTIVITY_ROLLUP_BACKFILL_ROWS_PER_SECOND: z.coerce.number().int().positive().optional(), // Source rows the activity rollup backfill reads per second (default 20000)
Expand Down
6 changes: 0 additions & 6 deletions apps/sim/lib/core/config/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ const FEATURE_FLAGS = {
'Enable the organization People directory, org chart, profile imports, and directory sync. Supports organization rollout; disabled by default.',
fallback: 'PEOPLE',
},
'my-activity': {
description:
"Enable list_my_activity: the caller's own activity across their connected sources, in the " +
'Search MCP and the organization Assistant. Supports organization rollout; disabled by default.',
fallback: 'MY_ACTIVITY',
},
'mothership-model-selector': {
description:
'Show the Mothership model selector, model-specific effort levels, and Fast for supported ' +
Expand Down
6 changes: 3 additions & 3 deletions apps/sim/lib/internal/organization-search/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export interface OrganizationToolEntry {
inputSchema: z.ZodType
/** The arguments a workflow run's secret could fill, projected out of what the tool returns. */
modelInputPaths: readonly string[]
/** Who may call it: anyone, only a person (not a workspace API key), or callers with a feature on. */
requires?: 'person' | 'people' | 'activity'
/** Who may call it: anyone, only a person (not a workspace API key), or callers with People on. */
requires?: 'person' | 'people'
description: (context: DescriptionContext) => string
}

Expand Down Expand Up @@ -141,7 +141,7 @@ export const ORGANIZATION_TOOL_CATALOG = {
label: 'List My Activity',
inputSchema: listMyActivityMcpSchema,
modelInputPaths: [],
requires: 'activity',
requires: 'person',
description: ({ surface }): string => {
const [who, they, their] =
surface === 'mcp'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secret-tr

vi.hoisted(() => {
vi.stubEnv('PEOPLE', 'true')
vi.stubEnv('MY_ACTIVITY', 'true')
})

const { searchAvailable, liveItems } = vi.hoisted(() => ({
Expand Down
12 changes: 0 additions & 12 deletions apps/sim/lib/knowledge/mcp/route-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { createKnowledgeMcpServer } from '@/lib/knowledge/mcp/server'
import { repairToolCallMessage, toolCallInputIssues } from '@/lib/knowledge/mcp/tool-arguments'
import { getSearchMcpUrl } from '@/lib/knowledge/mcp/urls'
import { canLookUpPeople } from '@/lib/people/directory-lookup'
import { isMyActivityEnabled } from '@/lib/sim-search/live/activity'
import { v2CaughtOrchestrationError, v2Error } from '@/app/api/v2/lib/response'

const logger = createLogger('KnowledgeMcp')
Expand All @@ -43,16 +42,6 @@ function mcpAuth(resource: string) {
return mcpCredentialAuth({ resource, allowUnboundApiTokens: true })
}

/**
* Whether this message needs list_my_activity registered: a call to it, which its use case
* authorizes, or a tools/list while the feature is on for this organization.
*/
async function offersListMyActivity(message: Record<string, unknown>, organizationId: string) {
if (message.method === 'tools/call')
return isRecordLike(message.params) && message.params.name === 'list_my_activity'
return message.method === 'tools/list' && isMyActivityEnabled(organizationId)
}

export function createKnowledgeMcpHandlers() {
/** JSON-RPC is a protocol boundary; SDK dispatch calls the same authorized knowledge use cases. */
const handler = withRouteHandler(
Expand Down Expand Up @@ -93,7 +82,6 @@ export function createKnowledgeMcpHandlers() {
auth: admission.auth,
...parsed.data.params,
searchPeople: await offersSearchPeople(message, admission.auth.principal, organizationId),
listMyActivity: await offersListMyActivity(message, organizationId),
})
return await serveStatelessMcp(server, request, message)
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions apps/sim/lib/knowledge/mcp/server.protocol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ describe('Search MCP protocol', () => {
'chat',
'list_my_chat_history',
'search_experts',
'list_my_activity',
])
const searchSchema = tools.find((tool) => tool.name === 'search')?.inputSchema
const readSchema = tools.find((tool) => tool.name === 'read_document')?.inputSchema
Expand Down
6 changes: 4 additions & 2 deletions apps/sim/lib/knowledge/mcp/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ describe('organization chat', () => {
'chat',
'list_my_chat_history',
'search_experts',
'list_my_activity',
])
})
it('offers no chat history to a workspace API key, which acts for no person', () => {
Expand All @@ -525,12 +526,13 @@ describe('organization chat', () => {
})
expect(mocks.tools.has('list_my_chat_history')).toBe(false)
expect(mocks.tools.has('search_experts')).toBe(false)
expect(mocks.tools.has('list_my_activity')).toBe(false)
expect(mocks.configs.get('search')?.description).not.toContain('Other tools')
})
it.each([
[{}, 'Other tools: who knows a topic: search_experts.'],
[{}, 'Other tools: your own activity: list_my_activity; who knows a topic: search_experts.'],
[
{ searchPeople: true, listMyActivity: true },
{ searchPeople: true },
'Other tools: your own activity: list_my_activity; who knows a topic: search_experts; colleagues by name/role: search_people.',
],
])('points search at only the other tools this caller has (%o)', (offered, routing) => {
Expand Down
3 changes: 0 additions & 3 deletions apps/sim/lib/knowledge/mcp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ interface KnowledgeMcpContext {
auth: V2ApiKeyAuthContext
/** Registers search_people, which its use cases authorize on every call. */
searchPeople?: boolean
/** Registers list_my_activity, which its use case authorizes on every call. */
listMyActivity?: boolean
}

/** What a caller is told when the rate limit refuses a call, with when to retry if known. */
Expand Down Expand Up @@ -170,7 +168,6 @@ export function createKnowledgeMcpServer(context: KnowledgeMcpContext): McpServe
const granted = {
person: personal,
people: Boolean(context.searchPeople),
activity: Boolean(context.listMyActivity) && personal,
}
/** Whether this caller has a tool, so the server lists only those and descriptions point only to them. */
const offers = (name: OrganizationToolName): boolean => {
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/lib/mothership/chat/payload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ describe('buildCopilotRequestPayload', () => {
model: '',
})
expect(payload.entitlements).toEqual(
enabled ? [entitlement, 'workflow-code'] : ['workflow-code']
enabled ? [entitlement, 'workflow-code', 'my-activity'] : ['workflow-code', 'my-activity']
)
expect(featureFlagsMockFns.mockIsFeatureEnabled).toHaveBeenCalledWith(rolloutFlag, {
orgId: 'org-1',
Expand Down
11 changes: 7 additions & 4 deletions apps/sim/lib/mothership/entitlements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { readDashboardAvailability } from '@/lib/dashboards/application/availabi
import { isDashboardsEnabled } from '@/lib/dashboards/feature-flag'
import { ENTITLEMENTS, type Entitlement } from '@/lib/mothership/generated/protocol'
import { canLookUpPeople } from '@/lib/people/directory-lookup'
import { isMyActivityEnabled } from '@/lib/sim-search/live/activity'
import { readWorkflowTestAvailability } from '@/lib/workflow-tests/application/availability'
import { isWorkflowTestsEnabled } from '@/lib/workflow-tests/feature-flag'

Expand Down Expand Up @@ -90,10 +89,14 @@ const EVALUATORS: Record<Entitlement, EntitlementEvaluator> = {
assistant: ({ principal, organizationId }) =>
principal ? canLookUpPeople(principal, organizationId) : Promise.resolve(false),
},
/** `list_my_activity` in organization chats; its use case re-checks the flag. */
/**
* `list_my_activity` in organization chats, generally available; its use case authorizes every
* call. Vestigial like `workflowCode`: delete it once the Mothership worker stops gating the
* tool on it, via the `contracts:sync` that drops the name.
*/
[ENTITLEMENTS.myActivity]: {
assistant: ({ organizationId }) => isMyActivityEnabled(organizationId),
organization: ({ organizationId }) => isMyActivityEnabled(organizationId),
assistant: () => Promise.resolve(true),
organization: () => Promise.resolve(true),
},
}

Expand Down
2 changes: 0 additions & 2 deletions apps/sim/lib/sim-search/live/activity-paging.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import { afterAll, beforeAll, expect, it, vi } from 'vitest'
import { NativeSearchError } from '@/lib/sim-search/live/http'
import type { LiveAccount, NativeActivityInput, NativeDocument } from '@/lib/sim-search/live/types'

vi.hoisted(() => vi.stubEnv('MY_ACTIVITY', 'true'))

interface FakeItem {
id: string
at: string
Expand Down
27 changes: 1 addition & 26 deletions apps/sim/lib/sim-search/live/activity.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,10 @@ import {
} from '@sim/db/schema'
import { generateId } from '@sim/utils/id'
import { eq, inArray } from 'drizzle-orm'
import { afterAll, beforeAll, expect, it, vi } from 'vitest'
import { afterAll, beforeAll, expect, it } from 'vitest'
import { listMyActivityServerTool } from '@/lib/mothership/tools/server/knowledge/my-activity'
import { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secret-trace-registry'

/** The `my-activity` flag as a test sets it; every other flag resolves as configured. */
const myActivity = vi.hoisted(() => ({ enabled: true }))
vi.mock('@/lib/core/config/feature-flags', async (importOriginal) => {
const actual = await importOriginal<typeof import('@/lib/core/config/feature-flags')>()
return {
...actual,
isFeatureEnabled: (...args: Parameters<typeof actual.isFeatureEnabled>) =>
args[0] === 'my-activity'
? Promise.resolve(myActivity.enabled)
: actual.isFeatureEnabled(...args),
}
})

const org = generateId()
const readerId = generateId()
const otherId = generateId()
Expand Down Expand Up @@ -119,15 +106,3 @@ it('refuses a window longer than a quarter and a cursor it did not mint', async
await listMyActivityServerTool.execute({ cursor: 'not-a-cursor' }, turn(readerId, readerChat))
).toMatchObject({ success: false, message: expect.stringContaining('Invalid cursor') })
})

it('refuses to list activity for an organization where the feature is off', async () => {
myActivity.enabled = false
try {
expect(await listMyActivityServerTool.execute({}, turn(readerId, readerChat))).toMatchObject({
success: false,
message: expect.stringContaining('Activity listing is not enabled'),
})
} finally {
myActivity.enabled = true
}
})
14 changes: 1 addition & 13 deletions apps/sim/lib/sim-search/live/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
import { fingerprint, instantScopePart } from '@/lib/api/cursor-binding'
import { admitContent } from '@/lib/core/application'
import { env } from '@/lib/core/config/env'
import { isFeatureEnabled } from '@/lib/core/config/feature-flags'
import { OrchestrationError } from '@/lib/core/orchestration/types'
import { resourceScopeFromOwner, resourceScopeKey } from '@/lib/core/resource-scope'
import { createPinnedConnectionPool } from '@/lib/core/security/input-validation.server'
Expand Down Expand Up @@ -91,11 +90,6 @@ export interface ListMyActivityInput {
admitReads?: (accounts: number) => Promise<void>
}

/** Whether `list_my_activity` is rolled out to this organization (the `my-activity` flag). */
export function isMyActivityEnabled(organizationId: string): Promise<boolean> {
return isFeatureEnabled('my-activity', { orgId: organizationId })
}

/** Why an account's page stopped early when some of its items could not be checked in time. */
const UNVERIFIED_MESSAGE =
'Some items could not be checked against this source’s access rules in time; continue with nextCursor to read them.'
Expand Down Expand Up @@ -198,17 +192,11 @@ export const listMyActivity = defineAuthorizedKnowledgeUseCase({
async execute({ principal, input }): Promise<ListMyActivityResult> {
const userId = requirePrincipalSubjectUserId(principal)
const { organizationId } = input
const [, , enabled] = await Promise.all([
await Promise.all([
/** Live provider results carry no stored provenance; they are projected through `safeContent`. */
admitContent(principal, []),
requireOrganizationSearchAvailable(organizationId),
isMyActivityEnabled(organizationId),
])
if (!enabled)
throw new OrchestrationError(
'forbidden',
'Activity listing is not enabled for this organization'
)
const parsed = listMyActivityInputSchema.parse({
startDate: input.startDate,
endDate: input.endDate,
Expand Down
Loading