MCPcopy Index your code
hub / github.com/simstudioai/sim / useGenerateVersionDescription

Function useGenerateVersionDescription

apps/sim/hooks/queries/deployments.ts:434–507  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

432 * Hook for generating a version description using AI based on workflow diff
433 */
434export function useGenerateVersionDescription() {
435 return useMutation({
436 mutationFn: async ({
437 workflowId,
438 version,
439 onStreamChunk,
440 signal,
441 }: GenerateVersionDescriptionVariables): Promise<string> => {
442 const { generateWorkflowDiffSummary, formatDiffSummaryForDescriptionAsync } = await import(
443 '@/lib/workflows/comparison/compare'
444 )
445
446 const currentState = await fetchDeploymentVersionState(workflowId, version, signal)
447
448 let previousState = null
449 if (version > 1) {
450 try {
451 previousState = await fetchDeploymentVersionState(workflowId, version - 1, signal)
452 } catch {
453 // Previous version may not exist, continue without it
454 }
455 }
456
457 const diffSummary = generateWorkflowDiffSummary(currentState, previousState)
458 const diffText = await formatDiffSummaryForDescriptionAsync(
459 diffSummary,
460 currentState,
461 workflowId
462 )
463
464 const wandResponse = await requestRaw(
465 wandGenerateStreamContract,
466 {
467 body: {
468 prompt: `Generate a deployment version description based on these changes:\n\n${diffText}`,
469 systemPrompt: VERSION_DESCRIPTION_SYSTEM_PROMPT,
470 stream: true,
471 workflowId,
472 },
473 signal,
474 },
475 {
476 headers: {
477 'Cache-Control': 'no-cache, no-transform',
478 },
479 cache: 'no-store',
480 }
481 )
482
483 if (!wandResponse.body) {
484 throw new Error('Response body is null')
485 }
486
487 const { readSSEStream } = await import('@/lib/core/utils/sse')
488 const accumulatedContent = await readSSEStream(wandResponse.body, {
489 onAccumulated: onStreamChunk,
490 signal,
491 })

Callers 1

VersionDescriptionModalFunction · 0.90

Calls 7

requestRawFunction · 0.90
readSSEStreamFunction · 0.85
infoMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected