Skip to content

Commit

Permalink
Merge branch 'development' into feat/isolated-view-test
Browse files Browse the repository at this point in the history
  • Loading branch information
nartovm authored Jan 24, 2025
2 parents dbdf0be + 952be60 commit c9593d6
Show file tree
Hide file tree
Showing 17 changed files with 228 additions and 46 deletions.
5 changes: 0 additions & 5 deletions apps/chat-e2e/src/ui/webElements/chatHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
} from '../selectors';
import { BaseElement } from './baseElement';

import { API } from '@/src/testData';
import { Tags } from '@/src/ui/domData';
import { Locator, Page } from '@playwright/test';

Expand Down Expand Up @@ -61,11 +60,7 @@ export class ChatHeader extends BaseElement {
}

async openConversationSettingsPopup() {
const modelsResponsePromise = this.page.waitForResponse(API.modelsHost);
const addonsResponsePromise = this.page.waitForResponse(API.addonsHost);
await this.conversationSettings.click();
await modelsResponsePromise;
await addonsResponsePromise;
}

public async hoverOverChatModel() {
Expand Down
19 changes: 4 additions & 15 deletions apps/chat/src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,15 @@ import {
import { EntityType } from '@/src/types/common';
import { Translation } from '@/src/types/translation';

import {
AddonsActions,
AddonsSelectors,
} from '@/src/store/addons/addons.reducers';
import { AddonsSelectors } from '@/src/store/addons/addons.reducers';
import { ChatActions } from '@/src/store/chat/chat.reducer';
import { ChatSelectors } from '@/src/store/chat/chat.selectors';
import {
ConversationsActions,
ConversationsSelectors,
} from '@/src/store/conversations/conversations.reducers';
import { useAppDispatch, useAppSelector } from '@/src/store/hooks';
import {
ModelsActions,
ModelsSelectors,
} from '@/src/store/models/models.reducers';
import { ModelsSelectors } from '@/src/store/models/models.reducers';
import { PublicationSelectors } from '@/src/store/publication/publication.reducers';
import { SettingsSelectors } from '@/src/store/settings/settings.reducers';
import { UISelectors } from '@/src/store/ui/ui.reducers';
Expand Down Expand Up @@ -199,6 +193,7 @@ export const ChatView = memo(() => {
!modelsMap[conv.assistantModelId])
);
}));

