Skip to content

Commit

Permalink
feat: pass agentId as a parameter to the server action
Browse files Browse the repository at this point in the history
  • Loading branch information
sakit0 committed Dec 16, 2024
1 parent 11a1a8e commit 49844e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions app/(playground)/p/[agentId]/canary/contexts/graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from "react";
import { deriveFlows } from "../lib/graph";
import type {
AgentId,
Artifact,
Connection,
ConnectionId,
Expand Down Expand Up @@ -223,6 +224,7 @@ export function GraphContextProvider({
defaultGraph,
defaultGraphUrl,
onPersistAction,
agentId,
}: {
children: ReactNode;
defaultGraph: Graph;
Expand All @@ -231,7 +233,8 @@ export function GraphContextProvider({
* Persists the graph to the server.
* Returns the new graph URL.
*/
onPersistAction: (graph: Graph) => Promise<string>;
onPersistAction: (agentId: AgentId, graph: Graph) => Promise<string>;
agentId: AgentId;
}) {
const graphRef = useRef(defaultGraph);
const [graph, setGraph] = useState(graphRef.current);
Expand All @@ -241,14 +244,14 @@ export function GraphContextProvider({
const persist = useCallback(async () => {
isPendingPersistRef.current = false;
try {
const newGraphUrl = await onPersistAction(graphRef.current);
const newGraphUrl = await onPersistAction(agentId, graphRef.current);
setGraphUrl(newGraphUrl);
return newGraphUrl;
} catch (error) {
console.error("Failed to persist graph:", error);
return graphUrl;
}
}, [onPersistAction, graphUrl]);
}, [onPersistAction, graphUrl, agentId]);

const flush = useCallback(async () => {
if (persistTimeoutRef.current) {
Expand Down
5 changes: 3 additions & 2 deletions app/(playground)/p/[agentId]/canary/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default async function Page({
(res) => res.json() as unknown as Graph,
);

async function persistGraph(graph: Graph) {
async function persistGraph(agentId: AgentId, graph: Graph) {
"use server";
const { url } = await putGraph(graph);
await db
Expand All @@ -85,7 +85,7 @@ export default async function Page({
let graphUrl = agent.graphUrl;
if (!isLatestVersion(graph)) {
graph = migrateGraph(graph);
graphUrl = await persistGraph(graph);
graphUrl = await persistGraph(agentId, graph);
}

async function updateAgentName(agentName: string) {
Expand Down Expand Up @@ -131,6 +131,7 @@ export default async function Page({
defaultGraph={graph}
onPersistAction={persistGraph}
defaultGraphUrl={graphUrl}
agentId={agentId}
>
<PropertiesPanelProvider>
<ReactFlowProvider>
Expand Down

0 comments on commit 49844e8

Please sign in to comment.