searchCLI #5

Merged
lotte merged 4 commits from searchCLI into main 2025-04-21 00:39:02 +00:00
2 changed files with 38 additions and 9 deletions
Showing only changes of commit 853b60d762 - Show all commits

View file

@ -569,19 +569,11 @@ async function processCommand(input) {
}
}
/**
* Custom respond function for handling results
* @param {string} action The action being performed
* @param {string} module The module being used
* @param {Array} params The parameters for the action
* @returns {Function} A respond function for handling results
*/
function createRespondFunction(action, module, params) {
// Keep track of whether we're waiting for results
let isWaitingForResults = false;
return async (response) => {
// Check if this is a progress message
const isProgressMessage =
typeof response === 'object' &&
response.text &&
@ -604,12 +596,46 @@ function createRespondFunction(action, module, params) {
// First check for the responseData property (directly from service)
if (response.responseData) {
// Format the data using the appropriate formatter
if (module === 'sigma') {
let formattedData;
if (action === 'search' || action === 'complexSearch') {
formattedData = formatSigmaSearchResults(response.responseData);
/*
This conversion functionality exists because the Fylgja CLI's formatting
system expects search results in a specific structure with results and
totalCount properties, while the underlying sigma search service
returns results as a direct array of rule objects. This adapter pattern allows
the system to handle different response formats from various backend services
without requiring extensive changes to either the service layer or the presentation
layer. It essentially serves as a compatibility layer between components that were
likely developed independently or evolved at different times in the project's
lifecycle, maintaining backward compatibility while allowing for flexibility
in how data is processed throughout the application.
*/
// Try to adapt data structure if needed
let dataToFormat = response.responseData;
// If responseData is just an array, wrap it in proper structure
if (Array.isArray(dataToFormat)) {
dataToFormat = {
results: dataToFormat,
totalCount: dataToFormat.length
};
}
// If missing totalCount but has pagination info, adapt
else if (dataToFormat.results &&
!dataToFormat.totalCount &&
dataToFormat.pagination &&
dataToFormat.pagination.totalResults) {
dataToFormat.totalCount = dataToFormat.pagination.totalResults;
}
formattedData = formatSigmaSearchResults(dataToFormat);
formatOutput(formattedData, 'search_results');
} else if (action === 'details') {
formattedData = formatSigmaDetails(response.responseData);
@ -638,6 +664,7 @@ function createRespondFunction(action, module, params) {
};
}
/**
* Display help text
*/

View file

@ -147,6 +147,7 @@ const handleCommand = async (command, respond) => {
// Respond with the search results
await respond({
blocks: blocks,
responseData: searchResult.results,
response_type: isEphemeral ? 'ephemeral' : 'in_channel'
});
@ -271,6 +272,7 @@ const handleComplexSearch = async (command, respond) => {
// Respond with the search results
await respond({
blocks: blocks,
responseData: searchResult.results,
response_type: 'ephemeral' // Complex searches are usually more specific to the user
});