import type { SuperagentToolCall, SuperagentToolRenderer, SuperagentToolRendererResolver, SuperagentToolRenderers, } from '../types'; import { isArtifactToolCall } from './artifactToolUtils'; import { isMcpToolName, resolveFromRegistry } from './toolWidgetUtils'; import { ActivatePlatformSkillWidget } from './widgets/ActivatePlatformSkillWidget'; import { AgentBlueprintWidget } from './widgets/AgentBlueprintWidget'; import { ArtifactWidget } from './widgets/ArtifactWidget'; import { AutomationActionWidget } from './widgets/AutomationActionWidget'; import { ClarifyingQuestionsWidget } from './clarifyingQuestions/ClarifyingQuestionsWidget'; import { ConfigurePspCredentialsWidget } from './widgets/ConfigurePspCredentialsWidget'; import { ConnectionStatusWidget } from './widgets/ConnectionStatusWidget'; import { CreateAutomationWidget } from './widgets/CreateAutomationWidget'; import { CreateEntitiesWidget } from './widgets/CreateEntitiesWidget'; import { CreateWorkflowWidget } from './widgets/CreateWorkflowWidget'; import { DeleteEntitiesWidget, UpdateEntitiesWidget } from './widgets/EntityWriteWidget'; import { GeneratedImagesWidget } from './widgets/GeneratedImagesWidget'; import { GetBackendFunctionLogsWidget } from './widgets/GetBackendFunctionLogsWidget'; import { GetConnectorsInfoWidget } from './widgets/GetConnectorsInfoWidget'; import { GrepSearchWidget } from './widgets/GrepSearchWidget'; import { McpToolWidget } from './widgets/McpToolWidget'; import { ReadEntitiesWidget } from './widgets/ReadEntitiesWidget'; import { ReadFileWidget } from './widgets/ReadFileWidget'; import { BrowserbaseScreenshotWidget } from './widgets/ScreenshotWidgets'; import { SearchWebWidget } from './widgets/SearchWebWidget'; import { SelectPaymentProviderWidget } from './widgets/SelectPaymentProviderWidget'; import { SetSecretsWidget } from './widgets/SetSecretsWidget'; import { ShowChannelConnectionOptionsWidget } from './widgets/ShowChannelConnectionOptionsWidget'; import { SuggestSkillInstallationWidget } from './widgets/SuggestSkillInstallationWidget'; import { TestBackendFunctionWidget } from './widgets/TestBackendFunctionWidget'; import { UpdateIdentityWidget } from './widgets/UpdateIdentityWidget'; import { WriteFileWidget } from './widgets/WriteFileWidget'; /** * Built-in tool widgets — the native mirror of the web builder's * TOOL_UI_COMPONENTS map (FunctionDisplay.tsx), scoped to the tools superagent * flows actually expose (create_user_agent_tools in * backend/app/user_apps/app_agents/user_agent/tools.py). ToolCallSummary * consults this registry after the host's `toolRenderers` prop (host renderers * always win), so a host can override or extend any entry without forking the * package. * * Approval-paused calls (waiting_for_user_input) bypass this registry and * keep rendering the timeline's ToolApprovalCard — unless the tool is listed * in `approvalCapableToolNames` below. */ export const defaultToolRenderers: SuperagentToolRenderers = { activate_platform_skill: ActivatePlatformSkillWidget, ask_clarifying_questions: ClarifyingQuestionsWidget, browserbase_screenshot: BrowserbaseScreenshotWidget, build_mode: AgentBlueprintWidget, configure_psp_credentials: ConfigurePspCredentialsWidget, create_automation: CreateAutomationWidget, create_entity_records: CreateEntitiesWidget, create_or_update_workflow: CreateWorkflowWidget, delete_entities: DeleteEntitiesWidget, generate_image: GeneratedImagesWidget, get_backend_function_logs: GetBackendFunctionLogsWidget, get_connectors_info: GetConnectorsInfoWidget, grep: GrepSearchWidget, list_automations: AutomationActionWidget, local_browser_screenshot: BrowserbaseScreenshotWidget, manage_automation: AutomationActionWidget, read_entities: ReadEntitiesWidget, read_file: ReadFileWidget, request_oauth_authorization: ConnectionStatusWidget, select_payment_provider: SelectPaymentProviderWidget, sequence_connect: SetSecretsWidget, set_secrets: SetSecretsWidget, show_channel_connection_options: ShowChannelConnectionOptionsWidget, suggest_payments_installation: ConnectionStatusWidget, suggest_skill_installation: SuggestSkillInstallationWidget, test_backend_function: TestBackendFunctionWidget, update_entities: UpdateEntitiesWidget, update_identity: UpdateIdentityWidget, web_search: SearchWebWidget, write_file: WriteFileWidget, }; /** * Ordered fallbacks for tool families that can't be exact-name-keyed, mirroring * the web FunctionDisplay dispatch: * - artifacts by SHAPE, not name — the alias set overlaps plausible real * backend-function/MCP tool names (e.g. `render_ui`), so isArtifactToolCall's * client_artifact guard decides (exact keys would misroute those); * - MCP tools by the backend's `mcp__` name prefix. * Artifact check first, matching the web (an artifact call never carries the * mcp_ prefix, so today the order is cosmetic). */ const defaultToolRendererResolvers: readonly SuperagentToolRendererResolver[] = [ (toolCall) => (isArtifactToolCall(toolCall) ? ArtifactWidget : undefined), (toolCall) => (isMcpToolName(toolCall.name) ? McpToolWidget : undefined), ]; /** * Full built-in lookup: exact `defaultToolRenderers` entry first, then the * resolver list. The host `toolRenderers` prop stays exact-name-only and is * consulted before this (unchanged public semantics). */ export function resolveDefaultToolRenderer( toolCall: SuperagentToolCall, ): SuperagentToolRenderer | undefined { return resolveFromRegistry(defaultToolRenderers, defaultToolRendererResolvers, toolCall); } /** * Built-in renderers that opt in to approval-paused calls: for these tools the * widget renders its own approval UI (entity/payment approval cards), so it * claims the call even while it is waiting_for_user_input. Every other * built-in still steps aside for the legacy ToolApprovalCard, and host-supplied * `toolRenderers` keep their existing always-win semantics. */ export const approvalCapableToolNames: ReadonlySet = new Set([ // Claims its waiting call to render nothing — the question lives in the composer // slot, so stepping aside would surface a generic card beside it. 'ask_clarifying_questions', 'configure_psp_credentials', 'delete_entities', 'select_payment_provider', 'update_entities', ]); /** * Tools whose *consecutive* calls collapse into one widget: createToolChunks * wraps each run in a synthetic `grouped: true` call before renderer dispatch, * mirroring the web's groupConsecutive preprocessing. The tool's renderer * receives the grouped call and expands it via flattenToolCall (see * GrepSearchWidget, GeneratedImagesWidget). */ export const groupedToolNames: ReadonlySet = new Set([ 'generate_image', 'grep', ]);