Skip to content

Commit 6a4d873

Browse files
committed
Refactor ApiDetails to conditionally display the base prompt tab based on the presence of a 'gen-ai' tag in the API collection. Remove detectedBasePrompt from ApiCollection DTO to streamline data handling.
1 parent 8f7fb1e commit 6a4d873

File tree

2 files changed

+41
-27
lines changed

2 files changed

+41
-27
lines changed

apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiDetails.jsx

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function ApiDetails(props) {
7272
const [loading, setLoading] = useState(false)
7373
const [showMoreActions, setShowMoreActions] = useState(false)
7474
const setSelectedSampleApi = PersistStore(state => state.setSelectedSampleApi)
75+
const allCollections = PersistStore(state => state.allCollections)
7576
const [disabledTabs, setDisabledTabs] = useState([])
7677
const [description, setDescription] = useState("")
7778
const [headersWithData, setHeadersWithData] = useState([])
@@ -608,21 +609,31 @@ function ApiDetails(props) {
608609
<Text variant="headingSm" fontWeight="semibold">
609610
Detected Prompt Template
610611
</Text>
611-
<Box background="bg-surface" padding="2" borderRadius="1" style={{ minHeight: '200px' }}>
612-
<SampleData
613-
data={{
614-
message: detectedBasePrompt,
615-
vulnerabilitySegments: func.findPlaceholders(detectedBasePrompt)
616-
}}
617-
editorLanguage="plaintext"
618-
readOnly={true}
619-
minHeight="200px"
620-
wordWrap={true}
621-
/>
622-
</Box>
623-
<Text variant="bodySm" color="subdued">
624-
Auto-detected prompt template with placeholders from agent traffic. This template represents the common structure of prompts sent to this endpoint.
625-
</Text>
612+
{detectedBasePrompt ? (
613+
<>
614+
<Box background="bg-surface" padding="2" borderRadius="1" style={{ minHeight: '200px' }}>
615+
<SampleData
616+
data={{
617+
message: detectedBasePrompt,
618+
vulnerabilitySegments: func.findPlaceholders(detectedBasePrompt)
619+
}}
620+
editorLanguage="plaintext"
621+
readOnly={true}
622+
minHeight="200px"
623+
wordWrap={true}
624+
/>
625+
</Box>
626+
<Text variant="bodySm" color="subdued">
627+
Auto-detected prompt template with placeholders from agent traffic. This template represents the common structure of prompts sent to this endpoint.
628+
</Text>
629+
</>
630+
) : (
631+
<Box padding="4">
632+
<Text variant="bodyMd" color="subdued">
633+
No prompt template detected yet. The base prompt template will be automatically detected from agent traffic when requests are made to this endpoint.
634+
</Text>
635+
</Box>
636+
)}
626637
</VerticalStack>
627638
</Box>
628639
</VerticalStack>
@@ -829,6 +840,20 @@ function ApiDetails(props) {
829840
</VerticalStack>
830841
)
831842

843+
// Check if collection has gen-ai tag (same pattern as CreateGuardrailModal.jsx)
844+
const hasGenAiTag = () => {
845+
if (!apiDetail?.apiCollectionId || !allCollections) return false;
846+
const collection = allCollections.find(c => c.id === apiDetail.apiCollectionId);
847+
if (!collection) return false;
848+
849+
return collection.envType && collection.envType.some(envType =>
850+
envType.keyName === 'gen-ai'
851+
);
852+
};
853+
854+
// Always show BasePromptTab for AI agents (collections with gen-ai tag)
855+
const shouldShowBasePromptTab = hasGenAiTag();
856+
832857
const components = showForbidden
833858
? [<Box padding="4" key="forbidden"><ForbiddenRole /></Box>]
834859
: [
@@ -838,7 +863,7 @@ function ApiDetails(props) {
838863
tabs={[
839864
ValuesTab,
840865
SchemaTab,
841-
...(detectedBasePrompt ? [BasePromptTab] : []),
866+
...(shouldShowBasePromptTab ? [BasePromptTab] : []),
842867
...(hasIssues ? [IssuesTab] : []),
843868
ApiCallStatsTab,
844869
DependencyTab

libs/dao/src/main/java/com/akto/dto/ApiCollection.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ public class ApiCollection {
7272
String registryStatus;
7373
public static final String REGISTRY_STATUS = "registryStatus";
7474

75-
String detectedBasePrompt;
76-
public static final String DETECTED_BASE_PROMPT = "detectedBasePrompt";
77-
7875
private static final List<String> ENV_KEYWORDS_WITH_DOT = Arrays.asList(
7976
"staging", "preprod", "qa", "demo", "dev", "test", "svc",
8077
"localhost", "local", "intranet", "lan", "example", "invalid",
@@ -470,12 +467,4 @@ public String getRegistryStatus() {
470467
public void setRegistryStatus(String registryStatus) {
471468
this.registryStatus = registryStatus;
472469
}
473-
474-
public String getDetectedBasePrompt() {
475-
return detectedBasePrompt;
476-
}
477-
478-
public void setDetectedBasePrompt(String detectedBasePrompt) {
479-
this.detectedBasePrompt = detectedBasePrompt;
480-
}
481470
}

0 commit comments

Comments
 (0)