Merge branch 'dev' into redesigning-block-menu

This commit is contained in:
abhi1992002
2025-06-06 18:23:17 +05:30
8 changed files with 59 additions and 43 deletions

View File

@@ -22,6 +22,9 @@ class AgentExecutorBlock(Block):
user_id: str = SchemaField(description="User ID")
graph_id: str = SchemaField(description="Graph ID")
graph_version: int = SchemaField(description="Graph Version")
agent_name: Optional[str] = SchemaField(
default=None, description="Name to display in the Builder UI"
)
inputs: BlockInput = SchemaField(description="Input data for the graph")
input_schema: dict = SchemaField(description="Input schema for the graph")

View File

@@ -68,7 +68,7 @@ def get_blocks(
) -> BlockResponse:
"""
Get blocks based on either category, type or provider.
Providing nothing assumes category is `all`.
Providing nothing fetches all block types.
"""
# Only one of category, type, or provider can be specified
if (category and type) or (category and provider) or (type and provider):
@@ -79,7 +79,6 @@ def get_blocks(
take = page_size
total = 0
# todo kcze cache instances?
for block_type in load_all_blocks().values():
block: Block[BlockSchema, BlockSchema] = block_type()
# Skip disabled blocks
@@ -109,10 +108,10 @@ def get_blocks(
take -= 1
blocks.append(block)
# todo kcze costs
costs = get_block_costs()
return BlockResponse(
blocks=[b.to_dict() for b in blocks],
blocks=[{**b.to_dict(), "costs": costs.get(b.id, [])} for b in blocks],
pagination=server_model.Pagination(
total_items=total,
total_pages=total // page_size + (1 if total % page_size > 0 else 0),

View File

@@ -18,6 +18,7 @@ logger = logging.getLogger(__name__)
router = fastapi.APIRouter()
# Taken from backend/server/v2/store/db.py
def sanitize_query(query: str | None) -> str | None:
if query is None:
return query
@@ -44,7 +45,9 @@ def sanitize_query(query: str | None) -> str | None:
async def get_suggestions(
user_id: Annotated[str, fastapi.Depends(get_user_id)],
) -> builder_model.SuggestionsResponse:
# todo kcze temp response
"""
Get all suggestions for the Blocks Menu.
"""
return builder_model.SuggestionsResponse(
otto_suggestions=[
"What blocks do I need to get started?",
@@ -59,9 +62,9 @@ async def get_suggestions(
providers=[
ProviderName.TWITTER,
ProviderName.GITHUB,
ProviderName.HUBSPOT,
ProviderName.EXA,
ProviderName.JINA,
ProviderName.NOTION,
ProviderName.GOOGLE,
ProviderName.DISCORD,
ProviderName.GOOGLE_MAPS,
],
top_blocks=await builder_db.get_suggested_blocks(),
@@ -75,6 +78,9 @@ async def get_suggestions(
async def get_block_categories(
category_blocks: Annotated[int, fastapi.Query()] = 3,
) -> Sequence[builder_model.BlockCategoryResponse]:
"""
Get all block categories with a specified number of blocks per category.
"""
return builder_db.get_block_categories(category_blocks)
@@ -89,6 +95,9 @@ async def get_blocks(
page: Annotated[int, fastapi.Query()] = 1,
page_size: Annotated[int, fastapi.Query()] = 50,
) -> builder_model.BlockResponse:
"""
Get blocks based on either category, type, or provider.
"""
return builder_db.get_blocks(
category=category,
type=type,
@@ -106,6 +115,9 @@ async def get_providers(
page: Annotated[int, fastapi.Query()] = 1,
page_size: Annotated[int, fastapi.Query()] = 50,
) -> builder_model.ProviderResponse:
"""
Get all integration providers with their block counts.
"""
return builder_db.get_providers(
page=page,
page_size=page_size,
@@ -121,6 +133,9 @@ async def search(
options: builder_model.SearchRequest,
user_id: Annotated[str, fastapi.Depends(get_user_id)],
) -> builder_model.SearchResponse:
"""
Search for blocks (including integrations), marketplace agents, and user library agents.
"""
# If no filters are provided, then we will return all types
if not options.filter:
options.filter = [
@@ -178,18 +193,14 @@ async def search(
)
more_pages = False
if blocks.blocks.pagination.current_page < blocks.blocks.pagination.total_pages:
more_pages = True
if my_agents.pagination.current_page < my_agents.pagination.total_pages:
more_pages = True
if (
marketplace_agents.pagination.current_page
blocks.blocks.pagination.current_page < blocks.blocks.pagination.total_pages
or my_agents.pagination.current_page < my_agents.pagination.total_pages
or marketplace_agents.pagination.current_page
< marketplace_agents.pagination.total_pages
):
more_pages = True
# todo kcze sort results
return builder_model.SearchResponse(
items=blocks.blocks.blocks + my_agents.agents + marketplace_agents.agents,
total_items={
@@ -210,4 +221,7 @@ async def search(
async def get_counts(
user_id: Annotated[str, fastapi.Depends(get_user_id)],
) -> builder_model.CountResponse:
"""
Get item counts for the menu categories in the Blocks Menu.
"""
return await builder_db.get_counts(user_id)

View File

@@ -105,7 +105,6 @@ const FlowEditor: React.FC<{
setAgentDescription,
savedAgent,
availableNodes,
availableFlows,
getOutputType,
requestSave,
requestSaveAndRun,

View File

@@ -10,6 +10,7 @@ import BackendAPI, {
GraphID,
NodeExecutionResult,
SpecialBlockID,
Node,
} from "@/lib/autogpt-server-api";
import {
deepEquals,
@@ -177,6 +178,16 @@ export default function useAgentGraph(
setAgentName(graph.name);
setAgentDescription(graph.description);
const getGraphName = (node: Node) => {
if (node.input_default.agent_name) {
return node.input_default.agent_name;
}
return (
availableFlows.find((flow) => flow.id === node.input_default.graph_id)
?.name || null
);
};
setNodes((prevNodes) => {
const _newNodes = graph.nodes.map((node) => {
const block = availableNodes.find(
@@ -184,12 +195,8 @@ export default function useAgentGraph(
)!;
if (!block) return null;
const prevNode = prevNodes.find((n) => n.id === node.id);
const flow =
block.uiType == BlockUIType.AGENT
? availableFlows.find(
(flow) => flow.id === node.input_default.graph_id,
)
: null;
const graphName =
(block.uiType == BlockUIType.AGENT && getGraphName(node)) || null;
const newNode: CustomNode = {
id: node.id,
type: "custom",
@@ -201,7 +208,7 @@ export default function useAgentGraph(
isOutputOpen: false,
...prevNode?.data,
block_id: block.id,
blockType: flow?.name || block.name,
blockType: graphName || block.name,
blockCosts: block.costs,
categories: block.categories,
description: block.description,
@@ -284,15 +291,17 @@ export default function useAgentGraph(
const getToolFuncName = (nodeId: string) => {
const sinkNode = nodes.find((node) => node.id === nodeId);
const sinkNodeName = sinkNode
? sinkNode.data.block_id === SpecialBlockID.AGENT
? sinkNode.data.hardcodedValues?.graph_id
? availableFlows.find(
(flow) => flow.id === sinkNode.data.hardcodedValues.graph_id,
)?.name || "agentexecutorblock"
: "agentexecutorblock"
: sinkNode.data.title.split(" ")[0]
: "";
if (!sinkNode) return "";
const sinkNodeName =
sinkNode.data.block_id === SpecialBlockID.AGENT
? sinkNode.data.hardcodedValues?.agent_name ||
availableFlows.find(
(flow) => flow.id === sinkNode.data.hardcodedValues.graph_id,
)?.name ||
"agentexecutorblock"
: sinkNode.data.title.split(" ")[0];
return sinkNodeName;
};
@@ -1101,7 +1110,6 @@ export default function useAgentGraph(
setAgentDescription,
savedAgent,
availableNodes,
availableFlows,
getOutputType,
requestSave,
requestSaveAndRun,

View File

@@ -241,12 +241,7 @@ export default class BackendAPI {
searchBlocks(options: {
search_query?: string;
filter?: (
| "blocks"
| "integrations"
| "marketplace_agents"
| "my_agents"
)[];
filter?: ("blocks" | "integrations" | "marketplace_agents" | "my_agents")[];
by_creator?: string[];
search_id?: string;
page?: number;

View File

@@ -74,10 +74,7 @@ export type ProviderResponse = {
export type BlockSearchResponse = {
items: (Block | LibraryAgent | StoreAgent)[];
total_items: Record<
| "blocks"
| "integrations"
| "marketplace_agents"
| "my_agents",
"blocks" | "integrations" | "marketplace_agents" | "my_agents",
number
>;
page: number;

View File

@@ -423,6 +423,7 @@ export const convertLibraryAgentIntoBlock = (agent: LibraryAgent) => {
graph_version: agent.graph_version,
input_schema: agent.input_schema,
output_schema: agent.output_schema,
agent_name: agent.name,
},
} as Block;