Restore AI-assisted code generation in Code Step dialog
Feature was present in TUI but missing after GUI conversion. Now includes: - Split layout: Code editor (left) | AI Assist panel (right) - Provider selector dropdown for AI calls - Prompt editor with smart default template showing available variables - "Generate Code" button that calls AI in background thread - Response feedback area showing success/error status - Automatic markdown fence stripping from AI responses - Available variables computed from tool arguments + previous step outputs Co-Authored-By: Claude Opus 4.5 <[email protected]>
This commit is contained in:
@@ -261,6 +261,34 @@ class ToolBuilderPage(QWidget):
|
||||
del self._tool.arguments[idx]
|
||||
self._refresh_arguments()
|
||||
|
||||
def _get_available_vars(self, up_to_step: int = -1) -> list:
|
||||
"""Get available variables for a step.
|
||||
|
||||
Args:
|
||||
up_to_step: Include variables from steps before this index.
|
||||
-1 means include all existing steps (for new steps).
|
||||
"""
|
||||
vars_list = ["input"]
|
||||
|
||||
# Add argument variables
|
||||
if self._tool and self._tool.arguments:
|
||||
for arg in self._tool.arguments:
|
||||
if arg.variable and arg.variable not in vars_list:
|
||||
vars_list.append(arg.variable)
|
||||
|
||||
# Add output variables from previous steps
|
||||
if self._tool and self._tool.steps:
|
||||
steps_to_check = self._tool.steps if up_to_step < 0 else self._tool.steps[:up_to_step]
|
||||
for step in steps_to_check:
|
||||
if hasattr(step, 'output_var') and step.output_var:
|
||||
# Handle comma-separated output vars
|
||||
for var in step.output_var.split(','):
|
||||
var = var.strip()
|
||||
if var and var not in vars_list:
|
||||
vars_list.append(var)
|
||||
|
||||
return vars_list
|
||||
|
||||
def _add_prompt_step(self):
|
||||
"""Add a prompt step."""
|
||||
from ..dialogs.step_dialog import PromptStepDialog
|
||||
@@ -275,7 +303,8 @@ class ToolBuilderPage(QWidget):
|
||||
def _add_code_step(self):
|
||||
"""Add a code step."""
|
||||
from ..dialogs.step_dialog import CodeStepDialog
|
||||
dialog = CodeStepDialog(self)
|
||||
available_vars = self._get_available_vars()
|
||||
dialog = CodeStepDialog(self, available_vars=available_vars)
|
||||
if dialog.exec():
|
||||
step = dialog.get_step()
|
||||
if not self._tool:
|
||||
@@ -297,7 +326,8 @@ class ToolBuilderPage(QWidget):
|
||||
dialog = PromptStepDialog(self, step)
|
||||
elif isinstance(step, CodeStep):
|
||||
from ..dialogs.step_dialog import CodeStepDialog
|
||||
dialog = CodeStepDialog(self, step)
|
||||
available_vars = self._get_available_vars(up_to_step=idx)
|
||||
dialog = CodeStepDialog(self, step, available_vars=available_vars)
|
||||
else:
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user