The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
perf(ai): smooth out chat streaming (#29211)
Etienne1bc7199a23f3
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatAssistantMessageRenderer.tsx b/packages/twenty-front/src/modules/ai/components/AiChatAssistantMessageRenderer.tsxindex e392aa56ac8..2995775c952 100644--- a/packages/twenty-front/src/modules/ai/components/AiChatAssistantMessageRenderer.tsx+++ b/packages/twenty-front/src/modules/ai/components/AiChatAssistantMessageRenderer.tsx@@ -197,14 +197,6 @@ export const AiChatAssistantMessageRenderer = ({key={index}parts={renderItem.parts}isLastMessageStreaming={isLastMessageStreaming}- hasAssistantTextResponseStarted={renderItems- .slice(index + 1)- .some(- (nextRenderItem) =>- nextRenderItem.type === 'part' &&- nextRenderItem.part.type === 'text' &&- nextRenderItem.part.text.trim().length > 0,- )}isTrailingWhileStreaming={isLastMessageStreaming &&!hasError &&diff --git a/packages/twenty-front/src/modules/ai/components/AiChatThinkingRow.tsx b/packages/twenty-front/src/modules/ai/components/AiChatThinkingRow.tsxdeleted file mode 100644index 8789b585d6a..00000000000--- a/packages/twenty-front/src/modules/ai/components/AiChatThinkingRow.tsx+++ /dev/null@@ -1,36 +0,0 @@-import { styled } from '@linaria/react';-import { t } from '@lingui/core/macro';-import { ThinkingOrbitLoaderIcon } from 'twenty-ui/icon';-import { themeCssVariables } from 'twenty-ui/theme';--const StyledRow = styled.div`- align-items: center;- color: ${themeCssVariables.font.color.tertiary};- display: flex;- gap: ${themeCssVariables.spacing[2]};- min-height: ${themeCssVariables.spacing[6]};-`;--const StyledLoaderIconContainer = styled.div`- align-items: center;- display: flex;- justify-content: center;- min-width: calc(${themeCssVariables.icon.size.sm} * 1px);-`;--const StyledLabel = styled.span`- font-size: ${themeCssVariables.font.size.md};- font-weight: ${themeCssVariables.font.weight.regular};- line-height: ${themeCssVariables.text.lineHeight.md};-`;--export const AiChatThinkingRow = () => {- return (- <StyledRow>- <StyledLoaderIconContainer>- <ThinkingOrbitLoaderIcon />- </StyledLoaderIconContainer>- <StyledLabel>{t`Thinking`}</StyledLabel>- </StyledRow>- );-};diff --git a/packages/twenty-front/src/modules/ai/components/ThinkingReasoningStepRow.tsx b/packages/twenty-front/src/modules/ai/components/ThinkingReasoningStepRow.tsxnew file mode 100644index 00000000000..dfb07742550--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/ThinkingReasoningStepRow.tsx@@ -0,0 +1,48 @@+import { styled } from '@linaria/react';+import { isNonEmptyString } from '@sniptt/guards';+import { type ReasoningUIPart } from 'ai';+import { IconCpu, ThinkingOrbitLoaderIcon } from 'twenty-ui/icon';+import { themeCssVariables } from 'twenty-ui/theme';++import { LazyMarkdownRenderer } from '@/ai/components/LazyMarkdownRenderer';+import { StyledParagraph } from '@/ai/components/LazyMarkdownRendererStyledComponents';+import { ThinkingStepRowLayout } from '@/ai/components/ThinkingStepRowLayout';+import { getReasoningStepLabel } from '@/ai/utils/getReasoningStepLabel';++const StyledReasoningText = styled.div`+ color: ${themeCssVariables.font.color.tertiary};+ font-size: ${themeCssVariables.font.size.md};+ font-weight: ${themeCssVariables.font.weight.regular};+ line-height: ${themeCssVariables.text.lineHeight.lg};+ padding-left: calc(+ ${themeCssVariables.icon.size.sm} * 1px + ${themeCssVariables.spacing[2]}+ );++ // reasoning uses single newlines as line breaks, which markdown would collapse+ ${StyledParagraph} {+ white-space: pre-line;+ }+`;++type ThinkingReasoningStepRowProps = {+ isActive: boolean;+ part: ReasoningUIPart;+};++export const ThinkingReasoningStepRow = ({+ isActive,+ part,+}: ThinkingReasoningStepRowProps) => (+ <ThinkingStepRowLayout+ icon={isActive ? <ThinkingOrbitLoaderIcon /> : <IconCpu size={14} />}+ label={getReasoningStepLabel({ text: part.text, isActive })}+ isActive={isActive}+ details={+ isNonEmptyString(part.text.trim()) ? (+ <StyledReasoningText>+ <LazyMarkdownRenderer text={part.text} />+ </StyledReasoningText>+ ) : undefined+ }+ />+);diff --git a/packages/twenty-front/src/modules/ai/components/ThinkingStepRowLayout.tsx b/packages/twenty-front/src/modules/ai/components/ThinkingStepRowLayout.tsxnew file mode 100644index 00000000000..6329f84e1fd--- /dev/null+++ b/packages/twenty-front/src/modules/ai/components/ThinkingStepRowLayout.tsx@@ -0,0 +1,153 @@+import { styled } from '@linaria/react';+import { type ReactNode, useState } from 'react';+import { isDefined } from 'twenty-shared/utils';+import { IconChevronRight } from 'twenty-ui/icon';+import { Collapsible } from 'twenty-ui/primitives/layout';+import { OverflowingTextWithTooltip } from 'twenty-ui/primitives/typography';+import { themeCssVariables } from 'twenty-ui/theme';++import { ShimmeringText } from '@/ai/components/ShimmeringText';+import { TooltipDelay } from '@/ui/layout/tooltip/constants/TooltipDelay';++const StyledRowLabel = styled.div`+ color: inherit;+ font-size: ${themeCssVariables.font.size.md};+ font-weight: ${themeCssVariables.font.weight.regular};+ line-height: ${themeCssVariables.text.lineHeight.md};+ max-width: 100%;+ min-width: 0;+ overflow: hidden;+ text-overflow: ellipsis;+ transition: color calc(${themeCssVariables.animation.duration.fast} * 1s)+ ease-in-out;+ white-space: nowrap;+`;++const StyledIconContainer = styled.div`+ align-items: center;+ color: ${themeCssVariables.font.color.light};+ display: flex;+ justify-content: center;+ min-width: calc(${themeCssVariables.icon.size.sm} * 1px);+`;++const StyledRowLabelContainer = styled.div`+ align-items: center;+ display: flex;+ flex: 1;+ gap: ${themeCssVariables.spacing[1]};+ min-width: 0;+`;++const StyledChevronContainer = styled.div`+ align-items: center;+ color: ${themeCssVariables.font.color.light};+ display: flex;+ justify-content: center;+ transform: rotate(0deg);+ transition: transform calc(${themeCssVariables.animation.duration.fast} * 1s)+ ease-in-out;++ [data-panel-open] & {+ transform: rotate(90deg);+ }+`;++const StyledRowContainer = styled.div`+ display: flex;+ flex-direction: column;+ gap: ${themeCssVariables.spacing[1]};+`;++const StyledRow = styled.div<{ isExpandable: boolean }>`+ align-items: center;+ background: none;+ border: none;+ color: ${themeCssVariables.font.color.tertiary};+ cursor: ${({ isExpandable }) => (isExpandable ? 'pointer' : 'default')};+ display: flex;+ font-family: inherit;+ gap: ${themeCssVariables.spacing[2]};+ min-height: 24px;+ padding: 0;+ text-align: left;+ transition: color calc(${themeCssVariables.animation.duration.fast} * 1s)+ ease-in-out;+ width: 100%;++ &:hover {+ color: ${({ isExpandable }) =>+ isExpandable+ ? themeCssVariables.font.color.primary+ : themeCssVariables.font.color.tertiary};+ }++ &:focus-visible {+ outline: 2px solid ${themeCssVariables.color.blue};+ outline-offset: 2px;+ }+`;++const StyledShimmeringLabel = styled(ShimmeringText)`+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+`;++type ThinkingStepRowLayoutProps = {+ icon: ReactNode;+ label: string;+ isActive: boolean;+ details?: ReactNode;+};++export const ThinkingStepRowLayout = ({+ icon,+ label,+ isActive,+ details,+}: ThinkingStepRowLayoutProps) => {+ const [isExpanded, setIsExpanded] = useState(false);+ const isExpandable = isDefined(details);++ const rowContent = (+ <>+ <StyledIconContainer>{icon}</StyledIconContainer>+ <StyledRowLabelContainer>+ <StyledRowLabel>+ {isActive ? (+ <StyledShimmeringLabel>{label}</StyledShimmeringLabel>+ ) : (+ <OverflowingTextWithTooltip+ text={label}+ tooltipDelay={TooltipDelay.shortDelay}+ />+ )}+ </StyledRowLabel>+ {isExpandable && (+ <StyledChevronContainer>+ <IconChevronRight size={14} />+ </StyledChevronContainer>+ )}+ </StyledRowLabelContainer>+ </>+ );++ return (+ <Collapsible.Root+ open={isExpanded}+ onOpenChange={setIsExpanded}+ render={<StyledRowContainer />}+ >+ {isExpandable ? (+ <Collapsible.Trigger render={<StyledRow as="button" isExpandable />}>+ {rowContent}+ </Collapsible.Trigger>+ ) : (+ <StyledRow isExpandable={false}>{rowContent}</StyledRow>+ )}++ {isExpandable && <Collapsible.Panel>{details}</Collapsible.Panel>}+ </Collapsible.Root>+ );+};diff --git a/packages/twenty-front/src/modules/ai/components/ThinkingStepsDisplay.tsx b/packages/twenty-front/src/modules/ai/components/ThinkingStepsDisplay.tsxindex e31d26dbd80..288c2ae511b 100644--- a/packages/twenty-front/src/modules/ai/components/ThinkingStepsDisplay.tsx+++ b/packages/twenty-front/src/modules/ai/components/ThinkingStepsDisplay.tsx@@ -2,16 +2,15 @@ import { styled } from '@linaria/react';import { plural, t } from '@lingui/core/macro';import { useState } from 'react';import { Collapsible } from 'twenty-ui/primitives/layout';-import { IconChevronRight, IconCpu } from 'twenty-ui/icon';+import { IconChevronRight, ThinkingOrbitLoaderIcon } from 'twenty-ui/icon';import { isDefined } from 'twenty-shared/utils';import { themeCssVariables } from 'twenty-ui/theme';-import { AiChatThinkingRow } from '@/ai/components/AiChatThinkingRow';-import { LazyMarkdownRenderer } from '@/ai/components/LazyMarkdownRenderer';-import { StyledParagraph } from '@/ai/components/LazyMarkdownRendererStyledComponents';+import { ShimmeringText } from '@/ai/components/ShimmeringText';+import { ThinkingReasoningStepRow } from '@/ai/components/ThinkingReasoningStepRow';import { ThinkingToolStepRow } from '@/ai/components/ThinkingToolStepRow';-import { getActiveReasoningContent } from '@/ai/utils/getActiveReasoningContent';-import { getLastReasoningContent } from '@/ai/utils/getLastReasoningContent';+import { useToolDisplayContext } from '@/ai/hooks/useToolDisplayContext';+import { getThinkingStepLabel } from '@/ai/utils/getThinkingStepLabel';import { isThinkingStepPartActive } from '@/ai/utils/isThinkingStepPartActive';import { type ThinkingStepPart } from '@/ai/types/ThinkingStepPart';import { formatRoundedDuration } from '~/utils/format/formatRoundedDuration';@@ -36,8 +35,12 @@ const StyledSummaryText = styled.span`font-size: ${themeCssVariables.font.size.md};font-weight: ${themeCssVariables.font.weight.regular};line-height: ${themeCssVariables.text.lineHeight.md};+ min-width: 0;+ overflow: hidden;+ text-overflow: ellipsis;transition: color calc(${themeCssVariables.animation.duration.fast} * 1s)ease-in-out;+ white-space: nowrap;`;const StyledSummaryButton = styled.button`@@ -50,7 +53,9 @@ const StyledSummaryButton = styled.button`display: flex;font-family: inherit;gap: ${themeCssVariables.spacing[2]};+ max-width: 100%;min-height: 24px;+ min-width: 0;padding: 0;width: fit-content;@@ -64,152 +69,120 @@ const StyledSummaryButton = styled.button`}`;-const StyledSummaryChevronContainer = styled.div`+const StyledChevronContainer = styled.div`align-items: center;color: ${themeCssVariables.font.color.light};display: flex;+ flex-shrink: 0;justify-content: center;+ min-width: calc(${themeCssVariables.icon.size.sm} * 1px);transform: rotate(0deg);transition: transform calc(${themeCssVariables.animation.duration.fast} * 1s)ease-in-out;- [data-panel-open] > & {+ [data-panel-open] & {transform: rotate(90deg);}`;-const StyledRow = styled.div`- align-items: center;- color: ${themeCssVariables.font.color.tertiary};- display: flex;- gap: ${themeCssVariables.spacing[2]};- min-height: 24px;-`;--const StyledRowLabel = styled.span`- color: inherit;+const StyledStepCount = styled.span`+ color: ${themeCssVariables.font.color.light};+ flex-shrink: 0;font-size: ${themeCssVariables.font.size.md};- font-weight: ${themeCssVariables.font.weight.regular};line-height: ${themeCssVariables.text.lineHeight.md};- transition: color calc(${themeCssVariables.animation.duration.fast} * 1s)- ease-in-out;+ white-space: nowrap;`;-const StyledReasoningContainer = styled.div`- padding-left: calc(- ${themeCssVariables.icon.size.sm} * 1px + ${themeCssVariables.spacing[2]}- );-`;--const StyledReasoningText = styled.div`- color: ${themeCssVariables.font.color.tertiary};+const StyledShimmeringRowLabel = styled(ShimmeringText)`font-size: ${themeCssVariables.font.size.md};- font-weight: ${themeCssVariables.font.weight.regular};- line-height: ${themeCssVariables.text.lineHeight.lg};-- // reasoning uses single newlines as line breaks, which markdown would collapse- ${StyledParagraph} {- white-space: pre-line;- }+ line-height: ${themeCssVariables.text.lineHeight.md};+ min-width: 0;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;`;const StyledIconContainer = styled.div`align-items: center;color: ${themeCssVariables.font.color.light};display: flex;+ flex-shrink: 0;justify-content: center;min-width: calc(${themeCssVariables.icon.size.sm} * 1px);`;-const StyledRowLabelContainer = styled.div`- align-items: center;- display: flex;- flex: 1;- gap: ${themeCssVariables.spacing[1]};- min-width: 0;-`;-const ThinkingStepRow = ({isActive,part,}: {isActive: boolean;part: ThinkingStepPart;-}) => {- if (part.type !== 'reasoning') {- return <ThinkingToolStepRow part={part} isActive={isActive} />;- }-- if (isActive) {- return <AiChatThinkingRow />;- }-- return (- <StyledRow>- <StyledIconContainer>- <IconCpu size={14} />- </StyledIconContainer>- <StyledRowLabelContainer>- <StyledRowLabel>{t`Thought`}</StyledRowLabel>- </StyledRowLabelContainer>- </StyledRow>+}) =>+ part.type === 'reasoning' ? (+ <ThinkingReasoningStepRow part={part} isActive={isActive} />+ ) : (+ <ThinkingToolStepRow part={part} isActive={isActive} />);-};export const ThinkingStepsDisplay = ({parts,isLastMessageStreaming,- hasAssistantTextResponseStarted,isTrailingWhileStreaming = false,workDurationMs,}: {parts: ThinkingStepPart[];isLastMessageStreaming: boolean;- hasAssistantTextResponseStarted: boolean;isTrailingWhileStreaming?: boolean;workDurationMs?: number | null;}) => {const [isExpanded, setIsExpanded] = useState(false);+ const displayContext = useToolDisplayContext();- const stepCount = parts.length;- const hasActiveStep = parts.some((part) =>+ const stepCountLabel = plural(parts.length, {+ one: '# step',+ other: '# steps',+ });+ const activePart = parts.findLast((part) =>isThinkingStepPartActive(part, isLastMessageStreaming),);+ const isWorking =+ isLastMessageStreaming &&+ (isDefined(activePart) || isTrailingWhileStreaming);- const activeReasoningContent = getActiveReasoningContent(parts);- const finalReasoningContent = getLastReasoningContent(parts);- const reasoningContent = hasActiveStep- ? activeReasoningContent- : finalReasoningContent;- const shouldDisplayReasoningContent = reasoningContent?.trim().length;- const shouldKeepExpandedBeforeAnswer = !hasAssistantTextResponseStarted;- const shouldShowSummaryButton =- !hasActiveStep && !shouldKeepExpandedBeforeAnswer;+ const workingLabel = isDefined(activePart)+ ? getThinkingStepLabel({ part: activePart, isActive: true, displayContext })+ : t`Thinking`;- const shouldRenderRows =- hasActiveStep || isExpanded || shouldKeepExpandedBeforeAnswer;+ const summaryLabel =+ isDefined(workDurationMs) && !isLastMessageStreaming+ ? t`Worked for ${formatRoundedDuration(workDurationMs)}`+ : stepCountLabel;return (<Collapsible.Root- open={shouldRenderRows}+ open={isExpanded}onOpenChange={setIsExpanded}render={<StyledContainer />}>- {shouldShowSummaryButton && (- <Collapsible.Trigger render={<StyledSummaryButton />}>- <StyledSummaryChevronContainer>+ <Collapsible.Trigger render={<StyledSummaryButton />}>+ {isWorking ? (+ <StyledIconContainer>+ <ThinkingOrbitLoaderIcon />+ </StyledIconContainer>+ ) : (+ <StyledChevronContainer><IconChevronRight size={14} />- </StyledSummaryChevronContainer>- <StyledSummaryText>- {isDefined(workDurationMs)- ? t`Worked for ${formatRoundedDuration(workDurationMs)}`- : plural(stepCount, {- one: '# step',- other: '# steps',- })}- </StyledSummaryText>- </Collapsible.Trigger>- )}+ </StyledChevronContainer>+ )}+ {isWorking ? (+ <StyledShimmeringRowLabel>{workingLabel}</StyledShimmeringRowLabel>+ ) : (+ <StyledSummaryText>{summaryLabel}</StyledSummaryText>+ )}+ {isWorking && parts.length > 1 && (+ <StyledStepCount>{stepCountLabel}</StyledStepCount>+ )}+ </Collapsible.Trigger><Collapsible.Panel><StyledStepsContentContainer>@@ -220,14 +193,6 @@ export const ThinkingStepsDisplay = ({isActive={isThinkingStepPartActive(part, isLastMessageStreaming)}/>))}- {isTrailingWhileStreaming && !hasActiveStep && <AiChatThinkingRow />}- {!!shouldDisplayReasoningContent && (- <StyledReasoningContainer>- <StyledReasoningText>- <LazyMarkdownRenderer text={reasoningContent} />- </StyledReasoningText>- </StyledReasoningContainer>- )}</StyledStepsContentContainer></Collapsible.Panel></Collapsible.Root>diff --git a/packages/twenty-front/src/modules/ai/components/ThinkingToolStepRow.tsx b/packages/twenty-front/src/modules/ai/components/ThinkingToolStepRow.tsxindex 5b631e528c8..1ebd8bbdc1f 100644--- a/packages/twenty-front/src/modules/ai/components/ThinkingToolStepRow.tsx+++ b/packages/twenty-front/src/modules/ai/components/ThinkingToolStepRow.tsx@@ -2,115 +2,25 @@ import { styled } from '@linaria/react';import { t } from '@lingui/core/macro';import { isNonEmptyString } from '@sniptt/guards';import { getToolName, type DynamicToolUIPart, type ToolUIPart } from 'ai';-import { useState } from 'react';import { isDefined, isNonEmptyArray, isPlainObject } from 'twenty-shared/utils';import { JsonTree } from 'twenty-ui/components/data-display';-import { IconChevronRight } from 'twenty-ui/icon';-import { Collapsible } from 'twenty-ui/primitives/layout';import { Tabs } from 'twenty-ui/primitives/navigation';-import { OverflowingTextWithTooltip } from 'twenty-ui/primitives/typography';import { themeCssVariables } from 'twenty-ui/theme';import { type JsonValue } from 'type-fest';-import { ShimmeringText } from '@/ai/components/ShimmeringText';+import { ThinkingStepRowLayout } from '@/ai/components/ThinkingStepRowLayout';import { ToolRecordsWidget } from '@/ai/components/ToolRecordsWidget';import { useToolDisplayContext } from '@/ai/hooks/useToolDisplayContext';+import { getThinkingStepLabel } from '@/ai/utils/getThinkingStepLabel';import { getToolIcon } from '@/ai/utils/getToolIcon';import { getToolRecordOutput } from '@/ai/utils/getToolRecordOutput';-import { getToolDisplayMessage } from '@/ai/utils/tool-display/getToolDisplayMessage';import { unwrapToolInput } from '@/ai/utils/tool-display/unwrapToolInput';import { TabList } from '@/ui/layout/tab-list/components/TabList';import { TabListRoot } from '@/ui/layout/tab-list/components/TabListRoot';import { activeTabIdComponentState } from '@/ui/layout/tab-list/states/activeTabIdComponentState';-import { TooltipDelay } from '@/ui/layout/tooltip/constants/TooltipDelay';import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';import { useCopyToClipboard } from '~/hooks/useCopyToClipboard';-const StyledToolRowLabel = styled.div`- color: inherit;- font-size: ${themeCssVariables.font.size.md};- font-weight: ${themeCssVariables.font.weight.regular};- line-height: ${themeCssVariables.text.lineHeight.md};- max-width: 100%;- min-width: 0;- overflow: hidden;- text-overflow: ellipsis;- transition: color calc(${themeCssVariables.animation.duration.fast} * 1s)- ease-in-out;- white-space: nowrap;-`;--const StyledIconContainer = styled.div`- align-items: center;- color: ${themeCssVariables.font.color.light};- display: flex;- justify-content: center;- min-width: calc(${themeCssVariables.icon.size.sm} * 1px);-`;--const StyledRowLabelContainer = styled.div`- align-items: center;- display: flex;- flex: 1;- gap: ${themeCssVariables.spacing[1]};- min-width: 0;-`;--const StyledChevronContainer = styled.div`- align-items: center;- color: ${themeCssVariables.font.color.light};- display: flex;- justify-content: center;- transform: rotate(0deg);- transition: transform calc(${themeCssVariables.animation.duration.fast} * 1s)- ease-in-out;-- [data-panel-open] & {- transform: rotate(90deg);- }-`;--const StyledToolRowContainer = styled.div`- display: flex;- flex-direction: column;- gap: ${themeCssVariables.spacing[1]};-`;--const StyledToolRow = styled.div<{ isExpandable: boolean }>`- align-items: center;- background: none;- border: none;- color: ${themeCssVariables.font.color.tertiary};- cursor: ${({ isExpandable }) => (isExpandable ? 'pointer' : 'default')};- display: flex;- font-family: inherit;- gap: ${themeCssVariables.spacing[2]};- min-height: 24px;- padding: 0;- text-align: left;- transition: color calc(${themeCssVariables.animation.duration.fast} * 1s)- ease-in-out;- width: 100%;-- &:hover {- color: ${({ isExpandable }) =>- isExpandable- ? themeCssVariables.font.color.primary- : themeCssVariables.font.color.tertiary};- }-- &:focus-visible {- outline: 2px solid ${themeCssVariables.color.blue};- outline-offset: 2px;- }-`;--const StyledShimmeringLabel = styled(ShimmeringText)`- overflow: hidden;- text-overflow: ellipsis;- white-space: nowrap;-`;-const StyledToolDetailsContainer = styled.div`background: ${themeCssVariables.background.transparent.lighter};border: 1px solid ${themeCssVariables.border.color.light};@@ -162,7 +72,6 @@ export const ThinkingToolStepRow = ({part,}: ThinkingToolStepRowProps) => {const { copyToClipboard } = useCopyToClipboard();- const [isExpanded, setIsExpanded] = useState(false);const rawToolName = getToolName(part);const { toolInput, toolName } = unwrapToolInput({input: part.input,@@ -171,12 +80,10 @@ export const ThinkingToolStepRow = ({const displayContext = useToolDisplayContext();const ToolIcon = getToolIcon(toolName);- const displayMessage = getToolDisplayMessage({- input: part.input,- toolName: rawToolName,- isFinished: !isActive,+ const displayMessage = getThinkingStepLabel({+ part,+ isActive,displayContext,- output: part.output,});const hasError = isDefined(part.errorText);const { message: recordsMessage, recordReferences } =@@ -199,49 +106,13 @@ export const ThinkingToolStepRow = ({{ id: 'input', title: t`Input` },];- const rowContent = (- <>- <StyledIconContainer>- <ToolIcon size={14} />- </StyledIconContainer>- <StyledRowLabelContainer>- <StyledToolRowLabel>- {isActive ? (- <StyledShimmeringLabel>{displayMessage}</StyledShimmeringLabel>- ) : (- <OverflowingTextWithTooltip- text={displayMessage}- tooltipDelay={TooltipDelay.shortDelay}- />- )}- </StyledToolRowLabel>- {isExpandable && (- <StyledChevronContainer>- <IconChevronRight size={14} />- </StyledChevronContainer>- )}- </StyledRowLabelContainer>- </>- );-return (- <Collapsible.Root- open={isExpanded}- onOpenChange={setIsExpanded}- render={<StyledToolRowContainer />}- >- {isExpandable ? (- <Collapsible.Trigger- render={<StyledToolRow as="button" isExpandable />}- >- {rowContent}- </Collapsible.Trigger>- ) : (- <StyledToolRow isExpandable={false}>{rowContent}</StyledToolRow>- )}-- {isExpandable && (- <Collapsible.Panel>+ <ThinkingStepRowLayout+ icon={<ToolIcon size={14} />}+ label={displayMessage}+ isActive={isActive}+ details={+ isExpandable ? (<StyledToolDetailsContainer>{isNonEmptyArray(recordReferences) && (<StyledToolRecordsContainer>@@ -289,8 +160,8 @@ export const ThinkingToolStepRow = ({</TabListRoot>)}</StyledToolDetailsContainer>- </Collapsible.Panel>- )}- </Collapsible.Root>+ ) : undefined+ }+ />);};diff --git a/packages/twenty-front/src/modules/ai/components/__stories__/ThinkingStepsDisplay.stories.tsx b/packages/twenty-front/src/modules/ai/components/__stories__/ThinkingStepsDisplay.stories.tsxindex e81980da0d0..c37cb2a2e7a 100644--- a/packages/twenty-front/src/modules/ai/components/__stories__/ThinkingStepsDisplay.stories.tsx+++ b/packages/twenty-front/src/modules/ai/components/__stories__/ThinkingStepsDisplay.stories.tsx@@ -24,7 +24,6 @@ const meta: Meta<typeof ThinkingStepsDisplay> = {},args: {isLastMessageStreaming: false,- hasAssistantTextResponseStarted: true,parts: [{ type: 'reasoning', state: 'done', text: 'Reviewed the request.' },],@@ -50,9 +49,6 @@ export const SummaryDisclosure: Story = {expect(canvasElement.ownerDocument.getElementById(panelId)).toBeVisible();expect(canvas.getByText('Thought')).toBeVisible();});- await expect(- await canvas.findByText('Reviewed the request.'),- ).toBeVisible();await userEvent.keyboard(' ');await waitFor(() => {expect(toggle).toHaveAttribute('aria-expanded', 'false');@@ -61,24 +57,23 @@ export const SummaryDisclosure: Story = {},};-export const BeforeAnswer: Story = {+export const WhileWorking: Story = {args: {- hasAssistantTextResponseStarted: false,isLastMessageStreaming: true,+ isTrailingWhileStreaming: true,},play: async ({ canvasElement }) => {const canvas = within(canvasElement);- expect(canvas.queryByRole('button', { name: '1 step' })).toBeNull();- expect(canvas.getByText('Thought')).toBeVisible();- await expect(- await canvas.findByText('Reviewed the request.'),- ).toBeVisible();+ expect(canvas.getByRole('button', { name: 'Thinking' })).toHaveAttribute(+ 'aria-expanded',+ 'false',+ );+ expect(canvas.queryByText('Thought')).toBeNull();},};export const ToolDisclosure: Story = {args: {- hasAssistantTextResponseStarted: false,parts: [{type: 'dynamic-tool',@@ -92,7 +87,8 @@ export const ToolDisclosure: Story = {},play: async ({ canvasElement }) => {const canvas = within(canvasElement);- const toggle = canvas.getByRole('button', { name: /inspect_tool/ });+ await userEvent.click(canvas.getByRole('button', { name: '1 step' }));+ const toggle = await canvas.findByRole('button', { name: /inspect_tool/ });expect(toggle).toHaveAttribute('aria-expanded', 'false');await userEvent.click(toggle);const panelId = toggle.getAttribute('aria-controls');diff --git a/packages/twenty-front/src/modules/ai/components/__tests__/AiChatAssistantMessageRenderer.test.tsx b/packages/twenty-front/src/modules/ai/components/__tests__/AiChatAssistantMessageRenderer.test.tsxindex 82b40950da1..e086ce3eb2b 100644--- a/packages/twenty-front/src/modules/ai/components/__tests__/AiChatAssistantMessageRenderer.test.tsx+++ b/packages/twenty-front/src/modules/ai/components/__tests__/AiChatAssistantMessageRenderer.test.tsx@@ -6,18 +6,16 @@ import { AiChatAssistantMessageRenderer } from '@/ai/components/AiChatAssistantMjest.mock('@/ai/components/ThinkingStepsDisplay', () => ({ThinkingStepsDisplay: ({- hasAssistantTextResponseStarted,parts,isTrailingWhileStreaming,workDurationMs,}: {parts: unknown[];- hasAssistantTextResponseStarted: boolean;isTrailingWhileStreaming?: boolean;workDurationMs?: number | null;}) => (<div data-testid="thinking-steps-display">- {`thinking-${parts.length}-${hasAssistantTextResponseStarted ? 'answer-started' : 'answer-pending'}${isTrailingWhileStreaming ? '-trailing-while-streaming' : ''}${workDurationMs ? `-worked-${workDurationMs}` : ''}`}+ {`thinking-${parts.length}${isTrailingWhileStreaming ? '-trailing-while-streaming' : ''}${workDurationMs ? `-worked-${workDurationMs}` : ''}`}</div>),}));@@ -100,7 +98,7 @@ describe('AiChatAssistantMessageRenderer', () => {renderAssistantRenderer(messageParts);expect(screen.getByTestId('thinking-steps-display')).toHaveTextContent(- 'thinking-2-answer-started',+ 'thinking-2',);expect(screen.getByTestId('markdown-renderer')).toHaveTextContent('Final answer',@@ -137,38 +135,9 @@ describe('AiChatAssistantMessageRenderer', () => {'thinking-steps-display',);- expect(thinkingStepsDisplays[0]).toHaveTextContent(- /^thinking-1-answer-started$/,- );+ expect(thinkingStepsDisplays[0]).toHaveTextContent(/^thinking-1$/);expect(thinkingStepsDisplays[1]).toHaveTextContent(- 'thinking-1-answer-started-worked-83000',- );- });-- it('should keep answer-started false for thinking blocks with no following text', () => {- const messageParts = [- {- type: 'text',- text: 'Preamble',- },- {- type: 'reasoning',- text: 'Reasoning content',- state: 'done',- },- {- type: 'tool-web_search',- toolCallId: 'tool-1',- input: { query: 'crm software' },- output: { result: { ok: true } },- state: 'output-available',- },- ] as ExtendedUIMessagePart[];-- renderAssistantRenderer(messageParts);-- expect(screen.getByTestId('thinking-steps-display')).toHaveTextContent(- 'thinking-2-answer-pending',+ 'thinking-1-worked-83000',);});@@ -220,7 +189,7 @@ describe('AiChatAssistantMessageRenderer', () => {renderAssistantRenderer(messageParts);expect(screen.getByTestId('thinking-steps-display')).toHaveTextContent(- 'thinking-1-answer-pending',+ 'thinking-1',);});@@ -317,7 +286,7 @@ describe('AiChatAssistantMessageRenderer', () => {renderAssistantRenderer(messageParts);expect(screen.getByTestId('thinking-steps-display')).toHaveTextContent(- 'thinking-2-answer-started',+ 'thinking-2',);});@@ -465,7 +434,7 @@ describe('AiChatAssistantMessageRenderer', () => {renderAssistantRenderer(messageParts);expect(screen.getByTestId('thinking-steps-display')).toHaveTextContent(- 'thinking-1-answer-started',+ 'thinking-1',);});@@ -552,7 +521,7 @@ describe('AiChatAssistantMessageRenderer', () => {] as ExtendedUIMessagePart[]);expect(screen.getByTestId('thinking-steps-display')).toHaveTextContent(- 'thinking-1-answer-started',+ 'thinking-1',);});diff --git a/packages/twenty-front/src/modules/ai/components/__tests__/ThinkingStepsDisplay.test.tsx b/packages/twenty-front/src/modules/ai/components/__tests__/ThinkingStepsDisplay.test.tsxindex bd3a88d3f2c..9684ddf35d3 100644--- a/packages/twenty-front/src/modules/ai/components/__tests__/ThinkingStepsDisplay.test.tsx+++ b/packages/twenty-front/src/modules/ai/components/__tests__/ThinkingStepsDisplay.test.tsx@@ -103,7 +103,6 @@ const createToolPart = ({}) as ThinkingStepPart;const renderThinkingStepsDisplay = ({- hasAssistantTextResponseStarted = false,isLastMessageStreaming,parts,isTrailingWhileStreaming = false,@@ -111,7 +110,6 @@ const renderThinkingStepsDisplay = ({}: {parts: ThinkingStepPart[];isLastMessageStreaming: boolean;- hasAssistantTextResponseStarted?: boolean;isTrailingWhileStreaming?: boolean;workDurationMs?: number | null;}) => {@@ -120,7 +118,6 @@ const renderThinkingStepsDisplay = ({<ThinkingStepsDisplayparts={parts}isLastMessageStreaming={isLastMessageStreaming}- hasAssistantTextResponseStarted={hasAssistantTextResponseStarted}isTrailingWhileStreaming={isTrailingWhileStreaming}workDurationMs={workDurationMs}/>@@ -129,7 +126,7 @@ const renderThinkingStepsDisplay = ({};describe('ThinkingStepsDisplay', () => {- it('should render expanded thinking rows with active loader while streaming', () => {+ it('should show the running step as a single line while streaming', () => {renderThinkingStepsDisplay({isLastMessageStreaming: true,parts: [@@ -141,18 +138,14 @@ describe('ThinkingStepsDisplay', () => {],});- expect(screen.queryByRole('button', { name: /steps/i })).toBeNull();- expect(screen.getByText('Thinking')).toBeInTheDocument();- expect(screen.getByTestId('markdown-renderer')).toHaveTextContent(- 'Active reasoning content',- );expect(- screen.getByText('Searched the web for crm software'),- ).toBeInTheDocument();- expect(document.querySelector('svg[viewBox="0 0 14 14"]')).not.toBeNull();+ screen.getByRole('button', { name: /Thinking.*2 steps/ }),+ ).toHaveAttribute('aria-expanded', 'false');+ expect(screen.queryByText('Searched the web for crm software')).toBeNull();+ expect(screen.queryByText('Active reasoning content')).toBeNull();});- it('should render the loading label for a tool step awaiting its output while streaming', () => {+ it('should label the line with a tool step awaiting its output', () => {renderThinkingStepsDisplay({isLastMessageStreaming: true,parts: [createToolPart({ output: null, state: 'input-available' })],@@ -163,7 +156,7 @@ describe('ThinkingStepsDisplay', () => {).toBeInTheDocument();});- it('should append the pending thinking row after completed steps when requested', () => {+ it('should show thinking between steps', () => {renderThinkingStepsDisplay({isLastMessageStreaming: true,isTrailingWhileStreaming: true,@@ -173,16 +166,7 @@ describe('ThinkingStepsDisplay', () => {expect(screen.getByText('Thinking')).toBeInTheDocument();});- it('should not render a thinking row for completed steps by default', () => {- renderThinkingStepsDisplay({- isLastMessageStreaming: true,- parts: [createToolPart()],- });-- expect(screen.queryByText('Thinking')).toBeNull();- });-- it('should not append the pending thinking row while a tool step is still running', () => {+ it('should label the line with the running tool rather than thinking', () => {renderThinkingStepsDisplay({isLastMessageStreaming: true,isTrailingWhileStreaming: true,@@ -195,62 +179,66 @@ describe('ThinkingStepsDisplay', () => {).toBeInTheDocument();});- it('should render done state collapsed by default', () => {+ it('should count the steps while the answer streams', () => {renderThinkingStepsDisplay({- isLastMessageStreaming: false,- hasAssistantTextResponseStarted: true,- parts: [- createToolPart(),- createReasoningPart({- state: 'done',- text: 'Completed reasoning content',- }),- ],+ isLastMessageStreaming: true,+ workDurationMs: 4_000,+ parts: [createToolPart()],});- const summaryButton = screen.getByRole('button', { name: /2 steps/i });-- expect(summaryButton).toHaveAttribute('aria-expanded', 'false');- expect(screen.queryByText('Thought')).toBeNull();- expect(screen.queryByText('Completed reasoning content')).toBeNull();+ expect(screen.getByRole('button', { name: '1 step' })).toBeInTheDocument();+ expect(screen.queryByText('Thinking')).toBeNull();});- it('should summarize done state with the work duration when known', () => {- renderThinkingStepsDisplay({- isLastMessageStreaming: false,- hasAssistantTextResponseStarted: true,- workDurationMs: 83_000,- parts: [createToolPart(), createReasoningPart()],+ it('should keep the same single line when the stream ends', () => {+ const parts = [+ createToolPart(),+ createReasoningPart({+ state: 'done',+ text: 'Completed reasoning content',+ }),+ ];+ const { rerender } = renderThinkingStepsDisplay({+ isLastMessageStreaming: true,+ parts,});- expect(- screen.getByRole('button', { name: 'Worked for 1m 23s' }),- ).toHaveAttribute('aria-expanded', 'false');- expect(screen.queryByText(/steps/i)).toBeNull();+ const line = screen.getByRole('button', { name: '2 steps' });++ rerender(+ <ThemeProvider colorScheme="light">+ <ThinkingStepsDisplay+ parts={parts}+ isLastMessageStreaming={false}+ workDurationMs={83_000}+ />+ </ThemeProvider>,+ );++ expect(screen.getByRole('button', { name: 'Worked for 1m 23s' })).toBe(+ line,+ );+ expect(screen.queryByText('Thought')).toBeNull();});- it('should keep done state expanded while streaming before answer text starts', () => {+ it('should label the line with the latest reasoning title', () => {renderThinkingStepsDisplay({isLastMessageStreaming: true,- hasAssistantTextResponseStarted: false,parts: [- createToolPart(),createReasoningPart({- state: 'done',- text: 'Completed reasoning content',+ state: 'streaming',+ text: '**Looking into the data**\n\nFirst pass.\n\n**Selecting tool fields**\n\nThe query',}),],});- expect(screen.queryByRole('button', { name: /steps/i })).toBeNull();- expect(screen.getByText('Thought')).toBeInTheDocument();- expect(screen.getByText('Completed reasoning content')).toBeInTheDocument();+ expect(screen.getByText('Selecting tool fields')).toBeInTheDocument();+ expect(screen.queryByText('Thinking')).toBeNull();});- it('should collapse done state once answer text starts while streaming', () => {+ it('should render done state collapsed by default', () => {renderThinkingStepsDisplay({- isLastMessageStreaming: true,- hasAssistantTextResponseStarted: true,+ isLastMessageStreaming: false,parts: [createToolPart(),createReasoningPart({@@ -267,10 +255,22 @@ describe('ThinkingStepsDisplay', () => {expect(screen.queryByText('Completed reasoning content')).toBeNull();});- it('should render rows and full reasoning content after expanding done state', async () => {+ it('should summarize done state with the work duration when known', () => {+ renderThinkingStepsDisplay({+ isLastMessageStreaming: false,+ workDurationMs: 83_000,+ parts: [createToolPart(), createReasoningPart()],+ });++ expect(+ screen.getByRole('button', { name: 'Worked for 1m 23s' }),+ ).toHaveAttribute('aria-expanded', 'false');+ expect(screen.queryByText(/steps/i)).toBeNull();+ });++ it('should render rows, then reasoning content once its row is expanded', async () => {renderThinkingStepsDisplay({isLastMessageStreaming: false,- hasAssistantTextResponseStarted: true,parts: [createToolPart(),createReasoningPart({@@ -285,7 +285,10 @@ describe('ThinkingStepsDisplay', () => {await userEvent.click(summaryButton);expect(summaryButton).toHaveAttribute('aria-expanded', 'true');- expect(screen.getByText('Thought')).toBeInTheDocument();+ expect(screen.queryByText('Completed reasoning content')).toBeNull();++ await userEvent.click(screen.getByRole('button', { name: 'Thought' }));+expect(screen.getByText('Completed reasoning content')).toBeInTheDocument();expect(screen.getByText('Searched the web for crm software'),@@ -295,7 +298,6 @@ describe('ThinkingStepsDisplay', () => {it('should toggle tool details and display output/input tabs', async () => {renderThinkingStepsDisplay({isLastMessageStreaming: false,- hasAssistantTextResponseStarted: true,parts: [createToolPart(),createReasoningPart({@@ -334,7 +336,6 @@ describe('ThinkingStepsDisplay', () => {it('should show the records a tool step found when its row is expanded', async () => {renderThinkingStepsDisplay({isLastMessageStreaming: false,- hasAssistantTextResponseStarted: true,parts: [createToolPart({type: 'tool-find_many_companies',diff --git a/packages/twenty-front/src/modules/ai/hooks/__tests__/useUpdateStreamingPartsWithDiff.test.tsx b/packages/twenty-front/src/modules/ai/hooks/__tests__/useUpdateStreamingPartsWithDiff.test.tsxindex 6af65157c33..d20c38eb0c6 100644--- a/packages/twenty-front/src/modules/ai/hooks/__tests__/useUpdateStreamingPartsWithDiff.test.tsx+++ b/packages/twenty-front/src/modules/ai/hooks/__tests__/useUpdateStreamingPartsWithDiff.test.tsx@@ -80,15 +80,6 @@ describe('useUpdateStreamingPartsWithDiff', () => {);});- it('does not process again a refetched message whose content did not change', () => {- const updateStreamingPartsWithDiff = renderUpdateStreamingPartsWithDiff();-- updateStreamingPartsWithDiff([buildMessage('answer', 'Done')]);- updateStreamingPartsWithDiff([buildMessage('answer', 'Done')]);-- expect(processWorkspaceSetupCompletion).toHaveBeenCalledTimes(1);- });-it('leaves messages written before this session alone', () => {const updateStreamingPartsWithDiff = renderUpdateStreamingPartsWithDiff();diff --git a/packages/twenty-front/src/modules/ai/hooks/useUpdateStreamingPartsWithDiff.ts b/packages/twenty-front/src/modules/ai/hooks/useUpdateStreamingPartsWithDiff.tsindex f8ec46c23e7..a4cdc32017e 100644--- a/packages/twenty-front/src/modules/ai/hooks/useUpdateStreamingPartsWithDiff.ts+++ b/packages/twenty-front/src/modules/ai/hooks/useUpdateStreamingPartsWithDiff.ts@@ -5,7 +5,6 @@ import { isNonEmptyString } from '@sniptt/guards';import { useState } from 'react';import { Temporal } from 'temporal-polyfill';import { type ExtendedUIMessage } from 'twenty-shared/ai';-import { isDeeplyEqual } from '~/utils/isDeeplyEqual';export const useUpdateStreamingPartsWithDiff = () => {const agentChatUISessionStartTime = useAtomStateValue(@@ -52,10 +51,7 @@ export const useUpdateStreamingPartsWithDiff = () => {const lastSeenMessage = lastSeenMessages[index];// a stream flush keeps the unchanged messages, a refetch rebuilds them all- if (- lastSeenMessage === incomingMessage ||- isDeeplyEqual(lastSeenMessage, incomingMessage)- ) {+ if (lastSeenMessage === incomingMessage) {continue;}diff --git a/packages/twenty-front/src/modules/ai/utils/__tests__/getThinkingStepLabel.test.ts b/packages/twenty-front/src/modules/ai/utils/__tests__/getThinkingStepLabel.test.tsnew file mode 100644index 00000000000..65d106c4ae5--- /dev/null+++ b/packages/twenty-front/src/modules/ai/utils/__tests__/getThinkingStepLabel.test.ts@@ -0,0 +1,80 @@+import { i18n } from '@lingui/core';++import { type ThinkingStepPart } from '@/ai/types/ThinkingStepPart';+import { type ToolDisplayContext } from '@/ai/types/ToolDisplayContext';+import { getThinkingStepLabel } from '@/ai/utils/getThinkingStepLabel';++const emptyDisplayContext: ToolDisplayContext = {+ labelByName: new Map(),+ indexByName: new Map(),+ objectMetadataItems: [],+};++const webSearchPart = {+ type: 'tool-web_search',+ toolCallId: 'tool-call-id',+ input: { query: 'CRM tools' },+ output: { results: [] },+ state: 'output-available',+} as ThinkingStepPart;++describe('getThinkingStepLabel', () => {+ beforeAll(() => {+ i18n.load('en', {});+ i18n.activate('en');+ });++ it('should use the latest reasoning title', () => {+ const label = getThinkingStepLabel({+ part: {+ type: 'reasoning',+ text: '**Planning**\nfirst\n**Searching records**\nsecond',+ state: 'done',+ } as ThinkingStepPart,+ isActive: false,+ displayContext: emptyDisplayContext,+ });++ expect(label).toBe('Searching records');+ });++ it('should fall back to a generic reasoning label', () => {+ const reasoningPart = {+ type: 'reasoning',+ text: 'no title',+ state: 'streaming',+ } as ThinkingStepPart;++ expect(+ getThinkingStepLabel({+ part: reasoningPart,+ isActive: true,+ displayContext: emptyDisplayContext,+ }),+ ).toBe('Thinking');+ expect(+ getThinkingStepLabel({+ part: reasoningPart,+ isActive: false,+ displayContext: emptyDisplayContext,+ }),+ ).toBe('Thought');+ });++ it('should describe a tool step as in progress while active', () => {+ const activeLabel = getThinkingStepLabel({+ part: webSearchPart,+ isActive: true,+ displayContext: emptyDisplayContext,+ });+ const finishedLabel = getThinkingStepLabel({+ part: webSearchPart,+ isActive: false,+ displayContext: emptyDisplayContext,+ });++ expect(activeLabel).toContain('CRM tools');+ expect(finishedLabel).toContain('Searched');+ expect(activeLabel).not.toBe(finishedLabel);+ });+});diff --git a/packages/twenty-front/src/modules/ai/utils/__tests__/thinkingStepsDisplayState.test.ts b/packages/twenty-front/src/modules/ai/utils/__tests__/thinkingStepsDisplayState.test.tsindex ec33b010107..d22234512de 100644--- a/packages/twenty-front/src/modules/ai/utils/__tests__/thinkingStepsDisplayState.test.ts+++ b/packages/twenty-front/src/modules/ai/utils/__tests__/thinkingStepsDisplayState.test.ts@@ -1,7 +1,5 @@import { type ExtendedUIMessagePart } from 'twenty-shared/ai';-import { getActiveReasoningContent } from '@/ai/utils/getActiveReasoningContent';-import { getLastReasoningContent } from '@/ai/utils/getLastReasoningContent';import { groupContiguousThinkingStepParts } from '@/ai/utils/groupContiguousThinkingStepParts';import { isThinkingStepPartActive } from '@/ai/utils/isThinkingStepPartActive';import { type ThinkingStepPart } from '@/ai/types/ThinkingStepPart';@@ -122,20 +120,4 @@ describe('thinkingStepsDisplayState', () => {expect(isThinkingStepPartActive(failedToolPart, true)).toBe(false);});});-- describe('reasoning content helpers', () => {- const parts = [- createReasoningPart({ state: 'done', text: 'Initial reasoning' }),- createToolPart({ type: 'tool-web_search' }),- createReasoningPart({ state: 'streaming', text: 'Active reasoning' }),- ];-- it('should return active reasoning content', () => {- expect(getActiveReasoningContent(parts)).toBe('Active reasoning');- });-- it('should return the latest reasoning content', () => {- expect(getLastReasoningContent(parts)).toBe('Active reasoning');- });- });});diff --git a/packages/twenty-front/src/modules/ai/utils/getActiveReasoningContent.ts b/packages/twenty-front/src/modules/ai/utils/getActiveReasoningContent.tsdeleted file mode 100644index afafcd2200d..00000000000--- a/packages/twenty-front/src/modules/ai/utils/getActiveReasoningContent.ts+++ /dev/null@@ -1,14 +0,0 @@-import { type ReasoningUIPart } from 'ai';--import { type ThinkingStepPart } from '@/ai/types/ThinkingStepPart';--export const getActiveReasoningContent = (- parts: ThinkingStepPart[],-): string | null => {- const activeReasoningPart = parts.find(- (part): part is ReasoningUIPart =>- part.type === 'reasoning' && part.state === 'streaming',- );-- return activeReasoningPart?.text ?? null;-};diff --git a/packages/twenty-front/src/modules/ai/utils/getLastReasoningContent.ts b/packages/twenty-front/src/modules/ai/utils/getLastReasoningContent.tsdeleted file mode 100644index 8cd130aee2f..00000000000--- a/packages/twenty-front/src/modules/ai/utils/getLastReasoningContent.ts+++ /dev/null@@ -1,13 +0,0 @@-import { type ReasoningUIPart } from 'ai';--import { type ThinkingStepPart } from '@/ai/types/ThinkingStepPart';--export const getLastReasoningContent = (- parts: ThinkingStepPart[],-): string | null => {- const reasoningParts = parts.filter(- (part): part is ReasoningUIPart => part.type === 'reasoning',- );-- return reasoningParts.at(-1)?.text ?? null;-};diff --git a/packages/twenty-front/src/modules/ai/utils/getLatestReasoningTitle.ts b/packages/twenty-front/src/modules/ai/utils/getLatestReasoningTitle.tsnew file mode 100644index 00000000000..43ea674b687--- /dev/null+++ b/packages/twenty-front/src/modules/ai/utils/getLatestReasoningTitle.ts@@ -0,0 +1,11 @@+import { isNonEmptyString } from '@sniptt/guards';++const REASONING_TITLE_REGEX = /^\*\*(.+?)\*\*\s*$/gm;++export const getLatestReasoningTitle = (text: string): string | null => {+ const latestTitle = [...text.matchAll(REASONING_TITLE_REGEX)]+ .at(-1)?.[1]+ ?.trim();++ return isNonEmptyString(latestTitle) ? latestTitle : null;+};diff --git a/packages/twenty-front/src/modules/ai/utils/getReasoningStepLabel.ts b/packages/twenty-front/src/modules/ai/utils/getReasoningStepLabel.tsnew file mode 100644index 00000000000..84b48eea8c3--- /dev/null+++ b/packages/twenty-front/src/modules/ai/utils/getReasoningStepLabel.ts@@ -0,0 +1,11 @@+import { t } from '@lingui/core/macro';++import { getLatestReasoningTitle } from '@/ai/utils/getLatestReasoningTitle';++export const getReasoningStepLabel = ({+ text,+ isActive,+}: {+ text: string;+ isActive: boolean;+}) => getLatestReasoningTitle(text) ?? (isActive ? t`Thinking` : t`Thought`);diff --git a/packages/twenty-front/src/modules/ai/utils/getThinkingStepLabel.ts b/packages/twenty-front/src/modules/ai/utils/getThinkingStepLabel.tsnew file mode 100644index 00000000000..d44f8e6c85c--- /dev/null+++ b/packages/twenty-front/src/modules/ai/utils/getThinkingStepLabel.ts@@ -0,0 +1,25 @@+import { getToolName } from 'ai';++import { type ThinkingStepPart } from '@/ai/types/ThinkingStepPart';+import { type ToolDisplayContext } from '@/ai/types/ToolDisplayContext';+import { getReasoningStepLabel } from '@/ai/utils/getReasoningStepLabel';+import { getToolDisplayMessage } from '@/ai/utils/tool-display/getToolDisplayMessage';++export const getThinkingStepLabel = ({+ part,+ isActive,+ displayContext,+}: {+ part: ThinkingStepPart;+ isActive: boolean;+ displayContext: ToolDisplayContext;+}) =>+ part.type === 'reasoning'+ ? getReasoningStepLabel({ text: part.text, isActive })+ : getToolDisplayMessage({+ input: part.input,+ toolName: getToolName(part),+ isFinished: !isActive,+ displayContext,+ output: part.output,+ });