mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-01-21 04:57:58 -05:00
Compare commits
1 Commits
testing-cl
...
lluisagust
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77dbb18f92 |
@@ -1,33 +1,21 @@
|
||||
"use client";
|
||||
import React, {
|
||||
createContext,
|
||||
useState,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
MouseEvent,
|
||||
Suspense,
|
||||
} from "react";
|
||||
import Link from "next/link";
|
||||
import { BlocksControl } from "@/app/(platform)/build/components/legacy-builder/BlocksControl";
|
||||
import {
|
||||
ReactFlow,
|
||||
ReactFlowProvider,
|
||||
Controls,
|
||||
Background,
|
||||
Node,
|
||||
OnConnect,
|
||||
Connection,
|
||||
MarkerType,
|
||||
NodeChange,
|
||||
EdgeChange,
|
||||
useReactFlow,
|
||||
applyEdgeChanges,
|
||||
applyNodeChanges,
|
||||
} from "@xyflow/react";
|
||||
import "@xyflow/react/dist/style.css";
|
||||
import { CustomNode } from "../CustomNode/CustomNode";
|
||||
import "./flow.css";
|
||||
Control,
|
||||
ControlPanel,
|
||||
} from "@/app/(platform)/build/components/legacy-builder/ControlPanel";
|
||||
import { GraphSearchControl } from "@/app/(platform)/build/components/legacy-builder/GraphSearchControl";
|
||||
import OttoChatWidget from "@/app/(platform)/build/components/legacy-builder/OttoChatWidget";
|
||||
import { SaveControl } from "@/app/(platform)/build/components/legacy-builder/SaveControl";
|
||||
import NewControlPanel from "@/app/(platform)/build/components/NewControlPanel/NewControlPanel";
|
||||
import { IconRedo2, IconUndo2 } from "@/components/__legacy__/ui/icons";
|
||||
import {
|
||||
Alert,
|
||||
AlertDescription,
|
||||
AlertTitle,
|
||||
} from "@/components/molecules/Alert/Alert";
|
||||
import { useToast } from "@/components/molecules/Toast/use-toast";
|
||||
import useAgentGraph from "@/hooks/useAgentGraph";
|
||||
import {
|
||||
BlockUIType,
|
||||
formatEdgeID,
|
||||
@@ -35,35 +23,47 @@ import {
|
||||
GraphID,
|
||||
LibraryAgent,
|
||||
} from "@/lib/autogpt-server-api";
|
||||
import { Key, storage } from "@/services/storage/local-storage";
|
||||
import { findNewlyAddedBlockCoordinates, getTypeColor } from "@/lib/utils";
|
||||
import { history } from "../history";
|
||||
import { CustomEdge } from "../CustomEdge/CustomEdge";
|
||||
import ConnectionLine from "../ConnectionLine";
|
||||
import {
|
||||
Control,
|
||||
ControlPanel,
|
||||
} from "@/app/(platform)/build/components/legacy-builder/ControlPanel";
|
||||
import { SaveControl } from "@/app/(platform)/build/components/legacy-builder/SaveControl";
|
||||
import { BlocksControl } from "@/app/(platform)/build/components/legacy-builder/BlocksControl";
|
||||
import { GraphSearchControl } from "@/app/(platform)/build/components/legacy-builder/GraphSearchControl";
|
||||
import { IconUndo2, IconRedo2 } from "@/components/__legacy__/ui/icons";
|
||||
import {
|
||||
Alert,
|
||||
AlertDescription,
|
||||
AlertTitle,
|
||||
} from "@/components/molecules/Alert/Alert";
|
||||
import { startTutorial } from "../tutorial";
|
||||
import useAgentGraph from "@/hooks/useAgentGraph";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { useRouter, usePathname, useSearchParams } from "next/navigation";
|
||||
import RunnerUIWrapper, { RunnerUIWrapperRef } from "../RunnerUIWrapper";
|
||||
import OttoChatWidget from "@/app/(platform)/build/components/legacy-builder/OttoChatWidget";
|
||||
import { useToast } from "@/components/molecules/Toast/use-toast";
|
||||
import { useCopyPaste } from "../useCopyPaste";
|
||||
import NewControlPanel from "@/app/(platform)/build/components/NewControlPanel/NewControlPanel";
|
||||
import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";
|
||||
import { Key, storage } from "@/services/storage/local-storage";
|
||||
import {
|
||||
applyEdgeChanges,
|
||||
applyNodeChanges,
|
||||
Background,
|
||||
Connection,
|
||||
Controls,
|
||||
EdgeChange,
|
||||
MarkerType,
|
||||
Node,
|
||||
NodeChange,
|
||||
OnConnect,
|
||||
ReactFlow,
|
||||
ReactFlowProvider,
|
||||
useReactFlow,
|
||||
} from "@xyflow/react";
|
||||
import "@xyflow/react/dist/style.css";
|
||||
import Link from "next/link";
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
import React, {
|
||||
createContext,
|
||||
MouseEvent,
|
||||
Suspense,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { BuildActionBar } from "../BuildActionBar";
|
||||
import ConnectionLine from "../ConnectionLine";
|
||||
import { CustomEdge } from "../CustomEdge/CustomEdge";
|
||||
import { CustomNode } from "../CustomNode/CustomNode";
|
||||
import { history } from "../history";
|
||||
import RunnerUIWrapper, { RunnerUIWrapperRef } from "../RunnerUIWrapper";
|
||||
import { startTutorial } from "../tutorial";
|
||||
import { useCopyPaste } from "../useCopyPaste";
|
||||
import "./flow.css";
|
||||
|
||||
// This is for the history, this is the minimum distance a block must move before it is logged
|
||||
// It helps to prevent spamming the history with small movements especially when pressing on a input in a block
|
||||
@@ -762,6 +762,10 @@ const FlowEditor: React.FC<{
|
||||
[],
|
||||
);
|
||||
|
||||
const handleSaveAgent = useCallback(async () => {
|
||||
await saveAgent();
|
||||
}, [saveAgent]);
|
||||
|
||||
const handleRunButton = useCallback(async () => {
|
||||
if (isRunning) return;
|
||||
if (!savedAgent) {
|
||||
@@ -770,8 +774,10 @@ const FlowEditor: React.FC<{
|
||||
});
|
||||
return;
|
||||
}
|
||||
await saveAgent();
|
||||
runnerUIRef.current?.runOrOpenInput();
|
||||
const saved = await saveAgent();
|
||||
if (saved) {
|
||||
runnerUIRef.current?.runOrOpenInput(saved);
|
||||
}
|
||||
}, [isRunning, savedAgent, toast, saveAgent]);
|
||||
|
||||
const handleScheduleButton = useCallback(async () => {
|
||||
@@ -946,7 +952,7 @@ const FlowEditor: React.FC<{
|
||||
<SaveControl
|
||||
agentMeta={savedAgent}
|
||||
canSave={!isSaving && !isRunning && !isStopping}
|
||||
onSave={saveAgent}
|
||||
onSave={handleSaveAgent}
|
||||
agentDescription={agentDescription}
|
||||
onDescriptionChange={setAgentDescription}
|
||||
agentName={agentName}
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
import React, {
|
||||
useState,
|
||||
forwardRef,
|
||||
useImperativeHandle,
|
||||
useMemo,
|
||||
} from "react";
|
||||
import { Node } from "@xyflow/react";
|
||||
import { CustomNodeData } from "@/app/(platform)/build/components/legacy-builder/CustomNode/CustomNode";
|
||||
import {
|
||||
BlockUIType,
|
||||
CredentialsMetaInput,
|
||||
GraphMeta,
|
||||
} from "@/lib/autogpt-server-api/types";
|
||||
import RunnerOutputUI, { OutputNodeInfo } from "./RunnerOutputUI";
|
||||
import { Node } from "@xyflow/react";
|
||||
import { forwardRef, useImperativeHandle, useMemo, useState } from "react";
|
||||
import { RunnerInputDialog } from "./RunnerInputUI";
|
||||
import RunnerOutputUI, { OutputNodeInfo } from "./RunnerOutputUI";
|
||||
|
||||
interface RunnerUIWrapperProps {
|
||||
graph: GraphMeta;
|
||||
@@ -33,7 +28,7 @@ interface RunnerUIWrapperProps {
|
||||
export interface RunnerUIWrapperRef {
|
||||
openRunInputDialog: () => void;
|
||||
openRunnerOutput: () => void;
|
||||
runOrOpenInput: () => void;
|
||||
runOrOpenInput: (graphOverride?: GraphMeta) => void;
|
||||
}
|
||||
|
||||
const RunnerUIWrapper = forwardRef<RunnerUIWrapperRef, RunnerUIWrapperProps>(
|
||||
@@ -43,8 +38,8 @@ const RunnerUIWrapper = forwardRef<RunnerUIWrapperRef, RunnerUIWrapperProps>(
|
||||
) => {
|
||||
const [isRunInputDialogOpen, setIsRunInputDialogOpen] = useState(false);
|
||||
const [isRunnerOutputOpen, setIsRunnerOutputOpen] = useState(false);
|
||||
|
||||
const graphInputs = graph.input_schema.properties;
|
||||
const [graphOverride, setGraphOverride] = useState<GraphMeta | null>(null);
|
||||
const graphToUse = graphOverride || graph;
|
||||
|
||||
const graphOutputs = useMemo((): OutputNodeInfo[] => {
|
||||
const outputNodes = nodes.filter(
|
||||
@@ -71,10 +66,17 @@ const RunnerUIWrapper = forwardRef<RunnerUIWrapperRef, RunnerUIWrapperProps>(
|
||||
const openRunInputDialog = () => setIsRunInputDialogOpen(true);
|
||||
const openRunnerOutput = () => setIsRunnerOutputOpen(true);
|
||||
|
||||
const runOrOpenInput = () => {
|
||||
const runOrOpenInput = (graphOverrideParam?: GraphMeta) => {
|
||||
if (graphOverrideParam) {
|
||||
setGraphOverride(graphOverrideParam);
|
||||
}
|
||||
const graphToCheck = graphOverrideParam || graph;
|
||||
const inputs = graphToCheck.input_schema.properties;
|
||||
const credentials = graphToCheck.credentials_input_schema.properties;
|
||||
|
||||
if (
|
||||
Object.keys(graphInputs).length > 0 ||
|
||||
Object.keys(graph.credentials_input_schema.properties).length > 0
|
||||
Object.keys(inputs).length > 0 ||
|
||||
Object.keys(credentials).length > 0
|
||||
) {
|
||||
openRunInputDialog();
|
||||
} else {
|
||||
@@ -96,8 +98,11 @@ const RunnerUIWrapper = forwardRef<RunnerUIWrapperRef, RunnerUIWrapperProps>(
|
||||
<>
|
||||
<RunnerInputDialog
|
||||
isOpen={isRunInputDialogOpen}
|
||||
doClose={() => setIsRunInputDialogOpen(false)}
|
||||
graph={graph}
|
||||
doClose={() => {
|
||||
setIsRunInputDialogOpen(false);
|
||||
setGraphOverride(null);
|
||||
}}
|
||||
graph={graphToUse}
|
||||
doRun={saveAndRun}
|
||||
doCreateSchedule={createRunSchedule}
|
||||
/>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { CustomEdge } from "@/app/(platform)/build/components/legacy-builder/CustomEdge/CustomEdge";
|
||||
import { CustomNode } from "@/app/(platform)/build/components/legacy-builder/CustomNode/CustomNode";
|
||||
import { getGetV2ListLibraryAgentsQueryKey } from "@/app/api/__generated__/endpoints/library/library";
|
||||
import { useToast } from "@/components/molecules/Toast/use-toast";
|
||||
import {
|
||||
ApiError,
|
||||
@@ -15,20 +16,19 @@ import {
|
||||
GraphMeta,
|
||||
LibraryAgent,
|
||||
LinkCreatable,
|
||||
Node,
|
||||
NodeCreatable,
|
||||
NodeExecutionResult,
|
||||
Node,
|
||||
} from "@/lib/autogpt-server-api";
|
||||
import { useBackendAPI } from "@/lib/autogpt-server-api/context";
|
||||
import { deepEquals, getTypeColor, pruneEmptyValues } from "@/lib/utils";
|
||||
import { useOnboarding } from "@/providers/onboarding/onboarding-provider";
|
||||
import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { MarkerType } from "@xyflow/react";
|
||||
import { default as NextLink } from "next/link";
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";
|
||||
import { useOnboarding } from "@/providers/onboarding/onboarding-provider";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { getGetV2ListLibraryAgentsQueryKey } from "@/app/api/__generated__/endpoints/library/library";
|
||||
|
||||
export default function useAgentGraph(
|
||||
flowID?: GraphID,
|
||||
@@ -734,17 +734,18 @@ export default function useAgentGraph(
|
||||
resetEdgeBeads,
|
||||
]);
|
||||
|
||||
const saveAgent = useCallback(async () => {
|
||||
const saveAgent = useCallback(async (): Promise<Graph | null> => {
|
||||
console.log("saveAgent");
|
||||
setIsSaving(true);
|
||||
try {
|
||||
await _saveAgent();
|
||||
const saved = await _saveAgent();
|
||||
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: getGetV2ListLibraryAgentsQueryKey(),
|
||||
});
|
||||
|
||||
completeStep("BUILDER_SAVE_AGENT");
|
||||
return saved;
|
||||
} catch (error) {
|
||||
const errorMessage =
|
||||
error instanceof Error ? error.message : String(error);
|
||||
@@ -754,10 +755,11 @@ export default function useAgentGraph(
|
||||
title: "Error saving agent",
|
||||
description: errorMessage,
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
}
|
||||
}, [_saveAgent, toast, completeStep]);
|
||||
}, [_saveAgent, toast, completeStep, queryClient]);
|
||||
|
||||
const saveAndRun = useCallback(
|
||||
async (
|
||||
|
||||
Reference in New Issue
Block a user