@@ -32,16 +32,8 @@ export function buildAppPublishPrompt(
3232 canvasContext : CanvasContext ,
3333 historicalData ?: HistoricalData ,
3434) : string {
35- // Analyze which variables are actually used in canvas nodes
36- const usedVariables = analyzeVariableUsage ( canvasData . nodes , canvasData . variables ) ;
37-
38- // Filter variables to only include those that are actually used
39- const filteredVariables = canvasData . variables . filter ( ( variable ) =>
40- usedVariables . has ( variable . name ) ,
41- ) ;
42-
4335 const nodesText = buildNodesText ( canvasData . nodes ) ;
44- const variablesText = buildVariablesText ( filteredVariables ) ;
36+ const variablesText = buildVariablesText ( canvasData . variables ) ;
4537 const canvasContextText = buildCanvasContextText ( canvasContext ) ;
4638 const historicalContext = historicalData ? buildHistoricalContext ( historicalData ) : '' ;
4739
@@ -74,34 +66,45 @@ ${historicalContext ? `### Historical Learning Context\n${historicalContext}` :
7466
7567## Template Generation Guidelines
7668
77- ### 1. Natural Language Conversion
69+ ### 1. Language Consistency (CRITICAL)
70+ - **MUST maintain the same language as used in Canvas Nodes and Prompts**
71+ - If Canvas Nodes contain Chinese text, generate templates in Chinese
72+ - If Canvas Nodes contain English text, generate templates in English
73+ - If Canvas Nodes contain mixed languages, follow the primary language pattern
74+ - **Language Detection**: Analyze the Canvas Nodes content to determine the user's preferred language
75+ - **Consistency Requirement**: All template fields (title, description, content) must use the same language as the Canvas Nodes
76+
77+ ### 2. Natural Language Conversion
7878- Convert technical workflow descriptions into user-friendly language
7979- Use clear, actionable language that explains what the workflow does
8080- Focus on user benefits and outcomes
81+ - **Maintain language consistency with Canvas Nodes**
8182
82- ### 2 . Variable Integration
83+ ### 3 . Variable Integration
8384- **CRITICAL**: Only include variables that are actually used in Canvas Nodes and Prompts
8485- Replace specific values with {{variable_name}} placeholders
8586- Ensure all variables are properly represented in the template
8687- Maintain semantic meaning while making it parameterizable
8788- **Variable Usage Validation**: Only variables that appear in {{variable_name}} format within the Canvas Nodes should be included in the template
8889
89- ### 3 . Template Structure
90+ ### 4 . Template Structure
9091- Start with a clear description of what the workflow accomplishes
9192- Explain what inputs are needed (variables)
9293- Describe the expected output or result
9394- Use conversational, helpful tone
95+ - **Maintain language consistency with Canvas Nodes**
9496
95- ### 4 . Variable Type Handling
97+ ### 5 . Variable Type Handling
9698- **string**: Use descriptive placeholders like "{{topic}}" or "{{style}}"
9799- **resource**: Use file-related placeholders like "{{upload_file}}" or "{{document}}"
98100- **option**: Use selection-related placeholders like "{{format}}" or "{{mode}}"
99101
100- ### 5 . Quality Standards
102+ ### 6 . Quality Standards
101103- Templates should be self-explanatory
102104- Variables should have clear, descriptive names
103105- Maintain workflow functionality while improving usability
104106- Ensure consistency with existing variable names
107+ - **Language consistency is mandatory - all output must match Canvas Nodes language**
105108
106109## Output Format Requirements
107110
@@ -145,17 +148,19 @@ ${historicalContext ? `### Historical Learning Context\n${historicalContext}` :
145148\`\`\`
146149
147150## Key Principles
148- 1. **Clarity**: Users should immediately understand what the workflow does
149- 2. **Simplicity**: Avoid technical jargon, use everyday language
150- 3. **Completeness**: Include all necessary variables and context
151- 4. **Actionability**: Users should know exactly what to provide and expect
152- 5. **Professionalism**: Maintain a helpful, trustworthy tone
153- 6. **Variable Usage Validation**: Only include variables that are actually referenced in Canvas Nodes with {{variable_name}} format
151+ 1. **Language Consistency**: **CRITICAL** - All template fields must use the same language as Canvas Nodes
152+ 2. **Clarity**: Users should immediately understand what the workflow does
153+ 3. **Simplicity**: Avoid technical jargon, use everyday language
154+ 4. **Completeness**: Include all necessary variables and context
155+ 5. **Actionability**: Users should know exactly what to provide and expect
156+ 6. **Professionalism**: Maintain a helpful, trustworthy tone
157+ 7. **Variable Usage Validation**: Only include variables that are actually referenced in Canvas Nodes with {{variable_name}} format
154158
155159## Critical Focus: Workflow Publishing Template String
156160
157161The **"content"** field in the template object is the most important output - this is the **workflow publishing template string** that will be used by users. It must:
158162
163+ - **Language Consistency**: **CRITICAL** - Must use the same language as Canvas Nodes
159164- **Be Natural and Conversational**: Sound like a helpful assistant explaining what they'll do
160165- **Include Only Used Variables**: Only variables that are actually referenced in Canvas Nodes with {{variable_name}} format should be included
161166- **Maintain Original Intent**: Preserve the user's original goal and requirements
@@ -205,43 +210,10 @@ ${APP_PUBLISH_EXAMPLES}
205210 - Only variables that are actually used in Canvas Nodes should be included
206211 - Templates should maintain the original workflow intent
207212 - Language should be professional yet approachable
213+ - **Language Consistency**: **CRITICAL** - All template fields must match the language used in Canvas Nodes
208214 - **Variable Usage Validation**: Verify that all {{variable_name}} placeholders in the template correspond to variables actually referenced in Canvas Nodes` ;
209215}
210216
211- /**
212- * Analyze which variables are actually used in canvas nodes
213- * Returns a set of variable names that are referenced in node content
214- */
215- function analyzeVariableUsage ( nodes : CanvasNode [ ] , variables : WorkflowVariable [ ] ) : Set < string > {
216- const usedVariables = new Set < string > ( ) ;
217-
218- if ( ! nodes ?. length || ! variables ?. length ) {
219- return usedVariables ;
220- }
221-
222- // Get all variable names
223- const variableNames = variables . map ( ( v ) => v . name ) ;
224-
225- // Check each node for variable references
226- for ( const node of nodes ) {
227- const content = node . data ?. content || node . content || '' ;
228- if ( typeof content === 'string' && content . length > 0 ) {
229- // Check for {{variable_name}} pattern
230- const variablePattern = / \{ \{ ( [ ^ } ] + ) \} \} / g;
231- let match : RegExpExecArray | null = variablePattern . exec ( content ) ;
232- while ( match !== null ) {
233- const variableName = match [ 1 ] ?. trim ( ) ;
234- if ( variableName && variableNames . includes ( variableName ) ) {
235- usedVariables . add ( variableName ) ;
236- }
237- match = variablePattern . exec ( content ) ;
238- }
239- }
240- }
241-
242- return usedVariables ;
243- }
244-
245217/**
246218 * Build nodes text - format canvas nodes into readable description
247219 */
0 commit comments