if (isNotAllowedModel) {
setNotAllowedType(EntityType.Model);
} else if (
Expand Down Expand Up @@ -595,13 +590,7 @@ export const ChatView = memo(() => {
!isExternal
}
isShowSettings={isShowChatSettings}
setShowSettings={(isShow) => {
if (isShow) {
dispatch(ModelsActions.getModels());
dispatch(AddonsActions.getAddons());
}
setIsShowChatSettings(isShow);
}}
setShowSettings={setIsShowChatSettings}
selectedConversationIds={
selectedConversationsIds
}
Expand Down
20 changes: 19 additions & 1 deletion apps/chat/src/components/Chat/ChatInput/ChatInputMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import { usePromptSelection } from '@/src/hooks/usePromptSelection';
import { useTokenizer } from '@/src/hooks/useTokenizer';

import { getUserCustomContent } from '@/src/utils/app/file';
import {
getConversationSchema,
isFormValueValid,
} from '@/src/utils/app/form-schema';
import { isMobile } from '@/src/utils/app/mobile';
import { getPromptLimitDescription } from '@/src/utils/app/modals';

Expand Down Expand Up @@ -182,6 +186,16 @@ export const ChatInputMessage = Inversify.register(
selectedPrompt,
} = usePromptSelection(maxTokensLength, modelTokenizer, '');

const isSchemaValueValid = useMemo(() => {
const schema =
selectedConversations.map(getConversationSchema)?.[0] ??
configurationSchema;

if (!schema) return true;

return isFormValueValid(schema, chatFormValue);
}, [selectedConversations, configurationSchema, chatFormValue]);

const isInputEmpty = useMemo(() => {
return (
!content.trim().length &&
Expand All @@ -202,7 +216,8 @@ export const ChatInputMessage = Inversify.register(
!isModelsLoaded ||
isUploadingFilePresent ||
isConversationNameInvalid ||
isConversationPathInvalid;
isConversationPathInvalid ||
!isSchemaValueValid;

const canAttach =
(canAttachFiles || canAttachFolders || canAttachLinks) &&
Expand Down Expand Up @@ -454,6 +469,9 @@ export const ChatInputMessage = Inversify.register(
if (isConversationPathInvalid) {
return t(errorsMessages.entityPathInvalid);
}
if (!isSchemaValueValid) {
return t('Please select one of the options above');
}
return t('Please type a message');
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ import { memo, useCallback } from 'react';

import { useTranslation } from 'next-i18next';

import { getMessageSchema } from '@/src/utils/app/form-schema';
import {
getMessageSchema,
isFormSchemaValid,
} from '@/src/utils/app/form-schema';

import { Translation } from '@/src/types/translation';

import { ChatActions } from '@/src/store/chat/chat.reducer';
import { ChatSelectors } from '@/src/store/chat/chat.selectors';
import { ConversationsSelectors } from '@/src/store/conversations/conversations.reducers';
import { useAppDispatch, useAppSelector } from '@/src/store/hooks';

import { FormSchema } from '@/src/components/Chat/ChatMessage/MessageSchema/FormSchema';
import { ErrorMessage } from '@/src/components/Common/ErrorMessage';

import {
DialSchemaProperties,
Expand All @@ -29,6 +34,7 @@ const AssistantSchemaView = ({ schema }: AssistantSchemaViewProps) => {
const isPlayback = useAppSelector(
ConversationsSelectors.selectIsPlaybackSelectedConversations,
);
const formValue = useAppSelector(ChatSelectors.selectChatFormValue);

const handleChange = useCallback(
(property: string, value: MessageFormValueType, submit?: boolean) => {
Expand All @@ -54,6 +60,8 @@ const AssistantSchemaView = ({ schema }: AssistantSchemaViewProps) => {
schema={schema}
onChange={handleChange}
disabled={isPlayback}
formValue={formValue}
showSelected
/>
</div>
);
Expand All @@ -74,6 +82,13 @@ export const AssistantSchema = memo(function AssistantSchema({

if (!schema) return null;

if (!isFormSchemaValid(schema))
return (
<div className="mt-2">
<ErrorMessage error={t('Form schema is invalid') ?? ''} />
</div>
);

if (
!isLastMessage &&
!message.content &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ export const FormSchema = memo(function FormSchema({
buttonClassName,
}: FormSchemaProps) {
return (
<div className={classNames('flex flex-col gap-2', wrapperClassName)}>
<div
data-no-context-menu
className={classNames('flex flex-col gap-2', wrapperClassName)}
>
{Object.entries(schema.properties).map(([name, property]) => (
<PropertyRenderer
property={property}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,12 @@ const InvalidSchemaMessage = () => {
);
};

const config = {
errorLogMessage: 'Invalid schema error:',
};

export const UserSchema = withErrorBoundary(
MemoUserSchema,
<InvalidSchemaMessage />,
config,
);

export const AssistantSchema = withErrorBoundary(
MemoAssistantSchema,
<InvalidSchemaMessage />,
config,
);
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getConfigurationSchema,
getFormButtonType,
getMessageSchema,
isFormSchemaValid,
} from '@/src/utils/app/form-schema';

import { FormButtonType } from '@/src/types/chat';
Expand All @@ -19,6 +20,7 @@ import { ErrorMessage } from '@/src/components/Common/ErrorMessage';
import {
DialSchemaProperties,
Message,
MessageFormSchema,
MessageFormValue,
MessageFormValueType,
} from '@epam/ai-dial-shared';
Expand All @@ -32,25 +34,20 @@ interface UserSchemaProps {
setFormValue?: (value: MessageFormValue) => void;
onSubmit?: (formValue?: MessageFormValue, content?: string) => void;
disabled?: boolean;
schema?: MessageFormSchema;
}

export const UserSchema = memo(function UserSchema({
messageIndex,
allMessages,
const UserSchemaView = memo(function UserSchemaView({
isEditing,
setInputValue,
formValue,
setFormValue,
onSubmit,
disabled,
schema,
}: UserSchemaProps) {
const { t } = useTranslation(Translation.Chat);

const schema = useMemo(() => {
if (messageIndex === 0) return getConfigurationSchema(allMessages[0]);
return getMessageSchema(allMessages[messageIndex - 1]);
}, [allMessages, messageIndex]);

const handleChange = useCallback(
(property: string, value: MessageFormValueType, submit?: boolean) => {
if (schema && formValue) {
Expand Down Expand Up @@ -129,3 +126,22 @@ export const UserSchema = memo(function UserSchema({
</div>
) : null;
});

export const UserSchema = memo(function UserSchema(props: UserSchemaProps) {
const { t } = useTranslation(Translation.Chat);

const schema = useMemo(() => {
if (props.messageIndex === 0)
return getConfigurationSchema(props.allMessages[0]);
return getMessageSchema(props.allMessages[props.messageIndex - 1]);
}, [props.allMessages, props.messageIndex]);

if (schema && !isFormSchemaValid(schema))
return (
<div className="mt-2">
<ErrorMessage error={t('Form schema is invalid') ?? ''} />
</div>
);

return <UserSchemaView {...props} schema={schema} />;
});
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export function SettingContainer({ children }: SettingContainerProps) {

function EmptySettings() {
const { t } = useTranslation(Translation.Chat);

return (
<SettingContainer>
<FieldContainer>
Expand Down
7 changes: 5 additions & 2 deletions apps/chat/src/components/Chat/EmptyChatDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,12 @@ const EmptyChatDescriptionView = ({
const versions = useMemo(
() =>
models.filter(
(m) => installedModelIds.has(m.reference) && m.name === model?.name,
(m) =>
(installedModelIds.has(m.reference) ||
model?.reference === m.reference) &&
m.name === model?.name,
),
[installedModelIds, model?.name, models],
[installedModelIds, model?.name, model?.reference, models],
);

const incorrectModel = !model;
Expand Down
10 changes: 9 additions & 1 deletion apps/chat/src/components/Chatbar/ChatFolders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ export const ChatSection = ({
const [isSectionHighlighted, setIsSectionHighlighted] = useState(false);

const searchTerm = useAppSelector(ConversationsSelectors.selectSearchTerm);
const selectedPublication = useAppSelector(
PublicationSelectors.selectSelectedPublication,
);
const selectFilteredFoldersSelector = useMemo(
() =>
ConversationsSelectors.selectFilteredFolders(
Expand Down Expand Up @@ -405,14 +408,19 @@ export const ChatSection = ({
return null;
}

const isOrganizationAndPublicationSelected =
name === ORGANIZATION_SECTION_NAME && selectedPublication;

return (
<CollapsibleSection
onToggle={handleToggle}
name={name}
openByDefault={openByDefault ?? isExpanded}
isExpanded={isExpanded}
dataQa={dataQa}
isHighlighted={isSectionHighlighted}
isHighlighted={
isOrganizationAndPublicationSelected ? false : isSectionHighlighted
}
>
<div>
{rootFolders.map((folder, index, arr) => {
Expand Down
6 changes: 5 additions & 1 deletion apps/chat/src/components/Folder/Folder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,9 @@ const Folder = <T extends ConversationInfo | PromptInfo | DialFile>({
const iconSize = additionalItemData?.isSidePanelItem ? 24 : 18;
const folderIconStrokeWidth = additionalItemData?.isSidePanelItem ? 1.5 : 2;
const isSidePanelItem = additionalItemData?.isSidePanelItem;
const isInApproveRequiredSectionOrNot =
(selectedPublicationUrl && additionalItemData?.publicationUrl) ||
(!selectedPublicationUrl && !additionalItemData?.publicationUrl);

return (
<div
Expand Down Expand Up @@ -1105,7 +1108,8 @@ const Folder = <T extends ConversationInfo | PromptInfo | DialFile>({
: highlightedFolders?.includes(currentFolder.id) &&
isPartOfSelectedPublication &&
featureType &&
!canSelectFolders
!canSelectFolders &&
isInApproveRequiredSectionOrNot
? 'text-accent-primary'
: 'text-primary',
)}
Expand Down
10 changes: 9 additions & 1 deletion apps/chat/src/components/Promptbar/components/PromptFolders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ const _PromptSection = ({
const [isSectionHighlighted, setIsSectionHighlighted] = useState(false);

const searchTerm = useAppSelector(PromptsSelectors.selectSearchTerm);
const selectedPublication = useAppSelector(
PublicationSelectors.selectSelectedPublication,
);

const filteredPromptsSelector = useMemo(
() => PromptsSelectors.selectFilteredPrompts(filters, searchTerm),
Expand Down Expand Up @@ -386,14 +389,19 @@ const _PromptSection = ({
return null;
}

const isOrganizationAndPublicationSelected =
name === ORGANIZATION_SECTION_NAME && selectedPublication;

return (
<CollapsibleSection
onToggle={handleToggle}
name={name}
openByDefault={openByDefault ?? isExpanded}
isExpanded={isExpanded}
dataQa={dataQa}
isHighlighted={isSectionHighlighted}
isHighlighted={
isOrganizationAndPublicationSelected ? false : isSectionHighlighted
}
>
<div>
{rootFolders.map((folder, index, arr) => (
Expand Down
1 change: 1 addition & 0 deletions apps/chat/src/store/conversations/conversations.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ const duplicateConversationEpic: AppEpic = (action$, state$) =>
selectedIdToReplaceWithNewOne: conversation.id,
}),
),
of(PublicationActions.selectPublication(null)),
);
}),
);
Expand Down
6 changes: 3 additions & 3 deletions apps/chat/src/store/conversations/conversations.reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,16 @@ export const conversationsSlice = createSlice({
selectedIdToReplaceWithNewOne?: string;
}>,
) => {
state.conversations = combineEntities(state.conversations, [
newConversation,
]);
state.selectedConversationsIds =
selectedIdToReplaceWithNewOne &&
state.selectedConversationsIds.length > 1
? state.selectedConversationsIds.map((id) =>
id === selectedIdToReplaceWithNewOne ? newConversation.id : id,
)
: [newConversation.id];
state.conversations = combineEntities(state.conversations, [
newConversation,
]);

state.areSelectedConversationsLoaded = true;
},
Expand Down
Loading

0 comments on commit c9593d6

Please sign in to comment.