Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/CONST/SENTRY_LABEL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3141,6 +3141,7 @@ const SENTRY_LABEL = {
},
ADD_AGENT_PAGE: {
AVATAR: 'AddAgentPage-Avatar',
INSTRUCTIONS: 'AddAgentPage-Instructions',
},
EDIT_AGENT_PAGE: {
CHAT: 'EditAgentPage-Chat',
Expand All @@ -3153,6 +3154,9 @@ const SENTRY_LABEL = {
AVATAR: 'EditAgentPage-Avatar',
BOT_AVATAR_SELECTOR: 'EditAgentPage-BotAvatarSelector',
},
EDIT_AGENT_PROMPT_PAGE: {
INSTRUCTIONS: 'EditAgentPromptPage-Instructions',
},
SETTINGS_PROFILE: {
AVATAR: 'SettingsProfile-Avatar',
CONTACT_METHOD_THREE_DOTS_REMOVE: 'SettingsProfile-ContactMethodThreeDotsRemove',
Expand All @@ -3168,6 +3172,7 @@ const SENTRY_LABEL = {
PHONE_NUMBER: 'SettingsProfile-PhoneNumber',
ADDRESS: 'SettingsProfile-Address',
TIMEZONE_AUTOMATIC_SWITCH: 'SettingsProfile-TimezoneAutomaticSwitch',
AI_PROMPT: 'SettingsProfile-AIPrompt',
AI_PROMPT_SAVE: 'SettingsProfile-AIPromptSave',
AVATAR_EDIT: 'SettingsProfile-AvatarEdit',
AVATAR_UPLOAD_PHOTO: 'SettingsProfile-AvatarUploadPhoto',
Expand Down
1 change: 1 addition & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6841,6 +6841,7 @@ const CONST = {
STATE_CHARACTER_LIMIT: 32,
REPORT_TITLE_FORMULA_LIMIT: 500,
AGENT_PROMPT_LIMIT: 300,
AGENT_PROMPT_MAX_LENGTH: 60000,

// Test receipt data
TEST_RECEIPT: {
Expand Down
2 changes: 2 additions & 0 deletions src/pages/settings/Agents/DynamicAddAgentPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ function DynamicAddAgentPageContent({route, template}: DynamicAddAgentPageConten
excludedMarkdownStyles={['mentionReport']}
onKeyPress={submitFormOnModEnter}
defaultValue={defaultPrompt}
maxLength={CONST.AGENT_PROMPT_MAX_LENGTH}
sentryLabel={CONST.SENTRY_LABEL.ADD_AGENT_PAGE.INSTRUCTIONS}
multiline
// Keep native markdown sizing enabled across rotation so the input retains focus while its height limit changes.
autoGrowHeight={shouldAutoGrowPromptInput}
Expand Down
2 changes: 2 additions & 0 deletions src/pages/settings/Agents/Fields/DynamicEditPromptPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ function DynamicEditPromptPage({route}: DynamicEditPromptPageProps) {
type="markdown"
excludedMarkdownStyles={['mentionReport']}
defaultValue={Str.htmlDecode(agentPrompt?.prompt ?? '')}
maxLength={CONST.AGENT_PROMPT_MAX_LENGTH}
sentryLabel={CONST.SENTRY_LABEL.EDIT_AGENT_PROMPT_PAGE.INSTRUCTIONS}
multiline
// Keep native markdown sizing enabled across rotation so the input retains focus while its height limit changes.
autoGrowHeight={shouldAutoGrowPromptInput}
Expand Down
2 changes: 2 additions & 0 deletions src/pages/settings/Profile/AgentAIPromptSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ function AgentAIPromptSection({accountID, parentScrollViewRef}: AgentAIPromptSec
value={draftPrompt}
onChangeText={handleChangeText}
onKeyPress={handleKeyPress}
maxLength={CONST.AGENT_PROMPT_MAX_LENGTH}
sentryLabel={CONST.SENTRY_LABEL.SETTINGS_PROFILE.AI_PROMPT}
multiline
autoGrowHeight
maxAutoGrowHeight={variables.lineHeightNormal * MAX_VISIBLE_PROMPT_LINES}
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/ProfilePageTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,18 @@ describe('ProfilePage - agent account', () => {
expect(screen.queryByTestId('save-prompt-button')).toBeNull();
});

it('allows an AI prompt longer than a chat comment', async () => {
// Given an agent account, whose profile shows a markdown prompt input that otherwise falls back to the chat comment limit
await setupUser('testbot_123@expensify.ai', true);

// When the profile page renders
renderPageWithNavigation(SCREENS.SETTINGS.PROFILE.ROOT);
await waitForBatchedUpdatesWithAct();

// Then the prompt input uses the agent prompt limit, so a prompt longer than a chat comment is not cut off
expect(screen.getByTestId('ai-prompt-input').props.maxLength).toBe(CONST.AGENT_PROMPT_MAX_LENGTH);
});

it('calls openProfilePage on mount for agent account', async () => {
const mockOpenProfilePage = jest.mocked(AgentActions.openProfilePage);
await setupUser('testbot_123@expensify.ai', true);
Expand Down
14 changes: 13 additions & 1 deletion tests/unit/pages/settings/AddAgentPageTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,11 @@ jest.mock('@components/Form/FormProvider', () => {
return MockFormProvider;
});

const mockInputWrapperProps = jest.fn<void, [{inputID: string; maxLength?: number}]>();

jest.mock('@components/Form/InputWrapper', () => {
function MockInputWrapper({inputID, defaultValue}: {inputID: string; defaultValue?: string}) {
function MockInputWrapper({inputID, defaultValue, maxLength}: {inputID: string; defaultValue?: string; maxLength?: number}) {
mockInputWrapperProps({inputID, maxLength});
return `${inputID}::${defaultValue ?? ''}`;
}
return MockInputWrapper;
Expand Down Expand Up @@ -275,6 +278,15 @@ describe('AddAgentPage', () => {
expect(JSON.stringify(toJSON())).toContain('prompt::addAgentPage.defaultPrompt');
});

it('allows a prompt longer than a chat comment', () => {
// Given the agent builder, whose markdown prompt input otherwise falls back to the chat comment limit
// When the page renders
renderAddAgentPage();

// Then the prompt input uses the agent prompt limit, so a prompt longer than a chat comment is not cut off
expect(mockInputWrapperProps).toHaveBeenCalledWith({inputID: 'prompt', maxLength: CONST.AGENT_PROMPT_MAX_LENGTH});
});

it('seeds a random default avatar into the draft on mount when it is empty', () => {
renderAddAgentPage();

Expand Down
19 changes: 17 additions & 2 deletions tests/unit/pages/settings/EditPromptPageTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
import EditPromptPage from '@pages/settings/Agents/Fields/DynamicEditPromptPage';
import scrollToMultilineInput from '@pages/settings/Agents/scrollToMultilineInput';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';

Expand All @@ -18,7 +19,7 @@ import {Platform, View} from 'react-native';
import createMock from '../../../utils/createMock';

const mockPromptMount = jest.fn();
const mockPromptProps = jest.fn<void, [{onFocus?: () => void; onBlur?: () => void}]>();
const mockPromptProps = jest.fn<void, [{onFocus?: () => void; onBlur?: () => void; maxLength?: number}]>();

jest.mock('@pages/settings/Agents/scrollToMultilineInput', () => jest.fn());

Expand Down Expand Up @@ -87,7 +88,7 @@ jest.mock('@components/Form/FormProvider', () => {

jest.mock('@components/Form/InputWrapper', () => {
const {useEffect} = jest.requireActual<typeof React>('react');
function MockInputWrapper({inputID, defaultValue, ...props}: {inputID: string; defaultValue?: string; onFocus?: () => void; onBlur?: () => void}) {
function MockInputWrapper({inputID, defaultValue, ...props}: {inputID: string; defaultValue?: string; onFocus?: () => void; onBlur?: () => void; maxLength?: number}) {
mockPromptProps(props);
useEffect(() => {
mockPromptMount();
Expand Down Expand Up @@ -201,4 +202,18 @@ describe('EditPromptPage', () => {

expect(JSON.stringify(toJSON())).toContain('prompt::Old prompt');
});

it('allows a prompt longer than a chat comment', () => {
// Given the prompt editor, which uses a markdown input that otherwise falls back to the chat comment limit
// When the page renders
render(
<EditPromptPage
route={mockRoute}
navigation={mockNavigation}
/>,
);

// Then the prompt input uses the agent prompt limit, so a prompt longer than a chat comment is not cut off
expect(mockPromptProps.mock.lastCall?.[0].maxLength).toBe(CONST.AGENT_PROMPT_MAX_LENGTH);
});
});
Loading