feat(ai): open Ask AI side panel with a preprompt in two modes (#22582)

Add the ability to open the Ask AI side panel pre-filled with a prompt
from any frontend component, with a mode to control whether the message
is sent automatically or left for the user to review.

- agentChatPrepromptState: holds the pending preprompt and its mode
(PREFILL = fill only, SEND = fill and auto-submit)
- useOpenAskAiPageWithPreprompt: seeds the new-thread draft, opens a
fresh Ask AI thread and stores the preprompt intent
- AgentChatPrepromptEffect: applies the intent once the chat editor and
send listener are mounted, either restoring the editor content or
dispatching the send event and clearing the editor

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/twentyhq/twenty/pull/22582?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
This commit is contained in:
Weiko
2026-07-06 17:38:28 +02:00
committed by GitHub
parent 62c7e8f6b4
commit 8580cd6f27
6 changed files with 122 additions and 0 deletions
@@ -13,6 +13,7 @@ import {
} from 'twenty-shared/types';
import { type AppLocale } from 'twenty-shared/translations';
import { useOpenAskAiPageWithPreprompt } from '@/ai/hooks/useOpenAskAiPageWithPreprompt';
import { currentUserState } from '@/auth/states/currentUserState';
import { useCommandMenuConfirmationModal } from '@/command-menu-item/confirmation-modal/hooks/useCommandMenuConfirmationModal';
import { useUnmountCommand } from '@/command-menu-item/engine-command/hooks/useUnmountEngineCommand';
@@ -63,6 +64,7 @@ export const useFrontComponentExecutionContext = ({
frontComponentId,
});
const { openConfirmationModal } = useCommandMenuConfirmationModal();
const { openAskAiPageWithPreprompt } = useOpenAskAiPageWithPreprompt();
const { navigateSidePanel } = useNavigateSidePanel();
const { openRecordInSidePanel: openRecordInSidePanelInternal } =
useOpenRecordInSidePanel();
@@ -193,6 +195,23 @@ export const useFrontComponentExecutionContext = ({
return;
}
if (
params.page === SidePanelPages.AskAI &&
isDefined(params.preprompt) &&
isNonEmptyString(params.preprompt.text)
) {
openAskAiPageWithPreprompt({
text: params.preprompt.text,
mode: params.preprompt.mode,
});
if (params.shouldResetSearchState === true) {
setSidePanelSearch('');
}
return;
}
navigateSidePanel({
page: params.page,
pageTitle: params.pageTitle,