Skip to content

Commit

Permalink
fix: assistant failing to fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Pauer authored and fpauer committed Nov 21, 2024
1 parent a03fbb0 commit 9f271ca
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 42 deletions.
4 changes: 2 additions & 2 deletions packages/dashboard/src/components/assistant/chatbot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const Chatbot: FC<AssistantChatbotProps> = (
) => {
const dispatch = useDispatch();
const assistant = useSelector((state: DashboardState) => state.assistant);
const { iotSiteWisePrivateClient } = useClients();
const { iotSiteWise } = useClients();
const { getContextByComponent } = useAssistantContext();
const initialMessages: Array<IMessage> = [
{
Expand All @@ -42,7 +42,7 @@ export const Chatbot: FC<AssistantChatbotProps> = (

const client = new IoTSitewiseAssistantClient({
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
iotSiteWiseClient: iotSiteWisePrivateClient!,
iotSiteWiseClient: iotSiteWise!,
});

const { messages, setMessages, invokeAssistant, generateSummary, clearAll } =
Expand Down
22 changes: 2 additions & 20 deletions packages/dashboard/src/components/dashboard/getClients.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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,
};
};
4 changes: 1 addition & 3 deletions packages/dashboard/src/components/dashboard/getQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 4 additions & 6 deletions packages/dashboard/src/components/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -92,14 +91,13 @@ const Dashboard: React.FC<DashboardProperties> = ({
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 (
Expand Down
8 changes: 3 additions & 5 deletions packages/dashboard/src/components/dashboard/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -58,10 +57,9 @@ const DashboardView: React.FC<DashboardViewProperties> = ({
? debounce(onViewportChange, 100)
: undefined;

const { region } = useAWSRegion(clientConfiguration);
const clients = useMemo(
() => getClients(clientConfiguration, region),
[clientConfiguration, region]
() => getClients(clientConfiguration),
[clientConfiguration]
);

return (
Expand All @@ -74,7 +72,7 @@ const DashboardView: React.FC<DashboardViewProperties> = ({
>
<ClientContext.Provider value={clients}>
<QueryContext.Provider
value={getQueries(clientConfiguration, region, edgeMode)}
value={getQueries(clientConfiguration, edgeMode)}
>
<QueryClientProvider client={queryClient}>
<Provider
Expand Down
6 changes: 3 additions & 3 deletions packages/dashboard/src/hooks/useAssistantConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ export const useAssistantConfiguration = (widgetId: string) => {
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;
Expand Down
2 changes: 1 addition & 1 deletion packages/dashboard/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 0 additions & 2 deletions packages/dashboard/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
type IoTSiteWise as InternalIoTSiteWise,
type DescribeDashboardRequest,
type DescribeDashboardResponse,
type IoTSiteWise,
Expand Down Expand Up @@ -30,7 +29,6 @@ export type DashboardIotSiteWiseClients = {
iotEventsClient: IoTEventsClient;
iotTwinMakerClient: IoTTwinMakerClient;
iotSiteWise: IoTSiteWise;
iotSiteWisePrivateClient?: InternalIoTSiteWise;
};

export type DashboardIotSiteWiseQueries = {
Expand Down

0 comments on commit 9f271ca

Please sign in to comment.