Skip to content

Commit 2ed51e7

Browse files
committed
Serialize account and organization truth into the copilot VFS
Workspace standing, membership, billing, org role, access-control restrictions, published-block provenance, and fork topology were reachable only through three parameterless tools (or not at all). They are ambient read-only facts, so they belong in the VFS where they are greppable, cost no tool round-trip, and every agent that can read gets them — the same move that retired get_blocks_and_tools and list_user_workflows. Adds account/{workspace,workspaces,members,billing}.json (always mounted) and organization/{organization,access-control,custom-blocks,forks}.json (only when the workspace is org-hosted). Every file projects an existing use case or util after getOrMaterializeVFS's access assert — no new queries, no new authorization. One relation per file, cross-referenced by id-and-name stub, so overlapping facts cannot disagree. Volatile content (billing, access control, forks) is lazy, so numbers are read-time fresh and unasked-for reads cost nothing. Projection follows the viewer: member emails are admin-only, fork detail requires workspace admin on a forking-enabled org, and the whole organization/ namespace is absent for a personal workspace — which is itself the answer. Retires get_account_billing, get_enterprise_context, and list_user_workspaces along with their handlers; display titles stay for transcript replay.
1 parent 3959fe9 commit 2ed51e7

14 files changed

Lines changed: 778 additions & 671 deletions

apps/sim/lib/copilot/entitlements.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getErrorMessage } from '@sim/utils/errors'
33
import { LRUCache } from 'lru-cache'
44
import { hasWorkspaceSandboxAccess } from '@/lib/billing/core/subscription'
55
import { isCustomBlocksEligible } from '@/lib/workflows/custom-blocks/operations'
6+
import { getWorkspaceWithOwner } from '@/lib/workspaces/permissions/utils'
67

78
const logger = createLogger('CopilotEntitlements')
89

@@ -12,6 +13,7 @@ const logger = createLogger('CopilotEntitlements')
1213
*/
1314
export const CUSTOM_BLOCKS_ENTITLEMENT = 'custom-blocks'
1415
export const SIM_SANDBOXES_ENTITLEMENT = 'sim-sandboxes'
16+
export const ORGANIZATION_CONTEXT_ENTITLEMENT = 'organization-context'
1517

1618
/**
1719
* Workspace entitlements — plan/flag-gated org capabilities sent to the
@@ -36,6 +38,18 @@ const ENTITLEMENT_EVALUATORS: Record<
3638
> = {
3739
[CUSTOM_BLOCKS_ENTITLEMENT]: isCustomBlocksEligible,
3840
[SIM_SANDBOXES_ENTITLEMENT]: hasWorkspaceSandboxAccess,
41+
[ORGANIZATION_CONTEXT_ENTITLEMENT]: isOrganizationContextAvailable,
42+
}
43+
44+
/**
45+
* True when this workspace belongs to an organization, which is exactly when
46+
* the copilot's `organization/` VFS namespace has anything in it. Advertising
47+
* it keeps a personal workspace's agents from ever hearing that org standing,
48+
* access-control groups, or fork topology exist.
49+
*/
50+
async function isOrganizationContextAvailable(workspaceId: string): Promise<boolean> {
51+
const workspace = await getWorkspaceWithOwner(workspaceId)
52+
return Boolean(workspace?.organizationId)
3953
}
4054

