From 9f271cab0defd3e5ffd454005b9f1b4e3790c3c6 Mon Sep 17 00:00:00 2001 From: Fernando Pauer Date: Thu, 21 Nov 2024 10:45:27 -0800 Subject: [PATCH] fix: assistant failing to fetch --- .../src/components/assistant/chatbot.tsx | 4 ++-- .../src/components/dashboard/getClients.ts | 22 ++----------------- .../src/components/dashboard/getQueries.ts | 4 +--- .../src/components/dashboard/index.tsx | 10 ++++----- .../src/components/dashboard/view.tsx | 8 +++---- .../src/hooks/useAssistantConfiguration.ts | 6 ++--- packages/dashboard/src/messages.ts | 2 +- packages/dashboard/src/types.ts | 2 -- 8 files changed, 16 insertions(+), 42 deletions(-) diff --git a/packages/dashboard/src/components/assistant/chatbot.tsx b/packages/dashboard/src/components/assistant/chatbot.tsx index 050de1ae1..90a989ff1 100644 --- a/packages/dashboard/src/components/assistant/chatbot.tsx +++ b/packages/dashboard/src/components/assistant/chatbot.tsx @@ -28,7 +28,7 @@ export const Chatbot: FC = ( ) => { const dispatch = useDispatch(); const assistant = useSelector((state: DashboardState) => state.assistant); - const { iotSiteWisePrivateClient } = useClients(); + const { iotSiteWise } = useClients(); const { getContextByComponent } = useAssistantContext(); const initialMessages: Array = [ { @@ -42,7 +42,7 @@ export const Chatbot: FC = ( const client = new IoTSitewiseAssistantClient({ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - iotSiteWiseClient: iotSiteWisePrivateClient!, + iotSiteWiseClient: iotSiteWise!, }); const { messages, setMessages, invokeAssistant, generateSummary, clearAll } = diff --git a/packages/dashboard/src/components/dashboard/getClients.ts b/packages/dashboard/src/components/dashboard/getClients.ts index cff2f5e25..c699c7db9 100644 --- a/packages/dashboard/src/components/dashboard/getClients.ts +++ b/packages/dashboard/src/components/dashboard/getClients.ts @@ -1,17 +1,12 @@ import { IoTEventsClient } from '@aws-sdk/client-iot-events'; -import { - IoTSiteWiseClient, - IoTSiteWise, - IoTSiteWise as InternalIoTSiteWise, -} from '@aws-sdk/client-iotsitewise'; +import { IoTSiteWiseClient, IoTSiteWise } from '@aws-sdk/client-iotsitewise'; import { IoTTwinMakerClient } from '@aws-sdk/client-iottwinmaker'; import { type DashboardClientConfiguration } from '~/types'; import { type DashboardClientContext } from './clientContext'; import { isCredentials } from '~/hooks/useAWSRegion'; export const getClients = ( - dashboardClientConfiguration: DashboardClientConfiguration, - region: string + dashboardClientConfiguration: DashboardClientConfiguration ): DashboardClientContext => { if (!isCredentials(dashboardClientConfiguration)) { return { @@ -41,23 +36,10 @@ export const getClients = ( region: dashboardClientConfiguration.awsRegion, }); - // This is required to set endpoint for Pen Test - const assistantEndpointMetadata = document.querySelector( - 'meta[name="assistantEndpoint"]' - ) as HTMLMetaElement; - const iotSiteWisePrivateClient = new InternalIoTSiteWise({ - credentials: dashboardClientConfiguration.awsCredentials, - region: dashboardClientConfiguration.awsRegion, - endpoint: - assistantEndpointMetadata?.content ?? - `https://data.iotsitewise.${region}.amazonaws.com`, - }); - return { iotEventsClient, iotSiteWiseClient, iotTwinMakerClient, iotSiteWise, - iotSiteWisePrivateClient, }; }; diff --git a/packages/dashboard/src/components/dashboard/getQueries.ts b/packages/dashboard/src/components/dashboard/getQueries.ts index 1e591c48e..10192a7d7 100644 --- a/packages/dashboard/src/components/dashboard/getQueries.ts +++ b/packages/dashboard/src/components/dashboard/getQueries.ts @@ -8,12 +8,10 @@ import { type EdgeMode } from '@iot-app-kit/core'; export const getQueries = ( dashboardClientConfiguration: DashboardClientConfiguration, - region: string, edgeMode?: EdgeMode ): DashboardIotSiteWiseQueries => { const { iotEventsClient, iotSiteWiseClient } = getClients( - dashboardClientConfiguration, - region + dashboardClientConfiguration ); if (!iotEventsClient || !iotSiteWiseClient) { diff --git a/packages/dashboard/src/components/dashboard/index.tsx b/packages/dashboard/src/components/dashboard/index.tsx index 307dd8a47..f8c7825bf 100644 --- a/packages/dashboard/src/components/dashboard/index.tsx +++ b/packages/dashboard/src/components/dashboard/index.tsx @@ -31,7 +31,6 @@ import { debounce } from 'lodash'; import { FpsView } from 'react-fps'; import { PropertiesPanel } from '~/customization/propertiesSections'; import { queryClient } from '~/data/query-client'; -import { useAWSRegion } from '~/hooks/useAWSRegion'; import '../../styles/variables.css'; export type DashboardProperties = { @@ -92,14 +91,13 @@ const Dashboard: React.FC = ({ assistantConfiguration?.state, ]); - const { region } = useAWSRegion(clientConfiguration); const clients = useMemo( - () => getClients(clientConfiguration, region), - [clientConfiguration, region] + () => getClients(clientConfiguration), + [clientConfiguration] ); const queries = useMemo( - () => getQueries(clientConfiguration, region, edgeMode), - [clientConfiguration, edgeMode, region] + () => getQueries(clientConfiguration, edgeMode), + [clientConfiguration, edgeMode] ); return ( diff --git a/packages/dashboard/src/components/dashboard/view.tsx b/packages/dashboard/src/components/dashboard/view.tsx index e6ebd942c..90163d750 100644 --- a/packages/dashboard/src/components/dashboard/view.tsx +++ b/packages/dashboard/src/components/dashboard/view.tsx @@ -25,7 +25,6 @@ import { getQueries } from './getQueries'; import { QueryContext } from './queryContext'; import '@cloudscape-design/global-styles/index.css'; -import { useAWSRegion } from '~/hooks/useAWSRegion'; import '../../styles/variables.css'; export type DashboardViewProperties = { @@ -58,10 +57,9 @@ const DashboardView: React.FC = ({ ? debounce(onViewportChange, 100) : undefined; - const { region } = useAWSRegion(clientConfiguration); const clients = useMemo( - () => getClients(clientConfiguration, region), - [clientConfiguration, region] + () => getClients(clientConfiguration), + [clientConfiguration] ); return ( @@ -74,7 +72,7 @@ const DashboardView: React.FC = ({ > { const dispatch = useDispatch(); const readOnly = useSelector((state: DashboardState) => state.readOnly); const assistant = useSelector((state: DashboardState) => state.assistant); - const { iotSiteWisePrivateClient } = useClients(); + const { iotSiteWise } = useClients(); const assistantClient = useMemo( () => new IoTSitewiseAssistantClient({ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - iotSiteWiseClient: iotSiteWisePrivateClient!, + iotSiteWiseClient: iotSiteWise!, }), - [iotSiteWisePrivateClient] + [iotSiteWise] ); let assistantConfiguration: AssistantProperty | undefined; diff --git a/packages/dashboard/src/messages.ts b/packages/dashboard/src/messages.ts index 5c9242d4b..e80daa26d 100644 --- a/packages/dashboard/src/messages.ts +++ b/packages/dashboard/src/messages.ts @@ -311,7 +311,7 @@ export const DefaultDashboardMessages: DashboardMessages = { assistant: { floatingMenu: { propertySelection: - 'Select the checkboxes from the widgets below to include them in the AI generate summary action.', + 'Select the checkboxes in the widgets below and click on Generate summary to see the AI generated summaries.', error: { ariaLabel: 'error', propertyLimitHeader: 'Property limit reached', diff --git a/packages/dashboard/src/types.ts b/packages/dashboard/src/types.ts index 74b9946bd..76a0e9554 100644 --- a/packages/dashboard/src/types.ts +++ b/packages/dashboard/src/types.ts @@ -1,5 +1,4 @@ import { - type IoTSiteWise as InternalIoTSiteWise, type DescribeDashboardRequest, type DescribeDashboardResponse, type IoTSiteWise, @@ -30,7 +29,6 @@ export type DashboardIotSiteWiseClients = { iotEventsClient: IoTEventsClient; iotTwinMakerClient: IoTTwinMakerClient; iotSiteWise: IoTSiteWise; - iotSiteWisePrivateClient?: InternalIoTSiteWise; }; export type DashboardIotSiteWiseQueries = {