From 7870edab9216eb3a195f016b796d99e848f60b9d Mon Sep 17 00:00:00 2001 From: Clint Andrew Hall Date: Fri, 6 Dec 2024 07:16:33 -0500 Subject: [PATCH] Switch to lazy imports to improve bundle counts; fix API counts --- .../packages/ai/service_providers/connector_id.ts | 1 + x-pack/packages/ai/service_providers/id.ts | 3 +++ x-pack/packages/ai/service_providers/index.ts | 15 ++++++++++++++- .../packages/ai/service_providers/logo/index.ts | 3 +++ x-pack/packages/ai/service_providers/solutions.ts | 3 +++ .../packages/service_providers/index.ts | 9 +++++++++ .../stack_connectors/public/common/index.ts | 14 ++++++-------- 7 files changed, 39 insertions(+), 9 deletions(-) diff --git a/x-pack/packages/ai/service_providers/connector_id.ts b/x-pack/packages/ai/service_providers/connector_id.ts index f8a29e93f7765..b789ecad9f5b1 100644 --- a/x-pack/packages/ai/service_providers/connector_id.ts +++ b/x-pack/packages/ai/service_providers/connector_id.ts @@ -18,6 +18,7 @@ export const SERVICE_PROVIDER_CONNECTOR_IDS: Record = /** * Returns true if the given string is a supported connector type, false otherwise. + * @param id The connector type ID to check. */ export const isSupportedConnectorId = (id: string) => Object.values(SERVICE_PROVIDER_CONNECTOR_IDS).includes(id); diff --git a/x-pack/packages/ai/service_providers/id.ts b/x-pack/packages/ai/service_providers/id.ts index e2634578295ba..6a019d2494150 100644 --- a/x-pack/packages/ai/service_providers/id.ts +++ b/x-pack/packages/ai/service_providers/id.ts @@ -5,6 +5,9 @@ * 2.0. */ +/** + * Available AI Service Provider IDs. + */ export type ServiceProviderID = (typeof SERVICE_PROVIDER_IDS)[number]; // There are more service providers in @kbn/stack-connectors-plugin, but until diff --git a/x-pack/packages/ai/service_providers/index.ts b/x-pack/packages/ai/service_providers/index.ts index 6409e06be2706..0a994305cbe39 100644 --- a/x-pack/packages/ai/service_providers/index.ts +++ b/x-pack/packages/ai/service_providers/index.ts @@ -7,6 +7,7 @@ export { type ServiceProviderID, SERVICE_PROVIDER_IDS } from './id'; export { getReactComponentLogo, getBase64Logo, getUrlLogo } from './logo'; +export type { ProviderSolution } from './solutions'; import { SERVICE_PROVIDER_CONNECTOR_IDS } from './connector_id'; import { type ServiceProviderID, SERVICE_PROVIDER_IDS } from './id'; @@ -41,7 +42,14 @@ export const SERVICE_PROVIDERS = SERVICE_PROVIDER_IDS.reduce((acc, id) => { return acc; }, {} as Record); -export const { bedrock, gemini, openai } = SERVICE_PROVIDERS; +export const { + /** Amazon Bedrock */ + bedrock, + /** Google Gemini */ + gemini, + /** Open AI */ + openai, +} = SERVICE_PROVIDERS; /** * Return all Service Provider IDs. @@ -55,7 +63,12 @@ export const getServiceProviders = () => SERVICE_PROVIDERS; /** * Return a Service Provider by ID. + * @param id The ID of the Service Provider. */ export const getServiceProvider = (id: ServiceProviderID) => SERVICE_PROVIDERS[id]; +/** + * Returns true if the given string is a supported connector type, false otherwise. + * @param id The connector type ID to check. + */ export { isSupportedConnectorId } from './connector_id'; diff --git a/x-pack/packages/ai/service_providers/logo/index.ts b/x-pack/packages/ai/service_providers/logo/index.ts index a81ec952e334e..b5ba1d87d50e5 100644 --- a/x-pack/packages/ai/service_providers/logo/index.ts +++ b/x-pack/packages/ai/service_providers/logo/index.ts @@ -48,15 +48,18 @@ const LOGO_URL = { /** * Get a lazy-loaded React component, wrapped in a `Suspense` boundary, for the logo of a service provider. + * @param id The ID of the service provider. */ export const getReactComponentLogo = (id: ServiceProviderID) => LOGO_REACT[id]; /** * Get the base64-encoded SVG of the logo of a service provider. + * @param id The ID of the service provider. */ export const getBase64Logo = async (id: ServiceProviderID) => LOGO_BASE_64[id](); /** * Get the URL of the logo of a service provider. + * @param id The ID of the service provider. */ export const getUrlLogo = async (id: ServiceProviderID) => LOGO_URL[id](); diff --git a/x-pack/packages/ai/service_providers/solutions.ts b/x-pack/packages/ai/service_providers/solutions.ts index 41defc56b76e8..54d56d2af5e43 100644 --- a/x-pack/packages/ai/service_providers/solutions.ts +++ b/x-pack/packages/ai/service_providers/solutions.ts @@ -7,6 +7,9 @@ import { ServiceProviderID } from './id'; +/** + * Solutions in which AI Service Providers can be used. + */ export type ProviderSolution = 'Observability' | 'Security' | 'Search'; // There are more service providers in @kbn/stack-connectors-plugin, diff --git a/x-pack/packages/kbn-ai-assistant/packages/service_providers/index.ts b/x-pack/packages/kbn-ai-assistant/packages/service_providers/index.ts index b238741b86134..be23cef60d8fe 100644 --- a/x-pack/packages/kbn-ai-assistant/packages/service_providers/index.ts +++ b/x-pack/packages/kbn-ai-assistant/packages/service_providers/index.ts @@ -34,9 +34,14 @@ export const SERVICE_PROVIDERS = { openai, } as const; +/** The ID of an AI Service Provider. */ export type ServiceProviderID = keyof typeof SERVICE_PROVIDERS; const SERVICE_PROVIDER_IDS = Object.keys(SERVICE_PROVIDERS) as ServiceProviderID[]; +/** + * Returns true if the given string is a supported connector type, false otherwise. + * @param id The connector type ID to check. + */ export const isSupportedConnectorId = (id: string): id is ServiceProviderID => { return id in SERVICE_PROVIDERS; }; @@ -53,20 +58,24 @@ export const getServiceProviders = () => SERVICE_PROVIDERS; /** * Return a Service Provider by ID. + * @param id The ID of the Service Provider to get. */ export const getServiceProvider = (id: ServiceProviderID) => SERVICE_PROVIDERS[id]; /** * Get a lazy-loaded React component, wrapped in a `Suspense` boundary, for the logo of a service provider. + * @param id The ID of the service provider. */ export const getReactComponentLogo = (id: ServiceProviderID) => _getReactComponentLogo(id); /** * Get the base64-encoded SVG of the logo of a service provider. + * @param id The ID of the service provider. */ export const getBase64Logo = async (id: ServiceProviderID) => _getBase64Logo(id); /** * Get the URL of the logo of a service provider. + * @param id The ID of the service provider. */ export const getUrlLogo = async (id: ServiceProviderID) => _getUrlLogo(id); diff --git a/x-pack/plugins/stack_connectors/public/common/index.ts b/x-pack/plugins/stack_connectors/public/common/index.ts index a1f0f2037f37e..2b1d2f95d4012 100644 --- a/x-pack/plugins/stack_connectors/public/common/index.ts +++ b/x-pack/plugins/stack_connectors/public/common/index.ts @@ -5,15 +5,16 @@ * 2.0. */ -import GeminiLogo from '@kbn/ai-service-providers/logo/gemini'; -import OpenAILogo from '@kbn/ai-service-providers/logo/open_ai'; -import BedrockLogo from '@kbn/ai-service-providers/logo/bedrock'; +import { getReactComponentLogo } from '@kbn/ai-service-providers'; export { GEMINI_CONNECTOR_ID } from '../../common/gemini/constants'; +export const GeminiLogo = getReactComponentLogo('gemini'); export { OPENAI_CONNECTOR_ID, OpenAiProviderType } from '../../common/openai/constants'; -export { OpenAILogo }; -export { GeminiLogo }; +export const OpenAILogo = getReactComponentLogo('openai'); + +export { BEDROCK_CONNECTOR_ID } from '../../common/bedrock/constants'; +export const BedrockLogo = getReactComponentLogo('bedrock'); import SentinelOneLogo from '../connector_types/sentinelone/logo'; @@ -27,6 +28,3 @@ export { SUB_ACTION as CROWDSTRIKE_SUB_ACTION, } from '../../common/crowdstrike/constants'; export { CrowdstrikeLogo }; - -export { BEDROCK_CONNECTOR_ID } from '../../common/bedrock/constants'; -export { BedrockLogo };