Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

[Fix] Highlight in single pass when enforce type is text (#1200)

jagadeeswaran-zipstackfb92669ed55c
diff --git a/frontend/src/components/custom-tools/prompt-card/PromptCard.jsx b/frontend/src/components/custom-tools/prompt-card/PromptCard.jsx
index ce0d1c0a8..b31d186b9 100644
--- a/frontend/src/components/custom-tools/prompt-card/PromptCard.jsx
+++ b/frontend/src/components/custom-tools/prompt-card/PromptCard.jsx
@@ -49,6 +49,7 @@ const PromptCard = memo(
details,
summarizeIndexStatus,
updateCustomTool,
+ singlePassExtractMode,
} = useCustomToolStore();
const { messages } = useSocketCustomToolStore();
const { setAlertDetails } = useAlertStore();
@@ -166,6 +167,48 @@ const PromptCard = memo(
);
};
+ const addCoordsToFlattened = (coords, flattened) => {
+ if (Array.isArray(coords)) {
+ flattened.push(coords);
+ }
+ };
+
+ const processNestedArray = (nestedValue, flattened) => {
+ if (Array.isArray(nestedValue)) {
+ nestedValue.forEach((coords) =>
+ addCoordsToFlattened(coords, flattened)
+ );
+ }
+ };
+
+ const processObjectValues = (item, flattened) => {
+ if (typeof item === "object" && !Array.isArray(item)) {
+ Object.values(item).forEach((value) =>
+ processNestedArray(value, flattened)
+ );
+ }
+ };
+
+ const processArrayItem = (item, flattened) => {
+ if (Array.isArray(item)) {
+ addCoordsToFlattened(item, flattened);
+ } else {
+ processObjectValues(item, flattened);
+ }
+ };
+
+ const flattenHighlightData = (data) => {
+ if (!data || typeof data !== "object") return data;
+
+ const flattened = [];
+ Object.values(data).forEach((value) => {
+ if (Array.isArray(value)) {
+ value.forEach((item) => processArrayItem(item, flattened));
+ }
+ });
+ return flattened;
+ };
+
const handleSelectHighlight = (
highlightData,
highlightedPrompt,
@@ -173,9 +216,13 @@ const PromptCard = memo(
confidenceData
) => {
if (details?.enable_highlight) {
+ const processedHighlight =
+ singlePassExtractMode && typeof highlightData === "object"
+ ? flattenHighlightData(highlightData)
+ : highlightData;
updateCustomTool({
selectedHighlight: {
- highlight: highlightData,
+ highlight: processedHighlight,
highlightedPrompt: highlightedPrompt,
highlightedProfile: highlightedProfile,
confidence: confidenceData,