owenkaplinsky commited on
Commit
60456b4
·
1 Parent(s): bce9c73

Fix issues

Browse files
.gitignore CHANGED
@@ -1,2 +1,4 @@
1
  .env
2
- node_modules
 
 
 
1
  .env
2
+ node_modules
3
+ .github
4
+ .gitignore
project/app.py CHANGED
@@ -36,44 +36,52 @@ def execute_blockly_logic(user_inputs):
36
 
37
  result = ""
38
 
39
- code_lines = latest_blockly_code.splitlines()
40
-
41
- cleaned_lines = []
42
- skip = False
43
- for line in code_lines:
44
- stripped = line.strip()
45
-
46
- # When we reach the Interface block, start skipping until after demo.launch()
47
- if stripped.startswith("demo = gr.Interface("):
48
- skip = True
49
  continue
50
- if skip:
51
- # Stop skipping after demo.launch(...) line
52
- if stripped.startswith("demo.launch("):
53
- skip = False
 
54
  continue
55
-
56
- # Keep everything else
57
- cleaned_lines.append(line)
58
-
59
- # Remove trailing blank lines
60
- while cleaned_lines and not cleaned_lines[-1].strip():
61
- cleaned_lines.pop()
62
-
63
- code_to_run = "\n".join(cleaned_lines)
64
-
65
- if len(code_lines) > 7:
66
- code_to_run = "\n".join(code_lines[:-7])
67
- else:
68
- code_to_run = "\n".join(code_lines)
 
 
69
 
70
  def capture_result(msg):
71
  nonlocal result
72
  result = msg
73
 
74
- env = {"reply": capture_result}
 
 
 
 
75
 
76
  try:
 
 
77
  exec(code_to_run, env)
78
  if "create_mcp" in env:
79
  import inspect
@@ -141,7 +149,7 @@ def build_interface():
141
 
142
  with gr.Row():
143
  submit_btn = gr.Button("Submit")
144
- refresh_btn = gr.Button("Refresh Inputs")
145
 
146
  def refresh_inputs():
147
  global latest_blockly_code
 
36
 
37
  result = ""
38
 
39
+ # More comprehensive filtering of Gradio-related code
40
+ lines = latest_blockly_code.split('\n')
41
+ filtered_lines = []
42
+ skip_mode = False
43
+ in_demo_block = False
44
+
45
+ for line in lines:
46
+ # Skip import gradio line
47
+ if 'import gradio' in line:
 
48
  continue
49
+
50
+ # Skip Gradio interface creation and any demo-related lines
51
+ if 'demo = gr.Interface' in line:
52
+ in_demo_block = True
53
+ skip_mode = True
54
  continue
55
+ elif 'demo.launch' in line:
56
+ skip_mode = False
57
+ in_demo_block = False
58
+ continue
59
+ elif in_demo_block:
60
+ # Skip everything in the demo block (multi-line Interface declaration)
61
+ continue
62
+
63
+ # Skip any standalone gr. calls
64
+ if 'gr.' in line:
65
+ continue
66
+
67
+ if not skip_mode:
68
+ filtered_lines.append(line)
69
+
70
+ code_to_run = '\n'.join(filtered_lines)
71
 
72
  def capture_result(msg):
73
  nonlocal result
74
  result = msg
75
 
76
+ # Set up the environment with necessary imports that might be needed
77
+ env = {
78
+ "reply": capture_result,
79
+ "__builtins__": __builtins__,
80
+ }
81
 
82
  try:
83
+ # Import any required modules in the execution environment
84
+ exec("import os", env)
85
  exec(code_to_run, env)
86
  if "create_mcp" in env:
87
  import inspect
 
149
 
150
  with gr.Row():
151
  submit_btn = gr.Button("Submit")
152
+ refresh_btn = gr.Button("Refresh")
153
 
154
  def refresh_inputs():
155
  global latest_blockly_code
project/src/blocks/text.js CHANGED
@@ -452,8 +452,8 @@ const create_mcp = {
452
  extensions: ["test_cleanup_extension"]
453
  };
454
 
