Merge branch 'master' into ntindle/samples

This commit is contained in:
Nicholas Tindle
2024-09-13 23:35:34 -05:00
committed by GitHub
7 changed files with 52 additions and 20 deletions

View File

@@ -588,7 +588,9 @@ const FlowEditor: React.FC<{
<SaveControl
agentMeta={savedAgent}
onSave={(isTemplate) => requestSave(isTemplate ?? false)}
agentDescription={agentDescription}
onDescriptionChange={setAgentDescription}
agentName={agentName}
onNameChange={setAgentName}
/>
</ControlPanel>

View File

@@ -18,6 +18,8 @@ import {
interface SaveControlProps {
agentMeta: GraphMeta | null;
agentName: string;
agentDescription: string;
onSave: (isTemplate: boolean | undefined) => void;
onNameChange: (name: string) => void;
onDescriptionChange: (description: string) => void;
@@ -35,7 +37,9 @@ interface SaveControlProps {
export const SaveControl = ({
agentMeta,
onSave,
agentName,
onNameChange,
agentDescription,
onDescriptionChange,
}: SaveControlProps) => {
/**
@@ -75,7 +79,7 @@ export const SaveControl = ({
id="name"
placeholder="Enter your agent name"
className="col-span-3"
defaultValue={agentMeta?.name || ""}
value={agentName}
onChange={(e) => onNameChange(e.target.value)}
/>
<Label htmlFor="description">Description</Label>
@@ -83,9 +87,21 @@ export const SaveControl = ({
id="description"
placeholder="Your agent description"
className="col-span-3"
defaultValue={agentMeta?.description || ""}
value={agentDescription}
onChange={(e) => onDescriptionChange(e.target.value)}
/>
{agentMeta?.version && (
<>
<Label htmlFor="version">Version</Label>
<Input
id="version"
placeholder="Version"
className="col-span-3"
value={agentMeta?.version || "-"}
disabled
/>
</>
)}
</div>
</CardContent>
<CardFooter className="flex flex-col items-stretch gap-2">

View File

@@ -16,6 +16,7 @@ import {
import { Connection, MarkerType } from "@xyflow/react";
import Ajv from "ajv";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useRouter, useSearchParams, usePathname } from "next/navigation";
const ajv = new Ajv({ strict: false, allErrors: true });
@@ -24,6 +25,11 @@ export default function useAgentGraph(
template?: boolean,
passDataToBeads?: boolean,
) {
const [router, searchParams, pathname] = [
useRouter(),
useSearchParams(),
usePathname(),
];
const [savedAgent, setSavedAgent] = useState<Graph | null>(null);
const [agentDescription, setAgentDescription] = useState<string>("");
const [agentName, setAgentName] = useState<string>("");
@@ -307,7 +313,7 @@ export default function useAgentGraph(
(template ? api.getTemplate(flowID) : api.getGraph(flowID)).then(
(graph) => {
console.log("Loading graph");
console.debug("Loading graph");
loadGraph(graph);
},
);
@@ -608,7 +614,7 @@ export default function useAgentGraph(
}));
return {
id: node.id,
id: node.data.backend_id,
block_id: node.data.block_id,
input_default: inputDefault,
input_nodes: inputNodes,
@@ -637,11 +643,8 @@ export default function useAgentGraph(
nodes: formattedNodes,
links: links,
};
if (savedAgent && deepEquals(payload, savedAgent)) {
console.debug(
"No need to save: Graph is the same as version on server",
);
if (savedAgent && deepEquals(payload, savedAgent, true)) {
console.warn("No need to save: Graph is the same as version on server");
// Trigger state change
setSavedAgent(savedAgent);
return;
@@ -664,6 +667,13 @@ export default function useAgentGraph(
: api.createGraph(payload));
console.debug("Response from the API:", newSavedAgent);
// Route the URL to the new flow ID if it's a new agent.
if (!savedAgent) {
const path = new URLSearchParams(searchParams);
path.set("flowID", newSavedAgent.id);
router.replace(`${pathname}?${path.toString()}`);
}
// Update the node IDs on the frontend
setSavedAgent(newSavedAgent);
setNodes((prev) => {

View File

@@ -20,19 +20,23 @@ export function hashString(str: string): number {
}
/** Derived from https://stackoverflow.com/a/32922084 */
export function deepEquals(x: any, y: any): boolean {
export function deepEquals(x: any, y: any, allowMissingKeys = false): boolean {
const ok = Object.keys,
tx = typeof x,
ty = typeof y;
return (
const sk = (a: object, b: object) => ok(a).filter((k) => k in b);
const skipLengthCheck = allowMissingKeys && !Array.isArray(x);
const res =
x &&
y &&
tx === ty &&
(tx === "object"
? ok(x).length === ok(y).length &&
ok(x).every((key) => deepEquals(x[key], y[key]))
: x === y)
);
? (skipLengthCheck || ok(x).length === ok(y).length) &&
sk(x, y).every((key) => deepEquals(x[key], y[key], allowMissingKeys))
: x === y);
return res;
}
/** Get tailwind text color class from type name */

View File

@@ -161,9 +161,9 @@ services:
migrate:
condition: service_completed_successfully
environment:
- DATABASE_URL=postgresql://agpt_user:pass123@postgres:5432/agpt_local?connect_timeout=60
- DATABASE_URL=postgresql://agpt_user:pass123@postgres:5432/agpt_local?connect_timeout=60&schema=market
ports:
- "8015:8000"
- "8015:8015"
networks:
- app-network

View File

@@ -56,6 +56,6 @@ WORKDIR /app/rnd/market
FROM server_dependencies AS server
ENV DATABASE_URL=""
ENV PORT=8000
ENV PORT=8015
CMD ["uvicorn", "market.app:app", "--reload"]
CMD ["poetry", "run", "app"]

View File

@@ -59,7 +59,7 @@ def format():
def app():
port = os.getenv("PORT", "8015")
run("uvicorn", "market.app:app", "--reload", "--port", port)
run("uvicorn", "market.app:app", "--reload", "--port", port, "--host", "0.0.0.0")
def setup():