removing templates

This commit is contained in:
SwiftyOS
2024-12-10 10:40:23 +01:00
parent 54baa84c28
commit 07d732ece7
7 changed files with 30 additions and 91 deletions

View File

@@ -9,8 +9,7 @@ export default function Home() {
return (
<FlowEditor
className="flow-container"
flowID={query.get("flowID") ?? query.get("templateID") ?? undefined}
template={!!query.get("templateID")}
flowID={query.get("flowID") ?? undefined}
/>
);
}

View File

@@ -70,9 +70,8 @@ export const FlowContext = createContext<FlowContextType | null>(null);
const FlowEditor: React.FC<{
flowID?: string;
template?: boolean;
className?: string;
}> = ({ flowID, template, className }) => {
}> = ({ flowID, className }) => {
const {
addNodes,
addEdges,
@@ -106,7 +105,7 @@ const FlowEditor: React.FC<{
setNodes,
edges,
setEdges,
} = useAgentGraph(flowID, template, visualizeBeads !== "no");
} = useAgentGraph(flowID, visualizeBeads !== "no");
const router = useRouter();
const pathname = usePathname();

View File

@@ -96,19 +96,16 @@ export const AgentImportForm: React.FC<
name: values.agentName,
description: values.agentDescription,
is_active: !values.importAsTemplate,
is_template: values.importAsTemplate,
};
(values.importAsTemplate
? api.createTemplate(payload)
: api.createGraph(payload)
)
(api.createGraph(payload)
)
.then((response) => {
const qID = values.importAsTemplate ? "templateID" : "flowID";
const qID = "flowID";
window.location.href = `/build?${qID}=${response.id}`;
})
.catch((error) => {
const entity_type = values.importAsTemplate ? "template" : "agent";
const entity_type = "agent";
form.setError("root", {
message: `Could not create ${entity_type}: ${error}`,
});
@@ -159,7 +156,6 @@ export const AgentImportForm: React.FC<
setAgentObject(agent);
form.setValue("agentName", agent.name);
form.setValue("agentDescription", agent.description);
form.setValue("importAsTemplate", agent.is_template);
} catch (error) {
console.error("Error loading agent file:", error);
}
@@ -218,19 +214,7 @@ export const AgentImportForm: React.FC<
>
Agent
</span>
<Switch
data-testid="import-as-template-switch"
disabled={field.disabled}
checked={field.value}
onCheckedChange={field.onChange}
/>
<span
className={
field.value ? "" : "text-gray-400 dark:text-gray-600"
}
>
Template
</span>
</div>
</FormControl>
<FormMessage />

View File

@@ -21,17 +21,17 @@ interface SaveControlProps {
agentMeta: GraphMeta | null;
agentName: string;
agentDescription: string;
onSave: (isTemplate: boolean | undefined) => void;
onSave: () => void;
onNameChange: (name: string) => void;
onDescriptionChange: (description: string) => void;
pinSavePopover: boolean;
}
/**
* A SaveControl component to be used within the ControlPanel. It allows the user to save the agent / template.
* A SaveControl component to be used within the ControlPanel. It allows the user to save the agent.
* @param {Object} SaveControlProps - The properties of the SaveControl component.
* @param {GraphMeta | null} SaveControlProps.agentMeta - The agent's metadata, or null if creating a new agent.
* @param {(isTemplate: boolean | undefined) => void} SaveControlProps.onSave - Function to save the agent or template.
* @param {() => void} SaveControlProps.onSave - Function to save the agent.
* @param {(name: string) => void} SaveControlProps.onNameChange - Function to handle name changes.
* @param {(description: string) => void} SaveControlProps.onDescriptionChange - Function to handle description changes.
* @returns The SaveControl component.
@@ -51,15 +51,10 @@ export const SaveControl = ({
* We should migrate this to be handled with form controls and a form library.
*/
// Determines if we're saving a template or an agent
let isTemplate = agentMeta?.is_template ? true : undefined;
const handleSave = useCallback(() => {
onSave(isTemplate);
}, [onSave, isTemplate]);
onSave();
}, [onSave]);
const getType = () => {
return agentMeta?.is_template ? "template" : "agent";
};
const { toast } = useToast();
@@ -159,7 +154,7 @@ export const SaveControl = ({
data-id="save-control-save-agent"
data-testid="save-control-save-agent-button"
>
Save {getType()}
Save Agent
</Button>
</CardFooter>
</Card>

View File

@@ -50,13 +50,15 @@ function AgentDetailContent({ agent }: { agent: AgentDetailResponse }) {
title: "Saving and opening a new agent...",
duration: 2000,
});
const apiUrl =
process.env.NEXT_PUBLIC_AGPT_MARKETPLACE_URL ||
"http://localhost:8015/api/v1/market";
const api = new MarketplaceAPI(apiUrl);
const serverAPIUrl = process.env.NEXT_PUBLIC_AGPT_SERVER_API_URL;
const serverAPI = new AutoGPTServerAPI(serverAPIUrl);
try {
console.debug(`Installing agent with id: ${id}`);
let agent = await api.downloadAgent(id);
@@ -65,13 +67,12 @@ function AgentDetailContent({ agent }: { agent: AgentDetailResponse }) {
id: agent.id,
version: agent.version,
is_active: true,
is_template: false,
name: agent.name,
description: agent.description,
nodes: agent.graph.nodes,
links: agent.graph.links,
};
const result = await serverAPI.createTemplate(data);
const result = await serverAPI.createGraph(data);
makeAnalyticsEvent({
event_name: "agent_installed_from_marketplace",
event_data: {

View File

@@ -89,10 +89,6 @@ export default class BaseAutoGPTServerAPI {
return graphs.map(parseGraphMetaWithRuns);
}
listTemplates(): Promise<GraphMeta[]> {
return this._get("/templates");
}
getGraph(
id: string,
version?: number,
@@ -108,55 +104,27 @@ export default class BaseAutoGPTServerAPI {
return this._get(`/graphs/${id}`, query);
}
getTemplate(id: string, version?: number): Promise<Graph> {
const query = version !== undefined ? `?version=${version}` : "";
return this._get(`/templates/${id}` + query);
}
getGraphAllVersions(id: string): Promise<Graph[]> {
return this._get(`/graphs/${id}/versions`);
}
getTemplateAllVersions(id: string): Promise<Graph[]> {
return this._get(`/templates/${id}/versions`);
}
createGraph(graphCreateBody: GraphCreatable): Promise<Graph>;
createGraph(fromTemplateID: string, templateVersion: number): Promise<Graph>;
createGraph(
graphOrTemplateID: GraphCreatable | string,
templateVersion?: number,
): Promise<Graph> {
let requestBody: GraphCreateRequestBody;
if (typeof graphOrTemplateID == "string") {
if (templateVersion == undefined) {
throw new Error("templateVersion not specified");
}
requestBody = {
template_id: graphOrTemplateID,
template_version: templateVersion,
};
} else {
requestBody = { graph: graphOrTemplateID };
}
createGraph(
graphID: GraphCreatable | string,
): Promise<Graph> {
let requestBody = { graph: graphID } as GraphCreateRequestBody;
return this._request("POST", "/graphs", requestBody);
}
createTemplate(templateCreateBody: GraphCreatable): Promise<Graph> {
const requestBody: GraphCreateRequestBody = { graph: templateCreateBody };
return this._request("POST", "/templates", requestBody);
}
updateGraph(id: string, graph: GraphUpdateable): Promise<Graph> {
return this._request("PUT", `/graphs/${id}`, graph);
}
updateTemplate(id: string, template: GraphUpdateable): Promise<Graph> {
return this._request("PUT", `/templates/${id}`, template);
}
deleteGraph(id: string): Promise<void> {
return this._request("DELETE", `/graphs/${id}`);
}
@@ -647,11 +615,11 @@ export default class BaseAutoGPTServerAPI {
callCount == 0
? this.sendWebSocketMessage(method, data, callCount + 1)
: setTimeout(
() => {
this.sendWebSocketMessage(method, data, callCount + 1);
},
2 ** (callCount - 1) * 1000,
);
() => {
this.sendWebSocketMessage(method, data, callCount + 1);
},
2 ** (callCount - 1) * 1000,
);
});
}
}
@@ -674,14 +642,9 @@ export default class BaseAutoGPTServerAPI {
/* *** UTILITY TYPES *** */
type GraphCreateRequestBody =
| {
template_id: string;
template_version: number;
}
| {
graph: GraphCreatable;
};
type GraphCreateRequestBody = {
graph: GraphCreatable;
};
type WebsocketMessageTypeMap = {
subscribe: { graph_id: string };

View File

@@ -224,14 +224,12 @@ export type GraphUpdateable = Omit<
Graph,
| "version"
| "is_active"
| "is_template"
| "links"
| "input_schema"
| "output_schema"
> & {
version?: number;
is_active?: boolean;
is_template?: boolean;
links: Array<LinkCreatable>;
input_schema?: BlockIOObjectSubSchema;
output_schema?: BlockIOObjectSubSchema;