455
- const tool_def = {
456
- type: "tool_def",
457
  message0: "function %1 %2 %3",
458
  args0: [
459
  { type: "field_input", name: "NAME", text: "newFunction" },
@@ -489,7 +489,7 @@ function generateUniqueToolName(workspace, excludeBlock) {
489
 
490
  // Collect all existing tool names, excluding the block being created
491
  for (const block of allBlocks) {
492
- if (block.type === 'tool_def' && block !== excludeBlock && block.getFieldValue('NAME')) {
493
  existingNames.add(block.getFieldValue('NAME'));
494
  }
495
  }
@@ -520,10 +520,10 @@ Blockly.Blocks['create_mcp'] = {
520
  }
521
  };
522
 
523
- // Register tool_def block separately to include custom init logic
524
- Blockly.Blocks['tool_def'] = {
525
  init: function () {
526
- this.jsonInit(tool_def);
527
  // Apply extensions
528
  Blockly.Extensions.apply('test_cleanup_extension', this, false);
529
  // Initialize mutator state
 
452
  extensions: ["test_cleanup_extension"]
453
  };
454
 
455
+ const func_def = {
456
+ type: "func_def",
457
  message0: "function %1 %2 %3",
458
  args0: [
459
  { type: "field_input", name: "NAME", text: "newFunction" },
 
489
 
490
  // Collect all existing tool names, excluding the block being created
491
  for (const block of allBlocks) {
492
+ if (block.type === 'func_def' && block !== excludeBlock && block.getFieldValue('NAME')) {
493
  existingNames.add(block.getFieldValue('NAME'));
494
  }
495
  }
 
520
  }
521
  };
522
 
523
+ // Register func_def block separately to include custom init logic
524
+ Blockly.Blocks['func_def'] = {
525
  init: function () {
526
+ this.jsonInit(func_def);
527
  // Apply extensions
528
  Blockly.Extensions.apply('test_cleanup_extension', this, false);
529
  // Initialize mutator state
project/src/generators/python.js CHANGED
@@ -136,7 +136,7 @@ demo.launch(mcp_server=True)
136
  return code;
137
  };
138
 
139
- forBlock['tool_def'] = function (block, generator) {
140
  const name = block.getFieldValue('NAME');
141
  const typedInputs = [];
142
  let i = 0;
 
136
  return code;
137
  };
138
 
139
+ forBlock['func_def'] = function (block, generator) {
140
  const name = block.getFieldValue('NAME');
141
  const typedInputs = [];
142
  let i = 0;
project/src/index.js CHANGED
@@ -49,6 +49,17 @@ const ws = Blockly.inject(blocklyDiv, {
49
  colour: '#ccc',
50
  snap: false
51
  },
 
 
 
 
 
 
 
 
 
 
 
52
  renderer: 'zelos',
53
  theme: myTheme,
54
  });
@@ -58,7 +69,6 @@ const updateCode = () => {
58
  const codeEl = document.querySelector('#generatedCode code');
59
 
60
  const call = `def llm_call(prompt, model):
61
- global history
62
  from openai import OpenAI
63
  import os
64
 
@@ -138,7 +148,7 @@ ws.addChangeListener((event) => {
138
  if (
139
  removedBlock &&
140
  oldParent &&
141
- (removedBlock.type.startsWith('input_reference_') && (oldParent.type === 'create_mcp' || oldParent.type === 'tool_def'))
142
  ) {
143
  // Only duplicate if removed from a mutator input (X0, X1, X2, etc.)
144
  // NOT from other inputs like RETURN, BODY, or title input
 
49
  colour: '#ccc',
50
  snap: false
51
  },
52
+ disable: false,
53
+ collapse: false,
54
+ zoom: {
55
+ controls: true,
56
+ wheel: true,
57
+ startScale: 1.0,
58
+ maxScale: 3,
59
+ minScale: 0.3,
60
+ scaleSpeed: 1.2,
61
+ pinch: true
62
+ },
63
  renderer: 'zelos',
64
  theme: myTheme,
65
  });
 
69
  const codeEl = document.querySelector('#generatedCode code');
70
 
71
  const call = `def llm_call(prompt, model):
 
72
  from openai import OpenAI
73
  import os
74
 
 
148
  if (
149
  removedBlock &&
150
  oldParent &&
151
+ (removedBlock.type.startsWith('input_reference_') && (oldParent.type === 'create_mcp' || oldParent.type === 'func_def'))
152
  ) {
153
  // Only duplicate if removed from a mutator input (X0, X1, X2, etc.)
154
  // NOT from other inputs like RETURN, BODY, or title input
project/src/toolbox.js CHANGED
@@ -11,16 +11,31 @@ export const toolbox = {
11
  },
12
  {
13
  kind: 'category',
14
- name: 'Custom',
15
  categorystyle: 'logic_category',
16
  contents: [
 
 
 
 
17
  {
18
  kind: 'block',
19
  type: 'llm_call',
20
  },
 
 
 
 
 
 
 
 
 
 
 
21
  {
22
  kind: 'block',
23
- type: 'tool_def',
24
  },
25
  ]
26
  },
 
11
  },
12
  {
13
  kind: 'category',
14
+ name: 'AI',
15
  categorystyle: 'logic_category',
16
  contents: [
17
+ {
18
+ "kind": "label",
19
+ "text": "Text"
20
+ },
21
  {
22
  kind: 'block',
23
  type: 'llm_call',
24
  },
25
+ {
26
+ "kind": "label",
27
+ "text": "Image"
28
+ },
29
+ ]
30
+ },
31
+ {
32
+ kind: 'category',
33
+ name: 'Functions',
34
+ categorystyle: 'logic_category',
35
+ contents: [
36
  {
37
  kind: 'block',
38
+ type: 'func_def',
39
  },
40
  ]
41
  },