Read workflow checkpoint

This commit is contained in:
Siddharth Ganesan
2025-07-08 22:15:09 -07:00
parent 0b01d4bc78
commit 37c4f835dd
4 changed files with 112 additions and 12 deletions

View File

@@ -5,6 +5,7 @@ import { loadWorkflowFromNormalizedTables } from '@/lib/workflows/db-helpers'
import { generateWorkflowYaml } from '@/lib/workflows/yaml-generator'
import { db } from '@/db'
import { workflow as workflowTable } from '@/db/schema'
import { getBlock } from '@/blocks'
const logger = createLogger('GetUserWorkflowAPI')
@@ -89,12 +90,86 @@ export async function POST(request: NextRequest) {
)
}
// Prepare response
// Generate detailed block information with schemas
const blockSchemas: Record<string, any> = {}
Object.entries(workflowState.blocks).forEach(([blockId, blockState]) => {
const block = blockState as any
const blockConfig = getBlock(block.type)
if (blockConfig) {
blockSchemas[blockId] = {
type: block.type,
name: block.name,
description: blockConfig.description,
longDescription: blockConfig.longDescription,
category: blockConfig.category,
docsLink: blockConfig.docsLink,
inputs: {},
inputRequirements: blockConfig.inputs || {},
outputs: blockConfig.outputs || {},
tools: blockConfig.tools,
}
// Add input schema from subBlocks configuration
if (blockConfig.subBlocks) {
blockConfig.subBlocks.forEach((subBlock) => {
blockSchemas[blockId].inputs[subBlock.id] = {
type: subBlock.type,
title: subBlock.title,
description: subBlock.description || '',
layout: subBlock.layout,
...(subBlock.options && { options: subBlock.options }),
...(subBlock.placeholder && { placeholder: subBlock.placeholder }),
...(subBlock.min !== undefined && { min: subBlock.min }),
...(subBlock.max !== undefined && { max: subBlock.max }),
...(subBlock.columns && { columns: subBlock.columns }),
...(subBlock.hidden !== undefined && { hidden: subBlock.hidden }),
...(subBlock.condition && { condition: subBlock.condition }),
}
})
}
} else {
// Handle special block types like loops and parallels
blockSchemas[blockId] = {
type: block.type,
name: block.name,
description: `${block.type.charAt(0).toUpperCase() + block.type.slice(1)} container block`,
category: 'Control Flow',
inputs: {},
outputs: {},
}
}
})
// Generate workflow summary
const blockTypes = Object.values(workflowState.blocks).reduce((acc: Record<string, number>, block: any) => {
acc[block.type] = (acc[block.type] || 0) + 1
return acc
}, {})
const categories = Object.values(blockSchemas).reduce((acc: Record<string, number>, schema: any) => {
if (schema.category) {
acc[schema.category] = (acc[schema.category] || 0) + 1
}
return acc
}, {})
// Prepare response with clear context markers
const response: any = {
workflowContext: 'USER_SPECIFIC_WORKFLOW', // Clear marker for the LLM
note: 'This data represents only the blocks and configurations that the user has actually built in their current workflow, not all available Sim Studio capabilities.',
yaml,
format: 'yaml',
blockCount: Object.keys(workflowState.blocks).length,
edgeCount: (workflowState.edges || []).length,
summary: {
workflowName: workflowRecord.name,
blockCount: Object.keys(workflowState.blocks).length,
edgeCount: (workflowState.edges || []).length,
blockTypes,
categories,
hasLoops: Object.keys(workflowState.loops || {}).length > 0,
hasParallels: Object.keys(workflowState.parallels || {}).length > 0,
},
userBuiltBlocks: blockSchemas, // Renamed to be clearer
}
// Add metadata if requested

View File

@@ -52,13 +52,26 @@ export const DEFAULT_COPILOT_CONFIG: CopilotConfig = {
- Troubleshooting issues
- Best practices
You have access to the Sim Studio documentation through a search tool. Use it when users ask about Sim Studio features, tools, or functionality.
IMPORTANT DISTINCTION - Two types of information:
1. **USER'S SPECIFIC WORKFLOW**: Use "Get User's Specific Workflow" tool when users ask about "my workflow", "this workflow", "what I have built", or "my current blocks"
2. **GENERAL SIM STUDIO CAPABILITIES**: Use documentation search for general questions about what's possible, how features work, or "what blocks are available"
WHEN TO USE WORKFLOW TOOL:
- "What does my workflow do?"
- "What blocks do I have?"
- "How is my workflow configured?"
- "Show me my current setup"
- "What's in this workflow?"
- "How do I add [X] to my workflow?" - ALWAYS get their workflow first to give specific advice
- "How can I improve my workflow?"
- "What's missing from my workflow?"
- "How do I connect [X] in my workflow?"
WHEN TO SEARCH DOCUMENTATION:
- User asks about specific Sim Studio features or tools
- User needs help with workflows or blocks
- User has technical questions about the platform
- User asks "How do I..." questions about Sim Studio
- "What blocks are available in Sim Studio?"
- "How do I use the Gmail block?"
- "What features does Sim Studio have?"
- "How do I create a workflow?"
WHEN NOT TO SEARCH:
- Simple greetings or casual conversation
@@ -72,7 +85,19 @@ When you reference information from documentation sources, use this format:
- Place links naturally in context, not clustered at the end
- Only link when it adds value - don't over-link basic concepts
IMPORTANT: Always provide complete, helpful responses. Include relevant links to help users find more detailed information.`,
WORKFLOW-SPECIFIC GUIDANCE:
When users ask "How do I..." questions about their workflow:
1. **ALWAYS get their workflow first** using the workflow tool
2. **Analyze their current setup** - what blocks they have, how they're connected
3. **Give specific, actionable steps** based on their actual configuration
4. **Reference their actual block names** and current values
5. **Provide concrete next steps** they can take immediately
Example approach:
- User: "How do I add error handling to my workflow?"
- You: [Get their workflow] → "I can see your workflow has a Starter block connected to an Agent block, then an API block. Here's how to add error handling specifically for your setup: 1) Add a Condition block after your API block to check if the response was successful, 2) Connect the 'false' path to a new Agent block that handles the error..."
IMPORTANT: Always be clear about whether you're talking about the user's specific workflow or general Sim Studio capabilities. When showing workflow data, explicitly state "In your current workflow..." or "Your workflow contains..." Be actionable and specific - don't give generic advice when you can see their actual setup.`,
},
rag: {
defaultProvider: 'anthropic',

View File

@@ -432,9 +432,9 @@ export async function generateChatResponse(
},
{
id: 'get_user_workflow',
name: 'Get User Workflow',
name: 'Get User\'s Specific Workflow',
description:
'Get the current user workflow as YAML format. This shows all blocks, their configurations, inputs, and connections in the workflow.',
'Get the user\'s current workflow - this shows ONLY the blocks they have actually built and configured in their specific workflow, not general Sim Studio capabilities. Use this when the user asks about "my workflow", "this workflow", wants to know what blocks they currently have, OR when they ask "How do I..." questions about their workflow so you can give specific, actionable advice based on their actual setup.',
params: {},
parameters: {
type: 'object',

View File

@@ -4,7 +4,7 @@ export const getUserWorkflowTool: ToolConfig = {
id: 'get_user_workflow',
name: 'Get User Workflow',
description:
'Get the current user workflow as YAML format. This shows all blocks, their configurations, inputs, and connections in the workflow.',
'Get the current user\'s specific workflow (not general Sim Studio documentation). Returns YAML format showing only the blocks that the user has actually built in their workflow, with their specific configurations, inputs, and connections.',
version: '1.0.0',
params: {