MCPcopy Create free account
hub / github.com/VGabriel45/SolidityVisualizer / modifyAndCacheDiagram

Function modifyAndCacheDiagram

src/lib/fetch-backend.ts:75–129  ·  view source on GitHub ↗
(
  username: string,
  repo: string,
  instructions: string,
)

Source from the content-addressed store, hash-verified

73}
74
75export async function modifyAndCacheDiagram(
76 username: string,
77 repo: string,
78 instructions: string,
79): Promise<ModifyApiResponse> {
80 try {
81 // First get the current diagram from cache
82 const currentDiagram = await getCachedDiagram(username, repo);
83 const explanation = await getCachedExplanation(username, repo);
84
85 if (!currentDiagram || !explanation) {
86 return { error: "No existing diagram or explanation found to modify" };
87 }
88
89 const baseUrl =
90 process.env.NEXT_PUBLIC_API_DEV_URL ?? process.env.NEXT_PUBLIC_API_PROD_URL;
91 const url = new URL(`${baseUrl}/modify`);
92
93 const response = await fetch(url, {
94 method: "POST",
95 headers: {
96 "Content-Type": "application/json",
97 },
98 body: JSON.stringify({
99 username,
100 repo,
101 instructions: instructions,
102 current_diagram: currentDiagram,
103 explanation: explanation,
104 }),
105 });
106
107 if (response.status === 429) {
108 return { error: "Rate limit exceeded. Please try again later." };
109 }
110
111 const data = (await response.json()) as ModifyApiResponse;
112
113 if (data.error) {
114 return { error: data.error };
115 }
116
117 // Call the server action to cache the diagram
118 await cacheDiagramAndExplanation(
119 username,
120 repo,
121 data.diagram!,
122 explanation,
123 );
124 return { diagram: data.diagram };
125 } catch (error) {
126 console.error("Error modifying diagram:", error);
127 return { error: "Failed to modify diagram. Please try again later." };
128 }
129}
130
131export async function getCostOfGeneration(
132 username: string,

Callers

nothing calls this directly

Calls 3

getCachedDiagramFunction · 0.90
getCachedExplanationFunction · 0.90

Tested by

no test coverage detected