4155
const entitlementsCache = new LRUCache<string, Promise<string[]>>({

apps/sim/lib/copilot/generated/tool-catalog-v1.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,10 @@ export interface ToolCatalogEntry {
5555
| 'generate_audio'
5656
| 'generate_image'
5757
| 'generate_video'
58-
| 'get_account_billing'
5958
| 'get_block_outputs'
6059
| 'get_block_upstream_references'
6160
| 'get_deployed_workflow_state'
6261
| 'get_deployment_status'
63-
| 'get_enterprise_context'
6462
| 'get_workflow_data'
6563
| 'get_workflow_run_options'
6664
| 'glob'
@@ -69,7 +67,6 @@ export interface ToolCatalogEntry {
6967
| 'knowledge'
7068
| 'list_deployment_versions'
7169
| 'list_integration_tools'
72-
| 'list_user_workspaces'
7370
| 'list_workspace_mcp_servers'
7471
| 'load_deployment'
7572
| 'load_integration_tool'
@@ -186,12 +183,10 @@ export interface ToolCatalogEntry {
186183
| 'generate_audio'
187184
| 'generate_image'
188185
| 'generate_video'
189-
| 'get_account_billing'
190186
| 'get_block_outputs'
191187
| 'get_block_upstream_references'
192188
| 'get_deployed_workflow_state'
193189
| 'get_deployment_status'
194-
| 'get_enterprise_context'
195190
| 'get_workflow_data'
196191
| 'get_workflow_run_options'
197192
| 'glob'
@@ -200,7 +195,6 @@ export interface ToolCatalogEntry {
200195
| 'knowledge'
201196
| 'list_deployment_versions'
202197
| 'list_integration_tools'
203-
| 'list_user_workspaces'
204198
| 'list_workspace_mcp_servers'
205199
| 'load_deployment'
206200
| 'load_integration_tool'
@@ -3004,14 +2998,6 @@ export const GenerateVideo: ToolCatalogEntry = {
30042998
capabilities: ['file_input', 'file_output', 'generated_media'],
30052999
}
30063000

3007-
export const GetAccountBilling: ToolCatalogEntry = {
3008-
id: 'get_account_billing',
3009-
name: 'get_account_billing',
3010-
route: 'sim',
3011-
mode: 'async',
3012-
parameters: { type: 'object', properties: {} },
3013-
}
3014-
30153001
export const GetBlockOutputs: ToolCatalogEntry = {
30163002
id: 'get_block_outputs',
30173003
name: 'get_block_outputs',
@@ -3089,14 +3075,6 @@ export const GetDeploymentStatus: ToolCatalogEntry = {
30893075
},
30903076
}
30913077

3092-
export const GetEnterpriseContext: ToolCatalogEntry = {
3093-
id: 'get_enterprise_context',
3094-
name: 'get_enterprise_context',
3095-
route: 'sim',
3096-
mode: 'async',
3097-
parameters: { type: 'object', properties: {} },
3098-
}
3099-
31003078
export const GetWorkflowData: ToolCatalogEntry = {
31013079
id: 'get_workflow_data',
31023080
name: 'get_workflow_data',
@@ -3287,14 +3265,6 @@ export const ListIntegrationTools: ToolCatalogEntry = {
32873265
},
32883266
}
32893267

3290-
export const ListUserWorkspaces: ToolCatalogEntry = {
3291-
id: 'list_user_workspaces',
3292-
name: 'list_user_workspaces',
3293-
route: 'sim',
3294-
mode: 'async',
3295-
parameters: { type: 'object', properties: {} },
3296-
}
3297-
32983268
export const ListWorkspaceMcpServers: ToolCatalogEntry = {
32993269
id: 'list_workspace_mcp_servers',
33003270
name: 'list_workspace_mcp_servers',
@@ -7245,12 +7215,10 @@ export const TOOL_CATALOG: Record<string, ToolCatalogEntry> = {
72457215
[GenerateAudio.id]: GenerateAudio,
72467216
[GenerateImage.id]: GenerateImage,
72477217
[GenerateVideo.id]: GenerateVideo,
7248-
[GetAccountBilling.id]: GetAccountBilling,
72497218
[GetBlockOutputs.id]: GetBlockOutputs,
72507219
[GetBlockUpstreamReferences.id]: GetBlockUpstreamReferences,
72517220
[GetDeployedWorkflowState.id]: GetDeployedWorkflowState,
72527221
[GetDeploymentStatus.id]: GetDeploymentStatus,
7253-
[GetEnterpriseContext.id]: GetEnterpriseContext,
72547222
[GetWorkflowData.id]: GetWorkflowData,
72557223
[GetWorkflowRunOptions.id]: GetWorkflowRunOptions,
72567224
[Glob.id]: Glob,
@@ -7259,7 +7227,6 @@ export const TOOL_CATALOG: Record<string, ToolCatalogEntry> = {
72597227
[Knowledge.id]: Knowledge,
72607228
[ListDeploymentVersions.id]: ListDeploymentVersions,
72617229
[ListIntegrationTools.id]: ListIntegrationTools,
7262-
[ListUserWorkspaces.id]: ListUserWorkspaces,
72637230
[ListWorkspaceMcpServers.id]: ListWorkspaceMcpServers,
72647231
[LoadDeployment.id]: LoadDeployment,
72657232
[LoadIntegrationTool.id]: LoadIntegrationTool,

apps/sim/lib/copilot/generated/tool-schemas-v1.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,13 +2959,6 @@ export const TOOL_RUNTIME_SCHEMAS: Record<string, ToolRuntimeSchemaEntry> = {
29592959
},
29602960
resultSchema: undefined,
29612961
},
2962-
get_account_billing: {
2963-
parameters: {
2964-
type: 'object',
2965-
properties: {},
2966-
},
2967-
resultSchema: undefined,
2968-
},
29692962
get_block_outputs: {
29702963
parameters: {
29712964
type: 'object',
@@ -3034,13 +3027,6 @@ export const TOOL_RUNTIME_SCHEMAS: Record<string, ToolRuntimeSchemaEntry> = {
30343027
},
30353028
resultSchema: undefined,
30363029
},
3037-
get_enterprise_context: {
3038-
parameters: {
3039-
type: 'object',
3040-
properties: {},
3041-
},
3042-
resultSchema: undefined,
3043-
},
30443030
get_workflow_data: {
30453031
parameters: {
30463032
type: 'object',
@@ -3209,13 +3195,6 @@ export const TOOL_RUNTIME_SCHEMAS: Record<string, ToolRuntimeSchemaEntry> = {
32093195
},
32103196
resultSchema: undefined,
32113197
},
3212-
list_user_workspaces: {
3213-
parameters: {
3214-
type: 'object',
3215-
properties: {},
3216-
},
3217-
resultSchema: undefined,
3218-
},
32193198
list_workspace_mcp_servers: {
32203199
parameters: {
32213200
type: 'object',

apps/sim/lib/copilot/tool-executor/register-handlers.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,16 @@ import {
1010
DeployAsMcp,
1111
DiffWorkflows,
1212
GenerateApiKey,
13-
GetAccountBilling,
1413
GetBlockOutputs,
1514
GetBlockUpstreamReferences,
1615
GetDeployedWorkflowState,
1716
GetDeploymentStatus,
18-
GetEnterpriseContext,
1917
GetWorkflowData,
2018
GetWorkflowRunOptions,
2119
Glob as GlobTool,
2220
Grep as GrepTool,
2321
ListDeploymentVersions,
2422
ListIntegrationTools,
25-
ListUserWorkspaces,
2623
ListWorkspaceMcpServers,
2724
LoadDeployment,
2825
ManageCredential,
@@ -53,8 +50,6 @@ import {
5350
UpdateDeploymentVersion,
5451
UpdateWorkspaceMcpServer,
5552
} from '@/lib/copilot/generated/tool-catalog-v1'
56-
import { executeGetAccountBilling } from '@/lib/copilot/tools/handlers/account'
57-
import { executeGetEnterpriseContext } from '@/lib/copilot/tools/handlers/enterprise-context'
5853
import { createServerToolHandler } from '@/lib/copilot/tools/registry/server-tool-adapter'
5954
import { getRegisteredServerToolNames } from '@/lib/copilot/tools/server/router'
6055
import { executeDeployCustomBlock } from '../tools/handlers/deployment/custom-block'
@@ -114,7 +109,6 @@ import {
114109
executeGetDeployedWorkflowState,
115110
executeGetWorkflowData,
116111
executeGetWorkflowRunOptions,
117-
executeListUserWorkspaces,
118112
} from '../tools/handlers/workflow/queries'
119113
import { registerHandlers } from './executor'
120114
import type { ToolHandler } from './types'
@@ -139,9 +133,6 @@ function h(fn: (params: any, context: any) => Promise<any>): ToolHandler {
139133

140134
function buildHandlerMap(): Record<string, ToolHandler> {
141135
return {
142-
[ListUserWorkspaces.id]: h((_p, c) => executeListUserWorkspaces(c)),
143-
[GetAccountBilling.id]: h((_p, c) => executeGetAccountBilling(c)),
144-
[GetEnterpriseContext.id]: h((_p, c) => executeGetEnterpriseContext(c)),
145136
[GetWorkflowData.id]: h(executeGetWorkflowData),
146137
[GetWorkflowRunOptions.id]: h(executeGetWorkflowRunOptions),
147138
[GetBlockOutputs.id]: h(executeGetBlockOutputs),

apps/sim/lib/copilot/tools/handlers/account.test.ts

Lines changed: 0 additions & 107 deletions
This file was deleted.

apps/sim/lib/copilot/tools/handlers/account.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)