Skip to content

Commit

Permalink
Switch to lazy imports to improve bundle counts; fix API counts
Browse files Browse the repository at this point in the history
  • Loading branch information
clintandrewhall committed Dec 6, 2024
1 parent 138c08a commit 7870eda
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 9 deletions.
1 change: 1 addition & 0 deletions x-pack/packages/ai/service_providers/connector_id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const SERVICE_PROVIDER_CONNECTOR_IDS: Record<ServiceProviderID, string> =

/**
* 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);
3 changes: 3 additions & 0 deletions x-pack/packages/ai/service_providers/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion x-pack/packages/ai/service_providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -41,7 +42,14 @@ export const SERVICE_PROVIDERS = SERVICE_PROVIDER_IDS.reduce((acc, id) => {
return acc;
}, {} as Record<ServiceProviderID, ServiceProvider>);

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.
Expand All @@ -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';
3 changes: 3 additions & 0 deletions x-pack/packages/ai/service_providers/logo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]();
3 changes: 3 additions & 0 deletions x-pack/packages/ai/service_providers/solutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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);
14 changes: 6 additions & 8 deletions x-pack/plugins/stack_connectors/public/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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 };

0 comments on commit 7870eda

Please sign in to comment.