MCPcopy
hub / github.com/ahmedkhaleel2004/gitdiagram / run

Function run

src/app/api/generate/stream/route.ts:209–844  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

207 };
208
209 const run = async () => {
210 let audit = createGenerationSessionAudit({
211 sessionId: randomUUID(),
212 provider: "unknown",
213 model: "unknown",
214 });
215 let estimate: GenerationEstimateResult | null = null;
216 let quotaReservation: ComplimentaryQuotaReservation | null = null;
217 const actualUsages: GenerationTokenUsage[] = [];
218 let hasCompleteMeasuredUsage = true;
219 let storageVisibility: ArtifactVisibility = githubPat?.trim()
220 ? "private"
221 : "public";
222
223 const persistTerminalAudit = async (nextAudit = audit) => {
224 await persistTerminalSessionAudit({
225 username,
226 repo,
227 githubPat,
228 visibility: storageVisibility,
229 audit: nextAudit,
230 });
231 };
232
233 try {
234 throwIfAborted(generationAbortController.signal);
235 const provider = getProvider();
236 const providerLabel = getProviderLabel(provider);
237 const model = getModel(provider);
238
239 if (isComplimentaryGateEnabled() && !apiKey) {
240 if (provider !== "openai") {
241 const error = getComplimentaryProviderMismatchMessage();
242 audit = withFailure(
243 {
244 ...audit,
245 provider,
246 model,
247 quotaStatus: "denied",
248 },
249 {
250 failureStage: "started",
251 validationError: error,
252 },
253 );
254 await persistTerminalAudit();
255 send({
256 status: "error",
257 session_id: audit.sessionId,
258 error,
259 error_code: "COMPLIMENTARY_GATE_PROVIDER_MISMATCH",
260 failure_stage: "started",
261 validation_error: error,
262 cost_summary: audit.finalCost ?? audit.estimatedCost,
263 latest_session_audit: audit,
264 });
265 closeStream();
266 return;

Callers 1

startFunction · 0.85

Calls 15

getProviderFunction · 0.90
getProviderLabelFunction · 0.90
getModelFunction · 0.90
withFailureFunction · 0.90
getGithubDataFunction · 0.90
estimateGenerationCostFunction · 0.90

Tested by

no test coverage detected