owenkaplinsky commited on
Commit
b36a945
·
1 Parent(s): f53803f
Files changed (2) hide show
  1. project/chat.py +33 -21
  2. project/src/index.js +3 -3
project/chat.py CHANGED
@@ -1139,28 +1139,40 @@ def create_gradio_interface():
1139
 
1140
  # Only proceed if validation passed (no error was set)
1141
  if tool_result is None:
1142
- # Check if this is the first MCP output block creation attempt
1143
- if (not first_output_block_attempted and
1144
- placement_type == "input" and
1145
- input_name and
1146
- input_name.startswith("R")):
1147
- is_first_output_attempt = True
1148
- # Mark that we've attempted an output block in this conversation
1149
- first_output_block_attempted = True
1150
- # Return warning instead of creating the block
1151
- tool_result = "[TOOL] Automated warning: Make sure your output block contains the full and entire value needed. Block placement was **not** executed. Retry with the full command needed in one go."
1152
- result_label = "Output Block Warning"
1153
- print(Fore.YELLOW + f"[FIRST OUTPUT BLOCK] Intercepted first output block attempt with command `{command}`." + Style.RESET_ALL)
1154
- else:
1155
- # Normal block creation
1156
- if blockID is None:
1157
- print(Fore.YELLOW + f"Agent created block with command `{command}`." + Style.RESET_ALL)
 
 
 
 
 
 
 
 
1158
  else:
1159
- print(Fore.YELLOW + f"Agent created block with command `{command}`, type: {placement_type}, blockID: `{blockID}`." + Style.RESET_ALL)
1160
- if input_name:
1161
- print(Fore.YELLOW + f" Input name: {input_name}" + Style.RESET_ALL)
1162
- tool_result = create_block(command, blockID, placement_type, input_name)
1163
- result_label = "Create Operation"
 
 
 
 
1164
 
1165
  elif function_name == "create_variable":
1166
  name = function_args.get("name", "")
 
1139
 
1140
  # Only proceed if validation passed (no error was set)
1141
  if tool_result is None:
1142
+ # Validate type: "input" usage with input_name
1143
+ if placement_type == "input" and input_name:
1144
+ valid_mcp_outputs = all(input_name.startswith("R") and input_name[1:].isdigit() for _ in [input_name]) if input_name.startswith("R") else False
1145
+ valid_conditional_branches = input_name in ("DO0", "DO1", "DO2", "DO3", "DO4", "DO5", "ELSE") or input_name.startswith("DO")
1146
+
1147
+ if not valid_mcp_outputs and not valid_conditional_branches:
1148
+ tool_result = f"[ERROR] Invalid input_name '{input_name}' used with type: 'input'. Valid values are:\n- MCP output slots: 'R0', 'R1', 'R2', etc.\n- Conditional branches: 'DO0', 'DO1', 'DO2', etc., or 'ELSE'\n\nThe attempted command was:\n\n`{command_stripped}`"
1149
+ result_label = "Invalid Placement Error"
1150
+ print(Fore.RED + f"[VALIDATION ERROR] Invalid input_name for type 'input': {input_name}" + Style.RESET_ALL)
1151
+
1152
+ # Only proceed if no validation errors
1153
+ if tool_result is None:
1154
+ # Check if this is the first MCP output block creation attempt
1155
+ if (not first_output_block_attempted and
1156
+ placement_type == "input" and
1157
+ input_name and
1158
+ input_name.startswith("R")):
1159
+ is_first_output_attempt = True
1160
+ # Mark that we've attempted an output block in this conversation
1161
+ first_output_block_attempted = True
1162
+ # Return warning instead of creating the block
1163
+ tool_result = "[TOOL] Automated warning: Make sure your output block contains the full and entire value needed. Block placement was **not** executed. Retry with the full command needed in one go."
1164
+ result_label = "Output Block Warning"
1165
+ print(Fore.YELLOW + f"[FIRST OUTPUT BLOCK] Intercepted first output block attempt with command `{command}`." + Style.RESET_ALL)
1166
  else:
1167
+ # Normal block creation
1168
+ if blockID is None:
1169
+ print(Fore.YELLOW + f"Agent created block with command `{command}`." + Style.RESET_ALL)
1170
+ else:
1171
+ print(Fore.YELLOW + f"Agent created block with command `{command}`, type: {placement_type}, blockID: `{blockID}`." + Style.RESET_ALL)
1172
+ if input_name:
1173
+ print(Fore.YELLOW + f" Input name: {input_name}" + Style.RESET_ALL)
1174
+ tool_result = create_block(command, blockID, placement_type, input_name)
1175
+ result_label = "Create Operation"
1176
 
1177
  elif function_name == "create_variable":
1178
  name = function_args.get("name", "")
project/src/index.js CHANGED
@@ -1274,7 +1274,7 @@ const updateCode = () => {
1274
  const blocks = ws.getAllBlocks(false);
1275
  const hasCall = blocks.some(block => block.type === 'llm_call');
1276
  const hasAPI = blocks.some(block => block.type === 'call_api');
1277
- const hasPrime = code.includes('math_isPrime()');
1278
  const hasNumberCheck = code.includes('isinstance(') && code.includes(', Number)');
1279
 
1280
  if (hasCall) {
@@ -1285,9 +1285,9 @@ const updateCode = () => {
1285
  code = API + code;
1286
  }
1287
 
1288
- // Replace math_isPrime() with isprime() and add sympy import
1289
  if (hasPrime) {
1290
- code = code.replace(/math_isPrime\(\)/g, 'isprime()');
1291
  code = "from sympy import isprime\n\n" + code;
1292
  }
1293
 
 
1274
  const blocks = ws.getAllBlocks(false);
1275
  const hasCall = blocks.some(block => block.type === 'llm_call');
1276
  const hasAPI = blocks.some(block => block.type === 'call_api');
1277
+ const hasPrime = code.includes('math_isPrime(');
1278
  const hasNumberCheck = code.includes('isinstance(') && code.includes(', Number)');
1279
 
1280
  if (hasCall) {
 
1285
  code = API + code;
1286
  }
1287
 
1288
+ // Replace math_isPrime(...) with isprime(...) and add sympy import
1289
  if (hasPrime) {
1290
+ code = code.replace(/math_isPrime\(([^)]*)\)/g, 'isprime($1)');
1291
  code = "from sympy import isprime\n\n" + code;
1292
  }
1293