ef499b6d47
## Summary - Re-enable one lint rule that was temporarily disabled during the ESLint-to-Oxlint migration: - **`twenty/sort-css-properties-alphabetically`** in twenty-front — 578 violations auto-fixed across 390 files - Document why **`typescript/consistent-type-imports`** cannot be auto-fixed in twenty-server: NestJS relies on `emitDecoratorMetadata` for DI, so converting constructor parameter imports to `import type` erases them at compile time and breaks dependency injection at runtime - Right-size CI runners, reducing 8-core usage from 18 jobs to 3: | Change | Jobs | Rationale | |--------|------|-----------| | **Keep 8-core** | `ci-merge-queue/e2e-test`, `ci-front/front-sb-build`, `ci-front/front-build` | Heavy builds needing max CPU + memory (10GB NODE_OPTIONS, full Storybook webpack bundling) | | **8-core → 4-core** | `ci-server` (build, lint-typecheck, validation, test, integration-test), `ci-front/front-sb-test`, `ci-zapier/server-setup`, `ci-sdk/sdk-e2e-test` | Already sharded into 10-12 parallel instances, I/O-bound (DB/Redis), or moderate single builds | | **8-core → 2-core** | `ci-emails/emails-test` | Trivially lightweight (build + curl health check) | | **Removed** | `ci-front/front-chromatic-deployment` | Dead code — permanently disabled with `if: false` | - Fix merge queue CI issues: - **Concurrency**: Use `merge_group.base_ref` instead of unique merge group ref so new queue entries cancel previous runs - **Required status checks**: Add `merge_group` trigger to all 6 required CI workflows (front, server, shared, website, docker-compose, sdk) with `changed-files-check` auto-skipped for merge_group events — status check jobs auto-pass without re-running full CI - **Build caching**: Add Nx build cache restore/save to E2E test job with fallback to `main` branch cache for faster frontend and server builds ## Test plan - [ ] CI passes on this PR (verifies lint rule auto-fix works) - [ ] Verify 4-core runner jobs complete within their 30-minute timeouts - [ ] Verify merge queue status checks auto-pass (ci-front-status-check, ci-server-status-check, etc.) - [ ] Verify merge queue E2E concurrency cancels previous runs when a new PR enters the queue
379 lines
11 KiB
TypeScript
379 lines
11 KiB
TypeScript
import { styled } from '@linaria/react';
|
|
import { useContext, useState } from 'react';
|
|
|
|
import { IconChevronDown, IconChevronUp } from 'twenty-ui/display';
|
|
import { JsonTree } from 'twenty-ui/json-visualizer';
|
|
import { AnimatedExpandableContainer } from 'twenty-ui/layout';
|
|
import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
|
|
|
|
import { useLingui } from '@lingui/react/macro';
|
|
import { type DataMessagePart } from 'twenty-shared/ai';
|
|
import { type JsonValue } from 'type-fest';
|
|
import { useCopyToClipboard } from '~/hooks/useCopyToClipboard';
|
|
|
|
const StyledContainer = styled.div`
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: ${themeCssVariables.spacing[2]};
|
|
margin-top: ${themeCssVariables.spacing[2]};
|
|
`;
|
|
|
|
const StyledToggleButton = styled.div`
|
|
align-items: center;
|
|
background: none;
|
|
border: none;
|
|
color: ${themeCssVariables.font.color.tertiary};
|
|
cursor: pointer;
|
|
display: flex;
|
|
font-size: ${themeCssVariables.font.size.sm};
|
|
gap: ${themeCssVariables.spacing[1]};
|
|
padding: ${themeCssVariables.spacing[1]} 0;
|
|
transition: color calc(${themeCssVariables.animation.duration.normal} * 1s);
|
|
|
|
&:hover {
|
|
color: ${themeCssVariables.font.color.secondary};
|
|
}
|
|
`;
|
|
|
|
const StyledContentContainer = styled.div`
|
|
background: ${themeCssVariables.background.transparent.lighter};
|
|
border: 1px solid ${themeCssVariables.border.color.light};
|
|
border-radius: ${themeCssVariables.border.radius.sm};
|
|
min-width: 0;
|
|
padding: ${themeCssVariables.spacing[3]};
|
|
`;
|
|
|
|
const StyledJsonTreeContainer = styled.div`
|
|
overflow-x: auto;
|
|
|
|
ul {
|
|
min-width: 0;
|
|
}
|
|
`;
|
|
|
|
const StyledTabContainer = styled.div`
|
|
border-bottom: 1px solid ${themeCssVariables.border.color.light};
|
|
display: flex;
|
|
gap: ${themeCssVariables.spacing[3]};
|
|
margin-bottom: ${themeCssVariables.spacing[3]};
|
|
`;
|
|
|
|
const StyledTab = styled.div<{ isActive: boolean }>`
|
|
color: ${({ isActive }) =>
|
|
isActive
|
|
? themeCssVariables.font.color.primary
|
|
: themeCssVariables.font.color.tertiary};
|
|
cursor: pointer;
|
|
font-size: ${themeCssVariables.font.size.sm};
|
|
font-weight: ${({ isActive }) =>
|
|
isActive
|
|
? themeCssVariables.font.weight.medium
|
|
: themeCssVariables.font.weight.regular};
|
|
padding-bottom: ${themeCssVariables.spacing[2]};
|
|
transition: color calc(${themeCssVariables.animation.duration.normal} * 1s);
|
|
|
|
&:hover {
|
|
color: ${themeCssVariables.font.color.secondary};
|
|
}
|
|
`;
|
|
|
|
const StyledTimingSection = styled.div`
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: ${themeCssVariables.spacing[2]};
|
|
`;
|
|
|
|
const StyledTimingRow = styled.div`
|
|
align-items: center;
|
|
display: flex;
|
|
font-size: ${themeCssVariables.font.size.sm};
|
|
justify-content: space-between;
|
|
padding: ${themeCssVariables.spacing[1]} 0;
|
|
`;
|
|
|
|
const StyledTimingLabel = styled.span`
|
|
color: ${themeCssVariables.font.color.secondary};
|
|
`;
|
|
|
|
const StyledTimingValue = styled.span`
|
|
color: ${themeCssVariables.font.color.primary};
|
|
font-weight: ${themeCssVariables.font.weight.medium};
|
|
`;
|
|
|
|
type TabType = 'timing' | 'details' | 'context';
|
|
|
|
type TimingRowProps = {
|
|
label: string;
|
|
value: string | number | undefined;
|
|
};
|
|
|
|
const TimingRow = ({ label, value }: TimingRowProps) => {
|
|
if (value === undefined) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<StyledTimingRow>
|
|
<StyledTimingLabel>{label}</StyledTimingLabel>
|
|
<StyledTimingValue>{value}</StyledTimingValue>
|
|
</StyledTimingRow>
|
|
);
|
|
};
|
|
|
|
const formatBytes = (bytes: number) => {
|
|
if (bytes === 0) return '0 B';
|
|
const k = 1024;
|
|
const sizes = ['B', 'KB', 'MB'];
|
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
return `${Math.round((bytes / Math.pow(k, i)) * 100) / 100} ${sizes[i]}`;
|
|
};
|
|
|
|
const formatNumber = (num: number) => num.toLocaleString();
|
|
|
|
const formatTokenBreakdown = (
|
|
total: number,
|
|
prompt?: number,
|
|
completion?: number,
|
|
) => {
|
|
const formattedTotal = formatNumber(total);
|
|
const hasValidBreakdown =
|
|
prompt !== undefined &&
|
|
completion !== undefined &&
|
|
prompt > 0 &&
|
|
completion > 0;
|
|
|
|
if (hasValidBreakdown) {
|
|
return `${formattedTotal} (${formatNumber(prompt)} → ${formatNumber(completion)})`;
|
|
}
|
|
|
|
return formattedTotal;
|
|
};
|
|
|
|
type DebugInfo = NonNullable<DataMessagePart['routing-status']['debug']>;
|
|
|
|
type TimingTabProps = {
|
|
debug: DebugInfo;
|
|
};
|
|
|
|
const TimingTab = ({ debug }: TimingTabProps) => {
|
|
const { t } = useLingui();
|
|
const totalTime =
|
|
debug.agentExecutionStartTimeMs !== undefined
|
|
? `${debug.agentExecutionStartTimeMs + (debug.agentExecutionTimeMs || 0)}ms`
|
|
: undefined;
|
|
|
|
const totalCost =
|
|
debug.totalCostInCredits !== undefined
|
|
? formatNumber(debug.totalCostInCredits)
|
|
: undefined;
|
|
|
|
return (
|
|
<StyledTimingSection>
|
|
<TimingRow
|
|
label={t`Routing decision`}
|
|
value={debug.routingTimeMs && `${debug.routingTimeMs}ms`}
|
|
/>
|
|
<TimingRow
|
|
label={t`Context building (routing)`}
|
|
value={debug.contextBuildTimeMs && `${debug.contextBuildTimeMs}ms`}
|
|
/>
|
|
<TimingRow
|
|
label={t`Context building (agent)`}
|
|
value={
|
|
debug.agentContextBuildTimeMs && `${debug.agentContextBuildTimeMs}ms`
|
|
}
|
|
/>
|
|
<TimingRow
|
|
label={t`Tool generation`}
|
|
value={debug.toolGenerationTimeMs && `${debug.toolGenerationTimeMs}ms`}
|
|
/>
|
|
<TimingRow
|
|
label={t`AI request prep`}
|
|
value={debug.aiRequestPrepTimeMs && `${debug.aiRequestPrepTimeMs}ms`}
|
|
/>
|
|
<TimingRow
|
|
label={t`Agent execution`}
|
|
value={debug.agentExecutionTimeMs && `${debug.agentExecutionTimeMs}ms`}
|
|
/>
|
|
<TimingRow label={t`Total time`} value={totalTime} />
|
|
<TimingRow label={t`Available tools`} value={debug.toolCount} />
|
|
<TimingRow label={t`Tool calls made`} value={debug.toolCallCount} />
|
|
<TimingRow label={t`Context records`} value={debug.contextRecordCount} />
|
|
<TimingRow
|
|
label={t`Context size`}
|
|
value={
|
|
debug.contextSizeBytes !== undefined
|
|
? formatBytes(debug.contextSizeBytes)
|
|
: undefined
|
|
}
|
|
/>
|
|
<TimingRow
|
|
label={t`Routing tokens`}
|
|
value={
|
|
debug.routingTotalTokens !== undefined
|
|
? formatTokenBreakdown(
|
|
debug.routingTotalTokens,
|
|
debug.routingPromptTokens,
|
|
debug.routingCompletionTokens,
|
|
)
|
|
: undefined
|
|
}
|
|
/>
|
|
<TimingRow
|
|
label={t`Agent tokens`}
|
|
value={
|
|
debug.agentTotalTokens !== undefined
|
|
? formatTokenBreakdown(
|
|
debug.agentTotalTokens,
|
|
debug.agentPromptTokens,
|
|
debug.agentCompletionTokens,
|
|
)
|
|
: undefined
|
|
}
|
|
/>
|
|
<TimingRow
|
|
label={t`Total cost`}
|
|
value={totalCost !== undefined ? t`${totalCost} credits` : undefined}
|
|
/>
|
|
</StyledTimingSection>
|
|
);
|
|
};
|
|
|
|
type DetailsTabProps = {
|
|
debug: DebugInfo;
|
|
copyToClipboard: (value: string) => void;
|
|
};
|
|
|
|
const DetailsTab = ({ debug, copyToClipboard }: DetailsTabProps) => {
|
|
const { t } = useLingui();
|
|
|
|
const detailsData = {
|
|
selectedAgent: {
|
|
id: debug.selectedAgentId,
|
|
label: debug.selectedAgentLabel,
|
|
},
|
|
fastModel: debug.fastModel,
|
|
smartModel: debug.smartModel,
|
|
agentModel: debug.agentModel,
|
|
availableAgents: debug.availableAgents,
|
|
};
|
|
|
|
return (
|
|
<StyledJsonTreeContainer>
|
|
<JsonTree
|
|
value={detailsData as JsonValue}
|
|
shouldExpandNodeInitially={() => true}
|
|
emptyArrayLabel={t`Empty Array`}
|
|
emptyObjectLabel={t`Empty Object`}
|
|
emptyStringLabel={t`[empty string]`}
|
|
arrowButtonCollapsedLabel={t`Expand`}
|
|
arrowButtonExpandedLabel={t`Collapse`}
|
|
onNodeValueClick={copyToClipboard}
|
|
/>
|
|
</StyledJsonTreeContainer>
|
|
);
|
|
};
|
|
|
|
type ContextTabProps = {
|
|
debug: DebugInfo;
|
|
copyToClipboard: (value: string) => void;
|
|
};
|
|
|
|
const ContextTab = ({ debug, copyToClipboard }: ContextTabProps) => {
|
|
const { t } = useLingui();
|
|
|
|
if (!debug.context) {
|
|
return (
|
|
<StyledTimingLabel>
|
|
{t`No context was provided for this request`}
|
|
</StyledTimingLabel>
|
|
);
|
|
}
|
|
|
|
try {
|
|
const contextData = JSON.parse(debug.context);
|
|
|
|
return (
|
|
<StyledJsonTreeContainer>
|
|
<JsonTree
|
|
value={contextData as JsonValue}
|
|
shouldExpandNodeInitially={() => false}
|
|
emptyArrayLabel={t`Empty Array`}
|
|
emptyObjectLabel={t`Empty Object`}
|
|
emptyStringLabel={t`[empty string]`}
|
|
arrowButtonCollapsedLabel={t`Expand`}
|
|
arrowButtonExpandedLabel={t`Collapse`}
|
|
onNodeValueClick={copyToClipboard}
|
|
/>
|
|
</StyledJsonTreeContainer>
|
|
);
|
|
} catch {
|
|
const contextValue = debug.context;
|
|
return (
|
|
<StyledTimingLabel>
|
|
{t`Failed to parse context: ${contextValue}`}
|
|
</StyledTimingLabel>
|
|
);
|
|
}
|
|
};
|
|
|
|
type RoutingDebugDisplayProps = {
|
|
debug: DebugInfo;
|
|
};
|
|
|
|
export const RoutingDebugDisplay = ({ debug }: RoutingDebugDisplayProps) => {
|
|
const { theme } = useContext(ThemeContext);
|
|
const { t } = useLingui();
|
|
const { copyToClipboard } = useCopyToClipboard();
|
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
const [activeTab, setActiveTab] = useState<TabType>('timing');
|
|
|
|
return (
|
|
<StyledContainer>
|
|
<StyledToggleButton onClick={() => setIsExpanded(!isExpanded)}>
|
|
<StyledTimingLabel>{t`Debug Info`}</StyledTimingLabel>
|
|
{isExpanded ? (
|
|
<IconChevronUp size={theme.icon.size.sm} />
|
|
) : (
|
|
<IconChevronDown size={theme.icon.size.sm} />
|
|
)}
|
|
</StyledToggleButton>
|
|
|
|
<AnimatedExpandableContainer isExpanded={isExpanded} mode="fit-content">
|
|
<StyledContentContainer>
|
|
<StyledTabContainer>
|
|
<StyledTab
|
|
isActive={activeTab === 'timing'}
|
|
onClick={() => setActiveTab('timing')}
|
|
>
|
|
{t`Timing`}
|
|
</StyledTab>
|
|
<StyledTab
|
|
isActive={activeTab === 'details'}
|
|
onClick={() => setActiveTab('details')}
|
|
>
|
|
{t`Details`}
|
|
</StyledTab>
|
|
{debug.context && (
|
|
<StyledTab
|
|
isActive={activeTab === 'context'}
|
|
onClick={() => setActiveTab('context')}
|
|
>
|
|
{t`Context`}
|
|
</StyledTab>
|
|
)}
|
|
</StyledTabContainer>
|
|
|
|
{activeTab === 'timing' && <TimingTab debug={debug} />}
|
|
{activeTab === 'details' && (
|
|
<DetailsTab debug={debug} copyToClipboard={copyToClipboard} />
|
|
)}
|
|
{activeTab === 'context' && (
|
|
<ContextTab debug={debug} copyToClipboard={copyToClipboard} />
|
|
)}
|
|
</StyledContentContainer>
|
|
</AnimatedExpandableContainer>
|
|
</StyledContainer>
|
|
);
|
|
};
|