Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[front] - feat(front): popular assistants tab (#5649)
* [front/lib/api/assistant] - feature: implement and store popular agents data - Added a new function to compute the most popular agents based on mentions within a specified timeframe - Store the popular agents in Redis with an expiry, refreshing the data when outdated [front/lib/api/assistant] - refactor: extend usage of safeRedisClient for Redis interactions - Modified existing Redis interactions to use the safeRedisClient for better error handling and consistency - Included expiration time for popular agents data to ensure up-to-date information is maintained in cache [front/lib/api/assistant] - feature: add retrieval of popular agents from Redis - Implemented a function to fetch the most popular agents from Redis, updating the cache if data is stale - Ensured that only relevant data is retrieved and parsed from Redis for the list of popular agents * [front/lib/api/assistant] - refactor: streamline agent usage tracking and ranking in Redis - Removed the individual sorting and storage of agent messages, switching to a hash based count per workspace for efficiency - Added logic to update and fetch agent message counts and ranking only when data is outdated - Removed the dependency on the uuid package by eliminating the need for unique message identifiers - Implemented a function to retrieve the usage stats of agents, considering message counts within a set ranking timeframe - Improved code maintainability by introducing utility functions and constants related to agent popularity metrics * [assistant/agent_usage] - refactor: streamline agent usage data structure in Redis - Removed the 'index' field from the agent usage data structure as it's no longer needed - Adjusted the data parsing logic to work with the simplified data structure, parsing counts as integers directly - Updated the Redis transaction to store just the counts without JSON stringification * [front/lib/api/assistant] - refactor: streamline agent usage update logic - Replaced last updated timestamp check with TTL based validation to manage agent usage updates - Implemented a stale data check, where outdated agent mention counts trigger an asynchronous update without blocking the retrieval - Doubled the expiration time for both agent message and user counts in Redis for extended data availability * [assistant] - refactor: remove placeholder for most popular agents - Eliminate the static slice operation placeholder which was limiting the popular agents' implementation [api/assistant] - refactor: clean up agent popularity code - Remove the unused function `getMostPopularAgents` and its associated constants [assistant/new] - feature: include usage data in assistant loading calls - Extend the data includes to fetch agent usage information in addition to the authors data in the new assistant page - Adjust the agents API query parameters to fetch both authors and usage data for comprehensive data loading on assistant instantiation * [front/lib/api/assistant] - feature: implement agent usage signaling functionality - Added a new function `signalAgentUsage` which appears to be a placeholder for future implementation [front/pages/api/w/[wId]/assistant/agent_configurations] - refactor: streamline agent configurations usage fetching - Replaced the `getAgentUsage` call with `getAgentUsage` to fetch usage data in batch - Introduced a Map for efficient lookups of message counts by agent configuration ID - Agent configurations now include a default structure for usage data with userCount, messageCount, usersWithAgentInListCount, and timePeriodSec fields * [assistant] - refactor: streamline agent usage signaling process - Removed parameters from signalAgentUsage function to simplify its signature - Modified postUserMessage and editUserMessage to not send unnecessary data to signalAgentError - Adjusted storeCountsInRedis function to directly increment message count in Redis without extra parameters [assistant/conversation] - refactor: remove deprecated userId and timestamp from agent messages - Eliminated sending of userId and timestamp when signaling agent usage - Updated associated agent message handling functions to reflect changes in data flow [assistant/agent_configurations] - style: clean up import statement for getAgentsUsage function - Removed unnecessary line breaks from the getAgentsUsage import statement for better readability * [types] - feature: introduce LightAgentUsageType and update usage property - Added a new type LightAgentUsageType for more efficient usage tracking - Extended the usage property to accept either AgentUsageType or LightAgentUsageType * [front/components/assistant] - feature: enhance assistant usage message with light agent type support - Extend assistant usage message functionality to handle 'LightAgentUsageType' - Utilize the newly imported 'isAgentUsageType' to check for proper usage type before rendering the message [front/lib/api/assistant] - refactor: enrich agent usage data with time period information - Add 'timePeriodSec' to the return object in agent usage related API calls - Ensure that the usage data includes the time period for better context in usage metrics [front/pages/api/w/[wId]/assistant] - fix: correct agent configuration usage assignment - Fix the mapping of agent usage data to agent configurations, ensuring accurate data representation - Address the incorrect assignment of 'timePeriodSec' to messageCount, ensuring correct mapping for time period - Refactor the creation of the usageMap to properly store and retrieve 'mentionCount' objects * [assistant] - refactor: clean up code and update agent configurations API - Removed outdated TODO comment from AssistantBrowser component - Refactored import statements in agent configurations API handler - Updated `agentsGetView` parameter to "assistants-search" for assistant creation page * [front/assistant] - refactor: streamline most_popular agents and add limit to usage retrieval - Removed sorting from the `most_popular` field as sorting is now handled in the `getAgentsUsage` function - Added limit parameter to `getAgentsUsage` function to support fetching a limited number of agent usage records [front/api] - refactor: change fetching and mapping logic for agent usage - Replaced manual Map creation with lodash's `keyBy` for better readability and efficiency - Updated agent configurations API to accept a limit query parameter for the usage data [types/assistant] - refactor: remove redundant comment about usage computation in agent types - Removed outdated comment as the agent usage is now conditionally computed based on the presence of the `limit` query parameter * [front/assistant] - refactor: streamline agent usage data and related components - Removed checks for usersWithAgentInListCount when newScope is "private" in Sharing component - Simplified assistantUsageMessage by removing isAgentUsageType and related conditionals - Updated getAgentsUsage function to include user count and removed outdated agent list count logic - Cleaned up imports and unused code across frontend components related to agent usage [types/assistant] - refactor: remove deprecated LightAgentUsageType and related function - Deleted LightAgentUsageType and isAgentUsageType check as they are no longer used in the overall agent usage context * [api/assistant] - refactor: secure agent usage query with authentication - Added authentication parameter to getAgentUsage to ensure requests are authenticated - Added check to confirm the workspace ID matches the authenticated user's workspace ID [api/assistant] - feature: add graceful shutdown for Redis connections - Implemented closing of Redis connections to prevent potential resource leaks - Ensured Redis connections are closed after usage in agent usage data retrieval functions [api] - fix: correct API endpoint to use authentication for agent usage - Updated agent usage API handler to pass the authenticator to the getAgentUsage function - Refined agent usage data query logic to align with new authentication requirement * [assistant] - feature: improve most popular agents sorting and clarify code - Sort the 'most_popular' agents by their message count in descending order for better relevance - Replace the magic number `-2` with a named constant `TTL_KEY_NOT_EXIST` to increase code readability and maintainability * [front/components/assistant] - fix: handle possible undefined usage in AssistantBrowser sorting - Ensure sorting by messageCount doesn't break when a.usage or b.usage is undefined by coalescing to zero. * [front/lib/api/assistant] - fix: handle redis connection cleanup on usage signal - Ensure redis client is properly closed using try-finally to prevent potential resource leaks - Code refactor to enhance the reliability of agent usage signaling by including connection cleanup logic --------- Co-authored-by: Jules <[email protected]> Co-authored-by: Jules <[email protected]>
- Loading branch information