diff --git a/x-pack/plugins/observability_ai_assistant/public/application.tsx b/x-pack/plugins/observability_ai_assistant/public/application.tsx
index 4d915f412fcbe..a15d6a2de2a41 100644
--- a/x-pack/plugins/observability_ai_assistant/public/application.tsx
+++ b/x-pack/plugins/observability_ai_assistant/public/application.tsx
@@ -14,6 +14,8 @@ import React, { useMemo } from 'react';
import type { Observable } from 'rxjs';
import { KibanaThemeProvider } from '@kbn/react-kibana-context-theme';
import { ObservabilityAIAssistantProvider } from './context/observability_ai_assistant_provider';
+import { ObservabilityAiAssistantContext } from './context/observability_ai_assistant_plugins/observability_ai_assistant_plugin_context';
+import { LicenseProvider } from './context/license/license_context';
import { observabilityAIAssistantRouter } from './routes/config';
import type {
ObservabilityAIAssistantPluginStartDependencies,
@@ -39,22 +41,31 @@ export function Application({
return (
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
);
diff --git a/x-pack/plugins/observability_ai_assistant/public/components/chat/chat_body.tsx b/x-pack/plugins/observability_ai_assistant/public/components/chat/chat_body.tsx
index ddf47f1f6f341..0b841efe7a3bb 100644
--- a/x-pack/plugins/observability_ai_assistant/public/components/chat/chat_body.tsx
+++ b/x-pack/plugins/observability_ai_assistant/public/components/chat/chat_body.tsx
@@ -22,7 +22,7 @@ import type { Message } from '../../../common/types';
import type { UseGenAIConnectorsResult } from '../../hooks/use_genai_connectors';
import type { UseKnowledgeBaseResult } from '../../hooks/use_knowledge_base';
import { useTimeline } from '../../hooks/use_timeline';
-import { useLicense } from '../../hooks/use_license';
+import { useLicenseContext } from '../../context/license/use_license_context';
import { useObservabilityAIAssistantChatService } from '../../hooks/use_observability_ai_assistant_chat_service';
import { MissingCredentialsCallout } from '../missing_credentials_callout';
import { ExperimentalFeatureBanner } from './experimental_feature_banner';
@@ -74,8 +74,8 @@ export function ChatBody({
onChatComplete: (messages: Message[]) => void;
onSaveTitle: (title: string) => void;
}) {
- const { hasAtLeast } = useLicense();
- const hasCorrectLicense = hasAtLeast('enterprise');
+ const license = useLicenseContext();
+ const hasCorrectLicense = license?.hasAtLeast('enterprise');
const chatService = useObservabilityAIAssistantChatService();
diff --git a/x-pack/plugins/observability_ai_assistant/public/components/chat/experimental_feature_banner.tsx b/x-pack/plugins/observability_ai_assistant/public/components/chat/experimental_feature_banner.tsx
index aca0e5121e6a3..48935a49ccf02 100644
--- a/x-pack/plugins/observability_ai_assistant/public/components/chat/experimental_feature_banner.tsx
+++ b/x-pack/plugins/observability_ai_assistant/public/components/chat/experimental_feature_banner.tsx
@@ -42,7 +42,7 @@ export function ExperimentalFeatureBanner() {
-
+
{i18n.translate(
'xpack.observabilityAiAssistant.experimentalFunctionBanner.feedbackButton',
{ defaultMessage: 'Give feedback' }
diff --git a/x-pack/plugins/observability_ai_assistant/public/components/page_template.tsx b/x-pack/plugins/observability_ai_assistant/public/components/page_template.tsx
index ca360c10ffe96..94c36f463aaf4 100644
--- a/x-pack/plugins/observability_ai_assistant/public/components/page_template.tsx
+++ b/x-pack/plugins/observability_ai_assistant/public/components/page_template.tsx
@@ -19,7 +19,11 @@ const pageSectionContentClassName = css`
export function ObservabilityAIAssistantPageTemplate({ children }: { children: React.ReactNode }) {
const {
- services: { observabilityShared },
+ services: {
+ plugins: {
+ start: { observabilityShared },
+ },
+ },
} = useKibana();
const PageTemplate = observabilityShared.navigation.PageTemplate;
diff --git a/x-pack/plugins/observability_ai_assistant/public/context/license/license_context.tsx b/x-pack/plugins/observability_ai_assistant/public/context/license/license_context.tsx
new file mode 100644
index 0000000000000..f6fe296a3a9c0
--- /dev/null
+++ b/x-pack/plugins/observability_ai_assistant/public/context/license/license_context.tsx
@@ -0,0 +1,23 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0; you may not use this file except in compliance with the Elastic License
+ * 2.0.
+ */
+
+import React from 'react';
+import useObservable from 'react-use/lib/useObservable';
+import { ILicense } from '@kbn/licensing-plugin/public';
+import { useObservabilityAiAssistantPluginContext } from '../observability_ai_assistant_plugins/use_observability_ai_assistant_plugin_context';
+
+export const LicenseContext = React.createContext(undefined);
+
+export function LicenseProvider({ children }: { children: React.ReactChild }) {
+ const {
+ start: { licensing },
+ } = useObservabilityAiAssistantPluginContext();
+ const license = useObservable(licensing.license$);
+
+ // render rest of application and pass down license via context
+ return ;
+}
diff --git a/x-pack/plugins/observability_ai_assistant/public/context/license/use_license_context.ts b/x-pack/plugins/observability_ai_assistant/public/context/license/use_license_context.ts
new file mode 100644
index 0000000000000..25c2a9c243b45
--- /dev/null
+++ b/x-pack/plugins/observability_ai_assistant/public/context/license/use_license_context.ts
@@ -0,0 +1,13 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0; you may not use this file except in compliance with the Elastic License
+ * 2.0.
+ */
+
+import { useContext } from 'react';
+import { LicenseContext } from './license_context';
+
+export function useLicenseContext() {
+ return useContext(LicenseContext);
+}
diff --git a/x-pack/plugins/observability_ai_assistant/public/context/observability_ai_assistant_plugins/observability_ai_assistant_plugin_context.tsx b/x-pack/plugins/observability_ai_assistant/public/context/observability_ai_assistant_plugins/observability_ai_assistant_plugin_context.tsx
new file mode 100644
index 0000000000000..935b485e31242
--- /dev/null
+++ b/x-pack/plugins/observability_ai_assistant/public/context/observability_ai_assistant_plugins/observability_ai_assistant_plugin_context.tsx
@@ -0,0 +1,17 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0; you may not use this file except in compliance with the Elastic License
+ * 2.0.
+ */
+
+import { createContext } from 'react';
+import { ObservabilityAIAssistantPluginStartDependencies } from '../../types';
+
+export interface ObservabilityAiAssistantPluginContextValue {
+ start: ObservabilityAIAssistantPluginStartDependencies;
+}
+
+export const ObservabilityAiAssistantContext = createContext(
+ {} as ObservabilityAiAssistantPluginContextValue
+);
diff --git a/x-pack/plugins/observability_ai_assistant/public/context/observability_ai_assistant_plugins/use_observability_ai_assistant_plugin_context.ts b/x-pack/plugins/observability_ai_assistant/public/context/observability_ai_assistant_plugins/use_observability_ai_assistant_plugin_context.ts
new file mode 100644
index 0000000000000..76db35d5d9531
--- /dev/null
+++ b/x-pack/plugins/observability_ai_assistant/public/context/observability_ai_assistant_plugins/use_observability_ai_assistant_plugin_context.ts
@@ -0,0 +1,13 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0; you may not use this file except in compliance with the Elastic License
+ * 2.0.
+ */
+
+import { useContext } from 'react';
+import { ObservabilityAiAssistantContext } from './observability_ai_assistant_plugin_context';
+
+export function useObservabilityAiAssistantPluginContext() {
+ return useContext(ObservabilityAiAssistantContext);
+}
diff --git a/x-pack/plugins/observability_ai_assistant/public/functions/lens.tsx b/x-pack/plugins/observability_ai_assistant/public/functions/lens.tsx
index b5d745efd110f..d5d2c715d0c52 100644
--- a/x-pack/plugins/observability_ai_assistant/public/functions/lens.tsx
+++ b/x-pack/plugins/observability_ai_assistant/public/functions/lens.tsx
@@ -40,7 +40,11 @@ function Lens({
end: string;
}) {
const {
- services: { lens, dataViews },
+ services: {
+ plugins: {
+ start: { lens, dataViews },
+ },
+ },
} = useKibana();
const formulaAsync = useAsync(() => {
diff --git a/x-pack/plugins/observability_ai_assistant/public/hooks/use_kibana.ts b/x-pack/plugins/observability_ai_assistant/public/hooks/use_kibana.ts
index d8cd468aedbb7..03cdd5f5ac826 100644
--- a/x-pack/plugins/observability_ai_assistant/public/hooks/use_kibana.ts
+++ b/x-pack/plugins/observability_ai_assistant/public/hooks/use_kibana.ts
@@ -9,9 +9,9 @@ import { CoreStart } from '@kbn/core/public';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { ObservabilityAIAssistantPluginStartDependencies } from '../types';
-export type StartServices = CoreStart &
- ObservabilityAIAssistantPluginStartDependencies &
- TAdditionalServices & {};
+export type StartServices = CoreStart & {
+ plugins: { start: ObservabilityAIAssistantPluginStartDependencies };
+} & TAdditionalServices & {};
const useTypedKibana = () =>
useKibana>();
diff --git a/x-pack/plugins/observability_ai_assistant/public/hooks/use_license.ts b/x-pack/plugins/observability_ai_assistant/public/hooks/use_license.ts
deleted file mode 100644
index 57aafe0613c15..0000000000000
--- a/x-pack/plugins/observability_ai_assistant/public/hooks/use_license.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License
- * 2.0; you may not use this file except in compliance with the Elastic License
- * 2.0.
- */
-
-import { useCallback } from 'react';
-import { Observable } from 'rxjs';
-import useObservable from 'react-use/lib/useObservable';
-import type { ILicense, LicenseType } from '@kbn/licensing-plugin/public';
-import { useKibana } from './use_kibana';
-
-interface UseLicenseReturnValue {
- getLicense: () => ILicense | null;
- hasAtLeast: (level: LicenseType) => boolean | undefined;
-}
-
-export const useLicense = (): UseLicenseReturnValue => {
- const { licensing } = useKibana().services;
-
- const license = useObservable(licensing?.license$ ?? new Observable(), null);
-
- return {
- getLicense: () => license,
- hasAtLeast: useCallback(
- (level: LicenseType) => {
- if (!license) return;
-
- return !!license && license.isAvailable && license.isActive && license.hasAtLeast(level);
- },
- [license]
- ),
- };
-};
diff --git a/x-pack/plugins/observability_ai_assistant/public/hooks/use_license_management_locator.ts b/x-pack/plugins/observability_ai_assistant/public/hooks/use_license_management_locator.ts
index d872c5ae5d42d..650627ec9ff7c 100644
--- a/x-pack/plugins/observability_ai_assistant/public/hooks/use_license_management_locator.ts
+++ b/x-pack/plugins/observability_ai_assistant/public/hooks/use_license_management_locator.ts
@@ -5,12 +5,14 @@
* 2.0.
*/
-import { useKibana } from './use_kibana';
+import { useObservabilityAiAssistantPluginContext } from '../context/observability_ai_assistant_plugins/use_observability_ai_assistant_plugin_context';
const LICENSE_MANAGEMENT_LOCATOR = 'LICENSE_MANAGEMENT_LOCATOR';
export const useLicenseManagementLocator = () => {
- const { share } = useKibana().services;
+ const {
+ start: { share },
+ } = useObservabilityAiAssistantPluginContext();
const locator = share.url.locators.get(LICENSE_MANAGEMENT_LOCATOR);