Skip to content

Commit

Permalink
Merge branch 'feature-better-auth' of https://github.com/microsoft/ch…
Browse files Browse the repository at this point in the history
…at-copilot into feature-better-auth
  • Loading branch information
gitri-ms committed Aug 8, 2023
2 parents ab69bc4 + a1fea64 commit 358b41b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true
"**/Thumbs.db": true,
"**.lock": true,
},
}
8 changes: 5 additions & 3 deletions webapp/src/components/chat/chat-history/ChatHistoryItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

import { Persona, Text, makeStyles, mergeClasses, shorthands } from '@fluentui/react-components';
import { AvatarProps, Persona, Text, makeStyles, mergeClasses, shorthands } from '@fluentui/react-components';
import { ThumbDislike24Filled, ThumbLike16Filled } from '@fluentui/react-icons';
import React from 'react';
import { DefaultChatUser } from '../../../libs/auth/AuthHelper';
Expand Down Expand Up @@ -93,9 +93,11 @@ export const ChatHistoryItem: React.FC<ChatHistoryItemProps> = ({ message, getRe
: chat.getChatUserById(message.userName, selectedId, conversations[selectedId].users);
const fullName = user?.fullName ?? message.userName;

const avatar = isBot
const avatar: AvatarProps = isBot
? { image: { src: conversations[selectedId].botProfilePicture } }
: { name: fullName, color: 'colorful' as const };
: isDefaultUser
? { idForColor: selectedId, color: 'colorful' }
: { name: fullName, color: 'colorful' };

let content: JSX.Element;
if (isBot && message.type === ChatMessageType.Plan) {
Expand Down
12 changes: 10 additions & 2 deletions webapp/src/components/open-api-plugins/PluginConnector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Dismiss20Regular } from '@fluentui/react-icons';
import { FormEvent, useState } from 'react';
import { TokenHelper } from '../../libs/auth/TokenHelper';
import { useAppDispatch } from '../../redux/app/hooks';
import { AdditionalApiProperties, PluginAuthRequirements } from '../../redux/features/plugins/PluginsState';
import { AdditionalApiProperties, Plugin, PluginAuthRequirements } from '../../redux/features/plugins/PluginsState';
import { connectPlugin } from '../../redux/features/plugins/pluginsSlice';
import { useDialogClasses } from '../../styles';

Expand All @@ -28,6 +28,7 @@ interface PluginConnectorProps {
publisher: string;
authRequirements: PluginAuthRequirements;
apiProperties?: AdditionalApiProperties;
inactive?: Plugin['inactive'];
}

export const PluginConnector: React.FC<PluginConnectorProps> = ({
Expand All @@ -36,6 +37,7 @@ export const PluginConnector: React.FC<PluginConnectorProps> = ({
publisher,
authRequirements,
apiProperties,
inactive,
}) => {
const classes = useDialogClasses();

Expand Down Expand Up @@ -103,7 +105,13 @@ export const PluginConnector: React.FC<PluginConnectorProps> = ({
modalType="alert"
>
<DialogTrigger>
<Button data-testid="openPluginDialogButton" aria-label="Enable plugin" appearance="primary">
<Button
data-testid="openPluginDialogButton"
aria-label="Enable plugin"
appearance="primary"
disabled={!!inactive}
title={inactive}
>
Enable
</Button>
</DialogTrigger>
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/components/open-api-plugins/cards/PluginCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface PluginCardProps {
}

export const PluginCard: React.FC<PluginCardProps> = ({ plugin }) => {
const { name, publisher, enabled, authRequirements, apiProperties, icon, description } = plugin;
const { name, publisher, enabled, authRequirements, apiProperties, icon, description, inactive } = plugin;
const dispatch = useAppDispatch();

const onDisconnectClick = (event: FormEvent) => {
Expand Down Expand Up @@ -42,6 +42,7 @@ export const PluginCard: React.FC<PluginCardProps> = ({ plugin }) => {
publisher={publisher}
authRequirements={authRequirements}
apiProperties={apiProperties}
inactive={inactive}
/>
)
}
Expand Down
41 changes: 22 additions & 19 deletions webapp/src/libs/hooks/useChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import botIcon2 from '../../assets/bot-icons/bot-icon-2.png';
import botIcon3 from '../../assets/bot-icons/bot-icon-3.png';
import botIcon4 from '../../assets/bot-icons/bot-icon-4.png';
import botIcon5 from '../../assets/bot-icons/bot-icon-5.png';
import { FeatureKeys } from '../../redux/features/app/AppState';

export interface GetResponseOptions {
messageType: ChatMessageType;
Expand All @@ -43,7 +44,7 @@ export const useChat = () => {
const dispatch = useAppDispatch();
const { instance, inProgress } = useMsal();
const { conversations } = useAppSelector((state: RootState) => state.conversations);
const { activeUserInfo } = useAppSelector((state: RootState) => state.app);
const { activeUserInfo, features } = useAppSelector((state: RootState) => state.app);

const botService = new BotService(process.env.REACT_APP_BACKEND_URI as string);
const chatService = new ChatService(process.env.REACT_APP_BACKEND_URI as string);
Expand Down Expand Up @@ -74,25 +75,23 @@ export const useChat = () => {
const chatTitle = `Copilot @ ${new Date().toLocaleString()}`;
const accessToken = await AuthHelper.getSKaaSAccessToken(instance, inProgress);
try {
await chatService
.createChatAsync(chatTitle, accessToken)
.then((result: ICreateChatSessionResponse) => {
const newChat: ChatState = {
id: result.chatSession.id,
title: result.chatSession.title,
systemDescription: result.chatSession.systemDescription,
memoryBalance: result.chatSession.memoryBalance,
messages: [result.initialBotMessage],
users: [loggedInUser],
botProfilePicture: getBotProfilePicture(Object.keys(conversations).length),
input: '',
botResponseStatus: undefined,
userDataLoaded: false,
};
await chatService.createChatAsync(chatTitle, accessToken).then((result: ICreateChatSessionResponse) => {
const newChat: ChatState = {
id: result.chatSession.id,
title: result.chatSession.title,
systemDescription: result.chatSession.systemDescription,
memoryBalance: result.chatSession.memoryBalance,
messages: [result.initialBotMessage],
users: [loggedInUser],
botProfilePicture: getBotProfilePicture(Object.keys(conversations).length),
input: '',
botResponseStatus: undefined,
userDataLoaded: false,
};

dispatch(addConversation(newChat));
return newChat.id;
});
dispatch(addConversation(newChat));
return newChat.id;
});
} catch (e: any) {
const errorMessage = `Unable to create new chat. Details: ${getErrorDetails(e)}`;
dispatch(addAlert({ message: errorMessage, type: AlertType.Error }));
Expand Down Expand Up @@ -151,6 +150,10 @@ export const useChat = () => {

const chatUsers = await chatService.getAllChatParticipantsAsync(chatSession.id, accessToken);

if (!features[FeatureKeys.MultiUserChat].enabled && chatUsers.length > 1) {
continue;
}

loadedConversations[chatSession.id] = {
id: chatSession.id,
title: chatSession.title,
Expand Down
3 changes: 3 additions & 0 deletions webapp/src/redux/features/plugins/PluginsState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import GithubIcon from '../../../assets/plugin-icons/github.png';
import JiraIcon from '../../../assets/plugin-icons/jira.png';
import KlarnaIcon from '../../../assets/plugin-icons/klarna.png';
import GraphIcon from '../../../assets/plugin-icons/ms-graph.png';
import { AuthHelper } from '../../../libs/auth/AuthHelper';

/*
* For each OpenAPI Spec you're supporting in the Kernel,
Expand Down Expand Up @@ -60,6 +61,7 @@ export interface Plugin {
authData?: string; // token or encoded auth header value
apiProperties?: AdditionalApiProperties;
manifestDomain?: string; // Website domain hosting the OpenAI Plugin Manifest file for custom plugins
inactive?: string; // If truthy, disables the plugin and gives the reason why
}

export interface PluginsState {
Expand All @@ -75,6 +77,7 @@ export const initialState: PluginsState = {
publisher: 'Microsoft',
description: 'Use your Microsoft Account to access your personal Graph information and Microsoft services.',
enabled: false,
inactive: AuthHelper.IsAuthAAD ? undefined : 'Only available when using Azure AD authorization',
authRequirements: {
Msal: true,
scopes: Constants.plugins.msGraphScopes,
Expand Down

0 comments on commit 358b41b

Please sign in to comment.