Skip to content

Commit 26a65af

Browse files
committed
fix: resolve 2-routing workflow JavaScript progression bug
- Fix duplicate button IDs causing event handler conflicts - Add missing DOM elements for prototype rendering (output-frame, results-container) - Initialize outputFrame reference in demo object - Fix WorkflowVisualizer constructor to use proper container ID - Correct step ID references in workflow progression - Enable Generate Prototype button after successful task analysis - Ensure end-to-end workflow completion with Ollama local models
1 parent b3637b4 commit 26a65af

2 files changed

Lines changed: 83 additions & 22 deletions

File tree

examples/agent-workflows/2-routing/app.js

Lines changed: 77 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class RoutingPrototypingDemo {
9898
this.generateButton = document.getElementById('generate-btn');
9999
this.analyzeButton = document.getElementById('analyze-btn');
100100
this.refineButton = document.getElementById('refine-btn');
101+
this.outputFrame = document.getElementById('output-frame');
101102

102103
// Initialize settings system first
103104
await this.initializeSettings();
@@ -148,22 +149,57 @@ class RoutingPrototypingDemo {
148149
}
149150
}
150151

152+
// Helper methods to manage both button sets
153+
setGenerateButtonState(disabled) {
154+
if (this.generateButton) {
155+
this.generateButton.disabled = disabled;
156+
}
157+
const sidebarGenerateBtn = document.getElementById('sidebar-generate-btn');
158+
if (sidebarGenerateBtn) {
159+
sidebarGenerateBtn.disabled = disabled;
160+
}
161+
}
162+
163+
setRefineButtonState(disabled) {
164+
if (this.refineButton) {
165+
this.refineButton.disabled = disabled;
166+
}
167+
const sidebarRefineBtn = document.getElementById('sidebar-refine-btn');
168+
if (sidebarRefineBtn) {
169+
sidebarRefineBtn.disabled = disabled;
170+
}
171+
}
172+
151173
setupEventListeners() {
152-
// Analyze Task button event listener
174+
// Main canvas button event listeners
153175
if (this.analyzeButton) {
154176
this.analyzeButton.addEventListener('click', () => this.analyzeTask());
155177
}
156178

157-
// Generate Prototype button event listener
158179
if (this.generateButton) {
159180
this.generateButton.addEventListener('click', () => this.generatePrototype());
160181
}
161182

162-
// Refine button event listener
163183
if (this.refineButton) {
164184
this.refineButton.addEventListener('click', () => this.refinePrototype());
165185
}
166186

187+
// Sidebar button event listeners (duplicates)
188+
const sidebarAnalyzeBtn = document.getElementById('sidebar-analyze-btn');
189+
if (sidebarAnalyzeBtn) {
190+
sidebarAnalyzeBtn.addEventListener('click', () => this.analyzeTask());
191+
}
192+
193+
const sidebarGenerateBtn = document.getElementById('sidebar-generate-btn');
194+
if (sidebarGenerateBtn) {
195+
sidebarGenerateBtn.addEventListener('click', () => this.generatePrototype());
196+
}
197+
198+
const sidebarRefineBtn = document.getElementById('sidebar-refine-btn');
199+
if (sidebarRefineBtn) {
200+
sidebarRefineBtn.addEventListener('click', () => this.refinePrototype());
201+
}
202+
167203
// Template selection event listeners
168204
document.querySelectorAll('.template-card').forEach(card => {
169205
card.addEventListener('click', () => {
@@ -190,6 +226,28 @@ class RoutingPrototypingDemo {
190226

191227
getModels() {
192228
return [
229+
{
230+
id: 'ollama_gemma3_270m',
231+
name: 'Gemma3 270M (Local)',
232+
speed: 'Very Fast',
233+
capability: 'Basic',
234+
cost: 0.0,
235+
costLabel: 'Free (Local)',
236+
maxComplexity: 0.3,
237+
description: 'Ultra-fast local model for simple tasks',
238+
color: '#16a34a'
239+
},
240+
{
241+
id: 'ollama_llama32_3b',
242+
name: 'Llama3.2 3B (Local)',
243+
speed: 'Fast',
244+
capability: 'Balanced',
245+
cost: 0.0,
246+
costLabel: 'Free (Local)',
247+
maxComplexity: 0.7,
248+
description: 'Balanced local model for moderate complexity tasks',
249+
color: '#059669'
250+
},
193251
{
194252
id: 'openai_gpt35',
195253
name: 'GPT-3.5 Turbo',
@@ -282,7 +340,7 @@ class RoutingPrototypingDemo {
282340
}
283341

284342
selectDefaultModel() {
285-
this.selectModel('openai_gpt35');
343+
this.selectModel('ollama_gemma3_270m');
286344
}
287345

288346
analyzeComplexityRealTime(prompt) {
@@ -387,10 +445,10 @@ class RoutingPrototypingDemo {
387445
}
388446

389447
async analyzeTask() {
390-
this.generateButton.disabled = true;
448+
this.setGenerateButtonState(true);
391449

392450
const pipeline = this.createWorkflowPipeline();
393-
pipeline.updateStepStatus('task-analysis', 'active');
451+
pipeline.updateStepStatus('analyze', 'active');
394452

395453
// Simulate analysis delay
396454
await this.delay(500);
@@ -404,21 +462,21 @@ class RoutingPrototypingDemo {
404462
const recommendedModel = this.recommendModel(complexity);
405463
this.selectModel(recommendedModel.id);
406464

407-
pipeline.updateStepStatus('task-analysis', 'completed');
408-
pipeline.updateStepStatus('routing', 'active');
465+
pipeline.updateStepStatus('analyze', 'completed');
466+
pipeline.updateStepStatus('route', 'active');
409467

410468
// Simulate routing delay
411469
await this.delay(300);
412470

413471
this.createRoutingVisualization(this.selectedModel, complexity);
414-
pipeline.updateStepStatus('routing', 'completed');
415-
pipeline.updateStepStatus('generation', 'pending');
472+
pipeline.updateStepStatus('route', 'completed');
473+
pipeline.updateStepStatus('generate', 'pending');
416474

417-
this.generateButton.disabled = false;
475+
this.setGenerateButtonState(false);
418476
}
419477

420478
createRoutingVisualization(selectedModel, complexity) {
421-
const visualizer = new WorkflowVisualizer('routing-visualizer');
479+
const visualizer = new WorkflowVisualizer('routing-visualization');
422480
visualizer.clear();
423481

424482
const routes = this.getModels().map(model => ({
@@ -435,7 +493,7 @@ class RoutingPrototypingDemo {
435493
this.refineButton.disabled = true;
436494

437495
const pipeline = this.createWorkflowPipeline();
438-
pipeline.updateStepStatus('generation', 'active');
496+
pipeline.updateStepStatus('generate', 'active');
439497

440498
const agentState = this.agentConfigManager.getState();
441499

@@ -474,14 +532,14 @@ class RoutingPrototypingDemo {
474532
this.renderPrototypeResult(result);
475533
this.displayGenerationResults(result);
476534

477-
pipeline.updateStepStatus('generation', 'completed');
478-
this.refineButton.disabled = false;
535+
pipeline.updateStepStatus('generate', 'completed');
536+
this.setRefineButtonState(false);
479537

480538
} catch (error) {
481539
console.error('Generation failed:', error);
482-
pipeline.updateStepStatus('generation', 'error');
540+
pipeline.updateStepStatus('generate', 'error');
483541
} finally {
484-
this.generateButton.disabled = false;
542+
this.setGenerateButtonState(false);
485543
}
486544
}
487545

@@ -520,13 +578,13 @@ class RoutingPrototypingDemo {
520578
const container = document.getElementById('results-container');
521579
container.innerHTML = '';
522580

523-
const visualizer = new WorkflowVisualizer();
581+
const visualizer = new WorkflowVisualizer('results-container');
524582
visualizer.createResultsDisplay({
525583
'Selected Model': this.selectedModel.name,
526584
'Task Complexity': `${(this.currentComplexity * 100).toFixed(0)}%`,
527585
'Estimated Cost': `$${(Math.random() * 0.1).toFixed(4)}`,
528586
'Execution Time': `${(result.duration || 2500 / 1000).toFixed(2)}s`
529-
}, 'results-container');
587+
});
530588
}
531589

532590
async refinePrototype() {

examples/agent-workflows/2-routing/index.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ <h3 class="sidebar-title">🤖 Agent Configuration</h3>
346346
<div class="sidebar-section">
347347
<h3 class="sidebar-title">🚀 Actions</h3>
348348
<div class="controls">
349-
<button id="analyze-btn" class="btn">Analyze Task</button>
350-
<button id="generate-btn" class="btn primary" data-testid="execute-routing" disabled>Generate Prototype</button>
351-
<button id="refine-btn" class="btn" disabled>Refine Output</button>
349+
<button id="sidebar-analyze-btn" class="btn">Analyze Task</button>
350+
<button id="sidebar-generate-btn" class="btn primary" data-testid="execute-routing" disabled>Generate Prototype</button>
351+
<button id="sidebar-refine-btn" class="btn" disabled>Refine Output</button>
352352
</div>
353353
</div>
354354
</div>
@@ -385,6 +385,8 @@ <h4>🚀 Ready to Prototype</h4>
385385
<p>Describe your idea above and click "Analyze Task" to see the AI routing in action.</p>
386386
<p style="font-size: 0.875rem; margin-top: 1rem;">The system will analyze complexity and route to the optimal model automatically.</p>
387387
</div>
388+
<!-- Prototype Output Frame -->
389+
<iframe id="output-frame" style="display: none; width: 100%; height: 400px; border: 1px solid var(--border); border-radius: var(--radius-md); margin-top: 1rem;"></iframe>
388390
</div>
389391
</div>
390392
</div>
@@ -396,6 +398,7 @@ <h4>🚀 Ready to Prototype</h4>
396398
<h3>Generation Results</h3>
397399
</div>
398400
<div id="results-content"></div>
401+
<div id="results-container"></div>
399402
</div>
400403
</div>
401404
</main>

0 commit comments

Comments
 (0)