( userId: string, messageId: string | undefined, options: Required<BuildIntegrationToolSchemasOptions>, workspaceId?: string )
| 134 | } |
| 135 | |
| 136 | async function buildIntegrationToolSchemasUncached( |
| 137 | userId: string, |
| 138 | messageId: string | undefined, |
| 139 | options: Required<BuildIntegrationToolSchemasOptions>, |
| 140 | workspaceId?: string |
| 141 | ): Promise<ToolSchema[]> { |
| 142 | const reqLogger = logger.withMetadata({ messageId }) |
| 143 | const integrationTools: ToolSchema[] = [] |
| 144 | try { |
| 145 | const { createUserToolSchema } = await import('@/tools/params') |
| 146 | let shouldAppendEmailTagline = false |
| 147 | |
| 148 | try { |
| 149 | const subscription = await getHighestPrioritySubscription(userId) |
| 150 | shouldAppendEmailTagline = !subscription || !isPaid(subscription.plan) |
| 151 | } catch (error) { |
| 152 | reqLogger.warn('Failed to load subscription for copilot tool descriptions', { |
| 153 | userId, |
| 154 | error: toError(error).message, |
| 155 | }) |
| 156 | } |
| 157 | |
| 158 | let allowedIntegrations: Set<string> | null = null |
| 159 | let toolIdToBlockType: Map<string, string> | null = null |
| 160 | if (workspaceId) { |
| 161 | try { |
| 162 | const [{ getUserPermissionConfig }, { getAllBlocks }] = await Promise.all([ |
| 163 | import('@/ee/access-control/utils/permission-check'), |
| 164 | import('@/blocks/registry'), |
| 165 | ]) |
| 166 | const permissionConfig = await getUserPermissionConfig(userId, workspaceId) |
| 167 | if (permissionConfig?.allowedIntegrations) { |
| 168 | allowedIntegrations = new Set( |
| 169 | permissionConfig.allowedIntegrations.map((i) => i.toLowerCase()) |
| 170 | ) |
| 171 | toolIdToBlockType = new Map() |
| 172 | for (const blockConfig of getAllBlocks()) { |
| 173 | const access = blockConfig.tools?.access |
| 174 | if (!access) continue |
| 175 | for (const toolId of access) { |
| 176 | toolIdToBlockType.set(stripVersionSuffix(toolId), blockConfig.type.toLowerCase()) |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | } catch (error) { |
| 181 | reqLogger.warn('Failed to load permission config for tool schema filter', { |
| 182 | userId, |
| 183 | workspaceId, |
| 184 | error: toError(error).message, |
| 185 | }) |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | for (const { toolId, config: toolConfig, service } of getExposedIntegrationTools()) { |
| 190 | try { |
| 191 | if (allowedIntegrations && toolIdToBlockType) { |
| 192 | const owningBlock = toolIdToBlockType.get(stripVersionSuffix(toolId)) |
| 193 | if (owningBlock && !allowedIntegrations.has(owningBlock)) { |
no test coverage detected