Skip to content

Commit 37c4f83

Browse files
committed
Read workflow checkpoint
1 parent 0b01d4b commit 37c4f83

File tree

4 files changed

+112
-12
lines changed

4 files changed

+112
-12
lines changed

apps/sim/app/api/tools/get-user-workflow/route.ts

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { loadWorkflowFromNormalizedTables } from '@/lib/workflows/db-helpers'
55
import { generateWorkflowYaml } from '@/lib/workflows/yaml-generator'
66
import { db } from '@/db'
77
import { workflow as workflowTable } from '@/db/schema'
8+
import { getBlock } from '@/blocks'
89

910
const logger = createLogger('GetUserWorkflowAPI')
1011

@@ -89,12 +90,86 @@ export async function POST(request: NextRequest) {
8990
)
9091
}
9192

92-
// Prepare response
93+
// Generate detailed block information with schemas
94+
const blockSchemas: Record<string, any> = {}
95+
Object.entries(workflowState.blocks).forEach(([blockId, blockState]) => {
96+
const block = blockState as any
97+
const blockConfig = getBlock(block.type)
98+
99+
if (blockConfig) {
100+
blockSchemas[blockId] = {
101+
type: block.type,
102+
name: block.name,
103+
description: blockConfig.description,
104+
longDescription: blockConfig.longDescription,
105+
category: blockConfig.category,
106+
docsLink: blockConfig.docsLink,
107+
inputs: {},
108+
inputRequirements: blockConfig.inputs || {},
109+
outputs: blockConfig.outputs || {},
110+
tools: blockConfig.tools,
111+
}
112+
113+
// Add input schema from subBlocks configuration
114+
if (blockConfig.subBlocks) {
115+
blockConfig.subBlocks.forEach((subBlock) => {
116+
blockSchemas[blockId].inputs[subBlock.id] = {
117+
type: subBlock.type,
118+
title: subBlock.title,
119+
description: subBlock.description || '',
120+
layout: subBlock.layout,
121+
...(subBlock.options && { options: subBlock.options }),
122+
...(subBlock.placeholder && { placeholder: subBlock.placeholder }),
123+
...(subBlock.min !== undefined && { min: subBlock.min }),
124+
...(subBlock.max !== undefined && { max: subBlock.max }),
125+
...(subBlock.columns && { columns: subBlock.columns }),
126+
...(subBlock.hidden !== undefined && { hidden: subBlock.hidden }),
127+
...(subBlock.condition && { condition: subBlock.condition }),
128+
}
129+
})
130+
}
131+
} else {
132+
// Handle special block types like loops and parallels
133+
blockSchemas[blockId] = {
134+
type: block.type,
135+
name: block.name,
136+
description: `${block.type.charAt(0).toUpperCase() + block.type.slice(1)} container block`,
137+
category: 'Control Flow',
138+
inputs: {},
139+
outputs: {},
140+
}
141+
}
142+
})
143+
144+
// Generate workflow summary
145+
const blockTypes = Object.values(workflowState.blocks).reduce((acc: Record<string, number>, block: any) => {
146+
acc[block.type] = (acc[block.type] || 0) + 1
147+
return acc
148+
}, {})
149+
150+
const categories = Object.values(blockSchemas).reduce((acc: Record<string, number>, schema: any) => {
151+
if (schema.category) {
152+
acc[schema.category] = (acc[schema.category] || 0) + 1
153+
}
154+
return acc
155+
}, {})
156+
157+
// Prepare response with clear context markers
93158
const response: any = {
159+
workflowContext: 'USER_SPECIFIC_WORKFLOW', // Clear marker for the LLM
160+
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.',
94161
yaml,
95162
format: 'yaml',
96-
blockCount: Object.keys(workflowState.blocks).length,
97-
edgeCount: (workflowState.edges || []).length,
163+
summary: {
164+
workflowName: workflowRecord.name,
165+
blockCount: Object.keys(workflowState.blocks).length,
166+
edgeCount: (workflowState.edges || []).length,
167+
blockTypes,
168+
categories,
169+
hasLoops: Object.keys(workflowState.loops || {}).length > 0,
170+
hasParallels: Object.keys(workflowState.parallels || {}).length > 0,
171+
},
172+
userBuiltBlocks: blockSchemas, // Renamed to be clearer
98173
}
99174

