AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat(frontend): extract frontend changes from hackathon/copilot branch (#11717)
Swifty4a9b13acb6bc
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/5-run/components/AgentOnboardingCredentials/AgentOnboardingCredentials.tsx b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/5-run/components/AgentOnboardingCredentials/AgentOnboardingCredentials.tsxindex 72e296fd88..f0bb652a06 100644--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/5-run/components/AgentOnboardingCredentials/AgentOnboardingCredentials.tsx+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/5-run/components/AgentOnboardingCredentials/AgentOnboardingCredentials.tsx@@ -1,6 +1,6 @@-import { CredentialsInput } from "@/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/CredentialsInput";import { CredentialsMetaInput } from "@/app/api/__generated__/models/credentialsMetaInput";import { GraphMeta } from "@/app/api/__generated__/models/graphMeta";+import { CredentialsInput } from "@/components/contextual/CredentialsInput/CredentialsInput";import { useState } from "react";import { getSchemaDefaultCredentials } from "../../helpers";import { areAllCredentialsSet, getCredentialFields } from "./helpers";diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/5-run/page.tsx b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/5-run/page.tsxindex 30e1b67090..db04278d80 100644--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/5-run/page.tsx+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/5-run/page.tsx@@ -1,12 +1,12 @@"use client";-import { RunAgentInputs } from "@/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentInputs/RunAgentInputs";import {Card,CardContent,CardHeader,CardTitle,} from "@/components/__legacy__/ui/card";+import { RunAgentInputs } from "@/components/contextual/RunAgentInputs/RunAgentInputs";import { ErrorCard } from "@/components/molecules/ErrorCard/ErrorCard";import { CircleNotchIcon } from "@phosphor-icons/react/dist/ssr";import { Play } from "lucide-react";diff --git a/autogpt_platform/frontend/src/app/(platform)/auth/integrations/setup-wizard/page.tsx b/autogpt_platform/frontend/src/app/(platform)/auth/integrations/setup-wizard/page.tsxindex f7d4935907..9e2e637ef6 100644--- a/autogpt_platform/frontend/src/app/(platform)/auth/integrations/setup-wizard/page.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/auth/integrations/setup-wizard/page.tsx@@ -1,11 +1,11 @@"use client";-import { CredentialsInput } from "@/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/CredentialsInput";import { useGetOauthGetOauthAppInfo } from "@/app/api/__generated__/endpoints/oauth/oauth";import { okData } from "@/app/api/helpers";import { Button } from "@/components/atoms/Button/Button";import { Text } from "@/components/atoms/Text/Text";import { AuthCard } from "@/components/auth/AuthCard";+import { CredentialsInput } from "@/components/contextual/CredentialsInput/CredentialsInput";import { ErrorCard } from "@/components/molecules/ErrorCard/ErrorCard";import type {BlockIOCredentialsSubSchema,diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/AgentOutputs/AgentOutputs.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/AgentOutputs/AgentOutputs.tsxindex 20493b2ca0..cfea5d9452 100644--- a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/AgentOutputs/AgentOutputs.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/AgentOutputs/AgentOutputs.tsx@@ -1,11 +1,6 @@import { BlockUIType } from "@/app/(platform)/build/components/types";import { useGraphStore } from "@/app/(platform)/build/stores/graphStore";import { useNodeStore } from "@/app/(platform)/build/stores/nodeStore";-import {- globalRegistry,- OutputActions,- OutputItem,-} from "@/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/OutputRenderers";import { Label } from "@/components/__legacy__/ui/label";import { ScrollArea } from "@/components/__legacy__/ui/scroll-area";import {@@ -23,6 +18,11 @@ import {TooltipProvider,TooltipTrigger,} from "@/components/atoms/Tooltip/BaseTooltip";+import {+ globalRegistry,+ OutputActions,+ OutputItem,+} from "@/components/contextual/OutputRenderers";import { BookOpenIcon } from "@phosphor-icons/react";import { useMemo } from "react";import { useShallow } from "zustand/react/shallow";diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/NodeOutput/components/ContentRenderer.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/NodeOutput/components/ContentRenderer.tsxindex 9cb1a62e3d..6571bc7b6f 100644--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/NodeOutput/components/ContentRenderer.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/NodeOutput/components/ContentRenderer.tsx@@ -1,7 +1,7 @@"use client";-import type { OutputMetadata } from "@/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/OutputRenderers";-import { globalRegistry } from "@/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/OutputRenderers";+import type { OutputMetadata } from "@/components/contextual/OutputRenderers";+import { globalRegistry } from "@/components/contextual/OutputRenderers";export const TextRenderer: React.FC<{value: any;diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/NodeOutput/components/NodeDataViewer/NodeDataViewer.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/NodeOutput/components/NodeDataViewer/NodeDataViewer.tsxindex 31b89315d6..0858db8f0e 100644--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/NodeOutput/components/NodeDataViewer/NodeDataViewer.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/NodeOutput/components/NodeDataViewer/NodeDataViewer.tsx@@ -1,7 +1,3 @@-import {- OutputActions,- OutputItem,-} from "@/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/OutputRenderers";import { ScrollArea } from "@/components/__legacy__/ui/scroll-area";import { Button } from "@/components/atoms/Button/Button";import { Text } from "@/components/atoms/Text/Text";@@ -11,6 +7,10 @@ import {TooltipProvider,TooltipTrigger,} from "@/components/atoms/Tooltip/BaseTooltip";+import {+ OutputActions,+ OutputItem,+} from "@/components/contextual/OutputRenderers";import { Dialog } from "@/components/molecules/Dialog/Dialog";import { beautifyString } from "@/lib/utils";import {diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/NodeOutput/components/NodeDataViewer/useNodeDataViewer.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/NodeOutput/components/NodeDataViewer/useNodeDataViewer.tsindex 1adec625a0..d3c555970c 100644--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/NodeOutput/components/NodeDataViewer/useNodeDataViewer.ts+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/NodeOutput/components/NodeDataViewer/useNodeDataViewer.ts@@ -1,6 +1,6 @@-import type { OutputMetadata } from "@/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/OutputRenderers";-import { globalRegistry } from "@/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/OutputRenderers";-import { downloadOutputs } from "@/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/OutputRenderers/utils/download";+import type { OutputMetadata } from "@/components/contextual/OutputRenderers";+import { globalRegistry } from "@/components/contextual/OutputRenderers";+import { downloadOutputs } from "@/components/contextual/OutputRenderers/utils/download";import { useToast } from "@/components/molecules/Toast/use-toast";import { beautifyString } from "@/lib/utils";import React, { useMemo, useState } from "react";diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/WebhookDisclaimer.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/WebhookDisclaimer.tsxindex 044bf994ad..1fdee05a2a 100644--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/WebhookDisclaimer.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/WebhookDisclaimer.tsx@@ -1,10 +1,10 @@-import { Alert, AlertDescription } from "@/components/molecules/Alert/Alert";-import { Text } from "@/components/atoms/Text/Text";-import Link from "next/link";import { useGetV2GetLibraryAgentByGraphId } from "@/app/api/__generated__/endpoints/library/library";import { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";-import { useQueryStates, parseAsString } from "nuqs";-import { isValidUUID } from "@/app/(platform)/chat/helpers";+import { Text } from "@/components/atoms/Text/Text";+import { Alert, AlertDescription } from "@/components/molecules/Alert/Alert";+import { isValidUUID } from "@/lib/utils";+import Link from "next/link";+import { parseAsString, useQueryStates } from "nuqs";export const WebhookDisclaimer = ({ nodeId }: { nodeId: string }) => {const [{ flowID }] = useQueryStates({diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/legacy-builder/ExpandableOutputDialog.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/legacy-builder/ExpandableOutputDialog.tsxindex 98edbca2fb..1ccb3d1261 100644--- a/autogpt_platform/frontend/src/app/(platform)/build/components/legacy-builder/ExpandableOutputDialog.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/legacy-builder/ExpandableOutputDialog.tsx@@ -1,9 +1,9 @@-import type { OutputMetadata } from "@/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/OutputRenderers";+import type { OutputMetadata } from "@/components/contextual/OutputRenderers";import {globalRegistry,OutputActions,OutputItem,-} from "@/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/OutputRenderers";+} from "@/components/contextual/OutputRenderers";import { Dialog } from "@/components/molecules/Dialog/Dialog";import { beautifyString } from "@/lib/utils";import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/legacy-builder/NodeInputs.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/legacy-builder/NodeInputs.tsxindex 36df180c8c..51fed5bef1 100644--- a/autogpt_platform/frontend/src/app/(platform)/build/components/legacy-builder/NodeInputs.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/legacy-builder/NodeInputs.tsx@@ -3,7 +3,6 @@ import {CustomNodeData,} from "@/app/(platform)/build/components/legacy-builder/CustomNode/CustomNode";import { NodeTableInput } from "@/app/(platform)/build/components/legacy-builder/NodeTableInput";-import { CredentialsInput } from "@/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/CredentialsInput";import { Button } from "@/components/__legacy__/ui/button";import { Calendar } from "@/components/__legacy__/ui/calendar";import { LocalValuedInput } from "@/components/__legacy__/ui/input";@@ -28,6 +27,7 @@ import {SelectValue,} from "@/components/__legacy__/ui/select";import { Switch } from "@/components/atoms/Switch/Switch";+import { CredentialsInput } from "@/components/contextual/CredentialsInput/CredentialsInput";import { GoogleDrivePickerInput } from "@/components/contextual/GoogleDrivePicker/GoogleDrivePickerInput";import {BlockIOArraySubSchema,diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/Chat.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/Chat.tsxnew file mode 100644index 0000000000..461c885dc3--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/Chat.tsx@@ -0,0 +1,134 @@+"use client";++import { Button } from "@/components/atoms/Button/Button";+import { Text } from "@/components/atoms/Text/Text";+import { cn } from "@/lib/utils";+import { List } from "@phosphor-icons/react";+import React, { useState } from "react";+import { ChatContainer } from "./components/ChatContainer/ChatContainer";+import { ChatErrorState } from "./components/ChatErrorState/ChatErrorState";+import { ChatLoadingState } from "./components/ChatLoadingState/ChatLoadingState";+import { SessionsDrawer } from "./components/SessionsDrawer/SessionsDrawer";+import { useChat } from "./useChat";++export interface ChatProps {+ className?: string;+ headerTitle?: React.ReactNode;+ showHeader?: boolean;+ showSessionInfo?: boolean;+ showNewChatButton?: boolean;+ onNewChat?: () => void;+ headerActions?: React.ReactNode;+}++export function Chat({+ className,+ headerTitle = "AutoGPT Copilot",+ showHeader = true,+ showSessionInfo = true,+ showNewChatButton = true,+ onNewChat,+ headerActions,+}: ChatProps) {+ const {+ messages,+ isLoading,+ isCreating,+ error,+ sessionId,+ createSession,+ clearSession,+ loadSession,+ } = useChat();++ const [isSessionsDrawerOpen, setIsSessionsDrawerOpen] = useState(false);++ const handleNewChat = () => {+ clearSession();+ onNewChat?.();+ };++ const handleSelectSession = async (sessionId: string) => {+ try {+ await loadSession(sessionId);+ } catch (err) {+ console.error("Failed to load session:", err);+ }+ };++ return (+ <div className={cn("flex h-full flex-col", className)}>+ {/* Header */}+ {showHeader && (+ <header className="shrink-0 border-t border-zinc-200 bg-white p-3">+ <div className="flex items-center justify-between">+ <div className="flex items-center gap-3">+ <button+ aria-label="View sessions"+ onClick={() => setIsSessionsDrawerOpen(true)}+ className="flex size-8 items-center justify-center rounded hover:bg-zinc-100"+ >+ <List width="1.25rem" height="1.25rem" />+ </button>+ {typeof headerTitle === "string" ? (+ <Text variant="h2" className="text-lg font-semibold">+ {headerTitle}+ </Text>+ ) : (+ headerTitle+ )}+ </div>+ <div className="flex items-center gap-3">+ {showSessionInfo && sessionId && (+ <>+ {showNewChatButton && (+ <Button+ variant="outline"+ size="small"+ onClick={handleNewChat}+ >+ New Chat+ </Button>+ )}+ </>+ )}+ {headerActions}+ </div>+ </div>+ </header>+ )}++ {/* Main Content */}+ <main className="flex min-h-0 flex-1 flex-col overflow-hidden">+ {/* Loading State - show when explicitly loading/creating OR when we don't have a session yet and no error */}+ {(isLoading || isCreating || (!sessionId && !error)) && (+ <ChatLoadingState+ message={isCreating ? "Creating session..." : "Loading..."}+ />+ )}++ {/* Error State */}+ {error && !isLoading && (+ <ChatErrorState error={error} onRetry={createSession} />+ )}++ {/* Session Content */}+ {sessionId && !isLoading && !error && (+ <ChatContainer+ sessionId={sessionId}+ initialMessages={messages}+ className="flex-1"+ />+ )}+ </main>++ {/* Sessions Drawer */}+ <SessionsDrawer+ isOpen={isSessionsDrawerOpen}+ onClose={() => setIsSessionsDrawerOpen(false)}+ onSelectSession={handleSelectSession}+ currentSessionId={sessionId}+ />+ </div>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/AgentCarouselMessage/AgentCarouselMessage.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/AgentCarouselMessage/AgentCarouselMessage.tsxsimilarity index 65%rename from autogpt_platform/frontend/src/app/(platform)/chat/components/AgentCarouselMessage/AgentCarouselMessage.tsxrename to autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/AgentCarouselMessage/AgentCarouselMessage.tsxindex 125f834e05..582b24de5e 100644--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/AgentCarouselMessage/AgentCarouselMessage.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/AgentCarouselMessage/AgentCarouselMessage.tsx@@ -1,15 +1,16 @@-import React from "react";-import { Text } from "@/components/atoms/Text/Text";import { Button } from "@/components/atoms/Button/Button";import { Card } from "@/components/atoms/Card/Card";-import { List, Robot, ArrowRight } from "@phosphor-icons/react";+import { Text } from "@/components/atoms/Text/Text";import { cn } from "@/lib/utils";+import { ArrowRight, List, Robot } from "@phosphor-icons/react";+import Image from "next/image";export interface Agent {id: string;name: string;description: string;version?: number;+ image_url?: string;}export interface AgentCarouselMessageProps {@@ -30,7 +31,7 @@ export function AgentCarouselMessage({return (<divclassName={cn(- "mx-4 my-2 flex flex-col gap-4 rounded-lg border border-purple-200 bg-purple-50 p-6 dark:border-purple-900 dark:bg-purple-950",+ "mx-4 my-2 flex flex-col gap-4 rounded-lg border border-purple-200 bg-purple-50 p-6",className,)}>@@ -40,13 +41,10 @@ export function AgentCarouselMessage({<List size={24} weight="bold" className="text-white" /></div><div>- <Text variant="h3" className="text-purple-900 dark:text-purple-100">+ <Text variant="h3" className="text-purple-900">Found {displayCount} {displayCount === 1 ? "Agent" : "Agents"}</Text>- <Text- variant="small"- className="text-purple-700 dark:text-purple-300"- >+ <Text variant="small" className="text-purple-700">Select an agent to view details or run it</Text></div>@@ -57,40 +55,49 @@ export function AgentCarouselMessage({{agents.map((agent) => (<Cardkey={agent.id}- className="border border-purple-200 bg-white p-4 dark:border-purple-800 dark:bg-purple-900"+ className="border border-purple-200 bg-white p-4"><div className="flex gap-3">- <div className="flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-lg bg-purple-100 dark:bg-purple-800">- <Robot size={20} weight="bold" className="text-purple-600" />+ <div className="relative h-10 w-10 flex-shrink-0 overflow-hidden rounded-lg bg-purple-100">+ {agent.image_url ? (+ <Image+ src={agent.image_url}+ alt={`${agent.name} preview image`}+ fill+ className="object-cover"+ />+ ) : (+ <div className="flex h-full w-full items-center justify-center">+ <Robot+ size={20}+ weight="bold"+ className="text-purple-600"+ />+ </div>+ )}</div><div className="flex-1 space-y-2"><div><Textvariant="body"- className="font-semibold text-purple-900 dark:text-purple-100"+ className="font-semibold text-purple-900">{agent.name}</Text>{agent.version && (- <Text- variant="small"- className="text-purple-600 dark:text-purple-400"- >+ <Text variant="small" className="text-purple-600">v{agent.version}</Text>)}</div>- <Text- variant="small"- className="line-clamp-2 text-purple-700 dark:text-purple-300"- >+ <Text variant="small" className="line-clamp-2 text-purple-700">{agent.description}</Text>{onSelectAgent && (<ButtononClick={() => onSelectAgent(agent.id)}variant="ghost"- className="mt-2 flex items-center gap-1 p-0 text-sm text-purple-600 hover:text-purple-800 dark:text-purple-400 dark:hover:text-purple-200"+ className="mt-2 flex items-center gap-1 p-0 text-sm text-purple-600 hover:text-purple-800">View details<ArrowRight size={16} weight="bold" />@@ -103,10 +110,7 @@ export function AgentCarouselMessage({</div>{totalCount && totalCount > agents.length && (- <Text- variant="small"- className="text-center text-purple-600 dark:text-purple-400"- >+ <Text variant="small" className="text-center text-purple-600">Showing {agents.length} of {totalCount} results</Text>)}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/AgentInputsSetup/AgentInputsSetup.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/AgentInputsSetup/AgentInputsSetup.tsxnew file mode 100644index 0000000000..3ef71eca09--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/AgentInputsSetup/AgentInputsSetup.tsx@@ -0,0 +1,246 @@+"use client";++import { Button } from "@/components/atoms/Button/Button";+import { Card } from "@/components/atoms/Card/Card";+import { Text } from "@/components/atoms/Text/Text";+import { CredentialsInput } from "@/components/contextual/CredentialsInput/CredentialsInput";+import { RunAgentInputs } from "@/components/contextual/RunAgentInputs/RunAgentInputs";++import type { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";+import {+ BlockIOCredentialsSubSchema,+ BlockIOSubSchema,+} from "@/lib/autogpt-server-api/types";+import { cn, isEmpty } from "@/lib/utils";+import { PlayIcon, WarningIcon } from "@phosphor-icons/react";+import { useMemo } from "react";+import { useAgentInputsSetup } from "./useAgentInputsSetup";++type LibraryAgentInputSchemaProperties = LibraryAgent["input_schema"] extends {+ properties: infer P;+}+ ? P extends Record<string, BlockIOSubSchema>+ ? P+ : Record<string, BlockIOSubSchema>+ : Record<string, BlockIOSubSchema>;++type LibraryAgentCredentialsInputSchemaProperties =+ LibraryAgent["credentials_input_schema"] extends {+ properties: infer P;+ }+ ? P extends Record<string, BlockIOCredentialsSubSchema>+ ? P+ : Record<string, BlockIOCredentialsSubSchema>+ : Record<string, BlockIOCredentialsSubSchema>;++interface Props {+ agentName?: string;+ inputSchema: LibraryAgentInputSchemaProperties | Record<string, any>;+ credentialsSchema?:+ | LibraryAgentCredentialsInputSchemaProperties+ | Record<string, any>;+ message: string;+ requiredFields?: string[];+ onRun: (+ inputs: Record<string, any>,+ credentials: Record<string, any>,+ ) => void;+ onCancel?: () => void;+ className?: string;+}++export function AgentInputsSetup({+ agentName,+ inputSchema,+ credentialsSchema,+ message,+ requiredFields,+ onRun,+ onCancel,+ className,+}: Props) {+ const { inputValues, setInputValue, credentialsValues, setCredentialsValue } =+ useAgentInputsSetup();++ const inputSchemaObj = useMemo(() => {+ if (!inputSchema) return { properties: {}, required: [] };+ if ("properties" in inputSchema && "type" in inputSchema) {+ return inputSchema as {+ properties: Record<string, any>;+ required?: string[];+ };+ }+ return { properties: inputSchema as Record<string, any>, required: [] };+ }, [inputSchema]);++ const credentialsSchemaObj = useMemo(() => {+ if (!credentialsSchema) return { properties: {}, required: [] };+ if ("properties" in credentialsSchema && "type" in credentialsSchema) {+ return credentialsSchema as {+ properties: Record<string, any>;+ required?: string[];+ };+ }+ return {+ properties: credentialsSchema as Record<string, any>,+ required: [],+ };+ }, [credentialsSchema]);++ const agentInputFields = useMemo(() => {+ const properties = inputSchemaObj.properties || {};+ return Object.fromEntries(+ Object.entries(properties).filter(+ ([_, subSchema]: [string, any]) => !subSchema.hidden,+ ),+ );+ }, [inputSchemaObj]);++ const agentCredentialsInputFields = useMemo(() => {+ return credentialsSchemaObj.properties || {};+ }, [credentialsSchemaObj]);++ const inputFields = Object.entries(agentInputFields);+ const credentialFields = Object.entries(agentCredentialsInputFields);++ const defaultsFromSchema = useMemo(() => {+ const defaults: Record<string, any> = {};+ Object.entries(agentInputFields).forEach(([key, schema]) => {+ if ("default" in schema && schema.default !== undefined) {+ defaults[key] = schema.default;+ }+ });+ return defaults;+ }, [agentInputFields]);++ const defaultsFromCredentialsSchema = useMemo(() => {+ const defaults: Record<string, any> = {};+ Object.entries(agentCredentialsInputFields).forEach(([key, schema]) => {+ if ("default" in schema && schema.default !== undefined) {+ defaults[key] = schema.default;+ }+ });+ return defaults;+ }, [agentCredentialsInputFields]);++ const mergedInputValues = useMemo(() => {+ return { ...defaultsFromSchema, ...inputValues };+ }, [defaultsFromSchema, inputValues]);++ const mergedCredentialsValues = useMemo(() => {+ return { ...defaultsFromCredentialsSchema, ...credentialsValues };+ }, [defaultsFromCredentialsSchema, credentialsValues]);++ const allRequiredInputsAreSet = useMemo(() => {+ const requiredInputs = new Set(+ requiredFields || (inputSchemaObj.required as string[]) || [],+ );+ const nonEmptyInputs = new Set(+ Object.keys(mergedInputValues).filter(+ (k) => !isEmpty(mergedInputValues[k]),+ ),+ );+ const missing = [...requiredInputs].filter(+ (input) => !nonEmptyInputs.has(input),+ );+ return missing.length === 0;+ }, [inputSchemaObj.required, mergedInputValues, requiredFields]);++ const allCredentialsAreSet = useMemo(() => {+ const requiredCredentials = new Set(+ (credentialsSchemaObj.required as string[]) || [],+ );+ if (requiredCredentials.size === 0) {+ return true;+ }+ const missing = [...requiredCredentials].filter((key) => {+ const cred = mergedCredentialsValues[key];+ return !cred || !cred.id;+ });+ return missing.length === 0;+ }, [credentialsSchemaObj.required, mergedCredentialsValues]);++ const canRun = allRequiredInputsAreSet && allCredentialsAreSet;++ function handleRun() {+ if (canRun) {+ onRun(mergedInputValues, mergedCredentialsValues);+ }+ }++ return (+ <Card+ className={cn(+ "mx-4 my-2 overflow-hidden border-blue-200 bg-blue-50",+ className,+ )}+ >+ <div className="flex items-start gap-4 p-6">+ <div className="flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-full bg-blue-500">+ <WarningIcon size={24} weight="bold" className="text-white" />+ </div>+ <div className="flex-1">+ <Text variant="h3" className="mb-2 text-blue-900">+ {agentName ? `Configure ${agentName}` : "Agent Configuration"}+ </Text>+ <Text variant="body" className="mb-4 text-blue-700">+ {message}+ </Text>++ {inputFields.length > 0 && (+ <div className="mb-4 space-y-4">+ {inputFields.map(([key, inputSubSchema]) => (+ <RunAgentInputs+ key={key}+ schema={inputSubSchema}+ value={inputValues[key] ?? inputSubSchema.default}+ placeholder={inputSubSchema.description}+ onChange={(value) => setInputValue(key, value)}+ />+ ))}+ </div>+ )}++ {credentialFields.length > 0 && (+ <div className="mb-4 space-y-4">+ {credentialFields.map(([key, schema]) => {+ const requiredCredentials = new Set(+ (credentialsSchemaObj.required as string[]) || [],+ );+ return (+ <CredentialsInput+ key={key}+ schema={schema}+ selectedCredentials={credentialsValues[key]}+ onSelectCredentials={(value) =>+ setCredentialsValue(key, value)+ }+ siblingInputs={mergedInputValues}+ isOptional={!requiredCredentials.has(key)}+ />+ );+ })}+ </div>+ )}++ <div className="flex gap-2">+ <Button+ variant="primary"+ size="small"+ onClick={handleRun}+ disabled={!canRun}+ >+ <PlayIcon className="mr-2 h-4 w-4" weight="bold" />+ Run Agent+ </Button>+ {onCancel && (+ <Button variant="outline" size="small" onClick={onCancel}>+ Cancel+ </Button>+ )}+ </div>+ </div>+ </div>+ </Card>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/AgentInputsSetup/useAgentInputsSetup.ts b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/AgentInputsSetup/useAgentInputsSetup.tsnew file mode 100644index 0000000000..e36a3f3c5d--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/AgentInputsSetup/useAgentInputsSetup.ts@@ -0,0 +1,38 @@+import type { CredentialsMetaInput } from "@/lib/autogpt-server-api/types";+import { useState } from "react";++export function useAgentInputsSetup() {+ const [inputValues, setInputValues] = useState<Record<string, any>>({});+ const [credentialsValues, setCredentialsValues] = useState<+ Record<string, CredentialsMetaInput>+ >({});++ function setInputValue(key: string, value: any) {+ setInputValues((prev) => ({+ ...prev,+ [key]: value,+ }));+ }++ function setCredentialsValue(key: string, value?: CredentialsMetaInput) {+ if (value) {+ setCredentialsValues((prev) => ({+ ...prev,+ [key]: value,+ }));+ } else {+ setCredentialsValues((prev) => {+ const next = { ...prev };+ delete next[key];+ return next;+ });+ }+ }++ return {+ inputValues,+ setInputValue,+ credentialsValues,+ setCredentialsValue,+ };+}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/AuthPromptWidget/AuthPromptWidget.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/AuthPromptWidget/AuthPromptWidget.tsxsimilarity index 84%rename from autogpt_platform/frontend/src/app/(platform)/chat/components/AuthPromptWidget/AuthPromptWidget.tsxrename to autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/AuthPromptWidget/AuthPromptWidget.tsxindex 885a06e92a..33f02e660f 100644--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/AuthPromptWidget/AuthPromptWidget.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/AuthPromptWidget/AuthPromptWidget.tsx@@ -1,10 +1,9 @@"use client";-import React from "react";-import { useRouter } from "next/navigation";import { Button } from "@/components/atoms/Button/Button";-import { SignInIcon, UserPlusIcon, ShieldIcon } from "@phosphor-icons/react";import { cn } from "@/lib/utils";+import { ShieldIcon, SignInIcon, UserPlusIcon } from "@phosphor-icons/react";+import { useRouter } from "next/navigation";export interface AuthPromptWidgetProps {message: string;@@ -54,8 +53,8 @@ export function AuthPromptWidget({return (<divclassName={cn(- "my-4 overflow-hidden rounded-lg border border-violet-200 dark:border-violet-800",- "bg-gradient-to-br from-violet-50 to-purple-50 dark:from-violet-950/30 dark:to-purple-950/30",+ "my-4 overflow-hidden rounded-lg border border-violet-200",+ "bg-gradient-to-br from-violet-50 to-purple-50","duration-500 animate-in fade-in-50 slide-in-from-bottom-2",className,)}@@ -66,21 +65,19 @@ export function AuthPromptWidget({<ShieldIcon size={20} weight="fill" className="text-white" /></div><div>- <h3 className="text-lg font-semibold text-neutral-900 dark:text-neutral-100">+ <h3 className="text-lg font-semibold text-neutral-900">Authentication Required</h3>- <p className="text-sm text-neutral-600 dark:text-neutral-400">+ <p className="text-sm text-neutral-600">Sign in to set up and manage agents</p></div></div>- <div className="mb-5 rounded-md bg-white/50 p-4 dark:bg-neutral-900/50">- <p className="text-sm text-neutral-700 dark:text-neutral-300">- {message}- </p>+ <div className="mb-5 rounded-md bg-white/50 p-4">+ <p className="text-sm text-neutral-700">{message}</p>{agentInfo && (- <div className="mt-3 text-xs text-neutral-600 dark:text-neutral-400">+ <div className="mt-3 text-xs text-neutral-600"><p>Ready to set up:{" "}<span className="font-medium">{agentInfo.name}</span>@@ -114,7 +111,7 @@ export function AuthPromptWidget({</Button></div>- <div className="mt-4 text-center text-xs text-neutral-500 dark:text-neutral-500">+ <div className="mt-4 text-center text-xs text-neutral-500">Your chat session will be preserved after signing in</div></div>diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatContainer/ChatContainer.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatContainer/ChatContainer.tsxnew file mode 100644index 0000000000..6f7a0e8f51--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatContainer/ChatContainer.tsx@@ -0,0 +1,88 @@+import type { SessionDetailResponse } from "@/app/api/__generated__/models/sessionDetailResponse";+import { cn } from "@/lib/utils";+import { useCallback } from "react";+import { usePageContext } from "../../usePageContext";+import { ChatInput } from "../ChatInput/ChatInput";+import { MessageList } from "../MessageList/MessageList";+import { QuickActionsWelcome } from "../QuickActionsWelcome/QuickActionsWelcome";+import { useChatContainer } from "./useChatContainer";++export interface ChatContainerProps {+ sessionId: string | null;+ initialMessages: SessionDetailResponse["messages"];+ className?: string;+}++export function ChatContainer({+ sessionId,+ initialMessages,+ className,+}: ChatContainerProps) {+ const { messages, streamingChunks, isStreaming, sendMessage } =+ useChatContainer({+ sessionId,+ initialMessages,+ });+ const { capturePageContext } = usePageContext();++ // Wrap sendMessage to automatically capture page context+ const sendMessageWithContext = useCallback(+ async (content: string, isUserMessage: boolean = true) => {+ const context = capturePageContext();+ await sendMessage(content, isUserMessage, context);+ },+ [sendMessage, capturePageContext],+ );++ const quickActions = [+ "Find agents for social media management",+ "Show me agents for content creation",+ "Help me automate my business",+ "What can you help me with?",+ ];++ return (+ <div+ className={cn("flex h-full min-h-0 flex-col", className)}+ style={{+ backgroundColor: "#ffffff",+ backgroundImage:+ "radial-gradient(#e5e5e5 0.5px, transparent 0.5px), radial-gradient(#e5e5e5 0.5px, #ffffff 0.5px)",+ backgroundSize: "20px 20px",+ backgroundPosition: "0 0, 10px 10px",+ }}+ >+ {/* Messages or Welcome Screen */}+ <div className="flex min-h-0 flex-1 flex-col overflow-hidden pb-24">+ {messages.length === 0 ? (+ <QuickActionsWelcome+ title="Welcome to AutoGPT Copilot"+ description="Start a conversation to discover and run AI agents."+ actions={quickActions}+ onActionClick={sendMessageWithContext}+ disabled={isStreaming || !sessionId}+ />+ ) : (+ <MessageList+ messages={messages}+ streamingChunks={streamingChunks}+ isStreaming={isStreaming}+ onSendMessage={sendMessageWithContext}+ className="flex-1"+ />+ )}+ </div>++ {/* Input - Always visible */}+ <div className="fixed bottom-0 left-0 right-0 z-50 border-t border-zinc-200 bg-white p-4">+ <ChatInput+ onSend={sendMessageWithContext}+ disabled={isStreaming || !sessionId}+ placeholder={+ sessionId ? "Type your message..." : "Creating session..."+ }+ />+ </div>+ </div>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatContainer/createStreamEventDispatcher.ts b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatContainer/createStreamEventDispatcher.tssimilarity index 95%rename from autogpt_platform/frontend/src/app/(platform)/chat/components/ChatContainer/createStreamEventDispatcher.tsrename to autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatContainer/createStreamEventDispatcher.tsindex b8421c3386..844f126d49 100644--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatContainer/createStreamEventDispatcher.ts+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatContainer/createStreamEventDispatcher.ts@@ -1,14 +1,14 @@import { toast } from "sonner";-import type { StreamChunk } from "@/app/(platform)/chat/useChatStream";+import { StreamChunk } from "../../useChatStream";import type { HandlerDependencies } from "./useChatContainer.handlers";import {+ handleError,+ handleLoginNeeded,+ handleStreamEnd,handleTextChunk,handleTextEnded,handleToolCallStart,handleToolResponse,- handleLoginNeeded,- handleStreamEnd,- handleError,} from "./useChatContainer.handlers";export function createStreamEventDispatcher(diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatContainer/helpers.ts b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatContainer/helpers.tssimilarity index 68%rename from autogpt_platform/frontend/src/app/(platform)/chat/components/ChatContainer/helpers.tsrename to autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatContainer/helpers.tsindex 3a94dab1ea..cd05563369 100644--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatContainer/helpers.ts+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatContainer/helpers.ts@@ -1,5 +1,24 @@-import type { ChatMessageData } from "@/app/(platform)/chat/components/ChatMessage/useChatMessage";import type { ToolResult } from "@/types/chat";+import type { ChatMessageData } from "../ChatMessage/useChatMessage";++export function removePageContext(content: string): string {+ // Remove "Page URL: ..." pattern at start of line (case insensitive, handles various formats)+ let cleaned = content.replace(/^\s*Page URL:\s*[^\n\r]*/gim, "");++ // Find "User Message:" marker at start of line to preserve the actual user message+ const userMessageMatch = cleaned.match(/^\s*User Message:\s*([\s\S]*)$/im);+ if (userMessageMatch) {+ // If we found "User Message:", extract everything after it+ cleaned = userMessageMatch[1];+ } else {+ // If no "User Message:" marker, remove "Page Content:" and everything after it at start of line+ cleaned = cleaned.replace(/^\s*Page Content:[\s\S]*$/gim, "");+ }++ // Clean up extra whitespace and newlines+ cleaned = cleaned.replace(/\n\s*\n\s*\n+/g, "\n\n").trim();+ return cleaned;+}export function createUserMessage(content: string): ChatMessageData {return {@@ -63,6 +82,7 @@ export function isAgentArray(value: unknown): value is Array<{name: string;description: string;version?: number;+ image_url?: string;}> {if (!Array.isArray(value)) {return false;@@ -77,7 +97,8 @@ export function isAgentArray(value: unknown): value is Array<{typeof item.name === "string" &&"description" in item &&typeof item.description === "string" &&- (!("version" in item) || typeof item.version === "number"),+ (!("version" in item) || typeof item.version === "number") &&+ (!("image_url" in item) || typeof item.image_url === "string"),);}@@ -232,6 +253,7 @@ export function isSetupInfo(value: unknown): value is {export function extractCredentialsNeeded(parsedResult: Record<string, unknown>,+ toolName: string = "run_agent",): ChatMessageData | null {try {const setupInfo = parsedResult?.setup_info as@@ -244,7 +266,7 @@ export function extractCredentialsNeeded(| Record<string, Record<string, unknown>>| undefined;if (missingCreds && Object.keys(missingCreds).length > 0) {- const agentName = (setupInfo?.agent_name as string) || "this agent";+ const agentName = (setupInfo?.agent_name as string) || "this block";const credentials = Object.values(missingCreds).map((credInfo) => ({provider: (credInfo.provider as string) || "unknown",providerName:@@ -264,7 +286,7 @@ export function extractCredentialsNeeded(}));return {type: "credentials_needed",- toolName: "run_agent",+ toolName,credentials,message: `To run ${agentName}, you need to add ${credentials.length === 1 ? "credentials" : `${credentials.length} credentials`}.`,agentName,@@ -277,3 +299,92 @@ export function extractCredentialsNeeded(return null;}}++export function extractInputsNeeded(+ parsedResult: Record<string, unknown>,+ toolName: string = "run_agent",+): ChatMessageData | null {+ try {+ const setupInfo = parsedResult?.setup_info as+ | Record<string, unknown>+ | undefined;+ const requirements = setupInfo?.requirements as+ | Record<string, unknown>+ | undefined;+ const inputs = requirements?.inputs as+ | Array<Record<string, unknown>>+ | undefined;+ const credentials = requirements?.credentials as+ | Array<Record<string, unknown>>+ | undefined;++ if (!inputs || inputs.length === 0) {+ return null;+ }++ const agentName = (setupInfo?.agent_name as string) || "this agent";+ const agentId = parsedResult?.graph_id as string | undefined;+ const graphVersion = parsedResult?.graph_version as number | undefined;++ const properties: Record<string, any> = {};+ const requiredProps: string[] = [];+ inputs.forEach((input) => {+ const name = input.name as string;+ if (name) {+ properties[name] = {+ title: input.name as string,+ description: (input.description as string) || "",+ type: (input.type as string) || "string",+ default: input.default,+ enum: input.options,+ format: input.format,+ };+ if ((input.required as boolean) === true) {+ requiredProps.push(name);+ }+ }+ });++ const inputSchema: Record<string, any> = {+ type: "object",+ properties,+ };+ if (requiredProps.length > 0) {+ inputSchema.required = requiredProps;+ }++ const credentialsSchema: Record<string, any> = {};+ if (credentials && credentials.length > 0) {+ credentials.forEach((cred) => {+ const id = cred.id as string;+ if (id) {+ credentialsSchema[id] = {+ type: "object",+ properties: {},+ credentials_provider: [cred.provider as string],+ credentials_types: [(cred.type as string) || "api_key"],+ credentials_scopes: cred.scopes as string[] | undefined,+ };+ }+ });+ }++ return {+ type: "inputs_needed",+ toolName,+ agentName,+ agentId,+ graphVersion,+ inputSchema,+ credentialsSchema:+ Object.keys(credentialsSchema).length > 0+ ? credentialsSchema+ : undefined,+ message: `Please provide the required inputs to run ${agentName}.`,+ timestamp: new Date(),+ };+ } catch (err) {+ console.error("Failed to extract inputs from setup info:", err);+ return null;+ }+}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatContainer/useChatContainer.handlers.ts b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatContainer/useChatContainer.handlers.tssimilarity index 85%rename from autogpt_platform/frontend/src/app/(platform)/chat/components/ChatContainer/useChatContainer.handlers.tsrename to autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatContainer/useChatContainer.handlers.tsindex fdbecb5d61..064b847064 100644--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatContainer/useChatContainer.handlers.ts+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatContainer/useChatContainer.handlers.ts@@ -1,13 +1,18 @@-import type { Dispatch, SetStateAction, MutableRefObject } from "react";-import type { StreamChunk } from "@/app/(platform)/chat/useChatStream";-import type { ChatMessageData } from "@/app/(platform)/chat/components/ChatMessage/useChatMessage";-import { parseToolResponse, extractCredentialsNeeded } from "./helpers";+import type { Dispatch, MutableRefObject, SetStateAction } from "react";+import { StreamChunk } from "../../useChatStream";+import type { ChatMessageData } from "../ChatMessage/useChatMessage";+import {+ extractCredentialsNeeded,+ extractInputsNeeded,+ parseToolResponse,+} from "./helpers";export interface HandlerDependencies {setHasTextChunks: Dispatch<SetStateAction<boolean>>;setStreamingChunks: Dispatch<SetStateAction<string[]>>;streamingChunksRef: MutableRefObject<string[]>;setMessages: Dispatch<SetStateAction<ChatMessageData[]>>;+ setIsStreamingInitiated: Dispatch<SetStateAction<boolean>>;sessionId: string;}@@ -100,11 +105,18 @@ export function handleToolResponse(parsedResult = null;}if (- chunk.tool_name === "run_agent" &&+ (chunk.tool_name === "run_agent" || chunk.tool_name === "run_block") &&chunk.success &&parsedResult?.type === "setup_requirements") {- const credentialsMessage = extractCredentialsNeeded(parsedResult);+ const inputsMessage = extractInputsNeeded(parsedResult, chunk.tool_name);+ if (inputsMessage) {+ deps.setMessages((prev) => [...prev, inputsMessage]);+ }+ const credentialsMessage = extractCredentialsNeeded(+ parsedResult,+ chunk.tool_name,+ );if (credentialsMessage) {deps.setMessages((prev) => [...prev, credentialsMessage]);}@@ -197,10 +209,15 @@ export function handleStreamEnd(deps.setStreamingChunks([]);deps.streamingChunksRef.current = [];deps.setHasTextChunks(false);+ deps.setIsStreamingInitiated(false);console.log("[Stream End] Stream complete, messages in local state");}-export function handleError(chunk: StreamChunk, _deps: HandlerDependencies) {+export function handleError(chunk: StreamChunk, deps: HandlerDependencies) {const errorMessage = chunk.message || chunk.content || "An error occurred";console.error("Stream error:", errorMessage);+ deps.setIsStreamingInitiated(false);+ deps.setHasTextChunks(false);+ deps.setStreamingChunks([]);+ deps.streamingChunksRef.current = [];}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatContainer/useChatContainer.ts b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatContainer/useChatContainer.tsnew file mode 100644index 0000000000..8e7dee7718--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatContainer/useChatContainer.ts@@ -0,0 +1,206 @@+import type { SessionDetailResponse } from "@/app/api/__generated__/models/sessionDetailResponse";+import { useCallback, useMemo, useRef, useState } from "react";+import { toast } from "sonner";+import { useChatStream } from "../../useChatStream";+import type { ChatMessageData } from "../ChatMessage/useChatMessage";+import { createStreamEventDispatcher } from "./createStreamEventDispatcher";+import {+ createUserMessage,+ filterAuthMessages,+ isToolCallArray,+ isValidMessage,+ parseToolResponse,+ removePageContext,+} from "./helpers";++interface Args {+ sessionId: string | null;+ initialMessages: SessionDetailResponse["messages"];+}++export function useChatContainer({ sessionId, initialMessages }: Args) {+ const [messages, setMessages] = useState<ChatMessageData[]>([]);+ const [streamingChunks, setStreamingChunks] = useState<string[]>([]);+ const [hasTextChunks, setHasTextChunks] = useState(false);+ const [isStreamingInitiated, setIsStreamingInitiated] = useState(false);+ const streamingChunksRef = useRef<string[]>([]);+ const { error, sendMessage: sendStreamMessage } = useChatStream();+ const isStreaming = isStreamingInitiated || hasTextChunks;++ const allMessages = useMemo(() => {+ const processedInitialMessages: ChatMessageData[] = [];+ // Map to track tool calls by their ID so we can look up tool names for tool responses+ const toolCallMap = new Map<string, string>();++ for (const msg of initialMessages) {+ if (!isValidMessage(msg)) {+ console.warn("Invalid message structure from backend:", msg);+ continue;+ }++ let content = String(msg.content || "");+ const role = String(msg.role || "assistant").toLowerCase();+ const toolCalls = msg.tool_calls;+ const timestamp = msg.timestamp+ ? new Date(msg.timestamp as string)+ : undefined;++ // Remove page context from user messages when loading existing sessions+ if (role === "user") {+ content = removePageContext(content);+ // Skip user messages that become empty after removing page context+ if (!content.trim()) {+ continue;+ }+ processedInitialMessages.push({+ type: "message",+ role: "user",+ content,+ timestamp,+ });+ continue;+ }++ // Handle assistant messages first (before tool messages) to build tool call map+ if (role === "assistant") {+ // Strip <thinking> tags from content+ content = content+ .replace(/<thinking>[\s\S]*?<\/thinking>/gi, "")+ .trim();++ // If assistant has tool calls, create tool_call messages for each+ if (toolCalls && isToolCallArray(toolCalls) && toolCalls.length > 0) {+ for (const toolCall of toolCalls) {+ const toolName = toolCall.function.name;+ const toolId = toolCall.id;+ // Store tool name for later lookup+ toolCallMap.set(toolId, toolName);++ try {+ const args = JSON.parse(toolCall.function.arguments || "{}");+ processedInitialMessages.push({+ type: "tool_call",+ toolId,+ toolName,+ arguments: args,+ timestamp,+ });+ } catch (err) {+ console.warn("Failed to parse tool call arguments:", err);+ processedInitialMessages.push({+ type: "tool_call",+ toolId,+ toolName,+ arguments: {},+ timestamp,+ });+ }+ }+ // Only add assistant message if there's content after stripping thinking tags+ if (content.trim()) {+ processedInitialMessages.push({+ type: "message",+ role: "assistant",+ content,+ timestamp,+ });+ }+ } else if (content.trim()) {+ // Assistant message without tool calls, but with content+ processedInitialMessages.push({+ type: "message",+ role: "assistant",+ content,+ timestamp,+ });+ }+ continue;+ }++ // Handle tool messages - look up tool name from tool call map+ if (role === "tool") {+ const toolCallId = (msg.tool_call_id as string) || "";+ const toolName = toolCallMap.get(toolCallId) || "unknown";+ const toolResponse = parseToolResponse(+ content,+ toolCallId,+ toolName,+ timestamp,+ );+ if (toolResponse) {+ processedInitialMessages.push(toolResponse);+ }+ continue;+ }++ // Handle other message types (system, etc.)+ if (content.trim()) {+ processedInitialMessages.push({+ type: "message",+ role: role as "user" | "assistant" | "system",+ content,+ timestamp,+ });+ }+ }++ return [...processedInitialMessages, ...messages];+ }, [initialMessages, messages]);++ const sendMessage = useCallback(+ async function sendMessage(+ content: string,+ isUserMessage: boolean = true,+ context?: { url: string; content: string },+ ) {+ if (!sessionId) {+ console.error("Cannot send message: no session ID");+ return;+ }+ if (isUserMessage) {+ const userMessage = createUserMessage(content);+ setMessages((prev) => [...filterAuthMessages(prev), userMessage]);+ } else {+ setMessages((prev) => filterAuthMessages(prev));+ }+ setStreamingChunks([]);+ streamingChunksRef.current = [];+ setHasTextChunks(false);+ setIsStreamingInitiated(true);+ const dispatcher = createStreamEventDispatcher({+ setHasTextChunks,+ setStreamingChunks,+ streamingChunksRef,+ setMessages,+ sessionId,+ setIsStreamingInitiated,+ });+ try {+ await sendStreamMessage(+ sessionId,+ content,+ dispatcher,+ isUserMessage,+ context,+ );+ } catch (err) {+ console.error("Failed to send message:", err);+ setIsStreamingInitiated(false);+ const errorMessage =+ err instanceof Error ? err.message : "Failed to send message";+ toast.error("Failed to send message", {+ description: errorMessage,+ });+ }+ },+ [sessionId, sendStreamMessage],+ );++ return {+ messages: allMessages,+ streamingChunks,+ isStreaming,+ error,+ sendMessage,+ };+}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatCredentialsSetup/ChatCredentialsSetup.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatCredentialsSetup/ChatCredentialsSetup.tsxnew file mode 100644index 0000000000..4b9da57286--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatCredentialsSetup/ChatCredentialsSetup.tsx@@ -0,0 +1,149 @@+import { Text } from "@/components/atoms/Text/Text";+import { CredentialsInput } from "@/components/contextual/CredentialsInput/CredentialsInput";+import type { BlockIOCredentialsSubSchema } from "@/lib/autogpt-server-api";+import { cn } from "@/lib/utils";+import { CheckIcon, RobotIcon, WarningIcon } from "@phosphor-icons/react";+import { useEffect, useRef } from "react";+import { useChatCredentialsSetup } from "./useChatCredentialsSetup";++export interface CredentialInfo {+ provider: string;+ providerName: string;+ credentialType: "api_key" | "oauth2" | "user_password" | "host_scoped";+ title: string;+ scopes?: string[];+}++interface Props {+ credentials: CredentialInfo[];+ agentName?: string;+ message: string;+ onAllCredentialsComplete: () => void;+ onCancel: () => void;+ className?: string;+}++function createSchemaFromCredentialInfo(+ credential: CredentialInfo,+): BlockIOCredentialsSubSchema {+ return {+ type: "object",+ properties: {},+ credentials_provider: [credential.provider],+ credentials_types: [credential.credentialType],+ credentials_scopes: credential.scopes,+ discriminator: undefined,+ discriminator_mapping: undefined,+ discriminator_values: undefined,+ };+}++export function ChatCredentialsSetup({+ credentials,+ agentName: _agentName,+ message,+ onAllCredentialsComplete,+ onCancel: _onCancel,+}: Props) {+ const { selectedCredentials, isAllComplete, handleCredentialSelect } =+ useChatCredentialsSetup(credentials);++ // Track if we've already called completion to prevent double calls+ const hasCalledCompleteRef = useRef(false);++ // Reset the completion flag when credentials change (new credential setup flow)+ useEffect(+ function resetCompletionFlag() {+ hasCalledCompleteRef.current = false;+ },+ [credentials],+ );++ // Auto-call completion when all credentials are configured+ useEffect(+ function autoCompleteWhenReady() {+ if (isAllComplete && !hasCalledCompleteRef.current) {+ hasCalledCompleteRef.current = true;+ onAllCredentialsComplete();+ }+ },+ [isAllComplete, onAllCredentialsComplete],+ );++ return (+ <div className="group relative flex w-full justify-start gap-3 px-4 py-3">+ <div className="flex w-full max-w-3xl gap-3">+ <div className="flex-shrink-0">+ <div className="flex h-7 w-7 items-center justify-center rounded-lg bg-indigo-500">+ <RobotIcon className="h-4 w-4 text-indigo-50" />+ </div>+ </div>++ <div className="flex min-w-0 flex-1 flex-col">+ <div className="group relative min-w-20 overflow-hidden rounded-xl border border-slate-100 bg-slate-50/20 px-6 py-2.5 text-sm leading-relaxed backdrop-blur-xl">+ <div className="absolute inset-0 bg-gradient-to-br from-slate-200/20 via-slate-300/10 to-transparent" />+ <div className="relative z-10 space-y-3 text-slate-900">+ <div>+ <Text variant="h4" className="mb-1 text-slate-900">+ Credentials Required+ </Text>+ <Text variant="small" className="text-slate-600">+ {message}+ </Text>+ </div>++ <div className="space-y-3">+ {credentials.map((cred, index) => {+ const schema = createSchemaFromCredentialInfo(cred);+ const isSelected = !!selectedCredentials[cred.provider];++ return (+ <div+ key={`${cred.provider}-${index}`}+ className={cn(+ "relative rounded-lg border p-3",+ isSelected+ ? "border-green-500 bg-green-50/50"+ : "border-slate-200 bg-white/50",+ )}+ >+ <div className="mb-2 flex items-center gap-2">+ {isSelected ? (+ <CheckIcon+ size={16}+ className="text-green-500"+ weight="bold"+ />+ ) : (+ <WarningIcon+ size={16}+ className="text-slate-500"+ weight="bold"+ />+ )}+ <Text+ variant="small"+ className="font-semibold text-slate-900"+ >+ {cred.providerName}+ </Text>+ </div>++ <CredentialsInput+ schema={schema}+ selectedCredentials={selectedCredentials[cred.provider]}+ onSelectCredentials={(credMeta) =>+ handleCredentialSelect(cred.provider, credMeta)+ }+ />+ </div>+ );+ })}+ </div>+ </div>+ </div>+ </div>+ </div>+ </div>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatCredentialsSetup/useChatCredentialsSetup.ts b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatCredentialsSetup/useChatCredentialsSetup.tssimilarity index 100%rename from autogpt_platform/frontend/src/app/(platform)/chat/components/ChatCredentialsSetup/useChatCredentialsSetup.tsrename to autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatCredentialsSetup/useChatCredentialsSetup.tsdiff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatErrorState/ChatErrorState.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatErrorState/ChatErrorState.tsxsimilarity index 100%rename from autogpt_platform/frontend/src/app/(platform)/chat/components/ChatErrorState/ChatErrorState.tsxrename to autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatErrorState/ChatErrorState.tsxdiff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatInput/ChatInput.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatInput/ChatInput.tsxnew file mode 100644index 0000000000..3101174a11--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatInput/ChatInput.tsx@@ -0,0 +1,64 @@+import { Input } from "@/components/atoms/Input/Input";+import { cn } from "@/lib/utils";+import { ArrowUpIcon } from "@phosphor-icons/react";+import { useChatInput } from "./useChatInput";++export interface ChatInputProps {+ onSend: (message: string) => void;+ disabled?: boolean;+ placeholder?: string;+ className?: string;+}++export function ChatInput({+ onSend,+ disabled = false,+ placeholder = "Type your message...",+ className,+}: ChatInputProps) {+ const inputId = "chat-input";+ const { value, setValue, handleKeyDown, handleSend } = useChatInput({+ onSend,+ disabled,+ maxRows: 5,+ inputId,+ });++ return (+ <div className={cn("relative flex-1", className)}>+ <Input+ id={inputId}+ label="Chat message input"+ hideLabel+ type="textarea"+ value={value}+ onChange={(e) => setValue(e.target.value)}+ onKeyDown={handleKeyDown}+ placeholder={placeholder}+ disabled={disabled}+ rows={1}+ wrapperClassName="mb-0 relative"+ className="pr-12"+ />+ <span id="chat-input-hint" className="sr-only">+ Press Enter to send, Shift+Enter for new line+ </span>++ <button+ onClick={handleSend}+ disabled={disabled || !value.trim()}+ className={cn(+ "absolute right-3 top-1/2 flex h-8 w-8 -translate-y-1/2 items-center justify-center rounded-full",+ "border border-zinc-800 bg-zinc-800 text-white",+ "hover:border-zinc-900 hover:bg-zinc-900",+ "disabled:border-zinc-200 disabled:bg-zinc-200 disabled:text-white disabled:opacity-50",+ "transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-neutral-950",+ "disabled:pointer-events-none",+ )}+ aria-label="Send message"+ >+ <ArrowUpIcon className="h-3 w-3" weight="bold" />+ </button>+ </div>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatInput/useChatInput.ts b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatInput/useChatInput.tssimilarity index 65%rename from autogpt_platform/frontend/src/app/(platform)/chat/components/ChatInput/useChatInput.tsrename to autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatInput/useChatInput.tsindex 2efae95483..08cf565daa 100644--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatInput/useChatInput.ts+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatInput/useChatInput.ts@@ -1,21 +1,22 @@-import { KeyboardEvent, useCallback, useState, useRef, useEffect } from "react";+import { KeyboardEvent, useCallback, useEffect, useState } from "react";interface UseChatInputArgs {onSend: (message: string) => void;disabled?: boolean;maxRows?: number;+ inputId?: string;}export function useChatInput({onSend,disabled = false,maxRows = 5,+ inputId = "chat-input",}: UseChatInputArgs) {const [value, setValue] = useState("");- const textareaRef = useRef<HTMLTextAreaElement>(null);useEffect(() => {- const textarea = textareaRef.current;+ const textarea = document.getElementById(inputId) as HTMLTextAreaElement;if (!textarea) return;textarea.style.height = "auto";const lineHeight = parseInt(@@ -27,23 +28,25 @@ export function useChatInput({textarea.style.height = `${newHeight}px`;textarea.style.overflowY =textarea.scrollHeight > maxHeight ? "auto" : "hidden";- }, [value, maxRows]);+ }, [value, maxRows, inputId]);const handleSend = useCallback(() => {if (disabled || !value.trim()) return;onSend(value.trim());setValue("");- if (textareaRef.current) {- textareaRef.current.style.height = "auto";+ const textarea = document.getElementById(inputId) as HTMLTextAreaElement;+ if (textarea) {+ textarea.style.height = "auto";}- }, [value, onSend, disabled]);+ }, [value, onSend, disabled, inputId]);const handleKeyDown = useCallback(- (event: KeyboardEvent<HTMLTextAreaElement>) => {+ (event: KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => {if (event.key === "Enter" && !event.shiftKey) {event.preventDefault();handleSend();}+ // Shift+Enter allows default behavior (new line) - no need to handle explicitly},[handleSend],);@@ -53,6 +56,5 @@ export function useChatInput({setValue,handleKeyDown,handleSend,- textareaRef,};}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatLoadingState/ChatLoadingState.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatLoadingState/ChatLoadingState.tsxnew file mode 100644index 0000000000..c0cdb33c50--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatLoadingState/ChatLoadingState.tsx@@ -0,0 +1,19 @@+import { LoadingSpinner } from "@/components/atoms/LoadingSpinner/LoadingSpinner";+import { cn } from "@/lib/utils";++export interface ChatLoadingStateProps {+ message?: string;+ className?: string;+}++export function ChatLoadingState({ className }: ChatLoadingStateProps) {+ return (+ <div+ className={cn("flex flex-1 items-center justify-center p-6", className)}+ >+ <div className="flex flex-col items-center gap-4 text-center">+ <LoadingSpinner />+ </div>+ </div>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatMessage/ChatMessage.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatMessage/ChatMessage.tsxnew file mode 100644index 0000000000..69a1ab63fb--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatMessage/ChatMessage.tsx@@ -0,0 +1,341 @@+"use client";++import { useGetV2GetUserProfile } from "@/app/api/__generated__/endpoints/store/store";+import Avatar, {+ AvatarFallback,+ AvatarImage,+} from "@/components/atoms/Avatar/Avatar";+import { Button } from "@/components/atoms/Button/Button";+import { useSupabase } from "@/lib/supabase/hooks/useSupabase";+import { cn } from "@/lib/utils";+import {+ ArrowClockwise,+ CheckCircleIcon,+ CheckIcon,+ CopyIcon,+ RobotIcon,+} from "@phosphor-icons/react";+import { useRouter } from "next/navigation";+import { useCallback, useState } from "react";+import { getToolActionPhrase } from "../../helpers";+import { AgentCarouselMessage } from "../AgentCarouselMessage/AgentCarouselMessage";+import { AuthPromptWidget } from "../AuthPromptWidget/AuthPromptWidget";+import { ChatCredentialsSetup } from "../ChatCredentialsSetup/ChatCredentialsSetup";+import { ExecutionStartedMessage } from "../ExecutionStartedMessage/ExecutionStartedMessage";+import { MarkdownContent } from "../MarkdownContent/MarkdownContent";+import { MessageBubble } from "../MessageBubble/MessageBubble";+import { NoResultsMessage } from "../NoResultsMessage/NoResultsMessage";+import { ToolCallMessage } from "../ToolCallMessage/ToolCallMessage";+import { ToolResponseMessage } from "../ToolResponseMessage/ToolResponseMessage";+import { useChatMessage, type ChatMessageData } from "./useChatMessage";+export interface ChatMessageProps {+ message: ChatMessageData;+ className?: string;+ onDismissLogin?: () => void;+ onDismissCredentials?: () => void;+ onSendMessage?: (content: string, isUserMessage?: boolean) => void;+ agentOutput?: ChatMessageData;+}++export function ChatMessage({+ message,+ className,+ onDismissCredentials,+ onSendMessage,+ agentOutput,+}: ChatMessageProps) {+ const { user } = useSupabase();+ const router = useRouter();+ const [copied, setCopied] = useState(false);+ const {+ isUser,+ isToolCall,+ isToolResponse,+ isLoginNeeded,+ isCredentialsNeeded,+ } = useChatMessage(message);++ const { data: profile } = useGetV2GetUserProfile({+ query: {+ select: (res) => (res.status === 200 ? res.data : null),+ enabled: isUser && !!user,+ queryKey: ["/api/store/profile", user?.id],+ },+ });++ const handleAllCredentialsComplete = useCallback(+ function handleAllCredentialsComplete() {+ // Send a user message that explicitly asks to retry the setup+ // This ensures the LLM calls get_required_setup_info again and proceeds with execution+ if (onSendMessage) {+ onSendMessage(+ "I've configured the required credentials. Please check if everything is ready and proceed with setting up the agent.",+ );+ }+ // Optionally dismiss the credentials prompt+ if (onDismissCredentials) {+ onDismissCredentials();+ }+ },+ [onSendMessage, onDismissCredentials],+ );++ function handleCancelCredentials() {+ // Dismiss the credentials prompt+ if (onDismissCredentials) {+ onDismissCredentials();+ }+ }++ const handleCopy = useCallback(async () => {+ if (message.type !== "message") return;++ try {+ await navigator.clipboard.writeText(message.content);+ setCopied(true);+ setTimeout(() => setCopied(false), 2000);+ } catch (error) {+ console.error("Failed to copy:", error);+ }+ }, [message]);++ const handleTryAgain = useCallback(() => {+ if (message.type !== "message" || !onSendMessage) return;+ onSendMessage(message.content, message.role === "user");+ }, [message, onSendMessage]);++ const handleViewExecution = useCallback(() => {+ if (message.type === "execution_started" && message.libraryAgentLink) {+ router.push(message.libraryAgentLink);+ }+ }, [message, router]);++ // Render credentials needed messages+ if (isCredentialsNeeded && message.type === "credentials_needed") {+ return (+ <ChatCredentialsSetup+ credentials={message.credentials}+ agentName={message.agentName}+ message={message.message}+ onAllCredentialsComplete={handleAllCredentialsComplete}+ onCancel={handleCancelCredentials}+ className={className}+ />+ );+ }++ // Render login needed messages+ if (isLoginNeeded && message.type === "login_needed") {+ // If user is already logged in, show success message instead of auth prompt+ if (user) {+ return (+ <div className={cn("px-4 py-2", className)}>+ <div className="my-4 overflow-hidden rounded-lg border border-green-200 bg-gradient-to-br from-green-50 to-emerald-50">+ <div className="px-6 py-4">+ <div className="flex items-center gap-3">+ <div className="flex h-10 w-10 items-center justify-center rounded-full bg-green-600">+ <CheckCircleIcon+ size={20}+ weight="fill"+ className="text-white"+ />+ </div>+ <div>+ <h3 className="text-lg font-semibold text-neutral-900">+ Successfully Authenticated+ </h3>+ <p className="text-sm text-neutral-600">+ You're now signed in and ready to continue+ </p>+ </div>+ </div>+ </div>+ </div>+ </div>+ );+ }++ // Show auth prompt if not logged in+ return (+ <div className={cn("px-4 py-2", className)}>+ <AuthPromptWidget+ message={message.message}+ sessionId={message.sessionId}+ agentInfo={message.agentInfo}+ />+ </div>+ );+ }++ // Render tool call messages+ if (isToolCall && message.type === "tool_call") {+ return (+ <div className={cn("px-4 py-2", className)}>+ <ToolCallMessage toolName={message.toolName} />+ </div>+ );+ }++ // Render no_results messages - use dedicated component, not ToolResponseMessage+ if (message.type === "no_results") {+ return (+ <div className={cn("px-4 py-2", className)}>+ <NoResultsMessage+ message={message.message}+ suggestions={message.suggestions}+ />+ </div>+ );+ }++ // Render agent_carousel messages - use dedicated component, not ToolResponseMessage+ if (message.type === "agent_carousel") {+ return (+ <div className={cn("px-4 py-2", className)}>+ <AgentCarouselMessage+ agents={message.agents}+ totalCount={message.totalCount}+ />+ </div>+ );+ }++ // Render execution_started messages - use dedicated component, not ToolResponseMessage+ if (message.type === "execution_started") {+ return (+ <div className={cn("px-4 py-2", className)}>+ <ExecutionStartedMessage+ executionId={message.executionId}+ agentName={message.agentName}+ message={message.message}+ onViewExecution={+ message.libraryAgentLink ? handleViewExecution : undefined+ }+ />+ </div>+ );+ }++ // Render tool response messages (but skip agent_output if it's being rendered inside assistant message)+ if (isToolResponse && message.type === "tool_response") {+ // Check if this is an agent_output that should be rendered inside assistant message+ if (message.result) {+ let parsedResult: Record<string, unknown> | null = null;+ try {+ parsedResult =+ typeof message.result === "string"+ ? JSON.parse(message.result)+ : (message.result as Record<string, unknown>);+ } catch {+ parsedResult = null;+ }+ if (parsedResult?.type === "agent_output") {+ // Skip rendering - this will be rendered inside the assistant message+ return null;+ }+ }++ return (+ <div className={cn("px-4 py-2", className)}>+ <ToolResponseMessage+ toolName={getToolActionPhrase(message.toolName)}+ result={message.result}+ />+ </div>+ );+ }++ // Render regular chat messages+ if (message.type === "message") {+ return (+ <div+ className={cn(+ "group relative flex w-full gap-3 px-4 py-3",+ isUser ? "justify-end" : "justify-start",+ className,+ )}+ >+ <div className="flex w-full max-w-3xl gap-3">+ {!isUser && (+ <div className="flex-shrink-0">+ <div className="flex h-7 w-7 items-center justify-center rounded-lg bg-indigo-500">+ <RobotIcon className="h-4 w-4 text-indigo-50" />+ </div>+ </div>+ )}++ <div+ className={cn(+ "flex min-w-0 flex-1 flex-col",+ isUser && "items-end",+ )}+ >+ <MessageBubble variant={isUser ? "user" : "assistant"}>+ <MarkdownContent content={message.content} />+ {agentOutput &&+ agentOutput.type === "tool_response" &&+ !isUser && (+ <div className="mt-4">+ <ToolResponseMessage+ toolName={+ agentOutput.toolName+ ? getToolActionPhrase(agentOutput.toolName)+ : "Agent Output"+ }+ result={agentOutput.result}+ />+ </div>+ )}+ </MessageBubble>+ <div+ className={cn(+ "mt-1 flex gap-1",+ isUser ? "justify-end" : "justify-start",+ )}+ >+ {isUser && onSendMessage && (+ <Button+ variant="ghost"+ size="icon"+ onClick={handleTryAgain}+ aria-label="Try again"+ >+ <ArrowClockwise className="size-3 text-neutral-500" />+ </Button>+ )}+ <Button+ variant="ghost"+ size="icon"+ onClick={handleCopy}+ aria-label="Copy message"+ >+ {copied ? (+ <CheckIcon className="size-3 text-green-600" />+ ) : (+ <CopyIcon className="size-3 text-neutral-500" />+ )}+ </Button>+ </div>+ </div>++ {isUser && (+ <div className="flex-shrink-0">+ <Avatar className="h-7 w-7">+ <AvatarImage+ src={profile?.avatar_url ?? ""}+ alt={profile?.username ?? "User"}+ />+ <AvatarFallback className="rounded-lg bg-neutral-200 text-neutral-600">+ {profile?.username?.charAt(0)?.toUpperCase() || "U"}+ </AvatarFallback>+ </Avatar>+ </div>+ )}+ </div>+ </div>+ );+ }++ // Fallback for unknown message types+ return null;+}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatMessage/useChatMessage.ts b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatMessage/useChatMessage.tssimilarity index 88%rename from autogpt_platform/frontend/src/app/(platform)/chat/components/ChatMessage/useChatMessage.tsrename to autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatMessage/useChatMessage.tsindex ae4f48f35b..9a597d4b26 100644--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatMessage/useChatMessage.ts+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ChatMessage/useChatMessage.ts@@ -1,5 +1,5 @@-import { formatDistanceToNow } from "date-fns";import type { ToolArguments, ToolResult } from "@/types/chat";+import { formatDistanceToNow } from "date-fns";export type ChatMessageData =| {@@ -65,6 +65,7 @@ export type ChatMessageData =name: string;description: string;version?: number;+ image_url?: string;}>;totalCount?: number;timestamp?: string | Date;@@ -77,6 +78,17 @@ export type ChatMessageData =message?: string;libraryAgentLink?: string;timestamp?: string | Date;+ }+ | {+ type: "inputs_needed";+ toolName: string;+ agentName?: string;+ agentId?: string;+ graphVersion?: number;+ inputSchema: Record<string, any>;+ credentialsSchema?: Record<string, any>;+ message: string;+ timestamp?: string | Date;};export function useChatMessage(message: ChatMessageData) {@@ -96,5 +108,6 @@ export function useChatMessage(message: ChatMessageData) {isNoResults: message.type === "no_results",isAgentCarousel: message.type === "agent_carousel",isExecutionStarted: message.type === "execution_started",+ isInputsNeeded: message.type === "inputs_needed",};}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/ExecutionStartedMessage/ExecutionStartedMessage.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ExecutionStartedMessage/ExecutionStartedMessage.tsxsimilarity index 67%rename from autogpt_platform/frontend/src/app/(platform)/chat/components/ExecutionStartedMessage/ExecutionStartedMessage.tsxrename to autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ExecutionStartedMessage/ExecutionStartedMessage.tsxindex 77c7f8fe9b..1ac3b440e0 100644--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/ExecutionStartedMessage/ExecutionStartedMessage.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ExecutionStartedMessage/ExecutionStartedMessage.tsx@@ -1,8 +1,7 @@-import React from "react";-import { Text } from "@/components/atoms/Text/Text";import { Button } from "@/components/atoms/Button/Button";-import { CheckCircle, Play, ArrowSquareOut } from "@phosphor-icons/react";+import { Text } from "@/components/atoms/Text/Text";import { cn } from "@/lib/utils";+import { ArrowSquareOut, CheckCircle, Play } from "@phosphor-icons/react";export interface ExecutionStartedMessageProps {executionId: string;@@ -22,7 +21,7 @@ export function ExecutionStartedMessage({return (<divclassName={cn(- "mx-4 my-2 flex flex-col gap-4 rounded-lg border border-green-200 bg-green-50 p-6 dark:border-green-900 dark:bg-green-950",+ "mx-4 my-2 flex flex-col gap-4 rounded-lg border border-green-200 bg-green-50 p-6",className,)}>@@ -32,48 +31,33 @@ export function ExecutionStartedMessage({<CheckCircle size={24} weight="bold" className="text-white" /></div><div className="flex-1">- <Text- variant="h3"- className="mb-1 text-green-900 dark:text-green-100"- >+ <Text variant="h3" className="mb-1 text-green-900">Execution Started</Text>- <Text variant="body" className="text-green-700 dark:text-green-300">+ <Text variant="body" className="text-green-700">{message}</Text></div></div>{/* Details */}- <div className="rounded-md bg-green-100 p-4 dark:bg-green-900">+ <div className="rounded-md bg-green-100 p-4"><div className="space-y-2">{agentName && (<div className="flex items-center justify-between">- <Text- variant="small"- className="font-semibold text-green-900 dark:text-green-100"- >+ <Text variant="small" className="font-semibold text-green-900">Agent:</Text>- <Text- variant="body"- className="text-green-800 dark:text-green-200"- >+ <Text variant="body" className="text-green-800">{agentName}</Text></div>)}<div className="flex items-center justify-between">- <Text- variant="small"- className="font-semibold text-green-900 dark:text-green-100"- >+ <Text variant="small" className="font-semibold text-green-900">Execution ID:</Text>- <Text- variant="small"- className="font-mono text-green-800 dark:text-green-200"- >+ <Text variant="small" className="font-mono text-green-800">{executionId.slice(0, 16)}...</Text></div>@@ -94,7 +78,7 @@ export function ExecutionStartedMessage({</div>)}- <div className="flex items-center gap-2 text-green-600 dark:text-green-400">+ <div className="flex items-center gap-2 text-green-600"><Play size={16} weight="fill" /><Text variant="small">Your agent is now running. You can monitor its progress in the monitordiff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/MarkdownContent/MarkdownContent.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/MarkdownContent/MarkdownContent.tsxsimilarity index 80%rename from autogpt_platform/frontend/src/app/(platform)/chat/components/MarkdownContent/MarkdownContent.tsxrename to autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/MarkdownContent/MarkdownContent.tsxindex e82e29c438..51a0794090 100644--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/MarkdownContent/MarkdownContent.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/MarkdownContent/MarkdownContent.tsx@@ -1,9 +1,9 @@"use client";+import { cn } from "@/lib/utils";import React from "react";import ReactMarkdown from "react-markdown";import remarkGfm from "remark-gfm";-import { cn } from "@/lib/utils";interface MarkdownContentProps {content: string;@@ -41,7 +41,7 @@ export function MarkdownContent({ content, className }: MarkdownContentProps) {if (isInline) {return (<code- className="rounded bg-zinc-100 px-1.5 py-0.5 font-mono text-sm text-zinc-800 dark:bg-zinc-800 dark:text-zinc-200"+ className="rounded bg-zinc-100 px-1.5 py-0.5 font-mono text-sm text-zinc-800"{...props}>{children}@@ -49,17 +49,14 @@ export function MarkdownContent({ content, className }: MarkdownContentProps) {);}return (- <code- className="font-mono text-sm text-zinc-100 dark:text-zinc-200"- {...props}- >+ <code className="font-mono text-sm text-zinc-100" {...props}>{children}</code>);},pre: ({ children, ...props }) => (<pre- className="my-2 overflow-x-auto rounded-md bg-zinc-900 p-3 dark:bg-zinc-950"+ className="my-2 overflow-x-auto rounded-md bg-zinc-900 p-3"{...props}>{children}@@ -70,7 +67,7 @@ export function MarkdownContent({ content, className }: MarkdownContentProps) {href={href}target="_blank"rel="noopener noreferrer"- className="text-purple-600 underline decoration-1 underline-offset-2 hover:text-purple-700 dark:text-purple-400 dark:hover:text-purple-300"+ className="text-purple-600 underline decoration-1 underline-offset-2 hover:text-purple-700"{...props}>{children}@@ -126,7 +123,7 @@ export function MarkdownContent({ content, className }: MarkdownContentProps) {return (<inputtype="checkbox"- className="mr-2 h-4 w-4 rounded border-zinc-300 text-purple-600 focus:ring-purple-500 disabled:cursor-not-allowed disabled:opacity-70 dark:border-zinc-600"+ className="mr-2 h-4 w-4 rounded border-zinc-300 text-purple-600 focus:ring-purple-500 disabled:cursor-not-allowed disabled:opacity-70"disabled{...props}/>@@ -136,57 +133,42 @@ export function MarkdownContent({ content, className }: MarkdownContentProps) {},blockquote: ({ children, ...props }) => (<blockquote- className="my-2 border-l-4 border-zinc-300 pl-3 italic text-zinc-700 dark:border-zinc-600 dark:text-zinc-300"+ className="my-2 border-l-4 border-zinc-300 pl-3 italic text-zinc-700"{...props}>{children}</blockquote>),h1: ({ children, ...props }) => (- <h1- className="my-2 text-xl font-bold text-zinc-900 dark:text-zinc-100"- {...props}- >+ <h1 className="my-2 text-xl font-bold text-zinc-900" {...props}>{children}</h1>),h2: ({ children, ...props }) => (- <h2- className="my-2 text-lg font-semibold text-zinc-800 dark:text-zinc-200"- {...props}- >+ <h2 className="my-2 text-lg font-semibold text-zinc-800" {...props}>{children}</h2>),h3: ({ children, ...props }) => (<h3- className="my-1 text-base font-semibold text-zinc-800 dark:text-zinc-200"+ className="my-1 text-base font-semibold text-zinc-800"{...props}>{children}</h3>),h4: ({ children, ...props }) => (- <h4- className="my-1 text-sm font-medium text-zinc-700 dark:text-zinc-300"- {...props}- >+ <h4 className="my-1 text-sm font-medium text-zinc-700" {...props}>{children}</h4>),h5: ({ children, ...props }) => (- <h5- className="my-1 text-sm font-medium text-zinc-700 dark:text-zinc-300"- {...props}- >+ <h5 className="my-1 text-sm font-medium text-zinc-700" {...props}>{children}</h5>),h6: ({ children, ...props }) => (- <h6- className="my-1 text-xs font-medium text-zinc-600 dark:text-zinc-400"- {...props}- >+ <h6 className="my-1 text-xs font-medium text-zinc-600" {...props}>{children}</h6>),@@ -196,15 +178,12 @@ export function MarkdownContent({ content, className }: MarkdownContentProps) {</p>),hr: ({ ...props }) => (- <hr- className="my-3 border-zinc-300 dark:border-zinc-700"- {...props}- />+ <hr className="my-3 border-zinc-300" {...props} />),table: ({ children, ...props }) => (<div className="my-2 overflow-x-auto"><table- className="min-w-full divide-y divide-zinc-200 rounded border border-zinc-200 dark:divide-zinc-700 dark:border-zinc-700"+ className="min-w-full divide-y divide-zinc-200 rounded border border-zinc-200"{...props}>{children}@@ -213,7 +192,7 @@ export function MarkdownContent({ content, className }: MarkdownContentProps) {),th: ({ children, ...props }) => (<th- className="bg-zinc-50 px-3 py-2 text-left text-xs font-semibold text-zinc-700 dark:bg-zinc-800 dark:text-zinc-300"+ className="bg-zinc-50 px-3 py-2 text-left text-xs font-semibold text-zinc-700"{...props}>{children}@@ -221,7 +200,7 @@ export function MarkdownContent({ content, className }: MarkdownContentProps) {),td: ({ children, ...props }) => (<td- className="border-t border-zinc-200 px-3 py-2 text-sm dark:border-zinc-700"+ className="border-t border-zinc-200 px-3 py-2 text-sm"{...props}>{children}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/MessageBubble/MessageBubble.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/MessageBubble/MessageBubble.tsxnew file mode 100644index 0000000000..98b50f3d28--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/MessageBubble/MessageBubble.tsx@@ -0,0 +1,56 @@+import { cn } from "@/lib/utils";+import { ReactNode } from "react";++export interface MessageBubbleProps {+ children: ReactNode;+ variant: "user" | "assistant";+ className?: string;+}++export function MessageBubble({+ children,+ variant,+ className,+}: MessageBubbleProps) {+ const userTheme = {+ bg: "bg-slate-900",+ border: "border-slate-800",+ gradient: "from-slate-900/30 via-slate-800/20 to-transparent",+ text: "text-slate-50",+ };++ const assistantTheme = {+ bg: "bg-slate-50/20",+ border: "border-slate-100",+ gradient: "from-slate-200/20 via-slate-300/10 to-transparent",+ text: "text-slate-900",+ };++ const theme = variant === "user" ? userTheme : assistantTheme;++ return (+ <div+ className={cn(+ "group relative min-w-20 overflow-hidden rounded-xl border px-6 py-2.5 text-sm leading-relaxed backdrop-blur-xl transition-all duration-500 ease-in-out",+ theme.bg,+ theme.border,+ variant === "user" && "text-right",+ variant === "assistant" && "text-left",+ className,+ )}+ >+ {/* Gradient flare background */}+ <div+ className={cn("absolute inset-0 bg-gradient-to-br", theme.gradient)}+ />+ <div+ className={cn(+ "relative z-10 transition-all duration-500 ease-in-out",+ theme.text,+ )}+ >+ {children}+ </div>+ </div>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/MessageList/MessageList.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/MessageList/MessageList.tsxnew file mode 100644index 0000000000..22b51c0a92--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/MessageList/MessageList.tsx@@ -0,0 +1,121 @@+"use client";++import { cn } from "@/lib/utils";+import { ChatMessage } from "../ChatMessage/ChatMessage";+import type { ChatMessageData } from "../ChatMessage/useChatMessage";+import { StreamingMessage } from "../StreamingMessage/StreamingMessage";+import { ThinkingMessage } from "../ThinkingMessage/ThinkingMessage";+import { useMessageList } from "./useMessageList";++export interface MessageListProps {+ messages: ChatMessageData[];+ streamingChunks?: string[];+ isStreaming?: boolean;+ className?: string;+ onStreamComplete?: () => void;+ onSendMessage?: (content: string) => void;+}++export function MessageList({+ messages,+ streamingChunks = [],+ isStreaming = false,+ className,+ onStreamComplete,+ onSendMessage,+}: MessageListProps) {+ const { messagesEndRef, messagesContainerRef } = useMessageList({+ messageCount: messages.length,+ isStreaming,+ });++ return (+ <div+ ref={messagesContainerRef}+ className={cn(+ "flex-1 overflow-y-auto",+ "scrollbar-thin scrollbar-track-transparent scrollbar-thumb-zinc-300",+ className,+ )}+ >+ <div className="mx-auto flex max-w-3xl flex-col py-4">+ {/* Render all persisted messages */}+ {messages.map((message, index) => {+ // Check if current message is an agent_output tool_response+ // and if previous message is an assistant message+ let agentOutput: ChatMessageData | undefined;++ if (message.type === "tool_response" && message.result) {+ let parsedResult: Record<string, unknown> | null = null;+ try {+ parsedResult =+ typeof message.result === "string"+ ? JSON.parse(message.result)+ : (message.result as Record<string, unknown>);+ } catch {+ parsedResult = null;+ }+ if (parsedResult?.type === "agent_output") {+ const prevMessage = messages[index - 1];+ if (+ prevMessage &&+ prevMessage.type === "message" &&+ prevMessage.role === "assistant"+ ) {+ // This agent output will be rendered inside the previous assistant message+ // Skip rendering this message separately+ return null;+ }+ }+ }++ // Check if next message is an agent_output tool_response to include in current assistant message+ if (message.type === "message" && message.role === "assistant") {+ const nextMessage = messages[index + 1];+ if (+ nextMessage &&+ nextMessage.type === "tool_response" &&+ nextMessage.result+ ) {+ let parsedResult: Record<string, unknown> | null = null;+ try {+ parsedResult =+ typeof nextMessage.result === "string"+ ? JSON.parse(nextMessage.result)+ : (nextMessage.result as Record<string, unknown>);+ } catch {+ parsedResult = null;+ }+ if (parsedResult?.type === "agent_output") {+ agentOutput = nextMessage;+ }+ }+ }++ return (+ <ChatMessage+ key={index}+ message={message}+ onSendMessage={onSendMessage}+ agentOutput={agentOutput}+ />+ );+ })}++ {/* Render thinking message when streaming but no chunks yet */}+ {isStreaming && streamingChunks.length === 0 && <ThinkingMessage />}++ {/* Render streaming message if active */}+ {isStreaming && streamingChunks.length > 0 && (+ <StreamingMessage+ chunks={streamingChunks}+ onComplete={onStreamComplete}+ />+ )}++ {/* Invisible div to scroll to */}+ <div ref={messagesEndRef} />+ </div>+ </div>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/MessageList/useMessageList.ts b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/MessageList/useMessageList.tssimilarity index 100%rename from autogpt_platform/frontend/src/app/(platform)/chat/components/MessageList/useMessageList.tsrename to autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/MessageList/useMessageList.tsdiff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/NoResultsMessage/NoResultsMessage.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/NoResultsMessage/NoResultsMessage.tsxsimilarity index 72%rename from autogpt_platform/frontend/src/app/(platform)/chat/components/NoResultsMessage/NoResultsMessage.tsxrename to autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/NoResultsMessage/NoResultsMessage.tsxindex 38eac24bce..b6adc8b93c 100644--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/NoResultsMessage/NoResultsMessage.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/NoResultsMessage/NoResultsMessage.tsx@@ -1,7 +1,6 @@-import React from "react";import { Text } from "@/components/atoms/Text/Text";-import { MagnifyingGlass, X } from "@phosphor-icons/react";import { cn } from "@/lib/utils";+import { MagnifyingGlass, X } from "@phosphor-icons/react";export interface NoResultsMessageProps {message: string;@@ -17,26 +16,26 @@ export function NoResultsMessage({return (<divclassName={cn(- "mx-4 my-2 flex flex-col items-center gap-4 rounded-lg border border-gray-200 bg-gray-50 p-6 dark:border-gray-800 dark:bg-gray-900",+ "mx-4 my-2 flex flex-col items-center gap-4 rounded-lg border border-gray-200 bg-gray-50 p-6",className,)}>{/* Icon */}<div className="relative flex h-16 w-16 items-center justify-center">- <div className="flex h-16 w-16 items-center justify-center rounded-full bg-gray-200 dark:bg-gray-700">+ <div className="flex h-16 w-16 items-center justify-center rounded-full bg-gray-200"><MagnifyingGlass size={32} weight="bold" className="text-gray-500" /></div>- <div className="absolute -right-1 -top-1 flex h-8 w-8 items-center justify-center rounded-full bg-gray-400 dark:bg-gray-600">+ <div className="absolute -right-1 -top-1 flex h-8 w-8 items-center justify-center rounded-full bg-gray-400"><X size={20} weight="bold" className="text-white" /></div></div>{/* Content */}<div className="text-center">- <Text variant="h3" className="mb-2 text-gray-900 dark:text-gray-100">+ <Text variant="h3" className="mb-2 text-gray-900">No Results Found</Text>- <Text variant="body" className="text-gray-700 dark:text-gray-300">+ <Text variant="body" className="text-gray-700">{message}</Text></div>@@ -44,17 +43,14 @@ export function NoResultsMessage({{/* Suggestions */}{suggestions.length > 0 && (<div className="w-full space-y-2">- <Text- variant="small"- className="font-semibold text-gray-900 dark:text-gray-100"- >+ <Text variant="small" className="font-semibold text-gray-900">Try these suggestions:</Text>- <ul className="space-y-1 rounded-md bg-gray-100 p-4 dark:bg-gray-800">+ <ul className="space-y-1 rounded-md bg-gray-100 p-4">{suggestions.map((suggestion, index) => (<likey={index}- className="flex items-start gap-2 text-sm text-gray-700 dark:text-gray-300"+ className="flex items-start gap-2 text-sm text-gray-700"><span className="mt-1 text-gray-500">•</span><span>{suggestion}</span>diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/QuickActionsWelcome/QuickActionsWelcome.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/QuickActionsWelcome/QuickActionsWelcome.tsxnew file mode 100644index 0000000000..dd76fd9fb6--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/QuickActionsWelcome/QuickActionsWelcome.tsx@@ -0,0 +1,94 @@+"use client";++import { Text } from "@/components/atoms/Text/Text";+import { cn } from "@/lib/utils";++export interface QuickActionsWelcomeProps {+ title: string;+ description: string;+ actions: string[];+ onActionClick: (action: string) => void;+ disabled?: boolean;+ className?: string;+}++export function QuickActionsWelcome({+ title,+ description,+ actions,+ onActionClick,+ disabled = false,+ className,+}: QuickActionsWelcomeProps) {+ return (+ <div+ className={cn("flex flex-1 items-center justify-center p-8", className)}+ >+ <div className="w-full max-w-3xl">+ <div className="mb-12 text-center">+ <Text+ variant="h2"+ className="mb-3 text-2xl font-semibold text-zinc-900"+ >+ {title}+ </Text>+ <Text variant="body" className="text-zinc-500">+ {description}+ </Text>+ </div>+ <div className="grid gap-3 sm:grid-cols-2">+ {actions.map((action) => {+ // Use slate theme for all cards+ const theme = {+ bg: "bg-slate-50/10",+ border: "border-slate-100",+ hoverBg: "hover:bg-slate-50/20",+ hoverBorder: "hover:border-slate-200",+ gradient: "from-slate-200/20 via-slate-300/10 to-transparent",+ text: "text-slate-900",+ hoverText: "group-hover:text-slate-900",+ };++ return (+ <button+ key={action}+ onClick={() => onActionClick(action)}+ disabled={disabled}+ className={cn(+ "group relative overflow-hidden rounded-xl border p-5 text-left backdrop-blur-xl",+ "transition-all duration-200",+ theme.bg,+ theme.border,+ theme.hoverBg,+ theme.hoverBorder,+ "hover:shadow-sm",+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/50 focus-visible:ring-offset-2",+ "disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:shadow-none",+ )}+ >+ {/* Gradient flare background */}+ <div+ className={cn(+ "absolute inset-0 bg-gradient-to-br",+ theme.gradient,+ )}+ />++ <Text+ variant="body"+ className={cn(+ "relative z-10 font-medium",+ theme.text,+ theme.hoverText,+ )}+ >+ {action}+ </Text>+ </button>+ );+ })}+ </div>+ </div>+ </div>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/SessionsDrawer/SessionsDrawer.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/SessionsDrawer/SessionsDrawer.tsxnew file mode 100644index 0000000000..74aa709a46--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/SessionsDrawer/SessionsDrawer.tsx@@ -0,0 +1,136 @@+"use client";++import { useGetV2ListSessions } from "@/app/api/__generated__/endpoints/chat/chat";+import { Text } from "@/components/atoms/Text/Text";+import { scrollbarStyles } from "@/components/styles/scrollbars";+import { cn } from "@/lib/utils";+import { X } from "@phosphor-icons/react";+import { formatDistanceToNow } from "date-fns";+import { Drawer } from "vaul";++interface SessionsDrawerProps {+ isOpen: boolean;+ onClose: () => void;+ onSelectSession: (sessionId: string) => void;+ currentSessionId?: string | null;+}++export function SessionsDrawer({+ isOpen,+ onClose,+ onSelectSession,+ currentSessionId,+}: SessionsDrawerProps) {+ const { data, isLoading } = useGetV2ListSessions(+ { limit: 100 },+ {+ query: {+ enabled: isOpen,+ },+ },+ );++ const sessions =+ data?.status === 200+ ? data.data.sessions.filter((session) => {+ // Filter out sessions without messages (sessions that were never updated)+ // If updated_at equals created_at, the session was created but never had messages+ return session.updated_at !== session.created_at;+ })+ : [];++ function handleSelectSession(sessionId: string) {+ onSelectSession(sessionId);+ onClose();+ }++ return (+ <Drawer.Root+ open={isOpen}+ onOpenChange={(open) => !open && onClose()}+ direction="right"+ >+ <Drawer.Portal>+ <Drawer.Overlay className="fixed inset-0 z-[60] bg-black/10 backdrop-blur-sm" />+ <Drawer.Content+ className={cn(+ "fixed right-0 top-0 z-[70] flex h-full w-96 flex-col border-l border-zinc-200 bg-white",+ scrollbarStyles,+ )}+ >+ <div className="shrink-0 p-4">+ <div className="flex items-center justify-between">+ <Drawer.Title className="text-lg font-semibold">+ Chat Sessions+ </Drawer.Title>+ <button+ aria-label="Close"+ onClick={onClose}+ className="flex size-8 items-center justify-center rounded hover:bg-zinc-100"+ >+ <X width="1.25rem" height="1.25rem" />+ </button>+ </div>+ </div>++ <div className="flex-1 overflow-y-auto p-4">+ {isLoading ? (+ <div className="flex items-center justify-center py-8">+ <Text variant="body" className="text-zinc-500">+ Loading sessions...+ </Text>+ </div>+ ) : sessions.length === 0 ? (+ <div className="flex items-center justify-center py-8">+ <Text variant="body" className="text-zinc-500">+ No sessions found+ </Text>+ </div>+ ) : (+ <div className="space-y-2">+ {sessions.map((session) => {+ const isActive = session.id === currentSessionId;+ const updatedAt = session.updated_at+ ? formatDistanceToNow(new Date(session.updated_at), {+ addSuffix: true,+ })+ : "";++ return (+ <button+ key={session.id}+ onClick={() => handleSelectSession(session.id)}+ className={cn(+ "w-full rounded-lg border p-3 text-left transition-colors",+ isActive+ ? "border-indigo-500 bg-zinc-50"+ : "border-zinc-200 bg-zinc-100/50 hover:border-zinc-300 hover:bg-zinc-50",+ )}+ >+ <div className="flex flex-col gap-1">+ <Text+ variant="body"+ className={cn(+ "font-medium",+ isActive ? "text-indigo-900" : "text-zinc-900",+ )}+ >+ {session.title || "Untitled Chat"}+ </Text>+ <div className="flex items-center gap-2 text-xs text-zinc-500">+ <span>{session.id.slice(0, 8)}...</span>+ {updatedAt && <span>•</span>}+ <span>{updatedAt}</span>+ </div>+ </div>+ </button>+ );+ })}+ </div>+ )}+ </div>+ </Drawer.Content>+ </Drawer.Portal>+ </Drawer.Root>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/StreamingMessage/StreamingMessage.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/StreamingMessage/StreamingMessage.tsxnew file mode 100644index 0000000000..2a6e3d5822--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/StreamingMessage/StreamingMessage.tsx@@ -0,0 +1,42 @@+import { cn } from "@/lib/utils";+import { RobotIcon } from "@phosphor-icons/react";+import { MarkdownContent } from "../MarkdownContent/MarkdownContent";+import { MessageBubble } from "../MessageBubble/MessageBubble";+import { useStreamingMessage } from "./useStreamingMessage";++export interface StreamingMessageProps {+ chunks: string[];+ className?: string;+ onComplete?: () => void;+}++export function StreamingMessage({+ chunks,+ className,+ onComplete,+}: StreamingMessageProps) {+ const { displayText } = useStreamingMessage({ chunks, onComplete });++ return (+ <div+ className={cn(+ "group relative flex w-full justify-start gap-3 px-4 py-3",+ className,+ )}+ >+ <div className="flex w-full max-w-3xl gap-3">+ <div className="flex-shrink-0">+ <div className="flex h-7 w-7 items-center justify-center rounded-lg bg-indigo-600">+ <RobotIcon className="h-4 w-4 text-indigo-50" />+ </div>+ </div>++ <div className="flex min-w-0 flex-1 flex-col">+ <MessageBubble variant="assistant">+ <MarkdownContent content={displayText} />+ </MessageBubble>+ </div>+ </div>+ </div>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/StreamingMessage/useStreamingMessage.ts b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/StreamingMessage/useStreamingMessage.tssimilarity index 100%rename from autogpt_platform/frontend/src/app/(platform)/chat/components/StreamingMessage/useStreamingMessage.tsrename to autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/StreamingMessage/useStreamingMessage.tsdiff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ThinkingMessage/ThinkingMessage.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ThinkingMessage/ThinkingMessage.tsxnew file mode 100644index 0000000000..d8adddf416--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ThinkingMessage/ThinkingMessage.tsx@@ -0,0 +1,70 @@+import { cn } from "@/lib/utils";+import { RobotIcon } from "@phosphor-icons/react";+import { useEffect, useRef, useState } from "react";+import { MessageBubble } from "../MessageBubble/MessageBubble";++export interface ThinkingMessageProps {+ className?: string;+}++export function ThinkingMessage({ className }: ThinkingMessageProps) {+ const [showSlowLoader, setShowSlowLoader] = useState(false);+ const timerRef = useRef<NodeJS.Timeout | null>(null);++ useEffect(() => {+ if (timerRef.current === null) {+ timerRef.current = setTimeout(() => {+ setShowSlowLoader(true);+ }, 8000);+ }++ return () => {+ if (timerRef.current) {+ clearTimeout(timerRef.current);+ timerRef.current = null;+ }+ };+ }, []);++ return (+ <div+ className={cn(+ "group relative flex w-full justify-start gap-3 px-4 py-3",+ className,+ )}+ >+ <div className="flex w-full max-w-3xl gap-3">+ <div className="flex-shrink-0">+ <div className="flex h-7 w-7 items-center justify-center rounded-lg bg-indigo-500">+ <RobotIcon className="h-4 w-4 text-indigo-50" />+ </div>+ </div>++ <div className="flex min-w-0 flex-1 flex-col">+ <MessageBubble variant="assistant">+ <div className="transition-all duration-500 ease-in-out">+ {showSlowLoader ? (+ <div className="flex flex-col items-center gap-3 py-2">+ <div className="loader" style={{ flexShrink: 0 }} />+ <p className="text-sm text-slate-700">+ Taking a bit longer to think, wait a moment please+ </p>+ </div>+ ) : (+ <span+ className="inline-block bg-gradient-to-r from-neutral-400 via-neutral-600 to-neutral-400 bg-clip-text text-transparent"+ style={{+ backgroundSize: "200% 100%",+ animation: "shimmer 2s ease-in-out infinite",+ }}+ >+ Thinking...+ </span>+ )}+ </div>+ </MessageBubble>+ </div>+ </div>+ </div>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ToolCallMessage/ToolCallMessage.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ToolCallMessage/ToolCallMessage.tsxnew file mode 100644index 0000000000..97590ae0cf--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ToolCallMessage/ToolCallMessage.tsx@@ -0,0 +1,24 @@+import { Text } from "@/components/atoms/Text/Text";+import { cn } from "@/lib/utils";+import { WrenchIcon } from "@phosphor-icons/react";+import { getToolActionPhrase } from "../../helpers";++export interface ToolCallMessageProps {+ toolName: string;+ className?: string;+}++export function ToolCallMessage({ toolName, className }: ToolCallMessageProps) {+ return (+ <div className={cn("flex items-center justify-center gap-2", className)}>+ <WrenchIcon+ size={14}+ weight="bold"+ className="flex-shrink-0 text-neutral-500"+ />+ <Text variant="small" className="text-neutral-500">+ {getToolActionPhrase(toolName)}...+ </Text>+ </div>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ToolResponseMessage/ToolResponseMessage.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ToolResponseMessage/ToolResponseMessage.tsxnew file mode 100644index 0000000000..b84204c3ff--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/components/ToolResponseMessage/ToolResponseMessage.tsx@@ -0,0 +1,260 @@+import { Text } from "@/components/atoms/Text/Text";+import "@/components/contextual/OutputRenderers";+import {+ globalRegistry,+ OutputItem,+} from "@/components/contextual/OutputRenderers";+import { cn } from "@/lib/utils";+import type { ToolResult } from "@/types/chat";+import { WrenchIcon } from "@phosphor-icons/react";+import { getToolActionPhrase } from "../../helpers";++export interface ToolResponseMessageProps {+ toolName: string;+ result?: ToolResult;+ success?: boolean;+ className?: string;+}++export function ToolResponseMessage({+ toolName,+ result,+ success: _success = true,+ className,+}: ToolResponseMessageProps) {+ if (!result) {+ return (+ <div className={cn("flex items-center justify-center gap-2", className)}>+ <WrenchIcon+ size={14}+ weight="bold"+ className="flex-shrink-0 text-neutral-500"+ />+ <Text variant="small" className="text-neutral-500">+ {getToolActionPhrase(toolName)}...+ </Text>+ </div>+ );+ }++ let parsedResult: Record<string, unknown> | null = null;+ try {+ parsedResult =+ typeof result === "string"+ ? JSON.parse(result)+ : (result as Record<string, unknown>);+ } catch {+ parsedResult = null;+ }++ if (parsedResult && typeof parsedResult === "object") {+ const responseType = parsedResult.type as string | undefined;++ if (responseType === "agent_output") {+ const execution = parsedResult.execution as+ | {+ outputs?: Record<string, unknown[]>;+ }+ | null+ | undefined;+ const outputs = execution?.outputs || {};+ const message = parsedResult.message as string | undefined;++ return (+ <div className={cn("space-y-4 px-4 py-2", className)}>+ <div className="flex items-center gap-2">+ <WrenchIcon+ size={14}+ weight="bold"+ className="flex-shrink-0 text-neutral-500"+ />+ <Text variant="small" className="text-neutral-500">+ {getToolActionPhrase(toolName)}+ </Text>+ </div>+ {message && (+ <div className="rounded border p-4">+ <Text variant="small" className="text-neutral-600">+ {message}+ </Text>+ </div>+ )}+ {Object.keys(outputs).length > 0 && (+ <div className="space-y-4">+ {Object.entries(outputs).map(([outputName, values]) =>+ values.map((value, index) => {+ const renderer = globalRegistry.getRenderer(value);+ if (renderer) {+ return (+ <OutputItem+ key={`${outputName}-${index}`}+ value={value}+ renderer={renderer}+ label={outputName}+ />+ );+ }+ return (+ <div+ key={`${outputName}-${index}`}+ className="rounded border p-4"+ >+ <Text variant="large-medium" className="mb-2 capitalize">+ {outputName}+ </Text>+ <pre className="overflow-auto text-sm">+ {JSON.stringify(value, null, 2)}+ </pre>+ </div>+ );+ }),+ )}+ </div>+ )}+ </div>+ );+ }++ if (responseType === "block_output" && parsedResult.outputs) {+ const outputs = parsedResult.outputs as Record<string, unknown[]>;++ return (+ <div className={cn("space-y-4 px-4 py-2", className)}>+ <div className="flex items-center gap-2">+ <WrenchIcon+ size={14}+ weight="bold"+ className="flex-shrink-0 text-neutral-500"+ />+ <Text variant="small" className="text-neutral-500">+ {getToolActionPhrase(toolName)}+ </Text>+ </div>+ <div className="space-y-4">+ {Object.entries(outputs).map(([outputName, values]) =>+ values.map((value, index) => {+ const renderer = globalRegistry.getRenderer(value);+ if (renderer) {+ return (+ <OutputItem+ key={`${outputName}-${index}`}+ value={value}+ renderer={renderer}+ label={outputName}+ />+ );+ }+ return (+ <div+ key={`${outputName}-${index}`}+ className="rounded border p-4"+ >+ <Text variant="large-medium" className="mb-2 capitalize">+ {outputName}+ </Text>+ <pre className="overflow-auto text-sm">+ {JSON.stringify(value, null, 2)}+ </pre>+ </div>+ );+ }),+ )}+ </div>+ </div>+ );+ }++ // Handle other response types with a message field (e.g., understanding_updated)+ if (parsedResult.message && typeof parsedResult.message === "string") {+ // Format tool name from snake_case to Title Case+ const formattedToolName = toolName+ .split("_")+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))+ .join(" ");++ // Clean up message - remove incomplete user_name references+ let cleanedMessage = parsedResult.message;+ // Remove "Updated understanding with: user_name" pattern if user_name is just a placeholder+ cleanedMessage = cleanedMessage.replace(+ /Updated understanding with:\s*user_name\.?\s*/gi,+ "",+ );+ // Remove standalone user_name references+ cleanedMessage = cleanedMessage.replace(/\buser_name\b\.?\s*/gi, "");+ cleanedMessage = cleanedMessage.trim();++ // Only show message if it has content after cleaning+ if (!cleanedMessage) {+ return (+ <div+ className={cn(+ "flex items-center justify-center gap-2 px-4 py-2",+ className,+ )}+ >+ <WrenchIcon+ size={14}+ weight="bold"+ className="flex-shrink-0 text-neutral-500"+ />+ <Text variant="small" className="text-neutral-500">+ {formattedToolName}+ </Text>+ </div>+ );+ }++ return (+ <div className={cn("space-y-2 px-4 py-2", className)}>+ <div className="flex items-center justify-center gap-2">+ <WrenchIcon+ size={14}+ weight="bold"+ className="flex-shrink-0 text-neutral-500"+ />+ <Text variant="small" className="text-neutral-500">+ {formattedToolName}+ </Text>+ </div>+ <div className="rounded border p-4">+ <Text variant="small" className="text-neutral-600">+ {cleanedMessage}+ </Text>+ </div>+ </div>+ );+ }+ }++ const renderer = globalRegistry.getRenderer(result);+ if (renderer) {+ return (+ <div className={cn("px-4 py-2", className)}>+ <div className="mb-2 flex items-center gap-2">+ <WrenchIcon+ size={14}+ weight="bold"+ className="flex-shrink-0 text-neutral-500"+ />+ <Text variant="small" className="text-neutral-500">+ {getToolActionPhrase(toolName)}+ </Text>+ </div>+ <OutputItem value={result} renderer={renderer} />+ </div>+ );+ }++ return (+ <div className={cn("flex items-center justify-center gap-2", className)}>+ <WrenchIcon+ size={14}+ weight="bold"+ className="flex-shrink-0 text-neutral-500"+ />+ <Text variant="small" className="text-neutral-500">+ {getToolActionPhrase(toolName)}...+ </Text>+ </div>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/helpers.ts b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/helpers.tssimilarity index 92%rename from autogpt_platform/frontend/src/app/(platform)/chat/helpers.tsrename to autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/helpers.tsindex 5a1e5eb93f..0fade56b73 100644--- a/autogpt_platform/frontend/src/app/(platform)/chat/helpers.ts+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/helpers.ts@@ -64,10 +64,3 @@ export function getToolCompletionPhrase(toolName: string): string {`Finished ${toolName.replace(/_/g, " ").replace("...", "")}`);}--/** Validate UUID v4 format */-export function isValidUUID(value: string): boolean {- const uuidRegex =- /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;- return uuidRegex.test(value);-}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/useChatPage.ts b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/useChat.tssimilarity index 78%rename from autogpt_platform/frontend/src/app/(platform)/chat/useChatPage.tsrename to autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/useChat.tsindex 4f1db5471a..8445d68b3f 100644--- a/autogpt_platform/frontend/src/app/(platform)/chat/useChatPage.ts+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/useChat.ts@@ -1,17 +1,12 @@"use client";+import { useSupabase } from "@/lib/supabase/hooks/useSupabase";import { useEffect, useRef } from "react";-import { useRouter, useSearchParams } from "next/navigation";import { toast } from "sonner";-import { useChatSession } from "@/app/(platform)/chat/useChatSession";-import { useSupabase } from "@/lib/supabase/hooks/useSupabase";-import { useChatStream } from "@/app/(platform)/chat/useChatStream";+import { useChatSession } from "./useChatSession";+import { useChatStream } from "./useChatStream";-export function useChatPage() {- const router = useRouter();- const searchParams = useSearchParams();- const urlSessionId =- searchParams.get("session_id") || searchParams.get("session");+export function useChat() {const hasCreatedSessionRef = useRef(false);const hasClaimedSessionRef = useRef(false);const { user } = useSupabase();@@ -25,29 +20,24 @@ export function useChatPage() {isCreating,error,createSession,- refreshSession,claimSession,clearSession: clearSessionBase,+ loadSession,} = useChatSession({- urlSessionId,+ urlSessionId: null,autoCreate: false,});useEffect(function autoCreateSession() {- if (- !urlSessionId &&- !hasCreatedSessionRef.current &&- !isCreating &&- !sessionIdFromHook- ) {+ if (!hasCreatedSessionRef.current && !isCreating && !sessionIdFromHook) {hasCreatedSessionRef.current = true;createSession().catch((_err) => {hasCreatedSessionRef.current = false;});}},- [urlSessionId, isCreating, sessionIdFromHook, createSession],+ [isCreating, sessionIdFromHook, createSession],);useEffect(@@ -111,7 +101,6 @@ export function useChatPage() {clearSessionBase();hasCreatedSessionRef.current = false;hasClaimedSessionRef.current = false;- router.push("/chat");}return {@@ -121,8 +110,8 @@ export function useChatPage() {isCreating,error,createSession,- refreshSession,clearSession,+ loadSession,sessionId: sessionIdFromHook,};}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/useChatDrawer.ts b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/useChatDrawer.tsnew file mode 100644index 0000000000..62e1a5a569--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/useChatDrawer.ts@@ -0,0 +1,17 @@+"use client";++import { create } from "zustand";++interface ChatDrawerState {+ isOpen: boolean;+ open: () => void;+ close: () => void;+ toggle: () => void;+}++export const useChatDrawer = create<ChatDrawerState>((set) => ({+ isOpen: false,+ open: () => set({ isOpen: true }),+ close: () => set({ isOpen: false }),+ toggle: () => set((state) => ({ isOpen: !state.isOpen })),+}));diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/useChatSession.ts b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/useChatSession.tssimilarity index 89%rename from autogpt_platform/frontend/src/app/(platform)/chat/useChatSession.tsrename to autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/useChatSession.tsindex 99f4efc093..a54dc9e32a 100644--- a/autogpt_platform/frontend/src/app/(platform)/chat/useChatSession.ts+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/useChatSession.ts@@ -1,17 +1,18 @@-import { useCallback, useEffect, useState, useRef, useMemo } from "react";-import { useQueryClient } from "@tanstack/react-query";-import { toast } from "sonner";import {- usePostV2CreateSession,+ getGetV2GetSessionQueryKey,+ getGetV2GetSessionQueryOptions,postV2CreateSession,useGetV2GetSession,usePatchV2SessionAssignUser,- getGetV2GetSessionQueryKey,+ usePostV2CreateSession,} from "@/app/api/__generated__/endpoints/chat/chat";import type { SessionDetailResponse } from "@/app/api/__generated__/models/sessionDetailResponse";-import { storage, Key } from "@/services/storage/local-storage";-import { isValidUUID } from "@/app/(platform)/chat/helpers";import { okData } from "@/app/api/helpers";+import { isValidUUID } from "@/lib/utils";+import { Key, storage } from "@/services/storage/local-storage";+import { useQueryClient } from "@tanstack/react-query";+import { useCallback, useEffect, useMemo, useRef, useState } from "react";+import { toast } from "sonner";interface UseChatSessionArgs {urlSessionId?: string | null;@@ -155,10 +156,22 @@ export function useChatSession({async function loadSession(id: string) {try {setError(null);+ // Invalidate the query cache for this session to force a fresh fetch+ await queryClient.invalidateQueries({+ queryKey: getGetV2GetSessionQueryKey(id),+ });+ // Set sessionId after invalidation to ensure the hook refetchessetSessionId(id);storage.set(Key.CHAT_SESSION_ID, id);- const result = await refetch();- if (!result.data || result.isError) {+ // Force fetch with fresh data (bypass cache)+ const queryOptions = getGetV2GetSessionQueryOptions(id, {+ query: {+ staleTime: 0, // Force fresh fetch+ retry: 1,+ },+ });+ const result = await queryClient.fetchQuery(queryOptions);+ if (!result || ("status" in result && result.status !== 200)) {console.warn("Session not found on server, clearing local state");storage.clean(Key.CHAT_SESSION_ID);setSessionId(null);@@ -171,7 +184,7 @@ export function useChatSession({throw error;}},- [refetch],+ [queryClient],);const refreshSession = useCallback(diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/useChatStream.ts b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/useChatStream.tsnew file mode 100644index 0000000000..1471a13a71--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/useChatStream.ts@@ -0,0 +1,371 @@+import type { ToolArguments, ToolResult } from "@/types/chat";+import { useCallback, useEffect, useRef, useState } from "react";+import { toast } from "sonner";++const MAX_RETRIES = 3;+const INITIAL_RETRY_DELAY = 1000;++export interface StreamChunk {+ type:+ | "text_chunk"+ | "text_ended"+ | "tool_call"+ | "tool_call_start"+ | "tool_response"+ | "login_needed"+ | "need_login"+ | "credentials_needed"+ | "error"+ | "usage"+ | "stream_end";+ timestamp?: string;+ content?: string;+ message?: string;+ tool_id?: string;+ tool_name?: string;+ arguments?: ToolArguments;+ result?: ToolResult;+ success?: boolean;+ idx?: number;+ session_id?: string;+ agent_info?: {+ graph_id: string;+ name: string;+ trigger_type: string;+ };+ provider?: string;+ provider_name?: string;+ credential_type?: string;+ scopes?: string[];+ title?: string;+ [key: string]: unknown;+}++type VercelStreamChunk =+ | { type: "start"; messageId: string }+ | { type: "finish" }+ | { type: "text-start"; id: string }+ | { type: "text-delta"; id: string; delta: string }+ | { type: "text-end"; id: string }+ | { type: "tool-input-start"; toolCallId: string; toolName: string }+ | {+ type: "tool-input-available";+ toolCallId: string;+ toolName: string;+ input: ToolArguments;+ }+ | {+ type: "tool-output-available";+ toolCallId: string;+ toolName?: string;+ output: ToolResult;+ success?: boolean;+ }+ | {+ type: "usage";+ promptTokens: number;+ completionTokens: number;+ totalTokens: number;+ }+ | {+ type: "error";+ errorText: string;+ code?: string;+ details?: Record<string, unknown>;+ };++const LEGACY_STREAM_TYPES = new Set<StreamChunk["type"]>([+ "text_chunk",+ "text_ended",+ "tool_call",+ "tool_call_start",+ "tool_response",+ "login_needed",+ "need_login",+ "credentials_needed",+ "error",+ "usage",+ "stream_end",+]);++function isLegacyStreamChunk(+ chunk: StreamChunk | VercelStreamChunk,+): chunk is StreamChunk {+ return LEGACY_STREAM_TYPES.has(chunk.type as StreamChunk["type"]);+}++function normalizeStreamChunk(+ chunk: StreamChunk | VercelStreamChunk,+): StreamChunk | null {+ if (isLegacyStreamChunk(chunk)) {+ return chunk;+ }+ switch (chunk.type) {+ case "text-delta":+ return { type: "text_chunk", content: chunk.delta };+ case "text-end":+ return { type: "text_ended" };+ case "tool-input-available":+ return {+ type: "tool_call_start",+ tool_id: chunk.toolCallId,+ tool_name: chunk.toolName,+ arguments: chunk.input,+ };+ case "tool-output-available":+ return {+ type: "tool_response",+ tool_id: chunk.toolCallId,+ tool_name: chunk.toolName,+ result: chunk.output,+ success: chunk.success ?? true,+ };+ case "usage":+ return {+ type: "usage",+ promptTokens: chunk.promptTokens,+ completionTokens: chunk.completionTokens,+ totalTokens: chunk.totalTokens,+ };+ case "error":+ return {+ type: "error",+ message: chunk.errorText,+ code: chunk.code,+ details: chunk.details,+ };+ case "finish":+ return { type: "stream_end" };+ case "start":+ case "text-start":+ case "tool-input-start":+ return null;+ }+}++export function useChatStream() {+ const [isStreaming, setIsStreaming] = useState(false);+ const [error, setError] = useState<Error | null>(null);+ const retryCountRef = useRef<number>(0);+ const retryTimeoutRef = useRef<NodeJS.Timeout | null>(null);+ const abortControllerRef = useRef<AbortController | null>(null);++ const stopStreaming = useCallback(() => {+ if (abortControllerRef.current) {+ abortControllerRef.current.abort();+ abortControllerRef.current = null;+ }+ if (retryTimeoutRef.current) {+ clearTimeout(retryTimeoutRef.current);+ retryTimeoutRef.current = null;+ }+ setIsStreaming(false);+ }, []);++ useEffect(() => {+ return () => {+ stopStreaming();+ };+ }, [stopStreaming]);++ const sendMessage = useCallback(+ async (+ sessionId: string,+ message: string,+ onChunk: (chunk: StreamChunk) => void,+ isUserMessage: boolean = true,+ context?: { url: string; content: string },+ isRetry: boolean = false,+ ) => {+ stopStreaming();++ const abortController = new AbortController();+ abortControllerRef.current = abortController;++ if (abortController.signal.aborted) {+ return Promise.reject(new Error("Request aborted"));+ }++ if (!isRetry) {+ retryCountRef.current = 0;+ }+ setIsStreaming(true);+ setError(null);++ try {+ const url = `/api/chat/sessions/${sessionId}/stream`;+ const body = JSON.stringify({+ message,+ is_user_message: isUserMessage,+ context: context || null,+ });++ const response = await fetch(url, {+ method: "POST",+ headers: {+ "Content-Type": "application/json",+ Accept: "text/event-stream",+ },+ body,+ signal: abortController.signal,+ });++ if (!response.ok) {+ const errorText = await response.text();+ throw new Error(errorText || `HTTP ${response.status}`);+ }++ if (!response.body) {+ throw new Error("Response body is null");+ }++ const reader = response.body.getReader();+ const decoder = new TextDecoder();+ let buffer = "";++ return new Promise<void>((resolve, reject) => {+ let didDispatchStreamEnd = false;++ function dispatchStreamEnd() {+ if (didDispatchStreamEnd) return;+ didDispatchStreamEnd = true;+ onChunk({ type: "stream_end" });+ }++ const cleanup = () => {+ reader.cancel().catch(() => {+ // Ignore cancel errors+ });+ };++ async function readStream() {+ try {+ while (true) {+ const { done, value } = await reader.read();++ if (done) {+ cleanup();+ dispatchStreamEnd();+ retryCountRef.current = 0;+ stopStreaming();+ resolve();+ return;+ }++ buffer += decoder.decode(value, { stream: true });+ const lines = buffer.split("\n");+ buffer = lines.pop() || "";++ for (const line of lines) {+ if (line.startsWith("data: ")) {+ const data = line.slice(6);+ if (data === "[DONE]") {+ cleanup();+ dispatchStreamEnd();+ retryCountRef.current = 0;+ stopStreaming();+ resolve();+ return;+ }++ try {+ const rawChunk = JSON.parse(data) as+ | StreamChunk+ | VercelStreamChunk;+ const chunk = normalizeStreamChunk(rawChunk);+ if (!chunk) {+ continue;+ }++ // Call the chunk handler+ onChunk(chunk);++ // Handle stream lifecycle+ if (chunk.type === "stream_end") {+ didDispatchStreamEnd = true;+ cleanup();+ retryCountRef.current = 0;+ stopStreaming();+ resolve();+ return;+ } else if (chunk.type === "error") {+ cleanup();+ reject(+ new Error(+ chunk.message || chunk.content || "Stream error",+ ),+ );+ return;+ }+ } catch (err) {+ // Skip invalid JSON lines+ console.warn("Failed to parse SSE chunk:", err, data);+ }+ }+ }+ }+ } catch (err) {+ if (err instanceof Error && err.name === "AbortError") {+ cleanup();+ return;+ }++ const streamError =+ err instanceof Error ? err : new Error("Failed to read stream");++ if (retryCountRef.current < MAX_RETRIES) {+ retryCountRef.current += 1;+ const retryDelay =+ INITIAL_RETRY_DELAY * Math.pow(2, retryCountRef.current - 1);++ toast.info("Connection interrupted", {+ description: `Retrying in ${retryDelay / 1000} seconds...`,+ });++ retryTimeoutRef.current = setTimeout(() => {+ sendMessage(+ sessionId,+ message,+ onChunk,+ isUserMessage,+ context,+ true,+ ).catch((_err) => {+ // Retry failed+ });+ }, retryDelay);+ } else {+ setError(streamError);+ toast.error("Connection Failed", {+ description:+ "Unable to connect to chat service. Please try again.",+ });+ cleanup();+ dispatchStreamEnd();+ retryCountRef.current = 0;+ stopStreaming();+ reject(streamError);+ }+ }+ }++ readStream();+ });+ } catch (err) {+ const streamError =+ err instanceof Error ? err : new Error("Failed to start stream");+ setError(streamError);+ setIsStreaming(false);+ throw streamError;+ }+ },+ [stopStreaming],+ );++ return {+ isStreaming,+ error,+ sendMessage,+ stopStreaming,+ };+}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/usePageContext.ts b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/usePageContext.tsnew file mode 100644index 0000000000..c567422a5c--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/chat/components/Chat/usePageContext.ts@@ -0,0 +1,98 @@+import { useCallback } from "react";++export interface PageContext {+ url: string;+ content: string;+}++const MAX_CONTENT_CHARS = 10000;++/**+ * Hook to capture the current page context (URL + full page content)+ * Privacy-hardened: removes sensitive inputs and enforces content size limits+ */+export function usePageContext() {+ const capturePageContext = useCallback((): PageContext => {+ if (typeof window === "undefined" || typeof document === "undefined") {+ return { url: "", content: "" };+ }++ const url = window.location.href;++ // Clone document to avoid modifying the original+ const clone = document.cloneNode(true) as Document;++ // Remove script, style, and noscript elements+ const scripts = clone.querySelectorAll("script, style, noscript");+ scripts.forEach((el) => el.remove());++ // Remove sensitive elements and their content+ const sensitiveSelectors = [+ "input",+ "textarea",+ "[contenteditable]",+ 'input[type="password"]',+ 'input[type="email"]',+ 'input[type="tel"]',+ 'input[type="search"]',+ 'input[type="hidden"]',+ "form",+ "[data-sensitive]",+ "[data-sensitive='true']",+ ];++ sensitiveSelectors.forEach((selector) => {+ const elements = clone.querySelectorAll(selector);+ elements.forEach((el) => {+ // For form elements, remove the entire element+ if (el.tagName === "FORM") {+ el.remove();+ } else {+ // For inputs and textareas, clear their values but keep the element structure+ if (+ el instanceof HTMLInputElement ||+ el instanceof HTMLTextAreaElement+ ) {+ el.value = "";+ el.textContent = "";+ } else {+ // For other sensitive elements, remove them entirely+ el.remove();+ }+ }+ });+ });++ // Strip any remaining input values that might have been missed+ const allInputs = clone.querySelectorAll("input, textarea");+ allInputs.forEach((el) => {+ if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {+ el.value = "";+ el.textContent = "";+ }+ });++ // Get text content from body+ const body = clone.body;+ const content = body?.textContent || body?.innerText || "";++ // Clean up whitespace+ let cleanedContent = content+ .replace(/\s+/g, " ")+ .replace(/\n\s*\n/g, "\n")+ .trim();++ // Enforce maximum content size+ if (cleanedContent.length > MAX_CONTENT_CHARS) {+ cleanedContent =+ cleanedContent.substring(0, MAX_CONTENT_CHARS) + "... [truncated]";+ }++ return {+ url,+ content: cleanedContent,+ };+ }, []);++ return { capturePageContext };+}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatContainer/ChatContainer.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatContainer/ChatContainer.tsxdeleted file mode 100644index 32f9d6c6eb..0000000000--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatContainer/ChatContainer.tsx+++ /dev/null@@ -1,68 +0,0 @@-import { cn } from "@/lib/utils";-import { ChatInput } from "@/app/(platform)/chat/components/ChatInput/ChatInput";-import { MessageList } from "@/app/(platform)/chat/components/MessageList/MessageList";-import { QuickActionsWelcome } from "@/app/(platform)/chat/components/QuickActionsWelcome/QuickActionsWelcome";-import { useChatContainer } from "./useChatContainer";-import type { SessionDetailResponse } from "@/app/api/__generated__/models/sessionDetailResponse";--export interface ChatContainerProps {- sessionId: string | null;- initialMessages: SessionDetailResponse["messages"];- onRefreshSession: () => Promise<void>;- className?: string;-}--export function ChatContainer({- sessionId,- initialMessages,- onRefreshSession,- className,-}: ChatContainerProps) {- const { messages, streamingChunks, isStreaming, sendMessage } =- useChatContainer({- sessionId,- initialMessages,- onRefreshSession,- });-- const quickActions = [- "Find agents for social media management",- "Show me agents for content creation",- "Help me automate my business",- "What can you help me with?",- ];-- return (- <div className={cn("flex h-full flex-col", className)}>- {/* Messages or Welcome Screen */}- {messages.length === 0 ? (- <QuickActionsWelcome- title="Welcome to AutoGPT Chat"- description="Start a conversation to discover and run AI agents."- actions={quickActions}- onActionClick={sendMessage}- disabled={isStreaming || !sessionId}- />- ) : (- <MessageList- messages={messages}- streamingChunks={streamingChunks}- isStreaming={isStreaming}- onSendMessage={sendMessage}- className="flex-1"- />- )}-- {/* Input - Always visible */}- <div className="border-t border-zinc-200 p-4 dark:border-zinc-800">- <ChatInput- onSend={sendMessage}- disabled={isStreaming || !sessionId}- placeholder={- sessionId ? "Type your message..." : "Creating session..."- }- />- </div>- </div>- );-}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatContainer/useChatContainer.ts b/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatContainer/useChatContainer.tsdeleted file mode 100644index c75ad587a5..0000000000--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatContainer/useChatContainer.ts+++ /dev/null@@ -1,130 +0,0 @@-import { useState, useCallback, useRef, useMemo } from "react";-import { toast } from "sonner";-import { useChatStream } from "@/app/(platform)/chat/useChatStream";-import type { SessionDetailResponse } from "@/app/api/__generated__/models/sessionDetailResponse";-import type { ChatMessageData } from "@/app/(platform)/chat/components/ChatMessage/useChatMessage";-import {- parseToolResponse,- isValidMessage,- isToolCallArray,- createUserMessage,- filterAuthMessages,-} from "./helpers";-import { createStreamEventDispatcher } from "./createStreamEventDispatcher";--interface UseChatContainerArgs {- sessionId: string | null;- initialMessages: SessionDetailResponse["messages"];- onRefreshSession: () => Promise<void>;-}--export function useChatContainer({- sessionId,- initialMessages,-}: UseChatContainerArgs) {- const [messages, setMessages] = useState<ChatMessageData[]>([]);- const [streamingChunks, setStreamingChunks] = useState<string[]>([]);- const [hasTextChunks, setHasTextChunks] = useState(false);- const streamingChunksRef = useRef<string[]>([]);- const { error, sendMessage: sendStreamMessage } = useChatStream();- const isStreaming = hasTextChunks;-- const allMessages = useMemo(() => {- const processedInitialMessages = initialMessages- .filter((msg: Record<string, unknown>) => {- if (!isValidMessage(msg)) {- console.warn("Invalid message structure from backend:", msg);- return false;- }- const content = String(msg.content || "").trim();- const toolCalls = msg.tool_calls;- return (- content.length > 0 ||- (toolCalls && Array.isArray(toolCalls) && toolCalls.length > 0)- );- })- .map((msg: Record<string, unknown>) => {- const content = String(msg.content || "");- const role = String(msg.role || "assistant").toLowerCase();- const toolCalls = msg.tool_calls;- if (- role === "assistant" &&- toolCalls &&- isToolCallArray(toolCalls) &&- toolCalls.length > 0- ) {- return null;- }- if (role === "tool") {- const timestamp = msg.timestamp- ? new Date(msg.timestamp as string)- : undefined;- const toolResponse = parseToolResponse(- content,- (msg.tool_call_id as string) || "",- "unknown",- timestamp,- );- if (!toolResponse) {- return null;- }- return toolResponse;- }- return {- type: "message",- role: role as "user" | "assistant" | "system",- content,- timestamp: msg.timestamp- ? new Date(msg.timestamp as string)- : undefined,- };- })- .filter((msg): msg is ChatMessageData => msg !== null);-- return [...processedInitialMessages, ...messages];- }, [initialMessages, messages]);-- const sendMessage = useCallback(- async function sendMessage(content: string, isUserMessage: boolean = true) {- if (!sessionId) {- console.error("Cannot send message: no session ID");- return;- }- if (isUserMessage) {- const userMessage = createUserMessage(content);- setMessages((prev) => [...filterAuthMessages(prev), userMessage]);- } else {- setMessages((prev) => filterAuthMessages(prev));- }- setStreamingChunks([]);- streamingChunksRef.current = [];- setHasTextChunks(false);- const dispatcher = createStreamEventDispatcher({- setHasTextChunks,- setStreamingChunks,- streamingChunksRef,- setMessages,- sessionId,- });- try {- await sendStreamMessage(sessionId, content, dispatcher, isUserMessage);- } catch (err) {- console.error("Failed to send message:", err);- const errorMessage =- err instanceof Error ? err.message : "Failed to send message";- toast.error("Failed to send message", {- description: errorMessage,- });- }- },- [sessionId, sendStreamMessage],- );-- return {- messages: allMessages,- streamingChunks,- isStreaming,- error,- sendMessage,- };-}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatCredentialsSetup/ChatCredentialsSetup.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatCredentialsSetup/ChatCredentialsSetup.tsxdeleted file mode 100644index 3868e17a10..0000000000--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatCredentialsSetup/ChatCredentialsSetup.tsx+++ /dev/null@@ -1,153 +0,0 @@-import { CredentialsInput } from "@/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/CredentialsInput";-import { Card } from "@/components/atoms/Card/Card";-import { Text } from "@/components/atoms/Text/Text";-import type { BlockIOCredentialsSubSchema } from "@/lib/autogpt-server-api";-import { cn } from "@/lib/utils";-import { CheckIcon, KeyIcon, WarningIcon } from "@phosphor-icons/react";-import { useEffect, useRef } from "react";-import { useChatCredentialsSetup } from "./useChatCredentialsSetup";--export interface CredentialInfo {- provider: string;- providerName: string;- credentialType: "api_key" | "oauth2" | "user_password" | "host_scoped";- title: string;- scopes?: string[];-}--interface Props {- credentials: CredentialInfo[];- agentName?: string;- message: string;- onAllCredentialsComplete: () => void;- onCancel: () => void;- className?: string;-}--function createSchemaFromCredentialInfo(- credential: CredentialInfo,-): BlockIOCredentialsSubSchema {- return {- type: "object",- properties: {},- credentials_provider: [credential.provider],- credentials_types: [credential.credentialType],- credentials_scopes: credential.scopes,- discriminator: undefined,- discriminator_mapping: undefined,- discriminator_values: undefined,- };-}--export function ChatCredentialsSetup({- credentials,- agentName: _agentName,- message,- onAllCredentialsComplete,- onCancel: _onCancel,- className,-}: Props) {- const { selectedCredentials, isAllComplete, handleCredentialSelect } =- useChatCredentialsSetup(credentials);-- // Track if we've already called completion to prevent double calls- const hasCalledCompleteRef = useRef(false);-- // Reset the completion flag when credentials change (new credential setup flow)- useEffect(- function resetCompletionFlag() {- hasCalledCompleteRef.current = false;- },- [credentials],- );-- // Auto-call completion when all credentials are configured- useEffect(- function autoCompleteWhenReady() {- if (isAllComplete && !hasCalledCompleteRef.current) {- hasCalledCompleteRef.current = true;- onAllCredentialsComplete();- }- },- [isAllComplete, onAllCredentialsComplete],- );-- return (- <Card- className={cn(- "mx-4 my-2 overflow-hidden border-orange-200 bg-orange-50 dark:border-orange-900 dark:bg-orange-950",- className,- )}- >- <div className="flex items-start gap-4 p-6">- <div className="flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-full bg-orange-500">- <KeyIcon size={24} weight="bold" className="text-white" />- </div>- <div className="flex-1">- <Text- variant="h3"- className="mb-2 text-orange-900 dark:text-orange-100"- >- Credentials Required- </Text>- <Text- variant="body"- className="mb-4 text-orange-700 dark:text-orange-300"- >- {message}- </Text>-- <div className="space-y-3">- {credentials.map((cred, index) => {- const schema = createSchemaFromCredentialInfo(cred);- const isSelected = !!selectedCredentials[cred.provider];-- return (- <div- key={`${cred.provider}-${index}`}- className={cn(- "relative rounded-lg border border-orange-200 bg-white p-4 dark:border-orange-800 dark:bg-orange-900/20",- isSelected &&- "border-green-500 bg-green-50 dark:border-green-700 dark:bg-green-950/30",- )}- >- <div className="mb-2 flex items-center justify-between">- <div className="flex items-center gap-2">- {isSelected ? (- <CheckIcon- size={20}- className="text-green-500"- weight="bold"- />- ) : (- <WarningIcon- size={20}- className="text-orange-500"- weight="bold"- />- )}- <Text- variant="body"- className="font-semibold text-orange-900 dark:text-orange-100"- >- {cred.providerName}- </Text>- </div>- </div>-- <CredentialsInput- schema={schema}- selectedCredentials={selectedCredentials[cred.provider]}- onSelectCredentials={(credMeta) =>- handleCredentialSelect(cred.provider, credMeta)- }- />- </div>- );- })}- </div>- </div>- </div>- </Card>- );-}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatInput/ChatInput.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatInput/ChatInput.tsxdeleted file mode 100644index f1caceef70..0000000000--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatInput/ChatInput.tsx+++ /dev/null@@ -1,63 +0,0 @@-import { cn } from "@/lib/utils";-import { PaperPlaneRightIcon } from "@phosphor-icons/react";-import { Button } from "@/components/atoms/Button/Button";-import { useChatInput } from "./useChatInput";--export interface ChatInputProps {- onSend: (message: string) => void;- disabled?: boolean;- placeholder?: string;- className?: string;-}--export function ChatInput({- onSend,- disabled = false,- placeholder = "Type your message...",- className,-}: ChatInputProps) {- const { value, setValue, handleKeyDown, handleSend, textareaRef } =- useChatInput({- onSend,- disabled,- maxRows: 5,- });-- return (- <div className={cn("flex gap-2", className)}>- <textarea- ref={textareaRef}- value={value}- onChange={(e) => setValue(e.target.value)}- onKeyDown={handleKeyDown}- placeholder={placeholder}- disabled={disabled}- rows={1}- autoComplete="off"- aria-label="Chat message input"- aria-describedby="chat-input-hint"- className={cn(- "flex-1 resize-none rounded-lg border border-neutral-200 bg-white px-4 py-2 text-sm",- "placeholder:text-neutral-400",- "focus:border-violet-600 focus:outline-none focus:ring-2 focus:ring-violet-600/20",- "dark:border-neutral-800 dark:bg-neutral-900 dark:text-neutral-100 dark:placeholder:text-neutral-500",- "disabled:cursor-not-allowed disabled:opacity-50",- )}- />- <span id="chat-input-hint" className="sr-only">- Press Enter to send, Shift+Enter for new line- </span>-- <Button- variant="primary"- size="small"- onClick={handleSend}- disabled={disabled || !value.trim()}- className="self-end"- aria-label="Send message"- >- <PaperPlaneRightIcon className="h-4 w-4" weight="fill" />- </Button>- </div>- );-}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatLoadingState/ChatLoadingState.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatLoadingState/ChatLoadingState.tsxdeleted file mode 100644index 20f2a980f0..0000000000--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatLoadingState/ChatLoadingState.tsx+++ /dev/null@@ -1,31 +0,0 @@-import React from "react";-import { Text } from "@/components/atoms/Text/Text";-import { ArrowClockwiseIcon } from "@phosphor-icons/react";-import { cn } from "@/lib/utils";--export interface ChatLoadingStateProps {- message?: string;- className?: string;-}--export function ChatLoadingState({- message = "Loading...",- className,-}: ChatLoadingStateProps) {- return (- <div- className={cn("flex flex-1 items-center justify-center p-6", className)}- >- <div className="flex flex-col items-center gap-4 text-center">- <ArrowClockwiseIcon- size={32}- weight="bold"- className="animate-spin text-purple-500"- />- <Text variant="body" className="text-zinc-600 dark:text-zinc-400">- {message}- </Text>- </div>- </div>- );-}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatMessage/ChatMessage.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatMessage/ChatMessage.tsxdeleted file mode 100644index 6d8fdacb9a..0000000000--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/ChatMessage/ChatMessage.tsx+++ /dev/null@@ -1,194 +0,0 @@-"use client";--import { cn } from "@/lib/utils";-import { RobotIcon, UserIcon, CheckCircleIcon } from "@phosphor-icons/react";-import { useCallback } from "react";-import { MessageBubble } from "@/app/(platform)/chat/components/MessageBubble/MessageBubble";-import { MarkdownContent } from "@/app/(platform)/chat/components/MarkdownContent/MarkdownContent";-import { ToolCallMessage } from "@/app/(platform)/chat/components/ToolCallMessage/ToolCallMessage";-import { ToolResponseMessage } from "@/app/(platform)/chat/components/ToolResponseMessage/ToolResponseMessage";-import { AuthPromptWidget } from "@/app/(platform)/chat/components/AuthPromptWidget/AuthPromptWidget";-import { ChatCredentialsSetup } from "@/app/(platform)/chat/components/ChatCredentialsSetup/ChatCredentialsSetup";-import { useSupabase } from "@/lib/supabase/hooks/useSupabase";-import { useChatMessage, type ChatMessageData } from "./useChatMessage";-import { getToolActionPhrase } from "@/app/(platform)/chat/helpers";-export interface ChatMessageProps {- message: ChatMessageData;- className?: string;- onDismissLogin?: () => void;- onDismissCredentials?: () => void;- onSendMessage?: (content: string, isUserMessage?: boolean) => void;-}--export function ChatMessage({- message,- className,- onDismissCredentials,- onSendMessage,-}: ChatMessageProps) {- const { user } = useSupabase();- const {- formattedTimestamp,- isUser,- isAssistant,- isToolCall,- isToolResponse,- isLoginNeeded,- isCredentialsNeeded,- } = useChatMessage(message);-- const handleAllCredentialsComplete = useCallback(- function handleAllCredentialsComplete() {- // Send a user message that explicitly asks to retry the setup- // This ensures the LLM calls get_required_setup_info again and proceeds with execution- if (onSendMessage) {- onSendMessage(- "I've configured the required credentials. Please check if everything is ready and proceed with setting up the agent.",- );- }- // Optionally dismiss the credentials prompt- if (onDismissCredentials) {- onDismissCredentials();- }- },- [onSendMessage, onDismissCredentials],- );-- function handleCancelCredentials() {- // Dismiss the credentials prompt- if (onDismissCredentials) {- onDismissCredentials();- }- }-- // Render credentials needed messages- if (isCredentialsNeeded && message.type === "credentials_needed") {- return (- <ChatCredentialsSetup- credentials={message.credentials}- agentName={message.agentName}- message={message.message}- onAllCredentialsComplete={handleAllCredentialsComplete}- onCancel={handleCancelCredentials}- className={className}- />- );- }-- // Render login needed messages- if (isLoginNeeded && message.type === "login_needed") {- // If user is already logged in, show success message instead of auth prompt- if (user) {- return (- <div className={cn("px-4 py-2", className)}>- <div className="my-4 overflow-hidden rounded-lg border border-green-200 bg-gradient-to-br from-green-50 to-emerald-50 dark:border-green-800 dark:from-green-950/30 dark:to-emerald-950/30">- <div className="px-6 py-4">- <div className="flex items-center gap-3">- <div className="flex h-10 w-10 items-center justify-center rounded-full bg-green-600">- <CheckCircleIcon- size={20}- weight="fill"- className="text-white"- />- </div>- <div>- <h3 className="text-lg font-semibold text-neutral-900 dark:text-neutral-100">- Successfully Authenticated- </h3>- <p className="text-sm text-neutral-600 dark:text-neutral-400">- You're now signed in and ready to continue- </p>- </div>- </div>- </div>- </div>- </div>- );- }-- // Show auth prompt if not logged in- return (- <div className={cn("px-4 py-2", className)}>- <AuthPromptWidget- message={message.message}- sessionId={message.sessionId}- agentInfo={message.agentInfo}- returnUrl="/chat"- />- </div>- );- }-- // Render tool call messages- if (isToolCall && message.type === "tool_call") {- return (- <div className={cn("px-4 py-2", className)}>- <ToolCallMessage toolName={message.toolName} />- </div>- );- }-- // Render tool response messages- if (- (isToolResponse && message.type === "tool_response") ||- message.type === "no_results" ||- message.type === "agent_carousel" ||- message.type === "execution_started"- ) {- return (- <div className={cn("px-4 py-2", className)}>- <ToolResponseMessage toolName={getToolActionPhrase(message.toolName)} />- </div>- );- }-- // Render regular chat messages- if (message.type === "message") {- return (- <div- className={cn(- "flex gap-3 px-4 py-4",- isUser && "flex-row-reverse",- className,- )}- >- {/* Avatar */}- <div className="flex-shrink-0">- <div- className={cn(- "flex h-8 w-8 items-center justify-center rounded-full",- isUser && "bg-zinc-200 dark:bg-zinc-700",- isAssistant && "bg-purple-600 dark:bg-purple-500",- )}- >- {isUser ? (- <UserIcon className="h-5 w-5 text-zinc-700 dark:text-zinc-200" />- ) : (- <RobotIcon className="h-5 w-5 text-white" />- )}- </div>- </div>-- {/* Message Content */}- <div className={cn("flex max-w-[70%] flex-col", isUser && "items-end")}>- <MessageBubble variant={isUser ? "user" : "assistant"}>- <MarkdownContent content={message.content} />- </MessageBubble>-- {/* Timestamp */}- <span- className={cn(- "mt-1 text-xs text-zinc-500 dark:text-zinc-400",- isUser && "text-right",- )}- >- {formattedTimestamp}- </span>- </div>- </div>- );- }-- // Fallback for unknown message types- return null;-}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/MessageBubble/MessageBubble.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/MessageBubble/MessageBubble.tsxdeleted file mode 100644index 96798493a1..0000000000--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/MessageBubble/MessageBubble.tsx+++ /dev/null@@ -1,28 +0,0 @@-import { cn } from "@/lib/utils";-import { ReactNode } from "react";--export interface MessageBubbleProps {- children: ReactNode;- variant: "user" | "assistant";- className?: string;-}--export function MessageBubble({- children,- variant,- className,-}: MessageBubbleProps) {- return (- <div- className={cn(- "rounded-lg px-4 py-3 text-sm",- variant === "user" && "bg-violet-600 text-white dark:bg-violet-500",- variant === "assistant" &&- "border border-neutral-200 bg-white dark:border-neutral-700 dark:bg-neutral-900 dark:text-neutral-100",- className,- )}- >- {children}- </div>- );-}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/MessageList/MessageList.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/MessageList/MessageList.tsxdeleted file mode 100644index aa8c4d9772..0000000000--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/MessageList/MessageList.tsx+++ /dev/null@@ -1,61 +0,0 @@-import { cn } from "@/lib/utils";-import { ChatMessage } from "../ChatMessage/ChatMessage";-import type { ChatMessageData } from "../ChatMessage/useChatMessage";-import { StreamingMessage } from "../StreamingMessage/StreamingMessage";-import { useMessageList } from "./useMessageList";--export interface MessageListProps {- messages: ChatMessageData[];- streamingChunks?: string[];- isStreaming?: boolean;- className?: string;- onStreamComplete?: () => void;- onSendMessage?: (content: string) => void;-}--export function MessageList({- messages,- streamingChunks = [],- isStreaming = false,- className,- onStreamComplete,- onSendMessage,-}: MessageListProps) {- const { messagesEndRef, messagesContainerRef } = useMessageList({- messageCount: messages.length,- isStreaming,- });-- return (- <div- ref={messagesContainerRef}- className={cn(- "flex-1 overflow-y-auto",- "scrollbar-thin scrollbar-track-transparent scrollbar-thumb-zinc-300 dark:scrollbar-thumb-zinc-700",- className,- )}- >- <div className="space-y-0">- {/* Render all persisted messages */}- {messages.map((message, index) => (- <ChatMessage- key={index}- message={message}- onSendMessage={onSendMessage}- />- ))}-- {/* Render streaming message if active */}- {isStreaming && streamingChunks.length > 0 && (- <StreamingMessage- chunks={streamingChunks}- onComplete={onStreamComplete}- />- )}-- {/* Invisible div to scroll to */}- <div ref={messagesEndRef} />- </div>- </div>- );-}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/QuickActionsWelcome/QuickActionsWelcome.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/QuickActionsWelcome/QuickActionsWelcome.tsxdeleted file mode 100644index 0cf637542a..0000000000--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/QuickActionsWelcome/QuickActionsWelcome.tsx+++ /dev/null@@ -1,51 +0,0 @@-import React from "react";-import { Text } from "@/components/atoms/Text/Text";-import { cn } from "@/lib/utils";--export interface QuickActionsWelcomeProps {- title: string;- description: string;- actions: string[];- onActionClick: (action: string) => void;- disabled?: boolean;- className?: string;-}--export function QuickActionsWelcome({- title,- description,- actions,- onActionClick,- disabled = false,- className,-}: QuickActionsWelcomeProps) {- return (- <div- className={cn("flex flex-1 items-center justify-center p-4", className)}- >- <div className="max-w-2xl text-center">- <Text- variant="h2"- className="mb-4 text-3xl font-bold text-zinc-900 dark:text-zinc-100"- >- {title}- </Text>- <Text variant="body" className="mb-8 text-zinc-600 dark:text-zinc-400">- {description}- </Text>- <div className="grid gap-2 sm:grid-cols-2">- {actions.map((action) => (- <button- key={action}- onClick={() => onActionClick(action)}- disabled={disabled}- className="rounded-lg border border-zinc-200 bg-white p-4 text-left text-sm hover:bg-zinc-50 disabled:cursor-not-allowed disabled:opacity-50 dark:border-zinc-800 dark:bg-zinc-900 dark:hover:bg-zinc-800"- >- {action}- </button>- ))}- </div>- </div>- </div>- );-}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/StreamingMessage/StreamingMessage.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/StreamingMessage/StreamingMessage.tsxdeleted file mode 100644index 73b0419740..0000000000--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/StreamingMessage/StreamingMessage.tsx+++ /dev/null@@ -1,42 +0,0 @@-import { cn } from "@/lib/utils";-import { Robot } from "@phosphor-icons/react";-import { MessageBubble } from "@/app/(platform)/chat/components/MessageBubble/MessageBubble";-import { MarkdownContent } from "@/app/(platform)/chat/components/MarkdownContent/MarkdownContent";-import { useStreamingMessage } from "./useStreamingMessage";--export interface StreamingMessageProps {- chunks: string[];- className?: string;- onComplete?: () => void;-}--export function StreamingMessage({- chunks,- className,- onComplete,-}: StreamingMessageProps) {- const { displayText } = useStreamingMessage({ chunks, onComplete });-- return (- <div className={cn("flex gap-3 px-4 py-4", className)}>- {/* Avatar */}- <div className="flex-shrink-0">- <div className="flex h-8 w-8 items-center justify-center rounded-full bg-purple-600 dark:bg-purple-500">- <Robot className="h-5 w-5 text-white" />- </div>- </div>-- {/* Message Content */}- <div className="flex max-w-[70%] flex-col">- <MessageBubble variant="assistant">- <MarkdownContent content={displayText} />- </MessageBubble>-- {/* Timestamp */}- <span className="mt-1 text-xs text-neutral-500 dark:text-neutral-400">- Typing...- </span>- </div>- </div>- );-}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/ToolCallMessage/ToolCallMessage.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/ToolCallMessage/ToolCallMessage.tsxdeleted file mode 100644index c1babc587c..0000000000--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/ToolCallMessage/ToolCallMessage.tsx+++ /dev/null@@ -1,49 +0,0 @@-import React from "react";-import { WrenchIcon } from "@phosphor-icons/react";-import { cn } from "@/lib/utils";-import { getToolActionPhrase } from "@/app/(platform)/chat/helpers";--export interface ToolCallMessageProps {- toolName: string;- className?: string;-}--export function ToolCallMessage({ toolName, className }: ToolCallMessageProps) {- return (- <div- className={cn(- "mx-10 max-w-[70%] overflow-hidden rounded-lg border transition-all duration-200",- "border-neutral-200 dark:border-neutral-700",- "bg-white dark:bg-neutral-900",- "animate-in fade-in-50 slide-in-from-top-1",- className,- )}- >- {/* Header */}- <div- className={cn(- "flex items-center justify-between px-3 py-2",- "bg-gradient-to-r from-neutral-50 to-neutral-100 dark:from-neutral-800/20 dark:to-neutral-700/20",- )}- >- <div className="flex items-center gap-2 overflow-hidden">- <WrenchIcon- size={16}- weight="bold"- className="flex-shrink-0 text-neutral-500 dark:text-neutral-400"- />- <span className="relative inline-block overflow-hidden text-sm font-medium text-neutral-700 dark:text-neutral-300">- {getToolActionPhrase(toolName)}...- <span- className={cn(- "absolute inset-0 bg-gradient-to-r from-transparent via-white/50 to-transparent",- "dark:via-white/20",- "animate-shimmer",- )}- />- </span>- </div>- </div>- </div>- );-}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/components/ToolResponseMessage/ToolResponseMessage.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/components/ToolResponseMessage/ToolResponseMessage.tsxdeleted file mode 100644index fe5d858461..0000000000--- a/autogpt_platform/frontend/src/app/(platform)/chat/components/ToolResponseMessage/ToolResponseMessage.tsx+++ /dev/null@@ -1,52 +0,0 @@-import React from "react";-import { WrenchIcon } from "@phosphor-icons/react";-import { cn } from "@/lib/utils";-import { getToolActionPhrase } from "@/app/(platform)/chat/helpers";--export interface ToolResponseMessageProps {- toolName: string;- success?: boolean;- className?: string;-}--export function ToolResponseMessage({- toolName,- success = true,- className,-}: ToolResponseMessageProps) {- return (- <div- className={cn(- "mx-10 max-w-[70%] overflow-hidden rounded-lg border transition-all duration-200",- success- ? "border-neutral-200 dark:border-neutral-700"- : "border-red-200 dark:border-red-800",- "bg-white dark:bg-neutral-900",- "animate-in fade-in-50 slide-in-from-top-1",- className,- )}- >- {/* Header */}- <div- className={cn(- "flex items-center justify-between px-3 py-2",- "bg-gradient-to-r",- success- ? "from-neutral-50 to-neutral-100 dark:from-neutral-800/20 dark:to-neutral-700/20"- : "from-red-50 to-red-100 dark:from-red-900/20 dark:to-red-800/20",- )}- >- <div className="flex items-center gap-2">- <WrenchIcon- size={16}- weight="bold"- className="text-neutral-500 dark:text-neutral-400"- />- <span className="text-sm font-medium text-neutral-700 dark:text-neutral-300">- {getToolActionPhrase(toolName)}...- </span>- </div>- </div>- </div>- );-}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/page.tsx b/autogpt_platform/frontend/src/app/(platform)/chat/page.tsxindex 09e530c296..9c04e40594 100644--- a/autogpt_platform/frontend/src/app/(platform)/chat/page.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/chat/page.tsx@@ -1,30 +1,17 @@"use client";-import { useChatPage } from "./useChatPage";-import { ChatContainer } from "./components/ChatContainer/ChatContainer";-import { ChatErrorState } from "./components/ChatErrorState/ChatErrorState";-import { ChatLoadingState } from "./components/ChatLoadingState/ChatLoadingState";-import { useGetFlag, Flag } from "@/services/feature-flags/use-get-flag";+import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";import { useRouter } from "next/navigation";import { useEffect } from "react";+import { Chat } from "./components/Chat/Chat";export default function ChatPage() {const isChatEnabled = useGetFlag(Flag.CHAT);const router = useRouter();- const {- messages,- isLoading,- isCreating,- error,- sessionId,- createSession,- clearSession,- refreshSession,- } = useChatPage();useEffect(() => {if (isChatEnabled === false) {- router.push("/404");+ router.push("/marketplace");}}, [isChatEnabled, router]);@@ -34,50 +21,7 @@ export default function ChatPage() {return (<div className="flex h-full flex-col">- {/* Header */}- <header className="border-b border-zinc-200 bg-white p-4 dark:border-zinc-800 dark:bg-zinc-900">- <div className="container mx-auto flex items-center justify-between">- <h1 className="text-xl font-semibold">Chat</h1>- {sessionId && (- <div className="flex items-center gap-4">- <span className="text-sm text-zinc-600 dark:text-zinc-400">- Session: {sessionId.slice(0, 8)}...- </span>- <button- onClick={clearSession}- className="text-sm text-zinc-600 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-zinc-100"- >- New Chat- </button>- </div>- )}- </div>- </header>-- {/* Main Content */}- <main className="container mx-auto flex flex-1 flex-col overflow-hidden">- {/* Loading State - show when explicitly loading/creating OR when we don't have a session yet and no error */}- {(isLoading || isCreating || (!sessionId && !error)) && (- <ChatLoadingState- message={isCreating ? "Creating session..." : "Loading..."}- />- )}-- {/* Error State */}- {error && !isLoading && (- <ChatErrorState error={error} onRetry={createSession} />- )}-- {/* Session Content */}- {sessionId && !isLoading && !error && (- <ChatContainer- sessionId={sessionId}- initialMessages={messages}- onRefreshSession={refreshSession}- className="flex-1"- />- )}- </main>+ <Chat className="flex-1" /></div>);}diff --git a/autogpt_platform/frontend/src/app/(platform)/chat/useChatStream.ts b/autogpt_platform/frontend/src/app/(platform)/chat/useChatStream.tsdeleted file mode 100644index 40455e9979..0000000000--- a/autogpt_platform/frontend/src/app/(platform)/chat/useChatStream.ts+++ /dev/null@@ -1,204 +0,0 @@-import { useState, useCallback, useRef, useEffect } from "react";-import { toast } from "sonner";-import type { ToolArguments, ToolResult } from "@/types/chat";--const MAX_RETRIES = 3;-const INITIAL_RETRY_DELAY = 1000;--export interface StreamChunk {- type:- | "text_chunk"- | "text_ended"- | "tool_call"- | "tool_call_start"- | "tool_response"- | "login_needed"- | "need_login"- | "credentials_needed"- | "error"- | "usage"- | "stream_end";- timestamp?: string;- content?: string;- message?: string;- tool_id?: string;- tool_name?: string;- arguments?: ToolArguments;- result?: ToolResult;- success?: boolean;- idx?: number;- session_id?: string;- agent_info?: {- graph_id: string;- name: string;- trigger_type: string;- };- provider?: string;- provider_name?: string;- credential_type?: string;- scopes?: string[];- title?: string;- [key: string]: unknown;-}--export function useChatStream() {- const [isStreaming, setIsStreaming] = useState(false);- const [error, setError] = useState<Error | null>(null);- const eventSourceRef = useRef<EventSource | null>(null);- const retryCountRef = useRef<number>(0);- const retryTimeoutRef = useRef<NodeJS.Timeout | null>(null);- const abortControllerRef = useRef<AbortController | null>(null);-- const stopStreaming = useCallback(() => {- if (abortControllerRef.current) {- abortControllerRef.current.abort();- abortControllerRef.current = null;- }- if (eventSourceRef.current) {- eventSourceRef.current.close();- eventSourceRef.current = null;- }- if (retryTimeoutRef.current) {- clearTimeout(retryTimeoutRef.current);- retryTimeoutRef.current = null;- }- retryCountRef.current = 0;- setIsStreaming(false);- }, []);-- useEffect(() => {- return () => {- stopStreaming();- };- }, [stopStreaming]);-- const sendMessage = useCallback(- async (- sessionId: string,- message: string,- onChunk: (chunk: StreamChunk) => void,- isUserMessage: boolean = true,- ) => {- stopStreaming();-- const abortController = new AbortController();- abortControllerRef.current = abortController;-- if (abortController.signal.aborted) {- return Promise.reject(new Error("Request aborted"));- }-- retryCountRef.current = 0;- setIsStreaming(true);- setError(null);-- try {- const url = `/api/chat/sessions/${sessionId}/stream?message=${encodeURIComponent(- message,- )}&is_user_message=${isUserMessage}`;-- const eventSource = new EventSource(url);- eventSourceRef.current = eventSource;-- abortController.signal.addEventListener("abort", () => {- eventSource.close();- eventSourceRef.current = null;- });-- return new Promise<void>((resolve, reject) => {- const cleanup = () => {- eventSource.removeEventListener("message", messageHandler);- eventSource.removeEventListener("error", errorHandler);- };-- const messageHandler = (event: MessageEvent) => {- try {- const chunk = JSON.parse(event.data) as StreamChunk;-- if (retryCountRef.current > 0) {- retryCountRef.current = 0;- }-- // Call the chunk handler- onChunk(chunk);-- // Handle stream lifecycle- if (chunk.type === "stream_end") {- cleanup();- stopStreaming();- resolve();- } else if (chunk.type === "error") {- cleanup();- reject(- new Error(chunk.message || chunk.content || "Stream error"),- );- }- } catch (err) {- const parseError =- err instanceof Error- ? err- : new Error("Failed to parse stream chunk");- setError(parseError);- cleanup();- reject(parseError);- }- };-- const errorHandler = () => {- if (eventSourceRef.current) {- eventSourceRef.current.close();- eventSourceRef.current = null;- }-- if (retryCountRef.current < MAX_RETRIES) {- retryCountRef.current += 1;- const retryDelay =- INITIAL_RETRY_DELAY * Math.pow(2, retryCountRef.current - 1);-- toast.info("Connection interrupted", {- description: `Retrying in ${retryDelay / 1000} seconds...`,- });-- retryTimeoutRef.current = setTimeout(() => {- sendMessage(sessionId, message, onChunk, isUserMessage).catch(- (_err) => {- // Retry failed- },- );- }, retryDelay);- } else {- const streamError = new Error(- "Stream connection failed after multiple retries",- );- setError(streamError);- toast.error("Connection Failed", {- description:- "Unable to connect to chat service. Please try again.",- });- cleanup();- stopStreaming();- reject(streamError);- }- };-- eventSource.addEventListener("message", messageHandler);- eventSource.addEventListener("error", errorHandler);- });- } catch (err) {- const streamError =- err instanceof Error ? err : new Error("Failed to start stream");- setError(streamError);- setIsStreaming(false);- throw streamError;- }- },- [stopStreaming],- );-- return {- isStreaming,- error,- sendMessage,- stopStreaming,- };-}diff --git a/autogpt_platform/frontend/src/app/(platform)/layout.tsx b/autogpt_platform/frontend/src/app/(platform)/layout.tsxindex 2975e7d097..f5e3f3b99b 100644--- a/autogpt_platform/frontend/src/app/(platform)/layout.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/layout.tsx@@ -1,6 +1,6 @@import { Navbar } from "@/components/layout/Navbar/Navbar";-import { AdminImpersonationBanner } from "./admin/components/AdminImpersonationBanner";import { ReactNode } from "react";+import { AdminImpersonationBanner } from "./admin/components/AdminImpersonationBanner";export default function PlatformLayout({ children }: { children: ReactNode }) {return (diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/NewAgentLibraryView.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/NewAgentLibraryView.tsxindex e184bc59f1..b9091584bf 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/NewAgentLibraryView.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/NewAgentLibraryView.tsx@@ -163,7 +163,7 @@ export function NewAgentLibraryView() {return (<>- <div className="mx-4 grid h-full grid-cols-1 gap-0 pt-3 md:ml-4 md:mr-0 md:gap-4 lg:grid-cols-[25%_70%]">+ <div className="mx-4 grid h-full w-full grid-cols-1 gap-0 pt-3 md:ml-4 md:mr-0 md:gap-4 lg:grid-cols-[25%_70%]"><SectionWrap className="mb-3 block"><divclassName={cn(diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/AgentInputsReadOnly/AgentInputsReadOnly.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/AgentInputsReadOnly/AgentInputsReadOnly.tsxindex a66c6ecfc0..88a2be9b34 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/AgentInputsReadOnly/AgentInputsReadOnly.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/AgentInputsReadOnly/AgentInputsReadOnly.tsx@@ -2,9 +2,9 @@import type { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";import { Text } from "@/components/atoms/Text/Text";+import { CredentialsInput } from "@/components/contextual/CredentialsInput/CredentialsInput";+import { isSystemCredential } from "@/components/contextual/CredentialsInput/helpers";import type { CredentialsMetaInput } from "@/lib/autogpt-server-api/types";-import { CredentialsInput } from "../CredentialsInputs/CredentialsInput";-import { isSystemCredential } from "../CredentialsInputs/helpers";import { RunAgentInputs } from "../RunAgentInputs/RunAgentInputs";import { getAgentCredentialsFields, getAgentInputFields } from "./helpers";diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentInputs/RunAgentInputs.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentInputs/RunAgentInputs.tsxindex d3e6fd9669..72d04d634b 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentInputs/RunAgentInputs.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentInputs/RunAgentInputs.tsx@@ -68,9 +68,15 @@ export function RunAgentInputs({type="number"value={value ?? ""}placeholder={placeholder || "Enter number"}- onChange={(e) =>- onChange(Number((e.target as HTMLInputElement).value))- }+ onChange={(e) => {+ const v = (e.target as HTMLInputElement).value;+ if (!v || v.trim() === "") {+ onChange(undefined);+ } else {+ const numValue = Number(v);+ onChange(isNaN(numValue) ? undefined : numValue);+ }+ }}{...props}/>);@@ -125,14 +131,32 @@ export function RunAgentInputs({);break;- case DataType.DATE:+ case DataType.DATE: {+ function normalizeDateValue(val: any): Date | null {+ if (!val) return null;+ if (val instanceof Date) {+ return isNaN(val.getTime()) ? null : val;+ }+ if (typeof val === "string") {+ if (/^\d{4}-\d{2}-\d{2}$/.test(val)) {+ const [y, m, d] = val.split("-").map(Number);+ const date = new Date(y, m - 1, d);+ return isNaN(date.getTime()) ? null : date;+ }+ const date = new Date(val);+ return isNaN(date.getTime()) ? null : date;+ }+ return null;+ }++ const dateValue = normalizeDateValue(value);innerInputElement = (<DSInputid={`${baseId}-date`}label={schema.title ?? placeholder ?? "Date"}hideLabeltype="date"- value={value ? format(value as Date, "yyyy-MM-dd") : ""}+ value={dateValue ? format(dateValue, "yyyy-MM-dd") : ""}onChange={(e) => {const v = (e.target as HTMLInputElement).value;if (!v) onChange(undefined);@@ -146,6 +170,7 @@ export function RunAgentInputs({/>);break;+ }case DataType.TIME:innerInputElement = (diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentModal/components/CredentialsGroupedView/CredentialsGroupedView.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentModal/components/CredentialsGroupedView/CredentialsGroupedView.tsxindex 05b2966af7..2ae159e739 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentModal/components/CredentialsGroupedView/CredentialsGroupedView.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentModal/components/CredentialsGroupedView/CredentialsGroupedView.tsx@@ -1,4 +1,4 @@-import { CredentialsInput } from "@/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/CredentialsInput";+import { CredentialsInput } from "@/components/contextual/CredentialsInput/CredentialsInput";import {Accordion,AccordionContent,diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentModal/components/helpers.ts b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentModal/components/helpers.tsindex 61267f733d..72f0fcb451 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentModal/components/helpers.ts+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentModal/components/helpers.ts@@ -1,5 +1,5 @@import { CredentialsProvidersContextType } from "@/providers/agent-credentials/credentials-provider";-import { getSystemCredentials } from "../../CredentialsInputs/helpers";+import { getSystemCredentials } from "../../../../../../../../../../../components/contextual/CredentialsInput/helpers";export type CredentialField = [string, any];diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentModal/useAgentRunModal.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentModal/useAgentRunModal.tsxindex 3aafd4be50..c867b11098 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentModal/useAgentRunModal.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentModal/useAgentRunModal.tsx@@ -22,7 +22,7 @@ import {useRef,useState,} from "react";-import { getSystemCredentials } from "../CredentialsInputs/helpers";+import { getSystemCredentials } from "../../../../../../../../../../components/contextual/CredentialsInput/helpers";import { showExecutionErrorToast } from "./errorHelpers";export type RunVariant =diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedRunView/components/RunOutputs.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedRunView/components/RunOutputs.tsxindex 20e218abb2..9824283c40 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedRunView/components/RunOutputs.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedRunView/components/RunOutputs.tsx@@ -3,12 +3,12 @@import type {OutputMetadata,OutputRenderer,-} from "@/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/OutputRenderers";+} from "@/components/contextual/OutputRenderers";import {globalRegistry,OutputActions,OutputItem,-} from "@/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/OutputRenderers";+} from "@/components/contextual/OutputRenderers";import React, { useMemo } from "react";type OutputsRecord = Record<string, Array<unknown>>;diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedTemplateView/SelectedTemplateView.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedTemplateView/SelectedTemplateView.tsxindex d0c49c2a93..bc411d37e6 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedTemplateView/SelectedTemplateView.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedTemplateView/SelectedTemplateView.tsx@@ -4,11 +4,11 @@ import type { GraphExecutionMeta } from "@/app/api/__generated__/models/graphExeimport type { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";import { Input } from "@/components/atoms/Input/Input";import { ErrorCard } from "@/components/molecules/ErrorCard/ErrorCard";+import { CredentialsInput } from "../../../../../../../../../../components/contextual/CredentialsInput/CredentialsInput";import {getAgentCredentialsFields,getAgentInputFields,} from "../../modals/AgentInputsReadOnly/helpers";-import { CredentialsInput } from "../../modals/CredentialsInputs/CredentialsInput";import { RunAgentInputs } from "../../modals/RunAgentInputs/RunAgentInputs";import { LoadingSelectedContent } from "../LoadingSelectedContent";import { RunDetailCard } from "../RunDetailCard/RunDetailCard";diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedTriggerView/SelectedTriggerView.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedTriggerView/SelectedTriggerView.tsxindex 0d0cdc95cc..74dfbd12c2 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedTriggerView/SelectedTriggerView.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedTriggerView/SelectedTriggerView.tsx@@ -2,12 +2,12 @@import type { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";import { Input } from "@/components/atoms/Input/Input";+import { CredentialsInput } from "@/components/contextual/CredentialsInput/CredentialsInput";import { ErrorCard } from "@/components/molecules/ErrorCard/ErrorCard";import {getAgentCredentialsFields,getAgentInputFields,} from "../../modals/AgentInputsReadOnly/helpers";-import { CredentialsInput } from "../../modals/CredentialsInputs/CredentialsInput";import { RunAgentInputs } from "../../modals/RunAgentInputs/RunAgentInputs";import { LoadingSelectedContent } from "../LoadingSelectedContent";import { RunDetailCard } from "../RunDetailCard/RunDetailCard";diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/OldAgentLibraryView/components/agent-run-draft-view.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/OldAgentLibraryView/components/agent-run-draft-view.tsxindex 1b155543f1..53a7e8b860 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/OldAgentLibraryView/components/agent-run-draft-view.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/OldAgentLibraryView/components/agent-run-draft-view.tsx@@ -12,7 +12,6 @@ import {} from "@/lib/autogpt-server-api";import { useBackendAPI } from "@/lib/autogpt-server-api/context";-import { CredentialsInput } from "@/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/CredentialsInput";import { RunAgentInputs } from "@/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentInputs/RunAgentInputs";import { ScheduleTaskDialog } from "@/app/(platform)/library/agents/[id]/components/OldAgentLibraryView/components/cron-scheduler-dialog";import ActionButtonGroup from "@/components/__legacy__/action-button-group";@@ -30,6 +29,7 @@ import {} from "@/components/__legacy__/ui/icons";import { Input } from "@/components/__legacy__/ui/input";import { Button } from "@/components/atoms/Button/Button";+import { CredentialsInput } from "@/components/contextual/CredentialsInput/CredentialsInput";import { InformationTooltip } from "@/components/molecules/InformationTooltip/InformationTooltip";import {useToast,diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/OldAgentLibraryView/components/agent-run-output-view.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/OldAgentLibraryView/components/agent-run-output-view.tsxindex e55914b4ea..668ac2e215 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/OldAgentLibraryView/components/agent-run-output-view.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/OldAgentLibraryView/components/agent-run-output-view.tsx@@ -11,12 +11,12 @@ import {} from "@/components/__legacy__/ui/card";import LoadingBox from "@/components/__legacy__/ui/loading";-import type { OutputMetadata } from "../../NewAgentLibraryView/components/selected-views/OutputRenderers";+import type { OutputMetadata } from "../../../../../../../../components/contextual/OutputRenderers";import {globalRegistry,OutputActions,OutputItem,-} from "../../NewAgentLibraryView/components/selected-views/OutputRenderers";+} from "../../../../../../../../components/contextual/OutputRenderers";export function AgentRunOutputView({agentRunOutputs,diff --git a/autogpt_platform/frontend/src/app/api/chat/sessions/[sessionId]/stream/route.ts b/autogpt_platform/frontend/src/app/api/chat/sessions/[sessionId]/stream/route.tsindex ca33483587..d63eed0ca2 100644--- a/autogpt_platform/frontend/src/app/api/chat/sessions/[sessionId]/stream/route.ts+++ b/autogpt_platform/frontend/src/app/api/chat/sessions/[sessionId]/stream/route.ts@@ -4,8 +4,91 @@ import { NextRequest } from "next/server";/*** SSE Proxy for chat streaming.- * EventSource doesn't support custom headers, so we need a server-side proxy- * that adds authentication and forwards the SSE stream to the client.+ * Supports POST with context (page content + URL) in the request body.+ */+export async function POST(+ request: NextRequest,+ { params }: { params: Promise<{ sessionId: string }> },+) {+ const { sessionId } = await params;++ try {+ const body = await request.json();+ const { message, is_user_message, context } = body;++ if (!message) {+ return new Response(+ JSON.stringify({ error: "Missing message parameter" }),+ { status: 400, headers: { "Content-Type": "application/json" } },+ );+ }++ // Get auth token from server-side session+ const token = await getServerAuthToken();++ // Build backend URL+ const backendUrl = environment.getAGPTServerBaseUrl();+ const streamUrl = new URL(+ `/api/chat/sessions/${sessionId}/stream`,+ backendUrl,+ );++ // Forward request to backend with auth header+ const headers: Record<string, string> = {+ "Content-Type": "application/json",+ Accept: "text/event-stream",+ "Cache-Control": "no-cache",+ Connection: "keep-alive",+ };++ if (token) {+ headers["Authorization"] = `Bearer ${token}`;+ }++ const response = await fetch(streamUrl.toString(), {+ method: "POST",+ headers,+ body: JSON.stringify({+ message,+ is_user_message: is_user_message ?? true,+ context: context || null,+ }),+ });++ if (!response.ok) {+ const error = await response.text();+ return new Response(error, {+ status: response.status,+ headers: { "Content-Type": "application/json" },+ });+ }++ // Return the SSE stream directly+ return new Response(response.body, {+ headers: {+ "Content-Type": "text/event-stream",+ "Cache-Control": "no-cache, no-transform",+ Connection: "keep-alive",+ "X-Accel-Buffering": "no",+ },+ });+ } catch (error) {+ console.error("SSE proxy error:", error);+ return new Response(+ JSON.stringify({+ error: "Failed to connect to chat service",+ detail: error instanceof Error ? error.message : String(error),+ }),+ {+ status: 500,+ headers: { "Content-Type": "application/json" },+ },+ );+ }+}++/**+ * Legacy GET endpoint for backward compatibility*/export async function GET(request: NextRequest,diff --git a/autogpt_platform/frontend/src/app/globals.css b/autogpt_platform/frontend/src/app/globals.cssindex 1f782f753b..0625c26082 100644--- a/autogpt_platform/frontend/src/app/globals.css+++ b/autogpt_platform/frontend/src/app/globals.css@@ -141,6 +141,52 @@}}+@keyframes shimmer {+ 0% {+ background-position: -200% 0;+ }+ 100% {+ background-position: 200% 0;+ }+}++@keyframes l3 {+ 25% {+ background-position:+ 0 0,+ 100% 100%,+ 100% calc(100% - 5px);+ }+ 50% {+ background-position:+ 0 100%,+ 100% 100%,+ 0 calc(100% - 5px);+ }+ 75% {+ background-position:+ 0 100%,+ 100% 0,+ 100% 5px;+ }+}++.loader {+ width: 80px;+ height: 70px;+ border: 5px solid rgb(241 245 249);+ padding: 0 8px;+ box-sizing: border-box;+ background:+ linear-gradient(rgb(15 23 42) 0 0) 0 0/8px 20px,+ linear-gradient(rgb(15 23 42) 0 0) 100% 0/8px 20px,+ radial-gradient(farthest-side, rgb(15 23 42) 90%, #0000) 0 5px/8px 8px+ content-box,+ transparent;+ background-repeat: no-repeat;+ animation: l3 2s infinite linear;+}+input[type="number"]::-webkit-outer-spin-button,input[type="number"]::-webkit-inner-spin-button {-webkit-appearance: none;diff --git a/autogpt_platform/frontend/src/app/layout.tsx b/autogpt_platform/frontend/src/app/layout.tsxindex 453f816dee..1836b1d4f2 100644--- a/autogpt_platform/frontend/src/app/layout.tsx+++ b/autogpt_platform/frontend/src/app/layout.tsx@@ -54,7 +54,7 @@ export default async function RootLayout({}}/></head>- <body>+ <body className="min-h-screen"><ErrorBoundary context="application"><Providersattribute="class"diff --git a/autogpt_platform/frontend/src/components/atoms/Input/Input.tsx b/autogpt_platform/frontend/src/components/atoms/Input/Input.tsxindex f59c01e77d..413ecf5d33 100644--- a/autogpt_platform/frontend/src/components/atoms/Input/Input.tsx+++ b/autogpt_platform/frontend/src/components/atoms/Input/Input.tsx@@ -92,7 +92,7 @@ export function Input({className={cn(baseStyles,errorStyles,- "-mb-1 h-auto min-h-[2.875rem] rounded-medium",+ "-mb-1 h-auto min-h-[2.875rem] rounded-3xl",// Size variants for textareasize === "small" && ["min-h-[2.25rem]", // 36px minimum@@ -107,6 +107,11 @@ export function Input({)}placeholder={placeholder || label}onChange={handleTextareaChange}+ onKeyDown={+ props.onKeyDown as+ | React.KeyboardEventHandler<HTMLTextAreaElement>+ | undefined+ }rows={props.rows || 3}{...(hideLabel ? { "aria-label": label } : {})}id={props.id}diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/CredentialsInput.tsx b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/CredentialsInput.tsxsimilarity index 99%rename from autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/CredentialsInput.tsxrename to autogpt_platform/frontend/src/components/contextual/CredentialsInput/CredentialsInput.tsxindex 7fc88c1488..eba814fe08 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/CredentialsInput.tsx+++ b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/CredentialsInput.tsx@@ -1,3 +1,5 @@+"use client";+import { Text } from "@/components/atoms/Text/Text";import {BlockIOCredentialsSubSchema,diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/components/APIKeyCredentialsModal/APIKeyCredentialsModal.tsx b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/APIKeyCredentialsModal/APIKeyCredentialsModal.tsxsimilarity index 100%rename from autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/components/APIKeyCredentialsModal/APIKeyCredentialsModal.tsxrename to autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/APIKeyCredentialsModal/APIKeyCredentialsModal.tsxdiff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/components/APIKeyCredentialsModal/useAPIKeyCredentialsModal.ts b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/APIKeyCredentialsModal/useAPIKeyCredentialsModal.tssimilarity index 100%rename from autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/components/APIKeyCredentialsModal/useAPIKeyCredentialsModal.tsrename to autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/APIKeyCredentialsModal/useAPIKeyCredentialsModal.tsdiff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/components/CredentialRow/CredentialRow.tsx b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/CredentialRow/CredentialRow.tsxsimilarity index 100%rename from autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/components/CredentialRow/CredentialRow.tsxrename to autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/CredentialRow/CredentialRow.tsxdiff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/components/CredentialsAccordionView/CredentialsAccordionView.tsx b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/CredentialsAccordionView/CredentialsAccordionView.tsxsimilarity index 100%rename from autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/components/CredentialsAccordionView/CredentialsAccordionView.tsxrename to autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/CredentialsAccordionView/CredentialsAccordionView.tsxdiff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/components/CredentialsFlatView/CredentialsFlatView.tsx b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/CredentialsFlatView/CredentialsFlatView.tsxsimilarity index 100%rename from autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/components/CredentialsFlatView/CredentialsFlatView.tsxrename to autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/CredentialsFlatView/CredentialsFlatView.tsxdiff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/components/CredentialsSelect/CredentialsSelect.tsx b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/CredentialsSelect/CredentialsSelect.tsxsimilarity index 100%rename from autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/components/CredentialsSelect/CredentialsSelect.tsxrename to autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/CredentialsSelect/CredentialsSelect.tsxdiff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/components/DeleteConfirmationModal/DeleteConfirmationModal.tsx b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/DeleteConfirmationModal/DeleteConfirmationModal.tsxsimilarity index 100%rename from autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/components/DeleteConfirmationModal/DeleteConfirmationModal.tsxrename to autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/DeleteConfirmationModal/DeleteConfirmationModal.tsxdiff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/components/HotScopedCredentialsModal/HotScopedCredentialsModal.tsx b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/HotScopedCredentialsModal/HotScopedCredentialsModal.tsxsimilarity index 100%rename from autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/components/HotScopedCredentialsModal/HotScopedCredentialsModal.tsxrename to autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/HotScopedCredentialsModal/HotScopedCredentialsModal.tsxdiff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/components/OAuthWaitingModal/OAuthWaitingModal.tsx b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/OAuthWaitingModal/OAuthWaitingModal.tsxsimilarity index 100%rename from autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/components/OAuthWaitingModal/OAuthWaitingModal.tsxrename to autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/OAuthWaitingModal/OAuthWaitingModal.tsxdiff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/components/PasswordCredentialsModal/PasswordCredentialsModal.tsx b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/PasswordCredentialsModal/PasswordCredentialsModal.tsxsimilarity index 100%rename from autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/components/PasswordCredentialsModal/PasswordCredentialsModal.tsxrename to autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/PasswordCredentialsModal/PasswordCredentialsModal.tsxdiff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/helpers.ts b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/helpers.tssimilarity index 100%rename from autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/helpers.tsrename to autogpt_platform/frontend/src/components/contextual/CredentialsInput/helpers.tsdiff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/useCredentialsInput.ts b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/useCredentialsInput.tssimilarity index 100%rename from autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/useCredentialsInput.tsrename to autogpt_platform/frontend/src/components/contextual/CredentialsInput/useCredentialsInput.tsdiff --git a/autogpt_platform/frontend/src/components/contextual/GoogleDrivePicker/GoogleDrivePicker.tsx b/autogpt_platform/frontend/src/components/contextual/GoogleDrivePicker/GoogleDrivePicker.tsxindex 4decd2dbdb..b05bab8a9a 100644--- a/autogpt_platform/frontend/src/components/contextual/GoogleDrivePicker/GoogleDrivePicker.tsx+++ b/autogpt_platform/frontend/src/components/contextual/GoogleDrivePicker/GoogleDrivePicker.tsx@@ -1,7 +1,7 @@"use client";-import { CredentialsInput } from "@/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/CredentialsInput";import { Button } from "@/components/atoms/Button/Button";+import { CredentialsInput } from "@/components/contextual/CredentialsInput/CredentialsInput";import { CircleNotchIcon, FolderOpenIcon } from "@phosphor-icons/react";import {Props as BaseProps,diff --git a/autogpt_platform/frontend/src/components/contextual/OutputRenderers/components/OutputActions.tsx b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/components/OutputActions.tsxnew file mode 100644index 0000000000..cfe69e8709--- /dev/null+++ b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/components/OutputActions.tsx@@ -0,0 +1,106 @@+"use client";++import React, { useState } from "react";+import { CheckIcon, CopyIcon, DownloadIcon } from "@phosphor-icons/react";+import { Button } from "@/components/atoms/Button/Button";+import { OutputRenderer, OutputMetadata } from "../types";+import { downloadOutputs } from "../utils/download";+import { cn } from "@/lib/utils";++interface OutputActionsProps {+ items: Array<{+ value: unknown;+ metadata?: OutputMetadata;+ renderer: OutputRenderer;+ }>;+ isPrimary?: boolean;+ className?: string;+}++export function OutputActions({+ items,+ isPrimary = false,+}: OutputActionsProps) {+ const [copied, setCopied] = useState(false);++ const handleCopyAll = async () => {+ const textContents: string[] = [];++ for (const item of items) {+ const copyContent = item.renderer.getCopyContent(+ item.value,+ item.metadata,+ );+ if (+ copyContent &&+ item.renderer.isConcatenable(item.value, item.metadata)+ ) {+ // For concatenable items, extract the text+ let text: string;+ if (typeof copyContent.data === "string") {+ text = copyContent.data;+ } else if (copyContent.fallbackText) {+ text = copyContent.fallbackText;+ } else {+ continue;+ }+ textContents.push(text);+ }+ }++ if (textContents.length > 0) {+ const combinedText = textContents.join("\n\n");+ try {+ await navigator.clipboard.writeText(combinedText);+ setCopied(true);+ setTimeout(() => setCopied(false), 2000);+ } catch (error) {+ console.error("Failed to copy:", error);+ }+ }+ };++ const handleDownloadAll = () => {+ downloadOutputs(items);+ };++ return (+ <div className="flex items-center gap-3">+ <Button+ variant={isPrimary ? "primary" : "ghost"}+ size={isPrimary ? "small" : "icon"}+ onClick={handleCopyAll}+ aria-label="Copy all text outputs"+ className={cn(isPrimary ? "min-w-0" : "")}+ >+ {copied ? (+ <CheckIcon className="size-4 text-green-600" />+ ) : (+ <CopyIcon+ className={cn(+ "size-4",+ isPrimary ? "text-white" : "text-neutral-500",+ )}+ />+ )}+ {isPrimary && <span>Copy All</span>}+ </Button>++ <Button+ variant={isPrimary ? "primary" : "ghost"}+ size={isPrimary ? "small" : "icon"}+ onClick={handleDownloadAll}+ aria-label="Download outputs"+ className={cn(isPrimary ? "min-w-0" : "")}+ >+ <DownloadIcon+ className={cn(+ "size-4",+ isPrimary ? "text-white" : "text-neutral-500",+ )}+ />+ {isPrimary && <span>Download All</span>}+ </Button>+ </div>+ );+}diff --git a/autogpt_platform/frontend/src/components/contextual/OutputRenderers/components/OutputItem.tsx b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/components/OutputItem.tsxnew file mode 100644index 0000000000..c5c91d5d48--- /dev/null+++ b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/components/OutputItem.tsx@@ -0,0 +1,30 @@+"use client";++import { Text } from "@/components/atoms/Text/Text";+import { OutputMetadata, OutputRenderer } from "../types";++interface OutputItemProps {+ value: any;+ metadata?: OutputMetadata;+ renderer: OutputRenderer;+ label?: string;+}++export function OutputItem({+ value,+ metadata,+ renderer,+ label,+}: OutputItemProps) {+ return (+ <div className="relative">+ {label && (+ <Text variant="large-medium" className="capitalize">+ {label}+ </Text>+ )}++ <div className="relative">{renderer.render(value, metadata)}</div>+ </div>+ );+}diff --git a/autogpt_platform/frontend/src/components/contextual/OutputRenderers/index.ts b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/index.tsnew file mode 100644index 0000000000..ba26054eb2--- /dev/null+++ b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/index.ts@@ -0,0 +1,20 @@+import { globalRegistry } from "./types";+import { textRenderer } from "./renderers/TextRenderer";+import { codeRenderer } from "./renderers/CodeRenderer";+import { imageRenderer } from "./renderers/ImageRenderer";+import { videoRenderer } from "./renderers/VideoRenderer";+import { jsonRenderer } from "./renderers/JSONRenderer";+import { markdownRenderer } from "./renderers/MarkdownRenderer";++// Register all renderers in priority order+globalRegistry.register(videoRenderer);+globalRegistry.register(imageRenderer);+globalRegistry.register(codeRenderer);+globalRegistry.register(markdownRenderer);+globalRegistry.register(jsonRenderer);+globalRegistry.register(textRenderer);++export { globalRegistry };+export type { OutputRenderer, OutputMetadata, DownloadContent } from "./types";+export { OutputItem } from "./components/OutputItem";+export { OutputActions } from "./components/OutputActions";diff --git a/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/CodeRenderer.tsx b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/CodeRenderer.tsxnew file mode 100644index 0000000000..93df7d8ddd--- /dev/null+++ b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/CodeRenderer.tsx@@ -0,0 +1,135 @@+import React from "react";+import {+ OutputRenderer,+ OutputMetadata,+ DownloadContent,+ CopyContent,+} from "../types";++function getFileExtension(language: string): string {+ const extensionMap: Record<string, string> = {+ javascript: "js",+ typescript: "ts",+ python: "py",+ java: "java",+ csharp: "cs",+ cpp: "cpp",+ c: "c",+ html: "html",+ css: "css",+ json: "json",+ xml: "xml",+ yaml: "yaml",+ markdown: "md",+ sql: "sql",+ bash: "sh",+ shell: "sh",+ plaintext: "txt",+ };++ return extensionMap[language.toLowerCase()] || "txt";+}++function canRenderCode(value: unknown, metadata?: OutputMetadata): boolean {+ if (metadata?.type === "code" || metadata?.language) {+ return typeof value === "string";+ }++ if (typeof value !== "string") return false;++ const markdownIndicators = [+ /^#{1,6}\s+/m,+ /\*\*[^*]+\*\*/,+ /\[([^\]]+)\]\(([^)]+)\)/,+ /^>\s+/m,+ /^\s*[-*+]\s+\w+/m,+ /!\[([^\]]*)\]\(([^)]+)\)/,+ ];++ let markdownMatches = 0;+ for (const pattern of markdownIndicators) {+ if (pattern.test(value)) {+ markdownMatches++;+ if (markdownMatches >= 2) {+ return false;+ }+ }+ }++ const codeIndicators = [+ /^(function|const|let|var|class|import|export|if|for|while)\s/m,+ /^def\s+\w+\s*\(/m,+ /^import\s+/m,+ /^from\s+\w+\s+import/m,+ /^\s*<[^>]+>/,+ /[{}[\]();]/,+ ];++ return codeIndicators.some((pattern) => pattern.test(value));+}++function renderCode(+ value: unknown,+ metadata?: OutputMetadata,+): React.ReactNode {+ const codeValue = String(value);+ const language = metadata?.language || "plaintext";++ return (+ <div className="group relative">+ {metadata?.language && (+ <div className="absolute right-2 top-2 rounded bg-background/80 px-2 py-1 text-xs text-muted-foreground">+ {language}+ </div>+ )}+ <pre className="overflow-x-auto rounded-md bg-muted p-3">+ <code className="font-mono text-sm">{codeValue}</code>+ </pre>+ </div>+ );+}++function getCopyContentCode(+ value: unknown,+ _metadata?: OutputMetadata,+): CopyContent | null {+ const codeValue = String(value);+ return {+ mimeType: "text/plain",+ data: codeValue,+ fallbackText: codeValue,+ };+}++function getDownloadContentCode(+ value: unknown,+ metadata?: OutputMetadata,+): DownloadContent | null {+ const codeValue = String(value);+ const language = metadata?.language || "txt";+ const extension = getFileExtension(language);+ const blob = new Blob([codeValue], { type: "text/plain" });++ return {+ data: blob,+ filename: metadata?.filename || `code.${extension}`,+ mimeType: "text/plain",+ };+}++function isConcatenableCode(+ _value: unknown,+ _metadata?: OutputMetadata,+): boolean {+ return true;+}++export const codeRenderer: OutputRenderer = {+ name: "CodeRenderer",+ priority: 30,+ canRender: canRenderCode,+ render: renderCode,+ getCopyContent: getCopyContentCode,+ getDownloadContent: getDownloadContentCode,+ isConcatenable: isConcatenableCode,+};diff --git a/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/ImageRenderer.tsx b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/ImageRenderer.tsxnew file mode 100644index 0000000000..f2a7636c6e--- /dev/null+++ b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/ImageRenderer.tsx@@ -0,0 +1,209 @@+import React from "react";+import {+ OutputRenderer,+ OutputMetadata,+ DownloadContent,+ CopyContent,+} from "../types";++const imageExtensions = [+ ".jpg",+ ".jpeg",+ ".png",+ ".gif",+ ".bmp",+ ".svg",+ ".webp",+ ".ico",+];++const imageMimeTypes = [+ "image/jpeg",+ "image/png",+ "image/gif",+ "image/bmp",+ "image/svg+xml",+ "image/webp",+ "image/x-icon",+];++function guessMimeType(url: string): string | null {+ const extension = url.split(".").pop()?.toLowerCase();+ const mimeMap: Record<string, string> = {+ jpg: "image/jpeg",+ jpeg: "image/jpeg",+ png: "image/png",+ gif: "image/gif",+ bmp: "image/bmp",+ svg: "image/svg+xml",+ webp: "image/webp",+ ico: "image/x-icon",+ };+ return extension ? mimeMap[extension] || null : null;+}++function canRenderImage(value: unknown, metadata?: OutputMetadata): boolean {+ if (+ metadata?.type === "image" ||+ (metadata?.mimeType && imageMimeTypes.includes(metadata.mimeType))+ ) {+ return true;+ }++ if (typeof value === "object" && value !== null) {+ const obj = value as any;+ if (obj.url || obj.data || obj.path) {+ const urlOrData = obj.url || obj.data || obj.path;++ if (typeof urlOrData === "string") {+ if (urlOrData.startsWith("data:image/")) {+ return true;+ }++ if (+ urlOrData.startsWith("http://") ||+ urlOrData.startsWith("https://")+ ) {+ const hasImageExt = imageExtensions.some((ext) =>+ urlOrData.toLowerCase().includes(ext),+ );+ return hasImageExt;+ }+ }+ }++ if (obj.filename) {+ const hasImageExt = imageExtensions.some((ext) =>+ obj.filename.toLowerCase().endsWith(ext),+ );+ return hasImageExt;+ }+ }++ if (typeof value === "string") {+ if (value.startsWith("data:image/")) {+ return true;+ }++ if (value.startsWith("http://") || value.startsWith("https://")) {+ const hasImageExt = imageExtensions.some((ext) =>+ value.toLowerCase().includes(ext),+ );+ return hasImageExt;+ }++ if (metadata?.filename) {+ const hasImageExt = imageExtensions.some((ext) =>+ metadata.filename!.toLowerCase().endsWith(ext),+ );+ return hasImageExt;+ }+ }++ return false;+}++function renderImage(+ value: unknown,+ metadata?: OutputMetadata,+): React.ReactNode {+ const imageUrl = String(value);+ const altText = metadata?.filename || "Output image";++ return (+ <div className="group relative">+ {/* eslint-disable-next-line @next/next/no-img-element */}+ <img+ src={imageUrl}+ alt={altText}+ className="h-auto max-w-full rounded-md border border-gray-200"+ loading="lazy"+ />+ </div>+ );+}++function getCopyContentImage(+ value: unknown,+ metadata?: OutputMetadata,+): CopyContent | null {+ const imageUrl = String(value);++ if (imageUrl.startsWith("data:")) {+ const mimeMatch = imageUrl.match(/data:([^;]+)/);+ const mimeType = mimeMatch?.[1] || "image/png";++ return {+ mimeType: mimeType,+ data: async () => {+ const response = await fetch(imageUrl);+ return await response.blob();+ },+ alternativeMimeTypes: ["image/png", "text/plain"],+ fallbackText: imageUrl,+ };+ }++ const mimeType = metadata?.mimeType || guessMimeType(imageUrl) || "image/png";++ return {+ mimeType: mimeType,+ data: async () => {+ const response = await fetch(imageUrl);+ return await response.blob();+ },+ alternativeMimeTypes: ["image/png", "text/plain"],+ fallbackText: imageUrl,+ };+}++function getDownloadContentImage(+ value: unknown,+ metadata?: OutputMetadata,+): DownloadContent | null {+ const imageUrl = String(value);++ if (imageUrl.startsWith("data:")) {+ const [mimeInfo, base64Data] = imageUrl.split(",");+ const mimeType = mimeInfo.match(/data:([^;]+)/)?.[1] || "image/png";+ const byteCharacters = atob(base64Data);+ const byteNumbers = new Array(byteCharacters.length);++ for (let i = 0; i < byteCharacters.length; i++) {+ byteNumbers[i] = byteCharacters.charCodeAt(i);+ }++ const byteArray = new Uint8Array(byteNumbers);+ const blob = new Blob([byteArray], { type: mimeType });++ const extension = mimeType.split("/")[1] || "png";+ return {+ data: blob,+ filename: metadata?.filename || `image.${extension}`,+ mimeType,+ };+ }++ return {+ data: imageUrl,+ filename: metadata?.filename || "image.png",+ mimeType: metadata?.mimeType || "image/png",+ };+}++function isConcatenableImage(+ _value: unknown,+ _metadata?: OutputMetadata,+): boolean {+ return false;+}++export const imageRenderer: OutputRenderer = {+ name: "ImageRenderer",+ priority: 40,+ canRender: canRenderImage,+ render: renderImage,+ getCopyContent: getCopyContentImage,+ getDownloadContent: getDownloadContentImage,+ isConcatenable: isConcatenableImage,+};diff --git a/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/JSONRenderer.tsx b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/JSONRenderer.tsxnew file mode 100644index 0000000000..668f9179c3--- /dev/null+++ b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/JSONRenderer.tsx@@ -0,0 +1,204 @@+"use client";++import React, { useState } from "react";+import { CaretDown, CaretRight } from "@phosphor-icons/react";+import {+ OutputRenderer,+ OutputMetadata,+ DownloadContent,+ CopyContent,+} from "../types";++function canRenderJSON(value: unknown, _metadata?: OutputMetadata): boolean {+ if (_metadata?.type === "json") {+ return true;+ }++ if (typeof value === "object" && value !== null) {+ return true;+ }++ if (typeof value === "string") {+ try {+ JSON.parse(value);+ return true;+ } catch {+ return false;+ }+ }++ return false;+}++function renderJSON(+ value: unknown,+ _metadata?: OutputMetadata,+): React.ReactNode {+ let jsonData = value;++ if (typeof value === "string") {+ try {+ jsonData = JSON.parse(value);+ } catch {+ return null;+ }+ }++ return <JSONViewer data={jsonData} />;+}++function getCopyContentJSON(+ value: unknown,+ _metadata?: OutputMetadata,+): CopyContent | null {+ const jsonString =+ typeof value === "string" ? value : JSON.stringify(value, null, 2);++ return {+ mimeType: "application/json",+ data: jsonString,+ alternativeMimeTypes: ["text/plain"],+ fallbackText: jsonString,+ };+}++function getDownloadContentJSON(+ value: unknown,+ _metadata?: OutputMetadata,+): DownloadContent | null {+ const jsonString =+ typeof value === "string" ? value : JSON.stringify(value, null, 2);+ const blob = new Blob([jsonString], { type: "application/json" });++ return {+ data: blob,+ filename: _metadata?.filename || "output.json",+ mimeType: "application/json",+ };+}++function isConcatenableJSON(+ _value: unknown,+ _metadata?: OutputMetadata,+): boolean {+ return true;+}++export const jsonRenderer: OutputRenderer = {+ name: "JSONRenderer",+ priority: 20,+ canRender: canRenderJSON,+ render: renderJSON,+ getCopyContent: getCopyContentJSON,+ getDownloadContent: getDownloadContentJSON,+ isConcatenable: isConcatenableJSON,+};++function JSONViewer({ data }: { data: any }) {+ const [collapsed, setCollapsed] = useState<Record<string, boolean>>({});++ const toggleCollapse = (key: string) => {+ setCollapsed((prev) => ({ ...prev, [key]: !prev[key] }));+ };++ const renderValue = (value: any, key: string = ""): React.ReactNode => {+ if (value === null)+ return <span className="text-muted-foreground">null</span>;+ if (value === undefined)+ return <span className="text-muted-foreground">undefined</span>;++ if (typeof value === "boolean") {+ return <span className="text-blue-600">{value.toString()}</span>;+ }++ if (typeof value === "number") {+ return <span className="text-green-600">{value}</span>;+ }++ if (typeof value === "string") {+ return <span className="text-orange-600">"{value}"</span>;+ }++ if (Array.isArray(value)) {+ const isCollapsed = collapsed[key];+ const itemCount = value.length;++ if (itemCount === 0) {+ return <span className="text-muted-foreground">[]</span>;+ }++ return (+ <div className="inline-block">+ <button+ onClick={() => toggleCollapse(key)}+ className="inline-flex items-center rounded px-1 hover:bg-muted"+ >+ {isCollapsed ? (+ <CaretRight className="size-3" />+ ) : (+ <CaretDown className="size-3" />+ )}+ <span className="ml-1 text-muted-foreground">+ Array({itemCount})+ </span>+ </button>+ {!isCollapsed && (+ <div className="ml-4 mt-1">+ {value.map((item, index) => (+ <div key={index} className="flex">+ <span className="mr-2 text-muted-foreground">{index}:</span>+ {renderValue(item, `${key}[${index}]`)}+ </div>+ ))}+ </div>+ )}+ </div>+ );+ }++ if (typeof value === "object") {+ const isCollapsed = collapsed[key];+ const keys = Object.keys(value);++ if (keys.length === 0) {+ return <span className="text-muted-foreground">{"{}"}</span>;+ }++ return (+ <div className="inline-block">+ <button+ onClick={() => toggleCollapse(key)}+ className="inline-flex items-center rounded px-1 hover:bg-muted"+ >+ {isCollapsed ? (+ <CaretRight className="size-3" />+ ) : (+ <CaretDown className="size-3" />+ )}+ <span className="ml-1 text-muted-foreground">Object</span>+ </button>+ {!isCollapsed && (+ <div className="ml-4 mt-1">+ {keys.map((objKey) => (+ <div key={objKey} className="flex">+ <span className="mr-2 text-purple-600">+ "{objKey}":+ </span>+ {renderValue(value[objKey], `${key}.${objKey}`)}+ </div>+ ))}+ </div>+ )}+ </div>+ );+ }++ return <span className="text-muted-foreground">{String(value)}</span>;+ };++ return (+ <div className="overflow-x-auto rounded-md bg-muted p-3 font-mono text-sm">+ {renderValue(data, "root")}+ </div>+ );+}diff --git a/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/MarkdownRenderer.tsx b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/MarkdownRenderer.tsxnew file mode 100644index 0000000000..d94966c6c8--- /dev/null+++ b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/MarkdownRenderer.tsx@@ -0,0 +1,456 @@+"use client";++import React from "react";+import ReactMarkdown from "react-markdown";+import remarkGfm from "remark-gfm";+import remarkMath from "remark-math";+import rehypeKatex from "rehype-katex";+import rehypeHighlight from "rehype-highlight";+import rehypeSlug from "rehype-slug";+import rehypeAutolinkHeadings from "rehype-autolink-headings";+import {+ OutputRenderer,+ OutputMetadata,+ DownloadContent,+ CopyContent,+} from "../types";+import "highlight.js/styles/github-dark.css";+import "katex/dist/katex.min.css";++const markdownPatterns = [+ /```[\s\S]*?```/u, // Fenced code blocks (check first)+ /^#{1,6}\s+\S+/gmu, // ATX headers (require content)+ /\*\*[^*\n]+?\*\*/u, // **bold**+ /__(?!_)[^_\n]+?__(?!_)/u, // __bold__ (avoid ___/snake_case_)+ /(?<!\*)\*(?!\*)(?:[^*\n]|(?<=\\)\*)+?(?<!\\)\*(?!\*)/u, // *italic* (try to avoid **)+ /(?<!_)_(?!_)(?:[^_\n]|(?<=\\)_)+?(?<!\\)_(?!_)/u, // _italic_ with guards+ /\[([^\]\n]+)\]\(([^)\s]+)(?:\s+"[^"]*")?\)/u, // Links with optional title (simple)+ /!\[([^\]\n]*)\]\(([^)\s]+)(?:\s+"[^"]*")?\)/u, // Images with optional title (simple)+ /`[^`\n]+`/u, // Inline code+ /^(?:\s*[-*+]\s+\S.*)(?:\n\s*[-*+]\s+\S.*)+$/gmu, // UL list (≥2 items)+ /^(?:\s*\d+\.\s+\S.*)(?:\n\s*\d+\.\s+\S.*)+$/gmu, // OL list (≥2 items)+ /^>\s+\S.*/gm, // Blockquotes+ /^\|[^|\n]+(\|[^|\n]+)+\|\s*$/gm, // Table row (at least two cells)+ /^\s*\|(?:\s*:?[-=]{3,}\s*\|)+\s*$/gm, // Table separator row+ /\$\$[\s\S]+?\$\$/u, // Display math+ /(?<!\\)(?<!\w)\$[^$\n]+?\$(?!\w)/u, // Inline math: avoid prices/ids+];++const videoExtensions = [".mp4", ".webm", ".ogg", ".mov", ".avi"];++function isVideoUrl(url: string): boolean {+ if (url.includes("youtube.com/watch") || url.includes("youtu.be/")) {+ return true;+ }+ try {+ const parsed = new URL(url);+ if (+ parsed.hostname === "vimeo.com" ||+ parsed.hostname === "www.vimeo.com"+ ) {+ return true;+ }+ } catch {+ // If URL parsing fails, treat as not a Vimeo URL.+ }+ return videoExtensions.some((ext) => url.toLowerCase().includes(ext));+}++function getVideoEmbedUrl(url: string): string | null {+ const youtubeMatch = url.match(+ /(?:youtube\.com\/watch\?v=|youtu\.be\/)([^&\s]+)/,+ );+ if (youtubeMatch) {+ return `https://www.youtube.com/embed/${youtubeMatch[1]}`;+ }++ const vimeoMatch = url.match(/vimeo\.com\/(\d+)/);+ if (vimeoMatch) {+ return `https://player.vimeo.com/video/${vimeoMatch[1]}`;+ }++ if (videoExtensions.some((ext) => url.toLowerCase().includes(ext))) {+ return url;+ }++ return null;+}++function renderVideoEmbed(url: string): React.ReactNode {+ const embedUrl = getVideoEmbedUrl(url);++ if (!embedUrl) {+ return (+ <a+ href={url}+ target="_blank"+ rel="noopener noreferrer"+ className="text-blue-600 underline"+ >+ {url}+ </a>+ );+ }++ if (videoExtensions.some((ext) => embedUrl.toLowerCase().includes(ext))) {+ return (+ <div className="my-4">+ <video+ controls+ className="w-full max-w-2xl rounded-lg shadow-md"+ preload="metadata"+ >+ <source src={embedUrl} />+ Your browser does not support the video tag.+ </video>+ </div>+ );+ }++ return (+ <div className="my-4">+ <div className="relative aspect-video">+ <iframe+ src={embedUrl}+ title="Embedded video player"+ className="absolute left-0 top-0 h-full w-full rounded-lg shadow-md"+ allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"+ allowFullScreen+ />+ </div>+ </div>+ );+}++function canRenderMarkdown(value: unknown, metadata?: OutputMetadata): boolean {+ if (+ metadata?.type === "markdown" ||+ metadata?.mimeType === "text/markdown" ||+ metadata?.mimeType === "text/x-markdown"+ ) {+ return true;+ }++ if (typeof value !== "string") {+ return false;+ }++ if (metadata?.filename?.toLowerCase().endsWith(".md")) {+ return true;+ }++ let matchCount = 0;+ const requiredMatches = 2;++ for (const pattern of markdownPatterns) {+ if (pattern.test(value)) {+ matchCount++;+ if (matchCount >= requiredMatches) {+ return true;+ }+ }+ }++ return false;+}++function renderMarkdown(+ value: unknown,+ _metadata?: OutputMetadata,+): React.ReactNode {+ const markdownContent = String(value);++ return (+ <div className="markdown-output">+ <ReactMarkdown+ className="prose prose-sm dark:prose-invert max-w-none"+ remarkPlugins={[+ remarkGfm, // GitHub Flavored Markdown (tables, task lists, strikethrough)+ [remarkMath, { singleDollarTextMath: false }], // Math support for LaTeX+ ]}+ rehypePlugins={[+ rehypeKatex, // Render math with KaTeX+ rehypeHighlight, // Syntax highlighting for code blocks+ rehypeSlug, // Add IDs to headings+ [rehypeAutolinkHeadings, { behavior: "wrap" }], // Make headings clickable+ ]}+ components={{+ // Custom components for better rendering+ pre: ({ children, ...props }) => (+ <pre+ className="my-4 overflow-x-auto rounded-md bg-gray-900 p-4 dark:bg-gray-950"+ {...props}+ >+ {children}+ </pre>+ ),+ code: ({ children, ...props }: any) => {+ // Check if it's inline code by looking at the parent+ const isInline = !props.className?.includes("language-");+ if (isInline) {+ return (+ <code+ className="rounded bg-gray-100 px-1.5 py-0.5 font-mono text-sm text-gray-800 dark:bg-gray-800 dark:text-gray-200"+ {...props}+ >+ {children}+ </code>+ );+ }+ // Block code is handled by rehype-highlight+ return (+ <code className="font-mono text-sm text-gray-100" {...props}>+ {children}+ </code>+ );+ },+ a: ({ children, href, ...props }) => (+ <a+ href={href}+ target="_blank"+ rel="noopener noreferrer"+ className="text-black underline decoration-1 underline-offset-2 transition-colors"+ {...props}+ >+ {children}+ </a>+ ),+ blockquote: ({ children, ...props }) => (+ <blockquote+ className="my-4 border-l-4 border-blue-500 pl-4 italic text-gray-700 dark:border-blue-400 dark:text-gray-300"+ {...props}+ >+ {children}+ </blockquote>+ ),+ table: ({ children, ...props }) => (+ <div className="my-4 overflow-x-auto">+ <table+ className="min-w-full divide-y divide-gray-200 rounded-lg border border-gray-200 dark:divide-gray-700 dark:border-gray-700"+ {...props}+ >+ {children}+ </table>+ </div>+ ),+ th: ({ children, ...props }) => (+ <th+ className="bg-gray-50 px-4 py-3 text-left text-xs font-semibold uppercase tracking-wider text-gray-700 dark:bg-gray-800 dark:text-gray-300"+ {...props}+ >+ {children}+ </th>+ ),+ td: ({ children, ...props }) => (+ <td+ className="border-t border-gray-200 px-4 py-3 text-sm text-gray-600 dark:border-gray-700 dark:text-gray-400"+ {...props}+ >+ {children}+ </td>+ ),+ // GitHub Flavored Markdown task lists+ input: ({ ...props }: any) => {+ if (props.type === "checkbox") {+ return (+ <input+ type="checkbox"+ className="mr-2 h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500 disabled:cursor-not-allowed disabled:opacity-70"+ disabled+ {...props}+ />+ );+ }+ return <input {...props} />;+ },+ // Better list styling+ ul: ({ children, ...props }: any) => (+ <ul+ className={`my-4 list-disc space-y-2 pl-6 ${+ props.className?.includes("contains-task-list")+ ? "list-none pl-0"+ : ""+ }`}+ {...props}+ >+ {children}+ </ul>+ ),+ ol: ({ children, ...props }) => (+ <ol className="my-4 list-decimal space-y-2 pl-6" {...props}>+ {children}+ </ol>+ ),+ li: ({ children, ...props }: any) => (+ <li+ className={`text-gray-700 dark:text-gray-300 ${+ props.className?.includes("task-list-item")+ ? "flex items-start"+ : ""+ }`}+ {...props}+ >+ {children}+ </li>+ ),+ // Better heading styles+ h1: ({ children, ...props }) => (+ <h1+ className="my-6 text-3xl font-bold text-gray-900 dark:text-gray-100"+ {...props}+ >+ {children}+ </h1>+ ),+ h2: ({ children, ...props }) => (+ <h2+ className="my-5 text-2xl font-semibold text-gray-800 dark:text-gray-200"+ {...props}+ >+ {children}+ </h2>+ ),+ h3: ({ children, ...props }) => (+ <h3+ className="my-4 text-xl font-semibold text-gray-800 dark:text-gray-200"+ {...props}+ >+ {children}+ </h3>+ ),+ h4: ({ children, ...props }) => (+ <h4+ className="my-3 text-lg font-medium text-gray-700 dark:text-gray-300"+ {...props}+ >+ {children}+ </h4>+ ),+ h5: ({ children, ...props }) => (+ <h5+ className="my-2 text-base font-medium text-gray-700 dark:text-gray-300"+ {...props}+ >+ {children}+ </h5>+ ),+ h6: ({ children, ...props }) => (+ <h6+ className="my-2 text-sm font-medium text-gray-600 dark:text-gray-400"+ {...props}+ >+ {children}+ </h6>+ ),+ // Horizontal rule+ hr: ({ ...props }) => (+ <hr+ className="my-6 border-gray-300 dark:border-gray-700"+ {...props}+ />+ ),+ // Strikethrough (GFM)+ del: ({ children, ...props }) => (+ <del+ className="text-gray-500 line-through dark:text-gray-500"+ {...props}+ >+ {children}+ </del>+ ),+ // Image handling+ img: ({ src, alt, ...props }) => {+ // Check if it's a video URL pattern+ if (src && isVideoUrl(src)) {+ return renderVideoEmbed(src);+ }++ return (+ // eslint-disable-next-line @next/next/no-img-element+ <img+ src={src}+ alt={alt}+ className="my-4 h-auto max-w-full rounded-lg shadow-md"+ loading="lazy"+ {...props}+ />+ );+ },+ // Custom paragraph to handle standalone video URLs+ p: ({ children, ...props }) => {+ // Check if paragraph contains just a video URL+ if (typeof children === "string" && isVideoUrl(children.trim())) {+ return renderVideoEmbed(children.trim());+ }++ // Check for video URLs in link children+ if (React.Children.count(children) === 1) {+ const child = React.Children.toArray(children)[0];+ if (React.isValidElement(child) && child.type === "a") {+ const href = child.props.href;+ if (href && isVideoUrl(href)) {+ return renderVideoEmbed(href);+ }+ }+ }++ return (+ <p+ className="my-3 leading-relaxed text-gray-700 dark:text-gray-300"+ {...props}+ >+ {children}+ </p>+ );+ },+ }}+ >+ {markdownContent}+ </ReactMarkdown>+ </div>+ );+}++function getCopyContentMarkdown(+ value: unknown,+ _metadata?: OutputMetadata,+): CopyContent | null {+ const markdownText = String(value);+ return {+ mimeType: "text/markdown",+ data: markdownText,+ fallbackText: markdownText,+ alternativeMimeTypes: ["text/plain"],+ };+}++function getDownloadContentMarkdown(+ value: unknown,+ metadata?: OutputMetadata,+): DownloadContent | null {+ const markdownText = String(value);+ const blob = new Blob([markdownText], { type: "text/markdown" });++ return {+ data: blob,+ filename: metadata?.filename || "output.md",+ mimeType: "text/markdown",+ };+}++function isConcatenableMarkdown(+ _value: unknown,+ _metadata?: OutputMetadata,+): boolean {+ return true;+}++export const markdownRenderer: OutputRenderer = {+ name: "MarkdownRenderer",+ priority: 35,+ canRender: canRenderMarkdown,+ render: renderMarkdown,+ getCopyContent: getCopyContentMarkdown,+ getDownloadContent: getDownloadContentMarkdown,+ isConcatenable: isConcatenableMarkdown,+};diff --git a/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/TextRenderer.tsx b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/TextRenderer.tsxnew file mode 100644index 0000000000..725743fb7e--- /dev/null+++ b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/TextRenderer.tsx@@ -0,0 +1,71 @@+import React from "react";+import {+ OutputRenderer,+ OutputMetadata,+ DownloadContent,+ CopyContent,+} from "../types";++function canRenderText(value: unknown, _metadata?: OutputMetadata): boolean {+ return (+ typeof value === "string" ||+ typeof value === "number" ||+ typeof value === "boolean"+ );+}++function renderText(+ value: unknown,+ _metadata?: OutputMetadata,+): React.ReactNode {+ const textValue = String(value);++ return (+ <p className="resize-none overflow-x-auto whitespace-pre-wrap break-words border-none text-sm text-neutral-700">+ {textValue}+ </p>+ );+}++function getCopyContentText(+ value: unknown,+ _metadata?: OutputMetadata,+): CopyContent | null {+ const textValue = String(value);+ return {+ mimeType: "text/plain",+ data: textValue,+ fallbackText: textValue,+ };+}++function getDownloadContentText(+ value: unknown,+ _metadata?: OutputMetadata,+): DownloadContent | null {+ const textValue = String(value);+ const blob = new Blob([textValue], { type: "text/plain" });++ return {+ data: blob,+ filename: _metadata?.filename || "output.txt",+ mimeType: "text/plain",+ };+}++function isConcatenableText(+ _value: unknown,+ _metadata?: OutputMetadata,+): boolean {+ return true;+}++export const textRenderer: OutputRenderer = {+ name: "TextRenderer",+ priority: 0,+ canRender: canRenderText,+ render: renderText,+ getCopyContent: getCopyContentText,+ getDownloadContent: getDownloadContentText,+ isConcatenable: isConcatenableText,+};diff --git a/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/VideoRenderer.tsx b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/VideoRenderer.tsxnew file mode 100644index 0000000000..bd74eacbd6--- /dev/null+++ b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/renderers/VideoRenderer.tsx@@ -0,0 +1,169 @@+import React from "react";+import {+ OutputRenderer,+ OutputMetadata,+ DownloadContent,+ CopyContent,+} from "../types";++const videoExtensions = [+ ".mp4",+ ".webm",+ ".ogg",+ ".mov",+ ".avi",+ ".mkv",+ ".m4v",+];++const videoMimeTypes = [+ "video/mp4",+ "video/webm",+ "video/ogg",+ "video/quicktime",+ "video/x-msvideo",+ "video/x-matroska",+];++function guessMimeType(url: string): string | null {+ const extension = url.split(".").pop()?.toLowerCase();+ const mimeMap: Record<string, string> = {+ mp4: "video/mp4",+ webm: "video/webm",+ ogg: "video/ogg",+ mov: "video/quicktime",+ avi: "video/x-msvideo",+ mkv: "video/x-matroska",+ m4v: "video/mp4",+ };+ return extension ? mimeMap[extension] || null : null;+}++function canRenderVideo(value: unknown, metadata?: OutputMetadata): boolean {+ if (+ metadata?.type === "video" ||+ (metadata?.mimeType && videoMimeTypes.includes(metadata.mimeType))+ ) {+ return true;+ }++ if (typeof value === "string") {+ if (value.startsWith("data:video/")) {+ return true;+ }++ if (value.startsWith("http://") || value.startsWith("https://")) {+ return videoExtensions.some((ext) => value.toLowerCase().includes(ext));+ }++ if (metadata?.filename) {+ return videoExtensions.some((ext) =>+ metadata.filename!.toLowerCase().endsWith(ext),+ );+ }+ }++ return false;+}++function renderVideo(+ value: unknown,+ metadata?: OutputMetadata,+): React.ReactNode {+ const videoUrl = String(value);++ return (+ <div className="group relative">+ <video+ controls+ className="h-auto max-w-full rounded-md border border-gray-200"+ preload="metadata"+ >+ <source src={videoUrl} type={metadata?.mimeType || "video/mp4"} />+ Your browser does not support the video tag.+ </video>+ </div>+ );+}++function getCopyContentVideo(+ value: unknown,+ metadata?: OutputMetadata,+): CopyContent | null {+ const videoUrl = String(value);++ if (videoUrl.startsWith("data:")) {+ const mimeMatch = videoUrl.match(/data:([^;]+)/);+ const mimeType = mimeMatch?.[1] || "video/mp4";++ return {+ mimeType: mimeType,+ data: videoUrl,+ alternativeMimeTypes: ["text/plain"],+ fallbackText: videoUrl,+ };+ }++ const mimeType = metadata?.mimeType || guessMimeType(videoUrl) || "video/mp4";++ return {+ mimeType: mimeType,+ data: async () => {+ const response = await fetch(videoUrl);+ return await response.blob();+ },+ alternativeMimeTypes: ["text/plain"],+ fallbackText: videoUrl,+ };+}++function getDownloadContentVideo(+ value: unknown,+ metadata?: OutputMetadata,+): DownloadContent | null {+ const videoUrl = String(value);++ if (videoUrl.startsWith("data:")) {+ const [mimeInfo, base64Data] = videoUrl.split(",");+ const mimeType = mimeInfo.match(/data:([^;]+)/)?.[1] || "video/mp4";+ const byteCharacters = atob(base64Data);+ const byteNumbers = new Array(byteCharacters.length);++ for (let i = 0; i < byteCharacters.length; i++) {+ byteNumbers[i] = byteCharacters.charCodeAt(i);+ }++ const byteArray = new Uint8Array(byteNumbers);+ const blob = new Blob([byteArray], { type: mimeType });++ const extension = mimeType.split("/")[1] || "mp4";+ return {+ data: blob,+ filename: metadata?.filename || `video.${extension}`,+ mimeType,+ };+ }++ return {+ data: videoUrl,+ filename: metadata?.filename || "video.mp4",+ mimeType: metadata?.mimeType || "video/mp4",+ };+}++function isConcatenableVideo(+ _value: unknown,+ _metadata?: OutputMetadata,+): boolean {+ return false;+}++export const videoRenderer: OutputRenderer = {+ name: "VideoRenderer",+ priority: 45,+ canRender: canRenderVideo,+ render: renderVideo,+ getCopyContent: getCopyContentVideo,+ getDownloadContent: getDownloadContentVideo,+ isConcatenable: isConcatenableVideo,+};diff --git a/autogpt_platform/frontend/src/components/contextual/OutputRenderers/types.ts b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/types.tsnew file mode 100644index 0000000000..0b2c8ed6bf--- /dev/null+++ b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/types.ts@@ -0,0 +1,60 @@+import { ReactNode } from "react";++export interface OutputMetadata {+ type?: string;+ language?: string;+ mimeType?: string;+ filename?: string;+ [key: string]: any;+}++export interface DownloadContent {+ data: Blob | string;+ filename: string;+ mimeType: string;+}++export interface CopyContent {+ mimeType: string; // Primary MIME type to try+ data: Blob | string | (() => Promise<Blob | string>); // Data or async function to get data+ fallbackText?: string; // Optional fallback text if rich copy fails+ alternativeMimeTypes?: string[]; // Alternative MIME types to try if primary isn't supported+}++export interface OutputRenderer {+ name: string;+ priority: number;+ canRender(value: any, metadata?: OutputMetadata): boolean;+ render(value: any, metadata?: OutputMetadata): ReactNode;+ getCopyContent(value: any, metadata?: OutputMetadata): CopyContent | null;+ getDownloadContent(+ value: any,+ metadata?: OutputMetadata,+ ): DownloadContent | null;+ isConcatenable(value: any, metadata?: OutputMetadata): boolean;+}++export class OutputRendererRegistry {+ private renderers: OutputRenderer[] = [];++ register(renderer: OutputRenderer): void {+ const index = this.renderers.findIndex(+ (r) => r.priority < renderer.priority,+ );+ if (index === -1) {+ this.renderers.push(renderer);+ } else {+ this.renderers.splice(index, 0, renderer);+ }+ }++ getRenderer(value: any, metadata?: OutputMetadata): OutputRenderer | null {+ return this.renderers.find((r) => r.canRender(value, metadata)) || null;+ }++ getAllRenderers(): OutputRenderer[] {+ return [...this.renderers];+ }+}++export const globalRegistry = new OutputRendererRegistry();diff --git a/autogpt_platform/frontend/src/components/contextual/OutputRenderers/utils/copy.ts b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/utils/copy.tsnew file mode 100644index 0000000000..5b18f44669--- /dev/null+++ b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/utils/copy.ts@@ -0,0 +1,115 @@+import { CopyContent } from "../types";++export function isClipboardTypeSupported(mimeType: string): boolean {+ // ClipboardItem.supports() is the proper way to check+ if ("ClipboardItem" in window && "supports" in ClipboardItem) {+ return ClipboardItem.supports(mimeType);+ }++ // Fallback for browsers that don't support the supports() method+ // These are generally supported+ const fallbackSupported = ["text/plain", "text/html", "image/png"];++ return fallbackSupported.includes(mimeType);+}++export function getSupportedClipboardType(+ preferredTypes: string[],+): string | null {+ for (const type of preferredTypes) {+ if (isClipboardTypeSupported(type)) {+ return type;+ }+ }+ return null;+}++export async function copyToClipboard(copyContent: CopyContent): Promise<void> {+ try {+ // Determine the best supported MIME type+ const supportedTypes = [+ copyContent.mimeType,+ ...(copyContent.alternativeMimeTypes || []),+ ];+ const bestType = getSupportedClipboardType(supportedTypes);++ if (!bestType) {+ // No supported type found, use fallback text if available+ if (copyContent.fallbackText) {+ await navigator.clipboard.writeText(copyContent.fallbackText);+ return;+ }+ throw new Error(+ `None of the MIME types are supported: ${supportedTypes.join(", ")}`,+ );+ }++ // Get the data (resolve if it's a function)+ let data = copyContent.data;+ if (typeof data === "function") {+ data = await data();+ }++ // If data is already a Blob, use it directly+ if (data instanceof Blob) {+ // If we need a different MIME type than the blob has, recreate it+ if (bestType !== data.type && bestType !== copyContent.mimeType) {+ data = new Blob([data], { type: bestType });+ }++ await navigator.clipboard.write([+ new ClipboardItem({+ [bestType]: data,+ }),+ ]);+ return;+ }++ // If data is a string+ if (typeof data === "string") {+ // For plain text, use the simpler writeText API+ if (bestType === "text/plain") {+ await navigator.clipboard.writeText(data);+ return;+ }++ // For other text formats (HTML, JSON, etc.), create a blob+ const blob = new Blob([data], { type: bestType });+ await navigator.clipboard.write([+ new ClipboardItem({+ [bestType]: blob,+ }),+ ]);+ }+ } catch (_error) {+ // If rich copy fails and we have fallback text, try that+ if (copyContent.fallbackText) {+ try {+ await navigator.clipboard.writeText(copyContent.fallbackText);+ return;+ } catch {+ // Even fallback failed+ }+ }+ throw _error;+ }+}++export async function fetchAndCopyImage(imageUrl: string): Promise<void> {+ try {+ const response = await fetch(imageUrl);+ if (!response.ok) throw new Error("Failed to fetch image");++ const blob = await response.blob();+ const mimeType = blob.type || "image/png";++ await navigator.clipboard.write([+ new ClipboardItem({+ [mimeType]: blob,+ }),+ ]);+ } catch (_error) {+ // If fetching fails (e.g., CORS), fall back to copying the URL+ await navigator.clipboard.writeText(imageUrl);+ }+}diff --git a/autogpt_platform/frontend/src/components/contextual/OutputRenderers/utils/download.ts b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/utils/download.tsnew file mode 100644index 0000000000..78adda8029--- /dev/null+++ b/autogpt_platform/frontend/src/components/contextual/OutputRenderers/utils/download.ts@@ -0,0 +1,74 @@+import { OutputRenderer, OutputMetadata } from "../types";++export interface DownloadItem {+ value: any;+ metadata?: OutputMetadata;+ renderer: OutputRenderer;+}++export async function downloadOutputs(items: DownloadItem[]) {+ const concatenableTexts: string[] = [];+ const nonConcatenableDownloads: Array<{ blob: Blob; filename: string }> = [];++ for (const item of items) {+ if (item.renderer.isConcatenable(item.value, item.metadata)) {+ const copyContent = item.renderer.getCopyContent(+ item.value,+ item.metadata,+ );+ if (copyContent) {+ // Extract text from CopyContent+ let text: string;+ if (typeof copyContent.data === "string") {+ text = copyContent.data;+ } else if (copyContent.fallbackText) {+ text = copyContent.fallbackText;+ } else {+ continue;+ }+ concatenableTexts.push(text);+ }+ } else {+ const downloadContent = item.renderer.getDownloadContent(+ item.value,+ item.metadata,+ );+ if (downloadContent) {+ if (typeof downloadContent.data === "string") {+ if (downloadContent.data.startsWith("http")) {+ const link = document.createElement("a");+ link.href = downloadContent.data;+ link.download = downloadContent.filename;+ link.click();+ }+ } else {+ nonConcatenableDownloads.push({+ blob: downloadContent.data as Blob,+ filename: downloadContent.filename,+ });+ }+ }+ }+ }++ if (concatenableTexts.length > 0) {+ const combinedText = concatenableTexts.join("\n\n---\n\n");+ const blob = new Blob([combinedText], { type: "text/plain" });+ downloadBlob(blob, "combined_output.txt");+ }++ for (const download of nonConcatenableDownloads) {+ downloadBlob(download.blob, download.filename);+ }+}++function downloadBlob(blob: Blob, filename: string) {+ const url = URL.createObjectURL(blob);+ const link = document.createElement("a");+ link.href = url;+ link.download = filename;+ document.body.appendChild(link);+ link.click();+ document.body.removeChild(link);+ URL.revokeObjectURL(url);+}diff --git a/autogpt_platform/frontend/src/components/contextual/RunAgentInputs/RunAgentInputs.tsx b/autogpt_platform/frontend/src/components/contextual/RunAgentInputs/RunAgentInputs.tsxnew file mode 100644index 0000000000..bc054e42b8--- /dev/null+++ b/autogpt_platform/frontend/src/components/contextual/RunAgentInputs/RunAgentInputs.tsx@@ -0,0 +1,389 @@+import { format } from "date-fns";+import React from "react";++import { Input as DSInput } from "@/components/atoms/Input/Input";+import { Select as DSSelect } from "@/components/atoms/Select/Select";+import { MultiToggle } from "@/components/molecules/MultiToggle/MultiToggle";+// Removed shadcn Select usage in favor of DS Select for time picker+import { Button } from "@/components/atoms/Button/Button";+import { FileInput } from "@/components/atoms/FileInput/FileInput";+import { Switch } from "@/components/atoms/Switch/Switch";+import { GoogleDrivePickerInput } from "@/components/contextual/GoogleDrivePicker/GoogleDrivePickerInput";+import { InformationTooltip } from "@/components/molecules/InformationTooltip/InformationTooltip";+import { TimePicker } from "@/components/molecules/TimePicker/TimePicker";+import {+ BlockIOObjectSubSchema,+ BlockIOSubSchema,+ BlockIOTableSubSchema,+ DataType,+ determineDataType,+ TableRow,+} from "@/lib/autogpt-server-api/types";+import { PlusIcon, XIcon } from "@phosphor-icons/react";+import { useRunAgentInputs } from "./useRunAgentInputs";++/**+ * A generic prop structure for the TypeBasedInput.+ *+ * onChange expects an event-like object with e.target.value so the parent+ * can do something like setInputValues(e.target.value).+ */+interface Props {+ schema: BlockIOSubSchema;+ value?: any;+ placeholder?: string;+ onChange: (value: any) => void;+ readOnly?: boolean;+}++/**+ * A generic, data-type-based input component that uses Shadcn UI.+ * It inspects the schema via `determineDataType` and renders+ * the correct UI component.+ */+export function RunAgentInputs({+ schema,+ value,+ placeholder,+ onChange,+ readOnly = false,+ ...props+}: Props & React.HTMLAttributes<HTMLElement>) {+ const { handleUploadFile, uploadProgress } = useRunAgentInputs();++ const dataType = determineDataType(schema);++ const baseId = String(schema.title ?? "input")+ .replace(/\s+/g, "-")+ .toLowerCase();++ let innerInputElement: React.ReactNode = null;+ switch (dataType) {+ case DataType.NUMBER:+ innerInputElement = (+ <DSInput+ id={`${baseId}-number`}+ label={schema.title ?? placeholder ?? "Number"}+ hideLabel+ type="number"+ value={value ?? ""}+ placeholder={placeholder || "Enter number"}+ onChange={(e) => {+ const v = (e.target as HTMLInputElement).value;+ if (!v || v.trim() === "") {+ onChange(undefined);+ } else {+ const numValue = Number(v);+ onChange(isNaN(numValue) ? undefined : numValue);+ }+ }}+ {...props}+ />+ );+ break;++ case DataType.LONG_TEXT:+ innerInputElement = (+ <DSInput+ id={`${baseId}-textarea`}+ label={schema.title ?? placeholder ?? "Text"}+ hideLabel+ type="textarea"+ rows={3}+ value={value ?? ""}+ placeholder={placeholder || "Enter text"}+ onChange={(e) => onChange((e.target as HTMLInputElement).value)}+ {...props}+ />+ );+ break;++ case DataType.GOOGLE_DRIVE_PICKER: {+ const pickerSchema = schema as any;+ const config: import("@/lib/autogpt-server-api/types").GoogleDrivePickerConfig =+ pickerSchema.google_drive_picker_config || {};++ innerInputElement = (+ <GoogleDrivePickerInput+ config={config}+ value={value}+ onChange={onChange}+ className="w-full"+ showRemoveButton={!readOnly}+ />+ );+ break;+ }++ case DataType.BOOLEAN:+ innerInputElement = (+ <>+ <span className="text-sm text-gray-500">+ {placeholder || (value ? "Enabled" : "Disabled")}+ </span>+ <Switch+ className="ml-auto"+ checked={!!value}+ onCheckedChange={(checked: boolean) => onChange(checked)}+ {...props}+ />+ </>+ );+ break;++ case DataType.DATE: {+ function normalizeDateValue(val: any): Date | null {+ if (!val) return null;+ if (val instanceof Date) {+ return isNaN(val.getTime()) ? null : val;+ }+ if (typeof val === "string") {+ if (/^\d{4}-\d{2}-\d{2}$/.test(val)) {+ const [y, m, d] = val.split("-").map(Number);+ const date = new Date(y, m - 1, d);+ return isNaN(date.getTime()) ? null : date;+ }+ const date = new Date(val);+ return isNaN(date.getTime()) ? null : date;+ }+ return null;+ }++ const dateValue = normalizeDateValue(value);+ innerInputElement = (+ <DSInput+ id={`${baseId}-date`}+ label={schema.title ?? placeholder ?? "Date"}+ hideLabel+ type="date"+ value={dateValue ? format(dateValue, "yyyy-MM-dd") : ""}+ onChange={(e) => {+ const v = (e.target as HTMLInputElement).value;+ if (!v) onChange(undefined);+ else {+ const [y, m, d] = v.split("-").map(Number);+ onChange(new Date(y, m - 1, d));+ }+ }}+ placeholder={placeholder || "Pick a date"}+ {...props}+ />+ );+ break;+ }++ case DataType.TIME:+ innerInputElement = (+ <TimePicker value={value?.toString()} onChange={onChange} />+ );+ break;++ case DataType.DATE_TIME:+ innerInputElement = (+ <DSInput+ id={`${baseId}-datetime`}+ label={schema.title ?? placeholder ?? "Date time"}+ hideLabel+ type="datetime-local"+ value={value ?? ""}+ onChange={(e) => onChange((e.target as HTMLInputElement).value)}+ placeholder={placeholder || "Enter date and time"}+ {...props}+ />+ );+ break;++ case DataType.FILE:+ innerInputElement = (+ <FileInput+ value={value}+ placeholder={placeholder}+ onChange={onChange}+ onUploadFile={handleUploadFile}+ uploadProgress={uploadProgress}+ {...props}+ />+ );+ break;++ case DataType.SELECT:+ if (+ "enum" in schema &&+ Array.isArray(schema.enum) &&+ schema.enum.length > 0+ ) {+ innerInputElement = (+ <DSSelect+ id={`${baseId}-select`}+ label={schema.title ?? placeholder ?? "Select"}+ hideLabel+ value={value ?? ""}+ onValueChange={(val: string) => onChange(val)}+ placeholder={placeholder || "Select an option"}+ options={schema.enum+ .filter((opt) => opt)+ .map((opt) => ({ value: opt, label: String(opt) }))}+ />+ );+ break;+ }++ case DataType.MULTI_SELECT: {+ const _schema = schema as BlockIOObjectSubSchema;+ const properties = _schema.properties || {};+ const allKeys = Object.keys(properties);+ const selectedValues = Object.entries(value || {})+ .filter(([_, v]) => v)+ .map(([k]) => k);++ innerInputElement = (+ <MultiToggle+ items={allKeys.map((key) => ({+ value: key,+ label: properties[key]?.title ?? key,+ }))}+ selectedValues={selectedValues}+ onChange={(values: string[]) =>+ onChange(+ Object.fromEntries(+ allKeys.map((opt) => [opt, values.includes(opt)]),+ ),+ )+ }+ className="nodrag"+ aria-label={schema.title}+ />+ );+ break;+ }++ case DataType.TABLE: {+ // Render a simple table UI for the run modal+ const tableSchema = schema as BlockIOTableSubSchema;+ const headers = tableSchema.items?.properties+ ? Object.keys(tableSchema.items.properties)+ : ["Column 1", "Column 2", "Column 3"];++ const tableData: TableRow[] = Array.isArray(value) ? value : [];++ const updateRow = (index: number, header: string, newValue: string) => {+ const newData = [...tableData];+ if (!newData[index]) {+ newData[index] = {};+ }+ newData[index][header] = newValue;+ onChange(newData);+ };++ const addRow = () => {+ const newRow: TableRow = {};+ headers.forEach((header) => {+ newRow[header] = "";+ });+ onChange([...tableData, newRow]);+ };++ const removeRow = (index: number) => {+ const newData = tableData.filter((_, i) => i !== index);+ onChange(newData);+ };++ innerInputElement = (+ <div className="w-full space-y-2">+ <div className="overflow-hidden rounded-md border">+ <table className="w-full text-sm">+ <thead>+ <tr className="bg-gray-50 dark:bg-gray-800">+ {headers.map((header) => (+ <th+ key={header}+ className="px-3 py-2 text-left font-medium"+ >+ {header}+ </th>+ ))}+ <th className="w-10 px-3 py-2"></th>+ </tr>+ </thead>+ <tbody>+ {tableData.map((row, rowIndex) => (+ <tr key={rowIndex} className="border-t dark:border-gray-700">+ {headers.map((header) => (+ <td key={header} className="px-3 py-1">+ <input+ type="text"+ value={String(row[header] || "")}+ onChange={(e) =>+ updateRow(rowIndex, header, e.target.value)+ }+ className="w-full rounded border px-2 py-1 dark:border-gray-700 dark:bg-gray-900"+ placeholder={`Enter ${header}`}+ />+ </td>+ ))}+ <td className="px-3 py-1">+ <Button+ type="button"+ variant="ghost"+ size="small"+ onClick={() => removeRow(rowIndex)}+ className="h-8 w-8 p-0"+ >+ <XIcon className="h-4 w-4" weight="bold" />+ </Button>+ </td>+ </tr>+ ))}+ </tbody>+ </table>+ </div>+ <Button+ type="button"+ variant="outline"+ size="small"+ onClick={addRow}+ className="w-full"+ >+ <PlusIcon className="mr-2 h-4 w-4" weight="bold" />+ Add Row+ </Button>+ </div>+ );+ break;+ }++ case DataType.SHORT_TEXT:+ default:+ innerInputElement = (+ <DSInput+ id={`${baseId}-text`}+ label={schema.title ?? placeholder ?? "Text"}+ hideLabel+ type="text"+ value={value ?? ""}+ onChange={(e) => onChange((e.target as HTMLInputElement).value)}+ placeholder={placeholder || "Enter text"}+ disabled={readOnly}+ {...props}+ />+ );+ }++ return (+ <div className="flex w-full flex-col gap-0 space-y-2">+ <label className="large-medium flex items-center gap-1 font-medium">+ {schema.title || placeholder}+ <InformationTooltip description={schema.description} />+ </label>+ <div className="no-drag relative flex w-full">+ {readOnly ? (+ <div style={{ pointerEvents: "none", opacity: 0.7 }}>+ {innerInputElement}+ </div>+ ) : (+ innerInputElement+ )}+ </div>+ </div>+ );+}diff --git a/autogpt_platform/frontend/src/components/contextual/RunAgentInputs/useRunAgentInputs.ts b/autogpt_platform/frontend/src/components/contextual/RunAgentInputs/useRunAgentInputs.tsnew file mode 100644index 0000000000..38fe30b9ea--- /dev/null+++ b/autogpt_platform/frontend/src/components/contextual/RunAgentInputs/useRunAgentInputs.ts@@ -0,0 +1,19 @@+import BackendAPI from "@/lib/autogpt-server-api";+import { useState } from "react";++export function useRunAgentInputs() {+ const api = new BackendAPI();+ const [uploadProgress, setUploadProgress] = useState(0);++ async function handleUploadFile(file: File) {+ const result = await api.uploadFile(file, "gcs", 24, (progress) =>+ setUploadProgress(progress),+ );+ return result;+ }++ return {+ uploadProgress,+ handleUploadFile,+ };+}diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/custom/CredentialField/CredentialField.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/custom/CredentialField/CredentialField.tsxindex 6ffd9be3a0..7e34673125 100644--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/custom/CredentialField/CredentialField.tsx+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/custom/CredentialField/CredentialField.tsx@@ -1,6 +1,6 @@import { useNodeStore } from "@/app/(platform)/build/stores/nodeStore";-import { CredentialsInput } from "@/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/CredentialsInputs/CredentialsInput";import { Switch } from "@/components/atoms/Switch/Switch";+import { CredentialsInput } from "@/components/contextual/CredentialsInput/CredentialsInput";import {BlockIOCredentialsSubSchema,CredentialsMetaInput,diff --git a/autogpt_platform/frontend/src/lib/utils.ts b/autogpt_platform/frontend/src/lib/utils.tsindex 94f3d87876..d3abc56b6c 100644--- a/autogpt_platform/frontend/src/lib/utils.ts+++ b/autogpt_platform/frontend/src/lib/utils.ts@@ -496,3 +496,9 @@ export function validateYouTubeUrl(val: string): boolean {return false;}}++export function isValidUUID(value: string): boolean {+ const uuidRegex =+ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;+ return uuidRegex.test(value);+}