Compare commits

...

8 Commits

9 changed files with 45 additions and 33 deletions

View File

@@ -31,7 +31,7 @@ integration_creds_manager = IntegrationCredentialsManager()
async def list_library_agents(
user_id: str,
search_term: Optional[str] = None,
sort_by: library_model.LibraryAgentSort = library_model.LibraryAgentSort.UPDATED_AT,
sort_by: Optional[library_model.LibraryAgentSort] = None,
page: int = 1,
page_size: int = 50,
) -> library_model.LibraryAgentResponse:
@@ -41,7 +41,7 @@ async def list_library_agents(
Args:
user_id: The ID of the user whose LibraryAgents we want to retrieve.
search_term: Optional string to filter agents by name/description.
sort_by: Sorting field (createdAt, updatedAt, isFavorite, isCreatedByUser).
sort_by: Sorting field (createdAt, updatedAt, lastExecuted).
page: Current page (1-indexed).
page_size: Number of items per page.
@@ -89,12 +89,23 @@ async def list_library_agents(
]
# Determine sorting
order_by: prisma.types.LibraryAgentOrderByInput | None = None
order_by: (
prisma.types.LibraryAgentOrderByInput
| list[prisma.types.LibraryAgentOrderByInput]
| None
) = None
if sort_by == library_model.LibraryAgentSort.CREATED_AT:
order_by = {"createdAt": "asc"}
elif sort_by == library_model.LibraryAgentSort.UPDATED_AT:
order_by = {"updatedAt": "desc"}
elif sort_by == library_model.LibraryAgentSort.LAST_EXECUTED:
# Sort by the most recent AgentGraph.Execution (startedAt) first.
# If no executions exist, fall back to sorting by updatedAt.
order_by = [
{"AgentGraph": {"Executions": {"startedAt": "desc"}}}, # FIXME: not supprted
{"updatedAt": "desc"},
]
try:
library_agents = await prisma.models.LibraryAgent.prisma().find_many(
@@ -472,7 +483,7 @@ async def add_store_agent_to_library(
Args:
store_listing_version_id: The ID of the store listing version containing the agent.
user_id: The users library to which the agent is being added.
user_id: The user's library to which the agent is being added.
Returns:
The newly created LibraryAgent if successfully added, the existing corresponding one if any.

View File

@@ -319,6 +319,7 @@ class LibraryAgentSort(str, Enum):
CREATED_AT = "createdAt"
UPDATED_AT = "updatedAt"
LAST_EXECUTED = "lastExecuted"
class LibraryAgentUpdateRequest(pydantic.BaseModel):

View File

@@ -37,7 +37,7 @@ async def list_library_agents(
None, description="Search term to filter agents"
),
sort_by: library_model.LibraryAgentSort = Query(
library_model.LibraryAgentSort.UPDATED_AT,
library_model.LibraryAgentSort.LAST_EXECUTED,
description="Criteria to sort results by",
),
page: int = Query(

View File

@@ -11,24 +11,29 @@ import {
import { LibraryAgentSort } from "@/app/api/__generated__/models/libraryAgentSort";
import { useLibrarySortMenu } from "./useLibrarySortMenu";
const defaultSort = LibraryAgentSort.lastExecuted;
export default function LibrarySortMenu(): React.ReactNode {
const { handleSortChange } = useLibrarySortMenu();
const { getSortLabel, setLibrarySort } = useLibrarySortMenu();
return (
<div className="flex items-center">
<span className="hidden whitespace-nowrap sm:inline">sort by</span>
<Select onValueChange={handleSortChange}>
<Select
onValueChange={(value) => setLibrarySort(value as LibraryAgentSort)}
defaultValue={defaultSort}
>
<SelectTrigger className="ml-1 w-fit space-x-1 border-none px-0 text-base underline underline-offset-4 shadow-none">
<ArrowDownNarrowWideIcon className="h-4 w-4 sm:hidden" />
<SelectValue placeholder="Last Modified" />
<SelectValue placeholder={getSortLabel(defaultSort)} />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem value={LibraryAgentSort.createdAt}>
Creation Date
</SelectItem>
<SelectItem value={LibraryAgentSort.updatedAt}>
Last Modified
</SelectItem>
{Object.entries(LibraryAgentSort).map(([key, value]) => (
<SelectItem key={key} value={value}>
{getSortLabel(value)}
</SelectItem>
))}
</SelectGroup>
</SelectContent>
</Select>

View File

@@ -1,27 +1,20 @@
import { useCallback } from "react";
import { LibraryAgentSort } from "@/app/api/__generated__/models/libraryAgentSort";
import { useLibraryPageContext } from "../state-provider";
export const useLibrarySortMenu = () => {
const { setLibrarySort } = useLibraryPageContext();
const handleSortChange = (value: LibraryAgentSort) => {
// Simply updating the sort state - React Query will handle the rest
setLibrarySort(value);
};
const getSortLabel = (sort: LibraryAgentSort) => {
switch (sort) {
case LibraryAgentSort.createdAt:
return "Creation Date";
case LibraryAgentSort.updatedAt:
return "Last Modified";
default:
return "Last Modified";
}
};
const getSortLabel = useCallback((sort: LibraryAgentSort) => {
return {
[LibraryAgentSort.createdAt]: "Creation Date",
[LibraryAgentSort.updatedAt]: "Last Modified",
[LibraryAgentSort.lastExecuted]: "Last Executed",
}[sort];
}, []);
return {
handleSortChange,
setLibrarySort,
getSortLabel,
};
};

View File

@@ -31,7 +31,7 @@ export function LibraryPageStateProvider({
const [searchTerm, setSearchTerm] = useState<string>("");
const [uploadedFile, setUploadedFile] = useState<File | null>(null);
const [librarySort, setLibrarySort] = useState<LibraryAgentSort>(
LibraryAgentSort.updatedAt,
LibraryAgentSort.lastExecuted,
);
return (

View File

@@ -16,4 +16,5 @@ export type LibraryAgentSort =
export const LibraryAgentSort = {
createdAt: "createdAt",
updatedAt: "updatedAt",
lastExecuted: "lastExecuted",
} as const;

View File

@@ -3086,7 +3086,7 @@
"schema": {
"$ref": "#/components/schemas/LibraryAgentSort",
"description": "Criteria to sort results by",
"default": "updatedAt"
"default": "lastExecuted"
},
"description": "Criteria to sort results by"
},
@@ -4809,7 +4809,7 @@
},
"LibraryAgentSort": {
"type": "string",
"enum": ["createdAt", "updatedAt"],
"enum": ["createdAt", "updatedAt", "lastExecuted"],
"title": "LibraryAgentSort",
"description": "Possible sort options for sorting library agents."
},

View File

@@ -467,6 +467,7 @@ export type LibraryAgentPresetUpdatable = Partial<
export enum LibraryAgentSortEnum {
CREATED_AT = "createdAt",
UPDATED_AT = "updatedAt",
LAST_EXECUTED = "lastExecuted",
}
/* *** CREDENTIALS *** */