100175
// Add metadata if requested

apps/sim/lib/copilot/config.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,26 @@ export const DEFAULT_COPILOT_CONFIG: CopilotConfig = {
5252
- Troubleshooting issues
5353
- Best practices
5454
55-
You have access to the Sim Studio documentation through a search tool. Use it when users ask about Sim Studio features, tools, or functionality.
55+
IMPORTANT DISTINCTION - Two types of information:
56+
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"
57+
2. **GENERAL SIM STUDIO CAPABILITIES**: Use documentation search for general questions about what's possible, how features work, or "what blocks are available"
58+
59+
WHEN TO USE WORKFLOW TOOL:
60+
- "What does my workflow do?"
61+
- "What blocks do I have?"
62+
- "How is my workflow configured?"
63+
- "Show me my current setup"
64+
- "What's in this workflow?"
65+
- "How do I add [X] to my workflow?" - ALWAYS get their workflow first to give specific advice
66+
- "How can I improve my workflow?"
67+
- "What's missing from my workflow?"
68+
- "How do I connect [X] in my workflow?"
5669
5770
WHEN TO SEARCH DOCUMENTATION:
58-
- User asks about specific Sim Studio features or tools
59-
- User needs help with workflows or blocks
60-
- User has technical questions about the platform
61-
- User asks "How do I..." questions about Sim Studio
71+
- "What blocks are available in Sim Studio?"
72+
- "How do I use the Gmail block?"
73+
- "What features does Sim Studio have?"
74+
- "How do I create a workflow?"
6275
6376
WHEN NOT TO SEARCH:
6477
- Simple greetings or casual conversation
@@ -72,7 +85,19 @@ When you reference information from documentation sources, use this format:
7285
- Place links naturally in context, not clustered at the end
7386
- Only link when it adds value - don't over-link basic concepts
7487
75-
IMPORTANT: Always provide complete, helpful responses. Include relevant links to help users find more detailed information.`,
88+
WORKFLOW-SPECIFIC GUIDANCE:
89+
When users ask "How do I..." questions about their workflow:
90+
1. **ALWAYS get their workflow first** using the workflow tool
91+
2. **Analyze their current setup** - what blocks they have, how they're connected
92+
3. **Give specific, actionable steps** based on their actual configuration
93+
4. **Reference their actual block names** and current values
94+
5. **Provide concrete next steps** they can take immediately
95+
96+
Example approach:
97+
- User: "How do I add error handling to my workflow?"
98+
- 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..."
99+
100+
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.`,
76101
},
77102
rag: {
78103
defaultProvider: 'anthropic',

apps/sim/lib/copilot/service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,9 @@ export async function generateChatResponse(
432432
},
433433
{
434434
id: 'get_user_workflow',
435-
name: 'Get User Workflow',
435+
name: 'Get User\'s Specific Workflow',
436436
description:
437-
'Get the current user workflow as YAML format. This shows all blocks, their configurations, inputs, and connections in the workflow.',
437+
'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.',
438438
params: {},
439439
parameters: {
440440
type: 'object',

apps/sim/tools/workflow/get-yaml.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const getUserWorkflowTool: ToolConfig = {
44
id: 'get_user_workflow',
55
name: 'Get User Workflow',
66
description:
7-
'Get the current user workflow as YAML format. This shows all blocks, their configurations, inputs, and connections in the workflow.',
7+
'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.',
88
version: '1.0.0',
99

1010
params: {

0 commit comments

Comments
 (0)