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
89 changes: 84 additions & 5 deletions src/components/SmartGeneration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ interface ChangeField {
member_type: string;
cube: string;
reason?: string;
source?: "map" | "nested" | "ai";
}

interface ChangeBlock {
Expand Down Expand Up @@ -896,7 +897,11 @@ const SmartGeneration: FC<SmartGenerationProps> = ({
new Set()
);

const [selectedModelFields, setSelectedModelFields] = useState<Set<string>>(
new Set()
);
const [profileData, setProfileData] = useState<any>(null);
const [skipLlm, setSkipLlm] = useState(false);
const [progressEvents, setProgressEvents] = useState<ProgressEvent[]>([]);
const abortRef = useRef<AbortController | null>(null);

Expand Down Expand Up @@ -1204,7 +1209,8 @@ const SmartGeneration: FC<SmartGenerationProps> = ({
file_name: fileNameOverride || undefined,
cube_name: cubeNameOverride || undefined,
selected_columns: isSubset ? [...selectedColumns] : undefined,
});
skip_llm: skipLlm || undefined,
} as any);

if (result.error) {
setError(result.error.message);
Expand All @@ -1216,13 +1222,43 @@ const SmartGeneration: FC<SmartGenerationProps> = ({
const preview = genData?.change_preview;
if (preview) {
setChangePreview(preview as ChangePreview);

// Required fields: rewrite rule dimensions + filter dimensions (always included)
const requiredSet = new Set<string>(genData?.required_fields || []);

// Default selection rules:
// ALWAYS checked: count measure, required fields (rewrite rules + filters)
// Checked by default: regular columns (no source tag)
// Unchecked (opt-in): map fields, nested fields, AI-generated fields
const isDefaultSelected = (f: any) => {
const key = `${f.cube}.${f.name}`;
// Always include required fields
if (requiredSet.has(key)) return true;
// Always include the count measure
if (f.name === "count" && f.member_type === "measure") return true;
// Opt-in sources: map, nested (ARRAY JOIN), AI-generated
if (f.source === "map" || f.source === "nested" || f.source === "ai")
return false;
// Everything else checked by default
return true;
};

const allKeys = [
...(preview.fields_added || [])
.filter(isDefaultSelected)
.map((f: any) => `${f.cube}.${f.name}`),
...(preview.fields_updated || [])
.filter(isDefaultSelected)
.map((f: any) => `${f.cube}.${f.name}`),
];
setSelectedModelFields(new Set(allKeys));
}

// Capture AI metric suggestions from the LLM (if any)
const aiSuggestions = genData?.ai_enrichment?.suggested_metrics || [];
setSuggestedAIMetrics(aiSuggestions);
// All selected by default
setSelectedAIMetricNames(new Set(aiSuggestions.map((m: any) => m.name)));
// AI metrics are opt-in (unchecked by default)
setSelectedAIMetricNames(new Set());

setStep("change_preview");
}, [
Expand Down Expand Up @@ -1255,6 +1291,15 @@ const SmartGeneration: FC<SmartGenerationProps> = ({
).length ?? 0;
const applyIsSubset = selectedColumns.size < applyActiveCount;

// Compute excluded fields: all preview fields NOT in the user's selection
const allPreviewFields = [
...((changePreview?.fields_added || []) as ChangeField[]),
...((changePreview?.fields_updated || []) as ChangeField[]),
].map((f) => `${f.cube}.${f.name}`);
const excludedFields = allPreviewFields.filter(
(key) => !selectedModelFields.has(key)
);

const result = await execSmartGen({
datasource_id: dataSource.id!,
branch_id: branchId,
Expand All @@ -1269,9 +1314,10 @@ const SmartGeneration: FC<SmartGenerationProps> = ({
filters: filters.length > 0 ? filters : undefined,
file_name: fileNameOverride || undefined,
cube_name: cubeNameOverride || undefined,
selected_ai_metrics:
selectedAIMetricNames.size > 0 ? [...selectedAIMetricNames] : undefined,
selected_ai_metrics: [...selectedAIMetricNames],
selected_columns: applyIsSubset ? [...selectedColumns] : undefined,
excluded_fields: excludedFields.length > 0 ? excludedFields : undefined,
skip_llm: skipLlm || undefined,
} as any);

if (result.error) {
Expand All @@ -1292,6 +1338,8 @@ const SmartGeneration: FC<SmartGenerationProps> = ({
filters,
selectedAIMetricNames,
selectedColumns,
selectedModelFields,
changePreview,
profileData,
execSmartGen,
]);
Expand Down Expand Up @@ -1579,6 +1627,24 @@ const SmartGeneration: FC<SmartGenerationProps> = ({
/>
)}

<div
style={{
display: "flex",
alignItems: "center",
gap: 8,
marginBottom: 8,
}}
>
<Checkbox
checked={skipLlm}
onChange={(e) => setSkipLlm(e.target.checked)}
>
<Text style={{ fontSize: 12 }}>
Skip LLM enrichment (faster, no AI metrics or descriptions)
</Text>
</Checkbox>
</div>

<div className={styles.actions}>
<Button
size="large"
Expand Down Expand Up @@ -1733,6 +1799,19 @@ const SmartGeneration: FC<SmartGenerationProps> = ({
)}

<div className={styles.actions}>
<Button
size="large"
onClick={() => {
setStep("select");
setChangePreview(null);
setSuggestedAIMetrics([]);
setSelectedAIMetricNames(new Set());
setSelectedModelFields(new Set());
setError(null);
}}
>
Start Over
</Button>
<Button
size="large"
onClick={() => {
Expand Down
2 changes: 2 additions & 0 deletions src/graphql/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13961,6 +13961,7 @@ export const SmartGenDataSchemasDocument = gql`
$cube_name: String
$selected_ai_metrics: [String]
$selected_columns: [String]
$skip_llm: Boolean
) {
smart_gen_dataschemas(
datasource_id: $datasource_id
Expand All @@ -13977,6 +13978,7 @@ export const SmartGenDataSchemasDocument = gql`
cube_name: $cube_name
selected_ai_metrics: $selected_ai_metrics
selected_columns: $selected_columns
skip_llm: $skip_llm
) {
code
message
Expand Down
2 changes: 2 additions & 0 deletions src/graphql/gql/datasources.gql
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ mutation SmartGenDataSchemas(
$cube_name: String
$selected_ai_metrics: [String]
$selected_columns: [String]
$skip_llm: Boolean
) {
smart_gen_dataschemas(
datasource_id: $datasource_id
Expand All @@ -244,6 +245,7 @@ mutation SmartGenDataSchemas(
cube_name: $cube_name
selected_ai_metrics: $selected_ai_metrics
selected_columns: $selected_columns
skip_llm: $skip_llm
) {
code
message
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/schemas/hasura.json

Large diffs are not rendered by default.